Index: include/lldb/Core/Disassembler.h =================================================================== --- include/lldb/Core/Disassembler.h +++ include/lldb/Core/Disassembler.h @@ -225,7 +225,7 @@ GetInstructionAtIndex (size_t idx) const; uint32_t - GetIndexOfNextBranchInstruction(uint32_t start) const; + GetIndexOfNextBranchInstruction(uint32_t start, lldb::ProcessSP &process_sp) const; uint32_t GetIndexOfInstructionAtLoadAddress (lldb::addr_t load_addr, Target &target); Index: source/Core/Disassembler.cpp =================================================================== --- source/Core/Disassembler.cpp +++ source/Core/Disassembler.cpp @@ -1061,12 +1061,13 @@ } uint32_t -InstructionList::GetIndexOfNextBranchInstruction(uint32_t start) const +InstructionList::GetIndexOfNextBranchInstruction(uint32_t start, lldb::ProcessSP &process_sp) const { size_t num_instructions = m_instructions.size(); uint32_t next_branch = UINT32_MAX; - for (size_t i = start; i < num_instructions; i++) + size_t i; + for (i = start; i < num_instructions; i++) { if (m_instructions[i]->DoesBranch()) { @@ -1074,6 +1075,47 @@ break; } } + + // Hexagon needs the first instruction of the packet with the branch. + // Go backwards until we find an instruction marked end-of-packet, or + // until we hit start. + if (process_sp->GetTarget().GetArchitecture().GetTriple().getArch() == llvm::Triple::hexagon) + { + // If we didn't find a branch, find the last packet start. + if (next_branch == UINT32_MAX) + { + i = num_instructions - 1; + } + + while (i > start) + { + --i; + + Error error; + uint32_t inst_bytes; + Target &target = process_sp->GetTarget(); + lldb::addr_t addr = m_instructions[i]->GetAddress().GetLoadAddress(&target); + process_sp->ReadMemory(addr, &inst_bytes, sizeof(inst_bytes), error); + // If we have an error reading memory, return start + if (!error.Success()) + return start; + // check if this is the last instruction in a packet + // bits 15:14 will be 11b or 00b for a duplex + if (((inst_bytes & 0xC000) == 0xC000) || + ((inst_bytes & 0xC000) == 0x0000)) + { + // instruction after this should be the start of next packet + next_branch = i + 1; + break; + } + } + + if (next_branch == UINT32_MAX) + { + // We couldn't find the previous packet, so return start + next_branch = start; + } + } return next_branch; } Index: source/Target/ThreadPlanStepRange.cpp =================================================================== --- source/Target/ThreadPlanStepRange.cpp +++ source/Target/ThreadPlanStepRange.cpp @@ -380,8 +380,9 @@ return false; else { + ProcessSP process_sp(GetThread().GetProcess()); uint32_t branch_index; - branch_index = instructions->GetIndexOfNextBranchInstruction (pc_index); + branch_index = instructions->GetIndexOfNextBranchInstruction (pc_index, process_sp); Address run_to_address;