From 499bed21c0bdd79c2673ecd0569d55270fab901f Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Mon, 4 May 2015 20:57:46 -0700 Subject: [PATCH] Moving debugger. --- src/xenia/cpu/backend/x64/x64_function.cc | 6 ++- src/xenia/cpu/backend/x64/x64_function.h | 4 +- src/xenia/cpu/frontend/ppc_frontend.cc | 2 - src/xenia/cpu/function.cc | 3 +- src/xenia/cpu/function.h | 14 ++--- src/xenia/cpu/processor.cc | 3 +- src/xenia/cpu/processor.h | 12 +++-- src/xenia/cpu/sources.gypi | 2 - src/xenia/cpu/thread_state.cc | 1 + src/xenia/debug/breakpoint.h | 45 ++++++++++++++++ src/xenia/debug/debug_server.cc | 18 +++++++ src/xenia/debug/debug_server.h | 21 ++++++++ src/xenia/{cpu => debug}/debugger.cc | 14 ++--- src/xenia/{cpu => debug}/debugger.h | 63 +++++++++-------------- src/xenia/debug/sources.gypi | 11 ++++ src/xenia/debug/trace_writer.cc | 18 +++++++ src/xenia/debug/trace_writer.h | 29 +++++++++++ src/xenia/sources.gypi | 1 + 18 files changed, 200 insertions(+), 67 deletions(-) create mode 100644 src/xenia/debug/breakpoint.h create mode 100644 src/xenia/debug/debug_server.cc create mode 100644 src/xenia/debug/debug_server.h rename src/xenia/{cpu => debug}/debugger.cc (94%) rename src/xenia/{cpu => debug}/debugger.h (63%) create mode 100644 src/xenia/debug/sources.gypi create mode 100644 src/xenia/debug/trace_writer.cc create mode 100644 src/xenia/debug/trace_writer.h diff --git a/src/xenia/cpu/backend/x64/x64_function.cc b/src/xenia/cpu/backend/x64/x64_function.cc index 99cd73e44..42c81a475 100644 --- a/src/xenia/cpu/backend/x64/x64_function.cc +++ b/src/xenia/cpu/backend/x64/x64_function.cc @@ -30,9 +30,11 @@ void X64Function::Setup(void* machine_code, size_t code_size) { code_size_ = code_size; } -int X64Function::AddBreakpointImpl(Breakpoint* breakpoint) { return 0; } +int X64Function::AddBreakpointImpl(debug::Breakpoint* breakpoint) { return 0; } -int X64Function::RemoveBreakpointImpl(Breakpoint* breakpoint) { return 0; } +int X64Function::RemoveBreakpointImpl(debug::Breakpoint* breakpoint) { + return 0; +} int X64Function::CallImpl(ThreadState* thread_state, uint32_t return_address) { auto backend = diff --git a/src/xenia/cpu/backend/x64/x64_function.h b/src/xenia/cpu/backend/x64/x64_function.h index 49e1fe15e..614bc4390 100644 --- a/src/xenia/cpu/backend/x64/x64_function.h +++ b/src/xenia/cpu/backend/x64/x64_function.h @@ -30,8 +30,8 @@ class X64Function : public Function { void Setup(void* machine_code, size_t code_size); protected: - virtual int AddBreakpointImpl(Breakpoint* breakpoint); - virtual int RemoveBreakpointImpl(Breakpoint* breakpoint); + virtual int AddBreakpointImpl(debug::Breakpoint* breakpoint); + virtual int RemoveBreakpointImpl(debug::Breakpoint* breakpoint); virtual int CallImpl(ThreadState* thread_state, uint32_t return_address); private: diff --git a/src/xenia/cpu/frontend/ppc_frontend.cc b/src/xenia/cpu/frontend/ppc_frontend.cc index dfa2707d0..261809d84 100644 --- a/src/xenia/cpu/frontend/ppc_frontend.cc +++ b/src/xenia/cpu/frontend/ppc_frontend.cc @@ -19,8 +19,6 @@ namespace xe { namespace cpu { namespace frontend { -using xe::cpu::Runtime; - void InitializeIfNeeded(); void CleanupOnShutdown(); diff --git a/src/xenia/cpu/function.cc b/src/xenia/cpu/function.cc index c0399808a..9f90044af 100644 --- a/src/xenia/cpu/function.cc +++ b/src/xenia/cpu/function.cc @@ -10,13 +10,14 @@ #include "xenia/cpu/function.h" #include "xenia/base/logging.h" -#include "xenia/cpu/debugger.h" #include "xenia/cpu/symbol_info.h" #include "xenia/cpu/thread_state.h" namespace xe { namespace cpu { +using xe::debug::Breakpoint; + Function::Function(FunctionInfo* symbol_info) : address_(symbol_info->address()), symbol_info_(symbol_info) {} diff --git a/src/xenia/cpu/function.h b/src/xenia/cpu/function.h index 25c8fa37b..4c457fb20 100644 --- a/src/xenia/cpu/function.h +++ b/src/xenia/cpu/function.h @@ -16,11 +16,11 @@ #include "xenia/cpu/debug_info.h" #include "xenia/cpu/thread_state.h" +#include "xenia/debug/breakpoint.h" namespace xe { namespace cpu { -class Breakpoint; class FunctionInfo; class Function { @@ -36,15 +36,15 @@ class Function { debug_info_ = std::move(debug_info); } - int AddBreakpoint(Breakpoint* breakpoint); - int RemoveBreakpoint(Breakpoint* breakpoint); + int AddBreakpoint(debug::Breakpoint* breakpoint); + int RemoveBreakpoint(debug::Breakpoint* breakpoint); int Call(ThreadState* thread_state, uint32_t return_address); protected: - Breakpoint* FindBreakpoint(uint32_t address); - virtual int AddBreakpointImpl(Breakpoint* breakpoint) { return 0; } - virtual int RemoveBreakpointImpl(Breakpoint* breakpoint) { return 0; } + debug::Breakpoint* FindBreakpoint(uint32_t address); + virtual int AddBreakpointImpl(debug::Breakpoint* breakpoint) { return 0; } + virtual int RemoveBreakpointImpl(debug::Breakpoint* breakpoint) { return 0; } virtual int CallImpl(ThreadState* thread_state, uint32_t return_address) = 0; protected: @@ -54,7 +54,7 @@ class Function { // TODO(benvanik): move elsewhere? DebugData? std::mutex lock_; - std::vector breakpoints_; + std::vector breakpoints_; }; } // namespace cpu diff --git a/src/xenia/cpu/processor.cc b/src/xenia/cpu/processor.cc index 858b597b6..72e2e9c4e 100644 --- a/src/xenia/cpu/processor.cc +++ b/src/xenia/cpu/processor.cc @@ -22,6 +22,7 @@ #include "xenia/cpu/module.h" #include "xenia/cpu/thread_state.h" #include "xenia/cpu/xex_module.h" +#include "xenia/debug/debugger.h" #include "xenia/profiling.h" // TODO(benvanik): based on compiler support @@ -108,7 +109,7 @@ int Processor::Setup() { assert_not_null(memory_); // Create debugger first. Other types hook up to it. - debugger_.reset(new Debugger(this)); + debugger_.reset(new xe::debug::Debugger(this)); std::unique_ptr builtin_module(new BuiltinModule(this)); builtin_module_ = builtin_module.get(); diff --git a/src/xenia/cpu/processor.h b/src/xenia/cpu/processor.h index 9cbc5f0ed..b7d685d02 100644 --- a/src/xenia/cpu/processor.h +++ b/src/xenia/cpu/processor.h @@ -14,7 +14,6 @@ #include #include "xenia/cpu/backend/backend.h" -#include "xenia/cpu/debugger.h" #include "xenia/cpu/entry_table.h" #include "xenia/cpu/export_resolver.h" #include "xenia/cpu/frontend/ppc_frontend.h" @@ -23,10 +22,15 @@ #include "xenia/cpu/thread_state.h" #include "xenia/memory.h" +namespace xe { +namespace debug { +class Debugger; +} // namespace debug +} // namespace xe + namespace xe { namespace cpu { -class Runtime; class ThreadState; class XexModule; @@ -43,7 +47,7 @@ class Processor { ~Processor(); Memory* memory() const { return memory_; } - Debugger* debugger() const { return debugger_.get(); } + debug::Debugger* debugger() const { return debugger_.get(); } frontend::PPCFrontend* frontend() const { return frontend_.get(); } backend::Backend* backend() const { return backend_.get(); } ExportResolver* export_resolver() const { return export_resolver_; } @@ -85,7 +89,7 @@ class Processor { uint32_t debug_info_flags_; uint32_t trace_flags_; - std::unique_ptr debugger_; + std::unique_ptr debugger_; std::unique_ptr frontend_; std::unique_ptr backend_; diff --git a/src/xenia/cpu/sources.gypi b/src/xenia/cpu/sources.gypi index 9f48f6e7b..a8652e844 100644 --- a/src/xenia/cpu/sources.gypi +++ b/src/xenia/cpu/sources.gypi @@ -6,8 +6,6 @@ 'cpu.h', 'debug_info.cc', 'debug_info.h', - 'debugger.cc', - 'debugger.h', 'entry_table.cc', 'entry_table.h', 'export_resolver.cc', diff --git a/src/xenia/cpu/thread_state.cc b/src/xenia/cpu/thread_state.cc index b86eacdb0..4e1efcefa 100644 --- a/src/xenia/cpu/thread_state.cc +++ b/src/xenia/cpu/thread_state.cc @@ -12,6 +12,7 @@ #include "xenia/base/assert.h" #include "xenia/base/threading.h" #include "xenia/cpu/processor.h" +#include "xenia/debug/debugger.h" namespace xe { namespace cpu { diff --git a/src/xenia/debug/breakpoint.h b/src/xenia/debug/breakpoint.h new file mode 100644 index 000000000..148825d10 --- /dev/null +++ b/src/xenia/debug/breakpoint.h @@ -0,0 +1,45 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2013 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#ifndef XENIA_DEBUG_BREAKPOINT_H_ +#define XENIA_DEBUG_BREAKPOINT_H_ + +#include + +namespace xe { +namespace debug { + +class Breakpoint { + public: + enum Type { + TEMP_TYPE, + CODE_TYPE, + }; + + public: + Breakpoint(Type type, uint32_t address); + ~Breakpoint(); + + Type type() const { return type_; } + uint32_t address() const { return address_; } + + const char* id() const { return id_.c_str(); } + void set_id(const char* id) { id_ = std::string(id); } + + private: + Type type_; + uint32_t address_; + + std::string id_; +}; + +} // namespace debug +} // namespace xe + +#endif // XENIA_DEBUG_BREAKPOINT_H_ diff --git a/src/xenia/debug/debug_server.cc b/src/xenia/debug/debug_server.cc new file mode 100644 index 000000000..c9b1a6595 --- /dev/null +++ b/src/xenia/debug/debug_server.cc @@ -0,0 +1,18 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2015 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#include "xenia/debug/debug_server.h" + +namespace xe { +namespace debug { + +// + +} // namespace debug +} // namespace xe diff --git a/src/xenia/debug/debug_server.h b/src/xenia/debug/debug_server.h new file mode 100644 index 000000000..39810ab36 --- /dev/null +++ b/src/xenia/debug/debug_server.h @@ -0,0 +1,21 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2015 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#ifndef XENIA_DEBUG_DEBUG_SERVER_H_ +#define XENIA_DEBUG_DEBUG_SERVER_H_ + +namespace xe { +namespace debug { + +// + +} // namespace debug +} // namespace xe + +#endif // XENIA_DEBUG_DEBUG_SERVER_H_ diff --git a/src/xenia/cpu/debugger.cc b/src/xenia/debug/debugger.cc similarity index 94% rename from src/xenia/cpu/debugger.cc rename to src/xenia/debug/debugger.cc index 898d1c405..1ee153d94 100644 --- a/src/xenia/cpu/debugger.cc +++ b/src/xenia/debug/debugger.cc @@ -7,7 +7,7 @@ ****************************************************************************** */ -#include "xenia/cpu/debugger.h" +#include "xenia/debug/debugger.h" #include @@ -15,14 +15,16 @@ #include "xenia/cpu/processor.h" namespace xe { -namespace cpu { +namespace debug { + +using xe::cpu::ThreadState; Breakpoint::Breakpoint(Type type, uint32_t address) : type_(type), address_(address) {} Breakpoint::~Breakpoint() = default; -Debugger::Debugger(Processor* processor) : processor_(processor) {} +Debugger::Debugger(cpu::Processor* processor) : processor_(processor) {} Debugger::~Debugger() = default; @@ -156,8 +158,8 @@ void Debugger::OnThreadDestroyed(ThreadState* thread_state) { } } -void Debugger::OnFunctionDefined(FunctionInfo* symbol_info, - Function* function) { +void Debugger::OnFunctionDefined(cpu::FunctionInfo* symbol_info, + cpu::Function* function) { // Man, I'd love not to take this lock. std::vector breakpoints; { @@ -195,5 +197,5 @@ void Debugger::OnBreakpointHit(ThreadState* thread_state, // Note that we stay suspended. } -} // namespace cpu +} // namespace debug } // namespace xe diff --git a/src/xenia/cpu/debugger.h b/src/xenia/debug/debugger.h similarity index 63% rename from src/xenia/cpu/debugger.h rename to src/xenia/debug/debugger.h index dde7e1ef9..69eddff55 100644 --- a/src/xenia/cpu/debugger.h +++ b/src/xenia/debug/debugger.h @@ -7,8 +7,8 @@ ****************************************************************************** */ -#ifndef XENIA_CPU_DEBUGGER_H_ -#define XENIA_CPU_DEBUGGER_H_ +#ifndef XENIA_DEBUG_DEBUGGER_H_ +#define XENIA_DEBUG_DEBUGGER_H_ #include #include @@ -17,38 +17,20 @@ #include "xenia/base/delegate.h" #include "xenia/cpu/thread_state.h" +#include "xenia/debug/breakpoint.h" namespace xe { namespace cpu { - -class Debugger; class Function; class FunctionInfo; class Processor; +} // namespace cpu +} // namespace xe -class Breakpoint { - public: - enum Type { - TEMP_TYPE, - CODE_TYPE, - }; +namespace xe { +namespace debug { - public: - Breakpoint(Type type, uint32_t address); - ~Breakpoint(); - - Type type() const { return type_; } - uint32_t address() const { return address_; } - - const char* id() const { return id_.c_str(); } - void set_id(const char* id) { id_ = std::string(id); } - - private: - Type type_; - uint32_t address_; - - std::string id_; -}; +class Debugger; class DebugEvent { public: @@ -62,32 +44,32 @@ class DebugEvent { class BreakpointHitEvent : public DebugEvent { public: - BreakpointHitEvent(Debugger* debugger, ThreadState* thread_state, + BreakpointHitEvent(Debugger* debugger, cpu::ThreadState* thread_state, Breakpoint* breakpoint) : DebugEvent(debugger), thread_state_(thread_state), breakpoint_(breakpoint) {} ~BreakpointHitEvent() override = default; - ThreadState* thread_state() const { return thread_state_; } + cpu::ThreadState* thread_state() const { return thread_state_; } Breakpoint* breakpoint() const { return breakpoint_; } protected: - ThreadState* thread_state_; + cpu::ThreadState* thread_state_; Breakpoint* breakpoint_; }; class Debugger { public: - Debugger(Processor* processor); + Debugger(cpu::Processor* processor); ~Debugger(); - Processor* processor() const { return processor_; } + cpu::Processor* processor() const { return processor_; } int SuspendAllThreads(uint32_t timeout_ms = UINT_MAX); int ResumeThread(uint32_t thread_id); int ResumeAllThreads(bool force = false); - void ForEachThread(std::function callback); + void ForEachThread(std::function callback); int AddBreakpoint(Breakpoint* breakpoint); int RemoveBreakpoint(Breakpoint* breakpoint); @@ -97,26 +79,27 @@ class Debugger { // TODO(benvanik): utility functions for modification (make function ignored, // etc). - void OnThreadCreated(ThreadState* thread_state); - void OnThreadDestroyed(ThreadState* thread_state); - void OnFunctionDefined(FunctionInfo* symbol_info, Function* function); + void OnThreadCreated(cpu::ThreadState* thread_state); + void OnThreadDestroyed(cpu::ThreadState* thread_state); + void OnFunctionDefined(cpu::FunctionInfo* symbol_info, + cpu::Function* function); - void OnBreakpointHit(ThreadState* thread_state, Breakpoint* breakpoint); + void OnBreakpointHit(cpu::ThreadState* thread_state, Breakpoint* breakpoint); public: Delegate breakpoint_hit; private: - Processor* processor_; + cpu::Processor* processor_; std::mutex threads_lock_; - std::unordered_map threads_; + std::unordered_map threads_; std::mutex breakpoints_lock_; std::multimap breakpoints_; }; -} // namespace cpu +} // namespace debug } // namespace xe -#endif // XENIA_CPU_DEBUGGER_H_ +#endif // XENIA_DEBUG_DEBUGGER_H_ diff --git a/src/xenia/debug/sources.gypi b/src/xenia/debug/sources.gypi new file mode 100644 index 000000000..d05bfde07 --- /dev/null +++ b/src/xenia/debug/sources.gypi @@ -0,0 +1,11 @@ +# Copyright 2015 Ben Vanik. All Rights Reserved. +{ + 'sources': [ + 'debug_server.cc', + 'debug_server.h', + 'debugger.cc', + 'debugger.h', + 'trace_writer.cc', + 'trace_writer.h', + ], +} diff --git a/src/xenia/debug/trace_writer.cc b/src/xenia/debug/trace_writer.cc new file mode 100644 index 000000000..6b65905be --- /dev/null +++ b/src/xenia/debug/trace_writer.cc @@ -0,0 +1,18 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2015 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#include "xenia/debug/trace_writer.h" + +namespace xe { +namespace debug { + +// + +} // namespace debug +} // namespace xe diff --git a/src/xenia/debug/trace_writer.h b/src/xenia/debug/trace_writer.h new file mode 100644 index 000000000..2ccf63622 --- /dev/null +++ b/src/xenia/debug/trace_writer.h @@ -0,0 +1,29 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2015 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#ifndef XENIA_DEBUG_TRACE_WRITER_H_ +#define XENIA_DEBUG_TRACE_WRITER_H_ + +namespace xe { +namespace debug { + +enum TraceFlags { + kTraceFunctionInfo = 1 << 0, + kTraceInstructionReferences = 1 << 1, + kTraceInstructionResults = 1 << 2, +}; + +class TraceWriter { + public: +}; + +} // namespace debug +} // namespace xe + +#endif // XENIA_DEBUG_TRACE_WRITER_H_ diff --git a/src/xenia/sources.gypi b/src/xenia/sources.gypi index 566a797eb..a929237b5 100644 --- a/src/xenia/sources.gypi +++ b/src/xenia/sources.gypi @@ -15,6 +15,7 @@ 'apu/sources.gypi', 'base/sources.gypi', 'cpu/sources.gypi', + 'debug/sources.gypi', 'gpu/sources.gypi', 'hid/sources.gypi', 'kernel/sources.gypi',