+static char *
+string_to_utf8 (MonoString *s)
+{
+ char *as;
+ GError *error = NULL;
+
+ g_assert (s);
+
+ if (!s->length)
+ return g_strdup ("");
+
+ as = g_utf16_to_utf8 (mono_string_chars (s), s->length, NULL, NULL, &error);
+ if (error) {
+ /* Happens with StringBuilders */
+ g_error_free (error);
+ return g_strdup ("<INVALID UTF8>");
+ }
+ else
+ return as;
+}
+
+/*
+ * cpos (ebp + arg_info[n].offset) points to the beginning of the
+ * stack slot for this argument. On little-endian systems, we can
+ * simply dereference it. On big-endian systems, we need to adjust
+ * cpos upward first if the datatype we're referencing is smaller than
+ * a stack slot. Also - one can't assume that gpointer is also the
+ * size of a stack slot - use SIZEOF_REGISTER instead. The following
+ * helper macro tries to keep down the mess of all the pointer
+ * calculations.
+ */
+#if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
+#define arg_in_stack_slot(cpos, type) ((type *)(cpos))
+#else
+#define arg_in_stack_slot(cpos, type) ((type *)((sizeof(type) < SIZEOF_REGISTER) ? (((gssize)(cpos)) + SIZEOF_REGISTER - sizeof(type)) : (gssize)(cpos)))
+#endif