使用glib时,未知位置warning的处理

本文介绍如何通过调整G_DEBUG环境变量,利用glib的assert机制提高程序调试效率,特别是在面对非致命性错误时,通过设置G_DEBUG为fatal-warnings或fatal-criticals,使程序在遇到特定警告或错误时中断,便于使用如gdb等调试工具定位问题根源。

开发基于glib的程序时,经常会出现类似如下的log:

** (process:6437): CRITICAL **: xxxxxxxxx: assertion '( func != NULL ) && ( xxx != NULL ) && ( count > 0 )' failed

这时因为某些非致命性的assert失败,从而输出的log,但程序往往仍在运行,该log提供的信息有时又非常有限,无法定位出问题位置。

glib中提供了G_DEBUG这个环境变量,可以通过设置这个环境变量使得该类warning会导致程序trap,使得如gdb一类的调试器能够捕获到程序中断的位置,来加速问题解决。

G_DEBUG的使用如下:

This environment variable can be set to a list of debug options, which cause GLib to print out different types of debugging information.
fatal-warnings        Causes GLib to abort the program at the first call to g_warning() or g_critical().
fatal-criticals          Causes GLib to abort the program at the first call to g_critical().
gc-friendly             Newly allocated memory that isn't directly initialized, as well as memory being freed will be reset to 0. The point here is to allow memory checkers and similar programs that use Boehm GC alike algorithms to produce more accurate results.
resident-modules   All modules loaded by GModule will be made resident. This can be useful for tracking memory leaks in modules which are later unloaded; but it can also hide bugs where code is accessed after the module would have normally been unloaded.
bind-now-modules All modules loaded by GModule will bind their symbols at load time, even when the code uses %G_MODULE_BIND_LAZY.

例如,以如下方式运行程序:

G_DEBUG=fatal-warnings gdb ./a.out

修改后,报错: ERROR: qtwayland-native-5.15.3+gitAUTOINC+f9dfeb6e72-r0 do_configure: Error calling /DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/build-qti-distro-rb-debug/tmp-glibc/work/x86_64-linux/qtwayland-native/5.15.3+gitAUTOINC+f9dfeb6e72-r0/recipe-sysroot-native/usr/bin/qmake -makefile -o Makefile QT_BUILD_PARTS-=examples QT_BUILD_PARTS-=tests -no-feature-wayland-vulkan-server-buffer /DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/build-qti-distro-rb-debug/tmp-glibc/work/x86_64-linux/qtwayland-native/5.15.3+gitAUTOINC+f9dfeb6e72-r0/git/src/qtwaylandscanner -- -no-feature-wayland-brcm -no-feature-wayland-client -no-feature-wayland-drm-egl-server-buffer -no-feature-wayland-egl -no-feature-wayland-libhybris-egl-server-buffer -no-feature-wayland-server -no-feature-wayland-vulkan-server-buffer -no-feature-xcomposite-egl -no-feature-xcomposite-glx ERROR: qtwayland-native-5.15.3+gitAUTOINC+f9dfeb6e72-r0 do_configure: ExecutionError('/DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/build-qti-distro-rb-debug/tmp-glibc/work/x86_64-linux/qtwayland-native/5.15.3+gitAUTOINC+f9dfeb6e72-r0/temp/run.do_configure.102733', 1, None, None) ERROR: Logfile of failure stored in: /DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/build-qti-distro-rb-debug/tmp-glibc/work/x86_64-linux/qtwayland-native/5.15.3+gitAUTOINC+f9dfeb6e72-r0/temp/log.do_configure.102733 Log data follows: | DEBUG: Executing python function extend_recipe_sysroot | NOTE: Direct dependencies are ['/DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/poky/meta-joynext/meta-qt5/recipes-qt/qt5/qtbase-native_git.bb:do_populate_sysroot', '/DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/poky/meta/recipes-devtools/quilt/quilt-native_0.67.bb:do_populate_sysroot', 'virtual:native:/DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/poky/meta-joynext/meta-qt5/recipes-qt/qt5/qtdeclarative_git.bb:do_populate_sysroot', 'virtual:native:/DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/poky/meta/recipes-devtools/pkgconfig/pkgconfig_git.bb:do_populate_sysroot', 'virtual:native:/DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/poky/meta/recipes-graphics/wayland/wayland_1.20.0.bb:do_populate_sysroot'] | NOTE: Installed into sysroot: [] | NOTE: Skipping as already exists in sysroot: ['qtbase-native', 'quilt-native', 'qtdeclarative-native', 'pkgconfig-native', 'wayland-native', 'zlib-native', 'dbus-native', 'expat-native', 'libffi-native', 'python3-native', 'libxml2-native', 'xz-native', 'libtool-native', 'glib-2.0-native', 'gettext-minimal-native', 'cmake-native', 'texinfo-dummy-native', 'readline-native', 'ncurses-native', 'openssl-native', 'libtirpc-native', 'sqlite3-native', 'gdbm-native', 'util-linux-libuuid-native', 'bzip2-native', 'libnsl2-native', 'libpcre-native', 'gettext-native', 'util-linux-native', 'zstd-native', 'curl-native', 'perl-native', 'libpcre2-native', 'libcap-ng-native', 'make-native'] | DEBUG: Python function extend_recipe_sysroot finished | DEBUG: Executing shell function qmake5_base_preconfigure | DEBUG: Shell function qmake5_base_preconfigure finished | DEBUG: Executing shell function do_configure | NOTE: qmake using profiles: '/DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/build-qti-distro-rb-debug/tmp-glibc/work/x86_64-linux/qtwayland-native/5.15.3+gitAUTOINC+f9dfeb6e72-r0/git/src/qtwaylandscanner' | NOTE: qmake prevar substitution: ' QT_BUILD_PARTS-=examples QT_BUILD_PARTS-=tests -no-feature-wayland-vulkan-server-buffer' | NOTE: qmake configure substitution: ' -no-feature-wayland-brcm -no-feature-wayland-client -no-feature-wayland-drm-egl-server-buffer -no-feature-wayland-egl -no-feature-wayland-libhybris-egl-server-buffer -no-feature-wayland-server -no-feature-wayland-vulkan-server-buffer -no-feature-xcomposite-egl -no-feature-xcomposite-glx' | Usage: /DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/build-qti-distro-rb-debug/tmp-glibc/work/x86_64-linux/qtwayland-native/5.15.3+gitAUTOINC+f9dfeb6e72-r0/recipe-sysroot-native/usr/bin/qmake [mode] [options] [files] | | QMake has two modes, one mode for generating project files based on | some heuristics, and the other for generating makefiles. Normally you | shouldn't need to specify a mode, as makefile generation is the default | mode for qmake, but you may use this to test qmake on an existing project | | Mode: | -project Put qmake into project file generation mode | In this mode qmake interprets [files] as files to | be added to the .pro file. By default, all files with | known source extensions are added. | Note: The created .pro file probably will | need to be edited. For example add the QT variable to | specify what modules are required. | -makefile Put qmake into makefile generation mode (default) | In this mode qmake interprets files as project files to | be processed, if skipped qmake will try to find a project | file in your current working directory | | Warnings Options: | -Wnone Turn off all warnings; specific ones may be re-enabled by | later -W options | -Wall Turn on all warnings | -Wparser Turn on parser warnings | -Wlogic Turn on logic warnings (on by default) | -Wdeprecated Turn on deprecation warnings (on by default) | | Options: | * You can place any variable assignment in options and it will be * | * processed as if it was in [files]. These assignments will be * | * processed before [files] by default. * | -o file Write output to file | -d Increase debug level | -t templ Overrides TEMPLATE as templ | -tp prefix Overrides TEMPLATE so that prefix is prefixed into the value | -help This help | -v Version information | -early All subsequent variable assignments will be | parsed right before default_pre.prf | -before All subsequent variable assignments will be | parsed right before [files] (the default) | -after All subsequent variable assignments will be | parsed after [files] | -late All subsequent variable assignments will be | parsed right after default_post.prf | -norecursive Don't do a recursive search | -recursive Do a recursive search | -set <prop> <value> Set persistent property | -unset <prop> Unset persistent property | -query <prop> Query persistent property. Show all if <prop> is empty. | -qtconf file Use file instead of looking for qt.conf | -cache file Use file as cache [makefile mode only] | -spec spec Use spec as QMAKESPEC [makefile mode only] | -nocache Don't use a cache file [makefile mode only] | -nodepend Don't generate dependencies [makefile mode only] | -nomoc Don't generate moc targets [makefile mode only] | -nopwd Don't look for files in pwd [project mode only] | ***Unknown option -no-feature-wayland-vulkan-server-buffer | ERROR: Error calling /DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/build-qti-distro-rb-debug/tmp-glibc/work/x86_64-linux/qtwayland-native/5.15.3+gitAUTOINC+f9dfeb6e72-r0/recipe-sysroot-native/usr/bin/qmake -makefile -o Makefile QT_BUILD_PARTS-=examples QT_BUILD_PARTS-=tests -no-feature-wayland-vulkan-server-buffer /DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/build-qti-distro-rb-debug/tmp-glibc/work/x86_64-linux/qtwayland-native/5.15.3+gitAUTOINC+f9dfeb6e72-r0/git/src/qtwaylandscanner -- -no-feature-wayland-brcm -no-feature-wayland-client -no-feature-wayland-drm-egl-server-buffer -no-feature-wayland-egl -no-feature-wayland-libhybris-egl-server-buffer -no-feature-wayland-server -no-feature-wayland-vulkan-server-buffer -no-feature-xcomposite-egl -no-feature-xcomposite-glx | WARNING: /DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/build-qti-distro-rb-debug/tmp-glibc/work/x86_64-linux/qtwayland-native/5.15.3+gitAUTOINC+f9dfeb6e72-r0/temp/run.do_configure.102733:212 exit 1 from 'exit 1' | WARNING: Backtrace (BB generated script): | #1: bbfatal_log, /DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/build-qti-distro-rb-debug/tmp-glibc/work/x86_64-linux/qtwayland-native/5.15.3+gitAUTOINC+f9dfeb6e72-r0/temp/run.do_configure.102733, line 212 | #2: die, /DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/build-qti-distro-rb-debug/tmp-glibc/work/x86_64-linux/qtwayland-native/5.15.3+gitAUTOINC+f9dfeb6e72-r0/temp/run.do_configure.102733, line 202 | #3: qmake5_base_do_configure, /DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/build-qti-distro-rb-debug/tmp-glibc/work/x86_64-linux/qtwayland-native/5.15.3+gitAUTOINC+f9dfeb6e72-r0/temp/run.do_configure.102733, line 188 | #4: do_configure, /DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/build-qti-distro-rb-debug/tmp-glibc/work/x86_64-linux/qtwayland-native/5.15.3+gitAUTOINC+f9dfeb6e72-r0/temp/run.do_configure.102733, line 156 | #5: main, /DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/build-qti-distro-rb-debug/tmp-glibc/work/x86_64-linux/qtwayland-native/5.15.3+gitAUTOINC+f9dfeb6e72-r0/temp/run.do_configure.102733, line 216 ERROR: Task (virtual:native:/DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/poky/meta-joynext/meta-qt5/recipes-qt/qt5/qtwayland_git.bb:do_configure) failed with exit code '1' WARNING: Recipe inherits features_check but doesn't use it
最新发布
08-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值