Skip to content

Commit

Permalink
[wasm][debugger] Reuse debugger-agent on wasm debugger (#52300)
Browse files Browse the repository at this point in the history
* Trying to reuse debugger-agent on wasm debugger. This will remove a lot of code that does the same thing on mini-wasm-debugger.

* Replace remove_breakpoint and clear_all_breakpoints with the ones on debugger-agent and remove unused code.

* Stepping and callstack using debugger-agent.

* Remove more code.

* Get frame values using debugger-agent.

* Working valuetypes and call function on valuetypes.
make -C src/mono/wasm/ run-debugger-tests TEST_FILTER=DebuggerTests.SteppingTests.InspectValueTypeMethodArgsWhileStepping is working without use_cfo.

* Failed:   316, Passed:   175

* Failed:   307, Passed:   184, Skipped:     0, Total:   491

* Failed:   280, Passed:   211

* Failed:   277, Passed:   214

* Implemented boxed value.
Failed:   271, Passed:   220

* Implementing get properties on objects.
Implementing handling error on debugger-agent.

* Implementing callfunctionon object.
Failed:   248, Passed:   243

* Implementing get pointer values.
Failed:   243, Passed:   248

* Fixing pointer values and implement call on function with pointers.
Failed:   226, Passed:   265

* Reimplement call function on, and implement set values.
Failed:   192, Passed:   299

* Failed:   192, Passed:   299

* Fixing valuetype with null values.

Failed:   184, Passed:   307

* Implemented Evaluate expressions, conditional breakpoints, all breakpoints tests are passing.
Failed:   172, Passed:   319

* Fixing evaluate with value type.
Failed:   156, Passed:   335

* Trim part and add cache.
Failed:   148, Passed:   343

* Fixing evaluate expression.
Failed:    99, Passed:   392

* GetPropertiesTests working.

Failed:    53, Passed:   438

* Passing delegate tests.
Failed:    31, Passed:   460

* Removing unused code.

* Implementing exception handler.
Failed:    30, Passed:   461

* Fixing cfo returning array.
Removing more code.
Removing 2 tests that tests functions which does not exist anymore.
Failed:    18, Passed:   471

* Fix CallFunctionOn returning primitive types and null.

Failed:     9, Passed:   480

* Failed:     7, Passed:   482

* Fixing some tests.
Failed:     2, Passed:   488

* Removing a lot of code.
Failed:     4, Passed:   485

* 0 ERRORS!

* Removing more code.
No errors.

* Fixing added tests.

* Return javascript callstack after managed callstack.
Step out from managed code return to native wasm or javascript.
Adding debug info to Wasm.Browser.Sample to help testing debugger with sample.

* Change what Ankit suggested.
Clear cache with valuetypes and pointers after resume or step.

* Fixing suggestions.

* Fix error on wasm build.

* Apply suggestions from code review

Co-authored-by: Larry Ewing <lewing@microsoft.com>

* Changing what was suggested by @lewing.

* Fix pointer tests.

* Refactoring CreateJObjectForVariableValue

* Changing what @lewing suggested.

* Apply suggestions from code review

Co-authored-by: Larry Ewing <lewing@microsoft.com>

* Update src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs

Co-authored-by: Larry Ewing <lewing@microsoft.com>

* Update src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs

Co-authored-by: Larry Ewing <lewing@microsoft.com>

* Fixing @lewing changes.

* Trying to fix CI.

Co-authored-by: Larry Ewing <lewing@microsoft.com>
  • Loading branch information
thaystg and lewing committed Jun 23, 2021
1 parent d7a5b89 commit 4f4f0db
Show file tree
Hide file tree
Showing 18 changed files with 2,839 additions and 3,447 deletions.
479 changes: 301 additions & 178 deletions src/mono/mono/mini/debugger-agent.c

Large diffs are not rendered by default.

66 changes: 66 additions & 0 deletions src/mono/mono/mini/debugger-agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,45 @@
#define __MONO_DEBUGGER_AGENT_H__

#include "mini.h"
#include "debugger-protocol.h"

#include <mono/utils/mono-stack-unwinding.h>

#define MONO_DBG_CALLBACKS_VERSION (4)
// 2. debug_log parameters changed from MonoString* to MonoStringHandle
// 3. debug_log parameters changed from MonoStringHandle back to MonoString*

typedef struct _InvokeData InvokeData;

struct _InvokeData
{
int id;
int flags;
guint8 *p;
guint8 *endp;
/* This is the context which needs to be restored after the invoke */
MonoContext ctx;
gboolean has_ctx;
/*
* If this is set, invoke this method with the arguments given by ARGS.
*/
MonoMethod *method;
gpointer *args;
guint32 suspend_count;
int nmethods;

InvokeData *last_invoke;
};

typedef struct {
const char *name;
void (*connect) (const char *address);
void (*close1) (void);
void (*close2) (void);
gboolean (*send) (void *buf, int len);
int (*recv) (void *buf, int len);
} DebuggerTransport;

struct _MonoDebuggerCallbacks {
int version;
void (*parse_options) (char *options);
Expand Down Expand Up @@ -46,4 +79,37 @@ mono_debugger_agent_stub_init (void);
MONO_API MONO_RT_EXTERNAL_ONLY gboolean
mono_debugger_agent_transport_handshake (void);

MONO_API void
mono_debugger_agent_register_transport (DebuggerTransport *trans);

MdbgProtErrorCode
mono_process_dbg_packet (int id, MdbgProtCommandSet command_set, int command, gboolean *no_reply, guint8 *p, guint8 *end, MdbgProtBuffer *buf);

void
mono_init_debugger_agent_for_wasm (int log_level);

void*
mono_dbg_create_breakpoint_events (GPtrArray *ss_reqs, GPtrArray *bp_reqs, MonoJitInfo *ji, MdbgProtEventKind kind);

void
mono_dbg_process_breakpoint_events (void *_evts, MonoMethod *method, MonoContext *ctx, int il_offset);

void
mono_dbg_debugger_agent_user_break (void);

void
mono_wasm_save_thread_context (void);

DebuggerTlsData*
mono_wasm_get_tls (void);

MdbgProtErrorCode
mono_do_invoke_method (DebuggerTlsData *tls, MdbgProtBuffer *buf, InvokeData *invoke, guint8 *p, guint8 **endp);

void
mono_debugger_agent_handle_exception (MonoException *exc, MonoContext *throw_ctx, MonoContext *catch_ctx, StackFrameInfo *catch_frame);

void
mono_ss_discard_frame_context (void *the_tls);

#endif
7 changes: 0 additions & 7 deletions src/mono/mono/mini/debugger-engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,13 +388,6 @@ collect_domain_bp (gpointer key, gpointer value, gpointer user_data)
jit_mm_unlock (jit_mm);
}

void
mono_de_clear_all_breakpoints (void)
{
while (breakpoints->len)
mono_de_clear_breakpoint ((MonoBreakpoint*)g_ptr_array_index (breakpoints, 0));
}

/*
* mono_de_set_breakpoint:
*
Expand Down
13 changes: 12 additions & 1 deletion src/mono/mono/mini/debugger-engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,6 @@ MonoBreakpoint* mono_de_set_breakpoint (MonoMethod *method, long il_offset, Even
void mono_de_collect_breakpoints_by_sp (SeqPoint *sp, MonoJitInfo *ji, GPtrArray *ss_reqs, GPtrArray *bp_reqs);
void mono_de_clear_breakpoints_for_domain (MonoDomain *domain);
void mono_de_add_pending_breakpoints (MonoMethod *method, MonoJitInfo *ji);
void mono_de_clear_all_breakpoints (void);
MonoBreakpoint * mono_de_get_breakpoint_by_id (int id);

//single stepping
Expand Down Expand Up @@ -545,3 +544,15 @@ void win32_debugger_log(FILE *stream, const gchar *format, ...);
#define PRINT_ERROR_MSG(...) g_printerr (__VA_ARGS__)
#define PRINT_MSG(...) g_print (__VA_ARGS__)
#endif

int
mono_ss_create_init_args (SingleStepReq *ss_req, SingleStepArgs *args);

void
mono_ss_args_destroy (SingleStepArgs *ss_args);

int
mono_get_this_async_id (DbgEngineStackFrame *frame);

void
mono_ss_calculate_framecount (void *tls, MonoContext *ctx, gboolean force_use_ctx, DbgEngineStackFrame ***frames, int *nframes);
1 change: 0 additions & 1 deletion src/mono/mono/mini/debugger-protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ m_dbgprot_decode_int (uint8_t *buf, uint8_t **endbuf, uint8_t *limit)
{
*endbuf = buf + 4;
g_assert (*endbuf <= limit);

return (((int)buf [0]) << 24) | (((int)buf [1]) << 16) | (((int)buf [2]) << 8) | (((int)buf [3]) << 0);
}

Expand Down
14 changes: 10 additions & 4 deletions src/mono/mono/mini/debugger-protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ typedef enum {
MDBGPROT_CMD_VM_START_BUFFERING = 14,
MDBGPROT_CMD_VM_STOP_BUFFERING = 15,
MDBGPROT_CMD_VM_READ_MEMORY = 16,
MDBGPROT_CMD_VM_WRITE_MEMORY = 17
MDBGPROT_CMD_VM_WRITE_MEMORY = 17,
MDBGPROT_CMD_GET_ASSEMBLY_BY_NAME = 18
} MdbgProtCmdVM;

typedef enum {
Expand Down Expand Up @@ -173,7 +174,9 @@ typedef enum {
MDBGPROT_CMD_METHOD_MAKE_GENERIC_METHOD = 10,
MDBGPROT_CMD_METHOD_TOKEN = 11,
MDBGPROT_CMD_METHOD_ASSEMBLY = 12,
MDBGPROT_CMD_METHOD_GET_CLASS_TOKEN = 13
MDBGPROT_CMD_METHOD_GET_CLASS_TOKEN = 13,
MDBGPROT_CMD_METHOD_HAS_ASYNC_DEBUG_INFO = 14,
MDBGPROT_CMD_METHOD_GET_NAME_FULL = 15
} MdbgProtCmdMethod;

typedef enum {
Expand All @@ -197,7 +200,8 @@ typedef enum {
MDBGPROT_CMD_TYPE_IS_INITIALIZED = 18,
MDBGPROT_CMD_TYPE_CREATE_INSTANCE = 19,
MDBGPROT_CMD_TYPE_GET_VALUE_SIZE = 20,
MDBGPROT_CMD_TYPE_GET_VALUES_ICORDBG = 21
MDBGPROT_CMD_TYPE_GET_VALUES_ICORDBG = 21,
MDBGPROT_CMD_TYPE_GET_PARENTS = 22
} MdbgProtCmdType;

typedef enum {
Expand Down Expand Up @@ -235,7 +239,9 @@ typedef enum {
MDBGPROT_CMD_OBJECT_REF_GET_DOMAIN = 5,
MDBGPROT_CMD_OBJECT_REF_SET_VALUES = 6,
MDBGPROT_CMD_OBJECT_REF_GET_INFO = 7,
MDBGPROT_CMD_OBJECT_REF_GET_VALUES_ICORDBG = 8
MDBGPROT_CMD_OBJECT_REF_GET_VALUES_ICORDBG = 8,
MDBGPROT_CMD_OBJECT_REF_DELEGATE_GET_METHOD = 9,
MDBGPROT_CMD_OBJECT_IS_DELEGATE = 10
} MdbgProtCmdObject;

typedef enum {
Expand Down
Loading

0 comments on commit 4f4f0db

Please sign in to comment.