Skip to content

Commit

Permalink
[metadata] Add mono_get_defaults ()
Browse files Browse the repository at this point in the history
And use it in the debugger
  • Loading branch information
lambdageek committed Jan 15, 2022
1 parent 06cbfc0 commit 9ec5b63
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 20 deletions.
16 changes: 6 additions & 10 deletions src/mono/mono/component/debugger-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,6 @@ static gint32 suspend_count;
/* Whenever to buffer reply messages and send them together */
static gboolean buffer_replies;

MonoDefaults *mdbg_mono_defaults;

#ifndef TARGET_WASM
#define GET_TLS_DATA_FROM_THREAD(thread) \
DebuggerTlsData *tls = NULL; \
Expand Down Expand Up @@ -727,13 +725,11 @@ mono_debugger_is_disconnected (void)
}

static void
debugger_agent_init (MonoDefaults *mono_defaults)
debugger_agent_init (void)
{
if (!agent_config.enabled)
return;

mdbg_mono_defaults = mono_defaults;

DebuggerEngineCallbacks cbs;
memset (&cbs, 0, sizeof (cbs));
cbs.tls_get_restore_state = tls_get_restore_state;
Expand Down Expand Up @@ -4750,7 +4746,7 @@ static void
debugger_agent_handle_exception (MonoException *exc, MonoContext *throw_ctx,
MonoContext *catch_ctx, StackFrameInfo *catch_frame)
{
if (catch_ctx == NULL && catch_frame == NULL && get_mini_debug_options ()->suspend_on_unhandled && mono_object_class (exc) != mdbg_mono_defaults->threadabortexception_class) {
if (catch_ctx == NULL && catch_frame == NULL && get_mini_debug_options ()->suspend_on_unhandled && mono_object_class (exc) != mono_get_defaults ()->threadabortexception_class) {
mono_runtime_printf_err ("Unhandled exception, suspending...");
while (1)
;
Expand Down Expand Up @@ -6512,7 +6508,7 @@ module_apply_changes (MonoImage *image, MonoArray *dmeta, MonoArray *dil, MonoAr
static void
buffer_add_cattr_arg (Buffer *buf, MonoType *t, MonoDomain *domain, MonoObject *val)
{
if (val && val->vtable->klass == mdbg_mono_defaults->runtimetype_class) {
if (val && val->vtable->klass == mono_get_defaults ()->runtimetype_class) {
/* Special case these so the client doesn't have to handle Type objects */

buffer_add_byte (buf, VALUE_TYPE_ID_TYPE);
Expand Down Expand Up @@ -8712,16 +8708,16 @@ method_commands_internal (int command, MonoMethod *method, MonoDomain *domain, g
g_error ("Could not load token due to %s", mono_error_get_message (error));
}

if (handle_class == mdbg_mono_defaults->typehandle_class) {
if (handle_class == mono_get_defaults ()->typehandle_class) {
buffer_add_byte (buf, TOKEN_TYPE_TYPE);
if (method->wrapper_type == MONO_WRAPPER_DYNAMIC_METHOD)
buffer_add_typeid (buf, domain, (MonoClass *) val);
else
buffer_add_typeid (buf, domain, mono_class_from_mono_type_internal ((MonoType*)val));
} else if (handle_class == mdbg_mono_defaults->fieldhandle_class) {
} else if (handle_class == mono_get_defaults ()->fieldhandle_class) {
buffer_add_byte (buf, TOKEN_TYPE_FIELD);
buffer_add_fieldid (buf, domain, (MonoClassField *)val);
} else if (handle_class == mdbg_mono_defaults->methodhandle_class) {
} else if (handle_class == mono_get_defaults ()->methodhandle_class) {
buffer_add_byte (buf, TOKEN_TYPE_METHOD);
buffer_add_methodid (buf, domain, (MonoMethod *)val);
} else if (handle_class == mono_get_string_class ()) {
Expand Down
4 changes: 2 additions & 2 deletions src/mono/mono/component/debugger-stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static void
stub_debugger_parse_options (char *options);

static void
stub_debugger_init (MonoDefaults *mono_defaults);
stub_debugger_init (void);

static void
stub_debugger_breakpoint_hit (void *sigctx);
Expand Down Expand Up @@ -113,7 +113,7 @@ stub_debugger_parse_options (char *options)
}

static void
stub_debugger_init (MonoDefaults *mono_defaults)
stub_debugger_init (void)
{
}

Expand Down
4 changes: 1 addition & 3 deletions src/mono/mono/component/debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ typedef struct _DebuggerTlsData DebuggerTlsData;

typedef struct MonoComponentDebugger {
MonoComponent component;
void (*init) (MonoDefaults *mono_defaults);
void (*init) (void);
void (*user_break) (void);
void (*parse_options) (char *options);
void (*breakpoint_hit) (void *sigctx);
Expand All @@ -199,8 +199,6 @@ typedef struct MonoComponentDebugger {
} MonoComponentDebugger;


extern MonoDefaults *mdbg_mono_defaults;

#define DE_ERR_NONE 0
// WARNING WARNING WARNING
// Error codes MUST match those of sdb for now
Expand Down
6 changes: 2 additions & 4 deletions src/mono/mono/component/mini-wasm-debugger.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,14 @@ mono_wasm_enable_debugging_internal (int debug_level)
}

static void
mono_wasm_debugger_init (MonoDefaults *mono_defaults)
mono_wasm_debugger_init (void)
{
int debug_level = mono_wasm_get_debug_level();
mono_wasm_enable_debugging_internal (debug_level);

if (!debugger_enabled)
return;

mdbg_mono_defaults = mono_defaults;

DebuggerEngineCallbacks cbs = {
.tls_get_restore_state = tls_get_restore_state,
.try_process_suspend = try_process_suspend,
Expand Down Expand Up @@ -433,7 +431,7 @@ mono_wasm_breakpoint_hit (void)
}

static void
mono_wasm_debugger_init (MonoDefaults *mono_defaults)
mono_wasm_debugger_init (void)
{
}

Expand Down
4 changes: 4 additions & 0 deletions src/mono/mono/metadata/class-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,10 @@ typedef struct {
/* If you need a MonoType, use one of the mono_get_*_type () functions in class-inlines.h */
extern MonoDefaults mono_defaults;

MONO_COMPONENT_API
MonoDefaults *
mono_get_defaults (void);

#define GENERATE_GET_CLASS_WITH_CACHE_DECL(shortname) \
MonoClass* mono_class_get_##shortname##_class (void);

Expand Down
6 changes: 6 additions & 0 deletions src/mono/mono/metadata/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ mono_loader_init ()
}
}

MonoDefaults *
mono_get_defaults (void)
{
return &mono_defaults;
}

void
mono_global_loader_data_lock (void)
{
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/mini/mini-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -4522,7 +4522,7 @@ mini_init (const char *filename, const char *runtime_version)
if (default_opt & MONO_OPT_AOT)
mono_aot_init ();

mono_component_debugger ()->init (&mono_defaults);
mono_component_debugger ()->init ();

#ifdef MONO_ARCH_GSHARED_SUPPORTED
mono_set_generic_sharing_supported (TRUE);
Expand Down

0 comments on commit 9ec5b63

Please sign in to comment.