Skip to content

Commit e4470d5

Browse files
committed
Merge branch 'cli-updates-revided'
2 parents 2d0d043 + ff0c4fa commit e4470d5

File tree

5 files changed

+44
-8
lines changed

5 files changed

+44
-8
lines changed

src/cli/main.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@ void create_parser(QCommandLineParser &p) {
5252
"all registers.",
5353
"REG" });
5454
p.addOption({ "dump-to-json", "Configure reportor dump to json file.", "FNAME" });
55+
p.addOption({ "only-dump", "Do not start the processor." });
56+
p.addOption({ "disable-console-dump", "Configure reporter not to dump to console." });
5557
p.addOption({ { "dump-registers", "d-regs" }, "Dump registers state at program exit." });
5658
p.addOption({ "dump-cache-stats", "Dump cache statistics at program exit." });
5759
p.addOption({ "dump-cycles", "Dump number of CPU cycles till program end." });
5860
p.addOption({ "dump-range", "Dump memory range.", "START,LENGTH,FNAME" });
61+
p.addOption({ "dump-symbol-table", "Dump the symbol table." });
5962
p.addOption({ "load-range", "Load memory range.", "START,FNAME" });
6063
p.addOption({ "expect-fail", "Expect that program causes CPU trap and fail if it doesn't." });
6164
p.addOption({ "fail-match",
@@ -139,7 +142,7 @@ void configure_cache(CacheConfig &cacheconf, const QStringList &cachearg, const
139142
cacheconf.set_write_policy(CacheConfig::WP_THROUGH_ALLOC);
140143
} else {
141144
fprintf(
142-
stderr, "Write policy for %s cache is incorrect (correct wb/wt/wtna/wta). \n",
145+
stderr, "Write policy for %s cache is incorrect (correct wb/wt/wtna/wta).\n",
143146
qPrintable(which));
144147
exit(EXIT_FAILURE);
145148
}
@@ -161,7 +164,7 @@ void parse_u32_option(
161164
(config.*setter)(value);
162165
} else {
163166
fprintf(
164-
stderr, "Value of option %s is not a valid unsigned integer.",
167+
stderr, "Value of option %s is not a valid unsigned integer.\n",
165168
qPrintable(option_name));
166169
exit(EXIT_FAILURE);
167170
}
@@ -291,9 +294,13 @@ void configure_reporter(QCommandLineParser &p, Reporter &r, const SymbolTable *s
291294
r.dump_format = (DumpFormat)(r.dump_format | DumpFormat::JSON);
292295
r.dump_file_json = p.value("dump-to-json");
293296
}
297+
if (p.isSet("disable-console-dump")) {
298+
r.dump_format = (DumpFormat)(r.dump_format & ~(DumpFormat::CONSOLE));
299+
}
294300
if (p.isSet("dump-registers")) { r.enable_regs_reporting(); }
295301
if (p.isSet("dump-cache-stats")) { r.enable_cache_stats(); }
296302
if (p.isSet("dump-cycles")) { r.enable_cycles_reporting(); }
303+
if (p.isSet("dump-symbol-table")) { r.enable_symbol_table_reporting(); }
297304

298305
QStringList fail = p.values("fail-match");
299306
for (const auto & i : fail) {
@@ -542,6 +549,11 @@ int main(int argc, char *argv[]) {
542549

543550
load_ranges(machine, p.values("load-range"));
544551

545-
machine.play();
552+
if (p.isSet("only-dump")) {
553+
QMetaObject::invokeMethod(&machine, &Machine::program_exit, Qt::QueuedConnection);
554+
} else {
555+
// QTimer::singleShot(0, &machine, &Machine::play); alternative
556+
QMetaObject::invokeMethod(&machine, &Machine::play, Qt::QueuedConnection);
557+
}
546558
return QCoreApplication::exec();
547559
}

src/cli/reporter.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ void Reporter::machine_trap(SimulatorException &e) {
8484
}
8585

8686
void Reporter::report() {
87-
if (e_regs | e_cycles | e_cycles | e_fail) { printf("Machine state report:\n"); }
87+
if (dump_format & DumpFormat::CONSOLE) {
88+
if (e_regs | e_cycles | e_cycles | e_fail) { printf("Machine state report:\n"); }
89+
}
8890

8991
if (e_regs) { report_regs(); }
9092
if (e_cache_stats) { report_caches(); }
@@ -106,15 +108,35 @@ void Reporter::report() {
106108
report_range(range);
107109
}
108110

111+
if (e_symtab) {
112+
QJsonObject symtab_json = {};
113+
114+
for (const auto &name : machine->symbol_table()->names()) {
115+
SymbolValue sym_val;
116+
machine->symbol_table()->name_to_value(sym_val, name);
117+
QString value = QString::asprintf(machine->core()->get_xlen() == Xlen::_32 ? "0x%08" PRIx64 : "0x%016" PRIx64, sym_val);
118+
if (dump_format & DumpFormat::JSON) {
119+
symtab_json[name] = value;
120+
}
121+
if (dump_format & DumpFormat::CONSOLE) {
122+
printf("SYM[%s]: %s\n", qPrintable(name), qPrintable(value));
123+
}
124+
}
125+
126+
if (dump_format & DumpFormat::JSON) {
127+
dump_data_json["symbols"] = symtab_json;
128+
}
129+
}
130+
109131
if (dump_format & DumpFormat::JSON) {
110132
QFile file(dump_file_json);
111133
QByteArray bytes = QJsonDocument(dump_data_json).toJson(QJsonDocument::Indented);
112134
if (file.open(QIODevice::WriteOnly)) {
113135
file.write(bytes);
114136
file.close();
115-
printf("JSON object written to file");
137+
printf("JSON object written to file\n");
116138
} else {
117-
printf("Could not open file for writing");
139+
printf("Could not open file for writing\n");
118140
}
119141
}
120142
}

src/cli/reporter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class Reporter : public QObject {
3131
void enable_regs_reporting() { e_regs = true; };
3232
void enable_cache_stats() { e_cache_stats = true; };
3333
void enable_cycles_reporting() { e_cycles = true; };
34+
void enable_symbol_table_reporting() { e_symtab = true; };
3435

3536
enum FailReason {
3637
FR_NONE = 0,
@@ -63,6 +64,7 @@ private slots:
6364
bool e_regs = false;
6465
bool e_cache_stats = false;
6566
bool e_cycles = false;
67+
bool e_symtab = false;
6668
FailReason e_fail = FR_NONE;
6769

6870
void report();

src/machine/memory/backend/lcddisplay.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ bool LcdDisplay::write_raw_pixel(Offset destination, uint16_t value) {
7676
Q_ASSERT((destination & 1U) == 0); // uint16_t aligned
7777

7878
if (destination + 1 >= get_fb_size_bytes()) {
79-
printf("WARNING: LCD display - read out of range.");
79+
printf("WARNING: LCD display - read out of range.\n");
8080
return false;
8181
}
8282

src/os_emulation/ossyscall.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ int OsSyscallExceptionHandler::do_sys_openat(
10521052

10531053
result = 0;
10541054
if (int64_t(a1) != TARGET_AT_FDCWD) {
1055-
printf("Unimplemented openat argument a1 %" PRId64, a1);
1055+
printf("Unimplemented openat argument a1 %" PRId64 "\n", a1);
10561056
if (unknown_syscall_stop) { emit core->stop_on_exception_reached(); }
10571057
return TARGET_ENOSYS;
10581058
}

0 commit comments

Comments
 (0)