Skip to content

Commit 0429722

Browse files
committed
allow mono debugging and jit flags
1 parent c8ca462 commit 0429722

File tree

5 files changed

+51
-2
lines changed

5 files changed

+51
-2
lines changed

.vscode/launch.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Attach",
6+
"type": "mono",
7+
"request": "attach",
8+
"address": "localhost",
9+
"port": 5831
10+
}
11+
]
12+
}

clr_loader/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Dict, Optional
1+
from typing import Dict, Optional, Sequence
22

33
from .wrappers import Runtime
44
from .util.find import find_libmono, find_dotnet_root
@@ -8,6 +8,8 @@
88

99
def get_mono(
1010
domain: Optional[str] = None,
11+
debug: bool = False,
12+
jit_options: Optional[Sequence[str]] = None,
1113
config_file: Optional[str] = None,
1214
global_config_file: Optional[str] = None,
1315
libmono: Optional[str] = None,
@@ -20,6 +22,8 @@ def get_mono(
2022

2123
impl = Mono(
2224
domain=domain,
25+
debug=debug,
26+
jit_options=jit_options,
2327
config_file=config_file,
2428
global_config_file=global_config_file,
2529
libmono=libmono,

clr_loader/ffi/mono.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,19 @@
1111
typedef struct _MonoMethod MonoMethod;
1212
typedef struct _MonoObject MonoObject;
1313
14+
typedef enum {
15+
MONO_DEBUG_FORMAT_NONE,
16+
MONO_DEBUG_FORMAT_MONO,
17+
/* Deprecated, the mdb debugger is not longer supported. */
18+
MONO_DEBUG_FORMAT_DEBUGGER
19+
} MonoDebugFormat;
20+
1421
MonoDomain* mono_jit_init(const char *root_domain_name);
1522
void mono_jit_cleanup(MonoDomain *domain);
23+
void mono_jit_parse_options(int argc, char * argv[]);
24+
25+
void mono_debug_init (MonoDebugFormat format);
26+
1627
MonoAssembly* mono_domain_assembly_open(MonoDomain *domain, const char *name);
1728
MonoImage* mono_assembly_get_image(MonoAssembly *assembly);
1829

clr_loader/mono.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import atexit
2-
from typing import Optional
2+
from typing import Optional, Sequence
33

44
from .ffi import load_mono, ffi
55

@@ -17,13 +17,17 @@ def __init__(
1717
libmono,
1818
*,
1919
domain=None,
20+
debug=False,
21+
jit_options: Optional[Sequence[str]] = None,
2022
config_file: Optional[str] = None,
2123
global_config_file: Optional[str] = None,
2224
):
2325
self._assemblies = {}
2426

2527
initialize(
2628
config_file=config_file,
29+
debug=debug,
30+
jit_options=jit_options,
2731
global_config_file=global_config_file,
2832
libmono=libmono,
2933
)
@@ -95,6 +99,8 @@ def __call__(self, ptr, size):
9599

96100
def initialize(
97101
libmono: str,
102+
debug: bool = False,
103+
jit_options: Optional[Sequence[str]] = None,
98104
config_file: Optional[str] = None,
99105
global_config_file: Optional[str] = None,
100106
) -> None:
@@ -113,6 +119,13 @@ def initialize(
113119

114120
config_encoded = config_file.encode("utf8")
115121

122+
if jit_options:
123+
options = list(map(lambda x: ffi.new("char[]", x.encode("utf8")), jit_options))
124+
_MONO.mono_jit_parse_options(len(options), options)
125+
126+
if debug:
127+
_MONO.mono_debug_init(_MONO.MONO_DEBUG_FORMAT_MONO)
128+
116129
_ROOT_DOMAIN = _MONO.mono_jit_init(b"clr_loader")
117130
_MONO.mono_domain_set_config(_ROOT_DOMAIN, b".", config_encoded)
118131
_check_result(_ROOT_DOMAIN, "Failed to initialize Mono")

tests/test_common.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ def test_mono(example_netstandard):
3131

3232
run_tests(asm)
3333

34+
def test_mono_debug(example_netstandard):
35+
from clr_loader import get_mono
36+
37+
mono = get_mono(debug=True,
38+
jit_options=['--debugger-agent=address=0.0.0.0:5831,transport=dt_socket,server=y'])
39+
asm = mono.get_assembly(os.path.join(example_netstandard, "example.dll"))
40+
41+
run_tests(asm)
42+
3443

3544
def test_coreclr(example_netcore):
3645
from clr_loader import get_coreclr

0 commit comments

Comments
 (0)