Skip to content

Instantly share code, notes, and snippets.

@hilbix
Created September 2, 2018 15:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hilbix/f375b4019ac68244c079f54c339f0729 to your computer and use it in GitHub Desktop.
Save hilbix/f375b4019ac68244c079f54c339f0729 to your computer and use it in GitHub Desktop.
No-Brainer function to debug with `gdb` from shell level
# This function keeps IO redirection and commandline arguments
# when you want to debug some executable.
#
# Just type "debug" in front of the call:
# "b u g" "${p[@]}" < <(in) 1> >(out) 2> >(two) 3> >(three)
# debug "b u g" "${p[@]}" < <(in) 1> >(out) 2> >(two) 3> >(three)
#
# All you need is a /dev/tty
debug()
{
1000<&0 1001>&1 1002>&2 \
0</dev/tty 1>/dev/tty 2>&0 \
/usr/bin/gdb -q -nx -nw \
-ex 'set exec-wrapper /bin/bash -c "exec 0<&1000 1>&1001 2>&1002 \"\$@\"" exec' \
-ex r \
--args "$@";
}
@hilbix
Copy link
Author

hilbix commented Sep 2, 2018

See Stackoverflow

And I currently realize, that this probably can be expressed as shell alias as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment