Fixed horrendous crash in the JIT from packing change in the debug table (bug 3334, r=me).
I accidentally changed the debug table packing in a commit a while ago. This explains the nonsense debug output and crashes people have been getting on the 1.1 branch. Fortunately this is (mostly) detectable via the "debug.natives" table and the JIT will unpack symbols based on that information.
This commit is contained in:
@@ -69,6 +69,11 @@ int BaseRuntime::CreateFromMemory(sp_file_hdr_t *hdr, uint8_t *base)
|
||||
plugin->base_size = hdr->imagesize;
|
||||
set_err = SP_ERROR_NONE;
|
||||
|
||||
if (hdr->version == 0x0101)
|
||||
{
|
||||
plugin->debug.unpacked = true;
|
||||
}
|
||||
|
||||
/* We have to read the name section first */
|
||||
for (sectnum = 0; sectnum < hdr->sections; sectnum++)
|
||||
{
|
||||
@@ -195,6 +200,10 @@ int BaseRuntime::CreateFromMemory(sp_file_hdr_t *hdr, uint8_t *base)
|
||||
{
|
||||
plugin->debug.stringbase = (const char *)(base + secptr->dataoffs);
|
||||
}
|
||||
else if (strcmp(nameptr, ".dbg.natives") == 0)
|
||||
{
|
||||
plugin->debug.unpacked = false;
|
||||
}
|
||||
|
||||
secptr++;
|
||||
sectnum++;
|
||||
|
||||
@@ -88,7 +88,6 @@ IPluginRuntime *SourcePawnEngine2::LoadPlugin(ICompilation *co, const char *file
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pRuntime = new BaseRuntime();
|
||||
if ((error = pRuntime->CreateFromMemory(&hdr, base)) != SP_ERROR_NONE)
|
||||
{
|
||||
|
||||
@@ -19,6 +19,7 @@ typedef struct sp_plugin_debug_s
|
||||
sp_fdbg_line_t *lines; /**< lines table */
|
||||
uint32_t syms_num; /**< number of symbols */
|
||||
sp_fdbg_symbol_t *symbols; /**< symbol table */
|
||||
bool unpacked; /**< Whether debug structures are unpacked */
|
||||
} sp_plugin_debug_t;
|
||||
|
||||
class BaseContext;
|
||||
|
||||
@@ -742,37 +742,72 @@ int DebugInfo::LookupFile(ucell_t addr, const char **filename)
|
||||
|
||||
int DebugInfo::LookupFunction(ucell_t addr, const char **name)
|
||||
{
|
||||
uint32_t max, iter;
|
||||
sp_fdbg_symbol_t *sym;
|
||||
sp_fdbg_arraydim_t *arr;
|
||||
uint8_t *cursor = (uint8_t *)(m_pPlugin->debug.symbols);
|
||||
|
||||
max = m_pPlugin->debug.syms_num;
|
||||
for (iter = 0; iter < max; iter++)
|
||||
if (!m_pPlugin->debug.unpacked)
|
||||
{
|
||||
sym = (sp_fdbg_symbol_t *)cursor;
|
||||
uint32_t max, iter;
|
||||
sp_fdbg_symbol_t *sym;
|
||||
sp_fdbg_arraydim_t *arr;
|
||||
uint8_t *cursor = (uint8_t *)(m_pPlugin->debug.symbols);
|
||||
|
||||
if (sym->ident == SP_SYM_FUNCTION
|
||||
&& sym->codestart <= addr
|
||||
&& sym->codeend > addr)
|
||||
max = m_pPlugin->debug.syms_num;
|
||||
for (iter = 0; iter < max; iter++)
|
||||
{
|
||||
*name = m_pPlugin->debug.stringbase + sym->name;
|
||||
return SP_ERROR_NONE;
|
||||
}
|
||||
sym = (sp_fdbg_symbol_t *)cursor;
|
||||
|
||||
if (sym->ident == SP_SYM_FUNCTION
|
||||
&& sym->codestart <= addr
|
||||
&& sym->codeend > addr)
|
||||
{
|
||||
*name = m_pPlugin->debug.stringbase + sym->name;
|
||||
return SP_ERROR_NONE;
|
||||
}
|
||||
|
||||
if (sym->dimcount > 0)
|
||||
{
|
||||
cursor += sizeof(sp_fdbg_symbol_t);
|
||||
arr = (sp_fdbg_arraydim_t *)cursor;
|
||||
cursor += sizeof(sp_fdbg_arraydim_t) * sym->dimcount;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sym->dimcount > 0)
|
||||
{
|
||||
cursor += sizeof(sp_fdbg_symbol_t);
|
||||
arr = (sp_fdbg_arraydim_t *)cursor;
|
||||
cursor += sizeof(sp_fdbg_arraydim_t) * sym->dimcount;
|
||||
continue;
|
||||
}
|
||||
|
||||
cursor += sizeof(sp_fdbg_symbol_t);
|
||||
return SP_ERROR_NOT_FOUND;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t max, iter;
|
||||
sp_u_fdbg_symbol_t *sym;
|
||||
sp_u_fdbg_arraydim_t *arr;
|
||||
uint8_t *cursor = (uint8_t *)(m_pPlugin->debug.symbols);
|
||||
|
||||
return SP_ERROR_NOT_FOUND;
|
||||
max = m_pPlugin->debug.syms_num;
|
||||
for (iter = 0; iter < max; iter++)
|
||||
{
|
||||
sym = (sp_u_fdbg_symbol_t *)cursor;
|
||||
|
||||
if (sym->ident == SP_SYM_FUNCTION
|
||||
&& sym->codestart <= addr
|
||||
&& sym->codeend > addr)
|
||||
{
|
||||
*name = m_pPlugin->debug.stringbase + sym->name;
|
||||
return SP_ERROR_NONE;
|
||||
}
|
||||
|
||||
if (sym->dimcount > 0)
|
||||
{
|
||||
cursor += sizeof(sp_u_fdbg_symbol_t);
|
||||
arr = (sp_u_fdbg_arraydim_t *)cursor;
|
||||
cursor += sizeof(sp_u_fdbg_arraydim_t) * sym->dimcount;
|
||||
continue;
|
||||
}
|
||||
|
||||
cursor += sizeof(sp_u_fdbg_symbol_t);
|
||||
}
|
||||
|
||||
return SP_ERROR_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
int DebugInfo::LookupLine(ucell_t addr, uint32_t *line)
|
||||
|
||||
@@ -1344,32 +1344,65 @@ void ProfCallGate_End(sp_context_t *ctx)
|
||||
|
||||
const char *find_func_name(sp_plugin_t *plugin, uint32_t offs)
|
||||
{
|
||||
uint32_t max, iter;
|
||||
sp_fdbg_symbol_t *sym;
|
||||
sp_fdbg_arraydim_t *arr;
|
||||
uint8_t *cursor = (uint8_t *)(plugin->debug.symbols);
|
||||
|
||||
max = plugin->debug.syms_num;
|
||||
for (iter = 0; iter < max; iter++)
|
||||
if (!plugin->debug.unpacked)
|
||||
{
|
||||
sym = (sp_fdbg_symbol_t *)cursor;
|
||||
uint32_t max, iter;
|
||||
sp_fdbg_symbol_t *sym;
|
||||
sp_fdbg_arraydim_t *arr;
|
||||
uint8_t *cursor = (uint8_t *)(plugin->debug.symbols);
|
||||
|
||||
if (sym->ident == SP_SYM_FUNCTION
|
||||
&& sym->codestart <= offs
|
||||
&& sym->codeend > offs)
|
||||
max = plugin->debug.syms_num;
|
||||
for (iter = 0; iter < max; iter++)
|
||||
{
|
||||
return plugin->debug.stringbase + sym->name;
|
||||
}
|
||||
sym = (sp_fdbg_symbol_t *)cursor;
|
||||
|
||||
if (sym->ident == SP_SYM_FUNCTION
|
||||
&& sym->codestart <= offs
|
||||
&& sym->codeend > offs)
|
||||
{
|
||||
return plugin->debug.stringbase + sym->name;
|
||||
}
|
||||
|
||||
if (sym->dimcount > 0)
|
||||
{
|
||||
cursor += sizeof(sp_fdbg_symbol_t);
|
||||
arr = (sp_fdbg_arraydim_t *)cursor;
|
||||
cursor += sizeof(sp_fdbg_arraydim_t) * sym->dimcount;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sym->dimcount > 0)
|
||||
{
|
||||
cursor += sizeof(sp_fdbg_symbol_t);
|
||||
arr = (sp_fdbg_arraydim_t *)cursor;
|
||||
cursor += sizeof(sp_fdbg_arraydim_t) * sym->dimcount;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t max, iter;
|
||||
sp_u_fdbg_symbol_t *sym;
|
||||
sp_u_fdbg_arraydim_t *arr;
|
||||
uint8_t *cursor = (uint8_t *)(plugin->debug.symbols);
|
||||
|
||||
cursor += sizeof(sp_fdbg_symbol_t);
|
||||
max = plugin->debug.syms_num;
|
||||
for (iter = 0; iter < max; iter++)
|
||||
{
|
||||
sym = (sp_u_fdbg_symbol_t *)cursor;
|
||||
|
||||
if (sym->ident == SP_SYM_FUNCTION
|
||||
&& sym->codestart <= offs
|
||||
&& sym->codeend > offs)
|
||||
{
|
||||
return plugin->debug.stringbase + sym->name;
|
||||
}
|
||||
|
||||
if (sym->dimcount > 0)
|
||||
{
|
||||
cursor += sizeof(sp_u_fdbg_symbol_t);
|
||||
arr = (sp_u_fdbg_arraydim_t *)cursor;
|
||||
cursor += sizeof(sp_u_fdbg_arraydim_t) * sym->dimcount;
|
||||
continue;
|
||||
}
|
||||
|
||||
cursor += sizeof(sp_u_fdbg_symbol_t);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
Reference in New Issue
Block a user