add c# debug (mono debug)
This commit is contained in:
@ -17,7 +17,6 @@
|
|||||||
#include <glm/gtx/matrix_decompose.hpp>
|
#include <glm/gtx/matrix_decompose.hpp>
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include "Prism/Physics/PxPhysicsWrappers.h"
|
#include "Prism/Physics/PxPhysicsWrappers.h"
|
||||||
|
|||||||
@ -17,6 +17,8 @@
|
|||||||
#include <mono/metadata/class.h>
|
#include <mono/metadata/class.h>
|
||||||
#include <mono/metadata/object.h>
|
#include <mono/metadata/object.h>
|
||||||
#include <mono/metadata/reflection.h>
|
#include <mono/metadata/reflection.h>
|
||||||
|
#include <mono/metadata/mono-debug.h>
|
||||||
|
#include <mono/metadata/debug-helpers.h>
|
||||||
|
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
|
|
||||||
@ -35,6 +37,12 @@ namespace Prism
|
|||||||
MonoImage* s_AppAssemblyImage = nullptr;
|
MonoImage* s_AppAssemblyImage = nullptr;
|
||||||
MonoImage* s_CoreAssemblyImage = nullptr;
|
MonoImage* s_CoreAssemblyImage = nullptr;
|
||||||
|
|
||||||
|
#ifdef ENABLE_MONO_DEBUG
|
||||||
|
static bool s_EnableMonoPDBDebug = true;
|
||||||
|
#else
|
||||||
|
static bool s_EnableMonoPDBDebug = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static MonoMethod* GetMethod(MonoImage* image, const std::string& methodDesc);
|
static MonoMethod* GetMethod(MonoImage* image, const std::string& methodDesc);
|
||||||
|
|
||||||
@ -86,22 +94,16 @@ namespace Prism
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::ifstream file(filepath, std::ios::binary | std::ios::ate);
|
std::ifstream file(filepath, std::ios::binary | std::ios::ate);
|
||||||
if (!file.is_open()) {
|
if (!file.is_open()) { return nullptr;}
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::streamsize size = file.tellg();
|
std::streamsize size = file.tellg();
|
||||||
if (size <= 0) {
|
if (size <= 0) { return nullptr; }
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
file.seekg(0, std::ios::beg);
|
file.seekg(0, std::ios::beg);
|
||||||
|
|
||||||
std::vector<char> buffer(size);
|
std::vector<char> buffer(size);
|
||||||
|
|
||||||
if (!file.read(buffer.data(), size)) {
|
if (!file.read(buffer.data(), size)) { return nullptr;}
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
MonoImageOpenStatus status;
|
MonoImageOpenStatus status;
|
||||||
@ -117,6 +119,36 @@ namespace Prism
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (s_EnableMonoPDBDebug)
|
||||||
|
{
|
||||||
|
PM_CORE_INFO("loading pdb file...");
|
||||||
|
std::filesystem::path pdbPath(filepath);
|
||||||
|
pdbPath.replace_extension(".pdb");
|
||||||
|
|
||||||
|
if (std::ifstream pdbfile(pdbPath, std::ios::binary | std::ios::ate); pdbfile.is_open())
|
||||||
|
{
|
||||||
|
std::streamsize pdbfileSize = pdbfile.tellg();
|
||||||
|
if (pdbfileSize > 0)
|
||||||
|
{
|
||||||
|
pdbfile.seekg(0, std::ios::beg);
|
||||||
|
|
||||||
|
std::vector<char> pdbData(pdbfileSize);
|
||||||
|
if (pdbfile.read(pdbData.data(), pdbfileSize))
|
||||||
|
{
|
||||||
|
mono_debug_open_image_from_memory(image, reinterpret_cast<const mono_byte*>(pdbData.data()), static_cast<int>(pdbfileSize));
|
||||||
|
PM_CORE_INFO("loaded pdb file: {0}", pdbPath.string());
|
||||||
|
PM_CORE_INFO(" size: {0}", pdbfileSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PM_CORE_INFO("pdb file not found, skiped");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const auto assembly = mono_assembly_load_from_full(image, filepath, &status, 0);
|
const auto assembly = mono_assembly_load_from_full(image, filepath, &status, 0);
|
||||||
|
|
||||||
mono_image_close(image);
|
mono_image_close(image);
|
||||||
@ -128,7 +160,18 @@ namespace Prism
|
|||||||
{
|
{
|
||||||
mono_set_dirs("library/mono/net8.0", "");
|
mono_set_dirs("library/mono/net8.0", "");
|
||||||
mono_set_assemblies_path("library/mono/net8.0");
|
mono_set_assemblies_path("library/mono/net8.0");
|
||||||
// mono_jit_set_trace_options("--verbose");
|
|
||||||
|
if (s_EnableMonoPDBDebug)
|
||||||
|
{
|
||||||
|
const char* argv[2]
|
||||||
|
{
|
||||||
|
"--debugger-agent=transport=dt_socket,address=127.0.0.1:2550,server=y,suspend=n,loglevel=3,logfile=MonoDebugger.log",
|
||||||
|
"--soft-breakpoints"
|
||||||
|
};
|
||||||
|
|
||||||
|
mono_jit_parse_options(2, (char**)argv);
|
||||||
|
mono_debug_init(MONO_DEBUG_FORMAT_MONO);
|
||||||
|
}
|
||||||
|
|
||||||
auto domain = mono_jit_init("Prism");
|
auto domain = mono_jit_init("Prism");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user