kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

commit a24bb437a9063b0d9f51a75282495f5d191b67dc
parent 9bfc0800ac4b96f20ceeec6c00cc845e5ca51ef0
Author: Ryan Sepassi <rsepassi@gmail.com>
Date:   Thu, 21 May 2026 10:46:50 -0700

dbg: fallback to expr so jit/expr can be elided

Diffstat:
Mdriver/dbg.c | 38+++++++++++++++++++++++++++++---------
Mtest/driver/run.sh | 20++++++++++++++++++++
2 files changed, 49 insertions(+), 9 deletions(-)

diff --git a/driver/dbg.c b/driver/dbg.c @@ -103,9 +103,12 @@ void driver_help_dbg(void) { " sl step to next source line (into calls)\n" " n, next step to next source line (over calls)\n" " finish run until current frame returns\n" - " jit [LANG|NAME] { ... } compile and append a frontend snippet\n" - " edit [LANG|NAME] edit and append a frontend snippet\n" - " expr C_EXPR | expr { ... } compile and call a C thunk\n" + " jit [LANG|NAME] { ... } compile and append a language snippet\n" + " edit [LANG|NAME] edit and append a language snippet\n" + " expr EXPR | expr { ... } compile and call an expression thunk\n" + " EXPR same as expr EXPR\n" + " LANG defaults to the input language;\n" + " expression thunks use C syntax today\n" " call SYMBOL [INT_OR_ADDR...] call function, returns uint64_t\n" " jump ADDR set PC to ADDR (no resume)\n" " bt, backtrace print stack trace with arguments\n" @@ -2152,7 +2155,8 @@ static void dbg_cmd_expr(DbgState *s, const char *expr) { while (*expr && dbg_isspace((unsigned char)*expr)) ++expr; if (!*expr) { - driver_errf(DBG_TOOL, "usage: expr C_EXPR | expr { C_STATEMENTS }"); + driver_errf(DBG_TOOL, "usage: expr EXPR | expr { STATEMENTS } " + "(expression thunks use C syntax today)"); return; } @@ -2613,9 +2617,12 @@ static void dbg_cmd_help(void) { " sl step to next source line (into calls)\n" " n, next step to next source line (over calls)\n" " finish run until current frame returns\n" - " jit [LANG|NAME] { ... } compile and append a frontend snippet\n" - " edit [LANG|NAME], e [...] edit and append a frontend snippet\n" - " expr C_EXPR | expr { ... } compile and call a C thunk\n" + " jit [LANG|NAME] { ... } compile and append a language snippet\n" + " edit [LANG|NAME], e [...] edit and append a language snippet\n" + " expr EXPR | expr { ... } compile and call an expression thunk\n" + " EXPR same as expr EXPR\n" + " LANG defaults to the input language;\n" + " expression thunks use C syntax today\n" " call SYMBOL [INT_OR_ADDR...] call function, returns uint64_t\n" " jump ADDR set PC to ADDR (no resume)\n" " bt, backtrace print stack trace with arguments\n" @@ -2677,8 +2684,17 @@ static char *dbg_take_word(char *line, char **word_out) { } static int dbg_dispatch(DbgState *s, char *line) { + char raw[LINE_CAP]; + size_t raw_len = driver_strlen(line); char *cmd; - char *rest = dbg_take_word(line, &cmd); + char *rest; + + if (raw_len >= sizeof(raw)) + raw_len = sizeof(raw) - 1u; + driver_memcpy(raw, line, raw_len); + raw[raw_len] = '\0'; + + rest = dbg_take_word(line, &cmd); if (!*cmd) return 0; /* blank line */ @@ -2940,7 +2956,11 @@ static int dbg_dispatch(DbgState *s, char *line) { return 0; } - driver_errf(DBG_TOOL, "unknown command: %s (try 'h')", cmd); + if (s->session) { + dbg_cmd_expr(s, raw); + } else { + driver_errf(DBG_TOOL, "unknown command: %s (try 'h')", cmd); + } return 0; } diff --git a/test/driver/run.sh b/test/driver/run.sh @@ -398,6 +398,26 @@ else fail=$((fail + 1)) fi +host_arch=$(uname -m) +host_os=$(uname -s) +if { [ "$host_arch" = "arm64" ] || [ "$host_arch" = "aarch64" ]; } && + { [ "$host_os" = "Darwin" ] || [ "$host_os" = "Linux" ]; }; then + if printf '1 + 2\nq\n' | "$CFREE" dbg "$work/main.c" \ + > "$work/dbg-raw-expr.out" 2> "$work/dbg-raw-expr.err" && + grep -q '\$1 = 3 (0x3)' "$work/dbg-raw-expr.out"; then + printf 'PASS %s\n' "dbg-raw-expression" + pass=$((pass + 1)) + else + printf 'FAIL %s\n' "dbg-raw-expression" + sed 's/^/ stdout| /' "$work/dbg-raw-expr.out" + sed 's/^/ stderr| /' "$work/dbg-raw-expr.err" + fail=$((fail + 1)) + fi +else + printf 'SKIP %s (unsupported host %s/%s)\n' \ + "dbg-raw-expression" "$host_os" "$host_arch" +fi + total=$((pass + fail)) if [ "$fail" -gt 0 ]; then printf '\ndriver: %d/%d passed\n' "$pass" "$total"