Skip to content

Commit

Permalink
TRACE()
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertvanheusden committed May 4, 2024
1 parent 925fe29 commit 5898943
Show file tree
Hide file tree
Showing 17 changed files with 190 additions and 167 deletions.
154 changes: 77 additions & 77 deletions bus.cpp

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ void console::put_char(const char c)
tx = 0;
else if (c == 10) {
if (debug_buffer.empty() == false) {
DOLOG(::debug, true, "TTY: %s", debug_buffer.c_str());
TRACE("TTY: %s", debug_buffer.c_str());

debug_buffer.clear();
}
Expand Down Expand Up @@ -322,7 +322,7 @@ void console::put_string(const std::string & what)

void console::operator()()
{
DOLOG(::info, true, "Console thread started");
TRACE("Console thread started");

set_thread_name("kek::console");

Expand Down Expand Up @@ -360,5 +360,5 @@ void console::operator()()
}
}

DOLOG(::info, true, "Console thread terminating");
TRACE("Console thread terminating");
}
24 changes: 12 additions & 12 deletions cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ bool cpu::execute_any_pending_interrupt()
if (trap_delay.has_value()) {
trap_delay.value()--;

DOLOG(debug, false, "Delayed trap: %d instructions left", trap_delay.value());
TRACE("Delayed trap: %d instructions left", trap_delay.value());

if (trap_delay.value() > 0)
return false;
Expand Down Expand Up @@ -409,7 +409,7 @@ bool cpu::execute_any_pending_interrupt()

interrupts->second.erase(vector);

DOLOG(debug, false, "Invoking interrupt vector %o (IPL %d, current: %d)", v, i, current_level);
TRACE("Invoking interrupt vector %o (IPL %d, current: %d)", v, i, current_level);

trap(v, i, true);

Expand Down Expand Up @@ -458,7 +458,7 @@ void cpu::queue_interrupt(const uint8_t level, const uint8_t vector)

any_queued_interrupts = true;

DOLOG(debug, false, "Queueing interrupt vector %o (IPL %d, current: %d), n: %zu", vector, level, getPSW_spl(), it->second.size());
TRACE("Queueing interrupt vector %o (IPL %d, current: %d), n: %zu", vector, level, getPSW_spl(), it->second.size());
}

void cpu::addToMMR1(const gam_rc_t & g)
Expand Down Expand Up @@ -838,7 +838,7 @@ bool cpu::additional_double_operand_instructions(const uint16_t instr)
addToMMR1(g_dst);
uint16_t shift = g_dst.value.value() & 077;

DOLOG(debug, true, "shift %06o with %d", R, shift);
TRACE("shift %06o with %d", R, shift);

bool sign = SIGN(R, wm_word);

Expand Down Expand Up @@ -1638,7 +1638,7 @@ bool cpu::condition_code_operations(const uint16_t instr)
void cpu::pushStack(const uint16_t v)
{
if (getRegister(6) == stackLimitRegister) {
DOLOG(debug, false, "stackLimitRegister reached %06o while pushing %06o", stackLimitRegister, v);
TRACE("stackLimitRegister reached %06o while pushing %06o", stackLimitRegister, v);

trap(04, 7);
}
Expand Down Expand Up @@ -1687,7 +1687,7 @@ bool cpu::misc_operations(const uint16_t instr)
wait_time += end - start; // used for MIPS calculation
}

DOLOG(debug, false, "WAIT returned");
TRACE("WAIT returned");

return true;

