summaryrefslogtreecommitdiff
path: root/src/core/gdbstub/gdbstub.cpp
diff options
context:
space:
mode:
authorGravatar Lioncash2018-10-03 18:47:57 -0400
committerGravatar Lioncash2018-10-04 00:14:15 -0400
commitbaed7e1fba99c3f1932c6a41ad1496d1b6490a5a (patch)
tree004a9784a05294531e2f3975205f856a96b1a1ef /src/core/gdbstub/gdbstub.cpp
parentMerge pull request #1330 from raven02/tlds (diff)
downloadyuzu-baed7e1fba99c3f1932c6a41ad1496d1b6490a5a.tar.gz
yuzu-baed7e1fba99c3f1932c6a41ad1496d1b6490a5a.tar.xz
yuzu-baed7e1fba99c3f1932c6a41ad1496d1b6490a5a.zip
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.cpp44
1 files changed, 27 insertions, 17 deletions
diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp
index 5bc947010..e961ef121 100644
--- a/src/core/gdbstub/gdbstub.cpp
+++ b/src/core/gdbstub/gdbstub.cpp
@@ -209,7 +209,7 @@ static Kernel::Thread* FindThreadById(int id) {
209 for (u32 core = 0; core < Core::NUM_CPU_CORES; core++) { 209 for (u32 core = 0; core < Core::NUM_CPU_CORES; core++) {
210 const auto& threads = Core::System::GetInstance().Scheduler(core)->GetThreadList(); 210 const auto& threads = Core::System::GetInstance().Scheduler(core)->GetThreadList();
211 for (auto& thread : threads) { 211 for (auto& thread : threads) {
212 if (thread->GetThreadId() == static_cast<u32>(id)) { 212 if (thread->GetThreadID() == static_cast<u32>(id)) {
213 current_core = core; 213 current_core = core;
214 return thread.get(); 214 return thread.get();
215 } 215 }
@@ -223,16 +223,18 @@ static u64 RegRead(std::size_t id, Kernel::Thread* thread = nullptr) {
223 return 0; 223 return 0;
224 } 224 }
225 225
226 const auto& thread_context = thread->GetContext();
227
226 if (id < SP_REGISTER) { 228 if (id < SP_REGISTER) {
227 return thread->context.cpu_registers[id]; 229 return thread_context.cpu_registers[id];
228 } else if (id == SP_REGISTER) { 230 } else if (id == SP_REGISTER) {
229 return thread->context.sp; 231 return thread_context.sp;
230 } else if (id == PC_REGISTER) { 232 } else if (id == PC_REGISTER) {
231 return thread->context.pc; 233 return thread_context.pc;
232 } else if (id == PSTATE_REGISTER) { 234 } else if (id == PSTATE_REGISTER) {
233 return thread->context.pstate; 235 return thread_context.pstate;
234 } else if (id > PSTATE_REGISTER && id < FPCR_REGISTER) { 236 } else if (id > PSTATE_REGISTER && id < FPCR_REGISTER) {
235 return thread->context.vector_registers[id - UC_ARM64_REG_Q0][0]; 237 return thread_context.vector_registers[id - UC_ARM64_REG_Q0][0];
236 } else { 238 } else {
237 return 0; 239 return 0;
238 } 240 }
@@ -243,16 +245,18 @@ static void RegWrite(std::size_t id, u64 val, Kernel::Thread* thread = nullptr)
243 return; 245 return;
244 } 246 }
245 247
248 auto& thread_context = thread->GetContext();
249
246 if (id < SP_REGISTER) { 250 if (id < SP_REGISTER) {
247 thread->context.cpu_registers[id] = val; 251 thread_context.cpu_registers[id] = val;
248 } else if (id == SP_REGISTER) { 252 } else if (id == SP_REGISTER) {
249 thread->context.sp = val; 253 thread_context.sp = val;
250 } else if (id == PC_REGISTER) { 254 } else if (id == PC_REGISTER) {
251 thread->context.pc = val; 255 thread_context.pc = val;
252 } else if (id == PSTATE_REGISTER) { 256 } else if (id == PSTATE_REGISTER) {
253 thread->context.pstate = static_cast<u32>(val); 257 thread_context.pstate = static_cast<u32>(val);
254 } else if (id > PSTATE_REGISTER && id < FPCR_REGISTER) { 258 } else if (id > PSTATE_REGISTER && id < FPCR_REGISTER) {
255 thread->context.vector_registers[id - (PSTATE_REGISTER + 1)][0] = val; 259 thread_context.vector_registers[id - (PSTATE_REGISTER + 1)][0] = val;
256 } 260 }
257} 261}
258 262
@@ -595,7 +599,7 @@ static void HandleQuery() {
595 for (u32 core = 0; core < Core::NUM_CPU_CORES; core++) { 599 for (u32 core = 0; core < Core::NUM_CPU_CORES; core++) {
596 const auto& threads = Core::System::GetInstance().Scheduler(core)->GetThreadList(); 600 const auto& threads = Core::System::GetInstance().Scheduler(core)->GetThreadList();
597 for (const auto& thread : threads) { 601 for (const auto& thread : threads) {
598 val += fmt::format("{:x}", thread->GetThreadId()); 602 val += fmt::format("{:x}", thread->GetThreadID());
599 val += ","; 603 val += ",";
600 } 604 }
601 } 605 }
@@ -612,7 +616,7 @@ static void HandleQuery() {
612 for (const auto& thread : threads) { 616 for (const auto& thread : threads) {
613 buffer += 617 buffer +=
614 fmt::format(R"*(<thread id="{:x}" core="{:d}" name="Thread {:x}"></thread>)*", 618 fmt::format(R"*(<thread id="{:x}" core="{:d}" name="Thread {:x}"></thread>)*",
615 thread->GetThreadId(), core, thread->GetThreadId()); 619 thread->GetThreadID(), core, thread->GetThreadID());
616 } 620 }
617 } 621 }
618 buffer += "</threads>"; 622 buffer += "</threads>";
@@ -693,7 +697,7 @@ static void SendSignal(Kernel::Thread* thread, u32 signal, bool full = true) {
693 } 697 }
694 698
695 if (thread) { 699 if (thread) {
696 buffer += fmt::format(";thread:{:x};", thread->GetThreadId()); 700 buffer += fmt::format(";thread:{:x};", thread->GetThreadID());
697 } 701 }
698 702
699 SendReply(buffer.c_str()); 703 SendReply(buffer.c_str());
@@ -857,7 +861,9 @@ static void WriteRegister() {
857 } 861 }
858 862
859 // Update Unicorn context skipping scheduler, no running threads at this point 863 // Update Unicorn context skipping scheduler, no running threads at this point
860 Core::System::GetInstance().ArmInterface(current_core).LoadContext(current_thread->context); 864 Core::System::GetInstance()
865 .ArmInterface(current_core)
866 .LoadContext(current_thread->GetContext());
861 867
862 SendReply("OK"); 868 SendReply("OK");
863} 869}
@@ -886,7 +892,9 @@ static void WriteRegisters() {
886 } 892 }
887 893
888 // Update Unicorn context skipping scheduler, no running threads at this point 894 // Update Unicorn context skipping scheduler, no running threads at this point
889 Core::System::GetInstance().ArmInterface(current_core).LoadContext(current_thread->context); 895 Core::System::GetInstance()
896 .ArmInterface(current_core)
897 .LoadContext(current_thread->GetContext());
890 898
891 SendReply("OK"); 899 SendReply("OK");
892} 900}
@@ -960,7 +968,9 @@ static void Step() {
960 if (command_length > 1) { 968 if (command_length > 1) {
961 RegWrite(PC_REGISTER, GdbHexToLong(command_buffer + 1), current_thread); 969 RegWrite(PC_REGISTER, GdbHexToLong(command_buffer + 1), current_thread);
962 // Update Unicorn context skipping scheduler, no running threads at this point 970 // Update Unicorn context skipping scheduler, no running threads at this point
963 Core::System::GetInstance().ArmInterface(current_core).LoadContext(current_thread->context); 971 Core::System::GetInstance()
972 .ArmInterface(current_core)
973 .LoadContext(current_thread->GetContext());
964 } 974 }
965 step_loop = true; 975 step_loop = true;
966 halt_loop = true; 976 halt_loop = true;