Skip to content

Commit 6da1046

Browse files
Debugger: Make reg names safer, stop using v000.
Better to use S000, etc. as that's more clear throughout.
1 parent 3a21941 commit 6da1046

14 files changed

+70
-82
lines changed

Core/Debugger/DebugInterface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class DebugInterface {
6161
virtual int GetNumCategories() {return 0;}
6262
virtual int GetNumRegsInCategory(int cat) {return 0;}
6363
virtual const char *GetCategoryName(int cat) {return 0;}
64-
virtual const char *GetRegName(int cat, int index) {return 0;}
64+
virtual std::string GetRegName(int cat, int index) { return ""; }
6565
virtual void PrintRegValue(int cat, int index, char *out, size_t outSize) {
6666
snprintf(out, outSize, "%08X", GetGPR32Value(index));
6767
}

Core/Debugger/DisassemblyManager.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -847,9 +847,9 @@ bool DisassemblyMacro::disassemble(u32 address, DisassemblyLineInfo &dest, bool
847847

848848
addressSymbol = g_symbolMap->GetLabelString(immediate);
849849
if (!addressSymbol.empty() && insertSymbols) {
850-
snprintf(buffer, sizeof(buffer), "%s,%s", cpuDebug->GetRegName(0, rt), addressSymbol.c_str());
850+
snprintf(buffer, sizeof(buffer), "%s,%s", cpuDebug->GetRegName(0, rt).c_str(), addressSymbol.c_str());
851851
} else {
852-
snprintf(buffer, sizeof(buffer), "%s,0x%08X", cpuDebug->GetRegName(0, rt), immediate);
852+
snprintf(buffer, sizeof(buffer), "%s,0x%08X", cpuDebug->GetRegName(0, rt).c_str(), immediate);
853853
}
854854

855855
dest.params = buffer;
@@ -862,9 +862,9 @@ bool DisassemblyMacro::disassemble(u32 address, DisassemblyLineInfo &dest, bool
862862

863863
addressSymbol = g_symbolMap->GetLabelString(immediate);
864864
if (!addressSymbol.empty() && insertSymbols) {
865-
snprintf(buffer, sizeof(buffer), "%s,%s", cpuDebug->GetRegName(0, rt), addressSymbol.c_str());
865+
snprintf(buffer, sizeof(buffer), "%s,%s", cpuDebug->GetRegName(0, rt).c_str(), addressSymbol.c_str());
866866
} else {
867-
snprintf(buffer, sizeof(buffer), "%s,0x%08X", cpuDebug->GetRegName(0, rt), immediate);
867+
snprintf(buffer, sizeof(buffer), "%s,0x%08X", cpuDebug->GetRegName(0, rt).c_str(), immediate);
868868
}
869869

870870
dest.params = buffer;

Core/MIPS/ARM/ArmRegCacheFPU.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ void ArmRegCacheFPU::QFlush(int quad) {
618618
}
619619

620620
if (qr[quad].isDirty && !qr[quad].isTemp) {
621-
INFO_LOG(JIT, "Flushing Q%i (%s)", quad, GetVectorNotation(qr[quad].mipsVec, qr[quad].sz));
621+
INFO_LOG(JIT, "Flushing Q%i (%s)", quad, GetVectorNotation(qr[quad].mipsVec, qr[quad].sz).c_str());
622622

623623
ARMReg q = QuadAsQ(quad);
624624
// Unlike reads, when writing to the register file we need to be careful to write the correct
@@ -881,7 +881,7 @@ ARMReg ArmRegCacheFPU::QMapReg(int vreg, VectorSize sz, int flags) {
881881
// We didn't find the extra register, but we got a list of regs to flush. Flush 'em.
882882
// Here we can check for opportunities to do a "transpose-flush" of row vectors, etc.
883883
if (!quadsToFlush.empty()) {
884-
INFO_LOG(JIT, "New mapping %s collided with %d quads, flushing them.", GetVectorNotation(vreg, sz), (int)quadsToFlush.size());
884+
INFO_LOG(JIT, "New mapping %s collided with %d quads, flushing them.", GetVectorNotation(vreg, sz).c_str(), (int)quadsToFlush.size());
885885
}
886886
for (size_t i = 0; i < quadsToFlush.size(); i++) {
887887
QFlush(quadsToFlush[i]);
@@ -973,7 +973,7 @@ ARMReg ArmRegCacheFPU::QMapReg(int vreg, VectorSize sz, int flags) {
973973
qr[quad].isDirty = (flags & MAP_DIRTY) != 0;
974974
qr[quad].spillLock = true;
975975

976-
INFO_LOG(JIT, "Mapped Q%i to vfpu %i (%s), sz=%i, dirty=%i", quad, vreg, GetVectorNotation(vreg, sz), (int)sz, qr[quad].isDirty);
976+
INFO_LOG(JIT, "Mapped Q%i to vfpu %i (%s), sz=%i, dirty=%i", quad, vreg, GetVectorNotation(vreg, sz).c_str(), (int)sz, qr[quad].isDirty);
977977
if (sz == V_Single || sz == V_Pair) {
978978
return D_0(QuadAsQ(quad));
979979
} else {

Core/MIPS/IR/IRInst.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ int IRWriter::AddConstantFloat(float value) {
208208
return AddConstant(val);
209209
}
210210

211-
const char *GetGPRName(int r) {
211+
static std::string GetGPRName(int r) {
212212
if (r < 32) {
213213
return currentDebugMIPS->GetRegName(0, r);
214214
}
@@ -259,7 +259,7 @@ void DisassembleParam(char *buf, int bufSize, u8 param, char type, u32 constant)
259259

260260
switch (type) {
261261
case 'G':
262-
snprintf(buf, bufSize, "%s", GetGPRName(param));
262+
snprintf(buf, bufSize, "%s", GetGPRName(param).c_str());
263263
break;
264264
case 'F':
265265
if (param >= 32) {

Core/MIPS/MIPSDebugInterface.cpp

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "Core/Debugger/SymbolMap.h"
2828
#include "Core/Debugger/DebugInterface.h"
2929
#include "Core/MIPS/MIPSDebugInterface.h"
30+
#include "Core/MIPS/MIPSVFPUUtils.h"
3031
#include "Core/HLE/sceKernelThread.h"
3132
#include "Core/MemMap.h"
3233
#include "Core/MIPS/MIPSTables.h"
@@ -60,12 +61,12 @@ class MipsExpressionFunctions: public IExpressionFunctions
6061
char reg[8];
6162
snprintf(reg, sizeof(reg), "r%d", i);
6263

63-
if (strcasecmp(str, reg) == 0 || strcasecmp(str, cpu->GetRegName(0, i)) == 0)
64+
if (strcasecmp(str, reg) == 0 || strcasecmp(str, cpu->GetRegName(0, i).c_str()) == 0)
6465
{
6566
referenceIndex = i;
6667
return true;
6768
}
68-
else if (strcasecmp(str, cpu->GetRegName(1, i)) == 0)
69+
else if (strcasecmp(str, cpu->GetRegName(1, i).c_str()) == 0)
6970
{
7071
referenceIndex = REF_INDEX_FPU | i;
7172
return true;
@@ -81,7 +82,7 @@ class MipsExpressionFunctions: public IExpressionFunctions
8182

8283
for (int i = 0; i < 128; i++)
8384
{
84-
if (strcasecmp(str, cpu->GetRegName(2, i)) == 0)
85+
if (strcasecmp(str, cpu->GetRegName(2, i).c_str()) == 0)
8586
{
8687
referenceIndex = REF_INDEX_VFPU | i;
8788
return true;
@@ -261,9 +262,7 @@ const char *MIPSDebugInterface::GetName()
261262
return ("R4");
262263
}
263264

264-
// NOT threadsafe.
265-
const char *MIPSDebugInterface::GetRegName(int cat, int index)
266-
{
265+
std::string MIPSDebugInterface::GetRegName(int cat, int index) {
267266
static const char *regName[32] = {
268267
"zero", "at", "v0", "v1",
269268
"a0", "a1", "a2", "a3",
@@ -274,23 +273,20 @@ const char *MIPSDebugInterface::GetRegName(int cat, int index)
274273
"t8", "t9", "k0", "k1",
275274
"gp", "sp", "fp", "ra"
276275
};
276+
static const char *fpRegName[32] = {
277+
"f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
278+
"f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
279+
"f16", "f16", "f18", "f19", "f20", "f21", "f22", "f23",
280+
"f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
281+
};
277282

278-
// really nasty hack so that this function can be called several times on one line of c++.
279-
static int access = 0;
280-
access++;
281-
access &= 3;
282-
static char temp[4][16];
283-
284-
if (cat == 0) {
283+
if (cat == 0 && (unsigned)index < sizeof(regName)) {
285284
return regName[index];
286-
} else if (cat == 1) {
287-
snprintf(temp[access], sizeof(temp[access]), "f%d", index);
288-
return temp[access];
285+
} else if (cat == 1 && (unsigned)index < sizeof(fpRegName)) {
286+
return fpRegName[index];
289287
} else if (cat == 2) {
290-
snprintf(temp[access], sizeof(temp[access]), "v%03x", index);
291-
return temp[access];
292-
} else {
293-
return "???";
288+
return GetVectorNotation(index, V_Single);
294289
}
290+
return "???";
295291
}
296292

Core/MIPS/MIPSDebugInterface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class MIPSDebugInterface : public DebugInterface
6262
static int r[3] = { 32, 32, 128 };
6363
return r[cat];
6464
}
65-
const char *GetRegName(int cat, int index) override;
65+
std::string GetRegName(int cat, int index) override;
6666

6767
void PrintRegValue(int cat, int index, char *out, size_t outSize) override {
6868
switch (cat) {

Core/MIPS/MIPSDis.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
#define _POS ((op>>6 ) & 0x1F)
3535
#define _SIZE ((op>>11) & 0x1F)
3636

37-
#define RN(i) currentDebugMIPS->GetRegName(0,i)
38-
#define FN(i) currentDebugMIPS->GetRegName(1,i)
39-
//#define VN(i) currentMIPS->GetRegName(2,i)
37+
#define RN(i) (currentDebugMIPS->GetRegName(0, i).c_str())
38+
#define FN(i) (currentDebugMIPS->GetRegName(1, i).c_str())
39+
//#define VN(i) (currentDebugMIPS->GetRegName(2, i).c_str())
4040

4141
namespace MIPSDis
4242
{

Core/MIPS/MIPSDisVFPU.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
#define _SIZE ((op>>11) & 0x1F)
3535

3636

37-
#define RN(i) currentDebugMIPS->GetRegName(0,i)
38-
#define FN(i) currentDebugMIPS->GetRegName(1,i)
39-
//#define VN(i) currentDebugMIPS->GetRegName(2,i)
37+
#define RN(i) (currentDebugMIPS->GetRegName(0, i).c_str())
38+
#define FN(i) (currentDebugMIPS->GetRegName(1, i).c_str())
39+
//#define VN(i) (currentDebugMIPS->GetRegName(2, i).c_str())
4040

4141

4242
#define S_not(a,b,c) (a<<2)|(b)|(c<<5)
@@ -48,8 +48,7 @@
4848
#define VertOff 1
4949
#define MtxOff 4
5050

51-
inline const char *VN(int v, VectorSize size)
52-
{
51+
inline std::string VNStr(int v, VectorSize size) {
5352
static const char *vfpuCtrlNames[VFPU_CTRL_MAX] = {
5453
"SPFX",
5554
"TPFX",
@@ -77,11 +76,13 @@ inline const char *VN(int v, VectorSize size)
7776
return GetVectorNotation(v, size);
7877
}
7978

80-
inline const char *MN(int v, MatrixSize size)
81-
{
79+
inline std::string MNStr(int v, MatrixSize size) {
8280
return GetMatrixNotation(v, size);
8381
}
8482

83+
#define VN(v, s) (VNStr(v, s).c_str())
84+
#define MN(v, s) (MNStr(v, s).c_str())
85+
8586
inline const char *VSuff(MIPSOpcode op)
8687
{
8788
int a = (op>>7)&1;

Core/MIPS/MIPSVFPUUtils.cpp

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "Common/BitScan.h"
2424
#include "Common/CommonFuncs.h"
2525
#include "Common/File/VFS/VFS.h"
26+
#include "Common/StringUtils.h"
2627
#include "Core/Reporting.h"
2728
#include "Core/MIPS/MIPS.h"
2829
#include "Core/MIPS/MIPSVFPUUtils.h"
@@ -538,11 +539,7 @@ MatrixOverlapType GetMatrixOverlap(int mtx1, int mtx2, MatrixSize msize) {
538539
return OVERLAP_NONE;
539540
}
540541

541-
const char *GetVectorNotation(int reg, VectorSize size)
542-
{
543-
static char temp[4][16];
544-
static int yo = 0; yo++; yo &= 3;
545-
542+
std::string GetVectorNotation(int reg, VectorSize size) {
546543
int mtx = (reg>>2)&7;
547544
int col = reg&3;
548545
int row = 0;
@@ -557,34 +554,27 @@ const char *GetVectorNotation(int reg, VectorSize size)
557554
}
558555
if (transpose && c == 'C') c='R';
559556
if (transpose)
560-
snprintf(temp[yo], sizeof(temp[yo]), "%c%i%i%i",c,mtx,row,col);
561-
else
562-
snprintf(temp[yo], sizeof(temp[yo]), "%c%i%i%i",c,mtx,col,row);
563-
return temp[yo];
557+
return StringFromFormat("%c%i%i%i", c, mtx, row, col);
558+
return StringFromFormat("%c%i%i%i", c, mtx, col, row);
564559
}
565560

566-
const char *GetMatrixNotation(int reg, MatrixSize size)
567-
{
568-
static char temp[4][16];
569-
static int yo=0;yo++;yo&=3;
570-
int mtx = (reg>>2)&7;
571-
int col = reg&3;
572-
int row = 0;
573-
int transpose = (reg>>5)&1;
574-
char c;
575-
switch (size)
576-
{
577-
case M_2x2: c='M'; row=(reg>>5)&2; break;
578-
case M_3x3: c='M'; row=(reg>>6)&1; break;
579-
case M_4x4: c='M'; row=(reg>>5)&2; break;
580-
default: c='?'; break;
581-
}
582-
if (transpose && c=='M') c='E';
583-
if (transpose)
584-
snprintf(temp[yo], sizeof(temp[yo]), "%c%i%i%i",c,mtx,row,col);
585-
else
586-
snprintf(temp[yo], sizeof(temp[yo]), "%c%i%i%i",c,mtx,col,row);
587-
return temp[yo];
561+
std::string GetMatrixNotation(int reg, MatrixSize size) {
562+
int mtx = (reg>>2)&7;
563+
int col = reg&3;
564+
int row = 0;
565+
int transpose = (reg>>5)&1;
566+
char c;
567+
switch (size)
568+
{
569+
case M_2x2: c='M'; row=(reg>>5)&2; break;
570+
case M_3x3: c='M'; row=(reg>>6)&1; break;
571+
case M_4x4: c='M'; row=(reg>>5)&2; break;
572+
default: c='?'; break;
573+
}
574+
if (transpose && c=='M') c='E';
575+
if (transpose)
576+
return StringFromFormat("%c%i%i%i", c, mtx, row, col);
577+
return StringFromFormat("%c%i%i%i", c, mtx, col, row);
588578
}
589579

590580
bool GetVFPUCtrlMask(int reg, u32 *mask) {

Core/MIPS/MIPSVFPUUtils.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
1717

1818
#pragma once
19-
#include <cmath>
2019

20+
#include <cmath>
21+
#include <string>
2122
#include "Common/CommonTypes.h"
2223
#include "Core/MIPS/MIPS.h"
2324

@@ -216,8 +217,8 @@ VectorSize MatrixVectorSize(MatrixSize sz);
216217
int GetNumVectorElements(VectorSize sz);
217218
int GetMatrixSideSafe(MatrixSize sz);
218219
int GetMatrixSide(MatrixSize sz);
219-
const char *GetVectorNotation(int reg, VectorSize size);
220-
const char *GetMatrixNotation(int reg, MatrixSize size);
220+
std::string GetVectorNotation(int reg, VectorSize size);
221+
std::string GetMatrixNotation(int reg, MatrixSize size);
221222
inline bool IsMatrixTransposed(int matrixReg) {
222223
return (matrixReg >> 5) & 1;
223224
}

Windows/Debugger/CtrlDisAsmView.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ void CtrlDisAsmView::assembleOpcode(u32 address, std::string defaultText)
302302
{
303303
for (int reg = 0; reg < debugger->GetNumRegsInCategory(cat); reg++)
304304
{
305-
if (strcasecmp(debugger->GetRegName(cat,reg),registerName.c_str()) == 0)
305+
if (strcasecmp(debugger->GetRegName(cat,reg).c_str(), registerName.c_str()) == 0)
306306
{
307307
debugger->SetRegValue(cat,reg,value);
308308
Reporting::NotifyDebugger();

Windows/Debugger/CtrlRegisterList.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ void CtrlRegisterList::onPaint(WPARAM wParam, LPARAM lParam)
251251
if (i<cpu->GetNumRegsInCategory(category))
252252
{
253253
char temp[256];
254-
int temp_len = snprintf(temp, sizeof(temp), "%s", cpu->GetRegName(category, i));
254+
int temp_len = snprintf(temp, sizeof(temp), "%s", cpu->GetRegName(category, i).c_str());
255255
SetTextColor(hdc,0x600000);
256256
TextOutA(hdc,17,rowY1,temp,temp_len);
257257
SetTextColor(hdc,0x000000);

unittest/TestArmEmitter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ bool TestArmEmitter() {
243243
int R001 = GetRowName(0, M_4x4, 1, 0);
244244
int R002 = GetRowName(0, M_4x4, 2, 0);
245245
int R003 = GetRowName(0, M_4x4, 3, 0);
246-
printf("Col 010: %s\n", GetVectorNotation(C010, V_Quad));
247-
printf("Row 003: %s\n", GetVectorNotation(R003, V_Quad));
246+
printf("Col 010: %s\n", GetVectorNotation(C010, V_Quad).c_str());
247+
printf("Row 003: %s\n", GetVectorNotation(R003, V_Quad).c_str());
248248

249249
MIPSAnalyst::AnalysisResults results;
250250
memset(&results, 0, sizeof(results));

unittest/UnitTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ bool TestMatrixTranspose() {
431431
}
432432

433433
void TestGetMatrix(int matrix, MatrixSize sz) {
434-
INFO_LOG(SYSTEM, "Testing matrix %s", GetMatrixNotation(matrix, sz));
434+
INFO_LOG(SYSTEM, "Testing matrix %s", GetMatrixNotation(matrix, sz).c_str());
435435
u8 fullMatrix[16];
436436

437437
u8 cols[4];
@@ -449,8 +449,8 @@ void TestGetMatrix(int matrix, MatrixSize sz) {
449449
// int rowName = GetRowName(matrix, sz, i, 0);
450450
int colName = cols[i];
451451
int rowName = rows[i];
452-
INFO_LOG(SYSTEM, "Column %i: %s", i, GetVectorNotation(colName, vsz));
453-
INFO_LOG(SYSTEM, "Row %i: %s", i, GetVectorNotation(rowName, vsz));
452+
INFO_LOG(SYSTEM, "Column %i: %s", i, GetVectorNotation(colName, vsz).c_str());
453+
INFO_LOG(SYSTEM, "Row %i: %s", i, GetVectorNotation(rowName, vsz).c_str());
454454

455455
u8 colRegs[4];
456456
u8 rowRegs[4];

0 commit comments

Comments
 (0)