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

后端 未结 5 1699
渐次进展
渐次进展 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: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.

提交回复
热议问题