From e65bede08bb8c84213613be29be97e037f3934b3 Mon Sep 17 00:00:00 2001 From: ghidra1 Date: Fri, 17 Nov 2023 10:33:36 -0500 Subject: [PATCH] GP-0 Corrected loongarch ilp32f pentry sizing issue. Improved cspec parse error reporting to include line number. --- .../sleigh/SleighLanguageValidator.java | 8 +--- .../program/model/lang/BasicCompilerSpec.java | 44 ++++++++++--------- .../Loongarch/data/languages/ilp32f.cspec | 18 ++++---- .../Loongarch/data/languages/loongarch.ldefs | 27 ++++++------ 4 files changed, 48 insertions(+), 49 deletions(-) diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/sleigh/SleighLanguageValidator.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/sleigh/SleighLanguageValidator.java index 36397c7e8d..41cfde76f2 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/sleigh/SleighLanguageValidator.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/sleigh/SleighLanguageValidator.java @@ -139,11 +139,9 @@ public class SleighLanguageValidator { throw new SleighException( specFile + " is not properly case dependent: " + result.getMessage()); } - try { - InputStream in = specFile.getInputStream(); + try (InputStream in = specFile.getInputStream()) { verifier.setErrorHandler(new VerifierErrorHandler(specFile)); verifier.verify(new InputSource(in)); - in.close(); } catch (Exception e) { throw new SleighException( @@ -211,11 +209,9 @@ public class SleighLanguageValidator { catch (Exception e) { throw new SleighException("Error creating verifier", e); } - try { - InputStream in = fileToValidate.getInputStream(); + try (InputStream in = fileToValidate.getInputStream()) { verifier.setErrorHandler(new VerifierErrorHandler(fileToValidate)); verifier.verify(new InputSource(in)); - in.close(); } catch (Exception e) { throw new SleighException( diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/lang/BasicCompilerSpec.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/lang/BasicCompilerSpec.java index 09e34cc9b4..a4ab9dffec 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/lang/BasicCompilerSpec.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/lang/BasicCompilerSpec.java @@ -121,36 +121,41 @@ public class BasicCompilerSpec implements CompilerSpec { Exception parseException = null; ErrorHandler errHandler = getErrorHandler(cspecFile.toString()); - InputStream stream; + XmlPullParser parser = null; try { SleighLanguageValidator.validateCspecFile(cspecFile); - stream = cspecFile.getInputStream(); - XmlPullParser parser = - XmlPullParserFactory.create(stream, cspecFile.getAbsolutePath(), errHandler, false); - initialize(cspecFile.getAbsolutePath(), parser); - stream.close(); + try (InputStream stream = cspecFile.getInputStream()) { + parser = XmlPullParserFactory.create(stream, cspecFile.getAbsolutePath(), + errHandler, false); + initialize(cspecFile.getAbsolutePath(), parser); + } if (models == null || models.length == 0) { throw new SAXException("No prototype models defined"); } } - catch (SleighException e) { + catch (Exception e) { parseException = e; - Throwable cause = e.getCause(); // Recover the cause (from the validator exception) - if (cause != null) { - if (cause instanceof SAXException || cause instanceof IOException) { - parseException = (Exception) cause; + if (e instanceof SleighException) { + Throwable cause = e.getCause(); // Recover the cause (from the validator exception) + if (cause != null) { + if (cause instanceof SAXException || cause instanceof IOException) { + parseException = (Exception) cause; + } } } - } - catch (IOException | SAXException | XmlParseException | DuplicateNameException e) { - parseException = e; - } - - if (parseException != null) { + String lineInfo = ""; + if (parser != null) { + lineInfo = ":" + parser.getLineNumber(); + } throw new CompilerSpecNotFoundException(language.getLanguageID(), - description.getCompilerSpecID(), cspecFile.getName(), parseException); + description.getCompilerSpecID(), cspecFile.getName() + lineInfo, parseException); + } + finally { + if (parser != null) { + parser.dispose(); + } } } @@ -1084,8 +1089,7 @@ public class BasicCompilerSpec implements CompilerSpec { @Override public PrototypeModel matchConvention(String conventionName) { - if (conventionName == null || - CALLING_CONVENTION_unknown.equals(conventionName) || + if (conventionName == null || CALLING_CONVENTION_unknown.equals(conventionName) || CALLING_CONVENTION_default.equals(conventionName)) { return defaultModel; } diff --git a/Ghidra/Processors/Loongarch/data/languages/ilp32f.cspec b/Ghidra/Processors/Loongarch/data/languages/ilp32f.cspec index f43c6a5fd0..3ece9fc402 100644 --- a/Ghidra/Processors/Loongarch/data/languages/ilp32f.cspec +++ b/Ghidra/Processors/Loongarch/data/languages/ilp32f.cspec @@ -29,28 +29,28 @@ - + - + - + - + - + - + - + - + @@ -94,7 +94,7 @@ - + diff --git a/Ghidra/Processors/Loongarch/data/languages/loongarch.ldefs b/Ghidra/Processors/Loongarch/data/languages/loongarch.ldefs index 2661e7c86c..e49fbe075b 100644 --- a/Ghidra/Processors/Loongarch/data/languages/loongarch.ldefs +++ b/Ghidra/Processors/Loongarch/data/languages/loongarch.ldefs @@ -29,6 +29,19 @@ + + Loongson 3 64-bit with 32-bit FP + + + - - - Loongson 3 64-bit with 64-bit FP - - - \ No newline at end of file