mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-07-05 11:33:39 -04:00
jgadget debug improvements (#3000)
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
#ifndef BINARY_H
|
||||
#define BINARY_H
|
||||
#ifndef JGADGET_BINARY_H
|
||||
#define JGADGET_BINARY_H
|
||||
|
||||
#include "JSystem/JUtility/JUTAssert.h"
|
||||
#include "dolphin/types.h"
|
||||
#include "JSystem/JGadget/search.h"
|
||||
|
||||
namespace JGadget {
|
||||
@@ -12,8 +11,7 @@ struct TEBit {
|
||||
u32 value;
|
||||
};
|
||||
|
||||
const void* parseVariableUInt_16_32_following(const void* pu16, u32* pu32First, u32* pu32Second,
|
||||
TEBit* tebit);
|
||||
const void* parseVariableUInt_16_32_following(const void* pu16, u32* pu32First, u32* pu32Second, TEBit* tebit);
|
||||
|
||||
inline bool isPower2(unsigned int arg0) {
|
||||
return arg0 != 0 && (arg0 & arg0 - 1) == 0;
|
||||
@@ -57,14 +55,6 @@ struct TParse_header_block {
|
||||
bool parse(const void* ppData_inout, u32 a2) {
|
||||
return parse_next(&ppData_inout, a2);
|
||||
}
|
||||
|
||||
bool checkNext(const void** ptrLocation, u32* headerEnd, u32 idx) {
|
||||
bool checkNext = false;
|
||||
if (parseHeader_next(ptrLocation, headerEnd, idx)) {
|
||||
checkNext = true;
|
||||
}
|
||||
return checkNext;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
@@ -194,4 +184,4 @@ struct TValueIterator_misaligned : public TValueIterator<TParseValue_misaligned<
|
||||
} // namespace binary
|
||||
} // namespace JGadget
|
||||
|
||||
#endif /* BINARY_H */
|
||||
#endif /* JGADGET_BINARY_H */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef DEFINE_H
|
||||
#define DEFINE_H
|
||||
#ifndef JGADGET_DEFINE_H
|
||||
#define JGADGET_DEFINE_H
|
||||
|
||||
#include "types.h"
|
||||
#include <dolphin/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -25,11 +25,13 @@ public:
|
||||
JGadget_outMessage& operator<<(u32);
|
||||
JGadget_outMessage& operator<<(const void*);
|
||||
|
||||
static const int BUFFER_SIZE = 256;
|
||||
|
||||
private:
|
||||
MessageFunc mMsgFunc;
|
||||
char mBuffer[256];
|
||||
char mBuffer[BUFFER_SIZE];
|
||||
char* mWrite_p;
|
||||
char* mFile;
|
||||
const char* mFile;
|
||||
int mLine;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
#ifndef SEARCH_H
|
||||
#define SEARCH_H
|
||||
#ifndef JGADGET_SEARCH_H
|
||||
#define JGADGET_SEARCH_H
|
||||
|
||||
#include "dolphin/os.h"
|
||||
#include <dolphin/types.h>
|
||||
#include <iterator.h>
|
||||
#include <functional.h>
|
||||
#include <algorithm.h>
|
||||
|
||||
namespace JGadget {
|
||||
|
||||
namespace search {
|
||||
|
||||
template <typename T>
|
||||
struct TExpandStride_ {};
|
||||
|
||||
@@ -18,11 +16,29 @@ struct TExpandStride_<s32> {
|
||||
static s32 get(s32 n) { return n << 3; }
|
||||
};
|
||||
|
||||
struct TPR1IsEqual_string_ {
|
||||
TPR1IsEqual_string_(const char* sz) {
|
||||
string_ = sz;
|
||||
}
|
||||
|
||||
bool operator()(const char* sz) const {
|
||||
bool ret;
|
||||
if (string_ == NULL) {
|
||||
ret = sz == NULL;
|
||||
} else {
|
||||
ret = sz != NULL && strcmp(string_, sz) == 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
const char* string_;
|
||||
};
|
||||
|
||||
} // namespace search
|
||||
|
||||
//! @todo: mangled name isn't correct, fix this
|
||||
//! Current: toValueFromIndex<PFdd_d>__7JGadgetFiPCPFdd_dUlRCPFdd_d
|
||||
//! Target: toValueFromIndex<PFdd_d>__7JGadgetFiPCPFdd_dUlRCPFdd_d_RCPFdd_d
|
||||
const char* toStringFromIndex(int index, const char* const* pValue, u32 count, const char* fallback);
|
||||
int toIndexFromString_linear(const char*, const char* const*, u32, int);
|
||||
|
||||
template <typename T>
|
||||
inline const T& toValueFromIndex(int idx, const T* pValue, u32 count, const T& fallback) {
|
||||
JUT_ASSERT(200, pValue!=NULL);
|
||||
@@ -34,6 +50,21 @@ inline const T& toValueFromIndex(int idx, const T* pValue, u32 count, const T& f
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename Predicate>
|
||||
inline int toIndexFromValue_linear_if(Predicate p, const T* pValue, u32 count, int fallback) {
|
||||
JUT_ASSERT(212, pValue!=NULL);
|
||||
|
||||
const T* first = pValue;
|
||||
const T* last = pValue + count;
|
||||
const T* found = std::find_if(first, last, p);
|
||||
|
||||
if (found == last) {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
return std::distance(first, found);
|
||||
}
|
||||
|
||||
template <typename Category, typename T, typename Distance, typename Pointer, typename Reference>
|
||||
struct TIterator : public std::iterator<Category, T, Distance, Pointer, Reference> {
|
||||
};
|
||||
@@ -130,4 +161,4 @@ inline Iterator findUpperBound_binary_current(Iterator first, Iterator last, Ite
|
||||
|
||||
} // namespace JGadget
|
||||
|
||||
#endif /* SEARCH_H */
|
||||
#endif /* JGADGET_SEARCH_H */
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
#ifndef JGADGET_STD_STREAM_H
|
||||
#define JGADGET_STD_STREAM_H
|
||||
|
||||
#include "JSystem/JGadget/std-streambuf.h"
|
||||
#include "global.h"
|
||||
|
||||
namespace JGadget {
|
||||
class TStream_base {
|
||||
public:
|
||||
TStream_base() {}
|
||||
virtual ~TStream_base() = 0;
|
||||
|
||||
void setf(u32);
|
||||
void setf(u32, u32);
|
||||
void width(s32);
|
||||
|
||||
s32 precision() const {
|
||||
return precision_;
|
||||
}
|
||||
|
||||
s32 width() const {
|
||||
return width_;
|
||||
}
|
||||
|
||||
u32 flags() const {
|
||||
return flags_;
|
||||
}
|
||||
|
||||
void Init_() {
|
||||
flags_ = skipws|dec;
|
||||
width_ = 0;
|
||||
precision_ = 6;
|
||||
}
|
||||
|
||||
static const u32 skipws = 0x400000;
|
||||
static const u32 dec = 0x1;
|
||||
|
||||
private:
|
||||
/* 0x4 */ u32 flags_;
|
||||
/* 0x8 */ s32 width_;
|
||||
/* 0xC */ s32 precision_;
|
||||
};
|
||||
|
||||
class TStream : public TStream_base {
|
||||
public:
|
||||
TStream();
|
||||
virtual ~TStream() = 0;
|
||||
|
||||
void init(TStreamBuffer* psb);
|
||||
bool fail() const;
|
||||
bool good() const;
|
||||
void setstate(u8 state);
|
||||
void clear(u8 state);
|
||||
TStreamBuffer* rdbuf() const;
|
||||
void fill(char);
|
||||
static char widen(char);
|
||||
static char narrow(char, char);
|
||||
|
||||
char fill() const {
|
||||
return fill_;
|
||||
}
|
||||
|
||||
private:
|
||||
/* 0x10 */ u8 state_;
|
||||
/* 0x14 */ TStreamBuffer* rdbuf_;
|
||||
/* 0x18 */ char fill_;
|
||||
};
|
||||
|
||||
class TInputStream {
|
||||
public:
|
||||
struct sentry {
|
||||
sentry(TInputStream& stream, bool);
|
||||
|
||||
operator bool() const { return _0x0; }
|
||||
|
||||
/* 0x0 */ bool _0x0;
|
||||
};
|
||||
|
||||
int get();
|
||||
|
||||
TStream* _0x0;
|
||||
virtual ~TInputStream();
|
||||
|
||||
private:
|
||||
/* 0x08 */ int field_0x8;
|
||||
};
|
||||
|
||||
class TOutputStream {
|
||||
public:
|
||||
struct sentry {
|
||||
sentry(TOutputStream& stream) {
|
||||
_0x0 = &stream;
|
||||
|
||||
_0x4 = stream._0x0->good();
|
||||
if (!_0x4) {
|
||||
stream._0x0->setstate(2);
|
||||
}
|
||||
}
|
||||
|
||||
~sentry() {
|
||||
if (!_0x0->_0x0->fail() && (_0x0->_0x0->flags() & 2)) {
|
||||
_0x0->flush();
|
||||
}
|
||||
}
|
||||
|
||||
operator bool() const { return _0x4; }
|
||||
|
||||
/* 0x0 */ TOutputStream* _0x0;
|
||||
/* 0x4 */ bool _0x4;
|
||||
};
|
||||
|
||||
struct TBufferIterator {
|
||||
TBufferIterator(TStreamBuffer* psb) {
|
||||
buffer_ = psb;
|
||||
}
|
||||
|
||||
void operator=(char param_0) {
|
||||
if (buffer_ != NULL && TTrait_char<char>::eq_int_type(buffer_->sputc(param_0), TTrait_char<char>::eof())) {
|
||||
buffer_ = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
TBufferIterator& operator*() {
|
||||
return *this;
|
||||
}
|
||||
|
||||
void operator++() {}
|
||||
|
||||
bool failed() const { return buffer_ == NULL; }
|
||||
|
||||
TStreamBuffer* buffer_;
|
||||
};
|
||||
|
||||
TOutputStream& operator<<(const char*);
|
||||
TOutputStream& operator<<(char);
|
||||
TOutputStream& operator<<(s32);
|
||||
TOutputStream& operator<<(u32);
|
||||
TOutputStream& operator<<(bool);
|
||||
TOutputStream& operator<<(double);
|
||||
|
||||
void flush();
|
||||
TBufferIterator& Put_CString_prefixed_(const char*, u32, const char*, u32);
|
||||
TBufferIterator& Put_longInt_(u32, bool);
|
||||
TBufferIterator& Put(double);
|
||||
|
||||
TBufferIterator& Put(const char* param_0, u32 param_1) {
|
||||
return Put_CString_prefixed_(param_0, param_1, NULL, 0);
|
||||
}
|
||||
|
||||
TBufferIterator& Put(s32 param_0) {
|
||||
return Put_longInt_(param_0, true);
|
||||
}
|
||||
|
||||
TBufferIterator& Put(u32 param_0) {
|
||||
return Put_longInt_(param_0, false);
|
||||
}
|
||||
|
||||
TBufferIterator& Put(bool param_0) {
|
||||
u32 flags = _0x0->flags();
|
||||
const TCString_* s = &saaosz_bool_[!(flags & 8) ? 0 : 1][param_0 ? 1 : 0];
|
||||
return Put_CString_prefixed_(s->sz, s->len, NULL, 0);
|
||||
}
|
||||
|
||||
TStream* _0x0;
|
||||
virtual ~TOutputStream();
|
||||
|
||||
struct TCString_ {
|
||||
const char* sz;
|
||||
u32 len;
|
||||
};
|
||||
|
||||
struct saoCaseNumeral_struct {
|
||||
const char _0[16];
|
||||
TCString_ _1; // 0x10
|
||||
TCString_ _2; // 0x18
|
||||
TCString_ _3; // 0x20
|
||||
};
|
||||
|
||||
static const saoCaseNumeral_struct saoCaseNumeral_[2];
|
||||
static const TCString_ saoszPrefix_sign_[3];
|
||||
static const TCString_ saaosz_bool_[2][2];
|
||||
static const TCString_ soszPrefix_oct_;
|
||||
|
||||
static const saoCaseNumeral_struct& getCaseNumeral_(u32 flags) {
|
||||
return saoCaseNumeral_[!(flags & 4) ? 0 : 1];
|
||||
}
|
||||
|
||||
private:
|
||||
/* 0x08 */ int field_0x8;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* JGADGET_STD_STREAM_H */
|
||||
@@ -0,0 +1,76 @@
|
||||
#ifndef JGADGET_STD_STREAMBUF_H
|
||||
#define JGADGET_STD_STREAMBUF_H
|
||||
|
||||
#include <dolphin/types.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace JGadget {
|
||||
template <typename T>
|
||||
struct TTrait_char {};
|
||||
|
||||
template <>
|
||||
struct TTrait_char<char> {
|
||||
static int eof() { return -1; }
|
||||
static int to_int_type(char value) { return (int)value; }
|
||||
static char to_char_type(int value) { return (char)value; }
|
||||
static bool eq_int_type(int a, int b) { return a == b; }
|
||||
static size_t length(const char* sz) { return strlen(sz); }
|
||||
};
|
||||
|
||||
class TStreamBuffer {
|
||||
public:
|
||||
TStreamBuffer() {
|
||||
pBase_get_ = NULL;
|
||||
pEnd_get_ = NULL;
|
||||
pCurrent_get_ = NULL;
|
||||
pBase_put_ = NULL;
|
||||
pEnd_put_ = NULL;
|
||||
pCurrent_put_ = NULL;
|
||||
}
|
||||
|
||||
virtual ~TStreamBuffer() = 0;
|
||||
|
||||
int sputc(char param_0) {
|
||||
if (pCurrent_put_ < pEnd_put_) {
|
||||
*pCurrent_put_ = param_0;
|
||||
pCurrent_put_++;
|
||||
return TTrait_char<char>::to_int_type(param_0);
|
||||
} else {
|
||||
return overflow(TTrait_char<char>::to_int_type(param_0));
|
||||
}
|
||||
}
|
||||
|
||||
int sgetc();
|
||||
|
||||
int sbumpc() {
|
||||
if (pCurrent_get_ < pEnd_get_) {
|
||||
int var_r29 = TTrait_char<char>::to_int_type(*pCurrent_get_);
|
||||
pCurrent_get_++;
|
||||
return var_r29;
|
||||
}
|
||||
|
||||
return uflow();
|
||||
}
|
||||
|
||||
int snextc() {
|
||||
int var_r31 = TTrait_char<char>::eof();
|
||||
return TTrait_char<char>::eq_int_type(sbumpc(), var_r31) ? var_r31 : sgetc();
|
||||
}
|
||||
|
||||
virtual void setbuf(char*, s32);
|
||||
virtual s32 sync();
|
||||
virtual int underflow();
|
||||
virtual int uflow();
|
||||
virtual s32 xsputn(const char*, s32);
|
||||
virtual int overflow(int);
|
||||
|
||||
/* 0x04 */ char* pBase_get_;
|
||||
/* 0x08 */ char* pEnd_get_;
|
||||
/* 0x0C */ char* pCurrent_get_;
|
||||
/* 0x10 */ char* pBase_put_;
|
||||
/* 0x14 */ char* pEnd_put_;
|
||||
/* 0x18 */ char* pCurrent_put_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* JGADGET_STD_STREAMBUF_H */
|
||||
@@ -70,6 +70,10 @@ namespace JUTAssertion {
|
||||
inline void showAssert(u32 device, const char* file, int line, const char* msg) {
|
||||
showAssert_f(device, file, line, "%s", msg);
|
||||
}
|
||||
|
||||
inline void setWarningMessage(u32 device, char* file, int line, const char* msg) {
|
||||
setWarningMessage_f(device, file, line, "%s", msg);
|
||||
}
|
||||
};
|
||||
|
||||
extern bool sAssertVisible;
|
||||
|
||||
Reference in New Issue
Block a user