added sm_dump_handles command for tracking down Handle leaks... more to come someday
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40906
This commit is contained in:
parent
897135194b
commit
00e9d047c7
@ -15,6 +15,7 @@
|
||||
#include "sm_srvcmds.h"
|
||||
#include "sm_version.h"
|
||||
#include "sm_stringutil.h"
|
||||
#include "HandleSys.h"
|
||||
|
||||
RootConsoleMenu g_RootMenu;
|
||||
|
||||
@ -254,3 +255,24 @@ CON_COMMAND(sm, "SourceMod Menu")
|
||||
{
|
||||
g_RootMenu.GotRootCmd();
|
||||
}
|
||||
|
||||
CON_COMMAND(sm_dump_handles, "Dumps Handle usage to a file for finding Handle leaks")
|
||||
{
|
||||
if (engine->Cmd_Argc() < 2)
|
||||
{
|
||||
g_RootMenu.ConsolePrint("Usage: sm_dump_handles <file>");
|
||||
return;
|
||||
}
|
||||
|
||||
const char *arg = engine->Cmd_Argv(1);
|
||||
FILE *fp = fopen(arg, "wt");
|
||||
if (!fp)
|
||||
{
|
||||
g_RootMenu.ConsolePrint("Could not find file \"%s\"", arg);
|
||||
return;
|
||||
}
|
||||
|
||||
g_HandleSys.Dump(fp);
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "HandleSys.h"
|
||||
#include "ShareSys.h"
|
||||
#include "PluginSys.h"
|
||||
#include "ExtensionSys.h"
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
@ -899,3 +900,52 @@ bool HandleSystem::InitAccessDefaults(TypeAccess *pTypeAccess, HandleAccess *pHa
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void HandleSystem::Dump(FILE *fp)
|
||||
{
|
||||
fprintf(fp, "%-10.10s\t%-20.20s\t%-20.20s\n", "Handle", "Owner", "Type");
|
||||
fprintf(fp, "---------------------------------------------\n");
|
||||
for (unsigned int i=1; i<=m_HandleTail; i++)
|
||||
{
|
||||
if (m_Handles[i].set == HandleSet_Freed
|
||||
|| m_Handles[i].set == HandleSet_Identity)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
/* Get the index */
|
||||
unsigned int index = (m_Handles[i].serial << 16) | i;
|
||||
/* Determine the owner */
|
||||
const char *owner = "UNKNOWN";
|
||||
if (m_Handles[i].owner)
|
||||
{
|
||||
IdentityToken_t *pOwner = m_Handles[i].owner;
|
||||
if (pOwner == g_pCoreIdent)
|
||||
{
|
||||
owner = "CORE";
|
||||
} else if (pOwner == g_PluginSys.GetIdentity()) {
|
||||
owner = "PLUGINSYS";
|
||||
} else {
|
||||
CExtension *ext = g_Extensions.GetExtensionFromIdent(pOwner);
|
||||
if (ext)
|
||||
{
|
||||
owner = ext->GetFilename();
|
||||
} else {
|
||||
CPlugin *pPlugin = g_PluginSys.GetPluginFromIdentity(pOwner);
|
||||
if (pPlugin)
|
||||
{
|
||||
owner = pPlugin->GetFilename();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
owner = "NONE";
|
||||
}
|
||||
const char *type = "ANON";
|
||||
QHandleType *pType = &m_Types[m_Handles[i].type];
|
||||
if (pType->nameIdx != -1)
|
||||
{
|
||||
type = m_strtab->GetString(pType->nameIdx);
|
||||
}
|
||||
fprintf(fp, "0x%08x\t%-20.20s\t%-20.20s\n", index, owner, type);
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
#define _INCLUDE_SOURCEMOD_HANDLESYSTEM_H_
|
||||
|
||||
#include <IHandleSys.h>
|
||||
#include <stdio.h>
|
||||
#include "sm_globals.h"
|
||||
#include "sm_trie.h"
|
||||
#include "sourcemod.h"
|
||||
@ -136,6 +137,8 @@ public: //IHandleSystem
|
||||
const HandleSecurity *pSec,
|
||||
const HandleAccess *pAccess,
|
||||
HandleError *err);
|
||||
|
||||
void Dump(FILE *fp);
|
||||
protected:
|
||||
/**
|
||||
* Decodes a handle with sanity and security checking.
|
||||
|
@ -1961,3 +1961,13 @@ void CPluginManager::AddFunctionsToForward(const char *name, IChangeableForward
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CPlugin *CPluginManager::GetPluginFromIdentity(IdentityToken_t *pToken)
|
||||
{
|
||||
if (pToken->type != g_PluginIdent)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (CPlugin *)(pToken->ptr);
|
||||
}
|
||||
|
@ -362,6 +362,8 @@ public:
|
||||
*/
|
||||
void AddFunctionsToForward(const char *name, IChangeableForward *pForward);
|
||||
|
||||
CPlugin *GetPluginFromIdentity(IdentityToken_t *pToken);
|
||||
|
||||
private:
|
||||
LoadRes _LoadPlugin(CPlugin **pPlugin, const char *path, bool debug, PluginType type, char error[], size_t maxlength);
|
||||
|
||||
@ -398,6 +400,7 @@ protected:
|
||||
* Caching internal objects
|
||||
*/
|
||||
void ReleaseIterator(CPluginIterator *iter);
|
||||
public:
|
||||
inline IdentityToken_t *GetIdentity()
|
||||
{
|
||||
return m_MyIdent;
|
||||
|
Loading…
Reference in New Issue
Block a user