Search code examples
gdbsearch-path

Is current directory always in the search path of gdb


I noticed that when I use gdb I can use either

$ gdb ./main

or

$ gdb main

Is the current directory guaranteed to be in the search path of gdb?


Solution

  • Yes. GDB will first try to access the file exactly as specified, so in this case as a relative path from the current directory. In both of these cases you'll find main. This will obviously also work if you give an absolute path, like: gdb /path/to/main.

    If the file can't be found exactly as specified then GDB will search the environment $PATH just like a shell will, so gdb main will hunt for main along your $PATH, but gdb foo/main will not find main under foo along your $PATH.