-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.sh
191 lines (180 loc) · 6.07 KB
/
project.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/usr/bin/bash
################################################################################
# zaal
################################################################################
# There's a __project.sh__ at the root. load it first: `. project.sh`
#
# tools:
# static code analyzer:
# - c: splint, cppcheck
# memory debugger: valgrind
# system call tracer: strace
# display info about .obj files: objdump
# diff between two files/dirs: delta <DIR1> <DIR2>
#
# opening/editing files: noevim
# folding/unfolding: z Shift+m, z Shift+r
# switch between source/header: F2
#
# lookup refrences: lsp, ctags
# find/replace in single file: neovim
# find/replace in whole project: ambr <source_text> <dest_text>
# find files: ctrl-t | ff <file-name> | fzf | fd
# find string/text in single file: neovim (/)
# find string/text in whole project: ft <text> | rg <text>
# find docs of c standard librariy:
# - install man-pages-devel and man <method>
# - zeal
# - www.devdocs.io
#
# debuggers: gf2, gdb
################################################################################
app=""
compiler="cc"
flags="-Wall -Wextra -Wpedantic -Wformat=2 -Wno-unused-parameter -Wshadow
-Wwrite-strings -Wstrict-prototypes -Wold-style-definition -Wredundant-decls
-Wnested-externs -Wmissing-include-dirs
-Wjump-misses-init -Wlogical-op"
src="src/*.c"
mode="debug"
build_dir="build/$mode"
mode_flags=""
if [ "$mode" == "debug" ]; then
app="zaal"
mode_flags="-g -pg -O0 -DDEBUG"
fi
if [ "$mode" == "release" ]; then
app="zaal"
mode_flags="-O3 -pg"
fi
if [ "$mode" == "test" ]; then
app="zaal_test"
fi
_generateTags() {
echo ">>> generating tags"
ctags --fields=+iaSl --extras=+q --extras=+f --sort=yes -R src/*
}
p() {
commands=("build" "debug" "run" "build type" "clean" "generate tags"
"search" "search/replace"
"linter - splint" "linter - cppcheck" "valgrind"
"uftrace" "nm - list symbols from object files" "ldd - print shared object dependencies"
"objdump -S: Intermix source code with disassembly"
"objdump -g: Display debug information in object file"
"objdump -d: Display assembler contents of executable sections"
"readelf -h: Display the ELF file header"
"readelf -s:Display the symbol table"
"readelf -d: Display the dynamic section (if present)"
"strace - trace system calls and signals"
"strace -c: Count time, calls, and errors for each system call"
"ltrace: trace library calls"
"strings - print the sequences of printable characters in files"
"size - list section sizes and total size of binary files")
selected=$(printf '%s\n' "${commands[@]}" | fzf --header="project:")
case $selected in
"build")
clear
echo ">>> Creating '$build_dir' directory"
mkdir -p "$build_dir"
_generateTags
echo ">>> Compiling ($mode)"
$compiler $mode_flags $flags -o $build_dir/$app $src
;;
"debug")
echo ">>> Debugging $app - $mode"
selected=$(/bin/ls ./tests/ -p | fzf --header="files:")
gf2 --args ./$build_dir/$app ./tests/$selected &
;;
"run")
clear
echo ">>> Running $app - $mode"
selected=$(/bin/ls ./tests/ -p | fzf --header="files:")
./$build_dir/$app ./tests/$selected
;;
"build type")
build_types=("debug" "release")
build_type_selected=$(printf '%s\n' "${build_types[@]}" | fzf --header="build type:")
case $build_type_selected in
"debug")
sed -i '38,40s/mode="release"/mode="debug"/' project.sh
source ./project.sh;;
"release")
sed -i '38,40s/mode="debug"/mode="release"/' project.sh
source ./project.sh;;
*) ;;
esac
;;
"clean")
clear
echo ">>> Cleaning '$build_dir' directory"
rm -r "$build_dir";;
"generate tags")
clear
_generateTags;;
"search")
clear
read -p "keyword: " p_keyword; rg "$p_keyword" ;;
"search/replace")
clear
read -p "to_search: " to_search
read -p "to_replace: " to_replace
ambr "$to_search" "$to_replace" ;;
"linter - splint")
clear
splint +trytorecover src/*;;
"linter - cppcheck")
clear
cppcheck --enable=all --inconclusive --suppress=missingIncludeSystem --language=c src/;;
"valgrind")
clear
valgrind --leak-check=full --show-leak-kinds=all -s -v $build_dir/$app;; #src/*
"uftrace")
selected=$(/bin/ls ./tests/ -p | fzf --header="files:")
uftrace record ./$build_dir/$app tests/$selected
uftrace tui
;;
"nm - list symbols from object files")
clear
nm $build_dir/$app;;
"ldd - print shared object dependencies")
clear
ldd $build_dir/$app;;
"objdump -S: Intermix source code with disassembly")
clear
objdump ./$build_dir/$app -S | less ;;
"objdump -g: Display debug information in object file")
clear
objdump ./$build_dir/$app -g | less;;
"objdump -d: Display assembler contents of executable sections")
clear
objdump ./$build_dir/$app -d | less;;
"readelf -h: Display the ELF file header")
clear
readelf ./$build_dir/$app -h;;
"readelf -s:Display the symbol table")
clear
readelf ./$build_dir/$app -s;;
"readelf -d: Display the dynamic section (if present)")
clear
readelf ./$build_dir/$app -d;;
"strace - trace system calls and signals")
clear
selected=$(/bin/ls ./tests/ -p | fzf --header="files:")
strace ./$build_dir/$app ./tests/$selected ;;
"strace -c: Count time, calls, and errors for each system call")
clear
selected=$(/bin/ls ./tests/ -p | fzf --header="files:")
strace -c ./$build_dir/$app ./tests/$selected ;;
"ltrace: trace library calls")
clear
selected=$(/bin/ls ./tests/ -p | fzf --header="files:")
ltrace ./$build_dir/$app ./tests/$selected ;;
"strings - print the sequences of printable characters in files")
clear
strings $build_dir/$app ;;
"size - list section sizes and total size of binary files")
clear
size $build_dir/$app ;;
*) ;;
esac
}