PoC of helper tool to capture macro and enum values

Craig Ringer craig@2ndquadrant.com
Wed Jan 6 13:52:18 GMT 2021


Hi all

Here's a PoC of a tool I scratched together today to extract symbolic
values for enums and macros from arbitrary executables into a form that
'stap' can use.

I scripted gdb to dump the info and generate a .c file that I then compile
and supply to stap as an additional input. But I intend to change it to
directly generate a tapset soon; indirection via the .c file is entirely
unnecessary, and it's useless for non-kernel runtimes. I'll switch to
tapset .stpm generation soon.

I'm not super happy with the result. The biggest issue is that gdb's Python
API appears to lack a way to set up a scope within which expressions should
be evaluated. You can do some limited scoping of symbol lookups, but not
macros. You have to actually run the target program and break at relevant
locations, which is a hassle that makes the whole thing less useful.

It can also only dump macros if the target executable was built with -ggdb3
which is uncommon.

Anyway, flawed or not, here's the first draft. Example dumps some symbols
from a postgres executable.

-- 
 Craig Ringer                   http://www.2ndQuadrant.com/
 2ndQuadrant - PostgreSQL Solutions for the Enterprise
-------------- next part --------------
A non-text attachment was scrubbed...
Name: postgres_syms.sh
Type: application/x-shellscript
Size: 124 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/systemtap/attachments/20210106/1c445860/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: stap-enum-gdb.py
Type: text/x-python
Size: 5936 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/systemtap/attachments/20210106/1c445860/attachment.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: postgres_syms.gdb
Type: application/octet-stream
Size: 236 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/systemtap/attachments/20210106/1c445860/attachment.obj>


More information about the Systemtap mailing list