Search code examples
pythongdbcoredump

GDB+Python: Determining target type


Is there a way to determine whether the debugged target is a core dump or a 'live' process?


Solution

  • As far as I know, there is no dedicated way to do it in Python, however, you can still use

    • gdb.execute("<command>", to_string=<boolean>) to execute a "CLI" command in Python, where to_string being True will tell GDB to collect the output and return it as a string (cf. doc)

    • maint print target-stack which will print the layers used internally to access the inferior. You should see "core (Local core dump file)" if the core-debugging layer is active.

    So all-in-all, a bit of code like

    out = gdb.execute("maint print target-stack", to_string=True)
    print "Local core dump file" in out
    

    should do the trick.