16

when use GNU gdb to debug a c process.

list command will print the lines but not telling me the file name.

set breakpoints can display all the line and file info I want but I don't want to set a breakpoint and have to disable or delete it.

(gdb) b oyss_funtion
Breakpoint 13 at 0x8049130: file main.c, line 119.

Is there a gdb command or settings can show me the file line info of a function(symbol) without setting a breakpoint there?

oyss
  • 662
  • 1
  • 8
  • 20
  • Besides other interesting things the `bt` (short for `backtrace`) command provides this info. – alk Dec 25 '13 at 09:22

1 Answers1

18

Use info line command.

info line oyss_function

For example, assume the file test.c contains:

#include <stdio.h>

int main(void)
{
    printf("\n");
    return 0;
}

Then, invoking info line main in GDB gets:

(gdb) info line main
Line 4 of "test.c" starts at address 0x400498 <main> and ends at 0x40049c <main+4>.
timrau
  • 22,578
  • 4
  • 51
  • 64
  • I'm getting `No line number information available for address 0x48a746
    `. Why would this happen? Edit: Oops, needed to compile with `-g` in GCC.
    – sudo Feb 22 '17 at 01:40
  • This answer only show the file name. To get the full path see this answer below a linked question: [c++ - Identify source file name for a symbol in gdb debugger - Stack Overflow](https://stackoverflow.com/a/58827608/5267751). – user202729 Oct 05 '21 at 23:50