Search code examples
command-linegdb

gdb --args with --symbols


I would like to start gdb from the command line, giving it a symbol file via --symbols and giving it an executable via --args:

gdb --symbols=/path/to/symbol_file --args /other_path/to/exe arg1 arg2

The problem is that the --args flag must come at the end of the gdb command, since everything following the executable is passed as an argument to the executable. Since, according to the docs, the executable is treated as both the symbol file and executable file (and the core file), it overwrites the symbol file specified by --symbols. This is fixed by doing this instead:

gdb --symbols=/path/to/symbol_file --exec=/other_path/to/exe

Now, however, I can't pass the inferior arguments to the executable. I know it is possible to provide either the symbol file or the inferior arguments after gdb has started using symbol-file or set args, but is there any way to achieve this all with command line arguments?

GNU gdb (GDB) 11.2


Solution

  • This works:

    gdb -q --symbols=/bin/date --exec=/bin/sleep -ex 'set args 60'
    
    Reading symbols from /bin/date...
    
    (gdb) run
    Starting program: /usr/bin/sleep 60
    

    That said, you are probably doing it wrong. See documentation for how to automatically associate the /path/to/symbol_file with the binary.