20 #include "pedigree/kernel/debugger/commands/MemoryInspector.h" 21 #include "pedigree/kernel/processor/Processor.h" 22 #include "pedigree/kernel/processor/ProcessorInformation.h" 23 #include "pedigree/kernel/processor/VirtualAddressSpace.h" 24 #include "pedigree/kernel/processor/state.h" 38 output =
"<Address> | <Register name>";
46 if (input ==
"memory")
52 if (!tryGoto(addrString, nAddress, state))
54 output =
"Bad address or register.\n";
65 pScreen->disableCli();
69 resize(pScreen->
getWidth(), pScreen->getHeight() - 3);
70 setScrollKeys(
'j',
'k');
74 ' ', 0, 0, pScreen->
getWidth() - 1, DebuggerIO::White,
79 "Pedigree debugger - Memory inspector", 0, 0, DebuggerIO::White,
82 resetStatusLine(pScreen);
84 scrollTo(nAddress / m_nCharsPerLine);
94 while ((c = pScreen->
getChar()) == 0)
103 scroll(static_cast<ssize_t>(height()));
105 scroll(-static_cast<ssize_t>(height()));
109 doGoto(pScreen, state);
111 doSearch(
true, pScreen, state);
113 doSearch(
false, pScreen, state);
120 pScreen->
drawString(
" ", 1, 0, DebuggerIO::White, DebuggerIO::Black);
125 const char *MemoryInspector::getLine1(
128 colour = DebuggerIO::DarkGrey;
129 uintptr_t nLine = index * m_nCharsPerLine;
132 str.append(nLine, 16,
sizeof(uintptr_t) * 2,
'0');
136 const char *MemoryInspector::getLine2(
140 colOffset =
sizeof(uintptr_t) * 2 + 1;
142 uintptr_t nLine = index * m_nCharsPerLine;
144 #if !defined(MIPS_COMMON) && !defined(ARM_COMMON) 146 reinterpret_cast<void *>(nLine)))
148 colour = DebuggerIO::Red;
149 return "Memory not mapped.";
154 uint8_t *pLine =
reinterpret_cast<uint8_t *
>(nLine);
157 for (
unsigned int i = 0; i < m_nCharsPerLine; i++)
159 str.append(pLine[i], 16, 2,
'0');
161 if (((i + 1) % 8 == 0) && ((i + 1) < m_nCharsPerLine))
166 for (
unsigned int i = 0; i < m_nCharsPerLine; i++)
168 if (pLine[i] >= 33 && pLine[i] <= 126)
169 str.append(static_cast<char>(pLine[i]), 1);
175 #if !defined(MIPS_COMMON) && !defined(ARM_COMMON) 182 size_t MemoryInspector::getLineCount()
188 #elif defined(BITS_64) 189 return 0x2000000000000000;
193 void MemoryInspector::resetStatusLine(
DebuggerIO *pScreen)
200 ' ', pScreen->getHeight() - 1, 0, pScreen->
getWidth() - 1,
201 DebuggerIO::White, DebuggerIO::Green);
206 "backspace: Page up. space: Page down. q: Quit. /,?: Fwd/Rev search. " 208 pScreen->getHeight() - 1, 0, DebuggerIO::White, DebuggerIO::Green);
210 "backspace", pScreen->getHeight() - 1, 0, DebuggerIO::Yellow,
213 "space", pScreen->getHeight() - 1, 20, DebuggerIO::Yellow,
216 "q", pScreen->getHeight() - 1, 38, DebuggerIO::Yellow,
219 "/,?", pScreen->getHeight() - 1, 47, DebuggerIO::Yellow,
222 "g", pScreen->getHeight() - 1, 68, DebuggerIO::Yellow,
226 void MemoryInspector::doGoto(
DebuggerIO *pScreen, InterruptState &state)
234 ' ', pScreen->getHeight() - 2, 0, pScreen->
getWidth() - 1,
235 DebuggerIO::White, DebuggerIO::Black);
238 "[Go to address or register value]", pScreen->getHeight() - 2, 0,
239 DebuggerIO::White, DebuggerIO::Black);
242 str, pScreen->getHeight() - 2, 35, DebuggerIO::White,
246 while ((c = pScreen->
getChar()) == 0)
248 if (c ==
'\n' || c ==
'\r')
257 ' ', pScreen->getHeight() - 2, 0, pScreen->
getWidth() - 1,
258 DebuggerIO::White, DebuggerIO::Black);
261 if (!tryGoto(str, nAddress, state))
264 "Bad address or register.", pScreen->getHeight() - 2, 0,
265 DebuggerIO::Red, DebuggerIO::Black);
269 scrollTo(nAddress / m_nCharsPerLine);
273 void MemoryInspector::doSearch(
274 bool bForward,
DebuggerIO *pScreen, InterruptState &state)
283 ' ', pScreen->getHeight() - 2, 0, pScreen->
getWidth() - 1,
284 DebuggerIO::White, DebuggerIO::Black);
288 "[Search] ", pScreen->getHeight() - 2, 0, DebuggerIO::White,
292 "[Reverse]", pScreen->getHeight() - 2, 0, DebuggerIO::White,
296 str, pScreen->getHeight() - 2, 10, DebuggerIO::White,
300 while ((c = pScreen->
getChar()) == 0)
302 if (c ==
'\n' || c ==
'\r')
311 ' ', pScreen->getHeight() - 2, 0, pScreen->
getWidth() - 1,
312 DebuggerIO::White, DebuggerIO::Black);
314 unsigned int nChars = 0;
324 if (str.length() > 8)
327 "Search string too long (> 8 characters)",
328 pScreen->getHeight() - 2, 0, DebuggerIO::Red,
333 nChars = str.length();
334 for (
size_t i = 0; i < str.length(); i++)
340 if (str.left(2) ==
"0x")
342 nChars = str.length() / 2;
346 "Hex string too long, 8 bytes max.", pScreen->getHeight() - 2,
347 0, DebuggerIO::Red, DebuggerIO::Black);
350 for (
size_t i = 0; i < nChars; i++)
355 mystr += str[i * 2 + 1];
357 int nConverted = mystr.intValue(16);
359 if (nConverted == -1)
362 "Malformed hexadecimal number.", pScreen->getHeight() - 2,
363 0, DebuggerIO::Red, DebuggerIO::Black);
366 pChars[nChars - i - 1] =
static_cast<uint8_t
>(nConverted);
371 str =
"[Search for ";
373 str =
"[Reverse for ";
374 for (
size_t i = 0; i < nChars; i++)
376 str.append(pChars[i], 16, 2,
'0');
379 str +=
": over ?(K|M) of memory]";
381 str, pScreen->getHeight() - 2, 0, DebuggerIO::White, DebuggerIO::Black);
388 ' ', pScreen->getHeight() - 2, 0, pScreen->
getWidth() - 1,
389 DebuggerIO::White, DebuggerIO::Black);
392 str, pScreen->getHeight() - 2, 0, DebuggerIO::White,
396 str2, pScreen->getHeight() - 2, str.length() + 1, DebuggerIO::White,
400 while ((c = pScreen->
getChar()) == 0)
402 if (c ==
'\n' || c ==
'\r')
412 ' ', pScreen->getHeight() - 2, 0, pScreen->
getWidth() - 1,
413 DebuggerIO::White, DebuggerIO::Black);
415 char suffix = str[0];
416 if (suffix ==
'M' || suffix ==
'K')
418 int num = str2.intValue();
422 "Malformed number.", pScreen->getHeight() - 2, 0, DebuggerIO::Red,
426 size_t nRange =
static_cast<size_t>(num);
429 else if (suffix ==
'M')
433 "Searching...", pScreen->getHeight() - 2, 0, DebuggerIO::Green,
439 bool MemoryInspector::tryGoto(
442 for (
size_t i = 0; i < state.getRegisterCount(); i++)
447 result = state.getRegister(i);
451 uintptr_t n = str.uintptrValue();
virtual size_t getWidth()=0
virtual void enableCli()=0
void autocomplete(const HugeStaticString &input, HugeStaticString &output)
bool execute(const HugeStaticString &input, HugeStaticString &output, InterruptState &state, DebuggerIO *screen)
static ProcessorInformation & information()
StaticString right(int n) const
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