When I stop at a break point in gdb, it just shows the filename.cpp. How can I view the full pathname of this file?
Click the Start button and then click Computer, click to open the location of the desired file, hold down the Shift key and right-click the file. Copy As Path: Click this option to paste the full file path into a document. Properties: Click this option to immediately view the full file path (location).
Firstly, we use the dirname command to find the directory in which a file is located. Then we change the directory using the cd command. Next, we print the current working directory using the pwd command. Here, we have applied the -P option to show the physical location instead of the symbolic link.
GDB has a list of directories to search for source files; this is called the source path. Each time GDB wants a source file, it tries all the directories in the list, in the order they are present in the list, until it finds a file with the desired name.
Use the "file" command. You must compile the program with debug information in order to see the source code while debugging.
Use the info source
command to get info for the current stack frame.
Here is an example of its output:
(gdb) info source Current source file is /build/gtk+2.0-LJ3oCC/gtk+2.0-2.24.30/modules/input/gtkimcontextxim.c Located in /home/sashoalm/Desktop/compile/gtk+2.0-2.24.30/modules/input/gtkimcontextxim.c Contains 1870 lines. Source language is c. Producer is GNU C11 5.3.1 20160225 -mtune=generic -march=i686 -g -g -O2 -O2 -fstack-protector-strong -fPIC -fstack-protector-strong. Compiled with DWARF 2 debugging format. Does not include preprocessor macro info.
In Python scripting
To learn Python scripting, or if you want to see just the full path and nothing else:
class Curpath(gdb.Command): """ Print absolute path of the current file. """ def __init__(self): super().__init__('curpath', gdb.COMMAND_FILES) def invoke(self, argument, from_tty): gdb.write(gdb.selected_frame().find_sal().symtab.fullname() + os.linesep) Curpath()
Usage:
curpath
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With