Use <string.h> & <3ds/exheader.h>, fix some bugs, etc.

also fix all warnings and use -Werror
This commit is contained in:
TuxSH
2018-05-24 00:55:38 +02:00
parent e6b7dc1dc5
commit d28e961adc
85 changed files with 276 additions and 643 deletions

View File

@@ -163,7 +163,7 @@ static int GDB_ParseCommonThreadInfo(char *out, GDBContext *ctx, int sig)
s64 dummy;
u32 core;
Result r = svcGetDebugThreadContext(&regs, ctx->debug, threadId, THREADCONTEXT_CONTROL_ALL);
int n = sprintf(out, "T%02xthread:%x;", sig, threadId);
int n = sprintf(out, "T%02xthread:%lx;", sig, threadId);
if(R_FAILED(r))
return n;
@@ -171,12 +171,12 @@ static int GDB_ParseCommonThreadInfo(char *out, GDBContext *ctx, int sig)
r = svcGetDebugThreadParam(&dummy, &core, ctx->debug, ctx->currentThreadId, DBGTHREAD_PARAMETER_CPU_CREATOR); // Creator = "first ran, and running the thread"
if(R_SUCCEEDED(r))
n += sprintf(out + n, "core:%x;", core);
n += sprintf(out + n, "core:%lx;", core);
for(u32 i = 0; i <= 12; i++)
n += sprintf(out + n, "%x:%08x;", i, __builtin_bswap32(regs.cpu_registers.r[i]));
n += sprintf(out + n, "%lx:%08lx;", i, __builtin_bswap32(regs.cpu_registers.r[i]));
n += sprintf(out + n, "d:%08x;e:%08x;f:%08x;19:%08x;",
n += sprintf(out + n, "d:%08lx;e:%08lx;f:%08lx;19:%08lx;",
__builtin_bswap32(regs.cpu_registers.sp), __builtin_bswap32(regs.cpu_registers.lr), __builtin_bswap32(regs.cpu_registers.pc),
__builtin_bswap32(regs.cpu_registers.cpsr));
@@ -184,10 +184,10 @@ static int GDB_ParseCommonThreadInfo(char *out, GDBContext *ctx, int sig)
{
u64 val;
memcpy(&val, &regs.fpu_registers.d[i], 8);
n += sprintf(out + n, "%x:%016llx;", 26 + i, __builtin_bswap64(val));
n += sprintf(out + n, "%lx:%016llx;", 26 + i, __builtin_bswap64(val));
}
n += sprintf(out + n, "2a:%08x;2b:%08x;", __builtin_bswap32(regs.fpu_registers.fpscr), __builtin_bswap32(regs.fpu_registers.fpexc));
n += sprintf(out + n, "2a:%08lx;2b:%08lx;", __builtin_bswap32(regs.fpu_registers.fpscr), __builtin_bswap32(regs.fpu_registers.fpexc));
return n;
}
@@ -301,7 +301,7 @@ int GDB_SendStopReply(GDBContext *ctx, const DebugEventInfo *info)
{
// no signal, SIGTERM, SIGQUIT (process exited), SIGTERM (process terminated)
static int threadExitRepliesSigs[] = { 0, SIGTERM, SIGQUIT, SIGTERM };
return GDB_SendFormattedPacket(ctx, "w%02x;%x", threadExitRepliesSigs[(u32)info->exit_thread.reason], info->thread_id);
return GDB_SendFormattedPacket(ctx, "w%02x;%lx", threadExitRepliesSigs[(u32)info->exit_thread.reason], info->thread_id);
}
break;
}
@@ -365,7 +365,7 @@ int GDB_SendStopReply(GDBContext *ctx, const DebugEventInfo *info)
GDB_SendDebugString(ctx, "Warning: unknown watchpoint encountered!\n");
GDB_ParseCommonThreadInfo(buffer, ctx, SIGTRAP);
return GDB_SendFormattedPacket(ctx, "%s%swatch:%08x;", buffer, kinds[(u32)kind], exc.stop_point.fault_information);
return GDB_SendFormattedPacket(ctx, "%s%swatch:%08lx;", buffer, kinds[(u32)kind], exc.stop_point.fault_information);
break;
}

View File

