20 #include "pedigree/kernel/debugger/commands/SlamCommand.h" 21 #include "pedigree/kernel/debugger/DebuggerIO.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" 54 m_nLines = NUM_SLAM_BT_FRAMES + 1;
56 m_It = m_Tree.begin();
60 pScreen->disableCli();
64 resize(pScreen->
getWidth(), pScreen->getHeight() - 2);
65 setScrollKeys(
'j',
'k');
69 ' ', 0, 0, pScreen->
getWidth() - 1, DebuggerIO::White,
74 "Pedigree debugger - Slam allocation resolver", 0, 0, DebuggerIO::White,
82 ' ', pScreen->getHeight() - 1, 0, pScreen->
getWidth() - 1,
83 DebuggerIO::White, DebuggerIO::Green);
88 "q: Quit. c: Clean. d: Dump to serial. enter: Next allocation.",
89 pScreen->getHeight() - 1, 0, DebuggerIO::White, DebuggerIO::Green);
91 "q", pScreen->getHeight() - 1, 0, DebuggerIO::Yellow,
94 "c", pScreen->getHeight() - 1, 9, DebuggerIO::Yellow,
97 "d", pScreen->getHeight() - 1, 19, DebuggerIO::Yellow,
100 "enter", pScreen->getHeight() - 1, 38, DebuggerIO::Yellow,
112 while (!(c = pScreen->
getChar()))
126 scroll(static_cast<ssize_t>(height()));
130 scroll(-static_cast<ssize_t>(height()));
132 else if (c ==
'\n' || c ==
'\r')
136 if (m_It == m_Tree.end())
138 m_It = m_Tree.begin();
145 m_It = m_Tree.begin();
150 Machine::instance().
getSerial(0)->write(
"AllocDump {\n");
151 for (m_It = m_Tree.begin(); m_It != m_Tree.end(); m_It++)
156 str +=
"Alloc {\nBacktrace [";
157 for (
int i = 0; i < NUM_SLAM_BT_FRAMES; i++)
160 str.append(pA->bt[i], 16);
162 uintptr_t symStart = 0;
164 pA->bt[i], &symStart);
166 str.append(pA->bt[i], 16);
172 str +=
static_cast<const char *
>(symbol.name);
181 Machine::instance().
getSerial(0)->write(str);
183 Machine::instance().
getSerial(0)->write(
"}\n");
193 pScreen->
drawString(
" ", 1, 0, DebuggerIO::White, DebuggerIO::Black);
199 const char *SlamCommand::getLine1(
207 bgColour = DebuggerIO::Black;
210 colour = DebuggerIO::Yellow;
212 Line +=
" allocations from this source (";
215 Line += m_Tree.count();
217 if (pA->size >= 1024 * 1024)
219 Line += (pA->size / (1024 * 1024));
222 else if (pA->size >= 1024)
224 Line += (pA->size / 1024);
236 colour = DebuggerIO::White;
237 uintptr_t symStart = 0;
243 Line.append(pA->bt[index], 16);
250 Line.append(symStart, 16);
254 Line +=
static_cast<const char *
>(symbol.name);
259 const char *SlamCommand::getLine2(
269 size_t SlamCommand::getLineCount()
274 void SlamCommand::addAllocation(uintptr_t *backtrace,
size_t requested)
283 for (
int i = 0; i < NUM_SLAM_BT_FRAMES; i++)
284 accum ^= backtrace[i];
292 &pAlloc->bt, backtrace, NUM_SLAM_BT_FRAMES *
sizeof(uintptr_t));
294 pAlloc->size = requested;
295 m_Tree.insert(accum, pAlloc);
299 pOther->size += requested;
305 void SlamCommand::removeAllocation(uintptr_t *backtrace,
size_t requested)
314 for (
int i = 0; i < NUM_SLAM_BT_FRAMES; i++)
315 accum ^= backtrace[i];
322 m_Tree.remove(accum);
void autocomplete(const HugeStaticString &input, HugeStaticString &output)
virtual size_t getWidth()=0
virtual Serial * getSerial(size_t n)=0
bool execute(const HugeStaticString &input, HugeStaticString &output, InterruptState &state, DebuggerIO *screen)
virtual void enableCli()=0
static KernelElf & instance()
uintptr_t globalLookupSymbol(const char *pName)
virtual void drawString(const char *str, size_t row, size_t col, Colour foreColour, Colour backColour)=0
virtual void drawHorizontalLine(char c, size_t row, size_t colStart, size_t colEnd, Colour foreColour, Colour backColour)=0