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
45
votes
2 answers

How do I debug a failing cargo test in GDB?

I have a failing Cargo test: $ cargo test [snip] Running target/gunzip-c62d8688496249d8 running 2 tests test test_extract_failure ... FAILED test test_extract_success ... ok failures: ---- test_extract_failure stdout ---- task…
dhardy
  • 11,175
  • 7
  • 38
  • 46
45
votes
2 answers

Is there a gdb command to finish a loop construct?

In gdb, I have the finish command to easily finish execution of a function frame, often when walking through code in the debugger, after looking at a few iterations of a loop, I'd like to finish the loop and continue walking after it. Presently, I…
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
44
votes
2 answers

Using gdb to convert addresses to lines

I have a stack trace generated by a stripped application which looks like this: *** Check failure stack trace: *** @ 0x7f0e442d392d (unknown) @ 0x7f0e442d7b1f (unknown) @ 0x7f0e442d7067 (unknown) @ 0x7f0e442d801d …
Allan
  • 4,562
  • 8
  • 38
  • 59
44
votes
7 answers

Is there any way to tell GDB to wait for a process to start and attach to it?

I have a process that is called by another process which is called by another process and so on ad nauseam. It's a child process in a long tool chain. This process is crashing. I would like to catch this process in GDB to understand why it's…
Nathan Fellman
  • 122,701
  • 101
  • 260
  • 319
44
votes
3 answers

How can I break on UBSan reports in gdb and continue?

Recent versions of GCC and Clang feature Undefined Behavior Sanitizer (UBSan) which is a compile flag (-fsanitize=undefined) that adds runtime instrumentation code. On errors, a warning such as this one is shown: packet-ber.c:1917:23: runtime…
Lekensteyn
  • 64,486
  • 22
  • 159
  • 192
44
votes
1 answer

gdb scripting: execute commands at selected breakpoint

I'd like to predefine some breakpoints in a gdb script and to invoke some special commands at these breakpoints and afterwards to automatically continue the program execution. So, ideally, I'd like to have a gdb script like the following: b…
Lord Bo
  • 3,152
  • 3
  • 15
  • 22
43
votes
9 answers

GDB kind of doesn't work on macOS Sierra

It is a problem that appeared when I first updated to macOS Sierra yesterday. GDB itself is running OK. However, somehow, it cannot run my program. When I type 'run' and 'enter', it immediately crashes with the information: During startup program…
Scott Chang
  • 631
  • 1
  • 6
  • 9
43
votes
7 answers

How to set a breakpoint in GDB where the function returns?

I have a C++ function which has many return statements at various places. How to set a breakpoint at the return statement where the function actually returns ? And what does "break" command without argument means?
avd
  • 13,993
  • 32
  • 78
  • 99
42
votes
5 answers

How to enable gdb pretty printing for C++ STL objects in Eclipse CDT?

I'm trying to add pretty printing for STL objects in eclipse cdt. I tried to follow the steps described here: http://sourceware.org/gdb/wiki/STLSupport I checked out the python folder, but I can't seem to get this done... I created a gdbinit and…
AlejandroVK
  • 7,373
  • 13
  • 54
  • 77
42
votes
3 answers

how does gdb work?

I want to know how does gdb work internally. e.g. I know a brief idea that it makes use of ptrace() system call to monitor traced program. But I want to know how it handles signals, how it inserts new code, and other such fabulous things it does.
Anonymous
  • 1,287
  • 6
  • 20
  • 21
42
votes
2 answers

How does a breakpoint in debugger work?

Breakpoints are one of the coolest feature supported by most popular Debuggers like GDB. But how a breakpoint works ? What code modifications does the compiler do to achieve the breakpoint? Are there any special hardware features used to support…
Shan
  • 5,054
  • 12
  • 44
  • 58
42
votes
2 answers

gdb - debugging with pipe

Say I have a two programs named blah and ret. I want to debug blah program which receives input from ret program via I/O redirection. How do I debug the blah program in the following case using gdb? bash> ret | blah
suresh
  • 4,084
  • 10
  • 44
  • 59
42
votes
5 answers

How to evaluate functions in GDB?

I wonder why evaluate function doesn't work in gdb? In my source file I include, when debugging in gdb, these examples are wrong evaluations. (gdb) p pow(3,2) $10 = 1 (gdb) p pow(3,3) $11 = 1 (gdb) p sqrt(9) $12 = 0
Tim
  • 1
  • 141
  • 372
  • 590
42
votes
4 answers

How do I set persistent and conditional watchpoints on locally scoped variables?

If I set a watchpoint for a variable local to the current scope, it will be auto deleted when going out of the scope. Is there any way to set it once and keep it auto alive whenever entering the same scope? Is there anyway to set conditional…
Tim
  • 1
  • 141
  • 372
  • 590
41
votes
2 answers

How to restrict gdb debugging to one thread at a time

I want to debug a multi-threaded program by controlling which threads execute when. I am using C++ and gdb. I have two threads besides the main thread (for the example program) and I want to debug one thread while keeping the other stopped. Here is…
Yogeshwer Sharma
  • 3,647
  • 5
  • 25
  • 27