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

How can I get GDB to tell me what address caused a segfault?

I'd like to know if my program is accessing NULL pointers or stale memory. The backtrace looks like this: Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x2b0fa4c8 (LWP 1333)] 0x299a6ad4 in pthread_mutex_lock () from…
nornagon
  • 15,393
  • 18
  • 71
  • 85
57
votes
1 answer

GDB: How to list all source files used for compilation

New to the project, have multiple source files used for compilation and some "could" be dynamic libraries, loaded at runtime. When debugging the executable using "GDB", is there a command to list all the source files (static) used to build the…
Mike
  • 1,205
  • 3
  • 12
  • 21
57
votes
1 answer

How to list all variables in the current context in gdb?

In gdb, after reaching a breakpoint, I want to list all the variables in the current context, instead of giving each variable name explicitly? Is there any way to achieve this at all?
Hailiang Zhang
  • 17,604
  • 23
  • 71
  • 117
56
votes
8 answers

Line number of segmentation fault

Is there any gcc option I can set that will give me the line number of the segmentation fault? I know I can: Debug line by line Put printfs in the code to narrow down. Edits: bt / where on gdb give No stack. Helpful suggestion
Rohit
  • 1,710
  • 5
  • 20
  • 29
56
votes
2 answers

gdb, set breakpoint on all functions in a file

Is there a single command in gdb which can set breakpoints on all the functions in a given file ? I know about rbreak regex which sets breakpoints in matching regular expression functions, but my file doesnt have fixed patterned functions. In…
Smash
  • 839
  • 1
  • 9
  • 10
55
votes
6 answers

How to print variable in gdb

Sometimes gdb prints "incomplete type" for some type of variables. What does this mean and how can we see that value?
grigy
  • 6,696
  • 12
  • 49
  • 76
55
votes
24 answers

What tools do you use to develop C++ applications on Linux?

I develop C++ applications in a Linux environment. The tools I use every day include Eclipse with the CDT plugin, gdb and valgrind. What tools do other people use? Is there anything out there for Linux that rivals the slickness of Microsoft Visual…
Clayton
  • 6,089
  • 10
  • 44
  • 47
54
votes
1 answer

Is it possible to debug a gcc-compiled program using lldb, or debug a clang-compiled program using gdb?

(Preface: I'm pretty new to C/C++ and I don't really know how debugging in native code actually works.) Some sources say that gdb and lldb can debug any program compiled to machine code. Others say that to debug with gdb you must compile in gcc with…
Neil Traft
  • 18,367
  • 15
  • 63
  • 70
53
votes
1 answer

Terminate program hitting CTRL+C within GDB

My program is determined to stop its execution by hitting CTRL+C in command window. By now, I have a critical error right in this stopping phase, so i want to debug with gdb. Problem is, gdb redefines CTRL+C as its own interrupt and pauses the…
Benjamin
  • 1,143
  • 1
  • 14
  • 29
53
votes
5 answers

How to get the symbol name for a memory address in GDB?

For instance, I know that 0x46767f0 belongs to an NSString*, is there any way I can find out what NSString it is to help me find some bugs I'm after?
Coocoo4Cocoa
  • 48,756
  • 50
  • 150
  • 175
52
votes
4 answers

Why gdb casting is not working?

I use print (CEthPacket*) 0xeb609a0 to examine an object at the given address and get A syntax error in expression, near ') 0xeb609a0'. What am I doing wrong? EDIT: CEthPacket is a C++ class and I'm on gdb Fedora (6.8-37.el5).
jackhab
  • 17,128
  • 37
  • 99
  • 136
51
votes
6 answers

In Clion's debugger, how do I show the entire contents of an int array

Right now it is only showing the first element of the array but I want a visual of all the elements in the array. I think Clion is using GDB. EDIT: I am referring specifically to arrays on the heap. Arrays on the stack can be visualised.
Embedded_Mugs
  • 2,132
  • 3
  • 21
  • 33
50
votes
5 answers

How do I view the value of an variable in C++?

I am using gdb to debug a C++ program. I have this code: int x = floor(sqrt(3)); and I want to view the value of x. However, gdb claims that x is "< optimized_out >". How do I view the value of x? Should I change my compiler flags?
dangerChihuahua007
  • 20,299
  • 35
  • 117
  • 206
50
votes
1 answer

gdb: How do I pause during loop execution?

I'm writing a software renderer in g++ under mingw32 in Windows 7, using NetBeans 7 as my IDE. I've been needing to profile it of late, and this need has reached critical mass now that I'm past laying down the structure. I looked around, and to me…
Engineer
  • 8,529
  • 7
  • 65
  • 105
50
votes
1 answer

gdb in docker container returns "ptrace: Operation not permitted."

I've checked /proc/sys/kernel/yama/ptrace_scope in the container and on the host - both report the value as zero but when attached to pid one gdb reports Reading symbols from /opt/my-web-proxy/bin/my-web-proxy...done. Attaching to program:…
Adrian Cornish
  • 23,227
  • 13
  • 61
  • 77