Use GDB to debug
What is GDB?
GDB, the GNU Project debugger, allows you to see what is going on `inside' another program while it executes -- or what another program was doing at the moment it crashed.
https://sourceware.org/gdb/onlinedocs/gdb/index.html
Off-line Debug
When you got segmentation fault, you can use gdb to load the core dump file to debug what happened.
But Linux default did not enable core dump file, you will need to enable it by the following command.
Beware, ulimit command will set the core dump file size to unlimited, and it will be only enabled in the current shell.ulimit -c unlimited
sudo sysctl -w kernel.core_pattern=/tmp/core-%e.%p.%h.%t
g++ -g -std=c++11 -o myprogram myprogram.cpp `pkg-config opencv --cflags --libs`
Ex: /tmp/core-myprogram.17521.evan-desktop.1565936379
Use gdb to load the binary (with symbol) and core dump filegdb myprogram /tmp/coredump
$ gdb ./opencv_gstreamer_csi_camera /tmp/core-opencv_gstreame.12124.evan-desktop.1565941066
GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git
Copyright (C) 2018 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 "aarch64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://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 ./opencv_gstreamer_csi_camera...done.
warning: core file may not match specified executable file.
[New LWP 12124]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/aarch64-linux-gnu/libthread_db.so.1".
Core was generated by `./opencv_gstreamer_csi_camera myfile'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 strlen () at ../sysdeps/aarch64/strlen.S:94
94 ../sysdeps/aarch64/strlen.S: No such file or directory.
(gdb)
(gdb) bt
#0 0x0000007f9fb86450 in strlen () at ../sysdeps/aarch64/strlen.S:94
#1 0x0000007f9fdabdc4 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(char const*) ()
at /usr/lib/aarch64-linux-gnu/libstdc++.so.6
#2 0x0000005576eff184 in main(int, char**) (argc=2, argv=0x7fd85bcf98)
at opencv_gstreamer_csi_camera.cpp:80
(gdb) f 2
#2 0x0000005576eff184 in main (argc=2, argv=0x7fd85bcf98)
at opencv_gstreamer_csi_camera.cpp:80
80 filename = argv[++i];
(gdb) p i
$1 = 2
(gdb) p filename
$2 = "/media/evan/USB/CLIP2564_1900_100_50_64.AVI"
(gdb) t
[Current thread is 1 (Thread 0x7f99493010 (LWP 12124))]
(gdb) t 1
[Switching to thread 1 (Thread 0x7f99493010 (LWP 12124))]
#2 0x0000005576eff184 in main (argc=2, argv=0x7fd85bcf98)
at opencv_gstreamer_csi_camera.cpp:80
80 filename = argv[++i];
On-Line debug
Please refer to this page.
Reference
https://www.gnu.org/software/gdb/
網誌管理員已經移除這則留言。
回覆刪除