@@ -630,6 +630,7 @@ ctrl_serialized_string_from_event(Arena *arena, CTRL_Event *event, U64 max)
630630 str8_serial_push_struct (scratch .arena , & srl , & event -> exception_code );
631631 str8_serial_push_struct (scratch .arena , & srl , & event -> rgba );
632632 str8_serial_push_struct (scratch .arena , & srl , & event -> bp_flags );
633+ str8_serial_push_struct (scratch .arena , & srl , & event -> target_os );
633634 str8_serial_push_struct (scratch .arena , & srl , & event -> tls_model );
634635 str8_serial_push_struct (scratch .arena , & srl , & event -> tls_index );
635636 str8_serial_push_struct (scratch .arena , & srl , & event -> tls_offset );
@@ -666,6 +667,7 @@ ctrl_event_from_serialized_string(Arena *arena, String8 string)
666667 read_off += str8_deserial_read_struct (string , read_off , & event .exception_code );
667668 read_off += str8_deserial_read_struct (string , read_off , & event .rgba );
668669 read_off += str8_deserial_read_struct (string , read_off , & event .bp_flags );
670+ read_off += str8_deserial_read_struct (string , read_off , & event .target_os );
669671 read_off += str8_deserial_read_struct (string , read_off , & event .tls_model );
670672 read_off += str8_deserial_read_struct (string , read_off , & event .tls_index );
671673 read_off += str8_deserial_read_struct (string , read_off , & event .tls_offset );
@@ -1270,6 +1272,7 @@ ctrl_entity_store_apply_events(CTRL_EntityCtxRWStore *store, CTRL_EventList *lis
12701272 CTRL_Entity * machine = ctrl_entity_from_handle (& store -> ctx , ctrl_handle_make (event -> entity .machine_id , dmn_handle_zero ()));
12711273 CTRL_Entity * process = ctrl_entity_alloc (store , machine , CTRL_EntityKind_Process , event -> arch , event -> entity , (U64 )event -> entity_id );
12721274 process -> tls_model = event -> tls_model ;
1275+ process -> target_os = event -> target_os ;
12731276 }break ;
12741277 case CTRL_EventKind_EndProc :
12751278 {
@@ -2129,7 +2132,7 @@ ctrl_establish_frame_unwind_context__dwarf(Arena *arena, CTRL_Handle process_han
21292132}
21302133
21312134internal CTRL_UnwindStepResult
2132- ctrl_unwind_step__dwarf (CTRL_Handle process_handle , CTRL_Handle module_handle , Arch arch , void * regs , CTRL_FrameUnwindContext * frame_ctx , U64 endt_us )
2135+ ctrl_unwind_step__dwarf (CTRL_Handle process_handle , Arch arch , void * regs , CTRL_FrameUnwindContext * frame_ctx , U64 endt_us )
21332136{
21342137 Temp scratch = scratch_begin (0 , 0 );
21352138
@@ -3032,47 +3035,6 @@ ctrl_unwind_step__pe_x64(CTRL_Handle process_handle, CTRL_Handle module_handle,
30323035 return result ;
30333036}
30343037
3035- //- rjf: abstracted unwind step
3036-
3037- internal CTRL_UnwindStepResult
3038- ctrl_establish_frame_unwind_context (Arena * arena , CTRL_Handle process_handle , CTRL_Handle module_handle , Arch arch , void * regs , U64 endt_us , CTRL_FrameUnwindContext * ctx_out )
3039- {
3040- CTRL_UnwindStepResult result = {0 };
3041- #if OS_LINUX
3042- result = ctrl_establish_frame_unwind_context__dwarf (arena , process_handle , module_handle , arch , regs , endt_us , ctx_out );
3043- #elif OS_WINDOWS
3044- // windows does not have a concept of frame context
3045- #else
3046- # error "unwinder is not defined for current OS"
3047- #endif
3048- return result ;
3049- }
3050-
3051- internal CTRL_UnwindStepResult
3052- ctrl_unwind_step (CTRL_Handle process , CTRL_Handle module , U64 module_base_vaddr , Arch arch , void * reg_block , CTRL_FrameUnwindContext * frame_ctx , U64 endt_us )
3053- {
3054- CTRL_UnwindStepResult result = {0 };
3055- #if OS_LINUX
3056- result = ctrl_unwind_step__dwarf (process , module , arch , reg_block , frame_ctx , endt_us );
3057- #elif OS_WINDOWS
3058- switch (arch )
3059- {
3060- case Arch_Null :{}break ;
3061- case Arch_x64 :{result = ctrl_unwind_step__pe_x64 (process , module , module_base_vaddr , reg_block , endt_us );}break ;
3062- case Arch_x86 :
3063- case Arch_arm32 :
3064- case Arch_arm64 :
3065- {
3066- NotImplemented ;
3067- }break ;
3068- default :{InvalidPath ;}break ;
3069- }
3070- #else
3071- # error "unwinder is not defined for current OS"
3072- #endif
3073- return result ;
3074- }
3075-
30763038//- rjf: abstracted full unwind
30773039
30783040internal CTRL_Unwind
@@ -3110,11 +3072,28 @@ ctrl_unwind_from_thread(Arena *arena, CTRL_EntityCtx *ctx, CTRL_Handle thread, U
31103072 }
31113073
31123074 // rip -> module
3113- CTRL_Entity * module = ctrl_module_from_process_vaddr (process_entity , rip );
3075+ CTRL_Entity * module_entity = ctrl_module_from_process_vaddr (process_entity , rip );
31143076
31153077 // establish frame context
31163078 CTRL_FrameUnwindContext frame_ctx = {0 };
3117- CTRL_UnwindStepResult frame_ctx_result = ctrl_establish_frame_unwind_context (scratch .arena , process_entity -> handle , module -> handle , arch , regs_block , endt_us , & frame_ctx );
3079+ CTRL_UnwindStepResult frame_ctx_result = {0 };
3080+ switch (process_entity -> target_os )
3081+ {
3082+ case OperatingSystem_Null :{}break ;
3083+ case OperatingSystem_Windows :
3084+ {
3085+ // no concept of frame unwind context
3086+ }break ;
3087+ case OperatingSystem_Linux :
3088+ {
3089+ frame_ctx_result = ctrl_establish_frame_unwind_context__dwarf (arena , process_entity -> handle , module_entity -> handle , arch , regs_block , endt_us , & frame_ctx );
3090+ }break ;
3091+ case OperatingSystem_Mac :
3092+ {
3093+ NotImplemented ;
3094+ }break ;
3095+ default : { InvalidPath ; }break ;
3096+ }
31183097 unwind .flags |= frame_ctx_result .flags ;
31193098 if (unwind .flags & (CTRL_UnwindFlag_Stale |CTRL_UnwindFlag_Error ))
31203099 {
@@ -3131,10 +3110,41 @@ ctrl_unwind_from_thread(Arena *arena, CTRL_EntityCtx *ctx, CTRL_Handle thread, U
31313110 frame_node_count += 1 ;
31323111
31333112 // rjf: unwind one step
3134- CTRL_UnwindStepResult step = ctrl_unwind_step (process_entity -> handle , module -> handle , module -> vaddr_range .min , arch , regs_block , & frame_ctx , endt_us );
3135- unwind .flags |= step .flags ;
3113+ CTRL_UnwindStepResult step_result = {0 };
3114+ switch (process_entity -> target_os )
3115+ {
3116+ case OperatingSystem_Null :{}break ;
3117+ case OperatingSystem_Windows :
3118+ {
3119+ switch (arch )
3120+ {
3121+ case Arch_Null :{}break ;
3122+ case Arch_x64 :
3123+ {
3124+ step_result = ctrl_unwind_step__pe_x64 (process_entity -> handle , module_entity -> handle , module_entity -> vaddr_range .min , regs_block , endt_us );
3125+ }break ;
3126+ case Arch_x86 :
3127+ case Arch_arm32 :
3128+ case Arch_arm64 :
3129+ {
3130+ NotImplemented ;
3131+ }break ;
3132+ default : { InvalidPath ; } break ;
3133+ }
3134+ }break ;
3135+ case OperatingSystem_Linux :
3136+ {
3137+ step_result = ctrl_unwind_step__dwarf (process_entity -> handle , arch , regs_block , & frame_ctx , endt_us );
3138+ }break ;
3139+ case OperatingSystem_Mac :
3140+ {
3141+ NotImplemented ;
3142+ }break ;
3143+ default : { InvalidPath ; }break ;
3144+ }
31363145
31373146 // stop unwinding on errors or stale data
3147+ unwind .flags |= step_result .flags ;
31383148 if (unwind .flags & (CTRL_UnwindFlag_Stale |CTRL_UnwindFlag_Error ) ||
31393149 (regs_rsp_from_arch_block (arch , regs_block ) == rsp && regs_rip_from_arch_block (arch , regs_block ) == rip ))
31403150 {
@@ -4524,6 +4534,7 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg,
45244534 out_evt -> arch = event -> arch ;
45254535 out_evt -> entity_id = event -> code ;
45264536 out_evt -> tls_model = ctrl_dynamic_linker_type_from_dmn (event -> tls_model );
4537+ out_evt -> target_os = OperatingSystem_CURRENT ; // TODO: operating system of the remote target machine
45274538 ctrl_state -> process_counter += 1 ;
45284539 }break ;
45294540 case DMN_EventKind_CreateThread :
@@ -6945,6 +6956,10 @@ ctrl_call_stack_artifact_create(String8 key, B32 *cancel_signal, B32 *retry_out,
69456956 dst_e -> timestamp = src_e -> timestamp ;
69466957 dst_e -> bp_flags = src_e -> bp_flags ;
69476958 dst_e -> string = push_str8_copy (scratch .arena , src_e -> string );
6959+ dst_e -> tls_index = src_e -> tls_index ;
6960+ dst_e -> tls_offset = src_e -> tls_offset ;
6961+ dst_e -> target_os = src_e -> target_os ;
6962+ dst_e -> tls_model = src_e -> tls_model ;
69486963 }
69496964 if (dst_parent == & ctrl_entity_nil )
69506965 {
0 commit comments