@@ -127,7 +127,7 @@ GDB_DECLARE_REMOTE_COMMAND_HANDLER(SyncRequestInfo)
if(R_FAILED(r))
name[0] = 0;
n = sprintf(outbuf, "%s 0x%x, 0x%08x\n", name, cmdId, ctx->threadInfos[id].tls + 0x80);
n = sprintf(outbuf, "%s 0x%lx, 0x%08lx\n", name, cmdId, ctx->threadInfos[id].tls + 0x80);
end:
svcCloseHandle(handle);
@@ -181,9 +181,9 @@ GDB_DECLARE_REMOTE_COMMAND_HANDLER(TranslateHandle)
svcControlService(SERVICEOP_GET_NAME, serviceBuf, handle);
refcount = (u32)(refcountRaw - 1);
if(serviceBuf[0] != 0)
n = sprintf(outbuf, "(%s *)0x%08x /* %s handle, %u %s */\n", classBuf, kernelAddr, serviceBuf, refcount, refcount == 1 ? "reference" : "references");
n = sprintf(outbuf, "(%s *)0x%08lx /* %s handle, %lu %s */\n", classBuf, kernelAddr, serviceBuf, refcount, refcount == 1 ? "reference" : "references");
else
n = sprintf(outbuf, "(%s *)0x%08x /* %u %s */\n", classBuf, kernelAddr, refcount, refcount == 1 ? "reference" : "references");
n = sprintf(outbuf, "(%s *)0x%08lx /* %lu %s */\n", classBuf, kernelAddr, refcount, refcount == 1 ? "reference" : "references");
end:
svcCloseHandle(handle);
@@ -210,16 +210,16 @@ GDB_DECLARE_REMOTE_COMMAND_HANDLER(GetMmuConfig)
s64 TTBCR, TTBR0;
svcGetSystemInfo(&TTBCR, 0x10002, 0);
svcGetProcessInfo(&TTBR0, process, 0x10008);
n = sprintf(outbuf, "TTBCR = %u\nTTBR0 = 0x%08x\nTTBR1 =", (u32)TTBCR, (u32)TTBR0);
n = sprintf(outbuf, "TTBCR = %lu\nTTBR0 = 0x%08lx\nTTBR1 =", (u32)TTBCR, (u32)TTBR0);
for(u32 i = 0; i < (isN3DS ? 4 : 2); i++)
{
s64 TTBR1;
svcGetSystemInfo(&TTBR1, 0x10002, 1 + i);
if(i == (isN3DS ? 3 : 1))
n += sprintf(outbuf + n, " 0x%08x\n", (u32)TTBR1);
n += sprintf(outbuf + n, " 0x%08lx\n", (u32)TTBR1);
else
n += sprintf(outbuf + n, " 0x%08x /", (u32)TTBR1);
n += sprintf(outbuf + n, " 0x%08lx /", (u32)TTBR1);
}
svcCloseHandle(process);
}
@@ -294,7 +294,7 @@ GDB_DECLARE_REMOTE_COMMAND_HANDLER(GetMemRegions)
const char *perm = FormatMemPerm(memi.perm);
const char *state = FormatMemState(memi.state);
posInBuffer += sprintf(outbuf + posInBuffer, "%08X - %08X %s %s\n",
posInBuffer += sprintf(outbuf + posInBuffer, "%08lx - %08lx %s %s\n",
memi.base_addr, address, perm, state);
}
}

View File

