forked from dilawar/Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gdbrun.sh
executable file
·40 lines (29 loc) · 986 Bytes
/
gdbrun.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
#http://paraview.org/Wiki/CMake_Platform_Dependent_Issues
#The following is an extremely useful script that will run any command line in a gdb debugger. Put this text in an executable file called "gdbrun":
# Then one may be able to debug as-such:
# gdbrun /path/to/myexe --some-arg --some-other-arg
#Notes about this script:
# * It supports spaces in argument names (note the for loop)
# * Takes extra argument --break-main, which causes the program to stop once all the libraries are loaded
# * It always run debugger, even when program exits normally
# * Cannot be used with MPI or any other system that runs your program from a shell script
extra_text=""
if [ "$1" == "--break-main" ]; then
extra_text="break main"
shift
fi
EXEC="$1"
shift
run_text="run"
for a in "$@"; do
run_text="${run_text} \"$a\""
done
TMPFILE=/tmp/gdbrun.$$.$#.tmp
cat > ${TMPFILE} <<EOF
${extra_text}
${run_text}
EOF
gdb -x ${TMPFILE} "${EXEC}"
rm -f "${TMPFILE}"
#