mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-02 05:45:58 +02:00
Bug 276758, support for pe-dwarf.
This commit is contained in:
parent
593cd79862
commit
bd6747e339
4 changed files with 136 additions and 6 deletions
|
@ -13,13 +13,16 @@ package org.eclipse.cdt.utils.coff;
|
||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.RandomAccessFile;
|
import java.io.RandomAccessFile;
|
||||||
import com.ibm.icu.text.DateFormat;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.channels.FileChannel.MapMode;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
|
|
||||||
|
import com.ibm.icu.text.DateFormat;
|
||||||
|
|
||||||
public class Coff {
|
public class Coff {
|
||||||
|
|
||||||
public static final String NL = System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
public static final String NL = System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
@ -308,6 +311,13 @@ public class Coff {
|
||||||
//*/
|
//*/
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 5.1
|
||||||
|
*/
|
||||||
|
public ByteBuffer mapSectionData() throws IOException {
|
||||||
|
return sfile.getChannel().map(MapMode.READ_ONLY, s_scnptr, s_paddr).load().asReadOnlyBuffer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Reloc {
|
public static class Reloc {
|
||||||
|
@ -563,7 +573,7 @@ public class Coff {
|
||||||
// }
|
// }
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String[] getStringTable(byte[] bytes) {
|
public static String[] getStringTable(byte[] bytes) {
|
||||||
List<String> aList = new ArrayList<String>();
|
List<String> aList = new ArrayList<String>();
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.eclipse.cdt.utils.coff.Coff.OptionalHeader;
|
||||||
import org.eclipse.cdt.utils.coff.Coff.SectionHeader;
|
import org.eclipse.cdt.utils.coff.Coff.SectionHeader;
|
||||||
import org.eclipse.cdt.utils.coff.Coff.Symbol;
|
import org.eclipse.cdt.utils.coff.Coff.Symbol;
|
||||||
import org.eclipse.cdt.utils.coff.Exe.ExeHeader;
|
import org.eclipse.cdt.utils.coff.Exe.ExeHeader;
|
||||||
|
import org.eclipse.cdt.utils.debug.dwarf.DwarfReader;
|
||||||
import org.eclipse.cdt.utils.debug.stabs.StabsReader;
|
import org.eclipse.cdt.utils.debug.stabs.StabsReader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,6 +66,7 @@ import org.eclipse.cdt.utils.debug.stabs.StabsReader;
|
||||||
*/
|
*/
|
||||||
public class PE {
|
public class PE {
|
||||||
|
|
||||||
|
|
||||||
public static final String NL = System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
public static final String NL = System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
RandomAccessFile rfile;
|
RandomAccessFile rfile;
|
||||||
String filename;
|
String filename;
|
||||||
|
@ -840,6 +842,40 @@ public class PE {
|
||||||
if (reader == null) {
|
if (reader == null) {
|
||||||
reader = createCodeViewReader();
|
reader = createCodeViewReader();
|
||||||
}
|
}
|
||||||
|
if (reader == null) {
|
||||||
|
reader = createDwarfReader();
|
||||||
|
}
|
||||||
return reader;
|
return reader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ISymbolReader createDwarfReader() {
|
||||||
|
DwarfReader reader = null;
|
||||||
|
// Check if Dwarf data exists
|
||||||
|
try {
|
||||||
|
reader = new DwarfReader(this);
|
||||||
|
} catch (IOException e) {
|
||||||
|
// No Dwarf data in the Elf.
|
||||||
|
}
|
||||||
|
return reader;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 5.1
|
||||||
|
*/
|
||||||
|
public String getStringTableEntry(int offset) throws IOException
|
||||||
|
{
|
||||||
|
byte[] bytes = getStringTable();
|
||||||
|
offset = offset - 4;
|
||||||
|
for (int i = offset; i < bytes.length; i++) {
|
||||||
|
if (bytes[i] == 0) {
|
||||||
|
return new String(bytes, offset, i - offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new String();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFilename() {
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
|
import org.eclipse.cdt.utils.coff.PE;
|
||||||
|
import org.eclipse.cdt.utils.coff.Coff.SectionHeader;
|
||||||
import org.eclipse.cdt.utils.debug.DebugUnknownType;
|
import org.eclipse.cdt.utils.debug.DebugUnknownType;
|
||||||
import org.eclipse.cdt.utils.debug.IDebugEntryRequestor;
|
import org.eclipse.cdt.utils.debug.IDebugEntryRequestor;
|
||||||
import org.eclipse.cdt.utils.debug.tools.DebugSym;
|
import org.eclipse.cdt.utils.debug.tools.DebugSym;
|
||||||
|
@ -178,6 +180,13 @@ public class Dwarf {
|
||||||
init(exe);
|
init(exe);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 5.1
|
||||||
|
*/
|
||||||
|
public Dwarf(PE exe) throws IOException {
|
||||||
|
init(exe);
|
||||||
|
}
|
||||||
|
|
||||||
public void init(Elf exe) throws IOException {
|
public void init(Elf exe) throws IOException {
|
||||||
Elf.ELFhdr header = exe.getELFhdr();
|
Elf.ELFhdr header = exe.getELFhdr();
|
||||||
isLE = header.e_ident[Elf.ELFhdr.EI_DATA] == Elf.ELFhdr.ELFDATA2LSB;
|
isLE = header.e_ident[Elf.ELFhdr.EI_DATA] == Elf.ELFhdr.ELFDATA2LSB;
|
||||||
|
@ -198,6 +207,36 @@ public class Dwarf {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 5.1
|
||||||
|
*/
|
||||||
|
public void init(PE exe) throws IOException {
|
||||||
|
|
||||||
|
isLE = true;
|
||||||
|
SectionHeader[] sections = exe.getSectionHeaders();
|
||||||
|
|
||||||
|
|
||||||
|
for (int i = 0; i < sections.length; i++) {
|
||||||
|
String name = new String(sections[i].s_name).trim();
|
||||||
|
if (name.startsWith("/")) //$NON-NLS-1$
|
||||||
|
{
|
||||||
|
int stringTableOffset = Integer.parseInt(name.substring(1));
|
||||||
|
name = exe.getStringTableEntry(stringTableOffset);
|
||||||
|
}
|
||||||
|
for (String element : Dwarf.DWARF_SCNNAMES) {
|
||||||
|
if (name.equals(element)) {
|
||||||
|
try {
|
||||||
|
dwarfSections.put(element, sections[i].mapSectionData());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
CCorePlugin.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
int read_4_bytes(ByteBuffer in) throws IOException {
|
int read_4_bytes(ByteBuffer in) throws IOException {
|
||||||
try {
|
try {
|
||||||
byte[] bytes = new byte[4];
|
byte[] bytes = new byte[4];
|
||||||
|
|
|
@ -21,6 +21,8 @@ import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.ISymbolReader;
|
import org.eclipse.cdt.core.ISymbolReader;
|
||||||
|
import org.eclipse.cdt.utils.coff.PE;
|
||||||
|
import org.eclipse.cdt.utils.coff.Coff.SectionHeader;
|
||||||
import org.eclipse.cdt.utils.debug.IDebugEntryRequestor;
|
import org.eclipse.cdt.utils.debug.IDebugEntryRequestor;
|
||||||
import org.eclipse.cdt.utils.elf.Elf;
|
import org.eclipse.cdt.utils.elf.Elf;
|
||||||
import org.eclipse.cdt.utils.elf.Elf.Section;
|
import org.eclipse.cdt.utils.elf.Elf.Section;
|
||||||
|
@ -33,6 +35,11 @@ import org.eclipse.core.runtime.Path;
|
||||||
*/
|
*/
|
||||||
public class DwarfReader extends Dwarf implements ISymbolReader {
|
public class DwarfReader extends Dwarf implements ISymbolReader {
|
||||||
|
|
||||||
|
private static boolean isWindows() {
|
||||||
|
String os = System.getProperty("os.name"); //$NON-NLS-1$
|
||||||
|
return (os != null && os.toLowerCase().startsWith("win")); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
// These are sections that need be parsed to get the source file list.
|
// These are sections that need be parsed to get the source file list.
|
||||||
final static String[] DWARF_SectionsToParse =
|
final static String[] DWARF_SectionsToParse =
|
||||||
{
|
{
|
||||||
|
@ -42,12 +49,12 @@ public class DwarfReader extends Dwarf implements ISymbolReader {
|
||||||
DWARF_DEBUG_STR // this is optional. Some compilers don't generate it.
|
DWARF_DEBUG_STR // this is optional. Some compilers don't generate it.
|
||||||
};
|
};
|
||||||
|
|
||||||
private Collection<String> m_fileCollection = new ArrayList<String>();
|
private final Collection<String> m_fileCollection = new ArrayList<String>();
|
||||||
private String[] m_fileNames = null;
|
private String[] m_fileNames = null;
|
||||||
private String m_exeFileWin32Drive; // Win32 drive of the exe file.
|
private String m_exeFileWin32Drive; // Win32 drive of the exe file.
|
||||||
private boolean m_onWindows;
|
private boolean m_onWindows;
|
||||||
private boolean m_parsed = false;
|
private boolean m_parsed = false;
|
||||||
private ArrayList<Integer> m_parsedLineTableOffsets = new ArrayList<Integer>();
|
private final ArrayList<Integer> m_parsedLineTableOffsets = new ArrayList<Integer>();
|
||||||
private int m_parsedLineTableSize = 0;
|
private int m_parsedLineTableSize = 0;
|
||||||
|
|
||||||
public DwarfReader(String file) throws IOException {
|
public DwarfReader(String file) throws IOException {
|
||||||
|
@ -58,6 +65,13 @@ public class DwarfReader extends Dwarf implements ISymbolReader {
|
||||||
super(exe);
|
super(exe);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 5.1
|
||||||
|
*/
|
||||||
|
public DwarfReader(PE exe) throws IOException {
|
||||||
|
super(exe);
|
||||||
|
}
|
||||||
|
|
||||||
// Override parent.
|
// Override parent.
|
||||||
//
|
//
|
||||||
@Override
|
@Override
|
||||||
|
@ -80,7 +94,6 @@ public class DwarfReader extends Dwarf implements ISymbolReader {
|
||||||
try {
|
try {
|
||||||
dwarfSections.put(element, section.mapSectionData());
|
dwarfSections.put(element, section.mapSectionData());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
|
||||||
CCorePlugin.log(e);
|
CCorePlugin.log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,12 +102,44 @@ public class DwarfReader extends Dwarf implements ISymbolReader {
|
||||||
|
|
||||||
// Don't print during parsing.
|
// Don't print during parsing.
|
||||||
printEnabled = false;
|
printEnabled = false;
|
||||||
|
|
||||||
m_parsed = false;
|
m_parsed = false;
|
||||||
|
|
||||||
Path pa = new Path(exe.getFilename());
|
Path pa = new Path(exe.getFilename());
|
||||||
m_exeFileWin32Drive = pa.getDevice();
|
m_exeFileWin32Drive = pa.getDevice();
|
||||||
|
|
||||||
|
m_onWindows = isWindows();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(PE exe) throws IOException {
|
||||||
|
|
||||||
|
isLE = true;
|
||||||
|
SectionHeader[] sections = exe.getSectionHeaders();
|
||||||
|
|
||||||
|
for (int i = 0; i < sections.length; i++) {
|
||||||
|
String name = new String(sections[i].s_name).trim();
|
||||||
|
if (name.startsWith("/")) //$NON-NLS-1$
|
||||||
|
{
|
||||||
|
int stringTableOffset = Integer.parseInt(name.substring(1));
|
||||||
|
name = exe.getStringTableEntry(stringTableOffset);
|
||||||
|
}
|
||||||
|
for (String element : Dwarf.DWARF_SCNNAMES) {
|
||||||
|
if (name.equals(element)) {
|
||||||
|
try {
|
||||||
|
dwarfSections.put(element, sections[i].mapSectionData());
|
||||||
|
} catch (Exception e) {
|
||||||
|
CCorePlugin.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Don't print during parsing.
|
||||||
|
printEnabled = false;
|
||||||
|
m_parsed = false;
|
||||||
|
|
||||||
|
Path pa = new Path(exe.getFilename());
|
||||||
|
m_exeFileWin32Drive = pa.getDevice();
|
||||||
|
|
||||||
m_onWindows = (File.separatorChar == '\\');
|
m_onWindows = (File.separatorChar == '\\');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue