mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-08 00:35:49 +02:00
Add check in DwarfReader to avoid exception being caught
- In init, don't bother looking for a special note section if the note section size isn't greater than 12 bytes Change-Id: I57d2d7b0229996edcb1b4149c391e91b0472beea Reviewed-on: https://git.eclipse.org/r/25822 Tested-by: Hudson CI Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com> Reviewed-by: Jeff Johnston <jjohnstn@redhat.com> Tested-by: Jeff Johnston <jjohnstn@redhat.com>
This commit is contained in:
parent
82853c889d
commit
6f9b0cd178
1 changed files with 38 additions and 36 deletions
|
@ -98,45 +98,47 @@ public class DwarfReader extends Dwarf implements ISymbolReader, ICompileOptions
|
|||
for (Section section : sections) {
|
||||
if (section.sh_type == Elf.Section.SHT_NOTE) {
|
||||
ByteBuffer data = section.mapSectionData();
|
||||
try {
|
||||
// Read .note section, looking to see if it is named "GNU" and is of GNU_BUILD_ID type
|
||||
@SuppressWarnings("unused")
|
||||
int name_sz = read_4_bytes(data);
|
||||
int data_sz = read_4_bytes(data);
|
||||
int note_type = read_4_bytes(data);
|
||||
if (data.remaining() > 12) {
|
||||
try {
|
||||
// Read .note section, looking to see if it is named "GNU" and is of GNU_BUILD_ID type
|
||||
@SuppressWarnings("unused")
|
||||
int name_sz = read_4_bytes(data);
|
||||
int data_sz = read_4_bytes(data);
|
||||
int note_type = read_4_bytes(data);
|
||||
|
||||
String noteName = readString(data);
|
||||
String buildId = null;
|
||||
if (noteName.equals("GNU") && note_type == Elf.Section.NT_GNU_BUILD_ID) { //$NON-NLS-1$
|
||||
// We have the special GNU build-id note section. Skip over the name to
|
||||
// a 4-byte boundary.
|
||||
byte[] byteArray = new byte[data_sz];
|
||||
while ((data.position() & 0x3) != 0)
|
||||
data.get();
|
||||
int i = 0;
|
||||
// Read in the hex bytes from the note section's data.
|
||||
while (data.hasRemaining() && data_sz-- > 0) {
|
||||
byteArray[i++] = data.get();
|
||||
}
|
||||
// The build-id location is taken by converting the binary bytes to hex string.
|
||||
// The first byte is used as a directory specifier (e.g. 51/a4578fe2).
|
||||
String bName = DatatypeConverter.printHexBinary(byteArray).toLowerCase();
|
||||
buildId = bName.substring(0, 2) + "/" + bName.substring(2) + ".debug"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
// The build-id file should be in the special directory /usr/lib/debug/.build-id
|
||||
IPath buildIdPath = new Path("/usr/lib/debug/.build-id").append(buildId); //$NON-NLS-1$
|
||||
File buildIdFile = buildIdPath.toFile();
|
||||
if (buildIdFile.exists()) {
|
||||
// if the debug file exists from above, open it and get the section info from it
|
||||
Elf debugInfo = new Elf(buildIdFile.getCanonicalPath());
|
||||
sections = debugInfo.getSections();
|
||||
have_build_id = true;
|
||||
debugInfoPath = new Path(buildIdFile.getCanonicalPath()).removeLastSegments(1);
|
||||
break;
|
||||
String noteName = readString(data);
|
||||
String buildId = null;
|
||||
if (noteName.equals("GNU") && note_type == Elf.Section.NT_GNU_BUILD_ID) { //$NON-NLS-1$
|
||||
// We have the special GNU build-id note section. Skip over the name to
|
||||
// a 4-byte boundary.
|
||||
byte[] byteArray = new byte[data_sz];
|
||||
while ((data.position() & 0x3) != 0)
|
||||
data.get();
|
||||
int i = 0;
|
||||
// Read in the hex bytes from the note section's data.
|
||||
while (data.hasRemaining() && data_sz-- > 0) {
|
||||
byteArray[i++] = data.get();
|
||||
}
|
||||
// The build-id location is taken by converting the binary bytes to hex string.
|
||||
// The first byte is used as a directory specifier (e.g. 51/a4578fe2).
|
||||
String bName = DatatypeConverter.printHexBinary(byteArray).toLowerCase();
|
||||
buildId = bName.substring(0, 2) + "/" + bName.substring(2) + ".debug"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
// The build-id file should be in the special directory /usr/lib/debug/.build-id
|
||||
IPath buildIdPath = new Path("/usr/lib/debug/.build-id").append(buildId); //$NON-NLS-1$
|
||||
File buildIdFile = buildIdPath.toFile();
|
||||
if (buildIdFile.exists()) {
|
||||
// if the debug file exists from above, open it and get the section info from it
|
||||
Elf debugInfo = new Elf(buildIdFile.getCanonicalPath());
|
||||
sections = debugInfo.getSections();
|
||||
have_build_id = true;
|
||||
debugInfoPath = new Path(buildIdFile.getCanonicalPath()).removeLastSegments(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue