gdb: how to print the current line or find the current line number?

后端 未结 5 1674
渐次进展
渐次进展 2020-12-23 02:56

list commands prints a set of lines, but I need one single line, where I am and where an error has probably occurred.

相关标签:
5条回答
  • 2020-12-23 03:06

    The 'frame' command will give you what you are looking for. (This can be abbreviated just 'f'). Here is an example:

    (gdb) frame
    \#0  zmq::xsub_t::xrecv (this=0x617180, msg_=0x7ffff00008e0) at xsub.cpp:139
    139         int rc = fq.recv (msg_);
    (gdb)
    

    Without an argument, 'frame' just tells you where you are at (with an argument it changes the frame). More information on the frame command can be found here.

    0 讨论(0)
  • 2020-12-23 03:10

    All the answers above are correct, What I prefer is to use tui mode (ctrl+X A or 'tui enable') which shows your location and the function in a separate window which is very helpful for the users. Hope that helps too.

    0 讨论(0)
  • 2020-12-23 03:12

    I do get the same information while debugging. Though not while I am checking the stacktrace. Most probably you would have used the optimization flag I think. Check this link - something related.

    Try compiling with -g3 remove any optimization flag. Then it might work. HTH!

    0 讨论(0)
  • 2020-12-23 03:32

    Command where or frame can be used. where command will give more info with the function name

    0 讨论(0)
  • 2020-12-23 03:32

    Keep in mind that gdb is a powerful command -capable of low level instructions- so is tied to assembly concepts.

    What you are looking for is called de instruction pointer, i.e:

    The instruction pointer register points to the memory address which the processor will next attempt to execute. The instruction pointer is called ip in 16-bit mode, eip in 32-bit mode,and rip in 64-bit mode.

    more detail here

    all registers available on gdb execution can be shown with:

    (gdb) info registers
    

    with it you can find which mode your program is running (looking which of these registers exist)

    then (here using most common register rip nowadays, replace with eip or very rarely ip if needed):

    (gdb)info line *$rip
    

    will show you line number and file source

    (gdb) list *$rip
    

    will show you that line with a few before and after

    but probably

    (gdb) frame
    

    should be enough in many cases.

    0 讨论(0)
提交回复
热议问题