-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp
More file actions
323 lines (303 loc) · 10 KB
/
Copy pathp
File metadata and controls
323 lines (303 loc) · 10 KB
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#!/usr/bin/bash
#
# to run this file: ./p
#
# nvim tips:
# switch between source/header: F2
# search files: ctrl-f, alt-f
# search strings: ctrl-g, alt-g, /
# folding/unfolding: z Shift+m, z Shift+r
# lsp: ,l
# find/replace:
# project: ambr <src> <dst> <path>
# current buffer: :%s/akoman/zagros/g
menu () {
commands=(
# debug
"build(debug)" "gdb" "run(debug)" "clean(debug)"
# release
"build(release)" "run(release)" "clean(release)"
# documentation
"doxygen(generate)"
"doxygen(show)"
# static analyzer
"cppcheck(generate)"
"cppcheck(show)"
"frama-c" "frama-c (eva)" "ivette (eva)" "frama-c-gui (eva)"
# code coverage
"lcov"
"gcovr"
"genhtml"
"show lcov report"
"kcov(generate)"
"kcov(show)"
# we can't use lcov, gcov, gcovr(requires: gcc-multilib) with zagros, because these tools asks us to re-compile zagros with:
# --coverage -fprofile-arcs -ftest-coverage
# linker flags: -L/usr/lib/gcc/x86_64-unknown-linux-gnu/14.2/32/ -lgcov
# which is not possible. because there's no libc compiled with zagros. it's statically linked.
# but we can use them for zagros_test
# trace/profile
"valgrind(memcheck)" "callgrind" "kcachegrind" "cachegrind" "helgrind" "massif" "ms_print" "drd" "dhat" "dhat(cat)" "bbv" "bbv(cat)"
"perf"
"uftrace replay"
"uftrace record"
"uftrace dump"
"uftrace report"
"uftrace info"
"uftrace graph"
"uftrace tui"
# we can't use libasan as compiler flag. (-fsanitize=address) and as linker flag (-L/usr/lib32 -lasan),
# since zagros is statically linked and this flag needs libc compiled with zagros.
# we can't use uftrace, because of many reasons:
# 1. it just works with dynamically linked binaries. zagros is statically linked, so uftrace can't work with it.
# 2. it needs to pass -pg to compiler option, and this requires mcount from clib. but we're building our kernel without libc!
# 3. even with -finstrument-functions, our binary is still static. so uftrace can't work!
# alternative: manual tracing using this macro for each function:
# #define TRACE_ENTER() do { asm volatile("syscall" : : "a"(1), "D"(1), "S"("Entering " __func__ "\n"), "d"(strlen("Entering " __func__ "\n")) : "rcx", "r11", "memory"); } while(0) // Raw write syscall// Add TRACE_ENTER() at function starts; similar for exit.
# binary analyse
"ldd" "objdump" "strings" "nm" "readelf" "addr2line" "size" "file" "xxd"
# util
"scc" "search" "search/replace")
selected=$(printf '%s\n' "${commands[@]}" | fzf --header="project:")
case $selected in
"build(debug)")
echo ">>> creating build/debug directory"
mkdir -p build/debug
echo ">>> compiling (debug mode)"
bear -- cc -g -O0 -Wall -Wextra -pedantic -std=c11 --coverage -lSDL2 -lSDL2_ttf -lm -o build/debug/rokh lib/util/*.c lib/*.c example/*.c
echo ">>> transfering assets to build/debug"
cp assets/*.ttf build/debug
;;
"run(debug)")
cd build/debug
./rokh
cd ../..
;;
"gdb")
cd build/debug
gdb --tui rokh
cd ../..
;;
"clean(debug)")
echo ">>> cleaning build/debug directory"
rm -r build/debug/*
;;
"build(release)")
echo ">>> creating build/release directory"
mkdir -p build/release
echo ">>> compiling (release mode)"
cc -O3 -Wall -Wextra -pedantic -std=c11 --coverage -lSDL2 -lSDL2_ttf -lm -o build/release/rokh lib/util/*.c lib/*.c example/*.c
echo ">>> transfering assets to build/release"
cp assets/*.ttf build/release
;;
"run(release)")
echo ">>> running rokh (release)"
cd build/release
./rokh
cd ../..
;;
"clean(release)")
echo ">>> cleaning build/release directory"
rm -r build/release/*
;;
"doxygen(generate)")
doxygen
;;
"doxygen(show)")
~/software/brave/brave-browser-1.82.161-linux-amd64/brave ./docs/doxygen/html/index.html
;;
"cppcheck")
rm report/*
# --suppressions-list=suppress.txt
# Suppress a specific warning. The format of <spec> is: [error id]:[filename]:[line].
# - The [filename] and [line] are optional.
# - [error id] may be * to suppress all warnings (for a specified file or files).
# - [filename] may contain the wildcard characters * or ?.
cppcheck --addon=cppcheck/misra.json --addon=cppcheck/findcasts.json --addon=cppcheck/misc.json --addon=cppcheck/y2038.json --addon=cppcheck/threadsafety.json --inline-suppr --std=c11 --enable=all --error-exitcode=1 --platform=unix64 --report-type=misra-c-2012 -q --xml --xml-version=2 lib/util/*.c lib/*.c example/*.c -I lib/util/ > report/cppcheck.xml 2>&1
cppcheck-htmlreport --file=report/cppcheck.xml --title="rokh" --report-dir=report --source-dir=.
;;
"cppcheck(show)")
~/software/brave/brave-browser-1.82.161-linux-amd64/brave ./report/index.html
#xdg-open report/index.html
;;
"frama-c")
frama-c -json-compilation-database compile_commands.json example/* lib/* lib/util/*
;;
"frama-c (eva)")
frama-c -json-compilation-database compile_commands.json example/* lib/* lib/util/* -eva -eva-precision 11
;;
"ivette (eva)")
ivette -json-compilation-database compile_commands.json example/* lib/* lib/util/* -eva -eva-precision 11
;;
"frama-c-gui (eva)")
frama-c-gui -json-compilation-database compile_commands.json example/* lib/* lib/util/* -eva -eva-precision 11
;;
"lcov")
# https://wiki.cs.jmu.edu/student/gcov/start
./build/debug/rokh
lcov --capture --directory build/debug --output-file build/debug/coverage.info
;;
"gcovr")
gcovr build/debug
;;
"genhtml")
genhtml build/debug/coverage.info --output-directory build/debug/coverage_report
;;
"show lcov report")
~/software/brave/brave-browser-1.82.161-linux-amd64/brave ./build/debug/coverage_report/index.html
# xdg-open unit_test/build/coverage_report/index.html
;;
"kcov(generate)")
rm -r coverage/*
kcov coverage/ build/debug/rokh
;;
"kcov(show)")
~/software/brave/brave-browser-1.82.161-linux-amd64/brave ./coverage/index.html
# xdg-open coverage/index.html
;;
"llvm-cov")
;;
"valgrind(memcheck)")
valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all --track-origins=yes --xtree-leak=yes -s -v build/debug/rokh
;;
"callgrind")
valgrind --tool=callgrind --dump-instr=yes --collect-jumps=yes -s -v build/debug/rokh
;;
"kcachegrind")
ls callgrind.out.* cachegrind.out.* | fzf --header="kcachgrind: " | xargs kcachegrind
;;
"cachegrind")
valgrind --tool=cachegrind --cache-sim=yes --branch-sim=yes -s -v build/debug/rokh
;;
"helgrind")
valgrind --tool=helgrind -s -v build/debug/rokh
;;
"massif")
valgrind --tool=massif -s -v build/debug/rokh
;;
"ms_print")
ls massif.out.* | fzf --header="ms_print: " | xargs ms_print
;;
"drd")
valgrind --tool=drd --trace-fork-join=yes --trace-mutex=yes --trace-semaphore=yes -s -v build/debug/rokh
;;
"dhat")
valgrind --tool=dhat -s -v build/debug/rokh
;;
"dhat(cat)")
ls dhat.out.* | fzf --header="dhat: " | xargs cat | less
;;
"bbv")
valgrind --tool=exp-bbv -s -v build/debug/rokh
;;
"bbv(cat)")
ls bb.out.* | fzf --header="bbv: " | xargs cat | less
;;
"perf")
ls build/debug | fzf --header="perf: " | xargs perf stat -d
;;
"uftrace record(test)")
uftrace --srcline -a --symbols --time --no-libcall --symbols -F __clove_symint___UtilSuite* record build/debug/rokh
;;
"uftrace replay(tests)")
uftrace replay
;;
"uftrace dump(test)")
uftrace dump --chrome > dump.json
echo "load dump.json in chrome://tracing/"
;;
"uftrace report(test)")
uftrace report
;;
"uftrace info(test)")
uftrace info
;;
"uftrace graph(test)")
uftrace graph
;;
"uftrace tui(test)")
uftrace tui
;;
"lttng")
;;
"gprof")
;;
"ldd")
ls build/*.bin build/obj/* | fzf --header="objdump: " | xargs ldd | less -N
;;
"objdump")
ls build/*.bin build/obj/* | fzf --header="objdump: " | xargs objdump -x -d -p -f -a -t -r | less -N
;;
"strings")
ls build/debug/* | fzf --header="strings: " | xargs strings | less -N
;;
"nm")
ls build/debug/* | fzf --header="nm: " | xargs nm -l -n --synthetic | less -N
;;
"readelf")
ls build/*.bin build/obj/* | fzf --header="readelf: " | xargs readelf -a -h -g -t -s -d | less -N
;;
"addr2line")
file=$(ls build/*.bin build/obj/* | fzf --header="Select ELF file for addr2line")
echo "Enter the memory address:"; read -r addr;
addr2line -f -a -e $file $addr
;;
"size")
ls build/*.bin build/obj/* | fzf --header="size: " | xargs size --common -t -d -A | less -N
;;
"file")
ls build/*.* build/obj/* | fzf --header="file type: " | xargs file
;;
"xxd")
ls build/*.bin build/*.iso build/obj/* unit_test/build/*.o | fzf --header="xxd: " | xargs xxd | less
;;
"scc")
scc -p -a -u -i c,h,md,cpp,c++,hpp,txt,json,s,ld
;;
"search")
read -p "keyword: " p_keyword; rg "$p_keyword" ;;
"search/replace")
read -p "to_search: " to_search
read -p "to_replace: " to_replace
ambr "$to_search" "$to_replace" ;;
"elfedit")
;;
"strip")
;;
"objcopy")
;;
"ranlib")
;;
"gcc-ar")
;;
"gcc-nm")
;;
"gcc-ranlib")
;;
"gcov")
;;
"gcov-dump")
;;
"gcov-tool")
;;
"gprof")
;;
"gprofng")
;;
"gprofng-archive")
;;
"gprofng-collect-app")
;;
"gprofng-display-html")
;;
"gprofng-display-src")
;;
"gprofng-display-text")
;;
*) ;;
esac
}
if [ $# -eq 0 ]; then
menu
fi
"$@"