diff options
-rw-r--r-- | include/ntapi/nt_debug.h | 25 | ||||
-rw-r--r-- | include/ntapi/ntapi.h | 1 | ||||
-rw-r--r-- | project/common.mk | 1 | ||||
-rw-r--r-- | src/debug/ntapi_tt_debug_execution_flow.c | 95 | ||||
-rw-r--r-- | src/internal/ntapi.c | 1 | ||||
-rw-r--r-- | src/internal/ntapi_fnapi.h | 1 |
6 files changed, 124 insertions, 0 deletions
diff --git a/include/ntapi/nt_debug.h b/include/ntapi/nt_debug.h index 5e40cba..3e11193 100644 --- a/include/ntapi/nt_debug.h +++ b/include/ntapi/nt_debug.h @@ -208,6 +208,24 @@ typedef enum _nt_dbg_fltr_type { } nt_dbg_fltr_type; +/* execution flow masks */ +#define NT_DBG_FLOW_MASK_IDLE (1 << NT_DBG_STATE_IDLE) +#define NT_DBG_FLOW_MASK_REPLY_PENDING (1 << NT_DBG_STATE_REPLY_PENDING) + +#define NT_DBG_FLOW_MASK_CREATE_THREAD (1 << NT_DBG_STATE_CREATE_THREAD) +#define NT_DBG_FLOW_MASK_CREATE_PROCESS (1 << NT_DBG_STATE_CREATE_PROCESS) + +#define NT_DBG_FLOW_MASK_EXIT_THREAD (1 << NT_DBG_STATE_EXIT_THREAD) +#define NT_DBG_FLOW_MASK_EXIT_PROCESS (1 << NT_DBG_STATE_EXIT_PROCESS) + +#define NT_DBG_FLOW_MASK_EXCEPTION (1 << NT_DBG_STATE_EXCEPTION) +#define NT_DBG_FLOW_MASK_BREAKPOINT (1 << NT_DBG_STATE_BREAKPOINT) +#define NT_DBG_FLOW_MASK_SINGLE_STEP (1 << NT_DBG_STATE_SINGLE_STEP) + +#define NT_DBG_FLOW_MASK_DLL_LOAD (1 << NT_DBG_STATE_DLL_LOAD) +#define NT_DBG_FLOW_MASK_DLL_UNLOAD (1 << NT_DBG_STATE_DLL_UNLOAD) + + /* debug events */ typedef struct _nt_dbg_km_thread_exit { int32_t exit_status; @@ -321,4 +339,11 @@ typedef int32_t __stdcall ntapi_tt_create_attach_debug_object( __in void * hprocess, __in uint32_t flags); +typedef int32_t __stdcall ntapi_tt_debug_execution_flow( + __in void * hdbgobj, + __in void * hserver, + __in void * hlogfile, + __in uint32_t evtmask, + __in uint64_t * nevents); + #endif diff --git a/include/ntapi/ntapi.h b/include/ntapi/ntapi.h index dc2c22e..493edb2 100644 --- a/include/ntapi/ntapi.h +++ b/include/ntapi/ntapi.h @@ -669,6 +669,7 @@ typedef struct _ntapi_vtbl { /* nt_debug.h */ ntapi_tt_create_debug_object * tt_create_debug_object; ntapi_tt_create_attach_debug_object * tt_create_attach_debug_object; + ntapi_tt_debug_execution_flow * tt_debug_execution_flow; } ntapi_vtbl; diff --git a/project/common.mk b/project/common.mk index f5b4bd7..5009148 100644 --- a/project/common.mk +++ b/project/common.mk @@ -16,6 +16,7 @@ COMMON_SRCS = \ src/daemon/ntapi_dsr_init.c \ src/daemon/ntapi_dsr_internal_connection.c \ src/debug/ntapi_tt_create_debug_object.c \ + src/debug/ntapi_tt_debug_execution_flow.c \ src/fs/ntapi_tt_get_file_handle_type.c \ src/fs/ntapi_tt_istat.c \ src/fs/ntapi_tt_mount.c \ diff --git a/src/debug/ntapi_tt_debug_execution_flow.c b/src/debug/ntapi_tt_debug_execution_flow.c new file mode 100644 index 0000000..5bf4e6c --- /dev/null +++ b/src/debug/ntapi_tt_debug_execution_flow.c @@ -0,0 +1,95 @@ +#include <psxtypes/psxtypes.h> +#include <ntapi/nt_object.h> +#include <ntapi/nt_debug.h> +#include <ntapi/nt_guid.h> +#include <ntapi/nt_acl.h> +#include <ntapi/nt_tty.h> +#include "ntapi_impl.h" + +static int32_t __log_exception_to_server( + nt_dbg_wait_state_change * dbgstate, + void * hserver) +{ + int32_t status; + nt_tty_log_msg msg; + + if (!hserver) + return NT_STATUS_SUCCESS; + + __ntapi->tt_aligned_block_memset( + &msg,0,sizeof(msg)); + + msg.header.msg_type = NT_LPC_NEW_MESSAGE; + msg.header.data_size = sizeof(msg.data); + msg.header.msg_size = sizeof(msg); + msg.data.ttyinfo.opcode = NT_TTY_LOG_ENTRY; + msg.data.loginfo.type = NT_TTY_LOG_INFO_EXCEPTION_RECORD; + msg.data.loginfo.reserved = 0; + msg.data.loginfo.cid.process_id = dbgstate->cid.process_id; + msg.data.loginfo.cid.thread_id = dbgstate->cid.thread_id; + + __ntapi->tt_generic_memcpy( + &msg.data.loginfo.data, + &dbgstate->_u.exception_info.exception_record, + sizeof(nt_exception_record)); + + if ((status = __ntapi->zw_request_wait_reply_port(hserver,&msg,&msg))) + return status; + else if (msg.data.ttyinfo.status) + return msg.data.ttyinfo.status; + + return NT_STATUS_SUCCESS; +} + +int32_t __stdcall __ntapi_tt_debug_execution_flow( + __in void * hdbgobj, + __in void * hserver, + __in void * hlogfile, + __in uint32_t evtmask, + __in uint64_t * nevents) +{ + int32_t status; + int32_t response; + int floop; + uint64_t nevts; + uint64_t necap; + nt_dbg_wait_state_change dbgstate; + + (void)hlogfile; + + necap = (nevents && *nevents) ? *nevents : (uint64_t)(-1); + + for (nevts=0, floop=1; floop && (nevts < necap); nevts++) { + if ((status = __ntapi->zw_wait_for_debug_event( + hdbgobj, + NT_SYNC_NON_ALERTABLE, + 0,&dbgstate))) + return status; + + switch (dbgstate.state) { + case NT_DBG_STATE_EXCEPTION: + if (evtmask & NT_DBG_FLOW_MASK_EXCEPTION) { + __log_exception_to_server(&dbgstate,hserver); + } + + response = NT_DBG_EXCEPTION_NOT_HANDLED; + break; + + case NT_DBG_STATE_EXIT_PROCESS: + response = NT_DBG_CONTINUE; + floop = 0; + break; + + default: + response = NT_DBG_CONTINUE; + break; + } + + __ntapi->zw_debug_continue( + hdbgobj, + &dbgstate.cid, + response); + } + + return NT_STATUS_SUCCESS; +} diff --git a/src/internal/ntapi.c b/src/internal/ntapi.c index 2bd5299..5122305 100644 --- a/src/internal/ntapi.c +++ b/src/internal/ntapi.c @@ -446,6 +446,7 @@ static int32_t __fastcall __ntapi_init_once(ntapi_vtbl ** pvtbl) /* nt_debug.h */ __ntapi->tt_create_debug_object = __ntapi_tt_create_debug_object; __ntapi->tt_create_attach_debug_object = __ntapi_tt_create_attach_debug_object; + __ntapi->tt_debug_execution_flow = __ntapi_tt_debug_execution_flow; /* OS version dependent functions */ diff --git a/src/internal/ntapi_fnapi.h b/src/internal/ntapi_fnapi.h index 1ee52ed..6c20fbf 100644 --- a/src/internal/ntapi_fnapi.h +++ b/src/internal/ntapi_fnapi.h @@ -337,6 +337,7 @@ NTAPI_UFN(log_msg); /* debug */ NTAPI_UFN(tt_create_debug_object); NTAPI_UFN(tt_create_attach_debug_object); +NTAPI_UFN(tt_debug_execution_flow); /* csrss */ NTAPI_VFN(tt_get_csr_port_handle_addr_by_logic,i386); |