Tomasso
Tomasso

Reputation: 711

gdb: Can't list shared library source/symbols

My C++ application code is in directory A and my shared library source in directory B. I am building with g++. I specify the ‘-g -O0’ flags for each compilation step, and do not specify ‘-s’. I start gdb from the application directory A, and can list application source in directory A. When I try to list a C++ source file in the shared library:

(gdb) list MBQuickItem.cpp:0 No source file named MBQuickItem.cpp.

I then add the relative path to directory B to the source search path:

(gdb) dir ../Bi/ Source directories searched: /home/oreilly/A/../Bi:$cdir:$cwd

gdb does path completion when I’m typing ‘B’, so gdb clearly “knows” about this directory. Yet still it can’t find the source file:

(gdb) list MBQuickItem.cpp:0 No source file named MBQuickItem.cpp. (gdb) list ../B/MBQuickItem.cpp:0 No source file named ../B/MBQuickItem.cpp.

MBQuickItem.cpp definitely exists in directory B. What am I doing wrong?

(Directory names are not actually 'A' and 'B' - just simplifying things...)

I'm building with g++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0 I'm running GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0.20180409-git on ubuntu 18.04.3.

Here are the commands (partial listing) used to build the shared library:

g++ -c -g -pipe -O0 -std=gnu++11 -Wall -Wextra -D_REENTRANT -fPIC -DMBGUI_LIBRARY -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QMLMODELS_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I. -I../../../../Qt/5.14.2/gcc_64/include -I../../../../Qt/5.14.2/gcc_64/include/QtQuick -I../../../../Qt/5.14.2/gcc_64/include/QtGui -I../../../../Qt/5.14.2/gcc_64/include/QtQmlModels -I../../../../Qt/5.14.2/gcc_64/include/QtQml -I../../../../Qt/5.14.2/gcc_64/include/QtNetwork -I../../../../Qt/5.14.2/gcc_64/include/QtCore -I. -isystem /usr/include/libdrm -I../../../../Qt/5.14.2/gcc_64/mkspecs/linux-g++ -o MBQuickItem.o MBQuickItem.cpp

[...] g++ -g -Wl,-O1 -Wl,-rpath,/home/oreilly/Qt/5.14.2/gcc_64/lib -shared -Wl,-soname,libMBGui.so.1 -o libMBGui.so.1.0.0 Camera.o GmtGridSurface.o MBGui.o MBQuickItem.o MBQuickView.o Surface.o SurfaceRenderer.o moc_Camera.o moc_MBQuickItem.o moc_MBQuickView.o moc_SurfaceRenderer.o /home/oreilly/Qt/5.14.2/gcc_64/lib/libQt5Quick.so /home/oreilly/Qt/5.14.2/gcc_64/lib/libQt5Gui.so /home/oreilly/Qt/5.14.2/gcc_64/lib/libQt5QmlModels.so /home/oreilly/Qt/5.14.2/gcc_64/lib/libQt5Qml.so /home/oreilly/Qt/5.14.2/gcc_64/lib/libQt5Network.so /home/oreilly/Qt/5.14.2/gcc_64/lib/libQt5Core.so -lGL -lpthread ln -s libMBGui.so.1.0.0 libMBGui.so ln -s libMBGui.so.1.0.0 libMBGui.so.1 ln -s libMBGui.so.1.0.0 libMBGui.so.1.0

And here's the command linking the application code with the shared library:

g++ -g -Wl,-O0 -Wl,-rpath,/home/oreilly/Qt/5.14.2/gcc_64/lib -Wl,-rpath-link,/home/oreilly/Qt/5.14.2/gcc_64/lib -o mbgrdviz-3 main.o qrc_qml.o -L../MBGui -lMBGui -lgmt /home/oreilly/Qt/5.14.2/gcc_64/lib/libQt53DQuickExtras.so /home/oreilly/Qt/5.14.2/gcc_64/lib/libQt53DQuick.so /home/oreilly/Qt/5.14.2/gcc_64/lib/libQt5Quick.so /home/oreilly/Qt/5.14.2/gcc_64/lib/libQt53DExtras.so /home/oreilly/Qt/5.14.2/gcc_64/lib/libQt53DRender.so /home/oreilly/Qt/5.14.2/gcc_64/lib/libQt53DInput.so /home/oreilly/Qt/5.14.2/gcc_64/lib/libQt53DLogic.so /home/oreilly/Qt/5.14.2/gcc_64/lib/libQt53DCore.so /home/oreilly/Qt/5.14.2/gcc_64/lib/libQt5Gamepad.so /home/oreilly/Qt/5.14.2/gcc_64/lib/libQt5Gui.so /home/oreilly/Qt/5.14.2/gcc_64/lib/libQt5QmlModels.so /home/oreilly/Qt/5.14.2/gcc_64/lib/libQt5Qml.so /home/oreilly/Qt/5.14.2/gcc_64/lib/libQt5Network.so /home/oreilly/Qt/5.14.2/gcc_64/lib/libQt5Core.so -lGL -lpthread

Thanks!

Upvotes: 0

Views: 340

Answers (1)

Tomasso
Tomasso

Reputation: 711

Per darcamo's comment, issuing 'start' rather than 'run' loads the shared library symbols and stops at the very first instruction, at which point you can issue 'continue'.

Upvotes: 0

Related Questions