Skip to content

Commit

Permalink
pass native function params directly
Browse files Browse the repository at this point in the history
  • Loading branch information
maddinat0r committed Apr 9, 2017
1 parent 74c896d commit b5276ee
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 27 deletions.
14 changes: 6 additions & 8 deletions include/samplog/PluginLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@
#endif


typedef struct tagAMX AMX;


extern "C" DLL_PUBLIC bool samplog_LogNativeCall(
const char *module, AMX * const amx,
const char *module, AMX * const amx, cell * const params,
const char *name, const char *params_format);


Expand All @@ -37,9 +34,9 @@ extern "C" DLL_PUBLIC bool samplog_LogNativeCall(
namespace samplog
{
inline bool LogNativeCall(const char *module, AMX * const amx,
const char *name, const char *params_format)
cell * const params, const char *name, const char *params_format)
{
return samplog_LogNativeCall(module, amx, name, params_format);
return samplog_LogNativeCall(module, amx, params, name, params_format);
}

class CPluginLogger : public CLogger
Expand Down Expand Up @@ -70,9 +67,10 @@ namespace samplog
return GetAmxFunctionCallTrace(amx, call_info)
&& CLogger::Log(level, msg, call_info);
}
inline bool LogNativeCall(AMX * const amx, const char *name, const char *params_format)
inline bool LogNativeCall(AMX * const amx, cell * const params,
const char *name, const char *params_format)
{
return samplog::LogNativeCall(m_Module.c_str(), amx, name, params_format);
return samplog::LogNativeCall(m_Module.c_str(), amx, params, name, params_format);
}
};

Expand Down
10 changes: 0 additions & 10 deletions src/CAmxDebugManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,6 @@ bool CAmxDebugManager::GetFunctionCallTrace(AMX * const amx, std::vector<AmxFunc
return true;
}

const cell *CAmxDebugManager::GetNativeParamsPtr(AMX * const amx)
{
unsigned char *amx_data = amx->data;
if (amx_data == nullptr)
amx_data = amx->base + reinterpret_cast<AMX_HEADER *>(amx->base)->dat;

cell arg_offset = reinterpret_cast<cell>(amx_data)+amx->stk;
return reinterpret_cast<cell *>(arg_offset);
}


void samplog_RegisterAmx(AMX *amx)
{
Expand Down
2 changes: 0 additions & 2 deletions src/CAmxDebugManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ class CAmxDebugManager : public CSingleton<CAmxDebugManager>
bool GetFunctionCall(AMX * const amx, ucell address, AmxFuncCallInfo &dest);
bool GetFunctionCallTrace(AMX * const amx, std::vector<AmxFuncCallInfo> &dest);

const cell *GetNativeParamsPtr(AMX * const amx);

private:
bool m_DisableDebugInfo = false;
unordered_map<AMX_HEADER *, AMX_DBG *> m_AvailableDebugInfo;
Expand Down
10 changes: 4 additions & 6 deletions src/CLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,23 +208,23 @@ bool samplog_LogMessage(const char *module, LogLevel level, const char *msg,
}

bool samplog_LogNativeCall(const char *module,
AMX * const amx, const char *name, const char *params_format)
AMX * const amx, cell * const params, const char *name, const char *params_format)
{
if (module == nullptr || strlen(module) == 0)
return false;

if (amx == nullptr)
return false;

if (params == nullptr)
return false;

if (name == nullptr || strlen(name) == 0)
return false;

if (params_format == nullptr) // params_format == "" is valid (no parameters)
return false;

const cell *params = CAmxDebugManager::Get()->GetNativeParamsPtr(amx);
if (params == nullptr)
return false;

size_t format_len = strlen(params_format);

Expand Down Expand Up @@ -274,8 +274,6 @@ bool samplog_LogNativeCall(const char *module,
}
fmt_msg << ')';

//auto *call_info = static_cast<AmxFuncCallInfo *>(
// std::malloc(sizeof(AmxFuncCallInfo)));
std::vector<AmxFuncCallInfo> call_info;
CAmxDebugManager::Get()->GetFunctionCallTrace(amx, call_info);

Expand Down
2 changes: 1 addition & 1 deletion src/CLogger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ extern "C" DLL_PUBLIC bool samplog_LogMessage(
samplog_AmxFuncCallInfo const *call_info = NULL,
unsigned int call_info_size = 0);
extern "C" DLL_PUBLIC bool samplog_LogNativeCall(
const char *module, AMX * const amx,
const char *module, AMX * const amx, cell * const params,
const char *name, const char *params_format);

0 comments on commit b5276ee

Please sign in to comment.