Skip to content

Commit

Permalink
Merge pull request #19635 from hrydgard/more-debugger-stuff
Browse files Browse the repository at this point in the history
ImDebugger: Add some new minor things
  • Loading branch information
hrydgard authored Nov 15, 2024
2 parents 6c64608 + 2eaffcf commit b9ef2f6
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 64 deletions.
1 change: 1 addition & 0 deletions Core/HLE/AtracCtx.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ class Atrac : public AtracBase {
}

u8 *BufferStart();

void DoState(PointerWrap &p) override;
void WriteContextToPSPMem() override;

Expand Down
14 changes: 10 additions & 4 deletions Core/HLE/HLE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,20 @@ void HLEShutdown() {
mipsCallActions.clear();
}

void RegisterModule(const char *name, int numFunctions, const HLEFunction *funcTable)
{
int GetNumRegisteredModules() {
return (int)moduleDB.size();
}

void RegisterModule(const char *name, int numFunctions, const HLEFunction *funcTable) {
HLEModule module = {name, numFunctions, funcTable};
moduleDB.push_back(module);
}

int GetModuleIndex(const char *moduleName)
{
const HLEModule *GetModuleByIndex(int index) {
return &moduleDB[index];
}

int GetModuleIndex(const char *moduleName) {
for (size_t i = 0; i < moduleDB.size(); i++)
if (strcmp(moduleName, moduleDB[i].name) == 0)
return (int)i;
Expand Down
11 changes: 5 additions & 6 deletions Core/HLE/HLE.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ enum {
HLE_KERNEL_SYSCALL = 1 << 11,
};

struct HLEFunction
{
struct HLEFunction {
// This is the id, or nid, of the function (which is how it's linked.)
// Generally, the truncated least significant 32 bits of a SHA-1 hash.
u32 ID;
Expand All @@ -72,17 +71,15 @@ struct HLEFunction
u32 stackBytesToClear;
};

struct HLEModule
{
struct HLEModule {
const char *name;
int numFunctions;
const HLEFunction *funcTable;
};

typedef char SyscallModuleName[32];

struct Syscall
{
struct Syscall {
SyscallModuleName moduleName;
u32 symAddr;
u32 nid;
Expand All @@ -102,6 +99,8 @@ int GetFuncIndex(int moduleIndex, u32 nib);
int GetModuleIndex(const char *modulename);

void RegisterModule(const char *name, int numFunctions, const HLEFunction *funcTable);
int GetNumRegisteredModules();
const HLEModule *GetModuleByIndex(int index);

// Run the current thread's callbacks after the syscall finishes.
void hleCheckCurrentCallbacks();
Expand Down
9 changes: 8 additions & 1 deletion Core/HLE/sceAtrac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,20 @@

static const int atracDecodeDelay = 2300;

const int PSP_NUM_ATRAC_IDS = 6;
static bool atracInited = true;
static AtracBase *atracContexts[PSP_NUM_ATRAC_IDS];
static u32 atracContextTypes[PSP_NUM_ATRAC_IDS];
static int atracLibVersion = 0;
static u32 atracLibCrc = 0;

// For debugger only.
const AtracBase *__AtracGetCtx(int i, u32 *type) {
if (type) {
*type = atracContextTypes[i];
}
return atracContexts[i];
}

void __AtracInit() {
_assert_(sizeof(SceAtracContext) == 256);

Expand Down
6 changes: 6 additions & 0 deletions Core/HLE/sceAtrac.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ struct SceAtracContext {
SceAtracIdInfo info;
};

const int PSP_NUM_ATRAC_IDS = 6;

class AtracBase;

const AtracBase *__AtracGetCtx(int i, u32 *type);

// External interface used by sceSas.
u32 AtracSasAddStreamData(int atracID, u32 bufPtr, u32 bytesToAdd);
u32 AtracSasDecodeData(int atracID, u8* outbuf, u32 outbufPtr, u32 *SamplesNum, u32* finish, int *remains);
Expand Down
10 changes: 8 additions & 2 deletions Core/MIPS/MIPSStackWalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.

#include "Common/Log.h"
#include "Core/MemMap.h"
#include "Core/Debugger/SymbolMap.h"
#include "Core/MIPS/MIPSCodeUtils.h"
Expand Down Expand Up @@ -112,6 +113,7 @@ namespace MIPSStackWalk {
stop = start - LONGEST_FUNCTION;
}
for (u32 pc = start; Memory::IsValidAddress(pc) && pc >= stop; pc -= 4) {
_dbg_assert_(Memory::IsValidAddress(pc));
MIPSOpcode op = Memory::Read_Instruction(pc, true);

// Here's where they store the ra address.
Expand Down Expand Up @@ -161,7 +163,7 @@ namespace MIPSStackWalk {
}
}

std::vector<StackFrame> Walk(u32 pc, u32 ra, u32 sp, u32 threadEntry, u32 threadStackTop) {
std::vector<StackFrame> Walk(const u32 pc, u32 ra, u32 sp, const u32 threadEntry, u32 threadStackTop) {
std::vector<StackFrame> frames;

if (!Memory::IsValidAddress(pc) || !Memory::IsValidAddress(sp) || !Memory::IsValidAddress(ra)) {
Expand All @@ -175,7 +177,11 @@ namespace MIPSStackWalk {
current.stackSize = -1;

u32 prevEntry = INVALIDTARGET;
while (pc != threadEntry) {
while (current.pc != threadEntry) {
if (!Memory::IsValidAddress(current.pc)) {
break;
}

u32 possibleEntry = GuessEntry(current.pc);
if (DetermineFrameInfo(current, possibleEntry, threadEntry, ra)) {
frames.push_back(current);
Expand Down
8 changes: 4 additions & 4 deletions Core/MemMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ static bool Memory_TryBase(u32 flags) {
*view.out_ptr = (u8*)g_arena.CreateView(
position, view.size, base + view.virtual_address);
if (!*view.out_ptr) {
ERROR_LOG(Log::MemMap, "Failed at view %d", i);
goto bail;
DEBUG_LOG(Log::MemMap, "Failed at view %d", i);
}
#else
if (CanIgnoreView(view)) {
Expand All @@ -169,7 +169,7 @@ static bool Memory_TryBase(u32 flags) {
*view.out_ptr = (u8*)g_arena.CreateView(
position, view.size, base + (view.virtual_address & MEMVIEW32_MASK));
if (!*view.out_ptr) {
DEBUG_LOG(Log::MemMap, "Failed at view %d", i);
ERROR_LOG(Log::MemMap, "Failed at view %d", i);
goto bail;
}
}
Expand All @@ -185,11 +185,11 @@ static bool Memory_TryBase(u32 flags) {
if (views[i].size == 0)
continue;
SKIP(flags, views[i].flags);
if (*views[j].out_ptr) {
if (views[j].out_ptr && *views[j].out_ptr) {
if (!CanIgnoreView(views[j])) {
g_arena.ReleaseView(0, *views[j].out_ptr, views[j].size);
}
*views[j].out_ptr = NULL;
*views[j].out_ptr = nullptr;
}
}
return false;
Expand Down
Loading

0 comments on commit b9ef2f6

Please sign in to comment.