Skip to content

Commit

Permalink
[debugger] Add verbose option
Browse files Browse the repository at this point in the history
  • Loading branch information
tgtakaoka committed May 2, 2024
1 parent 63a0653 commit 8d10c1c
Show file tree
Hide file tree
Showing 25 changed files with 87 additions and 63 deletions.
2 changes: 1 addition & 1 deletion debugger/cdp1802/pins_cdp1802.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ void PinsCdp1802::setBreakInst(uint32_t addr) const {
Memory.put_inst(addr, InstCdp1802::IDL);
}

void PinsCdp1802::printCycles() const {
void PinsCdp1802::printCycles() {
const auto g = Signals::get();
const auto cycles = g->diff(Signals::put());
for (auto i = 0; i < cycles; ++i) {
Expand Down
5 changes: 3 additions & 2 deletions debugger/cdp1802/pins_cdp1802.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ struct PinsCdp1802 final : Pins {
void run() override;
void assertInt(uint8_t name) override;
void negateInt(uint8_t name) override;
void setBreakInst(uint32_t addr) const override;
void printCycles() override;

void execInst(const uint8_t *inst, uint8_t len);
uint8_t captureWrites(const uint8_t *inst, uint8_t len, uint16_t *addr,
uint8_t *buf, uint8_t max);

private:
void setBreakInst(uint32_t addr) const override;

friend struct RegsCdp1802;
Signals *rawPrepareCycle();
Signals *prepareCycle();
Expand All @@ -94,7 +96,6 @@ struct PinsCdp1802 final : Pins {
uint8_t *buf, uint8_t max);
bool skip(uint8_t inst);

void printCycles() const;
void disassembleCycles() const;
};

Expand Down
63 changes: 35 additions & 28 deletions debugger/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ constexpr char USAGE_ROM[] = " roM";

void usage() {
cli.println();
cli.print(F("* Bionic"));
cli.print("* Bionic");
Target::printIdentity();
cli.print(F(" * "));
cli.print(" * ");
cli.println(F(VERSION_TEXT));
cli.print(USAGE);
if (Debugger.mems().hasRomArea())
Expand All @@ -68,7 +68,7 @@ void commandHandler(char c, uintptr_t extra) {
}

void printPrompt() {
cli.print(F("> "));
cli.print("> ");
cli.readLetter(commandHandler, 0);
}

Expand Down Expand Up @@ -96,7 +96,7 @@ void memoryDump(uint32_t addr, uint16_t len, const char *space = nullptr) {
for (auto i = 0; i < 16; i++) {
const auto a = addr + i;
if (a < start || a >= end) {
cli.print(F(" "));
cli.print(" ");
} else {
const auto data = Debugger.mems().get(a, space);
mem_buffer[i] = data;
Expand Down Expand Up @@ -239,7 +239,7 @@ void handleMemory(uint32_t value, uintptr_t extra, State state) {
void handleAssembleLine(char *line, uintptr_t extra, State state) {
(void)extra;
if (state == State::CLI_CANCEL || *line == 0) {
cli.println(F("end"));
cli.println("end");
printPrompt();
return;
}
Expand Down Expand Up @@ -378,7 +378,7 @@ void handleLoadFile(char *line, uintptr_t extra, State state) {
File file = SD.open(line);
if (!file) {
cli.print(line);
cli.println(F(" not found"));
cli.println(" not found");
} else {
uint16_t size = 0;
char buffer[80];
Expand Down Expand Up @@ -406,7 +406,7 @@ void handleLoadFile(char *line, uintptr_t extra, State state) {
file.close();
cli.println();
cli.print(size);
cli.println(F(" bytes loaded"));
cli.println(" bytes loaded");
}
}
printPrompt();
Expand All @@ -425,7 +425,7 @@ void handleUploadFile(char *line, uintptr_t extra, State state) {
UploadContext *context = UploadContext::context(extra);
if (state == State::CLI_CANCEL) {
cli.print(context->size);
cli.println(F(" bytes uploaded"));
cli.println(" bytes uploaded");
printPrompt();
return;
}
Expand Down Expand Up @@ -535,9 +535,9 @@ void handleRomArea(uint32_t value, uintptr_t extra, State state) {
void handleSetBreak(uint32_t value, uintptr_t extra, State state) {
if (state != State::CLI_CANCEL) {
if (Debugger.pins().setBreakPoint(value)) {
cli.print(F("Set"));
cli.print("Set");
} else {
cli.print(F("Full"));
cli.print("Full");
}
Debugger.pins().printBreakPoints();
}
Expand All @@ -549,7 +549,7 @@ void handleClearBreak(char *line, uintptr_t extra, State state) {
if (str_buffer[0]) {
const auto index = atoi(str_buffer);
if (Debugger.pins().clearBreakPoint(index)) {
cli.print(F(" Clear"));
cli.print(" Clear");
Debugger.pins().printBreakPoints();
}
}
Expand All @@ -572,63 +572,65 @@ void Debugger::exec(char c) {
const auto maxAddr = mems().maxAddr();
switch (c) {
case 'R':
cli.println(F("Reset"));
cli.println("Reset");
target().reset();
if (_verbose)
target().printCycles();
goto regs;
case 'd':
cli.print(F("Dump? "));
cli.print("Dump? ");
cli.readHex(handleDump, DUMP_ADDR, maxAddr);
return;
#ifdef WITH_DISASSEMBLER
case 'D':
cli.print(F("Disassemble? "));
cli.print("Disassemble? ");
cli.readHex(handleDisassemble, DIS_ADDR, maxAddr);
return;
#endif
#ifdef WITH_ASSEMBLER
case 'A':
cli.print(F("Assemble? "));
cli.print("Assemble? ");
cli.readHex(handleAssembler, 0, maxAddr);
return;
#endif
case 'm':
cli.print(F("Memory? "));
cli.print("Memory? ");
cli.readHex(handleMemory, MEMORY_ADDR, maxAddr);
return;
case 'M':
if (target().printRomArea()) {
cli.print(F(" ROM area? "));
cli.print(" ROM area? ");
cli.readHex(handleRomArea, MEMORY_ADDR, maxAddr);
return;
}
break;
case 'B':
cli.print(F("Set break? "));
cli.print("Set break? ");
cli.readHex(handleSetBreak, 0, maxAddr);
return;
case 'b':
if (target().printBreakPoints()) {
cli.print(F("Clear break? "));
cli.print("Clear break? ");
cli.readLine(handleClearBreak, 0, str_buffer, sizeof(str_buffer));
return;
}
break;
case 'r':
cli.println(F("Registers"));
cli.println("Registers");
regs:
target().printRegisters();
target().disassembleNext();
break;
case '=':
cli.print(F("Set register? "));
cli.print("Set register? ");
cli.readWord(handleSetRegister, 0, str_buffer, sizeof(str_buffer));
return;
case 'S':
cli.println(F("Step"));
cli.println("Step");
target().step(true);
goto regs;
case 'G':
cli.println(F("Go"));
cli.println("Go");
if (target().isOnBreakPoint()) {
// step over break point
if (!target().step(false))
Expand All @@ -637,29 +639,34 @@ void Debugger::exec(char c) {
target().run();
goto regs;
case 'F':
cli.print(F("Files? "));
cli.print("Files? ");
cli.readLine(handleFileListing, 0, str_buffer, sizeof(str_buffer));
return;
case 'L':
cli.print(F("Load? "));
cli.print("Load? ");
cli.readLine(handleLoadFile, 0, str_buffer, sizeof(str_buffer));
return;
case 'U':
cli.println(F("Upload waiting..."));
cli.println("Upload waiting...");
upload_context.size = 0;
cli.readLine(handleUploadFile, upload_context.extra(),
upload_context.buffer, sizeof(upload_context.buffer));
return;
case 'I':
cli.println();
target().printDevices();
cli.print(F("Io? "));
cli.print("Io? ");
cli.readWord(handleIo, 0, str_buffer, sizeof(str_buffer));
return;
case 'W':
cli.print(F("Write identity? "));
cli.print("Write identity? ");
cli.readLine(handleWriteIdentity, 0, str_buffer, sizeof(str_buffer));
return;
case 'V':
_verbose = !_verbose;
cli.print("Verbose ");
cli.println(_verbose ? "ON" : "OFF");
break;
case '?':
usage();
break;
Expand Down
1 change: 1 addition & 0 deletions debugger/debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct Debugger {

private:
Target *_target;
bool _verbose;
};

extern struct Debugger Debugger;
Expand Down
2 changes: 1 addition & 1 deletion debugger/f3850/pins_f3850.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ void PinsF3850::setBreakInst(uint32_t addr) const {
Memory.put_inst(addr, InstF3850::BREAK);
}

void PinsF3850::printCycles() const {
void PinsF3850::printCycles() {
const auto g = Signals::get();
const auto cycles = g->diff(Signals::put());
for (auto i = 0; i < cycles; ++i) {
Expand Down
5 changes: 3 additions & 2 deletions debugger/f3850/pins_f3850.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,22 @@ struct PinsF3850 final : Pins {
void run() override;
void assertInt(uint8_t name) override;
void negateInt(uint8_t name) override;
void setBreakInst(uint32_t addr) const override;
void printCycles() override;

void execInst(const uint8_t *inst, uint8_t len);
uint8_t captureWrites(
const uint8_t *inst, uint8_t len, uint8_t *buf, uint8_t max);

private:
void setBreakInst(uint32_t addr) const override;

Signals *cycle();
Signals *cycle(uint8_t data);
void loop();
bool rawStep();
uint8_t execute(
const uint8_t *inst, uint8_t len, uint8_t *buf, uint8_t max);

void printCycles() const;
void disassembleCycles() const;};

extern struct PinsF3850 Pins;
Expand Down
5 changes: 3 additions & 2 deletions debugger/i8048/pins_i8048.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct PinsI8048 final : Pins {
void run() override;
void assertInt(uint8_t name) override;
void negateInt(uint8_t name) override;
void setBreakInst(uint32_t addr) const override;
void printCycles() override;

void execInst(const uint8_t *inst, uint8_t len);
uint8_t captureWrites(const uint8_t *inst, uint8_t len, uint16_t *addr,
Expand All @@ -84,6 +84,8 @@ struct PinsI8048 final : Pins {
ProgI8048 &_mems;
const InstI8048 &_inst;

void setBreakInst(uint32_t addr) const override;

Signals *prepareCycle();
Signals *completeCycle(Signals *signals);
void loop();
Expand All @@ -94,7 +96,6 @@ struct PinsI8048 final : Pins {
uint8_t *buf, uint8_t max);

void disassembleCycles();
void printCycles();
};

} // namespace i8048
Expand Down
5 changes: 3 additions & 2 deletions debugger/i8085/pins_i8085.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ struct PinsI8085 final : Pins {
void run() override;
void assertInt(uint8_t name) override;
void negateInt(uint8_t name) override;
void setBreakInst(uint32_t addr) const override;
void printCycles() override;

void execInst(const uint8_t *inst, uint8_t len);
uint8_t captureWrites(const uint8_t *inst, uint8_t len, uint16_t *addr,
uint8_t *buf, uint8_t max);

private:
void setBreakInst(uint32_t addr) const override;

Signals *cycleT1() const;
Signals *cycleT2() const;
Signals *cycleT2Pause() const;
Expand All @@ -100,7 +102,6 @@ struct PinsI8085 final : Pins {
uint8_t *buf, uint8_t max);

void disassembleCycles();
void printCycles();
};

extern struct PinsI8085 Pins;
Expand Down
5 changes: 3 additions & 2 deletions debugger/ins8060/pins_ins8060.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ struct PinsIns8060 final : Pins {
void run() override;
void assertInt(uint8_t name) override;
void negateInt(uint8_t name) override;
void setBreakInst(uint32_t addr) const override;
void printCycles() override;

void execInst(const uint8_t *inst, uint8_t len) const;
void captureWrites(const uint8_t *inst, uint8_t len, uint16_t *addr,
uint8_t *buf, uint8_t max) const;

private:
void setBreakInst(uint32_t addr) const override;

Signals *prepareCycle() const;
Signals *completeCycle(Signals *signals) const;
Signals *cycle(uint8_t data) const;
Expand All @@ -85,7 +87,6 @@ struct PinsIns8060 final : Pins {
void execute(const uint8_t *inst, uint8_t len, uint16_t *addr, uint8_t *buf,
uint8_t max) const;

void printCycles();
void disassembleCycles();
};

Expand Down
2 changes: 1 addition & 1 deletion debugger/ins8070/pins_ins8070.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ void PinsIns8070::setBreakInst(uint32_t addr) const {

void PinsIns8070::printCycles(const Signals *end) {
const auto g = Signals::get();
const auto cycles = g->diff(end);
const auto cycles = g->diff(end ? end : Signals::put());
for (auto i = 0; i < cycles; ++i) {
g->next(i)->print();
idle();
Expand Down
6 changes: 4 additions & 2 deletions debugger/ins8070/pins_ins8070.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ struct PinsIns8070 final : Pins {
void run() override;
void assertInt(uint8_t name) override;
void negateInt(uint8_t name) override;
void setBreakInst(uint32_t addr) const override;
void printCycles() override { printCycles(nullptr); }

void execInst(const uint8_t *inst, uint8_t len);
void captureWrites(const uint8_t *inst, uint8_t len, uint16_t *addr,
uint8_t *buf, uint8_t max);

private:
void setBreakInst(uint32_t addr) const override;

Signals *prepareCycle();
Signals *completeCycle(Signals *signals);
Signals *cycle();
Expand All @@ -91,7 +93,7 @@ struct PinsIns8070 final : Pins {
void execute(const uint8_t *inst, uint8_t len, uint16_t *addr, uint8_t *buf,
uint8_t max);

void printCycles(const Signals *end = Signals::put());
void printCycles(const Signals *end);
bool matchAll(Signals *begin, const Signals *end);
const Signals *findFetch(Signals *begein, const Signals *end);
void disassembleCycles();
Expand Down
Loading

0 comments on commit 8d10c1c

Please sign in to comment.