Running programs in gdb

Here are a few tips on gdb.

Run foo with python-generated output:

$ ./foo `python -c 'print("hello")'`
$ ./foo $(python -c 'print("hello")') # same thing
$ python -c 'print("hello")' | ./foo # is this different? Hmmm.

You can also do this in gdb:

$ gdb ./foo
...
(gdb) set args $(python -c 'print("A"*32)')

Do you want to generate a really long line? Just use python:

$ python -c 'print("A"*32)'

Perhaps you want to write a really long line followed by some hex thingy, like an address?

$ python -c 'print("A"*1024 + "\xff\xee\xcc\xbb")

There are numerous gdb tutorials online. Here is a quick read with some essentials:
http://www.cs.toronto.edu/~krueger/csc209h/tut/gdb_tutorial.html

1 Like