Applied clang-format.
This commit is contained in:
@@ -9,8 +9,8 @@
|
||||
#include "core/arm/unicorn/arm_unicorn.h"
|
||||
#include "core/core.h"
|
||||
#include "core/core_timing.h"
|
||||
#include "core/hle/kernel/svc.h"
|
||||
#include "core/gdbstub/gdbstub.h"
|
||||
#include "core/hle/kernel/svc.h"
|
||||
|
||||
// Load Unicorn DLL once on Windows using RAII
|
||||
#ifdef _MSC_VER
|
||||
@@ -39,11 +39,10 @@ LoadDll LoadDll::g_load_dll;
|
||||
static GDBStub::BreakpointAddress bkpt = {0};
|
||||
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);
|
||||
if(GDBStub::IsMemoryBreak() || (bkpt.type != GDBStub::BreakpointType::None && address == bkpt.address))
|
||||
{
|
||||
if (GDBStub::IsMemoryBreak() ||
|
||||
(bkpt.type != GDBStub::BreakpointType::None && address == bkpt.address)) {
|
||||
bkptHit = true;
|
||||
uc_emu_stop(uc);
|
||||
}
|
||||
@@ -81,8 +80,7 @@ ARM_Unicorn::ARM_Unicorn() {
|
||||
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_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));
|
||||
}
|
||||
}
|
||||
@@ -173,12 +171,9 @@ void ARM_Unicorn::SetTlsAddress(VAddr base) {
|
||||
}
|
||||
|
||||
void ARM_Unicorn::Run() {
|
||||
if(GDBStub::IsServerEnabled())
|
||||
{
|
||||
if (GDBStub::IsServerEnabled()) {
|
||||
ExecuteInstructions(std::max(4000000, 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
ExecuteInstructions(std::max(CoreTiming::GetDowncount(), 0));
|
||||
}
|
||||
}
|
||||
@@ -193,16 +188,13 @@ void ARM_Unicorn::ExecuteInstructions(int num_instructions) {
|
||||
MICROPROFILE_SCOPE(ARM_Jit);
|
||||
CHECKED(uc_emu_start(uc, GetPC(), 1ULL << 63, 0, num_instructions));
|
||||
CoreTiming::AddTicks(num_instructions);
|
||||
if(GDBStub::IsServerEnabled())
|
||||
{
|
||||
if(bkptHit)
|
||||
{
|
||||
if (GDBStub::IsServerEnabled()) {
|
||||
if (bkptHit) {
|
||||
uc_reg_write(uc, UC_ARM64_REG_PC, &bkpt.address);
|
||||
}
|
||||
Kernel::Thread *thread = Kernel::GetCurrentThread();
|
||||
Kernel::Thread* thread = Kernel::GetCurrentThread();
|
||||
SaveContext(thread->context);
|
||||
if(bkptHit)
|
||||
{
|
||||
if (bkptHit) {
|
||||
bkptHit = false;
|
||||
GDBStub::Break();
|
||||
}
|
||||
|
||||
@@ -41,10 +41,10 @@
|
||||
#include "core/core.h"
|
||||
#include "core/core_cpu.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/scheduler.h"
|
||||
#include "core/loader/loader.h"
|
||||
#include "core/memory.h"
|
||||
|
||||
const int GDB_BUFFER_SIZE = 10000;
|
||||
|
||||
@@ -147,7 +147,7 @@ static u32 command_length;
|
||||
static u32 latest_signal = 0;
|
||||
static bool memory_break = false;
|
||||
|
||||
Kernel::Thread *thread = nullptr;
|
||||
Kernel::Thread* thread = nullptr;
|
||||
int current_core = 0;
|
||||
|
||||
// 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_write;
|
||||
|
||||
Kernel::Thread *FindThread(int id, int& current_core)
|
||||
{
|
||||
Kernel::Thread *thread = nullptr;
|
||||
for(int core = 0; core < Core::NUM_CPU_CORES; core++)
|
||||
{
|
||||
Kernel::Thread* FindThread(int id, int& current_core) {
|
||||
Kernel::Thread* thread = nullptr;
|
||||
for (int core = 0; core < Core::NUM_CPU_CORES; core++) {
|
||||
auto list = Core::System::GetInstance().Scheduler(core)->GetThreadList();
|
||||
for(auto it = list.begin(); it != list.end(); it++)
|
||||
{
|
||||
if((*it)->GetThreadId() == id)
|
||||
{
|
||||
thread = &(*(*it));
|
||||
current_core = core;
|
||||
break;
|
||||
for (auto it = list.begin(); it != list.end(); it++) {
|
||||
if ((*it)->GetThreadId() == id) {
|
||||
thread = &(*(*it));
|
||||
current_core = core;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return thread;
|
||||
}
|
||||
|
||||
static u64 regr(int id, Kernel::Thread *thread = nullptr)
|
||||
{
|
||||
if(!thread)
|
||||
{
|
||||
static u64 regr(int id, Kernel::Thread* thread = nullptr) {
|
||||
if (!thread) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(id < SP_REGISTER)
|
||||
{
|
||||
if (id < SP_REGISTER) {
|
||||
return thread->context.cpu_registers[id];
|
||||
}
|
||||
else if(id == SP_REGISTER)
|
||||
{
|
||||
} else if (id == SP_REGISTER) {
|
||||
return thread->context.sp;
|
||||
}
|
||||
else if(id == PC_REGISTER)
|
||||
{
|
||||
} else if (id == PC_REGISTER) {
|
||||
return thread->context.pc;
|
||||
}
|
||||
else if(id == CPSR_REGISTER)
|
||||
{
|
||||
} else if (id == CPSR_REGISTER) {
|
||||
return thread->context.cpsr;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void regw(int id, u64 val, Kernel::Thread *thread = nullptr)
|
||||
{
|
||||
if(!thread)
|
||||
{
|
||||
static void regw(int id, u64 val, Kernel::Thread* thread = nullptr) {
|
||||
if (!thread) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(id < SP_REGISTER)
|
||||
{
|
||||
if (id < SP_REGISTER) {
|
||||
thread->context.cpu_registers[id] = val;
|
||||
}
|
||||
else if(id == SP_REGISTER)
|
||||
{
|
||||
} else if (id == SP_REGISTER) {
|
||||
thread->context.sp = val;
|
||||
}
|
||||
else if(id == PC_REGISTER)
|
||||
{
|
||||
} else if (id == PC_REGISTER) {
|
||||
thread->context.pc = val;
|
||||
}
|
||||
else if(id == CPSR_REGISTER)
|
||||
{
|
||||
} else if (id == CPSR_REGISTER) {
|
||||
thread->context.cpsr = val;
|
||||
}
|
||||
}
|
||||
@@ -555,39 +531,27 @@ static void SendReply(const char* reply) {
|
||||
}
|
||||
|
||||
/// Handle query command from gdb client.
|
||||
static void HandleQuery()
|
||||
{
|
||||
static void HandleQuery() {
|
||||
NGLOG_DEBUG(Debug_GDBStub, "gdb: query '{}'", 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");
|
||||
}
|
||||
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
|
||||
SendReply("PacketSize=2000;qXfer:features:read+");
|
||||
}
|
||||
else if(strncmp(query, "Xfer:features:read:target.xml:",
|
||||
strlen("Xfer:features:read:target.xml:")) == 0)
|
||||
{
|
||||
} else if (strncmp(query, "Xfer:features:read:target.xml:",
|
||||
strlen("Xfer:features:read:target.xml:")) == 0) {
|
||||
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);
|
||||
SendReply(buffer.c_str());
|
||||
}
|
||||
else if(strncmp(query, "fThreadInfo", strlen("fThreadInfo")) == 0)
|
||||
{
|
||||
} else if (strncmp(query, "fThreadInfo", strlen("fThreadInfo")) == 0) {
|
||||
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();
|
||||
for(auto it = list.begin(); it != list.end(); it++)
|
||||
{
|
||||
for (auto it = list.begin(); it != list.end(); it++) {
|
||||
char tmp[17] = {0};
|
||||
memset(tmp, 0, sizeof(tmp));
|
||||
sprintf(tmp, "%x", (*it)->GetThreadId());
|
||||
@@ -597,38 +561,28 @@ static void HandleQuery()
|
||||
}
|
||||
val.pop_back();
|
||||
SendReply(val.c_str());
|
||||
}
|
||||
else if(strncmp(query, "sThreadInfo", strlen("sThreadInfo")) == 0)
|
||||
{
|
||||
} else if (strncmp(query, "sThreadInfo", strlen("sThreadInfo")) == 0) {
|
||||
SendReply("l");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
SendReply("");
|
||||
}
|
||||
}
|
||||
|
||||
/// Handle set thread command from gdb client.
|
||||
static void HandleSetThread()
|
||||
{
|
||||
if(memcmp(command_buffer, "Hc", 2) == 0 || memcmp(command_buffer, "Hg", 2) == 0)
|
||||
{
|
||||
static void HandleSetThread() {
|
||||
if (memcmp(command_buffer, "Hc", 2) == 0 || memcmp(command_buffer, "Hg", 2) == 0) {
|
||||
int threadid = -1;
|
||||
if(command_buffer[2] != '-')
|
||||
{
|
||||
if (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);
|
||||
}
|
||||
if(!thread)
|
||||
{
|
||||
if (!thread) {
|
||||
threadid = 1;
|
||||
thread = FindThread(threadid, current_core);
|
||||
}
|
||||
if(thread)
|
||||
{
|
||||
if (thread) {
|
||||
SendReply("OK");
|
||||
return;
|
||||
}
|
||||
@@ -636,15 +590,12 @@ static void HandleSetThread()
|
||||
SendReply("E01");
|
||||
}
|
||||
|
||||
static void isThreadAlive()
|
||||
{
|
||||
static void isThreadAlive() {
|
||||
int threadid = (int)HexToInt(command_buffer + 1, strlen((char*)command_buffer + 1));
|
||||
if(threadid == 0)
|
||||
{
|
||||
if (threadid == 0) {
|
||||
threadid = 1;
|
||||
}
|
||||
if(FindThread(threadid, current_core))
|
||||
{
|
||||
if (FindThread(threadid, current_core)) {
|
||||
SendReply("OK");
|
||||
return;
|
||||
}
|
||||
@@ -656,28 +607,25 @@ static void isThreadAlive()
|
||||
*
|
||||
* @param signal Signal to be sent to client.
|
||||
*/
|
||||
static void SendSignal(Kernel::Thread *thread, u32 signal, bool full = true)
|
||||
{
|
||||
if(gdbserver_socket == -1)
|
||||
{
|
||||
static void SendSignal(Kernel::Thread* thread, u32 signal, bool full = true) {
|
||||
if (gdbserver_socket == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
latest_signal = signal;
|
||||
|
||||
std::string buffer;
|
||||
if(full)
|
||||
{
|
||||
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)));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (full) {
|
||||
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)));
|
||||
} else {
|
||||
buffer = fmt::format("T{:02x};", latest_signal);
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
@@ -903,7 +851,7 @@ bool send_trap = false;
|
||||
void Break(bool is_memory_break) {
|
||||
if (!halt_loop) {
|
||||
halt_loop = true;
|
||||
//SendSignal(SIGTRAP);
|
||||
// SendSignal(SIGTRAP);
|
||||
send_trap = true;
|
||||
}
|
||||
|
||||
@@ -914,7 +862,7 @@ void Break(bool is_memory_break) {
|
||||
static void Step() {
|
||||
step_loop = true;
|
||||
halt_loop = true;
|
||||
//SendSignal(SIGTRAP);
|
||||
// SendSignal(SIGTRAP);
|
||||
send_trap = true;
|
||||
}
|
||||
|
||||
@@ -1252,12 +1200,10 @@ void SetCpuStepFlag(bool is_step) {
|
||||
step_loop = is_step;
|
||||
}
|
||||
|
||||
void SendSig(void *_thread, int sig)
|
||||
{
|
||||
if(send_trap)
|
||||
{
|
||||
void SendSig(void* _thread, int sig) {
|
||||
if (send_trap) {
|
||||
send_trap = false;
|
||||
SendSignal((Kernel::Thread *)_thread, sig);
|
||||
SendSignal((Kernel::Thread*)_thread, sig);
|
||||
}
|
||||
}
|
||||
}; // namespace GDBStub
|
||||
|
||||
@@ -92,5 +92,5 @@ bool GetCpuStepFlag();
|
||||
*/
|
||||
void SetCpuStepFlag(bool is_step);
|
||||
|
||||
void SendSig(void *thread, int sig);
|
||||
void SendSig(void* thread, int sig);
|
||||
} // namespace GDBStub
|
||||
|
||||
Reference in New Issue
Block a user