mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-19 19:10:17 +00:00
upgrade istattach to status
This commit is contained in:
parent
372c43614e
commit
1a6f2ec2a3
@ -659,7 +659,7 @@ PK_API bool StopIteration() PY_RAISE;
|
||||
|
||||
#if PK_ENABLE_OS
|
||||
PK_API void py_debugger_waitforattach(const char* hostname, unsigned short port);
|
||||
PK_API bool py_debugger_isattached();
|
||||
PK_API int py_debugger_status();
|
||||
PK_API void py_debugger_exceptionbreakpoint(py_Ref exc);
|
||||
PK_API void py_debugger_exit(int code);
|
||||
#else
|
||||
|
@ -53,7 +53,8 @@ static struct c11_dap_server {
|
||||
c11_socket_handler toclient;
|
||||
bool isconfiguredone;
|
||||
bool isfirstatttach;
|
||||
bool isattach;
|
||||
bool isUserCode;
|
||||
bool isAttached;
|
||||
bool isclientready;
|
||||
} server;
|
||||
|
||||
@ -441,7 +442,8 @@ void c11_dap_init_server(const char* hostname, unsigned short port) {
|
||||
server.isconfiguredone = false;
|
||||
server.isclientready = false;
|
||||
server.isfirstatttach = false;
|
||||
server.isattach = false;
|
||||
server.isUserCode = false;
|
||||
server.isAttached = false;
|
||||
server.buffer_begin = server.buffer_data;
|
||||
server.server = c11_socket_create(C11_AF_INET, C11_SOCK_STREAM, 0);
|
||||
c11_socket_bind(server.server, hostname, port);
|
||||
@ -480,7 +482,8 @@ void c11_dap_configure_debugger() {
|
||||
if(server.isfirstatttach) {
|
||||
c11_dap_send_initialized_event();
|
||||
server.isfirstatttach = false;
|
||||
server.isattach = true;
|
||||
server.isAttached = true;
|
||||
server.isUserCode = true;
|
||||
} else if(server.isclientready) {
|
||||
server.isclientready = false;
|
||||
return;
|
||||
@ -491,7 +494,7 @@ void c11_dap_configure_debugger() {
|
||||
|
||||
void c11_dap_tracefunc(py_Frame* frame, enum py_TraceEvent event) {
|
||||
py_sys_settrace(NULL, false);
|
||||
server.isattach = false;
|
||||
server.isUserCode = false;
|
||||
C11_DEBUGGER_STATUS result = c11_debugger_on_trace(frame, event);
|
||||
if(result == C11_DEBUGGER_EXIT) {
|
||||
// c11_dap_send_output_event("console", "[DEBUGGER INFO] : program exit\n");
|
||||
@ -515,14 +518,14 @@ void c11_dap_tracefunc(py_Frame* frame, enum py_TraceEvent event) {
|
||||
C11_STOP_REASON reason = c11_debugger_should_pause();
|
||||
if(reason == C11_DEBUGGER_NOSTOP) {
|
||||
py_sys_settrace(c11_dap_tracefunc, false);
|
||||
server.isattach = true;
|
||||
server.isUserCode = true;
|
||||
return;
|
||||
}
|
||||
c11_dap_send_stop_event(reason);
|
||||
while(c11_debugger_should_keep_pause()) {
|
||||
c11_dap_handle_message();
|
||||
}
|
||||
server.isattach = true;
|
||||
server.isUserCode = true;
|
||||
py_sys_settrace(c11_dap_tracefunc, false);
|
||||
}
|
||||
|
||||
@ -543,13 +546,18 @@ void py_debugger_waitforattach(const char* hostname, unsigned short port) {
|
||||
|
||||
void py_debugger_exit(int exitCode) { c11_dap_send_exited_event(exitCode); }
|
||||
|
||||
bool py_debugger_isattached() { return server.isattach; }
|
||||
int py_debugger_status() {
|
||||
if(!server.isAttached) {
|
||||
return 0;
|
||||
}
|
||||
return server.isUserCode ? 1 : 2;
|
||||
}
|
||||
|
||||
void py_debugger_exceptionbreakpoint(py_Ref exc) {
|
||||
assert(py_isinstance(exc, tp_BaseException));
|
||||
|
||||
py_sys_settrace(NULL, true);
|
||||
server.isattach = false;
|
||||
server.isUserCode = false;
|
||||
|
||||
c11_debugger_exception_on_trace(exc);
|
||||
for(;;) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user