我正在尝试从DWARF信息中获取有关调用约定的信息。更具体地说,我想知道用于将参数传递给函数的寄存器/堆栈位置是哪些。我的问题是,在某些情况下,我从DWARF转储中获得了错误的信息。我使用的示例是以下"C代码":
int __attribute__ ((fastcall)) __attribute__ ((noinline)) mult (int x, int y) {
return x*y;
}
我使用以下命令编译这个示例:
gcc -c -g -m32 test.c -o test.o
现在,当我使用以下命令获取dwarf转储时:
dwarfdump test.o
我将翻译以下有关此函数的信息:
我得到了如下有关该函数的信息:
< 2><0x00000042> DW_TAG_formal_parameter
DW_AT_name "x"
DW_AT_decl_file 0x00000001 /home/khaled/Repo_current/trunk/test.c
DW_AT_decl_line 0x00000001
DW_AT_type <0x0000005b>
DW_AT_location DW_OP_fbreg -12
< 2><0x0000004e> DW_TAG_formal_parameter
DW_AT_name "y"
DW_AT_decl_file 0x00000001 /home/khaled/Repo_current/trunk/test.c
DW_AT_decl_line 0x00000001
DW_AT_type <0x0000005b>
DW_AT_location DW_OP_fbreg -16
通过查看DW_AT_location条目,可以得出它们是相对于框架基址的某些偏移量。这意味着它们是内存参数,但实际的调用约定 "fastcall" 强制将它们传递到寄存器中。通过查看生成的目标文件的反汇编代码,我可以看到它们从寄存器复制到函数入口处的堆栈位置。有没有办法从dwarf dump --或使用任何其他方法-- 知道参数最初在调用时传递到哪里?
谢谢。