您的位置:首页 > 运维架构 > Linux

如何用gdb进行汇编级的调试

2007-05-26 20:40 441 查看
我的方法是编译成汇编文件后(gcc -S) 然后用gas编译成.o 文件,再生成执行文件.

给你一个我的调试过程.

CODE:
[Copy to clipboard]

#include <stdio.h>

int main()
{
        printf("hello world/n");
        return 0;
}
gcc -S 019.c
生成019.s文件
as -o 019.o -gstabs 019.s
生成019.o文件
gcc -o 019 -Wall 019.o

gdb 019

[root@JETTER-WEB c]# gdb 019
GNU gdb Red Hat Linux (6.1post-1.20040607.62rh)
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   "019.c"
2               .section        .rodata
3       .LC0:
4               .string "hello world/n"
5               .text
6       .globl main
7               .type   main, @function
8       main:
9               pushl   %ebp
10              movl    %esp, %ebp
(gdb)
11              subl    $8, %esp
12              andl    $-16, %esp
13              movl    $0, %eax
14              addl    $15, %eax
15              addl    $15, %eax
16              shrl    $4, %eax
17              sall    $4, %eax
18              subl    %eax, %esp
19              subl    $12, %esp
20              pushl   $.LC0
(gdb)
21              call    printf
22              addl    $16, %esp
23              movl    $0, %eax
24              leave
25              ret
26              .size   main, .-main
27              .section        .note.GNU-stack,"",@progbits
28              .ident  "GCC: (GNU) 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)"
(gdb)

b 行号就可以了. 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息