Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a2e5ccafbc378cecf29bd1d5f3cbc9c363d7e6da (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 * (c) Copyright QNX Software System Ltd. 2002.
 * All Rights Reserved.
 */
package org.eclipse.cdt.debug.internal.core;

import java.util.ArrayList;
import java.util.StringTokenizer;

import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.cdt.debug.core.ICDebugger;
import org.eclipse.cdt.debug.core.ICDebuggerManager;
import org.eclipse.cdt.debug.core.ICDebuggerInfo;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;

public class CDebuggerManager implements ICDebuggerManager {

	public CDebuggerManager() {
	}

	public ICDebugger createDebugger(String id) {
		ICDebugger debugger = null;

		IExtensionPoint extension = CDebugCorePlugin.getDefault().getDescriptor().getExtensionPoint("CDebugger");
		if (extension != null) {
			IExtension[] extensions =  extension.getExtensions();
			for(int i = 0; i < extensions.length; i++){
				if ( id.equals(extensions[i].getUniqueIdentifier()) ) {
					IConfigurationElement [] configElements = extensions[i].getConfigurationElements();
					try {
						debugger = (ICDebugger)configElements[0].createExecutableExtension("class");
					}
					catch (CoreException e) {
						return null;
					}
				}
			}
		}
		return debugger;
	}
		
	public ICDebuggerInfo[] queryDebuggers(String platform_id) {
		IExtensionPoint extension = CDebugCorePlugin.getDefault().getDescriptor().getExtensionPoint("CDebugger");
		if (extension != null) {
			IExtension[] extensions =  extension.getExtensions();
			CDebuggerInfo dinfo;
			ArrayList dlist = new ArrayList(extensions.length);
			for(int i = 0; i < extensions.length; i++){
				IConfigurationElement [] configElements = extensions[i].getConfigurationElements();
				String platform = configElements[0].getAttribute("platform");
				if ( platform == null || platform.equals("*") || platform.indexOf(platform_id) != -1 ) {
					dlist.add(dinfo = new CDebuggerInfo());
					dinfo.name = extensions[i].getLabel();
					dinfo.id = extensions[i].getUniqueIdentifier();
					dinfo.platforms = platform;
				}
			}
			return (ICDebuggerInfo[]) dlist.toArray(new ICDebuggerInfo[dlist.size()]);
		}		
		return new ICDebuggerInfo[0];
	}
	
	class CDebuggerInfo implements ICDebuggerInfo {
		String id;
		String name;
		String platforms;
		
		public String getID() {
			return id;
		}
		
		public String getName() {
			return name;
		}
		
		public String[] getSupportedPlatforms() {
			StringTokenizer stoken = new StringTokenizer(platforms, ",");
			String[] platforms = new String[stoken.countTokens()];
			for( int i = 0; i < platforms.length; i++ ) {
				platforms[i] = stoken.nextToken();
			}
			return platforms;
		}
	}
}

Back to the top