Search for locations in machine codes (gcc / objdump -d)

If you have a specific line of C code to examine at the output of the machine, how can you find it in the output of objdump. Here is an example

if (cond)
   foo;
   bar();

and I want to see if the bar was turned on as I would like. Or would you use an alternative tool instead of objdump?

+5
source share
4 answers

You can run objdump with an option -S(e.g., "objdump -Sd a.out"). It will display the source code mixed with the assembler code if the source files from which the code was compiled are available.

Alternatively, you can use the following method:

int main(void) {
    int a = 0;
    asm("#");
    return a;
}

becomes

       .file   "a.c"
        .text
.globl main
        .type   main, @function
main:
        leal    4(%esp), %ecx
        andl    $-16, %esp
        pushl   -4(%ecx)
        pushl   %ebp
        movl    %esp, %ebp
        pushl   %ecx
        subl    $16, %esp
        movl    $0, -8(%ebp)
#APP
# 3 "a.c" 1
        #
# 0 "" 2
#NO_APP
        movl    -8(%ebp), %eax
        addl    $16, %esp
        popl    %ecx
        popl    %ebp
        leal    -4(%ecx), %esp
        ret
        .size   main, .-main
        .ident  "GCC: (GNU) 4.3.2"
        .section        .note.GNU-stack,"",@progbits
+7
source

, . gcc -g gdb disass.

+2

gcc, -S . , , ( , ).

+1

.

i386

  55      push %ebp
  89 e5   mov %esp, %ebp
  ...
  c9      leave # optional
  c3      ret

amd64/x86_64 ( 48):

  55                    push   %rbp
  48 89 e5              mov    %rsp,%rbp
  ..
  c9                    leaveq # optional
  c3                    retq   

, , objdump -S bla.o gcc bla.c -g -fsave-temps -fverbose-asm . , .

In your case, you can see if there are local bars in the bar that need a place on the local stack. If the bar is embedded, the stack is configured (for example sub $0x8,%esp) is executed immediately after the main prolog, main can access this var. If not, it is prohibited.

0
source

All Articles