Skip to content

Commit

Permalink
advanced debugging functions inlcuding breakpoint
Browse files Browse the repository at this point in the history
also help documentation and commandline autostart
  • Loading branch information
jaromil committed Nov 12, 2023
1 parent 22ae6f2 commit 863b927
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 36 deletions.
114 changes: 81 additions & 33 deletions src/breakroom/breakroom
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Breakroom main script

exitcode=0

_success() {
echo "[*] " "$1" "$2" "$3" "$4" 1>&2
}
Expand Down Expand Up @@ -40,19 +41,20 @@ fi
_success "Welcome to Breakroom, the Zencode debugger"

bconf=breakroom.conf
if ! [ -r $bconf ]; then
_message "Configuration not found, starting new"
_clearconf() {
cat <<EOF > $bconf
# running breakroom in `pwd`
script=0
conf=""
conf=0
keys=0
data=0
extra=0
break=0
EOF
else
cat $bconf | grep -v '=0$'
}
if ! [ -r $bconf ]; then
_message "Configuration not found, starting new"
_clearconf
fi

_setconf() {
Expand All @@ -75,17 +77,75 @@ _setjson() {
fi
}

if [ -r "${1}" ]; then
_setconf script ${1}
[ -r "${2}" ] && _setconf keys "${2}"
[ -r "${3}" ] && _setconf data "${3}"
[ -r "${4}" ] && _setconf extra "${4}"
fi
if [ "$1" = "-h" ]; then
_message "Command synopsis:"
_message " breakroom [ ⚡zencode ] [ 🔡data ] [ 🔢keys ] [ 🔣extra ]"
_message "Interactive console usage commands:"
_message " run ▶️ execute the current zencode configuration"
_message " list 📃 show the current zencode script and breakpoints"
_message " clear 🧹 reset all the breakroom configuration"
_message " trace 🧭 show the backtrace of current execution"
_message " heap 💾 show the HEAP of current execution"
_message " codec 🗃️ show the CODEC of Given scope execution"
_message " script [file] ⚡ get/set the zencode script file"
_message " data [file] 🔡 get/set the data JSON input file"
_message " keys [file] 🔢 get/set the keys JSON input file"
_message " extra [file] 🔣 get/set the extra JSON input file"
_message " conf [string] 🔤 get/set the zenroom conf string"
_message " break [int] 🚫 set a breakpoint at line number"
exit 0
fi

# Show current configuration
cat $bconf | grep -v '=0$'

_getJ64() {
what="$1"
if ! [ -r breakroom.exec.stderr ]; then
_error "Stderr execution log not found"
else
_message "$what:"
awk '/J64 '"$what"':/ {print(substr($3,1,length($3)-2))}' \
breakroom.exec.stderr | base64 -d | jq .
fi
}
_getscript() {
if ! [ -r ${script} ]; then
_error "Script file not found: $script"; continue
fi
if ! [ $break ]; then
cat -n $script
else
cat -n $script | awk '
{ if($1=="'"$break"'") printf "->%s\n",$0; else print $0 }'
fi
}

_execute() {
command -v zencode-exec
if [ $? != 0 ]; then
_error "zencode-exec not found in PATH"; return
fi
. ./$bconf
if [ "$1" != "" ]; then conf="$conf,$1"; fi
xconf=""
if [ "$conf" != "0" ]; then xconf="$conf"; fi
if [ "$1" != "" ]; then xconf="$xconf,$1"; fi
# create zencode-exec execution input
bexec=breakroom.exec
echo "${conf}" > $bexec
cat "$script" | base64 -w0 >> $bexec
echo "${xconf}" > $bexec
bscript=`mktemp`
cat $script > $bscript
if ! [ $break = 0 ]; then
head -n $break $script > $bscript
echo "and break" >> $bscript
fi
cat "$bscript" | base64 -w0 >> $bexec
echo >> $bexec
if [ -r "$keys" ]; then cat "$keys" | base64 -w0 >> $bexec; fi
echo >> $bexec
Expand All @@ -102,8 +162,7 @@ _execute() {
else
cat breakroom.exec.stderr | grep -v "^\"J64"
_error "Failed execution"
awk '/J64 TRACE:/ {print(substr($3,1,length($3)-2))}' \
breakroom.exec.stderr | base64 -d | jq .
_getJ64 "TRACE"
fi
}

Expand All @@ -124,13 +183,7 @@ while true; do
# GET
case "$bcmd" in
script|list)
if ! [ -r ${script} ]; then
_error "Script file not found: $script"; continue
fi
if ! [ $break ]; then cat -n $script
else cat -n $script | awk '
{ if($1=="'"$break"'") printf "->%s\n",$0; else print $0 }'
fi ;;
_getscript ;;
keys)
if ! [ -r ${keys} ]; then
_error "Keys file not found: $keys"; continue
Expand All @@ -149,22 +202,16 @@ while true; do
conf)
cat $bconf ;;
clear)
_setconf "break" 0 ;;
_clearconf
# _setconf "break" 0
;;
run)
_execute ;;
trace)
if ! [ -r breakroom.exec.stderr ]; then
_error "Execution stderr not found, run first"; continue
fi
awk '/J64 TRACE:/ {print(substr($3,1,length($3)-2))}' \
breakroom.exec.stderr | base64 -d | jq .
trace|bt)
_getJ64 TRACE
;;
heap)
if ! [ -r breakroom.exec.stderr ]; then
_error "Execution stderr not found, run first"; continue
fi
awk '/J64 HEAP:/ {print(substr($3,1,length($3)-2))}' \
breakroom.exec.stderr | base64 -d | jq .
_getJ64 HEAP
;;
codec|schema|given)
_execute "scope=given"
Expand Down Expand Up @@ -196,11 +243,12 @@ while true; do
conf)
_setconf "$bcmd" "$bval" ;;
"break")
bval=`echo $bline | cut -d' ' -f2`
if _isnum $bval; then _setconf "$bcmd" "$bval"
if _isnum $bval; then
_setconf "$bcmd" "$bval"
break="$bval"
else _error "Invalid Break line number: $bval"
fi ;;

fi
_getscript ;;
esac
fi # end GET/SET
done
Expand Down
4 changes: 1 addition & 3 deletions src/breakroom/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@

#define HISTFILE "breakroom_history.txt"

extern void load_file(char *dst, FILE *fd);

int breakpoint = 0;

char script[MAX_ZENCODE];
Expand Down Expand Up @@ -123,7 +121,7 @@ int main(int argc, char **argv) {
CMD("clear");
SETINT("break");
CMD("conf");
CMD("trace");
CMD("trace"); CMD("bt");
CMD("heap");
CMD("codec"); CMD("schema"); CMD("given");
fprintf(stdout,"Unknown command: %s\n", line);
Expand Down

0 comments on commit 863b927

Please sign in to comment.