mirror of
https://github.com/ksherlock/mpw.git
synced 2024-11-24 13:32:39 +00:00
sc / stackcrawl debugger command
This commit is contained in:
parent
f946dc1884
commit
cbe66b6798
108
bin/commands.cpp
108
bin/commands.cpp
@ -6,6 +6,9 @@
|
||||
#include <toolbox/os.h>
|
||||
#include <macos/errors.h>
|
||||
|
||||
#include <cpu/defs.h>
|
||||
#include <cpu/CpuModule.h>
|
||||
|
||||
#include "debugger.h"
|
||||
#include "debugger_internal.h"
|
||||
|
||||
@ -66,6 +69,7 @@ namespace Debug {
|
||||
struct tm *tm;
|
||||
time_t t = OS::MacToUnix(value);
|
||||
|
||||
// localtime vs gmtime?
|
||||
tm = ::localtime(&t);
|
||||
strftime(buffer, sizeof(buffer), "%Y-%m-%d %I:%M:%S %p", tm);
|
||||
puts(buffer);
|
||||
@ -76,30 +80,90 @@ namespace Debug {
|
||||
{
|
||||
|
||||
puts("");
|
||||
puts(" ## ");
|
||||
puts(" ## ## #### ");
|
||||
puts(" ## #### ## ");
|
||||
puts(" ## ## ");
|
||||
puts(" ## ## ## ## ");
|
||||
puts(" ## ## #### ");
|
||||
puts("## ## ## ## ");
|
||||
puts(" ######## #### ## ## ");
|
||||
puts(" ## #################### ## ");
|
||||
puts(" ## ############## ## ");
|
||||
puts(" #### ############ ## ");
|
||||
puts(" ###### ###### ## ");
|
||||
puts(" ###### ## ");
|
||||
puts(" #### ## ");
|
||||
puts(" ## ## ");
|
||||
puts(" ## ################ ## ");
|
||||
puts(" ## ## ## ## ");
|
||||
puts(" ## ## ## ## ");
|
||||
puts(" ## ## ## ## ");
|
||||
puts(" ## ## ## ## ");
|
||||
puts(" ## ## ## ## ");
|
||||
puts(" ###### ###### ");
|
||||
puts(" ## ");
|
||||
puts(" ## ## #### ");
|
||||
puts(" ## #### ## ");
|
||||
puts(" ## ## ");
|
||||
puts(" ## ## ## ## ");
|
||||
puts(" ## ## #### ");
|
||||
puts(" ## ## ## ## ");
|
||||
puts(" ######## #### ## ## ");
|
||||
puts(" ## #################### ## ");
|
||||
puts(" ## ############## ## ");
|
||||
puts(" #### ############ ## ");
|
||||
puts(" ###### ###### ## ");
|
||||
puts(" ###### ## ");
|
||||
puts(" #### ## ");
|
||||
puts(" ## ## ");
|
||||
puts(" ## ################ ## ");
|
||||
puts(" ## ## ## ## ");
|
||||
puts(" ## ## ## ## ");
|
||||
puts(" ## ## ## ## ");
|
||||
puts(" ## ## ## ## ");
|
||||
puts(" ## ## ## ## ");
|
||||
puts(" ###### ###### ");
|
||||
puts("");
|
||||
|
||||
}
|
||||
|
||||
|
||||
void StackCrawl(void)
|
||||
{
|
||||
// stack crawl based on a6 frame pointers. (link/unlink)
|
||||
// start with current a6.
|
||||
|
||||
uint32_t a6 = cpuGetAReg(6);
|
||||
|
||||
/*
|
||||
* a6: previous a6
|
||||
* a6+4 return pc
|
||||
* .... parameters, locals, stack data
|
||||
* previous a6
|
||||
* return pc
|
||||
* ....
|
||||
*/
|
||||
// todo -- need a function to verify address is w/in stack range.
|
||||
|
||||
|
||||
if (!a6) return;
|
||||
printf("a6: %08x\n", a6);
|
||||
|
||||
while(a6)
|
||||
{
|
||||
|
||||
uint32_t prevA6 = ReadLong(a6);
|
||||
uint32_t pc = ReadLong(a6+4); //
|
||||
|
||||
puts("------------");
|
||||
printf("a6: %08x\n", prevA6);
|
||||
printf("pc: %08x", pc);
|
||||
|
||||
// find the routine name...
|
||||
for (const auto &kv : SymbolTable)
|
||||
{
|
||||
const auto &name = kv.first;
|
||||
auto range = kv.second;
|
||||
|
||||
// range end may be 0
|
||||
if ((pc == range.first) || (pc >= range.first && pc < range.second))
|
||||
{
|
||||
uint32_t offset = pc - range.first;
|
||||
if (offset)
|
||||
printf(" %s+$%x", name.c_str(), offset);
|
||||
else
|
||||
printf(" %s", name.c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
puts("");
|
||||
|
||||
// hexdump contents between pc and previous....
|
||||
|
||||
|
||||
a6 = prevA6;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -759,7 +759,7 @@ void PrintRegisters(const BackTraceInfo &i)
|
||||
i.a[4], i.a[5], i.a[6], i.a[7]
|
||||
);
|
||||
|
||||
printf("PC: %08X CSR: %04x %s\n", i.pc, i.csr, srbits);
|
||||
printf("PC: %08x CSR: %04x %s\n", i.pc, i.csr, srbits);
|
||||
|
||||
}
|
||||
|
||||
|
@ -147,6 +147,8 @@ void ReadWriteBreak(int32_t address);
|
||||
void PrintError(uint32_t value);
|
||||
void PrintDate(uint32_t value);
|
||||
|
||||
void StackCrawl(void);
|
||||
|
||||
void ApplyTemplate(int32_t address, const std::string &name);
|
||||
|
||||
}
|
||||
|
@ -150,6 +150,7 @@ namespace {
|
||||
fgoto ident;
|
||||
};
|
||||
|
||||
|
||||
*|;
|
||||
|
||||
main := |*
|
||||
@ -268,6 +269,12 @@ namespace {
|
||||
Parse(parser, tkDUMP, 0, command);
|
||||
};
|
||||
|
||||
|
||||
'sc'i | 'stackcrawl'i {
|
||||
Parse(parser, tkSTACKCRAWL, 0, command);
|
||||
};
|
||||
|
||||
|
||||
'h'i | 'help'i {
|
||||
Parse(parser, tkHELP, 0, command);
|
||||
};
|
||||
|
@ -162,6 +162,10 @@ stmt ::= LIST expr(a) EOL.
|
||||
Debug::List(a.intValue);
|
||||
}
|
||||
|
||||
stmt ::= STACKCRAWL EOL.
|
||||
{
|
||||
Debug::StackCrawl();
|
||||
}
|
||||
|
||||
stmt ::= expr(a) SEMI SEMIH EOL.
|
||||
{
|
||||
@ -205,12 +209,13 @@ stmt ::= expr(a) SEMI SEMIDATE EOL.
|
||||
Debug::PrintDate(a.intValue);
|
||||
}
|
||||
|
||||
|
||||
stmt ::= expr(a) SEMI SEMIERROR EOL.
|
||||
{
|
||||
Debug::PrintError(a.intValue);
|
||||
}
|
||||
|
||||
|
||||
|
||||
stmt ::= expr(a) SEMI SEMIT IDENTIFIER(b) EOL.
|
||||
{
|
||||
Debug::ApplyTemplate(a.intValue, *b.stringValue);
|
||||
|
Loading…
Reference in New Issue
Block a user