mirror of
https://github.com/rehlds/metamod-r.git
synced 2025-01-27 22:17:54 +03:00
Add jit debug
This commit is contained in:
parent
5753c397d1
commit
50b0d6e1d3
@ -196,6 +196,7 @@
|
|||||||
<ClCompile Include="..\src\linkent.cpp" />
|
<ClCompile Include="..\src\linkent.cpp" />
|
||||||
<ClCompile Include="..\src\linkgame.cpp" />
|
<ClCompile Include="..\src\linkgame.cpp" />
|
||||||
<ClCompile Include="..\src\log_meta.cpp" />
|
<ClCompile Include="..\src\log_meta.cpp" />
|
||||||
|
<ClCompile Include="..\src\mdebug.cpp" />
|
||||||
<ClCompile Include="..\src\metamod_rehlds_api.cpp" />
|
<ClCompile Include="..\src\metamod_rehlds_api.cpp" />
|
||||||
<ClCompile Include="..\src\metamod.cpp" />
|
<ClCompile Include="..\src\metamod.cpp" />
|
||||||
<ClCompile Include="..\src\mlist.cpp" />
|
<ClCompile Include="..\src\mlist.cpp" />
|
||||||
@ -228,6 +229,7 @@
|
|||||||
<ClInclude Include="..\src\jitasm.h" />
|
<ClInclude Include="..\src\jitasm.h" />
|
||||||
<ClInclude Include="..\src\linkent.h" />
|
<ClInclude Include="..\src\linkent.h" />
|
||||||
<ClInclude Include="..\src\log_meta.h" />
|
<ClInclude Include="..\src\log_meta.h" />
|
||||||
|
<ClInclude Include="..\src\mdebug.h" />
|
||||||
<ClInclude Include="..\src\metamod_rehlds_api.h" />
|
<ClInclude Include="..\src\metamod_rehlds_api.h" />
|
||||||
<ClInclude Include="..\src\meta_api.h" />
|
<ClInclude Include="..\src\meta_api.h" />
|
||||||
<ClInclude Include="..\src\metamod.h" />
|
<ClInclude Include="..\src\metamod.h" />
|
||||||
|
@ -86,6 +86,9 @@
|
|||||||
<ClCompile Include="..\src\public_amalgamation.cpp">
|
<ClCompile Include="..\src\public_amalgamation.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\src\mdebug.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\src\api_info.h">
|
<ClInclude Include="..\src\api_info.h">
|
||||||
@ -172,6 +175,9 @@
|
|||||||
<ClInclude Include="..\src\metamod_rehlds_api.h">
|
<ClInclude Include="..\src\metamod_rehlds_api.h">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\src\mdebug.h">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="metamod.def">
|
<None Include="metamod.def">
|
||||||
|
@ -15,12 +15,13 @@ private:
|
|||||||
|
|
||||||
size_t CUniqueLabel::m_unique_index;
|
size_t CUniqueLabel::m_unique_index;
|
||||||
|
|
||||||
class CForwardCallbackJIT : public jitasm::function<int, CForwardCallbackJIT, int>
|
class CForwardCallbackJIT : public jitasm::function<void, CForwardCallbackJIT>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CForwardCallbackJIT(jitdata_t* jitdata);
|
CForwardCallbackJIT(jitdata_t* jitdata);
|
||||||
void naked_main();
|
void naked_main();
|
||||||
void call_func(Reg32 addr);
|
void call_func(Reg32 addr);
|
||||||
|
void jit_debug(const char* format, ...);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
jitdata_t* m_jitdata;
|
jitdata_t* m_jitdata;
|
||||||
@ -52,6 +53,8 @@ CForwardCallbackJIT::CForwardCallbackJIT(jitdata_t* jitdata) : m_jitdata(jitdata
|
|||||||
|
|
||||||
void CForwardCallbackJIT::naked_main()
|
void CForwardCallbackJIT::naked_main()
|
||||||
{
|
{
|
||||||
|
jit_debug("Enter %s\n", m_jitdata->name);
|
||||||
|
|
||||||
// prologue
|
// prologue
|
||||||
push(ebx);
|
push(ebx);
|
||||||
push(ebp);
|
push(ebp);
|
||||||
@ -151,6 +154,7 @@ void CForwardCallbackJIT::naked_main()
|
|||||||
mov(dword_ptr[globals + mg_status], eax); // NULL
|
mov(dword_ptr[globals + mg_status], eax); // NULL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jit_debug("Calling pre [%s] for plug [%s]\n", m_jitdata->name, plug->description());
|
||||||
call_func(ecx);
|
call_func(ecx);
|
||||||
|
|
||||||
mov(edx, dword_ptr[globals + mg_mres]);
|
mov(edx, dword_ptr[globals + mg_mres]);
|
||||||
@ -174,6 +178,7 @@ void CForwardCallbackJIT::naked_main()
|
|||||||
jz("skip_original");
|
jz("skip_original");
|
||||||
{
|
{
|
||||||
if (m_jitdata->pfn_original) {
|
if (m_jitdata->pfn_original) {
|
||||||
|
//jit_debug("Call original %s\n", m_jitdata->name);
|
||||||
mov(ecx, m_jitdata->pfn_original);
|
mov(ecx, m_jitdata->pfn_original);
|
||||||
call_func(ecx);
|
call_func(ecx);
|
||||||
}
|
}
|
||||||
@ -232,6 +237,7 @@ void CForwardCallbackJIT::naked_main()
|
|||||||
mov(dword_ptr[globals + mg_status], eax); // NULL
|
mov(dword_ptr[globals + mg_status], eax); // NULL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jit_debug("Calling post [%s] for plug [%s]\n", m_jitdata->name, plug->description());
|
||||||
call_func(ecx);
|
call_func(ecx);
|
||||||
|
|
||||||
mov(edx, dword_ptr[globals + mg_mres]);
|
mov(edx, dword_ptr[globals + mg_mres]);
|
||||||
@ -271,6 +277,7 @@ void CForwardCallbackJIT::naked_main()
|
|||||||
mov(esp, ebp);
|
mov(esp, ebp);
|
||||||
pop(ebp);
|
pop(ebp);
|
||||||
pop(ebx);
|
pop(ebx);
|
||||||
|
jit_debug("Leave %s\n", m_jitdata->name);
|
||||||
ret();
|
ret();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,6 +308,31 @@ void CForwardCallbackJIT::call_func(Reg32 addr)
|
|||||||
add(esp, m_jitdata->args_count * sizeof(int));
|
add(esp, m_jitdata->args_count * sizeof(int));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CForwardCallbackJIT::jit_debug(const char* format, ...)
|
||||||
|
{
|
||||||
|
#ifdef JIT_DEBUG
|
||||||
|
va_list argptr;
|
||||||
|
char string[1024] = "";
|
||||||
|
|
||||||
|
va_start(argptr, format);
|
||||||
|
Q_vsnprintf(string, sizeof string, format, argptr);
|
||||||
|
va_end(argptr);
|
||||||
|
|
||||||
|
char* memory_leak = Q_strdup(string); // yes, I'm lazy
|
||||||
|
static size_t print_ptr = size_t(&printf);
|
||||||
|
static size_t fprint_ptr = size_t(&mdebug_to_file);
|
||||||
|
|
||||||
|
pushad();
|
||||||
|
push(size_t(memory_leak));
|
||||||
|
call(dword_ptr[size_t(&print_ptr)]);
|
||||||
|
#ifdef JIT_DEBUG_FILE
|
||||||
|
call(dword_ptr[size_t(&fprint_ptr)]);
|
||||||
|
#endif
|
||||||
|
add(esp, 4);
|
||||||
|
popad();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
CJit::CJit() : m_callback_allocator(static_allocator::mp_rwx), m_tramp_allocator(static_allocator::mp_rwx)
|
CJit::CJit() : m_callback_allocator(static_allocator::mp_rwx), m_tramp_allocator(static_allocator::mp_rwx)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,10 @@ struct jitdata_t
|
|||||||
int plugins_count;
|
int plugins_count;
|
||||||
size_t table_offset; // from MPlugin
|
size_t table_offset; // from MPlugin
|
||||||
size_t post_table_offset; // from MPlugin
|
size_t post_table_offset; // from MPlugin
|
||||||
|
|
||||||
|
#ifdef JIT_DEBUG
|
||||||
|
const char* name;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
struct compile_data_t
|
struct compile_data_t
|
||||||
@ -85,6 +89,7 @@ public:
|
|||||||
size_t compile_tramp(size_t ptr_to_func/*, size_t hook, size_t hook_time*/);
|
size_t compile_tramp(size_t ptr_to_func/*, size_t hook, size_t hook_time*/);
|
||||||
void clear_callbacks();
|
void clear_callbacks();
|
||||||
void clear_tramps();
|
void clear_tramps();
|
||||||
|
size_t find_new_retaddr(size_t pfn);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool is_hook_needed(jitdata_t* jitdata);
|
static bool is_hook_needed(jitdata_t* jitdata);
|
||||||
|
@ -224,6 +224,10 @@ void compile_dllfunc_callbacks()
|
|||||||
jitdata.mm_hook_time = cd.mm_hook_time;
|
jitdata.mm_hook_time = cd.mm_hook_time;
|
||||||
jitdata.mm_hook = cd.mm_hook;
|
jitdata.mm_hook = cd.mm_hook;
|
||||||
|
|
||||||
|
#ifdef JIT_DEBUG
|
||||||
|
jitdata.name = cd.name;
|
||||||
|
#endif
|
||||||
|
|
||||||
*(size_t *)(size_t(&sFunctionTable) + cd.offset) = g_jit.compile_callback(&jitdata);
|
*(size_t *)(size_t(&sFunctionTable) + cd.offset) = g_jit.compile_callback(&jitdata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -245,6 +249,10 @@ void compile_newdllfunc_callbacks()
|
|||||||
jitdata.mm_hook_time = cd.mm_hook_time;
|
jitdata.mm_hook_time = cd.mm_hook_time;
|
||||||
jitdata.mm_hook = cd.mm_hook;
|
jitdata.mm_hook = cd.mm_hook;
|
||||||
|
|
||||||
|
#ifdef JIT_DEBUG
|
||||||
|
jitdata.name = cd.name;
|
||||||
|
#endif
|
||||||
|
|
||||||
*(size_t *)(size_t(&sNewFunctionTable) + cd.offset) = g_jit.compile_callback(&jitdata);
|
*(size_t *)(size_t(&sNewFunctionTable) + cd.offset) = g_jit.compile_callback(&jitdata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -253,6 +253,10 @@ void compile_engfuncs_callbacks()
|
|||||||
jitdata.mm_hook_time = cd.mm_hook_time;
|
jitdata.mm_hook_time = cd.mm_hook_time;
|
||||||
jitdata.mm_hook = cd.mm_hook;
|
jitdata.mm_hook = cd.mm_hook;
|
||||||
|
|
||||||
|
#ifdef JIT_DEBUG
|
||||||
|
jitdata.name = cd.name;
|
||||||
|
#endif
|
||||||
|
|
||||||
*(size_t *)(size_t(&g_meta_engfuncs_jit) + cd.offset) = g_jit.compile_callback(&jitdata);
|
*(size_t *)(size_t(&g_meta_engfuncs_jit) + cd.offset) = g_jit.compile_callback(&jitdata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -426,6 +426,10 @@ void meta_rebuild_callbacks()
|
|||||||
{
|
{
|
||||||
META_LOG("dll: Rebuilding callbacks...");
|
META_LOG("dll: Rebuilding callbacks...");
|
||||||
|
|
||||||
|
#ifdef JIT_DEBUG_FILE
|
||||||
|
mdebug_to_file("dll: Rebuilding callbacks...\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
g_jit.clear_callbacks();
|
g_jit.clear_callbacks();
|
||||||
|
|
||||||
compile_engine_callbacks();
|
compile_engine_callbacks();
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include <rehlds_api.h>
|
#include <rehlds_api.h>
|
||||||
|
|
||||||
#include "osdep.h"
|
#include "osdep.h"
|
||||||
|
#include "mdebug.h"
|
||||||
#include "api_info.h"
|
#include "api_info.h"
|
||||||
#include "commands_meta.h"
|
#include "commands_meta.h"
|
||||||
#include "metamod.h"
|
#include "metamod.h"
|
||||||
|
@ -53,6 +53,8 @@ private:
|
|||||||
size_t m_used = 0;
|
size_t m_used = 0;
|
||||||
std::vector<void *> m_pages;
|
std::vector<void *> m_pages;
|
||||||
memory_protection m_protection;
|
memory_protection m_protection;
|
||||||
|
|
||||||
|
friend class CJit;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool is_yes(const char* str);
|
bool is_yes(const char* str);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user