gdb - 获取 GDB 中函数的参数名称而不遇到断点
问题描述
我正在使用mingw的GDB。
当我遇到断点时,它会根据调试符号为我提供函数的参数名称:
Breakpoint 1, CApp::OnTextInput (this=0x81ab888, ch=97)
但是,我找不到获取未设置断点的函数的参数名称的方法。使用info functions
,我可以获取参数类型和函数名称,但不能获取参数名称。
有可能还是我总是必须打断点才能获取参数名称?
解决方案
我找不到如何用 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 个参数,其名称argc
和argv
.
您也可以使用 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
推荐阅读
- c# - 安装在 Windows Server 中时,OWIN SelfHosted 在 Windows 服务项目中出现异常
- bash - curl: (3) URL 使用错误/非法格式或缺少 URL
- reactjs - 基于可用空间的动态表分页
- node.js - 在 express 中使用 websockets ws 包从后端数据库中获取数据并返回响应客户端而不刷新页面
- reactjs - 每次在我的数据库中进行更改时,如何重新渲染我的所有反应客户端?
- netsuite - 使用 NetSuite REST API 批量创建发票
- python - 没有收到结果
- python - Google 地球引擎中不同 ROI 的索引越界异常
- ios - 如何将消费信息发送到App Store成功退款
- kotlin - kotlin中密封类与密封接口有什么区别