gdb interview questions
Top gdb frequently asked interview questions
I want to examine the contents of a std::vector
in GDB, how do I do it? Let's say it's a std::vector<int>
for the sake of simplicity.
Source: (StackOverflow)
I am running an application through gdb and I want to set a breakpoint for any time a specific variable is accessed / changed. Is there a good method for doing this? I would also be interested in other ways to monitor a variable in C/C++ to see if/when it changes.
Source: (StackOverflow)
I'm doing some assembly-level debugging in gdb. Is there a way to get gdb to show me the current assembly instruction in the same way that it shows the current source line? The default output after every command looks like this:
0x0001433f 990 Foo::bar(p);
This gives me the address of the current instruction, but I have to keep referring back to the output of disassemble
in order to see which instruction I'm currently executing.
Source: (StackOverflow)
Please don't reply I should use ddd, nemiver, emacs, vim, or any other front-end, I just prefer gdb as it is, but would like to see its output with some terminal colors.
Source: (StackOverflow)
How can I set a breakpoint in C or C++ code programatically that will work for gdb on Linux?
I.e.:
int main(int argc, char** argv)
{
/* set breakpoint here! */
int a = 3;
a++; /* In gdb> print a; expect result to be 3 */
return 0;
}
Source: (StackOverflow)
Is it possible to inspect the return value of a function in gdb assuming the return value is not assigned to a variable?
Source: (StackOverflow)
I can add a break point in gdb with:
b <filename>:<line no>
How can I remove an existing breakpoint at a particular location?
Source: (StackOverflow)
On Unix, is there any way that one process can change another's environment variables (assuming they're all being run by the same user)? A general solution would be best, but if not, what about the specific case where one is a child of the other?
Edit: How about via gdb?
Source: (StackOverflow)
The question is to all you people, who use VIM to develop C++ apps.
There was a period in my life, which can be described as
'I hate VIM!!!'..'VIM is nice!'
However, having grown up mostly on MS Dev IDE, I've got used to those F5-F11 shortcuts when debugging code, watch window, call stack and the main code - all visible vithout need to type any gdb commands.
So, here is the question:
Do you use VIM as well for debugging ? Or you switch to some IDE for this purpose ? Which one ?
For those who use VIM to debug code: are there plugins to set breakpoints in editor, highlight the line we're currently debugging, auto-navigation during step, step into, step out ?
Please, don't tell me you use gdb as command line, see only one line which is debugged etc.
And thanks for all your answers.
Andrey
Source: (StackOverflow)
Briefly: Does anyone know of a GUI for gdb that brings it on par or close to the feature set you get in the more recent version of Visual C++?
In detail: As someone who has spent a lot of time programming in Windows, one of the larger stumbling blocks I've found whenever I have to code C++ in Linux is that debugging anything using commandline gdb takes me several times longer than it does in Visual Studio, and it does not seem to be getting better with practice. Some things are just easier or faster to express graphically.
Specifically, I'm looking for a GUI that:
- Handles all the basics like stepping over & into code, watch variables and breakpoints
- Understands and can display the contents of complex & nested C++ data types
- Doesn't get confused by and preferably can intelligently step through templated code and data structures while displaying relevant information such as the parameter types
- Can handle threaded applications and switch between different threads to step through or view the state of
- Can handle attaching to an already-started process or reading a core dump, in addition to starting the program up in gdb
If such a program does not exist, then I'd like to hear about experiences people have had with programs that meet at least some of the bullet points.
Does anyone have any recommendations?
Edit:
Listing out the possibilities is great, and I'll take what I can get, but it would be even more helpful if you could include in your responses:
(a) Whether or not you've actually used this GUI and if so, what positive/negative feedback you have about it.
(b) If you know, which of the above-mentioned features are/aren't supported
Lists are easy to come by, sites like this are great because you can get an idea of people's personal experiences with applications.
Source: (StackOverflow)
I usually run a program as :
./a.out arg1 arg2 <file
I would like to debug it using gdb.
I am aware of the set args
functionality, but that only works from the gdb prompt.
Source: (StackOverflow)
How can I set up gdb
so that it saves the command history? When starting a new gdb
session I'd like to use the arrow up keys to access the commands of the previous sessions.
Source: (StackOverflow)
This question already has an answer here:
What are all the things I will need to check while analyzing core dump file?
Please tell me from scratch.
Source: (StackOverflow)