* 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
This commit is contained in:
@@ -9,7 +9,9 @@
|
|||||||
|
|
||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
|
#include <Autolock.h>
|
||||||
#include <Button.h>
|
#include <Button.h>
|
||||||
|
#include <ControlLook.h>
|
||||||
#include <LayoutBuilder.h>
|
#include <LayoutBuilder.h>
|
||||||
#include <ScrollView.h>
|
#include <ScrollView.h>
|
||||||
#include <TextControl.h>
|
#include <TextControl.h>
|
||||||
@@ -22,6 +24,12 @@
|
|||||||
#include "UserInterface.h"
|
#include "UserInterface.h"
|
||||||
|
|
||||||
|
|
||||||
|
enum {
|
||||||
|
MSG_NAVIGATE_PREVIOUS_BLOCK = 'npbl',
|
||||||
|
MSG_NAVIGATE_NEXT_BLOCK = 'npnl'
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
InspectorWindow::InspectorWindow(::Team* team, UserInterfaceListener* listener)
|
InspectorWindow::InspectorWindow(::Team* team, UserInterfaceListener* listener)
|
||||||
:
|
:
|
||||||
BWindow(BRect(100, 100, 700, 500), "Inspector", B_TITLED_WINDOW,
|
BWindow(BRect(100, 100, 700, 500), "Inspector", B_TITLED_WINDOW,
|
||||||
@@ -99,9 +107,15 @@ InspectorWindow::_Init()
|
|||||||
|
|
||||||
BLayoutBuilder::Group<>(this, B_VERTICAL)
|
BLayoutBuilder::Group<>(this, B_VERTICAL)
|
||||||
.SetInsets(4.0f, 4.0f, 4.0f, 4.0f)
|
.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:", "",
|
"Target Address:", "",
|
||||||
new BMessage(MSG_INSPECT_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)
|
.AddGroup(B_HORIZONTAL, 4.0f)
|
||||||
.Add(fHexMode = new BMenuField("outputStyle", "Hex Mode:",
|
.Add(fHexMode = new BMenuField("outputStyle", "Hex Mode:",
|
||||||
hexMenu))
|
hexMenu))
|
||||||
@@ -119,6 +133,10 @@ InspectorWindow::_Init()
|
|||||||
scrollView->SetTarget(fMemoryView = MemoryView::Create());
|
scrollView->SetTarget(fMemoryView = MemoryView::Create());
|
||||||
|
|
||||||
fAddressInput->SetTarget(this);
|
fAddressInput->SetTarget(this);
|
||||||
|
fPreviousBlockButton->SetTarget(this);
|
||||||
|
fNextBlockButton->SetTarget(this);
|
||||||
|
fPreviousBlockButton->SetEnabled(false);
|
||||||
|
fNextBlockButton->SetEnabled(false);
|
||||||
|
|
||||||
hexMenu->SetLabelFromMarked(true);
|
hexMenu->SetLabelFromMarked(true);
|
||||||
hexMenu->SetTargetForItems(fMemoryView);
|
hexMenu->SetTargetForItems(fMemoryView);
|
||||||
@@ -138,27 +156,36 @@ InspectorWindow::MessageReceived(BMessage* msg)
|
|||||||
switch (msg->what) {
|
switch (msg->what) {
|
||||||
case MSG_INSPECT_ADDRESS:
|
case MSG_INSPECT_ADDRESS:
|
||||||
{
|
{
|
||||||
ExpressionParser parser;
|
|
||||||
parser.SetSupportHexInput(true);
|
|
||||||
target_addr_t address = 0;
|
target_addr_t address = 0;
|
||||||
const char* addressExpression = fAddressInput->Text();
|
bool addressValid = false;
|
||||||
BString errorMessage;
|
if (msg->FindUInt64("address", &address) != B_OK)
|
||||||
try {
|
{
|
||||||
address = parser.EvaluateToInt64(addressExpression);
|
ExpressionParser parser;
|
||||||
} catch(ParseException parseError) {
|
parser.SetSupportHexInput(true);
|
||||||
errorMessage.SetToFormat("Failed to parse address: %s",
|
const char* addressExpression = fAddressInput->Text();
|
||||||
parseError.message.String());
|
BString errorMessage;
|
||||||
} catch(...) {
|
try {
|
||||||
errorMessage.SetToFormat(
|
address = parser.EvaluateToInt64(addressExpression);
|
||||||
"Unknown error while parsing address");
|
} 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) {
|
if (addressValid) {
|
||||||
BAlert* alert = new(std::nothrow) BAlert("Inspect Address",
|
|
||||||
errorMessage.String(), "Close");
|
|
||||||
if (alert != NULL)
|
|
||||||
alert->Go();
|
|
||||||
} else {
|
|
||||||
if (fCurrentBlock != NULL
|
if (fCurrentBlock != NULL
|
||||||
&& !fCurrentBlock->Contains(address)) {
|
&& !fCurrentBlock->Contains(address)) {
|
||||||
fCurrentBlock->ReleaseReference();
|
fCurrentBlock->ReleaseReference();
|
||||||
@@ -177,6 +204,31 @@ InspectorWindow::MessageReceived(BMessage* msg)
|
|||||||
}
|
}
|
||||||
break;
|
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
|
void
|
||||||
InspectorWindow::MemoryBlockRetrieved(TeamMemoryBlock* block)
|
InspectorWindow::MemoryBlockRetrieved(TeamMemoryBlock* block)
|
||||||
{
|
{
|
||||||
fCurrentBlock = block;
|
BAutolock lock(this);
|
||||||
fMemoryView->SetTargetAddress(block, fCurrentAddress);
|
if (lock.IsLocked()) {
|
||||||
|
fCurrentBlock = block;
|
||||||
|
fMemoryView->SetTargetAddress(block, fCurrentAddress);
|
||||||
|
fPreviousBlockButton->SetEnabled(true);
|
||||||
|
fNextBlockButton->SetEnabled(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ private:
|
|||||||
BMenuField* fHexMode;
|
BMenuField* fHexMode;
|
||||||
BMenuField* fTextMode;
|
BMenuField* fTextMode;
|
||||||
MemoryView* fMemoryView;
|
MemoryView* fMemoryView;
|
||||||
|
BButton* fPreviousBlockButton;
|
||||||
|
BButton* fNextBlockButton;
|
||||||
TeamMemoryBlock* fCurrentBlock;
|
TeamMemoryBlock* fCurrentBlock;
|
||||||
target_addr_t fCurrentAddress;
|
target_addr_t fCurrentAddress;
|
||||||
::Team* fTeam;
|
::Team* fTeam;
|
||||||
|
|||||||
@@ -163,11 +163,11 @@ MemoryView::Draw(BRect rect)
|
|||||||
PopState();
|
PopState();
|
||||||
|
|
||||||
if (fHexMode != HexModeNone) {
|
if (fHexMode != HexModeNone) {
|
||||||
if (currentAddress + (currentBlocksPerLine * hexBlockSize)
|
if (currentAddress + (currentBlocksPerLine * blockByteSize)
|
||||||
> maxAddress) {
|
> maxAddress) {
|
||||||
currentCharsPerLine = maxAddress - currentAddress;
|
currentCharsPerLine = maxAddress - currentAddress;
|
||||||
currentBlocksPerLine = currentCharsPerLine
|
currentBlocksPerLine = currentCharsPerLine
|
||||||
/ hexBlockSize;
|
/ blockByteSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32 j = 0; j < currentBlocksPerLine; j++) {
|
for (int32 j = 0; j < currentBlocksPerLine; j++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user