tags:

views:

262

answers:

2

howdy. i'd like to have gdb immediately run the executable, as if i'd typed "run". (motivation: i dislike typing "run")

one way is to can pipe the command to gdb like this: echo run | gdb myApp but the problem with this approach is that you lose interactivity with gdb. eg, if a breakpoint triggers or myApp crashes, gdb quits. this method is discussed here: http://stackoverflow.com/questions/322110/invoke-gdb-to-automatically-pass-arguments-to-the-program-being-debugged

looking at the options in --help i don't see a way to do this, but perhaps i'm missing something.

tia, orion

+1  A: 

I would use a gdb-script:

gdb -x your-script

where your-script contains something like:

file a.out
b main
r

afterwards you have the normal interactive gdb prompt

EDIT:

here is an optimization for the truly lazy:

  1. save the script as .gdbinit in the working directory.
  2. Afterwards you simply run gdb as

    gdb

... and gdb automatically loads and executes the content of .gdbinit.

hey thanks for the answer.that looks like just what i want except i don't get the gdb prompt, i get gdb being suspended and i'm back at the command line as if i'd typed "ctrl-z". if i "fg", then gdb resumes and the app runs.this is OS X.
orion elenzil
orion: mmmh - that's surprising to me. Works well with every UNIX flavor I am actually using (Linux, Solaris, AIX). What gdb version you are using?
A: 
gdb -ex run ./a.out

EDIT: Orion says this doesn't work on Mac OSX.

The -ex flag has been available since GDB-6.4 (released in 2005), but OSX uses Apple's fork of GDB, and the latest XCode for Leopard contains GDB 6.3.50-20050815 (Apple version gdb-967), so you are out of luck.

Building current GDB-7.0.1 release is one possible solution. Just be sure to read this.

Employed Russian
thanks for the answer.that line behaves the same as just "gdb ./a.out" for me tho.
orion elenzil