2013-12-23 02:50:14 +01:00
|
|
|
/**
|
|
|
|
|
******************************************************************************
|
|
|
|
|
* 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 ALLOY_RUNTIME_DEBUGGER_H_
|
|
|
|
|
#define ALLOY_RUNTIME_DEBUGGER_H_
|
|
|
|
|
|
2013-12-23 07:03:06 +01:00
|
|
|
#include <map>
|
2014-07-10 07:28:51 +02:00
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
|
|
#include <alloy/core.h>
|
2013-12-23 07:03:06 +01:00
|
|
|
|
2013-12-23 02:50:14 +01:00
|
|
|
|
|
|
|
|
namespace alloy {
|
|
|
|
|
namespace runtime {
|
|
|
|
|
|
2013-12-23 23:01:13 +01:00
|
|
|
class Debugger;
|
2013-12-23 07:03:06 +01:00
|
|
|
class Function;
|
|
|
|
|
class FunctionInfo;
|
2013-12-23 02:50:14 +01:00
|
|
|
class Runtime;
|
2013-12-23 08:04:24 +01:00
|
|
|
class ThreadState;
|
2013-12-23 02:50:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class Breakpoint {
|
|
|
|
|
public:
|
|
|
|
|
enum Type {
|
|
|
|
|
TEMP_TYPE,
|
|
|
|
|
CODE_TYPE,
|
|
|
|
|
};
|
|
|
|
|
public:
|
|
|
|
|
Breakpoint(Type type, uint64_t address);
|
|
|
|
|
~Breakpoint();
|
|
|
|
|
|
|
|
|
|
Type type() const { return type_; }
|
|
|
|
|
uint64_t address() const { return address_; }
|
|
|
|
|
|
2013-12-23 23:01:13 +01:00
|
|
|
const char* id() const { return id_.c_str(); }
|
|
|
|
|
void set_id(const char* id) { id_ = id; }
|
|
|
|
|
|
2013-12-23 02:50:14 +01:00
|
|
|
private:
|
|
|
|
|
Type type_;
|
|
|
|
|
uint64_t address_;
|
2013-12-23 23:01:13 +01:00
|
|
|
|
|
|
|
|
std::string id_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DebugEvent {
|
|
|
|
|
public:
|
|
|
|
|
DebugEvent(Debugger* debugger) :
|
2014-01-15 07:40:02 +01:00
|
|
|
debugger_(debugger) {}
|
2013-12-23 23:01:13 +01:00
|
|
|
virtual ~DebugEvent() {}
|
|
|
|
|
Debugger* debugger() const { return debugger_; }
|
|
|
|
|
protected:
|
|
|
|
|
Debugger* debugger_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BreakpointHitEvent : public DebugEvent {
|
|
|
|
|
public:
|
|
|
|
|
BreakpointHitEvent(
|
|
|
|
|
Debugger* debugger, ThreadState* thread_state, Breakpoint* breakpoint) :
|
|
|
|
|
thread_state_(thread_state), breakpoint_(breakpoint),
|
|
|
|
|
DebugEvent(debugger) {}
|
|
|
|
|
virtual ~BreakpointHitEvent() {}
|
|
|
|
|
ThreadState* thread_state() const { return thread_state_; }
|
|
|
|
|
Breakpoint* breakpoint() const { return breakpoint_; }
|
|
|
|
|
protected:
|
|
|
|
|
ThreadState* thread_state_;
|
|
|
|
|
Breakpoint* breakpoint_;
|
2013-12-23 02:50:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Debugger {
|
|
|
|
|
public:
|
|
|
|
|
Debugger(Runtime* runtime);
|
|
|
|
|
~Debugger();
|
|
|
|
|
|
|
|
|
|
Runtime* runtime() const { return runtime_; }
|
|
|
|
|
|
2013-12-23 23:01:13 +01:00
|
|
|
int SuspendAllThreads(uint32_t timeout_ms = UINT_MAX);
|
|
|
|
|
int ResumeThread(uint32_t thread_id);
|
2013-12-24 04:46:35 +01:00
|
|
|
int ResumeAllThreads(bool force = false);
|
2013-12-23 23:01:13 +01:00
|
|
|
|
2013-12-26 02:31:53 +01:00
|
|
|
void ForEachThread(std::function<void (ThreadState*)> callback);
|
|
|
|
|
|
2013-12-23 02:50:14 +01:00
|
|
|
int AddBreakpoint(Breakpoint* breakpoint);
|
|
|
|
|
int RemoveBreakpoint(Breakpoint* breakpoint);
|
2013-12-23 07:03:06 +01:00
|
|
|
void FindBreakpoints(
|
|
|
|
|
uint64_t address, std::vector<Breakpoint*>& out_breakpoints);
|
|
|
|
|
|
2013-12-23 23:01:13 +01:00
|
|
|
void OnThreadCreated(ThreadState* thread_state);
|
|
|
|
|
void OnThreadDestroyed(ThreadState* thread_state);
|
2013-12-23 07:03:06 +01:00
|
|
|
void OnFunctionDefined(FunctionInfo* symbol_info, Function* function);
|
2013-12-23 23:01:13 +01:00
|
|
|
|
2013-12-23 08:04:24 +01:00
|
|
|
void OnBreakpointHit(ThreadState* thread_state, Breakpoint* breakpoint);
|
2013-12-23 02:50:14 +01:00
|
|
|
|
2013-12-23 23:01:13 +01:00
|
|
|
public:
|
|
|
|
|
Delegate<BreakpointHitEvent> breakpoint_hit;
|
|
|
|
|
|
2013-12-23 02:50:14 +01:00
|
|
|
private:
|
|
|
|
|
Runtime* runtime_;
|
2013-12-23 07:03:06 +01:00
|
|
|
|
2014-07-10 07:28:51 +02:00
|
|
|
std::mutex threads_lock_;
|
2013-12-23 23:01:13 +01:00
|
|
|
typedef std::unordered_map<uint32_t, ThreadState*> ThreadMap;
|
|
|
|
|
ThreadMap threads_;
|
|
|
|
|
|
2014-07-10 07:28:51 +02:00
|
|
|
std::mutex breakpoints_lock_;
|
2013-12-23 23:01:13 +01:00
|
|
|
typedef std::multimap<uint64_t, Breakpoint*> BreakpointMultimap;
|
|
|
|
|
BreakpointMultimap breakpoints_;
|
2013-12-23 02:50:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace runtime
|
|
|
|
|
} // namespace alloy
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // ALLOY_RUNTIME_DEBUGGER_H_
|