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

How to print a null-terminated string with newlines without showing backslash escapes in gdb?

I have a variable char* x = "asd\nqwe\n ... " and I want to print it with newlines printed as newlines not backslash n. Is it possible?
Łukasz Lew
  • 48,526
  • 41
  • 139
  • 208
64
votes
9 answers

How to break when a specific exception type is thrown in GDB?

According to the documentation I can break on specific exception type by using conditional breakpoints. However the syntax for the condition isn't very clear to me: condition bnum Looking at the expression syntax I think this is the…
StackedCrooked
  • 34,653
  • 44
  • 154
  • 278
64
votes
7 answers

gcc -g :what will happen

This question was asked to me in an interview. they asked me how to generate a core dump file with which i can debug. then i said that with -g flag in gcc we can do it. then they have asked me what exactly does that -g flag do to the compiler. i…
Vijay
  • 65,327
  • 90
  • 227
  • 319
64
votes
4 answers

Print multiple variables with one command in GDB

I want to execute the very simple command print var1, var2, var3, var4 in gdb to examine the values of the vars from time to time. I don't want to use display because it clutters up my view. How can I do this? Right now all I can do is: p var1 p…
Rao Garimella
  • 649
  • 1
  • 5
  • 3
64
votes
10 answers

How to pretty-print STL containers in GDB?

I've followed the instructions on the GDB wiki to install the python pretty-printers for viewing STL containers. My ~/.gdbinit now looks like this: python import sys sys.path.insert(0, '/opt/gdb_prettyprint/python') from libstdcxx.v6.printers…
Nick Hutchinson
  • 5,044
  • 5
  • 33
  • 34
63
votes
4 answers

Best way to invoke gdb from inside program to print its stacktrace?

Using a function like this: #include #include #include #include void print_trace() { char pid_buf[30]; sprintf(pid_buf, "--pid=%d", getpid()); char name_buf[512]; …
Vi.
  • 37,014
  • 18
  • 93
  • 148
62
votes
3 answers

How clear gdb command screen?

Is it possible to clear the command window of gdb? I mean, is there a command in gdb that do the same (for the command windows) as the clear command in a bash terminal?
JohnTortugo
  • 6,356
  • 7
  • 36
  • 69
61
votes
1 answer

How do I print a #defined constant in GDB?

As per subject. I have some constants hash defined like so: #define CONST 40 I've set a breakpoint in my program. How do I print the value of that constant? (I know I can just look at the source code, but I want to be sure of it)
Charles Ma
  • 47,141
  • 22
  • 87
  • 101
60
votes
5 answers

How to determine if an object is an instance of certain derived C++ class from a pointer to a base class in GDB?

I'm debugging a C++ program with GDB. I have a pointer to an object of certain class. The pointer is declared to be of some super class which is extended by several sub-classes. There is no fields in the object to specify the precise class type of…
user1101096
  • 699
  • 2
  • 6
  • 7
60
votes
2 answers

po command in Xcode does not generate output

At some point during my work, Xcode's po and p commands stopped working. No matter what I enter, it doesn't generate output: (gdb) po self (gdb) po [self name] (gdb) po [UITableView class] (gdb) po @"Hello" (gdb) p indexPath.row (gdb) print…
Jonas Sourlier
  • 13,684
  • 16
  • 77
  • 148
59
votes
5 answers

Memory dump formatted like xxd from gdb

I'm trying to inspect a buffer which contains a binary formatted message, but also contains string data. As an example, I'm using this C code: int main (void) { char buf[100] = "\x01\x02\x03\x04String Data\xAA\xBB\xCC"; return 0; } I'd…
FatalError
  • 52,695
  • 14
  • 99
  • 116
59
votes
3 answers

How to interpret GDB "info frame" output?

Can some please help me to understand this: (gdb) info frame Stack level 0, frame at 0xb75f7390: eip = 0x804877f in base::func() (testing.cpp:16); saved eip 0x804869a called by frame at 0xb75f73b0 source language c++. Arglist at 0xb75f7388,…
Dew
  • 631
  • 1
  • 6
  • 4
59
votes
3 answers

Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.47.el6_2.9.i686 libgcc-4.4.6-3.el6.i686 libstdc++-4.4.6-3.el6.i686

CentOS 6.2 + GNU gdb (GDB) Red Hat Enterprise Linux (7.2-50.el6) When I debug a simple c++ code with GDB, I saw the following warning: Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.47.el6_2.9.i686 libgcc-4.4.6-3.el6.i686…
q0987
  • 34,938
  • 69
  • 242
  • 387
58
votes
2 answers

How to close layout SRC windows in gdb?

When debugging with GDB, i usually using layout src to check my code. But when i open it, i don't know how to close it. It seems that there are some other layout, and when open a new layout, it will split the window, but i still can not found a…
Frank Cheng
  • 5,928
  • 9
  • 52
  • 80
58
votes
10 answers

no debugging symbols found when using gdb

GNU gdb Fedora (6.8-37.el5) Kernal 2.6.18-164.el5 I am trying to debug my application. However, everytime I pass the binary to the gdb it says: (no debugging symbols found) Here is the file output of the binary, and as you can see it is not…
ant2009
  • 27,094
  • 154
  • 411
  • 609