diff --git a/src/alloy/backend/assembler.h b/src/alloy/backend/assembler.h index 7b686ee5e..9652bee37 100644 --- a/src/alloy/backend/assembler.h +++ b/src/alloy/backend/assembler.h @@ -42,7 +42,8 @@ public: virtual int Assemble( 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: Backend* backend_; diff --git a/src/alloy/backend/ivm/ivm_assembler.cc b/src/alloy/backend/ivm/ivm_assembler.cc index 58053a950..d2b08b964 100644 --- a/src/alloy/backend/ivm/ivm_assembler.cc +++ b/src/alloy/backend/ivm/ivm_assembler.cc @@ -55,7 +55,8 @@ void IVMAssembler::Reset() { int IVMAssembler::Assemble( 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); fn->set_debug_info(debug_info); diff --git a/src/alloy/backend/ivm/ivm_assembler.h b/src/alloy/backend/ivm/ivm_assembler.h index 1a03b0fad..5da5a2412 100644 --- a/src/alloy/backend/ivm/ivm_assembler.h +++ b/src/alloy/backend/ivm/ivm_assembler.h @@ -31,7 +31,8 @@ public: virtual int Assemble( 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: Arena intcode_arena_; diff --git a/src/alloy/backend/x64/x64_assembler.cc b/src/alloy/backend/x64/x64_assembler.cc index 29290e7e8..414b1f9d6 100644 --- a/src/alloy/backend/x64/x64_assembler.cc +++ b/src/alloy/backend/x64/x64_assembler.cc @@ -81,7 +81,8 @@ void X64Assembler::Reset() { int X64Assembler::Assemble( 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; // Lower HIR -> LIR. @@ -90,7 +91,7 @@ int X64Assembler::Assemble( XEEXPECTZERO(result); // Stash raw LIR. - if (debug_info) { + if (debug_info_flags & DEBUG_INFO_RAW_LIR_DISASM) { builder_->Dump(&string_buffer_); debug_info->set_raw_lir_disasm(string_buffer_.ToString()); string_buffer_.Reset(); @@ -101,7 +102,7 @@ int X64Assembler::Assemble( XEEXPECTZERO(result); // Stash optimized LIR. - if (debug_info) { + if (debug_info_flags & DEBUG_INFO_LIR_DISASM) { builder_->Dump(&string_buffer_); debug_info->set_lir_disasm(string_buffer_.ToString()); string_buffer_.Reset(); @@ -114,7 +115,7 @@ int X64Assembler::Assemble( XEEXPECTZERO(result); // Stash generated machine code. - if (debug_info) { + if (debug_info_flags & DEBUG_INFO_MACHINE_CODE_DISASM) { DumpMachineCode(machine_code, code_size, &string_buffer_); debug_info->set_machine_code_disasm(string_buffer_.ToString()); string_buffer_.Reset(); diff --git a/src/alloy/backend/x64/x64_assembler.h b/src/alloy/backend/x64/x64_assembler.h index bfb8d557c..db50b6350 100644 --- a/src/alloy/backend/x64/x64_assembler.h +++ b/src/alloy/backend/x64/x64_assembler.h @@ -36,7 +36,8 @@ public: virtual int Assemble( 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: void DumpMachineCode(void* machine_code, size_t code_size, StringBuffer* str); diff --git a/src/alloy/frontend/frontend.h b/src/alloy/frontend/frontend.h index 1686dbf06..c8a13b027 100644 --- a/src/alloy/frontend/frontend.h +++ b/src/alloy/frontend/frontend.h @@ -39,7 +39,7 @@ public: virtual int DeclareFunction( runtime::FunctionInfo* symbol_info) = 0; 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; protected: diff --git a/src/alloy/frontend/ppc/ppc_frontend.cc b/src/alloy/frontend/ppc/ppc_frontend.cc index eb416927d..4b9bb5a3d 100644 --- a/src/alloy/frontend/ppc/ppc_frontend.cc +++ b/src/alloy/frontend/ppc/ppc_frontend.cc @@ -92,11 +92,11 @@ int PPCFrontend::DeclareFunction( } int PPCFrontend::DefineFunction( - FunctionInfo* symbol_info, bool with_debug_info, + FunctionInfo* symbol_info, uint32_t debug_info_flags, Function** out_function) { PPCTranslator* translator = translator_pool_.Allocate(this); int result = translator->Translate( - symbol_info, with_debug_info, out_function); + symbol_info, debug_info_flags, out_function); translator_pool_.Release(translator); return result; } diff --git a/src/alloy/frontend/ppc/ppc_frontend.h b/src/alloy/frontend/ppc/ppc_frontend.h index 14a3b31e3..612b7c1b2 100644 --- a/src/alloy/frontend/ppc/ppc_frontend.h +++ b/src/alloy/frontend/ppc/ppc_frontend.h @@ -32,7 +32,7 @@ public: virtual int DeclareFunction( runtime::FunctionInfo* symbol_info); virtual int DefineFunction( - runtime::FunctionInfo* symbol_info, bool with_debug_info, + runtime::FunctionInfo* symbol_info, uint32_t debug_info_flags, runtime::Function** out_function); private: diff --git a/src/alloy/frontend/ppc/ppc_translator.cc b/src/alloy/frontend/ppc/ppc_translator.cc index efc0b8d5d..9e02475fc 100644 --- a/src/alloy/frontend/ppc/ppc_translator.cc +++ b/src/alloy/frontend/ppc/ppc_translator.cc @@ -58,7 +58,7 @@ PPCTranslator::~PPCTranslator() { int PPCTranslator::Translate( FunctionInfo* symbol_info, - bool with_debug_info, + uint32_t debug_info_flags, Function** out_function) { // 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. @@ -73,20 +73,25 @@ int PPCTranslator::Translate( } // 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; - if (FLAGS_always_disasm || with_debug_info) { + if (debug_info_flags) { debug_info = new DebugInfo(); } // Stash source. - if (debug_info) { + if (debug_info_flags & DEBUG_INFO_SOURCE_DISASM) { DumpSource(symbol_info, &string_buffer_); debug_info->set_source_disasm(string_buffer_.ToString()); string_buffer_.Reset(); - DumpSourceJson(symbol_info, &string_buffer_); - debug_info->set_source_json(string_buffer_.ToString()); - string_buffer_.Reset(); + if (debug_info_flags & DEBUG_INFO_JSON) { + DumpSourceJson(symbol_info, &string_buffer_); + debug_info->set_source_json(string_buffer_.ToString()); + string_buffer_.Reset(); + } } // Emit function. @@ -94,7 +99,7 @@ int PPCTranslator::Translate( XEEXPECTZERO(result); // Stash raw HIR. - if (debug_info) { + if (debug_info_flags & DEBUG_INFO_RAW_HIR_DISASM) { builder_->Dump(&string_buffer_); debug_info->set_raw_hir_disasm(string_buffer_.ToString()); string_buffer_.Reset(); @@ -105,14 +110,17 @@ int PPCTranslator::Translate( XEEXPECTZERO(result); // Stash optimized HIR. - if (debug_info) { + if (debug_info_flags & DEBUG_INFO_HIR_DISASM) { builder_->Dump(&string_buffer_); debug_info->set_hir_disasm(string_buffer_.ToString()); string_buffer_.Reset(); } // 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); result = 0; diff --git a/src/alloy/frontend/ppc/ppc_translator.h b/src/alloy/frontend/ppc/ppc_translator.h index 83bfce152..deda74313 100644 --- a/src/alloy/frontend/ppc/ppc_translator.h +++ b/src/alloy/frontend/ppc/ppc_translator.h @@ -31,7 +31,7 @@ public: ~PPCTranslator(); int Translate(runtime::FunctionInfo* symbol_info, - bool with_debug_info, + uint32_t debug_info_flags, runtime::Function** out_function); private: diff --git a/src/alloy/runtime/debug_info.h b/src/alloy/runtime/debug_info.h index 46131d029..b51ceefec 100644 --- a/src/alloy/runtime/debug_info.h +++ b/src/alloy/runtime/debug_info.h @@ -17,6 +17,22 @@ namespace alloy { 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 { public: DebugInfo(); diff --git a/src/alloy/runtime/runtime.cc b/src/alloy/runtime/runtime.cc index 2cda2c6f8..95e27a2d2 100644 --- a/src/alloy/runtime/runtime.cc +++ b/src/alloy/runtime/runtime.cc @@ -250,7 +250,7 @@ int Runtime::DemandFunction( if (symbol_status == SymbolInfo::STATUS_NEW) { // Symbol is undefined, so define now. Function* function = NULL; - int result = frontend_->DefineFunction(symbol_info, false, &function); + int result = frontend_->DefineFunction(symbol_info, DEBUG_INFO_NONE, &function); if (result) { symbol_info->set_status(SymbolInfo::STATUS_FAILED); return result; diff --git a/src/xenia/cpu/processor.cc b/src/xenia/cpu/processor.cc index b292a9e14..281a33c07 100644 --- a/src/xenia/cpu/processor.cc +++ b/src/xenia/cpu/processor.cc @@ -662,7 +662,8 @@ json_t* Processor::DumpFunction(uint64_t address, bool& succeeded) { // If we ever wanted absolute x64 addresses/etc we could // use the x64 from the function in the symbol table. Function* fn; - if (runtime_->frontend()->DefineFunction(info, true, &fn)) { + if (runtime_->frontend()->DefineFunction( + info, DEBUG_INFO_ALL_DISASM | DEBUG_INFO_JSON, &fn)) { succeeded = false; return json_string("Unable to resolve function"); }