Does GDB have a "step-to-next-call" instruction? -


windbg , related windows kernel debuggers support "pc" command runs target until reaching next call statement (in assembly). in other words, breaks prior creating new stack frame, sort of opposite of "finish". "start" in gdb runs until main starts, in essence want 'start' wildcard of "any next frame".

i'm trying locate similar functionality in gdb, have not found it.

is possible?

example windbg doc: http://windbg.info/doc/1-common-cmds.html#4_expr_and_cmds

simple answer: no, step-to-next-call not part of gdb commands.

gdb/python-aware answer: no, it's not part of gdb commands, it's easy implement!

i'm not sure understand if want stop before or after call instruction execution.

  • to stop before, need stepi/nexti (next assembly instruction) until see call in current instruction:

    import gdb  class stepbeforenextcall (gdb.command):     def __init__ (self):         super (stepbeforenextcall, self).__init__ ("step-before-next-call",                                                    gdb.command_obscure)      def invoke (self, arg, from_tty):         arch = gdb.selected_frame().architecture()          while true:             current_pc = addr2num(gdb.selected_frame().read_register("pc"))             disa = arch.disassemble(current_pc)[0]             if "call" in disa["asm"]: # or startswith ?                 break              silent=true             gdb.execute("stepi", to_string=silent)          print("step-before-next-call: next instruction call.")         print("{}: {}".format(hex(int(disa["addr"])), disa["asm"]))  def addr2num(addr):     try:         return int(addr)  # python 3     except:         return long(addr) # python 2  stepbeforenextcall() 
  • to stop after call, compute current stack depth, step until it's deeper:

    import gdb  def callstack_depth():     depth = 1     frame = gdb.newest_frame()     while frame not none:         frame = frame.older()         depth += 1     return depth  class steptonextcall (gdb.command):     def __init__ (self):         super (steptonextcall, self).__init__ ("step-to-next-call",                                                 gdb.command_obscure)      def invoke (self, arg, from_tty):         start_depth = current_depth =callstack_depth()          # step until we're 1 step deeper         while current_depth == start_depth:             silent=true             gdb.execute("step", to_string=silent)             current_depth = callstack_depth()          # display information new frame         gdb.execute("frame 0")  steptonextcall()  

just put in file, source gdb (or in .gdbinit) , provide new commands step-before-next-call , step-to-next-call.

relevant documentation there:


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -