Author Topic: Segfault in Codeblocks  (Read 4811 times)

Offline NeilK

  • Single posting newcomer
  • *
  • Posts: 4
Segfault in Codeblocks
« on: October 10, 2016, 04:47:29 am »
Hi,
I am developing a robotic application using OpenCV.  I have two downloads from OpenCV which will compile and run in the ubuntu mate terminal on my raspberry pi 2.4 computer.  They also build and run in Codeblocks.  However when I run the debugger in Codeblocks, I get a message saying program received a SIGSEGV segmentation fault.  The call stack has two addresses quoting file /lib/ldlinux-armhf.so.3.  Attached is the debugger log.
Can anyone help please?  Have been trawling the internet for several days now without success.  Have re-installed Codeblocks a couple of times (version 13.12).  My next option is to dump Codeblocks and try Eclipse.
Thanks & Regards
NeilK

Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: /home/eleanor/calib/CameraCalibration/
Adding source dir: /home/eleanor/calib/
Adding file: /home/eleanor/calib/CameraCalibration/bin/Debug/TestIO
Changing directory to: /home/eleanor/calib/CameraCalibration/.
Set variable: LD_LIBRARY_PATH=.:/usr/lib:/usr/libarm-linux-gnueabihf:/home/eleanor/OpenCV/lib:

[debug]Command-line: /usr/bin/gdb -nx -fullname  -quiet  -args /home/eleanor/calib/CameraCalibration/bin/Debug/TestIO
[debug]Working dir : /home/eleanor/calib/CameraCalibration

Starting debugger: /usr/bin/gdb -nx -fullname  -quiet  -args /home/eleanor/calib/CameraCalibration/bin/Debug/TestIO
done

[debug]> set prompt >>>>>>cb_gdb:
[debug]Skip initializing the scripting!

Setting breakpoints

[debug]Queued:[tty /dev/pts/1]
[debug]Reading symbols from /home/eleanor/calib/CameraCalibration/bin/Debug/TestIO...done.
[debug](gdb) >>>>>>cb_gdb:
[debug]> show version
[debug]GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1
[debug]Copyright (C) 2016 Free Software Foundation, Inc.
[debug]License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
[debug]This is free software: you are free to change and redistribute it.
[debug]There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
[debug]and "show warranty" for details.
[debug]This GDB was configured as "arm-linux-gnueabihf".
[debug]Type "show configuration" for configuration details.
[debug]For bug reporting instructions, please see:
[debug]<http://www.gnu.org/software/gdb/bugs/>.
[debug]Find the GDB manual and other documentation resources online at:
[debug]<http://www.gnu.org/software/gdb/documentation/>.
[debug]For help, type "help".
[debug]Type "apropos word" to search for commands related to "word".
[debug]>>>>>>cb_gdb:
[debug]> set confirm off

Debugger name and version: GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1

[debug]>>>>>>cb_gdb:
[debug]> set width 0
[debug]>>>>>>cb_gdb:
[debug]> set height 0
[debug]>>>>>>cb_gdb:
[debug]> set breakpoint pending on
[debug]>>>>>>cb_gdb:
[debug]> set print asm-demangle on
[debug]>>>>>>cb_gdb:
[debug]> set unwindonsignal on
[debug]>>>>>>cb_gdb:
[debug]> set print elements 0
[debug]>>>>>>cb_gdb:
[debug]> set disassembly-flavor intel
[debug]No symbol "disassembly" in current context.
[debug]>>>>>>cb_gdb:
[debug]> directory /home/eleanor/calib/CameraCalibration/
[debug]Source directories searched: /home/eleanor/calib/CameraCalibration:$cdir:$cwd
[debug]>>>>>>cb_gdb:
[debug]> directory /home/eleanor/calib/
[debug]Source directories searched: /home/eleanor/calib:/home/eleanor/calib/CameraCalibration:$cdir:$cwd
[debug]>>>>>>cb_gdb:
[debug]> set args Neilout444
[debug]>>>>>>cb_gdb:
[debug]> break "/home/eleanor/calib/file_input_output.cpp:67"
[debug]Breakpoint 1 at 0x11c2a: file /home/eleanor/calib/file_input_output.cpp, line 67.
[debug]>>>>>>cb_gdb:
[debug]> tty /dev/pts/1
[debug]>>>>>>cb_gdb:
[debug]> run
[debug]Starting program: /home/eleanor/calib/CameraCalibration/bin/Debug/TestIO Neilout444
[debug]Program received signal SIGSEGV, Segmentation fault.
[debug]0x76fd9822 in ?? () from /lib/ld-linux-armhf.so.3
[debug]>>>>>>cb_gdb:

Program received signal SIGSEGV, Segmentation fault.
In ?? () (/lib/ld-linux-armhf.so.3)

