Merge pull request #2409 from rolfbjarne/parse-debug-options-api
authorJoão Matos <joao@tritao.eu>
Fri, 8 Jan 2016 13:39:22 +0000 (13:39 +0000)
committerJoão Matos <joao@tritao.eu>
Fri, 8 Jan 2016 13:39:22 +0000 (13:39 +0000)
[runtime] Add API to set debug options without going through MONO_DEBUG.

1  2 
mono/mini/mini-runtime.c

diff --combined mono/mini/mini-runtime.c
index 902ccdca4b839008945bde22a7ac3712e4fa3e1f,cb1dc353b0681c4d68f84919f21043dad62fba7e..23c62d8092b036e30dc3a614ccb22c50b404c721
@@@ -2156,6 -2156,18 +2156,6 @@@ typedef struct 
        gpointer *wrapper_arg;
  } RuntimeInvokeInfo;
  
 -gboolean
 -mini_gsharedvt_runtime_invoke_supported (MonoMethodSignature *sig)
 -{
 -      gboolean supported = TRUE;
 -
 -      // FIXME:
 -      if (sig->ret->type == MONO_TYPE_GENERICINST && mono_class_is_nullable (mono_class_from_mono_type (sig->ret)))
 -              supported = FALSE;
 -
 -      return supported;
 -}
 -
  static RuntimeInvokeInfo*
  create_runtime_invoke_info (MonoDomain *domain, MonoMethod *method, gpointer compiled_method, gboolean callee_gsharedvt)
  {
  
        if (!info->dyn_call_info) {
                if (mono_llvm_only) {
 -                      gboolean supported;
 -
 -                      supported = mini_gsharedvt_runtime_invoke_supported (sig);
 -
 -                      if (mono_class_is_contextbound (method->klass) || !info->compiled_method)
 -                              supported = FALSE;
 -
  #ifndef ENABLE_GSHAREDVT
 -                      supported = FALSE;
 +                      g_assert_not_reached ();
  #endif
 -                      if (supported && !callee_gsharedvt) {
 +                      if (!callee_gsharedvt) {
                                /* Invoke a gsharedvt out wrapper instead */
                                MonoMethod *wrapper = mini_get_gsharedvt_out_sig_wrapper (sig);
                                MonoMethodSignature *wrapper_sig = mini_get_gsharedvt_out_sig_wrapper_signature (sig->hasthis, sig->ret->type != MONO_TYPE_VOID, sig->param_count);
                                g_free (wrapper_sig);
  
                                info->compiled_method = mono_jit_compile_method (wrapper);
 -                      } else if (supported) {
 +                      } else {
                                /* Gsharedvt methods can be invoked the same way */
                                /* The out wrapper has the same signature as the compiled gsharedvt method */
                                MonoMethodSignature *wrapper_sig = mini_get_gsharedvt_out_sig_wrapper_signature (sig->hasthis, sig->ret->type != MONO_TYPE_VOID, sig->param_count);
@@@ -2446,7 -2465,7 +2446,7 @@@ mono_jit_runtime_invoke (MonoMethod *me
  
        runtime_invoke = (MonoObject *(*)(MonoObject *, void **, MonoObject **, void *))info->runtime_invoke;
  
 -      if (info->gsharedvt_invoke) {
 +      if (mono_llvm_only) {
                MonoMethodSignature *sig = mono_method_signature (method);
                gpointer *args;
                gpointer retval_ptr;
                gpointer *param_refs;
                int i, pindex;
  
 +              g_assert (info->gsharedvt_invoke);
 +
                /*
                 * Instead of invoking the method directly, we invoke a gsharedvt out wrapper.
                 * The advantage of this is the gsharedvt out wrappers have a reduced set of
@@@ -3028,6 -3045,65 +3028,65 @@@ mono_get_delegate_virtual_invoke_impl (
        return cache [idx];
  }
  
+ gboolean
+ mini_parse_debug_option (const char *arg)
+ {
+       if (!strcmp (arg, "handle-sigint"))
+               debug_options.handle_sigint = TRUE;
+       else if (!strcmp (arg, "keep-delegates"))
+               debug_options.keep_delegates = TRUE;
+       else if (!strcmp (arg, "reverse-pinvoke-exceptions"))
+               debug_options.reverse_pinvoke_exceptions = TRUE;
+       else if (!strcmp (arg, "collect-pagefault-stats"))
+               debug_options.collect_pagefault_stats = TRUE;
+       else if (!strcmp (arg, "break-on-unverified"))
+               debug_options.break_on_unverified = TRUE;
+       else if (!strcmp (arg, "no-gdb-backtrace"))
+               debug_options.no_gdb_backtrace = TRUE;
+       else if (!strcmp (arg, "suspend-on-sigsegv"))
+               debug_options.suspend_on_sigsegv = TRUE;
+       else if (!strcmp (arg, "suspend-on-exception"))
+               debug_options.suspend_on_exception = TRUE;
+       else if (!strcmp (arg, "suspend-on-unhandled"))
+               debug_options.suspend_on_unhandled = TRUE;
+       else if (!strcmp (arg, "dont-free-domains"))
+               mono_dont_free_domains = TRUE;
+       else if (!strcmp (arg, "dyn-runtime-invoke"))
+               debug_options.dyn_runtime_invoke = TRUE;
+       else if (!strcmp (arg, "gdb"))
+               debug_options.gdb = TRUE;
+       else if (!strcmp (arg, "explicit-null-checks"))
+               debug_options.explicit_null_checks = TRUE;
+       else if (!strcmp (arg, "gen-seq-points"))
+               debug_options.gen_sdb_seq_points = TRUE;
+       else if (!strcmp (arg, "gen-compact-seq-points"))
+               debug_options.gen_seq_points_compact_data = TRUE;
+       else if (!strcmp (arg, "single-imm-size"))
+               debug_options.single_imm_size = TRUE;
+       else if (!strcmp (arg, "init-stacks"))
+               debug_options.init_stacks = TRUE;
+       else if (!strcmp (arg, "casts"))
+               debug_options.better_cast_details = TRUE;
+       else if (!strcmp (arg, "soft-breakpoints"))
+               debug_options.soft_breakpoints = TRUE;
+       else if (!strcmp (arg, "check-pinvoke-callconv"))
+               debug_options.check_pinvoke_callconv = TRUE;
+       else if (!strcmp (arg, "arm-use-fallback-tls"))
+               debug_options.arm_use_fallback_tls = TRUE;
+       else if (!strcmp (arg, "debug-domain-unload"))
+               mono_enable_debug_domain_unload (TRUE);
+       else if (!strcmp (arg, "partial-sharing"))
+               mono_set_partial_sharing_supported (TRUE);
+       else if (!strcmp (arg, "align-small-structs"))
+               mono_align_small_structs = TRUE;
+       else if (!strcmp (arg, "native-debugger-break"))
+               debug_options.native_debugger_break = TRUE;
+       else
+               return FALSE;
+       return TRUE;
+ }
  static void
  mini_parse_debug_options (void)
  {
        for (ptr = args; ptr && *ptr; ptr++) {
                const char *arg = *ptr;
  
-               if (!strcmp (arg, "handle-sigint"))
-                       debug_options.handle_sigint = TRUE;
-               else if (!strcmp (arg, "keep-delegates"))
-                       debug_options.keep_delegates = TRUE;
-               else if (!strcmp (arg, "reverse-pinvoke-exceptions"))
-                       debug_options.reverse_pinvoke_exceptions = TRUE;
-               else if (!strcmp (arg, "collect-pagefault-stats"))
-                       debug_options.collect_pagefault_stats = TRUE;
-               else if (!strcmp (arg, "break-on-unverified"))
-                       debug_options.break_on_unverified = TRUE;
-               else if (!strcmp (arg, "no-gdb-backtrace"))
-                       debug_options.no_gdb_backtrace = TRUE;
-               else if (!strcmp (arg, "suspend-on-sigsegv"))
-                       debug_options.suspend_on_sigsegv = TRUE;
-               else if (!strcmp (arg, "suspend-on-exception"))
-                       debug_options.suspend_on_exception = TRUE;
-               else if (!strcmp (arg, "suspend-on-unhandled"))
-                       debug_options.suspend_on_unhandled = TRUE;
-               else if (!strcmp (arg, "dont-free-domains"))
-                       mono_dont_free_domains = TRUE;
-               else if (!strcmp (arg, "dyn-runtime-invoke"))
-                       debug_options.dyn_runtime_invoke = TRUE;
-               else if (!strcmp (arg, "gdb"))
-                       debug_options.gdb = TRUE;
-               else if (!strcmp (arg, "explicit-null-checks"))
-                       debug_options.explicit_null_checks = TRUE;
-               else if (!strcmp (arg, "gen-seq-points"))
-                       debug_options.gen_sdb_seq_points = TRUE;
-               else if (!strcmp (arg, "gen-compact-seq-points"))
-                       debug_options.gen_seq_points_compact_data = TRUE;
-               else if (!strcmp (arg, "single-imm-size"))
-                       debug_options.single_imm_size = TRUE;
-               else if (!strcmp (arg, "init-stacks"))
-                       debug_options.init_stacks = TRUE;
-               else if (!strcmp (arg, "casts"))
-                       debug_options.better_cast_details = TRUE;
-               else if (!strcmp (arg, "soft-breakpoints"))
-                       debug_options.soft_breakpoints = TRUE;
-               else if (!strcmp (arg, "check-pinvoke-callconv"))
-                       debug_options.check_pinvoke_callconv = TRUE;
-               else if (!strcmp (arg, "arm-use-fallback-tls"))
-                       debug_options.arm_use_fallback_tls = TRUE;
-               else if (!strcmp (arg, "debug-domain-unload"))
-                       mono_enable_debug_domain_unload (TRUE);
-               else if (!strcmp (arg, "partial-sharing"))
-                       mono_set_partial_sharing_supported (TRUE);
-               else if (!strcmp (arg, "align-small-structs"))
-                       mono_align_small_structs = TRUE;
-               else if (!strcmp (arg, "native-debugger-break"))
-                       debug_options.native_debugger_break = TRUE;
-               else {
+               if (!mini_parse_debug_option (arg)) {
                        fprintf (stderr, "Invalid option for the MONO_DEBUG env variable: %s\n", arg);
                        fprintf (stderr, "Available options: 'handle-sigint', 'keep-delegates', 'reverse-pinvoke-exceptions', 'collect-pagefault-stats', 'break-on-unverified', 'no-gdb-backtrace', 'suspend-on-sigsegv', 'suspend-on-exception', 'suspend-on-unhandled', 'dont-free-domains', 'dyn-runtime-invoke', 'gdb', 'explicit-null-checks', 'gen-seq-points', 'gen-compact-seq-points', 'single-imm-size', 'init-stacks', 'casts', 'soft-breakpoints', 'check-pinvoke-callconv', 'arm-use-fallback-tls', 'debug-domain-unload', 'partial-sharing', 'align-small-structs', 'native-debugger-break'\n");
                        exit (1);