public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Adding Python files to be autoloaded for a particular architecture
@ 2020-07-17 16:11 Reuben Thomas
  2020-07-17 21:42 ` Joel Brobecker
  0 siblings, 1 reply; 11+ messages in thread
From: Reuben Thomas @ 2020-07-17 16:11 UTC (permalink / raw)
  To: gdb

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).

-- 
https://rrt.sc3d.org

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Adding Python files to be autoloaded for a particular architecture
  2020-07-17 16:11 Adding Python files to be autoloaded for a particular architecture Reuben Thomas
@ 2020-07-17 21:42 ` Joel Brobecker
  2020-07-17 22:03   ` Reuben Thomas
  0 siblings, 1 reply; 11+ messages in thread
From: Joel Brobecker @ 2020-07-17 21:42 UTC (permalink / raw)
  To: Reuben Thomas via Gdb

> 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

You can try with --with-system-gdbinit=xxx instead.

> 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.

We can probably delete these two files, if no one else finds them useful
anymore. But I don't think you really want to use GDB's system-gdbinit
as a system-gdbinit-dir; generally speaking, my understand of the
directory provided in the GDB sources is that it's a collection of
files that are not necessarily meant to always be relevant.

-- 
Joel

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Adding Python files to be autoloaded for a particular architecture
  2020-07-17 21:42 ` Joel Brobecker
@ 2020-07-17 22:03   ` Reuben Thomas
  2020-07-17 22:09     ` Christian Biesinger
  2020-07-17 22:14     ` Joel Brobecker
  0 siblings, 2 replies; 11+ messages in thread
From: Reuben Thomas @ 2020-07-17 22:03 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: Reuben Thomas via Gdb

On Fri, 17 Jul 2020 at 22:42, Joel Brobecker <brobecker@adacore.com> wrote:

> > 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
>
> You can try with --with-system-gdbinit=xxx instead.
>

Thanks, but surely --with-system-gdbinit is designed for the system
administrator? For example, on Debian, the supplied gdb is configured with
--with-system-gdbinit=/etc/gdb/gdbinit. I don't want to conflict with this
usage.

We can probably delete these two files, if no one else finds them useful
> anymore. But I don't think you really want to use GDB's system-gdbinit
> as a system-gdbinit-dir; generally speaking, my understand of the
> directory provided in the GDB sources is that it's a collection of
> files that are not necessarily meant to always be relevant.
>

Ah, OK, so I should instead configure with a different
--with-system-gdbinit-dir? But how can I get my files installed in that
directory? It seems like this is not something I can do with gdb's build
system.

So should I be using a different route to get an architecture support file
always installed and loaded?

-- 
https://rrt.sc3d.org

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Adding Python files to be autoloaded for a particular architecture
  2020-07-17 22:03   ` Reuben Thomas
@ 2020-07-17 22:09     ` Christian Biesinger
  2020-07-17 22:21       ` Reuben Thomas
  2020-07-17 22:14     ` Joel Brobecker
  1 sibling, 1 reply; 11+ messages in thread
From: Christian Biesinger @ 2020-07-17 22:09 UTC (permalink / raw)
  To: Reuben Thomas; +Cc: Joel Brobecker, Reuben Thomas via Gdb

On Fri, Jul 17, 2020 at 5:03 PM Reuben Thomas via Gdb
<gdb@sourceware.org> wrote:
>
> On Fri, 17 Jul 2020 at 22:42, Joel Brobecker <brobecker@adacore.com> wrote:
>
> > > 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
> >
> > You can try with --with-system-gdbinit=xxx instead.
> >
>
> Thanks, but surely --with-system-gdbinit is designed for the system
> administrator? For example, on Debian, the supplied gdb is configured with
> --with-system-gdbinit=/etc/gdb/gdbinit. I don't want to conflict with this
> usage.
>
> We can probably delete these two files, if no one else finds them useful
> > anymore. But I don't think you really want to use GDB's system-gdbinit
> > as a system-gdbinit-dir; generally speaking, my understand of the
> > directory provided in the GDB sources is that it's a collection of
> > files that are not necessarily meant to always be relevant.

FWIW I kinda think that directory should be renamed. Maybe
contrib/gdbinit, or sample-gdbinit, or something.

> Ah, OK, so I should instead configure with a different
> --with-system-gdbinit-dir? But how can I get my files installed in that
> directory? It seems like this is not something I can do with gdb's build
> system.
>
> So should I be using a different route to get an architecture support file
> always installed and loaded?

You could certainly add new rules modeled after the system-gdbinit
ones in gdb/data-directory/Makefile.in?

Christian

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Adding Python files to be autoloaded for a particular architecture
  2020-07-17 22:03   ` Reuben Thomas
  2020-07-17 22:09     ` Christian Biesinger
@ 2020-07-17 22:14     ` Joel Brobecker
  2020-07-17 22:18       ` Reuben Thomas
  1 sibling, 1 reply; 11+ messages in thread
From: Joel Brobecker @ 2020-07-17 22:14 UTC (permalink / raw)
  To: Reuben Thomas; +Cc: Reuben Thomas via Gdb

> > You can try with --with-system-gdbinit=xxx instead.
> >
> 
> Thanks, but surely --with-system-gdbinit is designed for the system
> administrator? For example, on Debian, the supplied gdb is configured with
> --with-system-gdbinit=/etc/gdb/gdbinit. I don't want to conflict with this
> usage.

I don't think you can categorize the intended user of each option.
They just do different things.

> We can probably delete these two files, if no one else finds them useful
> > anymore. But I don't think you really want to use GDB's system-gdbinit
> > as a system-gdbinit-dir; generally speaking, my understand of the
> > directory provided in the GDB sources is that it's a collection of
> > files that are not necessarily meant to always be relevant.
> 
> Ah, OK, so I should instead configure with a different
> --with-system-gdbinit-dir? But how can I get my files installed in that
> directory? It seems like this is not something I can do with gdb's build
> system.
> 
> So should I be using a different route to get an architecture support file
> always installed and loaded?

Thinking out loud (I do not know all the details off the top of my head),
I see a couple of ways:
  - You use a subdirectory of system-gdbinit, and then configure GDB
    to use that subdirectory
  - You create one file that the sources all the other files you need,
    and then configure GDB to use that file as the system-gdbinit.

-- 
Joel

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Adding Python files to be autoloaded for a particular architecture
  2020-07-17 22:14     ` Joel Brobecker
