Applied clang-format.

This commit is contained in:
Jarek Syrylak
2018-06-04 16:46:08 +01:00
committed by Jarek Syrylak
parent 341517a5f2
commit 7212fd5227
3 changed files with 69 additions and 131 deletions

View File

@@ -9,8 +9,8 @@
#include "core/arm/unicorn/arm_unicorn.h" #include "core/arm/unicorn/arm_unicorn.h"
#include "core/core.h" #include "core/core.h"
#include "core/core_timing.h" #include "core/core_timing.h"
#include "core/hle/kernel/svc.h"
#include "core/gdbstub/gdbstub.h" #include "core/gdbstub/gdbstub.h"
#include "core/hle/kernel/svc.h"
// Load Unicorn DLL once on Windows using RAII // Load Unicorn DLL once on Windows using RAII
#ifdef _MSC_VER #ifdef _MSC_VER
@@ -39,11 +39,10 @@ LoadDll LoadDll::g_load_dll;
static GDBStub::BreakpointAddress bkpt = {0}; static GDBStub::BreakpointAddress bkpt = {0};
static bool bkptHit = false; static bool bkptHit = false;
static void CodeHook(uc_engine *uc, uint64_t address, uint32_t size, void *user_data) static void CodeHook(uc_engine* uc, uint64_t address, uint32_t size, void* user_data) {
{
bkpt = GDBStub::GetNextBreakpointFromAddress(address, GDBStub::BreakpointType::Execute); bkpt = GDBStub::GetNextBreakpointFromAddress(address, GDBStub::BreakpointType::Execute);
if(GDBStub::IsMemoryBreak() || (bkpt.type != GDBStub::BreakpointType::None && address == bkpt.address)) if (GDBStub::IsMemoryBreak() ||
{ (bkpt.type != GDBStub::BreakpointType::None && address == bkpt.address)) {
bkptHit = true; bkptHit = true;
uc_emu_stop(uc); uc_emu_stop(uc);
} }
@@ -81,8 +80,7 @@ ARM_Unicorn::ARM_Unicorn() {
uc_hook hook{}; uc_hook hook{};
CHECKED(uc_hook_add(uc, &hook, UC_HOOK_INTR, (void*)InterruptHook, this, 0, -1)); CHECKED(uc_hook_add(uc, &hook, UC_HOOK_INTR, (void*)InterruptHook, this, 0, -1));
CHECKED(uc_hook_add(uc, &hook, UC_HOOK_MEM_INVALID, (void*)UnmappedMemoryHook, this, 0, -1)); CHECKED(uc_hook_add(uc, &hook, UC_HOOK_MEM_INVALID, (void*)UnmappedMemoryHook, this, 0, -1));
if(GDBStub::IsServerEnabled()) if (GDBStub::IsServerEnabled()) {
{
CHECKED(uc_hook_add(uc, &hook, UC_HOOK_CODE, (void*)CodeHook, this, 0, -1)); CHECKED(uc_hook_add(uc, &hook, UC_HOOK_CODE, (void*)CodeHook, this, 0, -1));
} }
} }
@@ -173,12 +171,9 @@ void ARM_Unicorn::SetTlsAddress(VAddr base) {
} }
void ARM_Unicorn::Run() { void ARM_Unicorn::Run() {
if(GDBStub::IsServerEnabled()) if (GDBStub::IsServerEnabled()) {
{
ExecuteInstructions(std::max(4000000, 0)); ExecuteInstructions(std::max(4000000, 0));
} } else {
else
{
ExecuteInstructions(std::max(CoreTiming::GetDowncount(), 0)); ExecuteInstructions(std::max(CoreTiming::GetDowncount(), 0));
} }
} }
@@ -193,16 +188,13 @@ void ARM_Unicorn::ExecuteInstructions(int num_instructions) {
MICROPROFILE_SCOPE(ARM_Jit); MICROPROFILE_SCOPE(ARM_Jit);
CHECKED(uc_emu_start(uc, GetPC(), 1ULL << 63, 0, num_instructions)); CHECKED(uc_emu_start(uc, GetPC(), 1ULL << 63, 0, num_instructions));
CoreTiming::AddTicks(num_instructions); CoreTiming::AddTicks(num_instructions);
if(GDBStub::IsServerEnabled()) if (GDBStub::IsServerEnabled()) {
{ if (bkptHit) {
if(bkptHit)
{
uc_reg_write(uc, UC_ARM64_REG_PC, &bkpt.address); uc_reg_write(uc, UC_ARM64_REG_PC, &bkpt.address);
} }
Kernel::Thread *thread = Kernel::GetCurrentThread(); Kernel::Thread* thread = Kernel::GetCurrentThread();
SaveContext(thread->context); SaveContext(thread->context);
if(bkptHit) if (bkptHit) {
{
bkptHit = false; bkptHit = false;
GDBStub::Break(); GDBStub::Break();
} }

View File

@@ -41,10 +41,10 @@
#include "core/core.h" #include "core/core.h"
#include "core/core_cpu.h" #include "core/core_cpu.h"
#include "core/gdbstub/gdbstub.h" #include "core/gdbstub/gdbstub.h"
#include "core/loader/loader.h"
#include "core/memory.h"
#include "core/hle/kernel/kernel.h" #include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/scheduler.h" #include "core/hle/kernel/scheduler.h"
#include "core/loader/loader.h"
#include "core/memory.h"
const int GDB_BUFFER_SIZE = 10000; const int GDB_BUFFER_SIZE = 10000;
@@ -147,7 +147,7 @@ static u32 command_length;
static u32 latest_signal = 0; static u32 latest_signal = 0;
static bool memory_break = false; static bool memory_break = false;
Kernel::Thread *thread = nullptr; Kernel::Thread* thread = nullptr;
int current_core = 0; int current_core = 0;
// Binding to a port within the reserved ports range (0-1023) requires root permissions, // Binding to a port within the reserved ports range (0-1023) requires root permissions,
@@ -175,75 +175,51 @@ static std::map<u64, Breakpoint> breakpoints_execute;
static std::map<u64, Breakpoint> breakpoints_read; static std::map<u64, Breakpoint> breakpoints_read;
static std::map<u64, Breakpoint> breakpoints_write; static std::map<u64, Breakpoint> breakpoints_write;
Kernel::Thread *FindThread(int id, int& current_core) Kernel::Thread* FindThread(int id, int& current_core) {
{ Kernel::Thread* thread = nullptr;
Kernel::Thread *thread = nullptr; for (int core = 0; core < Core::NUM_CPU_CORES; core++) {
for(int core = 0; core < Core::NUM_CPU_CORES; core++)
{
auto list = Core::System::GetInstance().Scheduler(core)->GetThreadList(); auto list = Core::System::GetInstance().Scheduler(core)->GetThreadList();
for(auto it = list.begin(); it != list.end(); it++) for (auto it = list.begin(); it != list.end(); it++) {
{ if ((*it)->GetThreadId() == id) {
if((*it)->GetThreadId() == id) thread = &(*(*it));
{ current_core = core;
thread = &(*(*it)); break;
current_core = core;
break;
} }
} }
} }
return thread; return thread;
} }
static u64 regr(int id, Kernel::Thread *thread = nullptr) static u64 regr(int id, Kernel::Thread* thread = nullptr) {
{ if (!thread) {
if(!thread)
{
return 0; return 0;
} }
if(id < SP_REGISTER) if (id < SP_REGISTER) {
{
return thread->context.cpu_registers[id]; return thread->context.cpu_registers[id];
} } else if (id == SP_REGISTER) {
else if(id == SP_REGISTER)
{
return thread->context.sp; return thread->context.sp;
} } else if (id == PC_REGISTER) {
else if(id == PC_REGISTER)
{
return thread->context.pc; return thread->context.pc;
} } else if (id == CPSR_REGISTER) {
else if(id == CPSR_REGISTER)
{
return thread->context.cpsr; return thread->context.cpsr;
} } else {
else
{
return 0; return 0;
} }
} }
static void regw(int id, u64 val, Kernel::Thread *thread = nullptr) static void regw(int id, u64 val, Kernel::Thread* thread = nullptr) {
{ if (!thread) {
if(!thread)
{
return; return;
} }
if(id < SP_REGISTER) if (id < SP_REGISTER) {
{
thread->context.cpu_registers[id] = val; thread->context.cpu_registers[id] = val;
} } else if (id == SP_REGISTER) {
else if(id == SP_REGISTER)
{
thread->context.sp = val; thread->context.sp = val;
} } else if (id == PC_REGISTER) {
else if(id == PC_REGISTER)
{
thread->context.pc = val; thread->context.pc = val;
} } else if (id == CPSR_REGISTER) {
else if(id == CPSR_REGISTER)
{
thread->context.cpsr = val; thread->context.cpsr = val;
} }
} }
@@ -555,39 +531,27 @@ static void SendReply(const char* reply) {
} }
/// Handle query command from gdb client. /// Handle query command from gdb client.
static void HandleQuery() static void HandleQuery() {
{
NGLOG_DEBUG(Debug_GDBStub, "gdb: query '{}'", command_buffer + 1); NGLOG_DEBUG(Debug_GDBStub, "gdb: query '{}'", command_buffer + 1);
const char* query = reinterpret_cast<const char*>(command_buffer + 1); const char* query = reinterpret_cast<const char*>(command_buffer + 1);
if(strcmp(query, "TStatus") == 0) if (strcmp(query, "TStatus") == 0) {
{
SendReply("T0"); SendReply("T0");
} } else if (strncmp(query, "Supported", strlen("Supported")) == 0) {
else if(strncmp(query, "Supported", strlen("Supported")) == 0)
{
// PacketSize needs to be large enough for target xml // PacketSize needs to be large enough for target xml
SendReply("PacketSize=2000;qXfer:features:read+"); SendReply("PacketSize=2000;qXfer:features:read+");
} } else if (strncmp(query, "Xfer:features:read:target.xml:",
else if(strncmp(query, "Xfer:features:read:target.xml:", strlen("Xfer:features:read:target.xml:")) == 0) {
strlen("Xfer:features:read:target.xml:")) == 0)
{
SendReply(target_xml); SendReply(target_xml);
} } else if (strncmp(query, "Offsets", strlen("Offsets")) == 0) {
else if(strncmp(query, "Offsets", strlen("Offsets")) == 0)
{
std::string buffer = fmt::format("TextSeg={:0x}", Memory::PROCESS_IMAGE_VADDR); std::string buffer = fmt::format("TextSeg={:0x}", Memory::PROCESS_IMAGE_VADDR);
SendReply(buffer.c_str()); SendReply(buffer.c_str());
} } else if (strncmp(query, "fThreadInfo", strlen("fThreadInfo")) == 0) {
else if(strncmp(query, "fThreadInfo", strlen("fThreadInfo")) == 0)
{
std::string val = "m"; std::string val = "m";
for(int core = 0; core < Core::NUM_CPU_CORES; core++) for (int core = 0; core < Core::NUM_CPU_CORES; core++) {
{
auto list = Core::System::GetInstance().Scheduler(core)->GetThreadList(); auto list = Core::System::GetInstance().Scheduler(core)->GetThreadList();
for(auto it = list.begin(); it != list.end(); it++) for (auto it = list.begin(); it != list.end(); it++) {
{
char tmp[17] = {0}; char tmp[17] = {0};
memset(tmp, 0, sizeof(tmp)); memset(tmp, 0, sizeof(tmp));
sprintf(tmp, "%x", (*it)->GetThreadId()); sprintf(tmp, "%x", (*it)->GetThreadId());
@@ -597,38 +561,28 @@ static void HandleQuery()
} }
val.pop_back(); val.pop_back();
SendReply(val.c_str()); SendReply(val.c_str());
} } else if (strncmp(query, "sThreadInfo", strlen("sThreadInfo")) == 0) {
else if(strncmp(query, "sThreadInfo", strlen("sThreadInfo")) == 0)
{
SendReply("l"); SendReply("l");
} } else {
else
{
SendReply(""); SendReply("");
} }
} }
/// Handle set thread command from gdb client. /// Handle set thread command from gdb client.
static void HandleSetThread() static void HandleSetThread() {
{ if (memcmp(command_buffer, "Hc", 2) == 0 || memcmp(command_buffer, "Hg", 2) == 0) {
if(memcmp(command_buffer, "Hc", 2) == 0 || memcmp(command_buffer, "Hg", 2) == 0)
{
int threadid = -1; int threadid = -1;
if(command_buffer[2] != '-') if (command_buffer[2] != '-') {
{
threadid = (int)HexToInt(command_buffer + 2, strlen((char*)command_buffer + 2)); threadid = (int)HexToInt(command_buffer + 2, strlen((char*)command_buffer + 2));
} }
if(threadid >= 1) if (threadid >= 1) {
{
thread = FindThread(threadid, current_core); thread = FindThread(threadid, current_core);
} }
if(!thread) if (!thread) {
{
threadid = 1; threadid = 1;
thread = FindThread(threadid, current_core); thread = FindThread(threadid, current_core);
} }
if(thread) if (thread) {
{
SendReply("OK"); SendReply("OK");
return; return;
} }
@@ -636,15 +590,12 @@ static void HandleSetThread()
SendReply("E01"); SendReply("E01");
} }
static void isThreadAlive() static void isThreadAlive() {
{
int threadid = (int)HexToInt(command_buffer + 1, strlen((char*)command_buffer + 1)); int threadid = (int)HexToInt(command_buffer + 1, strlen((char*)command_buffer + 1));
if(threadid == 0) if (threadid == 0) {
{
threadid = 1; threadid = 1;
} }
if(FindThread(threadid, current_core)) if (FindThread(threadid, current_core)) {
{
SendReply("OK"); SendReply("OK");
return; return;
} }
@@ -656,28 +607,25 @@ static void isThreadAlive()
* *
* @param signal Signal to be sent to client. * @param signal Signal to be sent to client.
*/ */
static void SendSignal(Kernel::Thread *thread, u32 signal, bool full = true) static void SendSignal(Kernel::Thread* thread, u32 signal, bool full = true) {
{ if (gdbserver_socket == -1) {
if(gdbserver_socket == -1)
{
return; return;
} }
latest_signal = signal; latest_signal = signal;
std::string buffer; std::string buffer;
if(full) if (full) {
{ buffer = fmt::format("T{:02x}{:02x}:{:016x};{:02x}:{:016x};", latest_signal, PC_REGISTER,
buffer = fmt::format("T{:02x}{:02x}:{:016x};{:02x}:{:016x};", latest_signal, PC_REGISTER, htonll(regr(PC_REGISTER, thread)), SP_REGISTER, htonll(regr(SP_REGISTER, thread))); htonll(regr(PC_REGISTER, thread)), SP_REGISTER,
} htonll(regr(SP_REGISTER, thread)));
else } else {
{
buffer = fmt::format("T{:02x};", latest_signal); buffer = fmt::format("T{:02x};", latest_signal);
} }
buffer += fmt::format("thread:{:x};", thread->GetThreadId()); buffer += fmt::format("thread:{:x};", thread->GetThreadId());
//NGLOG_ERROR(Debug_GDBStub, "Sig: {}", buffer.c_str()); // NGLOG_ERROR(Debug_GDBStub, "Sig: {}", buffer.c_str());
SendReply(buffer.c_str()); SendReply(buffer.c_str());
} }
@@ -903,7 +851,7 @@ bool send_trap = false;
void Break(bool is_memory_break) { void Break(bool is_memory_break) {
if (!halt_loop) { if (!halt_loop) {
halt_loop = true; halt_loop = true;
//SendSignal(SIGTRAP); // SendSignal(SIGTRAP);
send_trap = true; send_trap = true;
} }
@@ -914,7 +862,7 @@ void Break(bool is_memory_break) {
static void Step() { static void Step() {
step_loop = true; step_loop = true;
halt_loop = true; halt_loop = true;
//SendSignal(SIGTRAP); // SendSignal(SIGTRAP);
send_trap = true; send_trap = true;
} }
@@ -1252,12 +1200,10 @@ void SetCpuStepFlag(bool is_step) {
step_loop = is_step; step_loop = is_step;
} }
void SendSig(void *_thread, int sig) void SendSig(void* _thread, int sig) {
{ if (send_trap) {
if(send_trap)
{
send_trap = false; send_trap = false;
SendSignal((Kernel::Thread *)_thread, sig); SendSignal((Kernel::Thread*)_thread, sig);
} }
} }
}; // namespace GDBStub }; // namespace GDBStub

View File

@@ -92,5 +92,5 @@ bool GetCpuStepFlag();
*/ */
void SetCpuStepFlag(bool is_step); void SetCpuStepFlag(bool is_step);
void SendSig(void *thread, int sig); void SendSig(void* thread, int sig);
} // namespace GDBStub } // namespace GDBStub