AArch64: update the behaviour of breakpoint in the debugger.

When hitting a breakpoint, the debugger now stops with the PC pointing *after*
the breakpoint.

Before:

  vixl> disasm 6
  0x0000000002271c58  d2800021        mov x1, #0x1
  0x0000000002271c5c  d2800042        mov x2, #0x2
  0x0000000002271c60  d2800063        mov x3, #0x3
  0x0000000002271c64  d2800084        mov x4, #0x4
  0x0000000002271c68  d4200020        brk #0x1
  0x0000000002271c6c  d28000a5        mov x5, #0x5
  vixl> c
  Hit breakpoint at pc=0x2271c68.
  Next: 0x0000000002271c68  d4200020  brk #0x1
  vixl>

After:

  vixl> disasm 6
  0x000000000118dc58  d2800021        mov x1, #0x1
  0x000000000118dc5c  d2800042        mov x2, #0x2
  0x000000000118dc60  d2800063        mov x3, #0x3
  0x000000000118dc64  d2800084        mov x4, #0x4
  0x000000000118dc68  d4200020        brk #0x1
  0x000000000118dc6c  d28000a5        mov x5, #0x5
  vixl> c
  Hit breakpoint at pc=0x118dc68.
  Next: 0x000000000118dc6c  d28000a5  mov x5, #0x5

Change-Id: Ia14e030cd1fa4ab73e49ec0782c91c04fc4fcc5e
This commit is contained in:
Alexandre Rames 2016-07-21 10:31:16 +01:00
parent 86af869710
commit 0d68001a97
2 changed files with 17 additions and 59 deletions

View File

@ -561,8 +561,7 @@ const char* RegisterToken::kWAliases[kNumberOfRegisters][kMaxAliasNumber] =
Debugger::Debugger(Decoder* decoder, FILE* stream)
: Simulator(decoder, stream),
debug_parameters_(DBG_INACTIVE),
pending_request_(false),
debugger_active_(false),
steps_(0),
last_command_(NULL) {
disasm_ = new PrintDisassembler(stdout);
@ -582,7 +581,7 @@ void Debugger::Run() {
LogAllWrittenRegisters();
while (pc_ != kEndOfSimAddress) {
if (HasPendingRequest()) RunDebuggerShell();
if (IsDebuggerActive()) RunDebuggerShell();
ExecuteInstruction();
}
}
@ -734,7 +733,7 @@ char* Debugger::ReadCommandLine(const char* prompt, char* buffer, int length) {
void Debugger::RunDebuggerShell() {
if (IsDebuggerRunning()) {
if (IsDebuggerActive()) {
if (steps_ > 0) {
// Finish stepping first.
--steps_;
@ -760,12 +759,6 @@ void Debugger::RunDebuggerShell() {
printf("No previous command to run!\n");
}
}
if ((debug_parameters_ & DBG_BREAK) != 0) {
// The break request has now been handled, move to next instruction.
debug_parameters_ &= ~DBG_BREAK;
pc_ = pc_->GetNextInstruction();
}
}
}
@ -774,9 +767,7 @@ void Debugger::DoBreakpoint(const Instruction* instr) {
VIXL_ASSERT(instr->Mask(ExceptionMask) == BRK);
printf("Hit breakpoint at pc=%p.\n", reinterpret_cast<const void*>(instr));
SetDebugParameters(GetDebugParameters() | DBG_BREAK | DBG_ACTIVE);
// Make the shell point to the brk instruction.
WritePc(instr);
ActivateDebugger();
}
@ -1208,7 +1199,7 @@ void DebugCommand::PrintHelp(const char** aliases,
bool HelpCommand::Run(Debugger* debugger) {
VIXL_ASSERT(debugger->IsDebuggerRunning());
VIXL_ASSERT(debugger->IsDebuggerActive());
USE(debugger);
#define PRINT_HELP(Command) \
@ -1233,9 +1224,9 @@ DebugCommand* HelpCommand::Build(std::vector<Token*> args) {
bool ContinueCommand::Run(Debugger* debugger) {
VIXL_ASSERT(debugger->IsDebuggerRunning());
VIXL_ASSERT(debugger->IsDebuggerActive());
debugger->SetDebugParameters(debugger->GetDebugParameters() & ~DBG_ACTIVE);
debugger->DeactivateDebugger();
return true;
}
@ -1250,7 +1241,7 @@ DebugCommand* ContinueCommand::Build(std::vector<Token*> args) {
bool StepCommand::Run(Debugger* debugger) {
VIXL_ASSERT(debugger->IsDebuggerRunning());
VIXL_ASSERT(debugger->IsDebuggerActive());
// To avoid recursive calls to the debugger shell when hitting breakpoints
// while stepping, stepping is implemented by telling the debugger how many
@ -1301,7 +1292,7 @@ DebugCommand* StepCommand::Build(std::vector<Token*> args) {
bool SkipCommand::Run(Debugger* debugger) {
VIXL_ASSERT(debugger->IsDebuggerRunning());
VIXL_ASSERT(debugger->IsDebuggerActive());
int64_t steps = count();
if (steps < 0) {
@ -1379,7 +1370,7 @@ void PrintCommand::Print(FILE* out) {
bool PrintCommand::Run(Debugger* debugger) {
VIXL_ASSERT(debugger->IsDebuggerRunning());
VIXL_ASSERT(debugger->IsDebuggerActive());
Token* tok = target();
if (tok->IsIdentifier()) {
@ -1503,7 +1494,7 @@ DebugCommand* PrintCommand::Build(std::vector<Token*> args) {
bool ExamineCommand::Run(Debugger* debugger) {
VIXL_ASSERT(debugger->IsDebuggerRunning());
VIXL_ASSERT(debugger->IsDebuggerActive());
uint8_t* address = target()->ToAddress(debugger);
int64_t amount = count()->value();
@ -1586,7 +1577,7 @@ UnknownCommand::~UnknownCommand() {
bool UnknownCommand::Run(Debugger* debugger) {
VIXL_ASSERT(debugger->IsDebuggerRunning());
VIXL_ASSERT(debugger->IsDebuggerActive());
USE(debugger);
printf(" ** Unknown Command:");
@ -1610,7 +1601,7 @@ InvalidCommand::~InvalidCommand() {
bool InvalidCommand::Run(Debugger* debugger) {
VIXL_ASSERT(debugger->IsDebuggerRunning());
VIXL_ASSERT(debugger->IsDebuggerActive());
USE(debugger);
printf(" ** Invalid Command:");

View File

@ -44,13 +44,6 @@
namespace vixl {
namespace aarch64 {
// Flags that represent the debugger state.
enum DebugParameters {
DBG_INACTIVE = 0,
DBG_ACTIVE = 1 << 0, // The debugger is active.
DBG_BREAK = 1 << 1 // The debugger is at a breakpoint.
};
// Forward declarations.
class DebugCommand;
class Token;
@ -64,20 +57,9 @@ class Debugger : public Simulator {
virtual void Run();
virtual void VisitException(const Instruction* instr);
int GetDebugParameters() const { return debug_parameters_; }
VIXL_DEPRECATED("GetDebugParameters", int debug_parameters() const) {
return GetDebugParameters();
}
void SetDebugParameters(int parameters) {
debug_parameters_ = parameters;
UpdatePendingRequestStatus();
}
VIXL_DEPRECATED("SetDebugParameters",
void set_debug_parameters(int parameters)) {
return SetDebugParameters(parameters);
}
bool IsDebuggerActive() const { return debugger_active_; }
void ActivateDebugger() { debugger_active_ = true; }
void DeactivateDebugger() { debugger_active_ = false; }
// Numbers of instructions to execute before the debugger shell is given
// back control.
@ -92,20 +74,6 @@ class Debugger : public Simulator {
return SetSteps(value);
}
bool IsDebuggerRunning() const {
return (debug_parameters_ & DBG_ACTIVE) != 0;
}
bool HasPendingRequest() const { return pending_request_; }
VIXL_DEPRECATED("HasPendingRequest", bool pending_request() const) {
return HasPendingRequest();
}
void UpdatePendingRequestStatus() { pending_request_ = IsDebuggerRunning(); }
VIXL_DEPRECATED("UpdatePendingRequestStatus", void update_pending_request()) {
UpdatePendingRequestStatus();
}
void PrintInstructions(const void* address,
int64_t count = 1,
const char* prefix = "");
@ -124,8 +92,7 @@ class Debugger : public Simulator {
void RunDebuggerShell();
void DoBreakpoint(const Instruction* instr);
int debug_parameters_;
bool pending_request_;
bool debugger_active_;
int64_t steps_;
DebugCommand* last_command_;
PrintDisassembler* disasm_;