@ 2020-07-17 22:18       ` Reuben Thomas
  0 siblings, 0 replies; 11+ messages in thread
From: Reuben Thomas @ 2020-07-17 22:18 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: Reuben Thomas via Gdb

On Fri, 17 Jul 2020 at 23:14, Joel Brobecker <brobecker@adacore.com> wrote:

> > > You can try with --with-system-gdbinit=xxx instead.
> > >
> >
> > Thanks, but surely --with-system-gdbinit is designed for the system
> > administrator? For example, on Debian, the supplied gdb is configured
> with
> > --with-system-gdbinit=/etc/gdb/gdbinit. I don't want to conflict with
> this
> > usage.
>
> I don't think you can categorize the intended user of each option.
> They just do different things.
>

What I mean is that I cannot use --with-system-gdbinit for a solution that
I would eventually like to merge into gdb.

Thinking out loud (I do not know all the details off the top of my head),
> I see a couple of ways:
>   - You use a subdirectory of system-gdbinit, and then configure GDB
>     to use that subdirectory
>   - You create one file that the sources all the other files you need,
>     and then configure GDB to use that file as the system-gdbinit.
>

Again, both of these suggestions involve configuring GDB, so I don't see
how they can be suitable for code that can be merged into GDB.

Sorry if I'm failing to understand something here!

-- 
https://rrt.sc3d.org

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Adding Python files to be autoloaded for a particular architecture
  2020-07-17 22:09     ` Christian Biesinger
@ 2020-07-17 22:21       ` Reuben Thomas
  2020-07-17 22:31         ` Christian Biesinger
  0 siblings, 1 reply; 11+ messages in thread
From: Reuben Thomas @ 2020-07-17 22:21 UTC (permalink / raw)
  To: Christian Biesinger; +Cc: Joel Brobecker, Reuben Thomas via Gdb

On Fri, 17 Jul 2020 at 23:10, Christian Biesinger <cbiesinger@google.com>
wrote:

>
> You could certainly add new rules modeled after the system-gdbinit
> ones in gdb/data-directory/Makefile.in?
>

Thanks for your suggestion! Sorry if I'm failing to understand something
obvious, but what exactly do you mean by "new rules modeled after the
system-gdbinit ones"? In particular, it's not obvious to me how such a rule
would cause the file(s) I add to be automatically loaded on startup,
without also adding support for some other directory to GDB itself.

-- 
https://rrt.sc3d.org

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Adding Python files to be autoloaded for a particular architecture
  2020-07-17 22:21       ` Reuben Thomas
@ 2020-07-17 22:31         ` Christian Biesinger
  2020-07-17 22:37           ` Reuben Thomas
  0 siblings, 1 reply; 11+ messages in thread
From: Christian Biesinger @ 2020-07-17 22:31 UTC (permalink / raw)
  To: Reuben Thomas; +Cc: Joel Brobecker, Reuben Thomas via Gdb

On Fri, Jul 17, 2020 at 5:22 PM Reuben Thomas <rrt@sc3d.org> wrote:
>
> On Fri, 17 Jul 2020 at 23:10, Christian Biesinger <cbiesinger@google.com> wrote:
>>
>>
>> You could certainly add new rules modeled after the system-gdbinit
>> ones in gdb/data-directory/Makefile.in?
>
>
> Thanks for your suggestion! Sorry if I'm failing to understand something obvious, but what exactly do you mean by "new rules modeled after the system-gdbinit ones"? In particular, it's not obvious to me how such a rule would cause the file(s) I add to be automatically loaded on startup, without also adding support for some other directory to GDB itself.

Sorry, to clarify, my suggestion is:
- Configure your gdb with --with-system-gdbinit-dir=/etc/gdbinit.d or
something, and
- Add rules to install your new file in that dir, if your platform is
enabled & the system init dir was provided

Christian

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Adding Python files to be autoloaded for a particular architecture
  2020-07-17 22:31         ` Christian Biesinger
@ 2020-07-17 22:37           ` Reuben Thomas
  2020-07-20 20:26             ` Christian Biesinger
  0 siblings, 1 reply; 11+ messages in thread
From: Reuben Thomas @ 2020-07-17 22:37 UTC (permalink / raw)
  To: Christian Biesinger; +Cc: Joel Brobecker, Reuben Thomas via Gdb

[Apologies to Christian, I sent a reply off-list. Replying again to all.]

On Fri, 17 Jul 2020 at 23:32, Christian Biesinger <cbiesinger@google.com>
wrote:


> Sorry, to clarify, my suggestion is:
> - Configure your gdb with --with-system-gdbinit-dir=/etc/gdbinit.d or
> something, and
> - Add rules to install your new file in that dir, if your platform is
> enabled & the system init dir was provided
>

Thanks very much for the clarification. However, it's unfortunate that a
user of my architecture would have to configure --with-system-gdbinit-dir,
or not get the Python files?

-- 
https://rrt.sc3d.org

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Adding Python files to be autoloaded for a particular architecture
  2020-07-17 22:37           ` Reuben Thomas
@ 2020-07-20 20:26             ` Christian Biesinger
  2020-07-20 21:39               ` Reuben Thomas
  0 siblings, 1 reply; 11+ messages in thread
From: Christian Biesinger @ 2020-07-20 20:26 UTC (permalink / raw)
  To: Reuben Thomas; +Cc: Joel Brobecker, Reuben Thomas via Gdb

On Fri, Jul 17, 2020 at 5:38 PM Reuben Thomas <rrt@sc3d.org> wrote:
>
> [Apologies to Christian, I sent a reply off-list. Replying again to all.]
>
> On Fri, 17 Jul 2020 at 23:32, Christian Biesinger <cbiesinger@google.com> wrote:
>
>>
>> Sorry, to clarify, my suggestion is:
>> - Configure your gdb with --with-system-gdbinit-dir=/etc/gdbinit.d or
>> something, and
>> - Add rules to install your new file in that dir, if your platform is
>> enabled & the system init dir was provided
>
>
> Thanks very much for the clarification. However, it's unfortunate that a user of my architecture would have to configure --with-system-gdbinit-dir, or not get the Python files?

I see. In that case, I see two options:
- Put it in gdb/python/lib/gdb. That directory has so far only been
used as an implementation detail for gdb's python API, but maybe
maintainers will be OK with extending it in that way. That dir does
get installed whenever python is enabled.
- Or implement it in C++

How does that sound?


Christian

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Adding Python files to be autoloaded for a particular architecture
  2020-07-20 20:26             ` Christian Biesinger
@ 2020-07-20 21:39               ` Reuben Thomas
  0 siblings, 0 replies; 11+ messages in thread
From: Reuben Thomas @ 2020-07-20 21:39 UTC (permalink / raw)
  To: Christian Biesinger; +Cc: Joel Brobecker, Reuben Thomas via Gdb

On Mon, 20 Jul 2020 at 21:27, Christian Biesinger <cbiesinger@google.com>
wrote:

> I see. In that case, I see two options:
> - Put it in gdb/python/lib/gdb. That directory has so far only been
> used as an implementation detail for gdb's python API, but maybe
> maintainers will be OK with extending it in that way. That dir does
> get installed whenever python is enabled.
>

This feels like the wrong place, as after all what I'm implementing is not
an extension of the gdb package, but a use of it.


> - Or implement it in C++
>

It would be a shame to have to use another language.

However, there will certainly be some solution, and I guess I'll revisit
this once I have a contribution to submit to the maintainers.

Thanks very much for all your suggestions!

-- 
https://rrt.sc3d.org

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-07-20 21:39 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-17 16:11 Adding Python files to be autoloaded for a particular architecture Reuben Thomas
2020-07-17 21:42 ` Joel Brobecker
2020-07-17 22:03   ` Reuben Thomas
2020-07-17 22:09     ` Christian Biesinger
2020-07-17 22:21       ` Reuben Thomas
2020-07-17 22:31         ` Christian Biesinger
2020-07-17 22:37           ` Reuben Thomas
2020-07-20 20:26             ` Christian Biesinger
2020-07-20 21:39               ` Reuben Thomas
2020-07-17 22:14     ` Joel Brobecker
2020-07-17 22:18       ` Reuben Thomas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).