GP-1288: convert options to objects

This commit is contained in:
d-millar 2021-09-22 15:54:14 +00:00
parent 2c5b8d5863
commit cd1b5f6592
8 changed files with 212 additions and 64 deletions

View File

@ -114,6 +114,55 @@ public interface DebugControl extends DebugControlReentrant {
;
}
public static enum DebugFilterExecutionOption {
DEBUG_FILTER_BREAK(0, "Break"), //
DEBUG_FILTER_SECOND_CHANCE_BREAK(1, "Second-chance Break"), //
DEBUG_FILTER_OUTPUT(2, "Output-only"), //
DEBUG_FILTER_IGNORE(3, "Ignore"), //
DEBUG_FILTER_REMOVE(4, "Remove"), //
;
public static DebugFilterExecutionOption getByNumber(int val) {
for (DebugFilterExecutionOption m : DebugFilterExecutionOption.values()) {
if (m.val == val) {
return m;
}
}
return null;
}
DebugFilterExecutionOption(int val, String description) {
this.val = val;
this.description = description;
}
public final int val;
public final String description;
}
public static enum DebugFilterContinuationOption {
DEBUG_FILTER_GO_HANDLED(0, "Handled"), //
DEBUG_FILTER_GO_NOT_HANDLED(1, "Not Handled"), //
;
public static DebugFilterContinuationOption getByNumber(int val) {
for (DebugFilterContinuationOption m : DebugFilterContinuationOption.values()) {
if (m.val == val) {
return m;
}
}
return null;
}
DebugFilterContinuationOption(int val, String description) {
this.val = val;
this.description = description;
}
public final int val;
public final String description;
}
boolean getInterrupt();
int getInterruptTimeout();

View File

