Compare commits
1 Commits
pf/testing
...
bjd/comman
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
031cd302dd |
@@ -73,14 +73,32 @@ public:
|
|||||||
// a cost here (writing and reading the stack at each iteration), in the end it's
|
// a cost here (writing and reading the stack at each iteration), in the end it's
|
||||||
// probably better to pay the cost at just one location.
|
// probably better to pay the cost at just one location.
|
||||||
intptr_t next;
|
intptr_t next;
|
||||||
|
driver.mCurrentExecutingCommand = this;
|
||||||
mExecute(driver, this, &next);
|
mExecute(driver, this, &next);
|
||||||
return reinterpret_cast<CommandBase*>(reinterpret_cast<intptr_t>(this) + next);
|
return reinterpret_cast<CommandBase*>(reinterpret_cast<intptr_t>(this) + next);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void captureCallstack() noexcept {
|
||||||
|
auto c = utils::CallStack::unwind(4);
|
||||||
|
size_t i = 0;
|
||||||
|
for (; i < c.getFrameCount() && i < 16; i++) {
|
||||||
|
mCallstack[i] = c[i];
|
||||||
|
}
|
||||||
|
for (; i < 16; i++) {
|
||||||
|
mCallstack[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void printCallstack() noexcept {
|
||||||
|
auto c = utils::CallStack(mCallstack);
|
||||||
|
utils::slog.d << c << utils::io::endl;
|
||||||
|
}
|
||||||
|
|
||||||
inline ~CommandBase() noexcept = default;
|
inline ~CommandBase() noexcept = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Execute mExecute;
|
Execute mExecute;
|
||||||
|
std::array<intptr_t, 16> mCallstack = {0};
|
||||||
};
|
};
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
@@ -218,6 +236,7 @@ public:
|
|||||||
using Cmd = COMMAND_TYPE(methodName); \
|
using Cmd = COMMAND_TYPE(methodName); \
|
||||||
void* const p = allocateCommand(CommandBase::align(sizeof(Cmd))); \
|
void* const p = allocateCommand(CommandBase::align(sizeof(Cmd))); \
|
||||||
new(p) Cmd(mDispatcher.methodName##_, APPLY(std::move, params)); \
|
new(p) Cmd(mDispatcher.methodName##_, APPLY(std::move, params)); \
|
||||||
|
((Cmd*)p)->captureCallstack(); \
|
||||||
DEBUG_COMMAND_END(methodName, false); \
|
DEBUG_COMMAND_END(methodName, false); \
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,6 +256,7 @@ public:
|
|||||||
using Cmd = COMMAND_TYPE(methodName##R); \
|
using Cmd = COMMAND_TYPE(methodName##R); \
|
||||||
void* const p = allocateCommand(CommandBase::align(sizeof(Cmd))); \
|
void* const p = allocateCommand(CommandBase::align(sizeof(Cmd))); \
|
||||||
new(p) Cmd(mDispatcher.methodName##_, RetType(result), APPLY(std::move, params)); \
|
new(p) Cmd(mDispatcher.methodName##_, RetType(result), APPLY(std::move, params)); \
|
||||||
|
((Cmd*)p)->captureCallstack(); \
|
||||||
DEBUG_COMMAND_END(methodName, false); \
|
DEBUG_COMMAND_END(methodName, false); \
|
||||||
return result; \
|
return result; \
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ template<typename T>
|
|||||||
class ConcreteDispatcher;
|
class ConcreteDispatcher;
|
||||||
class Dispatcher;
|
class Dispatcher;
|
||||||
class CommandStream;
|
class CommandStream;
|
||||||
|
class CommandBase;
|
||||||
|
|
||||||
class Driver {
|
class Driver {
|
||||||
public:
|
public:
|
||||||
@@ -83,6 +84,8 @@ public:
|
|||||||
virtual void debugCommandEnd(CommandStream* cmds,
|
virtual void debugCommandEnd(CommandStream* cmds,
|
||||||
bool synchronous, const char* methodName) noexcept = 0;
|
bool synchronous, const char* methodName) noexcept = 0;
|
||||||
|
|
||||||
|
CommandBase* mCurrentExecutingCommand = nullptr;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Asynchronous calls here only to provide a type to CommandStream. They must be non-virtual
|
* Asynchronous calls here only to provide a type to CommandStream. They must be non-virtual
|
||||||
* so that calling the concrete implementation won't go through a vtable.
|
* so that calling the concrete implementation won't go through a vtable.
|
||||||
|
|||||||
@@ -36,6 +36,13 @@ public:
|
|||||||
* @see CallStack::capture()
|
* @see CallStack::capture()
|
||||||
*/
|
*/
|
||||||
CallStack() = default;
|
CallStack() = default;
|
||||||
|
template <unsigned long N>
|
||||||
|
explicit CallStack(const std::array<intptr_t, N>& symbols)
|
||||||
|
: m_frame_count(N) {
|
||||||
|
for (size_t i = 0; i < N; i++) {
|
||||||
|
m_stack[i] = symbols[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
CallStack(const CallStack&) = default;
|
CallStack(const CallStack&) = default;
|
||||||
~CallStack() = default;
|
~CallStack() = default;
|
||||||
|
|
||||||
@@ -114,12 +121,10 @@ private:
|
|||||||
|
|
||||||
static constexpr size_t NUM_FRAMES = 20;
|
static constexpr size_t NUM_FRAMES = 20;
|
||||||
|
|
||||||
struct StackFrameInfo {
|
using StackFrameInfo = intptr_t;
|
||||||
intptr_t pc;
|
|
||||||
};
|
|
||||||
|
|
||||||
size_t m_frame_count = 0;
|
size_t m_frame_count = 0;
|
||||||
StackFrameInfo m_stack[NUM_FRAMES];
|
StackFrameInfo m_stack[NUM_FRAMES] = {0};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace utils
|
} // namespace utils
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ intptr_t CallStack::operator[](size_t index) const {
|
|||||||
#endif
|
#endif
|
||||||
std::abort();
|
std::abort();
|
||||||
}
|
}
|
||||||
return m_stack[index].pc;
|
return m_stack[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t CallStack::getFrameCount() const noexcept {
|
size_t CallStack::getFrameCount() const noexcept {
|
||||||
@@ -91,7 +91,7 @@ void CallStack::update_gcc(size_t ignore) noexcept {
|
|||||||
size -= ignore;
|
size -= ignore;
|
||||||
#endif
|
#endif
|
||||||
for (ssize_t i = 0; i < size; i++) {
|
for (ssize_t i = 0; i < size; i++) {
|
||||||
m_stack[i].pc = intptr_t(array[ignore + i]);
|
m_stack[i] = intptr_t(array[ignore + i]);
|
||||||
}
|
}
|
||||||
size--; // the last one seems to always be 0x0
|
size--; // the last one seems to always be 0x0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user