* Expected behavior of gdb.lookup_symbol()
@ 2022-10-12 3:31 Gulshan Singh
0 siblings, 0 replies; only message in thread
From: Gulshan Singh @ 2022-10-12 3:31 UTC (permalink / raw)
To: gdb
[-- 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.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-10-12 3:32 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-12 3:31 Expected behavior of gdb.lookup_symbol() Gulshan Singh
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).