Point cloud library apps difficult to debug, possibly due to threading?

656 views Asked by At

I'm using the Point Cloud Library with cmake for compilation, and I've got it building in debug mode, but my program doesn't seg fault or abort in the way I'd expect it to.

Specifically, I get messages like this:

(gdb) run bunny
Starting program: debug/our_cvfh bunny
libc++abi.dylib: terminating
[New Thread 0x170b of process 80178]

Program received signal SIGABRT, Aborted.
0x00007fff88c6f866 in ?? ()
(gdb) bt
#0  0x00007fff88c6f866 in ?? ()
#1  0x00007fff8bb5235c in ?? ()
#2  0x0000000000000000 in ?? ()
(gdb) break rec/registered_views_source.h:305
Cannot access memory at address 0x961d60

In this case, I know where the error is, but I'd like to be able to backtrace it and see what called the function in this case.

Is PCL creating another thread, and that's why I can't backtrace? I'm not doing any visualizations right now, so I can't figure out why it'd be using threading.

I've also tried running the program in the debug directory instead of from my source root directory. Here's another example of it not working:

$ gdb our_cvfh
GNU gdb (GDB) 7.7
Copyright (C) 2014 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-apple-darwin13.1.0".
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 our_cvfh...done.
run (gdb) run
Starting program: /Users/jwoods/Projects/lidargl/fpfh/debug/our_cvfh
[New Thread 0x170b of process 33571]

Program received signal SIGSEGV, Segmentation fault.
0x000000010016cdec in ?? ()
(gdb) bt
#0  0x000000010016cdec in ?? ()
#1  0x00007fff5fbfbd08 in ?? ()
#2  0x00007fff5fbfbcc0 in ?? ()
#3  0x00007fff5fbfbcc8 in ?? ()
#4  0x00007fff5fbfbcc8 in ?? ()
#5  0x00007fff5fbfbcc8 in ?? ()
#6  0xffffffffffffffff in ?? ()
#7  0x00007fff5fbfbcc8 in ?? ()
#8  0x00007fff5fbfbcc8 in ?? ()
#9  0x00007fff5fbfbcc0 in ?? ()
#10 0x00007fff5fbfbcc0 in ?? ()
#11 0x00007fff5fbfbcc8 in ?? ()
#12 0x00007fff5fbfbcc8 in ?? ()
#13 0x00007fff5fbfbcc8 in ?? ()
#14 0x00007fff5fbff4a8 in ?? ()
#15 0x00007fff5fbff4d8 in ?? ()
#16 0x00007fff5fbff420 in ?? ()
#17 0x00007fff5fbff4d8 in ?? ()
#18 0x0000000000000000 in ?? ()
(gdb)

gdb works fine when I'm not using CMake, so my guess is it has something to do with CMake. This doesn't seem to present a problem for anyone else, which tells me it may also have to do with the fact that I'm using CMake with Mac OS X.

How do I get my normal GDB behavior?

Update

I can run dsymutil my_output_binary in order to generate the debugging symbols (following make). This is a workaround. I'd like it to be done automatically, and amn't sure why it's not. The dsymutil strategy works for most segfaults, but doesn't work for some cases of SIGABRT. Here is the output:

Calling compute <--- normal std::cerr output of my program, single-threaded
Assertion failed: (index >= 0 && index < size()), function operator[], file /usr/local/Cellar/eigen/3.2.1/include/eigen3/Eigen/src/Core/DenseCoeffsBase.h, line 378.
[New Thread 0x170b of process 64108]

Program received signal SIGABRT, Aborted.
0x00007fff84999866 in ?? ()
(gdb) bt
#0  0x00007fff84999866 in ?? ()
#1  0x00007fff862c335c in ?? ()
#2  0x0000000000000000 in ?? ()
(gdb) info threads
  Id   Target Id         Frame
  2    Thread 0x170b of process 64108 0x00007fff8499a662 in ?? ()
* 1    Thread 0x1503 of process 64108 0x00007fff84999866 in ?? ()
(gdb)

Note that my program is not itself multi-threaded, but it appears to be making use of a library which is creating threads — or at least that's what I gather from the gdb output.

I've tried disabling threading with Eigen, which is used by PCL.

Interestingly, lldb is able to generate the backtraces, but I'm curious as to why GDB can't.

1

There are 1 answers

0
Translunar On BEST ANSWER

Other than simply using LLDB in lieu of GDB, I haven't figured out how to debug threads.

However, I have figured out how to automatically produce debugging symbols! Hooray.

You need three files:

Put these in your project's cmake/Modules/ directory.

In CMakeLists.txt, you'll need the following lines after your project declaration:

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/")

if (APPLE) # this if statement is optional, but you definitely need the include()
  include(UseDebugSymbols)
endif (APPLE)

That will look in the appropriate location.

I should note that I made another change to my project simultaneously, which may also be useful to you. In my add_executable line, right after the name of the target, I added MACOSX_BUNDLE. This flag will cause it to be compiled as a .app instead of a regular binary. Here's an example from my project:

add_executable(pose MACOSX_BUNDLE pose.cpp rec/global_nn_recognizer_cvfh.cpp rec/global_nn_recognizer_cvfh.hpp rec/render_views_tesselated_sphere.cpp)