Making debug info toggles a flag to allow finer control.

This commit is contained in:
Ben Vanik 2014-01-13 21:12:10 -08:00
parent dfaa0e2d08
commit faa75c9407
13 changed files with 54 additions and 24 deletions

View File

@ -42,7 +42,8 @@ public:
virtual int Assemble( virtual int Assemble(
runtime::FunctionInfo* symbol_info, hir::HIRBuilder* builder, runtime::FunctionInfo* symbol_info, hir::HIRBuilder* builder,
runtime::DebugInfo* debug_info, runtime::Function** out_function) = 0; uint32_t debug_info_flags, runtime::DebugInfo* debug_info,
runtime::Function** out_function) = 0;
protected: protected:
Backend* backend_; Backend* backend_;

View File

@ -55,7 +55,8 @@ void IVMAssembler::Reset() {
int IVMAssembler::Assemble( int IVMAssembler::Assemble(
FunctionInfo* symbol_info, HIRBuilder* builder, FunctionInfo* symbol_info, HIRBuilder* builder,
DebugInfo* debug_info, Function** out_function) { uint32_t debug_info_flags, runtime::DebugInfo* debug_info,
Function** out_function) {
IVMFunction* fn = new IVMFunction(symbol_info); IVMFunction* fn = new IVMFunction(symbol_info);
fn->set_debug_info(debug_info); fn->set_debug_info(debug_info);

View File

@ -31,7 +31,8 @@ public:
virtual int Assemble( virtual int Assemble(
runtime::FunctionInfo* symbol_info, hir::HIRBuilder* builder, runtime::FunctionInfo* symbol_info, hir::HIRBuilder* builder,
runtime::DebugInfo* debug_info, runtime::Function** out_function); uint32_t debug_info_flags, runtime::DebugInfo* debug_info,
runtime::Function** out_function);
private: private:
Arena intcode_arena_; Arena intcode_arena_;

View File

@ -81,7 +81,8 @@ void X64Assembler::Reset() {
int X64Assembler::Assemble( int X64Assembler::Assemble(
FunctionInfo* symbol_info, HIRBuilder* hir_builder, FunctionInfo* symbol_info, HIRBuilder* hir_builder,
DebugInfo* debug_info, Function** out_function) { uint32_t debug_info_flags, DebugInfo* debug_info,
Function** out_function) {
int result = 0; int result = 0;
// Lower HIR -> LIR. // Lower HIR -> LIR.
@ -90,7 +91,7 @@ int X64Assembler::Assemble(
XEEXPECTZERO(result); XEEXPECTZERO(result);
// Stash raw LIR. // Stash raw LIR.
if (debug_info) { if (debug_info_flags & DEBUG_INFO_RAW_LIR_DISASM) {
builder_->Dump(&string_buffer_); builder_->Dump(&string_buffer_);
debug_info->set_raw_lir_disasm(string_buffer_.ToString()); debug_info->set_raw_lir_disasm(string_buffer_.ToString());
string_buffer_.Reset(); string_buffer_.Reset();
@ -101,7 +102,7 @@ int X64Assembler::Assemble(
XEEXPECTZERO(result); XEEXPECTZERO(result);
// Stash optimized LIR. // Stash optimized LIR.
if (debug_info) { if (debug_info_flags & DEBUG_INFO_LIR_DISASM) {
builder_->Dump(&string_buffer_); builder_->Dump(&string_buffer_);
debug_info->set_lir_disasm(string_buffer_.ToString()); debug_info->set_lir_disasm(string_buffer_.ToString());
string_buffer_.Reset(); string_buffer_.Reset();
@ -114,7 +115,7 @@ int X64Assembler::Assemble(
XEEXPECTZERO(result); XEEXPECTZERO(result);
// Stash generated machine code. // Stash generated machine code.
if (debug_info) { if (debug_info_flags & DEBUG_INFO_MACHINE_CODE_DISASM) {
DumpMachineCode(machine_code, code_size, &string_buffer_); DumpMachineCode(machine_code, code_size, &string_buffer_);
debug_info->set_machine_code_disasm(string_buffer_.ToString()); debug_info->set_machine_code_disasm(string_buffer_.ToString());
string_buffer_.Reset(); string_buffer_.Reset();

View File

@ -36,7 +36,8 @@ public:
virtual int Assemble( virtual int Assemble(
runtime::FunctionInfo* symbol_info, hir::HIRBuilder* builder, runtime::FunctionInfo* symbol_info, hir::HIRBuilder* builder,
runtime::DebugInfo* debug_info, runtime::Function** out_function); uint32_t debug_info_flags, runtime::DebugInfo* debug_info,
runtime::Function** out_function);
private: private:
void DumpMachineCode(void* machine_code, size_t code_size, StringBuffer* str); void DumpMachineCode(void* machine_code, size_t code_size, StringBuffer* str);

View File

@ -39,7 +39,7 @@ public:
virtual int DeclareFunction( virtual int DeclareFunction(
runtime::FunctionInfo* symbol_info) = 0; runtime::FunctionInfo* symbol_info) = 0;
virtual int DefineFunction( virtual int DefineFunction(
runtime::FunctionInfo* symbol_info, bool with_debug_info, runtime::FunctionInfo* symbol_info, uint32_t debug_info_flags,
runtime::Function** out_function) = 0; runtime::Function** out_function) = 0;
protected: protected:

View File

@ -92,11 +92,11 @@ int PPCFrontend::DeclareFunction(
} }
int PPCFrontend::DefineFunction( int PPCFrontend::DefineFunction(
FunctionInfo* symbol_info, bool with_debug_info, FunctionInfo* symbol_info, uint32_t debug_info_flags,
Function** out_function) { Function** out_function) {
PPCTranslator* translator = translator_pool_.Allocate(this); PPCTranslator* translator = translator_pool_.Allocate(this);
int result = translator->Translate( int result = translator->Translate(
symbol_info, with_debug_info, out_function); symbol_info, debug_info_flags, out_function);
translator_pool_.Release(translator); translator_pool_.Release(translator);
return result; return result;
} }

View File

@ -32,7 +32,7 @@ public:
virtual int DeclareFunction( virtual int DeclareFunction(
runtime::FunctionInfo* symbol_info); runtime::FunctionInfo* symbol_info);
virtual int DefineFunction( virtual int DefineFunction(
runtime::FunctionInfo* symbol_info, bool with_debug_info, runtime::FunctionInfo* symbol_info, uint32_t debug_info_flags,
runtime::Function** out_function); runtime::Function** out_function);
private: private:

View File

@ -58,7 +58,7 @@ PPCTranslator::~PPCTranslator() {
int PPCTranslator::Translate( int PPCTranslator::Translate(
FunctionInfo* symbol_info, FunctionInfo* symbol_info,
bool with_debug_info, uint32_t debug_info_flags,
Function** out_function) { Function** out_function) {
// Scan the function to find its extents. We only need to do this if we // Scan the function to find its extents. We only need to do this if we
// haven't already been provided with them from some other source. // haven't already been provided with them from some other source.
@ -73,20 +73,25 @@ int PPCTranslator::Translate(
} }
// NOTE: we only want to do this when required, as it's expensive to build. // NOTE: we only want to do this when required, as it's expensive to build.
if (FLAGS_always_disasm) {
debug_info_flags |= DEBUG_INFO_ALL_DISASM;
}
DebugInfo* debug_info = NULL; DebugInfo* debug_info = NULL;
if (FLAGS_always_disasm || with_debug_info) { if (debug_info_flags) {
debug_info = new DebugInfo(); debug_info = new DebugInfo();
} }
// Stash source. // Stash source.
if (debug_info) { if (debug_info_flags & DEBUG_INFO_SOURCE_DISASM) {
DumpSource(symbol_info, &string_buffer_); DumpSource(symbol_info, &string_buffer_);
debug_info->set_source_disasm(string_buffer_.ToString()); debug_info->set_source_disasm(string_buffer_.ToString());
string_buffer_.Reset(); string_buffer_.Reset();
DumpSourceJson(symbol_info, &string_buffer_); if (debug_info_flags & DEBUG_INFO_JSON) {
debug_info->set_source_json(string_buffer_.ToString()); DumpSourceJson(symbol_info, &string_buffer_);
string_buffer_.Reset(); debug_info->set_source_json(string_buffer_.ToString());
string_buffer_.Reset();
}
} }
// Emit function. // Emit function.
@ -94,7 +99,7 @@ int PPCTranslator::Translate(
XEEXPECTZERO(result); XEEXPECTZERO(result);
// Stash raw HIR. // Stash raw HIR.
if (debug_info) { if (debug_info_flags & DEBUG_INFO_RAW_HIR_DISASM) {
builder_->Dump(&string_buffer_); builder_->Dump(&string_buffer_);
debug_info->set_raw_hir_disasm(string_buffer_.ToString()); debug_info->set_raw_hir_disasm(string_buffer_.ToString());
string_buffer_.Reset(); string_buffer_.Reset();
@ -105,14 +110,17 @@ int PPCTranslator::Translate(
XEEXPECTZERO(result); XEEXPECTZERO(result);
// Stash optimized HIR. // Stash optimized HIR.
if (debug_info) { if (debug_info_flags & DEBUG_INFO_HIR_DISASM) {
builder_->Dump(&string_buffer_); builder_->Dump(&string_buffer_);
debug_info->set_hir_disasm(string_buffer_.ToString()); debug_info->set_hir_disasm(string_buffer_.ToString());
string_buffer_.Reset(); string_buffer_.Reset();
} }
// Assemble to backend machine code. // Assemble to backend machine code.
result = assembler_->Assemble(symbol_info, builder_, debug_info, out_function); result = assembler_->Assemble(
symbol_info, builder_,
debug_info_flags, debug_info,
out_function);
XEEXPECTZERO(result); XEEXPECTZERO(result);
result = 0; result = 0;

View File

@ -31,7 +31,7 @@ public:
~PPCTranslator(); ~PPCTranslator();
int Translate(runtime::FunctionInfo* symbol_info, int Translate(runtime::FunctionInfo* symbol_info,
bool with_debug_info, uint32_t debug_info_flags,
runtime::Function** out_function); runtime::Function** out_function);
private: private:

View File

@ -17,6 +17,22 @@ namespace alloy {
namespace runtime { namespace runtime {
enum DebugInfoFlags {
DEBUG_INFO_NONE = 0,
DEBUG_INFO_SOURCE_DISASM = (1 << 1),
DEBUG_INFO_RAW_HIR_DISASM = (1 << 2),
DEBUG_INFO_HIR_DISASM = (1 << 3),
DEBUG_INFO_RAW_LIR_DISASM = (1 << 4),
DEBUG_INFO_LIR_DISASM = (1 << 5),
DEBUG_INFO_MACHINE_CODE_DISASM = (1 << 6),
DEBUG_INFO_ALL_DISASM = 0xFFFF,
DEBUG_INFO_JSON = (1 << 16),
};
class DebugInfo { class DebugInfo {
public: public:
DebugInfo(); DebugInfo();

View File

@ -250,7 +250,7 @@ int Runtime::DemandFunction(
if (symbol_status == SymbolInfo::STATUS_NEW) { if (symbol_status == SymbolInfo::STATUS_NEW) {
// Symbol is undefined, so define now. // Symbol is undefined, so define now.
Function* function = NULL; Function* function = NULL;
int result = frontend_->DefineFunction(symbol_info, false, &function); int result = frontend_->DefineFunction(symbol_info, DEBUG_INFO_NONE, &function);
if (result) { if (result) {
symbol_info->set_status(SymbolInfo::STATUS_FAILED); symbol_info->set_status(SymbolInfo::STATUS_FAILED);
return result; return result;

View File

@ -662,7 +662,8 @@ json_t* Processor::DumpFunction(uint64_t address, bool& succeeded) {
// If we ever wanted absolute x64 addresses/etc we could // If we ever wanted absolute x64 addresses/etc we could
// use the x64 from the function in the symbol table. // use the x64 from the function in the symbol table.
Function* fn; Function* fn;
if (runtime_->frontend()->DefineFunction(info, true, &fn)) { if (runtime_->frontend()->DefineFunction(
info, DEBUG_INFO_ALL_DISASM | DEBUG_INFO_JSON, &fn)) {
succeeded = false; succeeded = false;
return json_string("Unable to resolve function"); return json_string("Unable to resolve function");
} }