20#include "pedigree/kernel/debugger/DebuggerIO.h"
21#include "pedigree/kernel/debugger/commands/SlamCommand.h"
22#include "pedigree/kernel/linker/KernelElf.h"
23#include "pedigree/kernel/machine/Machine.h"
24#include "pedigree/kernel/machine/Serial.h"
25#include "pedigree/kernel/utilities/Iterator.h"
26#include "pedigree/kernel/utilities/demangle.h"
27#include "pedigree/kernel/utilities/utility.h"
44 m_nLines = NUM_SLAM_BT_FRAMES + 1;
46 m_It = m_Tree.begin();
50 pScreen->disableCli();
54 resize(pScreen->
getWidth(), pScreen->getHeight() - 2);
55 setScrollKeys(
'j',
'k');
62 pScreen->
drawString(
"Pedigree debugger - Slam allocation resolver", 0, 0, DebuggerIO::White,
70 DebuggerIO::White, DebuggerIO::Green);
74 pScreen->
drawString(
"q: Quit. c: Clean. d: Dump to serial. enter: Next allocation.",
75 pScreen->getHeight() - 1, 0, DebuggerIO::White, DebuggerIO::Green);
76 pScreen->
drawString(
"q", pScreen->getHeight() - 1, 0, DebuggerIO::Yellow, DebuggerIO::Green);
77 pScreen->
drawString(
"c", pScreen->getHeight() - 1, 9, DebuggerIO::Yellow, DebuggerIO::Green);
78 pScreen->
drawString(
"d", pScreen->getHeight() - 1, 19, DebuggerIO::Yellow, DebuggerIO::Green);
79 pScreen->
drawString(
"enter", pScreen->getHeight() - 1, 38, DebuggerIO::Yellow, DebuggerIO::Green);
89 while (!(c = pScreen->
getChar()))
95 }
else if (c ==
'k') {
97 }
else if (c ==
' ') {
98 scroll(
static_cast<ssize_t
>(height()));
99 }
else if (c == 0x08) {
100 scroll(-
static_cast<ssize_t
>(height()));
101 }
else if (c ==
'\n' || c ==
'\r') {
104 if (m_It == m_Tree.end()) {
105 m_It = m_Tree.begin();
108 }
else if (c ==
'c') {
110 m_It = m_Tree.begin();
112 }
else if (c ==
'd') {
113 Machine::instance().
getSerial(0)->write_str(
"AllocDump {\n");
114 for (m_It = m_Tree.begin(); m_It != m_Tree.end(); m_It++) {
118 str +=
"Alloc {\nBacktrace [";
119 for (
int i = 0; i < NUM_SLAM_BT_FRAMES; i++) {
121 str.append(pA->bt[i], 16);
123 uintptr_t symStart = 0;
126 str.append(pA->bt[i], 16);
131 str +=
static_cast<const char*
>(
symbol.name);
140 Machine::instance().
getSerial(0)->write_str(str);
142 Machine::instance().
getSerial(0)->write_str(
"}\n");
151 pScreen->
drawString(
" ", 1, 0, DebuggerIO::White, DebuggerIO::Black);
162 SlamAllocation* pA = m_It.value();
164 bgColour = DebuggerIO::Black;
166 colour = DebuggerIO::Yellow;
168 Line +=
" allocations from this source (";
171 Line += m_Tree.count();
173 if (pA->size >= 1024 * 1024) {
174 Line += (pA->size / (1024 * 1024));
176 }
else if (pA->size >= 1024) {
177 Line += (pA->size / 1024);
187 colour = DebuggerIO::White;
188 uintptr_t symStart = 0;
192 Line.append(pA->bt[index], 16);
197 Line.append(symStart, 16);
201 Line +=
static_cast<const char*
>(
symbol.name);
206const char* SlamCommand::getLine2(
size_t index,
size_t& colOffset,
DebuggerIO::Colour& colour,
214size_t SlamCommand::getLineCount() {
218void SlamCommand::addAllocation(uintptr_t* backtrace,
size_t requested) {
226 for (
int i = 0; i < NUM_SLAM_BT_FRAMES; i++)
227 accum ^= backtrace[i];
230 SlamAllocation* pOther = m_Tree.lookup(accum);
232 SlamAllocation* pAlloc =
new SlamAllocation;
233 MemoryCopy(&pAlloc->bt, backtrace, NUM_SLAM_BT_FRAMES *
sizeof(uintptr_t));
235 pAlloc->size = requested;
236 m_Tree.insert(accum, pAlloc);
238 pOther->size += requested;
244void SlamCommand::removeAllocation(uintptr_t* backtrace,
size_t requested) {
252 for (
int i = 0; i < NUM_SLAM_BT_FRAMES; i++)
253 accum ^= backtrace[i];
256 SlamAllocation* pAlloc = m_Tree.lookup(accum);
259 m_Tree.remove(accum);
virtual void enableCli()=0
virtual void drawString(const char *str, size_t row, size_t col, Colour foreColour, Colour backColour)=0
virtual size_t getWidth()=0
virtual void drawHorizontalLine(char c, size_t row, size_t colStart, size_t colEnd, Colour foreColour, Colour backColour)=0
static KernelElf & instance()
uintptr_t globalLookupSymbol(const char *pName)
virtual Serial * getSerial(size_t n)=0
bool execute(const HugeStaticString &input, HugeStaticString &output, InterruptState &state, DebuggerIO *screen)
void autocomplete(const HugeStaticString &input, HugeStaticString &output)