From a1111200331a6adc5ba02c5318b419b561c8e36c Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Tue, 30 Dec 2014 14:09:07 -0500 Subject: [PATCH] add ;error and ;date debugger commands --- bin/CMakeLists.txt | 4 +- bin/commands.cpp | 105 ++++++++++++++++++++++++++++++++++++++ bin/debugger.cpp | 17 +++--- bin/debugger.h | 6 ++- bin/debugger_internal.cpp | 17 ++++++ bin/debugger_internal.h | 28 ++++++++++ bin/lexer.rl | 8 +++ bin/parser.lemon | 12 +++++ 8 files changed, 185 insertions(+), 12 deletions(-) create mode 100644 bin/commands.cpp create mode 100644 bin/debugger_internal.cpp create mode 100644 bin/debugger_internal.h diff --git a/bin/CMakeLists.txt b/bin/CMakeLists.txt index e7286b8..41ea2ff 100644 --- a/bin/CMakeLists.txt +++ b/bin/CMakeLists.txt @@ -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) diff --git a/bin/commands.cpp b/bin/commands.cpp new file mode 100644 index 0000000..2dd3685 --- /dev/null +++ b/bin/commands.cpp @@ -0,0 +1,105 @@ + +#include +#include + + +#include +#include + +#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(""); + + } + +} \ No newline at end of file diff --git a/bin/debugger.cpp b/bin/debugger.cpp index 128418b..9f1891d 100644 --- a/bin/debugger.cpp +++ b/bin/debugger.cpp @@ -48,6 +48,7 @@ #include "address_map.h" #include "debugger.h" +#include "debugger_internal.h" #include #include @@ -58,11 +59,15 @@ #include - #include - #include +#include +#include + + 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 ErrorTable; - std::map GlobalTable; - std::map TrapTable; - - std::unordered_multimap ErrorTableInvert; - std::unordered_map SymbolTableInvert; struct BackTraceInfo { uint32_t a[8]; diff --git a/bin/debugger.h b/bin/debugger.h index 035b501..4666eab 100644 --- a/bin/debugger.h +++ b/bin/debugger.h @@ -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 \ No newline at end of file +#endif diff --git a/bin/debugger_internal.cpp b/bin/debugger_internal.cpp new file mode 100644 index 0000000..3154895 --- /dev/null +++ b/bin/debugger_internal.cpp @@ -0,0 +1,17 @@ +#include "debugger_internal.h" + +namespace Debug { + + namespace Internal { + + Loader::DebugNameTable SymbolTable; + + std::map ErrorTable; + std::map GlobalTable; + std::map TrapTable; + + std::unordered_multimap ErrorTableInvert; + std::unordered_map SymbolTableInvert; + + } +} diff --git a/bin/debugger_internal.h b/bin/debugger_internal.h new file mode 100644 index 0000000..e94a601 --- /dev/null +++ b/bin/debugger_internal.h @@ -0,0 +1,28 @@ +#ifndef __debug_internal_h__ +#define __debug_internal_h__ + +#include +#include +#include +#include + +#include + +namespace Debug { + + namespace Internal { + + extern Loader::DebugNameTable SymbolTable; + + extern std::map ErrorTable; + extern std::map GlobalTable; + extern std::map TrapTable; + + extern std::unordered_multimap ErrorTableInvert; + extern std::unordered_map SymbolTableInvert; + + } + +} + +#endif diff --git a/bin/lexer.rl b/bin/lexer.rl index c861cc1..e4c4a35 100644 --- a/bin/lexer.rl +++ b/bin/lexer.rl @@ -122,6 +122,14 @@ namespace { Parse(parser, tkSEMIL, 0, command); }; + 'date'i { + Parse(parser, tkSEMIDATE, 0, command); + }; + + 'error'i { + Parse(parser, tkSEMIERROR, 0, command); + }; + *|; diff --git a/bin/parser.lemon b/bin/parser.lemon index 6141434..c27502c 100644 --- a/bin/parser.lemon +++ b/bin/parser.lemon @@ -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);