2

I want to implement rbreak from Python scripting.

The simplest way to do that would be to loop over all functions, and compare their name to a regular expression in Python.

Or if there is a better way without explicit looping, I'm interested as well.

I expect the solution to use some API like: https://sourceware.org/gdb/onlinedocs/gdb/Symbol-Tables-In-Python.html but it's hard to do it without examples.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985

1 Answers1

4

The documentation can definitely be improved. This provides a clue:

The outermost block is known as the global block.
The global block typically holds public global variables and functions.

A gdb.Block is iterable.

So all we need to do is get hold of the global block, and iterate over it.

Using the following test:

int a_global;
int foo() { return a_global; }
int bar() { return foo(); }
int main() { return bar(); }

$ gcc -g t.c && gdb -q ./a.out

(gdb) py
> for sym in gdb.lookup_global_symbol('main').symtab.global_block():
>   print(sym.name, sym.is_function)
^D
('foo', True)
('bar', True)
('main', True)
('a_global', False)

VoilĂ .

Employed Russian
  • 199,314
  • 34
  • 295
  • 362