From ed6d6081c133128d1f2c297303f2c3d27d465d7b Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Thu, 16 May 2013 21:18:43 -0400 Subject: [PATCH] Implement "Set next statement". Adds a context menu command allowing the user to specify that the active thread should be set to execute the specified statement next, by updating its instruction pointer. Implements second part of #9709. Note that care needs to be taken with this feature for now, as it doesn't yet sanity check the requested address. Setting the target to e.g. a statement in an entirely different function is likely to have unpredictable/unstable effects on the debugged program. --- .../gui/team_window/SourceView.cpp | 52 +++++++++++++------ 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/src/apps/debugger/user_interface/gui/team_window/SourceView.cpp b/src/apps/debugger/user_interface/gui/team_window/SourceView.cpp index c43e084936..1da9f89f45 100644 --- a/src/apps/debugger/user_interface/gui/team_window/SourceView.cpp +++ b/src/apps/debugger/user_interface/gui/team_window/SourceView.cpp @@ -314,6 +314,10 @@ private: void _ScrollToTop(); void _ScrollToBottom(); + bool _AddContextItem(BPopUpMenu* menu, + const char* text, uint32 what, + target_addr_t address) const; + private: float fMaxLineWidth; @@ -1255,31 +1259,20 @@ SourceView::TextView::MouseDown(BPoint where) if (!fSourceView->GetStatementForLine(line, statement)) return; BReference statementReference(statement, true); + target_addr_t address = statement->CoveringAddressRange().Start(); BPopUpMenu* menu = new(std::nothrow) BPopUpMenu(""); if (menu == NULL) return; ObjectDeleter menuDeleter(menu); - BMessage* message = new(std::nothrow) BMessage(MSG_THREAD_RUN); - if (message == NULL) - return; - ObjectDeleter messageDeleter(message); - - message->AddUInt64("address", statement->CoveringAddressRange() - .Start()); - BMenuItem* item = new(std::nothrow) BMenuItem("Run to cursor", - message); - if (item == NULL) - return; - ObjectDeleter itemDeleter(item); - messageDeleter.Detach(); - - if (!menu->AddItem(item)) + if (!_AddContextItem(menu, "Run to cursor", MSG_THREAD_RUN, address)) return; - itemDeleter.Detach(); - messageDeleter.Detach(); + if (!_AddContextItem(menu, "Set next statement", + MSG_THREAD_SET_ADDRESS, address)) { + return; + } menuDeleter.Detach(); BPoint screenWhere(where); @@ -1743,6 +1736,30 @@ SourceView::TextView::_ScrollToBottom(void) } +bool +SourceView::TextView::_AddContextItem(BPopUpMenu* menu, const char* text, + uint32 what, target_addr_t address) const +{ + BMessage* message = new(std::nothrow) BMessage(what); + if (message == NULL) + return false; + ObjectDeleter messageDeleter(message); + + message->AddUInt64("address", address); + BMenuItem* item = new(std::nothrow) BMenuItem(text, message); + if (item == NULL) + return false; + ObjectDeleter itemDeleter(item); + messageDeleter.Detach(); + + if (!menu->AddItem(item)) + return false; + + itemDeleter.Detach(); + return true; +} + + // #pragma mark - SourceView @@ -1795,6 +1812,7 @@ SourceView::MessageReceived(BMessage* message) { switch(message->what) { case MSG_THREAD_RUN: + case MSG_THREAD_SET_ADDRESS: { target_addr_t address; if (message->FindUInt64("address", &address) != B_OK)