Added a disassembly format 'i' to command line interface mem get command.
Updated prompt to include the name of the function the current instruction
is in the range of.
PiperOrigin-RevId: 642020787
Change-Id: I71d4c358f705ec7a92d7fc48182a2dde27a2da34
diff --git a/cheriot/debug_command_shell.cc b/cheriot/debug_command_shell.cc
index 46ad147..cbb9ff9 100644
--- a/cheriot/debug_command_shell.cc
+++ b/cheriot/debug_command_shell.cc
@@ -67,8 +67,8 @@
write_reg_re_{R"(\s*reg\s+set\s+(\$?\w+)\s+(\w+)\s*)"},
rd_vreg_re_{R"(\s*vreg(?:\s+get)?\s+(\$?\w+)(?:(?:\s*\:(\d+))?)"
R"((?:\s+(?:([oduxX])(8|16|32|64))?)?)?\s*)"},
- read_mem_re_{R"(\s*mem\s+get\s+(\w+)(?:\s+([foduxX]\d+)?)?\s*)"},
- read_mem2_re_{R"(\s*mem\s+(\w+)(?:\s+([foduxX]\d+)?)?\s*)"},
+ read_mem_re_{R"(\s*mem\s+get\s+(\w+)(?:\s+([foduxX]\d+|i)?)?\s*)"},
+ read_mem2_re_{R"(\s*mem\s+(\w+)(?:\s+([foduxX]\d+|i)?)?\s*)"},
write_mem_re_{R"(\s*mem\s+set\s+(\w+)\s+([oduxX]\d+)?\s+(\w+)\s*)"},
set_break_re_{R"(\s*break\s+set\s+(\$?\w+)\s*)"},
set_break2_re_{R"(\s*break\s+(\$?\w+)\s*)"},
@@ -233,6 +233,10 @@
if (pcc_result.ok()) {
auto *loader = core_access_[current_core_].loader_getter();
if (loader != nullptr) {
+ auto fcn_result = loader->GetFunctionName(pcc_result.value());
+ if (fcn_result.ok()) {
+ absl::StrAppend(&prompt, "[", fcn_result.value(), "]:\n");
+ }
auto symbol_result = loader->GetFcnSymbolName(pcc_result.value());
if (symbol_result.ok()) {
absl::StrAppend(&prompt, symbol_result.value(), ":\n");
@@ -1201,18 +1205,23 @@
char format_char = 'x';
int bit_width = 32;
+ // Get the bit width, but only if the format is not 'i'.
if (!format.empty()) {
- // Check the format specification.
- auto pos = format.find_first_not_of(' ');
- format_char = format[pos];
- auto status = absl::SimpleAtoi(format.substr(pos + 1), &bit_width);
- if (!status) {
- return absl::StrCat("Error '", format.substr(pos + 1),
- "': ", "unable to convert to int");
- }
- if ((bit_width != 8) && (bit_width != 16) && (bit_width != 32) &&
- (bit_width != 64)) {
- return absl::StrCat("Illegal bit width specification: ", bit_width);
+ if (format[0] == 'i') {
+ format_char = 'i';
+ } else {
+ // Check the format specification.
+ auto pos = format.find_first_not_of(' ');
+ format_char = format[pos];
+ auto status = absl::SimpleAtoi(format.substr(pos + 1), &bit_width);
+ if (!status) {
+ return absl::StrCat("Error '", format.substr(pos + 1),
+ "': ", "unable to convert to int");
+ }
+ if ((bit_width != 8) && (bit_width != 16) && (bit_width != 32) &&
+ (bit_width != 64)) {
+ return absl::StrCat("Illegal bit width specification: ", bit_width);
+ }
}
}
@@ -1223,6 +1232,17 @@
}
auto address = result.value();
+ // If format is 'i', then we are getting a disassembled instruction. Ignore
+ // bitwidth.
+ if (format_char == 'i') {
+ auto disasm_result =
+ core_access_[current_core_].debug_interface->GetDisassembly(address);
+ if (!disasm_result.ok()) {
+ return absl::StrCat("Error: ", disasm_result.status().message());
+ }
+ return absl::StrCat(" ", disasm_result.value());
+ }
+
// Perform the memory access.
size = bit_width / 8;
if (size > kMemBufferSize) size = kMemBufferSize;