From 2e0f2bf314f58ae0cd892047e0bc9de795730bb7 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Wed, 22 Jan 2025 23:31:38 -0500 Subject: [PATCH] add --show-eval for showing where top level eval is in progress --- base/loading.jl | 6 ++++++ base/options.jl | 1 + src/jloptions.c | 14 ++++++++++++++ src/jloptions.h | 1 + 4 files changed, 22 insertions(+) diff --git a/base/loading.jl b/base/loading.jl index 4193aae13b96a..45a1b78274d9c 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -2846,6 +2846,12 @@ function include_string(mapexpr::Function, mod::Module, code::AbstractString, # Wrap things to be eval'd in a :toplevel expr to carry line # information as part of the expr. line_and_ex.args[2] = ex + show_eval = JLOptions().show_eval + if show_eval == 2 # show everything + println("eval: ", line_and_ex) + elseif show_eval == 1 # show top location only + println("eval: ", line_and_ex.args[1]) + end result = Core.eval(mod, line_and_ex) end return result diff --git a/base/options.jl b/base/options.jl index 3281ec0de98d2..047a73f1b0012 100644 --- a/base/options.jl +++ b/base/options.jl @@ -61,6 +61,7 @@ struct JLOptions heap_size_hint::UInt64 trace_compile_timing::Int8 trim::Int8 + show_eval::Int8 task_metrics::Int8 timeout_for_safepoint_straggler_s::Int16 end diff --git a/src/jloptions.c b/src/jloptions.c index 2c5a9074eb465..b91039534d721 100644 --- a/src/jloptions.c +++ b/src/jloptions.c @@ -152,6 +152,7 @@ JL_DLLEXPORT void jl_init_options(void) 0, // heap-size-hint 0, // trace_compile_timing JL_TRIM_NO, // trim + 0, // show-eval 0, // task_metrics -1, // timeout_for_safepoint_straggler_s }; @@ -330,6 +331,7 @@ static const char opts_hidden[] = " and can throw errors. With unsafe-warn warnings will be\n" " printed for dynamic call sites that might lead to such\n" " errors. In safe mode compile-time errors are given instead.\n" + " --show-eval={loc|full|no*} Show the expression being evaluated before eval.\n" ; JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp) @@ -381,6 +383,7 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp) opt_gc_threads, opt_permalloc_pkgimg, opt_trim, + opt_show_eval, opt_experimental_features, }; static const char* const shortopts = "+vhqH:e:E:L:J:C:it:p:O:g:m:"; @@ -450,6 +453,7 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp) { "permalloc-pkgimg",required_argument, 0, opt_permalloc_pkgimg }, { "heap-size-hint", required_argument, 0, opt_heap_size_hint }, { "trim", optional_argument, 0, opt_trim }, + { "show-eval", optional_argument, 0, opt_show_eval }, { 0, 0, 0, 0 } }; @@ -994,6 +998,16 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp) else jl_errorf("julia: invalid argument to --trim={safe|no|unsafe|unsafe-warn} (%s)", optarg); break; + case opt_show_eval: + if (optarg == NULL || !strcmp(optarg,"loc")) + jl_options.show_eval = 1; + else if (!strcmp(optarg,"full")) + jl_options.show_eval = 2; + else if (!strcmp(optarg,"no")) + jl_options.show_eval = 0; + else + jl_errorf("julia: invalid argument to --show-eval={yes|no} (%s)", optarg); + break; case opt_task_metrics: if (!strcmp(optarg, "no")) jl_options.task_metrics = JL_OPTIONS_TASK_METRICS_OFF; diff --git a/src/jloptions.h b/src/jloptions.h index a8cc4a9a9e33d..853bc46d3e437 100644 --- a/src/jloptions.h +++ b/src/jloptions.h @@ -65,6 +65,7 @@ typedef struct { uint64_t heap_size_hint; int8_t trace_compile_timing; int8_t trim; + int8_t show_eval; int8_t task_metrics; int16_t timeout_for_safepoint_straggler_s; } jl_options_t;