调试:coredump和linux下gdb单步调试、传递配置文件路径信息
来源:互联网 发布:打开淘宝音乐就暂停 编辑:程序博客网 时间:2024/06/05 16:27
GDB + coredump调试
开启coredump:ulimit -c unlimited
ulimit -a 显示当前用户的各种限制。
ulimit -n 的数值表示每个进程可以打开的文件数目。
GDB调试
在某个文件设断点:
http://blog.csdn.net/yeyuangen/article/details/6825542
GDB 概述
————
GDB GNU UNIX VC BCB IDE UNIX GDB VC BCB “ ”
GDB
1
2
3
4
GDB GDB
一个调试示例
——————
tst.c
1 #include <stdio.h>
2
3 int func(int n)
4 {
5 int sum=0,i;
6 for(i=0; i<n; i++)
7 {
8 sum+=i;
9 }
10 return sum;
11 }
12
13
14 main()
15 {
16 int i;
17 long result = 0;
18 for(i=1; i<=100; i++)
19 {
20 result += i;
21 }
22
23 printf("result[1-100] = %d \n", result );
24 printf("result[1-250] = %d \n", func(250) );
25 }
Linux
hchen/test> cc -g tst.c -o tst
GDB
hchen/test> gdb tst <---------- GDB
GNU gdb 5.1.1
Copyright 2002 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-suse-linux"...
(gdb) l <-------------------- l list
1 #include <stdio.h>
2
3 int func(int n)
4 {
5 int sum=0,i;
6 for(i=0; i<n; i++)
7 {
8 sum+=i;
9 }
10 return sum;
(gdb) <--------------------
11 }
12
13
14 main()
15 {
16 int i;
17 long result = 0;
18 for(i=1; i<=100; i++)
19 {
20 result += i;
(gdb) break 16 <-------------------- 16
Breakpoint 1 at 0x8048496: file tst.c, line 16.
(gdb) break func <-------------------- func()
Breakpoint 2 at 0x8048456: file tst.c, line 5.
(gdb) info break <--------------------
Num Type Disp Enb Address What
1 breakpoint keep y 0x08048496 in main at tst.c:16
2 breakpoint keep y 0x08048456 in func at tst.c:5
(gdb) r <--------------------- run
Starting program: /home/hchen/test/tst
Breakpoint 1, main () at tst.c:17 <----------
17 long result = 0;
(gdb) n <--------------------- next
18 for(i=1; i<=100; i++)
(gdb) n
20 result += i;
(gdb) n
18 for(i=1; i<=100; i++)
(gdb) n
20 result += i;
(gdb) c <--------------------- continue
Continuing.
result[1-100] = 5050 <----------
Breakpoint 2, func (n=250) at tst.c:5
5 int sum=0,i;
(gdb) n
6 for(i=1; i<=n; i++)
(gdb) p i <--------------------- i print
$1 = 134513808
(gdb) n
8 sum+=i;
(gdb) n
6 for(i=1; i<=n; i++)
(gdb) p sum
$2 = 1
(gdb) n
8 sum+=i;
(gdb) p i
$3 = 2
(gdb) n
6 for(i=1; i<=n; i++)
(gdb) p sum
$4 = 3
(gdb) bt <---------------------
#0 func (n=250) at tst.c:5
#1 0x080484e4 in main () at tst.c:24
#2 0x400409ed in __libc_start_main () from /lib/libc.so.6
(gdb) finish <---------------------
Run till exit from #0 func (n=250) at tst.c:5
0x080484e4 in main () at tst.c:24
24 printf("result[1-250] = %d \n", func(250) );
Value returned is $6 = 31375
(gdb) c <---------------------
Continuing.
result[1-250] = 31375 <----------
Program exited with code 027. <--------
(gdb) q <--------------------- gdb
hchen/test>
gdb
GDB传递配置文件路径信息
tracker@TS232:~/testdir$ gdb /opt/taisan/Taskgen/current/bin/search_engine_url_status_task_creator
(gdb) run -r /opt/taisan/Taskgen/current
tracker@TS232:~/testdir$ gdb /opt/taisan/Taskgen/current/bin/search_engine_url_status_task_creator
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
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 "i486-linux-gnu"...
(gdb) run -r /opt/taisan/Taskgen/current
Starting program: /home/tracker/taisan_test/app/Taskgen/taisan_taskgen_v2.10.0.0_chenmz_test_b201204171027/bin/search_engine_url_status_task_creator -r /opt/taisan/Taskgen/current
[Thread debugging using libthread_db enabled]
[New Thread 0xb71546c0 (LWP 5113)]
[New Thread 0xb7153b90 (LWP 5116)]
[New Thread 0xb6952b90 (LWP 5117)]
[New Thread 0xb6151b90 (LWP 5118)]
[Thread 0xb6952b90 (LWP 5117) exited]
[New Thread 0xb5944b90 (LWP 5119)]
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb5944b90 (LWP 5119)]
0x08051795 in search_engine_url_status_task_creator_worker::wrap_run_loop (arg=0x925b608)
at search_engine_url_status_task_creator_worker.cpp:70
70search_engine_url_status_task_creator_worker.cpp: No such file or directory.
in search_engine_url_status_task_creator_worker.cpp
(gdb) tracker@TS232:~/testdir$ gdb /opt/taisan/Taskgen/current/bin/search_engine_url_status_task_creator
- 调试:coredump和linux下gdb单步调试、传递配置文件路径信息
- linux下gdb单步调试
- linux下gdb单步调试
- linux下gdb单步调试
- linux下gdb单步调试
- linux下gdb单步调试
- linux下gdb单步调试
- linux下gdb单步调试
- linux下gdb单步调试
- linux下gdb单步调试
- linux下gdb单步调试
- linux下gdb单步调试
- linux下gdb单步调试
- linux下gdb单步调试 .
- linux下gdb单步调试
- linux下gdb单步调试
- linux下GDB单步调试
- linux下gdb单步调试
- 【整理】Dword、LPSTR、LPWSTR、LPCSTR、LPCWSTR、LPTSTR、LPCTSTR
- Unity界面插件NGUI基础教程—转自V大(02)
- perl基础:perl中@_,和1,$2,...及其类似变量的含义
- Android通过AIDL实现下载进程通信
- 高级CSS选择器
- 调试:coredump和linux下gdb单步调试、传递配置文件路径信息
- 公钥和私钥
- 命令行运行cmake
- Perl 中的正则表达式
- 123
- Hadoop的那些事儿
- 黑马程序员_Asp.net页面使用showModalDialog时Postback弹出新页面解决办法
- GCC编译优化指南
- redis安装