I defined a convenience function for GDB using the Python API,
import gdb
verbose = True
class HCall(gdb.Function):
def __init__(self, funcname):
super(HCall,self).__init__(funcname)
def log_call(cmd):
if verbose:
print(cmd)
try:
gdb.execute(cmd)
except Exception, e:
print (e)
import traceback
# traceback.print_stack()
traceback.format_exc()
class NewCVar(HCall):
""" allocates a c variable in heap """
def __init__(self):
super(NewCVar,self).__init__("newcvar")
def invoke(self, name, oftype):
cmd = "call gdb.execute(set $" + name + " = malloc(sizeof(" + oftype + "))"
log_call(cmd)
return "$" + name
NewCVar()
I can load this file with "source usefunction.py", and print the help text with "function newcvar". Nevertheless GDB does not know about $newcvar, as I would expect (https://sourceware.org/gdb/onlinedocs/gdb/Functions-In-Python.html).
Does anyone have a clue what can I be doing wrong?
Thanks in advance!
gdb.execute("call gdb.execute(set $" + name + " = malloc(sizeof(" + oftype + "))"). But the gdbcallcommand is used to call a function in the target that is being debugged. What sort of target is gdb debugging when you run this? - Mark Plotnick