From 23c1b63f55f704f0f9968658cf8ebd13404737f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaus=20K=C3=A4mpf?= Date: Mon, 12 Sep 2022 19:57:33 +0200 Subject: [PATCH] Improve sleigh compiler error messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Klaus Kämpf --- .../src/decompile/cpp/slgh_compile.cc | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.cc index c26cd468fd..bc0585e754 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.cc @@ -1945,8 +1945,10 @@ void SleighCompile::buildPatterns(void) errors += 1; } for(int4 i=0;iisError()) + if (tables[i]->isError()) { + reportError(getLocation(tables[i]), "Problem in table '"+tables[i]->getName() + "':" + msg.str()); errors += 1; + } if (tables[i]->getPattern() == (TokenPattern *)0) { reportWarning(getLocation(tables[i]), "Unreferenced table '"+tables[i]->getName() + "'"); } @@ -2192,7 +2194,11 @@ const Location *SleighCompile::getLocation(Constructor *ctor) const const Location *SleighCompile::getLocation(SleighSymbol *sym) const { - return &symbolLocationMap.at(sym); + try { + return &symbolLocationMap.at(sym); + } catch (const std::exception &e) { + return NULL; + } } /// The current filename and line number are placed into a Location object @@ -2241,7 +2247,7 @@ void SleighCompile::reportError(const Location* loc, const string &msg) void SleighCompile::reportError(const string &msg) { - cerr << "ERROR " << msg << endl; + cerr << filename.back() << ":" << lineno.back() << " - ERROR " << msg << endl; errors += 1; if (errors > 1000000) { cerr << "Too many errors: Aborting" << endl; @@ -2670,7 +2676,10 @@ void SleighCompile::attachValues(vector *symlist,vector *n if (sym == (ValueSymbol *)0) continue; PatternValue *patval = sym->getPatternValue(); if (patval->maxValue() + 1 != numlist->size()) { - reportError(getCurrentLocation(), "Attach value '" + sym->getName() + "' is wrong size for list"); + ostringstream msg; + msg << "Attach value '" + sym->getName(); + msg << "' (range 0.." << patval->maxValue() << ") is wrong size for list (of " << numlist->size() << " entries"; + reportError(getCurrentLocation(), msg.str()); } symtab.replaceSymbol(sym, new ValueMapSymbol(sym->getName(),patval,*numlist)); } @@ -2695,7 +2704,10 @@ void SleighCompile::attachNames(vector *symlist,vector * if (sym == (ValueSymbol *)0) continue; PatternValue *patval = sym->getPatternValue(); if (patval->maxValue() + 1 != names->size()) { - reportError(getCurrentLocation(), "Attach name '" + sym->getName() + "' is wrong size for list"); + ostringstream msg; + msg << "Attach name '" + sym->getName(); + msg << "' (range 0.." << patval->maxValue() << ") is wrong size for list (of " << names->size() << " entries)"; + reportError(getCurrentLocation(), msg.str()); } symtab.replaceSymbol(sym,new NameSymbol(sym->getName(),patval,*names)); } @@ -2720,7 +2732,10 @@ void SleighCompile::attachVarnodes(vector *symlist,vectorgetPatternValue(); if (patval->maxValue() + 1 != varlist->size()) { - reportError(getCurrentLocation(), "Attach varnode '" + sym->getName() + "' is wrong size for list"); + ostringstream msg; + msg << "Attach varnode '" + sym->getName(); + msg << "' (range 0.." << patval->maxValue() << ") is wrong size for list (of " << varlist->size() << " entries)"; + reportError(getCurrentLocation(), msg.str()); } int4 sz = 0; for(int4 j=0;jsize();++j) {