The basic way to use GDB is not to mention it here.
command behavior for loading core files:
DGB EXE Core
For example
GdB./testall./core.2345
One of the most important commands is where, which is like WinDbg's command!analyze-v
I simulated a few crash cases, one by one said.
First: Delete two times the pointer causes the crash condition
SOURCE program
Char *a = new CHAR[2];
delete []a;
delete []a;
Run-time
GLIBC detected * * *./testall:double free or Corruption (fasttop): 0x09d7e008 * * *
======= BackTrace: =========
/LIB/LIBC.SO.6[0X1A6D35]
/lib/libc.so.6 (cfree+0x59) [0x1aad29]
/usr/lib/libstdc++.so.6 (_zdlpv+0x21) [0X683F5C1]
/usr/lib/libstdc++.so.6 (_ZDAPV+0X1D) [0x683f61d]
./testall[0x804a518]
./testall[0x804a242]
./testall[0x80493e4]
./testall[0x80495e0]
./testall (__gxx_personality_v0+0x19f) [0x804906b]
/lib/libc.so.6 (__LIBC_START_MAIN+0XDC) [0X152EBC]
./testall (__GXX_PERSONALITY_V0+0XB5) [0x8048f81]
======= Memory Map: ========
0013d000-00294000 R-xp 00000000 fd:00 12815259/lib/libc-2.5.so
00294000-00296000 r-xp 00157000 fd:00 12815259/lib/libc-2.5.so
00296000-00297000 rwxp 00159000 fd:00 12815259/lib/libc-2.5.so
00297000-0029a000 Rwxp 00297000 00:00 0
0089a000-008a5000 R-xp 00000000 fd:00 12815281/lib/libgcc_s-4.1.2-20080825.so.1
008a5000-008a6000 rwxp 0000a000 fd:00 12815281/lib/libgcc_s-4.1.2-20080825.so.1
00b52000-00b6d000 R-xp 00000000 fd:00 12815258/lib/ld-2.5.so
00b6d000-00b6e000 r-xp 0001a000 fd:00 12815258/lib/ld-2.5.so
00b6e000-00b6f000 rwxp 0001b000 fd:00 12815258/lib/ld-2.5.so
00b94000-00b95000 r-xp 00b94000 00:00 0 [VDSO]
00cd0000-00cf7000 R-xp 00000000 fd:00 12815266/lib/libm-2.5.so
00cf7000-00cf8000 r-xp 00026000 fd:00 12815266/lib/libm-2.5.so
00cf8000-00cf9000 rwxp 00027000 fd:00 12815266/lib/libm-2.5.so
00d17000-00d2d000 R-xp 00000000 fd:00 12815261/lib/libpthread-2.5.so
00d2d000-00d2e000 r-xp 00015000 fd:00 12815261/lib/libpthread-2.5.so
00d2e000-00d2f000 rwxp 00016000 fd:00 12815261/lib/libpthread-2.5.so
00d2f000-00d31000 Rwxp 00d2f000 00:00 0
0678c000-0686c000 R-xp 00000000 fd:00 12690777/usr/lib/libstdc++.so.6.0.8
0686c000-06870000 r-xp 000df000 fd:00 12690777/usr/lib/libstdc++.so.6.0.8
06870000-06871000 rwxp 000e3000 fd:00 12690777/usr/lib/libstdc++.so.6.0.8
06871000-06877000 Rwxp 06871000 00:00 0
08048000-0804e000 R-xp 00000000 fd:00 6127658/home/zhaha05/test/testall/testall
0804e000-0804f000 rw-p 00005000 fd:00 6127658/home/zhaha05/test/testall/testall
09d7e000-09d9f000 rw-p 09d7e000 00:00 0 [Heap]
b7f36000-b7f38000 rw-p b7f36000 00:00 0
b7f48000-b7f4b000 rw-p b7f48000 00:00 0
bf8da000-bf8ef000 rw-p bffe9000 00:00 0 [Stack]
Aborted (core dumped)
When GDB debugs the core file
GDB Testall core.8812
GNU gdb (gdb) Red Hat Enterprise Linux (7.0.1-45.EL5)
Copyright (C) Software Foundation, Inc.
License gplv3+: GNU GPL version 3 or later This was free software:you was 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 is configured as "I386-redhat-linux-gnu".
For bugs reporting instructions, please see:
Reading symbols From/home/zhaha05/test/testall/testall...done.
[New Thread 8812]
Warning:. Dynamic section for "/lib/libc.so.6" isn't at the expected address
Warning:difference appears to being caused by prelink, adjusting expectations
Reading symbols from/lib/libpthread.so.0 ... (No debugging symbols found) ... done.
[Thread debugging using libthread_db enabled]
Loaded symbols for/lib/libpthread.so.0
Reading symbols from/usr/lib/libstdc++.so.6 ... (No debugging symbols found) ... done.
Loaded symbols for/usr/lib/libstdc++.so.6
Reading symbols from/lib/libm.so.6 ... (No debugging symbols found) ... done.
Loaded symbols for/lib/libm.so.6
Reading symbols from/lib/libgcc_s.so.1 ... (No debugging symbols found) ... done.
Loaded symbols For/lib/libgcc_s.so.1
Reading symbols from/lib/libc.so.6 ... (No debugging symbols found) ... done.
Loaded symbols for/lib/libc.so.6
Reading symbols from/lib/ld-linux.so.2 ... (No debugging symbols found) ... done.
Loaded symbols for/lib/ld-linux.so.2
Core is generated by './testall '.
Program terminated with signal 6, aborted.
#0 0x00b94402 in __kernel_vsyscall ()
(GDB) where
#0 0x00b94402 in __kernel_vsyscall ()
#1 0x00165e30 in Raise () from/lib/libc.so.6
#2 0x00167741 in Abort () from/lib/libc.so.6
#3 0x0019e99b in __libc_message () from/lib/libc.so.6
#4 0x001a6d35 in _int_free () from/lib/libc.so.6
#5 0x001aad29 in free () from/lib/libc.so.6
#6 0x0683f5c1 in operator delete (void*) () from/usr/lib/libstdc++.so.6
#7 0x0683f61d in operator delete[] (void*) () from/usr/lib/libstdc++.so.6
#8 0x0804a518 in File_open_rha_test_c::testmethod (this=0x9d7e108, parser= ...)
At file.cpp:25
#9 0x0804a242 in Rha_test_case_c::run_command (command=0x9d7e2cc "FILE. OPEN ",
Parser= ...) At shell_test.h:194
#10 0x080493e4 in Shell_test_c::execute_command (
Cmd=0xbf8ecc94 "FILE. OPEN t.txt ") at shell_test.cpp:68
#11 0x080495e0 in Shell_test_c::go (this=0xbf8ed4cc, argc=1, argv=0xbf8ed574)
At shell_test.cpp:107
#12 0x0804906b in Main (Argc=1, argv=0xbf8ed574) at Main.cpp:7
(GDB)
Second: null pointer
SOURCE program
char *nullpointer = NULL;
strcpy (Nullpointer, "12334567890");
Run-time
Segmentation fault (core dumped)
When GdB debugs
Program terminated with signal one, segmentation fault.
#0 0x0804a48e in File_open_rha_test_c::testmethod (this=0x84e1108, parser= ...)
At file.cpp:23
strcpy (Nullpointer, "12334567890");
Third one: Buffer overflow
SOURCE program
Char overflow[1];
strcpy (Overflow, "1234567890");
Run-time
Segmentation fault
When GdB debugs
Program terminated with signal one, segmentation fault.
#0 0x0683a919 in __gnu_cxx::__exchange_and_add (int volatile*, int) ()
From/usr/lib/libstdc++.so.6
(GDB) where
#0 0x0683a919 in __gnu_cxx::__exchange_and_add (int volatile*, int) ()
From/usr/lib/libstdc++.so.6
#1 0x0681ed24 in Std::basic_string<char, Std::char_traits<char>, std::allocator<char> >::~basic_ String () () from/usr/lib/libstdc++.so.6
#2 0x0804a4d1 in File_open_rha_test_c::testmethod (this=0x8e7f108, parser= ...)
At file.cpp:24
#3 0x0804a1e2 in Rha_test_case_c::run_command (command=0x8e7f2cc "FILE. OPEN ",
Parser= ...) At shell_test.h:194
#4 0x08049384 in Shell_test_c::execute_command (
Cmd=0xbff0bd54 "FILE. OPEN t.txt ") at shell_test.cpp:68
#5 0x08049580 in Shell_test_c::go (this=0xbff0c58c, argc=1, argv=0xbff0c634)
At shell_test.cpp:107
#6 0x0804900b in Main (Argc=1, argv=0xbff0c634) at Main.cpp:7
Debugging a core dump file with GDB