简体   繁体   中英

What's the best way to work with core file in python?

I'm working on a bit of crash reporting code, and need to extract the stacktrace from a core dump file.

Currently, I'm using a subprocess call to:

'gdb -q -batch -nx -x /path/to/executable /path/to/coredump'

and passing it a command file with the contents:

thread apply all bt full
quit

This works fine, but I do have to parse output which seems a bit error prone.

One alternative might be to use the pygdb2 package, but I'm not quite sure it solves the problem I'm interested in as the package's description mentions controlling gdb from the python process being debugged. https://bitbucket.org/antocuni/pygdb2/

Any suggestions here?

Thanks! Matthew

gdb supports running python commands: https://sourceware.org/gdb/onlinedocs/gdb/Python-API.html#Python-API

The solution was to still run gdb as a subprocess, but in the cmd file, run a python script which dumped the stack to a json file. This was much easier to parse than raw text.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM