Merge pull request #4621 from alexanderkyte/strdup_env
[mono.git] / mono / mini / helpers.c
index 43bd17e2fa499d3fe6904a97f71492646718b10b..7f681b23bb5ba355da140cd5fb52c4b0fac81acb 100644 (file)
@@ -1,5 +1,6 @@
-/*
- * helpers.c: Assorted routines
+/**
+ * \file
+ * Assorted routines
  *
  * (C) 2003 Ximian, Inc.
  */
@@ -66,7 +67,7 @@ opnames[] = {
 #endif /* DISABLE_LOGGING */
 
 #if defined(__i386__) || defined(__x86_64__)
-#ifndef TARGET_ARM64
+#if !defined(TARGET_ARM64) && !defined(__APPLE__)
 #define emit_debug_info  TRUE
 #else
 #define emit_debug_info  FALSE
@@ -99,6 +100,7 @@ mono_inst_name (int op) {
        g_error ("unknown opcode name for %d", op);
        return NULL;
 #else
+       g_error ("unknown opcode name for %d", op);
        g_assert_not_reached ();
 #endif
 }
@@ -124,10 +126,9 @@ mono_blockset_print (MonoCompile *cfg, MonoBitSet *set, const char *name, guint
 }
 
 /**
- * mono_disassemble_code:
- * @cfg: compilation context
- * @code: a pointer to the code
- * @size: the code size in bytes
+ * \param cfg compilation context
+ * \param code a pointer to the code
+ * \param size the code size in bytes
  *
  * Disassemble to code to stdout.
  */
@@ -144,11 +145,11 @@ mono_disassemble_code (MonoCompile *cfg, guint8 *code, int size, char *id)
 #ifdef HOST_WIN32
        const char *tmp = g_get_tmp_dir ();
 #endif
-       const char *objdump_args = g_getenv ("MONO_OBJDUMP_ARGS");
+       char *objdump_args = g_getenv ("MONO_OBJDUMP_ARGS");
        char *as_file;
        char *o_file;
        char *cmd;
-       int unused;
+       int unused G_GNUC_UNUSED;
 
 #ifdef HOST_WIN32
        as_file = g_strdup_printf ("%s/test.s", tmp);    
@@ -214,8 +215,14 @@ mono_disassemble_code (MonoCompile *cfg, guint8 *code, int size, char *id)
 #else
 #if defined(sparc) && !defined(__GNUC__)
 #define DIS_CMD "dis"
-#elif defined(__i386__) || defined(__x86_64__)
+#elif defined(TARGET_X86)
 #define DIS_CMD "objdump -l -d"
+#elif defined(TARGET_AMD64)
+  #if defined(HOST_WIN32)
+  #define DIS_CMD "x86_64-w64-mingw32-objdump.exe -M x86-64 -d"
+  #else
+  #define DIS_CMD "objdump -l -d"
+  #endif
 #else
 #define DIS_CMD "objdump -d"
 #endif
@@ -264,11 +271,12 @@ mono_disassemble_code (MonoCompile *cfg, guint8 *code, int size, char *id)
        close (i);
 #endif
 
+#ifdef HAVE_SYSTEM
        cmd = g_strdup_printf (ARCH_PREFIX AS_CMD " %s -o %s", as_file, o_file);
        unused = system (cmd); 
        g_free (cmd);
        if (!objdump_args)
-               objdump_args = "";
+               objdump_args = g_strdup ("");
 
        fflush (stdout);
 
@@ -281,10 +289,14 @@ mono_disassemble_code (MonoCompile *cfg, guint8 *code, int size, char *id)
        unused = system (cmd);
        g_free (cmd);
 #endif
-       
+
        cmd = g_strdup_printf (ARCH_PREFIX DIS_CMD " %s %s", objdump_args, o_file);
        unused = system (cmd);
        g_free (cmd);
+       g_free (objdump_args);
+#else
+       g_assert_not_reached ();
+#endif /* HAVE_SYSTEM */
 
 #ifndef HOST_WIN32
        unlink (o_file);