Skip to content

Commit ae29435

Browse files
committed
jgadget debug improvements
1 parent 229527d commit ae29435

37 files changed

+1016
-87
lines changed

include/JSystem/JGadget/binary.h

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
#ifndef BINARY_H
2-
#define BINARY_H
1+
#ifndef JGADGET_BINARY_H
2+
#define JGADGET_BINARY_H
33

44
#include "JSystem/JUtility/JUTAssert.h"
5-
#include "dolphin/types.h"
65
#include "JSystem/JGadget/search.h"
76

87
namespace JGadget {
@@ -12,8 +11,7 @@ struct TEBit {
1211
u32 value;
1312
};
1413

15-
const void* parseVariableUInt_16_32_following(const void* pu16, u32* pu32First, u32* pu32Second,
16-
TEBit* tebit);
14+
const void* parseVariableUInt_16_32_following(const void* pu16, u32* pu32First, u32* pu32Second, TEBit* tebit);
1715

1816
inline bool isPower2(unsigned int arg0) {
1917
return arg0 != 0 && (arg0 & arg0 - 1) == 0;
@@ -57,14 +55,6 @@ struct TParse_header_block {
5755
bool parse(const void* ppData_inout, u32 a2) {
5856
return parse_next(&ppData_inout, a2);
5957
}
60-
61-
bool checkNext(const void** ptrLocation, u32* headerEnd, u32 idx) {
62-
bool checkNext = false;
63-
if (parseHeader_next(ptrLocation, headerEnd, idx)) {
64-
checkNext = true;
65-
}
66-
return checkNext;
67-
}
6858
};
6959

7060
template <typename T>
@@ -194,4 +184,4 @@ struct TValueIterator_misaligned : public TValueIterator<TParseValue_misaligned<
194184
} // namespace binary
195185
} // namespace JGadget
196186

197-
#endif /* BINARY_H */
187+
#endif /* JGADGET_BINARY_H */

include/JSystem/JGadget/define.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#ifndef DEFINE_H
2-
#define DEFINE_H
1+
#ifndef JGADGET_DEFINE_H
2+
#define JGADGET_DEFINE_H
33

4-
#include "types.h"
4+
#include <dolphin/types.h>
55

