Skip to content

Commit 699c6d6

Browse files
authored
Allow mono debugging and jit flags (#16)
1 parent c8ca462 commit 699c6d6

File tree

5 files changed

+56
-2
lines changed

5 files changed

+56
-2
lines changed

Diff for: .vscode/launch.json

+12
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+
}

Diff for: clr_loader/__init__.py

+5-1
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
@@ -12,6 +12,8 @@ def get_mono(
1212
global_config_file: Optional[str] = None,
1313
libmono: Optional[str] = None,
1414
sgen: bool = True,
15+
debug: bool = False,
16+
jit_options: Optional[Sequence[str]] = None,
1517
) -> Runtime:
1618
from .mono import Mono
1719

@@ -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,

Diff for: clr_loader/ffi/mono.py

+11
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

Diff for: clr_loader/mono.py

+14-1
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 = [ffi.new("char[]", o.encode("utf8")) for o in 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")

Diff for: tests/test_common.py

+14
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ def test_mono(example_netstandard):
3232
run_tests(asm)
3333

3434

35+
def test_mono_debug(example_netstandard):
36+
from clr_loader import get_mono
37+
38+
mono = get_mono(
39+
debug=True,
40+
jit_options=[
41+
"--debugger-agent=address=0.0.0.0:5831,transport=dt_socket,server=y"
42+
],
43+
)
44+
asm = mono.get_assembly(os.path.join(example_netstandard, "example.dll"))
45+
46+
run_tests(asm)
47+
48+
3549
def test_coreclr(example_netcore):
3650
from clr_loader import get_coreclr
3751

0 commit comments

Comments
 (0)