LLVM Clang address sanitizer on Linux with Matlab - linux

I tried to use address sanitizer for debug Matlab Mex code. I need invoke Matlab and then run matlab scripts to call Mex function. I did below configuration.
export LD_PRELOAD=/llvm_lib_path/libclang_rt.asan-x86_64.so
export ASAN_OPTIONS=alloc_dealloc_mismatch=0:halt_on_error=false:verbosity=1
But when I invoke Matlab, it hang up soon and can not launch the GUI.
I did the similar thing in MacOs and work as expected.
With verbosity=1, i can saw the sanitizer stopped at
==30485==T27 TSDDtor
==30485==T27 exited
==30485==T28: stack [0x2b2b6d23e000,0x2b2b6d43cdc0) size 0x1fedc0; local=0x2b2b6d43ccd4
==30485==T28 TSDDtor
==30485==T28 exited
==30485==T29: stack [0x2b2b6d23e000,0x2b2b6d43cdc0) size 0x1fedc0; local=0x2b2b6d43ccd4
==30485==T29 TSDDtor
==30485==T29 exited
==30485==T30: stack [0x2b2b6d23e000,0x2b2b6d43cdc0) size 0x1fedc0; local=0x2b2b6d43ccd4
==30485==T30 TSDDtor
==30485==T30 exited
Any thoughts?

Related

"stack build" failed randomly

When I used stack build to build a package, it failed randomly during the process of installing dependent packages. Here is an example error message:
While building package statistics-0.13.3.0 using:
/home/work/.stack/setup-exe-cache/x86_64-linux/setup-Simple-Cabal-1.24.0.0-ghc-8.0.1 --builddir=.stack-work/dist/x86_64-linux/Cabal-1.24.0.0 build --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure (-11)
Logs have been written to: /home/work/server/dev/taiji/.stack-work/logs/statistics-0.13.3.0.log
I said "failed randomly" because this can be fixed by restart stack build. But it will fail on building another package later.
I looked at the dmesg | tail, it says:
[1029507.778048] ghc[16868]: segfault at 7d538d610628 ip 00007f5384094ed0 sp 00007ffceed0bda0 error 4 in libHSrts_thr-ghc8.0.1.so[7f538407a000+63000]
[1029524.911751] ghc[17599]: segfault at 100206005838 ip 00007f1c727de754 sp 00007ffdc160fd58 error 4 in libHSghc-8.0.1-ghc8.0.1.so[7f1c6e4de000+49c9000]
[1029533.035216] ghc[16789]: segfault at 7da273b664f0 ip 00007fa273b35a8e sp 00007ffe2f55d540 error 4 in libHSrts_thr-ghc8.0.1.so[7fa273b1c000+63000]
Any idea?
This turns out to be a memory defect issue.

How can I debug this User Space application crash?

