I'm trying to learn the basics of gdb. I saw that, in gdb's help obscure, there's a line that says:
stop -- There is no 'stop' command
However, entering stop does not do the same thing as entering a nonexistant command - it doesn't print the "undefined command" message. Moreover, it appears to do nothing and output nothing.
Is this "command" there for some sort of backward compatibility reason? If not, why is there a command that doesn't do anything but have a line in the help that asserts that it is not a command? If so, why doesn't it print out at least something back to user indicating that nothing has been done, so that they are not confused if they assumed it does something related to its name? Or does it actually do something?
I feel like there's some sort of obvious-in-hindsight reason behind this weird command, but surprisingly I've found no way I can phrase it to Google such that it comes up with anyone else asking this question. I hope I'm not just being dumb and wasting y'alls' time, but I'm honestly stumped.
help obscure for stop command is indeed a bit obscure. To get more info about it you can read help stop:
(gdb) help stop
There is no `stop' command, but you can set a hook on `stop'.
This allows you to set a list of commands to be run each time execution
of the program stops.
Actually there is stop command but it does nothing. It is intended to be used in gdb hooks. See also hooks documentation:
In addition, a pseudo-command, ‘stop’ exists. Defining (‘hook-stop’)
makes the associated commands execute every time execution stops in
your program: before breakpoint commands are run, displays are
printed, or the stack frame is printed.
Related
Some debuggers (like pdb) automatically break at your first line of code, then allow you to add breakpoints as needed. I'd really like to have that functionality with gdb. (I need to trace code execution through a huge codebase, and none of my guesses as to where to set a breakpoint have been correct, so the program just runs through to the end.) I've read that you can get similar functionality with gdb's starti command, but gdb takes it a little too literally: it stops on the VERY first line of the program where the linking information is. How can I move past this and actually step into my program? I've tried running the s command, but nothing looks familiar.
Here's a picture of what I see when I run starti.
Use start, not starti. start puts a temporary breakpoint on your main() function and begins executing. It should start at the beginning of your program proper.
I want to improve the already good analysis of the PyInstaller issue https://github.com/pyinstaller/pyinstaller/issues/2355. For that I need to either catch all errors or set a specific break point with LLDB.
On GitHub I stated
For starters one would essentially just need a break point that catches all errors and then dump the call stack.
I tried break set -E C++, breakpoint set --selector __cxa_throw: [...] but nope, doesn't stop.
The execution does stop i.e. hit the break point if I do b Get but there are way too many functions this selector affects.
To conclude, how can I make the executable, available at http://frightanic.com/misc/hello-world, stop right when that error at ./src/common/stdpbase.cpp(62) occurs?
--selector specifies a break on an ObjC selector name. So I wouldn't expect that one to work. I don't know how these check macros work, but the one getting tripped says it returns a value in non-debug or stops in the debugger for debug, so I'd be surprised if it throws a C++ exception. The fact that the C++ exception breakpoint isn't getting tripped bears that out. You can specify a class::method to lldb's breakpoint. So you might try:
(lldb) break set -n wxStandardPathsBase::Get
That should narrow the breakpoint down. Of course if you have debug information for the wxwidgets, you should be able to set a file & line breakpoint which will also be more precise.
So I am relatively new to coding so please forgive improper vocab. What I am basically trying to do is create a script for, or perhaps enter commands into, GDB so that it can run my code with the input file of a test case over and over. Basically, I am working on a project right now that makes heavy usage of semaphores and mutexes, and somewhere, every once in a blue moon, my code breaks due to race conditions. If I could have gdb run my test case continuously until my code reached a seg fault, this would be ideal.
PS- Please be specific as to what I must do, I am not great at dissecting answers that have heavy technical answers.
Thank You!
The simplest solution is expect script. Expect is a program to automate interactions with programs that expose a text terminal interface.
Examples are available at http://en.wikipedia.org/wiki/Expect
The script should be like
#!/usr/bin/expect
# start gdb
spawn gdb yourprogram
while {1} {
# wait for gdb to start, expect the (gdb) to appear
expect "(gdb)"
# send command to run your program
send "run your_args\n"
expect {
"Program exited normally." {continue} # just run again
"(Some error message)" {interact} # start to debug
}
}
You can use GDB scripts in order to automate your GDB sessions.The GDB macro coding language consists of gdb commands along with basic looping statements and conditional statements.
You can find information about it here
http://www.adacore.com/adaanswers/gems/gem-119-gdb-scripting-part-1/
What are the best ways to automate a GDB debugging session?
I'm debugging multi-threaded code and I would just like to know if a line has been reached without it stopping but I don't want to start adding print statements everywhere.
Is this possible? Thanks!
You can attach commands to a breakpoint in gdb with the 'commands' command. One of those commands can be 'continue'.
You may be looking for tracepoints. These capture variable values without stopping execution.
http://sourceware.org/gdb/onlinedocs/gdb/Tracepoints.html
I have this in my program:
execv (programname, (char **)argv);
I'm not sure if the command is actually being executed correctly. How can I find out? Is this being run in the background?
I highly recommend getting a book that relates to the task you're trying to do. It's going to be a really long road if you ask a new question on SO on every step of the way. We love to help, but sometimes books are better.
Advanced UNIX Programming is an excellent one that contains a full sample of a shell, including pipelines. In fact, the example programs are available for download for free (but I recommend picking up a copy of the book anyway).
Since execv replace the current process, the command will be run on the same state as the parent process.
One way to know if your command is executed is to make the command print something on the console, if it is possible.
I believe execv() is supposed to overlay the current process with "programname". If you want to run a program in a separate process, you want fork() or system() -- I don't believe the latter is "standard" but it seems to be fairly ubiquitous.
From man page of execv.
RETURN VALUE
If any of the exec() functions returns, an error will have occurred. The return value is -1, and errno will be set to indicate the error.
So, if you get a return value, something went wrong.