diff options
author | Lioncash <mathew1800@gmail.com> | 2018-10-03 18:47:57 -0400 |
---|---|---|
committer | Lioncash <mathew1800@gmail.com> | 2018-10-04 00:14:15 -0400 |
commit | baed7e1fba99c3f1932c6a41ad1496d1b6490a5a (patch) | |
tree | 004a9784a05294531e2f3975205f856a96b1a1ef /src/core/gdbstub/gdbstub.cpp | |
parent | bc679c9b8c05d3db46da8cef77e729b31c6dbff5 (diff) |
kernel/thread: Make all instance variables private
Many of the member variables of the thread class aren't even used
outside of the class itself, so there's no need to make those variables
public. This change follows in the steps of the previous changes that
made other kernel types' members private.
The main motivation behind this is that the Thread class will likely
change in the future as emulation becomes more accurate, and letting
random bits of the emulator access data members of the Thread class
directly makes it a pain to shuffle around and/or modify internals.
Having all data members public like this also makes it difficult to
reason about certain bits of behavior without first verifying what parts
of the core actually use them.
Everything being public also generally follows the tendency for changes
to be introduced in completely different translation units that would
otherwise be better introduced as an addition to the Thread class'
public interface.
Diffstat (limited to 'src/core/gdbstub/gdbstub.cpp')
-rw-r--r-- | src/core/gdbstub/gdbstub.cpp | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp index 5bc9470106..e961ef121f 100644 --- a/src/core/gdbstub/gdbstub.cpp +++ b/src/core/gdbstub/gdbstub.cpp @@ -209,7 +209,7 @@ static Kernel::Thread* FindThreadById(int id) { for (u32 core = 0; core < Core::NUM_CPU_CORES; core++) { const auto& threads = Core::System::GetInstance().Scheduler(core)->GetThreadList(); for (auto& thread : threads) { - if (thread->GetThreadId() == static_cast<u32>(id)) { + if (thread->GetThreadID() == static_cast<u32>(id)) { current_core = core; return thread.get(); } @@ -223,16 +223,18 @@ static u64 RegRead(std::size_t id, Kernel::Thread* thread = nullptr) { return 0; } + const auto& thread_context = thread->GetContext(); + if (id < SP_REGISTER) { - return thread->context.cpu_registers[id]; + return thread_context.cpu_registers[id]; } else if (id == SP_REGISTER) { - return thread->context.sp; + return thread_context.sp; } else if (id == PC_REGISTER) { - return thread->context.pc; + return thread_context.pc; } else if (id == PSTATE_REGISTER) { - return thread->context.pstate; + return thread_context.pstate; } else if (id > PSTATE_REGISTER && id < FPCR_REGISTER) { - return thread->context.vector_registers[id - UC_ARM64_REG_Q0][0]; + return thread_context.vector_registers[id - UC_ARM64_REG_Q0][0]; } else { return 0; } @@ -243,16 +245,18 @@ static void RegWrite(std::size_t id, u64 val, Kernel::Thread* thread = nullptr) return; } + auto& thread_context = thread->GetContext(); + if (id < SP_REGISTER) { - thread->context.cpu_registers[id] = val; + thread_context.cpu_registers[id] = val; } else if (id == SP_REGISTER) { - thread->context.sp = val; + thread_context.sp = val; } else if (id == PC_REGISTER) { - thread->context.pc = val; + thread_context.pc = val; } else if (id == PSTATE_REGISTER) { - thread->context.pstate = static_cast<u32>(val); + thread_context.pstate = static_cast<u32>(val); } else if (id > PSTATE_REGISTER && id < FPCR_REGISTER) { - thread->context.vector_registers[id - (PSTATE_REGISTER + 1)][0] = val; + thread_context.vector_registers[id - (PSTATE_REGISTER + 1)][0] = val; } } @@ -595,7 +599,7 @@ static void HandleQuery() { for (u32 core = 0; core < Core::NUM_CPU_CORES; core++) { const auto& threads = Core::System::GetInstance().Scheduler(core)->GetThreadList(); for (const auto& thread : threads) { - val += fmt::format("{:x}", thread->GetThreadId()); + val += fmt::format("{:x}", thread->GetThreadID()); val += ","; } } @@ -612,7 +616,7 @@ static void HandleQuery() { for (const auto& thread : threads) { buffer += fmt::format(R"*(<thread id="{:x}" core="{:d}" name="Thread {:x}"></thread>)*", - thread->GetThreadId(), core, thread->GetThreadId()); + thread->GetThreadID(), core, thread->GetThreadID()); } } buffer += "</threads>"; @@ -693,7 +697,7 @@ static void SendSignal(Kernel::Thread* thread, u32 signal, bool full = true) { } if (thread) { - buffer += fmt::format(";thread:{:x};", thread->GetThreadId()); + buffer += fmt::format(";thread:{:x};", thread->GetThreadID()); } SendReply(buffer.c_str()); @@ -857,7 +861,9 @@ static void WriteRegister() { } // Update Unicorn context skipping scheduler, no running threads at this point - Core::System::GetInstance().ArmInterface(current_core).LoadContext(current_thread->context); + Core::System::GetInstance() + .ArmInterface(current_core) + .LoadContext(current_thread->GetContext()); SendReply("OK"); } @@ -886,7 +892,9 @@ static void WriteRegisters() { } // Update Unicorn context skipping scheduler, no running threads at this point - Core::System::GetInstance().ArmInterface(current_core).LoadContext(current_thread->context); + Core::System::GetInstance() + .ArmInterface(current_core) + .LoadContext(current_thread->GetContext()); SendReply("OK"); } @@ -960,7 +968,9 @@ static void Step() { if (command_length > 1) { RegWrite(PC_REGISTER, GdbHexToLong(command_buffer + 1), current_thread); // Update Unicorn context skipping scheduler, no running threads at this point - Core::System::GetInstance().ArmInterface(current_core).LoadContext(current_thread->context); + Core::System::GetInstance() + .ArmInterface(current_core) + .LoadContext(current_thread->GetContext()); } step_loop = true; halt_loop = true; |