66
#ifdef __cplusplus
77
extern "C" {
@@ -25,11 +25,13 @@ class JGadget_outMessage {
2525
JGadget_outMessage& operator<<(u32);
2626
JGadget_outMessage& operator<<(const void*);
2727

28+
static const int BUFFER_SIZE = 256;
29+
2830
private:
2931
MessageFunc mMsgFunc;
30-
char mBuffer[256];
32+
char mBuffer[BUFFER_SIZE];
3133
char* mWrite_p;
32-
char* mFile;
34+
const char* mFile;
3335
int mLine;
3436
};
3537

include/JSystem/JGadget/search.h

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
#ifndef SEARCH_H
2-
#define SEARCH_H
1+
#ifndef JGADGET_SEARCH_H
2+
#define JGADGET_SEARCH_H
33

4-
#include "dolphin/os.h"
4+
#include <dolphin/types.h>
55
#include <iterator.h>
66
#include <functional.h>
77
#include <algorithm.h>
88

99
namespace JGadget {
10-
1110
namespace search {
12-
1311
template <typename T>
1412
struct TExpandStride_ {};
1513

@@ -18,11 +16,29 @@ struct TExpandStride_<s32> {
1816
static s32 get(s32 n) { return n << 3; }
1917
};
2018

19+
struct TPR1IsEqual_string_ {
20+
TPR1IsEqual_string_(const char* sz) {
21+
string_ = sz;
22+
}
23+
24+
bool operator()(const char* sz) const {
25+
bool ret;
26+
if (string_ == NULL) {
27+
ret = sz == NULL;
28+
} else {
29+
ret = sz != NULL && strcmp(string_, sz) == 0;
30+
}
31+
return ret;
32+
}
33+
34+
const char* string_;
35+
};
36+
2137
} // namespace search
2238

23-
//! @todo: mangled name isn't correct, fix this
24-
//! Current: toValueFromIndex<PFdd_d>__7JGadgetFiPCPFdd_dUlRCPFdd_d
25-
//! Target: toValueFromIndex<PFdd_d>__7JGadgetFiPCPFdd_dUlRCPFdd_d_RCPFdd_d
39+
const char* toStringFromIndex(int index, const char* const* pValue, u32 count, const char* fallback);
40+
int toIndexFromString_linear(const char*, const char* const*, u32, int);
41+
2642
template <typename T>
2743
inline const T& toValueFromIndex(int idx, const T* pValue, u32 count, const T& fallback) {
2844
JUT_ASSERT(200, pValue!=NULL);
@@ -34,6 +50,21 @@ inline const T& toValueFromIndex(int idx, const T* pValue, u32 count, const T& f
3450
}
3551
}
3652

53+
template <typename T, typename Predicate>
54+
inline int toIndexFromValue_linear_if(Predicate p, const T* pValue, u32 count, int fallback) {
55+
JUT_ASSERT(212, pValue!=NULL);
56+
57+
const T* first = pValue;
58+
const T* last = pValue + count;
59+
const T* found = std::find_if(first, last, p);
60+
61+
if (found == last) {
62+
return fallback;
63+
}
64+
65+
return std::distance(first, found);
66+
}
67+
3768
template <typename Category, typename T, typename Distance, typename Pointer, typename Reference>
3869
struct TIterator : public std::iterator<Category, T, Distance, Pointer, Reference> {
3970
};
@@ -130,4 +161,4 @@ inline Iterator findUpperBound_binary_current(Iterator first, Iterator last, Ite
130161

131162
} // namespace JGadget
132163

133-
#endif /* SEARCH_H */
164+
#endif /* JGADGET_SEARCH_H */
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
#ifndef JGADGET_STD_STREAM_H
2+
#define JGADGET_STD_STREAM_H
3+
4+
#include "JSystem/JGadget/std-streambuf.h"
5+
#include "global.h"
6+
7+
namespace JGadget {
8+
class TStream_base {
9+
public:
10+
TStream_base() {}
11+
virtual ~TStream_base() = 0;
12+
13+
void setf(u32);
14+
void setf(u32, u32);
15+
void width(s32);
16+
17+
s32 precision() const {
18+
return precision_;
19+
}
20+
21+
s32 width() const {
22+
return width_;
23+
}
24+
25+
u32 flags() const {
26+
return flags_;
27+
}
28+
29+
void Init_() {
30+
flags_ = skipws|dec;
31+
width_ = 0;
32+
precision_ = 6;
33+
}
34+
35+
static const u32 skipws = 0x400000;
36+
static const u32 dec = 0x1;
37+
38+
private:
39+
/* 0x4 */ u32 flags_;
40+
/* 0x8 */ s32 width_;
41+
/* 0xC */ s32 precision_;
42+
};
43+
44+
class TStream : public TStream_base {
45+
public:
46+
TStream();
47+
virtual ~TStream() = 0;
48+
49+
void init(TStreamBuffer* psb);
50+
bool fail() const;
51+
bool good() const;
52+
void setstate(u8 state);
53+
void clear(u8 state);
54+
TStreamBuffer* rdbuf() const;
55+
void fill(char);
56+
static char widen(char);
57+
static char narrow(char, char);
58+
59+
char fill() const {
60+
return fill_;
61+
}
62+
63+
private:
64+
/* 0x10 */ u8 state_;
65+
/* 0x14 */ TStreamBuffer* rdbuf_;
66+
/* 0x18 */ char fill_;
67+
};
68+
69+
class TInputStream {
70+
public:
71+
struct sentry {
72+
sentry(TInputStream& stream, bool);
73+
74+
operator bool() const { return _0x0; }
75+
76+
/* 0x0 */ bool _0x0;
77+
};
78+
79+
int get();
80+
81+
TStream* _0x0;
82+
virtual ~TInputStream();
83+
84+
private:
85+
/* 0x08 */ int field_0x8;
86+
};
87+
88+
class TOutputStream {
89+
public:
90+
struct sentry {
91+
sentry(TOutputStream& stream) {
92+
_0x0 = &stream;
93+
94+
_0x4 = stream._0x0->good();
95+
if (!_0x4) {
96+
stream._0x0->setstate(2);
97+
}
98+
}
99+
100+
~sentry() {
101+
if (!_0x0->_0x0->fail() && (_0x0->_0x0->flags() & 2)) {
102+
_0x0->flush();
103+
}
104+
}
105+
106+
operator bool() const { return _0x4; }
107+
108+
/* 0x0 */ TOutputStream* _0x0;
109+
/* 0x4 */ bool _0x4;
110+
};
111+
112+
struct TBufferIterator {
113+
TBufferIterator(TStreamBuffer* psb) {
114+
buffer_ = psb;
115+
}
116+
117+
void operator=(char param_0) {
118+
if (buffer_ != NULL && TTrait_char<char>::eq_int_type(buffer_->sputc(param_0), TTrait_char<char>::eof())) {
119+
buffer_ = NULL;
120+
}
121+
}
122+
123+
TBufferIterator& operator*() {
124+
return *this;
125+
}
126+
127+
void operator++() {}
128+
129+
bool failed() const { return buffer_ == NULL; }
130+
131+
TStreamBuffer* buffer_;
132+
};
133+
134+
TOutputStream& operator<<(const char*);
135+
TOutputStream& operator<<(char);
136+
TOutputStream& operator<<(s32);
137+
TOutputStream& operator<<(u32);
138+
TOutputStream& operator<<(bool);
139+
TOutputStream& operator<<(double);
140+
141+
void flush();
142+
TBufferIterator& Put_CString_prefixed_(const char*, u32, const char*, u32);
143+
TBufferIterator& Put_longInt_(u32, bool);
144+
TBufferIterator& Put(double);
145+
146+
TBufferIterator& Put(const char* param_0, u32 param_1) {
147+
return Put_CString_prefixed_(param_0, param_1, NULL, 0);
148+
}
149+
150+
TBufferIterator& Put(s32 param_0) {
151+
return Put_longInt_(param_0, true);
152+
}
153+
154+
TBufferIterator& Put(u32 param_0) {
155+
return Put_longInt_(param_0, false);
156+
}
157+
158+
TBufferIterator& Put(bool param_0) {
159+
u32 flags = _0x0->flags();
160+
const TCString_* s = &saaosz_bool_[!(flags & 8) ? 0 : 1][param_0 ? 1 : 0];
161+
return Put_CString_prefixed_(s->sz, s->len, NULL, 0);
162+
}
163+
164+
TStream* _0x0;
165+
virtual ~TOutputStream();
166+
167+
struct TCString_ {
168+
const char* sz;
169+
u32 len;
170+
};
171+
172+
struct saoCaseNumeral_struct {
173+
const char _0[16];
174+
TCString_ _1; // 0x10
175+
TCString_ _2; // 0x18
176+
TCString_ _3; // 0x20
177+
};
178+
179+
static const saoCaseNumeral_struct saoCaseNumeral_[2];
180+
static const TCString_ saoszPrefix_sign_[3];
181+
static const TCString_ saaosz_bool_[2][2];
182+
static const TCString_ soszPrefix_oct_;
183+
184+
static const saoCaseNumeral_struct& getCaseNumeral_(u32 flags) {
185+
return saoCaseNumeral_[!(flags & 4) ? 0 : 1];
186+
}
187+
188+
private:
189+
/* 0x08 */ int field_0x8;
190+
};
191+
192+
}
193+
194+
#endif /* JGADGET_STD_STREAM_H */

0 commit comments

Comments
 (0)