Better asserts/checks around bad function addresses.

This commit is contained in:
Ben Vanik 2013-05-26 03:26:49 -07:00
parent bf9e92c027
commit 22f186d713
4 changed files with 11 additions and 1 deletions

View File

@ -36,6 +36,8 @@ void* _cdecl XeIndirectBranch(
// TODO(benvanik): track this statistic - this path is very slow!
Processor* processor = (Processor*)state->processor;
void* target_ptr = processor->GetFunctionPointer((uint32_t)target);
// target_ptr will be null when the given target is not a function.
XEASSERTNOTNULL(target_ptr);
return target_ptr;
}

View File

@ -244,7 +244,7 @@ FunctionSymbol* Processor::GetFunction(uint32_t address) {
void* Processor::GetFunctionPointer(uint32_t address) {
// Attempt to get the function.
FunctionSymbol* fn_symbol = GetFunction(address);
if (!fn_symbol) {
if (!fn_symbol || fn_symbol->type == FunctionSymbol::Unknown) {
return NULL;
}

View File

@ -148,6 +148,8 @@ VariableSymbol* SymbolDatabase::GetOrInsertVariable(uint32_t address) {
}
FunctionSymbol* SymbolDatabase::GetFunction(uint32_t address, bool analyze) {
XEASSERT(address);
SymbolMap::iterator i = symbols_.find(address);
if (i != symbols_.end() && i->second->symbol_type == Symbol::Function) {
return static_cast<FunctionSymbol*>(i->second);

View File

@ -106,6 +106,8 @@ int X64Emitter::PrepareFunction(FunctionSymbol* symbol) {
XESUCCEED();
}
XEASSERT(symbol->type != FunctionSymbol::Unknown);
// Create the custom redirector function.
// This function will jump to the on-demand compilation routine to
// generate the real function as required. Afterwards, it will be
@ -592,6 +594,10 @@ void X64Emitter::GenerateBasicBlock(FunctionBlock* block) {
}
}
if (FLAGS_log_codegen) {
fflush(stdout);
}
TraceInstruction(i);
if (!i.type) {