1
0
Fork 0

GUI: Add hardware breakpoint support from right click context menu

This commit is contained in:
Sigmapic 2013-11-24 11:15:52 +01:00
parent f3a7ed2e19
commit b0ef552740
4 changed files with 263 additions and 35 deletions

View File

@ -870,6 +870,8 @@ void Disassembly::disassambleAt(int_t parVA, int_t parCIP)
void Disassembly::disassembleClear() void Disassembly::disassembleClear()
{ {
//TODO: fix this (also try restarting) //TODO: fix this (also try restarting)
mBase = 0;
mSize = 0;
setRowCount(0); setRowCount(0);
reloadData(); reloadData();
} }
@ -882,3 +884,14 @@ void Disassembly::debugStateChangedSlot(DBGSTATE state)
disassembleClear(); disassembleClear();
} }
} }
int_t Disassembly::getBase()
{
return mBase;
}
int_t Disassembly::getSize()
{
return mSize;
}

View File

@ -57,6 +57,8 @@ public:
// Public Methods // Public Methods
uint_t rvaToVa(int_t rva); uint_t rvaToVa(int_t rva);
void disassembleClear(); void disassembleClear();
int_t getBase();
int_t getSize();
signals: signals:

View File

@ -20,19 +20,86 @@ CPUDisassembly::CPUDisassembly(QWidget *parent) : Disassembly(parent)
*/ */
void CPUDisassembly::contextMenuEvent(QContextMenuEvent* event) void CPUDisassembly::contextMenuEvent(QContextMenuEvent* event)
{ {
uint_t wVA = rvaToVa(getInitialSelection()); if(getSize() != 0)
BPXTYPE wBpType = DbgGetBpxTypeAt(wVA);
if((wBpType & bp_hardware) == bp_hardware)
{ {
mToggleHwBpAction->setText("Remove Hardware"); int wI;
} QMenu* wMenu = new QMenu(this);
else uint_t wVA = rvaToVa(getInitialSelection());
{ BPXTYPE wBpType = DbgGetBpxTypeAt(wVA);
mToggleHwBpAction->setText("Set Hardware on Execution");
}
QAction* wAction = mRightClickContextMenu->exec(event->globalPos()); // Build Menu
wMenu->addAction(mSetLabel);
wMenu->addAction(mSetComment);
wMenu->addAction(mSetBookmark);
// BP Menu
mBPMenu->clear();
// Soft BP
mBPMenu->addAction(mToggleInt3BpAction);
// Hardware BP
if((wBpType & bp_hardware) == bp_hardware)
{
mBPMenu->addAction(mClearHwBpAction);
}
else
{
BPMAP wBPList;
DbgGetBpList(bp_hardware, &wBPList);
if(wBPList.count < 4)
{
mBPMenu->addAction(mSetHwBpAction);
}
else
{
REGDUMP wRegDump;
DbgGetRegDump(&wRegDump);
for(wI = 0; wI < 4; wI++)
{
switch(wBPList.bp[wI].slot)
{
case 0:
msetHwBPOnSlot0Action->setText("Set Hardware on Execution on Slot 0 (0x" + QString("%1").arg(wBPList.bp[wI].addr, 8, 16, QChar('0')).toUpper() + ")");
break;
case 1:
msetHwBPOnSlot1Action->setText("Set Hardware on Execution on Slot 1 (0x" + QString("%1").arg(wBPList.bp[wI].addr, 8, 16, QChar('0')).toUpper() + ")");
break;
case 2:
msetHwBPOnSlot2Action->setText("Set Hardware on Execution on Slot 2 (0x" + QString("%1").arg(wBPList.bp[wI].addr, 8, 16, QChar('0')).toUpper() + ")");
break;
case 3:
msetHwBPOnSlot3Action->setText("Set Hardware on Execution on Slot 3 (0x" + QString("%1").arg(wBPList.bp[wI].addr, 8, 16, QChar('0')).toUpper() + ")");
break;
default:
break;
}
}
mHwSlotSelectMenu->addAction(msetHwBPOnSlot0Action);
mHwSlotSelectMenu->addAction(msetHwBPOnSlot1Action);
mHwSlotSelectMenu->addAction(msetHwBPOnSlot2Action);
mHwSlotSelectMenu->addAction(msetHwBPOnSlot3Action);
mBPMenu->addMenu(mHwSlotSelectMenu);
}
}
wMenu->addMenu(mBPMenu);
// Separator
wMenu->addSeparator();
// Goto Menu
mGotoMenu->addAction(mGotoOrigin);
mGotoMenu->addAction(mSetNewOriginHere);
wMenu->addMenu(mGotoMenu);
QAction* wAction = wMenu->exec(event->globalPos());
}
} }
@ -41,40 +108,41 @@ void CPUDisassembly::contextMenuEvent(QContextMenuEvent* event)
************************************************************************************/ ************************************************************************************/
void CPUDisassembly::setupRightClickContextMenu() void CPUDisassembly::setupRightClickContextMenu()
{ {
mRightClickContextMenu = new QMenu(this); // Labels
//label/comment
mSetLabel = new QAction("Label", this); mSetLabel = new QAction("Label", this);
mSetLabel->setShortcutContext(Qt::WidgetShortcut); mSetLabel->setShortcutContext(Qt::WidgetShortcut);
mSetLabel->setShortcut(QKeySequence(":")); mSetLabel->setShortcut(QKeySequence(":"));
this->addAction(mSetLabel); this->addAction(mSetLabel);
connect(mSetLabel, SIGNAL(triggered()), this, SLOT(setLabel())); connect(mSetLabel, SIGNAL(triggered()), this, SLOT(setLabel()));
// Comments
mSetComment = new QAction("Comment", this); mSetComment = new QAction("Comment", this);
mSetComment->setShortcutContext(Qt::WidgetShortcut); mSetComment->setShortcutContext(Qt::WidgetShortcut);
mSetComment->setShortcut(QKeySequence(";")); mSetComment->setShortcut(QKeySequence(";"));
this->addAction(mSetComment); this->addAction(mSetComment);
connect(mSetComment, SIGNAL(triggered()), this, SLOT(setComment())); connect(mSetComment, SIGNAL(triggered()), this, SLOT(setComment()));
// Bookmarks
mSetBookmark = new QAction("Bookmark", this); mSetBookmark = new QAction("Bookmark", this);
mSetBookmark->setShortcutContext(Qt::WidgetShortcut); mSetBookmark->setShortcutContext(Qt::WidgetShortcut);
mSetBookmark->setShortcut(QKeySequence("ctrl+d")); mSetBookmark->setShortcut(QKeySequence("ctrl+d"));
this->addAction(mSetBookmark); this->addAction(mSetBookmark);
connect(mSetBookmark, SIGNAL(triggered()), this, SLOT(setBookmark())); connect(mSetBookmark, SIGNAL(triggered()), this, SLOT(setBookmark()));
//---------------------- Go to ----------------------------------- //---------------------- Go to -----------------------------------
QMenu* wGotoMenu = new QMenu("Go to", this); // Menu
mGotoMenu = new QMenu("Go to", this);
// Origin action
mGotoOrigin = new QAction("Origin", this); mGotoOrigin = new QAction("Origin", this);
mGotoOrigin->setShortcutContext(Qt::WidgetShortcut); mGotoOrigin->setShortcutContext(Qt::WidgetShortcut);
mGotoOrigin->setShortcut(QKeySequence("*")); mGotoOrigin->setShortcut(QKeySequence("*"));
this->addAction(mGotoOrigin); this->addAction(mGotoOrigin);
connect(mGotoOrigin, SIGNAL(triggered()), this, SLOT(gotoOrigin())); connect(mGotoOrigin, SIGNAL(triggered()), this, SLOT(gotoOrigin()));
wGotoMenu->addAction(mGotoOrigin);
//---------------------- Breakpoints ----------------------------- //---------------------- Breakpoints -----------------------------
QMenu* wBPMenu = new QMenu("Breakpoint", this); // Menu
mBPMenu = new QMenu("Breakpoint", this);
// Standard breakpoint (option set using SetBPXOption) // Standard breakpoint (option set using SetBPXOption)
mToggleInt3BpAction = new QAction("Toggle", this); mToggleInt3BpAction = new QAction("Toggle", this);
@ -82,12 +150,27 @@ void CPUDisassembly::setupRightClickContextMenu()
mToggleInt3BpAction->setShortcut(QKeySequence(Qt::Key_F2)); mToggleInt3BpAction->setShortcut(QKeySequence(Qt::Key_F2));
this->addAction(mToggleInt3BpAction); this->addAction(mToggleInt3BpAction);
connect(mToggleInt3BpAction, SIGNAL(triggered()), this, SLOT(toggleInt3BPAction())); connect(mToggleInt3BpAction, SIGNAL(triggered()), this, SLOT(toggleInt3BPAction()));
wBPMenu->addAction(mToggleInt3BpAction);
// HW BP // HW BP
mToggleHwBpAction = new QAction("Set Hardware on Execution", this); mHwSlotSelectMenu = new QMenu("Set Hardware on Execution", this);
connect(mToggleHwBpAction, SIGNAL(triggered()), this, SLOT(toggleHwBpActionSlot()));
wBPMenu->addAction(mToggleHwBpAction); mSetHwBpAction = new QAction("Set Hardware on Execution", this);
connect(mSetHwBpAction, SIGNAL(triggered()), this, SLOT(toogleHwBpActionSlot()));
mClearHwBpAction = new QAction("Remove Hardware", this);
connect(mClearHwBpAction, SIGNAL(triggered()), this, SLOT(toogleHwBpActionSlot()));
msetHwBPOnSlot0Action = new QAction("Set Hardware on Execution on Slot 0 (Free)", this);
connect(msetHwBPOnSlot0Action, SIGNAL(triggered()), this, SLOT(setHwBpOnSlot0ActionSlot()));
msetHwBPOnSlot1Action = new QAction("Set Hardware on Execution on Slot 1 (Free)", this);
connect(msetHwBPOnSlot1Action, SIGNAL(triggered()), this, SLOT(setHwBpOnSlot1ActionSlot()));
msetHwBPOnSlot2Action = new QAction("Set Hardware on Execution on Slot 2 (Free)", this);
connect(msetHwBPOnSlot2Action, SIGNAL(triggered()), this, SLOT(setHwBpOnSlot2ActionSlot()));
msetHwBPOnSlot3Action = new QAction("Set Hardware on Execution on Slot 3 (Free)", this);
connect(msetHwBPOnSlot3Action, SIGNAL(triggered()), this, SLOT(setHwBpOnSlot3ActionSlot()));
//---------------------- New origin here ----------------------------- //---------------------- New origin here -----------------------------
mSetNewOriginHere = new QAction("Set New Origin Here", this); mSetNewOriginHere = new QAction("Set New Origin Here", this);
@ -95,15 +178,6 @@ void CPUDisassembly::setupRightClickContextMenu()
mSetNewOriginHere->setShortcut(QKeySequence("ctrl+*")); mSetNewOriginHere->setShortcut(QKeySequence("ctrl+*"));
this->addAction(mSetNewOriginHere); this->addAction(mSetNewOriginHere);
connect(mSetNewOriginHere, SIGNAL(triggered()), this, SLOT(setNewOriginHereActionSlot())); connect(mSetNewOriginHere, SIGNAL(triggered()), this, SLOT(setNewOriginHereActionSlot()));
//Add to menu
mRightClickContextMenu->addAction(mSetLabel);
mRightClickContextMenu->addAction(mSetComment);
mRightClickContextMenu->addAction(mSetBookmark);
mRightClickContextMenu->addMenu(wBPMenu); //Breakpoint->
mRightClickContextMenu->addSeparator(); //Seperator
mRightClickContextMenu->addMenu(wGotoMenu); //Go to->
mRightClickContextMenu->addAction(mSetNewOriginHere); //New origin here
} }
void CPUDisassembly::gotoOrigin() void CPUDisassembly::gotoOrigin()
@ -131,7 +205,7 @@ void CPUDisassembly::toggleInt3BPAction()
} }
void CPUDisassembly::toggleHwBpActionSlot() void CPUDisassembly::toogleHwBpActionSlot()
{ {
uint_t wVA = rvaToVa(getInitialSelection()); uint_t wVA = rvaToVa(getInitialSelection());
BPXTYPE wBpType = DbgGetBpxTypeAt(wVA); BPXTYPE wBpType = DbgGetBpxTypeAt(wVA);
@ -150,6 +224,127 @@ void CPUDisassembly::toggleHwBpActionSlot()
} }
void CPUDisassembly::setHwBpOnSlot0ActionSlot()
{
setHwBpAt(rvaToVa(getInitialSelection()), 0);
/*
qDebug() << "setHwBpOnSlot0ActionSlot";
int wI = 0;
int wSlot0Index = 0;
BPMAP wBPList;
uint_t wVA = rvaToVa(getInitialSelection());
QString wCmd = "";
DbgGetBpList(bp_hardware, &wBPList);
for(wI = 0; wI < 4; wI++)
{
if(wBPList.bp[wI].slot == 0)
{
wSlot0Index = wI;
break;
}
}
wCmd = "bphwc " + QString("%1").arg((uint_t)(wBPList.bp[wSlot0Index].addr), sizeof(uint_t) * 2, 16, QChar('0')).toUpper();
Bridge::getBridge()->execCmd(wCmd.toUtf8().constData());
Sleep(200);
wCmd = "bphws " + QString("%1").arg(wVA, sizeof(int_t) * 2, 16, QChar('0')).toUpper();
Bridge::getBridge()->execCmd(wCmd.toUtf8().constData());
*/
}
void CPUDisassembly::setHwBpOnSlot1ActionSlot()
{
setHwBpAt(rvaToVa(getInitialSelection()), 1);
}
void CPUDisassembly::setHwBpOnSlot2ActionSlot()
{
setHwBpAt(rvaToVa(getInitialSelection()), 2);
}
void CPUDisassembly::setHwBpOnSlot3ActionSlot()
{
setHwBpAt(rvaToVa(getInitialSelection()), 3);
}
void CPUDisassembly::setHwBpAt(uint_t va, int slot)
{
BPXTYPE wBpType = DbgGetBpxTypeAt(va);
if((wBpType & bp_hardware) == bp_hardware)
{
mBPMenu->addAction(mClearHwBpAction);
}
int wI = 0;
int wSlotIndex = -1;
BPMAP wBPList;
QString wCmd = "";
DbgGetBpList(bp_hardware, &wBPList);
// Find index of slot slot in the list
for(wI = 0; wI < wBPList.count; wI++)
{
if(wBPList.bp[wI].slot == (unsigned short)slot)
{
wSlotIndex = wI;
break;
}
}
if(wSlotIndex < 0) // Slot not used
{
wCmd = "bphws " + QString("%1").arg(va, sizeof(int_t) * 2, 16, QChar('0')).toUpper();
Bridge::getBridge()->execCmd(wCmd.toUtf8().constData());
}
else // Slot used
{
wCmd = "bphwc " + QString("%1").arg((uint_t)(wBPList.bp[wSlotIndex].addr), sizeof(uint_t) * 2, 16, QChar('0')).toUpper();
Bridge::getBridge()->execCmd(wCmd.toUtf8().constData());
Sleep(200);
wCmd = "bphws " + QString("%1").arg(va, sizeof(int_t) * 2, 16, QChar('0')).toUpper();
Bridge::getBridge()->execCmd(wCmd.toUtf8().constData());
}
/*
int wI = 0;
int wSlotIndex = 0;
BPMAP wBPList;
QString wCmd = "";
DbgGetBpList(bp_hardware, &wBPList);
for(wI = 0; wI < 4; wI++)
{
if(wBPList.bp[wI].slot == (unsigned short)slot)
{
wSlotIndex = wI;
break;
}
}
wCmd = "bphwc " + QString("%1").arg((uint_t)(wBPList.bp[wSlotIndex].addr), sizeof(uint_t) * 2, 16, QChar('0')).toUpper();
Bridge::getBridge()->execCmd(wCmd.toUtf8().constData());
Sleep(200);
wCmd = "bphws " + QString("%1").arg(va, sizeof(int_t) * 2, 16, QChar('0')).toUpper();
Bridge::getBridge()->execCmd(wCmd.toUtf8().constData());
*/
}
void CPUDisassembly::setNewOriginHereActionSlot() void CPUDisassembly::setNewOriginHereActionSlot()
{ {
uint_t wVA = rvaToVa(getInitialSelection()); uint_t wVA = rvaToVa(getInitialSelection());

View File

@ -20,11 +20,17 @@ public:
// Context Menu Management // Context Menu Management
void setupRightClickContextMenu(); void setupRightClickContextMenu();
void setHwBpAt(uint_t va, int slot);
signals: signals:
public slots: public slots:
void toggleInt3BPAction(); void toggleInt3BPAction();
void toggleHwBpActionSlot(); void toogleHwBpActionSlot();
void setHwBpOnSlot0ActionSlot();
void setHwBpOnSlot1ActionSlot();
void setHwBpOnSlot2ActionSlot();
void setHwBpOnSlot3ActionSlot();
void setNewOriginHereActionSlot(); void setNewOriginHereActionSlot();
void gotoOrigin(); void gotoOrigin();
void setLabel(); void setLabel();
@ -35,13 +41,25 @@ private:
// Rigth Click Context Menu // Rigth Click Context Menu
QMenu* mRightClickContextMenu; QMenu* mRightClickContextMenu;
// Menus
QMenu* mGotoMenu;
QMenu* mBPMenu;
QMenu* mHwSlotSelectMenu;
QAction* mToggleInt3BpAction; QAction* mToggleInt3BpAction;
QAction* mToggleHwBpAction; QAction* mSetHwBpAction;
QAction* mClearHwBpAction;
QAction* mSetNewOriginHere; QAction* mSetNewOriginHere;
QAction* mGotoOrigin; QAction* mGotoOrigin;
QAction* mSetComment; QAction* mSetComment;
QAction* mSetLabel; QAction* mSetLabel;
QAction* mSetBookmark; QAction* mSetBookmark;
QAction* msetHwBPOnSlot0Action;
QAction* msetHwBPOnSlot1Action;
QAction* msetHwBPOnSlot2Action;
QAction* msetHwBPOnSlot3Action;
}; };
#endif // CPUDISASSEMBLY_H #endif // CPUDISASSEMBLY_H