mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 02:39:44 +02:00
Merge remote-tracking branch
'origin/GP-233_James_add_sleigh_filenames--SQUASHED'
This commit is contained in:
commit
6196a53a94
13 changed files with 415 additions and 75 deletions
|
@ -15,7 +15,48 @@
|
|||
*/
|
||||
#include "sleighbase.hh"
|
||||
|
||||
const int4 SleighBase::SLA_FORMAT_VERSION = 2;
|
||||
const int4 SleighBase::SLA_FORMAT_VERSION = 3;
|
||||
|
||||
int4 SourceFileIndexer::index(const string filename){
|
||||
auto it = fileToIndex.find(filename);
|
||||
if (fileToIndex.end() != it){
|
||||
return it->second;
|
||||
}
|
||||
fileToIndex[filename] = leastUnusedIndex;
|
||||
indexToFile[leastUnusedIndex] = filename;
|
||||
return leastUnusedIndex++;
|
||||
}
|
||||
|
||||
int4 SourceFileIndexer::getIndex(string filename){
|
||||
return fileToIndex[filename];
|
||||
}
|
||||
|
||||
string SourceFileIndexer::getFilename(int4 index){
|
||||
return indexToFile[index];
|
||||
}
|
||||
|
||||
void SourceFileIndexer::restoreXml(const Element *el){
|
||||
const List &sourceFiles(el->getChildren());
|
||||
List::const_iterator iter = sourceFiles.begin();
|
||||
for (; iter != sourceFiles.end(); ++iter){
|
||||
string filename = (*iter)->getAttributeValue("name");
|
||||
int4 index = stoi((*iter)->getAttributeValue("index"),NULL,10);
|
||||
fileToIndex[filename] = index;
|
||||
indexToFile[index] = filename;
|
||||
}
|
||||
}
|
||||
|
||||
void SourceFileIndexer::saveXml(ostream& s) const {
|
||||
s << "<sourcefiles>\n";
|
||||
for (int4 i = 0; i < leastUnusedIndex; ++i){
|
||||
s << ("<sourcefile name=\"");
|
||||
const char *str = indexToFile.at(i).c_str();
|
||||
xml_escape(s,str);
|
||||
s << "\" index=\"" << dec << i << "\"/>\n";
|
||||
}
|
||||
s << "</sourcefiles>\n";
|
||||
}
|
||||
|
||||
|
||||
SleighBase::SleighBase(void)
|
||||
|
||||
|
@ -155,7 +196,7 @@ void SleighBase::saveXml(ostream &s) const
|
|||
if (numSections != 0)
|
||||
a_v_u(s,"numsections",numSections);
|
||||
s << ">\n";
|
||||
|
||||
indexer.saveXml(s);
|
||||
s << "<spaces";
|
||||
a_v(s,"defaultspace",getDefaultCodeSpace()->getName());
|
||||
s << ">\n";
|
||||
|
@ -231,6 +272,8 @@ void SleighBase::restoreXml(const Element *el)
|
|||
floatformats.back().restoreXml(*iter);
|
||||
++iter;
|
||||
}
|
||||
indexer.restoreXml(*iter);
|
||||
iter++;
|
||||
restoreXmlSpaces(*iter,this);
|
||||
iter++;
|
||||
symtab.restoreXml(*iter,this);
|
||||
|
|
|
@ -21,7 +21,35 @@
|
|||
#include "translate.hh"
|
||||
#include "slghsymbol.hh"
|
||||
|
||||
/// \brief class for recording source file information for SLEIGH constructors.
|
||||
|
||||
///
|
||||
/// A SLEIGH specification may contain many source files. This class is
|
||||
/// used to associate each constructor in a SLEIGH language to the source
|
||||
/// file where it is defined. This information is useful when debugging
|
||||
/// SLEIGH specifications. Sourcefiles are assigned a numeric index and
|
||||
/// the mapping from indices to filenames is written to the generated .sla
|
||||
/// file. For each constructor, the data written to the .sla file includes
|
||||
/// the source file index.
|
||||
class SourceFileIndexer {
|
||||
public:
|
||||
SourceFileIndexer() {leastUnusedIndex = 0;}
|
||||
~SourceFileIndexer(void) { }
|
||||
///Returns the index of the file. If the file is not in the index it is added.
|
||||
int4 index(const string filename);
|
||||
int4 getIndex(const string); ///< get the index of a file. Error if the file is not in the index.
|
||||
string getFilename(int4); ///< get the filename corresponding to an index
|
||||
void restoreXml(const Element *el); ///< read a stored index mapping from an XML file
|
||||
void saveXml(ostream&) const; ///< save the index mapping to an XML file
|
||||
|
||||
private:
|
||||
int4 leastUnusedIndex; ///< one-up count for assigning indices to files
|
||||
map<int4, string> indexToFile; ///< map from indices to files
|
||||
map<string, int4> fileToIndex; ///< map from files to indices
|
||||
};
|
||||
|
||||
/// \brief Common core of classes that read or write SLEIGH specification files natively.
|
||||
|
||||
///
|
||||
/// This class represents what's in common across the SLEIGH infrastructure between:
|
||||
/// - Reading the various SLEIGH specification files
|
||||
|
@ -36,6 +64,7 @@ protected:
|
|||
uint4 maxdelayslotbytes; ///< Maximum number of bytes in a delay-slot directive
|
||||
uint4 unique_allocatemask; ///< Bits that are guaranteed to be zero in the unique allocation scheme
|
||||
uint4 numSections; ///< Number of \e named sections
|
||||
SourceFileIndexer indexer; ///< source file index used when generating SLEIGH constructor debug info
|
||||
void buildXrefs(vector<string> &errorPairs); ///< Build register map. Collect user-ops and context-fields.
|
||||
void reregisterContext(void); ///< Reregister context fields for a new executable
|
||||
void restoreXml(const Element *el); ///< Read a SLEIGH specification from XML
|
||||
|
|
|
@ -2502,6 +2502,8 @@ Constructor *SleighCompile::createConstructor(SubtableSymbol *sym)
|
|||
sym->addConstructor(curct);
|
||||
symtab.addScope(); // Make a new symbol scope for our constructor
|
||||
pcode.resetLabelCount();
|
||||
int4 index = indexer.index(ctorLocationMap[curct].getFilename());
|
||||
curct->setSrcIndex(index);
|
||||
return curct;
|
||||
}
|
||||
|
||||
|
|
|
@ -1596,7 +1596,7 @@ void Constructor::saveXml(ostream &s) const
|
|||
s << " parent=\"0x" << hex << parent->getId() << "\"";
|
||||
s << " first=\"" << dec << firstwhitespace << "\"";
|
||||
s << " length=\"" << minimumlength << "\"";
|
||||
s << " line=\"" << lineno << "\">\n";
|
||||
s << " line=\"" << src_index << ":" << lineno << "\">\n";
|
||||
for(int4 i=0;i<operands.size();++i)
|
||||
s << "<oper id=\"0x" << hex << operands[i]->getId() << "\"/>\n";
|
||||
for(int4 i=0;i<printpiece.size();++i) {
|
||||
|
@ -1643,9 +1643,10 @@ void Constructor::restoreXml(const Element *el,SleighBase *trans)
|
|||
s >> minimumlength;
|
||||
}
|
||||
{
|
||||
istringstream s(el->getAttributeValue("line"));
|
||||
s.unsetf(ios::dec | ios::hex | ios::oct);
|
||||
s >> lineno;
|
||||
string src_and_line = el->getAttributeValue("line");
|
||||
size_t pos = src_and_line.find(":");
|
||||
src_index = stoi(src_and_line.substr(0, pos),NULL,10);
|
||||
lineno = stoi(src_and_line.substr(pos+1,src_and_line.length()),NULL,10);
|
||||
}
|
||||
const List &list(el->getChildren());
|
||||
List::const_iterator iter;
|
||||
|
|
|
@ -477,6 +477,7 @@ class Constructor { // This is NOT a symbol
|
|||
int4 firstwhitespace; // Index of first whitespace piece in -printpiece-
|
||||
int4 flowthruindex; // if >=0 then print only a single operand no markup
|
||||
int4 lineno;
|
||||
int4 src_index; //source file index
|
||||
mutable bool inerror; // An error is associated with this Constructor
|
||||
void orderOperands(void);
|
||||
public:
|
||||
|
@ -491,6 +492,8 @@ public:
|
|||
uintm getId(void) const { return id; }
|
||||
void setLineno(int4 ln) { lineno = ln; }
|
||||
int4 getLineno(void) const { return lineno; }
|
||||
void setSrcIndex(int4 index) {src_index = index;}
|
||||
int4 getSrcIndex(void) {return src_index;}
|
||||
void addContext(const vector<ContextChange *> &vec) { context = vec; }
|
||||
void addOperand(OperandSymbol *sym);
|
||||
void addInvisibleOperand(OperandSymbol *sym);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue