I'm debugging this app in Eclise CDT (which is using GDB), and I'm getting the following:
... etc. ...
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGINT, Interrupt.
2169 rtld.c: No such file or directory.
dl_main (phdr=<optimized out>, phnum=<optimized out>, user_entry=<optimized out>, auxv=<optimized out>) at rtld.c:2169
Temporary breakpoint 3, main (argc=3, argv=0x7fffffffd4a8) at /home/eyalroz/src/bbp-reader/src/main.cpp:104
... etc. ...
So, it looks like GDB was looking for the source file for glibc's rtld.c . I can download the sources, but - what do I do with them? Where do I put them?
(I'm using Kubuntu 16.04 Linux).
Here are some steps, they will work (theoretically) with any package:
Enable Sources for your package manager
I use Synaptic on XUbuntu, but you should be able to find equivalent for KUbuntu and your package manager, or edit the /etc/ files directly.
a. Open Synaptic
b. From Settings Menu -> Choose Repositories
c. Check the Source code check box.
d. Press close and reload source lists
Download source code for libc6-dev. In an empty directory, without sudo, run apt-get source libc6-dev. This will download tar file and apply all the patches for your platform. After this you should have a glibc-2.23/ (or similar) directory
In Eclipse CDT setup source lookup to map what the directory at build time of the C library was to where you have downloaded. To do this:
Step into the C Library function you want to debug (in my example I am using puts), you should end up with the source not found editor like this:
That editor shows you the build path. Press Locate File... button and browse for the specific source file where you downloaded it above. That should show you the source file.
Step 5 saved the path in the launch configuration for the containing directory. As glibc is large and contains multiple directories, you may want to apply this change to all directories. To do that:
Using the path displayed in Step 4, up until the glibc directory (/build/glibc-Qz8a69/glibc-2.23 in my example) add a path mapping globally in Eclipse CDT by:
Open Preferences -> C/C++ -> Debug -> Source Lookup Path
Press Add...
Choose Path Mapping, press OK and enter whatever name you want.
Press Add
Enter the path from step 7 in the Compilation Path and the corresponding directory on your machine in Local file system path. And press OK. It should now look like this:
Debug away.
Alternatively you can make the change just to an individual launch configuration.
Command Line GDB
You can do the same with GDB at the command line, after downloading source. Here is a trace:
$ gdb -q ./HelloSO
Reading symbols from ./HelloSO...done.
(gdb) b main
Breakpoint 1 at 0x40052a: file ../src/HelloSO.c, line 15.
(gdb) set substitute-path /build/glibc-Qz8a69/glibc-2.23 /tmp/x/glibc-2.23
(gdb) r
Starting program: /scratch/jacob/workspace/HelloSO/Debug/HelloSO
Breakpoint 1, main () at ../src/HelloSO.c:15
15 puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */
(gdb) s
_IO_puts (str=0x4005c4 "!!!Hello World!!!") at ioputs.c:33
33 {
(gdb) s
35 _IO_size_t len = strlen (str);
(gdb)
Related
I'm trying to debug a Raspberry Pi Pico project using openOCD + Picoprobe. I go through the steps that appear to be correct to do all this from my Linux PC (the Get started with Pico and C++ guide is for the Raspberry Pi, but there are tutorials online for PC), but when trying to set breakpoints in gdb, it appears to be looking at a different file.
My steps are the following:
In a console, navigate to the openOCD folder and run:
sudo src/openocd -s tcl/ -f tcl/interface/picoprobe.cfg -f tcl/target/rp2040.cfg
I get only info messages, no errors, until it waits for the gdb to connect
Info : starting gdb server for rp2040.core0 on 3333
Info : Listening on port 3333 for gdb connections
Then, in a different console, I navigate to what I want to debug, in this case the blink.c example. I stand inside the build folder with my .elf file and run
sudo gdb-multiarch blink.elf
(gdb) target extended-remote localhost:3333
(gdb) monitor reset init
(gdb) break 15
where 15 is a relevant debuggable line. But the thing is, the breakpoints are said to be set in a different file:
Breakpoint 1 at 0x20000178: file ../../../../../../libgcc/config/arm/lib1funcs.S, line 1461
and then on, all breakpoints are also set there. Here's an example trying to set 3 different breakpoints:
(gdb) b 15
Breakpoint 1 at 0x20000178: file ../../../../../../libgcc/config/arm/lib1funcs.S, line 1461.
(gdb) b 16
Note: breakpoint 1 also set at pc 0x20000178.
Breakpoint 2 at 0x20000178: file ../../../../../../libgcc/config/arm/lib1funcs.S, line 1461.
(gdb) b 17
Note: breakpoints 1 and 2 also set at pc 0x20000178.
Breakpoint 3 at 0x20000178: file ../../../../../../libgcc/config/arm/lib1funcs.S, line 1461.
So that. I am totally lost on what's happening here. Could anyone point me to why this is happening, or what that file does?
I see it's been a few months but I just ran into the same problem, here's what I've learned.
When you compile the C/C++ program that you're trying to debug, you need to compile it in debug mode, which tells the compiler to include debug symbols in the program. If compiling directly with gcc, you can use the -g flag. However, I'm assuming you're using CMake, in which case you can just add set(CMAKE_BUILD_TYPE Debug) to your CMakeLists.txt (found a few other options here as well)
Probably goes without saying, but after recompiling this way, you'll need to re-load your new program onto your target Pico by holding the bootsel button and plugging it into your machine directly (ie. not via your debugger Pico).
I also found that after doing this, setting breakpoints just to specific lines still didn't behave as expected, and I had to actually specify the name of the file as well, ex: break main.c:15
I'm performing post mortem debugging on a core file. The build was done such that the location of the source code is referenced as ../../../../../_vcs in the core. I placed the source code in /_vcs (that is, at root). However, I cannot get the set substitute-path gdb command to work. How is this supposed to be invoked?
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-114.el7
Copyright (C) 2013 Free Software Foundation, Inc.
...
Program terminated with signal 6, Aborted.
#0 0x00007f9f6fd37207 in raise () from /lib64/libc.so.6
(gdb) f 2
#2 0x000000000042c585 in SignalHandler (sig=11) at ../../../../../_vcs/trafficserver9/src/traffic_manager/traffic_manager.cc:935
935 ../../../../../_vcs/trafficserver9/src/traffic_manager/traffic_manager.cc: No such file or directory.
(gdb) set substitute-path ../../../../../ /
(gdb) l
930 ../../../../../_vcs/trafficserver9/src/traffic_manager/traffic_manager.cc: No such file or directory.
(gdb) set substitute-path ../../../../../_vcs /_vcs
(gdb) l
930 ../../../../../_vcs/trafficserver9/src/traffic_manager/traffic_manager.cc: No such file or directory.
(gdb) quit
-bash-4.2$ ls /_vcs/trafficserver9/src/traffic_manager/traffic_manager.cc
/_vcs/trafficserver9/src/traffic_manager/traffic_manager.cc
Note that I can list the file at the specified location after I manually substitute ../../../../../_vcs with /_vcs. What am I doing wrong? Do I have to escape parts of the path?
(As a side note, I can work around this problem via cd /. Then the indirect ../ references stop at / and I can access the directory. But it seems to me that set substitute-path should address this as well.)
Perhaps this isn't a workaround that works in all cases, but I happened to have a directory that was as deep in the source tree as the original binary was compiled in. (And if I didn't have such a directory, I could have made one.) So, I used the gdb command cd into a place that the compiled-in path ../../foo/bar/file.cpp would actually find the code.
At that point the gdb command list showed the source correctly.
Context: I have used RStudio on Ubuntu 18.04 to create an hello world R package with C++ code using Rcpp like described here in Rcpp Package Development:
Writing R extensions explains how I can start R with GDB attached for debugging via this shell command:
$ R -d gdb --vanilla
I want to use QtCreator instead of gdb to have debugging GUI, but this doesn't work (just opens a hex dump window and I cannot run R):
$ R -d qtcreator --vanilla
How can I use QtCreator for debugging?
Edit 1:
Attaching the QtCreator debugger to a running R session does not work:
If I start R, get the process ID in R via Sys.getpid() and choose
Debug > Start Debugging > Attach to running application I get an error:
Edit 2: The ptrace error is caused by kernel hardening that allows only debugging of child processes. I could solve this (temporarily) via
sudo su -
echo 0 > /proc/sys/kernel/yama/ptrace_scope
exit
Still an open issue: The QtCreator debugger shows the assembly code (not the C/C++ code)
Here the steps it takes me to do this using the gdb front end provided by Emacs. As an example, I am debugging a package that uses Rcpp:
Open the root directory of the package in Emacs.
Start an R session with ESS via M-x R.
Get the pid of the R session with Sys.getpid().
Start gdb front end with M-x gdb adding -p <pid> to the suggested command line.
In gdb add some break point in the package to be loaded. This will be marked as "pending".
In gdb continue the R process.
In R load the package with devtools::load_all().
In R call a function that will reach the break point.
In gdb you now have the normal interface but with the Source code being displayed in another buffer. Typically it takes one next step for the source buffer to show.
Here a screen shoot showing the *R* and *gdb* buffers together with the source code. Not the break-point indicated by the red dot and the cursor indicating where processing stands:
If you load the package some other way, e.g. with library(..., lib.loc = "..."), you should open the src directory of the package in the first step. That way Emacs can find the corresponding source file. I expect that this can be transferred to QtCreator as well.
I am trying to put the gdb to run with eclipse cdt on ubuntu to start debugging some simple programs. So I did the steps I reckon as necessary to get it running:
1. Create an executable project
2. Compile
3. Run
4. Create the file .gdbinit and place it on the main project folder
5. Set some of the debugger configuration:
5. I also tried to find a .gdbinit file that would look some like this:
set schedule-multiple
dir ~/gcc_build/4.7.2/build/gcc
dir ~/gcc_build/4.7.2/gcc
dir ~/gcc_build/4.7.2/gcc/cp
dir ~/gcc_build/4.7.2/gcc/lto
source ~/gcc_build/4.7.2/build/gcc/gdbinit.in
But I didn't find anything similar in my computer, even after doing a:
# find / -name .gdbinit
So, my file .gdbinit end up with the simple content - yes only that:
set new-console on
Then I clicked on Apply and Debug:
The gdb starts working nicely as expected. I press the button "step over / F6" and the debugger goes jumping through the code step by step. Until the point it reaches the command rand() and the gdb hangs with the message:
Can't find a source file at "/build/buildd/eglibc-2.19/stdlib/rand.c"
Locate the file or edit the source lookup path to include its location.
Thus I also tried unsuccessfully to find the rand.c to update this path to include its location:
# find / -name rand.c
# find / -name stdlib
After the error message from GDB complaining that rand.c is missing, then I tried to keep stepping... since then the stepping mode is disable when I restart the debug:
Is this problem happening because some setting for my file .gdbinit is missing? Or some how GDB is not able to find the rand.c from stdlib from c99? When I compile and run the program it runs nicely. Only when I try to launch the debugger is when GDB crashes.
Update: I got the missing rand.c problem after running the commands:
# apt-get install libc6-dbg
# apt-get source libc6
But now a different error appears:
Can't find a source file at "/build/buildd/eglibc-2.19/csu/libc-start.c"
Locate the file or edit the source lookup path to include its location.
Should I also install that library for gdb?
All suggestions are highly appreciated.
From what I saw on your description... looking to the 4th and 5th image you posted, you did right all the required steps.
However, it seems to me that your GDB is attached to several projects. That means that unless you really need that, I would strongly advise you to select all project that you are not currently debugging and delete them from the debugger mode. So, my suggestion is that after you have done all the steps you did so far, then go on:
Debug Configurations > C/C++ Applications: (drop down it)
... then click on each project you are not compiling, with right button from the mouse select "delete" - but don't worry, it will not delete your project, but only the attachment of that project to your debugger mode.
Then restart the eclipse. When you again try to run in the debugger mode, everything will run much smoother than before.
Step1:
Go to https://www.gnu.org/software/libc/ to download glibc.
Step2:
unzip it locally and whenever the eclipse prompts "Can't find ... xxx.c", just load the file into eclipse. It will work.
I'd like to debug to debug a remote application with GDB.
My target system is a FreeBSD 8.3 box with gdbserver running. The application has been compiled successfully on that box. My Eclipse CDT 4.2 runs on Windows 7 with recent MinGW installed.
This is an external program I'd like to debug. It is neither written by me nor I do have it as a library. I do not intend to write my own program. In this case it is Subversion 1.8.0-dev which I want to debug.
I have created a simple C project, attached the source of Subversion. Created a remote debug config and attached the sources to the running thread in gdbserver.
Now, eclipse enters the main function of Subversion but when I set a breakpoint in another attached source file, Eclipse says: No source file named ra_loader.c or it simply says "No source available".
Then It simply exists the application.
What am I missing here?
Try the suggestion made on this thread
Quote :
1) run a debug session and open the gdb console inside Eclipse
('Console' tab -> 'Display Selected Console' button -> choose the one
ending with 'gdb')
2) use command 'pwd' in the console to print
gdb's current working dir
3) use command 'info line main' to get
the source file where gdb expect to find of my "int main(...)"
function
4) concatenate the result of step 2 with result of step
3 (which should be a relative path) to see if it matches the
correct source file I want
5) use the 'cd' command in gdb (to
change the current working dir) till I get the correct match in
step 4
Knowing the initial working directory (2) and the correct working directory (5) for gdb , I had 2 options: 1) Use gdb's 'cd'
command every time I launch a debug session (I could setup a
.gdbinit file in the gdb initial working directory to do this
automatically) or 2) Setup the 'Source' tab, in 'Debug
Configurations', to make Eclipse use paths that match with gdb's
initial working dir ('Project - Path Relative to Source Folders'
worked for me)