- Ubuntu gdb 调试 过程
jin@ubuntu:~/jin/gdb$ gdb -v
GNU gdb (Ubuntu/Linaro 7.4-2012.02-0ubuntu2) 7.4-2012.02
Copyright (C) 2012 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 "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>.
jin@ubuntu:~/jin/gdb$ gdb -v
GNU gdb (Ubuntu/Linaro 7.4-2012.02-0ubuntu2) 7.4-2012.02
Copyright (C) 2012 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 "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>.
jin@ubuntu:~/jin/gdb$
jin@ubuntu:~/jin/gdb$
jin@ubuntu:~/jin/gdb$
jin@ubuntu:~/jin/gdb$ gdb a.out
GNU gdb (Ubuntu/Linaro 7.4-2012.02-0ubuntu2) 7.4-2012.02
Copyright (C) 2012 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 "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/jin/jin/gdb/a.out...(no debugging symbols found)...done.
(gdb) r
Starting program: /home/jin/jin/gdb/a.out
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
123
[New Thread 0x7ffff77fb700 (LWP 11897)]
Process_pid=[11894]
This is the main process.
This is the main process.
This is the main process.
This is a pthread. 0
This is a pthread. 1
This is a pthread. 2
This is a pthread. 3
This is a pthread. 4
This is a pthread. 5
^C
Program received signal SIGINT, Interrupt.
0x00007ffff7bc6148 in pthread_join () from /lib/x86_64-linux-gnu/libpthread.so.0
(gdb) i threads
Id Target Id Frame
2 Thread 0x7ffff77fb700 (LWP 11897) "a.out" 0x00007ffff78be06d in nanosleep () from /lib/x86_64-linux-gnu/libc.so.6
* 1 Thread 0x7ffff7fe6700 (LWP 11894) "a.out" 0x00007ffff7bc6148 in pthread_join () from /lib/x86_64-linux-gnu/libpthread.so.0
(gdb) bt
#0 0x00007ffff7bc6148 in pthread_join () from /lib/x86_64-linux-gnu/libpthread.so.0
#1 0x0000000000400832 in main ()
(gdb) c
Continuing.
This is a pthread. 6
This is a pthread. 7
This is a pthread. 8
This is a pthread. 9
This is a pthread. 10
This is a pthread. 11
This is a pthread. 12
This is a pthread. 13
^C
Program received signal SIGINT, Interrupt.
0x00007ffff7bc6148 in pthread_join () from /lib/x86_64-linux-gnu/libpthread.so.0
(gdb) q
A debugging session is active.
Inferior 1 [process 11894] will be killed.
Quit anyway? (y or n) y
jin@ubuntu:~/jin/gdb$
signal(SIGINT, sigroutine);
printf( "Process_pid=[%d]\n", getpid() );
void sigroutine(int unused)
{
printf("Catch a signal SIGINT \n");
//exit(1);
}
(gdb) r
Starting program: /home/jin/jin/gdb/a.out
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
123
[New Thread 0x7ffff77fb700 (LWP 12106)]
Process_pid=[12103]
This is a pthread. 0
This is the main process.
This is the main process.
This is the main process.
This is a pthread. 1
This is a pthread. 2
This is a pthread. 3
^C
Program received signal SIGINT, Interrupt.
0x00007ffff7bc6148 in pthread_join () from /lib/x86_64-linux-gnu/libpthread.so.0
(gdb) signal SIGINT
Continuing with signal SIGINT.
Catch a signal SIGINT
This is a pthread. 4
This is a pthread. 5
This is a pthread. 6
This is a pthread. 7
This is a pthread. 8
This is a pthread. 9
This is a pthread. 10
jin@ubuntu:~/jin/gdb$ cat /proc/sys/kernel/core_pattern
/home/jin/jin/gdb/%t-%e-%p-%c.core
jin@ubuntu:~/jin/gdb$
jin@ubuntu:~/jin/gdb$ ulimit -c
10240
jin@ubuntu:~/jin/gdb$ ./a.out
123
Process_pid=[12418]
This is the main process.
This is the main process.
This is the main process.
This is a pthread. 0
This is a pthread. 1
Segmentation fault (core dumped)
jin@ubuntu:~/jin/gdb$
jin@ubuntu:~/jin/gdb$ ls
1646235990-a.out-12412-10485760.core 1646236045-a.out-12418-10485760.core a.out test.cpp test.cpp~
jin@ubuntu:~/jin/gdb$ rm 164623*
jin@ubuntu:~/jin/gdb$ ./a.out
123
Process_pid=[12460]
This is the main process.
This is the main process.
This is the main process.
This is a pthread. 0
This is a pthread. 1
Segmentation fault (core dumped)
jin@ubuntu:~/jin/gdb$ cat 1646236077-a.out-12460-10485760.core
ELF>@@8�x @ `0`@�]P���$`��$��`�
�$p`�p&�$�`�`F�$@@���F�$ ���F�$PP�G�$���H�$���h�$ ��h�$0��h�$@@p��h�$ p����$00��Њ�$00Ѓ��$����$ ����� �����0�`�����PCORE
�0*0�0*0¶��0@�����0����m �$�������������$@3�����+���$�CORER$@���0*0�0*0a.out./a.out 0CORE!�����d@@8 �h�$ 0@
�
��yĶ���߶���Ķ��CORE�������������@LINUX�������������PCORE
�0*0�0*0R @`�F�$Њ�$�Њ�$��������Њ�$-�$3��
�$+
�$CORE���%%%%%%%%%%%%%%%%�@LINUX���%%%%%%%%%%%%%%%%�ELF>0@@x@8 @@@@@@��88@8@@@$
$
``8H @@`@`��TT@T@DDP�td� � @� @LLQ�tdR�td``��/lib64/ld-linux-x86-64.so.2GNUGNU���"o�@X�q�Ns^)
L%afmzZA 4 tlibpthread.so.0_Jv_RegisterClassespthread_createpthread_join__gmon_start__libc.so.6signalputsgetpidprintfsleep__libc_start_mainGLIBC_2.2.5P ui �ui �````` `(`08`
H����Z�UH���5J
�%L
@�%J
h������%B
h������%:
h������%2
h������%*
h������%"
h������%
h������%
h�p���1�I��^H��H���PTI��@H��@H�ǒ@��������H�H�y H��t��H�Ð������������UH��SH��=� uK�0`H�� H��(`H��H��H9�s$fDH��H�� ��(`H�� H9�r��s H�[]�fff.�H�=@ UH��t�H��]�8`��]Ð�UH��H�E�H�E��]�UH�������]�UH��H�� H�}��E��"�E��ƿ< @�������������E��}�/u����u���UH��H���}��S @�0�����UH��H�� H�E��j @����H�E���4@�H��������E��}�t
�o @������{@�����������ƿ� @�������E��� @������E��}�����u������������H�E��H���������Ð�������H�l$�L�d$�H�-� L�%� L�l$�L�t$�L�|$�H�\$�H��8L)�A��I��H��I�������H��t1@L��L��D��A��H��H9�u�H�\H�l$L�d$L�l$ L�t$(L�|$0H��8��Ð�������������UH��SH�H� H���t�`DH���H�H���u�H�[]Ð�H��O���H��This is a pthread. %d
Create pthread error!Process_pid=[%d]
This is the main process.;����d`����u������������������
����,,���TzRx
�$�����FJ
P �?;*3$"D����A�C
d����
F A�C
B����GA�C
R�����A�C
������A�C
$�h����Q��_@��
��������������������P
( @���o�@�@�@ �@
�
�$P_�$@�$!� ���op@���o���oX@@`�"��$�1j�$@�G�$p��$�.�$1�$
�$^C
jin@ubuntu:~/jin/gdb$
jin@ubuntu:~/jin/gdb$ ls
1646236077-a.out-12460-10485760.core a.out test.cpp test.cpp~
jin@ubuntu:~/jin/gdb$ gdb a.out 1646236077-a.out-12460-10485760.core
GNU gdb (Ubuntu/Linaro 7.4-2012.02-0ubuntu2) 7.4-2012.02
Copyright (C) 2012 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 "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/jin/jin/gdb/a.out...(no debugging symbols found)...done.
Illegal process-id: 1646236077-a.out-12460-10485760.core.
[New LWP 12460]
[New LWP 12461]
warning: Can't read pathname for load map: Input/output error.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `./a.out'.
Program terminated with signal 11, Segmentation fault.
#0 0x0000000000400724 in fun2() ()
(gdb) bt
#0 0x0000000000400724 in fun2() ()
#1 0x0000000000400732 in fun1() ()
#2 0x0000000000400830 in main ()
(gdb) i threads
Id Target Id Frame
2 Thread 0x7f24970af700 (LWP 12461) 0x00007f2497198f2d in write () from /lib/x86_64-linux-gnu/libc.so.6
* 1 Thread 0x7f249789b700 (LWP 12460) 0x0000000000400724 in fun2() ()
(gdb)
jin@ubuntu:~/jin/gdb$ ls 1646236077-a.out-12460-10485760.core -l
-rw------- 1 jin jin 8794112 Mar 2 07:47 1646236077-a.out-12460-10485760.core
jin@ubuntu:~/jin/gdb$
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <pthread.h>
int fun2()
{
printf("This is a fun2.\n");
char *prt = 0;
char *ptr = "test";
//free(ptr);
*prt = 0;
}
int fun1()
{
fun2();
}
void *thread(void *arg)
{
int i;
for (i = 0; i < 30000; i++)
{
printf("This is a pthread. %d\n", i);
sleep(1);
}
}
void sigroutine(int unused)
{
printf("Catch a signal SIGINT \n");
}
int main()
{
char *prt = 0;
printf("123\r\n");
///
pthread_t id;
int i, ret;
ret = pthread_create(&id, NULL, thread, NULL);
if (ret != 0)
{
printf("Create pthread error!\n");
exit (1);
}
signal(SIGINT, sigroutine);
printf("Process_pid=[%d]\n", getpid());
for (i = 0; i < 3; i++)
printf("This is the main process.\n");
pthread_join(id, NULL);
///
// while(1)
if (0)
{
sleep(1);
fun1();
//*prt =0;
}
}
int fun2()
{
printf("This is a fun2.\n");
char *prt = 0;
char *ptr = "test";
free(ptr);//14
*prt = 0;
}
g++ test.cpp -lpthread -g
Starting program: /home/jin/jin/gdb/a.out
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
123
[New Thread 0x7ffff77fb700 (LWP 12785)]
Process_pid=[12782]
This is the main process.
This is the main process.
This is the main process.
This is a pthread. 0
This is a fun2.
This is a pthread. 1
*** glibc detected *** /home/jin/jin/gdb/a.out: free(): invalid pointer: 0x00000000004009bc ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7da66)[0x7ffff7879a66]
/home/jin/jin/gdb/a.out[0x400792]
/home/jin/jin/gdb/a.out[0x4007a4]
/home/jin/jin/gdb/a.out[0x4008a2]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed)[0x7ffff781d7ed]
/home/jin/jin/gdb/a.out[0x4006a9]
======= Memory map: ========
00400000-00401000 r-xp 00000000 08:01 4200174 /home/jin/jin/gdb/a.out
00600000-00601000 r--p 00000000 08:01 4200174 /home/jin/jin/gdb/a.out
00601000-00602000 rw-p 00001000 08:01 4200174 /home/jin/jin/gdb/a.out
00602000-00623000 rw-p 00000000 00:00 0 [heap]
7ffff6dd3000-7ffff6de8000 r-xp 00000000 08:01 659004 /lib/x86_64-linux-gnu/libgcc_s.so.1
7ffff6de8000-7ffff6fe7000 ---p 00015000 08:01 659004 /lib/x86_64-linux-gnu/libgcc_s.so.1
7ffff6fe7000-7ffff6fe8000 r--p 00014000 08:01 659004 /lib/x86_64-linux-gnu/libgcc_s.so.1
7ffff6fe8000-7ffff6fe9000 rw-p 00015000 08:01 659004 /lib/x86_64-linux-gnu/libgcc_s.so.1
7ffff6ffa000-7ffff6ffb000 rw-p 00000000 00:00 0
7ffff6ffb000-7ffff6ffc000 ---p 00000000 00:00 0
7ffff6ffc000-7ffff77fc000 rw-p 00000000 00:00 0
7ffff77fc000-7ffff79b3000 r-xp 00000000 08:01 664893 /lib/x86_64-linux-gnu/libc-2.15.so
7ffff79b3000-7ffff7bb2000 ---p 001b7000 08:01 664893 /lib/x86_64-linux-gnu/libc-2.15.so
7ffff7bb2000-7ffff7bb6000 r--p 001b6000 08:01 664893 /lib/x86_64-linux-gnu/libc-2.15.so
7ffff7bb6000-7ffff7bb8000 rw-p 001ba000 08:01 664893 /lib/x86_64-linux-gnu/libc-2.15.so
7ffff7bb8000-7ffff7bbd000 rw-p 00000000 00:00 0
7ffff7bbd000-7ffff7bd5000 r-xp 00000000 08:01 664899 /lib/x86_64-linux-gnu/libpthread-2.15.so
7ffff7bd5000-7ffff7dd4000 ---p 00018000 08:01 664899 /lib/x86_64-linux-gnu/libpthread-2.15.so
7ffff7dd4000-7ffff7dd5000 r--p 00017000 08:01 664899 /lib/x86_64-linux-gnu/libpthread-2.15.so
7ffff7dd5000-7ffff7dd6000 rw-p 00018000 08:01 664899 /lib/x86_64-linux-gnu/libpthread-2.15.so
7ffff7dd6000-7ffff7dda000 rw-p 00000000 00:00 0
7ffff7dda000-7ffff7dfc000 r-xp 00000000 08:01 664901 /lib/x86_64-linux-gnu/ld-2.15.so
7ffff7fe5000-7ffff7fe8000 rw-p 00000000 00:00 0
7ffff7ff8000-7ffff7ffb000 rw-p 00000000 00:00 0
7ffff7ffb000-7ffff7ffc000 r-xp 00000000 00:00 0 [vdso]
7ffff7ffc000-7ffff7ffd000 r--p 00022000 08:01 664901 /lib/x86_64-linux-gnu/ld-2.15.so
7ffff7ffd000-7ffff7fff000 rw-p 00023000 08:01 664901 /lib/x86_64-linux-gnu/ld-2.15.so
7ffffffde000-7ffffffff000 rw-p 00000000 00:00 0 [stack]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
Program received signal SIGABRT, Aborted.
0x00007ffff7832035 in raise () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) where
#0 0x00007ffff7832035 in raise () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x00007ffff783579b in abort () from /lib/x86_64-linux-gnu/libc.so.6
#2 0x00007ffff786f22e in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#3 0x00007ffff7879a66 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#4 0x0000000000400792 in fun2 () at test.cpp:14
#5 0x00000000004007a4 in fun1 () at test.cpp:20
#6 0x00000000004008a2 in main () at test.cpp:62
(gdb) bt
#0 0x00007ffff7832035 in raise () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x00007ffff783579b in abort () from /lib/x86_64-linux-gnu/libc.so.6
#2 0x00007ffff786f22e in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#3 0x00007ffff7879a66 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#4 0x0000000000400792 in fun2 () at test.cpp:14
#5 0x00000000004007a4 in fun1 () at test.cpp:20
#6 0x00000000004008a2 in main () at test.cpp:62
(gdb) f 4
#4 0x0000000000400792 in fun2 () at test.cpp:14
14 free(ptr);
(gdb) disassemble
Dump of assembler code for function fun2():
0x0000000000400764 <+0>: push %rbp
0x0000000000400765 <+1>: mov %rsp,%rbp
0x0000000000400768 <+4>: sub $0x10,%rsp
0x000000000040076c <+8>: mov $0x4009ac,%edi
0x0000000000400771 <+13>: callq 0x400610 <puts@plt>
0x0000000000400776 <+18>: movq $0x0,-0x10(%rbp)
0x000000000040077e <+26>: movq $0x4009bc,-0x8(%rbp)
0x0000000000400786 <+34>: mov -0x8(%rbp),%rax
0x000000000040078a <+38>: mov %rax,%rdi
0x000000000040078d <+41>: callq 0x4005f0 <free@plt>
=> 0x0000000000400792 <+46>: mov -0x10(%rbp),%rax
0x0000000000400796 <+50>: movb $0x0,(%rax)
0x0000000000400799 <+53>: leaveq
0x000000000040079a <+54>: retq
End of assembler dump.
(gdb) backtrace
#0 0x00007ffff7832035 in raise () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x00007ffff783579b in abort () from /lib/x86_64-linux-gnu/libc.so.6
#2 0x00007ffff786f22e in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#3 0x00007ffff7879a66 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#4 0x0000000000400792 in fun2 () at test.cpp:14
#5 0x00000000004007a4 in fun1 () at test.cpp:20
#6 0x00000000004008a2 in main () at test.cpp:62
(gdb) frame 4
#4 0x0000000000400792 in fun2 () at test.cpp:14
14 free(ptr);
(gdb)
g++ test.cpp -lpthread
7ffff7ffd000-7ffff7fff000 rw-p 00023000 08:01 664901 /lib/x86_64-linux-gnu/ld-2.15.so
7ffffffde000-7ffffffff000 rw-p 00000000 00:00 0 [stack]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
Program received signal SIGABRT, Aborted.
0x00007ffff7832035 in raise () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) bt
#0 0x00007ffff7832035 in raise () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x00007ffff783579b in abort () from /lib/x86_64-linux-gnu/libc.so.6
#2 0x00007ffff786f22e in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#3 0x00007ffff7879a66 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#4 0x0000000000400792 in fun2() ()
#5 0x00000000004007a4 in fun1() ()
#6 0x00000000004008a2 in main ()
(gdb) f 4
#4 0x0000000000400792 in fun2() ()
(gdb)
int fun2()
{
printf("This is a fun2.\n");
char *prt = 0;
char *ptr = "test";
//free(ptr);
*prt = 0;//15
}
g++ test.cpp -lpthread -g
(gdb) bt
#0 0x000000000040073a in fun2 () at test.cpp:15
#1 0x0000000000400748 in fun1 () at test.cpp:20
#2 0x0000000000400846 in main () at test.cpp:62
(gdb) f 0
#0 0x000000000040073a in fun2 () at test.cpp:15
15 *prt = 0;
(gdb)
//
g++ test.cpp -lpthread -g1
g++ test.cpp -lpthread -g0
(gdb) f 0
#0 0x000000000040073a in fun2 ()
(gdb)
//
g++ test.cpp -lpthread -g2
(gdb) f 0
#0 0x000000000040073a in fun2 () at test.cpp:15
15 *prt = 0;
g++ test.cpp -lpthread -g1
$ gdb a.exe
GNU gdb (GDB) (Cygwin 10.2-1) 10.2
Copyright (C) 2021 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 "x86_64-pc-cygwin".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from a.exe...
(gdb) r
Starting program: /cygdrive/f/jin/gdb/a.exe
[New Thread 36004.0x5ccc]
[New Thread 36004.0x2d7c]
[New Thread 36004.0x8f5c]
123
[New Thread 36004.0x6644]
This is a pthread. 0
Process_pid=[982]
This is the main process.
This is the main process.
This is the main process.
This is a pthread. 1
This is a fun2.
Thread 1 "a" received signal SIGSEGV, Segmentation fault.
0x00000001004010ae in fun2 () at test.cpp:15
15 *prt = 0;
(gdb)
gdb调试coredump(使用篇)_瞌睡的洋葱的博客-优快云博客_gdb调试core文件