| 1 | #pragma once |
|---|---|
| 2 | |
| 3 | #include "basis/seadTypes.h" |
| 4 | #include "container/seadSafeArray.h" |
| 5 | |
| 6 | namespace sead |
| 7 | { |
| 8 | class StackTraceBase |
| 9 | { |
| 10 | public: |
| 11 | StackTraceBase(); |
| 12 | virtual ~StackTraceBase() = default; |
| 13 | |
| 14 | virtual uintptr_t get(s32 index) const = 0; |
| 15 | virtual s32 size() const = 0; |
| 16 | |
| 17 | void trace(const void*); |
| 18 | |
| 19 | protected: |
| 20 | virtual void clear_() = 0; |
| 21 | virtual void push_(uintptr_t addr) = 0; |
| 22 | virtual bool isFull_() = 0; |
| 23 | }; |
| 24 | |
| 25 | template <s32 Capacity> |
| 26 | class StackTrace : public StackTraceBase |
| 27 | { |
| 28 | public: |
| 29 | ~StackTrace() override = default; |
| 30 | |
| 31 | uintptr_t get(s32 index) const override |
| 32 | { |
| 33 | if (index >= mSize) |
| 34 | return 0; |
| 35 | return mBuffer[index]; |
| 36 | } |
| 37 | |
| 38 | s32 size() const override { return mSize; } |
| 39 | |
| 40 | protected: |
| 41 | void clear_() override { mSize = 0; } |
| 42 | |
| 43 | void push_(uintptr_t addr) override |
| 44 | { |
| 45 | mBuffer[mSize] = addr; |
| 46 | ++mSize; |
| 47 | } |
| 48 | |
| 49 | bool isFull_() override { return mSize >= mBuffer.size(); } |
| 50 | |
| 51 | private: |
| 52 | SafeArray<uintptr_t, Capacity> mBuffer{}; |
| 53 | s32 mSize{}; |
| 54 | }; |
| 55 | } // namespace sead |
| 56 |