Skip to content

Commit a1ed262

Browse files
committed
Detect active mono debugger automatically; remove debug_start_server
1 parent bda7b26 commit a1ed262

File tree

12 files changed

+20
-26
lines changed

12 files changed

+20
-26
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ All Doorstop arguments start with `--doorstop-` and always contain an argument.
157157
| `--doorstop-target-assembly string` | Path to the assembly to load and execute. |
158158
| `--doorstop-mono-dll-search-path-override string` | Overrides default Mono DLL search path |
159159
| `--doorstop-mono-debug-enabled bool` | If true, Mono debugger server will be enabled |
160-
| `--doorstop-mono-debug-start-server bool` | Whether Doorstop should initialize the debugger server automatically |
161160
| `--doorstop-mono-debug-suspend bool` | Whether to suspend the game execution until the debugger is attached. |
162161
| `--doorstop-mono-debug-address string` | The address to use for the Mono debugger server. |
163162
| `--doorstop-clr-corlib-dir string` | Path to coreclr library that contains the CoreCLR runtime |

assets/nix/run.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ dll_search_path_override=""
4141
# If 1, Mono debugger server will be enabled
4242
debug_enable="0"
4343

44-
# When debug_enabled is 1, this option specifies whether Doorstop should initialize the debugger server
45-
# If you experience crashes when starting the debugger on debug UnityPlayer builds, try setting this to 0
46-
debug_start_server="0"
47-
4844
# When debug_enabled is 1, specifies the address to use for the debugger server
4945
debug_address="127.0.0.1:10000"
5046

@@ -244,7 +240,6 @@ export DOORSTOP_TARGET_ASSEMBLY="$target_assembly"
244240
export DOORSTOP_IGNORE_DISABLED_ENV="$ignore_disable_switch"
245241
export DOORSTOP_MONO_DLL_SEARCH_PATH_OVERRIDE="$dll_search_path_override"
246242
export DOORSTOP_MONO_DEBUG_ENABLED="$debug_enable"
247-
export DOORSTOP_MONO_DEBUG_START_SERVER="$debug_start_server"
248243
export DOORSTOP_MONO_DEBUG_ADDRESS="$debug_address"
249244
export DOORSTOP_MONO_DEBUG_SUSPEND="$debug_suspend"
250245
export DOORSTOP_CLR_RUNTIME_CORECLR_PATH="$coreclr_path.$lib_extension"

assets/windows/doorstop_config.ini

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ dll_search_path_override=
2929
# If true, Mono debugger server will be enabled
3030
debug_enabled=false
3131

32-
# When debug_enabled is true, this option specifies whether Doorstop should initialize the debugger server
33-
# If you experience crashes when starting the debugger on debug UnityPlayer builds, try setting this to false
34-
debug_start_server=true
35-
3632
# When debug_enabled is true, specifies the address to use for the debugger server
3733
debug_address=127.0.0.1:10000
3834

src/bootstrap.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "util/paths.h"
99
#include "util/util.h"
1010

11+
bool_t mono_debug_init_called = FALSE;
12+
1113
void mono_doorstop_bootstrap(void *mono_domain) {
1214
if (getenv(TEXT("DOORSTOP_INITIALIZED"))) {
1315
LOG("DOORSTOP_INITIALIZED is set! Skipping!");
@@ -171,7 +173,13 @@ void *init_mono(const char *root_domain_name, const char *runtime_version) {
171173

172174
void *domain = mono.jit_init_version(root_domain_name, runtime_version);
173175

174-
if (config.mono_debug_enabled && config.mono_debug_start_server) {
176+
bool_t debugger_already_enabled = mono_debug_init_called;
177+
if (mono.debug_enabled) {
178+
debugger_already_enabled |= mono.debug_enabled();
179+
}
180+
181+
if (config.mono_debug_enabled && !debugger_already_enabled) {
182+
LOG("Detected mono debugger is not initialized; initialized it");
175183
mono.debug_init(MONO_DEBUG_FORMAT_MONO);
176184
mono.debug_domain_create(domain);
177185
}
@@ -350,4 +358,9 @@ void *hook_mono_image_open_from_data_with_name(void *data,
350358
status, refonly, name);
351359
}
352360
return result;
361+
}
362+
363+
void hook_mono_debug_init(MonoDebugFormat format) {
364+
mono_debug_init_called = TRUE;
365+
mono.debug_init(format);
353366
}

src/bootstrap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ void *hook_mono_image_open_from_data_with_name(void *data,
1313
MonoImageOpenStatus *status,
1414
int refonly, const char *name);
1515
void hook_mono_jit_parse_options(int argc, char **argv);
16+
void hook_mono_debug_init(MonoDebugFormat format);
1617

1718
#endif

src/config/common.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ void init_config_defaults() {
2424
config.ignore_disabled_env = FALSE;
2525
config.redirect_output_log = FALSE;
2626
config.mono_debug_enabled = FALSE;
27-
config.mono_debug_start_server = TRUE;
2827
config.mono_debug_suspend = FALSE;
2928
config.mono_debug_address = NULL;
3029
config.target_assembly = NULL;

src/config/config.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,6 @@ typedef struct {
4646
*/
4747
bool_t mono_debug_enabled;
4848

49-
/**
50-
* @brief Whether to manually intialize the mono debugger server.
51-
*
52-
* On debug Unity versions, Unity automatically initializes the debugger
53-
* server. Use this option to disable the automatic server initialization.
54-
*/
55-
bool_t mono_debug_start_server;
56-
5749
/**
5850
* @brief Whether to enable the debugger in suspended state.
5951
*

src/nix/config.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ void load_config() {
3333
get_env_bool("DOORSTOP_REDIRECT_OUTPUT_LOG", &config.redirect_output_log);
3434
get_env_bool("DOORSTOP_IGNORE_DISABLED_ENV", &config.ignore_disabled_env);
3535
get_env_bool("DOORSTOP_MONO_DEBUG_ENABLED", &config.mono_debug_enabled);
36-
get_env_bool("DOORSTOP_MONO_DEBUG_START_SERVER",
37-
&config.mono_debug_start_server);
3836
get_env_bool("DOORSTOP_MONO_DEBUG_SUSPEND", &config.mono_debug_suspend);
3937
try_get_env("DOORSTOP_MONO_DEBUG_ADDRESS", TEXT("127.0.0.1:10000"),
4038
&config.mono_debug_address);

src/nix/entrypoint.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ void *dlsym_hook(void *handle, const char *name) {
3838
capture_mono_path(res));
3939
REDIRECT_INIT("mono_jit_parse_options", load_mono_funcs,
4040
hook_mono_jit_parse_options, capture_mono_path(res));
41+
REDIRECT_INIT("mono_debug_init", load_mono_funcs, hook_mono_debug_init,
42+
capture_mono_path(res));
4143

4244
#undef REDIRECT_INIT
4345
return res;

src/runtimes/mono.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ DEF_CALL(void *, assembly_load_from_full, void *image, const char *fname,
3636
DEF_CALL(void *, jit_parse_options, int argc, char **argv)
3737
DEF_CALL(void *, debug_init, MonoDebugFormat format)
3838
DEF_CALL(void *, debug_domain_create, void *domain)
39+
DEF_CALL(int, debug_enabled)
3940
#else
4041

4142
#ifndef MONO_H

0 commit comments

Comments
 (0)