gdb - list source of current function without typing its name
(gdb) help list
List specified function or line.
With no argument, lists ten more lines after or around previous listing.
"list -" lists the ten lines before a previous ten-line listing.
One argument specifies a line, and ten lines are listed around that line.
Two arguments with comma between specify starting and ending lines to list.
Lines can be specified in these ways:
LINENUM, to list around that line in current file,
FILE:LINENUM, to list around that line in that file,
FUNCTION, to list around beginning of that function,
FILE:FUNCTION, to distinguish among like-named static functions.
*ADDRESS, to list around the line containing that address.
With two args if one is empty it stands for ten lines away from the other arg.
The *ADDRESS
is what is interesting.
On x86/x64 current pointer is in rip
register so:
(gdb) list *$pc
0x7ffff7b018a0 is at ../sysdeps/unix/syscall-template.S:82.
77 in ../sysdeps/unix/syscall-template.S
The example is from cat
command as I don't have anything with debug info at hand.
GNU gdb how to show source file name and lines of a symbol
Use info line
command.
info line oyss_function
For example, assume the file test.c
contains:
#include <stdio.h>
int main(void)
{
printf("\n");
return 0;
}
Then, invoking info line main
in GDB gets:
(gdb) info line main
Line 4 of "test.c" starts at address 0x400498 <main> and ends at 0x40049c <main+4>.
Is there a quick way to display the source code at a breakpoint in gdb?
You can use the list
command to show sources. list
takes a "linespec", which is gdb terminology for the kinds of arguments accepted by break
. So, you can either pass it whatever argument you used to make the breakpoint in the first place (e.g., list function
) or you can pass it the file and line shown by info b
(e.g., list mysource.c:75
).
How to get GDB to show the source code while debugging?
gdb find . -type d | xargs printf " -d %s"
prog
worked for me eventually. This supplies the directories recursively to gdb.
Found it here - https://titanwolf.org/Network/Articles/Article?AID=e61837e2-2ccc-4cce-80c8-3c8555aeacbd#gsc.tab=0
Now i am able to see the source code like how i wanted to :-)
Can I use gdb to skip a line without having to type line numbers?
jump +1
jumps to the next line line i.e. skipping the current line. You may also want to combine it with tbreak +1
to set a temporary breakpoint at the jump target.
See http://sourceware.org/gdb/current/onlinedocs/gdb/Specify-Location.html for more ways of expressing locations with gdb.
Note that without a breakpoint gdb
is likely to continue execution normally instead of jumping. So if jumping doesn't seem to work, make sure you set a breakpoint at the destination.
Related Topics
How to Create a Temporary Text File in C++
Std::Lower_Bound Slower for Std::Vector Than Std::Map::Find
Does the Evil Cast Get Trumped by the Evil Compiler
Can a Lambda Capturing Nothing Access Global Variables
Std::Locale Breakage on MACos 10.6 with Lang=En_Us.Utf-8
Std::Chrono::System_Clock::Now() Considering The Os Configured Time Zone
How to Properly Setup Googletest on Os X Aside from Xcode
Libstdc++ Glibcxx Version Errors
Warning: Narrowing Conversion C++11
A Better Way to Split a String into an Array of Strings in C/C++ Using Whitespace as a Delimiter
Are End+1 Iterators for Std::String Allowed
Breaking Readfile() Blocking - Named Pipe (Windows API)
Observer Design Pattern in C++
C++ What Happens When in One Thread Write and in Second Read the Same Object? (Is It Safe)
Capturing Cout in Visual Studio 2005 Output Window