sc / stackcrawl debugger command

This commit is contained in:
Kelvin Sherlock 2014-12-31 15:45:22 -05:00
parent f946dc1884
commit cbe66b6798
5 changed files with 102 additions and 24 deletions

View File

@ -6,6 +6,9 @@
#include <toolbox/os.h> #include <toolbox/os.h>
#include <macos/errors.h> #include <macos/errors.h>
#include <cpu/defs.h>
#include <cpu/CpuModule.h>
#include "debugger.h" #include "debugger.h"
#include "debugger_internal.h" #include "debugger_internal.h"
@ -66,6 +69,7 @@ namespace Debug {
struct tm *tm; struct tm *tm;
time_t t = OS::MacToUnix(value); time_t t = OS::MacToUnix(value);
// localtime vs gmtime?
tm = ::localtime(&t); tm = ::localtime(&t);
strftime(buffer, sizeof(buffer), "%Y-%m-%d %I:%M:%S %p", tm); strftime(buffer, sizeof(buffer), "%Y-%m-%d %I:%M:%S %p", tm);
puts(buffer); puts(buffer);
@ -82,7 +86,7 @@ namespace Debug {
puts(" ## ## "); puts(" ## ## ");
puts(" ## ## ## ## "); puts(" ## ## ## ## ");
puts(" ## ## #### "); puts(" ## ## #### ");
puts("## ## ## ## "); puts(" ## ## ## ## ");
puts(" ######## #### ## ## "); puts(" ######## #### ## ## ");
puts(" ## #################### ## "); puts(" ## #################### ## ");
puts(" ## ############## ## "); puts(" ## ############## ## ");
@ -102,4 +106,64 @@ namespace Debug {
} }
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;
}
}
} }

View File

@ -759,7 +759,7 @@ void PrintRegisters(const BackTraceInfo &i)
i.a[4], i.a[5], i.a[6], i.a[7] 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);
} }

View File

@ -147,6 +147,8 @@ void ReadWriteBreak(int32_t address);
void PrintError(uint32_t value); void PrintError(uint32_t value);
void PrintDate(uint32_t value); void PrintDate(uint32_t value);
void StackCrawl(void);
void ApplyTemplate(int32_t address, const std::string &name); void ApplyTemplate(int32_t address, const std::string &name);
} }

View File

@ -150,6 +150,7 @@ namespace {
fgoto ident; fgoto ident;
}; };
*|; *|;
main := |* main := |*
@ -268,6 +269,12 @@ namespace {
Parse(parser, tkDUMP, 0, command); Parse(parser, tkDUMP, 0, command);
}; };
'sc'i | 'stackcrawl'i {
Parse(parser, tkSTACKCRAWL, 0, command);
};
'h'i | 'help'i { 'h'i | 'help'i {
Parse(parser, tkHELP, 0, command); Parse(parser, tkHELP, 0, command);
}; };

View File

@ -162,6 +162,10 @@ stmt ::= LIST expr(a) EOL.
Debug::List(a.intValue); Debug::List(a.intValue);
} }
stmt ::= STACKCRAWL EOL.
{
Debug::StackCrawl();
}
stmt ::= expr(a) SEMI SEMIH EOL. stmt ::= expr(a) SEMI SEMIH EOL.
{ {
@ -205,12 +209,13 @@ stmt ::= expr(a) SEMI SEMIDATE EOL.
Debug::PrintDate(a.intValue); Debug::PrintDate(a.intValue);
} }
stmt ::= expr(a) SEMI SEMIERROR EOL. stmt ::= expr(a) SEMI SEMIERROR EOL.
{ {
Debug::PrintError(a.intValue); Debug::PrintError(a.intValue);
} }
stmt ::= expr(a) SEMI SEMIT IDENTIFIER(b) EOL. stmt ::= expr(a) SEMI SEMIT IDENTIFIER(b) EOL.
{ {
Debug::ApplyTemplate(a.intValue, *b.stringValue); Debug::ApplyTemplate(a.intValue, *b.stringValue);