I'm running a Qt5.4.0 application on my embedded Linux system (TI AM335x based) and it's stopping to run and I'm having a hard time debugging this. This is a QtWebKit QML example (youtubeview) but other QtWebKit examples are preforming the same for me so it's something WebKit based on my system.
When I run the application, it runs for a second or so, then ends with no messages. There is nothing reported to the syslog or dmesg either. When I kick it off with strace I can see this futex message:
futex(0x2d990, FUTEX_WAKE_PRIVATE, 1) = 0
futex(0x2d9ac, FUTEX_WAIT_PRIVATE, 7, NULL <unfinished ...>
+++ exited with 1 +++
Then it stops. Not very helpful... My next though was to debug this with GDB, however GDB crashes when I try to run this:
-sh-4.2# gdb youtubeview
GNU gdb (GDB) 7.5
Copyright (C) 2012 Free Software Foundation, Inc.
...
(gdb) run
Starting program: /usr/share/qt5/examples/webkitqml/youtubeview/youtubeview
/home/mike/ulf_qt_450/ulf/build-ulf/out/work/armv7ahf-vfp-neon-linux-gnueabihf/gdb/7.5-r0.0/gdb-7.5/gdb/utils.c:1081: internal-error: virtual memory exhausted: can't allocate 64652911 bytes.
A problem internal to GDB has been detected,
This issue occurs even if I set a break point at main first, just as soon as it starts running it will get stuck and run out of memory.
Are there other tools or techniques that can be used here to help isolate the issue?
Perhaps arguments to GDB to limit memory use or give some more information about why this Qt program made it crash?
Perhaps some FDs or system variables I could use to figure out why the FUTEX is being held and failing?
I'm not sure where to take this problem right now.
The Qt code itself is pretty simple, and I don't anticipate any issues in here:
#include <QGuiApplication>
#include <QQuickView>
int main(int argc, char* argv[])
{
QGuiApplication app(argc,argv);
QQuickView view;
view.setSource(QUrl("qrc:///" QWEBKIT_EXAMPLE_NAME ".qml"));
view.setResizeMode(QQuickView::SizeRootObjectToView);
view.show();
return app.exec();
return 0;
}
Running gdb on the device, especially with a huge library such as WebKit, is bound to get you out of memory errors.
Instead, run gdbserver on the device, and connect to it via gdb running on the host machine, using the toolchain's cross-gdb for that. In that scenario, the gdb on the host loads all the debug information, while the gdbserver on the device needs almost no memory.
It is even possible to have the separate debug information available on the host and stripped libraries on the device.
Please note that parts of WebKit are always built in release mode, even if the rest of Qt was built in debug mode, if you are going to debug into WebKit you might want to change that in the build system.
Here is a minimal example:
Device:
# gdbserver 192.168.1.2:12345 myapp
Process myapp created; pid = 989
Listening on port 12345
Host:
# arm-none-linux-gnueabi-gdb myapp
GNU gdb (Sourcery G++ Lite 2009q1-203) 6.8.50.20081022-cvs
(gdb) set solib-absolute-prefix /opt/targetroot
(gdb) target remote 192.168.1.42:12345
Remote debugging using 192.168.1.42:12345
(gdb) start
The "remote" target does not support "run". Try "help target" or "continue".
(gdb) break main
Breakpoint 1 at 0x1ab9c: file myapp/main.cpp, line 12.
(gdb) cont
Continuing.
Breakpoint 1, main (argc=1, argv=0xbecfedb4) at myapp/main.cpp:12
12 QApplication app(argc, argv, QApplication::GuiServer);
And you are right that it looks like a problem in QtWebKit itself, not in your application. Good luck!

Why process terminates abnormally without coredump?

I have stuck in a such problem that my c++ server program can't coredump when terminate abnormally. The program running in daemon mode with chdir to '/'.
I had done the following things:
ulimit -c unlimited, so coredump enabled.
echo "/tmp/coredump/core.%e.%p.%t" > /proc/sys/kernel/core_pattern, and chmod a+w coredump, so it has the permission to write coredump file.
and I had try such things:
send a SIGABRT via kill -6, it can coredump.
in dmesg, I can't find any info about the abnormally terminates process.
running the program not in daemon mode.
My OS version: CentOS release 6.4 (Final), x86_64
ps. the server program installed a signal handler (sigaction() with flag SA_RESETHAND) to catch such signals {SIGHUP, SIGINT, SIGQUIT, SIGTERM} for normally terminates(free resources). so it can exclude the signal shielding.

VLC wrapper in monodevelop

I'm programming c# in monodevelop for ubuntu program. When the program is started, it gets run time error. The error message from GDB is here:
Native stacktrace:
/usr/bin/mono() [0x80e6431]
/usr/bin/mono() [0x8062b70]
[0xb77b940c]
/lib/i386-linux-gnu/libc.so.6(_IO_file_underflow+0x68) [0xb76cb9c8]
/lib/i386-linux-gnu/libc.so.6(_IO_default_uflow+0x19) [0xb7612449]
/lib/i386-linux-gnu/libc.so.6(__uflow+0x90) [0xb7612260]
/lib/i386-linux-gnu/libc.so.6(getc+0xb2) [0xb7608772]
/usr/lib/i386-linux-gnu/liblua5.1.so.0(luaL_loadfile+0xdc) [0xb429fd8c]
/usr/lib/vlc/plugins/lua/liblua_plugin.so(+0xa055) [0xb42d8055]
/usr/lib/vlc/plugins/lua/liblua_plugin.so(+0xa220) [0xb42d8220]
/usr/lib/vlc/plugins/lua/liblua_plugin.so(+0xd689) [0xb42db689]
/usr/lib/vlc/plugins/lua/liblua_plugin.so(+0xa546) [0xb42d8546]
/usr/lib/libvlccore.so.5(+0x916a0) [0xb52706a0]
/usr/lib/libvlccore.so.5(vlc_module_load+0x573) [0xb5270de3]
/usr/lib/libvlccore.so.5(module_need+0x42) [0xb5271302]
/usr/lib/libvlccore.so.5(+0x27716) [0xb5206716]
/lib/i386-linux-gnu/libpthread.so.0(+0x6d4c) [0xb774fd4c]
/lib/i386-linux-gnu/libc.so.6(clone+0x5e) [0xb768ddde]
Debug info from gdb:
TagLib: MP4: No audio tracks
Unable to attach: program terminated with signal SIGSEGV, Segmentation fault.
Could anyone give a hand about this?
Than you very much

Debug error when debugging OpenGL program remotely

I can use gdb to debug my OpenGL program on the server locally. But when I Debug it remotely. some errors come out in glutCreateWindow() function. And I can run my program remotely. Just can't debug .
freeglut (/home/fshen/samuel/project_self/GLSL-learning/teapotshader/teapotshader):
ERROR: Internal error <FBConfig with necessary capabilities not found> in
function fgOpenWindow
X Error of failed request: BadWindow (invalid Window parameter)
Major opcode of failed request: 4 (X_DestroyWindow)
Resource id in failed request: 0x0
Serial number of failed request: 20
Current serial number in output stream: 23
PS:
First I can't run my program remotely. After setting export LIBGL_ALWAYS_INDIRECT=yes (I put this command in .bash_profile),I can run my project. Just can't debug it remotely. So I think i should add export LIBGL_ALWAYS_INDIRECT=yes into the GDB. But I don't know howto do it?

Resources