title: Getting calling conventions from DWARF info
body: <p>I am trying to get information about calling conventions from DWARF info. More specific, I want to get which registers / stack locations are used to pass arguments to functions. My problem is that I am getting somehow wrong information in some cases from DWARF dump. The example I am using is the following "C code":</p>
  
  <pre><code>int __attribute__ ((fastcall)) __attribute__ ((noinline)) mult (int x, int y) {
  return x*y;
  }
  </code></pre>
  
  <p>I compile this example using the following command:</p>
  
  <pre><code>gcc -c -g -m32 test.c -o test.o
  </code></pre>
  
  <p>Now when I use the following command to get the dwarf dump:</p>
  
  <pre><code>dwarfdump test.o
  </code></pre>
  
  <p>I am getting the following information about this function:</p>
  
  <pre><code>&lt; 2&gt;&lt;0x00000042&gt;      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                  &lt;0x0000005b&gt;
                          DW_AT_location              DW_OP_fbreg -12
  &lt; 2&gt;&lt;0x0000004e&gt;      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                  &lt;0x0000005b&gt;
                          DW_AT_location              DW_OP_fbreg -16
  </code></pre>
  
  <p>Looking at the DW_AT_location entries, it is some offset from the frame base. This implies they are memory arguments, but the actual calling convention "fastcall" forces passing them into registers. By looking at the disassembly of the produced object file, I can see they are copied from registers to stack locations at the entry point of the function. Is there a way to know from the dwarf dump --or using any other way-- where the arguments are passed at the call initially?</p>
  
  <p>Thanks, </p>