[debug]> info locals
[debug]No symbol table info available.
[debug]>>>>>>cb_gdb:
[debug]> info args
[debug]No symbol table info available.
[debug]>>>>>>cb_gdb:
[debug]> bt 30
[debug]#0  0x76fd9822 in ?? () from /lib/ld-linux-armhf.so.3
[debug]#1  0x76fd983a in ?? () from /lib/ld-linux-armhf.so.3
[debug]Backtrace stopped: previous frame identical to this frame (corrupt stack?)
[debug]>>>>>>cb_gdb:
 

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Segfault in Codeblocks
« Reply #1 on: October 10, 2016, 09:33:01 am »
This tells you that the dynamic linker has crashed for some reason.
Are you sure that the opencv lib you're using is correct for the raspberry pi?
Have you tried to put a breakpoint in the beginning of main? Does the debugger stops on it?
What is the output if you run the same executable in a terminal? (don't forget to adjust LD_LIBRARY_PATH).
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline NeilK

  • Single posting newcomer
  • *
  • Posts: 4
Re: Segfault in Codeblocks
« Reply #2 on: October 11, 2016, 04:31:13 am »
Dear Obfuscator,
Thanks for your reply.  The program runs fine in the terminal and in Codeblocks (without adjusting any library paths).  It is only when I try to use the the debugger that I get the error.  Doesn't this indicate that the problem is in the Codeblocks debugger, not the program itself.
I have put a breakpoint at the first statement after main, but the debugger doesn't get to it
If I have an incorrect version of OpenCV, why would the program run in the Ubuntu terminal.

Here is the output when I run the Codeblocks executable file 'TestIO' from the Ubuntu terminal.  It creates the output file 'Neil102' correctly. 

eleanor@eleanor-desktop:~/calib/CameraCalibration/bin/Debug$ ./TestIO Neil102
Hi there Neil

Write Done.

Reading:
100image1.jpg
Awesomeness
baboon.jpg
Two  2; One  1


R = [1, 0, 0;
  0, 1, 0;
  0, 0, 1]
T = [0;
  0;
  0]

MyData =
{ id = mydata1234, X = 3.14159, A = 97}

Attempt to read NonExisting (should initialize the data structure with its default).
NonExisting =
{ id = , X = 0, A = 0}

Tip: Open up Neil102 with a text editor to see the serialized data.
eleanor@eleanor-desktop:~/calib/CameraCalibration/bin/Debug$

Also, No problem with I run the 'TestIO' file in Codeblocks.

If I put a break point at the first statement after main ie at cout<<"Hi there Neil"<<endl<<endl;
then the output in the Codeblocks terminal window is "warning: GDB: Failed to set controlling terminal: Operation not permitted" and then a rectangular box on the next line.

Yours in confusion still,
NeilK

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Segfault in Codeblocks
« Reply #3 on: October 12, 2016, 01:54:20 am »
No it doesn't indicate it yet, lets do some more checks:
1. What happens if you export LD_LIBRARY_PATH=.:/usr/lib:/usr/libarm-linux-gnueabihf:/home/eleanor/OpenCV/lib: in a terminal and run the executable?
2. What is the output of ldd before and after the change to LD_LIBRARY_PATH?
3. Is your binary built for ARM architecture or is it x86/x86_64?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline NeilK

  • Single posting newcomer
  • *
  • Posts: 4
Re: Segfault in Codeblocks
« Reply #4 on: October 12, 2016, 06:24:30 am »
Dear Obfuscator,
I really appreciate your time on this.
I've run the export LD... command in my Ubuntu Mate terminal and run file_input_output.exe.  This behaves perfectly as before.  I've run the ldd command and put the output in the attached text file.  Unfortunately I didn't read your reply properly before I did this so I don't have an ldd output from before the export LD... command.  Can I unexport and rerun my executable and send you the ldd output.

Not sure about your binary question.  Is the binary your refer to the .o file created by Codeblocks and put in the .../obj/Debug folder?  Is the ARM/x86 build something I should be specifying in Codeblocks.  I haven't done anything specific in my setup for this so does Codeblocks default to one of these.  The last four flags in Compiler settings in Project build options relate to AMD....(x86-64 instruction set)... These are all unchecked.

Yours in hope (that you can fix this for me)

Thanks again & Regards

Neil K

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Segfault in Codeblocks
« Reply #5 on: October 12, 2016, 08:52:45 am »
Can I unexport and rerun my executable and send you the ldd output.
Yes, use the unset command.

The last four flags in Compiler settings in Project build options relate to AMD....(x86-64 instruction set)... These are all unchecked.
From this explanation it seems that you're using the default GNU GCC compiler. This compiler is meant to be used on Intel x86/x86_64 processors, not arms, and the flags are made for Intel processors. So you should not be using any of these. Can you post the full rebuild log?

The next step in debugging this is to start gdb from the command line.
Inspect the log of the debugger in C::B and repeat the commands in the command line and test if it crashes in a similar fashion. Then start removing commands and tell me which command is causing the problem.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline NeilK

  • Single posting newcomer
  • *
  • Posts: 4
Re: Segfault in Codeblocks
« Reply #6 on: October 18, 2016, 07:31:02 am »
Dear Obfuscator,
It appears this is a known problem for GDB and Ubuntu Mate.  See https://bugs.launchpad.net/gdb/+bug/1576432.  My son-in-law has now rebuilt my Raspberry with LXTerminal 0.2.0 and I am able to debug OpenCV C++ programs in CodeBlocks.  I look forward to a fruitful relationship with CodeBlocks.
Thanks again for all your help
NeilK