From 21e484aea9033ba164c993650b4c5dc25b43d7aa Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Thu, 16 Jun 2011 22:45:40 +0000 Subject: [PATCH] * Add previous/next block navigation buttons. * Fix a calculation error with respect to the last line of the block. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42216 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../gui/inspector_window/InspectorWindow.cpp | 99 +++++++++++++++---- .../gui/inspector_window/InspectorWindow.h | 2 + .../gui/inspector_window/MemoryView.cpp | 4 +- 3 files changed, 82 insertions(+), 23 deletions(-) diff --git a/src/apps/debugger/user_interface/gui/inspector_window/InspectorWindow.cpp b/src/apps/debugger/user_interface/gui/inspector_window/InspectorWindow.cpp index 1327e7fd4d..1f6a10320e 100644 --- a/src/apps/debugger/user_interface/gui/inspector_window/InspectorWindow.cpp +++ b/src/apps/debugger/user_interface/gui/inspector_window/InspectorWindow.cpp @@ -9,7 +9,9 @@ #include #include +#include #include +#include #include #include #include @@ -22,6 +24,12 @@ #include "UserInterface.h" +enum { + MSG_NAVIGATE_PREVIOUS_BLOCK = 'npbl', + MSG_NAVIGATE_NEXT_BLOCK = 'npnl' +}; + + InspectorWindow::InspectorWindow(::Team* team, UserInterfaceListener* listener) : BWindow(BRect(100, 100, 700, 500), "Inspector", B_TITLED_WINDOW, @@ -99,9 +107,15 @@ InspectorWindow::_Init() BLayoutBuilder::Group<>(this, B_VERTICAL) .SetInsets(4.0f, 4.0f, 4.0f, 4.0f) - .Add(fAddressInput = new BTextControl("addrInput", + .AddGroup(B_HORIZONTAL, 4.0f) + .Add(fAddressInput = new BTextControl("addrInput", "Target Address:", "", new BMessage(MSG_INSPECT_ADDRESS))) + .Add(fPreviousBlockButton = new BButton("navPrevious", "<", + new BMessage(MSG_NAVIGATE_PREVIOUS_BLOCK))) + .Add(fNextBlockButton = new BButton("navNext", ">", + new BMessage(MSG_NAVIGATE_NEXT_BLOCK))) + .End() .AddGroup(B_HORIZONTAL, 4.0f) .Add(fHexMode = new BMenuField("outputStyle", "Hex Mode:", hexMenu)) @@ -119,6 +133,10 @@ InspectorWindow::_Init() scrollView->SetTarget(fMemoryView = MemoryView::Create()); fAddressInput->SetTarget(this); + fPreviousBlockButton->SetTarget(this); + fNextBlockButton->SetTarget(this); + fPreviousBlockButton->SetEnabled(false); + fNextBlockButton->SetEnabled(false); hexMenu->SetLabelFromMarked(true); hexMenu->SetTargetForItems(fMemoryView); @@ -138,27 +156,36 @@ InspectorWindow::MessageReceived(BMessage* msg) switch (msg->what) { case MSG_INSPECT_ADDRESS: { - ExpressionParser parser; - parser.SetSupportHexInput(true); target_addr_t address = 0; - const char* addressExpression = fAddressInput->Text(); - BString errorMessage; - try { - address = parser.EvaluateToInt64(addressExpression); - } catch(ParseException parseError) { - errorMessage.SetToFormat("Failed to parse address: %s", - parseError.message.String()); - } catch(...) { - errorMessage.SetToFormat( - "Unknown error while parsing address"); + bool addressValid = false; + if (msg->FindUInt64("address", &address) != B_OK) + { + ExpressionParser parser; + parser.SetSupportHexInput(true); + const char* addressExpression = fAddressInput->Text(); + BString errorMessage; + try { + address = parser.EvaluateToInt64(addressExpression); + } catch(ParseException parseError) { + errorMessage.SetToFormat("Failed to parse address: %s", + parseError.message.String()); + } catch(...) { + errorMessage.SetToFormat( + "Unknown error while parsing address"); + } + + if (errorMessage.Length() > 0) { + BAlert* alert = new(std::nothrow) BAlert("Inspect Address", + errorMessage.String(), "Close"); + if (alert != NULL) + alert->Go(); + } else + addressValid = true; + } else { + addressValid = true; } - if (errorMessage.Length() > 0) { - BAlert* alert = new(std::nothrow) BAlert("Inspect Address", - errorMessage.String(), "Close"); - if (alert != NULL) - alert->Go(); - } else { + if (addressValid) { if (fCurrentBlock != NULL && !fCurrentBlock->Contains(address)) { fCurrentBlock->ReleaseReference(); @@ -177,6 +204,31 @@ InspectorWindow::MessageReceived(BMessage* msg) } break; } + case MSG_NAVIGATE_PREVIOUS_BLOCK: + case MSG_NAVIGATE_NEXT_BLOCK: + { + if (fCurrentBlock != NULL) + { + target_addr_t address = fCurrentBlock->BaseAddress(); + if (msg->what == MSG_NAVIGATE_PREVIOUS_BLOCK) + address -= fCurrentBlock->Size(); + else + address += fCurrentBlock->Size(); + + BMessage setMessage(MSG_INSPECT_ADDRESS); + setMessage.AddUInt64("address", address); + PostMessage(&setMessage); + } + break; + } + { + break; + } + default: + { + BWindow::MessageReceived(msg); + break; + } } } @@ -192,6 +244,11 @@ InspectorWindow::QuitRequested() void InspectorWindow::MemoryBlockRetrieved(TeamMemoryBlock* block) { - fCurrentBlock = block; - fMemoryView->SetTargetAddress(block, fCurrentAddress); + BAutolock lock(this); + if (lock.IsLocked()) { + fCurrentBlock = block; + fMemoryView->SetTargetAddress(block, fCurrentAddress); + fPreviousBlockButton->SetEnabled(true); + fNextBlockButton->SetEnabled(true); + } } diff --git a/src/apps/debugger/user_interface/gui/inspector_window/InspectorWindow.h b/src/apps/debugger/user_interface/gui/inspector_window/InspectorWindow.h index 7b2c9325b0..8c6e985891 100644 --- a/src/apps/debugger/user_interface/gui/inspector_window/InspectorWindow.h +++ b/src/apps/debugger/user_interface/gui/inspector_window/InspectorWindow.h @@ -45,6 +45,8 @@ private: BMenuField* fHexMode; BMenuField* fTextMode; MemoryView* fMemoryView; + BButton* fPreviousBlockButton; + BButton* fNextBlockButton; TeamMemoryBlock* fCurrentBlock; target_addr_t fCurrentAddress; ::Team* fTeam; diff --git a/src/apps/debugger/user_interface/gui/inspector_window/MemoryView.cpp b/src/apps/debugger/user_interface/gui/inspector_window/MemoryView.cpp index 0f2123197d..6348028563 100644 --- a/src/apps/debugger/user_interface/gui/inspector_window/MemoryView.cpp +++ b/src/apps/debugger/user_interface/gui/inspector_window/MemoryView.cpp @@ -163,11 +163,11 @@ MemoryView::Draw(BRect rect) PopState(); if (fHexMode != HexModeNone) { - if (currentAddress + (currentBlocksPerLine * hexBlockSize) + if (currentAddress + (currentBlocksPerLine * blockByteSize) > maxAddress) { currentCharsPerLine = maxAddress - currentAddress; currentBlocksPerLine = currentCharsPerLine - / hexBlockSize; + / blockByteSize; } for (int32 j = 0; j < currentBlocksPerLine; j++) {