linux下段错误调试,linux 下使用 gdb 调试段错误

错误代码#include 

#include 

#include 

int main(int argc, char argv[])

{

for (int i = 0; i 

{

printf("%s\n", argv[i]);

}

return 0;

}

编译运行结果如下[zhoumengkang@localhost unix]$ gcc test.c -std=c99

[zhoumengkang@localhost unix]$ ./a.out

段错误 (core dumped)

学习ddb的调试使用[zhoumengkang@localhost unix]$ gcc -g test.c -std=c99

[zhoumengkang@localhost unix]$ gdb a.out

GNU gdb (GDB) Red Hat Enterprise Linux (7.2-60.el6_4.1)

Copyright (C) 2010 Free Software Foundation, Inc.

License GPLv3+: GNU GPL version 3 or later 

This is free software: you are free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law.  Type "show copying"

and "show warranty" for details.

This GDB was configured as "x86_64-redhat-linux-gnu".

For bug reporting instructions, please see:

...

Reading symbols from /media/psf/coding/unix/a.out...done.

(gdb) run

Starting program: /media/psf/coding/unix/a.out

Program received signal SIGSEGV, Segmentation fault.

0x0000003c9a04812c in vfprintf () from /lib64/libc.so.6

Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.132.el6.x86_64

(gdb) bt

#0  0x0000003c9a04812c in vfprintf () from /lib64/libc.so.6

#1  0x0000003c9a04f48a in printf () from /lib64/libc.so.6

#2  0x00000000004004ff in main (argc=1, argv=0x7fffffffe4b8 "\364\346\377\377\377\177") at test.c:9

(gdb) frame 2

#2  0x00000000004004ff in main (argc=1, argv=0x7fffffffe4b8 "\364\346\377\377\377\177") at test.c:9

9        printf("%s\n", argv[i]);

(gdb) break test.c:8

Breakpoint 1 at 0x4004dc: file test.c, line 8.

(gdb) run

The program being debugged has been started already.

Start it from the beginning? (y or n) y

Starting program: /media/psf/coding/unix/a.out

Breakpoint 1, main (argc=1, argv=0x7fffffffe4b8 "\364\346\377\377\377\177") at test.c:9

9        printf("%s\n", argv[i]);

(gdb) print argv[i]

$2 = -12 '\364'

(gdb) next

Program received signal SIGSEGV, Segmentation fault.

0x0000003c9a04812c in vfprintf () from /lib64/libc.so.6

(gdb)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值