首页 > 解决方案 > 获取 GDB 中函数的参数名称而不遇到断点

问题描述

我正在使用mingw的GDB。

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

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

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

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

标签: gdbmingwreverse-engineering

解决方案


我找不到如何用 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有 2 个参数,其名称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

推荐阅读