【问题标题】:Get argument names of functions in GDB without hitting a breakpoint在不遇到断点的情况下获取 GDB 中函数的参数名称
【发布时间】:2020-08-23 22:37:54
【问题描述】:

我正在使用 mingw 的 GDB。

当我遇到断点时,它会根据调试符号为我提供函数的参数名称:

Breakpoint 1, CApp::OnTextInput (this=0x81ab888, ch=97)

但是,我找不到一种方法来获取未设置断点的函数的参数名称。使用info functions,我可以获取参数类型和函数名称,但不能获取参数名称。

是否有可能或者我总是必须打断点才能获取参数名称?

【问题讨论】:

    标签: gdb mingw reverse-engineering


    【解决方案1】:

    我找不到如何用 gdb 来做,但你可以用其他工具来做:dwarfdump 或 objdump。对于这个简单的程序:

    int main(int argc, char * argv[])
    {
      return 0;
    }
    

    您可以使用 dwarfdump 转储 dwarf 调试信息:

    $ dwarfdump a.out | grep -A30 "DW_AT_name.*main"
                          DW_AT_name                  main
                          DW_AT_decl_file             0x00000001 /tmp/1.c
                          DW_AT_decl_line             0x00000001
                          DW_AT_decl_column           0x00000005
                          DW_AT_prototyped            yes(1)
                          DW_AT_type                  <0x0000006e>
                          DW_AT_low_pc                0x00401106
                          DW_AT_high_pc               <offset-from-lowpc>18
                          DW_AT_frame_base            len 0x0001: 9c: DW_OP_call_frame_cfa
                          DW_AT_GNU_all_call_sites    yes(1)
                          DW_AT_sibling               <0x0000006e>
    < 2><0x0000004f>      DW_TAG_formal_parameter
                            DW_AT_name                  argc
                            DW_AT_decl_file             0x00000001 /tmp/1.c
                            DW_AT_decl_line             0x00000001
                            DW_AT_decl_column           0x0000000e
                            DW_AT_type                  <0x0000006e>
                            DW_AT_location              len 0x0002: 916c: DW_OP_fbreg -20
    < 2><0x0000005e>      DW_TAG_formal_parameter
                            DW_AT_name                  argv
                            DW_AT_decl_file             0x00000001 /tmp/1.c
                            DW_AT_decl_line             0x00000001
                            DW_AT_decl_column           0x0000001b
                            DW_AT_type                  <0x00000075>
                            DW_AT_location              len 0x0002: 9160: DW_OP_fbreg -32
    < 1><0x0000006e>    DW_TAG_base_type
                          DW_AT_byte_size             0x00000004
                          DW_AT_encoding              DW_ATE_signed
                          DW_AT_name                  int
    < 1><0x00000075>    DW_TAG_pointer_type
                          DW_AT_byte_size             0x00000008
    

    您可以在此处看到函数main 有两个参数,名称分别为argcargv

    您也可以使用 objdump 来获取相同的信息。这是main 的相关输出,它是来自objdump --dwarf=info a.out 输出的参数:

     <1><2d>: Abbrev Number: 2 (DW_TAG_subprogram)
        <2e>   DW_AT_external    : 1
        <2e>   DW_AT_name        : (indirect string, offset: 0x58): main
        <32>   DW_AT_decl_file   : 1
        <33>   DW_AT_decl_line   : 1
        <34>   DW_AT_decl_column : 5
        <35>   DW_AT_prototyped  : 1
        <35>   DW_AT_type        : <0x6e>
        <39>   DW_AT_low_pc      : 0x401106
        <41>   DW_AT_high_pc     : 0x12
        <49>   DW_AT_frame_base  : 1 byte block: 9c     (DW_OP_call_frame_cfa)
        <4b>   DW_AT_GNU_all_call_sites: 1
        <4b>   DW_AT_sibling     : <0x6e>
     <2><4f>: Abbrev Number: 3 (DW_TAG_formal_parameter)
        <50>   DW_AT_name        : (indirect string, offset: 0x5): argc
        <54>   DW_AT_decl_file   : 1
        <55>   DW_AT_decl_line   : 1
        <56>   DW_AT_decl_column : 14
        <57>   DW_AT_type        : <0x6e>
        <5b>   DW_AT_location    : 2 byte block: 91 6c  (DW_OP_fbreg: -20)
     <2><5e>: Abbrev Number: 3 (DW_TAG_formal_parameter)
        <5f>   DW_AT_name        : (indirect string, offset: 0x0): argv
        <63>   DW_AT_decl_file   : 1
        <64>   DW_AT_decl_line   : 1
        <65>   DW_AT_decl_column : 27
        <66>   DW_AT_type        : <0x75>
        <6a>   DW_AT_location    : 2 byte block: 91 60  (DW_OP_fbreg: -32)
     <2><6d>: Abbrev Number: 0
    

    【讨论】:

    • 你会如何用 objdump 做同样的事情?
    • 还添加了 objdump 输出。
    • 看起来 objdump 和 dwarfdump 都给了我参数的类型,但没有给我它的名字 - 但该信息必须存在于某个地方吧?
    • 你的编译器应该输出这个信息,这些信息应该可以被 objdump 和 dwarfdump 读取,除非在调试信息生成中没有错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多