[Mono-devel-list] [patch]New patch for error reporting when loading unmanaged libraries

Denis Gervalle dgl at softec.st
Tue May 18 18:13:02 EDT 2004


I have already reviewed my last proposal, and here is a better and I 
hope last patch. Additionaly to previous enhancement, I have added 
detailled report of which entry point has been search, and what have failed.

Denis Gervalle
SOFTEC sa
http://www.softec.st

Denis Gervalle wrote:
> Here is a new patch proposal against mono 0.91 for reporting detailled 
> informations when loading unmanaged libraries. This patch integrates all 
> remarks received from my previous proposal (thx to Paolo Molaro and 
> Josuah Tauberer):
>    - Only reports details when MONO_DEBUG is set
>    - Function signature is unchanged since exc_msg is only freeable when 
> MONO_DEBUG is set, and this is only useful on prelink. This is not 
> perfect, I know.
>    - Message is currently composed using a GString with 
> g_string_append(), but an approach with g_printf or similar is also 
> possible (no more time to try that)
>    - Message now include the name of the tried library before each error 
> message
>    - EntryPointNotFoundException also report details about what happens 
> during library loading.
> 
> Sorry, but the diff also contains a few 'warning' fix I have in my own 
> tree that is unrelated of course and that may have been fixed in cvs.
> 
> Hope that this one is a better try that will reach cvs :)
> 
> Denis Gervalle
> SOFTEC sa
> http://www.softec.st
> 
> 
> ------------------------------------------------------------------------
> 
> diff -ru mono-0.91-orig/mono/metadata/icall.c mono-0.91/mono/metadata/icall.c
> --- mono-0.91-orig/mono/metadata/icall.c	2004-05-04 21:51:24.000000000 +0200
> +++ mono-0.91/mono/metadata/icall.c	2004-05-18 20:45:57.000000000 +0200
> @@ -3044,7 +3044,7 @@
>  ves_icall_System_Reflection_Assembly_load_with_partial_name (MonoString *mname, MonoObject *evidence)
>  {
>  	gchar *name;
> -	MonoReflectionAssembly *res;
> +	MonoAssembly *res;
>  	MonoImageOpenStatus status;
>  	
>  	MONO_ARCH_SAVE_REGS;
> @@ -4475,19 +4475,19 @@
>  	/* g_print ("charset: %s\n", cset); */
>  	
>  	/* handle some common aliases */
> -	p = encodings [0];
> +	p = (char *)encodings [0];
>  	code = 0;
>  	for (i = 0; p != 0; ){
>  		if ((int) p < 7){
>  			code = (int) p;
> -			p = encodings [++i];
> +			p = (char *)encodings [++i];
>  			continue;
>  		}
>  		if (strcmp (p, codepage) == 0){
>  			*int_code_page = code;
>  			break;
>  		}
> -		p = encodings [++i];
> +		p = (char *)encodings [++i];
>  	}
>  	
>  	if (p - codepage > 5){
> @@ -4843,8 +4843,10 @@
>  		return;
>  	mono_lookup_pinvoke_call (method, &exc_class, &exc_arg);
>  	if (exc_class) {
> -		mono_raise_exception( 
> -			mono_exception_from_name_msg (mono_defaults.corlib, "System", exc_class, exc_arg ) );
> +		MonoException *exc = mono_exception_from_name_msg (mono_defaults.corlib, "System", exc_class, exc_arg );
> +		if(getenv("MONO_DEBUG"))
> +			g_free((gpointer)exc_arg);
> +		mono_raise_exception (exc);
>  	}
>  	/* create the wrapper, too? */
>  }
> @@ -4869,10 +4871,10 @@
>  }
>  
>  static void
> -ves_icall_System_Char_GetDataTablePointers (guint8 **category_data, guint8 **numeric_data,
> -		gdouble **numeric_data_values, guint16 **to_lower_data_low,
> -		guint16 **to_lower_data_high, guint16 **to_upper_data_low,
> -		guint16 **to_upper_data_high)
> +ves_icall_System_Char_GetDataTablePointers (const guint8 **category_data, const guint8 **numeric_data,
> +		const gdouble **numeric_data_values, const guint16 **to_lower_data_low,
> +		const guint16 **to_lower_data_high, const guint16 **to_upper_data_low,
> +		const guint16 **to_upper_data_high)
>  {
>  	*category_data = CategoryData;
>  	*numeric_data = NumericData;
> diff -ru mono-0.91-orig/mono/metadata/loader.c mono-0.91/mono/metadata/loader.c
> --- mono-0.91-orig/mono/metadata/loader.c	2004-04-15 16:51:58.000000000 +0200
> +++ mono-0.91/mono/metadata/loader.c	2004-05-18 22:26:01.684890258 +0200
> @@ -316,8 +316,6 @@
>  		mono_metadata_free_method_signature (sig);
>  		return method;
>  	case MEMBERREF_PARENT_TYPESPEC: {
> -		guint32 bcols [MONO_TYPESPEC_SIZE];
> -		guint32 len;
>  		MonoType *type;
>  		MonoMethod *result;
>  		MonoClass *klass;
> @@ -550,6 +548,26 @@
>  
>  static int wine_test_needed = 1;
>  
> +GModule *
> +mono_module_open(const char *filename, GString *errors)
> +{
> +	GModule *module;
> +
> +	module = g_module_open (filename, G_MODULE_BIND_LAZY);
> +    
> +	if(!module && errors) {
> +		if( errors->len )
> +			g_string_append (errors, " ==> ");
> +    
> +		g_string_append (errors, "Trying '");
> +		g_string_append (errors, filename);
> +		g_string_append (errors, "': ");
> +		g_string_append (errors, g_module_error());
> +	}
> +
> +	return module;
> +}
> +    
>  gpointer
>  mono_lookup_pinvoke_call (MonoMethod *method, const char **exc_class, const char **exc_arg)
>  {
> @@ -566,6 +584,7 @@
>  	char *full_name, *file_name;
>  	int i;
>  	GModule *gmodule = NULL;
> +	GString *errors = NULL;
>  
>  	g_assert (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL);
>  
> @@ -596,6 +615,10 @@
>  		wine_test_needed = 0;
>  	}
>  	
> +	// Enable detailed error reporting
> +	if(getenv("MONO_DEBUG") && exc_class)
> +		errors = g_string_new("");
> +	
>  	/*
>  	 * Try loading the module using a variety of names
>  	 */
> @@ -615,18 +638,18 @@
>  
>  		if (!gmodule) {
>  			full_name = g_module_build_path (NULL, file_name);
> -			gmodule = g_module_open (full_name, G_MODULE_BIND_LAZY);
> +			gmodule = mono_module_open (full_name, errors);
>  			g_free (full_name);
>  		}
>  
>  		if (!gmodule) {
>  			full_name = g_module_build_path (".", file_name);
> -			gmodule = g_module_open (full_name, G_MODULE_BIND_LAZY);
> +			gmodule = mono_module_open (full_name, errors);
>  			g_free (full_name);
>  		}
>  
>  		if (!gmodule) {
> -			gmodule=g_module_open (file_name, G_MODULE_BIND_LAZY);
> +			gmodule = mono_module_open (file_name, errors);
>  		}
>  
>  		g_free (file_name);
> @@ -636,13 +659,15 @@
>  	}
>  
>  	if (!gmodule) {
> -		gchar *error = g_strdup (g_module_error ());
> -
>  		if (exc_class) {
>  			*exc_class = "DllNotFoundException";
> -			*exc_arg = orig_scope;
> +			if (errors) {
> +				*exc_arg = errors->str;
> +				g_string_free (errors, FALSE);
> +			}
> +			else
> +				*exc_arg = orig_scope;
>  		}
> -		g_free (error);
>  		return NULL;
>  	}
>  
> @@ -679,10 +704,21 @@
>  	if (!method->addr) {
>  		if (exc_class) {
>  			*exc_class = "EntryPointNotFoundException";
> -			*exc_arg = import;
> +			if (errors) {
> +				g_string_append(" ==> Searching function '");
> +				g_string_append(import);
> +				*exc_arg = errors->str;
> +				g_string_free (errors, FALSE);
> +			}
> +			else
> +				*exc_arg = import;
>  		}
>  		return NULL;
>  	}
> +
> +	if( errors )
> +		g_string_free (errors, TRUE);
> +	
>  	return method->addr;
>  }
>  
> @@ -856,7 +892,6 @@
>  {
>  	MonoMethod *method, *result;
>  	MonoClass *ic = NULL;
> -	int i;
>  
>  	mono_loader_lock ();
>  
> @@ -1110,14 +1145,14 @@
>  mono_loader_wine_init ()
>  {
>  	GModule *module = g_module_open ("winelib.exe.so", G_MODULE_BIND_LAZY);
> -	int (*shared_wine_init)();
> +	int (*shared_wine_init)(void);
>  
>  	if (module == NULL){
>  		fprintf (stderr, "Could not load winelib.exe.so");
>  		return;
>  	}
>  
> -	g_module_symbol (module, "SharedWineInit", &shared_wine_init);
> +	g_module_symbol (module, "SharedWineInit", (gpointer *) &shared_wine_init);
>  	if (shared_wine_init == NULL)
>  		return;
>  
> diff -ru mono-0.91-orig/mono/metadata/loader.h mono-0.91/mono/metadata/loader.h
> --- mono-0.91-orig/mono/metadata/loader.h	2004-04-26 22:38:12.000000000 +0200
> +++ mono-0.91/mono/metadata/loader.h	2004-05-18 20:45:57.313189652 +0200
> @@ -167,6 +167,9 @@
>  void
>  mono_dllmap_insert (MonoImage *assembly, const char *dll, const char *func, const char *tdll, const char *tfunc);
>  
> +GModule *
> +mono_module_open(const char *filename, GString *errors);
> +
>  gpointer
>  mono_lookup_pinvoke_call (MonoMethod *method, const char **exc_class, const char **exc_arg);
>  
-------------- next part --------------
A non-text attachment was scrubbed...
Name: loadmodule3.unified.diff.patch
Type: text/x-patch
Size: 8108 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20040519/b021d5ec/attachment.bin 


More information about the Mono-devel-list mailing list