gdb.info: Source Path

Go forward to Machine Code
Go backward to Search
Go up to Source
Go to the top op gdb

Specifying source directories

Executable programs sometimes do not record the directories of the
source files from which they were compiled, just the names.  Even when
they do, the directories could be moved between the compilation and
your debugging session.  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.
   For example, suppose an executable references the file
`/usr/src/foo-1.0/lib/foo.c', and our source path is `/mnt/cross'.  The
file is first looked up literally; if this fails,
`/mnt/cross/usr/src/foo-1.0/lib/foo.c' is tried; if this fails,
`/mnt/cross/foo.c' is opened; if this fails, an error message is
printed.  GDB does not look up the parts of the source file name, such
as `/mnt/cross/src/foo-1.0/lib/foo.c'.  Likewise, the subdirectories of
the source path are not searched: if the source path is `/mnt/cross',
and the binary refers to `foo.c', GDB would not find it under
`/mnt/cross/usr/src/foo-1.0/lib'.
   Plain file names, relative file names with leading directories, file
names containing dots, etc. are all treated as described above; for
instance, if the source path is `/mnt/cross', and the source file is
recorded as `../lib/foo.c', GDB would first try `../lib/foo.c', then
`/mnt/cross/../lib/foo.c', and after that--`/mnt/cross/foo.c'.
   Note that the executable search path is _not_ used to locate the
source files.  Neither is the current working directory, unless it
happens to be in the source path.
   Whenever you reset or rearrange the source path, GDB clears out any
information it has cached about where source files are found and where
each line is in the file.
   When you start GDB, its source path includes only `cdir' and `cwd',
in that order.  To add other directories, use the `directory' command.
`directory DIRNAME ...'
`dir DIRNAME ...'
     Add directory DIRNAME to the front of the source path.  Several
     directory names may be given to this command, separated by `:'
     (`;' on MS-DOS and MS-Windows, where `:' usually appears as part
     of absolute file names) or whitespace.  You may specify a
     directory that is already in the source path; this moves it
     forward, so GDB searches it sooner.
     You can use the string `$cdir' to refer to the compilation
     directory (if one is recorded), and `$cwd' to refer to the current
     working directory.  `$cwd' is not the same as `.'--the former
     tracks the current working directory as it changes during your GDB
     session, while the latter is immediately expanded to the current
     directory at the time you add an entry to the source path.
`directory'
     Reset the source path to empty again.  This requires confirmation.
`show directories'
     Print the source path: show which directories it contains.
   If your source path is cluttered with directories that are no longer
of interest, GDB may sometimes cause confusion by finding the wrong
versions of source.  You can correct the situation as follows:
  1. Use `directory' with no argument to reset the source path to empty.
  2. Use `directory' with suitable arguments to reinstall the
     directories you want in the source path.  You can add all the
     directories in one command.