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
199
votes
11 answers

How to highlight and color gdb output during interactive debugging?

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.
elmarco
  • 31,633
  • 21
  • 64
  • 68
193
votes
3 answers

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?
341008
  • 9,862
  • 11
  • 52
  • 84
175
votes
9 answers

Do you debug C++ code in Vim? How?

The question is to all you people, who use Vim to develop C++ applications. There was a period in my life, which can be described as 'I hate Vim!!!'..'Vim is nice!' However, having grown up mostly on Microsoft development IDEs, I've got used to…
Andrew_Lvov
  • 4,621
  • 2
  • 25
  • 31
175
votes
8 answers

Multiple commands in gdb separated by some sort of delimiter ';'?

I am trying to execute two commands at once in gdb: finish; next I tried using the ';' to separate the commands but gdb did not let me do both at once. Is it possible to do multiple commands in gdb similar to bash commands separated by ';'…
Trevor Boyd Smith
  • 18,164
  • 32
  • 127
  • 177
166
votes
12 answers

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 Lion. GDB version is $ gdb --version GNU gdb…
S B
  • 8,134
  • 10
  • 54
  • 108
153
votes
2 answers

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 instead. What is the difference between the -g and…
haziz
  • 12,994
  • 16
  • 54
  • 75
150
votes
4 answers

How do I pass a command line argument while starting up GDB in Linux?

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 which works, but after that I don't know how to pass…
ShadyBears
  • 3,955
  • 13
  • 44
  • 66
149
votes
11 answers

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 for input again? Sometimes in a debugging…
casualcoder
  • 4,770
  • 6
  • 29
  • 35
149
votes
8 answers

Can I use GDB to debug a running process?

Under linux, can I use GDB to debug a process that is currently running?
Justin Ethier
  • 131,333
  • 52
  • 229
  • 284
146
votes
9 answers

gdb split view with code

I was just debugging a program in gdb and somehow I found a new feature I've never seen or even heard of before, a split view where I can see and browse the code in addition to giving commands: What is this? What did I do, or, more specifically,…
Kevin
  • 53,822
  • 15
  • 101
  • 132
142
votes
6 answers

Set breakpoint in C or C++ code programmatically for gdb on Linux

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…
J. Polfer
  • 12,251
  • 10
  • 54
  • 83
140
votes
3 answers

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 content of $0x4(%esp)? When I type print /d…
user478571
140
votes
9 answers

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 print the object to a file instead of the screen so…
pythonic metaphor
  • 10,296
  • 18
  • 68
  • 110
140
votes
12 answers

Most tricky/useful commands for gdb debugger

Can you post your most tricky and useful commands while you run a debugger like gdb or dbx.
Vijay
  • 65,327
  • 90
  • 227
  • 319
138
votes
5 answers

GDB: How to print the current line or find the current line number?

The list command prints a set of lines, but I need one single line: where I currently am and where an error has probably occurred.
Boris Burkov
  • 13,420
  • 17
  • 74
  • 109