diff --git a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props index 3efbe093fb75e..171be1106ee28 100644 --- a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props +++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props @@ -193,6 +193,13 @@ + + + + + + + diff --git a/src/mono/dlls/mscordbi/CMakeLists.txt b/src/mono/dlls/mscordbi/CMakeLists.txt index d060638b40d80..32e61b129f34a 100644 --- a/src/mono/dlls/mscordbi/CMakeLists.txt +++ b/src/mono/dlls/mscordbi/CMakeLists.txt @@ -130,11 +130,11 @@ if (CLR_CMAKE_HOST_UNIX) append("-Wno-strict-prototypes -Wno-deprecated -Wno-pointer-arith" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) endif (CLR_CMAKE_HOST_UNIX) -add_library(mscordbi SHARED "${mscorbi_sources};${PROJECT_SOURCE_DIR}/../../mono/mini/debugger-protocol.c;${PROJECT_SOURCE_DIR}/../../../coreclr/pal/prebuilt/idl/xcordebug_i.cpp;${PROJECT_SOURCE_DIR}/../../../coreclr/pal/prebuilt/idl/cordebug_i.cpp") +add_library(mscordbi SHARED "${mscorbi_sources};${PROJECT_SOURCE_DIR}/../../mono/component/debugger-protocol.c;${PROJECT_SOURCE_DIR}/../../../coreclr/pal/prebuilt/idl/xcordebug_i.cpp;${PROJECT_SOURCE_DIR}/../../../coreclr/pal/prebuilt/idl/cordebug_i.cpp") #SET(CMAKE_C_COMPILER ${CMAKE_CXX_COMPILER}) -set_source_files_properties(${PROJECT_SOURCE_DIR}/../../mono/mini/debugger-protocol.c PROPERTIES LANGUAGE CXX) +set_source_files_properties(${PROJECT_SOURCE_DIR}/../../mono/component/debugger-protocol.c PROPERTIES LANGUAGE CXX) set(COREDBI_LIBRARIES utilcodestaticnohost diff --git a/src/mono/dlls/mscordbi/cordb.h b/src/mono/dlls/mscordbi/cordb.h index f96ef8fc03d17..d81915dc85af3 100644 --- a/src/mono/dlls/mscordbi/cordb.h +++ b/src/mono/dlls/mscordbi/cordb.h @@ -12,7 +12,7 @@ #include "corhdr.h" #include "xcordebug.h" -#include +#include #include #include "arraylist.h" diff --git a/src/mono/mono/component/CMakeLists.txt b/src/mono/mono/component/CMakeLists.txt index f523d14e568dd..62ab5b3452832 100644 --- a/src/mono/mono/component/CMakeLists.txt +++ b/src/mono/mono/component/CMakeLists.txt @@ -6,6 +6,7 @@ set(MONO_EVENTPIPE_GEN_INCLUDE_PATH "${CMAKE_CURRENT_BINARY_DIR}/eventpipe") set(MONO_HOT_RELOAD_COMPONENT_NAME "hot_reload") set(MONO_DIAGNOSTICS_TRACING_COMPONENT_NAME "diagnostics_tracing") +set(MONO_DEBUGGER_COMPONENT_NAME "debugger") # a list of every component. set(components "") @@ -14,6 +15,27 @@ set(components "") # component_name-sources list for each component, and a # component_name-stub-sources list for the component stub. +# debugger +list(APPEND components + ${MONO_DEBUGGER_COMPONENT_NAME} +) +set(${MONO_DEBUGGER_COMPONENT_NAME}-sources + ${MONO_COMPONENT_PATH}/debugger.c + ${MONO_COMPONENT_PATH}/debugger.h + ${MONO_COMPONENT_PATH}/debugger-agent.c + ${MONO_COMPONENT_PATH}/debugger-agent.h + ${MONO_COMPONENT_PATH}/debugger-engine.c + ${MONO_COMPONENT_PATH}/debugger-engine.h + ${MONO_COMPONENT_PATH}/debugger-state-machine.h + ${MONO_COMPONENT_PATH}/debugger-state-machine.c + ${MONO_COMPONENT_PATH}/mini-wasm-debugger.c + ${MONO_COMPONENT_PATH}/debugger-protocol.h + ${MONO_COMPONENT_PATH}/debugger-protocol.c + ) +set(${MONO_DEBUGGER_COMPONENT_NAME}-stub-sources + ${MONO_COMPONENT_PATH}/debugger-stub.c + ) + # hot_reload list(APPEND components ${MONO_HOT_RELOAD_COMPONENT_NAME} diff --git a/src/mono/mono/mini/debugger-agent.c b/src/mono/mono/component/debugger-agent.c similarity index 97% rename from src/mono/mono/mini/debugger-agent.c rename to src/mono/mono/component/debugger-agent.c index f61ffce5d22c0..f72c95392e974 100644 --- a/src/mono/mono/mini/debugger-agent.c +++ b/src/mono/mono/component/debugger-agent.c @@ -78,16 +78,19 @@ #include #include #include -#include "debugger-state-machine.h" + +#include #include "debugger-agent.h" -#include "mini.h" -#include "seq-points.h" -#include "aot-runtime.h" -#include "mini-runtime.h" -#include "interp/interp.h" +#include +#include +#include +#include +#include #include "debugger-engine.h" -#include "mono/metadata/debug-mono-ppdb.h" -#include "mono/metadata/custom-attrs-internals.h" +#include +#include +#include +#include #ifdef HAVE_UCONTEXT_H #include @@ -125,6 +128,47 @@ #pragma warning(disable:4312) // FIXME pointer cast to different size #endif +#define GENERATE_TRY_GET_CLASS_WITH_CACHE_DBG(shortname,name_space,name) \ +MonoClass* \ +mono_class_try_get_##shortname##_class (void) \ +{ \ + static volatile MonoClass *tmp_class; \ + static volatile gboolean inited; \ + MonoClass *klass = (MonoClass *)tmp_class; \ + mono_memory_barrier (); \ + if (!inited) { \ + klass = mono_class_try_load_from_name (mdbg_mono_defaults->corlib, name_space, name); \ + tmp_class = klass; \ + mono_memory_barrier (); \ + inited = TRUE; \ + } \ + return klass; \ +} + +#ifndef MONO_HANDLE_TRACK_OWNER + +#define MONO_HANDLE_NEW_DBG(type, object) \ + (MONO_HANDLE_CAST_FOR (type) (mono_handle_new (MONO_HANDLE_TYPECHECK_FOR (type) (object), mono_thread_info_current ()))) + +#else + +#define MONO_HANDLE_NEW_DBG(type, object) \ + (MONO_HANDLE_CAST_FOR (type) (mono_handle_new (MONO_HANDLE_TYPECHECK_FOR (type) (object), mono_thread_info_current (), HANDLE_OWNER))) + +#endif + +static inline MonoType* +mono_get_object_type_dbg (void) +{ + return m_class_get_byval_arg (mdbg_mono_defaults->object_class); +} + +static inline MonoType* +mono_get_void_type_dbg (void) +{ + return m_class_get_byval_arg (mdbg_mono_defaults->void_class); +} + typedef struct { gboolean enabled; char *transport; @@ -367,6 +411,7 @@ 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) \ @@ -395,7 +440,6 @@ static gboolean buffer_replies; static void transport_init (void); static void transport_connect (const char *address); static gboolean transport_handshake (void); -static void register_transport (DebuggerTransport *trans); static gsize WINAPI debugger_thread (void *arg); @@ -475,8 +519,11 @@ static gboolean ensure_jit (DbgEngineStackFrame* the_frame); static int ensure_runtime_is_suspended (void); static int handle_multiple_ss_requests (void); -static GENERATE_TRY_GET_CLASS_WITH_CACHE (fixed_buffer, "System.Runtime.CompilerServices", "FixedBufferAttribute") +/* Callbacks used by wasm debugger */ +static void mono_dbg_debugger_agent_user_break (void); + +static GENERATE_TRY_GET_CLASS_WITH_CACHE_DBG (fixed_buffer, "System.Runtime.CompilerServices", "FixedBufferAttribute") #ifndef DISABLE_SOCKET_TRANSPORT static void @@ -550,6 +597,8 @@ parse_flag (const char *option, char *flag) static void debugger_agent_parse_options (char *options) { + if (!options) + return; char **args, **ptr; char *host; int port; @@ -686,11 +735,13 @@ mono_debugger_is_disconnected (void) } static void -debugger_agent_init (void) +debugger_agent_init (MonoDefaults *mono_defaults) { 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; @@ -701,13 +752,6 @@ debugger_agent_init (void) cbs.ss_calculate_framecount = mono_ss_calculate_framecount; cbs.ensure_jit = ensure_jit; cbs.ensure_runtime_is_suspended = ensure_runtime_is_suspended; - cbs.get_this_async_id = mono_get_this_async_id; - cbs.set_set_notification_for_wait_completion_flag = set_set_notification_for_wait_completion_flag; - cbs.get_notify_debugger_of_wait_completion_method = get_notify_debugger_of_wait_completion_method; - cbs.create_breakpoint_events = mono_dbg_create_breakpoint_events; - cbs.process_breakpoint_events = mono_dbg_process_breakpoint_events; - cbs.ss_create_init_args = mono_ss_create_init_args; - cbs.ss_args_destroy = mono_ss_args_destroy; cbs.handle_multiple_ss_requests = handle_multiple_ss_requests; mono_de_init (&cbs); @@ -735,7 +779,7 @@ debugger_agent_init (void) mono_profiler_set_jit_failed_callback (prof, jit_failed); mono_profiler_set_gc_finalizing_callback (prof, gc_finalizing); mono_profiler_set_gc_finalized_callback (prof, gc_finalized); - + mono_native_tls_alloc (&debugger_tls_id, NULL); /* Needed by the hash_table_new_type () call below */ @@ -1217,7 +1261,7 @@ register_socket_transport (void) trans.send = socket_transport_send; trans.recv = socket_transport_recv; - register_transport (&trans); + mono_debugger_agent_register_transport (&trans); } /* @@ -1258,7 +1302,7 @@ register_socket_fd_transport (void) trans.send = socket_transport_send; trans.recv = socket_transport_recv; - register_transport (&trans); + mono_debugger_agent_register_transport (&trans); } #endif /* DISABLE_SOCKET_TRANSPORT */ @@ -1267,27 +1311,9 @@ register_socket_fd_transport (void) * TRANSPORT CODE */ -#define MAX_TRANSPORTS 16 -static DebuggerTransport *transport; - -static DebuggerTransport transports [MAX_TRANSPORTS]; -static int ntransports; -void -mono_debugger_agent_register_transport (DebuggerTransport *trans) -{ - register_transport (trans); -} - -static void -register_transport (DebuggerTransport *trans) -{ - g_assert (ntransports < MAX_TRANSPORTS); - - memcpy (&transports [ntransports], trans, sizeof (DebuggerTransport)); - ntransports ++; -} +static DebuggerTransport *transport; static void transport_init (void) @@ -1298,6 +1324,8 @@ transport_init (void) register_socket_transport (); register_socket_fd_transport (); #endif + int ntransports = 0; + DebuggerTransport *transports = mono_debugger_agent_get_transports (&ntransports); for (i = 0; i < ntransports; ++i) { if (!strcmp (agent_config.transport, transports [i].name)) @@ -1357,8 +1385,8 @@ transport_recv (void *buf, int len) return result; } -gboolean -mono_debugger_agent_transport_handshake (void) +static gboolean +debugger_agent_transport_handshake (void) { gboolean result; MONO_ENTER_GC_UNSAFE; @@ -1575,16 +1603,20 @@ static GHashTable *obj_to_objref; static MonoGHashTable *suspended_objs; #ifdef TARGET_WASM -void mono_init_debugger_agent_for_wasm (int log_level_parm) +void +mono_init_debugger_agent_for_wasm (int log_level_parm) { if (mono_atomic_cas_i32 (&agent_inited, 1, 0) == 1) return; + int ntransports = 0; + DebuggerTransport *transports = mono_debugger_agent_get_transports (&ntransports); + ids_init(); objrefs = g_hash_table_new_full (NULL, NULL, NULL, mono_debugger_free_objref); obj_to_objref = g_hash_table_new (NULL, NULL); - log_level = log_level; + log_level = log_level_parm; event_requests = g_ptr_array_new (); vm_start_event_sent = TRUE; transport = &transports [0]; @@ -2148,11 +2180,11 @@ get_top_method_ji (gpointer ip, MonoDomain **domain, gpointer *out_ip) g_assert (ext->kind == MONO_LMFEXT_INTERP_EXIT || ext->kind == MONO_LMFEXT_INTERP_EXIT_WITH_CTX); frame = (MonoInterpFrameHandle*)ext->interp_exit_data; - ji = mini_get_interp_callbacks ()->frame_get_jit_info (frame); + ji = mini_get_interp_callbacks_api ()->frame_get_jit_info (frame); if (domain) *domain = mono_domain_get (); if (out_ip) - *out_ip = mini_get_interp_callbacks ()->frame_get_ip (frame); + *out_ip = mini_get_interp_callbacks_api ()->frame_get_ip (frame); } return ji; } @@ -2454,7 +2486,7 @@ process_suspend (DebuggerTlsData *tls, MonoContext *ctx) g_assert (ji); /* Can't suspend in these methods */ method = jinfo_get_method (ji); - if (method->klass == mono_defaults.string_class && (!strcmp (method->name, "memset") || strstr (method->name, "memcpy"))) + if (method->klass == mdbg_mono_defaults->string_class && (!strcmp (method->name, "memset") || strstr (method->name, "memcpy"))) return; save_thread_context (ctx); @@ -2911,7 +2943,7 @@ static gint32 isFixedSizeArray (MonoClassField *f) CattrNamedArg *arginfo; int num_named_args; - mono_reflection_create_custom_attr_data_args_noalloc (mono_defaults.corlib, attr->ctor, attr->data, attr->data_size, + mono_reflection_create_custom_attr_data_args_noalloc (mdbg_mono_defaults->corlib, attr->ctor, attr->data, attr->data_size, &typed_args, &named_args, &num_named_args, &arginfo, error); if (!is_ok (error)) { ret = 0; @@ -3072,7 +3104,7 @@ compute_frame_info (MonoInternalThread *thread, DebuggerTlsData *tls, gboolean f gboolean has_interp_resume_state = FALSE; MonoInterpFrameHandle interp_resume_frame = NULL; gpointer interp_resume_ip = 0; - mini_get_interp_callbacks ()->get_resume_state (jit_data, &has_interp_resume_state, &interp_resume_frame, &interp_resume_ip); + mini_get_interp_callbacks_api ()->get_resume_state (jit_data, &has_interp_resume_state, &interp_resume_frame, &interp_resume_ip); if (has_interp_resume_state && tls->frame_count > 0) { StackFrame *top_frame = tls->frames [0]; if (interp_resume_frame == top_frame->interp_frame) { @@ -3206,9 +3238,9 @@ dbg_path_get_basename (const char *filename) return g_strdup (&r[1]); } -static GENERATE_TRY_GET_CLASS_WITH_CACHE(hidden_klass, "System.Diagnostics", "DebuggerHiddenAttribute") -static GENERATE_TRY_GET_CLASS_WITH_CACHE(step_through_klass, "System.Diagnostics", "DebuggerStepThroughAttribute") -static GENERATE_TRY_GET_CLASS_WITH_CACHE(non_user_klass, "System.Diagnostics", "DebuggerNonUserCodeAttribute") +static GENERATE_TRY_GET_CLASS_WITH_CACHE_DBG (hidden_klass, "System.Diagnostics", "DebuggerHiddenAttribute") +static GENERATE_TRY_GET_CLASS_WITH_CACHE_DBG (step_through_klass, "System.Diagnostics", "DebuggerStepThroughAttribute") +static GENERATE_TRY_GET_CLASS_WITH_CACHE_DBG (non_user_klass, "System.Diagnostics", "DebuggerNonUserCodeAttribute") static void init_jit_info_dbg_attrs (MonoJitInfo *ji) @@ -3721,7 +3753,7 @@ runtime_initialized (MonoProfiler *prof) { process_profiler_event (EVENT_KIND_VM_START, mono_thread_current ()); if (CHECK_PROTOCOL_VERSION (2, 59)) - process_profiler_event (EVENT_KIND_ASSEMBLY_LOAD, (mono_defaults.corlib->assembly)); + process_profiler_event (EVENT_KIND_ASSEMBLY_LOAD, (mdbg_mono_defaults->corlib->assembly)); if (agent_config.defer) { ERROR_DECL (error); start_debugger_thread (error); @@ -4130,7 +4162,7 @@ breakpoint_matches_assembly (MonoBreakpoint *bp, MonoAssembly *assembly) //This ID is used to figure out if breakpoint hit on resumeOffset belongs to us or not //since thread probably changed... int -mono_get_this_async_id (DbgEngineStackFrame *frame) +mono_de_frame_async_id (DbgEngineStackFrame *frame) { MonoClassField *builder_field; gpointer builder; @@ -4326,7 +4358,7 @@ user_break_cb (StackFrameInfo *frame, MonoContext *ctx, gpointer user_data) /* * Called by System.Diagnostics.Debugger:Break (). */ -void +static void mono_dbg_debugger_agent_user_break (void) { if (agent_config.enabled) { @@ -4348,7 +4380,7 @@ mono_dbg_debugger_agent_user_break (void) mono_loader_unlock (); process_event (EVENT_KIND_USER_BREAK, NULL, 0, &ctx, events, suspend_policy); - } else if (mini_debug_options.native_debugger_break) { + } else if (get_mini_debug_options ()->native_debugger_break) { G_BREAKPOINT (); } } @@ -4759,11 +4791,11 @@ debugger_agent_unhandled_exception (MonoException *exc) process_event (EVENT_KIND_EXCEPTION, &ei, 0, NULL, events, suspend_policy); } -void -mono_debugger_agent_handle_exception (MonoException *exc, MonoContext *throw_ctx, +static void +debugger_agent_handle_exception (MonoException *exc, MonoContext *throw_ctx, MonoContext *catch_ctx, StackFrameInfo *catch_frame) { - if (catch_ctx == NULL && catch_frame == NULL && mini_debug_options.suspend_on_unhandled && mono_object_class (exc) != mono_defaults.threadabortexception_class) { + if (catch_ctx == NULL && catch_frame == NULL && get_mini_debug_options ()->suspend_on_unhandled && mono_object_class (exc) != mdbg_mono_defaults->threadabortexception_class) { mono_runtime_printf_err ("Unhandled exception, suspending..."); while (1) ; @@ -6142,7 +6174,7 @@ mono_do_invoke_method (DebuggerTlsData *tls, Buffer *buf, InvokeData *invoke, gu PRINT_DEBUG_MSG (1, "[%p] Invoke result: %p, exc: %s, time: %ld ms.\n", (gpointer) (gsize) mono_native_thread_id_get (), res, exc ? m_class_get_name (exc->vtable->klass) : NULL, (long)mono_stopwatch_elapsed_ms (&watch)); if (exc) { buffer_add_byte (buf, 0); - buffer_add_value (buf, mono_get_object_type (), &exc, domain); + buffer_add_value (buf, mono_get_object_type_dbg (), &exc, domain); } else { gboolean out_this = FALSE; gboolean out_args = FALSE; @@ -6157,11 +6189,11 @@ mono_do_invoke_method (DebuggerTlsData *tls, Buffer *buf, InvokeData *invoke, gu } else if (sig->ret->type == MONO_TYPE_VOID && !m->string_ctor) { if (!strcmp (m->name, ".ctor")) { if (!m_class_is_valuetype (m->klass)) - buffer_add_value (buf, mono_get_object_type (), &this_arg, domain); + buffer_add_value (buf, mono_get_object_type_dbg (), &this_arg, domain); else buffer_add_value (buf, m_class_get_byval_arg (m->klass), this_buf, domain); } else { - buffer_add_value (buf, mono_get_void_type (), NULL, domain); + buffer_add_value (buf, mono_get_void_type_dbg (), NULL, domain); } } else if (MONO_TYPE_IS_REFERENCE (sig->ret)) { if (sig->ret->byref) { @@ -6503,7 +6535,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 == mono_defaults.runtimetype_class) { + if (val && val->vtable->klass == mdbg_mono_defaults->runtimetype_class) { /* Special case these so the client doesn't have to handle Type objects */ buffer_add_byte (buf, VALUE_TYPE_ID_TYPE); @@ -6544,9 +6576,9 @@ buffer_add_cattrs (Buffer *buf, MonoDomain *domain, MonoImage *image, MonoClass ERROR_DECL (error); SETUP_ICALL_FRAME; - typed_args_h = MONO_HANDLE_NEW (MonoArray, NULL); - named_args_h = MONO_HANDLE_NEW (MonoArray, NULL); - val_h = MONO_HANDLE_NEW (MonoObject, NULL); + typed_args_h = MONO_HANDLE_NEW_DBG (MonoArray, NULL); + named_args_h = MONO_HANDLE_NEW_DBG (MonoArray, NULL); + val_h = MONO_HANDLE_NEW_DBG (MonoObject, NULL); mono_reflection_create_custom_attr_data_args (image, attr->ctor, attr->data, attr->data_size, typed_args_h, named_args_h, &arginfo, error); if (!is_ok (error)) { @@ -6708,7 +6740,7 @@ vm_commands (int command, int id, guint8 *p, guint8 *end, Buffer *buf) wait_for_suspend (); #ifdef TRY_MANAGED_SYSTEM_ENVIRONMENT_EXIT - env_class = mono_class_try_load_from_name (mono_defaults.corlib, "System", "Environment"); + env_class = mono_class_try_load_from_name (mdbg_mono_defaults->corlib, "System", "Environment"); if (env_class) { ERROR_DECL (error); exit_method = mono_class_get_method_from_name_checked (env_class, "Exit", 1, 0, error); @@ -7089,7 +7121,7 @@ event_commands (int command, guint8 *p, guint8 *end, Buffer *buf) if (exc_class) { req->modifiers [i].data.exc_class = exc_class; - if (!mono_class_is_assignable_from_internal (mono_defaults.exception_class, exc_class)) { + if (!mono_class_is_assignable_from_internal (mdbg_mono_defaults->exception_class, exc_class)) { g_free (req); return ERR_INVALID_ARGUMENT; } @@ -7750,7 +7782,7 @@ collect_interfaces (MonoClass *klass, GHashTable *ifaces, MonoError *error) static int get_static_field_value(MonoClassField* f, MonoClass* klass, MonoDomain* domain, MonoInternalThread* thread, Buffer* buf) { - MonoStringHandle string_handle = MONO_HANDLE_NEW(MonoString, NULL); // FIXME? Not always needed. + MonoStringHandle string_handle = MONO_HANDLE_NEW_DBG (MonoString, NULL); // FIXME? Not always needed. ERROR_DECL(error); guint8* val; MonoVTable* vtable; @@ -8692,19 +8724,19 @@ 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 == mono_defaults.typehandle_class) { + if (handle_class == mdbg_mono_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 == mono_defaults.fieldhandle_class) { + } else if (handle_class == mdbg_mono_defaults->fieldhandle_class) { buffer_add_byte (buf, TOKEN_TYPE_FIELD); buffer_add_fieldid (buf, domain, (MonoClassField *)val); - } else if (handle_class == mono_defaults.methodhandle_class) { + } else if (handle_class == mdbg_mono_defaults->methodhandle_class) { buffer_add_byte (buf, TOKEN_TYPE_METHOD); buffer_add_methodid (buf, domain, (MonoMethod *)val); - } else if (handle_class == mono_defaults.string_class) { + } else if (handle_class == mdbg_mono_defaults->string_class) { char *s; s = mono_string_to_utf8_checked_internal ((MonoString *)val, error); @@ -9003,7 +9035,7 @@ thread_commands (int command, guint8 *p, guint8 *end, Buffer *buf) if (tls->frames [0]->de.ji->is_interp) { MonoJitTlsData *jit_data = thread->thread_info->jit_data; - mini_get_interp_callbacks ()->set_resume_state (jit_data, NULL, NULL, tls->frames [0]->interp_frame, (guint8*)tls->frames [0]->de.ji->code_start + sp.native_offset); + mini_get_interp_callbacks_api ()->set_resume_state (jit_data, NULL, NULL, tls->frames [0]->interp_frame, (guint8*)tls->frames [0]->de.ji->code_start + sp.native_offset); } else { MONO_CONTEXT_SET_IP (&tls->restore_state.ctx, (guint8*)tls->frames [0]->de.ji->code_start + sp.native_offset); } @@ -9045,12 +9077,12 @@ cmd_stack_frame_get_this (StackFrame *frame, MonoMethodSignature *sig, Buffer *b if (m_class_is_valuetype (frame->api_method->klass)) { if (!sig->hasthis) { MonoObject *p = NULL; - buffer_add_value (buf, mono_get_object_type (), &p, frame->de.domain); + buffer_add_value (buf, mono_get_object_type_dbg (), &p, frame->de.domain); } else { if (frame->de.ji->is_interp) { guint8 *addr; - addr = (guint8*)mini_get_interp_callbacks ()->frame_get_this (frame->interp_frame); + addr = (guint8*)mini_get_interp_callbacks_api ()->frame_get_this (frame->interp_frame); buffer_add_value_full (buf, m_class_get_this_arg (frame->actual_method->klass), addr, frame->de.domain, FALSE, NULL, 1); } else { @@ -9065,7 +9097,7 @@ cmd_stack_frame_get_this (StackFrame *frame, MonoMethodSignature *sig, Buffer *b if (frame->de.ji->is_interp) { guint8 *addr; - addr = (guint8*)mini_get_interp_callbacks ()->frame_get_this (frame->interp_frame); + addr = (guint8*)mini_get_interp_callbacks_api ()->frame_get_this (frame->interp_frame); buffer_add_value_full (buf, m_class_get_byval_arg (frame->api_method->klass), addr, frame->de.domain, FALSE, NULL, 1); } else { @@ -9082,7 +9114,7 @@ cmd_stack_frame_get_parameter (StackFrame *frame, MonoMethodSignature *sig, int if (frame->de.ji->is_interp) { guint8 *addr; - addr = (guint8*)mini_get_interp_callbacks ()->frame_get_arg (frame->interp_frame, pos); + addr = (guint8*)mini_get_interp_callbacks_api ()->frame_get_arg (frame->interp_frame, pos); buffer_add_value_full (buf, sig->params [pos], addr, frame->de.domain, FALSE, NULL, 1); } else { @@ -9205,7 +9237,7 @@ frame_commands (int command, guint8 *p, guint8 *end, Buffer *buf) if (frame->de.ji->is_interp) { guint8 *addr; - addr = (guint8*)mini_get_interp_callbacks ()->frame_get_local (frame->interp_frame, pos); + addr = (guint8*)mini_get_interp_callbacks_api ()->frame_get_local (frame->interp_frame, pos); buffer_add_value_full (buf, header->locals [pos], addr, frame->de.domain, FALSE, NULL, 1); } else { @@ -9271,9 +9303,9 @@ frame_commands (int command, guint8 *p, guint8 *end, Buffer *buf) guint8 *addr; if (is_arg) - addr = (guint8*)mini_get_interp_callbacks ()->frame_get_arg (frame->interp_frame, pos); + addr = (guint8*)mini_get_interp_callbacks_api ()->frame_get_arg (frame->interp_frame, pos); else - addr = (guint8*)mini_get_interp_callbacks ()->frame_get_local (frame->interp_frame, pos); + addr = (guint8*)mini_get_interp_callbacks_api ()->frame_get_local (frame->interp_frame, pos); err = mono_de_set_interp_var (t, addr, val_buf); if (err != ERR_NONE) return err; @@ -9306,7 +9338,7 @@ frame_commands (int command, guint8 *p, guint8 *end, Buffer *buf) if (frame->de.ji->is_interp) { guint8 *addr; - addr = (guint8*)mini_get_interp_callbacks ()->frame_get_this (frame->interp_frame); + addr = (guint8*)mini_get_interp_callbacks_api ()->frame_get_this (frame->interp_frame); err = mono_de_set_interp_var (m_class_get_this_arg (frame->actual_method->klass), addr, val_buf); if (err != ERR_NONE) return err; @@ -9548,7 +9580,7 @@ object_commands (int command, guint8 *p, guint8 *end, Buffer *buf) MonoClassField *f = NULL; MonoClass *k; gboolean found; - MonoStringHandle string_handle = MONO_HANDLE_NEW (MonoString, NULL); // FIXME? Not always needed. + MonoStringHandle string_handle = MONO_HANDLE_NEW_DBG (MonoString, NULL); // FIXME? Not always needed. if (command == CMD_OBJECT_REF_IS_COLLECTED) { objid = decode_objid (p, &p, end); @@ -10226,36 +10258,28 @@ debugger_thread (void *arg) return 0; } -void -mono_debugger_agent_init (void) -{ - MonoDebuggerCallbacks cbs; - - memset (&cbs, 0, sizeof (cbs)); - cbs.version = MONO_DBG_CALLBACKS_VERSION; - cbs.parse_options = debugger_agent_parse_options; - cbs.init = debugger_agent_init; - cbs.breakpoint_hit = debugger_agent_breakpoint_hit; - cbs.single_step_event = debugger_agent_single_step_event; - cbs.single_step_from_context = debugger_agent_single_step_from_context; - cbs.breakpoint_from_context = debugger_agent_breakpoint_from_context; - cbs.free_mem_manager = debugger_agent_free_mem_manager; - cbs.unhandled_exception = debugger_agent_unhandled_exception; - cbs.handle_exception = mono_debugger_agent_handle_exception; - cbs.begin_exception_filter = debugger_agent_begin_exception_filter; - cbs.end_exception_filter = debugger_agent_end_exception_filter; - cbs.user_break = mono_dbg_debugger_agent_user_break; - cbs.debug_log = debugger_agent_debug_log; - cbs.debug_log_is_enabled = debugger_agent_debug_log_is_enabled; - cbs.send_crash = mono_debugger_agent_send_crash; - - mini_install_dbg_callbacks (&cbs); -} void -mono_debugger_agent_parse_options (char *options) -{ - sdb_options = options; +debugger_agent_add_function_pointers(MonoComponentDebugger* fn_table) +{ + fn_table->parse_options = debugger_agent_parse_options; + fn_table->init = debugger_agent_init; + fn_table->breakpoint_hit = debugger_agent_breakpoint_hit; + fn_table->single_step_event = debugger_agent_single_step_event; + fn_table->single_step_from_context = debugger_agent_single_step_from_context; + fn_table->breakpoint_from_context = debugger_agent_breakpoint_from_context; + fn_table->free_mem_manager = debugger_agent_free_mem_manager; + fn_table->unhandled_exception = debugger_agent_unhandled_exception; + fn_table->handle_exception = debugger_agent_handle_exception; + fn_table->begin_exception_filter = debugger_agent_begin_exception_filter; + fn_table->end_exception_filter = debugger_agent_end_exception_filter; + fn_table->user_break = mono_dbg_debugger_agent_user_break; + fn_table->debug_log = debugger_agent_debug_log; + fn_table->debug_log_is_enabled = debugger_agent_debug_log_is_enabled; + fn_table->send_crash = mono_debugger_agent_send_crash; + fn_table->transport_handshake = debugger_agent_transport_handshake; } + + #endif /* DISABLE_SDB */ diff --git a/src/mono/mono/component/debugger-agent.h b/src/mono/mono/component/debugger-agent.h new file mode 100644 index 0000000000000..60f4244820247 --- /dev/null +++ b/src/mono/mono/component/debugger-agent.h @@ -0,0 +1,56 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// + +#ifndef __MONO_DEBUGGER_AGENT_COMPONENT_H__ +#define __MONO_DEBUGGER_AGENT_COMPONENT_H__ + +#include +#include "debugger.h" +#include + +void +debugger_agent_add_function_pointers (MonoComponentDebugger* fn_table); + +void +mono_ss_calculate_framecount (void *the_tls, MonoContext *ctx, gboolean force_use_ctx, DbgEngineStackFrame ***frames, int *nframes); + +void +mono_ss_discard_frame_context (void *the_tls); + +#ifdef TARGET_WASM +DebuggerTlsData* +mono_wasm_get_tls (void); + +void +mono_init_debugger_agent_for_wasm (int log_level); + +void +mono_wasm_save_thread_context (void); + +#endif + +void +mini_wasm_debugger_add_function_pointers (MonoComponentDebugger* fn_table); + +MdbgProtErrorCode +mono_do_invoke_method (DebuggerTlsData *tls, MdbgProtBuffer *buf, InvokeData *invoke, guint8 *p, guint8 **endp); + +MdbgProtErrorCode +mono_process_dbg_packet (int id, MdbgProtCommandSet command_set, int command, gboolean *no_reply, guint8 *p, guint8 *end, MdbgProtBuffer *buf); + +void +mono_dbg_process_breakpoint_events (void *_evts, MonoMethod *method, MonoContext *ctx, int il_offset); + +void* +mono_dbg_create_breakpoint_events (GPtrArray *ss_reqs, GPtrArray *bp_reqs, MonoJitInfo *ji, MdbgProtEventKind kind); + +int +mono_ss_create_init_args (SingleStepReq *ss_req, SingleStepArgs *args); + +void +mono_ss_args_destroy (SingleStepArgs *ss_args); + +int +mono_de_frame_async_id (DbgEngineStackFrame *frame); +#endif diff --git a/src/mono/mono/mini/debugger-engine.c b/src/mono/mono/component/debugger-engine.c similarity index 95% rename from src/mono/mono/mini/debugger-engine.c rename to src/mono/mono/component/debugger-engine.c index 8c85227e8420c..7310283357178 100644 --- a/src/mono/mono/mini/debugger-engine.c +++ b/src/mono/mono/component/debugger-engine.c @@ -10,13 +10,13 @@ */ #include -#include "mini-runtime.h" +#include #if !defined (DISABLE_SDB) || defined(TARGET_WASM) #include -#include "seq-points.h" -#include "aot-runtime.h" +#include +#include #include "debugger-engine.h" #include "debugger-state-machine.h" #include @@ -24,6 +24,8 @@ static void mono_de_ss_start (SingleStepReq *ss_req, SingleStepArgs *ss_args); static gboolean mono_de_ss_update (SingleStepReq *req, MonoJitInfo *ji, SeqPoint *sp, void *tls, MonoContext *ctx, MonoMethod* method); +static gpointer get_this_addr(DbgEngineStackFrame* the_frame); +static MonoMethod* get_set_notification_method(MonoClass* async_builder_class); static DebuggerEngineCallbacks rt_callbacks; @@ -89,17 +91,6 @@ mono_de_foreach_domain (GHFunc func, gpointer user_data) g_hash_table_foreach (domains, func, user_data); } -/* - * LOCKING: Takes the loader lock - */ -void -mono_de_domain_remove (MonoDomain *domain) -{ - mono_loader_lock (); - g_hash_table_remove (domains, domain); - mono_loader_unlock (); -} - /* * LOCKING: Takes the loader lock */ @@ -210,7 +201,7 @@ insert_breakpoint (MonoSeqPointInfo *seq_points, MonoDomain *domain, MonoJitInfo PRINT_DEBUG_MSG (1, "[dbg] Attempting to insert seq point at dead IL offset %d, ignoring.\n", (int)bp->il_offset); } else if (count == 0) { if (ji->is_interp) { - mini_get_interp_callbacks ()->set_breakpoint (ji, inst->ip); + mini_get_interp_callbacks_api ()->set_breakpoint (ji, inst->ip); } else { #ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED mono_arch_set_breakpoint (ji, inst->ip); @@ -239,7 +230,7 @@ remove_breakpoint (BreakpointInstance *inst) if (count == 1 && inst->native_offset != SEQ_POINT_NATIVE_OFFSET_DEAD_CODE) { if (ji->is_interp) { - mini_get_interp_callbacks ()->clear_breakpoint (ji, ip); + mini_get_interp_callbacks_api ()->clear_breakpoint (ji, ip); } else { #ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED mono_arch_clear_breakpoint (ji, ip); @@ -464,17 +455,6 @@ mono_de_set_breakpoint (MonoMethod *method, long il_offset, EventRequest *req, M return bp; } -MonoBreakpoint * -mono_de_get_breakpoint_by_id (int id) -{ - for (int i = 0; i < breakpoints->len; ++i) { - MonoBreakpoint *bp = (MonoBreakpoint *)g_ptr_array_index (breakpoints, i); - if (bp->req->id == id) - return bp; - } - return NULL; -} - void mono_de_clear_breakpoint (MonoBreakpoint *bp) { @@ -617,7 +597,7 @@ mono_de_start_single_stepping (void) #ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED mono_arch_start_single_stepping (); #endif - mini_get_interp_callbacks ()->start_single_stepping (); + mini_get_interp_callbacks_api ()->start_single_stepping (); } } @@ -630,7 +610,7 @@ mono_de_stop_single_stepping (void) #ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED mono_arch_stop_single_stepping (); #endif - mini_get_interp_callbacks ()->stop_single_stepping (); + mini_get_interp_callbacks_api ()->stop_single_stepping (); } } @@ -656,11 +636,11 @@ get_top_method_ji (gpointer ip, MonoDomain **domain, gpointer *out_ip) g_assert (ext->kind == MONO_LMFEXT_INTERP_EXIT || ext->kind == MONO_LMFEXT_INTERP_EXIT_WITH_CTX); frame = (MonoInterpFrameHandle*)ext->interp_exit_data; - ji = mini_get_interp_callbacks ()->frame_get_jit_info (frame); + ji = mini_get_interp_callbacks_api ()->frame_get_jit_info (frame); if (domain) *domain = mono_domain_get (); if (out_ip) - *out_ip = mini_get_interp_callbacks ()->frame_get_ip (frame); + *out_ip = mini_get_interp_callbacks_api ()->frame_get_ip (frame); } return ji; } @@ -775,7 +755,7 @@ mono_de_cancel_ss (SingleStepReq *req) } void -mono_de_cancel_all_ss () +mono_de_cancel_all_ss (void) { int i; for (i = 0; i < the_ss_reqs->len; ++i) { @@ -832,7 +812,7 @@ mono_de_process_single_step (void *tls, gboolean from_signal) * Stopping in memset makes half-initialized vtypes visible. * Stopping in memcpy makes half-copied vtypes visible. */ - if (method->klass == mono_defaults.string_class && (!strcmp (method->name, "memset") || strstr (method->name, "memcpy"))) + if (method->klass == mdbg_mono_defaults->string_class && (!strcmp (method->name, "memset") || strstr (method->name, "memcpy"))) goto exit; /* @@ -892,13 +872,13 @@ mono_de_process_single_step (void *tls, gboolean from_signal) g_ptr_array_add (reqs, ss_req->req); void *bp_events; - bp_events = rt_callbacks.create_breakpoint_events (reqs, NULL, ji, EVENT_KIND_BREAKPOINT); + bp_events = mono_dbg_create_breakpoint_events (reqs, NULL, ji, EVENT_KIND_BREAKPOINT); g_ptr_array_free (reqs, TRUE); mono_loader_unlock (); - rt_callbacks.process_breakpoint_events (bp_events, method, ctx, il_offset); + mono_dbg_process_breakpoint_events (bp_events, method, ctx, il_offset); exit: mono_de_ss_req_release (ss_req); @@ -1123,7 +1103,7 @@ mono_de_process_breakpoint (void *void_tls, gboolean from_signal) mono_debug_free_method_async_debug_info (asyncMethod); //breakpoint was hit in parallelly executing async method, ignore it - if (ss_req->async_id != rt_callbacks.get_this_async_id (frames [0])) + if (ss_req->async_id != mono_de_frame_async_id (frames [0])) continue; } @@ -1154,14 +1134,14 @@ mono_de_process_breakpoint (void *void_tls, gboolean from_signal) mono_de_ss_start (ss_req, &args); } - void *bp_events = rt_callbacks.create_breakpoint_events (ss_reqs, bp_reqs, ji, kind); + void *bp_events = mono_dbg_create_breakpoint_events (ss_reqs, bp_reqs, ji, kind); mono_loader_unlock (); g_ptr_array_free (bp_reqs, TRUE); g_ptr_array_free (ss_reqs, TRUE); - rt_callbacks.process_breakpoint_events (bp_events, method, ctx, sp.il_offset); + mono_dbg_process_breakpoint_events (bp_events, method, ctx, sp.il_offset); } /* @@ -1352,7 +1332,7 @@ mono_de_ss_start (SingleStepReq *ss_req, SingleStepArgs *ss_args) // of this await call and sets async_id so we can distinguish it from parallel executions for (i = 0; i < asyncMethod->num_awaits; i++) { if (sp->il_offset == asyncMethod->yield_offsets [i]) { - ss_req->async_id = rt_callbacks.get_this_async_id (frames [0]); + ss_req->async_id = mono_de_frame_async_id (frames [0]); ss_bp_add_one (ss_req, &ss_req_bp_count, &ss_req_bp_cache, method, asyncMethod->resume_offsets [i]); g_hash_table_destroy (ss_req_bp_cache); mono_debug_free_method_async_debug_info (asyncMethod); @@ -1368,9 +1348,9 @@ mono_de_ss_start (SingleStepReq *ss_req, SingleStepArgs *ss_args) } if (ss_req->depth == STEP_DEPTH_OUT) { //If we are inside `async void` method, do normal step-out - if (rt_callbacks.set_set_notification_for_wait_completion_flag (frames [0])) { - ss_req->async_id = rt_callbacks.get_this_async_id (frames [0]); - ss_req->async_stepout_method = rt_callbacks.get_notify_debugger_of_wait_completion_method (); + if (set_set_notification_for_wait_completion_flag (frames [0])) { + ss_req->async_id = mono_de_frame_async_id (frames [0]); + ss_req->async_stepout_method = get_notify_debugger_of_wait_completion_method (); ss_bp_add_one (ss_req, &ss_req_bp_count, &ss_req_bp_cache, ss_req->async_stepout_method, 0); g_hash_table_destroy (ss_req_bp_cache); mono_debug_free_method_async_debug_info (asyncMethod); @@ -1499,7 +1479,7 @@ mono_de_ss_start (SingleStepReq *ss_req, SingleStepArgs *ss_args) mono_loader_unlock (); cleanup: - rt_callbacks.ss_args_destroy (ss_args); + mono_ss_args_destroy (ss_args); } @@ -1542,7 +1522,7 @@ mono_de_ss_create (MonoInternalThread *thread, StepSize size, StepDepth depth, S } SingleStepArgs args; - err = rt_callbacks.ss_create_init_args (ss_req, &args); + err = mono_ss_create_init_args (ss_req, &args); if (err) return err; g_ptr_array_add (the_ss_reqs, ss_req); @@ -1671,12 +1651,12 @@ get_object_id_for_debugger_method (MonoClass* async_builder_class) return method; } -gpointer +static gpointer get_this_addr (DbgEngineStackFrame *the_frame) { StackFrame *frame = (StackFrame *)the_frame; if (frame->de.ji->is_interp) - return mini_get_interp_callbacks ()->frame_get_this (frame->interp_frame); + return mini_get_interp_callbacks_api ()->frame_get_this (frame->interp_frame); MonoDebugVarInfo *var = frame->jit->this_var; if ((var->index & MONO_DEBUG_VAR_ADDRESS_MODE_FLAGS) != MONO_DEBUG_VAR_ADDRESS_MODE_REGOFFSET) @@ -1716,7 +1696,7 @@ get_async_method_builder (DbgEngineStackFrame *frame) return builder; } -MonoMethod* +static MonoMethod* get_set_notification_method (MonoClass* async_builder_class) { ERROR_DECL (error); @@ -1739,7 +1719,7 @@ get_notify_debugger_of_wait_completion_method (void) if (notify_debugger_of_wait_completion_method_cache != NULL) return notify_debugger_of_wait_completion_method_cache; ERROR_DECL (error); - MonoClass* task_class = mono_class_load_from_name (mono_defaults.corlib, "System.Threading.Tasks", "Task"); + MonoClass* task_class = mono_class_load_from_name (mdbg_mono_defaults->corlib, "System.Threading.Tasks", "Task"); GPtrArray* array = mono_class_get_methods_by_name (task_class, "NotifyDebuggerOfWaitCompletion", 0x24, 1, FALSE, error); mono_error_assert_ok (error); g_assert (array->len == 1); diff --git a/src/mono/mono/mini/debugger-engine.h b/src/mono/mono/component/debugger-engine.h similarity index 78% rename from src/mono/mono/mini/debugger-engine.h rename to src/mono/mono/component/debugger-engine.h index 20fe88fedb8d7..a3c30d6d995cc 100644 --- a/src/mono/mono/mini/debugger-engine.h +++ b/src/mono/mono/component/debugger-engine.h @@ -2,15 +2,15 @@ * \file */ -#ifndef __MONO_DEBUGGER_ENGINE_H__ -#define __MONO_DEBUGGER_ENGINE_H__ +#ifndef __MONO_DEBUGGER_ENGINE_COMPONENT_H__ +#define __MONO_DEBUGGER_ENGINE_COMPONENT_H__ -#include "mini.h" +#include #include -#include +#include "debugger-state-machine.h" #include #include -#include +#include "debugger-protocol.h" #define ModifierKind MdbgProtModifierKind #define StepDepth MdbgProtStepDepth @@ -263,59 +263,6 @@ #define FRAME_FLAG_DEBUGGER_INVOKE MDBGPROT_FRAME_FLAG_DEBUGGER_INVOKE #define FRAME_FLAG_NATIVE_TRANSITION MDBGPROT_FRAME_FLAG_NATIVE_TRANSITION -typedef struct { - ModifierKind kind; - union { - int count; /* For kind == MOD_KIND_COUNT */ - MonoInternalThread *thread; /* For kind == MOD_KIND_THREAD_ONLY */ - MonoClass *exc_class; /* For kind == MONO_KIND_EXCEPTION_ONLY */ - MonoAssembly **assemblies; /* For kind == MONO_KIND_ASSEMBLY_ONLY */ - GHashTable *source_files; /* For kind == MONO_KIND_SOURCE_FILE_ONLY */ - GHashTable *type_names; /* For kind == MONO_KIND_TYPE_NAME_ONLY */ - StepFilter filter; /* For kind == MOD_KIND_STEP */ - } data; - gboolean caught, uncaught, subclasses, not_filtered_feature, everything_else; /* For kind == MOD_KIND_EXCEPTION_ONLY */ -} Modifier; - -typedef struct{ - int id; - int event_kind; - int suspend_policy; - int nmodifiers; - gpointer info; - Modifier modifiers [MONO_ZERO_LEN_ARRAY]; -} EventRequest; - -/* - * Describes a single step request. - */ -typedef struct { - EventRequest *req; - MonoInternalThread *thread; - StepDepth depth; - StepSize size; - StepFilter filter; - gpointer last_sp; - gpointer start_sp; - MonoMethod *start_method; - MonoMethod *last_method; - int last_line; - /* Whenever single stepping is performed using start/stop_single_stepping () */ - gboolean global; - /* The list of breakpoints used to implement step-over */ - GSList *bps; - /* The number of frames at the start of a step-over */ - int nframes; - /* If set, don't stop in methods that are not part of user assemblies */ - MonoAssembly** user_assemblies; - /* Used to distinguish stepping breakpoint hits in parallel tasks executions */ - int async_id; - /* Used to know if we are in process of async step-out and distishing from exception breakpoints */ - MonoMethod* async_stepout_method; - int refcount; -} SingleStepReq; - - /* * Contains information about an inserted breakpoint. */ @@ -326,64 +273,6 @@ typedef struct { MonoDomain *domain; } BreakpointInstance; -/* - * Contains generic information about a breakpoint. - */ -typedef struct { - /* - * The method where the breakpoint is placed. Can be NULL in which case it - * is inserted into every method. This is used to implement method entry/ - * exit events. Can be a generic method definition, in which case the - * breakpoint is inserted into every instance. - */ - MonoMethod *method; - long il_offset; - EventRequest *req; - /* - * A list of BreakpointInstance structures describing where the breakpoint - * was inserted. There could be more than one because of - * generics/appdomains/method entry/exit. - */ - GPtrArray *children; -} MonoBreakpoint; - -typedef struct { - MonoJitInfo *ji; - MonoDomain *domain; - MonoMethod *method; - guint32 native_offset; -} DbgEngineStackFrame; - -typedef struct { - /* - * Method where to start single stepping - */ - MonoMethod *method; - - /* - * If ctx is set, tls must belong to the same thread. - */ - MonoContext *ctx; - void *tls; - - /* - * Stopped at a throw site - */ - gboolean step_to_catch; - - /* - * Sequence point to start from. - */ - SeqPoint sp; - MonoSeqPointInfo *info; - - /* - * Frame data, will be freed at the end of ss_start if provided - */ - DbgEngineStackFrame **frames; - int nframes; -} SingleStepArgs; - /* * OBJECT IDS */ @@ -430,9 +319,6 @@ typedef struct gboolean has_ctx; } StackFrame; -void mono_debugger_free_objref (gpointer value); - -typedef int DbgEngineErrorCode; #define DE_ERR_NONE 0 // WARNING WARNING WARNING // Error codes MUST match those of sdb for now @@ -453,32 +339,6 @@ mono_debugger_set_thread_state (DebuggerTlsData *ref, MonoDebuggerThreadState ex MonoDebuggerThreadState mono_debugger_get_thread_state (DebuggerTlsData *ref); -typedef struct { - MonoContext *(*tls_get_restore_state) (void *tls); - gboolean (*try_process_suspend) (void *tls, MonoContext *ctx, gboolean from_breakpoint); - gboolean (*begin_breakpoint_processing) (void *tls, MonoContext *ctx, MonoJitInfo *ji, gboolean from_signal); - void (*begin_single_step_processing) (MonoContext *ctx, gboolean from_signal); - - void (*ss_discard_frame_context) (void *tls); - void (*ss_calculate_framecount) (void *tls, MonoContext *ctx, gboolean force_use_ctx, DbgEngineStackFrame ***frames, int *nframes); - gboolean (*ensure_jit) (DbgEngineStackFrame *frame); - int (*ensure_runtime_is_suspended) (void); - - int (*get_this_async_id) (DbgEngineStackFrame *frame); - - void* (*create_breakpoint_events) (GPtrArray *ss_reqs, GPtrArray *bp_reqs, MonoJitInfo *ji, EventKind kind); - void (*process_breakpoint_events) (void *_evts, MonoMethod *method, MonoContext *ctx, int il_offset); - - gboolean (*set_set_notification_for_wait_completion_flag) (DbgEngineStackFrame *f); - MonoMethod* (*get_notify_debugger_of_wait_completion_method)(void); - - int (*ss_create_init_args) (SingleStepReq *ss_req, SingleStepArgs *args); - void (*ss_args_destroy) (SingleStepArgs *ss_args); - int (*handle_multiple_ss_requests)(void); -} DebuggerEngineCallbacks; - - -void mono_de_init (DebuggerEngineCallbacks *cbs); void mono_de_cleanup (void); void mono_de_set_log_level (int level, FILE *file); @@ -489,15 +349,13 @@ void mono_de_unlock (void); // domain handling void mono_de_foreach_domain (GHFunc func, gpointer user_data); void mono_de_domain_add (MonoDomain *domain); -void mono_de_domain_remove (MonoDomain *domain); //breakpoints void mono_de_clear_breakpoint (MonoBreakpoint *bp); MonoBreakpoint* mono_de_set_breakpoint (MonoMethod *method, long il_offset, EventRequest *req, MonoError *error); 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); -MonoBreakpoint * mono_de_get_breakpoint_by_id (int id); +void mono_de_add_pending_breakpoints(MonoMethod* method, MonoJitInfo* ji); //single stepping void mono_de_start_single_stepping (void); @@ -513,12 +371,12 @@ DbgEngineErrorCode mono_de_set_interp_var (MonoType *t, gpointer addr, guint8 *v gboolean set_set_notification_for_wait_completion_flag (DbgEngineStackFrame *frame); MonoClass * get_class_to_get_builder_field(DbgEngineStackFrame *frame); -gpointer get_this_addr (DbgEngineStackFrame *the_frame); gpointer get_async_method_builder (DbgEngineStackFrame *frame); -MonoMethod* get_set_notification_method (MonoClass* async_builder_class); MonoMethod* get_notify_debugger_of_wait_completion_method (void); MonoMethod* get_object_id_for_debugger_method (MonoClass* async_builder_class); +void mono_debugger_free_objref(gpointer value); + #ifdef HOST_ANDROID #define PRINT_DEBUG_MSG(level, ...) do { if (G_UNLIKELY ((level) <= log_level)) { g_print (__VA_ARGS__); } } while (0) #define DEBUG(level,s) do { if (G_UNLIKELY ((level) <= log_level)) { s; } } while (0) @@ -545,14 +403,5 @@ void win32_debugger_log(FILE *stream, const gchar *format, ...); #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); +mono_de_init(DebuggerEngineCallbacks* cbs); diff --git a/src/mono/mono/mini/debugger-mono-compat.h b/src/mono/mono/component/debugger-mono-compat.h similarity index 100% rename from src/mono/mono/mini/debugger-mono-compat.h rename to src/mono/mono/component/debugger-mono-compat.h diff --git a/src/mono/mono/mini/debugger-protocol.c b/src/mono/mono/component/debugger-protocol.c similarity index 100% rename from src/mono/mono/mini/debugger-protocol.c rename to src/mono/mono/component/debugger-protocol.c diff --git a/src/mono/mono/mini/debugger-protocol.h b/src/mono/mono/component/debugger-protocol.h similarity index 100% rename from src/mono/mono/mini/debugger-protocol.h rename to src/mono/mono/component/debugger-protocol.h diff --git a/src/mono/mono/mini/debugger-state-machine.c b/src/mono/mono/component/debugger-state-machine.c similarity index 99% rename from src/mono/mono/mini/debugger-state-machine.c rename to src/mono/mono/component/debugger-state-machine.c index 1aff76cbade32..c5b96b7aada53 100644 --- a/src/mono/mono/mini/debugger-state-machine.c +++ b/src/mono/mono/component/debugger-state-machine.c @@ -12,11 +12,10 @@ #include #include -#include -#include +#include "debugger-state-machine.h" #include #include -#include +#include "debugger-engine.h" #include #include diff --git a/src/mono/mono/mini/debugger-state-machine.h b/src/mono/mono/component/debugger-state-machine.h similarity index 100% rename from src/mono/mono/mini/debugger-state-machine.h rename to src/mono/mono/component/debugger-state-machine.h diff --git a/src/mono/mono/component/debugger-stub.c b/src/mono/mono/component/debugger-stub.c new file mode 100644 index 0000000000000..1c5467adadddd --- /dev/null +++ b/src/mono/mono/component/debugger-stub.c @@ -0,0 +1,203 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// + +#include + +#include "mono/mini/mini-runtime.h" +#include "debugger-agent.h" + +#include + +static bool +debugger_avaliable (void); + +static void +stub_debugger_parse_options (char *options); + +static void +stub_debugger_init (MonoDefaults *mono_defaults); + +static void +stub_debugger_breakpoint_hit (void *sigctx); + +static void +stub_debugger_single_step_event (void *sigctx); + +static void +stub_debugger_free_mem_manager (gpointer mem_manager); + +static void +stub_debugger_handle_exception (MonoException *exc, MonoContext *throw_ctx, MonoContext *catch_ctx, StackFrameInfo *catch_frame); + +static void +stub_debugger_begin_exception_filter (MonoException *exc, MonoContext *ctx, MonoContext *orig_ctx); + +static void +stub_debugger_end_exception_filter (MonoException *exc, MonoContext *ctx, MonoContext *orig_ctx); + +static void +stub_debugger_user_break (void); + +static void +stub_debugger_debug_log (int level, MonoString *category, MonoString *message); + +static gboolean +stub_debugger_debug_log_is_enabled (void); + +static void +stub_debugger_unhandled_exception (MonoException *exc); + +static void +stub_debugger_single_step_from_context (MonoContext *ctx); + +static void +stub_debugger_breakpoint_from_context (MonoContext *ctx); + +static void +stub_debugger_send_crash (char *json_dump, MonoStackHash *hashes, int pause); + +static gboolean +stub_debugger_transport_handshake (void); + +static void +stub_mono_wasm_breakpoint_hit (void); + +static void +stub_mono_wasm_single_step_hit (void); + +static MonoComponentDebugger fn_table = { + { MONO_COMPONENT_ITF_VERSION, &debugger_avaliable }, + &stub_debugger_init, + &stub_debugger_user_break, + &stub_debugger_parse_options, + &stub_debugger_breakpoint_hit, + &stub_debugger_single_step_event, + &stub_debugger_single_step_from_context, + &stub_debugger_breakpoint_from_context, + &stub_debugger_free_mem_manager, + &stub_debugger_unhandled_exception, + &stub_debugger_handle_exception, + &stub_debugger_begin_exception_filter, + &stub_debugger_end_exception_filter, + &stub_debugger_debug_log, + &stub_debugger_debug_log_is_enabled, + &stub_debugger_send_crash, + &stub_debugger_transport_handshake, + + //wasm + &stub_mono_wasm_breakpoint_hit, + &stub_mono_wasm_single_step_hit +}; + +static bool +debugger_avaliable (void) +{ + return false; +} + +MonoComponentDebugger * +mono_component_debugger_init (void) +{ + return &fn_table; +} + +static void +stub_debugger_parse_options (char *options) +{ + if (!options) + return; + g_error ("This runtime is configured with the debugger agent disabled."); +} + +static void +stub_debugger_init (MonoDefaults *mono_defaults) +{ +} + +static void +stub_debugger_breakpoint_hit (void *sigctx) +{ +} + +static void +stub_debugger_single_step_event (void *sigctx) +{ +} + +static void +stub_debugger_free_mem_manager (gpointer mem_manager) +{ +} + +static void +stub_debugger_handle_exception (MonoException *exc, MonoContext *throw_ctx, + MonoContext *catch_ctx, StackFrameInfo *catch_frame) +{ +} + +static void +stub_debugger_begin_exception_filter (MonoException *exc, MonoContext *ctx, MonoContext *orig_ctx) +{ +} + +static void +stub_debugger_end_exception_filter (MonoException *exc, MonoContext *ctx, MonoContext *orig_ctx) +{ +} + +static void +stub_debugger_user_break (void) +{ + G_BREAKPOINT (); +} + +static void +stub_debugger_debug_log (int level, MonoString *category, MonoString *message) +{ +} + +static gboolean +stub_debugger_debug_log_is_enabled (void) +{ + return FALSE; +} + +static void +stub_debugger_unhandled_exception (MonoException *exc) +{ + g_assert_not_reached (); +} + +static void +stub_debugger_single_step_from_context (MonoContext *ctx) +{ + g_assert_not_reached (); +} + +static void +stub_debugger_breakpoint_from_context (MonoContext *ctx) +{ + g_assert_not_reached (); +} + +static void +stub_debugger_send_crash (char *json_dump, MonoStackHash *hashes, int pause) +{ +} + +static gboolean +stub_debugger_transport_handshake (void) +{ + g_assert_not_reached(); +} + +static void +stub_mono_wasm_breakpoint_hit (void) +{ +} + +static void +stub_mono_wasm_single_step_hit (void) +{ +} diff --git a/src/mono/mono/component/debugger.c b/src/mono/mono/component/debugger.c new file mode 100644 index 0000000000000..2ebb4f46aae91 --- /dev/null +++ b/src/mono/mono/component/debugger.c @@ -0,0 +1,35 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// + +#include + +#include "mono/mini/mini-runtime.h" + +#include +#include "debugger-agent.h" +#include "debugger-engine.h" + +static bool +debugger_avaliable (void); + +static MonoComponentDebugger fn_table = { + { MONO_COMPONENT_ITF_VERSION, &debugger_avaliable } +}; + +static bool +debugger_avaliable (void) +{ + return true; +} + + +MonoComponentDebugger * +mono_component_debugger_init (void) +{ + debugger_agent_add_function_pointers (&fn_table); +#ifdef TARGET_WASM + mini_wasm_debugger_add_function_pointers (&fn_table); +#endif + return &fn_table; +} diff --git a/src/mono/mono/component/debugger.h b/src/mono/mono/component/debugger.h new file mode 100644 index 0000000000000..de50c5641137a --- /dev/null +++ b/src/mono/mono/component/debugger.h @@ -0,0 +1,224 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// + +#ifndef _MONO_COMPONENT_DEBUGGER_H +#define _MONO_COMPONENT_DEBUGGER_H + +#include +#include "mono/metadata/threads-types.h" +#include "mono/utils/mono-error.h" +#include "mono/utils/mono-context.h" +#include "mono/utils/mono-stack-unwinding.h" +#include "mono/component/component.h" +#include "debugger-protocol.h" +#include "mono/metadata/seq-points-data.h" + +typedef struct { + MdbgProtModifierKind kind; + union { + int count; /* For kind == MOD_KIND_COUNT */ + MonoInternalThread *thread; /* For kind == MOD_KIND_THREAD_ONLY */ + MonoClass *exc_class; /* For kind == MONO_KIND_EXCEPTION_ONLY */ + MonoAssembly **assemblies; /* For kind == MONO_KIND_ASSEMBLY_ONLY */ + GHashTable *source_files; /* For kind == MONO_KIND_SOURCE_FILE_ONLY */ + GHashTable *type_names; /* For kind == MONO_KIND_TYPE_NAME_ONLY */ + MdbgProtStepFilter filter; /* For kind == MOD_KIND_STEP */ + } data; + gboolean caught, uncaught, subclasses, not_filtered_feature, everything_else; /* For kind == MOD_KIND_EXCEPTION_ONLY */ +} Modifier; + +typedef struct{ + int id; + int event_kind; + int suspend_policy; + int nmodifiers; + gpointer info; + Modifier modifiers [MONO_ZERO_LEN_ARRAY]; +} EventRequest; + +typedef struct { + MonoJitInfo *ji; + MonoDomain *domain; + MonoMethod *method; + guint32 native_offset; +} DbgEngineStackFrame; + + +typedef struct { + /* + * Method where to start single stepping + */ + MonoMethod *method; + + /* + * If ctx is set, tls must belong to the same thread. + */ + MonoContext *ctx; + void *tls; + + /* + * Stopped at a throw site + */ + gboolean step_to_catch; + + /* + * Sequence point to start from. + */ + SeqPoint sp; + MonoSeqPointInfo *info; + + /* + * Frame data, will be freed at the end of ss_start if provided + */ + DbgEngineStackFrame **frames; + int nframes; +} SingleStepArgs; + +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; + +typedef struct { + EventRequest *req; + MonoInternalThread *thread; + MdbgProtStepDepth depth; + MdbgProtStepSize size; + MdbgProtStepFilter filter; + gpointer last_sp; + gpointer start_sp; + MonoMethod *start_method; + MonoMethod *last_method; + int last_line; + /* Whenever single stepping is performed using start/stop_single_stepping () */ + gboolean global; + /* The list of breakpoints used to implement step-over */ + GSList *bps; + /* The number of frames at the start of a step-over */ + int nframes; + /* If set, don't stop in methods that are not part of user assemblies */ + MonoAssembly** user_assemblies; + /* Used to distinguish stepping breakpoint hits in parallel tasks executions */ + int async_id; + /* Used to know if we are in process of async step-out and distishing from exception breakpoints */ + MonoMethod* async_stepout_method; + int refcount; +} SingleStepReq; + +typedef struct { + MonoContext *(*tls_get_restore_state) (void *tls); + gboolean (*try_process_suspend) (void *tls, MonoContext *ctx, gboolean from_breakpoint); + gboolean (*begin_breakpoint_processing) (void *tls, MonoContext *ctx, MonoJitInfo *ji, gboolean from_signal); + void (*begin_single_step_processing) (MonoContext *ctx, gboolean from_signal); + + void (*ss_discard_frame_context) (void *tls); + void (*ss_calculate_framecount) (void *tls, MonoContext *ctx, gboolean force_use_ctx, DbgEngineStackFrame ***frames, int *nframes); + gboolean (*ensure_jit) (DbgEngineStackFrame *frame); + int (*ensure_runtime_is_suspended) (void); + int (*handle_multiple_ss_requests)(void); +} DebuggerEngineCallbacks; + +/* + * Contains generic information about a breakpoint. + */ +typedef struct { + /* + * The method where the breakpoint is placed. Can be NULL in which case it + * is inserted into every method. This is used to implement method entry/ + * exit events. Can be a generic method definition, in which case the + * breakpoint is inserted into every instance. + */ + MonoMethod* method; + long il_offset; + EventRequest* req; + /* + * A list of BreakpointInstance structures describing where the breakpoint + * was inserted. There could be more than one because of + * generics/appdomains/method entry/exit. + */ + GPtrArray* children; +} MonoBreakpoint; + +typedef int DbgEngineErrorCode; + +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 _DebuggerTlsData DebuggerTlsData; + +typedef struct MonoComponentDebugger { + MonoComponent component; + void (*init) (MonoDefaults *mono_defaults); + void (*user_break) (void); + void (*parse_options) (char *options); + void (*breakpoint_hit) (void *sigctx); + void (*single_step_event) (void *sigctx); + void (*single_step_from_context) (MonoContext *ctx); + void (*breakpoint_from_context) (MonoContext *ctx); + void (*free_mem_manager) (gpointer mem_manager); + void (*unhandled_exception) (MonoException *exc); + void (*handle_exception) (MonoException *exc, MonoContext *throw_ctx, + MonoContext *catch_ctx, MonoStackFrameInfo *catch_frame); + void (*begin_exception_filter) (MonoException *exc, MonoContext *ctx, MonoContext *orig_ctx); + void (*end_exception_filter) (MonoException *exc, MonoContext *ctx, MonoContext *orig_ctx); + void (*debug_log) (int level, MonoString *category, MonoString *message); + gboolean (*debug_log_is_enabled) (void); + void (*send_crash) (char *json_dump, MonoStackHash *hashes, int pause); + gboolean (*transport_handshake) (void); + + //wasm + void (*mono_wasm_breakpoint_hit) (void); + void (*mono_wasm_single_step_hit) (void); + +} MonoComponentDebugger; + + +extern MonoDefaults *mdbg_mono_defaults; + +#define DE_ERR_NONE 0 +// WARNING WARNING WARNING +// Error codes MUST match those of sdb for now +#define DE_ERR_NOT_IMPLEMENTED 100 + +#if defined(HOST_WIN32) && !HAVE_API_SUPPORT_WIN32_CONSOLE +void win32_debugger_log(FILE *stream, const gchar *format, ...); +#define PRINT_ERROR_MSG(...) win32_debugger_log (log_file, __VA_ARGS__) +#define PRINT_MSG(...) win32_debugger_log (log_file, __VA_ARGS__) +#else +#define PRINT_ERROR_MSG(...) g_printerr (__VA_ARGS__) +#define PRINT_MSG(...) g_print (__VA_ARGS__) +#endif + + +MONO_COMPONENT_EXPORT_ENTRYPOINT +MonoComponentDebugger * +mono_component_debugger_init (void); + +#define MONO_DBG_CALLBACKS_VERSION (4) + + +#endif/*_MONO_COMPONENT_DEBUGGER_H*/ diff --git a/src/mono/mono/mini/mini-wasm-debugger.c b/src/mono/mono/component/mini-wasm-debugger.c similarity index 86% rename from src/mono/mono/mini/mini-wasm-debugger.c rename to src/mono/mono/component/mini-wasm-debugger.c index 8c5951cf1040a..4df2172841efe 100644 --- a/src/mono/mono/mini/mini-wasm-debugger.c +++ b/src/mono/mono/component/mini-wasm-debugger.c @@ -1,6 +1,6 @@ #include -#include "mini.h" -#include "mini-runtime.h" +#include +#include #include #include #include @@ -10,9 +10,10 @@ #include #include #include -#include -#include -#include +#include +#include "debugger-protocol.h" +#include "debugger-agent.h" +#include //XXX This is dirty, extend ee.h to support extracting info from MonoInterpFrameHandle #include @@ -24,6 +25,8 @@ #include "mono/metadata/assembly-internals.h" #include "mono/metadata/debug-mono-ppdb.h" +#include + static int log_level = 1; //functions exported to be used by JS @@ -40,7 +43,6 @@ extern void mono_wasm_asm_loaded (const char *asm_name, const char *assembly_dat G_END_DECLS -static void handle_exception (MonoException *exc, MonoContext *throw_ctx, MonoContext *catch_ctx, StackFrameInfo *catch_frame); static gboolean receive_debugger_agent_message (void *data, int len); static void assembly_loaded (MonoProfiler *prof, MonoAssembly *assembly); @@ -114,14 +116,14 @@ begin_single_step_processing (MonoContext *ctx, gboolean from_signal) static void ss_discard_frame_context (void *the_tls) { - mono_ss_discard_frame_context (mono_wasm_get_tls()); + mono_ss_discard_frame_context (mono_wasm_get_tls ()); } static void ss_calculate_framecount (void *tls, MonoContext *ctx, gboolean force_use_ctx, DbgEngineStackFrame ***out_frames, int *nframes) { - mono_wasm_save_thread_context(); - mono_ss_calculate_framecount(mono_wasm_get_tls(), NULL, force_use_ctx, out_frames, nframes); + mono_wasm_save_thread_context (); + mono_ss_calculate_framecount (mono_wasm_get_tls (), NULL, force_use_ctx, out_frames, nframes); } static gboolean @@ -144,12 +146,25 @@ handle_multiple_ss_requests (void) { return 1; } -void -mono_wasm_debugger_init (void) +static void +mono_wasm_enable_debugging_internal (int debug_level) { + PRINT_DEBUG_MSG (1, "DEBUGGING ENABLED\n"); + debugger_enabled = TRUE; + log_level = debug_level; +} + +static void +mono_wasm_debugger_init (MonoDefaults *mono_defaults) +{ + 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, @@ -159,24 +174,16 @@ mono_wasm_debugger_init (void) .ss_calculate_framecount = ss_calculate_framecount, .ensure_jit = ensure_jit, .ensure_runtime_is_suspended = ensure_runtime_is_suspended, - .get_this_async_id = mono_get_this_async_id, - .set_set_notification_for_wait_completion_flag = set_set_notification_for_wait_completion_flag, - .get_notify_debugger_of_wait_completion_method = get_notify_debugger_of_wait_completion_method, - .create_breakpoint_events = mono_dbg_create_breakpoint_events, - .process_breakpoint_events = mono_dbg_process_breakpoint_events, - .ss_create_init_args = mono_ss_create_init_args, - .ss_args_destroy = mono_ss_args_destroy, .handle_multiple_ss_requests = handle_multiple_ss_requests, }; - mono_debug_init (MONO_DEBUG_FORMAT_MONO); mono_de_init (&cbs); mono_de_set_log_level (log_level, stdout); - mini_debug_options.gen_sdb_seq_points = TRUE; - mini_debug_options.mdb_optimizations = TRUE; + get_mini_debug_options ()->gen_sdb_seq_points = TRUE; + get_mini_debug_options ()->mdb_optimizations = TRUE; mono_disable_optimizations (MONO_OPT_LINEARS); - mini_debug_options.load_aot_jit_info_eagerly = TRUE; + get_mini_debug_options ()->load_aot_jit_info_eagerly = TRUE; MonoProfilerHandle prof = mono_profiler_create (NULL); mono_profiler_set_jit_done_callback (prof, jit_done); @@ -184,9 +191,6 @@ mono_wasm_debugger_init (void) mono_profiler_set_domain_loaded_callback (prof, appdomain_load); mono_profiler_set_assembly_loaded_callback (prof, assembly_loaded); - mini_get_dbg_callbacks ()->handle_exception = mono_debugger_agent_handle_exception; - mini_get_dbg_callbacks ()->user_break = mono_dbg_debugger_agent_user_break; - //debugger-agent initialization DebuggerTransport trans; trans.name = "buffer-wasm-communication"; @@ -196,14 +200,6 @@ mono_wasm_debugger_init (void) mono_init_debugger_agent_for_wasm (log_level); } -MONO_API void -mono_wasm_enable_debugging (int debug_level) -{ - PRINT_DEBUG_MSG (1, "DEBUGGING ENABLED\n"); - debugger_enabled = TRUE; - log_level = debug_level; -} - static void assembly_loaded (MonoProfiler *prof, MonoAssembly *assembly) { @@ -233,17 +229,16 @@ assembly_loaded (MonoProfiler *prof, MonoAssembly *assembly) } } - -void +static void mono_wasm_single_step_hit (void) { - mono_de_process_single_step (mono_wasm_get_tls(), FALSE); + mono_de_process_single_step (mono_wasm_get_tls (), FALSE); } -void +static void mono_wasm_breakpoint_hit (void) { - mono_de_process_breakpoint (mono_wasm_get_tls(), FALSE); + mono_de_process_breakpoint (mono_wasm_get_tls (), FALSE); } static gboolean @@ -404,14 +399,14 @@ mono_wasm_send_dbg_command (int id, MdbgProtCommandSet command_set, int command, MdbgProtErrorCode error = 0; if (command_set == MDBGPROT_CMD_SET_VM && command == MDBGPROT_CMD_VM_INVOKE_METHOD ) { - DebuggerTlsData* tls = mono_wasm_get_tls(); + DebuggerTlsData* tls = mono_wasm_get_tls (); InvokeData invoke_data; - memset(&invoke_data, 0, sizeof(InvokeData)); + memset (&invoke_data, 0, sizeof (InvokeData)); invoke_data.endp = data + size; - error = mono_do_invoke_method(tls, &buf, &invoke_data, data, &data); + error = mono_do_invoke_method (tls, &buf, &invoke_data, data, &data); } else - error = mono_process_dbg_packet(id, command_set, command, &no_reply, data, data + size, &buf); + error = mono_process_dbg_packet (id, command_set, command, &no_reply, data, data + size, &buf); EM_ASM ({ MONO.mono_wasm_add_dbg_command_received ($0, $1, $2, $3); }, error == MDBGPROT_ERR_NONE, id, buf.buf, buf.p-buf.buf); @@ -433,19 +428,28 @@ receive_debugger_agent_message (void *data, int len) #else // HOST_WASM -void +static void mono_wasm_single_step_hit (void) { } -void +static void mono_wasm_breakpoint_hit (void) { } -void -mono_wasm_debugger_init (void) +static void +mono_wasm_debugger_init (MonoDefaults *mono_defaults) { } + #endif // HOST_WASM + +void +mini_wasm_debugger_add_function_pointers (MonoComponentDebugger* fn_table) +{ + fn_table->init = mono_wasm_debugger_init; + fn_table->mono_wasm_breakpoint_hit = mono_wasm_breakpoint_hit; + fn_table->mono_wasm_single_step_hit = mono_wasm_single_step_hit; +} diff --git a/src/mono/mono/metadata/assembly-internals.h b/src/mono/mono/metadata/assembly-internals.h index 4548b7fd86451..28f3fdc502ffc 100644 --- a/src/mono/mono/metadata/assembly-internals.h +++ b/src/mono/mono/metadata/assembly-internals.h @@ -31,7 +31,7 @@ typedef enum { G_ENUM_FUNCTIONS (MonoAssemblyNameEqFlags) -void +MONO_COMPONENT_API void mono_assembly_name_free_internal (MonoAssemblyName *aname); gboolean @@ -108,7 +108,7 @@ void mono_assembly_request_prepare_open (MonoAssemblyOpenReque MonoAssemblyContextKind asmctx, MonoAssemblyLoadContext *alc); -void mono_assembly_request_prepare_byname (MonoAssemblyByNameRequest *req, +MONO_COMPONENT_API void mono_assembly_request_prepare_byname (MonoAssemblyByNameRequest *req, MonoAssemblyContextKind asmctx, MonoAssemblyLoadContext *alc); @@ -120,7 +120,7 @@ MonoAssembly* mono_assembly_request_load_from (MonoImage *image, const const MonoAssemblyLoadRequest *req, MonoImageOpenStatus *status); -MonoAssembly* mono_assembly_request_byname (MonoAssemblyName *aname, +MONO_COMPONENT_API MonoAssembly* mono_assembly_request_byname (MonoAssemblyName *aname, const MonoAssemblyByNameRequest *req, MonoImageOpenStatus *status); diff --git a/src/mono/mono/metadata/class-init.h b/src/mono/mono/metadata/class-init.h index 5dbf66b6d1b40..1ec64459376cd 100644 --- a/src/mono/mono/metadata/class-init.h +++ b/src/mono/mono/metadata/class-init.h @@ -25,10 +25,10 @@ mono_class_create_generic_inst (MonoGenericClass *gclass); MonoClass * mono_class_create_bounded_array (MonoClass *element_class, uint32_t rank, mono_bool bounded); -MonoClass * +MONO_COMPONENT_API MonoClass * mono_class_create_array (MonoClass *element_class, uint32_t rank); -MonoClass * +MONO_COMPONENT_API MonoClass * mono_class_create_generic_parameter (MonoGenericParam *param); MonoClass * @@ -49,7 +49,7 @@ mono_class_setup_basic_field_info (MonoClass *klass); void mono_class_setup_fields (MonoClass *klass); -void +MONO_COMPONENT_API void mono_class_setup_methods (MonoClass *klass); void @@ -64,7 +64,7 @@ mono_class_layout_fields (MonoClass *klass, int base_instance_size, int packing_ void mono_class_setup_interface_offsets (MonoClass *klass); -void +MONO_COMPONENT_API void mono_class_setup_vtable (MonoClass *klass); void diff --git a/src/mono/mono/metadata/class-internals.h b/src/mono/mono/metadata/class-internals.h index 37ce4ce6a14a5..3759bb4de274f 100644 --- a/src/mono/mono/metadata/class-internals.h +++ b/src/mono/mono/metadata/class-internals.h @@ -317,7 +317,7 @@ int mono_class_interface_match (const uint8_t *bitmap, int id); MONO_API int mono_class_interface_offset (MonoClass *klass, MonoClass *itf); -int mono_class_interface_offset_with_variance (MonoClass *klass, MonoClass *itf, gboolean *non_exact_match); +MONO_COMPONENT_API int mono_class_interface_offset_with_variance (MonoClass *klass, MonoClass *itf, gboolean *non_exact_match); typedef gpointer MonoRuntimeGenericContext; @@ -578,7 +578,7 @@ typedef struct { MonoMethod *wrapper_method; } MonoJitICallInfo; -void +MONO_COMPONENT_API void mono_class_setup_supertypes (MonoClass *klass); /* WARNING @@ -773,7 +773,7 @@ mono_class_get_implemented_interfaces (MonoClass *klass, MonoError *error); int mono_class_get_vtable_size (MonoClass *klass); -gboolean +MONO_COMPONENT_API gboolean mono_class_is_open_constructed_type (MonoType *t); void @@ -788,10 +788,10 @@ mono_class_get_finalizer (MonoClass *klass); gboolean mono_class_needs_cctor_run (MonoClass *klass, MonoMethod *caller); -gboolean +MONO_COMPONENT_API gboolean mono_class_field_is_special_static (MonoClassField *field); -guint32 +MONO_COMPONENT_API guint32 mono_class_field_get_special_static_type (MonoClassField *field); gboolean @@ -800,7 +800,7 @@ mono_class_has_special_static_fields (MonoClass *klass); const char* mono_class_get_field_default_value (MonoClassField *field, MonoTypeEnum *def_type); -MonoProperty* +MONO_COMPONENT_API MonoProperty* mono_class_get_property_from_name_internal (MonoClass *klass, const char *name); const char* @@ -894,10 +894,10 @@ mono_method_get_is_covariant_override_impl (MonoMethod *method); void mono_method_set_is_covariant_override_impl (MonoMethod *methoddef); -MonoMethod* +MONO_COMPONENT_API MonoMethod* mono_class_inflate_generic_method_full_checked (MonoMethod *method, MonoClass *klass_hint, MonoGenericContext *context, MonoError *error); -MonoMethod * +MONO_COMPONENT_API MonoMethod * mono_class_inflate_generic_method_checked (MonoMethod *method, MonoGenericContext *context, MonoError *error); MonoMemoryManager * @@ -915,7 +915,7 @@ mono_metadata_get_inflated_signature (MonoMethodSignature *sig, MonoGenericConte MonoType* mono_class_inflate_generic_type_with_mempool (MonoImage *image, MonoType *type, MonoGenericContext *context, MonoError *error); -MonoType* +MONO_COMPONENT_API MonoType* mono_class_inflate_generic_type_checked (MonoType *type, MonoGenericContext *context, MonoError *error); MONO_API void @@ -1062,16 +1062,16 @@ mono_loader_init (void); void mono_loader_cleanup (void); -void +MONO_COMPONENT_API void mono_loader_lock (void); -void +MONO_COMPONENT_API void mono_loader_unlock (void); -void +MONO_COMPONENT_API void mono_loader_lock_track_ownership (gboolean track); -gboolean +MONO_COMPONENT_API gboolean mono_loader_lock_is_owned_by_self (void); void @@ -1086,7 +1086,7 @@ mono_reflection_init (void); void mono_icall_init (void); -gpointer +MONO_COMPONENT_API gpointer mono_method_get_wrapper_data (MonoMethod *method, guint32 id); gboolean @@ -1209,7 +1209,7 @@ mono_method_search_in_array_class (MonoClass *klass, const char *name, MonoMetho void mono_class_setup_interface_id (MonoClass *klass); -MonoGenericContainer* +MONO_COMPONENT_API MonoGenericContainer* mono_class_get_generic_container (MonoClass *klass); gpointer @@ -1220,13 +1220,13 @@ mono_class_alloc0 (MonoClass *klass, int size); #define mono_class_alloc0(klass, size) (g_cast (mono_class_alloc0 ((klass), (size)))) -void +MONO_COMPONENT_API void mono_class_setup_interfaces (MonoClass *klass, MonoError *error); -MonoClassField* +MONO_COMPONENT_API MonoClassField* mono_class_get_field_from_name_full (MonoClass *klass, const char *name, MonoType *type); -MonoVTable* +MONO_COMPONENT_API MonoVTable* mono_class_vtable_checked (MonoClass *klass, MonoError *error); void @@ -1247,7 +1247,7 @@ mono_class_is_variant_compatible (MonoClass *klass, MonoClass *oklass, gboolean gboolean mono_class_is_subclass_of_internal (MonoClass *klass, MonoClass *klassc, gboolean check_interfaces); -mono_bool +MONO_COMPONENT_API mono_bool mono_class_is_assignable_from_internal (MonoClass *klass, MonoClass *oklass); gboolean @@ -1261,7 +1261,7 @@ mono_field_get_type_checked (MonoClassField *field, MonoError *error); MonoType* mono_field_get_type_internal (MonoClassField *field); -MonoClassField* +MONO_COMPONENT_API MonoClassField* mono_class_get_fields_internal (MonoClass* klass, gpointer *iter); MonoClassField* @@ -1276,7 +1276,7 @@ mono_class_has_finalizer (MonoClass *klass); void mono_unload_interface_id (MonoClass *klass); -GPtrArray* +MONO_COMPONENT_API GPtrArray* mono_class_get_methods_by_name (MonoClass *klass, const char *name, guint32 bflags, guint32 mlisttype, gboolean allow_ctors, MonoError *error); char* @@ -1300,10 +1300,10 @@ mono_class_from_name_case_checked (MonoImage *image, const char* name_space, con MONO_PROFILER_API MonoClass * mono_class_from_mono_type_internal (MonoType *type); -MonoClassField* +MONO_COMPONENT_API MonoClassField* mono_field_from_token_checked (MonoImage *image, uint32_t token, MonoClass **retklass, MonoGenericContext *context, MonoError *error); -gpointer +MONO_COMPONENT_API gpointer mono_ldtoken_checked (MonoImage *image, guint32 token, MonoClass **handle_class, MonoGenericContext *context, MonoError *error); MonoImage * @@ -1312,10 +1312,10 @@ mono_get_image_for_generic_param (MonoGenericParam *param); char * mono_make_generic_name_string (MonoImage *image, int num); -MonoClass * +MONO_COMPONENT_API MonoClass * mono_class_load_from_name (MonoImage *image, const char* name_space, const char *name); -MonoClass* +MONO_COMPONENT_API MonoClass* mono_class_try_load_from_name (MonoImage *image, const char* name_space, const char *name); void @@ -1325,7 +1325,7 @@ gboolean mono_class_has_failure (const MonoClass *klass); /* Kind specific accessors */ -MonoGenericClass* +MONO_COMPONENT_API MonoGenericClass* mono_class_get_generic_class (MonoClass *klass); MonoGenericClass* diff --git a/src/mono/mono/metadata/components.c b/src/mono/mono/metadata/components.c index 765bc726a2efe..d0a2c1257f23d 100644 --- a/src/mono/mono/metadata/components.c +++ b/src/mono/mono/metadata/components.c @@ -6,6 +6,7 @@ #include #include #include "mono/component/component.h" +#include "mono/component/debugger.h" #include "mono/component/hot_reload.h" #include "mono/component/event_pipe.h" #include "mono/component/diagnostics_server.h" @@ -32,8 +33,14 @@ typedef struct _MonoComponentEntry { #define HOT_RELOAD_LIBRARY_NAME "hot_reload" #define HOT_RELOAD_COMPONENT_NAME HOT_RELOAD_LIBRARY_NAME + +#define DEBUGGER_LIBRARY_NAME "debugger" +#define DEBUGGER_COMPONENT_NAME DEBUGGER_LIBRARY_NAME + MonoComponentHotReload *hot_reload = NULL; +MonoComponentDebugger *debugger = NULL; + MonoComponentEventPipe *event_pipe = NULL; MonoComponentDiagnosticsServer *diagnostics_server = NULL; @@ -44,6 +51,7 @@ MonoComponentDiagnosticsServer *diagnostics_server = NULL; /* One per component */ MonoComponentEntry components[] = { + { DEBUGGER_LIBRARY_NAME, DEBUGGER_COMPONENT_NAME, COMPONENT_INIT_FUNC (debugger), (MonoComponent**)&debugger, NULL }, { HOT_RELOAD_LIBRARY_NAME, HOT_RELOAD_COMPONENT_NAME, COMPONENT_INIT_FUNC (hot_reload), (MonoComponent**)&hot_reload, NULL }, { DIAGNOSTICS_TRACING_LIBRARY_NAME, EVENT_PIPE_COMPONENT_NAME, COMPONENT_INIT_FUNC (event_pipe), (MonoComponent**)&event_pipe, NULL }, { DIAGNOSTICS_TRACING_LIBRARY_NAME, DIAGNOSTICS_SERVER_COMPONENT_NAME, COMPONENT_INIT_FUNC (diagnostics_server), (MonoComponent**)&diagnostics_server, NULL }, diff --git a/src/mono/mono/metadata/components.h b/src/mono/mono/metadata/components.h index 0a022e349a28b..2aceed820c9d3 100644 --- a/src/mono/mono/metadata/components.h +++ b/src/mono/mono/metadata/components.h @@ -9,6 +9,7 @@ #include #include #include +#include void mono_component_event_pipe_100ns_ticks_start (void); @@ -44,4 +45,12 @@ mono_component_diagnostics_server (void) return diagnostics_server; } +static inline +MonoComponentDebugger * +mono_component_debugger (void) +{ + extern MonoComponentDebugger *debugger; + return debugger; +} + #endif/*_MONO_METADATA_COMPONENTS_H*/ diff --git a/src/mono/mono/metadata/custom-attrs-internals.h b/src/mono/mono/metadata/custom-attrs-internals.h index 407268a22fad5..16a232a80db5f 100644 --- a/src/mono/mono/metadata/custom-attrs-internals.h +++ b/src/mono/mono/metadata/custom-attrs-internals.h @@ -29,10 +29,10 @@ mono_assembly_is_weak_field (MonoImage *image, guint32 field_idx); void mono_assembly_init_weak_fields (MonoImage *image); -void +MONO_COMPONENT_API void mono_reflection_create_custom_attr_data_args (MonoImage *image, MonoMethod *method, const guchar *data, guint32 len, MonoArrayHandleOut typed_args_out, MonoArrayHandleOut named_args_out, CattrNamedArg **named_arg_info, MonoError *error); -void +MONO_COMPONENT_API void mono_reflection_create_custom_attr_data_args_noalloc (MonoImage *image, MonoMethod *method, const guchar *data, guint32 len, gpointer **typed_args_out, gpointer **named_args_out, int *num_named_args, CattrNamedArg **named_arg_info, MonoError *error); diff --git a/src/mono/mono/metadata/debug-internals.h b/src/mono/mono/metadata/debug-internals.h index 4fb12e39eca24..e08b767b4c374 100644 --- a/src/mono/mono/metadata/debug-internals.h +++ b/src/mono/mono/metadata/debug-internals.h @@ -92,7 +92,7 @@ typedef struct { void mono_debugger_lock (void); void mono_debugger_unlock (void); -void +MONO_COMPONENT_API void mono_debug_get_seq_points (MonoDebugMethodInfo *minfo, char **source_file, GPtrArray **source_file_list, int **source_files, MonoSymSeqPoint **seq_points, int *n_seq_points); @@ -100,16 +100,16 @@ mono_debug_get_seq_points (MonoDebugMethodInfo *minfo, char **source_file, MONO_API void mono_debug_free_locals (MonoDebugLocalsInfo *info); -void +MONO_COMPONENT_API void mono_debug_free_method_async_debug_info (MonoDebugMethodAsyncInfo *info); -gboolean +MONO_COMPONENT_API gboolean mono_debug_image_has_debug_info (MonoImage *image); MonoDebugSourceLocation * mono_debug_lookup_source_location_by_il (MonoMethod *method, guint32 il_offset, MonoDomain *domain); -char* +MONO_COMPONENT_API char* mono_debug_image_get_sourcelink (MonoImage *image); #endif /* __DEBUG_INTERNALS_H__ */ diff --git a/src/mono/mono/metadata/debug-mono-ppdb.h b/src/mono/mono/metadata/debug-mono-ppdb.h index f7148be9f06a9..c27a97069c97e 100644 --- a/src/mono/mono/metadata/debug-mono-ppdb.h +++ b/src/mono/mono/metadata/debug-mono-ppdb.h @@ -38,7 +38,7 @@ mono_ppdb_lookup_locals (MonoDebugMethodInfo *minfo); MonoDebugMethodAsyncInfo* mono_ppdb_lookup_method_async_debug_info (MonoDebugMethodInfo *minfo); -MonoImage * +MONO_COMPONENT_API MonoImage * mono_ppdb_get_image (MonoPPDBFile *ppdb); char * diff --git a/src/mono/mono/metadata/domain-internals.h b/src/mono/mono/metadata/domain-internals.h index 176b70d772faf..398898c6e609a 100644 --- a/src/mono/mono/metadata/domain-internals.h +++ b/src/mono/mono/metadata/domain-internals.h @@ -80,7 +80,7 @@ mono_install_runtime_load (MonoLoadFunc func); MonoDomain* mono_runtime_load (const char *filename, const char *runtime_version); -void +MONO_COMPONENT_API void mono_runtime_quit_internal (void); void @@ -136,7 +136,7 @@ mono_runtime_register_runtimeconfig_json_properties (MonovmRuntimeConfigArgument void mono_runtime_install_appctx_properties (void); -void +MONO_COMPONENT_API void mono_domain_set_fast (MonoDomain *domain); G_END_DECLS diff --git a/src/mono/mono/metadata/gc-internals.h b/src/mono/mono/metadata/gc-internals.h index d1bd5590b06bb..60e2d79d0ff3c 100644 --- a/src/mono/mono/metadata/gc-internals.h +++ b/src/mono/mono/metadata/gc-internals.h @@ -68,7 +68,7 @@ void mono_object_register_finalizer_handle (MonoObjectHandle obj); extern void mono_gc_init (void); -extern void mono_gc_base_init (void); +MONO_COMPONENT_API extern void mono_gc_base_init (void); extern void mono_gc_base_cleanup (void); extern void mono_gc_init_icalls (void); @@ -78,7 +78,7 @@ extern void mono_gc_init_icalls (void); */ extern gboolean mono_gc_is_gc_thread (void); -extern gboolean mono_gc_is_finalizer_internal_thread (MonoInternalThread *thread); +MONO_COMPONENT_API extern gboolean mono_gc_is_finalizer_internal_thread (MonoInternalThread *thread); extern void mono_gc_set_stack_end (void *stack_end); @@ -174,7 +174,7 @@ typedef void (*MonoFinalizationProc)(gpointer, gpointer); // same as SGenFinaliz void mono_gc_register_for_finalization (MonoObject *obj, MonoFinalizationProc user_data); void mono_gc_add_memory_pressure (gint64 value); MONO_API int mono_gc_register_root (char *start, size_t size, MonoGCDescriptor descr, MonoGCRootSource source, void *key, const char *msg); -void mono_gc_deregister_root (char* addr); +MONO_COMPONENT_API void mono_gc_deregister_root (char* addr); void mono_gc_finalize_domain (MonoDomain *domain); void mono_gc_run_finalize (void *obj, void *data); void mono_gc_clear_domain (MonoDomain * domain); @@ -310,7 +310,7 @@ void mono_gc_set_desktop_mode (void); /* * Return whenever this GC can move objects */ -gboolean mono_gc_is_moving (void); +MONO_COMPONENT_API gboolean mono_gc_is_moving (void); typedef void* (*MonoGCLockedCallbackFunc) (void *data); diff --git a/src/mono/mono/metadata/handle.c b/src/mono/mono/metadata/handle.c index 50fb6f5612a3d..d6af32f73b291 100644 --- a/src/mono/mono/metadata/handle.c +++ b/src/mono/mono/metadata/handle.c @@ -149,7 +149,7 @@ mono_handle_chunk_leak_check (HandleStack *handles) { // There are deliberately locals and a constant NULL global with this same name. #ifdef __cplusplus -extern MonoThreadInfo * const mono_thread_info_current_var = NULL; +MonoThreadInfo * const mono_thread_info_current_var = NULL; #else MonoThreadInfo * const mono_thread_info_current_var = NULL; #endif diff --git a/src/mono/mono/metadata/handle.h b/src/mono/mono/metadata/handle.h index 62bf12881940c..0e43247971a06 100644 --- a/src/mono/mono/metadata/handle.h +++ b/src/mono/mono/metadata/handle.h @@ -124,9 +124,9 @@ typedef void (*GcScanFunc) (gpointer*, gpointer); #endif #ifndef MONO_HANDLE_TRACK_OWNER -MonoRawHandle mono_handle_new (MonoObject *object, MonoThreadInfo *info); +MONO_COMPONENT_API MonoRawHandle mono_handle_new (MonoObject *object, MonoThreadInfo *info); #else -MonoRawHandle mono_handle_new (MonoObject *object, MonoThreadInfo *info, const char* owner); +MONO_COMPONENT_API MonoRawHandle mono_handle_new (MonoObject *object, MonoThreadInfo *info, const char* owner); #endif void mono_handle_stack_scan (HandleStack *stack, GcScanFunc func, gpointer gc_data, gboolean precise, gboolean check); @@ -134,7 +134,7 @@ gboolean mono_handle_stack_is_empty (HandleStack *stack); HandleStack* mono_handle_stack_alloc (void); void mono_handle_stack_free (HandleStack *handlestack); MonoRawHandle mono_stack_mark_pop_value (MonoThreadInfo *info, HandleStackMark *stackmark, MonoRawHandle value); -MonoThreadInfo* mono_stack_mark_record_size (MonoThreadInfo *info, HandleStackMark *stackmark, const char *func_name); +MONO_COMPONENT_API MonoThreadInfo* mono_stack_mark_record_size (MonoThreadInfo *info, HandleStackMark *stackmark, const char *func_name); void mono_handle_stack_free_domain (HandleStack *stack, MonoDomain *domain); #ifdef MONO_HANDLE_TRACK_SP diff --git a/src/mono/mono/metadata/loader-internals.h b/src/mono/mono/metadata/loader-internals.h index a317db6978546..0e1934455d1dc 100644 --- a/src/mono/mono/metadata/loader-internals.h +++ b/src/mono/mono/metadata/loader-internals.h @@ -296,10 +296,10 @@ mono_mem_manager_free (MonoMemoryManager *memory_manager, gboolean debug_unload) void mono_mem_manager_free_objects (MonoMemoryManager *memory_manager); -void +MONO_COMPONENT_API void mono_mem_manager_lock (MonoMemoryManager *memory_manager); -void +MONO_COMPONENT_API void mono_mem_manager_unlock (MonoMemoryManager *memory_manager); MONO_COMPONENT_API diff --git a/src/mono/mono/metadata/marshal.h b/src/mono/mono/metadata/marshal.h index 6ce138c117026..08300a001efd5 100644 --- a/src/mono/mono/metadata/marshal.h +++ b/src/mono/mono/metadata/marshal.h @@ -403,7 +403,7 @@ mono_type_to_stind (MonoType *type); /* functions to create various architecture independent helper functions */ -MonoMethod * +MONO_COMPONENT_API MonoMethod * mono_marshal_method_from_wrapper (MonoMethod *wrapper); WrapperInfo* diff --git a/src/mono/mono/metadata/metadata-internals.h b/src/mono/mono/metadata/metadata-internals.h index a3f56cf1f84b1..545693ef12a58 100644 --- a/src/mono/mono/metadata/metadata-internals.h +++ b/src/mono/mono/metadata/metadata-internals.h @@ -720,7 +720,7 @@ table_info_get_rows (const MonoTableInfo *table) } /* for use with allocated memory blocks (assumes alignment is to 8 bytes) */ -guint mono_aligned_addr_hash (gconstpointer ptr); +MONO_COMPONENT_API guint mono_aligned_addr_hash (gconstpointer ptr); void mono_image_check_for_module_cctor (MonoImage *image); @@ -818,7 +818,7 @@ mono_image_effective_table (const MonoTableInfo **t, int *idx) int mono_image_relative_delta_index (MonoImage *image_dmeta, int token); -void +MONO_COMPONENT_API void mono_image_load_enc_delta (MonoImage *base_image, gconstpointer dmeta, uint32_t dmeta_len, gconstpointer dil, uint32_t dil_len, MonoError *error); gboolean @@ -916,7 +916,7 @@ mono_metadata_parse_generic_inst (MonoImage *image, const char **rptr, MonoError *error); -MonoGenericInst * +MONO_COMPONENT_API MonoGenericInst * mono_metadata_get_generic_inst (int type_argc, MonoType **type_argv); @@ -1052,7 +1052,7 @@ mono_type_create_from_typespec_checked (MonoImage *image, guint32 type_spec, Mon MonoMethodSignature* mono_method_get_signature_checked (MonoMethod *method, MonoImage *image, guint32 token, MonoGenericContext *context, MonoError *error); -MonoMethod * +MONO_COMPONENT_API MonoMethod * mono_get_method_checked (MonoImage *image, guint32 token, MonoClass *klass, MonoGenericContext *context, MonoError *error); guint32 @@ -1085,7 +1085,7 @@ mono_loader_set_strict_assembly_name_check (gboolean enabled); gboolean mono_loader_get_strict_assembly_name_check (void); -gboolean +MONO_COMPONENT_API gboolean mono_type_in_image (MonoType *type, MonoImage *image); gboolean diff --git a/src/mono/mono/metadata/metadata.c b/src/mono/mono/metadata/metadata.c index ca8cced208a76..1e3cd55ed2d8f 100644 --- a/src/mono/mono/metadata/metadata.c +++ b/src/mono/mono/metadata/metadata.c @@ -1967,8 +1967,6 @@ mono_metadata_init (void) for (i = 0; i < NBUILTIN_TYPES (); ++i) g_hash_table_insert (type_cache, (gpointer) &builtin_types [i], (gpointer) &builtin_types [i]); - mono_components_init (); - mono_metadata_update_init (); } diff --git a/src/mono/mono/metadata/mono-debug.h b/src/mono/mono/metadata/mono-debug.h index 4af24ca3d1a17..2ddbce0994715 100644 --- a/src/mono/mono/metadata/mono-debug.h +++ b/src/mono/mono/metadata/mono-debug.h @@ -191,7 +191,7 @@ mono_debug_add_delegate_trampoline (void* code, int size); MONO_API MonoDebugLocalsInfo* mono_debug_lookup_locals (MonoMethod *method, mono_bool ignore_pdb); -MonoDebugMethodAsyncInfo* +MONO_API MonoDebugMethodAsyncInfo* mono_debug_lookup_method_async_debug_info (MonoMethod *method); MONO_API diff --git a/src/mono/mono/metadata/mono-hash-internals.h b/src/mono/mono/metadata/mono-hash-internals.h index 1ba508b2030fd..84b8894f9e00e 100644 --- a/src/mono/mono/metadata/mono-hash-internals.h +++ b/src/mono/mono/metadata/mono-hash-internals.h @@ -7,11 +7,12 @@ #include "mono/metadata/mono-hash.h" #include "mono/metadata/mono-gc.h" +#include "mono/utils/mono-compiler.h" -MonoGHashTable * +MONO_COMPONENT_API MonoGHashTable * mono_g_hash_table_new_type_internal (GHashFunc hash_func, GEqualFunc key_equal_func, MonoGHashGCType type, MonoGCRootSource source, void *key, const char *msg); -void +MONO_COMPONENT_API void mono_g_hash_table_insert_internal (MonoGHashTable *h, gpointer k, gpointer v); #endif /* __MONO_G_HASH_INTERNALS_H__ */ diff --git a/src/mono/mono/metadata/object-internals.h b/src/mono/mono/metadata/object-internals.h index 0af9ed940682c..bba7439ff8839 100644 --- a/src/mono/mono/metadata/object-internals.h +++ b/src/mono/mono/metadata/object-internals.h @@ -84,7 +84,7 @@ } \ } while (0) -MonoClass * +MONO_COMPONENT_API MonoClass * mono_class_create_array (MonoClass *element_class, uint32_t rank); MonoArrayHandle @@ -1486,7 +1486,7 @@ mono_array_calc_byte_len (MonoClass *klass, uintptr_t len, uintptr_t *res); MonoArray* mono_array_new_checked (MonoClass *eclass, uintptr_t n, MonoError *error); -MonoArray* +MONO_COMPONENT_API MonoArray* mono_array_new_full_checked (MonoClass *array_class, uintptr_t *lengths, intptr_t *lower_bounds, MonoError *error); ICALL_EXPORT @@ -1499,7 +1499,7 @@ mono_create_ftnptr (gpointer addr); gpointer mono_get_addr_from_ftnptr (gpointer descr); -void +MONO_COMPONENT_API void mono_nullable_init (guint8 *buf, MonoObject *value, MonoClass *klass); void @@ -1508,13 +1508,13 @@ mono_nullable_init_from_handle (guint8 *buf, MonoObjectHandle value, MonoClass * void mono_nullable_init_unboxed (guint8 *buf, gpointer value, MonoClass *klass); -MonoObject * +MONO_COMPONENT_API MonoObject * mono_value_box_checked (MonoClass *klass, void* val, MonoError *error); MonoObjectHandle mono_value_box_handle (MonoClass *klass, gpointer val, MonoError *error); -MonoObject* +MONO_COMPONENT_API MonoObject* mono_nullable_box (gpointer buf, MonoClass *klass, MonoError *error); MonoObjectHandle @@ -1642,10 +1642,10 @@ mono_object_new_alloc_specific_checked (MonoVTable *vtable, MonoError *error); void mono_field_get_value_internal (MonoObject *obj, MonoClassField *field, void *value); -void +MONO_COMPONENT_API void mono_field_static_get_value_checked (MonoVTable *vt, MonoClassField *field, void *value, MonoStringHandleOut string_handle, MonoError *error); -void +MONO_COMPONENT_API void mono_field_static_get_value_for_thread (MonoInternalThread *thread, MonoVTable *vt, MonoClassField *field, void *value, MonoStringHandleOut string_handle, MonoError *error); guint8* @@ -1664,7 +1664,7 @@ mono_field_get_value_object_checked (MonoClassField *field, MonoObject *obj, Mon MonoObjectHandle mono_static_field_get_value_handle (MonoClassField *field, MonoError *error); -gpointer +MONO_COMPONENT_API gpointer mono_special_static_field_get_offset (MonoClassField *field, MonoError *error); gboolean @@ -1728,7 +1728,7 @@ mono_error_set_pending_exception (MonoError *error) MonoArray * mono_glist_to_array (GList *list, MonoClass *eclass, MonoError *error); -MonoObject * +MONO_COMPONENT_API MonoObject * mono_object_new_checked (MonoClass *klass, MonoError *error); MonoObjectHandle @@ -1772,7 +1772,7 @@ mono_string_new_len_checked (const char *text, guint length, MonoError *error); MonoString * mono_string_new_size_checked (gint32 len, MonoError *error); -MonoString* +MONO_COMPONENT_API MonoString* mono_ldstr_checked (MonoImage *image, uint32_t str_index, MonoError *error); MonoStringHandle @@ -1822,7 +1822,7 @@ mono_runtime_try_invoke (MonoMethod *method, void *obj, void **params, MonoObjec MONO_COMPONENT_API MonoObjectHandle mono_runtime_try_invoke_handle (MonoMethod *method, MonoObjectHandle obj, void **params, MonoError* error); -MonoObject* +MONO_COMPONENT_API MonoObject* mono_runtime_invoke_checked (MonoMethod *method, void *obj, void **params, MonoError *error); MonoObjectHandle @@ -1896,7 +1896,7 @@ mono_object_get_data (MonoObject *o) #define mono_handle_get_data_unsafe(handle) ((gpointer)((guint8*)MONO_HANDLE_RAW (handle) + MONO_ABI_SIZEOF (MonoObject))) -gpointer +MONO_COMPONENT_API gpointer mono_vtype_get_field_addr (gpointer vtype, MonoClassField *field); #define MONO_OBJECT_SETREF_INTERNAL(obj,fieldname,value) do { \ @@ -1929,7 +1929,7 @@ mono_string_empty_internal (MonoDomain *domain); char * mono_string_to_utf8len (MonoStringHandle s, gsize *utf8len, MonoError *error); -char* +MONO_COMPONENT_API char* mono_string_to_utf8_checked_internal (MonoString *string_obj, MonoError *error); mono_bool @@ -1938,7 +1938,7 @@ mono_string_equal_internal (MonoString *s1, MonoString *s2); unsigned mono_string_hash_internal (MonoString *s); -int +MONO_COMPONENT_API int mono_object_hash_internal (MonoObject* obj); ICALL_EXTERN_C @@ -1971,7 +1971,7 @@ MONO_PROFILER_API MonoDomain* mono_vtable_domain_internal (MonoVTable *vtable); MONO_PROFILER_API MonoClass* mono_vtable_class_internal (MonoVTable *vtable); -MonoMethod* +MONO_COMPONENT_API MonoMethod* mono_object_get_virtual_method_internal (MonoObject *obj, MonoMethod *method); MonoMethod* @@ -1995,7 +1995,7 @@ mono_raise_exception_internal (MonoException *ex); void mono_field_set_value_internal (MonoObject *obj, MonoClassField *field, void *value); -void +MONO_COMPONENT_API void mono_field_static_set_value_internal (MonoVTable *vt, MonoClassField *field, void *value); void @@ -2023,14 +2023,14 @@ mono_runtime_get_aotid_arr (void); MonoGCHandle mono_gchandle_new_internal (MonoObject *obj, mono_bool pinned); -MonoGCHandle +MONO_COMPONENT_API MonoGCHandle mono_gchandle_new_weakref_internal (MonoObject *obj, mono_bool track_resurrection); -ICALL_EXTERN_C +MONO_COMPONENT_API ICALL_EXTERN_C MonoObject* mono_gchandle_get_target_internal (MonoGCHandle gchandle); -void mono_gchandle_free_internal (MonoGCHandle gchandle); +MONO_COMPONENT_API void mono_gchandle_free_internal (MonoGCHandle gchandle); /* Reference queue support * @@ -2062,7 +2062,7 @@ mono_gc_wbarrier_set_arrayref_internal (MonoArray *arr, void* slot_ptr, MonoObj void mono_gc_wbarrier_arrayref_copy_internal (void* dest_ptr, const void* src_ptr, int count); -void +MONO_COMPONENT_API void mono_gc_wbarrier_generic_store_internal (void volatile* ptr, MonoObject* value); void diff --git a/src/mono/mono/metadata/reflection-internals.h b/src/mono/mono/metadata/reflection-internals.h index 9ea2c1cdc9816..b1504e4cda9f1 100644 --- a/src/mono/mono/metadata/reflection-internals.h +++ b/src/mono/mono/metadata/reflection-internals.h @@ -25,7 +25,7 @@ mono_domain_try_type_resolve_name (MonoAssembly *assembly, MonoStringHandle name MonoReflectionTypeBuilderHandle mono_class_get_ref_info (MonoClass *klass); -gboolean +MONO_COMPONENT_API gboolean mono_reflection_parse_type_checked (char *name, MonoTypeNameParse *info, MonoError *error); gboolean @@ -37,7 +37,7 @@ mono_reflection_type_resolve_user_types (MonoReflectionType *type, MonoError *er MonoType * mono_reflection_type_handle_mono_type (MonoReflectionTypeHandle ref_type, MonoError *error); -MonoType* +MONO_COMPONENT_API MonoType* mono_reflection_get_type_checked (MonoAssemblyLoadContext *alc, MonoImage *rootimage, MonoImage* image, MonoTypeNameParse *info, gboolean ignorecase, gboolean search_mscorlib, gboolean *type_resolve, MonoError *error); MonoType* @@ -63,17 +63,17 @@ mono_reflection_get_custom_attrs_blob_checked (MonoReflectionAssembly *assembly, MonoCustomAttrInfo* mono_custom_attrs_from_index_checked (MonoImage *image, uint32_t idx, gboolean ignore_missing, MonoError *error); -MonoCustomAttrInfo* +MONO_COMPONENT_API MonoCustomAttrInfo* mono_custom_attrs_from_method_checked (MonoMethod *method, MonoError *error); -MonoCustomAttrInfo* +MONO_COMPONENT_API MonoCustomAttrInfo* mono_custom_attrs_from_class_checked (MonoClass *klass, MonoError *error); -MonoCustomAttrInfo* +MONO_COMPONENT_API MonoCustomAttrInfo* mono_custom_attrs_from_assembly_checked (MonoAssembly *assembly, gboolean ignore_missing, MonoError *error); -MonoCustomAttrInfo* +MONO_COMPONENT_API MonoCustomAttrInfo* mono_custom_attrs_from_property_checked (MonoClass *klass, MonoProperty *property, MonoError *error); MonoCustomAttrInfo* mono_custom_attrs_from_event_checked (MonoClass *klass, MonoEvent *event, MonoError *error); -MonoCustomAttrInfo* +MONO_COMPONENT_API MonoCustomAttrInfo* mono_custom_attrs_from_field_checked (MonoClass *klass, MonoClassField *field, MonoError *error); MonoCustomAttrInfo* mono_custom_attrs_from_param_checked (MonoMethod *method, uint32_t param, MonoError *error); @@ -85,10 +85,10 @@ mono_identifier_unescape_type_name_chars (char* identifier); MonoImage * mono_find_dynamic_image_owner (void *ptr); -MonoReflectionAssemblyHandle +MONO_COMPONENT_API MonoReflectionAssemblyHandle mono_assembly_get_object_handle (MonoAssembly *assembly, MonoError *error); -MonoReflectionType* +MONO_COMPONENT_API MonoReflectionType* mono_type_get_object_checked (MonoType *type, MonoError *error); MonoReflectionTypeHandle diff --git a/src/mono/mono/metadata/runtime.h b/src/mono/mono/metadata/runtime.h index 99a6b4d364143..9ddcf7616e59f 100644 --- a/src/mono/mono/metadata/runtime.h +++ b/src/mono/mono/metadata/runtime.h @@ -16,13 +16,13 @@ #include #include -gboolean mono_runtime_try_shutdown (void); +MONO_COMPONENT_API gboolean mono_runtime_try_shutdown (void); void mono_runtime_init_tls (void); MONO_PROFILER_API char* mono_runtime_get_aotid (void); -MonoAssembly* mono_runtime_get_entry_assembly (void); +MONO_COMPONENT_API MonoAssembly* mono_runtime_get_entry_assembly (void); void mono_runtime_ensure_entry_assembly (MonoAssembly *assembly); diff --git a/src/mono/mono/metadata/seq-points-data.h b/src/mono/mono/metadata/seq-points-data.h index 8d07f44220341..4b9c1d0d479f8 100644 --- a/src/mono/mono/metadata/seq-points-data.h +++ b/src/mono/mono/metadata/seq-points-data.h @@ -8,6 +8,7 @@ #define __MONO_SEQ_POINTS_DATA_H__ #include +#include "mono/utils/mono-compiler.h" #define MONO_SEQ_POINT_FLAG_NONEMPTY_STACK 1 #define MONO_SEQ_POINT_FLAG_EXIT_IL 2 @@ -45,13 +46,13 @@ typedef struct { void mono_seq_point_info_free (gpointer info); -gboolean +MONO_COMPONENT_API gboolean mono_seq_point_iterator_next (SeqPointIterator* it); -void +MONO_COMPONENT_API void mono_seq_point_iterator_init (SeqPointIterator* it, MonoSeqPointInfo* info); -void +MONO_COMPONENT_API void mono_seq_point_init_next (MonoSeqPointInfo* info, SeqPoint sp, SeqPoint* next); int diff --git a/src/mono/mono/metadata/threads-types.h b/src/mono/mono/metadata/threads-types.h index 394a526c5524d..b9fe7d3a14fc3 100644 --- a/src/mono/mono/metadata/threads-types.h +++ b/src/mono/mono/metadata/threads-types.h @@ -80,7 +80,7 @@ typedef enum { MONO_THREAD_CREATE_FLAGS_SMALL_STACK = 0x08, } MonoThreadCreateFlags; -MonoInternalThread* +MONO_COMPONENT_API MonoInternalThread* mono_thread_create_internal (MonoThreadStart func, gpointer arg, MonoThreadCreateFlags flags, MonoError *error); MonoInternalThreadHandle @@ -197,11 +197,11 @@ MONO_PROFILER_API MonoInternalThread *mono_thread_internal_current (void); MonoInternalThreadHandle mono_thread_internal_current_handle (void); -gboolean +MONO_COMPONENT_API gboolean mono_thread_internal_abort (MonoInternalThread *thread); void mono_thread_internal_suspend_for_shutdown (MonoInternalThread *thread); -void mono_thread_internal_reset_abort (MonoInternalThread *thread); +MONO_COMPONENT_API void mono_thread_internal_reset_abort (MonoInternalThread *thread); void mono_thread_internal_unhandled_exception (MonoObject* exc); @@ -299,7 +299,7 @@ uint32_t mono_alloc_special_static_data (uint32_t static_type, uint32_t size, ui ICALL_EXTERN_C void* mono_get_special_static_data (uint32_t offset); -gpointer mono_get_special_static_data_for_thread (MonoInternalThread *thread, guint32 offset); +MONO_COMPONENT_API gpointer mono_get_special_static_data_for_thread (MonoInternalThread *thread, guint32 offset); void mono_thread_resume_interruption (gboolean exec); @@ -344,7 +344,7 @@ mono_thread_internal_current_is_attached (void); void mono_thread_internal_describe (MonoInternalThread *internal, GString *str); -gboolean +MONO_COMPONENT_API gboolean mono_thread_internal_is_current (MonoInternalThread *internal); gboolean diff --git a/src/mono/mono/metadata/verify-internals.h b/src/mono/mono/metadata/verify-internals.h index 4609a05bc2dab..ac4beff1450d9 100644 --- a/src/mono/mono/metadata/verify-internals.h +++ b/src/mono/mono/metadata/verify-internals.h @@ -11,7 +11,7 @@ #include gboolean mono_verifier_class_is_valid_generic_instantiation (MonoClass *klass); -gboolean mono_verifier_is_method_valid_generic_instantiation (MonoMethod *method); +MONO_COMPONENT_API gboolean mono_verifier_is_method_valid_generic_instantiation (MonoMethod *method); /*Token validation macros and functions */ #define IS_MEMBER_REF(token) (mono_metadata_token_table (token) == MONO_TABLE_MEMBERREF) diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index ba786bcf9d89e..c66362a55f395 100644 --- a/src/mono/mono/mini/CMakeLists.txt +++ b/src/mono/mono/mini/CMakeLists.txt @@ -168,15 +168,9 @@ set(mini_common_sources monovm.c) set(debugger_sources - debugger-engine.h - debugger-engine.c - debugger-agent.h - debugger-agent.c - debugger-protocol.h - debugger-protocol.c - debugger-agent-stubs.c - debugger-state-machine.h - debugger-state-machine.c) + debugger-agent-external.h + debugger-agent-external.c + ) set(amd64_sources mini-amd64.c @@ -228,7 +222,6 @@ set(wasm_sources tramp-wasm.c exceptions-wasm.c aot-runtime-wasm.c - mini-wasm-debugger.c wasm_m2n_invoke.g.h cpu-wasm.h) diff --git a/src/mono/mono/mini/aot-runtime.c b/src/mono/mono/mini/aot-runtime.c index 6a181644fee5f..5efa6184fb60a 100644 --- a/src/mono/mono/mini/aot-runtime.c +++ b/src/mono/mono/mini/aot-runtime.c @@ -65,7 +65,6 @@ #include "mini.h" #include "seq-points.h" -#include "debugger-agent.h" #include "aot-compiler.h" #include "aot-runtime.h" #include "jit-icalls.h" @@ -73,6 +72,8 @@ #include "mono-private-unstable.h" #include "llvmonly-runtime.h" +#include + #ifndef DISABLE_AOT #ifdef MONO_ARCH_CODE_EXEC_ONLY @@ -5321,10 +5322,10 @@ load_function_full (MonoAotModule *amodule, const char *name, MonoTrampInfo **ou MONO_AOT_ICALL (mono_exception_from_token) case MONO_JIT_ICALL_mono_debugger_agent_single_step_from_context: - target = (gpointer)mini_get_dbg_callbacks ()->single_step_from_context; + target = (gpointer)mono_component_debugger ()->single_step_from_context; break; case MONO_JIT_ICALL_mono_debugger_agent_breakpoint_from_context: - target = (gpointer)mini_get_dbg_callbacks ()->breakpoint_from_context; + target = (gpointer)mono_component_debugger ()->breakpoint_from_context; break; case MONO_JIT_ICALL_mono_throw_exception: target = mono_get_throw_exception_addr (); diff --git a/src/mono/mono/mini/debugger-agent-external.c b/src/mono/mono/mini/debugger-agent-external.c new file mode 100644 index 0000000000000..af2d1057359ad --- /dev/null +++ b/src/mono/mono/mini/debugger-agent-external.c @@ -0,0 +1,62 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// + +#include +#include +#include "debugger-agent-external.h" + +#ifndef DISABLE_SDB + +static char *sdb_options = NULL; + +#define MAX_TRANSPORTS 16 +static DebuggerTransport transports [MAX_TRANSPORTS]; +static int ntransports = 0; + +static void +register_transport (DebuggerTransport *trans) +{ + g_assert (ntransports < MAX_TRANSPORTS); + + memcpy (&transports [ntransports], trans, sizeof (DebuggerTransport)); + ntransports ++; +} + +void +mono_debugger_agent_register_transport (DebuggerTransport *trans) +{ + register_transport (trans); +} + +gboolean +mono_debugger_agent_transport_handshake (void) +{ + return mono_component_debugger ()->transport_handshake (); +} + +void +mono_debugger_agent_init (void) +{ + //not need to do anything anymore +} + +void +mono_debugger_agent_parse_options (char *options) +{ + sdb_options = options; +} + +DebuggerTransport * +mono_debugger_agent_get_transports (int *ntrans) +{ + *ntrans = ntransports; + return transports; +} + +char * +mono_debugger_agent_get_sdb_options (void) +{ + return sdb_options; +} +#endif /* DISABLE_SDB */ diff --git a/src/mono/mono/mini/debugger-agent-external.h b/src/mono/mono/mini/debugger-agent-external.h new file mode 100644 index 0000000000000..b37cd6b5e046e --- /dev/null +++ b/src/mono/mono/mini/debugger-agent-external.h @@ -0,0 +1,29 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// + +#ifndef __MONO_DEBUGGER_AGENT_H__ +#define __MONO_DEBUGGER_AGENT_H__ + +#include "mini.h" +#include "mono/component/debugger.h" + +MONO_API void +mono_debugger_agent_init (void); + +MONO_API void +mono_debugger_agent_parse_options (char *options); + +MONO_API MONO_RT_EXTERNAL_ONLY gboolean +mono_debugger_agent_transport_handshake (void); + +MONO_API void +mono_debugger_agent_register_transport (DebuggerTransport *trans); + +MONO_COMPONENT_API DebuggerTransport * +mono_debugger_agent_get_transports (int *ntrans); + +MONO_COMPONENT_API char * +mono_debugger_agent_get_sdb_options (void); + +#endif diff --git a/src/mono/mono/mini/debugger-agent-stubs.c b/src/mono/mono/mini/debugger-agent-stubs.c deleted file mode 100644 index 7746e3ae8c804..0000000000000 --- a/src/mono/mono/mini/debugger-agent-stubs.c +++ /dev/null @@ -1,122 +0,0 @@ -/* \file - * Soft Debugger stubs - * - * Author: - * Zoltan Varga (vargaz@gmail.com) - * - * Copyright 2009-2010 Novell, Inc. - * Copyright 2011 Xamarin Inc. - * Licensed under the MIT license. See LICENSE file in the project root for full license information. - */ - -#include - -#include "mini-runtime.h" -#include "debugger-agent.h" - -static void -stub_debugger_agent_parse_options (char *options) -{ - g_error ("This runtime is configured with the debugger agent disabled."); -} - -static void -stub_debugger_agent_init (void) -{ -} - -static void -stub_debugger_agent_breakpoint_hit (void *sigctx) -{ -} - -static void -stub_debugger_agent_single_step_event (void *sigctx) -{ -} - -static void -stub_debugger_agent_free_mem_manager (gpointer mem_manager) -{ -} - -static void -stub_debugger_agent_handle_exception (MonoException *exc, MonoContext *throw_ctx, - MonoContext *catch_ctx, StackFrameInfo *catch_frame) -{ -} - -static void -stub_debugger_agent_begin_exception_filter (MonoException *exc, MonoContext *ctx, MonoContext *orig_ctx) -{ -} - -static void -stub_debugger_agent_end_exception_filter (MonoException *exc, MonoContext *ctx, MonoContext *orig_ctx) -{ -} - -static void -stub_debugger_agent_user_break (void) -{ - G_BREAKPOINT (); -} - -static void -stub_debugger_agent_debug_log (int level, MonoString *category, MonoString *message) -{ -} - -static gboolean -stub_debugger_agent_debug_log_is_enabled (void) -{ - return FALSE; -} - -static void -stub_debugger_agent_unhandled_exception (MonoException *exc) -{ - g_assert_not_reached (); -} - -static void -stub_debugger_agent_single_step_from_context (MonoContext *ctx) -{ - g_assert_not_reached (); -} - -static void -stub_debugger_agent_breakpoint_from_context (MonoContext *ctx) -{ - g_assert_not_reached (); -} - -static void -stub_debugger_agent_send_crash (char *json_dump, MonoStackHash *hashes, int pause) -{ -} - -void -mono_debugger_agent_stub_init (void) -{ - MonoDebuggerCallbacks cbs; - - memset (&cbs, 0, sizeof (MonoDebuggerCallbacks)); - cbs.version = MONO_DBG_CALLBACKS_VERSION; - cbs.parse_options = stub_debugger_agent_parse_options; - cbs.init = stub_debugger_agent_init; - cbs.breakpoint_hit = stub_debugger_agent_breakpoint_hit; - cbs.single_step_event = stub_debugger_agent_single_step_event; - cbs.single_step_from_context = stub_debugger_agent_single_step_from_context; - cbs.breakpoint_from_context = stub_debugger_agent_breakpoint_from_context; - cbs.unhandled_exception = stub_debugger_agent_unhandled_exception; - cbs.handle_exception = stub_debugger_agent_handle_exception; - cbs.begin_exception_filter = stub_debugger_agent_begin_exception_filter; - cbs.end_exception_filter = stub_debugger_agent_end_exception_filter; - cbs.user_break = stub_debugger_agent_user_break; - cbs.debug_log = stub_debugger_agent_debug_log; - cbs.debug_log_is_enabled = stub_debugger_agent_debug_log_is_enabled; - cbs.send_crash = stub_debugger_agent_send_crash; - - mini_install_dbg_callbacks (&cbs); -} diff --git a/src/mono/mono/mini/debugger-agent.h b/src/mono/mono/mini/debugger-agent.h deleted file mode 100644 index bf0a06e2056fe..0000000000000 --- a/src/mono/mono/mini/debugger-agent.h +++ /dev/null @@ -1,115 +0,0 @@ -/** - * \file - */ - -#ifndef __MONO_DEBUGGER_AGENT_H__ -#define __MONO_DEBUGGER_AGENT_H__ - -#include "mini.h" -#include "debugger-protocol.h" - -#include - -#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); - void (*init) (void); - void (*breakpoint_hit) (void *sigctx); - void (*single_step_event) (void *sigctx); - void (*single_step_from_context) (MonoContext *ctx); - void (*breakpoint_from_context) (MonoContext *ctx); - void (*free_mem_manager) (gpointer mem_manager); - void (*unhandled_exception) (MonoException *exc); - void (*handle_exception) (MonoException *exc, MonoContext *throw_ctx, - MonoContext *catch_ctx, StackFrameInfo *catch_frame); - void (*begin_exception_filter) (MonoException *exc, MonoContext *ctx, MonoContext *orig_ctx); - void (*end_exception_filter) (MonoException *exc, MonoContext *ctx, MonoContext *orig_ctx); - void (*user_break) (void); - void (*debug_log) (int level, MonoString *category, MonoString *message); - gboolean (*debug_log_is_enabled) (void); - void (*send_crash) (char *json_dump, MonoStackHash *hashes, int pause); -}; - -typedef struct _DebuggerTlsData DebuggerTlsData; - -MONO_API void -mono_debugger_agent_init (void); - -MONO_API void -mono_debugger_agent_parse_options (char *options); - -void -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 diff --git a/src/mono/mono/mini/driver.c b/src/mono/mono/mini/driver.c index 4c694d5d0c558..f2792e4e6a4e4 100644 --- a/src/mono/mono/mini/driver.c +++ b/src/mono/mono/mini/driver.c @@ -56,6 +56,9 @@ #include "mono/metadata/custom-attrs-internals.h" #include +#include +#include + #include "mini.h" #include "jit.h" #include "aot-compiler.h" @@ -66,7 +69,6 @@ #include #include #include -#include "debugger-agent.h" #if TARGET_OSX # include #endif @@ -1807,7 +1809,7 @@ mono_jit_parse_options (int argc, char * argv[]) if (strncmp (argv [i], "--debugger-agent=", 17) == 0) { MonoDebugOptions *opt = mini_get_debug_options (); - sdb_options = g_strdup (argv [i] + 17); + mono_debugger_agent_parse_options (g_strdup (argv [i] + 17)); opt->mdb_optimizations = TRUE; enable_debugging = TRUE; } else if (!strcmp (argv [i], "--soft-breakpoints")) { @@ -2382,7 +2384,7 @@ mono_main (int argc, char* argv[]) } else if (strncmp (argv [i], "--debugger-agent=", 17) == 0) { MonoDebugOptions *opt = mini_get_debug_options (); - sdb_options = g_strdup (argv [i] + 17); + mono_debugger_agent_parse_options (g_strdup (argv [i] + 17)); opt->mdb_optimizations = TRUE; enable_debugging = TRUE; } else if (strcmp (argv [i], "--security") == 0) { @@ -3260,3 +3262,9 @@ mono_parse_env_options (int *ref_argc, char **ref_argv []) fprintf (stderr, "%s", ret); exit (1); } + +MonoDebugOptions * +get_mini_debug_options (void) +{ + return &mini_debug_options; +} diff --git a/src/mono/mono/mini/interp/interp.c b/src/mono/mono/mini/interp/interp.c index 1c7468ba3cadc..03c32b2a94710 100644 --- a/src/mono/mono/mini/interp/interp.c +++ b/src/mono/mono/mini/interp/interp.c @@ -72,10 +72,11 @@ #include #include #include -#include #include #include +#include + #ifdef TARGET_ARM #include #endif @@ -3286,7 +3287,7 @@ interp_exec_method (InterpFrame *frame, ThreadContext *context, FrameClauseArgs MINT_IN_BREAK; MINT_IN_CASE(MINT_BREAK) ++ip; - do_debugger_tramp (mini_get_dbg_callbacks ()->user_break, frame); + do_debugger_tramp (mono_component_debugger ()->user_break, frame); MINT_IN_BREAK; MINT_IN_CASE(MINT_BREAKPOINT) ++ip; diff --git a/src/mono/mono/mini/intrinsics.c b/src/mono/mono/mini/intrinsics.c index 20d6f8b5a2831..90c45fd6700b5 100644 --- a/src/mono/mono/mini/intrinsics.c +++ b/src/mono/mono/mini/intrinsics.c @@ -14,7 +14,6 @@ #include "mini-runtime.h" #include "ir-emit.h" #include "jit-icalls.h" -#include "debugger-agent.h" #include #include diff --git a/src/mono/mono/mini/method-to-ir.c b/src/mono/mono/mini/method-to-ir.c index d011f3b6da08e..53237a147061f 100644 --- a/src/mono/mono/mini/method-to-ir.c +++ b/src/mono/mono/mini/method-to-ir.c @@ -80,7 +80,6 @@ #include "jit-icalls.h" #include "jit.h" -#include "debugger-agent.h" #include "seq-points.h" #include "aot-compiler.h" #include "mini-llvm.h" diff --git a/src/mono/mono/mini/mini-amd64-gsharedvt.c b/src/mono/mono/mini/mini-amd64-gsharedvt.c index c18131d883cff..3a7d769e58994 100644 --- a/src/mono/mono/mini/mini-amd64-gsharedvt.c +++ b/src/mono/mono/mini/mini-amd64-gsharedvt.c @@ -27,7 +27,6 @@ #include "mini.h" #include "mini-amd64.h" #include "mini-amd64-gsharedvt.h" -#include "debugger-agent.h" #if defined (MONO_ARCH_GSHAREDVT_SUPPORTED) diff --git a/src/mono/mono/mini/mini-amd64.c b/src/mono/mono/mini/mini-amd64.c index 150791b62c3dd..87c0b175ee6c7 100644 --- a/src/mono/mono/mini/mini-amd64.c +++ b/src/mono/mono/mini/mini-amd64.c @@ -44,7 +44,6 @@ #include "ir-emit.h" #include "mini-amd64.h" #include "cpu-amd64.h" -#include "debugger-agent.h" #include "mini-gc.h" #include "mini-runtime.h" #include "aot-runtime.h" diff --git a/src/mono/mono/mini/mini-arm.c b/src/mono/mono/mini/mini-arm.c index 4fc43ee307166..58c0cef04842e 100644 --- a/src/mono/mono/mini/mini-arm.c +++ b/src/mono/mono/mini/mini-arm.c @@ -29,7 +29,6 @@ #include "mini-arm.h" #include "cpu-arm.h" #include "ir-emit.h" -#include "debugger-agent.h" #include "mini-gc.h" #include "mini-runtime.h" #include "aot-runtime.h" diff --git a/src/mono/mono/mini/mini-exceptions.c b/src/mono/mono/mini/mini-exceptions.c index 9ffc841076604..d6df5b150120d 100644 --- a/src/mono/mono/mini/mini-exceptions.c +++ b/src/mono/mono/mini/mini-exceptions.c @@ -70,11 +70,10 @@ #include #include #include +#include #include "mini.h" #include "trace.h" -#include "debugger-agent.h" -#include "debugger-engine.h" #include "seq-points.h" #include "llvm-runtime.h" #include "mini-llvm.h" @@ -2392,7 +2391,7 @@ handle_exception_first_pass (MonoContext *ctx, MonoObject *obj, gint32 *out_filt #endif } - mini_get_dbg_callbacks ()->begin_exception_filter (mono_ex, ctx, &initial_ctx); + mono_component_debugger ()->begin_exception_filter (mono_ex, ctx, &initial_ctx); if (G_UNLIKELY (mono_profiler_clauses_enabled ())) { jit_tls->orig_ex_ctx_set = TRUE; @@ -2416,7 +2415,7 @@ handle_exception_first_pass (MonoContext *ctx, MonoObject *obj, gint32 *out_filt if (enable_trace) g_print ("[%p:] EXCEPTION filter result: %d\n", (void*)(gsize)mono_native_thread_id_get (), filtered); - mini_get_dbg_callbacks ()->end_exception_filter (mono_ex, ctx, &initial_ctx); + mono_component_debugger ()->end_exception_filter (mono_ex, ctx, &initial_ctx); if (filtered && out_filter_idx) *out_filter_idx = filter_idx; if (out_ji) @@ -2657,7 +2656,7 @@ mono_handle_exception_internal (MonoContext *ctx, MonoObject *obj, gboolean resu if (res == MONO_FIRST_PASS_UNHANDLED) { if (mini_debug_options.break_on_exc) G_BREAKPOINT (); - mini_get_dbg_callbacks ()->handle_exception ((MonoException *)obj, ctx, NULL, NULL); + mono_component_debugger ()->handle_exception ((MonoException *)obj, ctx, NULL, NULL); // FIXME: This runs managed code so it might cause another stack overflow when // we are handling a stack overflow @@ -2667,21 +2666,21 @@ mono_handle_exception_internal (MonoContext *ctx, MonoObject *obj, gboolean resu gboolean unhandled = FALSE; if (unhandled) - mini_get_dbg_callbacks ()->handle_exception ((MonoException *)obj, ctx, NULL, NULL); + mono_component_debugger ()->handle_exception ((MonoException *)obj, ctx, NULL, NULL); else if (!ji || (jinfo_get_method (ji)->wrapper_type == MONO_WRAPPER_RUNTIME_INVOKE)) { if (last_mono_wrapper_runtime_invoke && !mono_thread_internal_current ()->threadpool_thread) { - mini_get_dbg_callbacks ()->handle_exception ((MonoException *)obj, ctx, NULL, NULL); + mono_component_debugger ()->handle_exception ((MonoException *)obj, ctx, NULL, NULL); if (mini_get_debug_options ()->top_runtime_invoke_unhandled) { mini_set_abort_threshold (&catch_frame); mono_unhandled_exception_internal (obj); } } else { - mini_get_dbg_callbacks ()->handle_exception ((MonoException *)obj, ctx, &ctx_cp, &catch_frame); + mono_component_debugger ()->handle_exception ((MonoException *)obj, ctx, &ctx_cp, &catch_frame); } } else if (res != MONO_FIRST_PASS_CALLBACK_TO_NATIVE) if (!is_caught_unmanaged) - mini_get_dbg_callbacks ()->handle_exception ((MonoException *)obj, ctx, &ctx_cp, &catch_frame); + mono_component_debugger ()->handle_exception ((MonoException *)obj, ctx, &ctx_cp, &catch_frame); } } diff --git a/src/mono/mono/mini/mini-posix.c b/src/mono/mono/mini/mini-posix.c index b273a96a5faa6..346b4bd43f2ef 100644 --- a/src/mono/mono/mini/mini-posix.c +++ b/src/mono/mono/mini/mini-posix.c @@ -69,13 +69,14 @@ #include #include #include -#include +#include +#include #include "mini.h" #include #include #include "trace.h" -#include "debugger-agent.h" +#include #include "mini-runtime.h" #include "jit-icalls.h" @@ -999,7 +1000,7 @@ dump_native_stacktrace (const char *signal, MonoContext *mctx) // see if we can notify any attached debugger instances. // // At this point we are accepting that the below step might end in a crash - mini_get_dbg_callbacks ()->send_crash (output, &hashes, 0 /* wait # seconds */); + mono_component_debugger ()->send_crash (output, &hashes, 0 /* wait # seconds */); } output = NULL; mono_state_free_mem (&merp_mem); diff --git a/src/mono/mono/mini/mini-runtime.c b/src/mono/mono/mini/mini-runtime.c index ce8930ff6c82c..45367721b8b86 100644 --- a/src/mono/mono/mini/mini-runtime.c +++ b/src/mono/mono/mini/mini-runtime.c @@ -72,6 +72,7 @@ #include #include #include +#include #include "mini.h" #include "seq-points.h" @@ -86,7 +87,6 @@ #include "mini-gc.h" #include "mini-llvm.h" -#include "debugger-agent.h" #include "lldb.h" #include "mini-runtime.h" #include "interp/interp.h" @@ -145,7 +145,6 @@ static mono_mutex_t jit_mutex; static MonoCodeManager *global_codeman; MonoDebugOptions mini_debug_options; -char *sdb_options; #ifdef VALGRIND_JIT_REGISTER_MAP int valgrind_register; @@ -3513,10 +3512,10 @@ MONO_SIG_HANDLER_FUNC (, mono_sigsegv_signal_handler) #if defined(MONO_ARCH_SOFT_DEBUG_SUPPORTED) && defined(HAVE_SIG_INFO) if (mono_arch_is_single_step_event (info, ctx)) { - mini_get_dbg_callbacks ()->single_step_event (ctx); + mono_component_debugger ()->single_step_event (ctx); return; } else if (mono_arch_is_breakpoint_event (info, ctx)) { - mini_get_dbg_callbacks ()->breakpoint_hit (ctx); + mono_component_debugger ()->breakpoint_hit (ctx); return; } #endif @@ -4147,7 +4146,7 @@ free_jit_mem_manager (MonoMemoryManager *mem_manager) g_hash_table_destroy (info->seq_points); g_hash_table_destroy (info->arch_seq_points); if (info->agent_info) - mini_get_dbg_callbacks ()->free_mem_manager (info); + mono_component_debugger ()->free_mem_manager (info); g_hash_table_destroy (info->gsharedvt_arg_tramp_hash); if (info->llvm_jit_callees) { g_hash_table_foreach (info->llvm_jit_callees, free_jit_callee_list, NULL); @@ -4214,21 +4213,6 @@ mini_install_interp_callbacks (const MonoEECallbacks *cbs) mono_interp_callbacks_pointer = cbs; } -static MonoDebuggerCallbacks dbg_cbs; - -void -mini_install_dbg_callbacks (MonoDebuggerCallbacks *cbs) -{ - g_assert (cbs->version == MONO_DBG_CALLBACKS_VERSION); - memcpy (&dbg_cbs, cbs, sizeof (MonoDebuggerCallbacks)); -} - -MonoDebuggerCallbacks* -mini_get_dbg_callbacks (void) -{ - return &dbg_cbs; -} - int mono_ee_api_version (void) { @@ -4286,14 +4270,9 @@ mini_init (const char *filename, const char *runtime_version) if (mono_use_interpreter) mono_ee_interp_init (mono_interp_opts_string); #endif - - mono_debugger_agent_stub_init (); -#ifndef DISABLE_SDB - mono_debugger_agent_init (); -#endif - - if (sdb_options) - mini_get_dbg_callbacks ()->parse_options (sdb_options); + mono_components_init (); + + mono_component_debugger ()->parse_options (mono_debugger_agent_get_sdb_options ()); mono_os_mutex_init_recursive (&jit_mutex); @@ -4332,8 +4311,8 @@ mini_init (const char *filename, const char *runtime_version) callbacks.get_runtime_build_info = mono_get_runtime_build_info; callbacks.get_runtime_build_version = mono_get_runtime_build_version; callbacks.set_cast_details = mono_set_cast_details; - callbacks.debug_log = mini_get_dbg_callbacks ()->debug_log; - callbacks.debug_log_is_enabled = mini_get_dbg_callbacks ()->debug_log_is_enabled; + callbacks.debug_log = mono_component_debugger ()->debug_log; + callbacks.debug_log_is_enabled = mono_component_debugger ()->debug_log_is_enabled; callbacks.get_vtable_trampoline = mini_get_vtable_trampoline; callbacks.get_imt_trampoline = mini_get_imt_trampoline; callbacks.imt_entry_inited = mini_imt_entry_inited; @@ -4428,11 +4407,7 @@ mini_init (const char *filename, const char *runtime_version) if (default_opt & MONO_OPT_AOT) mono_aot_init (); - mini_get_dbg_callbacks ()->init (); - -#ifdef TARGET_WASM - mono_wasm_debugger_init (); -#endif + mono_component_debugger ()->init (&mono_defaults); #ifdef MONO_ARCH_GSHARED_SUPPORTED mono_set_generic_sharing_supported (TRUE); @@ -4585,7 +4560,7 @@ register_icalls (void) #if defined(HOST_ANDROID) || defined(TARGET_ANDROID) mono_add_internal_call_internal ("System.Diagnostics.Debugger::Mono_UnhandledException_internal", - mini_get_dbg_callbacks ()->unhandled_exception); + mono_component_debugger ()->unhandled_exception); #endif /* @@ -4809,7 +4784,7 @@ register_icalls (void) register_icall (mono_fill_class_rgctx, mono_icall_sig_ptr_ptr_int, FALSE); register_icall (mono_fill_method_rgctx, mono_icall_sig_ptr_ptr_int, FALSE); - register_dyn_icall (mini_get_dbg_callbacks ()->user_break, mono_debugger_agent_user_break, mono_icall_sig_void, FALSE); + register_dyn_icall (mono_component_debugger ()->user_break, mono_debugger_agent_user_break, mono_icall_sig_void, FALSE); register_icall (mini_llvm_init_method, mono_icall_sig_void_ptr_ptr_ptr_ptr, TRUE); register_icall_no_wrapper (mini_llvmonly_resolve_iface_call_gsharedvt, mono_icall_sig_ptr_object_int_ptr_ptr); @@ -5180,3 +5155,9 @@ mini_get_stack_overflow_ex (void) { return mono_get_root_domain ()->stack_overflow_ex; } + +const MonoEECallbacks* +mini_get_interp_callbacks_api (void) +{ + return mono_interp_callbacks_pointer; +} diff --git a/src/mono/mono/mini/mini-runtime.h b/src/mono/mono/mini/mini-runtime.h index 67d441495bcc8..57fb1b2982466 100644 --- a/src/mono/mono/mini/mini-runtime.h +++ b/src/mono/mono/mini/mini-runtime.h @@ -452,9 +452,10 @@ extern GHashTable *mono_single_method_hash; extern GList* mono_aot_paths; extern MonoDebugOptions mini_debug_options; extern GSList *mono_interp_only_classes; -extern char *sdb_options; extern MonoMethodDesc *mono_stats_method_desc; +MONO_COMPONENT_API MonoDebugOptions *get_mini_debug_options (void); + /* This struct describes what execution engine feature to use. This subsume, and will eventually sunset, mono_aot_only / mono_llvm_only and friends. @@ -510,10 +511,7 @@ MonoEECallbacks* mono_interp_callbacks_pointer; #define mini_get_interp_callbacks() (mono_interp_callbacks_pointer) -typedef struct _MonoDebuggerCallbacks MonoDebuggerCallbacks; - -void mini_install_dbg_callbacks (MonoDebuggerCallbacks *cbs); -MonoDebuggerCallbacks *mini_get_dbg_callbacks (void); +MONO_COMPONENT_API const MonoEECallbacks* mini_get_interp_callbacks_api (void); MonoDomain* mini_init (const char *filename, const char *runtime_version); void mini_cleanup (MonoDomain *domain); @@ -530,10 +528,10 @@ void mono_precompile_assemblies (void); MONO_API int mono_parse_default_optimizations (const char* p); gboolean mono_running_on_valgrind (void); -MonoLMF * mono_get_lmf (void); +MONO_COMPONENT_API MonoLMF * mono_get_lmf (void); void mono_set_lmf (MonoLMF *lmf); -void mono_push_lmf (MonoLMFExt *ext); -void mono_pop_lmf (MonoLMF *lmf); +MONO_COMPONENT_API void mono_push_lmf (MonoLMFExt *ext); +MONO_COMPONENT_API void mono_pop_lmf (MonoLMF *lmf); MONO_API MONO_RT_EXTERNAL_ONLY void mono_jit_set_domain (MonoDomain *domain); @@ -555,7 +553,7 @@ gpointer mono_resolve_patch_target_ext (MonoMemoryManager *mem_manager, Mon void mini_register_jump_site (MonoMethod *method, gpointer ip); void mini_patch_jump_sites (MonoMethod *method, gpointer addr); void mini_patch_llvm_jit_callees (MonoMethod *method, gpointer addr); -gpointer mono_jit_search_all_backends_for_jit_info (MonoMethod *method, MonoJitInfo **ji); +MONO_COMPONENT_API gpointer mono_jit_search_all_backends_for_jit_info (MonoMethod *method, MonoJitInfo **ji); gpointer mono_jit_find_compiled_method_with_jit_info (MonoMethod *method, MonoJitInfo **ji); gpointer mono_jit_find_compiled_method (MonoMethod *method); gpointer mono_jit_compile_method (MonoMethod *method, MonoError *error); diff --git a/src/mono/mono/mini/mini-wasm.c b/src/mono/mono/mini/mini-wasm.c index 673e575781d9a..56d58e1c6a0d2 100644 --- a/src/mono/mono/mini/mini-wasm.c +++ b/src/mono/mono/mini/mini-wasm.c @@ -9,10 +9,12 @@ #include #include #include +#include //XXX This is dirty, extend ee.h to support extracting info from MonoInterpFrameHandle #include +static int mono_wasm_debug_level = 0; #ifndef DISABLE_JIT #include "ir-emit.h" @@ -760,3 +762,15 @@ mono_arch_load_function (MonoJitICallId jit_icall_id) { return NULL; } + +MONO_API void +mono_wasm_enable_debugging (int log_level) +{ + mono_wasm_debug_level = log_level; +} + +int +mono_wasm_get_debug_level (void) +{ + return mono_wasm_debug_level; +} diff --git a/src/mono/mono/mini/mini-wasm.h b/src/mono/mono/mini/mini-wasm.h index 1c78fb835289c..df0a852b1a563 100644 --- a/src/mono/mono/mini/mini-wasm.h +++ b/src/mono/mono/mini/mini-wasm.h @@ -97,18 +97,11 @@ typedef struct { #define MONO_ARCH_LLVM_TARGET_LAYOUT "e-m:e-p:32:32-i64:64-n32:64-S128" #define MONO_ARCH_LLVM_TARGET_TRIPLE "wasm32-unknown-emscripten" -void mono_wasm_debugger_init (void); - // sdks/wasm/driver.c is C and uses this G_EXTERN_C void mono_wasm_enable_debugging (int log_level); -void mono_wasm_breakpoint_hit (void); void mono_wasm_set_timeout (int timeout, int id); -void mono_wasm_single_step_hit (void); -void mono_wasm_breakpoint_hit (void); -void mono_wasm_user_break (void); - int mono_wasm_assembly_already_added (const char *assembly_name); void mono_wasm_print_stack_trace (void); diff --git a/src/mono/mono/mini/mini.c b/src/mono/mono/mini/mini.c index d03efcac91486..a15bfb89d178b 100644 --- a/src/mono/mono/mini/mini.c +++ b/src/mono/mono/mini/mini.c @@ -71,7 +71,6 @@ #include "jit-icalls.h" #include "mini-gc.h" -#include "debugger-agent.h" #include "llvm-runtime.h" #include "mini-llvm.h" #include "lldb.h" diff --git a/src/mono/mono/mini/mini.h b/src/mono/mono/mini/mini.h index c865bf5b2934e..a95cbabcb5174 100644 --- a/src/mono/mono/mini/mini.h +++ b/src/mono/mono/mini/mini.h @@ -2431,7 +2431,7 @@ gboolean mono_arch_opcode_needs_emulation (MonoCompile *cfg, int opcode); gboolean mono_arch_tailcall_supported (MonoCompile *cfg, MonoMethodSignature *caller_sig, MonoMethodSignature *callee_sig, gboolean virtual_); int mono_arch_translate_tls_offset (int offset); gboolean mono_arch_opcode_supported (int opcode); -void mono_arch_setup_resume_sighandler_ctx (MonoContext *ctx, gpointer func); +MONO_COMPONENT_API void mono_arch_setup_resume_sighandler_ctx (MonoContext *ctx, gpointer func); gboolean mono_arch_have_fast_tls (void); #ifdef MONO_ARCH_HAS_REGISTER_ICALL @@ -2450,14 +2450,14 @@ mono_arch_is_soft_float (void) /* Soft Debug support */ #ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED -void mono_arch_set_breakpoint (MonoJitInfo *ji, guint8 *ip); -void mono_arch_clear_breakpoint (MonoJitInfo *ji, guint8 *ip); -void mono_arch_start_single_stepping (void); -void mono_arch_stop_single_stepping (void); +MONO_COMPONENT_API void mono_arch_set_breakpoint (MonoJitInfo *ji, guint8 *ip); +MONO_COMPONENT_API void mono_arch_clear_breakpoint (MonoJitInfo *ji, guint8 *ip); +MONO_COMPONENT_API void mono_arch_start_single_stepping (void); +MONO_COMPONENT_API void mono_arch_stop_single_stepping (void); gboolean mono_arch_is_single_step_event (void *info, void *sigctx); gboolean mono_arch_is_breakpoint_event (void *info, void *sigctx); -void mono_arch_skip_breakpoint (MonoContext *ctx, MonoJitInfo *ji); -void mono_arch_skip_single_step (MonoContext *ctx); +MONO_COMPONENT_API void mono_arch_skip_breakpoint (MonoContext *ctx, MonoJitInfo *ji); +MONO_COMPONENT_API void mono_arch_skip_single_step (MonoContext *ctx); SeqPointInfo *mono_arch_get_seq_point_info (guint8 *code); #endif @@ -2482,9 +2482,9 @@ void mono_handle_hard_stack_ovf (MonoJitTlsData *jit_tls, MonoJi void mono_arch_undo_ip_adjustment (MonoContext *ctx); void mono_arch_do_ip_adjustment (MonoContext *ctx); gpointer mono_arch_ip_from_context (void *sigctx); -host_mgreg_t mono_arch_context_get_int_reg (MonoContext *ctx, int reg); -host_mgreg_t*mono_arch_context_get_int_reg_address (MonoContext *ctx, int reg); -void mono_arch_context_set_int_reg (MonoContext *ctx, int reg, host_mgreg_t val); +MONO_COMPONENT_API host_mgreg_t mono_arch_context_get_int_reg (MonoContext *ctx, int reg); +MONO_COMPONENT_API host_mgreg_t*mono_arch_context_get_int_reg_address (MonoContext *ctx, int reg); +MONO_COMPONENT_API void mono_arch_context_set_int_reg (MonoContext *ctx, int reg, host_mgreg_t val); void mono_arch_flush_register_windows (void); gboolean mono_arch_is_inst_imm (int opcode, int imm_opcode, gint64 imm); gboolean mono_arch_is_int_overflow (void *sigctx, void *info); @@ -2546,18 +2546,18 @@ gboolean mono_handle_exception (MonoContext *ctx, gpointer obj) void mono_handle_native_crash (const char *signal, MonoContext *mctx, MONO_SIG_HANDLER_INFO_TYPE *siginfo); MONO_API void mono_print_thread_dump (void *sigctx); MONO_API void mono_print_thread_dump_from_ctx (MonoContext *ctx); -void mono_walk_stack_with_ctx (MonoJitStackWalk func, MonoContext *start_ctx, MonoUnwindOptions unwind_options, void *user_data); -void mono_walk_stack_with_state (MonoJitStackWalk func, MonoThreadUnwindState *state, MonoUnwindOptions unwind_options, void *user_data); +MONO_COMPONENT_API void mono_walk_stack_with_ctx (MonoJitStackWalk func, MonoContext *start_ctx, MonoUnwindOptions unwind_options, void *user_data); +MONO_COMPONENT_API void mono_walk_stack_with_state (MonoJitStackWalk func, MonoThreadUnwindState *state, MonoUnwindOptions unwind_options, void *user_data); void mono_walk_stack (MonoJitStackWalk func, MonoUnwindOptions options, void *user_data); gboolean mono_thread_state_init_from_sigctx (MonoThreadUnwindState *ctx, void *sigctx); void mono_thread_state_init (MonoThreadUnwindState *ctx); -gboolean mono_thread_state_init_from_current (MonoThreadUnwindState *ctx); -gboolean mono_thread_state_init_from_monoctx (MonoThreadUnwindState *ctx, MonoContext *mctx); +MONO_COMPONENT_API gboolean mono_thread_state_init_from_current (MonoThreadUnwindState *ctx); +MONO_COMPONENT_API gboolean mono_thread_state_init_from_monoctx (MonoThreadUnwindState *ctx, MonoContext *mctx); void mono_setup_altstack (MonoJitTlsData *tls); void mono_free_altstack (MonoJitTlsData *tls); gpointer mono_altstack_restore_prot (host_mgreg_t *regs, guint8 *code, gpointer *tramp_data, guint8* tramp); -MonoJitInfo* mini_jit_info_table_find (gpointer addr); +MONO_COMPONENT_API MonoJitInfo* mini_jit_info_table_find (gpointer addr); MonoJitInfo* mini_jit_info_table_find_ext (gpointer addr, gboolean allow_trampolines); G_EXTERN_C void mono_resume_unwind (MonoContext *ctx); @@ -2565,7 +2565,7 @@ MonoJitInfo * mono_find_jit_info (MonoJitTlsData *jit_tls, MonoJi typedef gboolean (*MonoExceptionFrameWalk) (MonoMethod *method, gpointer ip, size_t native_offset, gboolean managed, gpointer user_data); MONO_API gboolean mono_exception_walk_trace (MonoException *ex, MonoExceptionFrameWalk func, gpointer user_data); -void mono_restore_context (MonoContext *ctx); +MONO_COMPONENT_API void mono_restore_context (MonoContext *ctx); guint8* mono_jinfo_get_unwind_info (MonoJitInfo *ji, guint32 *unwind_info_len); int mono_jinfo_get_epilog_size (MonoJitInfo *ji); G_EXTERN_C void mono_llvm_rethrow_exception (MonoObject *ex); @@ -2702,7 +2702,7 @@ mono_class_rgctx_get_array_size (int n, gboolean mrgctx); MonoGenericContext mono_method_construct_object_context (MonoMethod *method); -MonoMethod* +MONO_COMPONENT_API MonoMethod* mono_method_get_declaring_generic_method (MonoMethod *method); int @@ -2948,12 +2948,15 @@ mini_safepoints_enabled (void) gpointer mono_arch_load_function (MonoJitICallId jit_icall_id); -MonoGenericContext +MONO_COMPONENT_API MonoGenericContext mono_get_generic_context_from_stack_frame (MonoJitInfo *ji, gpointer generic_info); -gpointer +MONO_COMPONENT_API gpointer mono_get_generic_info_from_stack_frame (MonoJitInfo *ji, MonoContext *ctx); MonoMemoryManager* mini_get_default_mem_manager (void); +MONO_COMPONENT_API int +mono_wasm_get_debug_level (void); + #endif /* __MONO_MINI_H__ */ diff --git a/src/mono/mono/mini/monovm.c b/src/mono/mono/mini/monovm.c index a7a5f8ad65325..d3f1cdb93c678 100644 --- a/src/mono/mono/mini/monovm.c +++ b/src/mono/mono/mini/monovm.c @@ -11,6 +11,8 @@ #include #include +#include + static MonoCoreTrustedPlatformAssemblies *trusted_platform_assemblies; static MonoCoreLookupPaths *native_lib_paths; static MonoCoreLookupPaths *app_paths; diff --git a/src/mono/mono/mini/seq-points.h b/src/mono/mono/mini/seq-points.h index 17cba827789d5..a35584971c6c4 100644 --- a/src/mono/mono/mini/seq-points.h +++ b/src/mono/mono/mini/seq-points.h @@ -12,16 +12,16 @@ void mono_save_seq_point_info (MonoCompile *cfg, MonoJitInfo *jinfo); -MonoSeqPointInfo* +MONO_COMPONENT_API MonoSeqPointInfo* mono_get_seq_points (MonoMethod *method); -gboolean +MONO_COMPONENT_API gboolean mono_find_next_seq_point_for_native_offset (MonoMethod *method, gint32 native_offset, MonoSeqPointInfo **info, SeqPoint* seq_point); -gboolean +MONO_COMPONENT_API gboolean mono_find_prev_seq_point_for_native_offset (MonoMethod *method, gint32 native_offset, MonoSeqPointInfo **info, SeqPoint* seq_point); -gboolean +MONO_COMPONENT_API gboolean mono_find_seq_point (MonoMethod *method, gint32 il_offset, MonoSeqPointInfo **info, SeqPoint *seq_point); void diff --git a/src/mono/mono/mini/tramp-amd64-gsharedvt.c b/src/mono/mono/mini/tramp-amd64-gsharedvt.c index 63fec1dffea98..0d564fbeefe45 100644 --- a/src/mono/mono/mini/tramp-amd64-gsharedvt.c +++ b/src/mono/mono/mini/tramp-amd64-gsharedvt.c @@ -26,7 +26,6 @@ #include "mini.h" #include "mini-amd64.h" #include "mini-amd64-gsharedvt.h" -#include "debugger-agent.h" #if defined (MONO_ARCH_GSHAREDVT_SUPPORTED) diff --git a/src/mono/mono/mini/tramp-amd64.c b/src/mono/mono/mini/tramp-amd64.c index 086796f51daa8..ad749405c1511 100644 --- a/src/mono/mono/mini/tramp-amd64.c +++ b/src/mono/mono/mini/tramp-amd64.c @@ -28,12 +28,12 @@ #include "mini.h" #include "mini-amd64.h" #include "mini-runtime.h" -#include "debugger-agent.h" #ifndef DISABLE_INTERPRETER #include "interp/interp.h" #endif #include "mono/utils/mono-tls-inline.h" +#include #ifdef MONO_ARCH_CODE_EXEC_ONLY #include "aot-runtime.h" @@ -963,9 +963,9 @@ mono_arch_create_sdb_trampoline (gboolean single_step, MonoTrampInfo **info, gbo code = mono_arch_emit_load_aotconst (buf, code, &ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, GUINT_TO_POINTER (MONO_JIT_ICALL_mono_debugger_agent_breakpoint_from_context)); } else { if (single_step) - amd64_mov_reg_imm (code, AMD64_R11, mini_get_dbg_callbacks ()->single_step_from_context); + amd64_mov_reg_imm (code, AMD64_R11, mono_component_debugger ()->single_step_from_context); else - amd64_mov_reg_imm (code, AMD64_R11, mini_get_dbg_callbacks ()->breakpoint_from_context); + amd64_mov_reg_imm (code, AMD64_R11, mono_component_debugger ()->breakpoint_from_context); } amd64_call_reg (code, AMD64_R11); diff --git a/src/mono/mono/mini/tramp-arm.c b/src/mono/mono/mini/tramp-arm.c index 3a9f87e02ae3c..0834f106505e3 100644 --- a/src/mono/mono/mini/tramp-arm.c +++ b/src/mono/mono/mini/tramp-arm.c @@ -24,7 +24,6 @@ #include "mini.h" #include "mini-arm.h" #include "mini-runtime.h" -#include "debugger-agent.h" #include "jit-icalls.h" #ifndef DISABLE_INTERPRETER @@ -32,6 +31,8 @@ #endif #include "mono/utils/mono-tls-inline.h" +#include + void mono_arch_patch_callsite (guint8 *method_start, guint8 *code_ptr, guint8 *addr) { @@ -810,9 +811,9 @@ mono_arch_create_sdb_trampoline (gboolean single_step, MonoTrampInfo **info, gbo ARM_LDR_IMM (code, ARMREG_IP, ARMREG_PC, 0); ARM_B (code, 0); if (single_step) - *(gpointer*)code = (gpointer)mini_get_dbg_callbacks ()->single_step_from_context; + *(gpointer*)code = (gpointer)mono_component_debugger ()->single_step_from_context; else - *(gpointer*)code = (gpointer)mini_get_dbg_callbacks ()->breakpoint_from_context; + *(gpointer*)code = (gpointer)mono_component_debugger ()->breakpoint_from_context; code += 4; ARM_BLX_REG (code, ARMREG_IP); } diff --git a/src/mono/mono/mini/tramp-arm64.c b/src/mono/mono/mini/tramp-arm64.c index bffb46341a211..e0ea4f11e787e 100644 --- a/src/mono/mono/mini/tramp-arm64.c +++ b/src/mono/mono/mini/tramp-arm64.c @@ -17,7 +17,6 @@ #include "mini.h" #include "mini-runtime.h" -#include "debugger-agent.h" #include #include @@ -27,6 +26,8 @@ #endif #include "mono/utils/mono-tls-inline.h" +#include + void mono_arch_patch_callsite (guint8 *method_start, guint8 *code_ptr, guint8 *addr) { @@ -536,7 +537,7 @@ mono_arch_create_general_rgctx_lazy_fetch_trampoline (MonoTrampInfo **info, gboo * mono_arch_create_sdb_trampoline: * * Return a trampoline which captures the current context, passes it to - * mini_get_dbg_callbacks ()->single_step_from_context ()/mini_get_dbg_callbacks ()->breakpoint_from_context (), + * mono_component_debugger ()->single_step_from_context ()/mono_component_debugger ()->breakpoint_from_context (), * then restores the (potentially changed) context. */ guint8* @@ -604,7 +605,7 @@ mono_arch_create_sdb_trampoline (gboolean single_step, MonoTrampInfo **info, gbo else code = mono_arm_emit_aotconst (&ji, code, buf, ARMREG_IP0, MONO_PATCH_INFO_JIT_ICALL_ADDR, GUINT_TO_POINTER (MONO_JIT_ICALL_mono_debugger_agent_breakpoint_from_context)); } else { - void (*addr) (MonoContext *ctx) = single_step ? mini_get_dbg_callbacks ()->single_step_from_context : mini_get_dbg_callbacks ()->breakpoint_from_context; + void (*addr) (MonoContext *ctx) = single_step ? mono_component_debugger ()->single_step_from_context : mono_component_debugger ()->breakpoint_from_context; code = mono_arm_emit_imm64 (code, ARMREG_IP0, (guint64)addr); } diff --git a/src/mono/mono/mini/tramp-s390x.c b/src/mono/mono/mini/tramp-s390x.c index d035295e8721f..d301a3777eacf 100644 --- a/src/mono/mono/mini/tramp-s390x.c +++ b/src/mono/mono/mini/tramp-s390x.c @@ -51,9 +51,10 @@ #include "mini-s390x.h" #include "mini-runtime.h" #include "jit-icalls.h" -#include "debugger-agent.h" #include "mono/utils/mono-tls-inline.h" +#include + /*========================= End of Includes ========================*/ /*------------------------------------------------------------------*/ @@ -195,9 +196,9 @@ mono_arch_create_sdb_trampoline (gboolean single_step, MonoTrampInfo **info, gbo s390_la (code, s390_r2, 0, STK_BASE, ctx_offset); if (single_step) - ep = (mini_get_dbg_callbacks())->single_step_from_context; + ep = (mono_component_debugger ())->single_step_from_context; else - ep = (mini_get_dbg_callbacks())->breakpoint_from_context; + ep = (mono_component_debugger ())->breakpoint_from_context; S390_SET (code, s390_r1, ep); s390_basr (code, s390_r14, s390_r1); diff --git a/src/mono/mono/mini/tramp-wasm.c b/src/mono/mono/mini/tramp-wasm.c index 4156cfccb2344..8ba5f54b97855 100644 --- a/src/mono/mono/mini/tramp-wasm.c +++ b/src/mono/mono/mini/tramp-wasm.c @@ -1,5 +1,6 @@ #include "mini.h" #include "interp/interp.h" +#include void mono_sdb_single_step_trampoline (void); @@ -76,10 +77,10 @@ mono_arch_create_sdb_trampoline (gboolean single_step, MonoTrampInfo **info, gbo guint8* code; if (single_step) { name = "sdb_single_step_trampoline"; - code = (guint8*)mono_wasm_single_step_hit; + code = (guint8*)mono_component_debugger ()->mono_wasm_single_step_hit; } else { name = "sdb_breakpoint_trampoline"; - code = (guint8*)mono_wasm_breakpoint_hit; + code = (guint8*)mono_component_debugger ()->mono_wasm_breakpoint_hit; } if (info) diff --git a/src/mono/mono/mini/tramp-x86.c b/src/mono/mono/mini/tramp-x86.c index 218e961dc1648..582628105b1d5 100644 --- a/src/mono/mono/mini/tramp-x86.c +++ b/src/mono/mono/mini/tramp-x86.c @@ -24,10 +24,11 @@ #include "mini.h" #include "mini-x86.h" #include "mini-runtime.h" -#include "debugger-agent.h" #include "jit-icalls.h" #include "mono/utils/mono-tls-inline.h" +#include + /* * mono_arch_get_unbox_trampoline: * @m: method pointer @@ -618,7 +619,7 @@ mono_arch_get_gsharedvt_arg_trampoline (gpointer arg, gpointer addr) * mono_arch_create_sdb_trampoline: * * Return a trampoline which captures the current context, passes it to - * mini_get_dbg_callbacks ()->single_step_from_context ()/mini_get_dbg_callbacks ()->breakpoint_from_context (), + * mono_component_debugger ()->single_step_from_context ()/mono_component_debugger ()->breakpoint_from_context (), * then restores the (potentially changed) context. */ guint8* @@ -682,9 +683,9 @@ mono_arch_create_sdb_trampoline (gboolean single_step, MonoTrampInfo **info, gbo x86_breakpoint (code); } else { if (single_step) - x86_call_code (code, mini_get_dbg_callbacks ()->single_step_from_context); + x86_call_code (code, mono_component_debugger ()->single_step_from_context); else - x86_call_code (code, mini_get_dbg_callbacks ()->breakpoint_from_context); + x86_call_code (code, mono_component_debugger ()->breakpoint_from_context); } /* Restore registers from ctx */ diff --git a/src/mono/mono/sgen/gc-internal-agnostic.h b/src/mono/mono/sgen/gc-internal-agnostic.h index b14713fb62c67..73d431d54d8c7 100644 --- a/src/mono/mono/sgen/gc-internal-agnostic.h +++ b/src/mono/mono/sgen/gc-internal-agnostic.h @@ -98,7 +98,7 @@ MonoGCDescriptor mono_gc_make_descr_from_bitmap (gsize *bitmap, int numbits) MonoGCDescriptor mono_gc_make_vector_descr (void); /* Return a root descriptor for a root with all refs */ -MonoGCDescriptor mono_gc_make_root_descr_all_refs (int numbits) +MONO_COMPONENT_API MonoGCDescriptor mono_gc_make_root_descr_all_refs (int numbits) MONO_PERMIT (need (sgen_lock_gc)); /* Return the bitmap encoded by a descriptor */ diff --git a/src/mono/mono/utils/json.h b/src/mono/mono/utils/json.h index 03e6503fc9816..7b7d8e82b4689 100644 --- a/src/mono/mono/utils/json.h +++ b/src/mono/mono/utils/json.h @@ -12,7 +12,9 @@ #ifndef __MONO_UTILS_JSON_H__ #define __MONO_UTILS_JSON_H__ - #include +#include +#include "mono-compiler.h" + #define JSON_INDENT_VALUE 2 @@ -21,17 +23,17 @@ typedef struct JsonWriter { int indent; } JsonWriter; -void mono_json_writer_init (JsonWriter* writer); -void mono_json_writer_destroy (JsonWriter* writer); -void mono_json_writer_indent(JsonWriter* writer); -void mono_json_writer_indent_push(JsonWriter* writer); -void mono_json_writer_indent_pop(JsonWriter* writer); +MONO_COMPONENT_API void mono_json_writer_init (JsonWriter* writer); +MONO_COMPONENT_API void mono_json_writer_destroy (JsonWriter* writer); +MONO_COMPONENT_API void mono_json_writer_indent(JsonWriter* writer); +MONO_COMPONENT_API void mono_json_writer_indent_push(JsonWriter* writer); +MONO_COMPONENT_API void mono_json_writer_indent_pop(JsonWriter* writer); void mono_json_writer_vprintf(JsonWriter* writer, const gchar *format, va_list args); -void mono_json_writer_printf(JsonWriter* writer, const gchar *format, ...); -void mono_json_writer_array_begin(JsonWriter* writer); -void mono_json_writer_array_end(JsonWriter* writer); -void mono_json_writer_object_begin(JsonWriter* writer); -void mono_json_writer_object_end(JsonWriter* writer); -void mono_json_writer_object_key(JsonWriter* writer, const gchar* format, ...); +MONO_COMPONENT_API void mono_json_writer_printf(JsonWriter* writer, const gchar *format, ...); +MONO_COMPONENT_API void mono_json_writer_array_begin(JsonWriter* writer); +MONO_COMPONENT_API void mono_json_writer_array_end(JsonWriter* writer); +MONO_COMPONENT_API void mono_json_writer_object_begin(JsonWriter* writer); +MONO_COMPONENT_API void mono_json_writer_object_end(JsonWriter* writer); +MONO_COMPONENT_API void mono_json_writer_object_key(JsonWriter* writer, const gchar* format, ...); #endif diff --git a/src/mono/mono/utils/memfuncs.h b/src/mono/mono/utils/memfuncs.h index bc8c578bcb23a..904b28c96562c 100644 --- a/src/mono/mono/utils/memfuncs.h +++ b/src/mono/mono/utils/memfuncs.h @@ -12,6 +12,7 @@ #include #include +#include "mono-compiler.h" /* These functions must be used when it's possible that either destination is not @@ -19,7 +20,7 @@ word aligned or size is not a multiple of word size. */ void mono_gc_bzero_atomic (void *dest, size_t size); void mono_gc_bzero_aligned (void *dest, size_t size); -void mono_gc_memmove_atomic (void *dest, const void *src, size_t size); +MONO_COMPONENT_API void mono_gc_memmove_atomic (void *dest, const void *src, size_t size); void mono_gc_memmove_aligned (void *dest, const void *src, size_t size); guint64 mono_determine_physical_ram_size (void); guint64 mono_determine_physical_ram_available_size (void); diff --git a/src/mono/mono/utils/mono-context.h b/src/mono/mono/utils/mono-context.h index b305b9ba70589..bd1a3cd0104c2 100644 --- a/src/mono/mono/utils/mono-context.h +++ b/src/mono/mono/utils/mono-context.h @@ -1076,7 +1076,7 @@ typedef struct { * The naming is misleading, the SIGCTX argument should be the platform's context * structure (ucontext_c on posix, CONTEXT on windows). */ -void mono_sigctx_to_monoctx (void *sigctx, MonoContext *mctx); +MONO_COMPONENT_API void mono_sigctx_to_monoctx (void *sigctx, MonoContext *mctx); /* * This will not completely initialize SIGCTX since MonoContext contains less @@ -1084,6 +1084,6 @@ void mono_sigctx_to_monoctx (void *sigctx, MonoContext *mctx); * the system, and use this function to override the parts of it which are * also in MonoContext. */ -void mono_monoctx_to_sigctx (MonoContext *mctx, void *sigctx); +MONO_COMPONENT_API void mono_monoctx_to_sigctx (MonoContext *mctx, void *sigctx); #endif /* __MONO_MONO_CONTEXT_H__ */ diff --git a/src/mono/mono/utils/mono-error-internals.h b/src/mono/mono/utils/mono-error-internals.h index 76b3e33ee9c2f..2256c6b5adb6f 100644 --- a/src/mono/mono/utils/mono-error-internals.h +++ b/src/mono/mono/utils/mono-error-internals.h @@ -164,6 +164,7 @@ void mono_error_dup_strings (MonoError *error, gboolean dup_strings); /* This function is not very useful as you can't provide any details beyond the message.*/ +MONO_COMPONENT_API void mono_error_set_error (MonoError *error, int error_code, const char *msg_format, ...) MONO_ATTR_FORMAT_PRINTF(3,4); @@ -283,7 +284,7 @@ mono_error_set_platform_not_supported (MonoError *error, const char *message) MonoException* mono_error_prepare_exception (MonoError *error, MonoError *error_out); -MonoException* +MONO_COMPONENT_API MonoException* mono_error_convert_to_exception (MonoError *error); void diff --git a/src/mono/mono/utils/mono-flight-recorder.h b/src/mono/mono/utils/mono-flight-recorder.h index 092c8be2221b5..6a56f02e42436 100644 --- a/src/mono/mono/utils/mono-flight-recorder.h +++ b/src/mono/mono/utils/mono-flight-recorder.h @@ -31,16 +31,16 @@ typedef struct { MonoFlightRecorderItem *items [MONO_ZERO_LEN_ARRAY]; // The data of the history } MonoFlightRecorder; -MonoCoopMutex * +MONO_COMPONENT_API MonoCoopMutex * mono_flight_recorder_mutex (MonoFlightRecorder *recorder); -MonoFlightRecorder * +MONO_COMPONENT_API MonoFlightRecorder * mono_flight_recorder_init (size_t max_size, size_t payload_size); -void +MONO_COMPONENT_API void mono_flight_recorder_free (MonoFlightRecorder *recorder); -void +MONO_COMPONENT_API void mono_flight_recorder_append (MonoFlightRecorder *recorder, gpointer payload); // Used to traverse the ring buffer in order of oldest to newest message @@ -52,15 +52,15 @@ typedef struct { } MonoFlightRecorderIter; // Mutex has to be held when called -void +MONO_COMPONENT_API void mono_flight_recorder_iter_init (MonoFlightRecorder *recorder, MonoFlightRecorderIter *iter); // Mutex has to be held when called -void +MONO_COMPONENT_API void mono_flight_recorder_iter_destroy (MonoFlightRecorderIter *iter); // Mutex has to be held when called -gboolean +MONO_COMPONENT_API gboolean mono_flight_recorder_iter_next (MonoFlightRecorderIter *iter, MonoFlightRecorderHeader *header, gpointer *payload); #endif diff --git a/src/mono/mono/utils/mono-threads-api.h b/src/mono/mono/utils/mono-threads-api.h index a2c84d29e7243..0dee0c176f0fa 100644 --- a/src/mono/mono/utils/mono-threads-api.h +++ b/src/mono/mono/utils/mono-threads-api.h @@ -48,7 +48,7 @@ mono_stackdata_get_stackpointer (const MonoStackData *stackdata) MONO_API MONO_RT_EXTERNAL_ONLY gpointer mono_threads_enter_gc_unsafe_region (gpointer* stackdata); -gpointer +MONO_COMPONENT_API gpointer mono_threads_enter_gc_unsafe_region_internal (MonoStackData *stackdata); MONO_API MONO_RT_EXTERNAL_ONLY void diff --git a/src/mono/mono/utils/mono-threads.h b/src/mono/mono/utils/mono-threads.h index adb65611f4c71..4a29ab561e7f6 100644 --- a/src/mono/mono/utils/mono-threads.h +++ b/src/mono/mono/utils/mono-threads.h @@ -479,7 +479,7 @@ mono_thread_info_lookup (MonoNativeThreadId id); gboolean mono_thread_info_resume (MonoNativeThreadId tid); -void +MONO_COMPONENT_API void mono_thread_info_safe_suspend_and_run (MonoNativeThreadId id, gboolean interrupt_kernel, MonoSuspendThreadCallback callback, gpointer user_data); void @@ -552,7 +552,7 @@ mono_thread_info_is_live (THREAD_INFO_TYPE *info); int mono_thread_info_get_system_max_stack_size (void); -MonoThreadHandle* +MONO_COMPONENT_API MonoThreadHandle* mono_threads_open_thread_handle (MonoThreadHandle *handle); void diff --git a/src/mono/mono/utils/mono-time.h b/src/mono/mono/utils/mono-time.h index 874a4677c693a..685f2bc76e31e 100644 --- a/src/mono/mono/utils/mono-time.h +++ b/src/mono/mono/utils/mono-time.h @@ -17,7 +17,7 @@ gint64 mono_msec_boottime (void); /* Returns the number of milliseconds ticks from unspecified time: this should be monotonic */ -gint64 mono_msec_ticks (void); +MONO_COMPONENT_API gint64 mono_msec_ticks (void); /* Returns the number of 100ns ticks from unspecified time: this should be monotonic */ MONO_COMPONENT_API gint64 mono_100ns_ticks (void); diff --git a/src/mono/mono/utils/networking.h b/src/mono/mono/utils/networking.h index 4f6a0f5d73374..67a96391c6aed 100644 --- a/src/mono/mono/utils/networking.h +++ b/src/mono/mono/utils/networking.h @@ -87,11 +87,11 @@ typedef struct { } MonoAddress; /* This only supports IPV4 / IPV6 and tcp */ -int mono_get_address_info (const char *hostname, int port, int flags, MonoAddressInfo **res); +MONO_COMPONENT_API int mono_get_address_info (const char *hostname, int port, int flags, MonoAddressInfo **res); -void mono_free_address_info (MonoAddressInfo *ai); +MONO_COMPONENT_API void mono_free_address_info (MonoAddressInfo *ai); -void mono_socket_address_init (MonoSocketAddress *sa, socklen_t *len, int family, const void *address, int port); +MONO_COMPONENT_API void mono_socket_address_init (MonoSocketAddress *sa, socklen_t *len, int family, const void *address, int port); void *mono_get_local_interfaces (int family, int *interface_count); @@ -107,7 +107,7 @@ int mono_networking_get_tcp_protocol (void); int mono_networking_get_ip_protocol (void); int mono_networking_get_ipv6_protocol (void); -void mono_networking_init (void); +MONO_COMPONENT_API void mono_networking_init (void); void mono_networking_shutdown (void); diff --git a/src/mono/wasm/Makefile b/src/mono/wasm/Makefile index 86288cd674e70..64d7b9d658f94 100644 --- a/src/mono/wasm/Makefile +++ b/src/mono/wasm/Makefile @@ -51,6 +51,7 @@ provision-wasm: .stamp-wasm-install-and-select-$(EMSCRIPTEN_VERSION) # FIXME: When https://github.com/dotnet/runtime/issues/54565 is fixed, and the WasmApp targets are updated to use mono runtime components, remove this MONO_COMPONENT_LIBS= \ $(MONO_BIN_DIR)/libmono-component-hot_reload-static.a \ + $(MONO_BIN_DIR)/libmono-component-debugger-static.a \ $(MONO_BIN_DIR)/libmono-component-diagnostics_tracing-stub-static.a MONO_OBJ_DIR=$(OBJDIR)/mono/Browser.wasm.$(CONFIG) diff --git a/src/mono/wasm/wasm.proj b/src/mono/wasm/wasm.proj index ffc2fb92825ba..c8186ff30d3b6 100644 --- a/src/mono/wasm/wasm.proj +++ b/src/mono/wasm/wasm.proj @@ -190,6 +190,7 @@