mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
move the application to tools.
This commit is contained in:
parent
074516f532
commit
2ec990a2d5
4 changed files with 9 additions and 412 deletions
|
@ -1,53 +0,0 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
***********************************************************************/
|
||||
|
||||
package org.eclipse.cdt.utils.debug.stabs;
|
||||
|
||||
|
||||
public class StabSym implements Comparable {
|
||||
|
||||
public long addr;
|
||||
public long size;
|
||||
public int startLine;
|
||||
public int endLine;
|
||||
public String name;
|
||||
public String type;
|
||||
public String filename;
|
||||
|
||||
public StabSym() {
|
||||
}
|
||||
|
||||
public int compareTo(Object obj) {
|
||||
long thisVal = 0;
|
||||
long anotherVal = 0;
|
||||
if (obj instanceof StabSym) {
|
||||
StabSym entry = (StabSym) obj;
|
||||
thisVal = this.addr;
|
||||
anotherVal = entry.addr;
|
||||
} else if (obj instanceof Long) {
|
||||
Long val = (Long) obj;
|
||||
anotherVal = val.longValue();
|
||||
thisVal = (long) this.addr;
|
||||
}
|
||||
return (thisVal < anotherVal ? -1 : (thisVal == anotherVal ? 0 : 1));
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append("Type:").append(type).append("\n");
|
||||
buf.append("Name: ").append(name).append("\n");
|
||||
buf.append("\taddress:").append("0x").append(Long.toHexString(addr)).append("\n");
|
||||
buf.append("\tstartLine:").append(startLine).append("\n");
|
||||
buf.append("\tendLine:").append(endLine).append("\n");
|
||||
buf.append("\tSize:").append(size).append("\n");
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
|
@ -1,205 +0,0 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
***********************************************************************/
|
||||
|
||||
package org.eclipse.cdt.utils.debug.stabs;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.utils.debug.DebugParameterKind;
|
||||
import org.eclipse.cdt.utils.debug.DebugType;
|
||||
import org.eclipse.cdt.utils.debug.DebugVariableKind;
|
||||
import org.eclipse.cdt.utils.debug.IDebugEntryRequestor;
|
||||
|
||||
|
||||
/**
|
||||
* StabSymsRequestor
|
||||
*
|
||||
*/
|
||||
public class StabSymsRequestor implements IDebugEntryRequestor {
|
||||
|
||||
StabSym currentCU;
|
||||
StabSym currentFunction;
|
||||
|
||||
List list = new ArrayList();
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public StabSymsRequestor() {
|
||||
super();
|
||||
}
|
||||
|
||||
public StabSym[] getSortedEntries() {
|
||||
StabSym[] syms = getEntries();
|
||||
Arrays.sort(syms);
|
||||
return syms;
|
||||
}
|
||||
|
||||
public StabSym[] getEntries() {
|
||||
StabSym[] syms = new StabSym[list.size()];
|
||||
list.toArray(syms);
|
||||
return syms;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#enterCompilationUnit(java.lang.String, long)
|
||||
*/
|
||||
public void enterCompilationUnit(String name, long address) {
|
||||
StabSym sym = new StabSym();
|
||||
sym.name = name;
|
||||
sym.addr = address;
|
||||
sym.type = "CU";
|
||||
sym.filename = name;
|
||||
currentCU = sym;
|
||||
list.add(sym);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#exitCompilationUnit(long)
|
||||
*/
|
||||
public void exitCompilationUnit(long address) {
|
||||
if (currentCU != null) {
|
||||
currentCU.size = address;
|
||||
}
|
||||
currentCU = null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#enterInclude(java.lang.String)
|
||||
*/
|
||||
public void enterInclude(String name) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#exitInclude()
|
||||
*/
|
||||
public void exitInclude() {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#enterFunction(java.lang.String, int, boolean, long)
|
||||
*/
|
||||
public void enterFunction(String name, DebugType type, boolean isGlobal, long address) {
|
||||
StabSym sym = new StabSym();
|
||||
sym.name = name;
|
||||
sym.addr = address;
|
||||
sym.type = "Func";
|
||||
if (currentCU != null) {
|
||||
sym.filename = currentCU.filename;
|
||||
}
|
||||
currentFunction = sym;
|
||||
list.add(sym);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#exitFunction(long)
|
||||
*/
|
||||
public void exitFunction(long address) {
|
||||
if (currentFunction != null) {
|
||||
currentFunction.size = address;
|
||||
}
|
||||
currentFunction = null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#enterCodeBlock(long)
|
||||
*/
|
||||
public void enterCodeBlock(long offset) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#exitCodeBlock(long)
|
||||
*/
|
||||
public void exitCodeBlock(long offset) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#acceptStatement(int, long)
|
||||
*/
|
||||
public void acceptStatement(int line, long address) {
|
||||
StabSym sym = new StabSym();
|
||||
sym.name = "";
|
||||
sym.addr = address;
|
||||
sym.startLine = line;
|
||||
sym.type = "SLINE";
|
||||
if (currentFunction != null) {
|
||||
if (currentFunction.startLine == 0) {
|
||||
currentFunction.startLine = line;
|
||||
}
|
||||
currentFunction.endLine = line;
|
||||
}
|
||||
if (currentCU != null) {
|
||||
sym.filename = currentCU.filename;
|
||||
}
|
||||
list.add(sym);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#acceptIntegerConst(java.lang.String, long)
|
||||
*/
|
||||
public void acceptIntegerConst(String name, int value) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#acceptFloatConst(java.lang.String, double)
|
||||
*/
|
||||
public void acceptFloatConst(String name, double value) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#acceptTypeConst(java.lang.String, org.eclipse.cdt.utils.debug.DebugType, int)
|
||||
*/
|
||||
public void acceptTypeConst(String name, DebugType type, int value) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#acceptParameter(java.lang.String, int, int, long)
|
||||
*/
|
||||
public void acceptParameter(String name, DebugType type, DebugParameterKind kind, long offset) {
|
||||
StabSym sym = new StabSym();
|
||||
sym.name = name;
|
||||
sym.addr = offset;
|
||||
sym.type = "PARAM";
|
||||
if (currentCU != null) {
|
||||
sym.filename = currentCU.filename;
|
||||
}
|
||||
list.add(sym);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#acceptVariable(java.lang.String, int, int, long)
|
||||
*/
|
||||
public void acceptVariable(String name, DebugType type, DebugVariableKind kind, long address) {
|
||||
StabSym sym = new StabSym();
|
||||
sym.name = name;
|
||||
sym.addr = address;
|
||||
sym.type = "VAR";
|
||||
if (currentCU != null) {
|
||||
sym.filename = currentCU.filename;
|
||||
}
|
||||
list.add(sym);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#acceptCaughtException(java.lang.String, org.eclipse.cdt.utils.debug.DebugType, long)
|
||||
*/
|
||||
public void acceptCaughtException(String name, DebugType type, long address) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.utils.debug.IDebugEntryRequestor#acceptTypeDef(java.lang.String, org.eclipse.cdt.utils.debug.DebugType)
|
||||
*/
|
||||
public void acceptTypeDef(String name, DebugType type) {
|
||||
}
|
||||
|
||||
}
|
|
@ -14,7 +14,6 @@ import java.io.IOException;
|
|||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -34,6 +33,8 @@ import org.eclipse.cdt.utils.debug.DebugType;
|
|||
import org.eclipse.cdt.utils.debug.DebugUnknownType;
|
||||
import org.eclipse.cdt.utils.debug.DebugVariableKind;
|
||||
import org.eclipse.cdt.utils.debug.IDebugEntryRequestor;
|
||||
import org.eclipse.cdt.utils.debug.tools.DebugSym;
|
||||
import org.eclipse.cdt.utils.debug.tools.DebugSymsRequestor;
|
||||
import org.eclipse.cdt.utils.elf.Elf;
|
||||
|
||||
public class Stabs {
|
||||
|
@ -46,8 +47,6 @@ public class Stabs {
|
|||
byte[] stabstrData;
|
||||
boolean isLe;
|
||||
|
||||
StabSym[] entries;
|
||||
|
||||
boolean inCompilationUnit;
|
||||
boolean inFunction;
|
||||
boolean inInclude;
|
||||
|
@ -72,32 +71,6 @@ public class Stabs {
|
|||
init(stab, stabstr, le);
|
||||
}
|
||||
|
||||
public StabSym[] getEntries() throws IOException {
|
||||
if (entries == null) {
|
||||
parse();
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
public StabSym getEntry(long addr) throws IOException {
|
||||
if (entries == null) {
|
||||
parse();
|
||||
}
|
||||
int insertion = Arrays.binarySearch(entries, new Long(addr));
|
||||
if (insertion >= 0) {
|
||||
return entries[insertion];
|
||||
}
|
||||
if (insertion == -1) {
|
||||
return null;
|
||||
}
|
||||
insertion = -insertion - 1;
|
||||
StabSym entry = entries[insertion - 1];
|
||||
if (addr < (entry.addr + entry.size)) {
|
||||
return entries[insertion - 1];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void init(Elf exe) throws IOException {
|
||||
byte[] data = null;
|
||||
byte[] stabstr = null;
|
||||
|
@ -157,12 +130,6 @@ public class Stabs {
|
|||
return (short) (((bytes[offset] & 0xff) << 8) + (bytes[offset + 1] & 0xff));
|
||||
}
|
||||
|
||||
void parse() {
|
||||
StabSymsRequestor stabreq = new StabSymsRequestor();
|
||||
parse(stabreq);
|
||||
entries = stabreq.getSortedEntries();
|
||||
}
|
||||
|
||||
public void parse(IDebugEntryRequestor requestor) {
|
||||
List list = new ArrayList();
|
||||
long nstab = stabData.length / StabConstant.SIZE;
|
||||
|
@ -1365,18 +1332,16 @@ public class Stabs {
|
|||
return (DebugType) mapTypes.get(tn);
|
||||
}
|
||||
|
||||
public void print() {
|
||||
for (int i = 0; i < entries.length; i++) {
|
||||
StabSym entry = entries[i];
|
||||
System.out.println(entry);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
DebugSymsRequestor symreq = new DebugSymsRequestor();
|
||||
Stabs stabs = new Stabs(args[0]);
|
||||
stabs.parse();
|
||||
stabs.print();
|
||||
stabs.parse(symreq);
|
||||
DebugSym[] entries = symreq.getEntries();
|
||||
for (int i = 0; i < entries.length; i++) {
|
||||
DebugSym entry = entries[i];
|
||||
System.out.println(entry);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -1,110 +0,0 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
***********************************************************************/
|
||||
|
||||
package org.eclipse.cdt.utils.debug.stabs;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.cdt.utils.elf.Elf;
|
||||
|
||||
/**
|
||||
* StabsAddr2ine
|
||||
*
|
||||
* @author alain
|
||||
*/
|
||||
public class StabsAddr2line {
|
||||
|
||||
Stabs stabs;
|
||||
|
||||
public StabsAddr2line(String file) throws IOException {
|
||||
stabs = new Stabs(file);
|
||||
}
|
||||
|
||||
public StabsAddr2line(Elf elf) throws IOException {
|
||||
stabs = new Stabs(elf);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see IAddr2line#dispose()
|
||||
*/
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see IAddr2line#getStartLine(long)
|
||||
*/
|
||||
public int getStartLine(long address) throws IOException {
|
||||
StabSym entry = stabs.getEntry(address);
|
||||
if (entry != null) {
|
||||
return entry.startLine;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see IAddr2line#getEndLine(long)
|
||||
*/
|
||||
public int getEndLine(long address) throws IOException {
|
||||
StabSym entry = stabs.getEntry(address);
|
||||
if (entry != null) {
|
||||
return entry.endLine;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see IAddr2line#getFunction(long)
|
||||
*/
|
||||
public String getFunction(long address) throws IOException {
|
||||
StabSym entry = stabs.getEntry(address);
|
||||
if (entry != null) {
|
||||
return entry.name;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see IAddr2line#getFileName(long)
|
||||
*/
|
||||
public String getFileName(long address) throws IOException {
|
||||
StabSym entry = stabs.getEntry(address);
|
||||
if (entry != null) {
|
||||
return entry.filename;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
StabsAddr2line addr2line = new StabsAddr2line(args[0]);
|
||||
long address = Integer.decode(args[1]).longValue();
|
||||
int startLine = addr2line.getStartLine(address);
|
||||
int endLine = addr2line.getEndLine(address);
|
||||
String function = addr2line.getFunction(address);
|
||||
String filename = addr2line.getFileName(address);
|
||||
System.out.println(Long.toHexString(address));
|
||||
System.out.println(filename + ":" + function + ":" + startLine + ":" + endLine);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue