set up eval scratch; promote raddbg_markup to base layer, plug in custom codebase vsnprintf

This commit is contained in:
Ryan Fleury
2025-03-31 11:41:14 -07:00
parent 1adf280354
commit fbe0d3bc2e
7 changed files with 175 additions and 13 deletions
+4
View File
@@ -4,6 +4,10 @@
#ifndef BASE_MARKUP_H
#define BASE_MARKUP_H
#define RADDBG_MARKUP_IMPLEMENTATION
#define RADDBG_MARKUP_VSNPRINTF raddbg_vsnprintf
#include "lib_raddbg_markup/raddbg_markup.h"
internal void set_thread_name(String8 string);
internal void set_thread_namef(char *fmt, ...);
#define ThreadNameF(...) (set_thread_namef(__VA_ARGS__))
+4 -3
View File
@@ -14,11 +14,12 @@ internal void
e_select_interpret_ctx(E_InterpretCtx *ctx, RDI_Parsed *primary_rdi, U64 ip_voff)
{
e_interpret_ctx = ctx;
// compute and apply frame base
if(primary_rdi != 0)
{
E_Interpretation frame_base = { .code = ~0 };
RDI_Procedure *proc = rdi_procedure_from_voff(primary_rdi, ip_voff);
for(U64 loc_block_idx = proc->frame_base_location_first; loc_block_idx < proc->frame_base_location_opl; loc_block_idx += 1)
{
@@ -45,7 +46,7 @@ e_select_interpret_ctx(E_InterpretCtx *ctx, RDI_Parsed *primary_rdi, U64 ip_voff
break;
}
}
if(frame_base.code == E_InterpretationCode_Good)
{
*ctx->frame_base = frame_base.value.u64;
+2
View File
@@ -99,7 +99,9 @@ extern "C"
long long _InterlockedExchangeAdd64(long long volatile*, long long);
#pragma intrinsic(_InterlockedCompareExchange64)
#pragma intrinsic(_InterlockedExchangeAdd64)
#if RADDBG_MARKUP_DEFAULT_VSNPRINTF
int RADDBG_MARKUP_VSNPRINTF(char * const, unsigned long long const, const char * const, va_list);
#endif
#if defined(__cplusplus)
}
#endif
+5 -5
View File
@@ -27,7 +27,7 @@
// - The hover evaluation feature has been majorly upgraded to support all
// features normally available in the `Watch` view. Hover evaluations now
// explicitly show type information, and contain a view rule column, which
// can be edited in an identical way as the `Watch` view.
// can be edited in a way identical to the `Watch` view.
// - Added "auto tabs", which are colored differently than normal tabs. These
// tabs are automatically opened by the debugger when snapping to source code
// which is not already opened. They are automatically replaced and recycled
@@ -42,12 +42,13 @@
// those purposes, the `Threads` view is sufficient if not desirable, and
// the extra information provided by `Processes` and `Machines`, while useful
// in other contexts, is not useful in that common case. The `Machines` view
// now shows a superset of the information previosuly found in the
// now shows a superset of the information previously found in the
// `Scheduler` view.
// - The two separate interfaces for editing threads, breakpoints, and watch
// pins (the right-click context menu and the dedicated tabs) have been
// merged.
// - Added the ability to add a list environment strings to targets.
// merged. Both interfaces support exactly the same features in exactly the
// same way.
// - Added the ability to add a list of environment strings to targets.
// - The debugger releases are now packaged with a `raddbg_markup.h`
// single-header library which contains a number of source code markup tools
// which can be used in your programs. Some of these features are for direct
@@ -388,7 +389,6 @@
//- rjf: [lib]
#include "third_party/rad_lzb_simple/rad_lzb_simple.h"
#include "third_party/rad_lzb_simple/rad_lzb_simple.c"
#include "lib_raddbg_markup/raddbg_markup.h"
//- rjf: [h]
#include "base/base_inc.h"
+151
View File
@@ -0,0 +1,151 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
//~ rjf: Includes
//- rjf: [h]
#include "base/base_inc.h"
#include "os/os_inc.h"
#include "rdi_format/rdi_format_local.h"
#include "regs/regs.h"
#include "regs/rdi/regs_rdi.h"
#include "eval/eval_inc.h"
//- rjf: [c]
#include "base/base_inc.c"
#include "os/os_inc.c"
#include "rdi_format/rdi_format_local.c"
#include "regs/regs.c"
#include "regs/rdi/regs_rdi.c"
#include "eval/eval_inc.c"
////////////////////////////////
//~ rjf: Entry Point
internal void
entry_point(CmdLine *cmdline)
{
Arena *arena = arena_alloc();
char *indent_spaces = " ";
E_TypeCtx *type_ctx = push_array(arena, E_TypeCtx, 1);
e_select_type_ctx(type_ctx);
E_ParseCtx *parse_ctx = push_array(arena, E_ParseCtx, 1);
e_select_parse_ctx(parse_ctx);
E_IRCtx *ir_ctx = push_array(arena, E_IRCtx, 1);
e_select_ir_ctx(ir_ctx);
E_InterpretCtx *interpret_ctx = push_array(arena, E_InterpretCtx, 1);
e_select_interpret_ctx(interpret_ctx, 0, 0);
String8 exprs[] =
{
str8_lit("123"),
};
for EachElement(idx, exprs)
{
//- rjf: begin expression
String8 expr_text = exprs[idx];
raddbg_log("`%S`\n", expr_text);
//- rjf: tokenize
E_TokenArray tokens = e_token_array_from_text(arena, expr_text);
raddbg_log(" tokens:\n");
for EachIndex(idx, tokens.count)
{
E_Token token = tokens.v[idx];
String8 token_string = str8_substr(expr_text, token.range);
raddbg_log(" %S: `%S`\n", e_token_kind_strings[token.kind], token_string);
}
//- rjf: parse
E_Parse parse = e_parse_expr_from_text_tokens(arena, expr_text, &tokens);
{
typedef struct Task Task;
struct Task
{
Task *next;
E_Expr *expr;
S32 indent;
};
raddbg_log(" expr:\n");
Task start_task = {0, parse.exprs.first, 2};
Task *first_task = &start_task;
for(Task *t = first_task; t != 0; t = t->next)
{
E_Expr *expr = t->expr;
raddbg_log("%.*s%S", (int)t->indent*2, indent_spaces, e_expr_kind_strings[expr->kind]);
switch(expr->kind)
{
default:{}break;
case E_ExprKind_LeafU64:
{
raddbg_log(" (%I64u)", expr->value.u64);
}break;
}
raddbg_log("\n");
for(E_Expr *child = expr->first; child != &e_expr_nil; child = child->next)
{
Task *task = push_array(arena, Task, 1);
task->next = t->next;
t->next = task;
task->expr = child;
task->indent = t->indent+1;
}
}
}
//- rjf: type
E_IRTreeAndType irtree = e_irtree_and_type_from_expr(arena, parse.exprs.first);
{
raddbg_log(" type:\n");
S32 indent = 2;
for(E_TypeKey type_key = irtree.type_key;
!e_type_key_match(e_type_key_zero(), type_key);
type_key = e_type_direct_from_key(type_key),
indent += 1)
{
E_Type *type = e_type_from_key(arena, type_key);
raddbg_log("%.*s%S\n", (int)indent*2, indent_spaces, e_kind_basic_string_table[type->kind]);
}
}
//- rjf: irtree
{
typedef struct Task Task;
struct Task
{
Task *next;
E_IRNode *irnode;
S32 indent;
};
raddbg_log(" ir_tree:\n");
Task start_task = {0, irtree.root, 2};
Task *first_task = &start_task;
for(Task *t = first_task; t != 0; t = t->next)
{
E_IRNode *irnode = t->irnode;
raddbg_log("%.*s", (int)t->indent*2, indent_spaces);
switch(irnode->op)
{
default:{}break;
#define X(name) case RDI_EvalOp_##name:{raddbg_log(" " #name);}break;
RDI_EvalOp_XList
#undef X
}
if(irnode->value.u64 != 0)
{
raddbg_log(" (%I64u)", irnode->value.u64);
}
raddbg_log("\n");
for(E_IRNode *child = irnode->first; child != &e_irnode_nil; child = child->next)
{
Task *task = push_array(arena, Task, 1);
task->next = t->next;
t->next = task;
task->irnode = child;
task->indent = t->indent+1;
}
}
}
}
}