mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Debugging, but it doesn't work for some reason
This commit is contained in:
@@ -89,6 +89,9 @@ static class ScriptEngine
|
|||||||
|
|
||||||
private static FileSystemWatcher _userAssemblyWatcher ~ delete _;
|
private static FileSystemWatcher _userAssemblyWatcher ~ delete _;
|
||||||
|
|
||||||
|
// TODO: This should be a global setting somewhere
|
||||||
|
private static bool _debuggingEnabled = true;
|
||||||
|
|
||||||
internal static class Attributes
|
internal static class Attributes
|
||||||
{
|
{
|
||||||
internal static MonoClass* s_ShowInEditorAttribute;
|
internal static MonoClass* s_ShowInEditorAttribute;
|
||||||
@@ -96,11 +99,7 @@ static class ScriptEngine
|
|||||||
|
|
||||||
public static void Init()
|
public static void Init()
|
||||||
{
|
{
|
||||||
Mono.mono_set_assemblies_path("mono/lib");
|
InitMono();
|
||||||
|
|
||||||
s_RootDomain = Mono.mono_jit_init("GlitchyEngineJITRuntime");
|
|
||||||
Log.EngineLogger.Assert(s_RootDomain != null, "Failed to initialize mono root domain");
|
|
||||||
|
|
||||||
ScriptGlue.Init();
|
ScriptGlue.Init();
|
||||||
|
|
||||||
LoadScriptAssemblies();
|
LoadScriptAssemblies();
|
||||||
@@ -108,6 +107,32 @@ static class ScriptEngine
|
|||||||
InitAssemblyWatcher();
|
InitAssemblyWatcher();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void InitMono()
|
||||||
|
{
|
||||||
|
Mono.mono_set_assemblies_path("mono/lib");
|
||||||
|
|
||||||
|
if (_debuggingEnabled)
|
||||||
|
{
|
||||||
|
char8*[2] options = .(
|
||||||
|
"--debugger-agent=transport=dt_socket,address=127.0.0.1:2550,server=y,suspend=n,loglevel=3,logfile=MonoDebugger.log",
|
||||||
|
"--soft-breakpoints"
|
||||||
|
);
|
||||||
|
|
||||||
|
Mono.mono_jit_parse_options(options.Count, &options);
|
||||||
|
Mono.mono_debug_init(.Mono);
|
||||||
|
}
|
||||||
|
|
||||||
|
s_RootDomain = Mono.mono_jit_init("GlitchyEngineJITRuntime");
|
||||||
|
Log.EngineLogger.Assert(s_RootDomain != null, "Failed to initialize mono root domain");
|
||||||
|
|
||||||
|
if (_debuggingEnabled)
|
||||||
|
{
|
||||||
|
Mono.mono_debug_domain_create(s_RootDomain);
|
||||||
|
}
|
||||||
|
|
||||||
|
Mono.mono_thread_set_main(Mono.mono_thread_current());
|
||||||
|
}
|
||||||
|
|
||||||
static void InitAssemblyWatcher()
|
static void InitAssemblyWatcher()
|
||||||
{
|
{
|
||||||
if (_userAssemblyWatcher == null)
|
if (_userAssemblyWatcher == null)
|
||||||
@@ -143,8 +168,8 @@ static class ScriptEngine
|
|||||||
static void LoadScriptAssemblies()
|
static void LoadScriptAssemblies()
|
||||||
{
|
{
|
||||||
CreateAppDomain("GlitchyEngineScriptRuntime");
|
CreateAppDomain("GlitchyEngineScriptRuntime");
|
||||||
(s_CoreAssembly, s_CoreAssemblyImage) = LoadAssembly("resources/scripts/ScriptCore.dll");
|
(s_CoreAssembly, s_CoreAssemblyImage) = LoadAssembly("resources/scripts/ScriptCore.dll", _debuggingEnabled);
|
||||||
(s_AppAssembly, s_AppAssemblyImage) = LoadAssembly("SandboxProject/Assets/Scripts/bin/Sandbox.dll");
|
(s_AppAssembly, s_AppAssemblyImage) = LoadAssembly("SandboxProject/Assets/Scripts/bin/Sandbox.dll", _debuggingEnabled);
|
||||||
|
|
||||||
GetEntitiesFromAssemblies();
|
GetEntitiesFromAssemblies();
|
||||||
|
|
||||||
@@ -202,7 +227,7 @@ static class ScriptEngine
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MonoAssembly* LoadCSharpAssembly(StringView assemblyPath)
|
private static MonoAssembly* LoadCSharpAssembly(StringView assemblyPath, bool loadPDB = false)
|
||||||
{
|
{
|
||||||
List<uint8> data = new List<uint8>(1024);
|
List<uint8> data = new List<uint8>(1024);
|
||||||
|
|
||||||
@@ -223,7 +248,36 @@ static class ScriptEngine
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (loadPDB)
|
||||||
|
{
|
||||||
|
String pdbPath = scope .();
|
||||||
|
Path.ChangeExtension(assemblyPath, ".pdb", pdbPath);
|
||||||
|
|
||||||
|
if (File.Exists(pdbPath))
|
||||||
|
{
|
||||||
|
Log.EngineLogger.Trace($"Loading PDB \"{pdbPath}\"...");
|
||||||
|
|
||||||
|
List<uint8> pdbData = new List<uint8>(1024);
|
||||||
|
|
||||||
|
let result = File.ReadAll(pdbPath, pdbData);
|
||||||
|
|
||||||
|
if (result case .Err(let error))
|
||||||
|
{
|
||||||
|
Log.EngineLogger.Error("Failed to load PDB file ({error}).");
|
||||||
|
}
|
||||||
|
|
||||||
|
Mono.mono_debug_open_image_from_memory(image, pdbData.Ptr, (int32)pdbData.Count);
|
||||||
|
|
||||||
|
delete pdbData;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.EngineLogger.Warning($"Debugging enabled but no PDB-File found \"{assemblyPath}\".");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MonoAssembly* assembly = Mono.mono_assembly_load_from_full(image, assemblyPath.ToScopeCStr!(), &status, 0);
|
MonoAssembly* assembly = Mono.mono_assembly_load_from_full(image, assemblyPath.ToScopeCStr!(), &status, 0);
|
||||||
|
|
||||||
Mono.mono_image_close(image);
|
Mono.mono_image_close(image);
|
||||||
|
|
||||||
return assembly;
|
return assembly;
|
||||||
@@ -235,9 +289,9 @@ static class ScriptEngine
|
|||||||
Mono.mono_domain_set(s_AppDomain, true);
|
Mono.mono_domain_set(s_AppDomain, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static (MonoAssembly* assembly, MonoImage* image) LoadAssembly(StringView filepath)
|
static (MonoAssembly* assembly, MonoImage* image) LoadAssembly(StringView filepath, bool loadPDB = false)
|
||||||
{
|
{
|
||||||
MonoAssembly* assembly = LoadCSharpAssembly(filepath);
|
MonoAssembly* assembly = LoadCSharpAssembly(filepath, loadPDB);
|
||||||
MonoImage* image = Mono.mono_assembly_get_image(assembly);
|
MonoImage* image = Mono.mono_assembly_get_image(assembly);
|
||||||
|
|
||||||
return (assembly, image);
|
return (assembly, image);
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ static class Mono
|
|||||||
[LinkName(.C)]
|
[LinkName(.C)]
|
||||||
public static extern MonoDomain* mono_jit_init(char8* file);
|
public static extern MonoDomain* mono_jit_init(char8* file);
|
||||||
|
|
||||||
|
[LinkName(.C)]
|
||||||
|
public static extern void mono_jit_parse_options(int32 argc, char8** argv);
|
||||||
|
|
||||||
[LinkName(.C)]
|
[LinkName(.C)]
|
||||||
public static extern void mono_jit_cleanup(MonoDomain* domain);
|
public static extern void mono_jit_cleanup(MonoDomain* domain);
|
||||||
|
|
||||||
@@ -208,6 +211,24 @@ static class Mono
|
|||||||
|
|
||||||
[LinkName(.C)]
|
[LinkName(.C)]
|
||||||
public static extern char8* mono_error_get_message(MonoError* error);
|
public static extern char8* mono_error_get_message(MonoError* error);
|
||||||
|
|
||||||
|
[LinkName(.C)]
|
||||||
|
public static extern void mono_debug_init(DebugFormat debugFormat);
|
||||||
|
|
||||||
|
[LinkName(.C)]
|
||||||
|
public static extern void mono_debug_domain_create(MonoDomain* domain);
|
||||||
|
|
||||||
|
[LinkName(.C)]
|
||||||
|
public static extern void mono_debug_domain_unload(MonoDomain* domain);
|
||||||
|
|
||||||
|
[LinkName(.C)]
|
||||||
|
public static extern void mono_debug_open_image_from_memory(MonoImage *image, uint8* raw_contents, int32 size);
|
||||||
|
|
||||||
|
[LinkName(.C)]
|
||||||
|
public static extern void mono_thread_set_main(MonoThread* thread);
|
||||||
|
|
||||||
|
[LinkName(.C)]
|
||||||
|
public static extern MonoThread* mono_thread_current();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MonoDomain;
|
struct MonoDomain;
|
||||||
@@ -226,6 +247,8 @@ struct MonoObject;
|
|||||||
|
|
||||||
struct MonoMethod;
|
struct MonoMethod;
|
||||||
|
|
||||||
|
struct MonoThread;
|
||||||
|
|
||||||
struct MonoException
|
struct MonoException
|
||||||
{
|
{
|
||||||
void* _bla;
|
void* _bla;
|
||||||
@@ -339,6 +362,14 @@ enum MonoMetaTableEnum : int32
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum DebugFormat : uint32
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
Mono,
|
||||||
|
/** Deprecated, the mdb debugger is not longer supported. */
|
||||||
|
Debugger
|
||||||
|
}
|
||||||
|
|
||||||
enum FieldAttribute
|
enum FieldAttribute
|
||||||
{
|
{
|
||||||
FieldAccessMask = 0x0007,
|
FieldAccessMask = 0x0007,
|
||||||
|
|||||||
Reference in New Issue
Block a user