I have an executable, which I can read symbols from (so it seems.) My problem is this: when it comes time to run, I get the following error:
(gdb) run
Starting program: /home/usr/src/etcetera/etcetera/bin/theExecutable.exe
Cannot exec -c exec /home/usr/src/etcetera/etcetera/bin/theExecutable.exe.
Error: No such file or directory
During startup program exited with code 127
obviously, I have edited the directories here. I searched how to fix this on SO, and tried some of the following solutions:
GDB cannot see source file
GDB can't find source file
GDB won't load source file
got onto this link:
https://sourceware.org/gdb/download/onlinedocs/gdb/Source-Path.html#Source-Path
and am trying to change the source file directory. (The source files are not in the same location as the executable, but instead are spread over a range of different places.) Unless I am mistaken, the way of doing this is to go:
(gdb) directory /home/usr/src/etcetera/etcetera/rootDirectoryForSourcefiles
and have the GDB search this directory. I have even tried changing directory into the source directory, and then running but still, it wants to try where the executable lives.
Am I completely missing the mark here in an obvious way, or is this likely to be quite obscure?
You are barking up the wrong tree. You problem has ~nothing to do with source files, and everything to do with your executable file.
It may be related to something in your ~/.gdbinit, or your ~/.bashrc, or the way you invoked GDB.
You should start by doing a basic sanity check:
env SHELL=/bin/sh gdb -nx /bin/date
(gdb) run
If that doesn't work, your GDB installation is screwed up.
If that does work, one of the three things I mentioned above is very likely the cause of your troubles.
I had this problem and it turned out that the shell wasn't set correctly in the /etc/passwd file.
To solve it, I opened the file with
sudo vipw
and added /bin/bash to the my account's data there.
Try to:
export SHELL=/bin/sh
before running gdb
I had met same problem. When my
SHELL=/usr/local/bin/tcsh
but I have only the file .cshrc, gdb reports the same error.
When I change SHELL:
setenv SHELL /bin/csh
Then everything goes fine.
Related
To make gdb make use of a single source file, you can store it in the same directory where gdb is run. How about a complete folder ?
E.g. I have a folder called "bootup" with multiple subfolders and files in it. It generates a binary called "bootup" which I need to debug for a crash and also to understand code flow.
If i just have the bootup folder (containing the source code) in the path it doesn't seem to be enough. When i set a breakpoint and debug it still only shows the file as follows but not the source code.
(gdb)directory /root/bootup
Source directories searched: /root/bootup:/root:$cdir:$cwd
(gdb) n
141 in RecFns.cpp
(gdb)
142 in RecFns.cpp
RecFns.cpp is under /root/bootup/dir1/dir2/dir3/RecFns.cpp
What should I do to be able to get gdb printing the source file contents as I debug along.
As per http://sourceware.org/gdb/onlinedocs/gdb/Source-Path.html, directory xyz should be able to make gdb search in the directory specified. But this isn't working for me.
gdb find . -type d | xargs printf " -d %s" prog
worked for me eventually. This supplies the directories recursively to gdb.
Found it here - https://titanwolf.org/Network/Articles/Article?AID=e61837e2-2ccc-4cce-80c8-3c8555aeacbd#gsc.tab=0
Now i am able to see the source code like how i wanted to :-)
According to the official guideline of lldb, the ability to view source code during debug session (using the command source list) is done by setting new pathname for source files.
i.e. if i compiled my project in /tmp on one computer and deployed it on another computer where the source code reside in /Users/Src/ , i should type settings set target.source-map /tmp /Users/Src from running lldb in the deployment machine.
However, what happens if i got the executable from someone else, and don't know the build directory. and maybe the source-code is organized differently from where is was built (but the file contents is the same).
my questions are :
Does lldb know how to search for matching source file recursively in the supplied path ?
How can I get the original pathname form the mach-o executable ?
here's the formal description of the command :
Remap source file pathnames for the debug session. If your source files are no longer located in the same location as when the program was built --- maybe the program was built on a different computer --- you need to tell the debugger how to find the sources at their local file path instead of the build system's file path.
If you know a function name in the code in question, do:
(lldb) image lookup -vn <FunctionName> <BinaryImageNameContainingFunction>
and look for the CompileUnit entry. The path given there is the path lldb got from the debug information.
I have a C++ project in Ubuntu 12.04. To run the project the make file requires the following files:
1-All the .cpp files
2-All the .h files
3-Three shared libraries.
The project is fully functionall and performs according to the specifications. All the required .cpp files and .h files are available. The problem is that there is no main() function in any of the source files and the program entry point resides in one of the three shared libraries. My job is to find out the program execution pipeline and without having any main file I am not able to do that. I can't run the project in any IDE (i.e: eclipse) because there is no main function available.
Question: Can you please tell me how to find the program entry point?
P.S: I will be glad to provide any kind of information or material you may need to solve my problem.
Edit: The CMakeLists.txt file available here.
Edit 2: The build.sh file available here.
To find enty point look into each shared object with:
nm $library | egrep "T main$"
Library with main() will output something like
090d8ab0 T main
Very usefull way to visualize execution tree is to run:
valgrind --tool=callgrind ./my_executable -arg -arg ....
(you can abort execution early with Ctrl+C)
This will output callgrind.<pid> file. To visualize it run kcachegrind callgrind.<pid>.
You will need valgrind:
sudo apt-get install valgrind
and kcachegrind
sudo apt-get install kcachegrind
Build it with the debug option -g and step into the program with a debugger like gdb (or cgdb or ddd). You'll need any appropriate debug libraries libraries though.
Short of that, play with the code a bit. Try putting printf or cout statements that print internal variables in any functions that look important, and see what the program status is and how frequently they get called. If main is hidden in a library, there's probably another function somewhere that behaves like main for the purposes of the API provided by whatever library has the real main.
What's the API documentation for your libraries? (is this a school project?). It sounds odd to have a hidden main and not say anything about it.
In case you use a build system (CMake, SCons, ...) it is highly possible that the build system is also generating some files, and one of them might be containing the main() method. We use this methodology when we generate the main function in order to instantiate classes for libraries that were specifically selected in CMake-gui.
And again, it is possible that the build system deletes the generated files due to some obscure policy the original developers thought of but didn't tell you. So search through your build system files, see what is actually happening there.
Edit
So, after seeing you CMakeLists.txt:
check ${DIR_EXT}/covis/src/ci.cpp where DIR_EXT is SET( DIR_EXT "../ext/" CACHE PATH "Folder holding external libraries" )
See what's in there and let us know :)
Edit2
After seeing build.sh (execute steps in order):
1.
change
`cmake -D COMPILE_BINARY=ON ..`
to
`cmake -D COMPILE_BINARY=ON -DCMAKE_BUILD_TYPE=Debug ..`
and add the same -DCMAKE_BUILD_TYPE=Debug to the other cmake command too.
This will build your library and executable in debug mode.
2.
Now, in one of the c++ source files you have access to and you are sure will be called (the earlier the function will be calle the better), add:
asm("int $0x03");
This will create a breakpoint in your application.
(If you do not want to use this, see below).
3.
Build your application.
4.
Run it via a debugger in terminal:
gdb ./myapplication <ENTER>
(this will give you a gdb prompt)
(if you did not add the asm breakpoint from above, type in the gdb prompt: break filename.cpp:linenumber or break methodname to add a gdb breakpoint).
run <ENTER>
Now your application should stop in your function when it is executed.
You are still in the gdb prompt, so type:
bt <ENTER>
This will print out the backtrace of your application. Somewhere you should see a main function, together with filename and linenumber.
However, that setnames.sh looks interesting, see if it does not do anything funny :)
I'm trying to get up and running with Boost, so I'm trying to compile the simple example problem from Boost's "Getting Started" page. I've had two issues, and I'm not sure they're related (I'm better than a novice, but not by much) but maybe they're related...
1st issue: the "tar --bzip2 -xf /path/to/boost_1_49_0.tar.bz2" command didn't work (yes, I put the correct path in, but it gave me some errors, I forget what they were) so I used "tar -xjvf " from the directory where boost_1_49_0.tar.bz2 was located. That de-compressed the zip file and I proceeded with the example...
2nd issue: The example.cpp file will not compile, the first statement in the code is #include "boost/lambda/lambda.hpp" but then for every header file lambda.hpp is trying access, there's a "No such file or directory" compile error. For example, here are two (of the six, and I get errors for all 6) header files within lambda.hpp and the errors displayed by the cygwin compiler:
boost/lambda/lambda.hpp:14:33: boost/lambda/core.hpp: No such file or directory
boost/lambda/lambda.hpp:21:52: boost/lambda/detail/operator_actions.hpp: No such file or directory
If it helps, this is the command I'm running to compile (I generally create the executable in a separate -o command):
g++ -c example.cpp
Why can't the system find these? I added the installed directory (path/to/boost_1_49_0) to the PATH variable before I started so I know that's no it. Thanks for any advice...
(I've looked on stackoverflow and there were similar issues, but no solutions that worked)
It looks like you've already solved the first issue: namely, that you must specify the -j flag on tar to untar a bzip2'd file.
For the second issue, you need to specify boost on your include path, either by specifying it with the -I command line option or via the CPLUS_INCLUDE_PATH environment variable.
I think this may have been asked earlier but i can't find one that satisfied my requirements.
I am debugging(infact trying to understand) a large project by trying to analyze the code flow in various testsuites. But when i try to set breakpoints at some files, i get the error "no source file named filename found".
So my question is:
Can gdb only accept breakpoints for the source files where the code flow enters.?
Can I set breakpoints over entire lines of a file with something like b filename:*
Will a breakpoint at header file be accepted as header files are just appended at compile time?
Any insights are more than welcome.
Edit
I checked these issues with some hello world code and found same results as pointed out in one of the answers.but my issue in the actual project still remains on. I still get the same error even when i can see the edited output of the same line which is not accepted as a breakpoint.
Edit 2
I got it working but don't understand how and why it works..??
(gdb) b /home/neeraj/BTP/trunk/include/header.h:872
No source file named /home/neeraj/BTP/trunk/include/header.h:872
Make breakpoint pending on future shared library load? (y or [n]) n
(gdb) b /home/neeraj/BTP/trunk/src/driver.cpp:2
Breakpoint 1 at 0x806c61a: file ../../../trunk/src/driver.cpp, line 2.
(gdb) b /home/neeraj/BTP/trunk/include/header.h:872
Breakpoint 2 at 0x8052fa0: file ../../../trunk/include/header.h:872, line 872.
(gdb)
Any deeper insights..?
No.
No.
Yes.
Make sure you compile with -g (debug) option. Make sure the sourcepaths are set correctly. Use directory, show directories and dir commands to see/set.
The other thing to beware of besides shared libraries is that gdb source file names are relative to the directory where the code was compiled. If you haven't compiled with absolute pathnames, use the dir command to add the compilation directory to the list of places gdb searches for source code.
And a hint: I find I am wildly more productive when I use the Data Display Debugger (DDD) graphical front end to gdb.