From: Gulshan Singh <gsingh2011@gmail.com>
To: gdb@sourceware.org
Subject: Expected behavior of gdb.lookup_symbol()
Date: Tue, 11 Oct 2022 20:31:46 -0700 [thread overview]
Message-ID: <CANEZYrdEQ-9qfM8R=LNMPxqXByA5uf6FWkCy-1kTKvAnhWc_TQ@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1953 bytes --]
Hi,
I've noticed that the `gdb.lookup_symbol()` function in the Python API
returns None for certain types of symbols. For example:
$ gdb -q -nx -ex 'catch load libc' -ex 'run' /bin/ls
Reading symbols from /bin/ls...
(No debugging symbols found in /bin/ls)
Catchpoint 1 (load)
Starting program: /usr/bin/ls
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Catchpoint 1
Inferior loaded /lib/x86_64-linux-gnu/libselinux.so.1
/lib/x86_64-linux-gnu/libc.so.6
/lib/x86_64-linux-gnu/libpcre2-8.so.0
__GI__dl_debug_state () at ./elf/dl-debug.c:116
116 ./elf/dl-debug.c: No such file or directory.
(gdb) p __libc_malloc
$1 = {void *(size_t)} 0x7ffff7df3120 <__GI___libc_malloc>
(gdb) pi gdb.lookup_symbol('__libc_malloc')
(None, False)
(gdb) pi gdb.lookup_symbol('__GI___libc_malloc')
(<gdb.Symbol object at 0x7f896853e760>, False)
Here I was expecting both calls to `gdb.lookup_symbol()` to return a
`gdb.Symbol` object. I have debugging symbols installed. I determined the
name of the file containing the debug symbols like this:
(gdb) pi gdb.lookup_symbol('__GI___libc_malloc')[0].symtab.objfile
<gdb.Objfile
filename=/usr/lib/debug/.build-id/69/389d485a9793dbe873f0ea2c93e02efaa9aa3d.debug>
And I looked for those symbols in that file like this:
$ readelf -a
/usr/lib/debug/.build-id/69/389d485a9793dbe873f0ea2c93e02efaa9aa3d.debug |
grep __libc_malloc
5933: 00000000000a5120 828 FUNC LOCAL DEFAULT 15
__GI___libc_malloc
9639: 00000000000a5120 828 FUNC GLOBAL DEFAULT 15 __libc_malloc
It seems that the only difference is one is a local binding and one is a
global binding. Is this expected behavior? If so, why? And is there another
way to get the address of a symbol like this, or should I just resort to
calling `info address` with `gdb.execute()`?
My GDB version is GNU gdb (Ubuntu 12.0.90-0ubuntu1) 12.0.90, and I'm on
Ubuntu 22.04.1 LTS.
reply other threads:[~2022-10-12 3:32 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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='CANEZYrdEQ-9qfM8R=LNMPxqXByA5uf6FWkCy-1kTKvAnhWc_TQ@mail.gmail.com' \
--to=gsingh2011@gmail.com \
--cc=gdb@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).