Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* Using GDB as a Python interpreter
@ 2023-07-01  8:53 Florian Weimer via Gdb
  2023-07-03  7:11 ` Aktemur, Tankut Baris via Gdb
  2023-07-03 19:39 ` Tom Tromey
  0 siblings, 2 replies; 6+ messages in thread
From: Florian Weimer via Gdb @ 2023-07-01  8:53 UTC (permalink / raw)
  To: gdb

I want to run a Python script with GDB, from the shell command line,
without having to create two files.

I came up with the hack included below, but it's not particularly nice.
The downside is that the script file name must end in “.py”, which would
not allow to install the script in /usr/bin for most distributions.  I
don't see a way to override that.

Thanks,
Florian

#!/usr/bin/python

if 'gdb' not in globals():
    import sys
    import os

    pid, = sys.argv[1:]
    os.execvp('gdb', [
        'gdb', '--batch',
        '-ex', 'set debuginfod enabled off',
        '-ex', 'attach ' + pid,
        '-x', __file__,
    ])

dl_ns = gdb.lookup_global_symbol('_rtld_global').value()['_dl_ns']
nsid_min, nsid_max = dl_ns.type.range()
for nsid in range(nsid_min, nsid_max + 1):
    l = dl_ns[nsid]['_ns_loaded']
    if not l:
        continue
    print('namespace', nsid)
    while l:
        print('  {!r}'.format(l['l_name'].string()))
        ln = l['l_libname']
        while ln:
            print('    alias {!r}'.format(ln['name'].string()))
            ln = ln['next']
        l = l['l_next']


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

end of thread, other threads:[~2023-07-03 23:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-01  8:53 Using GDB as a Python interpreter Florian Weimer via Gdb
2023-07-03  7:11 ` Aktemur, Tankut Baris via Gdb
2023-07-03  8:13   ` Florian Weimer via Gdb
2023-07-03 19:39 ` Tom Tromey
2023-07-03 20:24   ` Mark Wielaard
2023-07-03 23:00     ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox