-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdbg
More file actions
executable file
·35 lines (28 loc) · 803 Bytes
/
dbg
File metadata and controls
executable file
·35 lines (28 loc) · 803 Bytes
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
#!/bin/sh
if [ -z "$1" ]; then
echo "Usage: $0 src.c" 1>&2
echo " $0 executable" 1>&2
echo " $0 executable core" 1>&2
exit 1
fi
executable=$(basename "$1" '.c')
if [ "$1" != "$executable" ]; then
should_compile=true
fi
if [ -z "$2" ]; then
set_breakpoint=true
fi
if [ "$should_compile" = true ]; then
gcc -std=c11 -g \
-Wall -Wextra -Wpedantic -Werror \
-Wfloat-equal -Wlogical-op -Wshadow -Wswitch-default \
-Wbad-function-cast -Wcast-qual -Waggregate-return \
-fno-diagnostics-show-option "$1" -o "$executable" \
|| exit $?
fi
if [ "$set_breakpoint" = true ]; then
gdb "$executable" -ex 'break main' -ex run -ex list
else
gdb "$executable" "$2"
fi
trap 'test "$should_compile" = true && rm "$executable"' EXIT