Skip to content

Commit e76e7e9

Browse files
author
Ted Woodward
committed
Add Hexagon packet support to ThreadPlanStepRange
Summary: Hexagon is a VLIW processor. It can execute multiple instructions at once, called a packet. Breakpoints need to be alone in a packet. This patch will make sure that temporary breakpoints used for stepping are set at the start of a packet, which will put the breakpoint in a packet by itself. Patch by Deepak Panickal of CodePlay and Ted Woodward of Qualcomm. Reviewers: deepak2427, clayborg Reviewed By: clayborg Subscribers: lldb-commits Differential Revision: http://reviews.llvm.org/D9437 llvm-svn: 237047
1 parent 5b20296 commit e76e7e9

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

lldb/include/lldb/Core/Disassembler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class InstructionList
225225
GetInstructionAtIndex (size_t idx) const;
226226

227227
uint32_t
228-
GetIndexOfNextBranchInstruction(uint32_t start) const;
228+
GetIndexOfNextBranchInstruction(uint32_t start, Target &target) const;
229229

230230
uint32_t
231231
GetIndexOfInstructionAtLoadAddress (lldb::addr_t load_addr, Target &target);

lldb/source/Core/Disassembler.cpp

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,19 +1061,66 @@ InstructionList::Append (lldb::InstructionSP &inst_sp)
10611061
}
10621062

10631063
uint32_t
1064-
InstructionList::GetIndexOfNextBranchInstruction(uint32_t start) const
1064+
InstructionList::GetIndexOfNextBranchInstruction(uint32_t start, Target &target) const
10651065
{
10661066
size_t num_instructions = m_instructions.size();
10671067

10681068
uint32_t next_branch = UINT32_MAX;
1069-
for (size_t i = start; i < num_instructions; i++)
1069+
size_t i;
1070+
for (i = start; i < num_instructions; i++)
10701071
{
10711072
if (m_instructions[i]->DoesBranch())
10721073
{
10731074
next_branch = i;
10741075
break;
10751076
}
10761077
}
1078+
1079+
// Hexagon needs the first instruction of the packet with the branch.
1080+
// Go backwards until we find an instruction marked end-of-packet, or
1081+
// until we hit start.
1082+
if (target.GetArchitecture().GetTriple().getArch() == llvm::Triple::hexagon)
1083+
{
1084+
// If we didn't find a branch, find the last packet start.
1085+
if (next_branch == UINT32_MAX)
1086+
{
1087+
i = num_instructions - 1;
1088+
}
1089+
1090+
while (i > start)
1091+
{
1092+
--i;
1093+
1094+
Error error;
1095+
uint32_t inst_bytes;
1096+
bool prefer_file_cache = false; // Read from process if process is running
1097+
lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
1098+
target.ReadMemory(m_instructions[i]->GetAddress(),
1099+
prefer_file_cache,
1100+
&inst_bytes,
1101+
sizeof(inst_bytes),
1102+
error,
1103+
&load_addr);
1104+
// If we have an error reading memory, return start
1105+
if (!error.Success())
1106+
return start;
1107+
// check if this is the last instruction in a packet
1108+
// bits 15:14 will be 11b or 00b for a duplex
1109+
if (((inst_bytes & 0xC000) == 0xC000) ||
1110+
((inst_bytes & 0xC000) == 0x0000))
1111+
{
1112+
// instruction after this should be the start of next packet
1113+
next_branch = i + 1;
1114+
break;
1115+
}
1116+
}
1117+
1118+
if (next_branch == UINT32_MAX)
1119+
{
1120+
// We couldn't find the previous packet, so return start
1121+
next_branch = start;
1122+
}
1123+
}
10771124
return next_branch;
10781125
}
10791126

lldb/source/Target/ThreadPlanStepRange.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,9 @@ ThreadPlanStepRange::SetNextBranchBreakpoint ()
380380
return false;
381381
else
382382
{
383+
Target &target = GetThread().GetProcess()->GetTarget();
383384
uint32_t branch_index;
384-
branch_index = instructions->GetIndexOfNextBranchInstruction (pc_index);
385+
branch_index = instructions->GetIndexOfNextBranchInstruction (pc_index, target);
385386

386387
Address run_to_address;
387388

0 commit comments

Comments
 (0)