Question

Test platform is on 32 bit Linux.

Here is my code:

#include <stdio.h>
#include "calc_mean.h"

extern double  mean(double, double);
extern int aaaa;
static int b;
static int c = 999999999;
static double d;
static float e = 2.0;
static double f = 2.0;

int main(int argc, char* argv[]) {

    double v1, v2, m;
    v1 = 5.2;
    v2 = 7.9;


    aaaa = 100;
    b = 123;
    c = 321;
    d = 13.3;
    e = 122.2;
    e = 123123.123;
    f = 11231233.0;
    f = 111233.0;
    f = 1133.0;
    f = 11231231231233.0;
    e = 33.4;

    printf("%d\n", aaaa);
    printf("asdfjkhadsfkjhadskfjh\n");
    printf("adsjfhaskdjfhakjdshfkajhdsfkjahdfkjh%d\n", aaaa);

    m  = mean(v1, v2);

    printf("The mean of %3.2f and %3.2f is %3.2f\n", v1, v2, m);

    return 0;
}

I use objdump to dump the .data section's content, and here are the info I got.

objdump -s -j .data test

dump info

test:     file format elf32-i386

Contents of section .data:
804a018 00000000 00000000 ffc99a3b 00000040  ...........;...@
804a028 00000000 00000040                    .......@

Then another method:

objdump -D test > dump

here is the .data section in dump

Disassembly of section .data:

0804a018 <__data_start>:
  804a018:       00 00                   add    %al,(%eax)
    ...

0804a01c <__dso_handle>:
  804a01c:       00 00                   add    %al,(%eax)
    ...

0804a020 <c>:
  804a020:       ff c9                   dec    %ecx
  804a022:       9a 3b 00 00 00 40 00    lcall  $0x40,$0x3b

0804a024 <e>:
 804a024:       00 00                   add    %al,(%eax)
 804a026:       00 40 00                add    %al,0x0(%eax)

0804a028 <f>:
  804a028:       00 00                   add    %al,(%eax)
  804a02a:       00 00                   add    %al,(%eax)
  804a02c:       00 00                   add    %al,(%eax)
  804a02e:       00                      .byte 0x0
  804a02f:       40                      inc    %eax

So what I am trying to do is obtaining the variable info(like variable name, length, value) from the dump(and probably with disassembly) info I present

But currently I don't know how to obtain the type info from the dump file, and I think without the type information, I can hardly know the length as well as value of each variable...

Could anyone give me some help?

THank you!

Was it helpful?

Solution

Variable information such as variable name, address, size etc. is usually compiled as DWARF information in the executable. It will only be available when you compile your code with -g flag. Look for section names starting with .dwarf when using objdump or similar tools.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top