Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helping ghidra further. #1307

Merged
merged 1 commit into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions src/core/gdb-server.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/***************************************************************************

Check notice on line 1 in src/core/gdb-server.cc

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Overall Code Complexity

The mean cyclomatic complexity increases from 7.65 to 7.80, threshold = 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.
* Copyright (C) 2020 PCSX-Redux authors *
* *
* This program is free software; you can redistribute it and/or modify *
Expand Down Expand Up @@ -478,28 +478,30 @@
if (g_emulator->settings.get<Emulator::SettingDebugSettings>().get<Emulator::DebugSettings::GdbServerTrace>()) {
g_system->log(LogClass::GDB, "GDB --> PCSX %s\n", m_cmd.c_str());
}
static const std::string qSupported = "qSupported:";
static const std::string qXferFeatures = "qXfer:features:read:target.xml:";
static const std::string qXferThreads = "qXfer:threads:read::";
static const std::string qXferMemMap = "qXfer:memory-map:read::";
static const std::string qSymbol = "qSymbol:";
using namespace std::literals;

static const auto qSupported = "qSupported:"sv;
static const auto qXferFeatures = "qXfer:features:read:target.xml:"sv;
static const auto qXferThreads = "qXfer:threads:read::"sv;
static const auto qXferMemMap = "qXfer:memory-map:read::"sv;
static const auto qSymbol = "qSymbol:"sv;
if (m_cmd == "!") {
// extended mode?
write("OK");
} else if (m_cmd == "?") {
// query reason for stop
if (g_system->running()) {
write("S00");
} else { // we may need one for 02 ? SIGINT
write("S05");
}
} else if (m_cmd == "D") {
// detach
write("OK");
close();
} else if (m_cmd == "qC") {
// return current thread id - always 00
write("QC00");
// return current thread id - always p1.t1
write("QCp1.t1");

Check warning on line 504 in src/core/gdb-server.cc

View check run for this annotation

Codecov / codecov/patch

src/core/gdb-server.cc#L504

Added line #L504 was not covered by tests
} else if (m_cmd == "qAttached") {
// query if attached to existing process - always true
write("1");
Expand Down Expand Up @@ -664,13 +666,21 @@
} else if (StringsHelpers::startsWith(m_cmd, "vKill;")) {
write("OK");
} else if (StringsHelpers::startsWith(m_cmd, qSupported)) {
// do we care about any features gdb supports?
// auto elements = split(m_cmd.substr(qSupported.length()), ";");
auto elements = StringsHelpers::split(m_cmd.substr(qSupported.length()), ";");
bool multiprocess = false;
for (const auto& element : elements) {
if (element == "multiprocess+") {
multiprocess = true;

Check warning on line 673 in src/core/gdb-server.cc

View check run for this annotation

Codecov / codecov/patch

src/core/gdb-server.cc#L669-L673

Added lines #L669 - L673 were not covered by tests
}
}
std::string answer = "PacketSize=47ff;qXfer:threads:read+;QStartNoAckMode+";
if (multiprocess) {
answer += ";multiprocess+";

Check warning on line 678 in src/core/gdb-server.cc

View check run for this annotation

Codecov / codecov/patch

src/core/gdb-server.cc#L676-L678

Added lines #L676 - L678 were not covered by tests
}
if (g_emulator->settings.get<Emulator::SettingDebugSettings>().get<Emulator::DebugSettings::GdbManifest>()) {
write("PacketSize=4000;qXfer:features:read+;qXfer:threads:read+;qXfer:memory-map:read+;QStartNoAckMode+");
} else {
write("PacketSize=4000;qXfer:threads:read+;QStartNoAckMode+");
answer += ";qXfer:features:read+;qXfer:memory-map:read+";

Check warning on line 681 in src/core/gdb-server.cc

View check run for this annotation

Codecov / codecov/patch

src/core/gdb-server.cc#L681

Added line #L681 was not covered by tests
}
write(std::move(answer));

Check warning on line 683 in src/core/gdb-server.cc

View check run for this annotation

Codecov / codecov/patch

src/core/gdb-server.cc#L683

Added line #L683 was not covered by tests
} else if (StringsHelpers::startsWith(m_cmd, "QStartNoAckMode")) {
m_ackEnabled = false;
write("OK");
Expand All @@ -693,7 +703,8 @@
g_emulator->settings.get<Emulator::SettingDebugSettings>().get<Emulator::DebugSettings::GdbManifest>()) {
writePaged(targetXML, m_cmd.substr(qXferFeatures.length()));
} else if (StringsHelpers::startsWith(m_cmd, qXferThreads)) {
writePaged("<?xml version=\"1.0\"?><threads></threads>", m_cmd.substr(qXferThreads.length()));
writePaged("<threads><thread id=\"p1.t1\" core=\"0\" name=\"MainThread\"/></threads>",
m_cmd.substr(qXferThreads.length()));

Check warning on line 707 in src/core/gdb-server.cc

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

PCSX::GdbClient::processCommand increases in cyclomatic complexity from 60 to 63, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

Check warning on line 707 in src/core/gdb-server.cc

View check run for this annotation

Codecov / codecov/patch

src/core/gdb-server.cc#L706-L707

Added lines #L706 - L707 were not covered by tests
} else {
g_system->log(LogClass::GDB, "Unknown GDB command: %s\n", m_cmd.c_str());
write("");
Expand Down
8 changes: 8 additions & 0 deletions tools/ghidra_scripts/ghidra_debugger_scripts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
define info proc mappings
echo 0x0 0xFFFFFFFF 0xFFFFFFFF 0x0 mem
end

define maintenance info sections
echo Exec file: `PSX Binary', file type elf64-mips:3000. \n
echo [0] 0x0->0xFFFFFFFF at 0x00000000: .interp ALLOC LOAD READWRITE DATA HAS_CONTENTS
end
Loading