11,668 questions
733
votes
9
answers
943k
views
How do I run a program with commandline arguments using GDB within a Bash script?
When running a program on GDB, usually, the arguments for the program are given at the run command. Is there a way to run the program using GDB and as well as give arguments within a shell script?
I ...
456
votes
4
answers
479k
views
Printing all global variables/local variables?
How can I print all global variables/local variables? Is that possible in gdb?
284
votes
6
answers
228k
views
Can I set a breakpoint on 'memory access' in GDB?
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 ...
261
votes
8
answers
446k
views
How to print register values in GDB?
How do I print the value of %eax and %ebp?
(gdb) p $eax
$1 = void
253
votes
4
answers
292k
views
How do I get the backtrace for all the threads in GDB?
Is there an equivalent command in GDB to that of WinDbg's !process 0 7?
I want to extract all the threads in a dump file along with their backtraces in GDB. info threads doesn't output the stack ...
241
votes
1
answer
197k
views
Step out of current function with GDB
Those who use Visual Studio will be familiar with the Shift + F11 hotkey, which steps out of a function, meaning it continues execution of the current function until it returns to its caller, at which ...
226
votes
28
answers
139k
views
Is there a C++ gdb GUI for Linux? [closed]
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 ...
221
votes
5
answers
171k
views
How to pass arguments and redirect stdin from a file to program run in gdb?
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.
205
votes
3
answers
189k
views
How do I set a conditional breakpoint in gdb, when char* x points to a string whose value equals "hello"?
Can I specify that I want gdb to break at line x when char* x points to a string whose value equals "hello"? If yes, how?
178
votes
2
answers
104k
views
GCC -g vs. -g3 GDB flag: What is the difference?
When compiling C source code with either GCC or Clang, I always use the -g flag to generate debugging information for GDB.
gcc -g -o helloworld helloworld.c
I noticed that some people recommend -g3 ...
173
votes
12
answers
151k
views
gdb fails with "Unable to find Mach task port for process-id" error
My app runs fine but gdb fails to debug it with the following error
(gdb) run
Starting program: /path/to/app
Unable to find Mach task port for process-id 83767: (os/kern) failure (0x5).
I am on OS X ...
159
votes
4
answers
225k
views
How do I pass a command line argument while starting up GDB in Linux? [duplicate]
I have to debug a program that has errors in it as part of my assignment. However, I must first pass command line arguments in order to solve this problem.
I do:
gdb -tui InsertionSortWithErrors
...
158
votes
11
answers
60k
views
Getting GDB to save a list of breakpoints
OK, info break lists the breakpoints, but not in a format that would work well with reusing them using the --command as in this question. Does GDB have a method for dumping them into a file acceptable ...
156
votes
10
answers
169k
views
GDB print to file instead of stdout
I am running GDB and want to examine one of those unfortunate god objects. It takes many pages (and I have a 24" monitor turned sideways!) to see the whole thing.
For ease of use, I'd like GDB to ...
152
votes
1
answer
153k
views
Print variables in hexadecimal or decimal format
Currently, when I print the value of a variable v in GDB (print v) I get an integer.
Is it possible to have GDB print such integer variables in hexadecimal or binary?
146
votes
3
answers
332k
views
How can one see content of stack with GDB?
I am new to GDB, so I have some questions:
How can I look at content of the stack?
Example: to see content of register, I type info registers. For the stack, what should it be?
How can I see the ...
140
votes
12
answers
45k
views
Most tricky/useful commands for gdb debugger [closed]
Can you post your most tricky and useful commands while you run a debugger like gdb or dbx.
138
votes
2
answers
149k
views
How to break on assembly instruction at a given address in gdb?
0x0000000000400448 <main+0>: push %rbp
0x0000000000400449 <main+1>: mov %rsp,%rbp
0x000000000040044c <main+4>: mov $0x6,%eax
0x0000000000400451 <main+9>: ...
134
votes
6
answers
137k
views
GDB corrupted stack frame - How to debug?
I have the following stack trace. Is it possible to make out anything useful from this for debugging?
Program received signal SIGSEGV, Segmentation fault.
0x00000002 in ?? ()
(gdb) bt
#0 0x00000002 ...
130
votes
4
answers
76k
views
Run an Application in GDB Until an Exception Occurs
I'm working on a multithreaded application, and I want to debug it using GDB.
Problem is, one of my threads keeps dying with the message:
pure virtual method called
terminate called without an ...
127
votes
13
answers
57k
views
Is there a way to change the environment variables of another process in Unix?
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 ...
123
votes
3
answers
82k
views
How to inspect the return value of a function in GDB?
Is it possible to inspect the return value of a function in gdb assuming the return value is not assigned to a variable?
122
votes
0
answers
4k
views
Android ndk gdb loaded shared libraries are missing *.oat
Both gdb 7.7 and gbd 7.11 missed some shared libraries when debugging my device (oppo r7s). I've pulled all libraries to local.
Here is a complete list of libraries shown by info shared
(gdb) info ...
119
votes
5
answers
232k
views
How to modify memory contents using GDB?
I know that we can use several commands to access and read memory: for example, print, p, x...
But how can I change the contents of memory at any specific location (while debugging in GDB)?
113
votes
3
answers
149k
views
Using gdb to single-step assembly code outside specified executable causes error "cannot find bounds of current function"
I'm outside gdb's target executable and I don't even have a stack that corresponds to that target. I want to single-step anyway, so that I can verify what's going on in my assembly code, because I'm ...