From 65a87239eea1cd2d3e5c5ffad60b6060a4a25996 Mon Sep 17 00:00:00 2001 From: midipix Date: Thu, 6 Jun 2019 06:14:39 +0000 Subject: debug interfaces: provide dbg_* interfaces as wrappers around struct __db_vtbl. --- arch/nt32/psxdbg.h | 28 +++++++++++++++++ arch/nt32/psxglue.h | 3 +- arch/nt64/psxdbg.h | 28 +++++++++++++++++ arch/nt64/psxglue.h | 3 +- project/arch.mk | 1 + src/arch/nt32/crt_glue.c | 2 ++ src/arch/nt32/debug.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ src/arch/nt32/vtbl.c | 1 + src/arch/nt64/crt_glue.c | 2 ++ src/arch/nt64/debug.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ src/arch/nt64/vtbl.c | 1 + 11 files changed, 225 insertions(+), 2 deletions(-) create mode 100644 arch/nt32/psxdbg.h create mode 100644 arch/nt64/psxdbg.h create mode 100644 src/arch/nt32/debug.c create mode 100644 src/arch/nt64/debug.c diff --git a/arch/nt32/psxdbg.h b/arch/nt32/psxdbg.h new file mode 100644 index 0000000..38c9fcd --- /dev/null +++ b/arch/nt32/psxdbg.h @@ -0,0 +1,28 @@ +#ifndef _PSXDBG_H_ +#define _PSXDBG_H_ + +struct __dbg_event; + +struct __dbg_vtbl { + int (*dbg_attach)(pid_t); + int (*dbg_detach)(int); + + int (*dbg_spawn)(const char *, char **, char **); + int (*dbg_fork)(void); + int (*dbg_suspend)(int); + int (*dbg_kill)(int); + + int (*dbg_event_query_one)(int, struct __dbg_event *); + int (*dbg_event_query_all)(int, struct __dbg_event[], int); + + int (*dbg_event_acquire)(int, struct __dbg_event *); + int (*dbg_event_respond)(int, struct __dbg_event *); + + int (*dbg_query_cpid)(int); + int (*dbg_query_syspid)(int); + + int (*dbg_common_error)(void); + int (*dbg_native_error)(void); +}; + +#endif diff --git a/arch/nt32/psxglue.h b/arch/nt32/psxglue.h index 37a2109..d8e653a 100644 --- a/arch/nt32/psxglue.h +++ b/arch/nt32/psxglue.h @@ -46,9 +46,10 @@ struct __psx_context { void * ldsoaddr; const unsigned short * ctty; void ** sys_vtbl; + const struct __psx_vtbl * psx_vtbl; const struct __seh_vtbl * seh_vtbl; + const struct __dbg_vtbl * dbg_vtbl; const struct __ldso_vtbl * ldso_vtbl; - const struct __psx_vtbl * psx_vtbl; unsigned int teb_sys_idx; unsigned int teb_libc_idx; void * pthread_surrogate_fn; diff --git a/arch/nt64/psxdbg.h b/arch/nt64/psxdbg.h new file mode 100644 index 0000000..38c9fcd --- /dev/null +++ b/arch/nt64/psxdbg.h @@ -0,0 +1,28 @@ +#ifndef _PSXDBG_H_ +#define _PSXDBG_H_ + +struct __dbg_event; + +struct __dbg_vtbl { + int (*dbg_attach)(pid_t); + int (*dbg_detach)(int); + + int (*dbg_spawn)(const char *, char **, char **); + int (*dbg_fork)(void); + int (*dbg_suspend)(int); + int (*dbg_kill)(int); + + int (*dbg_event_query_one)(int, struct __dbg_event *); + int (*dbg_event_query_all)(int, struct __dbg_event[], int); + + int (*dbg_event_acquire)(int, struct __dbg_event *); + int (*dbg_event_respond)(int, struct __dbg_event *); + + int (*dbg_query_cpid)(int); + int (*dbg_query_syspid)(int); + + int (*dbg_common_error)(void); + int (*dbg_native_error)(void); +}; + +#endif diff --git a/arch/nt64/psxglue.h b/arch/nt64/psxglue.h index 37a2109..d8e653a 100644 --- a/arch/nt64/psxglue.h +++ b/arch/nt64/psxglue.h @@ -46,9 +46,10 @@ struct __psx_context { void * ldsoaddr; const unsigned short * ctty; void ** sys_vtbl; + const struct __psx_vtbl * psx_vtbl; const struct __seh_vtbl * seh_vtbl; + const struct __dbg_vtbl * dbg_vtbl; const struct __ldso_vtbl * ldso_vtbl; - const struct __psx_vtbl * psx_vtbl; unsigned int teb_sys_idx; unsigned int teb_libc_idx; void * pthread_surrogate_fn; diff --git a/project/arch.mk b/project/arch.mk index 5236cb8..a33fd09 100644 --- a/project/arch.mk +++ b/project/arch.mk @@ -23,6 +23,7 @@ LDFLAGS_CONFIG += -Wl,--exclude-symbols=_IO_putc_unlocked LDFLAGS_CONFIG += -Wl,--exclude-symbols=___errno_location TARGET_SYS_HEADERS = \ + $(PROJECT_DIR)/include/sys/debug.h \ $(PROJECT_DIR)/include/sys/unwind.h \ install-headers: install-target-sys-headers diff --git a/src/arch/nt32/crt_glue.c b/src/arch/nt32/crt_glue.c index cd35d52..a710c39 100644 --- a/src/arch/nt32/crt_glue.c +++ b/src/arch/nt32/crt_glue.c @@ -9,6 +9,7 @@ extern const struct __ldso_vtbl * __ldso_vtbl; extern const struct __psx_vtbl * __psx_vtbl; extern const struct __seh_vtbl * __eh_vtbl; +extern const struct __dbg_vtbl * __db_vtbl; static int __pthread_surrogate_init(struct pthread * self); @@ -86,6 +87,7 @@ void __libc_entry_routine( __ldso_vtbl = ctx.ldso_vtbl; __psx_vtbl = ctx.psx_vtbl; __eh_vtbl = ctx.seh_vtbl; + __db_vtbl = ctx.dbg_vtbl; __teb_sys_idx = ctx.teb_sys_idx; __teb_libc_idx = ctx.teb_libc_idx; diff --git a/src/arch/nt32/debug.c b/src/arch/nt32/debug.c new file mode 100644 index 0000000..cfa6aee --- /dev/null +++ b/src/arch/nt32/debug.c @@ -0,0 +1,79 @@ +#include +#include +#include +#include +#include +#include "psxdbg.h" + +extern const struct __dbg_vtbl * __db_vtbl; + + +int __dbg_attach(pid_t pid) +{ + return __db_vtbl->dbg_attach(pid); +} + +int __dbg_detach(int pfd) +{ + return __db_vtbl->dbg_detach(pfd); +} + +int __dbg_spawn(const char * path, char ** argv, char ** envp) +{ + return __db_vtbl->dbg_spawn(path,argv,envp); +} + +int __dbg_fork() +{ + return __db_vtbl->dbg_fork(); +} + +int __dbg_suspend(int pfd) +{ + return __db_vtbl->dbg_suspend(pfd); +} + +int __dbg_kill(int pfd) +{ + return __db_vtbl->dbg_kill(pfd); +} + +int __dbg_event_query_one(int pfd, struct __dbg_event * evt) +{ + return __db_vtbl->dbg_event_query_one(pfd,evt); +} + +int __dbg_event_query_all(int pfd, struct __dbg_event evt[], int nelem) +{ + return __db_vtbl->dbg_event_query_all(pfd,evt,nelem); +} + +int __dbg_event_acquire(int pfd, struct __dbg_event * evt) +{ + return __db_vtbl->dbg_event_acquire(pfd,evt); +} + +int __dbg_event_respond(int pfd, struct __dbg_event * evt) +{ + return __db_vtbl->dbg_event_respond(pfd,evt); +} + +int __dbg_query_cpid(int pfd) +{ + return __db_vtbl->dbg_query_cpid(pfd); +} + +int __dbg_query_syspid(int pfd) +{ + return __db_vtbl->dbg_query_syspid(pfd); +} + +int __dbg_common_error(void) +{ + return __db_vtbl->dbg_common_error(); +} + +int __dbg_native_error(void) +{ + return __db_vtbl->dbg_native_error(); +} diff --git a/src/arch/nt32/vtbl.c b/src/arch/nt32/vtbl.c index ad0a0e9..8a0412f 100644 --- a/src/arch/nt32/vtbl.c +++ b/src/arch/nt32/vtbl.c @@ -6,6 +6,7 @@ const struct __ldso_vtbl * __ldso_vtbl = 0; const struct __psx_vtbl * __psx_vtbl = 0; const struct __seh_vtbl * __eh_vtbl = 0; +const struct __dbg_vtbl * __db_vtbl = 0; unsigned long ** __syscall_vtbl = 0; unsigned long __teb_sys_idx = 0; diff --git a/src/arch/nt64/crt_glue.c b/src/arch/nt64/crt_glue.c index cd35d52..a710c39 100644 --- a/src/arch/nt64/crt_glue.c +++ b/src/arch/nt64/crt_glue.c @@ -9,6 +9,7 @@ extern const struct __ldso_vtbl * __ldso_vtbl; extern const struct __psx_vtbl * __psx_vtbl; extern const struct __seh_vtbl * __eh_vtbl; +extern const struct __dbg_vtbl * __db_vtbl; static int __pthread_surrogate_init(struct pthread * self); @@ -86,6 +87,7 @@ void __libc_entry_routine( __ldso_vtbl = ctx.ldso_vtbl; __psx_vtbl = ctx.psx_vtbl; __eh_vtbl = ctx.seh_vtbl; + __db_vtbl = ctx.dbg_vtbl; __teb_sys_idx = ctx.teb_sys_idx; __teb_libc_idx = ctx.teb_libc_idx; diff --git a/src/arch/nt64/debug.c b/src/arch/nt64/debug.c new file mode 100644 index 0000000..cfa6aee --- /dev/null +++ b/src/arch/nt64/debug.c @@ -0,0 +1,79 @@ +#include +#include +#include +#include +#include +#include "psxdbg.h" + +extern const struct __dbg_vtbl * __db_vtbl; + + +int __dbg_attach(pid_t pid) +{ + return __db_vtbl->dbg_attach(pid); +} + +int __dbg_detach(int pfd) +{ + return __db_vtbl->dbg_detach(pfd); +} + +int __dbg_spawn(const char * path, char ** argv, char ** envp) +{ + return __db_vtbl->dbg_spawn(path,argv,envp); +} + +int __dbg_fork() +{ + return __db_vtbl->dbg_fork(); +} + +int __dbg_suspend(int pfd) +{ + return __db_vtbl->dbg_suspend(pfd); +} + +int __dbg_kill(int pfd) +{ + return __db_vtbl->dbg_kill(pfd); +} + +int __dbg_event_query_one(int pfd, struct __dbg_event * evt) +{ + return __db_vtbl->dbg_event_query_one(pfd,evt); +} + +int __dbg_event_query_all(int pfd, struct __dbg_event evt[], int nelem) +{ + return __db_vtbl->dbg_event_query_all(pfd,evt,nelem); +} + +int __dbg_event_acquire(int pfd, struct __dbg_event * evt) +{ + return __db_vtbl->dbg_event_acquire(pfd,evt); +} + +int __dbg_event_respond(int pfd, struct __dbg_event * evt) +{ + return __db_vtbl->dbg_event_respond(pfd,evt); +} + +int __dbg_query_cpid(int pfd) +{ + return __db_vtbl->dbg_query_cpid(pfd); +} + +int __dbg_query_syspid(int pfd) +{ + return __db_vtbl->dbg_query_syspid(pfd); +} + +int __dbg_common_error(void) +{ + return __db_vtbl->dbg_common_error(); +} + +int __dbg_native_error(void) +{ + return __db_vtbl->dbg_native_error(); +} diff --git a/src/arch/nt64/vtbl.c b/src/arch/nt64/vtbl.c index ad0a0e9..8a0412f 100644 --- a/src/arch/nt64/vtbl.c +++ b/src/arch/nt64/vtbl.c @@ -6,6 +6,7 @@ const struct __ldso_vtbl * __ldso_vtbl = 0; const struct __psx_vtbl * __psx_vtbl = 0; const struct __seh_vtbl * __eh_vtbl = 0; +const struct __dbg_vtbl * __db_vtbl = 0; unsigned long ** __syscall_vtbl = 0; unsigned long __teb_sys_idx = 0; -- cgit v1.2.3