This is an automated email from Gerrit. "Antonio Borneo <[email protected]>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/9510
-- gerrit commit 8536f7cac13be6c6750929b3a462d4f05080bc6e Author: Antonio Borneo <[email protected]> Date: Mon Mar 16 18:13:10 2026 +0100 target: arm: deprecate command 'arm disassemble' Deprecate the old command and fallback to the new one. Drop the old implementation of arm_disassemble(). While there, remove the include of "arm_disassembler.h" from the files that don't need it. Change-Id: Icd78805be623c2f737551c5ab8ace27d959d8757 Signed-off-by: Antonio Borneo <[email protected]> diff --git a/doc/openocd.texi b/doc/openocd.texi index e392f88db3..cae828543e 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -10513,24 +10513,6 @@ The target may later be resumed in the currently set core_state. that is not currently supported in OpenOCD.) @end deffn -@deffn {Command} {arm disassemble} address [count [@option{thumb}]] -@cindex disassemble -Disassembles @var{count} instructions starting at @var{address}. -If @var{count} is not specified, a single instruction is disassembled. -If @option{thumb} is specified, or the low bit of the address is set, -Thumb2 (mixed 16/32-bit) instructions are used; -else ARM (32-bit) instructions are used. -(Processors may also support the Jazelle state, but -those instructions are not currently understood by OpenOCD.) - -Note that all Thumb instructions are Thumb2 instructions, -so older processors (without Thumb2 support) will still -see correct disassembly of Thumb code. -Also, ThumbEE opcodes are the same as Thumb2, -with a handful of exceptions. -ThumbEE disassembly currently has no explicit support. -@end deffn - @deffn {Command} {arm mcr} pX op1 CRn CRm op2 value Write @var{value} to a coprocessor @var{pX} register passing parameters @var{CRn}, diff --git a/src/target/arm_disassembler.c b/src/target/arm_disassembler.c index 6dea19f935..0a89db6d73 100644 --- a/src/target/arm_disassembler.c +++ b/src/target/arm_disassembler.c @@ -15,10 +15,6 @@ #include "arm_disassembler.h" #include <helper/log.h> -#if HAVE_CAPSTONE -#include <capstone.h> -#endif - /* * This disassembler supports two main functions for OpenOCD: * @@ -3018,100 +3014,3 @@ int arm_access_size(struct arm_instruction *instruction) return 0; } } - -#if HAVE_CAPSTONE -static void print_opcode(struct command_invocation *cmd, const cs_insn *insn) -{ - uint32_t opcode = 0; - - memcpy(&opcode, insn->bytes, insn->size); - - if (insn->size == 4) { - uint16_t opcode_high = opcode >> 16; - opcode = opcode & 0xffff; - - command_print(cmd, "0x%08" PRIx64" %04x %04x\t%s%s%s", - insn->address, opcode, opcode_high, insn->mnemonic, - insn->op_str[0] ? "\t" : "", insn->op_str); - } else { - command_print(cmd, "0x%08" PRIx64" %04x\t%s%s%s", - insn->address, opcode, insn->mnemonic, - insn->op_str[0] ? "\t" : "", insn->op_str); - } -} - -int arm_disassemble(struct command_invocation *cmd, struct target *target, - target_addr_t address, size_t count, bool thumb_mode) -{ - csh handle; - int ret; - cs_insn *insn; - cs_mode mode; - - if (!cs_support(CS_ARCH_ARM)) { - LOG_ERROR("ARM architecture not supported by capstone"); - return ERROR_FAIL; - } - - mode = CS_MODE_LITTLE_ENDIAN; - - if (thumb_mode) - mode |= CS_MODE_THUMB; - - ret = cs_open(CS_ARCH_ARM, mode, &handle); - - if (ret != CS_ERR_OK) { - LOG_ERROR("cs_open() failed: %s", cs_strerror(ret)); - return ERROR_FAIL; - } - - ret = cs_option(handle, CS_OPT_SKIPDATA, CS_OPT_ON); - - if (ret != CS_ERR_OK) { - LOG_ERROR("cs_option() failed: %s", cs_strerror(ret)); - cs_close(&handle); - return ERROR_FAIL; - } - - insn = cs_malloc(handle); - - if (!insn) { - LOG_ERROR("cs_malloc() failed\n"); - cs_close(&handle); - return ERROR_FAIL; - } - - while (count > 0) { - uint8_t buffer[4]; - - ret = target_read_buffer(target, address, sizeof(buffer), buffer); - - if (ret != ERROR_OK) { - cs_free(insn, 1); - cs_close(&handle); - return ret; - } - - size_t size = sizeof(buffer); - const uint8_t *tmp = buffer; - - ret = cs_disasm_iter(handle, &tmp, &size, &address, insn); - - if (!ret) { - LOG_ERROR("cs_disasm_iter() failed: %s", - cs_strerror(cs_errno(handle))); - cs_free(insn, 1); - cs_close(&handle); - return ERROR_FAIL; - } - - print_opcode(cmd, insn); - count--; - } - - cs_free(insn, 1); - cs_close(&handle); - - return ERROR_OK; -} -#endif /* HAVE_CAPSTONE */ diff --git a/src/target/arm_disassembler.h b/src/target/arm_disassembler.h index 8317da997b..25b4423466 100644 --- a/src/target/arm_disassembler.h +++ b/src/target/arm_disassembler.h @@ -187,10 +187,6 @@ int arm_evaluate_opcode(uint32_t opcode, uint32_t address, int thumb_evaluate_opcode(uint16_t opcode, uint32_t address, struct arm_instruction *instruction); int arm_access_size(struct arm_instruction *instruction); -#if HAVE_CAPSTONE -int arm_disassemble(struct command_invocation *cmd, struct target *target, - target_addr_t address, size_t count, bool thumb_mode); -#endif #define COND(opcode) (arm_condition_strings[(opcode & 0xf0000000) >> 28]) diff --git a/src/target/armv4_5.c b/src/target/armv4_5.c index 1cf4e8ff1a..cb55a5a1ff 100644 --- a/src/target/armv4_5.c +++ b/src/target/armv4_5.c @@ -22,7 +22,6 @@ #include "armv4_5.h" #include "arm_jtag.h" #include "breakpoints.h" -#include "arm_disassembler.h" #include <helper/binarybuffer.h> #include "algorithm.h" #include "register.h" @@ -950,61 +949,6 @@ COMMAND_HANDLER(handle_arm_core_state_command) return ret; } -COMMAND_HANDLER(handle_arm_disassemble_command) -{ -#if HAVE_CAPSTONE - struct target *target = get_current_target(CMD_CTX); - - if (!target) { - command_print(CMD, "No target selected"); - return ERROR_FAIL; - } - - struct arm *arm = target_to_arm(target); - target_addr_t address; - unsigned int count = 1; - bool thumb = false; - - if (!is_arm(arm)) { - command_print(CMD, "current target isn't an ARM"); - return ERROR_FAIL; - } - - if (arm->core_type == ARM_CORE_TYPE_M_PROFILE) { - /* armv7m is always thumb mode */ - thumb = true; - } - - switch (CMD_ARGC) { - case 3: - if (strcmp(CMD_ARGV[2], "thumb") != 0) - return ERROR_COMMAND_SYNTAX_ERROR; - thumb = true; - /* FALL THROUGH */ - case 2: - COMMAND_PARSE_NUMBER(uint, CMD_ARGV[1], count); - /* FALL THROUGH */ - case 1: - COMMAND_PARSE_ADDRESS(CMD_ARGV[0], address); - if (address & 0x01) { - if (!thumb) { - command_print(CMD, "Disassemble as Thumb"); - thumb = true; - } - address &= ~1; - } - break; - default: - return ERROR_COMMAND_SYNTAX_ERROR; - } - - return arm_disassemble(CMD, target, address, count, thumb); -#else - command_print(CMD, "capstone disassembly framework required"); - return ERROR_FAIL; -#endif -} - COMMAND_HANDLER(handle_armv4_5_mcrmrc) { bool is_mcr = false; @@ -1247,13 +1191,6 @@ const struct command_registration arm_all_profiles_command_handlers[] = { .usage = "['arm'|'thumb']", .help = "display/change ARM core state", }, - { - .name = "disassemble", - .handler = handle_arm_disassemble_command, - .mode = COMMAND_EXEC, - .usage = "address [count ['thumb']]", - .help = "disassemble instructions", - }, { .chain = semihosting_common_handlers, }, diff --git a/src/target/armv7a.c b/src/target/armv7a.c index 9cde67788f..7336a73402 100644 --- a/src/target/armv7a.c +++ b/src/target/armv7a.c @@ -14,7 +14,6 @@ #include "armv7a.h" #include "armv7a_mmu.h" -#include "arm_disassembler.h" #include "register.h" #include <helper/binarybuffer.h> diff --git a/src/target/armv8.c b/src/target/armv8.c index a369a30418..d06fae4e0f 100644 --- a/src/target/armv8.c +++ b/src/target/armv8.c @@ -14,7 +14,6 @@ #include <helper/replacements.h> #include "armv8.h" -#include "arm_disassembler.h" #include "register.h" #include <helper/binarybuffer.h> diff --git a/src/target/cortex_m.c b/src/target/cortex_m.c index b34bed4202..f8b6164af9 100644 --- a/src/target/cortex_m.c +++ b/src/target/cortex_m.c @@ -25,7 +25,6 @@ #include "target_request.h" #include "target_type.h" #include "arm_adi_v5.h" -#include "arm_disassembler.h" #include "register.h" #include "arm_opcodes.h" #include "arm_semihosting.h" diff --git a/src/target/startup.tcl b/src/target/startup.tcl index 1cc9bb7fda..0b463dde08 100644 --- a/src/target/startup.tcl +++ b/src/target/startup.tcl @@ -295,6 +295,12 @@ proc "mips_m4k smp_off" {args} { eval mips_m4k smp off $args } +lappend _telnet_autocomplete_skip "arm disassemble" +proc "arm disassemble" {args} { + echo "DEPRECATED! use 'disassemble $args'" + eval disassemble $args +} + lappend _telnet_autocomplete_skip _post_init_target_cortex_a_cache_auto proc _post_init_target_cortex_a_cache_auto {} { set cortex_a_found 0 --
