20#include "pedigree/kernel/Log.h"
21#include "pedigree/kernel/debugger/Backtrace.h"
22#include "pedigree/kernel/debugger/DebuggerIO.h"
23#include "pedigree/kernel/debugger/commands/AllocationCommand.h"
24#include "pedigree/kernel/linker/KernelElf.h"
25#include "pedigree/kernel/process/Process.h"
26#include "pedigree/kernel/process/Thread.h"
27#include "pedigree/kernel/processor/Processor.h"
28#include "pedigree/kernel/processor/ProcessorInformation.h"
29#include "pedigree/kernel/utilities/Iterator.h"
30#include "pedigree/kernel/utilities/demangle.h"
31#include "pedigree/kernel/utilities/utility.h"
44 m_bAllocating(false) {}
55 m_nLines = NUM_BT_FRAMES + 1;
64 for (
int i = 0; i < NUM_BT_FRAMES; i++)
68 accum += pA->pid << 16;
74 m_Tree.insert(accum, pA);
80 m_It = m_Tree.begin();
84 pScreen->disableCli();
88 resize(pScreen->
getWidth(), pScreen->getHeight() - 2);
89 setScrollKeys(
'j',
'k');
96 pScreen->
drawString(
"Pedigree debugger - Page allocation resolver", 0, 0, DebuggerIO::White,
104 DebuggerIO::White, DebuggerIO::Green);
108 pScreen->
drawString(
"backspace: Page up. space: Page down. q: Quit. enter: Next allocation",
109 pScreen->getHeight() - 1, 0, DebuggerIO::White, DebuggerIO::Green);
110 pScreen->
drawString(
"backspace", pScreen->getHeight() - 1, 0, DebuggerIO::Yellow,
112 pScreen->
drawString(
"space", pScreen->getHeight() - 1, 20, DebuggerIO::Yellow, DebuggerIO::Green);
113 pScreen->
drawString(
"q", pScreen->getHeight() - 1, 38, DebuggerIO::Yellow, DebuggerIO::Green);
114 pScreen->
drawString(
"enter", pScreen->getHeight() - 1, 47, DebuggerIO::Yellow, DebuggerIO::Green);
124 while (!(c = pScreen->
getChar()))
130 }
else if (c ==
'k') {
132 }
else if (c ==
' ') {
133 scroll(
static_cast<ssize_t
>(height()));
134 }
else if (c == 0x08) {
135 scroll(-
static_cast<ssize_t
>(height()));
136 }
else if (c ==
'\n' || c ==
'\r') {
139 if (m_It == m_Tree.end()) {
140 m_It = m_Tree.begin();
151 pScreen->
drawString(
" ", 1, 0, DebuggerIO::White, DebuggerIO::Black);
161 Allocation* pA = m_It.value();
163 bgColour = DebuggerIO::Black;
165 colour = DebuggerIO::Yellow;
167 Line +=
" allocations from this source (";
170 Line += m_Tree.count();
177 colour = DebuggerIO::White;
178 uintptr_t symStart = 0;
182 Line.append(pA->ra[index], 16);
187 Line.append(symStart, 16);
191 Line +=
static_cast<const char*
>(
symbol.name);
196const char* AllocationCommand::getLine2(
size_t index,
size_t& colOffset,
DebuggerIO::Colour& colour,
204size_t AllocationCommand::getLineCount() {
208void AllocationCommand::allocatePage(physical_uintptr_t page) {
213 Allocation* pA =
new Allocation;
220 pA->pid = pP->
getId();
225 m_Allocations.pushBack(pA);
228void AllocationCommand::freePage(physical_uintptr_t page) {
229 m_Frees.
pushBack(
reinterpret_cast<void*
>(page));
232void AllocationCommand::postProcess() {
233 NOTICE(
"Beginning free-list post processing...");
235 physical_uintptr_t page =
reinterpret_cast<physical_uintptr_t
>(*it);
240 if ((*it2)->page == page) {
242 m_Allocations.erase(it2);
248 it = m_Frees.
begin();
250 NOTICE(
"End free-list post processing.");
253void AllocationCommand::checkpoint() {
254 NOTICE(
"Allocation checkpoint.");
256 m_Allocations.clear();
bool execute(const HugeStaticString &input, HugeStaticString &output, InterruptState &state, DebuggerIO *screen)
void autocomplete(const HugeStaticString &input, HugeStaticString &output)
uintptr_t m_pReturnAddresses[MAX_STACK_FRAMES]
void performBpBacktrace(uintptr_t base, uintptr_t instruction)
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)
static ProcessorInformation & information()
void pushBack(const T &value)
void clear(bool freeMem=false)