Bugzilla – Bug 321117
[PATCH OK] binary data symbol store is not supported
Last modified: 2007-09-15 21:24:46 UTC
---- Reported by joe@otee.dk 2006-05-12 08:31:14 MST ---- The attached patch fixes the exception when using Assembly.LoadFrom with a binary data symbol store. diff -Naur --exclude .DS_Store --exclude '*.rej' mono/mono/metadata/appdomain.c mono- patch_unity/mono/metadata/appdomain.c --- mono/mono/metadata/appdomain.c 2006-04-01 03:58:14.000000000 +0200 +++ mono-patch_unity/mono/metadata/appdomain.c 2006-04-29 20:08:49.000000000 +0200 @@ -28,6 +28,7 @@ #include <mono/metadata/marshal.h> #include <mono/metadata/monitor.h> #include <mono/metadata/threadpool.h> +#include <mono/metadata/mono-debug.h> #include <mono/utils/mono-uri.h> #define MONO_CORLIB_VERSION 49 @@ -991,16 +992,19 @@ guint32 raw_assembly_len = mono_array_length (raw_assembly); MonoImage *image = mono_image_open_from_data_full (mono_array_addr (raw_assembly, gchar, 0), raw_assembly_len, TRUE, NULL, refonly); - if (raw_symbol_store) - mono_raise_exception (mono_get_exception_not_implemented ("LoadAssemblyRaw: Raw Symbol Store not Implemented")); - if (!image) { mono_raise_exception (mono_get_exception_bad_image_format ("")); return NULL; } + if (raw_symbol_store != NULL) + { + mono_debug_init_2_memory (image, mono_array_addr (raw_symbol_store, guint8, 0), mono_array_length (raw_symbol_store)); + } + ass = mono_assembly_load_from_full (image, "", &status, refonly); + if (!ass) { mono_image_close (image); mono_raise_exception (mono_get_exception_bad_image_format ("")); diff -Naur --exclude .DS_Store --exclude '*.rej' mono/mono/metadata/debug-mono-symfile.c mono-patch_unity/mono/metadata/debug-mono-symfile.c --- mono/mono/metadata/debug-mono-symfile.c 2006-03-13 23:57:48.000000000 +0100 +++ mono-patch_unity/mono/metadata/debug-mono-symfile.c 2006-04-29 20:12:57.000000000 +0200 @@ -100,7 +100,7 @@ } MonoSymbolFile * -mono_debug_open_mono_symbol_file (MonoDebugHandle *handle, gboolean in_the_debugger) +mono_debug_open_mono_symbols (MonoDebugHandle *handle, const guint8 *raw_contents, int size, gboolean in_the_debugger) { MonoSymbolFile *symfile; FILE* f; @@ -108,9 +108,15 @@ mono_debugger_lock (); symfile = g_new0 (MonoSymbolFile, 1); - symfile->filename = g_strdup_printf ("%s.mdb", mono_image_get_filename (handle- >image)); - - if ((f = fopen (symfile->filename, "rb")) > 0) { + if (raw_contents != NULL) + { + symfile->raw_contents_size = size; + symfile->raw_contents = g_malloc (size); + memcpy(symfile->raw_contents, raw_contents, size); + symfile->filename = g_strdup_printf ("LoadedFromMemory"); + } + else if ((f = fopen (symfile->filename, "rb")) > 0) { + symfile->filename = g_strdup_printf ("%s.mdb", mono_image_get_filename (handle- >image)); struct stat stat_buf; if (fstat (fileno (f), &stat_buf) < 0) { diff -Naur --exclude .DS_Store --exclude '*.rej' mono/mono/metadata/debug-mono-symfile.h mono-patch_unity/mono/metadata/debug-mono-symfile.h --- mono/mono/metadata/debug-mono-symfile.h 2006-03-13 23:57:48.000000000 +0100 +++ mono-patch_unity/mono/metadata/debug-mono-symfile.h 2006-04-29 20:09:20.000000000 +0200 @@ -132,8 +132,11 @@ G_BEGIN_DECLS MonoSymbolFile * -mono_debug_open_mono_symbol_file (MonoDebugHandle *handle, - gboolean create_symfile); +mono_debug_open_mono_symbols (MonoDebugHandle * handle, + const guint8 *raw_contents, + int size, + gboolean in_the_debugger); + void mono_debug_close_mono_symbol_file (MonoSymbolFile *symfile); diff -Naur --exclude .DS_Store --exclude '*.rej' mono/mono/metadata/mono-debug.c mono- patch_unity/mono/metadata/mono-debug.c --- mono/mono/metadata/mono-debug.c 2006-04-01 03:58:14.000000000 +0200 +++ mono-patch_unity/mono/metadata/mono-debug.c 2006-04-29 20:09:34.000000000 +0200 @@ -40,7 +40,8 @@ static GHashTable *method_hash = NULL; -static MonoDebugHandle *mono_debug_open_image (MonoImage *image); +static MonoDebugHandle *mono_debug_open_image (MonoImage *image, const guint8 *raw_contents, int size); + static void mono_debug_close_image (MonoDebugHandle *debug); static MonoDebugHandle *_mono_debug_get_image (MonoImage *image); @@ -116,7 +117,7 @@ void mono_debug_init_1 (MonoDomain *domain) { - MonoDebugHandle *handle = mono_debug_open_image (mono_get_corlib ()); + MonoDebugHandle *handle = mono_debug_open_image (mono_get_corlib (), NULL, 0); mono_symbol_table->corlib = handle; } @@ -129,9 +130,21 @@ void mono_debug_init_2 (MonoAssembly *assembly) { - mono_debug_open_image (mono_assembly_get_image (assembly)); + mono_debug_open_image (mono_assembly_get_image (assembly), NULL, 0); +} + +/* + * Initialize debugging support - part 2. + * + * This method must be called between loading the image and loading the assembly. + */ +void +mono_debug_init_2_memory (MonoImage *image, const guint8 *raw_contents, int size) +{ + mono_debug_open_image (image, raw_contents, size); } + gboolean mono_debug_using_mono_debugger (void) { @@ -175,7 +188,7 @@ } static MonoDebugHandle * -mono_debug_open_image (MonoImage *image) +mono_debug_open_image (MonoImage *image, const guint8 *raw_contents, int size) { MonoDebugHandle *handle; @@ -194,7 +207,7 @@ g_hash_table_insert (mono_debug_handles, image, handle); - handle->symfile = mono_debug_open_mono_symbol_file (handle, in_the_mono_debugger); + handle->symfile = mono_debug_open_mono_symbols (handle, raw_contents, size, in_the_mono_debugger); if (in_the_mono_debugger) mono_debugger_add_symbol_file (handle); @@ -217,7 +230,7 @@ mono_debug_add_assembly (MonoAssembly *assembly, gpointer user_data) { mono_debugger_lock (); - mono_debug_open_image (mono_assembly_get_image (assembly)); + mono_debug_open_image (mono_assembly_get_image (assembly), NULL, 0); mono_debugger_unlock (); } diff -Naur --exclude .DS_Store --exclude '*.rej' mono/mono/metadata/mono-debug.h mono- patch_unity/mono/metadata/mono-debug.h --- mono/mono/metadata/mono-debug.h 2006-03-13 23:57:48.000000000 +0100 +++ mono-patch_unity/mono/metadata/mono-debug.h 2006-04-29 20:09:39.000000000 +0200 @@ -187,6 +187,7 @@ void mono_debug_init (MonoDebugFormat format); void mono_debug_init_1 (MonoDomain *domain); void mono_debug_init_2 (MonoAssembly *assembly); +void mono_debug_init_2_memory (MonoImage *image, const guint8 *raw_contents, int size); void mono_debug_cleanup (void); gboolean mono_debug_using_mono_debugger (void); ---- Additional Comments From vargaz@gmail.com 2006-05-12 12:24:22 MST ---- martin, could you look at this ? ---- Additional Comments From joe@otee.dk 2006-06-30 10:16:56 MST ---- Could someone please review and apply this patch. ---- Additional Comments From miguel@ximian.com 2006-07-15 16:24:54 MST ---- Hello Joachim, I will ask martin to review this patch, but before we can incorporate this patch into the Mono runtime, we would need to get a copyright assignment form that allows us to redistribute this code under a proprietary license. Alternatively, you can submit your patch under the MIT X11 terms, although a signed document would be best. Martin, can you please review this patch? ---- Additional Comments From martin@ximian.com 2006-07-18 11:59:57 MST ---- Created an attachment (id=169827) . ---- Additional Comments From martin@ximian.com 2006-07-18 12:01:38 MST ---- The patch looks good, but it requires a ChangeLog entry. When committing, please use the attached version, not the inline one. I fixed some small coding style buglets. ---- Additional Comments From martin@ximian.com 2006-07-18 12:09:38 MST ---- Btw. when making patches, it is better to attach them rather than posting them inline. If you attach them, all line endings get preserved while inlining it might add a few extra line breaks, so it can't be cut&pasted as a valid patch file anymore. ---- Additional Comments From martin@ximian.com 2006-07-18 14:21:34 MST ---- Ok, I okayed this bug a bit too quickly - this might possibly break the debugger. Still investigating the problem .... ---- Additional Comments From martin@ximian.com 2006-07-21 05:15:40 MST ---- Confirmed as breaking the debugger. ---- Additional Comments From martin@ximian.com 2006-07-21 05:27:21 MST ---- Created an attachment (id=169828) Working patch ---- Additional Comments From martin@ximian.com 2006-07-21 05:28:08 MST ---- Miguel, can I commit this ? ---- Additional Comments From miguel@ximian.com 2006-08-25 12:57:32 MST ---- This patch is now ok to commit; We received the fax ---- Additional Comments From martin@ximian.com 2006-08-30 10:21:32 MST ---- The patch is now in SVN. Imported an attachment (id=169827) Imported an attachment (id=169828) Unknown operating system unknown. Setting to default OS "Other".