代码调试手段
添加打印
#define GST_ERROR(...) GST_CAT_LEVEL_LOG (GST_CAT_DEFAULT, GST_LEVEL_ERROR, NULL, __VA_ARGS__)
#define GST_WARNING(...) GST_CAT_LEVEL_LOG (GST_CAT_DEFAULT, GST_LEVEL_WARNING, NULL, __VA_ARGS__)
#define GST_INFO(...) GST_CAT_LEVEL_LOG (GST_CAT_DEFAULT, GST_LEVEL_INFO, NULL, __VA_ARGS__)
#define GST_DEBUG(...) GST_CAT_LEVEL_LOG (GST_CAT_DEFAULT, GST_LEVEL_DEBUG, NULL, __VA_ARGS__)
#define GST_LOG(...) GST_CAT_LEVEL_LOG (GST_CAT_DEFAULT, GST_LEVEL_LOG, NULL, __VA_ARGS__)
#define GST_FIXME(...) GST_CAT_LEVEL_LOG (GST_CAT_DEFAULT, GST_LEVEL_FIXME, NULL, __VA_ARGS__)
#define GST_TRACE(...) GST_CAT_LEVEL_LOG (GST_CAT_DEFAULT, GST_LEVEL_TRACE, NULL, __VA_ARGS__)
gdb
确保core文件大小限制解除
fuqiang@fuqiang-VivoBook:/usr/lib/x86_64-linux-gnu$ ulimit -a
real-time non-blocking time (microseconds, -R) unlimited
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
...
fuqiang@fuqiang-VivoBook:/usr/lib/x86_64-linux-gnu$ ulimit -c unlimited
fuqiang@fuqiang-VivoBook:/usr/lib/x86_64-linux-gnu$ ulimit -a
real-time non-blocking time (microseconds, -R) unlimited
core file size (blocks, -c) unlimited
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
...
确认core文件的位置
sudo service apport stop
cat /proc/sys/kernel/core_pattern
echo core > /proc/sys/kernel/core_pattern
制造崩溃
static void
gst_mydecoder_init (Gstmydecoder * filter)
{
GST_ERROR("gst_mydecoder_init");
char *str = NULL;
str[0] = 0;
filter->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
执行
fuqiang@fuqiang-VivoBook:~/workspace/gstreamer$ gst-launch-1.0 --gst-debug=3 videotestsrc ! mydecoder ! autovideosink
(gst-launch-1.0:911980): GStreamer-CRITICAL **: 18:18:11.516: gst_debug_log_valist: assertion 'category != NULL' failed
0:00:00.016936571 911980 0x558ab0cca100 ERROR mydecoder gstmydecoder.c:123:gst_mydecoder_class_init: gst_mydecoder_class_init
0:00:00.016957593 911980 0x558ab0cca100 ERROR mydecoder gstmydecoder.c:158:gst_mydecoder_init: gst_mydecoder_init
Caught SIGSEGV
Spinning. Please run 'gdb gst-launch-1.0 911980' to continue debugging, Ctrl-C to quit, or Ctrl-\ to dump core
执行CTRL-\后生成core dump文件
fuqiang@fuqiang-VivoBook:~/workspace/gstreamer$ ls -al
总用量 4380
drwxrwxr-x 13 fuqiang fuqiang 4096 7月 20 18:18 .
drwxrwxr-x 6 fuqiang fuqiang 4096 7月 19 14:58 ..
drwxrwxr-x 8 fuqiang fuqiang 4096 7月 18 08:57 ci
-rw------- 1 fuqiang fuqiang 4599808 7月 20 18:18 core.911980
drwxrwxr-x 5 fuqiang fuqiang 4096 7月 16 20:51 data
-rw-rw-r-- 1 fuqiang fuqiang 131 7月 18 08:57 .editorconfig
drwxrwxr-x 8 fuqiang fuqiang 4096 7月 20 16:44 .git
-rw-rw-r-- 1 fuqiang fuqiang 1064 7月 16 20:51 .gitignore
drwxrwxr-x 3 fuqiang fuqiang 4096 7月 16 20:51 .gitlab
...
gdb调试
fuqiang@fuqiang-VivoBook:~/workspace/gstreamer$ gdb gst-launch-1.0 core.911980
GNU gdb (Ubuntu 12.0.90-0ubuntu1) 12.0.90
Copyright (C) 2022 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".
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 gst-launch-1.0...
[New LWP 911980]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `gst-launch-1.0 --gst-debug=3 videotestsrc ! mydecoder ! autovideosink'.
Program terminated with signal SIGQUIT, Quit.
#0 0x00007fdda845b7fa in __GI___clock_nanosleep (clock_id=clock_id@entry=0, flags=flags@entry=0, req=0x7ffeed177940, rem=0x7ffeed177930)
at ../sysdeps/unix/sysv/linux/clock_nanosleep.c:78
78 ../sysdeps/unix/sysv/linux/clock_nanosleep.c: 没有那个文件或目录.
(gdb)
bt调出堆栈后可以查看问题所在
gst_mydecoder_init (filter=<optimized out>) at ../subprojects/gst-plugins-bad/gst/mydecoder/gstmydecoder.c:160