1
/*******************************************************************************
2
* Copyright (c) 2000, 2008 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
*******************************************************************************/
12
package org.eclipse.cdt.utils.debug.tools;
14
import java.util.ArrayList;
15
import java.util.Arrays;
16
import java.util.List;
18
import org.eclipse.cdt.utils.debug.DebugParameterKind;
19
import org.eclipse.cdt.utils.debug.DebugType;
20
import org.eclipse.cdt.utils.debug.DebugVariableKind;
21
import org.eclipse.cdt.utils.debug.IDebugEntryRequestor;
28
public class DebugSymsRequestor implements IDebugEntryRequestor {
31
DebugSym currentFunction;
33
List<DebugSym> list = new ArrayList<DebugSym>();
38
public DebugSymsRequestor() {
42
public DebugSym[] getSortedEntries() {
43
DebugSym[] syms = getEntries();
48
public DebugSym[] getEntries() {
49
DebugSym[] syms = new DebugSym[list.size()];
54
public DebugSym getEntry(long addr) {
55
DebugSym[] entries = getSortedEntries();
56
int insertion = Arrays.binarySearch(entries, new Long(addr));
58
return entries[insertion];
60
if (insertion == -1) {
63
insertion = -insertion - 1;
64
DebugSym entry = entries[insertion - 1];
65
if (addr < (entry.addr + entry.size)) {
66
return entries[insertion - 1];
72
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#enterCompilationUnit(java.lang.String, long)
74
public void enterCompilationUnit(String name, long address) {
75
DebugSym sym = new DebugSym();
78
sym.type = "CU"; //$NON-NLS-1$
85
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#exitCompilationUnit(long)
87
public void exitCompilationUnit(long address) {
88
if (currentCU != null) {
89
currentCU.size = address;
95
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#enterInclude(java.lang.String)
97
public void enterInclude(String name) {
101
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#exitInclude()
103
public void exitInclude() {
107
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#enterFunction(java.lang.String, int, boolean, long)
109
public void enterFunction(String name, DebugType type, boolean isGlobal, long address) {
110
DebugSym sym = new DebugSym();
113
sym.type = "Func"; //$NON-NLS-1$
114
if (currentCU != null) {
115
sym.filename = currentCU.filename;
117
currentFunction = sym;
122
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#exitFunction(long)
124
public void exitFunction(long address) {
125
if (currentFunction != null) {
126
currentFunction.size = address;
128
currentFunction = null;
132
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#enterCodeBlock(long)
134
public void enterCodeBlock(long offset) {
138
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#exitCodeBlock(long)
140
public void exitCodeBlock(long offset) {
144
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#acceptStatement(int, long)
146
public void acceptStatement(int line, long address) {
147
DebugSym sym = new DebugSym();
148
sym.name = ""; //$NON-NLS-1$
150
sym.startLine = line;
151
sym.type = "SLINE"; //$NON-NLS-1$
152
if (currentFunction != null) {
153
if (currentFunction.startLine == 0) {
154
currentFunction.startLine = line;
156
currentFunction.endLine = line;
158
if (currentCU != null) {
159
sym.filename = currentCU.filename;
165
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#acceptIntegerConst(java.lang.String, long)
167
public void acceptIntegerConst(String name, int value) {
171
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#acceptFloatConst(java.lang.String, double)
173
public void acceptFloatConst(String name, double value) {
177
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#acceptTypeConst(java.lang.String, org.eclipse.cdt.utils.debug.DebugType, int)
179
public void acceptTypeConst(String name, DebugType type, int value) {
183
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#acceptParameter(java.lang.String, int, int, long)
185
public void acceptParameter(String name, DebugType type, DebugParameterKind kind, long offset) {
186
DebugSym sym = new DebugSym();
189
sym.type = "PARAM"; //$NON-NLS-1$
190
if (currentCU != null) {
191
sym.filename = currentCU.filename;
197
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#acceptVariable(java.lang.String, int, int, long)
199
public void acceptVariable(String name, DebugType type, DebugVariableKind kind, long address) {
200
DebugSym sym = new DebugSym();
203
sym.type = "VAR"; //$NON-NLS-1$
204
if (currentCU != null) {
205
sym.filename = currentCU.filename;
211
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#acceptCaughtException(java.lang.String, org.eclipse.cdt.utils.debug.DebugType, long)
213
public void acceptCaughtException(String name, DebugType type, long address) {
217
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#acceptTypeDef(java.lang.String, org.eclipse.cdt.utils.debug.DebugType)
219
public void acceptTypeDef(String name, DebugType type) {