GDB Debugger
Write a program that will cause uncaught exception and core dump
vi main.cpp
int main() {
int x = 1;
int y = 2;
int z = 1/0;
int s = x + y + z;
return s;
}
gcc -g -Wall -o a.out main.cpp
ulimit -c unlimited
./a.out
Floating point exception (core dumped)
ls
a.out core.22986 main.cpp
Using backtrace command "bt" and "list"
[ricky@pc009 gg]$ gdb a.out core.22986
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-80.el7
Copyright (C) 2013 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-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/ricky/gg/a.out...done.
[New LWP 22986]
Core was generated by `./a.out'.
Program terminated with signal 8, Arithmetic exception.
#0 0x000000000040050d in main () at main.cpp:4
4 int z = 1/0;
Missing separate debuginfos, use: debuginfo-install glibc-2.17-106.el7_2.8.x86_64
(gdb) bt
#0 0x000000000040050d in main () at main.cpp:4
(gdb) list
1 int main() {
2 int x = 1;
3 int y = 2;
4 int z = 1/0;
5 int s = x + y + z;
6 return s;
7 }
Real example
[quantprod@hkoffice083 esunny_proxy]$ gdb esunny_proxy core.29018
GNU gdb (GDB) Red Hat Enterprise
Linux 7.6.1-80.el7
Copyright (C) 2013 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-redhat-linux-gnu".
For bug reporting
instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /data/quantprod/esunny_proxy/esunny_proxy.20161117.082332.99f3fe3.multiplecontracts...done.
warning: core file may not match
specified executable file.
[New LWP 29048]
[New LWP 29037]
[New LWP 29018]
[New LWP 14421]
[New LWP 14432]
[New LWP 14433]
[New LWP 29235]
[New LWP 29047]
[New LWP 29021]
[Thread debugging using libthread_db enabled]
Using host libthread_db
library "/lib64/libthread_db.so.1".
Core was generated by `./esunny_proxy user_p'.
Program terminated with
signal 11, Segmentation fault.
#0 0x00007f03e241103f in pthread_timedjoin_np () from /lib64/libpthread.so.0
Missing separate
debuginfos, use: debuginfo-install glibc-2.17-106.el7_2.6.x86_64 libgcc-4.8.5-4.el7.x86_64 libstdc++-4.8.5-4.el7.x86_64 zlib-1.2.7-15.el7.x86_64
(gdb) bt
#0 0x00007f03e241103f in pthread_timedjoin_np () from /lib64/libpthread.so.0
#1 0x00007f03e1fd4c26 in CEsThread::Join(int) () from /lib/libForeignTradeApi.so
#2 0x00007f03e1ff643a in CTapTcpClient::~CTapTcpClient() () from /lib/libForeignTradeApi.so
#3 0x00007f03e1dc02d6 in CWorker::~CWorker (this=0xa60eb8, __in_chrg=<optimized out>) at ../Worker.cpp:134
#4 0x00007f03e1dbcc2e in DelEsunnyQuotClient
(client=0xa60eb0) at ../EsunnyQuotClient.cpp:16
#5 0x000000000046a37d in DestroyQuoteApi (client=client@entry=0xa60eb0) at /home/ricky/formax/XMAX/esunny.proxy/QuoteApi.h:32
#6 0x000000000047bde2 in operator() (this=<optimized out>, p=0xa60eb0) at /home/ricky/formax/XMAX/esunny.proxy/EsunnyProxy.h:148
#7 reset (__p=0xa60eb0, this=0xa450c0) at /usr/include/c++/4.8.2/bits/unique_ptr.h:262
#8 Esunny::EsunnyQuote::Restart (this=0xa45088) at /home/ricky/formax/XMAX/esunny.proxy/EsunnyProxy.h:95
#9 0x000000000047081a in
Esunny::RestarterThread::Run (this=0x7fff5c193050) at /home/ricky/formax/XMAX/esunny.proxy/EsunnyProxy.h:44
#10 0x00007f03e1b62220 in ?? () from /lib64/libstdc++.so.6
#11 0x00007f03e240fdc5 in start_thread
()
from /lib64/libpthread.so.0
#12 0x00007f03e12c9ced in clone () from /lib64/libc.so.6
Real Example 2:
[quantprod@hkoffice083 trycompile]$ gdb a.out core.9477
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-80.el7
Copyright (C) 2013 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-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /data/quantprod/ricky/trycompile/a.out...done.
[New LWP 9477]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Core was generated by `./a.out'.
Program terminated with signal 11, Segmentation fault.
#0 0x00007f453e91f03f in pthread_timedjoin_np () from /lib64/libpthread.so.0
Missing separate debuginfos, use: debuginfo-install glibc-2.17-106.el7_2.6.x86_64 libgcc-4.8.5-4.el7.x86_64 libstdc++-4.8.5-4.el7.x86_64 zlib-1.2.7-15.el7.x86_64
(gdb) bt
#0 0x00007f453e91f03f in pthread_timedjoin_np () from /lib64/libpthread.so.0
#1 0x00007f453f71ad06 in JoinWithTimeout (timeoutMillis=<optimized out>, this=0x152d380) at ../Basic/EsThread.cpp:152
#2 CEsThread::Join (this=<optimized out>, timeoutMillisec=<optimized out>) at ../Basic/EsThread.cpp:214
#3 0x00007f453f7214ca in CTapTcpClient::~CTapTcpClient (this=0x152d048, __in_chrg=<optimized out>) at ../socket/TcpClient.cpp:72
#4 0x00007f453f71f2d6 in CWorker::~CWorker (this=0x152d018, __in_chrg=<optimized out>) at ../Worker.cpp:134
#5 0x00007f453f71bc2e in DelEsunnyQuotClient (client=0x152d010) at ../EsunnyQuotClient.cpp:16
#6 0x0000000000400c87 in main (argc=1, argv=0x7ffcd6c1f8d8) at main.cpp:22
sudo yum install yum-utils
sudo debuginfo-install glibc-2.17-106.el7_2.6.x86_64 libgcc-4.8.5-4.el7.x86_64 libstdc++-4.8.5-4.el7.x86_64 zlib-1.2.7-15.el7.x86_64
[quantprod@hkoffice083 trycompile]$ gdb a.out core.10366
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-80.el7
Copyright (C) 2013 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-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /data/quantprod/ricky/trycompile/a.out...done.
[New LWP 10366]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Core was generated by `./a.out'.
Program terminated with signal 11, Segmentation fault.
#0 pthread_timedjoin_np (threadid=140579203938048, thread_return=0x0, abstime=0x7ffc65ad30d0) at pthread_timedjoin.c:43
43 if (INVALID_NOT_TERMINATED_TD_P (pd))
(gdb) bt
#0 pthread_timedjoin_np (threadid=140579203938048, thread_return=0x0, abstime=0x7ffc65ad30d0) at pthread_timedjoin.c:43
#1 0x00007fdb26f5bd06 in JoinWithTimeout (timeoutMillis=<optimized out>, this=0x1570380) at ../Basic/EsThread.cpp:152
#2 CEsThread::Join (this=<optimized out>, timeoutMillisec=<optimized out>) at ../Basic/EsThread.cpp:214
#3 0x00007fdb26f624ca in CTapTcpClient::~CTapTcpClient (this=0x1570048, __in_chrg=<optimized out>) at ../socket/TcpClient.cpp:72
#4 0x00007fdb26f602d6 in CWorker::~CWorker (this=0x1570018, __in_chrg=<optimized out>) at ../Worker.cpp:134
#5 0x00007fdb26f5cc2e in DelEsunnyQuotClient (client=0x1570010) at ../EsunnyQuotClient.cpp:16
#6 0x0000000000400c87 in main (argc=1, argv=0x7ffc65ad3298) at main.cpp:22
Visual Studio Community 2017 RC
Download VS 2017
Install only Linux development with C++
Create "Empty Project (Linux)"
Add > New Item
Code:
#include <iostream>
int main() {
int x = 1;
int y = 2;
int z = 1 / 0;
int s = x + y + z;
return 0;
}
Start "Remote GDB debugger"
Could not launch gdbserver Error
Could not launch gdbserver. gdbserver could either be missing on your system and needs to be instaled, or it failed to start the program.
Install gdb-gdbserver on CentOS 7.2
sudo yum install -y gdb-gdbserver
Visual Studio Debugger
It shows the debugging environment with "Exception Unhandled"
Remote Files
On CentOS 7, the directory "projects" is created by Visual Studio
[ricky@pc009 Project1]$ pwd && ls
/home/ricky/projects/Project1
bin obj Source.cpp