@@ -163,7 +163,7 @@ GDB_DECLARE_QUERY_HANDLER(CurrentThreadId)
if(ctx->currentThreadId == 0)
ctx->currentThreadId = GDB_GetCurrentThread(ctx);
return ctx->currentThreadId != 0 ? GDB_SendFormattedPacket(ctx, "QC%x", ctx->currentThreadId) : GDB_ReplyErrno(ctx, EPERM);
return ctx->currentThreadId != 0 ? GDB_SendFormattedPacket(ctx, "QC%lx", ctx->currentThreadId) : GDB_ReplyErrno(ctx, EPERM);
}
static void GDB_GenerateThreadListData(GDBContext *ctx)
@@ -187,7 +187,7 @@ static void GDB_GenerateThreadListData(GDBContext *ctx)
char *bufptr = ctx->threadListData;
for(u32 i = 0; i < nbAliveThreads; i++)
bufptr += sprintf(bufptr, i == (nbAliveThreads - 1) ? "%x" : "%x,", aliveThreadIds[i]);
bufptr += sprintf(bufptr, i == (nbAliveThreads - 1) ? "%lx" : "%lx,", aliveThreadIds[i]);
}
static int GDB_SendThreadData(GDBContext *ctx)
@@ -277,27 +277,27 @@ GDB_DECLARE_QUERY_HANDLER(ThreadExtraInfo)
if(val == 65)
sThreadDynamicPriority[0] = 0;
else
sprintf(sThreadDynamicPriority, "dynamic prio.: %d, ", (s32)val);
sprintf(sThreadDynamicPriority, "dynamic prio.: %ld, ", (s32)val);
r = svcGetDebugThreadParam(&dummy, &val, ctx->debug, id, DBGTHREAD_PARAMETER_PRIORITY);
if(R_FAILED(r))
sThreadStaticPriority[0] = 0;
else
sprintf(sThreadStaticPriority, "static prio.: %d, ", (s32)val);
sprintf(sThreadStaticPriority, "static prio.: %ld, ", (s32)val);
r = svcGetDebugThreadParam(&dummy, &val, ctx->debug, id, DBGTHREAD_PARAMETER_CPU_IDEAL);
if(R_FAILED(r))
sCoreIdeal[0] = 0;
else
sprintf(sCoreIdeal, "ideal core: %u, ", val);
sprintf(sCoreIdeal, "ideal core: %lu, ", val);
r = svcGetDebugThreadParam(&dummy, &val, ctx->debug, id, DBGTHREAD_PARAMETER_CPU_CREATOR); // Creator = "first ran, and running the thread"
if(R_FAILED(r))
sCoreCreator[0] = 0;
else
sprintf(sCoreCreator, "running on core %u", val);
sprintf(sCoreCreator, "running on core %lu", val);
n = sprintf(buf, "TLS: 0x%08x%s%s%s%s%s", tls, sStatus, sThreadDynamicPriority, sThreadStaticPriority,
n = sprintf(buf, "TLS: 0x%08lx%s%s%s%s%s", tls, sStatus, sThreadDynamicPriority, sThreadStaticPriority,
sCoreIdeal, sCoreCreator);
return GDB_SendHexPacket(ctx, buf, (u32)n);
@@ -324,5 +324,5 @@ GDB_DECLARE_QUERY_HANDLER(GetTLSAddr)
if(tls == 0)
return GDB_ReplyErrno(ctx, EINVAL);
return GDB_SendFormattedPacket(ctx, "%08x", tls + offset);
return GDB_SendFormattedPacket(ctx, "%08lx", tls + offset);
}

View File

@@ -87,9 +87,9 @@ GDB_DECLARE_XFER_OSDATA_HANDLER(CfwVersion)
isRelease = (bool)out;
if(GET_VERSION_REVISION(version) == 0)
sprintf(versionString, "v%u.%u", GET_VERSION_MAJOR(version), GET_VERSION_MINOR(version));
sprintf(versionString, "v%lu.%lu", GET_VERSION_MAJOR(version), GET_VERSION_MINOR(version));
else
sprintf(versionString, "v%u.%u.%u", GET_VERSION_MAJOR(version), GET_VERSION_MINOR(version), GET_VERSION_REVISION(version));
sprintf(versionString, "v%lu.%lu.%lu", GET_VERSION_MAJOR(version), GET_VERSION_MINOR(version), GET_VERSION_REVISION(version));
sz = (u32)sprintf(buf, (const char *)osdata_cfw_version_template_xml, versionString, commitHash, isRelease ? "Yes" : "No");
@@ -150,7 +150,7 @@ GDB_DECLARE_XFER_OSDATA_HANDLER(Processes)
static const char item[] =
" <item>\n"
" <column name=\"pid\">%u</column>\n"
" <column name=\"pid\">%lu</column>\n"
" <column name=\"command\">%s</column>\n"
" </item>\n";

View File

@@ -3,7 +3,7 @@
<osdata type="cfwversion">
<item>
<column name="Version">%s</column>
<column name="Commit hash">%08x</column>
<column name="Commit hash">%08lx</column>
<column name="Release">%s</column>
</item>
</osdata>