From: Simon Marchi <simark@simark.ca>
To: Christian Biesinger <cbiesinger@google.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH][PR/24474] Make gdb.lookup_static_symbol also check the STATIC_SCOPE
Date: Tue, 16 Jul 2019 03:28:00 -0000 [thread overview]
Message-ID: <8f4bcc74-18a0-c8f6-b97d-aef05021a656@simark.ca> (raw)
In-Reply-To: <20190605012421.252953-1-cbiesinger@google.com>
On 2019-06-04 9:24 p.m., Christian Biesinger via gdb-patches wrote:
> gdb/ChangeLog:
>
> 2019-06-04 Christian Biesinger <cbiesinger@google.com>
>
> PR/24474: Make gdb.lookup_global_symbol also check the STATIC_SCOPE
> because from a C/C++ developer's perspective, these are also globals.
> * NEWS: Mention this change.
> * python/py-symbol.c (gdbpy_lookup_global_symbol): Call
> lookup_static_symbol if lookup_global_symbol returns NULL.
>
> gdb/testsuite/ChangeLog:
>
> 2019-06-04 Christian Biesinger <cbiesinger@google.com>
>
> * gdb.python/py-symbol.c: Add a static variable and one in an anonymous
> namespace.
> * gdb.python/py-symbol.exp: Check that lookup_global_symbol finds those
> variables.
Hi Christian,
Sorry for the delay, I'll try to help you with this.
I am not sure this is the right thing to do, or at least some things need to be
clarified. Global symbols are visible through the entire program (there can only
be one of that name), whereas there can be many static symbols with the same name.
What should the user expect if there are multiple static symbols with the same name?
I suppose we'll return the first one that matches, without any particular guarantee
about which one.
It is possible to get to a particular static symbol using gdb.lookup_symbol, provided
you pass a block that is under the right static block, and that no other symbol shadows
this one from the point of view of the block. But IIRC, it can prove difficult to get
access the static block of a particular compilation unit (if you don't yet have a reference
to a frame block under that static block).
<thought drift>
I have been thinking for a while that we are missing the concept of compilation units in
our Python API, that would be the bridge between objfiles and global/static blocks.
- From an objfile, you could list all included compilation units or search through them
- From the compilation unit, you could obtain its global/static block.
From there, you could use gdb.lookup_symbol, passing the static block of the compilation unit.
However, in my (naive) attempt at adding compunits to the Python API [1], which consisted of
wrapping compunit_symtab objects in Python, the problem I faced is that compunit_symtab objects
are not created until full symbols are read. So unless you used -readnow, you would not
see all the compilation units you would expect (because they are lazily created).
</thought drift>
Would it be an option to add a gdb.lookup_static_symbol function, that would only look through
the static blocks? Its behavior could be that if you don't pass a block, it searches through
all the static blocks until it finds a matching symbol (just like your patch does with
gdb.lookup_global_symbol if no symbol is found). And if you pass a block, it restricts the
search to the static block linked to that block, ensuring you find the static symbol you want.
Simon
[1] https://github.com/simark/binutils-gdb/commits/py-compunit
next prev parent reply other threads:[~2019-07-16 3:28 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-05 1:24 Christian Biesinger via gdb-patches
2019-06-18 20:15 ` Christian Biesinger via gdb-patches
2019-07-08 22:05 ` [PING] " Christian Biesinger via gdb-patches
2019-07-15 16:52 ` Christian Biesinger via gdb-patches
2019-07-16 3:28 ` Simon Marchi [this message]
2019-07-26 22:05 ` Christian Biesinger via gdb-patches
2019-07-26 22:23 ` [PATCH v2] [PR/24474] Add gdb.lookup_static_symbol to the python API Christian Biesinger via gdb-patches
2019-07-30 1:14 ` Simon Marchi
2019-07-30 1:35 ` [PATCH v3] " Christian Biesinger via gdb-patches
2019-07-30 1:50 ` Simon Marchi
2019-07-30 1:59 ` [PATCH v4] " Christian Biesinger via gdb-patches
2019-07-30 15:41 ` Christian Biesinger via gdb-patches
2019-07-30 15:57 ` Eli Zaretskii
2019-07-30 16:01 ` Christian Biesinger via gdb-patches
2019-07-26 22:43 ` [PATCH][PR/24474] Make gdb.lookup_static_symbol also check the STATIC_SCOPE Simon Marchi
2019-08-01 19:05 ` Christian Biesinger via gdb-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8f4bcc74-18a0-c8f6-b97d-aef05021a656@simark.ca \
--to=simark@simark.ca \
--cc=cbiesinger@google.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox