Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to view the full path of a file in GDB?

Tags:

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?

like image 414
aaa Avatar asked Feb 01 '11 01:02

aaa


People also ask

How do I get the path of a 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).

How do you find the full path of a file in Linux?

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.

How does GDB find source files?

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.

Which command is used to display the source code for the current file?

Use the "file" command. You must compile the program with debug information in order to see the source code while debugging.


2 Answers

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.
like image 97
andy Avatar answered Nov 12 '22 09:11

andy


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