Find the path of the source code for the executable being currently debugged in GDB

前端 未结 5 1635
故里飘歌
故里飘歌 2020-12-29 05:19

I can set a breakpoint in main and debug the code with the correct source code, but I don\'t know where GDB is taking the source code from.

The source code is not pr

相关标签:
5条回答
  • 2020-12-29 05:52

    This information is kept in the binary in the DWARF2 format. So, in order to see the DWARF2 information, you can use the dwarfdump utility. Needed information is kept in the DW_AT_comp_dir field.

    0 讨论(0)
  • 2020-12-29 05:55

    Use the GDB "show directories" command to see the source search path.

    0 讨论(0)
  • 2020-12-29 06:04

    Use

    (gdb) show directories
    

    If you don't know where those directories are set, check your .gdbinit file to see if there are statements like

    directory /path/to/source
    

    See also this other Stack Overflow question about GDB.

    0 讨论(0)
  • 2020-12-29 06:09

    You can use the GDB command:

    info source
    

    Sample output:

    Current source file is a.c
    Compilation directory is /home/user/test
    Located in /home/user/test/a.c
    Contains 17 lines.
    Source language is c.
    Compiled with DWARF 2 debugging format.
    Includes preprocessor macro info.
    
    0 讨论(0)
  • 2020-12-29 06:17

    The binary is probably compiled with "-g" - i.e. debugging.

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