@ -15,21 +15,9 @@
*/
package agent.dbgeng.manager;
public interface DbgExceptionFilter {
String getName();
String getCmd();
public interface DbgExceptionFilter extends DbgEventFilter {
String getSecondCmd();
int getExecutionOption();
void setExecutionOption(int executionOption);
int getContinueOption();
void setContinueOption(int continueOption);
long getExceptionCode();
String getExceptionCode();
}

View File

@ -18,10 +18,10 @@ package agent.dbgeng.manager.impl;
import agent.dbgeng.manager.DbgEventFilter;
public class DbgEventFilterImpl implements DbgEventFilter {
private final String text;
private final String cmd;
private int executionOption;
private int continueOption;
protected final String text;
protected final String cmd;
protected int executionOption;
protected int continueOption;
public DbgEventFilterImpl(String text, String cmd, int executionOption, int continueOption) {
this.text = text;

View File

@ -17,56 +17,24 @@ package agent.dbgeng.manager.impl;
import agent.dbgeng.manager.DbgExceptionFilter;
public class DbgExceptionFilterImpl implements DbgExceptionFilter {
private final String text;
private final String cmd;
public class DbgExceptionFilterImpl extends DbgEventFilterImpl implements DbgExceptionFilter {
private final String cmd2;
private int executionOption;
private int continueOption;
private long exceptionCode;
public DbgExceptionFilterImpl(String text, String cmd, String cmd2, int executionOption,
int continueOption, long exceptionCode) {
this.text = text;
this.cmd = cmd;
super(text, cmd, executionOption, continueOption);
this.cmd2 = cmd2;
this.setExecutionOption(executionOption);
this.setContinueOption(continueOption);
this.exceptionCode = exceptionCode;
}
@Override
public String getName() {
return text;
}
@Override
public String getCmd() {
return cmd;
}
public String getSecondCmd() {
return cmd2;
}
public int getExecutionOption() {
return executionOption;
}
public void setExecutionOption(int executionOption) {
this.executionOption = executionOption;
}
public int getContinueOption() {
return continueOption;
}
public void setContinueOption(int continueOption) {
this.continueOption = continueOption;
}
public long getExceptionCode() {
return exceptionCode;
public String getExceptionCode() {
return Long.toHexString(exceptionCode);
}
}

View File

@ -0,0 +1,27 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package agent.dbgeng.model.iface2;
import ghidra.dbg.target.TargetTogglable;
public interface DbgModelTargetEventOption extends DbgModelTargetObject, TargetTogglable {
@Override
public default String getDisplay() {
return getName();
}
}

View File

@ -18,9 +18,10 @@ package agent.dbgeng.model.impl;
import java.util.List;
import java.util.Map;
import agent.dbgeng.dbgeng.DebugControl.DebugFilterContinuationOption;
import agent.dbgeng.dbgeng.DebugControl.DebugFilterExecutionOption;
import agent.dbgeng.manager.DbgEventFilter;
import agent.dbgeng.model.iface2.DbgModelTargetEvent;
import agent.dbgeng.model.iface2.DbgModelTargetEventContainer;
import agent.dbgeng.model.iface2.*;
import ghidra.dbg.target.schema.*;
import ghidra.dbg.util.PathUtils;
@ -40,6 +41,9 @@ public class DbgModelTargetEventImpl extends DbgModelTargetObjectImpl
return PathUtils.makeKey(indexFilter(filter));
}
protected DbgModelTargetEventOption execOption;
protected DbgModelTargetEventOption contOption;
private DbgEventFilter filter;
public DbgModelTargetEventImpl(DbgModelTargetEventContainer events, DbgEventFilter filter) {
@ -47,11 +51,18 @@ public class DbgModelTargetEventImpl extends DbgModelTargetObjectImpl
this.getModel().addModelObject(filter, this);
this.filter = filter;
DebugFilterExecutionOption exec =
DebugFilterExecutionOption.getByNumber(filter.getExecutionOption());
DebugFilterContinuationOption cont =
DebugFilterContinuationOption.getByNumber(filter.getContinueOption());
execOption = new DbgModelTargetEventOptionImpl(this, exec);
contOption = new DbgModelTargetEventOptionImpl(this, cont);
changeAttributes(List.of(), List.of(), Map.of( //
DISPLAY_ATTRIBUTE_NAME, getIndex(), //
"Command", filter.getCmd(), //
"Execute", filter.getExecutionOption(), //
"Continue", filter.getContinueOption() //
"Execute", execOption, //
"Continue", contOption //
), "Initialized");
}

View File

@ -0,0 +1,94 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package agent.dbgeng.model.impl;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import agent.dbgeng.dbgeng.DebugControl.DebugFilterContinuationOption;
import agent.dbgeng.dbgeng.DebugControl.DebugFilterExecutionOption;
import agent.dbgeng.model.iface2.*;
import ghidra.dbg.target.schema.*;
import ghidra.dbg.util.PathUtils;
@TargetObjectSchemaInfo(
name = "Event",
elements = {
@TargetElementType(type = Void.class) },
attributes = {
@TargetAttributeType(type = Object.class) })
public class DbgModelTargetEventOptionImpl extends DbgModelTargetObjectImpl
implements DbgModelTargetEventOption {
protected static String keyFilter(DebugFilterExecutionOption option) {
return PathUtils.makeKey(option.description);
}
protected static String keyFilter(DebugFilterContinuationOption option) {
return PathUtils.makeKey(option.description);
}
private DebugFilterExecutionOption optionEx;
private DebugFilterContinuationOption optionCont;
public DbgModelTargetEventOptionImpl(DbgModelTargetEvent event,
DebugFilterExecutionOption option) {
super(event.getModel(), event, keyFilter(option), "EventFilter");
this.getModel().addModelObject(option, this);
this.optionEx = option;
}
public DbgModelTargetEventOptionImpl(DbgModelTargetEvent event,
DebugFilterContinuationOption option) {
super(event.getModel(), event, keyFilter(option), "EventFilter");
this.getModel().addModelObject(option, this);
this.optionCont = option;
}
public DbgModelTargetEventOptionImpl(DbgModelTargetException exc,
DebugFilterExecutionOption option) {
super(exc.getModel(), exc, keyFilter(option), "EventFilter");
this.getModel().addModelObject(option, this);
this.optionEx = option;
}
public DbgModelTargetEventOptionImpl(DbgModelTargetException exc,
DebugFilterContinuationOption option) {
super(exc.getModel(), exc, keyFilter(option), "EventFilter");
this.getModel().addModelObject(option, this);
this.optionCont = option;
}
@Override
public CompletableFuture<Void> disable() {
// TODO Auto-generated method stub
return null;
}
@Override
public CompletableFuture<Void> enable() {
// TODO Auto-generated method stub
return null;
}
public void setAttributes() {
changeAttributes(List.of(), List.of(), Map.of( //
DISPLAY_ATTRIBUTE_NAME, getName() //
), "Initialized");
}
}

View File

@ -18,9 +18,10 @@ package agent.dbgeng.model.impl;
import java.util.List;
import java.util.Map;
import agent.dbgeng.dbgeng.DebugControl.DebugFilterContinuationOption;
import agent.dbgeng.dbgeng.DebugControl.DebugFilterExecutionOption;
import agent.dbgeng.manager.DbgExceptionFilter;
import agent.dbgeng.model.iface2.DbgModelTargetException;
import agent.dbgeng.model.iface2.DbgModelTargetExceptionContainer;
import agent.dbgeng.model.iface2.*;
import ghidra.dbg.target.schema.*;
import ghidra.dbg.util.PathUtils;
@ -40,6 +41,9 @@ public class DbgModelTargetExceptionImpl extends DbgModelTargetObjectImpl
return PathUtils.makeKey(indexFilter(filter));
}
protected DbgModelTargetEventOption execOption;
protected DbgModelTargetEventOption contOption;
private DbgExceptionFilter filter;
public DbgModelTargetExceptionImpl(DbgModelTargetExceptionContainer exceptions,
@ -48,13 +52,20 @@ public class DbgModelTargetExceptionImpl extends DbgModelTargetObjectImpl
this.getModel().addModelObject(filter, this);
this.filter = filter;
DebugFilterExecutionOption exec =
DebugFilterExecutionOption.getByNumber(filter.getExecutionOption());
DebugFilterContinuationOption cont =
DebugFilterContinuationOption.getByNumber(filter.getContinueOption());
execOption = new DbgModelTargetEventOptionImpl(this, exec);
contOption = new DbgModelTargetEventOptionImpl(this, cont);
changeAttributes(List.of(), List.of(), Map.of( //
DISPLAY_ATTRIBUTE_NAME, getIndex(), //
"Command", filter.getCmd(), //
"SecondCmd", filter.getCmd(), //
"Execute", filter.getExecutionOption(), //
"Continue", filter.getContinueOption(), //
"Exception", Long.toHexString(filter.getExceptionCode()) //
"Execute", execOption, //
"Continue", contOption, //
"Exception", filter.getExceptionCode() //
), "Initialized");
}