Debugger: Prevent adding breakpoints with invalid conditions

This commit is contained in:
Souryo 2016-12-04 11:40:31 -05:00
parent 52c1d160fe
commit 8261e95f93
7 changed files with 59 additions and 20 deletions

View file

@ -191,11 +191,6 @@ void Debugger::UpdateBreakpoints()
ExpressionEvaluator expEval(this); ExpressionEvaluator expEval(this);
for(Breakpoint &bp : _newBreakpoints) { for(Breakpoint &bp : _newBreakpoints) {
if(!expEval.Validate(bp.GetCondition())) {
//Remove any invalid condition (syntax-wise)
bp.ClearCondition();
}
for(int i = 0; i < Debugger::BreakpointTypeCount; i++) { for(int i = 0; i < Debugger::BreakpointTypeCount; i++) {
if(bp.HasBreakpointType((BreakpointType)i)) { if(bp.HasBreakpointType((BreakpointType)i)) {
_breakpoints[i].push_back(bp); _breakpoints[i].push_back(bp);

View file

@ -35,11 +35,13 @@
this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel();
this.picHelp = new System.Windows.Forms.PictureBox(); this.picHelp = new System.Windows.Forms.PictureBox();
this.txtCondition = new System.Windows.Forms.TextBox(); this.txtCondition = new System.Windows.Forms.TextBox();
this.picExpressionWarning = new System.Windows.Forms.PictureBox();
this.tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel(); this.tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel();
this.txtAddress = new System.Windows.Forms.TextBox(); this.txtAddress = new System.Windows.Forms.TextBox();
this.chkAbsolute = new System.Windows.Forms.CheckBox(); this.chkAbsolute = new System.Windows.Forms.CheckBox();
this.radSpecificAddress = new System.Windows.Forms.RadioButton(); this.radSpecificAddress = new System.Windows.Forms.RadioButton();
this.radAnyAddress = new System.Windows.Forms.RadioButton(); this.radAnyAddress = new System.Windows.Forms.RadioButton();
this.lblAddressSign = new System.Windows.Forms.Label();
this.tableLayoutPanel4 = new System.Windows.Forms.TableLayoutPanel(); this.tableLayoutPanel4 = new System.Windows.Forms.TableLayoutPanel();
this.flowLayoutPanel3 = new System.Windows.Forms.FlowLayoutPanel(); this.flowLayoutPanel3 = new System.Windows.Forms.FlowLayoutPanel();
this.chkReadVram = new System.Windows.Forms.CheckBox(); this.chkReadVram = new System.Windows.Forms.CheckBox();
@ -50,10 +52,10 @@
this.chkRead = new System.Windows.Forms.CheckBox(); this.chkRead = new System.Windows.Forms.CheckBox();
this.chkWrite = new System.Windows.Forms.CheckBox(); this.chkWrite = new System.Windows.Forms.CheckBox();
this.chkExec = new System.Windows.Forms.CheckBox(); this.chkExec = new System.Windows.Forms.CheckBox();
this.lblAddressSign = new System.Windows.Forms.Label();
this.tableLayoutPanel1.SuspendLayout(); this.tableLayoutPanel1.SuspendLayout();
this.tableLayoutPanel2.SuspendLayout(); this.tableLayoutPanel2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.picHelp)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.picHelp)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.picExpressionWarning)).BeginInit();
this.tableLayoutPanel3.SuspendLayout(); this.tableLayoutPanel3.SuspendLayout();
this.tableLayoutPanel4.SuspendLayout(); this.tableLayoutPanel4.SuspendLayout();
this.flowLayoutPanel3.SuspendLayout(); this.flowLayoutPanel3.SuspendLayout();
@ -133,11 +135,14 @@
// //
// tableLayoutPanel2 // tableLayoutPanel2
// //
this.tableLayoutPanel2.ColumnCount = 2; this.tableLayoutPanel2.ColumnCount = 3;
this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanel2.Controls.Add(this.picHelp, 1, 0); this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel2.Controls.Add(this.picHelp, 2, 0);
this.tableLayoutPanel2.Controls.Add(this.txtCondition, 0, 0); this.tableLayoutPanel2.Controls.Add(this.txtCondition, 0, 0);
this.tableLayoutPanel2.Controls.Add(this.picExpressionWarning, 1, 0);
this.tableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill; this.tableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel2.Location = new System.Drawing.Point(60, 94); this.tableLayoutPanel2.Location = new System.Drawing.Point(60, 94);
this.tableLayoutPanel2.Margin = new System.Windows.Forms.Padding(0); this.tableLayoutPanel2.Margin = new System.Windows.Forms.Padding(0);
@ -163,9 +168,20 @@
this.txtCondition.Location = new System.Drawing.Point(3, 3); this.txtCondition.Location = new System.Drawing.Point(3, 3);
this.txtCondition.MaxLength = 900; this.txtCondition.MaxLength = 900;
this.txtCondition.Name = "txtCondition"; this.txtCondition.Name = "txtCondition";
this.txtCondition.Size = new System.Drawing.Size(288, 20); this.txtCondition.Size = new System.Drawing.Size(264, 20);
this.txtCondition.TabIndex = 6; this.txtCondition.TabIndex = 6;
// //
// picExpressionWarning
//
this.picExpressionWarning.Image = global::Mesen.GUI.Properties.Resources.Warning;
this.picExpressionWarning.Location = new System.Drawing.Point(273, 5);
this.picExpressionWarning.Margin = new System.Windows.Forms.Padding(3, 5, 3, 3);
this.picExpressionWarning.Name = "picExpressionWarning";
this.picExpressionWarning.Size = new System.Drawing.Size(18, 18);
this.picExpressionWarning.TabIndex = 9;
this.picExpressionWarning.TabStop = false;
this.picExpressionWarning.Visible = false;
//
// tableLayoutPanel3 // tableLayoutPanel3
// //
this.tableLayoutPanel3.ColumnCount = 4; this.tableLayoutPanel3.ColumnCount = 4;
@ -234,6 +250,17 @@
this.radAnyAddress.Text = "Any"; this.radAnyAddress.Text = "Any";
this.radAnyAddress.UseVisualStyleBackColor = true; this.radAnyAddress.UseVisualStyleBackColor = true;
// //
// lblAddressSign
//
this.lblAddressSign.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.lblAddressSign.AutoSize = true;
this.lblAddressSign.Location = new System.Drawing.Point(72, 6);
this.lblAddressSign.Margin = new System.Windows.Forms.Padding(0);
this.lblAddressSign.Name = "lblAddressSign";
this.lblAddressSign.Size = new System.Drawing.Size(13, 13);
this.lblAddressSign.TabIndex = 9;
this.lblAddressSign.Text = "$";
//
// tableLayoutPanel4 // tableLayoutPanel4
// //
this.tableLayoutPanel4.ColumnCount = 2; this.tableLayoutPanel4.ColumnCount = 2;
@ -355,17 +382,6 @@
this.chkExec.UseVisualStyleBackColor = true; this.chkExec.UseVisualStyleBackColor = true;
this.chkExec.Enter += new System.EventHandler(this.chkRead_Enter); this.chkExec.Enter += new System.EventHandler(this.chkRead_Enter);
// //
// lblAddressSign
//
this.lblAddressSign.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.lblAddressSign.AutoSize = true;
this.lblAddressSign.Location = new System.Drawing.Point(72, 6);
this.lblAddressSign.Margin = new System.Windows.Forms.Padding(0);
this.lblAddressSign.Name = "lblAddressSign";
this.lblAddressSign.Size = new System.Drawing.Size(13, 13);
this.lblAddressSign.TabIndex = 9;
this.lblAddressSign.Text = "$";
//
// frmBreakpoint // frmBreakpoint
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -383,6 +399,7 @@
this.tableLayoutPanel2.ResumeLayout(false); this.tableLayoutPanel2.ResumeLayout(false);
this.tableLayoutPanel2.PerformLayout(); this.tableLayoutPanel2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.picHelp)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.picHelp)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.picExpressionWarning)).EndInit();
this.tableLayoutPanel3.ResumeLayout(false); this.tableLayoutPanel3.ResumeLayout(false);
this.tableLayoutPanel3.PerformLayout(); this.tableLayoutPanel3.PerformLayout();
this.tableLayoutPanel4.ResumeLayout(false); this.tableLayoutPanel4.ResumeLayout(false);
@ -421,5 +438,6 @@
private System.Windows.Forms.RadioButton radCpu; private System.Windows.Forms.RadioButton radCpu;
private System.Windows.Forms.RadioButton radPpu; private System.Windows.Forms.RadioButton radPpu;
private System.Windows.Forms.Label lblAddressSign; private System.Windows.Forms.Label lblAddressSign;
private System.Windows.Forms.PictureBox picExpressionWarning;
} }
} }

