void Debugger::FmtGenericMsg(AMX *amx, int error, char buffer[], size_t maxLength) { const char *filename = ""; char native[sNAMEMAX+1]; CList<CScript,AMX*>::iterator a = g_loadedscripts.find(amx); if (a) filename = (*a).getName(); size_t len = strlen(filename); for (size_t i=len-1; i<len; i--) { if ((filename[i] == '/' || filename[i] == '\\') && i != len - 1) { filename = &(filename[i+1]); break; } } if (error == AMX_ERR_EXIT) { UTIL_Format(buffer, maxLength, "Run time error %d (plugin \"%s\") - %s", error, filename, GenericError(AMX_ERR_EXIT)); } else if (error == AMX_ERR_NATIVE) { amx_GetNative(amx, reinterpret_cast<long>(amx->usertags[UT_NATIVE]), native); UTIL_Format(buffer, maxLength, "Run time error %d (plugin \"%s\") (native \"%s\") - debug not enabled!", error, filename, native); } else { UTIL_Format(buffer, maxLength, "Run time error %d (plugin \"%s\") - debug not enabled!", error, filename); } }
int AMXAPI native_handler(AMX *amx, int index) { Handler *pHandler = (Handler *)amx->userdata[UD_HANDLER]; char name[sNAMEMAX + 1]; amx_GetNative(amx, index, name); return pHandler->HandleNative(name, index, 0); }
int Debugger::FormatError(char *buffer, size_t maxLength) { if (!ErrorExists()) return -1; assert(m_Top >= 0 && m_Top < (int)m_pCalls.size()); Tracer *pTracer = m_pCalls[m_Top]; int error = pTracer->m_Error; const char *gen_err = GenericError(error); int size = 0; //trace_info_t *pTrace = pTracer->GetEnd(); //cell cip = _CipAsVa(m_pAmx->cip); //cell *p_cip = NULL; //int amx_err = AMX_ERR_NONE; size += UTIL_Format(buffer, maxLength, "Run time error %d: %s ", error, gen_err); buffer += size; maxLength -= size; if (error == AMX_ERR_NATIVE || error == AMX_ERR_INVNATIVE) { char native_name[sNAMEMAX+1]; int num = 0; /*//go two instructions back cip -= (sizeof(cell) * 2); int instr = _GetOpcodeFromCip(cip, p_cip); if (instr == OP_SYSREQ_C) { num = (int)*p_cip; }*/ //New code only requires this... num = (int)(_INT_PTR)m_pAmx->usertags[UT_NATIVE]; /*amx_err = */amx_GetNative(m_pAmx, num, native_name); /*if (num) amx_err = amx_GetNative(m_pAmx, (int)*p_cip, native_name); else amx_err = AMX_ERR_NOTFOUND;*/ //if (!amx_err) size += UTIL_Format(buffer, maxLength, "(native \"%s\")", native_name); } return size; }
static cell AMX_NATIVE_CALL invalid_native(AMX *amx, cell *params) { //A script has accidentally called an invalid native! give them a // first chance to block the resulting error. Handler *pHandler = (Handler *)amx->userdata[UD_HANDLER]; //this should never happen if (!pHandler) { LogError(amx, AMX_ERR_INVNATIVE, "Invalid native attempt"); return 0; } //this should never happen because this native won't be called // if the plugin isn't filtering. if (!pHandler->IsNativeFiltering()) { LogError(amx, AMX_ERR_INVNATIVE, "Invalid native attempt"); return 0; } char name[sNAMEMAX + 1]; int native = (int)(_INT_PTR)(amx->usertags[UT_NATIVE]); int err = amx_GetNative(amx, native, name); if (err != AMX_ERR_NONE) name[0] = '\0'; //1 - because we're trapping usage if (!pHandler->HandleNative(name, native, 1)) { amx->usertags[UT_NATIVE] = (void *)native; LogError(amx, AMX_ERR_INVNATIVE, NULL); return 0; } //Someday maybe allow native filters to write their own return value? return 0; }
void BinLog::WritePluginDB(FILE *fp) { int num = g_plugins.getPluginsNum(); fwrite(&num, sizeof(int), 1, fp); CPluginMngr::CPlugin *pl; char c; unsigned char len; for (CPluginMngr::iterator iter = g_plugins.begin(); iter; ++iter) { pl = &(*iter); if (pl->isValid()) c = 1; else c = 0; if (c && pl->isDebug()) c = 2; fwrite(&c, sizeof(char), 1, fp); if (c) { Debugger *pd = NULL; len = (char)strlen(pl->getName()); fwrite(&len, sizeof(char), 1, fp); len++; fwrite(pl->getName(), sizeof(char), len, fp); int natives, publics, files; AMX *amx = pl->getAMX(); // Write the number of Filenames if (c == 2) { pd = static_cast<Debugger *>(amx->userdata[UD_DEBUGGER]); files = pd->m_pAmxDbg->hdr->files; fwrite(&files, sizeof(int), 1, fp); } amx_NumNatives(amx, &natives); amx_NumPublics(amx, &publics); fwrite(&natives, sizeof(int), 1, fp); fwrite(&publics, sizeof(int), 1, fp); char name[34]; // Write the Filenames to the binfile if (c == 2) { AMX_DBG_FILE **ftable = pd->m_pAmxDbg->filetbl; for (int i=0; i<files; i++) { len = (char)strlen(ftable[i]->name); fwrite(&len, sizeof(char), 1, fp); len++; fwrite(ftable[i]->name, sizeof(char), len, fp); } } for (int i=0; i<natives; i++) { amx_GetNative(amx, i, name); len = (char)strlen(name); fwrite(&len, sizeof(char), 1, fp); len++; fwrite(name, sizeof(char), len, fp); } for (int i=0; i<publics; i++) { amx_GetPublic(amx, i, name); len = (char)strlen(name); fwrite(&len, sizeof(char), 1, fp); len++; fwrite(name, sizeof(char), len, fp); } } else { char empty[] = " "; len = 1; fwrite(&len, sizeof(char), 1, fp); fwrite(empty, sizeof(char), len, fp); int no = 0; fwrite(&no, sizeof(int), 1, fp); fwrite(&no, sizeof(int), 1, fp); } } }