From 01aa53440b04d51c30ce1f96eab2779f88414cad Mon Sep 17 00:00:00 2001 From: Jason Molenda Date: Mon, 22 Jul 2013 22:11:53 +0000 Subject: [PATCH] When a Cortex-M3 target is selected (armv7m), force disassembly to be in thumb mode. , llvm-svn: 186881 --- .../Disassembler/llvm/DisassemblerLLVMC.cpp | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp b/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp index 437860101e0f..233515a23f20 100644 --- a/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp +++ b/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp @@ -613,17 +613,9 @@ DisassemblerLLVMC::DisassemblerLLVMC (const ArchSpec &arch, const char *flavor_s } } - m_disasm_ap.reset (new LLVMCDisassembler(triple, flavor, *this)); - if (!m_disasm_ap->IsValid()) - { - // We use m_disasm_ap.get() to tell whether we are valid or not, so if this isn't good for some reason, - // we reset it, and then we won't be valid and FindPlugin will fail and we won't get used. - m_disasm_ap.reset(); - } - + ArchSpec thumb_arch(arch); if (arch.GetTriple().getArch() == llvm::Triple::arm) { - ArchSpec thumb_arch(arch); std::string thumb_arch_name (thumb_arch.GetTriple().getArchName().str()); // Replace "arm" with "thumb" so we get all thumb variants correct if (thumb_arch_name.size() > 3) @@ -636,6 +628,27 @@ DisassemblerLLVMC::DisassemblerLLVMC (const ArchSpec &arch, const char *flavor_s thumb_arch_name = "thumbv7"; } thumb_arch.GetTriple().setArchName(llvm::StringRef(thumb_arch_name.c_str())); + } + + // Cortex-M3 devices (e.g. armv7m) can only execute thumb (T2) instructions, + // so hardcode the primary disassembler to thumb mode. + if (arch.GetTriple().getArch() == llvm::Triple::arm + && (arch.GetCore() == ArchSpec::Core::eCore_arm_armv7m || arch.GetCore() == ArchSpec::Core::eCore_arm_armv7em)) + { + triple = thumb_arch.GetTriple().getTriple().c_str(); + } + + m_disasm_ap.reset (new LLVMCDisassembler(triple, flavor, *this)); + if (!m_disasm_ap->IsValid()) + { + // We use m_disasm_ap.get() to tell whether we are valid or not, so if this isn't good for some reason, + // we reset it, and then we won't be valid and FindPlugin will fail and we won't get used. + m_disasm_ap.reset(); + } + + // For arm CPUs that can execute arm or thumb instructions, also create a thumb instruction disassembler. + if (arch.GetTriple().getArch() == llvm::Triple::arm) + { std::string thumb_triple(thumb_arch.GetTriple().getTriple()); m_alternate_disasm_ap.reset(new LLVMCDisassembler(thumb_triple.c_str(), flavor, *this)); if (!m_alternate_disasm_ap->IsValid()) -- GitLab