mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-12-19 00:42:06 +00:00
dmnt: use hardware single step extension if available
This commit is contained in:
parent
ae91a32059
commit
6139b7d5ac
2 changed files with 28 additions and 17 deletions
|
@ -273,25 +273,31 @@ namespace ams::dmnt {
|
||||||
/* Note that we're stepping. */
|
/* Note that we're stepping. */
|
||||||
m_stepping = true;
|
m_stepping = true;
|
||||||
|
|
||||||
/* Determine where we're stepping to. */
|
if (m_use_hardware_single_step) {
|
||||||
u64 current_pc = ctx.pc;
|
/* Set thread single step. */
|
||||||
u64 step_target = 0;
|
R_TRY(this->SetThreadContext(std::addressof(ctx), thread_id, svc::ThreadContextFlag_SetSingleStep));
|
||||||
this->GetBranchTarget(ctx, thread_id, current_pc, step_target);
|
} else {
|
||||||
|
/* Determine where we're stepping to. */
|
||||||
|
u64 current_pc = ctx.pc;
|
||||||
|
u64 step_target = 0;
|
||||||
|
this->GetBranchTarget(ctx, thread_id, current_pc, step_target);
|
||||||
|
|
||||||
/* Ensure we end with valid breakpoints. */
|
/* Ensure we end with valid breakpoints. */
|
||||||
auto bp_guard = SCOPE_GUARD { this->ClearStep(); };
|
auto bp_guard = SCOPE_GUARD { this->ClearStep(); };
|
||||||
|
|
||||||
/* Set step breakpoint on current pc. */
|
/* Set step breakpoint on current pc. */
|
||||||
/* TODO: aarch32 breakpoints. */
|
/* TODO: aarch32 breakpoints. */
|
||||||
if (current_pc) {
|
if (current_pc) {
|
||||||
R_TRY(m_step_breakpoints.SetBreakPoint(current_pc, sizeof(u32), true));
|
R_TRY(m_step_breakpoints.SetBreakPoint(current_pc, sizeof(u32), true));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (step_target) {
|
||||||
|
R_TRY(m_step_breakpoints.SetBreakPoint(step_target, sizeof(u32), true));
|
||||||
|
}
|
||||||
|
|
||||||
|
bp_guard.Cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (step_target) {
|
|
||||||
R_TRY(m_step_breakpoints.SetBreakPoint(step_target, sizeof(u32), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
bp_guard.Cancel();
|
|
||||||
return ResultSuccess();
|
return ResultSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,7 @@ namespace ams::dmnt {
|
||||||
u64 m_continue_thread_id{};
|
u64 m_continue_thread_id{};
|
||||||
GdbSignal m_last_signal{};
|
GdbSignal m_last_signal{};
|
||||||
bool m_stepping{false};
|
bool m_stepping{false};
|
||||||
|
bool m_use_hardware_single_step{false};
|
||||||
bool m_thread_valid[ThreadCountMax]{};
|
bool m_thread_valid[ThreadCountMax]{};
|
||||||
u64 m_thread_ids[ThreadCountMax]{};
|
u64 m_thread_ids[ThreadCountMax]{};
|
||||||
osdbg::ThreadInfo m_thread_infos[ThreadCountMax]{};
|
osdbg::ThreadInfo m_thread_infos[ThreadCountMax]{};
|
||||||
|
@ -64,8 +65,12 @@ namespace ams::dmnt {
|
||||||
size_t m_module_count{};
|
size_t m_module_count{};
|
||||||
size_t m_main_module{};
|
size_t m_main_module{};
|
||||||
public:
|
public:
|
||||||
/* TODO: ifdef for hardware breakpoints. */
|
DebugProcess() : m_software_breakpoints(this), m_hardware_breakpoints(this), m_hardware_watchpoints(this), m_step_breakpoints(m_software_breakpoints) {
|
||||||
DebugProcess() : m_software_breakpoints(this), m_hardware_breakpoints(this), m_hardware_watchpoints(this), m_step_breakpoints(m_software_breakpoints) { /* ... */ }
|
if (svc::IsKernelMesosphere()) {
|
||||||
|
uint64_t value = 0;
|
||||||
|
m_use_hardware_single_step = R_SUCCEEDED(::ams::svc::GetInfo(std::addressof(value), ::ams::svc::InfoType_MesosphereMeta, ::ams::svc::InvalidHandle, ::ams::svc::MesosphereMetaInfo_IsSingleStepEnabled)) && value != 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
~DebugProcess() { this->Detach(); }
|
~DebugProcess() { this->Detach(); }
|
||||||
|
|
||||||
svc::Handle GetHandle() const { return m_debug_handle; }
|
svc::Handle GetHandle() const { return m_debug_handle; }
|
||||||
|
|
Loading…
Reference in a new issue