extend eval space size to allow u128 key for hash store & related cache keys, + some extra metadata determined by user (user-defined kind & extra u64)

This commit is contained in:
Ryan Fleury
2024-09-11 17:11:33 -07:00
parent 26fb91d539
commit deef05d0d2
10 changed files with 131 additions and 64 deletions
+31 -23
View File
@@ -4022,29 +4022,34 @@ internal B32
ctrl_eval_space_read(void *u, E_Space space, void *out, Rng1U64 range)
{
B32 result = 0;
CTRL_Entity *entity = (CTRL_Entity *)space.u64[1];
switch(space.kind)
{
switch(entity->kind)
default:{}break;
case CTRL_EvalSpaceKind_Entity:
{
default:{}break;
case CTRL_EntityKind_Process:
CTRL_Entity *entity = (CTRL_Entity *)space.u64_0;
switch(entity->kind)
{
U64 read_size = dmn_process_read(entity->handle.dmn_handle, range, out);
result = (read_size == dim_1u64(range));
}break;
case CTRL_EntityKind_Thread:
{
Temp scratch = scratch_begin(0, 0);
U64 regs_size = regs_block_size_from_arch(entity->arch);
void *regs = ctrl_query_cached_reg_block_from_thread(scratch.arena, ctrl_state->ctrl_thread_entity_store, entity->handle);
Rng1U64 legal_range = r1u64(0, regs_size);
Rng1U64 read_range = intersect_1u64(legal_range, range);
U64 read_size = dim_1u64(read_range);
MemoryCopy(out, (U8 *)regs + read_range.min, read_size);
result = (read_size == dim_1u64(range));
scratch_end(scratch);
}break;
}
default:{}break;
case CTRL_EntityKind_Process:
{
U64 read_size = dmn_process_read(entity->handle.dmn_handle, range, out);
result = (read_size == dim_1u64(range));
}break;
case CTRL_EntityKind_Thread:
{
Temp scratch = scratch_begin(0, 0);
U64 regs_size = regs_block_size_from_arch(entity->arch);
void *regs = ctrl_query_cached_reg_block_from_thread(scratch.arena, ctrl_state->ctrl_thread_entity_store, entity->handle);
Rng1U64 legal_range = r1u64(0, regs_size);
Rng1U64 read_range = intersect_1u64(legal_range, range);
U64 read_size = dim_1u64(read_range);
MemoryCopy(out, (U8 *)regs + read_range.min, read_size);
result = (read_size == dim_1u64(range));
scratch_end(scratch);
}break;
}
}break;
}
return result;
}
@@ -4921,7 +4926,8 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg)
eval_modules[eval_module_idx].arch = arch;
eval_modules[eval_module_idx].rdi = di_rdi_from_key(di_scope, &dbgi_key, max_U64);
eval_modules[eval_module_idx].vaddr_range = mod->vaddr_range;
eval_modules[eval_module_idx].space.u64[1]= (U64)process;
eval_modules[eval_module_idx].space = e_space_make(CTRL_EvalSpaceKind_Entity);
eval_modules[eval_module_idx].space.u64_0 = (U64)process;
if(mod == module)
{
eval_modules_primary = &eval_modules[eval_module_idx];
@@ -4953,7 +4959,8 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg)
E_ParseCtx *ctx = &parse_ctx;
ctx->ip_vaddr = thread_rip_vaddr;
ctx->ip_voff = thread_rip_voff;
ctx->ip_thread_space.u64[1] = (U64)thread;
ctx->ip_thread_space = e_space_make(CTRL_EvalSpaceKind_Entity);
ctx->ip_thread_space.u64_0 = (U64)thread;
ctx->modules = eval_modules;
ctx->modules_count = eval_modules_count;
ctx->primary_module = eval_modules_primary;
@@ -4978,7 +4985,8 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg)
ctx->space_read = ctrl_eval_space_read;
ctx->primary_space = eval_modules_primary->space;
ctx->reg_arch = eval_modules_primary->arch;
ctx->reg_space.u64[1] = (U64)thread;
ctx->reg_space = e_space_make(CTRL_EvalSpaceKind_Entity);
ctx->reg_space.u64_0 = (U64)thread;
ctx->module_base = push_array(temp.arena, U64, 1);
ctx->module_base[0]= module->vaddr_range.min;
ctx->tls_base = push_array(temp.arena, U64, 1);
+9
View File
@@ -259,6 +259,15 @@ struct CTRL_UserBreakpointList
U64 count;
};
////////////////////////////////
//~ rjf: Evaluation Spaces
typedef U64 CTRL_EvalSpaceKind;
enum
{
CTRL_EvalSpaceKind_Entity,
};
////////////////////////////////
//~ rjf: Generated Code
+6 -6
View File
@@ -2723,9 +2723,9 @@ internal D_Entity *
d_entity_from_eval_space(E_Space space)
{
D_Entity *entity = &d_nil_entity;
if(space.u64[0] == 0 && space.u64[1] != 0)
if(space.u64_0 != 0)
{
entity = (D_Entity *)space.u64[1];
entity = (D_Entity *)space.u64_0;
}
return entity;
}
@@ -2734,7 +2734,7 @@ internal E_Space
d_eval_space_from_entity(D_Entity *entity)
{
E_Space space = {0};
space.u64[1] = (U64)entity;
space.u64_0 = (U64)entity;
return space;
}
@@ -2750,7 +2750,7 @@ d_eval_space_read(void *u, E_Space space, void *out, Rng1U64 range)
//- rjf: nil-space -> fall back to file system
case D_EntityKind_Nil:
{
U128 key = space;
U128 key = space.u128;
U128 hash = hs_hash_from_key(key, 0);
HS_Scope *scope = hs_scope_open();
{
@@ -2909,7 +2909,7 @@ d_key_from_eval_space_range(E_Space space, Rng1U64 range, B32 zero_terminated)
//- rjf: nil space -> filesystem key encoded inside of `space`
case D_EntityKind_Nil:
{
result = space;
result = space.u128;
}break;
//- rjf: process space -> query
@@ -2937,7 +2937,7 @@ d_whole_range_from_eval_space(E_Space space)
U128 hash = {0};
for(U64 idx = 0; idx < 2; idx += 1)
{
hash = hs_hash_from_key(space, idx);
hash = hs_hash_from_key(space.u128, idx);
if(!u128_match(hash, u128_zero()))
{
break;
+5 -5
View File
@@ -8092,11 +8092,11 @@ df_frame(void)
{
E_MemberList entity_members = {0};
{
e_member_list_push_new(scratch.arena, &entity_members, .name = str8_lit("Enabled"), .off = 0, .type_key = e_type_key_basic(E_TypeKind_S64));
e_member_list_push_new(scratch.arena, &entity_members, .name = str8_lit("Hit Count"),.off = 0+8, .type_key = e_type_key_basic(E_TypeKind_U64));
e_member_list_push_new(scratch.arena, &entity_members, .name = str8_lit("Label"), .off = 0+8+8, .type_key = e_type_key_cons_ptr(arch_from_context(), e_type_key_basic(E_TypeKind_Char8)));
e_member_list_push_new(scratch.arena, &entity_members, .name = str8_lit("Location"), .off = 0+8+8+8, .type_key = e_type_key_cons_ptr(arch_from_context(), e_type_key_basic(E_TypeKind_Char8)));
e_member_list_push_new(scratch.arena, &entity_members, .name = str8_lit("Condition"),.off = 0+8+8+8+8,.type_key = e_type_key_cons_ptr(arch_from_context(), e_type_key_basic(E_TypeKind_Char8)));
e_member_list_push_new(scratch.arena, &entity_members, .name = str8_lit("enabled"), .off = 0, .type_key = e_type_key_basic(E_TypeKind_S64));
e_member_list_push_new(scratch.arena, &entity_members, .name = str8_lit("hit_count"),.off = 0+8, .type_key = e_type_key_basic(E_TypeKind_U64));
e_member_list_push_new(scratch.arena, &entity_members, .name = str8_lit("label"), .off = 0+8+8, .type_key = e_type_key_cons_ptr(arch_from_context(), e_type_key_basic(E_TypeKind_Char8)));
e_member_list_push_new(scratch.arena, &entity_members, .name = str8_lit("location"), .off = 0+8+8+8, .type_key = e_type_key_cons_ptr(arch_from_context(), e_type_key_basic(E_TypeKind_Char8)));
e_member_list_push_new(scratch.arena, &entity_members, .name = str8_lit("condition"),.off = 0+8+8+8+8,.type_key = e_type_key_cons_ptr(arch_from_context(), e_type_key_basic(E_TypeKind_Char8)));
}
E_MemberArray entity_members_array = e_member_array_from_list(scratch.arena, &entity_members);
E_TypeKey entity_type = e_type_key_cons(.arch = arch_from_context(),
+27 -22
View File
@@ -895,6 +895,8 @@ df_watch_view_column_alloc_(DF_WatchViewState *wv, DF_WatchViewColumnKind kind,
col->pct = pct;
col->string_size = Min(sizeof(col->string_buffer), params->string.size);
MemoryCopy(col->string_buffer, params->string.str, col->string_size);
col->display_string_size = Min(sizeof(col->display_string_buffer), params->display_string.size);
MemoryCopy(col->display_string_buffer, params->display_string.str, col->display_string_size);
col->view_rule_size = Min(sizeof(col->view_rule_buffer), params->view_rule.size);
MemoryCopy(col->view_rule_buffer, params->view_rule.str, col->view_rule_size);
col->is_non_code = params->is_non_code;
@@ -1056,11 +1058,11 @@ df_watch_view_build(DF_View *view, DF_WatchViewState *ewv, B32 modifiable, U32 d
{
E_MemberList bp_members = {0};
{
e_member_list_push_new(scratch.arena, &bp_members, .name = str8_lit("Enabled"), .off = 0, .type_key = e_type_key_basic(E_TypeKind_S64));
e_member_list_push_new(scratch.arena, &bp_members, .name = str8_lit("Hit Count"),.off = 0+8, .type_key = e_type_key_basic(E_TypeKind_U64));
e_member_list_push_new(scratch.arena, &bp_members, .name = str8_lit("Label"), .off = 0+8+8, .type_key = e_type_key_cons_ptr(arch_from_context(), e_type_key_basic(E_TypeKind_Char8)));
e_member_list_push_new(scratch.arena, &bp_members, .name = str8_lit("Location"), .off = 0+8+8+8, .type_key = e_type_key_cons_ptr(arch_from_context(), e_type_key_basic(E_TypeKind_Char8)));
e_member_list_push_new(scratch.arena, &bp_members, .name = str8_lit("Condition"),.off = 0+8+8+8+8,.type_key = e_type_key_cons_ptr(arch_from_context(), e_type_key_basic(E_TypeKind_Char8)));
e_member_list_push_new(scratch.arena, &bp_members, .name = str8_lit("enabled"), .off = 0, .type_key = e_type_key_basic(E_TypeKind_S64));
e_member_list_push_new(scratch.arena, &bp_members, .name = str8_lit("hit_count"),.off = 0+8, .type_key = e_type_key_basic(E_TypeKind_U64));
e_member_list_push_new(scratch.arena, &bp_members, .name = str8_lit("label"), .off = 0+8+8, .type_key = e_type_key_cons_ptr(arch_from_context(), e_type_key_basic(E_TypeKind_Char8)));
e_member_list_push_new(scratch.arena, &bp_members, .name = str8_lit("location"), .off = 0+8+8+8, .type_key = e_type_key_cons_ptr(arch_from_context(), e_type_key_basic(E_TypeKind_Char8)));
e_member_list_push_new(scratch.arena, &bp_members, .name = str8_lit("condition"),.off = 0+8+8+8+8,.type_key = e_type_key_cons_ptr(arch_from_context(), e_type_key_basic(E_TypeKind_Char8)));
}
E_MemberArray bp_members_array = e_member_array_from_list(scratch.arena, &bp_members);
E_TypeKey bp_type = e_type_key_cons(.arch = arch_from_context(), .kind = E_TypeKind_Struct, .name = str8_lit("Breakpoint"), .members = bp_members_array.v, .count = bp_members_array.count);
@@ -2098,19 +2100,22 @@ df_watch_view_build(DF_View *view, DF_WatchViewState *ewv, B32 modifiable, U32 d
for(DF_WatchViewColumn *col = ewv->first_column; col != 0; col = col->next)
UI_TableCell
{
String8 name = {0};
switch(col->kind)
String8 name = str8(col->display_string_buffer, col->display_string_size);
if(name.size == 0)
{
default:{}break;
case DF_WatchViewColumnKind_Expr: {name = str8_lit("Expression");}break;
case DF_WatchViewColumnKind_Value: {name = str8_lit("Value");}break;
case DF_WatchViewColumnKind_Type: {name = str8_lit("Type");}break;
case DF_WatchViewColumnKind_ViewRule:{name = str8_lit("View Rule");}break;
case DF_WatchViewColumnKind_Module: {name = str8_lit("Module");}break;
case DF_WatchViewColumnKind_Member:
switch(col->kind)
{
name = str8(col->string_buffer, col->string_size);
}break;
default:{}break;
case DF_WatchViewColumnKind_Expr: {name = str8_lit("Expression");}break;
case DF_WatchViewColumnKind_Value: {name = str8_lit("Value");}break;
case DF_WatchViewColumnKind_Type: {name = str8_lit("Type");}break;
case DF_WatchViewColumnKind_ViewRule:{name = str8_lit("View Rule");}break;
case DF_WatchViewColumnKind_Module: {name = str8_lit("Module");}break;
case DF_WatchViewColumnKind_Member:
{
name = str8(col->string_buffer, col->string_size);
}break;
}
}
switch(col->kind)
{
@@ -5469,11 +5474,11 @@ DF_VIEW_SETUP_FUNCTION_DEF(breakpoints)
{
DF_WatchViewState *wv = df_view_user_state(view, DF_WatchViewState);
df_watch_view_init(wv, view, DF_WatchViewFillKind_Breakpoints);
df_watch_view_column_alloc(wv, DF_WatchViewColumnKind_Member, 0.25f, .string = str8_lit("Label"), .dequote_string = 1, .is_non_code = 1);
df_watch_view_column_alloc(wv, DF_WatchViewColumnKind_Member, 0.35f, .string = str8_lit("Location"), .dequote_string = 1, .is_non_code = 1);
df_watch_view_column_alloc(wv, DF_WatchViewColumnKind_Member, 0.20f, .string = str8_lit("Condition"), .dequote_string = 1);
df_watch_view_column_alloc(wv, DF_WatchViewColumnKind_Member, 0.10f, .string = str8_lit("Enabled"), .view_rule = str8_lit("checkbox"));
df_watch_view_column_alloc(wv, DF_WatchViewColumnKind_Member, 0.10f, .string = str8_lit("Hit Count"));
df_watch_view_column_alloc(wv, DF_WatchViewColumnKind_Member, 0.25f, .string = str8_lit("label"), .display_string = str8_lit("Label"), .dequote_string = 1, .is_non_code = 1);
df_watch_view_column_alloc(wv, DF_WatchViewColumnKind_Member, 0.35f, .string = str8_lit("location"), .display_string = str8_lit("Location"), .dequote_string = 1, .is_non_code = 1);
df_watch_view_column_alloc(wv, DF_WatchViewColumnKind_Member, 0.20f, .string = str8_lit("condition"), .display_string = str8_lit("Condition"), .dequote_string = 1);
df_watch_view_column_alloc(wv, DF_WatchViewColumnKind_Member, 0.10f, .string = str8_lit("enabled"), .display_string = str8_lit("Enabled"), .view_rule = str8_lit("checkbox"));
df_watch_view_column_alloc(wv, DF_WatchViewColumnKind_Member, 0.10f, .string = str8_lit("hit_count"), .display_string = str8_lit("Hit Count"));
}
DF_VIEW_CMD_FUNCTION_DEF(breakpoints){}
DF_VIEW_UI_FUNCTION_DEF(breakpoints)
@@ -7065,7 +7070,7 @@ DF_VIEW_UI_FUNCTION_DEF(memory)
//- rjf: unpack parameterization info
//
E_Eval eval = e_eval_from_string(scratch.arena, string);
if(u128_match(eval.space, u128_zero()))
if(eval.space.kind == 0)
{
eval.space = d_eval_space_from_entity(d_entity_from_handle(d_regs()->process));
}
+3
View File
@@ -65,6 +65,7 @@ typedef struct DF_WatchViewColumnParams DF_WatchViewColumnParams;
struct DF_WatchViewColumnParams
{
String8 string;
String8 display_string;
String8 view_rule;
B32 is_non_code;
B32 dequote_string;
@@ -79,6 +80,8 @@ struct DF_WatchViewColumn
F32 pct;
U8 string_buffer[1024];
U64 string_size;
U8 display_string_buffer[1024];
U64 display_string_size;
U8 view_rule_buffer[1024];
U64 view_rule_size;
B32 is_non_code;
+11
View File
@@ -155,3 +155,14 @@ e_msg_list_concat_in_place(E_MsgList *dst, E_MsgList *to_push)
}
MemoryZeroStruct(to_push);
}
////////////////////////////////
//~ rjf: Space Functions
internal E_Space
e_space_make(E_SpaceKind kind)
{
E_Space space = {0};
space.kind = kind;
return space;
}
+28 -2
View File
@@ -78,8 +78,6 @@ struct E_OpInfo
////////////////////////////////
//~ rjf: Evaluation Spaces
typedef U128 E_Space;
//
// NOTE(rjf): Evaluations occur within the context of a "space". Each "space"
// refers to a different offset/address-space, but it's a bit looser of a
@@ -91,6 +89,29 @@ typedef U128 E_Space;
// value for understanding a key *into* a space, e.g. 1+2 -> 3, in a null
// space, or &foo, in the space of PID: 1234.
typedef U64 E_SpaceKind;
enum
{
E_SpaceKind_Null,
E_SpaceKind_FileSystem,
E_SpaceKind_FirstUserDefined,
};
typedef struct E_Space E_Space;
struct E_Space
{
E_SpaceKind kind;
union
{
U64 u64s[3];
struct
{
U64 u64_0;
U128 u128;
};
};
};
////////////////////////////////
//~ rjf: Evaluation Modes
@@ -134,4 +155,9 @@ internal void e_msg(Arena *arena, E_MsgList *msgs, E_MsgKind kind, void *locatio
internal void e_msgf(Arena *arena, E_MsgList *msgs, E_MsgKind kind, void *location, char *fmt, ...);
internal void e_msg_list_concat_in_place(E_MsgList *dst, E_MsgList *to_push);
////////////////////////////////
//~ rjf: Space Functions
internal E_Space e_space_make(E_SpaceKind kind);
#endif // EVAL_CORE_H
+1 -1
View File
@@ -121,7 +121,7 @@ e_interpret(String8 bytecode)
{
case E_IRExtKind_SetSpace:
{
selected_space = imm.u128;
MemoryCopy(&selected_space, &imm, sizeof(selected_space));
}break;
case RDI_EvalOp_Stop:
+10 -5
View File
@@ -138,7 +138,8 @@ e_oplist_push_set_space(Arena *arena, E_OpList *list, E_Space space)
{
E_Op *node = push_array_no_zero(arena, E_Op, 1);
node->opcode = E_IRExtKind_SetSpace;
node->value.u128 = space;
StaticAssert(sizeof(E_Space) <= sizeof(E_Value), space_size_check);
MemoryCopy(&node->value, &space, sizeof(space));
SLLQueuePush(list->first, list->last, node);
list->op_count += 1;
list->encoded_size += 1 + sizeof(space);
@@ -266,7 +267,8 @@ internal E_IRNode *
e_irtree_set_space(Arena *arena, E_Space space, E_IRNode *c)
{
E_IRNode *root = e_push_irnode(arena, E_IRExtKind_SetSpace);
root->value.u128 = space;
StaticAssert(sizeof(E_Space) <= sizeof(E_Value), space_size_check);
MemoryCopy(&root->value, &space, sizeof(space));
e_irnode_push_child(root, c);
return root;
}
@@ -1264,13 +1266,14 @@ e_irtree_and_type_from_expr(Arena *arena, E_Expr *expr)
case E_ExprKind_LeafFilePath:
{
U128 key = fs_key_from_path_range(expr->string, r1u64(0, max_U64));
E_Space space = {E_SpaceKind_FileSystem, .u128 = key};
U64 size = fs_size_from_path(expr->string);
E_IRNode *base_offset = e_irtree_const_u(arena, 0);
E_IRNode *set_space = e_irtree_set_space(arena, key, base_offset);
E_IRNode *set_space = e_irtree_set_space(arena, space, base_offset);
result.root = set_space;
result.type_key = e_type_key_cons_array(e_type_key_basic(E_TypeKind_U8), size);
result.mode = E_Mode_Offset;
result.space = key;
result.space = space;
}break;
//- rjf: types
@@ -1328,7 +1331,9 @@ e_append_oplist_from_irtree(Arena *arena, E_IRNode *root, E_OpList *out)
case E_IRExtKind_SetSpace:
{
e_oplist_push_set_space(arena, out, root->value.u128);
E_Space space = {0};
MemoryCopy(&space, &root->value, sizeof(space));
e_oplist_push_set_space(arena, out, space);
for(E_IRNode *child = root->first;
child != &e_irnode_nil;
child = child->next)