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
90
votes
3 answers

What are the best ways to automate a GDB debugging session?

Does GDB have a built in scripting mechanism, should I code up an expect script, or is there an even better solution out there? I'll be sending the same sequence of commands every time and I'll be saving the output of each command to a file (most…
Anonymous
  • 1,750
  • 3
  • 16
  • 21
89
votes
9 answers

How do I show what fields a struct has in GDB?

I came upon a struct (called ngx_http_variable_value_t) in my GDB (debugger) session and I would like to print what fields it has in the console. Is that possible?
prismofeverything
  • 8,799
  • 8
  • 38
  • 53
88
votes
8 answers

Why GDB jumps unpredictably between lines and prints variables as ""?

Can anyone explain this behavior of gdb? 900 memset(&new_ckpt_info,'\0',sizeof(CKPT_INFO)); (gdb) **903 prev_offset = cp_node->offset;** (gdb) **905 m_CPND_CKPTINFO_READ(ckpt_info,(char…
Arpit
  • 4,259
  • 10
  • 38
  • 43
87
votes
3 answers

How to set break point on one file of a project which has many files with same name?

I want to set a break point in gdb on file service.cpp on line 45 and I do: gdb> break service.cpp:45 The problem is that there are many service.cpp files in my application and it is not picking the one I am interested in. How can I specify the…
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
87
votes
5 answers

How to view a pointer like an array in GDB?

Suppose defined: int a[100] Type print a then gdb will automatically display it as an array:1, 2, 3, 4.... However, if a is passed to a function as a parameter, then gdb will treat it as a normal int pointer, type print a will display:(int…
CDT
  • 10,165
  • 18
  • 66
  • 97
86
votes
1 answer

How to disable "Type to continue, or q to quit" in gdb?

I want to automatise gdb, and waiting for the user input is undesirable. How to disable the message "Type to continue, or q to quit" in gdb?
Fábio Perez
  • 23,850
  • 22
  • 76
  • 100
85
votes
5 answers

Stopping at the first machine code instruction in GDB

After loading an executable into gdb, how do I break at the entry point, before the first instruction is executed? The executable I'm analyzing is a piece of malware that's encrypted so break main does absolutely nothing.
rickythefox
  • 6,601
  • 6
  • 40
  • 62
84
votes
6 answers

GDB: Listing all mapped memory regions for a crashed process

I've got a full-heap core dump from a dead process on an x86 Linux machine (kernel 2.6.35-22 if it matters), which I'm attempting to debug in GDB. Is there a GDB command I can use that means "show me a list of all the memory address regions…
Crashworks
  • 40,496
  • 12
  • 101
  • 170
82
votes
5 answers

Get rid of "quit anyway" prompt using GDB: Just kill the process and quit

Consider: (gdb) q A debugging session is active. Inferior 1 [process 9018] will be killed. Quit anyway? (y or n) y What is a .gdbinit option to make GDB always kill the running process at a quit request? I know that GDB can attach to…
kagali-san
  • 2,964
  • 7
  • 48
  • 87
81
votes
3 answers

How to attach a process in gdb

I have a simple C program that forks a process and then runs an executable. I want to attach the child process to gdb. I run the main program in a console and open another console to find the pid of the child process, then I start gdb with the…
as3rdaccount
  • 3,711
  • 12
  • 42
  • 62
80
votes
5 answers

How can I scroll back in GDB's command window in the TUI mode?

Suppose that (gdb) print *this resulted in 20 lines of output. Yes, there would be Type to continue, or q to quit, but I'd like to scroll back to the top after I got to the bottom of the output. I don't think…
nodakai
  • 7,773
  • 3
  • 30
  • 60
79
votes
1 answer

How can I disable new thread/thread exited messages in gdb?

I'm debugging an application, and I get a lot of messages like this: [New Thread 0x7fffde152700 (LWP 11142)] [Thread 0x7fffde152700 (LWP 11142) exited] [New Thread 0x7fff967fa700 (LWP 11143)] [Thread 0x7fff967fa700 (LWP 11143) exited] [New Thread…
Matthew
  • 28,056
  • 26
  • 104
  • 170
77
votes
4 answers

How to use gdb with input redirection?

In the Terminal, I have: myapp < myfileinput But if I want to use gdb, gdb myapp < myfileinput It didn't run correctly. How to use gdb here?
user53670
77
votes
1 answer

Watchpoint a fixed address

For my current embedded application I am trying to put GDB watch point at a fixed memory address. As an example, my application updates the following address: 0x10793ad0. In order to be sure which part of the code is corrupting the value, I tried…
maniac_inside
  • 908
  • 1
  • 7
  • 8
76
votes
3 answers

How to do an specific action when a certain breakpoint is hit in GDB?

I am looking for a way to do some action when a particular break point hits in gdb. Basically I have some memleak in my program. When malloc and free function hits, I need to enter into the function (step) and collect some basic information like…
Thangaraj
  • 3,038
  • 7
  • 40
  • 43