Skip to content

Commit

Permalink
[monodroid] Add debug.mono.log=debugger-log-level=LEVEL option (#3969)
Browse files Browse the repository at this point in the history
The mono debugger infrastructure code supports a `loglevel` option,
which the mono debugger team would like to set.

In theory we have code to allow setting set it: the `debug.mono.extra`
system property can contain a `loglevel=LEVEL` option, which is
parsed by `mono_runtime_init()`/`parse_runtime_args()` when
constructing the options for use with `mono_jit_parse_options()`.

In practice, we don't: [all codepaths][0] which set `debug.mono.extra`
always hardcode `loglevel=0`, with no way to override it.

To allow the mono debugger team to *actually* set the `loglevel`
value, add a new `debugger-log-level=LEVEL` option for use with the
`debug.mono.log` system property:

	adb shell setprop debug.mono.log debugger-log-level=10

The `debug.mono.log` system property is comma-separated, so it can be
used with other options as well:

	adb shell setprop debug.mono.log timing,gref,debugger-log-level=10

The `LEVEL` value is a positive 32-bit signed integer or `0`.  This
option will take precedence when the level is set in both the
`debug.mono.extra` and `debug.mono.log` system properties.

[0]: https://github.com/xamarin/androidtools/blob/master/Xamarin.AndroidTools/Debugging/DebuggingExtensions.cs#L92-L102
  • Loading branch information
grendello authored and jonpryor committed Dec 12, 2019
1 parent a3a02bf commit 87ba3fb
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
23 changes: 23 additions & 0 deletions src/monodroid/jni/debug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,29 @@ Debug::load_profiler_from_handle (void *dso_handle, const char *desc, const char
}

#if defined (DEBUG) && !defined (WINDOWS)
void
Debug::set_debugger_log_level (const char *level)
{
if (level == nullptr || *level == '\0') {
got_debugger_log_level = false;
return;
}

unsigned long v = strtoul (level, nullptr, 0);
if (v == ULONG_MAX && errno == ERANGE) {
log_error (LOG_DEFAULT, "Invalid debugger log level value '%s', expecting a positive integer or zero", level);
return;
}

if (v > INT_MAX) {
log_warn (LOG_DEFAULT, "Debugger log level value is higher than the maximum of %u, resetting to the maximum value.", INT_MAX);
v = INT_MAX;
}

got_debugger_log_level = true;
debugger_log_level = static_cast<int>(v);
}

inline void
Debug::parse_options (char *options, ConnOptions *opts)
{
Expand Down
14 changes: 14 additions & 0 deletions src/monodroid/jni/debug.hh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ namespace xamarin::android
public:
bool enable_soft_breakpoints ();
void start_debugging_and_profiling ();
void set_debugger_log_level (const char *level);

bool have_debugger_log_level () const
{
return got_debugger_log_level;
}

int get_debugger_log_level () const
{
return debugger_log_level;
}

private:
DebuggerConnectionStatus start_connection (char *options);
Expand All @@ -67,6 +78,7 @@ namespace xamarin::android
bool process_cmd (int fd, char *cmd);
void start_debugging ();
void start_profiling ();

friend void* conn_thread (void *arg);

private:
Expand All @@ -82,6 +94,8 @@ namespace xamarin::android
bool config_timedout;
timeval wait_tv;
timespec wait_ts;
bool got_debugger_log_level = false;
int debugger_log_level = 0;
#endif
};
}
Expand Down
9 changes: 6 additions & 3 deletions src/monodroid/jni/logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,14 @@ init_logging_categories ()
} else if (!strncmp (arg, "lref-", 5)) {
log_categories |= LOG_LREF;
light_lref = 1;
}

if (!strncmp (arg, "timing=bare", 11)) {
} else if (!strncmp (arg, "timing=bare", 11)) {
log_timing_categories |= LOG_TIMING_BARE;
}
#if !defined (WINDOWS) && defined (DEBUG)
else if (!strncmp (arg, "debugger-log-level=", 19)) {
debug.set_debugger_log_level (arg + 19);
}
#endif
}

utils.monodroid_strfreev (args);
Expand Down
8 changes: 7 additions & 1 deletion src/monodroid/jni/monodroid-glue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -623,9 +623,15 @@ MonodroidRuntime::mono_runtime_init (char *runtime_args)
} else if (options.debug && cur_time <= options.timeout_time) {
embeddedAssemblies.set_register_debug_symbols (true);

int loglevel;
if (debug.have_debugger_log_level ())
loglevel = debug.get_debugger_log_level ();
else
loglevel = options.loglevel;

char *debug_arg = utils.monodroid_strdup_printf (
"--debugger-agent=transport=dt_socket,loglevel=%d,address=%s:%d,%sembedding=1",
options.loglevel,
loglevel,
options.host,
options.sdb_port,
options.server ? "server=y," : ""
Expand Down

0 comments on commit 87ba3fb

Please sign in to comment.