mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2025-02-05 06:52:50 +00:00
Compare commits
3 commits
72ccf60df2
...
57022974f9
Author | SHA1 | Date | |
---|---|---|---|
|
57022974f9 | ||
|
009f581721 | ||
|
18530d0bf6 |
5 changed files with 108 additions and 19 deletions
|
@ -26,6 +26,8 @@ namespace ams::creport {
|
||||||
static_assert(DyingMessageAddressOffset == AMS_OFFSETOF(ams::svc::aarch64::ProcessLocalRegion, dying_message_region_address));
|
static_assert(DyingMessageAddressOffset == AMS_OFFSETOF(ams::svc::aarch64::ProcessLocalRegion, dying_message_region_address));
|
||||||
static_assert(DyingMessageAddressOffset == AMS_OFFSETOF(ams::svc::aarch32::ProcessLocalRegion, dying_message_region_address));
|
static_assert(DyingMessageAddressOffset == AMS_OFFSETOF(ams::svc::aarch32::ProcessLocalRegion, dying_message_region_address));
|
||||||
|
|
||||||
|
constexpr size_t CrashReportDataCacheSize = 256_KB;
|
||||||
|
|
||||||
/* Helper functions. */
|
/* Helper functions. */
|
||||||
bool TryGetCurrentTimestamp(u64 *out) {
|
bool TryGetCurrentTimestamp(u64 *out) {
|
||||||
/* Clear output. */
|
/* Clear output. */
|
||||||
|
@ -307,7 +309,15 @@ namespace ams::creport {
|
||||||
/* Save crash report. */
|
/* Save crash report. */
|
||||||
util::SNPrintf(file_path, sizeof(file_path), "sdmc:/atmosphere/crash_reports/%011lu_%016lx.log", timestamp, m_process_info.program_id);
|
util::SNPrintf(file_path, sizeof(file_path), "sdmc:/atmosphere/crash_reports/%011lu_%016lx.log", timestamp, m_process_info.program_id);
|
||||||
{
|
{
|
||||||
ScopedFile file(file_path);
|
/* Try to allocate data cache. */
|
||||||
|
void * const data_cache = lmem::AllocateFromExpHeap(m_heap_handle, CrashReportDataCacheSize + os::MemoryPageSize);
|
||||||
|
ON_SCOPE_EXIT { if (data_cache != nullptr) { lmem::FreeToExpHeap(m_heap_handle, data_cache); } };
|
||||||
|
|
||||||
|
/* Align up the data cache. This is safe because null will align up to null. */
|
||||||
|
void * const aligned_cache = reinterpret_cast<void *>(util::AlignUp(reinterpret_cast<uintptr_t>(data_cache), os::MemoryPageSize));
|
||||||
|
|
||||||
|
/* Open and save the file using the cache. */
|
||||||
|
ScopedFile file(file_path, aligned_cache, aligned_cache != nullptr ? CrashReportDataCacheSize : 0);
|
||||||
if (file.IsOpen()) {
|
if (file.IsOpen()) {
|
||||||
this->SaveToFile(file);
|
this->SaveToFile(file);
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ namespace ams::creport {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModuleList::SaveToFile(ScopedFile &file) {
|
void ModuleList::SaveToFile(ScopedFile &file) {
|
||||||
file.WriteFormat(" Number of Modules: %zu\n", m_num_modules);
|
file.WriteFormat(" Number of Modules: %02zu\n", m_num_modules);
|
||||||
for (size_t i = 0; i < m_num_modules; i++) {
|
for (size_t i = 0; i < m_num_modules; i++) {
|
||||||
const auto& module = m_modules[i];
|
const auto& module = m_modules[i];
|
||||||
file.WriteFormat(" Module %02zu:\n", i);
|
file.WriteFormat(" Module %02zu:\n", i);
|
||||||
|
|
|
@ -60,22 +60,24 @@ namespace ams::creport {
|
||||||
|
|
||||||
/* Print the line prefix. */
|
/* Print the line prefix. */
|
||||||
if (first) {
|
if (first) {
|
||||||
this->WriteFormat("%s", prefix);
|
this->Write(prefix, prefix_len);
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
this->WriteFormat("%*s", prefix_len, "");
|
std::memset(g_format_buffer, ' ', prefix_len);
|
||||||
|
this->Write(g_format_buffer, prefix_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Dump up to 0x20 of hex memory. */
|
/* Dump up to 0x20 of hex memory. */
|
||||||
{
|
{
|
||||||
char hex[MaximumLineLength * 2 + 2] = {};
|
char hex[MaximumLineLength * 2 + 2] = {};
|
||||||
for (size_t i = 0; i < cur_size; i++) {
|
for (size_t i = 0; i < cur_size; i++) {
|
||||||
util::SNPrintf(hex + i * 2, 3, "%02X", data_u8[data_ofs++]);
|
hex[i * 2 + 0] = "0123456789ABCDEF"[data_u8[data_ofs] >> 4];
|
||||||
|
hex[i * 2 + 1] = "0123456789ABCDEF"[data_u8[data_ofs] & 0xF];
|
||||||
|
++data_ofs;
|
||||||
}
|
}
|
||||||
hex[cur_size * 2 + 0] = '\n';
|
hex[cur_size * 2 + 0] = '\n';
|
||||||
hex[cur_size * 2 + 1] = '\x00';
|
|
||||||
|
|
||||||
this->WriteString(hex);
|
this->Write(hex, cur_size * 2 + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Continue. */
|
/* Continue. */
|
||||||
|
@ -83,16 +85,40 @@ namespace ams::creport {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ScopedFile::Write(const void *data, size_t size) {
|
void ScopedFile::Write(const void *data, size_t size) {
|
||||||
/* If we're not open, we can't write. */
|
/* If we're not open, we can't write. */
|
||||||
if (!this->IsOpen()) {
|
if (!this->IsOpen()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Advance, if we write successfully. */
|
/* If we have a cache, write to it. */
|
||||||
if (R_SUCCEEDED(fs::WriteFile(m_file, m_offset, data, size, fs::WriteOption::Flush))) {
|
if (m_cache != nullptr) {
|
||||||
m_offset += size;
|
/* Write into the cache, if we can. */
|
||||||
|
if (m_cache_size - m_cache_offset >= size || R_SUCCEEDED(this->TryWriteCache())) {
|
||||||
|
std::memcpy(m_cache + m_cache_offset, data, size);
|
||||||
|
m_cache_offset += size;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* Advance, if we write successfully. */
|
||||||
|
if (R_SUCCEEDED(fs::WriteFile(m_file, m_offset, data, size, fs::WriteOption::None))) {
|
||||||
|
m_offset += size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result ScopedFile::TryWriteCache() {
|
||||||
|
/* If there's no cached data, there's nothing to do. */
|
||||||
|
R_SUCCEED_IF(m_cache_offset == 0);
|
||||||
|
|
||||||
|
/* Try to write any cached data. */
|
||||||
|
R_TRY(fs::WriteFile(m_file, m_offset, m_cache, m_cache_offset, fs::WriteOption::None));
|
||||||
|
|
||||||
|
/* Update our extents. */
|
||||||
|
m_offset += m_cache_offset;
|
||||||
|
m_cache_offset = 0;
|
||||||
|
|
||||||
|
R_SUCCEED();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -25,8 +25,11 @@ namespace ams::creport {
|
||||||
fs::FileHandle m_file;
|
fs::FileHandle m_file;
|
||||||
s64 m_offset;
|
s64 m_offset;
|
||||||
bool m_opened;
|
bool m_opened;
|
||||||
|
u8 *m_cache;
|
||||||
|
const size_t m_cache_size;
|
||||||
|
s64 m_cache_offset;
|
||||||
public:
|
public:
|
||||||
ScopedFile(const char *path) : m_file(), m_offset(), m_opened(false) {
|
ScopedFile(const char *path, void *cache = nullptr, size_t cache_size = 0) : m_file(), m_offset(), m_opened(false), m_cache(static_cast<u8*>(cache)), m_cache_size(cache_size), m_cache_offset(0) {
|
||||||
if (R_SUCCEEDED(fs::CreateFile(path, 0))) {
|
if (R_SUCCEEDED(fs::CreateFile(path, 0))) {
|
||||||
m_opened = R_SUCCEEDED(fs::OpenFile(std::addressof(m_file), path, fs::OpenMode_Write | fs::OpenMode_AllowAppend));
|
m_opened = R_SUCCEEDED(fs::OpenFile(std::addressof(m_file), path, fs::OpenMode_Write | fs::OpenMode_AllowAppend));
|
||||||
}
|
}
|
||||||
|
@ -34,6 +37,10 @@ namespace ams::creport {
|
||||||
|
|
||||||
~ScopedFile() {
|
~ScopedFile() {
|
||||||
if (m_opened) {
|
if (m_opened) {
|
||||||
|
if (m_cache != nullptr) {
|
||||||
|
this->TryWriteCache();
|
||||||
|
}
|
||||||
|
fs::FlushFile(m_file);
|
||||||
fs::CloseFile(m_file);
|
fs::CloseFile(m_file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,6 +54,8 @@ namespace ams::creport {
|
||||||
void DumpMemory(const char *prefix, const void *data, size_t size);
|
void DumpMemory(const char *prefix, const void *data, size_t size);
|
||||||
|
|
||||||
void Write(const void *data, size_t size);
|
void Write(const void *data, size_t size);
|
||||||
|
private:
|
||||||
|
Result TryWriteCache();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
|
@ -1232,6 +1232,7 @@ namespace ams::dmnt {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reply_cur != send_buffer) {
|
if (reply_cur != send_buffer) {
|
||||||
|
AMS_DMNT2_GDB_LOG_DEBUG("ProcessDebugEvents: %s\n", send_buffer);
|
||||||
bool do_break;
|
bool do_break;
|
||||||
this->SendPacket(std::addressof(do_break), send_buffer);
|
this->SendPacket(std::addressof(do_break), send_buffer);
|
||||||
if (do_break) {
|
if (do_break) {
|
||||||
|
@ -1322,6 +1323,8 @@ namespace ams::dmnt {
|
||||||
/* Clear our reply packet. */
|
/* Clear our reply packet. */
|
||||||
reply[0] = 0;
|
reply[0] = 0;
|
||||||
|
|
||||||
|
bool should_log_result = true;
|
||||||
|
|
||||||
/* Handle the received packet. */
|
/* Handle the received packet. */
|
||||||
switch (m_receive_packet[0]) {
|
switch (m_receive_packet[0]) {
|
||||||
case 'D':
|
case 'D':
|
||||||
|
@ -1358,9 +1361,11 @@ namespace ams::dmnt {
|
||||||
if (!this->g()) {
|
if (!this->g()) {
|
||||||
m_killed = true;
|
m_killed = true;
|
||||||
}
|
}
|
||||||
|
should_log_result = false;
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
this->m();
|
this->m();
|
||||||
|
should_log_result = false;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
this->p();
|
this->p();
|
||||||
|
@ -1381,9 +1386,10 @@ namespace ams::dmnt {
|
||||||
this->QuestionMark();
|
this->QuestionMark();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
AMS_DMNT2_GDB_LOG_DEBUG("Not Implemented: %s\n", m_receive_packet);
|
AMS_DMNT2_GDB_LOG_ERROR("Not Implemented: %s\n", m_receive_packet);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
AMS_DMNT2_GDB_LOG_DEBUG("Reply: %s\n", should_log_result ? reply : "[...]");
|
||||||
}
|
}
|
||||||
|
|
||||||
void GdbServerImpl::D() {
|
void GdbServerImpl::D() {
|
||||||
|
@ -1401,6 +1407,7 @@ namespace ams::dmnt {
|
||||||
/* Get thread context. */
|
/* Get thread context. */
|
||||||
svc::ThreadContext ctx;
|
svc::ThreadContext ctx;
|
||||||
if (R_FAILED(m_debug_process.GetThreadContext(std::addressof(ctx), thread_id, svc::ThreadContextFlag_All))) {
|
if (R_FAILED(m_debug_process.GetThreadContext(std::addressof(ctx), thread_id, svc::ThreadContextFlag_All))) {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("Failed to get thread context\n");
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1412,6 +1419,7 @@ namespace ams::dmnt {
|
||||||
if (R_SUCCEEDED(m_debug_process.SetThreadContext(std::addressof(ctx), thread_id, svc::ThreadContextFlag_All))) {
|
if (R_SUCCEEDED(m_debug_process.SetThreadContext(std::addressof(ctx), thread_id, svc::ThreadContextFlag_All))) {
|
||||||
AppendReplyOk(m_reply_cur, m_reply_end);
|
AppendReplyOk(m_reply_cur, m_reply_end);
|
||||||
} else {
|
} else {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("Failed to set thread context\n");
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1421,9 +1429,11 @@ namespace ams::dmnt {
|
||||||
if (ParsePrefix(m_receive_packet, "Hg") || ParsePrefix(m_receive_packet, "HG")) {
|
if (ParsePrefix(m_receive_packet, "Hg") || ParsePrefix(m_receive_packet, "HG")) {
|
||||||
this->Hg();
|
this->Hg();
|
||||||
} else {
|
} else {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("'H'-command not implemented: %s\n", m_receive_packet);
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("Cannot use 'H'-command without DebugProcess\n");
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1458,6 +1468,7 @@ namespace ams::dmnt {
|
||||||
if (success) {
|
if (success) {
|
||||||
AppendReplyOk(m_reply_cur, m_reply_end);
|
AppendReplyOk(m_reply_cur, m_reply_end);
|
||||||
} else {
|
} else {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("'Hg'-command failed\n");
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1468,6 +1479,7 @@ namespace ams::dmnt {
|
||||||
/* Validate format. */
|
/* Validate format. */
|
||||||
char *comma = std::strchr(m_receive_packet, ',');
|
char *comma = std::strchr(m_receive_packet, ',');
|
||||||
if (comma == nullptr) {
|
if (comma == nullptr) {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("'M' command formatted incorrectly (no ','): %s\n", m_receive_packet);
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1475,6 +1487,7 @@ namespace ams::dmnt {
|
||||||
|
|
||||||
char *colon = std::strchr(comma + 1, ':');
|
char *colon = std::strchr(comma + 1, ':');
|
||||||
if (colon == nullptr) {
|
if (colon == nullptr) {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("'M' command formatted incorrectly (no ':'): %s\n", m_receive_packet);
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1484,6 +1497,7 @@ namespace ams::dmnt {
|
||||||
const u64 address = DecodeHex(m_receive_packet);
|
const u64 address = DecodeHex(m_receive_packet);
|
||||||
const u64 length = DecodeHex(comma + 1);
|
const u64 length = DecodeHex(comma + 1);
|
||||||
if (length >= sizeof(m_buffer)) {
|
if (length >= sizeof(m_buffer)) {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("Length exceeded buffer size: %ld >= %ld\n", length, sizeof(m_buffer));
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1495,6 +1509,7 @@ namespace ams::dmnt {
|
||||||
if (R_SUCCEEDED(m_debug_process.WriteMemory(m_buffer, address, length))) {
|
if (R_SUCCEEDED(m_debug_process.WriteMemory(m_buffer, address, length))) {
|
||||||
AppendReplyOk(m_reply_cur, m_reply_end);
|
AppendReplyOk(m_reply_cur, m_reply_end);
|
||||||
} else {
|
} else {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("Failed to write memory\n");
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1505,6 +1520,7 @@ namespace ams::dmnt {
|
||||||
/* Validate format. */
|
/* Validate format. */
|
||||||
char *equal = std::strchr(m_receive_packet, '=');
|
char *equal = std::strchr(m_receive_packet, '=');
|
||||||
if (equal == nullptr) {
|
if (equal == nullptr) {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("'P' command formatted incorrectly (no '='): %s\n", m_receive_packet);
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1530,9 +1546,11 @@ namespace ams::dmnt {
|
||||||
if (R_SUCCEEDED(m_debug_process.SetThreadContext(std::addressof(ctx), thread_id, flags))) {
|
if (R_SUCCEEDED(m_debug_process.SetThreadContext(std::addressof(ctx), thread_id, flags))) {
|
||||||
AppendReplyOk(m_reply_cur, m_reply_end);
|
AppendReplyOk(m_reply_cur, m_reply_end);
|
||||||
} else {
|
} else {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("Failed to set thread context");
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("Failed to get thread context");
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1541,7 +1559,7 @@ namespace ams::dmnt {
|
||||||
if (ParsePrefix(m_receive_packet, "QStartNoAckMode")) {
|
if (ParsePrefix(m_receive_packet, "QStartNoAckMode")) {
|
||||||
this->QStartNoAckMode();
|
this->QStartNoAckMode();
|
||||||
} else {
|
} else {
|
||||||
AMS_DMNT2_GDB_LOG_DEBUG("Not Implemented Q: %s\n", m_receive_packet);
|
AMS_DMNT2_GDB_LOG_ERROR("Not Implemented Q: %s\n", m_receive_packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1558,9 +1576,11 @@ namespace ams::dmnt {
|
||||||
if (R_SUCCEEDED(m_debug_process.GetThreadContext(std::addressof(ctx), thread_id, svc::ThreadContextFlag_Control))) {
|
if (R_SUCCEEDED(m_debug_process.GetThreadContext(std::addressof(ctx), thread_id, svc::ThreadContextFlag_Control))) {
|
||||||
AppendReplyOk(m_reply_cur, m_reply_end);
|
AppendReplyOk(m_reply_cur, m_reply_end);
|
||||||
} else {
|
} else {
|
||||||
AppendReplyFormat(m_reply_cur, m_reply_end, "E01");
|
AMS_DMNT2_GDB_LOG_ERROR("Failed to get thread context");
|
||||||
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("'T' command formatted incorrectly (no '.'): %s\n", m_receive_packet);
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1571,6 +1591,7 @@ namespace ams::dmnt {
|
||||||
|
|
||||||
/* Decode the type. */
|
/* Decode the type. */
|
||||||
if (!('0' <= m_receive_packet[0] && m_receive_packet[0] <= '4') || m_receive_packet[1] != ',') {
|
if (!('0' <= m_receive_packet[0] && m_receive_packet[0] <= '4') || m_receive_packet[1] != ',') {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("'Z' command formatted incorrectly (not starting with pattern '[0-4],'): %s\n", m_receive_packet);
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1581,6 +1602,7 @@ namespace ams::dmnt {
|
||||||
/* Decode the address/length. */
|
/* Decode the address/length. */
|
||||||
const char *comma = std::strchr(m_receive_packet, ',');
|
const char *comma = std::strchr(m_receive_packet, ',');
|
||||||
if (comma == nullptr) {
|
if (comma == nullptr) {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("'Z' command formatted incorrectly (no ','): %s\n", m_receive_packet);
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1596,6 +1618,7 @@ namespace ams::dmnt {
|
||||||
if (R_SUCCEEDED(m_debug_process.SetBreakPoint(address, length, false))) {
|
if (R_SUCCEEDED(m_debug_process.SetBreakPoint(address, length, false))) {
|
||||||
AppendReplyOk(m_reply_cur, m_reply_end);
|
AppendReplyOk(m_reply_cur, m_reply_end);
|
||||||
} else {
|
} else {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("Failed to set software breakpoint\n");
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1607,6 +1630,7 @@ namespace ams::dmnt {
|
||||||
if (R_SUCCEEDED(m_debug_process.SetHardwareBreakPoint(address, length, false))) {
|
if (R_SUCCEEDED(m_debug_process.SetHardwareBreakPoint(address, length, false))) {
|
||||||
AppendReplyOk(m_reply_cur, m_reply_end);
|
AppendReplyOk(m_reply_cur, m_reply_end);
|
||||||
} else {
|
} else {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("Failed to set hardware breakpoint\n");
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1618,6 +1642,7 @@ namespace ams::dmnt {
|
||||||
if (R_SUCCEEDED(m_debug_process.SetWatchPoint(address, length, false, true))) {
|
if (R_SUCCEEDED(m_debug_process.SetWatchPoint(address, length, false, true))) {
|
||||||
AppendReplyOk(m_reply_cur, m_reply_end);
|
AppendReplyOk(m_reply_cur, m_reply_end);
|
||||||
} else {
|
} else {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("Failed to set watchpoint-W\n");
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1629,6 +1654,7 @@ namespace ams::dmnt {
|
||||||
if (R_SUCCEEDED(m_debug_process.SetWatchPoint(address, length, true, false))) {
|
if (R_SUCCEEDED(m_debug_process.SetWatchPoint(address, length, true, false))) {
|
||||||
AppendReplyOk(m_reply_cur, m_reply_end);
|
AppendReplyOk(m_reply_cur, m_reply_end);
|
||||||
} else {
|
} else {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("Failed to set watchpoint-R\n");
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1640,6 +1666,7 @@ namespace ams::dmnt {
|
||||||
if (R_SUCCEEDED(m_debug_process.SetWatchPoint(address, length, true, true))) {
|
if (R_SUCCEEDED(m_debug_process.SetWatchPoint(address, length, true, true))) {
|
||||||
AppendReplyOk(m_reply_cur, m_reply_end);
|
AppendReplyOk(m_reply_cur, m_reply_end);
|
||||||
} else {
|
} else {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("Failed to set watchpoint-A\n");
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1668,6 +1695,7 @@ namespace ams::dmnt {
|
||||||
if (R_SUCCEEDED(result)) {
|
if (R_SUCCEEDED(result)) {
|
||||||
AppendReplyOk(m_reply_cur, m_reply_end);
|
AppendReplyOk(m_reply_cur, m_reply_end);
|
||||||
} else {
|
} else {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("Failed to continue thread\n");
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1697,6 +1725,7 @@ namespace ams::dmnt {
|
||||||
/* Validate format. */
|
/* Validate format. */
|
||||||
const char *comma = std::strchr(m_receive_packet, ',');
|
const char *comma = std::strchr(m_receive_packet, ',');
|
||||||
if (comma == nullptr) {
|
if (comma == nullptr) {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("'m' command formatted incorrectly (no ','): %s\n", m_receive_packet);
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1705,6 +1734,7 @@ namespace ams::dmnt {
|
||||||
const u64 address = DecodeHex(m_receive_packet);
|
const u64 address = DecodeHex(m_receive_packet);
|
||||||
const u64 length = DecodeHex(comma + 1);
|
const u64 length = DecodeHex(comma + 1);
|
||||||
if (length >= sizeof(m_buffer)) {
|
if (length >= sizeof(m_buffer)) {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("Length exceeded buffer size: %ld >= %ld\n", length, sizeof(m_buffer));
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1712,6 +1742,7 @@ namespace ams::dmnt {
|
||||||
/* Read the memory. */
|
/* Read the memory. */
|
||||||
/* TODO: Detect partial readability? */
|
/* TODO: Detect partial readability? */
|
||||||
if (R_FAILED(m_debug_process.ReadMemory(m_buffer, address, length))) {
|
if (R_FAILED(m_debug_process.ReadMemory(m_buffer, address, length))) {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("Failed to read memory\n");
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1745,6 +1776,7 @@ namespace ams::dmnt {
|
||||||
if (R_SUCCEEDED(m_debug_process.GetThreadContext(std::addressof(ctx), thread_id, flags))) {
|
if (R_SUCCEEDED(m_debug_process.GetThreadContext(std::addressof(ctx), thread_id, flags))) {
|
||||||
SetGdbRegisterPacket(m_reply_cur, m_reply_end, ctx, reg_num, m_debug_process.Is64Bit());
|
SetGdbRegisterPacket(m_reply_cur, m_reply_end, ctx, reg_num, m_debug_process.Is64Bit());
|
||||||
} else {
|
} else {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("Failed to get thread context");
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1755,7 +1787,7 @@ namespace ams::dmnt {
|
||||||
} else if (ParsePrefix(m_receive_packet, "vCont")) {
|
} else if (ParsePrefix(m_receive_packet, "vCont")) {
|
||||||
this->vCont();
|
this->vCont();
|
||||||
} else {
|
} else {
|
||||||
AMS_DMNT2_GDB_LOG_DEBUG("Not Implemented v: %s\n", m_receive_packet);
|
AMS_DMNT2_GDB_LOG_ERROR("Not Implemented v: %s\n", m_receive_packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1780,12 +1812,15 @@ namespace ams::dmnt {
|
||||||
/* Set the stop reply packet. */
|
/* Set the stop reply packet. */
|
||||||
this->AppendStopReplyPacket(m_debug_process.GetLastSignal());
|
this->AppendStopReplyPacket(m_debug_process.GetLastSignal());
|
||||||
} else {
|
} else {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("Failed to attach to process\n");
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("Invalid process id: %s\n", m_receive_packet);
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("Cannot attach to process while already attached\n");
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1937,7 +1972,7 @@ namespace ams::dmnt {
|
||||||
} else if (ParsePrefix(m_receive_packet, "qXfer:")) {
|
} else if (ParsePrefix(m_receive_packet, "qXfer:")) {
|
||||||
this->qXfer();
|
this->qXfer();
|
||||||
} else {
|
} else {
|
||||||
AMS_DMNT2_GDB_LOG_DEBUG("Not Implemented q: %s\n", m_receive_packet);
|
AMS_DMNT2_GDB_LOG_ERROR("Not Implemented q: %s\n", m_receive_packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1945,6 +1980,7 @@ namespace ams::dmnt {
|
||||||
if (this->HasDebugProcess()) {
|
if (this->HasDebugProcess()) {
|
||||||
AppendReplyFormat(m_reply_cur, m_reply_end, "1");
|
AppendReplyFormat(m_reply_cur, m_reply_end, "1");
|
||||||
} else {
|
} else {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("Not attached\n");
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1954,6 +1990,7 @@ namespace ams::dmnt {
|
||||||
/* Send the thread id. */
|
/* Send the thread id. */
|
||||||
AppendReplyFormat(m_reply_cur, m_reply_end, "QCp%lx.%lx", m_process_id.value, m_debug_process.GetLastThreadId());
|
AppendReplyFormat(m_reply_cur, m_reply_end, "QCp%lx.%lx", m_process_id.value, m_debug_process.GetLastThreadId());
|
||||||
} else {
|
} else {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("Not attached\n");
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2161,6 +2198,7 @@ namespace ams::dmnt {
|
||||||
} else {
|
} else {
|
||||||
/* All other qXfer require debug process. */
|
/* All other qXfer require debug process. */
|
||||||
if (!this->HasDebugProcess()) {
|
if (!this->HasDebugProcess()) {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("Not attached\n");
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2171,6 +2209,7 @@ namespace ams::dmnt {
|
||||||
} else if (ParsePrefix(m_receive_packet, "threads:read::")) {
|
} else if (ParsePrefix(m_receive_packet, "threads:read::")) {
|
||||||
if (!this->qXferThreadsRead()) {
|
if (!this->qXferThreadsRead()) {
|
||||||
m_killed = true;
|
m_killed = true;
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("Failed to read threads\n");
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
}
|
}
|
||||||
} else if (ParsePrefix(m_receive_packet, "libraries:read::")) {
|
} else if (ParsePrefix(m_receive_packet, "libraries:read::")) {
|
||||||
|
@ -2178,7 +2217,7 @@ namespace ams::dmnt {
|
||||||
} else if (ParsePrefix(m_receive_packet, "exec-file:read:")) {
|
} else if (ParsePrefix(m_receive_packet, "exec-file:read:")) {
|
||||||
AppendReplyFormat(m_reply_cur, m_reply_end, "l%s", m_debug_process.GetProcessName());
|
AppendReplyFormat(m_reply_cur, m_reply_end, "l%s", m_debug_process.GetProcessName());
|
||||||
} else {
|
} else {
|
||||||
AMS_DMNT2_GDB_LOG_DEBUG("Not Implemented qxfer: %s\n", m_receive_packet);
|
AMS_DMNT2_GDB_LOG_ERROR("Not Implemented qxfer: %s\n", m_receive_packet);
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2229,7 +2268,7 @@ namespace ams::dmnt {
|
||||||
m_reply_cur[length] = 0;
|
m_reply_cur[length] = 0;
|
||||||
m_reply_cur += std::strlen(m_reply_cur);
|
m_reply_cur += std::strlen(m_reply_cur);
|
||||||
} else {
|
} else {
|
||||||
AMS_DMNT2_GDB_LOG_DEBUG("Not Implemented qxfer:features:read: %s\n", m_receive_packet);
|
AMS_DMNT2_GDB_LOG_ERROR("Not Implemented qXfer:features:read: %s\n", m_receive_packet);
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2330,7 +2369,7 @@ namespace ams::dmnt {
|
||||||
/* Copy out the process list. */
|
/* Copy out the process list. */
|
||||||
GetAnnexBufferContents(m_reply_cur, offset, length);
|
GetAnnexBufferContents(m_reply_cur, offset, length);
|
||||||
} else {
|
} else {
|
||||||
AMS_DMNT2_GDB_LOG_DEBUG("Not Implemented qxfer:osdata:read: %s\n", m_receive_packet);
|
AMS_DMNT2_GDB_LOG_ERROR("Not Implemented qXfer:osdata:read: %s\n", m_receive_packet);
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2426,6 +2465,7 @@ namespace ams::dmnt {
|
||||||
|
|
||||||
/* Decode the type. */
|
/* Decode the type. */
|
||||||
if (!('0' <= m_receive_packet[0] && m_receive_packet[0] <= '4') || m_receive_packet[1] != ',') {
|
if (!('0' <= m_receive_packet[0] && m_receive_packet[0] <= '4') || m_receive_packet[1] != ',') {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("'Z' command formatted incorrectly (not starting with pattern '[0-4],'): %s\n", m_receive_packet);
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2436,6 +2476,7 @@ namespace ams::dmnt {
|
||||||
/* Decode the address/length. */
|
/* Decode the address/length. */
|
||||||
const char *comma = std::strchr(m_receive_packet, ',');
|
const char *comma = std::strchr(m_receive_packet, ',');
|
||||||
if (comma == nullptr) {
|
if (comma == nullptr) {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("'Z' command formatted incorrectly (no ','): %s\n", m_receive_packet);
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2450,6 +2491,7 @@ namespace ams::dmnt {
|
||||||
if (R_SUCCEEDED(m_debug_process.ClearBreakPoint(address, length))) {
|
if (R_SUCCEEDED(m_debug_process.ClearBreakPoint(address, length))) {
|
||||||
AppendReplyOk(m_reply_cur, m_reply_end);
|
AppendReplyOk(m_reply_cur, m_reply_end);
|
||||||
} else {
|
} else {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("Failed to clear software breakpoint\n");
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2459,6 +2501,7 @@ namespace ams::dmnt {
|
||||||
if (R_SUCCEEDED(m_debug_process.ClearHardwareBreakPoint(address, length))) {
|
if (R_SUCCEEDED(m_debug_process.ClearHardwareBreakPoint(address, length))) {
|
||||||
AppendReplyOk(m_reply_cur, m_reply_end);
|
AppendReplyOk(m_reply_cur, m_reply_end);
|
||||||
} else {
|
} else {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("Failed to clear hardware breakpoint\n");
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2470,6 +2513,7 @@ namespace ams::dmnt {
|
||||||
if (R_SUCCEEDED(m_debug_process.ClearWatchPoint(address, length))) {
|
if (R_SUCCEEDED(m_debug_process.ClearWatchPoint(address, length))) {
|
||||||
AppendReplyOk(m_reply_cur, m_reply_end);
|
AppendReplyOk(m_reply_cur, m_reply_end);
|
||||||
} else {
|
} else {
|
||||||
|
AMS_DMNT2_GDB_LOG_ERROR("Failed to clear watchpoint\n");
|
||||||
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
AppendReplyError(m_reply_cur, m_reply_end, "E01");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue