diff --git a/bin/debugger.cpp b/bin/debugger.cpp index 7a5fe89..7632a5b 100644 --- a/bin/debugger.cpp +++ b/bin/debugger.cpp @@ -75,7 +75,8 @@ namespace { AddressMap wbrkMap; // write breaks. ToolMap tbrkMap; // tool breaks. - std::map SymbolTable; + Loader::DebugNameTable SymbolTable; + std::map ErrorTable; std::map GlobalTable; std::map TrapTable; @@ -831,16 +832,20 @@ void SetXRegister(unsigned reg, uint32_t value) } +// todo -- return a range uint32_t VariableGet(const std::string &s) { auto iter = SymbolTable.find(s); if (iter == SymbolTable.end()) return 0; - return iter->second; + return iter->second.first; } +// TODO -- take a Token and construct a pair, if it's a range. +// var = expr : expr or var = expr@count + void VariableSet(const std::string &key, uint32_t value) { - SymbolTable.emplace(key, value); + SymbolTable.emplace(key, std::make_pair(value, 0)); } void Info(uint32_t address) @@ -848,11 +853,30 @@ void Info(uint32_t address) // print info on the value. Print(address); - + // 1. as a pointer. MM::Native::MemoryInfo(address); // 2. (todo) - check SymbolTable for procedure address. + for (const auto &kv : SymbolTable) + { + const auto &name = kv.first; + auto range = kv.second; + + //printf("%s: %x %x\n", name.c_str(), range.first, range.second); + + // range end may be 0 + if ((address == range.first) || (address >= range.first && address < range.second)) + { + uint32_t offset = address - range.first; + if (offset) + printf("Routine: %s+$%x\n", name.c_str(), offset); + else + printf("Routine: %s\n", name.c_str()); + break; + } + } + // 2. as a tool trap. if (address >= 0xa000 && address <= 0xafff) diff --git a/bin/debugger.h b/bin/debugger.h index 6b01088..90abf00 100644 --- a/bin/debugger.h +++ b/bin/debugger.h @@ -23,7 +23,9 @@ enum { // ; commands kHexdump = 1, kInfo, - kList + kList, + kBreak, + kTBreak }; struct Command { @@ -72,6 +74,9 @@ struct Token { std::string *stringValue; unsigned subtype; + // unsigned range? + // unsigned modifier? + #if 0 Token& operator=(uint32_t rhs) @@ -82,7 +87,7 @@ struct Token { return *this; } #endif - + operator uint32_t() const { return intValue; diff --git a/toolbox/loader.cpp b/toolbox/loader.cpp index 8f81ac3..94911ea 100644 --- a/toolbox/loader.cpp +++ b/toolbox/loader.cpp @@ -363,7 +363,7 @@ namespace Loader { // - void LoadDebugNames(std::map &table) + void LoadDebugNames(DebugNameTable &table) { if (Segments.empty()) return; @@ -493,7 +493,6 @@ namespace Loader { continue; } - table.emplace(std::move(s), start + si.address); // constant data @@ -504,8 +503,13 @@ namespace Loader { pc = (pc + length + 1) & ~1; } + + // TODO -- should this include the name and data? + table.emplace(std::move(s), std::make_pair(start + si.address, pc + si.address)); + // in case no link instruction... start = pc; + } } diff --git a/toolbox/loader.h b/toolbox/loader.h index f9762e2..bc20d6f 100644 --- a/toolbox/loader.h +++ b/toolbox/loader.h @@ -8,6 +8,7 @@ namespace Loader { + typedef std::map> DebugNameTable; namespace Native { /* @@ -21,7 +22,7 @@ namespace Loader { // scans segments for MacsBug debug names. // associates them with the start of the segment. - void LoadDebugNames(std::map &table); + void LoadDebugNames(DebugNameTable &table); }