1

I am calling a shared library (QSP.so) from MATLAB. The library is written in C and using a mex gateway, the data are passed the shared library. It seems that there is some bug in my C code as I have following problems:

1) In MATLAB, when I call the gateway function, MATLAB freezes most of the time. 2) When I use GDB to debug the code, as described Here, and set a breakpoint at the entry function (QSP), GDB does not stop at the breakpoint and creates following error:

warning: Could not load shared library symbols for ./QSP.so.
Do you need "set solib-search-path" or "set sysroot"?

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb289db40 (LWP 4234)]
0xb72a7a0e in ?? () from /lib/i386-linux-gnu/libc.so.6

I am pretty sure there is nothing wrong with the gateway as when I do not call the shared library, everything is fine. Without any debugger, on the other hand, it would be too hard to find the problem. So, I would like to know how I can get GDB stop at the breakpoint.

Also, following is my Makefile:

CC = gcc
CFLAGS = -c -fpic -Wall -Werror -O3 -g

all: QSP.o ExtraRoutines.o
    $(CC) -shared -o QSP.so -g $^

QSP.o: QSP.c ExtraRoutines.c QSP.h 
    $(CC) $(CFLAGS) $^

ExtraRoutines.o: ExtraRoutines.c QSP.h
    $(CC) $(CFLAGS) $^

Moving:
    mv -f QSP.so ../

Clean:
    rm *.o

As can be seen, I use -g flag for both .o and .so files

Any help is appreciated and thanks in advance.

Pouya
  • 1,871
  • 3
  • 20
  • 25

3 Answers3

3

I think the answer is in the error message,

Do you need "set solib-search-path" or "set sysroot"?

Maybe stash an appropriate setting in your home .gdbinit to see if you can help gdb find the symbol table.

Brian Tiffin
  • 3,978
  • 1
  • 24
  • 34
  • Why does one need to tell gdb where the shared library is located? Gdb could simply look into the /proc/PID/maps file to find out -- assuming that it does not already catch the dlopen() call. –  Jul 06 '20 at 16:30
2

In case anybody else has this question, the answer is the same as given in this question.

You need a .gdbinit file that points to your shared library. I'm using Eclipse and I simply give the .gdbinit I made with that one line to "attach to Process" configuration for debugging the c++ program. Assuming the .gdbinit file is in the root of the eclipse project which has a Debug folder where the shared library is, the line would be

set solib-search-path ./Debug/
Alijoonami
  • 21
  • 3
0

As I can see, you are using relative path for QSP.so.

Try changing the directory to path where the QSP.so is.

For example QSP.so is in /home/user/project/QSP.so:

  1. cd /home/user/project/
  2. gdb <app>
Zlopez
  • 660
  • 1
  • 5
  • 11