How to load multiple symbol files in gdb

前端 未结 6 913
一向
一向 2020-12-12 13:45

How to load multiple symbol files in gdb. I have a executable foo.out and loading a module bar.so. I have created two symbol files foo.symbol and bar.symbol. Ho

6条回答
  •  庸人自扰
    2020-12-12 14:38

    Additional symbols can be loaded to the gdb debug session with:

    add-symbol-file filename address
    

    Parameter address is the address for .text section. This address can be retrieved with:

    readelf -WS path/to/file.elf | grep .text | awk '{ print "0x"$5 }'
    

    This can be automated in gdb by adding following entry to ~/.gdbinit:

    define add-symbol-file-auto
      # Parse .text address to temp file
      shell echo set \$text_address=$(readelf -WS $arg0 | grep .text | awk '{ print "0x"$5 }') >/tmp/temp_gdb_text_address.txt
    
      # Source .text address
      source /tmp/temp_gdb_text_address.txt
    
      #  Clean tempfile
      shell rm -f /tmp/temp_gdb_text_address.txt
    
      # Load symbol table
      add-symbol-file $arg0 $text_address
    end
    

    After above function definition add-symbol-file-auto can be used load additional symbols:

    (gdb) add-symbol-file-auto path/to/bootloader.elf
    add symbol table from file "path/to/bootloader.elf" at
        .text_addr = 0x8010400
    (gdb) add-symbol-file-auto path/to/application.elf
    add symbol table from file "path/to/application.elf" at
        .text_addr = 0x8000000
    (gdb) break main
    Breakpoint 1 at 0x8006cb0: main. (2 locations)
    (gdb) info break
    Num     Type           Disp Enb Address    What
    1       breakpoint     keep y    
    1.1                         y     0x08006cb0 in main() at ./source/main.cpp:114
    1.2                         y     0x080106a6 in main() at ./main.cpp:10
    (gdb)
    

提交回复
热议问题