简体   繁体   English

在python中使用核心文件的最佳方法是什么?

[英]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. 我正在处理一些崩溃报告代码,并且需要从核心转储文件中提取stacktrace。

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. 一种替代方法是使用pygdb2软件包,但是我不确定它是否解决了我感兴趣的问题,因为该软件包的说明中提到了从调试的python进程控制gdb。 https://bitbucket.org/antocuni/pygdb2/ 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 gdb支持运行python命令: 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. 解决方案是仍然将gdb作为子进程运行,但是在cmd文件中,运行python脚本,该脚本将堆栈转储到json文件中。 This was much easier to parse than raw text. 这比原始文本更容易解析。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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