mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-11-16 03:00:25 -08:00
raddbg: explicit packet headers for ipc; render_opengl: fix bad scissoring; linux_socket: fix not waking up, fix SIGPIPE; dbg_engine: checkpoint on sketching out multi-demon attaching abstraction, machine ID -> demon ID
This commit is contained in:
1 parent
7da38c5f3b
commit
98467d0868
12 files changed
+230
-88
No files matched your search
+1
-1
@@ -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 raddbg telemetry debug", .linux = "./build.sh raddbg", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
|
||||
.f1 = { .win = "raddbg_stable --ipc kill_all && build raddbg telemetry debug", .linux = "./build.sh raddbg debug", .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, },
|
||||
|
||||
@@ -47,3 +47,4 @@ target:
|
||||
executable: "../jai/examples/invaders/invaders"
|
||||
working_directory: "../jai/examples/invaders"
|
||||
}
|
||||
linux_sigpipe: 1
|
||||
@@ -22,7 +22,7 @@ struct D_Eval
|
||||
//~ rjf: ID Types
|
||||
|
||||
typedef U64 D_MsgID;
|
||||
typedef U32 D_MachineID;
|
||||
typedef U32 D_DemonID;
|
||||
typedef U32 D_ControllerKind;
|
||||
typedef enum D_ControllerKindEnum
|
||||
{
|
||||
@@ -31,7 +31,7 @@ typedef enum D_ControllerKindEnum
|
||||
}
|
||||
D_ControllerKindEnum;
|
||||
|
||||
#define D_MachineID_Local (1)
|
||||
#define D_DemonID_LocalHost (1)
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Entity Handle Types
|
||||
@@ -39,7 +39,7 @@ D_ControllerKindEnum;
|
||||
typedef struct D_Handle D_Handle;
|
||||
struct D_Handle
|
||||
{
|
||||
D_MachineID machine_id;
|
||||
D_DemonID demon_id;
|
||||
D_ControllerKind controller_kind;
|
||||
U64 entity_id;
|
||||
};
|
||||
|
||||
@@ -1,13 +1,40 @@
|
||||
// Copyright (c) Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Local Host Demon Interface
|
||||
|
||||
D_DemonInterface d_local_demon =
|
||||
{
|
||||
dmn_ctrl_exclusive_access_begin,
|
||||
dmn_ctrl_exclusive_access_end,
|
||||
dmn_ctrl_launch,
|
||||
dmn_ctrl_attach,
|
||||
dmn_ctrl_kill,
|
||||
dmn_ctrl_detach,
|
||||
dmn_ctrl_run,
|
||||
dmn_halt,
|
||||
dmn_access_open,
|
||||
dmn_access_close,
|
||||
dmn_process_memory_reserve,
|
||||
dmn_process_memory_commit,
|
||||
dmn_process_memory_decommit,
|
||||
dmn_process_memory_release,
|
||||
dmn_process_memory_protect,
|
||||
dmn_process_read,
|
||||
dmn_process_write,
|
||||
dmn_thread_read_reg_block,
|
||||
dmn_thread_write_reg_block,
|
||||
dmn_thread_get_module_tls_vaddr,
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Basic Type Functions
|
||||
|
||||
internal U64
|
||||
d_hash_from_handle(D_Handle handle)
|
||||
{
|
||||
U64 buf[] = {handle.machine_id, handle.controller_kind, handle.entity_id};
|
||||
U64 buf[] = {handle.demon_id, handle.controller_kind, handle.entity_id};
|
||||
U64 hash = u64_hash_from_str8(str8_struct(&handle));
|
||||
return hash;
|
||||
}
|
||||
@@ -182,7 +209,7 @@ d_handle_array_from_list(Arena *arena, D_HandleList *src)
|
||||
internal String8
|
||||
d_string_from_handle(Arena *arena, D_Handle handle)
|
||||
{
|
||||
String8 result = str8f(arena, "$%x$%x$%I64x", handle.machine_id, handle.controller_kind, handle.entity_id);
|
||||
String8 result = str8f(arena, "$%x$%x$%I64x", handle.demon_id, handle.controller_kind, handle.entity_id);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -196,10 +223,10 @@ d_handle_from_string(String8 string)
|
||||
String8List parts = str8_split(scratch.arena, string, &split, 1, 0);
|
||||
if(parts.first && parts.first->next && parts.first->next->next)
|
||||
{
|
||||
D_MachineID machine_id = (U32)u64_from_str8(parts.first->string, 16);
|
||||
D_DemonID demon_id = (U32)u64_from_str8(parts.first->string, 16);
|
||||
D_ControllerKind controller_kind = (U32)u64_from_str8(parts.first->next->string, 16);
|
||||
U64 entity_id = u64_from_str8(parts.first->next->next->string, 16);
|
||||
handle.machine_id = machine_id;
|
||||
handle.demon_id = demon_id;
|
||||
handle.controller_kind = controller_kind;
|
||||
handle.entity_id = entity_id;
|
||||
}
|
||||
@@ -220,11 +247,11 @@ d_dmn_from_handle(D_Handle handle)
|
||||
}
|
||||
|
||||
internal D_Handle
|
||||
d_handle_from_dmn(D_MachineID machine_id, DMN_Handle handle)
|
||||
d_handle_from_dmn(D_DemonID demon_id, DMN_Handle handle)
|
||||
{
|
||||
D_Handle result = {0};
|
||||
{
|
||||
result.machine_id = machine_id;
|
||||
result.demon_id = demon_id;
|
||||
result.controller_kind = D_ControllerKind_Demon;
|
||||
result.entity_id = handle.u64[0];
|
||||
}
|
||||
@@ -232,11 +259,11 @@ d_handle_from_dmn(D_MachineID machine_id, DMN_Handle handle)
|
||||
}
|
||||
|
||||
internal D_Handle
|
||||
d_dump_handle_make(D_MachineID machine_id, U64 id)
|
||||
d_dump_handle_make(D_DemonID demon_id, U64 id)
|
||||
{
|
||||
D_Handle result = {0};
|
||||
{
|
||||
result.machine_id = machine_id;
|
||||
result.demon_id = demon_id;
|
||||
result.controller_kind = D_ControllerKind_Dump;
|
||||
result.entity_id = id;
|
||||
}
|
||||
@@ -915,7 +942,7 @@ d_entity_ctx_rw_store_alloc(void)
|
||||
store->ctx.hash_slots_count = 1024;
|
||||
store->ctx.hash_slots = push_array(arena, D_EntityHashSlot, store->ctx.hash_slots_count);
|
||||
D_Entity *root = store->ctx.root = d_entity_alloc(store, &d_entity_nil, D_EntityKind_Root, Arch_Null, d_handle_zero(), 0);
|
||||
D_Entity *local_machine = d_entity_alloc(store, root, D_EntityKind_Machine, Arch_CURRENT, d_handle_from_dmn(D_MachineID_Local, dmn_handle_zero()), 0);
|
||||
D_Entity *local_machine = d_entity_alloc(store, root, D_EntityKind_Machine, Arch_CURRENT, d_handle_from_dmn(D_DemonID_LocalHost, dmn_handle_zero()), 0);
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
String8 local_machine_name = push_str8f(scratch.arena, "This PC (%S)", get_system_info()->machine_name);
|
||||
d_entity_equip_string(store, local_machine, local_machine_name);
|
||||
@@ -1306,7 +1333,7 @@ d_entity_store_apply_events(D_EntityCtxRWStore *store, D_EventList *list)
|
||||
//- rjf: processes
|
||||
case D_EventKind_NewProc:
|
||||
{
|
||||
D_Entity *machine = d_entity_from_handle(d_handle_from_dmn(event->entity.machine_id, dmn_handle_zero()));
|
||||
D_Entity *machine = d_entity_from_handle(d_handle_from_dmn(event->entity.demon_id, dmn_handle_zero()));
|
||||
if(machine != &d_entity_nil)
|
||||
{
|
||||
D_Entity *process = d_entity_alloc(store, machine, D_EntityKind_Process, event->arch, event->entity, (U64)event->entity_id);
|
||||
@@ -2934,7 +2961,7 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
|
||||
(spoof == 0 || ev->instruction_pointer != spoof->new_ip_value))
|
||||
{
|
||||
Access *access = access_open();
|
||||
D_Handle process_handle = d_handle_from_dmn(D_MachineID_Local, ev->process);
|
||||
D_Handle process_handle = d_handle_from_dmn(D_DemonID_LocalHost, ev->process);
|
||||
D_Entity *process = d_entity_from_handle(process_handle);
|
||||
D_Entity *module = d_module_from_process_vaddr(process, ev->instruction_pointer);
|
||||
if(module != &d_entity_nil)
|
||||
@@ -3135,7 +3162,7 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
|
||||
D_Event *out_evt = d_event_list_push(scratch.arena, &evts);
|
||||
out_evt->kind = D_EventKind_NewProc;
|
||||
out_evt->msg_id = msg_id;
|
||||
out_evt->entity = d_handle_from_dmn(D_MachineID_Local, event->process);
|
||||
out_evt->entity = d_handle_from_dmn(D_DemonID_LocalHost, event->process);
|
||||
out_evt->arch = event->arch;
|
||||
out_evt->entity_id = event->code;
|
||||
out_evt->os = OperatingSystem_CURRENT; // TODO: operating system of the remote target machine
|
||||
@@ -3148,8 +3175,8 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
|
||||
D_Event *out_evt = d_event_list_push(scratch.arena, &evts);
|
||||
out_evt->kind = D_EventKind_NewThread;
|
||||
out_evt->msg_id = msg->msg_id;
|
||||
out_evt->entity = d_handle_from_dmn(D_MachineID_Local, event->thread);
|
||||
out_evt->parent = d_handle_from_dmn(D_MachineID_Local, event->process);
|
||||
out_evt->entity = d_handle_from_dmn(D_DemonID_LocalHost, event->thread);
|
||||
out_evt->parent = d_handle_from_dmn(D_DemonID_LocalHost, event->process);
|
||||
out_evt->arch = event->arch;
|
||||
out_evt->entity_id = event->code;
|
||||
out_evt->stack_base = event->stack_pointer;
|
||||
@@ -3164,8 +3191,8 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
|
||||
Temp scratch2 = scratch_begin(&scratch.arena, 1);
|
||||
|
||||
//- rjf: unpack module
|
||||
D_Handle process_handle = d_handle_from_dmn(D_MachineID_Local, event->process);
|
||||
D_Handle module_handle = d_handle_from_dmn(D_MachineID_Local, event->module);
|
||||
D_Handle process_handle = d_handle_from_dmn(D_DemonID_LocalHost, event->process);
|
||||
D_Handle module_handle = d_handle_from_dmn(D_DemonID_LocalHost, event->module);
|
||||
String8 module_path = path_normalized_from_string(scratch2.arena, event->string);
|
||||
U64 exe_timestamp = properties_from_file_path(module_path).modified;
|
||||
DMN_ModuleInfo *module_info = event->module_info;
|
||||
@@ -3330,7 +3357,7 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
|
||||
D_Event *out_evt = d_event_list_push(scratch.arena, &evts);
|
||||
out_evt->kind = D_EventKind_EndProc;
|
||||
out_evt->msg_id = msg->msg_id;
|
||||
out_evt->entity = d_handle_from_dmn(D_MachineID_Local, event->process);
|
||||
out_evt->entity = d_handle_from_dmn(D_DemonID_LocalHost, event->process);
|
||||
out_evt->u64_code = event->code;
|
||||
d_ctrl_state->process_counter -= 1;
|
||||
}break;
|
||||
@@ -3341,7 +3368,7 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
|
||||
D_Event *out_evt = d_event_list_push(scratch.arena, &evts);
|
||||
out_evt->kind = D_EventKind_EndThread;
|
||||
out_evt->msg_id = msg->msg_id;
|
||||
out_evt->entity = d_handle_from_dmn(D_MachineID_Local, event->thread);
|
||||
out_evt->entity = d_handle_from_dmn(D_DemonID_LocalHost, event->thread);
|
||||
out_evt->entity_id = event->code;
|
||||
}break;
|
||||
|
||||
@@ -3349,7 +3376,7 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
|
||||
case DMN_EventKind_UnloadModule:
|
||||
{
|
||||
//- rjf: unpack module
|
||||
D_Handle module_handle = d_handle_from_dmn(D_MachineID_Local, event->module);
|
||||
D_Handle module_handle = d_handle_from_dmn(D_DemonID_LocalHost, event->module);
|
||||
D_Entity *module_ent = d_entity_from_handle(module_handle);
|
||||
D_Entity *process_ent = d_process_from_entity(module_ent);
|
||||
String8 module_path = event->string;
|
||||
@@ -3386,8 +3413,8 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
|
||||
D_Event *out_evt = d_event_list_push(scratch.arena, &evts);
|
||||
out_evt->kind = D_EventKind_DebugString;
|
||||
out_evt->msg_id = msg->msg_id;
|
||||
out_evt->entity = d_handle_from_dmn(D_MachineID_Local, event->thread);
|
||||
out_evt->parent = d_handle_from_dmn(D_MachineID_Local, event->process);
|
||||
out_evt->entity = d_handle_from_dmn(D_DemonID_LocalHost, event->thread);
|
||||
out_evt->parent = d_handle_from_dmn(D_DemonID_LocalHost, event->process);
|
||||
out_evt->string = str8_substr(event->string, r1u64(string_idx*d_ctrl_state->c2u_ring_max_string_size, (string_idx+1)*d_ctrl_state->c2u_ring_max_string_size));
|
||||
}
|
||||
}break;
|
||||
@@ -3398,8 +3425,8 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
|
||||
D_Event *out_evt = d_event_list_push(scratch.arena, &evts);
|
||||
out_evt->kind = D_EventKind_ThreadName;
|
||||
out_evt->msg_id = msg->msg_id;
|
||||
out_evt->entity = d_handle_from_dmn(D_MachineID_Local, event->thread);
|
||||
out_evt->parent = d_handle_from_dmn(D_MachineID_Local, event->process);
|
||||
out_evt->entity = d_handle_from_dmn(D_DemonID_LocalHost, event->thread);
|
||||
out_evt->parent = d_handle_from_dmn(D_DemonID_LocalHost, event->process);
|
||||
out_evt->string = event->string;
|
||||
out_evt->entity_id = event->code;
|
||||
}break;
|
||||
@@ -3410,8 +3437,8 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
|
||||
D_Event *out_evt = d_event_list_push(scratch.arena, &evts);
|
||||
out_evt->kind = D_EventKind_ThreadColor;
|
||||
out_evt->msg_id = msg->msg_id;
|
||||
out_evt->entity = d_handle_from_dmn(D_MachineID_Local, event->thread);
|
||||
out_evt->parent = d_handle_from_dmn(D_MachineID_Local, event->process);
|
||||
out_evt->entity = d_handle_from_dmn(D_DemonID_LocalHost, event->thread);
|
||||
out_evt->parent = d_handle_from_dmn(D_DemonID_LocalHost, event->process);
|
||||
out_evt->entity_id = event->code;
|
||||
out_evt->rgba = event->user_data;
|
||||
}break;
|
||||
@@ -3421,7 +3448,7 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
|
||||
{
|
||||
D_Event *out_evt = d_event_list_push(scratch.arena, &evts);
|
||||
out_evt->kind = D_EventKind_SetVAddrRangeNote;
|
||||
out_evt->parent = d_handle_from_dmn(D_MachineID_Local, event->process);
|
||||
out_evt->parent = d_handle_from_dmn(D_DemonID_LocalHost, event->process);
|
||||
out_evt->msg_id = msg->msg_id;
|
||||
out_evt->vaddr_rng = r1u64(event->address, event->address + event->size);
|
||||
out_evt->string = event->string;
|
||||
@@ -3432,8 +3459,8 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
|
||||
{
|
||||
D_Event *out_evt = d_event_list_push(scratch.arena, &evts);
|
||||
out_evt->kind = D_EventKind_SetBreakpoint;
|
||||
out_evt->entity = d_handle_from_dmn(D_MachineID_Local, event->thread);
|
||||
out_evt->parent = d_handle_from_dmn(D_MachineID_Local, event->process);
|
||||
out_evt->entity = d_handle_from_dmn(D_DemonID_LocalHost, event->thread);
|
||||
out_evt->parent = d_handle_from_dmn(D_DemonID_LocalHost, event->process);
|
||||
out_evt->vaddr_rng = r1u64(event->address, event->address+event->size);
|
||||
out_evt->bp_flags = d_breakpoint_flags_from_dmn_trap_flags(event->flags);
|
||||
}break;
|
||||
@@ -3444,8 +3471,8 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
|
||||
// TODO(rjf): this needs to be reflected in the resolved trap list too!!!!!!!!
|
||||
D_Event *out_evt = d_event_list_push(scratch.arena, &evts);
|
||||
out_evt->kind = D_EventKind_UnsetBreakpoint;
|
||||
out_evt->entity = d_handle_from_dmn(D_MachineID_Local, event->thread);
|
||||
out_evt->parent = d_handle_from_dmn(D_MachineID_Local, event->process);
|
||||
out_evt->entity = d_handle_from_dmn(D_DemonID_LocalHost, event->thread);
|
||||
out_evt->parent = d_handle_from_dmn(D_DemonID_LocalHost, event->process);
|
||||
out_evt->vaddr_rng = r1u64(event->address, event->address+event->size);
|
||||
out_evt->bp_flags = d_breakpoint_flags_from_dmn_trap_flags(event->flags);
|
||||
}break;
|
||||
@@ -4111,7 +4138,7 @@ d_ctrl_thread__open_crash_dump(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
|
||||
|
||||
// rjf: create process handle
|
||||
d_ctrl_state->ctrl_thread_dump_handle_id_gen += 1;
|
||||
process = d_dump_handle_make(D_MachineID_Local, d_ctrl_state->ctrl_thread_dump_handle_id_gen);
|
||||
process = d_dump_handle_make(D_DemonID_LocalHost, d_ctrl_state->ctrl_thread_dump_handle_id_gen);
|
||||
|
||||
// rjf: gather threads
|
||||
dump_threads_count = threads_count;
|
||||
@@ -4128,7 +4155,7 @@ d_ctrl_thread__open_crash_dump(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
|
||||
{
|
||||
d_ctrl_state->ctrl_thread_dump_handle_id_gen += 1;
|
||||
MDMP_Thread *thread = &threads[idx];
|
||||
D_Handle thread_handle = d_dump_handle_make(D_MachineID_Local, d_ctrl_state->ctrl_thread_dump_handle_id_gen);
|
||||
D_Handle thread_handle = d_dump_handle_make(D_DemonID_LocalHost, d_ctrl_state->ctrl_thread_dump_handle_id_gen);
|
||||
dump_threads[idx].thread_handle = thread_handle;
|
||||
dump_threads[idx].id = thread->id;
|
||||
dump_threads[idx].context_foff = thread->thread_context.foff;
|
||||
@@ -4233,7 +4260,7 @@ d_ctrl_thread__open_crash_dump(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
|
||||
|
||||
// rjf: store
|
||||
d_ctrl_state->ctrl_thread_dump_handle_id_gen += 1;
|
||||
dump_modules[idx].module_handle = d_dump_handle_make(D_MachineID_Local, d_ctrl_state->ctrl_thread_dump_handle_id_gen);
|
||||
dump_modules[idx].module_handle = d_dump_handle_make(D_DemonID_LocalHost, d_ctrl_state->ctrl_thread_dump_handle_id_gen);
|
||||
dump_modules[idx].vaddr_range = vaddr_range;
|
||||
dump_modules[idx].path = str8_copy(arena, module_name);
|
||||
dump_modules[idx].file = module_file;
|
||||
@@ -4589,7 +4616,7 @@ d_ctrl_thread__kill_all(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
|
||||
default:{}break;
|
||||
case DMN_EventKind_CreateProcess:
|
||||
{
|
||||
D_Entity *new_process = d_entity_from_handle(d_handle_from_dmn(D_MachineID_Local, event->process));
|
||||
D_Entity *new_process = d_entity_from_handle(d_handle_from_dmn(D_DemonID_LocalHost, event->process));
|
||||
Task *t = push_array(scratch.arena, Task, 1);
|
||||
t->process = new_process;
|
||||
DLLPushBack(first_task, last_task, t);
|
||||
@@ -4810,7 +4837,7 @@ d_ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
|
||||
node != 0;
|
||||
node = node->next)
|
||||
{
|
||||
D_Handle thread = d_handle_from_dmn(D_MachineID_Local, node->v);
|
||||
D_Handle thread = d_handle_from_dmn(D_DemonID_LocalHost, node->v);
|
||||
U64 thread_pre_rip = d_ip_from_thread(thread);
|
||||
U64 thread_post_rip = thread_pre_rip;
|
||||
for(B32 done = 0; !done;)
|
||||
@@ -4829,7 +4856,7 @@ d_ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
|
||||
{
|
||||
default:{}break;
|
||||
case DMN_EventKind_ExitThread:
|
||||
if(d_handle_match(d_handle_from_dmn(D_MachineID_Local, event->thread), thread))
|
||||
if(d_handle_match(d_handle_from_dmn(D_DemonID_LocalHost, event->thread), thread))
|
||||
{
|
||||
stop_cause = D_EventCause_Error;
|
||||
goto stop;
|
||||
@@ -4992,7 +5019,7 @@ d_ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
|
||||
D_EvalScope *eval_scope = d_ctrl_thread__eval_scope_begin(scratch.arena, &msg->user_bps, &d_entity_nil);
|
||||
{
|
||||
DMN_TrapChunkList new_traps = {0};
|
||||
d_ctrl_thread__append_resolved_process_user_bp_traps(scratch.arena, eval_scope, d_handle_from_dmn(D_MachineID_Local, event->process), &msg->user_bps, &new_traps);
|
||||
d_ctrl_thread__append_resolved_process_user_bp_traps(scratch.arena, eval_scope, d_handle_from_dmn(D_DemonID_LocalHost, event->process), &msg->user_bps, &new_traps);
|
||||
log_infof("step_rule: create_process -> resolve traps\n");
|
||||
log_infof("new_traps:\n{\n");
|
||||
for(DMN_TrapChunkNode *n = new_traps.first; n != 0; n = n->next)
|
||||
@@ -5011,11 +5038,11 @@ d_ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
|
||||
}break;
|
||||
case DMN_EventKind_LoadModule:
|
||||
{
|
||||
D_Entity *thread = d_entity_from_handle(d_handle_from_dmn(D_MachineID_Local, event->thread));
|
||||
D_Entity *thread = d_entity_from_handle(d_handle_from_dmn(D_DemonID_LocalHost, event->thread));
|
||||
D_EvalScope *eval_scope = d_ctrl_thread__eval_scope_begin(scratch.arena, &msg->user_bps, thread);
|
||||
{
|
||||
DMN_TrapChunkList new_traps = {0};
|
||||
d_ctrl_thread__append_resolved_module_user_bp_traps(scratch.arena, eval_scope, d_handle_from_dmn(D_MachineID_Local, event->process), d_handle_from_dmn(D_MachineID_Local, event->module), &msg->user_bps, &new_traps);
|
||||
d_ctrl_thread__append_resolved_module_user_bp_traps(scratch.arena, eval_scope, d_handle_from_dmn(D_DemonID_LocalHost, event->process), d_handle_from_dmn(D_DemonID_LocalHost, event->module), &msg->user_bps, &new_traps);
|
||||
log_infof("step_rule: load_module -> resolve traps\n");
|
||||
log_infof("new_traps:\n{\n");
|
||||
for(DMN_TrapChunkNode *n = new_traps.first; n != 0; n = n->next)
|
||||
@@ -5036,7 +5063,7 @@ d_ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
|
||||
{
|
||||
D_Entity *bp = &d_entity_nil;
|
||||
{
|
||||
D_Entity *process = d_entity_from_handle(d_handle_from_dmn(D_MachineID_Local, event->process));
|
||||
D_Entity *process = d_entity_from_handle(d_handle_from_dmn(D_DemonID_LocalHost, event->process));
|
||||
for(D_Entity *child = process->first; child != &d_entity_nil; child = child->next)
|
||||
{
|
||||
if(child->kind == D_EntityKind_Breakpoint &&
|
||||
@@ -5068,7 +5095,7 @@ d_ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
|
||||
Access *access = access_open();
|
||||
|
||||
//- rjf: unpack process/module info
|
||||
D_Entity *process = d_entity_from_handle(d_handle_from_dmn(D_MachineID_Local, event->process));
|
||||
D_Entity *process = d_entity_from_handle(d_handle_from_dmn(D_DemonID_LocalHost, event->process));
|
||||
D_Entity *module = d_entity_child_from_kind(process, D_EntityKind_Module);
|
||||
U64 module_base_vaddr = module->vaddr_range.min;
|
||||
DI_Key dbgi_key = d_dbgi_key_from_module(module);
|
||||
@@ -5294,8 +5321,8 @@ d_ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
|
||||
//////////////////////////
|
||||
//- rjf: unpack info about thread attached to event
|
||||
//
|
||||
D_Entity *thread = d_entity_from_handle(d_handle_from_dmn(D_MachineID_Local, event->thread));
|
||||
D_Entity *process = d_entity_from_handle(d_handle_from_dmn(D_MachineID_Local, event->process));
|
||||
D_Entity *thread = d_entity_from_handle(d_handle_from_dmn(D_DemonID_LocalHost, event->thread));
|
||||
D_Entity *process = d_entity_from_handle(d_handle_from_dmn(D_DemonID_LocalHost, event->process));
|
||||
Arch arch = thread->arch;
|
||||
U64 thread_rip_vaddr = d_ip_from_thread(thread->handle);
|
||||
D_Entity *module = d_module_from_process_vaddr(process, thread_rip_vaddr);
|
||||
@@ -5483,7 +5510,7 @@ d_ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
|
||||
D_EventCause cond_bp_single_step_stop_cause = D_EventCause_Null;
|
||||
if(hit_conditional_bp_but_filtered) LogInfoNamedBlockF("conditional_bp_hit_single_step")
|
||||
{
|
||||
D_Handle thread = d_handle_from_dmn(D_MachineID_Local, event->thread);
|
||||
D_Handle thread = d_handle_from_dmn(D_DemonID_LocalHost, event->thread);
|
||||
U64 thread_pre_rip = d_ip_from_thread(thread);
|
||||
U64 thread_post_rip = thread_pre_rip;
|
||||
for(B32 single_step_done = 0; !single_step_done;)
|
||||
@@ -5513,7 +5540,7 @@ d_ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
|
||||
}break;
|
||||
case DMN_EventKind_SingleStep:
|
||||
{
|
||||
single_step_done = d_handle_match(d_handle_from_dmn(D_MachineID_Local, event->thread), thread);
|
||||
single_step_done = d_handle_match(d_handle_from_dmn(D_DemonID_LocalHost, event->thread), thread);
|
||||
cond_bp_single_step_stop_cause = d_event_cause_from_dmn_event_kind(event->kind);
|
||||
}break;
|
||||
}
|
||||
@@ -5674,7 +5701,7 @@ d_ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
|
||||
D_EventCause step_past_trap_net_stop_cause = D_EventCause_Null;
|
||||
if(step_past_trap_net) LogInfoNamedBlockF("trap_net__single_step_past_trap_net")
|
||||
{
|
||||
D_Handle thread = d_handle_from_dmn(D_MachineID_Local, event->thread);
|
||||
D_Handle thread = d_handle_from_dmn(D_DemonID_LocalHost, event->thread);
|
||||
U64 thread_pre_rip = d_ip_from_thread(thread);
|
||||
U64 thread_post_rip = thread_pre_rip;
|
||||
for(B32 single_step_done = 0; single_step_done == 0;)
|
||||
@@ -5703,7 +5730,7 @@ d_ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
|
||||
}break;
|
||||
case DMN_EventKind_SingleStep:
|
||||
{
|
||||
single_step_done = d_handle_match(d_handle_from_dmn(D_MachineID_Local, event->thread), thread);
|
||||
single_step_done = d_handle_match(d_handle_from_dmn(D_DemonID_LocalHost, event->thread), thread);
|
||||
step_past_trap_net_stop_cause = d_event_cause_from_dmn_event_kind(event->kind);
|
||||
}break;
|
||||
}
|
||||
@@ -5763,8 +5790,8 @@ d_ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
|
||||
D_Event *event = d_event_list_push(scratch.arena, &evts);
|
||||
event->kind = D_EventKind_Stopped;
|
||||
event->cause = stop_cause;
|
||||
event->entity = d_handle_from_dmn(D_MachineID_Local, stop_event->thread);
|
||||
event->parent = d_handle_from_dmn(D_MachineID_Local, stop_event->process);
|
||||
event->entity = d_handle_from_dmn(D_DemonID_LocalHost, stop_event->thread);
|
||||
event->parent = d_handle_from_dmn(D_DemonID_LocalHost, stop_event->process);
|
||||
event->exception_code = stop_event->code;
|
||||
event->exception_kind = d_exception_kind_from_dmn(stop_event->exception_kind);
|
||||
event->vaddr_rng = r1u64(stop_event->address, stop_event->address);
|
||||
@@ -5847,8 +5874,8 @@ d_ctrl_thread__single_step(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
|
||||
event->cause = stop_cause;
|
||||
if(stop_event != 0)
|
||||
{
|
||||
event->entity = d_handle_from_dmn(D_MachineID_Local, stop_event->thread);
|
||||
event->parent = d_handle_from_dmn(D_MachineID_Local, stop_event->process);
|
||||
event->entity = d_handle_from_dmn(D_DemonID_LocalHost, stop_event->thread);
|
||||
event->parent = d_handle_from_dmn(D_DemonID_LocalHost, stop_event->process);
|
||||
event->exception_code = stop_event->code;
|
||||
event->exception_kind = d_exception_kind_from_dmn(stop_event->exception_kind);
|
||||
event->vaddr_rng = r1u64(stop_event->address, stop_event->address);
|
||||
|
||||
@@ -313,6 +313,68 @@ struct D_ModuleReqCacheNode
|
||||
#define D_WAKEUP_FUNCTION_DEF(name) void name(void)
|
||||
typedef D_WAKEUP_FUNCTION_DEF(D_WakeupFunctionType);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Demon Interface V-Table
|
||||
|
||||
typedef struct D_DemonInterface D_DemonInterface;
|
||||
struct D_DemonInterface
|
||||
{
|
||||
//- rjf: control
|
||||
void (*ctrl_exclusive_access_begin)(void);
|
||||
void (*ctrl_exclusive_access_end)(void);
|
||||
U32 (*launch)(DMN_CtrlCtx *ctx, ProcessLaunchParams *params);
|
||||
B32 (*attach)(DMN_CtrlCtx *ctx, U32 pid);
|
||||
B32 (*kill)(DMN_CtrlCtx *ctx, DMN_Handle process, U32 exit_code);
|
||||
B32 (*detach)(DMN_CtrlCtx *ctx, DMN_Handle process);
|
||||
DMN_EventList (*run)(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls);
|
||||
|
||||
//- rjf: halting
|
||||
void (*halt)(U64 code, U64 user_data);
|
||||
|
||||
//- rjf: non-blocking-control-thread access barriers
|
||||
B32 (*access_open)(void);
|
||||
void (*access_close)(void);
|
||||
|
||||
//- rjf: process memory
|
||||
U64 (*reserve_memory)(DMN_Handle process, U64 vaddr, U64 size);
|
||||
void (*commit_memory)(DMN_Handle process, U64 vaddr, U64 size);
|
||||
void (*decommit_memory)(DMN_Handle process, U64 vaddr, U64 size);
|
||||
void (*release_memory)(DMN_Handle process, U64 vaddr, U64 size);
|
||||
void (*protect_memory)(DMN_Handle process, U64 vaddr, U64 size, AccessFlags flags);
|
||||
U64 (*read_memory)(DMN_Handle process, Rng1U64 range, void *dst);
|
||||
B32 (*write_memory)(DMN_Handle process, Rng1U64 range, void *src);
|
||||
|
||||
//- rjf: threads
|
||||
B32 (*thread_read_reg_block)(DMN_Handle thread, void *dst);
|
||||
B32 (*thread_write_reg_block)(DMN_Handle thread, void *src);
|
||||
B32 (*thread_get_module_tls_vaddr)(DMN_Handle thread, DMN_Handle module, U64 *vaddr_out);
|
||||
};
|
||||
|
||||
typedef struct D_DemonState D_DemonState;
|
||||
struct D_DemonState
|
||||
{
|
||||
D_DemonState *next;
|
||||
D_DemonState *prev;
|
||||
D_DemonID id;
|
||||
D_DemonInterface *fn;
|
||||
Arena *event_arena;
|
||||
DMN_EventList events;
|
||||
};
|
||||
|
||||
typedef struct D_DemonStateSlot D_DemonStateSlot;
|
||||
struct D_DemonStateSlot
|
||||
{
|
||||
D_DemonState *first;
|
||||
D_DemonState *last;
|
||||
};
|
||||
|
||||
typedef struct D_DemonCache D_DemonCache;
|
||||
struct D_DemonCache
|
||||
{
|
||||
U64 slots_count;
|
||||
D_DemonStateSlot *slots;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Main State Types
|
||||
|
||||
@@ -426,8 +488,8 @@ internal D_HandleArray d_handle_array_from_list(Arena *arena, D_HandleList *src
|
||||
internal String8 d_string_from_handle(Arena *arena, D_Handle handle);
|
||||
internal D_Handle d_handle_from_string(String8 string);
|
||||
internal DMN_Handle d_dmn_from_handle(D_Handle handle);
|
||||
internal D_Handle d_handle_from_dmn(D_MachineID machine_id, DMN_Handle handle);
|
||||
internal D_Handle d_dump_handle_make(D_MachineID machine_id, U64 id);
|
||||
internal D_Handle d_handle_from_dmn(D_DemonID demon_id, DMN_Handle handle);
|
||||
internal D_Handle d_dump_handle_make(D_DemonID demon_id, U64 id);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Trap Type Functions
|
||||
|
||||
@@ -2104,13 +2104,13 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
|
||||
}break;
|
||||
case D_CmdKind_FreezeLocalMachine:
|
||||
{
|
||||
D_MachineID machine_id = D_MachineID_Local;
|
||||
d_cmd(D_CmdKind_FreezeMachine, .entity = d_handle_from_dmn(machine_id, dmn_handle_zero()));
|
||||
D_DemonID demon_id = D_DemonID_LocalHost;
|
||||
d_cmd(D_CmdKind_FreezeMachine, .entity = d_handle_from_dmn(demon_id, dmn_handle_zero()));
|
||||
}break;
|
||||
case D_CmdKind_ThawLocalMachine:
|
||||
{
|
||||
D_MachineID machine_id = D_MachineID_Local;
|
||||
d_cmd(D_CmdKind_ThawMachine, .entity = d_handle_from_dmn(machine_id, dmn_handle_zero()));
|
||||
D_DemonID demon_id = D_DemonID_LocalHost;
|
||||
d_cmd(D_CmdKind_ThawMachine, .entity = d_handle_from_dmn(demon_id, dmn_handle_zero()));
|
||||
}break;
|
||||
case D_CmdKind_FreezeEntity:
|
||||
case D_CmdKind_ThawEntity:
|
||||
|
||||
@@ -15,6 +15,12 @@ lnx_sock_listener_thread_entry_point(void *p)
|
||||
struct epoll_event evts[1] = {0};
|
||||
int wait_result = LNX_RETRY_ON_EINTR(epoll_wait(session->epoll_fd, evts, ArrayCount(evts), -1));
|
||||
|
||||
//- rjf: call wakeup hook
|
||||
if(session->wakeup_hook)
|
||||
{
|
||||
session->wakeup_hook();
|
||||
}
|
||||
|
||||
//- rjf: code is 0 -> listener is ready for accept
|
||||
if(evts[0].data.u64 == 0)
|
||||
{
|
||||
@@ -93,7 +99,7 @@ lnx_sock_listener_thread_entry_point(void *p)
|
||||
ssize_t recv_result = LNX_RETRY_ON_EINTR(recv(con->socket, buffer, sizeof(buffer), MSG_DONTWAIT));
|
||||
|
||||
// rjf: bytes received -> push result to user.
|
||||
if(recv_result >= 0)
|
||||
if(recv_result > 0)
|
||||
{
|
||||
RingGuard g = guarded_ring_open(session->s2u_ring);
|
||||
U64 header[5] =
|
||||
@@ -113,7 +119,8 @@ lnx_sock_listener_thread_entry_point(void *p)
|
||||
else RWMutexScope(stripe->rw_mutex, 1)
|
||||
{
|
||||
close(con->socket);
|
||||
LNX_RETRY_ON_EINTR(epoll_ctl(session->epoll_fd, EPOLL_CTL_DEL, con->socket, 0));
|
||||
struct epoll_event evt = {0}; // NOTE(rjf): required on Linux pre-2.6.9
|
||||
LNX_RETRY_ON_EINTR(epoll_ctl(session->epoll_fd, EPOLL_CTL_DEL, con->socket, &evt));
|
||||
DLLRemove(slot->first, slot->last, con);
|
||||
con->next = stripe->free;
|
||||
stripe->free = con;
|
||||
@@ -296,7 +303,7 @@ sock_async_tick(void)
|
||||
|
||||
// rjf: got socket? -> send
|
||||
B32 send_failed = 0;
|
||||
if(ep_socket != -1 && send(ep_socket, t->data.str, t->data.size, 0) == -1)
|
||||
if(ep_socket != -1 && send(ep_socket, t->data.str, t->data.size, MSG_NOSIGNAL) == -1)
|
||||
{
|
||||
send_failed = 1;
|
||||
}
|
||||
@@ -311,7 +318,8 @@ sock_async_tick(void)
|
||||
if(MemoryMatchStruct(&c->endpoint, &t->endpoint))
|
||||
{
|
||||
close(c->socket);
|
||||
LNX_RETRY_ON_EINTR(epoll_ctl(session->epoll_fd, EPOLL_CTL_DEL, c->socket, 0));
|
||||
struct epoll_event evt = {0}; // NOTE(rjf): required on Linux pre-2.6.9
|
||||
LNX_RETRY_ON_EINTR(epoll_ctl(session->epoll_fd, EPOLL_CTL_DEL, c->socket, &evt));
|
||||
DLLRemove(slot->first, slot->last, c);
|
||||
c->next = stripe->free;
|
||||
stripe->free = c;
|
||||
@@ -337,6 +345,7 @@ sock_session_open(U16 listener_port, SOCK_WakeupFunctionType *wakeup_hook)
|
||||
session->u2s_ring = guarded_ring_alloc(arena, KB(256));
|
||||
session->s2u_ring = guarded_ring_alloc(arena, KB(256));
|
||||
session->epoll_fd = epoll_create(1);
|
||||
session->wakeup_hook = wakeup_hook;
|
||||
|
||||
//- rjf: set up listener
|
||||
{
|
||||
|
||||
@@ -40,6 +40,7 @@ struct LNX_SOCK_Session
|
||||
GuardedRing *u2s_ring;
|
||||
GuardedRing *s2u_ring;
|
||||
int epoll_fd;
|
||||
SOCK_WakeupFunctionType *wakeup_hook;
|
||||
int tcp_listen_socket;
|
||||
U64 connection_slots_count;
|
||||
StripeArray connection_stripes;
|
||||
|
||||
@@ -1136,7 +1136,7 @@ wm_get_events(Arena *arena, B32 wait)
|
||||
{ .fd = ConnectionNumber(lnx_wm_state->display), .events = POLLIN },
|
||||
{ .fd = lnx_wm_state->wakeup_fd, .events = POLLIN },
|
||||
};
|
||||
int timeout = wait && evts.count == 0 ? -1 : 0;
|
||||
int timeout = (wait && evts.count == 0 ? -1 : 0);
|
||||
int poll_status = poll(poll_fds, ArrayCount(poll_fds), timeout);
|
||||
if(poll_fds[1].revents & POLLIN)
|
||||
{
|
||||
|
||||
@@ -711,7 +711,7 @@ rd_ctrl_entity_from_eval_space(E_Space space)
|
||||
space.kind == RD_EvalSpaceKind_MetaUnattachedProcess)
|
||||
{
|
||||
D_Handle handle;
|
||||
handle.machine_id = (U32)((space.u64s[0] & 0xffffffff00000000ull) >> 32);
|
||||
handle.demon_id = (U32)((space.u64s[0] & 0xffffffff00000000ull) >> 32);
|
||||
handle.controller_kind = (U32)((space.u64s[0] & 0x00000000ffffffffull) >> 0);
|
||||
handle.entity_id = space.u64s[1];
|
||||
entity = d_entity_from_handle(handle);
|
||||
@@ -726,7 +726,7 @@ rd_eval_space_from_ctrl_entity(D_Entity *entity, E_SpaceKind kind)
|
||||
if(entity != &d_entity_nil)
|
||||
{
|
||||
space = e_space_make(kind);
|
||||
space.u64s[0] = (((U64)entity->handle.machine_id) << 32) | (((U64)entity->handle.controller_kind) << 0);
|
||||
space.u64s[0] = (((U64)entity->handle.demon_id) << 32) | (((U64)entity->handle.controller_kind) << 0);
|
||||
space.u64s[1] = entity->handle.entity_id;
|
||||
}
|
||||
return space;
|
||||
@@ -2828,7 +2828,7 @@ rd_view_ui(Rng2F32 rect)
|
||||
CFG_Node *locked = cfg_node_child_from_string_or_alloc(rd_state->cfg, cfg, s("locked"));
|
||||
cfg_node_release_all_children(rd_state->cfg, locked);
|
||||
CFG_Node *mid = cfg_node_new(rd_state->cfg, locked, s("mid"));
|
||||
cfg_node_newf(rd_state->cfg, mid, "%I64u", entity->handle.machine_id);
|
||||
cfg_node_newf(rd_state->cfg, mid, "%I64u", entity->handle.demon_id);
|
||||
CFG_Node *pid = cfg_node_new(rd_state->cfg, locked, s("pid"));
|
||||
cfg_node_newf(rd_state->cfg, pid, "%I64u", entity->id);
|
||||
CFG_Node *addr = cfg_node_new(rd_state->cfg, locked, s("addr"));
|
||||
@@ -4631,7 +4631,7 @@ rd_view_ui(Rng2F32 rect)
|
||||
CFG_Node *locked = cfg_node_child_from_string_or_alloc(rd_state->cfg, cfg, s("locked"));
|
||||
cfg_node_release_all_children(rd_state->cfg, locked);
|
||||
CFG_Node *mid = cfg_node_new(rd_state->cfg, locked, s("mid"));
|
||||
cfg_node_newf(rd_state->cfg, mid, "%I64u", entity->handle.machine_id);
|
||||
cfg_node_newf(rd_state->cfg, mid, "%I64u", entity->handle.demon_id);
|
||||
CFG_Node *pid = cfg_node_new(rd_state->cfg, locked, s("pid"));
|
||||
cfg_node_newf(rd_state->cfg, pid, "%I64u", entity->id);
|
||||
CFG_Node *addr = cfg_node_new(rd_state->cfg, locked, s("addr"));
|
||||
@@ -6367,7 +6367,7 @@ rd_window_frame(void)
|
||||
ID(panel);
|
||||
ID(view);
|
||||
#undef ID
|
||||
#define Handle(name) ui_labelf("%s: [0x%x, 0x%x, 0x%I64x]", #name, (regs->name).machine_id, (regs->name).controller_kind, (regs->name).entity_id)
|
||||
#define Handle(name) ui_labelf("%s: [0x%x, 0x%x, 0x%I64x]", #name, (regs->name).demon_id, (regs->name).controller_kind, (regs->name).entity_id)
|
||||
Handle(machine);
|
||||
Handle(process);
|
||||
Handle(module);
|
||||
@@ -12822,7 +12822,7 @@ rd_frame(void)
|
||||
{
|
||||
e_string2expr_map_insert(scratch.arena, macro_map, entity->string, expr);
|
||||
}
|
||||
if(kind == D_EntityKind_Machine && entity->handle.machine_id == D_MachineID_Local)
|
||||
if(kind == D_EntityKind_Machine && entity->handle.demon_id == D_DemonID_LocalHost)
|
||||
{
|
||||
e_string2expr_map_insert(scratch.arena, macro_map, str8_lit("local_machine"), expr);
|
||||
}
|
||||
|
||||
+53
-15
@@ -628,6 +628,7 @@ entry_point(CmdLine *cmd_line)
|
||||
make_directory(g_logs_folder);
|
||||
|
||||
//- rjf: dispatch to top-level codepath based on execution mode
|
||||
U32 ipc_packet_magic_start = 0x72726300;
|
||||
switch(exec_mode)
|
||||
{
|
||||
//- rjf: normal execution
|
||||
@@ -689,16 +690,34 @@ entry_point(CmdLine *cmd_line)
|
||||
{
|
||||
for(B32 quit = 0; !quit;)
|
||||
{
|
||||
//- rjf: receive socket data, run as IPC messages
|
||||
//- rjf: receive packets, run as IPC messages
|
||||
B32 ipc_command_frame = 0;
|
||||
SOCK_Protocol ipc_protocol = SOCK_Protocol_TCP;
|
||||
SOCK_Endpoint ipc_endpoint = {0};
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
String8 msg = {0};
|
||||
if(sock_recv(scratch.arena, icp_sock_session, &ipc_protocol, &ipc_endpoint, &msg, 0))
|
||||
String8 packet = {0};
|
||||
if(sock_recv(scratch.arena, icp_sock_session, &ipc_protocol, &ipc_endpoint, &packet, 0))
|
||||
{
|
||||
// rjf: use header to determine message portion
|
||||
String8 msg = {0};
|
||||
{
|
||||
U64 msg_size = 0;
|
||||
U64 header_size = sizeof(ipc_packet_magic_start) + sizeof(U64);
|
||||
if(str8_match(packet, str8_struct(&ipc_packet_magic_start), StringMatchFlag_RightSideSloppy) &&
|
||||
packet.size >= header_size)
|
||||
{
|
||||
U64 msg_size_cap = packet.size - header_size;
|
||||
msg_size = *(U64 *)(packet.str + sizeof(ipc_packet_magic_start));
|
||||
msg_size = Min(msg_size, msg_size_cap);
|
||||
msg = str8_substr(packet, r1u64(header_size, header_size+msg_size));
|
||||
}
|
||||
}
|
||||
|
||||
// rjf: split command by ;s
|
||||
String8List cmd_parts_of_msg = str8_split(scratch.arena, msg, (U8 *)";", 1, 0);
|
||||
|
||||
// rjf: pick target window
|
||||
RD_WindowState *dst_ws = rd_state->first_window_state;
|
||||
for(RD_WindowState *ws = dst_ws; ws != &rd_nil_window_state; ws = ws->order_next)
|
||||
{
|
||||
@@ -708,6 +727,8 @@ entry_point(CmdLine *cmd_line)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// rjf: got a window -> send command
|
||||
if(dst_ws != &rd_nil_window_state)
|
||||
{
|
||||
dst_ws->window_temporarily_focused_ipc = 1;
|
||||
@@ -766,12 +787,10 @@ entry_point(CmdLine *cmd_line)
|
||||
//- rjf: gather command outputs & send them back back to sender
|
||||
if(ipc_command_frame)
|
||||
{
|
||||
StringJoin join = {s(""), s("\0"), s("")};
|
||||
String8 msg = str8_list_join(scratch.arena, &rd_state->cmd_outputs, &join);
|
||||
if(msg.size == 0)
|
||||
{
|
||||
msg = s("done");
|
||||
}
|
||||
U64 packet_size = rd_state->cmd_outputs.total_size;
|
||||
str8_list_push_front(scratch.arena, &rd_state->cmd_outputs, str8_struct(&packet_size));
|
||||
str8_list_push_front(scratch.arena, &rd_state->cmd_outputs, str8_struct(&ipc_packet_magic_start));
|
||||
String8 msg = str8_list_join(scratch.arena, &rd_state->cmd_outputs, 0);
|
||||
sock_send(icp_sock_session, ipc_protocol, ipc_endpoint, msg, now_time_us()+5000000);
|
||||
}
|
||||
}
|
||||
@@ -803,13 +822,23 @@ entry_point(CmdLine *cmd_line)
|
||||
//- rjf: form message from command line inputs
|
||||
String8List parts = {0};
|
||||
{
|
||||
String8List text_parts = {0};
|
||||
for EachIndex(idx, cmd_line->argc-1)
|
||||
{
|
||||
str8_list_push(scratch.arena, &parts, str8_cstring(cmd_line->argv[idx+1]));
|
||||
String8 arg = str8_cstring(cmd_line->argv[idx+1]);
|
||||
if(!str8_match(arg, s("--ipc"), 0) && !str8_match(arg, s("-ipc"), 0))
|
||||
{
|
||||
str8_list_push(scratch.arena, &text_parts, arg);
|
||||
}
|
||||
}
|
||||
StringJoin join = {.sep = s(" ")};
|
||||
String8 text = str8_list_join(scratch.arena, &text_parts, &join);
|
||||
U64 msg_size = text_parts.total_size;
|
||||
str8_list_push(scratch.arena, &parts, str8_struct(&ipc_packet_magic_start));
|
||||
str8_list_push(scratch.arena, &parts, str8_struct(&msg_size));
|
||||
str8_list_push(scratch.arena, &parts, text);
|
||||
}
|
||||
StringJoin join = {str8_lit(""), str8_lit(" "), str8_lit("")};
|
||||
String8 msg = str8_list_join(scratch.arena, &parts, &join);
|
||||
String8 msg = str8_list_join(scratch.arena, &parts, 0);
|
||||
|
||||
//- rjf: send to server, get outputs
|
||||
String8List outputs = {0};
|
||||
@@ -817,15 +846,24 @@ entry_point(CmdLine *cmd_line)
|
||||
{
|
||||
SOCK_Protocol outputs_protocol = SOCK_Protocol_TCP;
|
||||
SOCK_Endpoint outputs_endpoint = {0};
|
||||
String8 output_data = {0};
|
||||
if(sock_recv(scratch.arena, ipc_sock_session, &outputs_protocol, &outputs_endpoint, &output_data, now_time_us()+10000000))
|
||||
String8 packet = {0};
|
||||
if(sock_recv(scratch.arena, ipc_sock_session, &outputs_protocol, &outputs_endpoint, &packet, now_time_us()+10000000) &&
|
||||
str8_match(packet, str8_struct(&ipc_packet_magic_start), StringMatchFlag_RightSideSloppy) &&
|
||||
packet.size >= sizeof(ipc_packet_magic_start) + sizeof(U64))
|
||||
{
|
||||
U64 msg_size = *(U64 *)(packet.str + sizeof(ipc_packet_magic_start));
|
||||
String8 msg = str8_skip(packet, sizeof(ipc_packet_magic_start) + sizeof(U64));
|
||||
msg.size = Min(msg.size, msg_size);
|
||||
U8 split_char = 0;
|
||||
outputs = str8_split(scratch.arena, output_data, &split_char, 1, 0);
|
||||
outputs = str8_split(scratch.arena, msg, &split_char, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
//- rjf: write outputs to stdout
|
||||
if(outputs.node_count == 0)
|
||||
{
|
||||
fprintf(stdout, "(response received, no output)\n");
|
||||
}
|
||||
for(String8Node *n = outputs.first; n != 0; n = n->next)
|
||||
{
|
||||
fwrite(n->string.str, 1, n->string.size, stdout);
|
||||
|
||||
@@ -108,7 +108,11 @@ r_ogl_scissor(Rng2F32 clip, Vec2F32 viewport_dim)
|
||||
{
|
||||
glScissor(x0, (S32)viewport_dim.y - y1, width, height);
|
||||
}
|
||||
return width > 0 && height > 0;
|
||||
else
|
||||
{
|
||||
glScissor(0, 0, 0, 0);
|
||||
}
|
||||
return width > 0 || height > 0;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
Reference in new issue
Block a user