How to pass arguments and redirect stdin from a file to program run in gdb?
You can do this: gdb –args path/to/executable -every -arg you can=think < of The magic bit being –args. Just type run in the gdb command console to start debugging.
You can do this: gdb –args path/to/executable -every -arg you can=think < of The magic bit being –args. Just type run in the gdb command console to start debugging.
You can switch to assembly layout in GDB: (gdb) layout asm See here for more information. The current assembly instruction will be shown in assembler window. ┌───────────────────────────────────────────────────────────────────────────┐ │0x7ffff740d756 <__libc_start_main+214> mov 0x39670b(%rip),%rax #│ │0x7ffff740d75d <__libc_start_main+221> mov 0x8(%rsp),%rsi │ │0x7ffff740d762 <__libc_start_main+226> mov 0x14(%rsp),%edi │ │0x7ffff740d766 <__libc_start_main+230> mov (%rax),%rdx │ │0x7ffff740d769 <__libc_start_main+233> callq *0x18(%rsp) │ >│0x7ffff740d76d <__libc_start_main+237> mov … Read more
info registers shows all the registers; info registers eax shows just the register eax. The command can be abbreviated as i r
Eclipse CDT will provide an experience comparable to using Visual Studio. I use Eclipse CDT on a daily basis for writing code and debugging local and remote processes. If you’re not familiar with using an Eclipse based IDE, the GUI will take a little getting used to. However, once you get to understand the GUI … Read more
With GCC 4.1.2, to print the whole of a std::vector<int> called myVector, do the following: print *(myVector._M_impl._M_start)@myVector.size() To print only the first N elements, do: print *(myVector._M_impl._M_start)@N Explanation This is probably heavily dependent on your compiler version, but for GCC 4.1.2, the pointer to the internal array is: myVector._M_impl._M_start And the GDB command to print … Read more
Short answer: mkdir -p ~/.config/gdb echo ‘set history save on’ >> ~/.config/gdb/gdbinit Long answer: Command history is covered in the GDB manual, 22.3 Command History. Create a file $HOME/.config/gdb/gdbinit, and add the following line: set history save on You can set the number of past commands saved with the following. The command is described as … Read more
You just need a binary (with debugging symbols included) that is identical to the one that generated the core dump file. Then you can run gdb path/to/the/binary path/to/the/core/dump/file to debug it. When it starts up, you can use bt (for backtrace) to get a stack trace from the time of the crash. In the backtrace, … Read more
watch only breaks on write, rwatch let you break on read, and awatch let you break on read/write. You can set read watchpoints on memory locations: gdb$ rwatch *0xfeedface Hardware read watchpoint 2: *0xfeedface but one limitation applies to the rwatch and awatch commands; you can’t use gdb variables in expressions: gdb$ rwatch $ebx+0xec1a04f Expression … Read more
Type info variables to list “All global and static variable names” (huge list. Type info locals to list “Local variables of current stack frame” (names and values), including static variables in that function. Type info args to list “Arguments of the current stack frame” (names and values).
set print elements 0 From the GDB manual: set print elements number-of-elements Set a limit on how many elements of an array GDB will print. If GDB is printing a large array, it stops printing after it has printed the number of elements set by the set print elements command. This limit also applies to … Read more