Search code examples
pythonpdb

start pdb in post mortem mode. any trick to avoid typing "c"


I'd like to create a small helper (e.g. a shell function), that allows me to call any python script in pdb post mortem mode.

withpdb() {
    cmd="$1" ; shift
    python -m pdb -- "$(which $cmd)" "$@"
}

So if I typed for example

mycmd.py param1 param2

and I encounter errors, that I want to analyze with pydb. I just go up in my bash history and prefix with withpdb

withpbd mycmd.py param1 param2

Now pdb is started with my script and as soon as I press c and return the script starts.

My question is: Is there any trick to avoid typing the initial "c" + enter?

If I have to write some wrapper code in python or another alngauge, that's also OK


Solution

  • Use the -c option to execute c upon startup. (And since you only have to write the function once, use continue instead of the abbreviation for clarity.)

    withpdb() {
      cmd="$1" ; shift
      python -m pdb -c continue -- "$(which $cmd)" "$@"
    }