Skip to content

Commit 0589f6b

Browse files
committed
Trace names of resident programs.
1 parent 53eecbc commit 0589f6b

File tree

2 files changed

+72
-2
lines changed

2 files changed

+72
-2
lines changed

machine.cpp

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,18 @@ void Machine::print_calls_returns()
182182
if (after_call | after_return) {
183183
auto &out = get_trace_stream();
184184

185-
out << "---------------------------------------------------\n";
185+
out << "---------------------------------------------------";
186186

187-
// TODO: print name of the routine at PC.
187+
// Print name of routine at new address.
188+
std::string name;
189+
bool at_start{};
190+
if (find_resident_name(cpu.get_pc(), name, at_start)) {
191+
if (!at_start) {
192+
out << " back to";
193+
}
194+
out << " " << name;
195+
}
196+
out << "\n";
188197
}
189198
}
190199

@@ -356,6 +365,11 @@ void Machine::drum_io(char op, unsigned drum_unit, unsigned zone, unsigned secto
356365
}
357366
} else {
358367
drums[drum_unit]->memory_to_drum(zone, sector, addr, nwords);
368+
369+
if (debug_instructions && drum_unit == 020 && zone == 0 && nwords == 1024) {
370+
// Load the table of resident programs, for tracing.
371+
load_resident_directory(addr);
372+
}
359373
}
360374
}
361375

@@ -795,6 +809,47 @@ void Machine::print_iso_string(std::ostream &out, unsigned addr)
795809
out << '\n';
796810
}
797811

812+
//
813+
// Load the table of resident programs, for tracing.
814+
//
815+
void Machine::load_resident_directory(unsigned base)
816+
{
817+
resident_name.clear();
818+
resident_addr.clear();
819+
for (unsigned offset = 0; offset < PAGE_NWORDS/4; offset += 2) {
820+
Word name = memory.load(base + offset);
821+
if (name == 0) {
822+
break;
823+
}
824+
unsigned address = memory.load(base + offset + 1) & 077777;
825+
826+
resident_name[address] = word_text_string(name);
827+
resident_addr.insert(address);
828+
}
829+
std::cout << " Load " << resident_name.size() << " names from TRP\n";
830+
}
831+
832+
//
833+
// Find name of resident routine, by address.
834+
// Set at_start to true when address matches the start of the routine.
835+
//
836+
bool Machine::find_resident_name(unsigned addr, std::string &name, bool &at_start)
837+
{
838+
// Find the next resident program after given address.
839+
auto it = resident_addr.upper_bound(addr);
840+
if (it == resident_addr.begin()) {
841+
// No residents at all.
842+
return false;
843+
}
844+
845+
// Get start address of the resident.
846+
unsigned start = *std::prev(it); // Largest element <= addr
847+
848+
name = resident_name[start];
849+
at_start = (addr == start);
850+
return true;
851+
}
852+
798853
//
799854
// Load boot code for Monitoring System Dubna.
800855
//

machine.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include <chrono>
2929
#include <memory>
3030
#include <vector>
31+
#include <set>
32+
#include <unordered_map>
3133

3234
#include "disk.h"
3335
#include "drum.h"
@@ -77,6 +79,12 @@ class Machine {
7779
// Enable system load list from the start.
7880
bool system_load_list_flag{};
7981

82+
// Get name of a resident program by address.
83+
std::unordered_map<unsigned, std::string> resident_name;
84+
85+
// Addresses of resident programs.
86+
std::multiset<unsigned> resident_addr;
87+
8088
// Trace output.
8189
static std::ofstream trace_stream;
8290

@@ -227,6 +235,13 @@ class Machine {
227235
// Load binary program (overlay).
228236
void boot_overlay(const std::string &filename, unsigned file_offset, const std::string &path = "");
229237

238+
// Load the table of resident programs, for tracing.
239+
void load_resident_directory(unsigned addr);
240+
241+
// Find name of resident routine, by address.
242+
// Set at_start to true when address matches the start of the routine.
243+
bool find_resident_name(unsigned addr, std::string &name, bool &at_start);
244+
230245
//
231246
// Trace methods.
232247
//

0 commit comments

Comments
 (0)