Merge remote-tracking branch 'origin/GP-3175_dev747368_dwarf_apple_silicon_kdk'

This commit is contained in:
Ryan Kurtz 2023-03-24 08:09:15 -04:00
commit 9594431f09
8 changed files with 57 additions and 5 deletions

View file

@ -431,6 +431,27 @@ public class DIEAggregate {
return getRef(DWARFAttribute.DW_AT_type);
}
/**
* Returns the name of the source file this item was declared in (DW_AT_decl_file)
*
* @return name of file this item was declared in, or null if info not available
*/
public String getSourceFile() {
AttrInfo attrInfo = findAttribute(DWARFAttribute.DW_AT_decl_file);
if (attrInfo == null) {
return null;
}
DWARFNumericAttribute attr = attrInfo.getValue(DWARFNumericAttribute.class);
if (attr == null) {
return null;
}
int fileNum = (int) attr.getUnsignedValue();
DWARFCompileUnit dcu = attrInfo.die.getCompilationUnit().getCompileUnit();
return dcu.isValidFileIndex(fileNum)
? dcu.getFileByIndex(fileNum)
: null;
}
/**
* Return a list of children that are of a specific DWARF type.
* <p>

View file

@ -144,6 +144,16 @@ public class DWARFCompileUnit {
return this.line.getFile(index, this.comp_dir);
}
/**
* Checks validity of a file index number.
*
* @param index file number, 1..N
* @return boolean true if index is a valid file number, false otherwise
*/
public boolean isValidFileIndex(int index) {
return line.isValidFileIndex(index);
}
/**
* Get the producer of the compile unit
* @return the producer of the compile unit

View file

@ -190,6 +190,17 @@ public class DWARFLine {
"Negative file index was given: " + Integer.toString(index));
}
/**
* Returns true if file exists.
*
* @param index file number, excluding 0
* @return boolean true if file exists
*/
public boolean isValidFileIndex(int index) {
index--;
return 0 <= index && index < file_names.size();
}
@Override
public String toString() {
StringBuffer buffer = new StringBuffer();

View file

@ -157,6 +157,14 @@ public final class DWARFAttribute {
public static final int DW_AT_GNU_pubtypes = 0x2135;
// end GNU DebugFission
// Apple proprietary tags
public static final int DW_AT_APPLE_ptrauth_key = 0x3e04;
public static final int DW_AT_APPLE_ptrauth_address_discriminated = 0x3e05;
public static final int DW_AT_APPLE_ptrauth_extra_discriminator = 0x3e06;
public static final int DW_AT_APPLE_omit_frame_ptr = 0x3fe7;
public static final int DW_AT_APPLE_optimized = 0x3fe1;
// end Apple proprietary tags
public static String toString(long value) {
return DWARFUtil.toString(DWARFAttribute.class, value);
}

View file

@ -98,4 +98,6 @@ public final class DWARFTag
public static final int DW_TAG_gnu_call_site_parameter = 0x410a;
public static final int DW_TAG_hi_user = 0xffff;
public static final int DW_TAG_APPLE_ptrauth_type = 0x4300; // Apple proprietary
}

View file

@ -175,6 +175,7 @@ public class DWARFDataTypeImporter {
case DWARFTag.DW_TAG_volatile_type:
case DWARFTag.DW_TAG_restrict_type:
case DWARFTag.DW_TAG_shared_type:
case DWARFTag.DW_TAG_APPLE_ptrauth_type:
result = makeDataTypeForConst(diea);
break;
case DWARFTag.DW_TAG_enumeration_type:

View file

@ -34,12 +34,11 @@ public class DWARFSourceInfo {
* @return new {@link DWARFSourceInfo} with filename:linenum info, or null if no info present in DIEA.
*/
public static DWARFSourceInfo create(DIEAggregate diea) {
int fileNum = (int) diea.getUnsignedLong(DWARFAttribute.DW_AT_decl_file, -1);
String file = diea.getSourceFile();
int lineNum = (int) diea.getUnsignedLong(DWARFAttribute.DW_AT_decl_line, -1);
return (fileNum != -1 && lineNum != -1)
? new DWARFSourceInfo(
diea.getCompilationUnit().getCompileUnit().getFileByIndex(fileNum), lineNum)
return (file != null && lineNum != -1)
? new DWARFSourceInfo(file, lineNum)
: null;
}

View file

@ -285,7 +285,7 @@ public class DataTypeUtilities {
DataType dataType2) {
if (dataType1 instanceof BuiltIn) {
// Same kind if both types share a common BuiltIn implementation
Class<?> baseClass = dataType1.getClass().getSuperclass();
Class<?> baseClass = dataType1.getClass();
Class<?> superClass;
while ((superClass = baseClass.getSuperclass()) != BuiltIn.class) {
baseClass = superClass;