dbg_engine: multi-server debugging checkpoint - hash cache of (server ID -> state), where state is {ID * dmn event queue}. when dequeueing demon events, pull from servers in round-robin style before running. when running, resume-all. if the local server returns -> halt all remote servers. if a remote server returns before local -> halt local. still need to correctly supply run controls to all servers (dbg_engine run controls need to not just be dmn but multi-server), and need to adjust halting logic such that all remote servers are halted if another remote server generated an event too.

This commit is contained in:
Ryan Fleury committed 2026-10-15 13:23:18 -07:00
1 parent 8036f7bed0
commit 0d44ddea29
17 files changed
+842 -390

No files matched your search

+1 -1
View File
@@ -14,7 +14,7 @@ target:
executable: "build/raddbg_server.exe"
working_directory: build
debug_subprocesses: 1
arguments: "mule_main.exe"
enabled: 1
}
target:
{
+14 -2
View File
@@ -104,7 +104,7 @@ d_init(void)
Arena *arena = arena_alloc();
d_ctrl_state = push_array(arena, D_CtrlState, 1);
d_ctrl_state->arena = arena;
d_ctrl_state->sock_session = sock_session_open(0, 0);
d_ctrl_state->sock_session = sock_session_open(0, d_ctrl_sock_wakeup);
for EachEnumVal(Arch, arch)
{
ARCH_Info *arch_info = arch_info_from_arch(arch);
@@ -145,9 +145,21 @@ d_init(void)
d_ctrl_state->ctrl_thread_entity_store = d_entity_ctx_rw_store_alloc();
d_ctrl_state->ctrl_thread_eval_cache = e_cache_alloc();
d_ctrl_state->ctrl_thread_msg_process_arena = arena_alloc();
d_ctrl_state->server_slots_count = 16;
d_ctrl_state->server_slots = push_array(arena, D_ServerSlot, d_ctrl_state->server_slots_count);
{
D_ServerState *ss = push_array(arena, D_ServerState, 1);
ss->server_id = D_ServerID_LocalHost;
ss->dmn_event_arena = arena_alloc();
U64 slot_idx = ss->server_id%d_ctrl_state->server_slots_count;
DLLPushBack_NP(d_ctrl_state->first_server, d_ctrl_state->last_server, ss, order_next, order_prev);
DLLPushBack_NP(d_ctrl_state->server_slots[slot_idx].first, d_ctrl_state->server_slots[slot_idx].last, ss, hash_next, hash_prev);
d_ctrl_state->next_dequeue_server = ss;
}
#if 0
d_ctrl_state->dmn_event_arena = arena_alloc();
#endif
d_ctrl_state->user_entry_point_arena = arena_alloc();
d_ctrl_state->dbg_dir_arena = arena_alloc();
for(D_ExceptionCodeKind k = (D_ExceptionCodeKind)0; k < D_ExceptionCodeKind_COUNT; k = (D_ExceptionCodeKind)(k+1))
{
if(d_exception_code_kind_default_enable_table[k])
+2
View File
@@ -251,8 +251,10 @@ struct D_Target
String8 stdout_path;
String8 stderr_path;
String8 stdin_path;
String8 remote_address;
D_MsgID msg_id;
B32 debug_subprocesses;
B32 deploy;
String8List env;
};
+488 -288
View File
@@ -380,8 +380,13 @@ d_serialized_string_from_msg_list(Arena *arena, D_MsgList *msgs)
str8_serial_push_struct(scratch.arena, &msgs_srlzed, &msg->env_inherit);
str8_serial_push_struct(scratch.arena, &msgs_srlzed, &msg->debug_subprocesses);
str8_serial_push_struct(scratch.arena, &msgs_srlzed, &msg->auto_download_debug_info);
str8_serial_push_struct(scratch.arena, &msgs_srlzed, &msg->deploy);
str8_serial_push_array (scratch.arena, &msgs_srlzed, &msg->exception_code_filters[0], ArrayCount(msg->exception_code_filters));
// rjf: write address string
str8_serial_push_struct(scratch.arena, &msgs_srlzed, &msg->address.size);
str8_serial_push_data(scratch.arena, &msgs_srlzed, msg->address.str, msg->address.size);
// rjf: write path string
str8_serial_push_struct(scratch.arena, &msgs_srlzed, &msg->path.size);
str8_serial_push_data(scratch.arena, &msgs_srlzed, msg->path.str, msg->path.size);
@@ -481,8 +486,14 @@ d_msg_list_from_serialized_string(Arena *arena, String8 string)
read_off += str8_deserial_read_struct(string, read_off, &msg->env_inherit);
read_off += str8_deserial_read_struct(string, read_off, &msg->debug_subprocesses);
read_off += str8_deserial_read_struct(string, read_off, &msg->auto_download_debug_info);
read_off += str8_deserial_read_struct(string, read_off, &msg->deploy);
read_off += str8_deserial_read_array (string, read_off, &msg->exception_code_filters[0], ArrayCount(msg->exception_code_filters));
// rjf: read address string
read_off += str8_deserial_read_struct(string, read_off, &msg->address.size);
msg->address.str = push_array_no_zero(arena, U8, msg->address.size);
read_off += str8_deserial_read(string, read_off, msg->address.str, msg->address.size, 1);
// rjf: read path string
read_off += str8_deserial_read_struct(string, read_off, &msg->path.size);
msg->path.str = push_array_no_zero(arena, U8, msg->path.size);
@@ -2879,158 +2890,170 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
ProfBeginFunction();
DMN_Event *event = push_array(arena, DMN_Event, 1);
Temp scratch = scratch_begin(&arena, 1);
D_EntityCtx *entity_ctx = &d_ctrl_state->ctrl_thread_entity_store->ctx;
//- rjf: loop -> try to get event, run, repeat
//////////////////////////////
//- rjf: loop -> try to get event, run if we don't have any, repeat
//
U64 spoof_old_ip_value = 0;
ProfScope("loop -> try to get event, run, repeat") for(B32 got_event = 0; got_event == 0;)
ProfScope("loop -> try to get event, run, repeat") for(B32 got_event = 0; !got_event;)
{
////////////////////////////
//- rjf: get next event
//
ProfScope("get next event")
{
// rjf: grab first event
DMN_EventNode *next_event_node = d_ctrl_state->first_dmn_event_node;
// rjf: log event
if(next_event_node != 0)
B32 first = 1;
for(D_ServerState *ss = d_ctrl_state->next_dequeue_server;
ss != d_ctrl_state->next_dequeue_server || first;
(first = 0, ss = (ss->order_next == 0 ? d_ctrl_state->first_server : ss->order_next), d_ctrl_state->next_dequeue_server = ss))
{
DMN_Event *ev = &next_event_node->v;
LogInfoNamedBlockF("dmn_event")
//- rjf: grab first event from this server
DMN_EventNode *next_event_node = ss->first_dmn_event_node;
if(next_event_node != 0)
{
log_infof("kind: %S\n", dmn_event_kind_string_table[ev->kind]);
log_infof("exception_kind: %S\n", dmn_exception_kind_string_table[ev->exception_kind]);
log_infof("process: [%I64u]\n", ev->process.u64[0]);
log_infof("thread: [%I64u]\n", ev->thread.u64[0]);
log_infof("module: [%I64u]\n", ev->module.u64[0]);
log_infof("arch: %S\n", string_from_arch(ev->arch));
log_infof("address: 0x%I64x\n", ev->address);
log_infof("string: \"%S\"\n", ev->string);
log_infof("ip_vaddr: 0x%I64x\n", ev->instruction_pointer);
}
}
// rjf: determine if we should filter
B32 should_filter_event = 0;
if(next_event_node != 0)
{
DMN_Event *ev = &next_event_node->v;
switch(ev->kind)
{
default:{}break;
case DMN_EventKind_Exception:
DMN_Event *ev = &next_event_node->v;
LogInfoNamedBlockF("dmn_event")
{
// NOTE(rjf): first chance exceptions -> try ignoring
should_filter_event = (ev->exception_repeated == 0 && (spoof == 0 || ev->instruction_pointer != spoof->new_ip_value));
// rjf: exception code -> kind
D_ExceptionCodeKind code_kind = D_ExceptionCodeKind_Null;
if(should_filter_event)
log_infof("kind: %S\n", dmn_event_kind_string_table[ev->kind]);
log_infof("exception_kind: %S\n", dmn_exception_kind_string_table[ev->exception_kind]);
log_infof("process: [%I64u]\n", ev->process.u64[0]);
log_infof("thread: [%I64u]\n", ev->thread.u64[0]);
log_infof("module: [%I64u]\n", ev->module.u64[0]);
log_infof("arch: %S\n", string_from_arch(ev->arch));
log_infof("address: 0x%I64x\n", ev->address);
log_infof("string: \"%S\"\n", ev->string);
log_infof("ip_vaddr: 0x%I64x\n", ev->instruction_pointer);
}
}
//- rjf: determine if we should filter
B32 should_filter_event = 0;
if(next_event_node != 0)
{
DMN_Event *ev = &next_event_node->v;
switch(ev->kind)
{
default:{}break;
case DMN_EventKind_Exception:
{
for(D_ExceptionCodeKind k = (D_ExceptionCodeKind)0; k < D_ExceptionCodeKind_COUNT; k = (D_ExceptionCodeKind)(k+1))
// NOTE(rjf): first chance exceptions -> try ignoring
should_filter_event = (ev->exception_repeated == 0 && (spoof == 0 || ev->instruction_pointer != spoof->new_ip_value));
// rjf: exception code -> kind
D_ExceptionCodeKind code_kind = D_ExceptionCodeKind_Null;
if(should_filter_event)
{
if(d_exception_code_kind_code_table[k] == ev->code)
for(D_ExceptionCodeKind k = (D_ExceptionCodeKind)0; k < D_ExceptionCodeKind_COUNT; k = (D_ExceptionCodeKind)(k+1))
{
code_kind = k;
break;
}
}
}
// rjf: exception code kind -> shouldn't stop? if so, do not filter
if(should_filter_event)
{
B32 shouldnt_filter = !!(d_ctrl_state->exception_code_filters[code_kind/64] & (1ull<<(code_kind%64)));
if(should_filter_event && shouldnt_filter)
{
should_filter_event = 0;
}
}
// rjf: special case: be gracious with ASan modules or symbols if
// they do their cute little 0xc0000005 exception trick...
if(!should_filter_event && ev->code == 0xc0000005 &&
(spoof == 0 || ev->instruction_pointer != spoof->new_ip_value))
{
Access *access = access_open();
D_Handle process_handle = d_handle_from_dmn(D_ServerID_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)
{
// rjf: determine base address of asan shadow space
U64 asan_shadow_base_vaddr = 0;
B32 asan_shadow_variable_exists_but_is_zero = 0;
DI_Key dbgi_key = d_dbgi_key_from_module(module);
RDI_Parsed *rdi = di_rdi_from_key(access, dbgi_key, 1, max_U64);
RDI_NameMap *unparsed_map = rdi_element_from_name_idx(rdi, NameMaps, RDI_NameMapKind_GlobalVariables);
{
RDI_ParsedNameMap map = {0};
rdi_parsed_from_name_map(rdi, unparsed_map, &map);
String8 name = str8_lit("__asan_shadow_memory_dynamic_address");
RDI_NameMapNode *node = rdi_name_map_lookup(rdi, &map, name.str, name.size);
if(node != 0)
if(d_exception_code_kind_code_table[k] == ev->code)
{
U32 id_count = 0;
U32 *ids = rdi_matches_from_map_node(rdi, node, &id_count);
if(id_count > 0)
{
RDI_Symbol *global_var = rdi_element_from_name_idx(rdi, GlobalVariables, ids[0]);
U64 global_var_voff = rdi_voff_from_location(global_var->location);
U64 global_var_vaddr = global_var_voff + module->vaddr_range.min;
Arch arch = process->arch;
U64 addr_size = bit_size_from_arch(arch)/8;
d_process_read(process_handle, r1u64(global_var_vaddr, global_var_vaddr+addr_size), &asan_shadow_base_vaddr);
asan_shadow_variable_exists_but_is_zero = (asan_shadow_base_vaddr == 0);
}
code_kind = k;
break;
}
}
// rjf: determine if this was a read/write to the shadow space
B32 violation_in_shadow_space = 0;
if(asan_shadow_base_vaddr != 0)
{
U64 asan_shadow_space_size = TB(128)/8;
if(asan_shadow_base_vaddr <= ev->address && ev->address < asan_shadow_base_vaddr+asan_shadow_space_size)
{
violation_in_shadow_space = 1;
}
}
// rjf: filter event if this violation occurred in asan's shadow space
if(violation_in_shadow_space || asan_shadow_variable_exists_but_is_zero)
{
should_filter_event = 1;
}
}
access_close(access);
}
}break;
// rjf: exception code kind -> shouldn't stop? if so, do not filter
if(should_filter_event)
{
B32 shouldnt_filter = !!(d_ctrl_state->exception_code_filters[code_kind/64] & (1ull<<(code_kind%64)));
if(should_filter_event && shouldnt_filter)
{
should_filter_event = 0;
}
}
// rjf: special case: be gracious with ASan modules or symbols if
// they do their cute little 0xc0000005 exception trick...
if(!should_filter_event && ev->code == 0xc0000005 && (spoof == 0 || ev->instruction_pointer != spoof->new_ip_value))
{
Access *access = access_open();
D_Handle process_handle = d_handle_from_dmn(D_ServerID_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)
{
// rjf: determine base address of asan shadow space
U64 asan_shadow_base_vaddr = 0;
B32 asan_shadow_variable_exists_but_is_zero = 0;
DI_Key dbgi_key = d_dbgi_key_from_module(module);
RDI_Parsed *rdi = di_rdi_from_key(access, dbgi_key, 1, max_U64);
RDI_NameMap *unparsed_map = rdi_element_from_name_idx(rdi, NameMaps, RDI_NameMapKind_GlobalVariables);
{
RDI_ParsedNameMap map = {0};
rdi_parsed_from_name_map(rdi, unparsed_map, &map);
String8 name = str8_lit("__asan_shadow_memory_dynamic_address");
RDI_NameMapNode *node = rdi_name_map_lookup(rdi, &map, name.str, name.size);
if(node != 0)
{
U32 id_count = 0;
U32 *ids = rdi_matches_from_map_node(rdi, node, &id_count);
if(id_count > 0)
{
RDI_Symbol *global_var = rdi_element_from_name_idx(rdi, GlobalVariables, ids[0]);
U64 global_var_voff = rdi_voff_from_location(global_var->location);
U64 global_var_vaddr = global_var_voff + module->vaddr_range.min;
Arch arch = process->arch;
U64 addr_size = bit_size_from_arch(arch)/8;
d_process_read(process_handle, r1u64(global_var_vaddr, global_var_vaddr+addr_size), &asan_shadow_base_vaddr);
asan_shadow_variable_exists_but_is_zero = (asan_shadow_base_vaddr == 0);
}
}
}
// rjf: determine if this was a read/write to the shadow space
B32 violation_in_shadow_space = 0;
if(asan_shadow_base_vaddr != 0)
{
U64 asan_shadow_space_size = TB(128)/8;
if(asan_shadow_base_vaddr <= ev->address && ev->address < asan_shadow_base_vaddr+asan_shadow_space_size)
{
violation_in_shadow_space = 1;
}
}
// rjf: filter event if this violation occurred in asan's shadow space
if(violation_in_shadow_space || asan_shadow_variable_exists_but_is_zero)
{
should_filter_event = 1;
}
}
access_close(access);
}
}break;
}
}
//- rjf: good event & unfiltered? -> pop from queue & grab as result
if(next_event_node != 0 && !should_filter_event)
{
got_event = 1;
SLLQueuePop(ss->first_dmn_event_node, ss->last_dmn_event_node);
dmn_event_deep_copy(arena, event, &next_event_node->v);
run_ctrls->ignore_previous_exception = 1;
}
//- rjf: good event but filtered? pop from queue, but we don't have a result yet.
if(next_event_node != 0 && should_filter_event)
{
SLLQueuePop(ss->first_dmn_event_node, ss->last_dmn_event_node);
run_ctrls->ignore_previous_exception = 0;
}
//- rjf: out of queued up demon events -> clear event arena
if(ss->first_dmn_event_node == 0)
{
ss->free_dmn_event_node = 0;
arena_clear(ss->dmn_event_arena);
}
}
// rjf: good event & unfiltered? -> pop from queue & grab as result
if(next_event_node != 0 && !should_filter_event)
{
got_event = 1;
SLLQueuePop(d_ctrl_state->first_dmn_event_node, d_ctrl_state->last_dmn_event_node);
MemoryCopyStruct(event, &next_event_node->v);
event->string = push_str8_copy(arena, event->string);
run_ctrls->ignore_previous_exception = 1;
}
// rjf: good event but filtered? pop from queue
if(next_event_node != 0 && should_filter_event)
{
SLLQueuePop(d_ctrl_state->first_dmn_event_node, d_ctrl_state->last_dmn_event_node);
run_ctrls->ignore_previous_exception = 0;
}
}
//- rjf: no event -> dmn_ctrl_run for a new one
if(got_event == 0) ProfScope("no event -> dmn_ctrl_run for a new one")
//- rjf: no event -> run all servers until we get a new one
if(!got_event) ProfScope("no event -> run all servers until we get a new one")
{
// rjf: prep spoof
//- rjf: prep spoof
B32 do_spoof = (spoof != 0 && dmn_handle_match(run_ctrls->single_step_thread, dmn_handle_zero()));
U64 size_of_spoof = 0;
if(do_spoof) ProfScope("prep spoof")
@@ -3041,16 +3064,17 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
d_process_read(spoof->process, r1u64(spoof->vaddr, spoof->vaddr+size_of_spoof), &spoof_old_ip_value);
}
// rjf: set spoof
//- rjf: set spoof
if(do_spoof) ProfScope("set spoof")
{
d_process_write(spoof->process, r1u64(spoof->vaddr, spoof->vaddr+size_of_spoof), &spoof->new_ip_value);
}
// rjf: run for new events
//- rjf: run for new events
ProfScope("run for new events")
{
LogInfoNamedBlockF("dmn_ctrl_run")
//- rjf: log run controls
LogInfoNamedBlockF("run")
{
log_infof("single_step_thread: [0x%I64x]\n", run_ctrls->single_step_thread);
log_infof("ignore_previous_exception: %i\n", !!run_ctrls->ignore_previous_exception);
@@ -3071,41 +3095,131 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
}
}
//- rjf: send run message to all *remote* servers - shouldn't matter much, but send starting at the
// current server position, so that we also fairly order the runs (assuming equal network latency)
U64 num_servers_running = 0;
{
B32 first = 1;
for(D_ServerState *ss = d_ctrl_state->next_dequeue_server;
ss != d_ctrl_state->next_dequeue_server || first;
(first = 0, ss = (ss->order_next == 0 ? d_ctrl_state->first_server : ss->order_next), d_ctrl_state->next_dequeue_server = ss))
{
if(ss->server_id != D_ServerID_LocalHost)
{
// rjf: unpack server
D_Handle server_handle = {.server_id = ss->server_id};
D_Entity *server = d_entity_from_handle(server_handle);
String8 server_addr = server->string;
SOCK_Endpoint server_endpoint = sock_endpoint_from_string(server_addr);
// rjf: form run message
DS_Msg msg = {0};
{
msg.kind = DS_MsgKind_Run;
// TODO(rjf)
}
// rjf: message -> packet
String8 packet = ds_packet_from_msg(scratch.arena, &msg);
// rjf: send run message
if(!sock_send(d_ctrl_state->sock_session, SOCK_Protocol_TCP, server_endpoint, packet, now_time_us()+10000000))
{
// TODO(rjf)
}
else
{
num_servers_running += 1;
}
}
}
}
//- rjf: run the local server synchronously - if we get a response from another server, it will
// halt the local one.
d_ctrl_state->ctrl_thread_dmn_run_block = 1;
DMN_EventList events = dmn_ctrl_run(scratch.arena, ctrl_ctx, run_ctrls);
d_ctrl_state->ctrl_thread_dmn_run_block = 0;
//- rjf: if we got significant events back (anything except a NotAttached), then we
// need to halt all connected remote servers.
if(events.first != 0 && (events.first->v.kind != DMN_EventKind_Error || events.first->v.error_kind != DMN_ErrorKind_NotAttached))
{
B32 first = 1;
for(D_ServerState *ss = d_ctrl_state->next_dequeue_server;
ss != d_ctrl_state->next_dequeue_server || first;
(first = 0, ss = (ss->order_next == 0 ? d_ctrl_state->first_server : ss->order_next), d_ctrl_state->next_dequeue_server = ss))
{
if(ss->server_id != D_ServerID_LocalHost)
{
// rjf: unpack server
D_Handle server_handle = {.server_id = ss->server_id};
D_Entity *server = d_entity_from_handle(server_handle);
String8 server_addr = server->string;
SOCK_Endpoint server_endpoint = sock_endpoint_from_string(server_addr);
// rjf: form halt message / packet
DS_Msg msg = {DS_MsgKind_Halt};
String8 packet = ds_packet_from_msg(scratch.arena, &msg);
// rjf: send
if(!sock_send(d_ctrl_state->sock_session, SOCK_Protocol_TCP, server_endpoint, packet, now_time_us()+10000000))
{
// TODO(rjf)
}
}
}
}
//- rjf: copy locally returned events to local server queue
{
D_ServerID server_id = D_ServerID_LocalHost;
U64 slot_idx = server_id%d_ctrl_state->server_slots_count;
for(D_ServerState *ss = d_ctrl_state->server_slots[slot_idx].first; ss != 0; ss = ss->order_next)
{
if(ss->server_id == server_id)
{
for EachNode(src_n, DMN_EventNode, events.first)
{
DMN_EventNode *dst_n = ss->free_dmn_event_node;
if(dst_n != 0)
{
SLLStackPop(ss->free_dmn_event_node);
}
else
{
dst_n = push_array(ss->dmn_event_arena, DMN_EventNode, 1);
}
dmn_event_deep_copy(ss->dmn_event_arena, &dst_n->v, &src_n->v);
SLLQueuePush(ss->first_dmn_event_node, ss->last_dmn_event_node, dst_n);
}
}
}
}
//- rjf: wait for all running servers to stop (either we're waiting on them for events, *or* we generated
// a halt, and we're waiting for that)
if(events.first != 0 && events.count == 1 && events.first->v.kind == DMN_EventKind_Error && events.first->v.error_kind == DMN_ErrorKind_NotAttached)
{
for(;num_servers_running > 0;)
{
// TODO(rjf)
}
}
//- rjf: bump all debuggee state generations
ins_atomic_u64_inc_eval(&d_ctrl_state->mem_gen);
ins_atomic_u64_inc_eval(&d_ctrl_state->reg_gen);
ins_atomic_u64_inc_eval(&d_ctrl_state->run_gen);
for(DMN_EventNode *src_n = events.first; src_n != 0; src_n = src_n->next)
{
DMN_EventNode *dst_n = d_ctrl_state->free_dmn_event_node;
if(dst_n != 0)
{
SLLStackPop(d_ctrl_state->free_dmn_event_node);
}
else
{
dst_n = push_array(d_ctrl_state->dmn_event_arena, DMN_EventNode, 1);
}
MemoryCopyStruct(&dst_n->v, &src_n->v);
dst_n->v.string = push_str8_copy(d_ctrl_state->dmn_event_arena, dst_n->v.string);
if(src_n->v.module_info != &dmn_module_info_nil)
{
dst_n->v.module_info = push_array(d_ctrl_state->dmn_event_arena, DMN_ModuleInfo, 1);
MemoryCopyStruct(dst_n->v.module_info, src_n->v.module_info);
dst_n->v.module_info->module_path = str8_copy(d_ctrl_state->dmn_event_arena, dst_n->v.module_info->module_path);
dst_n->v.module_info->debug_info_path = str8_copy(d_ctrl_state->dmn_event_arena, dst_n->v.module_info->debug_info_path);
}
SLLQueuePush(d_ctrl_state->first_dmn_event_node, d_ctrl_state->last_dmn_event_node, dst_n);
}
}
// rjf: unset spoof
//- rjf: unset spoof
if(do_spoof) ProfScope("unset spoof")
{
d_process_write(spoof->process, r1u64(spoof->vaddr, spoof->vaddr+size_of_spoof), &spoof_old_ip_value);
}
// rjf: irrespective of what event came back, we should ALWAYS check the
//- rjf: irrespective of what event came back, we should ALWAYS check the
// spoof's thread and see if it hit the spoof address, because we may have
// simply been sent other debug events first
if(spoof != 0)
@@ -3157,7 +3271,6 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
out_evt->arch = event->arch;
out_evt->entity_id = event->code;
out_evt->os = OperatingSystem_CURRENT; // TODO: operating system of the remote target machine
d_ctrl_state->process_counter += 1;
}break;
//- rjf: create thread
@@ -3350,7 +3463,6 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
out_evt->msg_id = msg->msg_id;
out_evt->entity = d_handle_from_dmn(D_ServerID_LocalHost, event->process);
out_evt->u64_code = event->code;
d_ctrl_state->process_counter -= 1;
}break;
//- rjf: exit thread
@@ -3470,21 +3582,6 @@ d_ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, D_Msg *msg, D
}
d_c2u_push_events(&evts);
//- rjf: if this is the first process in a session, clear the debug directory
// cache state
if(d_ctrl_state->process_counter == 1 && event->kind == DMN_EventKind_CreateProcess)
{
arena_clear(d_ctrl_state->dbg_dir_arena);
d_ctrl_state->dbg_dir_root = push_array(d_ctrl_state->dbg_dir_arena, D_DbgDirNode, 1);
}
//- rjf: out of queued up demon events -> clear event arena
if(d_ctrl_state->first_dmn_event_node == 0)
{
d_ctrl_state->free_dmn_event_node = 0;
arena_clear(d_ctrl_state->dmn_event_arena);
}
scratch_end(scratch);
ProfEnd();
return(event);
@@ -3803,6 +3900,126 @@ d_ctrl_thread__eval_scope_end(D_EvalScope *scope)
access_close(scope->access);
}
//- rjf: server connection lookups
internal D_Handle
d_ctrl_thread__handle_from_addr_or_connect(String8 addr)
{
D_Handle handle = {0};
//- rjf: try to find existing handle for this server address
B32 found = 0;
{
D_EntityArray servers = d_entity_array_from_kind(D_EntityKind_Server);
for EachIndex(idx, servers.count)
{
if(str8_match(servers.v[idx]->string, addr, 0))
{
handle = servers.v[idx]->handle;
found = 1;
break;
}
}
}
//- rjf: if not found, connect to server & handshake
if(!found)
{
SOCK_Endpoint endpoint = sock_endpoint_from_string(addr);
// rjf: handshake & get state
B32 good_handshake = 1;
{
Temp scratch = scratch_begin(0, 0);
// rjf: send handshake packet
{
DS_Msg server_msg = {0};
{
server_msg.kind = DS_MsgKind_Handshake;
server_msg.msg_id = 1;
}
String8 send_packet = ds_packet_from_msg(scratch.arena, &server_msg);
sock_send(d_ctrl_state->sock_session, SOCK_Protocol_TCP, endpoint, send_packet, max_U64);
}
// rjf: receive state packet(s)
{
SOCK_Protocol recv_protocol = SOCK_Protocol_TCP;
SOCK_Endpoint recv_endpoint = {0};
String8 recv_packet = {0};
sock_recv(scratch.arena, d_ctrl_state->sock_session, &recv_protocol, &recv_endpoint, &recv_packet, now_time_us()+10000000);
if(recv_packet.size == 0)
{
good_handshake = 0;
}
}
// rjf: report failure
if(!good_handshake)
{
log_user_errorf("Couldn't successfully connect to server at %S (%S).", sock_string_from_endpoint(scratch.arena, endpoint), addr);
}
scratch_end(scratch);
}
// rjf: push connect event
D_ServerID server_id = 0;
if(good_handshake)
{
Temp scratch = scratch_begin(0, 0);
D_EventList evts = {0};
D_Event *evt = d_event_list_push(scratch.arena, &evts);
d_ctrl_state->server_id_gen += 1;
server_id = D_ServerID_LocalHost + d_ctrl_state->server_id_gen;
evt->kind = D_EventKind_ServerConnect;
evt->entity_id = server_id;
evt->string = addr;
d_c2u_push_events(&evts);
scratch_end(scratch);
}
// rjf: set up server state
if(good_handshake)
{
D_ServerState *ss = d_ctrl_state->free_server;
if(ss != 0)
{
SLLStackPop_N(d_ctrl_state->free_server, order_next);
}
else
{
ss = push_array_no_zero(d_ctrl_state->arena, D_ServerState, 1);
}
MemoryZeroStruct(ss);
ss->server_id = server_id;
ss->dmn_event_arena = arena_alloc();
DLLPushBack_NP(d_ctrl_state->first_server, d_ctrl_state->last_server, ss, order_next, order_prev);
U64 slot_idx = server_id%d_ctrl_state->server_slots_count;
DLLPushBack_NP(d_ctrl_state->server_slots[slot_idx].first, d_ctrl_state->server_slots[slot_idx].last, ss, hash_next, hash_prev);
}
// rjf: form handle
handle.server_id = server_id;
}
return handle;
}
//- rjf: control system socket wakeup function
internal void
d_ctrl_sock_wakeup(void)
{
// NOTE(rjf): if we receive something from a socket while in a run state
// (e.g. blocked locally on a dmn_ctrl_run), then we want to generate a
// halt, so that we can wake up and process the received packet.
if(d_ctrl_state->ctrl_thread_dmn_run_block)
{
dmn_halt(0, 0);
}
}
//- rjf: log flusher
internal void
@@ -3827,56 +4044,7 @@ d_ctrl_thread__end_and_flush_log(void)
internal void
d_ctrl_thread__open_remote_server(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
{
SOCK_Endpoint endpoint = sock_endpoint_from_string(msg->path);
//- rjf: handshake & get state
B32 good_handshake = 1;
{
Temp scratch = scratch_begin(0, 0);
// rjf: send handshake packet
{
DS_Msg server_msg = {0};
{
server_msg.kind = DS_MsgKind_Handshake;
server_msg.msg_id = 1;
}
String8 send_packet = ds_packet_from_msg(scratch.arena, &server_msg);
sock_send(d_ctrl_state->sock_session, SOCK_Protocol_TCP, endpoint, send_packet, max_U64);
}
// rjf: receive state packet(s)
{
SOCK_Protocol recv_protocol = SOCK_Protocol_TCP;
SOCK_Endpoint recv_endpoint = {0};
String8 recv_packet = {0};
sock_recv(scratch.arena, d_ctrl_state->sock_session, &recv_protocol, &recv_endpoint, &recv_packet, now_time_us()+10000000);
if(recv_packet.size == 0)
{
good_handshake = 0;
}
}
// rjf: report failure
if(!good_handshake)
{
log_user_errorf("Couldn't successfully connect to server at %S (%S).", sock_string_from_endpoint(scratch.arena, endpoint), msg->path);
}
scratch_end(scratch);
}
//- rjf: push connect event
{
Temp scratch = scratch_begin(0, 0);
D_EventList evts = {0};
D_Event *evt = d_event_list_push(scratch.arena, &evts);
d_ctrl_state->server_id_gen += 1;
evt->kind = D_EventKind_ServerConnect;
evt->entity_id = D_ServerID_LocalHost + d_ctrl_state->server_id_gen;
evt->string = msg->path;
d_c2u_push_events(&evts);
scratch_end(scratch);
}
d_ctrl_thread__handle_from_addr_or_connect(msg->address);
}
internal void
@@ -3897,52 +4065,69 @@ d_ctrl_thread__launch(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
{
Temp scratch = scratch_begin(0, 0);
//- rjf: produce full stdout/stderr/stdin paths
String8 stdout_path = path_absolute_dst_from_relative_dst_src(scratch.arena, msg->stdout_path, msg->path);
String8 stdin_path = path_absolute_dst_from_relative_dst_src(scratch.arena, msg->stdin_path, msg->path);
String8 stderr_path = path_absolute_dst_from_relative_dst_src(scratch.arena, msg->stderr_path, msg->path);
//////////////////////////////
//- rjf: message -> launch parameters for debug servers
//
DS_LaunchParams launch_params =
{
.command_line = msg->cmd_line_string_list,
.path = msg->path,
.env = msg->env_string_list,
.stdout_path = msg->stdout_path,
.stdin_path = msg->stdin_path,
.stderr_path = msg->stderr_path,
.debug_subprocesses = msg->debug_subprocesses,
.inherit_env = msg->env_inherit,
};
//- rjf: obtain stdout/stderr/stdin handles
File stdout_handle = {0};
File stderr_handle = {0};
File stdin_handle = {0};
if(stdout_path.size != 0)
//////////////////////////////
//- rjf: remote? -> get server handle
//
D_Handle server = {.server_id = D_ServerID_LocalHost};
if(msg->address.size != 0)
{
File f = file_open(AccessFlag_Write|AccessFlag_Read, stdout_path);
file_close(f);
stdout_handle = file_open(AccessFlag_Write|AccessFlag_Append|AccessFlag_ShareRead|AccessFlag_ShareWrite|AccessFlag_Inherited, msg->stdout_path);
}
if(stderr_path.size != 0)
{
File f = file_open(AccessFlag_Write|AccessFlag_Read, stderr_path);
file_close(f);
stderr_handle = file_open(AccessFlag_Write|AccessFlag_Append|AccessFlag_ShareRead|AccessFlag_ShareWrite|AccessFlag_Inherited, msg->stderr_path);
}
if(stdin_path.size != 0)
{
stdin_handle = file_open(AccessFlag_Read|AccessFlag_ShareRead|AccessFlag_ShareWrite|AccessFlag_Inherited, stdin_path);
server = d_ctrl_thread__handle_from_addr_or_connect(msg->address);
}
//- rjf: launch
ProcessLaunchParams params = {0};
//////////////////////////////
//- rjf: remote? -> send message to launch, wait on new PID
//
U64 pid = 0;
if(msg->address.size != 0)
{
params.cmd_line = msg->cmd_line_string_list;
params.path = msg->path;
params.env = msg->env_string_list;
params.inherit_env = msg->env_inherit;
params.debug_subprocesses = msg->debug_subprocesses;
params.stdout_file = stdout_handle;
params.stderr_file = stderr_handle;
params.stdin_file = stdin_handle;
SOCK_Endpoint server_endpoint = sock_endpoint_from_string(msg->address);
DS_Msg server_msg = {DS_MsgKind_Launch, .launch_params = &launch_params};
String8 server_packet = ds_packet_from_msg(scratch.arena, &server_msg);
String8 server_response_packet = {0};
SOCK_Endpoint server_response_endpoint = {0};
if(!sock_send(d_ctrl_state->sock_session, SOCK_Protocol_TCP, server_endpoint, server_packet, now_time_us()+10000000))
{
log_user_errorf("Couldn't successfully send launch command to %S (%S).", sock_string_from_endpoint(scratch.arena, server_endpoint), msg->address);
}
else if(!sock_recv(scratch.arena, d_ctrl_state->sock_session, 0, &server_response_endpoint, &server_response_packet, now_time_us()+10000000))
{
log_user_errorf("Didn't receive launch command response from %S (%S) in time.", sock_string_from_endpoint(scratch.arena, server_endpoint), msg->address);
}
else
{
DS_Response response = ds_response_from_packet(scratch.arena, server_response_packet);
pid = response.pid;
}
}
U32 id = dmn_ctrl_launch(ctrl_ctx, &params);
//- rjf: close stdout/stderr/stdin files
file_close(stdout_handle);
file_close(stderr_handle);
file_close(stdin_handle);
//////////////////////////////
//- rjf: local? -> launch locally
//
else
{
pid = ds_ctrl_launch(ctrl_ctx, &launch_params);
}
//////////////////////////////
//- rjf: record (id -> entry points), and (id -> msg_id) so that we know custom entry points for this PID
//
// TODO(rjf): PID is not unique across machines. these should be under a server.
//
D_EntityCtxRWStore *entity_ctx_rw_store = d_ctrl_state->ctrl_thread_entity_store;
MutexScopeW(d_ctrl_state->ctrl_thread_entity_ctx_rw_mutex)
{
@@ -3950,11 +4135,11 @@ d_ctrl_thread__launch(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
{
{
String8 string = n->string;
D_Entity *entry = d_entity_alloc(entity_ctx_rw_store, entity_ctx_rw_store->ctx.root, D_EntityKind_EntryPoint, Arch_Null, d_handle_zero(), (U64)id);
D_Entity *entry = d_entity_alloc(entity_ctx_rw_store, entity_ctx_rw_store->ctx.root, D_EntityKind_EntryPoint, Arch_Null, d_handle_zero(), pid);
d_entity_equip_string(entity_ctx_rw_store, entry, string);
}
{
D_Entity *entry = d_entity_alloc(entity_ctx_rw_store, entity_ctx_rw_store->ctx.root, D_EntityKind_LaunchMsgID, Arch_Null, d_handle_zero(), (U64)id);
D_Entity *entry = d_entity_alloc(entity_ctx_rw_store, entity_ctx_rw_store->ctx.root, D_EntityKind_LaunchMsgID, Arch_Null, d_handle_zero(), pid);
entry->src_msg_id = msg->msg_id;
}
}
@@ -3969,35 +4154,50 @@ d_ctrl_thread__attach(DMN_CtrlCtx *ctrl_ctx, D_Msg *msg)
ProfBeginFunction();
Temp scratch = scratch_begin(0, 0);
//- rjf: attach
B32 attach_successful = dmn_ctrl_attach(ctrl_ctx, msg->entity_id);
//- rjf: run to handshake
if(attach_successful)
//////////////////////////////
//- rjf: remote? -> send message to attach, wait on success
//
B32 attach_successful = 0;
if(msg->address.size != 0)
{
DMN_Handle unfrozen_process = {0};
DMN_RunCtrls run_ctrls = {0};
run_ctrls.run_entities_are_unfrozen = 1;
run_ctrls.run_entities_are_processes = 1;
for(B32 done = 0; done == 0;)
// TODO(rjf)
}
//////////////////////////////
//- rjf: local? -> attach locally
//
else
{
//- rjf: attach
attach_successful = dmn_ctrl_attach(ctrl_ctx, msg->entity_id);
//- rjf: run to handshake
if(attach_successful)
{
DMN_Event *event = d_ctrl_thread__next_dmn_event(scratch.arena, ctrl_ctx, msg, &run_ctrls, 0);
switch(event->kind)
DMN_Handle unfrozen_process = {0};
DMN_RunCtrls run_ctrls = {0};
run_ctrls.run_entities_are_unfrozen = 1;
run_ctrls.run_entities_are_processes = 1;
for(B32 done = 0; done == 0;)
{
default:{}break;
case DMN_EventKind_CreateProcess:
DMN_Event *event = d_ctrl_thread__next_dmn_event(scratch.arena, ctrl_ctx, msg, &run_ctrls, 0);
switch(event->kind)
{
unfrozen_process = event->process;
run_ctrls.run_entities = &unfrozen_process;
run_ctrls.run_entity_count = 1;
}break;
case DMN_EventKind_Halt:
case DMN_EventKind_Exception:
case DMN_EventKind_Error:
case DMN_EventKind_HandshakeComplete:
{
done = 1;
}break;
default:{}break;
case DMN_EventKind_CreateProcess:
{
unfrozen_process = event->process;
run_ctrls.run_entities = &unfrozen_process;
run_ctrls.run_entity_count = 1;
}break;
case DMN_EventKind_Halt:
case DMN_EventKind_Exception:
case DMN_EventKind_Error:
case DMN_EventKind_HandshakeComplete:
{
done = 1;
}break;
}
}
}
}
+55 -4
View File
@@ -313,6 +313,45 @@ struct D_ModuleReqCacheNode
#define D_WAKEUP_FUNCTION_DEF(name) void name(void)
typedef D_WAKEUP_FUNCTION_DEF(D_WakeupFunctionType);
////////////////////////////////
//~ rjf: Server State Types
//
// Each call to `dmn_ctrl_run` can generate a sequence of debug events. We handle
// these one at a time, and so after a `dmn_ctrl_run`, we need to store all returned
// events in a queue, and process the full queue before doing another `dmn_ctrl_run`.
//
// Initially, there was just one of these queues, but on moving to multi-server
// debugging, we will have a sequence of events generated per-server. Then, we
// will just want to round-robin drain the queues before we dispatch another run
// to all servers.
//
typedef struct D_ServerState D_ServerState;
struct D_ServerState
{
// rjf: links
D_ServerState *hash_next;
D_ServerState *hash_prev;
D_ServerState *order_next;
D_ServerState *order_prev;
// rjf: server identifier
D_ServerID server_id;
// rjf: demon event queue
Arena *dmn_event_arena;
DMN_EventNode *first_dmn_event_node;
DMN_EventNode *last_dmn_event_node;
DMN_EventNode *free_dmn_event_node;
};
typedef struct D_ServerSlot D_ServerSlot;
struct D_ServerSlot
{
D_ServerState *first;
D_ServerState *last;
};
////////////////////////////////
//~ rjf: Main State Types
@@ -326,7 +365,7 @@ struct D_CtrlState
// rjf: name -> register hash tables for eval
E_String2NumMap arch_string2reg_tables[Arch_COUNT];
// rjf: caches
// rjf: shared caches
D_ThreadRegCache thread_reg_cache;
D_ModuleInfoCache module_info_cache;
D_DumpCache dump_cache;
@@ -363,18 +402,24 @@ struct D_CtrlState
D_EntityCtxRWStore *ctrl_thread_entity_store;
E_Cache *ctrl_thread_eval_cache;
Arena *ctrl_thread_msg_process_arena;
U64 server_slots_count;
D_ServerSlot *server_slots;
D_ServerState *first_server;
D_ServerState *last_server;
D_ServerState *free_server;
D_ServerState *next_dequeue_server;
B32 ctrl_thread_dmn_run_block;
#if 0
Arena *dmn_event_arena;
DMN_EventNode *first_dmn_event_node;
DMN_EventNode *last_dmn_event_node;
DMN_EventNode *free_dmn_event_node;
#endif
Arena *user_entry_point_arena;
String8List user_entry_points;
U64 exception_code_filters[(D_ExceptionCodeKind_COUNT+63)/64];
B32 auto_download_debug_info;
U64 process_counter;
D_ServerID server_id_gen;
Arena *dbg_dir_arena;
D_DbgDirNode *dbg_dir_root;
U64 module_req_cache_slots_count;
D_ModuleReqCacheNode **module_req_cache_slots;
String8List msg_user_bp_touched_files;
@@ -622,6 +667,12 @@ internal B32 d_ctrl_eval_space_read(E_Space space, void *out, E_SpaceRangeInfo *
internal D_EvalScope *d_ctrl_thread__eval_scope_begin(Arena *arena, D_BreakpointList *user_bps, D_Entity *thread);
internal void d_ctrl_thread__eval_scope_end(D_EvalScope *scope);
//- rjf: server connection lookups
internal D_Handle d_ctrl_thread__handle_from_addr_or_connect(String8 addr);
//- rjf: control system socket wakeup function
internal void d_ctrl_sock_wakeup(void);
//- rjf: log flusher
internal void d_ctrl_thread__end_and_flush_log(void);
+4 -1
View File
@@ -1774,6 +1774,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
String8 stdout_path = str8_skip_chop_whitespace(target->stdout_path);
String8 stderr_path = str8_skip_chop_whitespace(target->stderr_path);
String8 stdin_path = str8_skip_chop_whitespace(target->stdin_path);
String8 remote_address = str8_skip_chop_whitespace(target->remote_address);
String8List env = target->env;
if(working_directory.size == 0)
{
@@ -1813,12 +1814,14 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
D_Msg *msg = d_msg_list_push(scratch.arena, &ctrl_msgs);
msg->msg_id = target->msg_id;
msg->kind = D_MsgKind_Launch;
msg->address = str8_copy(scratch.arena, remote_address);
msg->path = str8_copy(scratch.arena, working_directory);
msg->cmd_line_string_list = str8_list_copy(scratch.arena, &cmdln_strings);
msg->stdout_path = str8_copy(scratch.arena, stdout_path);
msg->stderr_path = str8_copy(scratch.arena, stderr_path);
msg->stdin_path = str8_copy(scratch.arena, stdin_path);
msg->debug_subprocesses = target->debug_subprocesses;
msg->deploy = target->deploy;
msg->env_inherit = 1;
MemoryCopyArray(msg->exception_code_filters, exception_code_filters);
msg->auto_download_debug_info = auto_download_debug_info;
@@ -2197,7 +2200,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
{
D_Msg *msg = d_msg_list_push(scratch.arena, &ctrl_msgs);
msg->kind = D_MsgKind_OpenRemoteServer;
msg->path = str8_copy(scratch.arena, params->string);
msg->address = str8_copy(scratch.arena, params->string);
MemoryCopyArray(msg->exception_code_filters, exception_code_filters);
msg->auto_download_debug_info = auto_download_debug_info;
}break;
+2
View File
@@ -197,7 +197,9 @@ struct D_Msg
B32 env_inherit;
B32 debug_subprocesses;
B32 auto_download_debug_info;
B32 deploy;
U64 exception_code_filters[(D_ExceptionCodeKind_COUNT+63)/64];
String8 address;
String8 path;
String8List entry_points;
String8List cmd_line_string_list;
+182 -52
View File
@@ -31,40 +31,65 @@ ds_msg_from_packet(Arena *arena, String8 data)
off += str8_deserial_read_struct(payload, off, &msg.entity);
off += str8_deserial_read_struct(payload, off, &msg.pid);
// rjf: read command line strings
// rjf: read launch parameters extension
{
U64 cmd_line_string_count = 0;
off += str8_deserial_read_struct(payload, off, &cmd_line_string_count);
for EachIndex(idx, cmd_line_string_count)
B8 has_launch_params = 0;
off += str8_deserial_read_struct(payload, off, &has_launch_params);
if(has_launch_params)
{
String8 string = {0};
off += str8_deserial_read_struct(payload, off, &string.size);
string = str8_substr(payload, r1u64(off, off+string.size));
off += string.size;
str8_list_push(arena, &msg.command_line, string);
}
}
// rjf: read path
{
String8 string = {0};
off += str8_deserial_read_struct(payload, off, &string.size);
string = str8_substr(payload, r1u64(off, off+string.size));
off += string.size;
msg.path = string;
}
// rjf: read environment strings
{
U64 env_string_count = 0;
off += str8_deserial_read_struct(payload, off, &env_string_count);
for EachIndex(idx, env_string_count)
{
String8 string = {0};
off += str8_deserial_read_struct(payload, off, &string.size);
string = str8_substr(payload, r1u64(off, off+string.size));
off += string.size;
str8_list_push(arena, &msg.env, string);
msg.launch_params = push_array(arena, DS_LaunchParams, 1);
// rjf: read command line strings
{
U64 cmd_line_string_count = 0;
off += str8_deserial_read_struct(payload, off, &cmd_line_string_count);
for EachIndex(idx, cmd_line_string_count)
{
String8 string = {0};
off += str8_deserial_read_struct(payload, off, &string.size);
string = str8_substr(payload, r1u64(off, off+string.size));
off += string.size;
str8_list_push(arena, &msg.launch_params->command_line, string);
}
}
// rjf: read path
{
off += str8_deserial_read_struct(payload, off, &msg.launch_params->path.size);
msg.launch_params->path = str8_substr(payload, r1u64(off, off+msg.launch_params->path.size));
off += msg.launch_params->path.size;
}
// rjf: read environment strings
{
U64 env_string_count = 0;
off += str8_deserial_read_struct(payload, off, &env_string_count);
for EachIndex(idx, env_string_count)
{
String8 string = {0};
off += str8_deserial_read_struct(payload, off, &string.size);
string = str8_substr(payload, r1u64(off, off+string.size));
off += string.size;
str8_list_push(arena, &msg.launch_params->env, string);
}
}
// rjf: read std i/o paths
{
off += str8_deserial_read_struct(payload, off, &msg.launch_params->stdout_path.size);
msg.launch_params->stdout_path = str8_substr(payload, r1u64(off, off+msg.launch_params->stdout_path.size));
off += msg.launch_params->stdout_path.size;
off += str8_deserial_read_struct(payload, off, &msg.launch_params->stdin_path.size);
msg.launch_params->stdin_path = str8_substr(payload, r1u64(off, off+msg.launch_params->stdin_path.size));
off += msg.launch_params->stdin_path.size;
off += str8_deserial_read_struct(payload, off, &msg.launch_params->stderr_path.size);
msg.launch_params->stderr_path = str8_substr(payload, r1u64(off, off+msg.launch_params->stderr_path.size));
off += msg.launch_params->stderr_path.size;
}
// rjf: read bits
off += str8_deserial_read_struct(payload, off, &msg.launch_params->debug_subprocesses);
off += str8_deserial_read_struct(payload, off, &msg.launch_params->inherit_env);
}
}
@@ -105,30 +130,50 @@ ds_packet_from_msg(Arena *arena, DS_Msg *msg)
str8_serial_push_struct(scratch.arena, &srl, &msg->entity);
str8_serial_push_struct(scratch.arena, &srl, &msg->pid);
// rjf: write command line strings
// rjf: write launch parameters extension
B8 has_launch_params = (msg->launch_params != 0);
str8_serial_push_struct(scratch.arena, &srl, &has_launch_params);
if(has_launch_params)
{
str8_serial_push_struct(scratch.arena, &srl, &msg->command_line.node_count);
for EachNode(n, String8Node, msg->command_line.first)
// rjf: write command line strings
{
str8_serial_push_struct(scratch.arena, &srl, &n->string.size);
str8_serial_push_string(scratch.arena, &srl, n->string);
str8_serial_push_struct(scratch.arena, &srl, &msg->launch_params->command_line.node_count);
for EachNode(n, String8Node, msg->launch_params->command_line.first)
{
str8_serial_push_struct(scratch.arena, &srl, &n->string.size);
str8_serial_push_string(scratch.arena, &srl, n->string);
}
}
}
// rjf: write path
{
str8_serial_push_struct(scratch.arena, &srl, &msg->path.size);
str8_serial_push_string(scratch.arena, &srl, msg->path);
}
// rjf: write environment strings
{
str8_serial_push_struct(scratch.arena, &srl, &msg->env.node_count);
for EachNode(n, String8Node, msg->command_line.first)
// rjf: write path
{
str8_serial_push_struct(scratch.arena, &srl, &n->string.size);
str8_serial_push_string(scratch.arena, &srl, n->string);
str8_serial_push_struct(scratch.arena, &srl, &msg->launch_params->path.size);
str8_serial_push_string(scratch.arena, &srl, msg->launch_params->path);
}
// rjf: write environment strings
{
str8_serial_push_struct(scratch.arena, &srl, &msg->launch_params->env.node_count);
for EachNode(n, String8Node, msg->launch_params->env.first)
{
str8_serial_push_struct(scratch.arena, &srl, &n->string.size);
str8_serial_push_string(scratch.arena, &srl, n->string);
}
}
// rjf: write std i/o paths
{
str8_serial_push_struct(scratch.arena, &srl, &msg->launch_params->stdout_path.size);
str8_serial_push_string(scratch.arena, &srl, msg->launch_params->stdout_path);
str8_serial_push_struct(scratch.arena, &srl, &msg->launch_params->stdin_path.size);
str8_serial_push_string(scratch.arena, &srl, msg->launch_params->stdin_path);
str8_serial_push_struct(scratch.arena, &srl, &msg->launch_params->stderr_path.size);
str8_serial_push_string(scratch.arena, &srl, msg->launch_params->stderr_path);
}
// rjf: write bits
str8_serial_push_struct(scratch.arena, &srl, &msg->launch_params->debug_subprocesses);
str8_serial_push_struct(scratch.arena, &srl, &msg->launch_params->inherit_env);
}
// rjf: write traps
@@ -189,7 +234,7 @@ ds_response_from_packet(Arena *arena, String8 data)
// rjf: read data payload
off += str8_deserial_read_struct(payload, off, &result.data.size);
result.data.str = push_array(arena, U8, result.data.size);
off += str8_deserial_read(payload, off, result.data.str, result.data.size, result.data.size);
off += str8_deserial_read(payload, off, result.data.str, result.data.size, 1);
}
return result;
}
@@ -390,3 +435,88 @@ ds_packet_from_dmn_events(Arena *arena, DMN_EventList evts)
scratch_end(scratch);
return result;
}
////////////////////////////////
//~ rjf: Local Server Functions
internal U64
ds_ctrl_launch(DMN_CtrlCtx *ctrl_ctx, DS_LaunchParams *params)
{
Temp scratch = scratch_begin(0, 0);
//- rjf: produce full stdout/stderr/stdin paths
String8 stdout_path = path_absolute_dst_from_relative_dst_src(scratch.arena, params->stdout_path, params->path);
String8 stdin_path = path_absolute_dst_from_relative_dst_src(scratch.arena, params->stdin_path, params->path);
String8 stderr_path = path_absolute_dst_from_relative_dst_src(scratch.arena, params->stderr_path, params->path);
//- rjf: obtain stdout/stderr/stdin handles
File stdout_handle = {0};
File stderr_handle = {0};
File stdin_handle = {0};
if(stdout_path.size != 0)
{
File f = file_open(AccessFlag_Write|AccessFlag_Read, stdout_path);
file_close(f);
stdout_handle = file_open(AccessFlag_Write|AccessFlag_Append|AccessFlag_ShareRead|AccessFlag_ShareWrite|AccessFlag_Inherited, params->stdout_path);
}
if(stderr_path.size != 0)
{
File f = file_open(AccessFlag_Write|AccessFlag_Read, stderr_path);
file_close(f);
stderr_handle = file_open(AccessFlag_Write|AccessFlag_Append|AccessFlag_ShareRead|AccessFlag_ShareWrite|AccessFlag_Inherited, params->stderr_path);
}
if(stdin_path.size != 0)
{
stdin_handle = file_open(AccessFlag_Read|AccessFlag_ShareRead|AccessFlag_ShareWrite|AccessFlag_Inherited, stdin_path);
}
//- rjf: launch
ProcessLaunchParams dmn_launch_params = {0};
{
dmn_launch_params.cmd_line = params->command_line;
dmn_launch_params.path = params->path;
dmn_launch_params.env = params->env;
dmn_launch_params.inherit_env = params->inherit_env;
dmn_launch_params.debug_subprocesses = params->debug_subprocesses;
dmn_launch_params.stdout_file = stdout_handle;
dmn_launch_params.stderr_file = stderr_handle;
dmn_launch_params.stdin_file = stdin_handle;
}
U64 pid = dmn_ctrl_launch(ctrl_ctx, &dmn_launch_params);
//- rjf: close stdout/stderr/stdin files
file_close(stdout_handle);
file_close(stderr_handle);
file_close(stdin_handle);
scratch_end(scratch);
return pid;
}
internal B32
ds_ctrl_attach(DMN_CtrlCtx *ctrl_ctx, U32 pid)
{
B32 result = dmn_ctrl_attach(ctrl_ctx, pid);
return result;
}
internal B32
ds_ctrl_kill(DMN_CtrlCtx *ctrl_ctx, DMN_Handle process, U32 exit_code)
{
B32 result = dmn_ctrl_kill(ctrl_ctx, process, exit_code);
return result;
}
internal B32
ds_ctrl_detach(DMN_CtrlCtx *ctrl_ctx, DMN_Handle process)
{
B32 result = dmn_ctrl_detach(ctrl_ctx, process);
return result;
}
internal DMN_EventList
ds_ctrl_run(Arena *arena, DMN_CtrlCtx *ctrl_ctx, DMN_RunCtrls *ctrls)
{
DMN_EventList events = dmn_ctrl_run(arena, ctrl_ctx, ctrls);
return events;
}
+27 -9
View File
@@ -72,11 +72,22 @@ DS_MsgKind;
typedef U32 DS_MsgFlags;
enum
{
DS_MsgFlag_InheritEnv = (1<<0),
DS_MsgFlag_DebugSubprocesses = (1<<1),
DS_MsgFlag_IgnorePreviousException = (1<<2),
DS_MsgFlag_RunEntitiesAreUnfrozen = (1<<3),
DS_MsgFlag_RunEntitiesAreProcesses = (1<<4),
DS_MsgFlag_IgnorePreviousException = (1<<0),
DS_MsgFlag_RunEntitiesAreUnfrozen = (1<<1),
DS_MsgFlag_RunEntitiesAreProcesses = (1<<2),
};
typedef struct DS_LaunchParams DS_LaunchParams;
struct DS_LaunchParams
{
String8List command_line;
String8 path;
String8List env;
String8 stdout_path;
String8 stdin_path;
String8 stderr_path;
B32 debug_subprocesses;
B32 inherit_env;
};
typedef struct DS_Msg DS_Msg;
@@ -93,10 +104,8 @@ struct DS_Msg
U64 pid;
U64 code;
//- rjf: process launching parameters
String8List command_line;
String8 path;
String8List env;
//- rjf: process launching parameter extension
DS_LaunchParams *launch_params;
//- rjf: running parameters
DMN_TrapChunkList traps;
@@ -133,4 +142,13 @@ internal String8 ds_packet_from_response(Arena *arena, DS_Response *response);
internal DMN_EventList ds_dmn_events_from_packet(Arena *arena, String8 data);
internal String8 ds_packet_from_dmn_events(Arena *arena, DMN_EventList evts);
////////////////////////////////
//~ rjf: Local Server Functions
internal U64 ds_ctrl_launch(DMN_CtrlCtx *ctrl_ctx, DS_LaunchParams *params);
internal B32 ds_ctrl_attach(DMN_CtrlCtx *ctrl_ctx, U32 pid);
internal B32 ds_ctrl_kill(DMN_CtrlCtx *ctrl_ctx, DMN_Handle process, U32 exit_code);
internal B32 ds_ctrl_detach(DMN_CtrlCtx *ctrl_ctx, DMN_Handle process);
internal DMN_EventList ds_ctrl_run(Arena *arena, DMN_CtrlCtx *ctrl_ctx, DMN_RunCtrls *ctrls);
#endif // DBG_SERVER_H
+14
View File
@@ -122,3 +122,17 @@ dmn_event_list_push(Arena *arena, DMN_EventList *list)
result->module_info = &dmn_module_info_nil;
return result;
}
internal void
dmn_event_deep_copy(Arena *arena, DMN_Event *dst, DMN_Event *src)
{
MemoryCopyStruct(dst, src);
dst->string = str8_copy(arena, dst->string);
if(dst->module_info != 0)
{
dst->module_info = push_array(arena, DMN_ModuleInfo, 1);
MemoryCopyStruct(dst->module_info, src->module_info);
dst->module_info->module_path = str8_copy(arena, dst->module_info->module_path);
dst->module_info->debug_info_path = str8_copy(arena, dst->module_info->debug_info_path);
}
}
+1
View File
@@ -232,6 +232,7 @@ internal DMN_HandleArray dmn_handle_array_copy(Arena *arena, DMN_HandleArray *sr
//- rjf: event list building
internal DMN_Event *dmn_event_list_push(Arena *arena, DMN_EventList *list);
internal void dmn_event_deep_copy(Arena *arena, DMN_Event *dst, DMN_Event *src);
////////////////////////////////
//~ rjf: @dmn_os_hooks Main Layer Initialization (Implemented Per-OS)
+4 -1
View File
@@ -440,7 +440,10 @@ sock_recv(Arena *arena, SOCK_Session session, SOCK_Protocol *protocol_out, SOCK_
if(guarded_ring_read_or_wait(&guard, sizeof(header), header, endt_us))
{
U64 size_cap = s->s2u_ring->ring->size - sizeof(header);
protocol_out[0] = (SOCK_Protocol)header[0];
if(protocol_out != 0)
{
protocol_out[0] = (SOCK_Protocol)header[0];
}
endpoint_out->port = (U16)header[1];
endpoint_out->address_u64[0] = header[2];
endpoint_out->address_u64[1] = header[3];
+23 -15
View File
@@ -263,22 +263,28 @@ internal D_Target
rd_target_from_cfg(Arena *arena, CFG_Node *cfg)
{
D_Target target = {0};
target.exe = cfg_node_child_from_string(cfg, str8_lit("executable"))->first->string;
target.args = cfg_node_child_from_string(cfg, str8_lit("arguments"))->first->string;
target.working_directory = cfg_node_child_from_string(cfg, str8_lit("working_directory"))->first->string;
target.custom_entry_point_name = cfg_node_child_from_string(cfg, str8_lit("entry_point"))->first->string;
target.stdout_path = cfg_node_child_from_string(cfg, str8_lit("stdout_path"))->first->string;
target.stderr_path = cfg_node_child_from_string(cfg, str8_lit("stderr_path"))->first->string;
target.stdin_path = cfg_node_child_from_string(cfg, str8_lit("stdin_path"))->first->string;
target.exe = cfg_node_child_from_string(cfg, s("executable"))->first->string;
target.args = cfg_node_child_from_string(cfg, s("arguments"))->first->string;
target.working_directory = cfg_node_child_from_string(cfg, s("working_directory"))->first->string;
target.custom_entry_point_name = cfg_node_child_from_string(cfg, s("entry_point"))->first->string;
target.stdout_path = cfg_node_child_from_string(cfg, s("stdout_path"))->first->string;
target.stderr_path = cfg_node_child_from_string(cfg, s("stderr_path"))->first->string;
target.stdin_path = cfg_node_child_from_string(cfg, s("stdin_path"))->first->string;
target.msg_id = cfg->id;
target.debug_subprocesses = !!e_value_from_string(cfg_node_child_from_string(cfg, str8_lit("debug_subprocesses"))->first->string).u64;
target.debug_subprocesses = !!e_value_from_string(cfg_node_child_from_string(cfg, s("debug_subprocesses"))->first->string).u64;
for(CFG_Node *child = cfg->first; child != &cfg_nil_node; child = child->next)
{
if(str8_match(child->string, str8_lit("environment"), 0))
if(str8_match(child->string, s("environment"), 0))
{
str8_list_push(arena, &target.env, child->first->string);
}
}
B32 is_remote = !!e_value_from_string(cfg_node_child_from_string(cfg, s("remote"))->first->string).u64;
if(is_remote)
{
target.remote_address = cfg_node_child_from_string(cfg, s("address"))->first->string;
target.deploy = !!e_value_from_string(cfg_node_child_from_string(cfg, s("deploy"))->first->string).u64;\
}
return target;
}
@@ -14805,10 +14811,11 @@ rd_frame(void)
cycle:;
{
CFG_PanelTree panel_tree = cfg_panel_tree_from_cfg(scratch.arena, cfg_node_from_id(rd_regs()->window));
CFG_PanelNode *panel_nav_root = (panel_tree.zoom_root != &cfg_nil_panel_node ? panel_tree.zoom_root : panel_tree.root);
CFG_PanelNode *next_focused = &cfg_nil_panel_node;
for(CFG_PanelNode *p = panel_tree.focused;
p != &cfg_nil_panel_node;
p = cfg_panel_node_rec__depth_first(panel_tree.root, p, panel_sib_off, panel_child_off).next)
p = cfg_panel_node_rec__depth_first(panel_nav_root, p, panel_sib_off, panel_child_off).next)
{
if(p != panel_tree.focused && p->first == &cfg_nil_panel_node)
{
@@ -14818,9 +14825,9 @@ rd_frame(void)
}
if(next_focused == &cfg_nil_panel_node)
{
for(CFG_PanelNode *p = panel_tree.root;
for(CFG_PanelNode *p = panel_nav_root;
p != &cfg_nil_panel_node;
p = cfg_panel_node_rec__depth_first(panel_tree.root, p, panel_sib_off, panel_child_off).next)
p = cfg_panel_node_rec__depth_first(panel_nav_root, p, panel_sib_off, panel_child_off).next)
{
if(p != panel_tree.focused && p->first == &cfg_nil_panel_node)
{
@@ -14885,20 +14892,21 @@ rd_frame(void)
{
CFG_Node *window = cfg_node_from_id(rd_regs()->window);
CFG_PanelTree panel_tree = cfg_panel_tree_from_cfg(scratch.arena, window);
CFG_PanelNode *panel_nav_root = (panel_tree.zoom_root != &cfg_nil_panel_node ? panel_tree.zoom_root : panel_tree.root);
CFG_PanelNode *src_panel = panel_tree.focused;
Rng2F32 src_panel_rect = cfg_target_rect_from_panel_node(r2f32(v2f32(0, 0), v2f32(1000, 1000)), panel_tree.root, src_panel);
Rng2F32 src_panel_rect = cfg_target_rect_from_panel_node(r2f32(v2f32(0, 0), v2f32(1000, 1000)), panel_nav_root, src_panel);
Vec2F32 src_panel_center = center_2f32(src_panel_rect);
Vec2F32 src_panel_half_dim = scale_2f32(dim_2f32(src_panel_rect), 0.5f);
Vec2F32 travel_dim = add_2f32(src_panel_half_dim, v2f32(10.f, 10.f));
Vec2F32 travel_dst = add_2f32(src_panel_center, mul_2f32(travel_dim, v2f32((F32)panel_change_dir.x, (F32)panel_change_dir.y)));
CFG_PanelNode *dst_root = &cfg_nil_panel_node;
for(CFG_PanelNode *p = panel_tree.root; p != &cfg_nil_panel_node; p = cfg_panel_node_rec__depth_first_pre(panel_tree.root, p).next)
for(CFG_PanelNode *p = panel_nav_root; p != &cfg_nil_panel_node; p = cfg_panel_node_rec__depth_first_pre(panel_nav_root, p).next)
{
if(p == src_panel || p->first != &cfg_nil_panel_node)
{
continue;
}
Rng2F32 p_rect = cfg_target_rect_from_panel_node(r2f32(v2f32(0, 0), v2f32(1000, 1000)), panel_tree.root, p);
Rng2F32 p_rect = cfg_target_rect_from_panel_node(r2f32(v2f32(0, 0), v2f32(1000, 1000)), panel_nav_root, p);
if(contains_2f32(p_rect, travel_dst))
{
dst_root = p;
+14 -16
View File
@@ -143,34 +143,27 @@ dmn_thread__entry_point(void *p)
//- rjf: launching
case DS_MsgKind_Launch:
if(msg.launch_params != 0)
{
ProcessLaunchParams params = {0};
{
params.cmd_line = msg.command_line;
params.path = msg.path;
params.env = msg.env;
params.inherit_env = !!(msg.flags & DS_MsgFlag_InheritEnv);
params.debug_subprocesses = !!(msg.flags & DS_MsgFlag_DebugSubprocesses);
}
response.pid = dmn_ctrl_launch(ctrl_ctx, &params);
response.pid = ds_ctrl_launch(ctrl_ctx, msg.launch_params);
}break;
//- rjf: attaching
case DS_MsgKind_Attach:
{
response.good = dmn_ctrl_attach(ctrl_ctx, msg.pid);
response.good = ds_ctrl_attach(ctrl_ctx, msg.pid);
}break;
//- rjf: killing
case DS_MsgKind_Kill:
{
response.good = dmn_ctrl_kill(ctrl_ctx, msg.entity, (U32)msg.code);
response.good = ds_ctrl_kill(ctrl_ctx, msg.entity, (U32)msg.code);
}break;
//- rjf: detaching
case DS_MsgKind_Detach:
{
response.good = dmn_ctrl_detach(ctrl_ctx, msg.entity);
response.good = ds_ctrl_detach(ctrl_ctx, msg.entity);
}break;
//- rjf: running ops
@@ -189,7 +182,7 @@ dmn_thread__entry_point(void *p)
ctrls.run_entities_are_processes = !!(msg.flags & DS_MsgFlag_RunEntitiesAreProcesses);
};
response.good = 1;
events = dmn_ctrl_run(scratch.arena, ctrl_ctx, &ctrls);
events = ds_ctrl_run(scratch.arena, ctrl_ctx, &ctrls);
}break;
}
@@ -296,11 +289,16 @@ entry_point(CmdLine *cmd_line)
fprintf(stderr, " %.*s", str8_varg(n->string));
}
fprintf(stderr, "\n");
DS_Msg msg =
DS_LaunchParams launch_params =
{
.kind = DS_MsgKind_Launch,
.command_line = t->cmd_line,
.path = current_path,
.inherit_env = 1,
};
DS_Msg msg =
{
.kind = DS_MsgKind_Launch,
.launch_params = &launch_params,
};
String8 packet = ds_packet_from_msg(scratch.arena, &msg);
RWMutexScope(rds_state->c2d_rw_mutex, 1)
@@ -381,7 +379,7 @@ entry_point(CmdLine *cmd_line)
if(header_is_good)
{
String8 msg_raw = str8_skip(data, sizeof(header));
str8_deserial_read_struct(msg_raw, 2, &peek_kind);
str8_deserial_read_struct(msg_raw, 0, &peek_kind);
if(peek_kind < DS_MsgKind_Launch || DS_MsgKind_SingleStep < peek_kind)
{
DS_Msg msg = ds_msg_from_packet(scratch.arena, data);
+6
View File
@@ -124,3 +124,9 @@ sock_string_from_endpoint(Arena *arena, SOCK_Endpoint endpoint)
}
return result;
}
internal B32
sock_endpoint_match(SOCK_Endpoint a, SOCK_Endpoint b)
{
B32 result = (a.port == b.port && a.kind == b.kind && MemoryMatchArray(a.address_u8, b.address_u8));
}
+1
View File
@@ -60,6 +60,7 @@ typedef SOCK_WAKEUP_FUNCTION_DEF(SOCK_WakeupFunctionType);
internal SOCK_Endpoint sock_endpoint_from_string_port(String8 address, U16 port);
internal SOCK_Endpoint sock_endpoint_from_string(String8 address_and_port);
internal String8 sock_string_from_endpoint(Arena *arena, SOCK_Endpoint endpoint);
internal B32 sock_endpoint_match(SOCK_Endpoint a, SOCK_Endpoint b);
////////////////////////////////
//~ rjf: @per_os_impl Top-Level Layer Calls
+4 -1
View File
@@ -488,7 +488,10 @@ sock_recv(Arena *arena, SOCK_Session session, SOCK_Protocol *protocol_out, SOCK_
if(guarded_ring_read_or_wait(&guard, sizeof(header), header, endt_us))
{
U64 size_cap = s->s2u_ring->ring->size - sizeof(header);
protocol_out[0] = (SOCK_Protocol)header[0];
if(protocol_out != 0)
{
protocol_out[0] = (SOCK_Protocol)header[0];
}
endpoint_out->port = (U16)header[1];
endpoint_out->address_u64[0] = header[2];
endpoint_out->address_u64[1] = header[3];