Questions tagged [gdb]

Use this tag for problems related to or involving GDB, the standard debugger for the GNU software system.

The GNU Debugger, usually called just GDB and named gdb as an executable file, is the standard debugger for the GNU software system. It is a portable debugger that runs on many Unix-like systems and Microsoft Windows variants. GDB works for many programming languages, including C, C++, D, Go, Objective-C, Fortran, Java, OpenCL C, Pascal, assembly, Modula-2, and Ada.

Related Resources

11325 questions
109
votes
4 answers

GDB: break if variable equal value

I like to make GDB set a break point when a variable equal some value I set, I tried this example: #include main() { int i = 0; for(i=0;i<7;++i) printf("%d\n", i); return 0; } Output from GDB: (gdb) break if…
SIFE
  • 5,567
  • 7
  • 32
  • 46
108
votes
5 answers

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)?
bits
  • 8,110
  • 8
  • 46
  • 55
108
votes
12 answers

GDB missing in OS X v10.9 (Mavericks)

I went to use GDB in OS X v10.9 (Mavericks), and it's not there. Where has it gone? # /usr/lib/gdb -bash: /usr/bin/gdb: No such file or directory # gdb -bash: gdb: command not found I also launched Xcode 5.0.1: Preferences > Downloads ..and…
l'L'l
  • 44,951
  • 10
  • 95
  • 146
106
votes
7 answers

Inspecting standard container (std::map) contents with gdb

Supposing to have something like this: #include int main(){ std::map m; m[1] = 2; m[2] = 4; return 0; } I would like to be able to inspect the contents of the map running the program from gdb. If I try using the…
Paolo Tedesco
  • 55,237
  • 33
  • 144
  • 193
106
votes
3 answers

How to set breakpoints on future shared libraries with a command flag

I'm trying to automate a gdb session using the --command flag. I'm trying to set a breakpoint on a function in a shared library (the Unix equivalent of a DLL) . My cmds.gdb looks like this: set args /home/shlomi/conf/bugs/kde/font-break.txt b…
Shlomi Fish
  • 4,380
  • 3
  • 23
  • 27
105
votes
3 answers

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 not an expert at x86 assembly. Unfortunately,…
Paul
  • 1,800
  • 2
  • 17
  • 17
102
votes
2 answers

Saving core file in gdb

Is it possible to save/dump core file using gdb? Sometimes I want to save file to analyze it later.
Maciej Piechotka
  • 7,028
  • 6
  • 39
  • 61
101
votes
2 answers

How to make a GDB breakpoint only break after the point is reached a given number times?

I have a function that is called some large number of times, and eventually segfaults. However, I don't want to set a breakpoint at this function and stop after every time it's called, because I will be here for years. I've heard that I can set a…
Tony Stark
  • 24,588
  • 41
  • 96
  • 113
100
votes
3 answers

warning: Error disabling address space randomization: Operation not permitted

what have i done wrong (or didn't do) that gdb is not working properly for me? root@6be3d60ab7c6:/# cat minimal.c int main() { int i = 1337; return 0; } root@6be3d60ab7c6:/# gcc -g minimal.c -o minimal root@6be3d60ab7c6:/# gdb minimal GNU gdb…
Jas
  • 14,493
  • 27
  • 97
  • 148
97
votes
1 answer

gdb - debugging with piped input (not arguments)

I typically run my program with: perl -e 'print "A"x200' | ./vuln_prog The stdin is consumed by a gets() function in C++. If this were just a command argument, I could open gdb by doing: gdb ./vuln_prog run $(perl -e 'print "A"x200') However, my…
mandreko
  • 1,766
  • 2
  • 12
  • 24
96
votes
9 answers

How to go to the previous line in GDB?

Is it possible in gdb to go to a line before the currently executing line. e.g: void my_fun( somePtrType** arr,int start,int end) { // arr is an array of pointers to somePtrType //line a ... some assignments swap(&arr[ind1] , &arr[ind2] ) ; …
sud03r
  • 19,109
  • 16
  • 77
  • 96
93
votes
4 answers

How can I examine the stack frame with GDB?

Right now I've been using GDB to disassemble a binary file and check out different registers and whatnot. Is there an easy command to examine everything on the stack? Can this be limited to everything in a function?
GetOffMyLawn
  • 1,362
  • 4
  • 14
  • 21
90
votes
7 answers

How Does The Debugging Option -g Change the Binary Executable?

When writing C/C++ code, in order to debug the binary executable the debug option must be enabled on the compiler/linker. In the case of GCC, the option is -g. When the debug option is enabled, how does the affect the binary executable? What…
Jon Ball
  • 3,032
  • 3
  • 23
  • 24
90
votes
2 answers

android ndk gdb loaded sharedlibraries 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 shared From To Syms Read Shared…
Joey.Z
  • 4,492
  • 4
  • 38
  • 63
90
votes
4 answers

Are "EXC_BREAKPOINT (SIGTRAP)" exceptions caused by debugging breakpoints?

I have a multithreaded app that is very stable on all my test machines and seems to be stable for almost every one of my users (based on no complaints of crashes). The app crashes frequently for one user, though, who was kind enough to send crash…
Dennis
  • 1,215
  • 1
  • 12
  • 15