Expand Down Expand Up @@ -1811,7 +1811,7 @@ bool cpu::misc_operations(const uint16_t instr)
// 'is_interrupt' is not correct naming; it is true for mmu faults and interrupts
void cpu::trap(uint16_t vector, const int new_ipl, const bool is_interrupt)
{
DOLOG(debug, false, "*** CPU::TRAP %o, new-ipl: %d, is-interrupt: %d, run mode: %d ***", vector, new_ipl, is_interrupt, getPSW_runmode());
TRACE("*** CPU::TRAP %o, new-ipl: %d, is-interrupt: %d, run mode: %d ***", vector, new_ipl, is_interrupt, getPSW_runmode());

uint16_t before_psw = 0;
uint16_t before_pc = 0;
Expand All @@ -1825,7 +1825,7 @@ void cpu::trap(uint16_t vector, const int new_ipl, const bool is_interrupt)
bool kernel_mode = !(psw >> 14);

if (processing_trap_depth >= 2) {
DOLOG(debug, false, "Trap depth %d", processing_trap_depth);
TRACE("Trap depth %d", processing_trap_depth);

if (processing_trap_depth >= 3) {
*event = EVENT_HALT;
Expand Down Expand Up @@ -1879,10 +1879,10 @@ void cpu::trap(uint16_t vector, const int new_ipl, const bool is_interrupt)

// if we reach this point then the trap was processed without causing
// another trap
DOLOG(debug, false, "Trapping to %06o with PSW %06o", pc, psw);
TRACE("Trapping to %06o with PSW %06o", pc, psw);
}
catch(const int exception) {
DOLOG(debug, false, "trap during execution of trap (%d)", exception);
TRACE("trap during execution of trap (%d)", exception);

setPSW(before_psw, false);
}
Expand Down Expand Up @@ -2419,12 +2419,12 @@ void cpu::step()
if (misc_operations(instr))
return;

DOLOG(warning, true, "UNHANDLED instruction %06o @ %06o", instr, instruction_start);
DOLOG(warning, false, "UNHANDLED instruction %06o @ %06o", instr, instruction_start);

trap(010); // floating point nog niet geimplementeerd
}
catch(const int exception_nr) {
DOLOG(debug, false, "bus-trap during execution of command (%d)", exception_nr);
TRACE("bus-trap during execution of command (%d)", exception_nr);
}
}

Expand Down
17 changes: 8 additions & 9 deletions debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,10 +617,9 @@ void tm11_unload_tape(bus *const b)
b->getTM11()->unload();
}

void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const stop_event, const bool tracing_in)
void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const stop_event)
{
int32_t trace_start_addr = -1;
bool tracing = tracing_in;
int n_single_step = 1;
bool turbo = false;
std::optional<int> t_rl; // trace runlevel
Expand Down Expand Up @@ -759,9 +758,9 @@ void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const sto
continue;
}
else if (parts[0] == "trace" || parts[0] == "t") {
tracing = !tracing;
settrace(!gettrace());

cnsl->put_string_lf(format("Tracing set to %s", tracing ? "ON" : "OFF"));
cnsl->put_string_lf(format("Tracing set to %s", gettrace() ? "ON" : "OFF"));

continue;
}
Expand Down Expand Up @@ -1100,12 +1099,12 @@ void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const sto

while(*stop_event == EVENT_NONE) {
if (!single_step)
DOLOG(debug, false, "---");
TRACE("---");

if (trace_start_addr != -1 && c->getPC() == trace_start_addr)
tracing = true;
settrace(true);

if ((tracing || single_step) && (t_rl.has_value() == false || t_rl.value() == c->getPSW_runmode()))
if ((gettrace() || single_step) && (t_rl.has_value() == false || t_rl.value() == c->getPSW_runmode()))
disassemble(c, single_step ? cnsl : nullptr, c->getPC(), false);

auto bp_result = c->check_breakpoint();
Expand Down Expand Up @@ -1138,7 +1137,7 @@ void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const sto
}
}

void run_bic(console *const cnsl, bus *const b, std::atomic_uint32_t *const stop_event, const bool tracing, const uint16_t start_addr)
void run_bic(console *const cnsl, bus *const b, std::atomic_uint32_t *const stop_event, const uint16_t start_addr)
{
cpu *const c = b->getCpu();

Expand All @@ -1147,7 +1146,7 @@ void run_bic(console *const cnsl, bus *const b, std::atomic_uint32_t *const stop
*cnsl->get_running_flag() = true;

while(*stop_event == EVENT_NONE) {
if (tracing)
if (gettrace())
disassemble(c, nullptr, c->getPC(), false);

c->step();
Expand Down
4 changes: 2 additions & 2 deletions debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@


int disassemble(cpu *const c, console *const cnsl, const uint16_t pc, const bool instruction_only);
void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const stop_event, const bool tracing);
void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const stop_event);

void run_bic(console *const cnsl, bus *const b, std::atomic_uint32_t *const stop_event, const bool tracing, const uint16_t bic_start);
void run_bic(console *const cnsl, bus *const b, std::atomic_uint32_t *const stop_event, const uint16_t bic_start);
4 changes: 2 additions & 2 deletions disk_backend_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ bool disk_backend_file::begin(const bool snapshots)

bool disk_backend_file::read(const off_t offset_in, const size_t n, uint8_t *const target, const size_t sector_size)
{
DOLOG(debug, false, "disk_backend_file::read: read %zu bytes from offset %zu", n, offset_in);
TRACE("disk_backend_file::read: read %zu bytes from offset %zu", n, offset_in);

assert((offset_in % sector_size) == 0);
assert((n % sector_size) == 0);
Expand Down Expand Up @@ -95,7 +95,7 @@ bool disk_backend_file::read(const off_t offset_in, const size_t n, uint8_t *con

bool disk_backend_file::write(const off_t offset, const size_t n, const uint8_t *const from, const size_t sector_size)
{
DOLOG(debug, false, "disk_backend_file::write: write %zu bytes to offset %zu", n, offset);
TRACE("disk_backend_file::write: write %zu bytes to offset %zu", n, offset);

if (store_mem_range_in_overlay(offset, n, from, sector_size))
return true;
Expand Down
4 changes: 2 additions & 2 deletions disk_backend_nbd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ bool disk_backend_nbd::connect(const bool retry)

bool disk_backend_nbd::read(const off_t offset_in, const size_t n, uint8_t *const target, const size_t sector_size)
{
DOLOG(debug, false, "disk_backend_nbd::read: read %zu bytes from offset %zu", n, offset_in);
TRACE("disk_backend_nbd::read: read %zu bytes from offset %zu", n, offset_in);

if (n == 0)
return true;
Expand Down Expand Up @@ -256,7 +256,7 @@ bool disk_backend_nbd::read(const off_t offset_in, const size_t n, uint8_t *cons

bool disk_backend_nbd::write(const off_t offset, const size_t n, const uint8_t *const from, const size_t sector_size)
{
DOLOG(debug, false, "disk_backend_nbd::write: write %zu bytes to offset %zu", n, offset);
TRACE("disk_backend_nbd::write: write %zu bytes to offset %zu", n, offset);

if (n == 0)
return true;
Expand Down
10 changes: 5 additions & 5 deletions kw11-l.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void kw11_l::operator()()
{
set_thread_name("kek:kw-11l");

DOLOG(debug, true, "Starting KW11-L thread");
TRACE("Starting KW11-L thread");

while(!stop_flag) {
if (*cnsl->get_running_flag()) {
Expand All @@ -83,13 +83,13 @@ void kw11_l::operator()()
}
}

DOLOG(debug, true, "KW11-L thread terminating");
TRACE("KW11-L thread terminating");
}

uint16_t kw11_l::read_word(const uint16_t a)
{
if (a != ADDR_LFC) {
DOLOG(debug, true, "KW11-L read_word not for us (%06o)", a);
TRACE("KW11-L read_word not for us (%06o)", a);
return 0;
}

Expand All @@ -111,7 +111,7 @@ uint16_t kw11_l::read_word(const uint16_t a)
void kw11_l::write_word(const uint16_t a, const uint16_t value)
{
if (a != ADDR_LFC) {
DOLOG(debug, true, "KW11-L write_word not for us (%06o to %06o)", value, a);
TRACE("KW11-L write_word not for us (%06o to %06o)", value, a);
return;
}

Expand All @@ -121,7 +121,7 @@ void kw11_l::write_word(const uint16_t a, const uint16_t value)
std::unique_lock<std::mutex> lck(lf_csr_lock);
#endif

DOLOG(debug, false, "WRITE-I/O set line frequency clock/status register: %06o", value);
TRACE("WRITE-I/O set line frequency clock/status register: %06o", value);
lf_csr = value;
#if defined(BUILD_FOR_RP2040)
xSemaphoreGive(lf_csr_lock);
Expand Down
2 changes: 1 addition & 1 deletion loaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ std::optional<uint16_t> load_tape(bus *const b, const std::string & file)
}

#if !defined(ESP32)
DOLOG(debug, false, "%ld] reading %d (dec) bytes to %o (oct)", ftell(fh), count - 6, p);
TRACE("%ld] reading %d (dec) bytes to %o (oct)", ftell(fh), count - 6, p);
#endif

for(int i=0; i<count - 6; i++) {
Expand Down
31 changes: 21 additions & 10 deletions log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@
#endif


static const char *logfile = strdup("/tmp/kek.log");
static sockaddr_in syslog_ip_addr = { };
static bool is_file = true;
log_level_t log_level_file = warning;
log_level_t log_level_screen = warning;
static FILE *log_fh = nullptr;
static int lf_uid = -1;
static int lf_gid = -1;
static bool l_timestamp = true;
static const char *logfile = strdup("/tmp/kek.log");
static sockaddr_in syslog_ip_addr = { };
static bool is_file = true;
log_level_t log_level_file = warning;
log_level_t log_level_screen = warning;
static FILE *log_fh = nullptr;
static int lf_uid = -1;
static int lf_gid = -1;
static bool l_timestamp = true;
static thread_local int log_buffer_size = 128;
static thread_local char *log_buffer = reinterpret_cast<char *>(malloc(log_buffer_size));
static thread_local char *log_buffer = reinterpret_cast<char *>(malloc(log_buffer_size));
bool log_trace_enabled = false;

#if defined(ESP32)
int gettid()
Expand All @@ -39,6 +40,16 @@ int gettid()
}
#endif

void settrace(const bool on)
{
log_trace_enabled = on;
}

bool gettrace()
{
return log_trace_enabled;
}

void setlogfile(const char *const lf, const log_level_t ll_file, const log_level_t ll_screen, const bool timestamp)
{
if (log_fh)
Expand Down
13 changes: 13 additions & 0 deletions log.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ void setloguid(const int uid, const int gid);
void send_syslog(const int ll, const std::string & what);
void closelog();
void dolog(const log_level_t ll, const char *fmt, ...);
void settrace(const bool on);
bool gettrace();

#ifdef TURBO
#define DOLOG(ll, always, fmt, ...) do { } while(0)
Expand All @@ -38,3 +40,14 @@ void dolog(const log_level_t ll, const char *fmt, ...);
} while(0)
#endif
#endif

#ifdef TURBO
#define TRACE(fmt, ...) do { } while(0)
#else
#define TRACE(fmt, ...) do { \
extern bool log_trace_enabled; \
if (log_trace_enabled) { \
dolog(debug, fmt, ##__VA_ARGS__); \
} \
} while(0)
#endif
7 changes: 3 additions & 4 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ int main(int argc, char *argv[])
std::vector<disk_backend *> rl02_files;

bool run_debugger = false;
bool tracing = false;

bool enable_bootloader = false;
bootloader_t bootloader = BL_NONE;
Expand Down Expand Up @@ -416,7 +415,7 @@ int main(int argc, char *argv[])
break;

case 't':
tracing = true;
settrace(true);
break;

case 'n':
Expand Down Expand Up @@ -629,9 +628,9 @@ int main(int argc, char *argv[])
b->getKW11_L()->begin(cnsl);

if (is_bic)
run_bic(cnsl, b, &event, tracing, bic_start.value());
run_bic(cnsl, b, &event, bic_start.value());
else if (run_debugger || (bootloader == BL_NONE && test.empty() && tape.empty()))
debugger(cnsl, b, &event, tracing);
debugger(cnsl, b, &event);
else {
b->getCpu()->emulation_start(); // for statistics

Expand Down
Loading

0 comments on commit 5898943

Please sign in to comment.