add ;error and ;date debugger commands

This commit is contained in:
Kelvin Sherlock 2014-12-30 14:09:07 -05:00
parent 490519b0d1
commit a111120033
8 changed files with 185 additions and 12 deletions

View File

@ -47,7 +47,9 @@ set_source_files_properties(
)
add_executable(mpw loader.cpp debugger.cpp address_map.cpp lexer.cpp parser.cpp loadtrap.cpp)
add_executable(mpw loader.cpp debugger.cpp debugger_internal.cpp
address_map.cpp lexer.cpp parser.cpp loadtrap.cpp commands.cpp)
target_link_libraries(mpw CPU_LIB)
target_link_libraries(mpw TOOLBOX_LIB)
target_link_libraries(mpw MPW_LIB)

105
bin/commands.cpp Normal file
View File

@ -0,0 +1,105 @@
#include <cstdint>
#include <ctime>
#include <toolbox/os.h>
#include <macos/errors.h>
#include "debugger.h"
#include "debugger_internal.h"
namespace Debug {
using namespace Internal;
void PrintError(uint32_t value)
{
/* expr ; error -- interpret expr as an OSErr */
// errors are signed 16-bit values.
if ((int32_t)value > UINT16_MAX) return;
if ((int32_t)value < INT16_MIN) return;
uint16_t error = value;
printf("%d\n", (int16_t)error);
if (error)
{
bool found = false;
const char *cp = ErrorName(error);
if (cp)
{
printf("%s\n", cp);
found = true;
}
for (auto iter = ErrorTableInvert.find(error); iter != ErrorTableInvert.end(); ++iter) {
// multimap - continue until error doesn't match.
if (iter->first != error) break;
printf("%s\n", iter->second.c_str());
found = true;
}
if (!found) printf("Unknown error\n");
}
else
{
printf("noErr\n");
return;
}
}
void PrintDate(uint32_t value)
{
/* expr ; date -- interpret expr as a macos date */
char buffer[64];
struct tm *tm;
time_t t = OS::MacToUnix(value);
tm = ::localtime(&t);
strftime(buffer, sizeof(buffer), "%Y-%m-%d %I:%M:%S %p", tm);
puts(buffer);
}
void Moof(void)
{
puts("");
puts(" ## ");
puts(" ## ## #### ");
puts(" ## #### ## ");
puts(" ## ## ");
puts(" ## ## ## ## ");
puts(" ## ## #### ");
puts("## ## ## ## ");
puts(" ######## #### ## ## ");
puts(" ## #################### ## ");
puts(" ## ############## ## ");
puts(" #### ############ ## ");
puts(" ###### ###### ## ");
puts(" ###### ## ");
puts(" #### ## ");
puts(" ## ## ");
puts(" ## ################ ## ");
puts(" ## ## ## ## ");
puts(" ## ## ## ## ");
puts(" ## ## ## ## ");
puts(" ## ## ## ## ");
puts(" ## ## ## ## ");
puts(" ###### ###### ");
puts("");
}
}

View File

@ -48,6 +48,7 @@
#include "address_map.h"
#include "debugger.h"
#include "debugger_internal.h"
#include <cpu/defs.h>
#include <cpu/CpuModule.h>
@ -58,11 +59,15 @@
#include <mpw/mpw.h>
#include <toolbox/loader.h>
#include <toolbox/mm.h>
#include <toolbox/loader.h>
#include <toolbox/mm.h>
namespace {
using namespace Debug::Internal;
const uint32_t kGlobalSize = 0x10000;
const uint32_t kBackTraceSize = 20;
@ -78,14 +83,6 @@ namespace {
AddressMap wbrkMap; // write breaks.
ToolMap tbrkMap; // tool breaks.
Loader::DebugNameTable SymbolTable;
std::map<std::string, uint16_t> ErrorTable;
std::map<std::string, uint16_t> GlobalTable;
std::map<std::string, uint16_t> TrapTable;
std::unordered_multimap<uint16_t, std::string> ErrorTableInvert;
std::unordered_map<uint32_t, std::string> SymbolTableInvert;
struct BackTraceInfo {
uint32_t a[8];

View File

@ -140,6 +140,10 @@ void WriteBreak(int32_t address);
void ReadWriteBreak();
void ReadWriteBreak(int32_t address);
void PrintError(uint32_t value);
void PrintDate(uint32_t value);
}
#endif
#endif

17
bin/debugger_internal.cpp Normal file
View File

@ -0,0 +1,17 @@
#include "debugger_internal.h"
namespace Debug {
namespace Internal {
Loader::DebugNameTable SymbolTable;
std::map<std::string, uint16_t> ErrorTable;
std::map<std::string, uint16_t> GlobalTable;
std::map<std::string, uint16_t> TrapTable;
std::unordered_multimap<uint16_t, std::string> ErrorTableInvert;
std::unordered_map<uint32_t, std::string> SymbolTableInvert;
}
}

28
bin/debugger_internal.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef __debug_internal_h__
#define __debug_internal_h__
#include <cstdint>
#include <string>
#include <map>
#include <unordered_map>
#include <toolbox/loader.h>
namespace Debug {
namespace Internal {
extern Loader::DebugNameTable SymbolTable;
extern std::map<std::string, uint16_t> ErrorTable;
extern std::map<std::string, uint16_t> GlobalTable;
extern std::map<std::string, uint16_t> TrapTable;
extern std::unordered_multimap<uint16_t, std::string> ErrorTableInvert;
extern std::unordered_map<uint32_t, std::string> SymbolTableInvert;
}
}
#endif

View File

@ -122,6 +122,14 @@ namespace {
Parse(parser, tkSEMIL, 0, command);
};
'date'i {
Parse(parser, tkSEMIDATE, 0, command);
};
'error'i {
Parse(parser, tkSEMIERROR, 0, command);
};
*|;

View File

@ -201,6 +201,18 @@ stmt ::= expr(a) COLON expr(b) SEMI SEMIL EOL.
}
stmt ::= expr(a) SEMI SEMIDATE EOL.
{
Debug::PrintDate(a.intValue);
}
stmt ::= expr(a) SEMI SEMIERROR EOL.
{
Debug::PrintError(a.intValue);
}
stmt ::= DREGISTER(a) EQ expr(b) EOL.
{
Debug::SetDRegister(a.intValue, b.intValue);