1
/*******************************************************************************
2
* Copyright (c) 2000, 2007 QNX Software Systems and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* QNX Software Systems - Initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.debug.mi.core.cdi.model;
13
import java.util.Arrays;
14
import java.util.HashMap;
16
import org.eclipse.cdt.debug.core.cdi.ICDICondition;
17
import org.eclipse.cdt.debug.core.cdi.model.ICDIEventBreakpoint;
18
import org.eclipse.cdt.debug.core.model.ICBreakpointType;
19
import org.eclipse.cdt.debug.mi.core.output.MIBreakpoint;
24
public class EventBreakpoint extends Breakpoint implements ICDIEventBreakpoint {
26
public static final String CATCH = "org.eclipse.cdt.debug.gdb.catch";
27
public static final String THROW = "org.eclipse.cdt.debug.gdb.throw";
28
public static final String SIGNAL_CATCH = "org.eclipse.cdt.debug.gdb.signal";
29
public static final String STOP_ON_FORK = "org.eclipse.cdt.debug.gdb.catch_fork";
30
public static final String STOP_ON_VFORK = "org.eclipse.cdt.debug.gdb.catch_vfork";
31
public static final String STOP_ON_EXEC = "org.eclipse.cdt.debug.gdb.catch_exec";
35
public static final String CATCH_EXIT = "org.eclipse.cdt.debug.gdb.catch_exit";
39
public static final String CATCH_START = "org.eclipse.cdt.debug.gdb.catch_start";
43
public static final String CATCH_STOP = "org.eclipse.cdt.debug.gdb.catch_stop";
47
public static final String CATCH_THREAD_START = "org.eclipse.cdt.debug.gdb.catch_thread_start";
51
public static final String CATCH_THREAD_EXIT = "org.eclipse.cdt.debug.gdb.catch_thread_exit";
55
public static final String CATCH_THREAD_JOIN = "org.eclipse.cdt.debug.gdb.catch_thread_join";
59
public static final String CATCH_LOAD = "org.eclipse.cdt.debug.gdb.catch_load";
63
public static final String CATCH_UNLOAD = "org.eclipse.cdt.debug.gdb.catch_unload";
65
private String eventType;
67
private static final HashMap<String, String> idToKeyword = new HashMap<String, String>();
69
// these Ids are also referenced in mi.ui plugin as contribution
70
// to event breakpoints selector
71
idToKeyword.put(CATCH, "catch");
72
idToKeyword.put(THROW, "throw");
73
idToKeyword.put(SIGNAL_CATCH, "signal");
74
idToKeyword.put(STOP_ON_EXEC, "exec");
75
idToKeyword.put(STOP_ON_FORK, "fork");
76
idToKeyword.put(STOP_ON_VFORK, "vfork");
77
idToKeyword.put(CATCH_EXIT, "exit");
78
idToKeyword.put(CATCH_START, "start");
79
idToKeyword.put(CATCH_STOP, "stop");
80
idToKeyword.put(CATCH_THREAD_START, "thread_start");
81
idToKeyword.put(CATCH_THREAD_EXIT, "thread_exit");
82
idToKeyword.put(CATCH_THREAD_JOIN, "thread_join");
83
idToKeyword.put(CATCH_LOAD, "load");
84
idToKeyword.put(CATCH_UNLOAD, "unload");
87
public EventBreakpoint(Target target, String event, String arg, ICDICondition cond, boolean enabled) {
88
super(target, ICBreakpointType.REGULAR, cond, enabled);
89
this.eventType = event;
90
this.arg = arg==null?"":arg;
93
public String getEventType() {
97
public String getExtraArgument() {
102
public String getGdbEvent() {
103
String etype = getEventType();
104
String key= idToKeyword.get(etype);
105
if (key!=null) return key;
109
public String getGdbArg() {
110
return getExtraArgument();
114
public int hashCode() {
115
return eventType.hashCode();
118
public boolean equals(Object arg0) {
119
if (this == arg0) return true;
120
if (!(arg0 instanceof EventBreakpoint)) return false;
121
MIBreakpoint[] breakpoints = getMIBreakpoints();
122
if (breakpoints==null || breakpoints.length==0) {
123
return super.equals(arg0);
125
return Arrays.equals(breakpoints, ((EventBreakpoint)arg0).getMIBreakpoints());
128
* Returns event type by using miBreakpoint parameters
129
* @param miBreakpoint
130
* @return null if unknown type, null cannot be used to create valid EventBreakpoint
132
public static String getEventTypeFromMI(MIBreakpoint miBreakpoint) {
133
if (miBreakpoint.getWhat().equals("exception catch")) {
134
return EventBreakpoint.CATCH;
135
} else if (miBreakpoint.getWhat().equals("exception throw")) {
136
return EventBreakpoint.THROW;
137
} else if (miBreakpoint.getType().equals("catch signal")) {
138
// catch signal does not work in gdb
139
return EventBreakpoint.SIGNAL_CATCH;
141
String miType = miBreakpoint.getType();
142
String prefix = "catch ";
143
if (miType.startsWith(prefix)) {
144
String key = miType.substring(prefix.length());
145
for (String id : idToKeyword.keySet()) {
146
String etype = idToKeyword.get(id);
147
if (key.equals(etype)) {
152
return null; // not known/supported
155
public static String getEventArgumentFromMI(MIBreakpoint miBreakpoint) {
156
// need a working gdb command command that support catch event argument test test