linux下汇编调试

 [wanghq@FundTrade ~]$ gcc -S hello.c         
[wanghq@FundTrade ~]$ gcc --gstabs -g  hello.s    
[wanghq@FundTrade ~]$ gdb a.out

 

 

GNU gdb Red Hat Linux (6.3.0.0-1.132.EL4rh)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/tls/libthread_db.so.1".

(gdb) l
1               .file   "hello.c"
2               .section        .rodata
3       .LC0:
4               .string "orld"
5       .LC1:
6               .string "%s/n"
7               .text
8       .globl main
9               .type   main, @function
10      main:
(gdb) b 11
Breakpoint 1 at 0x8048368: file hello.s, line 11.
(gdb) r
Starting program: /usr/wanghq/a.out

Breakpoint 1, main () at hello.s:11
11              pushl   %ebp
Current language:  auto; currently asm
(gdb) n
12              movl    %esp, %ebp
(gdb) p $ebp
$1 = (void *) 0xbffa7e58
(gdb) p $esp
$2 = (void *) 0xbffa7df8
(gdb) n
main () at hello.s:13
13              subl    $8, %esp
(gdb)
main () at hello.s:14
14              andl    $-16, %esp
(gdb)
15              movl    $0, %eax
(gdb)
16              addl    $15, %eax
(gdb)
17              addl    $15, %eax
(gdb)
18              shrl    $4, %eax
(gdb)
19              sall    $4, %eax
(gdb)
20              subl    %eax, %esp
(gdb) p $esp
$3 = (void *) 0xbffa7df0
(gdb) n
main () at hello.s:21
21              subl    $8, %esp
(gdb) p $esp
$4 = (void *) 0xbffa7de0
(gdb) n
main () at hello.s:22
22              pushl   $.LC0
(gdb) p $esp
$5 = (void *) 0xbffa7dd8
(gdb) n
main () at hello.s:23
23              pushl   $.LC1
(gdb) p $esp
$6 = (void *) 0xbffa7dd4
(gdb) l
18              shrl    $4, %eax
19              sall    $4, %eax
20              subl    %eax, %esp
21              subl    $8, %esp
22              pushl   $.LC0
23              pushl   $.LC1
24              call    printf
25              addl    $16, %esp
26              movl    $0, %eax
27              leave
(gdb) n
main () at hello.s:24
24              call    printf
(gdb) p $esp
$7 = (void *) 0xbffa7dd0
(gdb) n
orld
25              addl    $16, %esp
(gdb) p $esp
$8 = (void *) 0xbffa7dd0
(gdb) n
main () at hello.s:26
26              movl    $0, %eax
(gdb) p $esp
$9 = (void *) 0xbffa7de0
(gdb) n
27              leave
(gdb) p $esp
$10 = (void *) 0xbffa7de0

 

 

 

hello.c文件

 

#include <stdio.h>

int main()
{
    printf("%s/n", "orld");
    return 0;
}

 

hello.s文件

 

    .file   "hello.c"
    .section    .rodata
.LC0:
    .string "orld"
.LC1:
    .string "%s/n"
    .text
.globl main
    .type   main, @function
main:
    pushl   %ebp
    movl    %esp, %ebp
    subl    $8, %esp
    andl    $-16, %esp
    movl    $0, %eax
    addl    $15, %eax
    addl    $15, %eax
    shrl    $4, %eax
    sall    $4, %eax
    subl    %eax, %esp
    subl    $8, %esp
    pushl   $.LC0
    pushl   $.LC1
    call    printf
    addl    $16, %esp
    movl    $0, %eax
    leave
    ret
    .size   main, .-main
    .section    .note.GNU-stack,"",@progbits
    .ident  "GCC: (GNU) 3.4.6 20060404 (Red Hat 3.4.6-3)"

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值