Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run gdb on an executable with arguments?

Tags:

gdb

How can I run something like gdb -e path/to/exe -ex 'run --argnamae argvalue'?

Let's assume a recent version of gfb, within the past year or two.

Gdb runs and prints responses but not interactively.

like image 889
John Cashew Avatar asked Feb 02 '26 02:02

John Cashew


2 Answers

I think you want gdb --args path/to/exe command line arguments

which will start gdb debugging path/to/exe pass three command line arguments to your exe command, line, and arguments, you can then interact with gdb before issuing the run command.

As for the ImportError: No module named 'libstdcxx' I believe this is already answered here which points to a bug report here.

It appears some versions of GCC have a broken pretty printers python script, you might need to adjust the python sys.path with (gdb) python sys.path.append("/usr/share/gcc-4.8/python"), adjust the path to match whatever GCC version is actually present on your system. You could probably add a command like this to your .gdbinit file to save typing it every time.

like image 101
Andrew Avatar answered Feb 04 '26 22:02

Andrew


How can I run something like ...

You can do this:

gdb path/to/exe -ex 'set args arg1 arg2 arg3'

Or use a shorthand notation for the above:

gdb --args path/to/exe arg1 arg2 arg3
like image 35
Employed Russian Avatar answered Feb 04 '26 23:02

Employed Russian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!