View file

@ -36,6 +36,8 @@ namespace Mesen.GUI.Debugger
AddBinding("BreakOnWriteVram", chkWriteVram); AddBinding("BreakOnWriteVram", chkWriteVram);
AddBinding("Condition", txtCondition); AddBinding("Condition", txtCondition);
this.toolTip.SetToolTip(this.picExpressionWarning, "Condition contains invalid syntax or symbols.");
this.toolTip.SetToolTip(this.chkAbsolute, "Check to set an absolute address based on the exact address in PRG/CHR ROM (not CPU/PPU memory)"); this.toolTip.SetToolTip(this.chkAbsolute, "Check to set an absolute address based on the exact address in PRG/CHR ROM (not CPU/PPU memory)");
this.toolTip.SetToolTip(this.picHelp, this.toolTip.SetToolTip(this.picHelp,
"Most expressions/operators are accepted (C++ syntax)." + Environment.NewLine + "Most expressions/operators are accepted (C++ syntax)." + Environment.NewLine +
@ -61,6 +63,16 @@ namespace Mesen.GUI.Debugger
protected override bool ValidateInput() protected override bool ValidateInput()
{ {
if(txtCondition.Text.Length > 0) {
EvalResultType resultType;
InteropEmu.DebugEvaluateExpression(txtCondition.Text, out resultType);
if(resultType == EvalResultType.Invalid) {
picExpressionWarning.Visible = true;
return false;
}
}
picExpressionWarning.Visible = false;
return chkRead.Checked || chkWrite.Checked || chkExec.Checked || chkReadVram.Checked || chkWriteVram.Checked || txtCondition.Text.Length > 0; return chkRead.Checked || chkWrite.Checked || chkExec.Checked || chkReadVram.Checked || chkWriteVram.Checked || txtCondition.Text.Length > 0;
} }

View file

@ -863,6 +863,7 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Icon.ico" /> <Content Include="Icon.ico" />
<None Include="Resources\Warning.png" />
<None Include="Resources\Import.png" /> <None Include="Resources\Import.png" />
<None Include="Resources\Export.png" /> <None Include="Resources\Export.png" />
<None Include="Resources\NsfBackground.png" /> <None Include="Resources\NsfBackground.png" />

View file

@ -449,5 +449,15 @@ namespace Mesen.GUI.Properties {
return ((System.Drawing.Bitmap)(obj)); return ((System.Drawing.Bitmap)(obj));
} }
} }
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap Warning {
get {
object obj = ResourceManager.GetObject("Warning", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
} }
} }

View file

@ -235,4 +235,7 @@
<data name="CheatCode" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="CheatCode" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\CheatCode.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\CheatCode.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="Warning" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Warning.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root> </root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 717 B