blob: 1fbc8a145e5e503f0274a5c807620a3cd55cde01 (
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
/*******************************************************************************
* Copyright (c) 2004, 2016 QNX Software Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* QNX Software Systems - Initial API and implementation
* Nokia - Added support for AbsoluteSourceContainer(159833)
* Texas Instruments - added extension point for source container type (279473)
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.debug.internal.core.sourcelookup;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
import org.eclipse.debug.core.sourcelookup.ISourceContainerType;
import org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant;
/**
* C/C++ source lookup director.
*
* Most instantiations of this class are transient, created through
* {@link ILaunchManager#newSourceLocator(String)}. A singleton is also created
* to represent the global source locators.
*
* An instance is either associated with a particular launch configuration or it
* has no association (global).
*
* This class is created by the {@link ILaunchManager#newSourceLocator(String)}
* (e.g. DebugPlugin.getDefault().getLaunchManager().newSourceLocator(type)) and
* must have a no-arguments constructor.
*/
public class CSourceLookupDirector extends AbstractSourceLookupDirector {
private static Set<String> fSupportedTypes;
private static Object fSupportedTypesLock = new Object();
@Override
public void initializeParticipants() {
addParticipants(new ISourceLookupParticipant[] { new CSourceLookupParticipant() });
}
@Override
public boolean supportsSourceContainerType(ISourceContainerType type) {
readSupportedContainerTypes();
return fSupportedTypes.contains(type.getId());
}
/**
* Translate a local file name to a name understood by the backend.
*
* This method is used when CDT needs to send a command to the backend
* containing a file name. For example, inserting a breakpoint. The platform
* breakpoint's file name is a path of a file on the user's machine, but GDB
* needs the path that corresponds to the debug information.
*
* @param sourceName
* file name of a local file
* @return file name as understood by the debugger backend
*/
public IPath getCompilationPath(String sourceName) {
for (ISourceContainer container : getSourceContainers()) {
IPath path = SourceUtils.getCompilationPath(container, sourceName);
if (path != null) {
return path;
}
}
return null;
}
/**
* Load and cache the source container types which are supported for CDT
* debugging.
*
* See Bug 279473 for more information.
*/
private void readSupportedContainerTypes() {
synchronized (fSupportedTypesLock) {
if (fSupportedTypes == null) {
fSupportedTypes = new HashSet<String>();
String name = CDebugCorePlugin.PLUGIN_ID + ".supportedSourceContainerTypes"; //$NON-NLS-1$;
IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(name);
if (extensionPoint != null) {
for (IExtension extension : extensionPoint.getExtensions()) {
for (IConfigurationElement configurationElements : extension.getConfigurationElements()) {
String id = configurationElements.getAttribute("id"); //$NON-NLS-1$;
if (id != null)
fSupportedTypes.add(id);
}
}
}
}
}
}
}
|