plug eval2 into watch debug tooltips

This commit is contained in:
Ryan Fleury committed 2026-07-29 12:30:40 -07:00
1 parent 076d41130c
commit 11cb826181
10 files changed
+389 -4

No files matched your search

+1 -1
View File
@@ -49,7 +49,7 @@ commands =
// .f1 = { .win = "raddbg_stable --ipc kill_all && build raddbg", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
// .f1 = { .win = "raddbg_stable --ipc kill_all && build raddbg debug telemetry", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
// .f1 = { .win = "raddbg_stable --ipc kill_all && build radbin", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
.f1 = { .win = "raddbg_stable --ipc kill_all && build torture && build ryan_scratch && pushd build && torture eval2/* && ryan_scratch", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
.f1 = { .win = "raddbg_stable --ipc kill_all && build raddbg", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
//- rjf: [raddbg wsl]
// .f1 = { .win = "wsl ./build.sh raddbg", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
+1 -1
View File
@@ -7,6 +7,7 @@ target:
working_directory: "../raddebugger"
arguments: "--user:C:/devel/raddebugger/build/raddbg_test.user"
debug_subprocesses: 0
enabled: 1
}
target:
{
@@ -66,7 +67,6 @@ target:
{
executable: "build/ryan_scratch.exe"
working_directory: build
enabled: 1
}
target:
{
+87
View File
@@ -6,6 +6,93 @@
#include "generated/dbg_engine.meta.c"
////////////////////////////////
//~ rjf: @eval2 Bundled Evaluation Path
internal D_Eval
d_eval_from_string(Arena *arena, String8 string)
{
D_Eval eval = {0};
{
E2_MsgList msgs = {0};
//- rjf: string -> expr
E2_Expr *expr = &e2_expr_nil;
{
E2_ParseState state = {0};
B32 identifier_is_type = 0;
for(;;)
{
E2_Parse parse = e2_parse_from_string(arena, &state, identifier_is_type, E2_LangKind_CLike, string);
identifier_is_type = 0;
expr = parse.expr;
e2_msg_list_concat_in_place(&msgs, &parse.msgs);
if(e2_parse_status_is_terminal(parse.status))
{
break;
}
}
}
//- rjf: expr -> irtree
E2_IRNode *irtree = &e2_irnode_nil;
{
E2_IRNode *resolve_result = &e2_irnode_nil;
E2_Val compile_time_eval_result = {0};
E2_CompileState state = {0};
for(;;)
{
E2_Compile compile = e2_compile_from_expr(arena, &state, resolve_result, compile_time_eval_result, expr);
resolve_result = &e2_irnode_nil;
MemoryZeroStruct(&compile_time_eval_result);
irtree = compile.irtree;
e2_msg_list_concat_in_place(&msgs, &compile.msgs);
switch(compile.status)
{
default:{}break;
case E2_CompileStatus_MissedIdentifierResolution:
{
resolve_result = e2_irnode_const_u64_or_smaller(arena, 123);
}break;
}
if(e2_compile_status_is_terminal(compile.status))
{
break;
}
}
}
//- rjf: ir tree -> bytecode
String8 bytecode = e2_bytecode_from_irnode(arena, irtree);
//- rjf: bytecode -> value
E2_Val val = {0};
{
E2_InterpState state = {0};
E2_SpaceMap space_map = {0};
for(;;)
{
E2_Interp interp = e2_interp_from_bytecode(arena, &state, &space_map, bytecode);
val = interp.val;
e2_msg_list_concat_in_place(&msgs, &interp.msgs);
if(e2_interp_status_is_terminal(interp.status))
{
break;
}
}
}
//- rjf: fill
eval.string = string;
eval.expr = expr;
eval.irtree = irtree;
eval.bytecode = bytecode;
eval.val = val;
eval.msgs = msgs;
}
return eval;
}
////////////////////////////////
//~ rjf: Layer Initialization
+19
View File
@@ -4,6 +4,20 @@
#ifndef DBG_ENGINE_CORE_H
#define DBG_ENGINE_CORE_H
////////////////////////////////
//~ rjf: @eval2 Evaluation Bundle
typedef struct D_Eval D_Eval;
struct D_Eval
{
String8 string;
E2_Expr *expr;
E2_IRNode *irtree;
String8 bytecode;
E2_Val val;
E2_MsgList msgs;
};
////////////////////////////////
//~ rjf: ID Types
@@ -318,6 +332,11 @@ struct D_TrapNet
B32 good_read;
};
////////////////////////////////
//~ rjf: @eval2 Bundled Evaluation Path
internal D_Eval d_eval_from_string(Arena *arena, String8 string);
////////////////////////////////
//~ rjf: Layer Initialization
+48 -1
View File
@@ -199,6 +199,22 @@ e2_msgf(Arena *arena, E2_MsgList *msgs, Rng1U64 src_range, char *fmt, ...)
return msg;
}
internal void
e2_msg_list_concat_in_place(E2_MsgList *dst, E2_MsgList *src)
{
if(dst->last != 0 && src->first != 0)
{
dst->last->next = src->first;
dst->last = src->last;
dst->count += src->count;
}
else if(src->first != 0)
{
MemoryCopyStruct(dst, src);
}
MemoryZeroStruct(src);
}
////////////////////////////////
//~ rjf: Assets
@@ -2594,7 +2610,7 @@ e2_parse_from_string(Arena *arena, E2_ParseState *state, B32 identifier_is_type,
internal E2_Compile
e2_compile_from_expr(Arena *arena, E2_CompileState *state, E2_IRNode *resolve_result, E2_Val compile_time_eval_result, E2_Expr *expr)
{
E2_Compile compile = {E2_CompileStatus_Error};
E2_Compile compile = {E2_CompileStatus_Error, .irtree = &e2_irnode_nil, .params_irtree = &e2_irnode_nil};
{
E2_IRNode *next_resolve_result = resolve_result;
@@ -3720,6 +3736,7 @@ e2_interp_from_bytecode(Arena *arena, E2_InterpState *state, E2_SpaceMap *space_
{
good = 0;
interp.status = E2_InterpStatus_BadRegCode;
e2_msgf(arena, &interp.msgs, r1u64(state->bytecode_off, state->bytecode_off+1), "Bad register code (%i).", base_reg_code);
}
}break;
case RDI_EvalOp_FrameOff: {ctx_flags = E2_CtxFlag_HasFrameBase; ctx_base_addr = state->selected_ctx.frame_base_addr;}goto optional_base_off;
@@ -3735,6 +3752,16 @@ e2_interp_from_bytecode(Arena *arena, E2_InterpState *state, E2_SpaceMap *space_
else
{
good = 0;
String8 missing_msg = {0};
switch(ctx_flags)
{
default:{}break;
case E2_CtxFlag_HasFrameBase: {missing_msg = s("Missing frame base address.");}break;
case E2_CtxFlag_HasModuleBase:{missing_msg = s("Missing module base address.");}break;
case E2_CtxFlag_HasTLSBase: {missing_msg = s("Missing thread-local-storage base address.");}break;
case E2_CtxFlag_HasCFA: {missing_msg = s("Missing canonical frame address.");}break;
}
e2_msg(arena, &interp.msgs, r1u64(state->bytecode_off, state->bytecode_off+1), missing_msg);
interp.status = E2_InterpStatus_MissingCtxFlag;
interp.missing_ctx_flags |= ctx_flags;
}
@@ -3979,6 +4006,7 @@ BinOp(U, u64, u64, symbol);
{
good = 0;
interp.status = E2_InterpStatus_BadOffset;
e2_msgf(arena, &interp.msgs, r1u64(state->bytecode_off, state->bytecode_off+1), "Couldn't read range [0x%I64x, 0x%I64x) (end of range is 0x%I64x).", offset, offset+bytes_to_read, popped_vals[1].string.size);
}
}break;
@@ -4029,6 +4057,25 @@ BinOp(U, u64, u64, symbol);
}break;
}
//- rjf: push generalized failure messages
switch(interp.status)
{
default:{}break;
case E2_InterpStatus_DivideByZero:
{
e2_msgf(arena, &interp.msgs, r1u64(state->bytecode_off, state->bytecode_off+1), "Divide by zero.");
}break;
case E2_InterpStatus_UnsupportedOp:
{
e2_msgf(arena, &interp.msgs, r1u64(state->bytecode_off, state->bytecode_off+1), "Unsupported opcode (%i).", op);
}break;
case E2_InterpStatus_BadOpTypes:
{
String8 opcode_name = rdi_string_from_eval_op(scratch.arena, op);
e2_msgf(arena, &interp.msgs, r1u64(state->bytecode_off, state->bytecode_off+1), "%S opcode cannot be applied to these types.", opcode_name);
}break;
}
//- rjf: if opcode successful -> do stack pops
if(good) for EachIndex(pop_idx, pop_count)
{
+1 -1
View File
@@ -64,7 +64,6 @@ typedef enum E2_CompileStatus
//- rjf: caller-provided info
E2_CompileStatus_MissedIdentifierResolution,
E2_CompileStatus_NewIdentifierDefinition,
E2_CompileStatus_NewCtxID,
E2_CompileStatus_MemberAccess,
E2_CompileStatus_IndexAccess,
E2_CompileStatus_Call,
@@ -559,6 +558,7 @@ internal E2_IRNode *e2_irtree_from_identifier(E2_IdentifierMap *map, String8 nam
internal E2_Msg *e2_msg(Arena *arena, E2_MsgList *msgs, Rng1U64 src_range, String8 string);
internal E2_Msg *e2_msgf(Arena *arena, E2_MsgList *msgs, Rng1U64 src_range, char *fmt, ...);
internal void e2_msg_list_concat_in_place(E2_MsgList *dst, E2_MsgList *src);
////////////////////////////////
//~ rjf: Assets
+6
View File
@@ -65,6 +65,12 @@ E2_ExprKindTable:
COUNT,
}
@data(String8) e2_expr_kind_string_table:
{
`{0}`
@expand(E2_ExprKindTable a) `str8_lit_comp("$(a.name)")`
}
@data(B8) e2_expr_kind_allow_type_operands_table:
{
0,
+52
View File
@@ -4,6 +4,58 @@
//- GENERATED CODE
C_LINKAGE_BEGIN
String8 e2_expr_kind_string_table[48] =
{
{0},
str8_lit_comp("Identifier"),
str8_lit_comp("MacroArg"),
str8_lit_comp("TypeIdentifier"),
str8_lit_comp("Numeric"),
str8_lit_comp("StringLiteral"),
str8_lit_comp("CharLiteral"),
str8_lit_comp("Ptr"),
str8_lit_comp("Array"),
str8_lit_comp("Function"),
str8_lit_comp("Const"),
str8_lit_comp("Volatile"),
str8_lit_comp("Unsigned"),
str8_lit_comp("Signed"),
str8_lit_comp("Dot"),
str8_lit_comp("Index"),
str8_lit_comp("Call"),
str8_lit_comp("DerefAsm"),
str8_lit_comp("SizeOf"),
str8_lit_comp("TypeOf"),
str8_lit_comp("Cast"),
str8_lit_comp("Deref"),
str8_lit_comp("Address"),
str8_lit_comp("Pos"),
str8_lit_comp("Neg"),
str8_lit_comp("LogNot"),
str8_lit_comp("BitNot"),
str8_lit_comp("Mul"),
str8_lit_comp("Div"),
str8_lit_comp("Mod"),
str8_lit_comp("Add"),
str8_lit_comp("Sub"),
str8_lit_comp("LShift"),
str8_lit_comp("RShift"),
str8_lit_comp("Less"),
str8_lit_comp("LtEq"),
str8_lit_comp("Grtr"),
str8_lit_comp("GrEq"),
str8_lit_comp("EqEq"),
str8_lit_comp("NtEq"),
str8_lit_comp("BitAnd"),
str8_lit_comp("BitXor"),
str8_lit_comp("BitOr"),
str8_lit_comp("LogAnd"),
str8_lit_comp("LogOr"),
str8_lit_comp("Define"),
str8_lit_comp("Macro"),
str8_lit_comp("Cond"),
};
B8 e2_expr_kind_allow_type_operands_table[48] =
{
0,
+1
View File
@@ -163,6 +163,7 @@ E2_ExprKindParseInfo *expr_kind_parse_infos;
};
C_LINKAGE_BEGIN
extern String8 e2_expr_kind_string_table[48];
extern B8 e2_expr_kind_allow_type_operands_table[48];
extern B8 e2_expr_kind_is_type_expr_table[48];
extern B8 e2_expr_kind_is_first_operand_type_maybe_table[48];
+173
View File
@@ -4368,6 +4368,179 @@ rd_view_ui(Rng2F32 rect)
rd_set_autocomp_regs(cell->eval, .ui_key = line_edit_key, .string = input, .cursor = cell_edit_state->cursor);
}
// rjf: @eval2 show tooltip for eval2 evaluation
#if 0
if(ui_hovering(sig) && row_depth == 0) UI_Tooltip RD_Font(RD_FontSlot_Code)
{
String8 expr = cell->eval.string;
D_Eval eval = d_eval_from_string(scratch.arena, expr);
String8 indent = s(" ");
// rjf: log string
ui_label(expr);
// rjf: log expression tree
if(eval.expr != &e2_expr_nil)
{
ui_spacer(ui_em(1.f, 1.f));
UI_TagF("weak") ui_label(s("--- Expression Tree ---"));
typedef struct Task Task;
struct Task
{
Task *next;
E2_Expr *expr;
E2_ExprNode *last_child;
S64 depth;
};
Task start_task = {0, eval.expr};
Task *top_task = &start_task;
Task *free_task = 0;
for(;top_task != 0;)
{
E2_Expr *expr = top_task->expr;
// rjf: do this expr node
if(top_task->last_child == 0)
{
String8 expr_kind_name = e2_expr_kind_string_table[expr->kind];
ui_labelf("%.*s%S", top_task->depth, indent.str, expr_kind_name);
}
// rjf: try to push a child
B32 pushed_child = 0;
{
E2_ExprNode *next_child = (top_task->last_child ? top_task->last_child->next : expr->first_child);
top_task->last_child = next_child;
if(next_child != 0)
{
Task *task = free_task;
if(task != 0)
{
SLLStackPop(free_task);
}
else
{
task = push_array_no_zero(scratch.arena, Task, 1);
}
MemoryZeroStruct(task);
task->expr = next_child->v;
task->depth = top_task->depth+1;
SLLStackPush(top_task, task);
pushed_child = 1;
}
}
// rjf: if we didn't push a child -> we're done
if(!pushed_child)
{
Task *popped = top_task;
SLLStackPop(top_task);
SLLStackPush(free_task, popped);
}
}
}
// rjf: log IR tree
if(eval.irtree != &e2_irnode_nil)
{
ui_spacer(ui_em(1.f, 1.f));
UI_TagF("weak") ui_label(s("--- IR Tree ---"));
typedef struct Task Task;
struct Task
{
Task *next;
E2_IRNode *irnode;
E2_IRNodePtrNode *last_child;
S64 depth;
};
Task start_task = {0, eval.irtree};
Task *top_task = &start_task;
Task *free_task = 0;
for(;top_task != 0;)
{
E2_IRNode *irnode = top_task->irnode;
// rjf: do this irnode
if(top_task->last_child == 0)
{
String8 type_string = e2_string_from_type_key(scratch.arena, irnode->type_key);
String8 op_name = {0};
if(irnode->op < RDI_EvalOp_COUNT)
{
op_name = rdi_string_from_eval_op(scratch.arena, irnode->op);
}
else
{
op_name = str8f(scratch.arena, "#%x", irnode->op);
}
ui_labelf("%.*s%S (type: %S)", top_task->depth, indent.str, op_name, type_string);
}
// rjf: try to push a child
B32 pushed_child = 0;
{
E2_IRNodePtrNode *next_child = (top_task->last_child ? top_task->last_child->next : irnode->first_child);
top_task->last_child = next_child;
if(next_child != 0)
{
Task *task = free_task;
if(task != 0)
{
SLLStackPop(free_task);
}
else
{
task = push_array_no_zero(scratch.arena, Task, 1);
}
MemoryZeroStruct(task);
task->irnode = next_child->v;
task->depth = top_task->depth+1;
SLLStackPush(top_task, task);
pushed_child = 1;
}
}
// rjf: if we didn't push a child -> we're done
if(!pushed_child)
{
Task *popped = top_task;
SLLStackPop(top_task);
SLLStackPush(free_task, popped);
}
}
}
// rjf: log bytecode
if(eval.bytecode.size != 0)
{
ui_spacer(ui_em(1.f, 1.f));
UI_TagF("weak") ui_label(s("--- Bytecode ---"));
String8 bytecode_string = rdi_string_from_bytecode(scratch.arena, rdi_arch_from_arch(Arch_CURRENT), eval.bytecode);
ui_label(bytecode_string);
}
// rjf: log value
{
ui_spacer(ui_em(1.f, 1.f));
UI_TagF("weak") ui_label(s("--- Value ---"));
ui_labelf("U64: %I64u (0x%I64x)", eval.val.u64, eval.val.u64);
ui_labelf("F32: %f", eval.val.f32);
ui_labelf("F64: %f", eval.val.f64);
}
// rjf: log messages
if(eval.msgs.count != 0)
{
ui_spacer(ui_em(1.f, 1.f));
UI_TagF("weak") ui_label(s("--- Messages ---"));
for EachNode(n, E2_Msg, eval.msgs.first)
{
ui_label(n->string);
}
}
}
#endif
// rjf: apply locks
{
CFG_Node *cfg = row_info->group_cfg_child;