Merge pull request #444 from knocte/xbuild_improvements
[mono.git] / mono / metadata / exception.c
1 /*
2  * exception.c: Exception handling
3  *
4  * Authors:
5  *      Paolo Molaro    (lupus@ximian.com)
6  *      Dietmar Maurer  (dietmar@ximian.com)
7  *      Dick Porter     (dick@ximian.com)
8  *      Miguel de Icaza (miguel@ximian.com)
9  *
10  * Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
11  * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
12  */
13
14 #include <mono/metadata/exception.h>
15 #include <mono/metadata/object-internals.h>
16 #include <mono/metadata/metadata-internals.h>
17 #include <mono/metadata/appdomain.h>
18 #include <mono/metadata/mono-debug.h>
19 #include <string.h>
20
21 #ifdef HAVE_EXECINFO_H
22 #include <execinfo.h>
23 #endif
24
25 /**
26  * mono_exception_from_name:
27  * @image: the Mono image where to look for the class
28  * @name_space: the namespace for the class
29  * @name: class name
30  *
31  * Creates an exception of the given namespace/name class in the
32  * current domain.
33  *
34  * Returns: the initialized exception instance.
35  */
36 MonoException *
37 mono_exception_from_name (MonoImage *image, const char *name_space,
38                           const char *name)
39 {
40         return mono_exception_from_name_domain (mono_domain_get (), image, name_space, name);
41 }
42
43 /**
44  * mono_exception_from_name_domain:
45  * @domain: Domain where the return object will be created.
46  * @image: the Mono image where to look for the class
47  * @name_space: the namespace for the class
48  * @name: class name
49  *
50  * Creates an exception object of the given namespace/name class on
51  * the given domain.
52  *
53  * Returns: the initialized exception instance.
54  */
55 MonoException *
56 mono_exception_from_name_domain (MonoDomain *domain, MonoImage *image, 
57                                  const char* name_space, const char *name)
58 {
59         MonoClass *klass;
60         MonoObject *o;
61         MonoDomain *caller_domain = mono_domain_get ();
62
63         klass = mono_class_from_name (image, name_space, name);
64
65         o = mono_object_new (domain, klass);
66         g_assert (o != NULL);
67
68         if (domain != caller_domain)
69                 mono_domain_set_internal (domain);
70         mono_runtime_object_init (o);
71         if (domain != caller_domain)
72                 mono_domain_set_internal (caller_domain);
73
74         return (MonoException *)o;
75 }
76
77
78 /**
79  * mono_exception_from_token:
80  * @image: the Mono image where to look for the class
81  * @token: The type token of the class
82  *
83  * Creates an exception of the type given by @token.
84  *
85  * Returns: the initialized exception instance.
86  */
87 MonoException *
88 mono_exception_from_token (MonoImage *image, guint32 token)
89 {
90         MonoClass *klass;
91         MonoObject *o;
92
93         klass = mono_class_get (image, token);
94
95         o = mono_object_new (mono_domain_get (), klass);
96         g_assert (o != NULL);
97         
98         mono_runtime_object_init (o);
99
100         return (MonoException *)o;
101 }
102
103 static MonoException *
104 create_exception_two_strings (MonoClass *klass, MonoString *a1, MonoString *a2)
105 {
106         MonoDomain *domain = mono_domain_get ();
107         MonoMethod *method = NULL;
108         MonoObject *o;
109         int count = 1;
110         gpointer args [2];
111         gpointer iter;
112         MonoMethod *m;
113
114         if (a2 != NULL)
115                 count++;
116         
117         o = mono_object_new (domain, klass);
118
119         iter = NULL;
120         while ((m = mono_class_get_methods (klass, &iter))) {
121                 MonoMethodSignature *sig;
122                 
123                 if (strcmp (".ctor", mono_method_get_name (m)))
124                         continue;
125                 sig = mono_method_signature (m);
126                 if (sig->param_count != count)
127                         continue;
128
129                 if (sig->params [0]->type != MONO_TYPE_STRING)
130                         continue;
131                 if (count == 2 && sig->params [1]->type != MONO_TYPE_STRING)
132                         continue;
133                 method = m;
134                 break;
135         }
136
137         args [0] = a1;
138         args [1] = a2;
139         mono_runtime_invoke (method, o, args, NULL);
140         return (MonoException *) o;
141 }
142
143 /**
144  * mono_exception_from_name_two_strings:
145  * @image: the Mono image where to look for the class
146  * @name_space: the namespace for the class
147  * @name: class name
148  * @a1: first string argument to pass
149  * @a2: second string argument to pass
150  *
151  * Creates an exception from a constructor that takes two string
152  * arguments.
153  *
154  * Returns: the initialized exception instance.
155  */
156 MonoException *
157 mono_exception_from_name_two_strings (MonoImage *image, const char *name_space,
158                                       const char *name, MonoString *a1, MonoString *a2)
159 {
160         MonoClass *klass = mono_class_from_name (image, name_space, name);
161
162         return create_exception_two_strings (klass, a1, a2);
163 }
164
165 /**
166  * mono_exception_from_name_msg:
167  * @image: the Mono image where to look for the class
168  * @name_space: the namespace for the class
169  * @name: class name
170  * @msg: the message to embed inside the exception
171  *
172  * Creates an exception and initializes its message field.
173  *
174  * Returns: the initialized exception instance.
175  */
176 MonoException *
177 mono_exception_from_name_msg (MonoImage *image, const char *name_space,
178                               const char *name, const char *msg)
179 {
180         MonoException *ex;
181
182         ex = mono_exception_from_name (image, name_space, name);
183
184         if (msg)
185                 MONO_OBJECT_SETREF (ex, message, mono_string_new (mono_object_get_domain ((MonoObject*)ex), msg));
186
187         return ex;
188 }
189
190 /**
191  * mono_exception_from_token_two_strings:
192  *
193  *   Same as mono_exception_from_name_two_strings, but lookup the exception class using
194  * IMAGE and TOKEN.
195  */
196 MonoException *
197 mono_exception_from_token_two_strings (MonoImage *image, guint32 token,
198                                                                            MonoString *a1, MonoString *a2)
199 {
200         MonoClass *klass = mono_class_get (image, token);
201
202         return create_exception_two_strings (klass, a1, a2);
203 }
204
205 /**
206  * mono_get_exception_divide_by_zero:
207  *
208  * Returns: a new instance of the System.DivideByZeroException
209  */
210 MonoException *
211 mono_get_exception_divide_by_zero ()
212 {
213         return mono_exception_from_name (mono_get_corlib (), "System",
214                                          "DivideByZeroException");
215 }
216
217 /**
218  * mono_get_exception_security:
219  *
220  * Returns: a new instance of the System.Security.SecurityException
221  */
222 MonoException *
223 mono_get_exception_security ()
224 {
225         return mono_exception_from_name (mono_get_corlib (), "System.Security",
226                                          "SecurityException");
227 }
228
229 /**
230  * mono_get_exception_thread_abort:
231  *
232  * Returns: a new instance of the System.Threading.ThreadAbortException.
233  */
234 MonoException *
235 mono_get_exception_thread_abort ()
236 {
237         return mono_exception_from_name (mono_get_corlib (), "System.Threading",
238                                          "ThreadAbortException");
239 }
240
241 /**
242  * mono_get_exception_thread_interrupted:
243  *
244  * Returns: a new instance of the System.Threading.ThreadInterruptedException.
245  */
246 MonoException *
247 mono_get_exception_thread_interrupted ()
248 {
249         return mono_exception_from_name (mono_get_corlib (), "System.Threading",
250                                          "ThreadInterruptedException");
251 }
252
253 /**
254  * mono_get_exception_arithmetic:
255  *
256  * Returns: a new instance of the System.ArithmeticException.
257  */
258 MonoException *
259 mono_get_exception_arithmetic ()
260 {
261         return mono_exception_from_name (mono_get_corlib (), "System",
262                                          "ArithmeticException");
263 }
264
265 /**
266  * mono_get_exception_overflow:
267  *
268  * Returns: a new instance of the System.OverflowException
269  */
270 MonoException *
271 mono_get_exception_overflow ()
272 {
273         return mono_exception_from_name (mono_get_corlib (), "System",
274                                          "OverflowException");
275 }
276
277 /**
278  * mono_get_exception_null_reference:
279  *
280  * Returns: a new instance of the System.NullReferenceException
281  */
282 MonoException *
283 mono_get_exception_null_reference ()
284 {
285         return mono_exception_from_name (mono_get_corlib (), "System",
286                                          "NullReferenceException");
287 }
288
289 /**
290  * mono_get_exception_execution_engine:
291  * @msg: the message to pass to the user
292  *
293  * Returns: a new instance of the System.ExecutionEngineException
294  */
295 MonoException *
296 mono_get_exception_execution_engine (const char *msg)
297 {
298         return mono_exception_from_name_msg (mono_get_corlib (), "System", "ExecutionEngineException", msg);
299 }
300
301 /**
302  * mono_get_exception_serialization:
303  * @msg: the message to pass to the user
304  *
305  * Returns: a new instance of the System.Runtime.Serialization.SerializationException
306  */
307 MonoException *
308 mono_get_exception_serialization (const char *msg)
309 {
310         return mono_exception_from_name_msg (mono_get_corlib (), "System.Runtime.Serialization", "SerializationException", msg);
311 }
312
313 /**
314  * mono_get_exception_invalid_cast:
315  *
316  * Returns: a new instance of the System.InvalidCastException
317  */
318 MonoException *
319 mono_get_exception_invalid_cast ()
320 {
321         return mono_exception_from_name (mono_get_corlib (), "System", "InvalidCastException");
322 }
323
324 /**
325  * mono_get_exception_invalid_operation:
326  * @msg: the message to pass to the user
327  *
328  * Returns: a new instance of the System.InvalidOperationException
329  */
330 MonoException *
331 mono_get_exception_invalid_operation (const char *msg)
332 {
333         return mono_exception_from_name_msg (mono_get_corlib (), "System",
334                                         "InvalidOperationException", msg);
335 }
336
337 /**
338  * mono_get_exception_index_out_of_range:
339  *
340  * Returns: a new instance of the System.IndexOutOfRangeException
341  */
342 MonoException *
343 mono_get_exception_index_out_of_range ()
344 {
345         return mono_exception_from_name (mono_get_corlib (), "System",
346                                          "IndexOutOfRangeException");
347 }
348
349 /**
350  * mono_get_exception_array_type_mismatch:
351  *
352  * Returns: a new instance of the System.ArrayTypeMismatchException
353  */
354 MonoException *
355 mono_get_exception_array_type_mismatch ()
356 {
357         return mono_exception_from_name (mono_get_corlib (), "System",
358                                          "ArrayTypeMismatchException");
359 }
360
361 /**
362  * mono_get_exception_type_load:
363  * @class_name: the name of the class that could not be loaded
364  * @assembly_name: the assembly where the class was looked up.
365  *
366  * Returns: a new instance of the System.TypeLoadException.
367  */
368 MonoException *
369 mono_get_exception_type_load (MonoString *class_name, char *assembly_name)
370 {
371         MonoString *s = assembly_name ? mono_string_new (mono_domain_get (), assembly_name) : mono_string_new (mono_domain_get (), "");
372
373         return mono_exception_from_name_two_strings (mono_get_corlib (), "System",
374                                                      "TypeLoadException", class_name, s);
375 }
376
377 /**
378  * mono_get_exception_not_implemented:
379  * @msg: the message to pass to the user
380  *
381  * Returns: a new instance of the System.NotImplementedException
382  */
383 MonoException *
384 mono_get_exception_not_implemented (const char *msg)
385 {
386         return mono_exception_from_name_msg (mono_get_corlib (), "System", "NotImplementedException", msg);
387 }
388
389 /**
390  * mono_get_exception_not_supported:
391  * @msg: the message to pass to the user
392  *
393  * Returns: a new instance of the System.NotSupportedException
394  */
395 MonoException *
396 mono_get_exception_not_supported (const char *msg)
397 {
398         return mono_exception_from_name_msg (mono_get_corlib (), "System", "NotSupportedException", msg);
399 }
400
401 /**
402  * mono_get_exception_missing_method:
403  * @class_name: the class where the lookup was performed.
404  * @member_name: the name of the missing method.
405  *
406  * Returns: a new instance of the System.MissingMethodException
407  */
408 MonoException *
409 mono_get_exception_missing_method (const char *class_name, const char *member_name)
410 {
411         MonoString *s1 = mono_string_new (mono_domain_get (), class_name);
412         MonoString *s2 = mono_string_new (mono_domain_get (), member_name);
413
414         return mono_exception_from_name_two_strings (mono_get_corlib (), "System",
415                                                      "MissingMethodException", s1, s2);
416 }
417
418 /**
419  * mono_get_exception_missing_field:
420  * @class_name: the class where the lookup was performed
421  * @member_name: the name of the missing method.
422  *
423  * Returns: a new instance of the System.MissingFieldException
424  */
425 MonoException *
426 mono_get_exception_missing_field (const char *class_name, const char *member_name)
427 {
428         MonoString *s1 = mono_string_new (mono_domain_get (), class_name);
429         MonoString *s2 = mono_string_new (mono_domain_get (), member_name);
430
431         return mono_exception_from_name_two_strings (mono_get_corlib (), "System",
432                                                      "MissingFieldException", s1, s2);
433 }
434
435 /**
436  * mono_get_exception_argument_null:
437  * @arg: the name of the argument that is null
438  *
439  * Returns: a new instance of the System.ArgumentNullException
440  */
441 MonoException*
442 mono_get_exception_argument_null (const char *arg)
443 {
444         MonoException *ex;
445
446         ex = mono_exception_from_name ( 
447                 mono_get_corlib (), "System", "ArgumentNullException");
448
449         if (arg) {
450                 MonoArgumentException *argex = (MonoArgumentException *)ex;
451                 MONO_OBJECT_SETREF (argex, param_name, mono_string_new (mono_object_get_domain ((MonoObject*)ex), arg));
452         }
453         
454         return ex;
455 }
456
457 /**
458  * mono_get_exception_argument:
459  * @arg: the name of the invalid argument.
460  *
461  * Returns: a new instance of the System.ArgumentException
462  */
463 MonoException *
464 mono_get_exception_argument (const char *arg, const char *msg)
465 {
466         MonoException *ex;
467
468         ex = mono_exception_from_name_msg (
469                 mono_get_corlib (), "System", "ArgumentException", msg);
470
471         if (arg) {
472                 MonoArgumentException *argex = (MonoArgumentException *)ex;
473                 MONO_OBJECT_SETREF (argex, param_name, mono_string_new (mono_object_get_domain ((MonoObject*)ex), arg));
474         }
475         
476         return ex;
477 }
478
479 /**
480  * mono_get_exception_argument_out_of_range:
481  * @arg: the name of the out of range argument.
482  *
483  * Returns: a new instance of the System.ArgumentOutOfRangeException
484  */
485 MonoException *
486 mono_get_exception_argument_out_of_range (const char *arg)
487 {
488         MonoException *ex;
489
490         ex = mono_exception_from_name (
491                 mono_get_corlib (), "System", "ArgumentOutOfRangeException");
492
493         if (arg) {
494                 MonoArgumentException *argex = (MonoArgumentException *)ex;
495                 MONO_OBJECT_SETREF (argex, param_name, mono_string_new (mono_object_get_domain ((MonoObject*)ex), arg));
496         }
497         
498         return ex;
499 }
500
501 /**
502  * mono_get_exception_thread_state:
503  * @msg: the message to present to the user
504  *
505  * Returns: a new instance of the System.Threading.ThreadStateException
506  */
507 MonoException *
508 mono_get_exception_thread_state (const char *msg)
509 {
510         return mono_exception_from_name_msg (
511                 mono_get_corlib (), "System.Threading", "ThreadStateException", msg);
512 }
513
514 /**
515  * mono_get_exception_io:
516  * @msg: the message to present to the user
517  *
518  * Returns: a new instance of the System.IO.IOException
519  */
520 MonoException *
521 mono_get_exception_io (const char *msg)
522 {
523         return mono_exception_from_name_msg ( 
524                 mono_get_corlib (), "System.IO", "IOException", msg);
525 }
526
527 /**
528  * mono_get_exception_file_not_found:
529  * @fname: the name of the file not found.
530  *
531  * Returns: a new instance of the System.IO.FileNotFoundException
532  */
533 MonoException *
534 mono_get_exception_file_not_found (MonoString *fname)
535 {
536         return mono_exception_from_name_two_strings (
537                 mono_get_corlib (), "System.IO", "FileNotFoundException", fname, fname);
538 }
539
540 /**
541  * mono_get_exception_file_not_found2:
542  * @msg: an informative message for the user.
543  * @fname: the name of the file not found.
544  *
545  * Returns: a new instance of the System.IO.FileNotFoundException
546  */
547 MonoException *
548 mono_get_exception_file_not_found2 (const char *msg, MonoString *fname)
549 {
550         MonoString *s = msg ? mono_string_new (mono_domain_get (), msg) : NULL;
551
552         return mono_exception_from_name_two_strings (
553                 mono_get_corlib (), "System.IO", "FileNotFoundException", s, fname);
554 }
555
556 /**
557  * mono_get_exception_type_initialization:
558  * @type_name: the name of the type that failed to initialize.
559  * @inner: the inner exception.
560  *
561  * Returns: a new instance of the System.TypeInitializationException
562  */
563 MonoException *
564 mono_get_exception_type_initialization (const gchar *type_name, MonoException *inner)
565 {
566         MonoClass *klass;
567         gpointer args [2];
568         MonoObject *exc;
569         MonoMethod *method;
570         gpointer iter;
571
572         klass = mono_class_from_name (mono_get_corlib (), "System", "TypeInitializationException");
573         g_assert (klass);
574
575         mono_class_init (klass);
576
577         /* TypeInitializationException only has 1 ctor with 2 args */
578         iter = NULL;
579         while ((method = mono_class_get_methods (klass, &iter))) {
580                 if (!strcmp (".ctor", mono_method_get_name (method)) && mono_method_signature (method)->param_count == 2)
581                         break;
582                 method = NULL;
583         }
584
585         g_assert (method);
586
587         args [0] = mono_string_new (mono_domain_get (), type_name);
588         args [1] = inner;
589
590         exc = mono_object_new (mono_domain_get (), klass);
591         mono_runtime_invoke (method, exc, args, NULL);
592
593         return (MonoException *) exc;
594 }
595
596 /**
597  * mono_get_exception_synchronization_lock:
598  * @inner: the inner exception.
599  *
600  * Returns: a new instance of the System.SynchronizationLockException
601  */
602 MonoException *
603 mono_get_exception_synchronization_lock (const char *msg)
604 {
605         return mono_exception_from_name_msg (mono_get_corlib (), "System.Threading", "SynchronizationLockException", msg);
606 }
607
608 /**
609  * mono_get_exception_cannot_unload_appdomain:
610  * @inner: the inner exception.
611  *
612  * Returns: a new instance of the System.CannotUnloadAppDomainException
613  */
614 MonoException *
615 mono_get_exception_cannot_unload_appdomain (const char *msg)
616 {
617         return mono_exception_from_name_msg (mono_get_corlib (), "System", "CannotUnloadAppDomainException", msg);
618 }
619
620 /**
621  * mono_get_exception_appdomain_unloaded
622  *
623  * Returns: a new instance of the System.AppDomainUnloadedException
624  */
625 MonoException *
626 mono_get_exception_appdomain_unloaded (void)
627 {
628         return mono_exception_from_name (mono_get_corlib (), "System", "AppDomainUnloadedException");
629 }
630
631 /**
632  * mono_get_exception_bad_image_format:
633  * @msg: an informative message for the user.
634  *
635  * Returns: a new instance of the System.BadImageFormatException
636  */
637 MonoException *
638 mono_get_exception_bad_image_format (const char *msg)
639 {
640         return mono_exception_from_name_msg (mono_get_corlib (), "System", "BadImageFormatException", msg);
641 }       
642
643 /**
644  * mono_get_exception_bad_image_format2:
645  * @msg: an informative message for the user.
646  * @fname: The full name of the file with the invalid image.
647  *
648  * Returns: a new instance of the System.BadImageFormatException
649  */
650 MonoException *
651 mono_get_exception_bad_image_format2 (const char *msg, MonoString *fname)
652 {
653         MonoString *s = msg ? mono_string_new (mono_domain_get (), msg) : NULL;
654
655         return mono_exception_from_name_two_strings (
656                 mono_get_corlib (), "System", "BadImageFormatException", s, fname);
657 }
658
659 /**
660  * mono_get_exception_stack_overflow:
661  *
662  * Returns: a new instance of the System.StackOverflowException
663  */
664 MonoException *
665 mono_get_exception_stack_overflow (void)
666 {
667         return mono_exception_from_name (mono_get_corlib (), "System", "StackOverflowException");       
668 }
669
670 /**
671  * mono_get_exception_out_of_memory:
672  *
673  * Returns: a new instance of the System.OutOfMemoryException
674  */
675 MonoException *
676 mono_get_exception_out_of_memory (void)
677 {
678         return mono_exception_from_name (mono_get_corlib (), "System", "OutOfMemoryException");
679 }
680
681 /**
682  * mono_get_exception_field_access:
683  *
684  * Returns: a new instance of the System.FieldAccessException
685  */
686 MonoException *
687 mono_get_exception_field_access (void)
688 {
689         return mono_exception_from_name (mono_get_corlib (), "System", "FieldAccessException");
690 }
691
692 /**
693  * mono_get_exception_field_access2:
694  * @msg: an informative message for the user.
695  *
696  * Returns: a new instance of the System.FieldAccessException
697  */
698 MonoException *
699 mono_get_exception_field_access_msg (const char *msg)
700 {
701         return mono_exception_from_name_msg (mono_get_corlib (), "System", "FieldAccessException", msg);
702 }
703
704 /**
705  * mono_get_exception_method_access:
706  *
707  * Returns: a new instance of the System.MethodAccessException
708  */
709 MonoException *
710 mono_get_exception_method_access (void)
711 {
712         return mono_exception_from_name (mono_get_corlib (), "System", "MethodAccessException");
713 }
714
715 /**
716  * mono_get_exception_method_access2:
717  * @msg: an informative message for the user.
718  *
719  * Returns: a new instance of the System.MethodAccessException
720  */
721 MonoException *
722 mono_get_exception_method_access_msg (const char *msg)
723 {
724         return mono_exception_from_name_msg (mono_get_corlib (), "System", "MethodAccessException", msg);
725 }
726
727 /**
728  * mono_get_exception_reflection_type_load:
729  * @types: an array of types that were defined in the moduled loaded.
730  * @exceptions: an array of exceptions that were thrown during the type loading.
731  *
732  * Returns: a new instance of the System.Reflection.ReflectionTypeLoadException
733  */
734 MonoException *
735 mono_get_exception_reflection_type_load (MonoArray *types, MonoArray *exceptions)
736 {
737         MonoClass *klass;
738         gpointer args [2];
739         MonoObject *exc;
740         MonoMethod *method;
741
742         klass = mono_class_from_name (mono_get_corlib (), "System.Reflection", "ReflectionTypeLoadException");
743         g_assert (klass);
744         mono_class_init (klass);
745
746         method = mono_class_get_method_from_name (klass, ".ctor", 2);
747         g_assert (method);
748
749         args [0] = types;
750         args [1] = exceptions;
751
752         exc = mono_object_new (mono_domain_get (), klass);
753         mono_runtime_invoke (method, exc, args, NULL);
754
755         return (MonoException *) exc;
756 }
757
758 MonoException *
759 mono_get_exception_runtime_wrapped (MonoObject *wrapped_exception)
760 {
761         MonoRuntimeWrappedException *ex = (MonoRuntimeWrappedException*)
762                 mono_exception_from_name (mono_get_corlib (), "System.Runtime.CompilerServices",
763                                                                   "RuntimeWrappedException");
764
765    MONO_OBJECT_SETREF (ex, wrapped_exception, wrapped_exception);
766    return (MonoException*)ex;
767 }       
768
769 char *
770 mono_exception_get_native_backtrace (MonoException *exc)
771 {
772 #ifdef HAVE_BACKTRACE_SYMBOLS
773         MonoDomain *domain;
774         MonoArray *arr = exc->native_trace_ips;
775         int i, len;
776         GString *text;
777         char **messages;
778
779         if (!arr)
780                 return g_strdup ("");
781         domain = mono_domain_get ();
782         len = mono_array_length (arr);
783         text = g_string_new_len (NULL, len * 20);
784         messages = backtrace_symbols (mono_array_addr (arr, gpointer, 0), len);
785
786
787         for (i = 0; i < len; ++i) {
788                 gpointer ip = mono_array_get (arr, gpointer, i);
789                 MonoJitInfo *ji = mono_jit_info_table_find (mono_domain_get (), ip);
790                 if (ji) {
791                         char *msg = mono_debug_print_stack_frame (ji->method, (char*)ip - (char*)ji->code_start, domain);
792                         g_string_append_printf (text, "%s\n", msg);
793                         g_free (msg);
794                 } else {
795                         g_string_append_printf (text, "%s\n", messages [i]);
796                 }
797         }
798
799         free (messages);
800         return g_string_free (text, FALSE);
801 #else
802         return g_strdup ("");
803 #endif
804 }
805
806 MonoString *
807 ves_icall_Mono_Runtime_GetNativeStackTrace (MonoException *exc)
808 {
809         char *trace;
810         MonoString *res;
811         if (!exc)
812                 mono_raise_exception (mono_get_exception_argument_null ("exception"));
813
814         trace = mono_exception_get_native_backtrace (exc);
815         res = mono_string_new (mono_domain_get (), trace);
816         g_free (trace);
817         return res;
818 }