Adding Python files to be autoloaded for a particular architecture

Reuben Thomas
2020-07-17T16:11:55Z

I have implemented gdb/binutils support for a new architecture (more on
that if & when I get it into a state in which it might be mergeable), and I
would like to have some Python loaded by default, to cope with an unusual
feature of the architecture (it's a stack machine, and gdb doesn't seem to
support stacks directly, so I added some Python routines to print out and
modify the stack).

This seems to be a suitable candidate for SYSTEM_GDBINIT_FILES. But if I
simply add a file to `SYSTEM_GDBINIT_FILES` in
`gdb/data-directory/Makefile.in`, and then configure with

--with-system-gdbinit-dir=$pkgdatadir/system-gdbinit

then all of the files are installed (there are already two existing files,
`elinos.py` and `wrs-linux.py`) and loaded when gdb starts up. This causes
errors, as `wrs-linux.py` in particular expects to find an environment
variable which I have not set.

So I wonder how I should do this? Ideally, I would like to load a file when
gdb is configured for my new architecture, but I can't find a mechanism for
that. I tried running `make SYSTEM_GDBINIT_FILES="my_file.py", but this
environment variable does not get passed to make in `data-directory`, so
has no effect unless I specifically run `make` in that directory.

Apologies if I've overlooked something obvious. I have been impressed that
so far I have been able to add a new backend with gdb/ld/gas/bfd/opcodes
support with no documentation (well, I did cheat a bit, and referred to the
defunct Internals manual; but on the whole the code is fairly clearly laid
out, and simply picking an existing architecture and finding all references
to it provided enough guidance).