mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-09-28 17:11:11 -09:00
GP-536: Fixed parsing of architecture and sections with GDB 10.1
This commit is contained in:
@@ -30,13 +30,26 @@ import ghidra.util.Msg;
|
|||||||
public class GdbModuleImpl implements GdbModule {
|
public class GdbModuleImpl implements GdbModule {
|
||||||
protected static final Pattern OBJECT_FILE_LINE_PATTERN =
|
protected static final Pattern OBJECT_FILE_LINE_PATTERN =
|
||||||
Pattern.compile("\\s*Object file: (?<name>.*)");
|
Pattern.compile("\\s*Object file: (?<name>.*)");
|
||||||
protected static final Pattern OBJECT_SECTION_LINE_PATTERN = Pattern.compile(
|
|
||||||
|
// Pattern observed in GDB 8 (probably applies to previous, too)
|
||||||
|
protected static final Pattern OBJECT_SECTION_LINE_PATTERN_V8 = Pattern.compile(
|
||||||
"\\s*" + //
|
"\\s*" + //
|
||||||
"0x(?<vmaS>[0-9A-Fa-f]+)\\s*->\\s*" + //
|
"0x(?<vmaS>[0-9A-Fa-f]+)\\s*->\\s*" + //
|
||||||
"0x(?<vmaE>[0-9A-Fa-f]+)\\s+at\\s+" + //
|
"0x(?<vmaE>[0-9A-Fa-f]+)\\s+at\\s+" + //
|
||||||
"0x(?<offset>[0-9A-Fa-f]+)\\s*:\\s*" + //
|
"0x(?<offset>[0-9A-Fa-f]+)\\s*:\\s*" + //
|
||||||
"(?<name>\\S+)\\s+" + //
|
"(?<name>\\S+)\\s+" + //
|
||||||
"(?<attrs>.*)");
|
"(?<attrs>.*)");
|
||||||
|
|
||||||
|
// Pattern observed in GDB 10 (may apply in 9, too)
|
||||||
|
protected static final Pattern OBJECT_SECTION_LINE_PATTERN_V10 = Pattern.compile(
|
||||||
|
"\\s*" + //
|
||||||
|
"\\[\\s*(?<idx>\\d+)\\]\\s+" + //
|
||||||
|
"0x(?<vmaS>[0-9A-Fa-f]+)\\s*->\\s*" + //
|
||||||
|
"0x(?<vmaE>[0-9A-Fa-f]+)\\s+at\\s+" + //
|
||||||
|
"0x(?<offset>[0-9A-Fa-f]+)\\s*:\\s*" + //
|
||||||
|
"(?<name>\\S+)\\s+" + //
|
||||||
|
"(?<attrs>.*)");
|
||||||
|
|
||||||
protected static final Pattern MSYMBOL_LINE_PATTERN = Pattern.compile(
|
protected static final Pattern MSYMBOL_LINE_PATTERN = Pattern.compile(
|
||||||
"\\s*" + //
|
"\\s*" + //
|
||||||
"\\[\\s*(?<idx>\\d+)\\]\\s+" + //
|
"\\[\\s*(?<idx>\\d+)\\]\\s+" + //
|
||||||
@@ -50,6 +63,8 @@ public class GdbModuleImpl implements GdbModule {
|
|||||||
protected Long base = null;
|
protected Long base = null;
|
||||||
protected Long max = null;
|
protected Long max = null;
|
||||||
|
|
||||||
|
protected Pattern sectionLinePattern = OBJECT_SECTION_LINE_PATTERN_V10;
|
||||||
|
|
||||||
protected final Map<String, GdbModuleSectionImpl> sections = new LinkedHashMap<>();
|
protected final Map<String, GdbModuleSectionImpl> sections = new LinkedHashMap<>();
|
||||||
protected final Map<String, GdbModuleSection> unmodifiableSections =
|
protected final Map<String, GdbModuleSection> unmodifiableSections =
|
||||||
Collections.unmodifiableMap(sections);
|
Collections.unmodifiableMap(sections);
|
||||||
@@ -143,8 +158,32 @@ public class GdbModuleImpl implements GdbModule {
|
|||||||
return minimalSymbols.request();
|
return minimalSymbols.request();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Matcher matchSectionLine(Pattern pattern, String line) {
|
||||||
|
Matcher matcher = pattern.matcher(line);
|
||||||
|
if (matcher.matches()) {
|
||||||
|
sectionLinePattern = pattern;
|
||||||
|
}
|
||||||
|
return matcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Matcher matchSectionLine(String line) {
|
||||||
|
Matcher matcher = sectionLinePattern.matcher(line);
|
||||||
|
if (matcher.matches()) {
|
||||||
|
return matcher;
|
||||||
|
}
|
||||||
|
matcher = matchSectionLine(OBJECT_SECTION_LINE_PATTERN_V10, line);
|
||||||
|
if (matcher.matches()) {
|
||||||
|
return matcher;
|
||||||
|
}
|
||||||
|
matcher = matchSectionLine(OBJECT_SECTION_LINE_PATTERN_V8, line);
|
||||||
|
if (matcher.matches()) {
|
||||||
|
return matcher;
|
||||||
|
}
|
||||||
|
return matcher;
|
||||||
|
}
|
||||||
|
|
||||||
protected void processSectionLine(String line) {
|
protected void processSectionLine(String line) {
|
||||||
Matcher matcher = OBJECT_SECTION_LINE_PATTERN.matcher(line);
|
Matcher matcher = matchSectionLine(line);
|
||||||
if (matcher.matches()) {
|
if (matcher.matches()) {
|
||||||
try {
|
try {
|
||||||
long vmaStart = Long.parseLong(matcher.group("vmaS"), 16);
|
long vmaStart = Long.parseLong(matcher.group("vmaS"), 16);
|
||||||
|
|||||||
@@ -74,11 +74,15 @@ public class GdbModelTargetEnvironment
|
|||||||
String[] tokens = out.split("\\s+");
|
String[] tokens = out.split("\\s+");
|
||||||
@SuppressWarnings("hiding")
|
@SuppressWarnings("hiding")
|
||||||
String arch = tokens[tokens.length - 1].trim();
|
String arch = tokens[tokens.length - 1].trim();
|
||||||
if (arch.endsWith(")")) {
|
while (arch.endsWith(".") || arch.endsWith(")") || arch.endsWith("\"")) {
|
||||||
arch = arch.substring(0, arch.length() - 1);
|
arch = arch.substring(0, arch.length() - 1);
|
||||||
}
|
}
|
||||||
|
while (arch.startsWith("\"")) {
|
||||||
|
arch = arch.substring(1);
|
||||||
|
}
|
||||||
// e.g., The target architecture is set automatically (currently i386)
|
// e.g., The target architecture is set automatically (currently i386)
|
||||||
// e.g., The target architecture is assumed to be i386
|
// e.g., The target architecture is assumed to be i386
|
||||||
|
// e.g., The target architecture is set to "auto" (currently "i386").
|
||||||
// TODO: I don't have a way to detect if this parsing strategy fails.
|
// TODO: I don't have a way to detect if this parsing strategy fails.
|
||||||
// TODO: I could search using a list of support architectures
|
// TODO: I could search using a list of support architectures
|
||||||
// Use "set architecture" to get "Valid arguments"
|
// Use "set architecture" to get "Valid arguments"
|
||||||
|
|||||||
Reference in New Issue
Block a user