Merge remote-tracking branch 'origin/GP-3369_DecompilerTemplateShortening' into patch

This commit is contained in:
Ryan Kurtz 2023-05-24 12:46:45 -04:00
commit 75b1dd163f
31 changed files with 709 additions and 134 deletions

View file

@ -213,7 +213,7 @@ CallGraphNode *CallGraph::addNode(Funcdata *f)
throw LowlevelError("Functions with duplicate entry points: "+f->getName()+" "+node.getFuncdata()->getName());
node.entryaddr = f->getAddress();
node.name = f->getName();
node.name = f->getDisplayName();
node.fd = f;
return &node;
}

View file

@ -395,6 +395,7 @@ void Symbol::decodeHeader(Decoder &decoder)
{
name.clear();
displayName.clear();
category = no_category;
symbolId = 0;
for(;;) {
@ -447,12 +448,17 @@ void Symbol::decodeHeader(Decoder &decoder)
if (decoder.readBool())
flags |= Varnode::volatil;
}
else if (attribId == ATTRIB_LABEL) {
displayName = decoder.readString();
}
}
if (category == function_parameter) {
catindex = decoder.readUnsignedInteger(ATTRIB_INDEX);
}
else
catindex = 0;
if (displayName.size() == 0)
displayName = name;
}
/// Encode the data-type for the Symbol
@ -532,6 +538,7 @@ FunctionSymbol::FunctionSymbol(Scope *sc,const string &nm,int4 size)
consumeSize = size;
buildType();
name = nm;
displayName = nm;
}
FunctionSymbol::FunctionSymbol(Scope *sc,int4 size)
@ -552,7 +559,7 @@ Funcdata *FunctionSymbol::getFunction(void)
{
if (fd != (Funcdata *)0) return fd;
SymbolEntry *entry = getFirstWholeMap();
fd = new Funcdata(name,scope,entry->getAddr(),this);
fd = new Funcdata(name,displayName,scope,entry->getAddr(),this);
return fd;
}
@ -575,7 +582,7 @@ void FunctionSymbol::decode(Decoder &decoder)
{
uint4 elemId = decoder.peekElement();
if (elemId == ELEM_FUNCTION) {
fd = new Funcdata("",scope,Address(),this);
fd = new Funcdata("","",scope,Address(),this);
try {
symbolId = fd->decode(decoder);
} catch(RecovError &err) {
@ -583,6 +590,7 @@ void FunctionSymbol::decode(Decoder &decoder)
throw DuplicateFunctionError(fd->getAddress(),fd->getName());
}
name = fd->getName();
displayName = fd->getDisplayName();
if (consumeSize < fd->getSize()) {
if ((fd->getSize()>1)&&(fd->getSize() <= 8))
consumeSize = fd->getSize();
@ -599,6 +607,9 @@ void FunctionSymbol::decode(Decoder &decoder)
else if (attribId == ATTRIB_ID) {
symbolId = decoder.readUnsignedInteger();
}
else if (attribId == ATTRIB_LABEL) {
displayName = decoder.readString();
}
}
decoder.closeElement(elemId);
}
@ -727,6 +738,7 @@ LabSymbol::LabSymbol(Scope *sc,const string &nm)
{
buildType();
name = nm;
displayName = nm;
}
/// \param sc is the Scope that will contain the new Symbol
@ -766,6 +778,8 @@ void ExternRefSymbol::buildNameType(void)
name = s.str();
name += "_exref"; // Indicate this is an external reference variable
}
if (displayName.size() == 0)
displayName = name;
flags |= Varnode::externref | Varnode::typelock;
}
@ -792,12 +806,15 @@ void ExternRefSymbol::decode(Decoder &decoder)
{
uint4 elemId = decoder.openElement(ELEM_EXTERNREFSYMBOL);
name = ""; // Name is empty
name.clear(); // Name is empty
displayName.clear();
for(;;) {
uint4 attribId = decoder.getNextAttributeId();
if (attribId == 0) break;
if (attribId == ATTRIB_NAME) // Unless we see it explicitly
name = decoder.readString();
else if (attribId == ATTRIB_LABEL)
displayName = decoder.readString();
}
refaddr = Address::decode(decoder);
decoder.closeElement(elemId);
@ -1798,8 +1815,10 @@ void ScopeInternal::addSymbolInternal(Symbol *sym)
nextUniqueId += 1;
}
try {
if (sym->name.size() == 0)
if (sym->name.size() == 0) {
sym->name = buildUndefinedName();
sym->displayName = sym->name;
}
if (sym->getType() == (Datatype *)0)
throw LowlevelError(sym->getName() + " symbol created with no type");
if (sym->getType()->getSize() < 1)
@ -2138,6 +2157,7 @@ void ScopeInternal::renameSymbol(Symbol *sym,const string &newname)
multiEntrySet.erase(sym); // The multi-entry set is sorted by name, remove
string oldname = sym->name;
sym->name = newname;
sym->displayName = newname;
insertNameTree(sym);
if (sym->wholeCount > 1)
multiEntrySet.insert(sym); // Reenter into the multi-entry set now that name is changed
@ -3315,14 +3335,32 @@ void Database::decode(Decoder &decoder)
for(;;) {
uint4 subId = decoder.openElement();
if (subId != ELEM_SCOPE) break;
string name = decoder.readString(ATTRIB_NAME);
uint8 id = decoder.readUnsignedInteger(ATTRIB_ID);
string name;
string displayName;
uint8 id = 0;
bool seenId = false;
for(;;) {
uint4 attribId = decoder.getNextAttributeId();
if (attribId == 0) break;
if (attribId == ATTRIB_NAME)
name = decoder.readString();
else if (attribId == ATTRIB_ID) {
id = decoder.readUnsignedInteger();
seenId = true;
}
else if (attribId == ATTRIB_LABEL)
displayName = decoder.readString();
}
if (name.empty() || !seenId)
throw DecoderError("Missing name and id attributes in scope");
Scope *parentScope = (Scope *)0;
uint4 parentId = decoder.peekElement();
if (parentId == ELEM_PARENT) {
parentScope = parseParentTag(decoder);
}
Scope *newScope = findCreateScope(id, name, parentScope);
if (!displayName.empty())
newScope->setDisplayName(displayName);
newScope->decode(decoder);
decoder.closeElement(subId);
}
@ -3356,4 +3394,39 @@ void Database::decodeScope(Decoder &decoder,Scope *newScope)
decoder.closeElement(elemId);
}
/// Some namespace objects may already exist. Create those that don't.
/// \param decoder is the stream to decode the path from
/// \return the namespace described by the path
Scope *Database::decodeScopePath(Decoder &decoder)
{
Scope *curscope = getGlobalScope();
uint4 elemId = decoder.openElement(ELEM_PARENT);
uint4 subId = decoder.openElement();
decoder.closeElementSkipping(subId); // Skip element describing the root scope
for(;;) {
subId = decoder.openElement();
if (subId != ELEM_VAL) break;
string displayName;
uint8 scopeId = 0;
for(;;) {
uint4 attribId = decoder.getNextAttributeId();
if (attribId == 0) break;
if (attribId == ATTRIB_ID)
scopeId = decoder.readUnsignedInteger();
else if (attribId == ATTRIB_LABEL)
displayName = decoder.readString();
}
string name = decoder.readString(ATTRIB_CONTENT);
if (scopeId == 0)
throw DecoderError("Missing name and id in scope");
curscope = findCreateScope(scopeId, name, curscope);
if (!displayName.empty())
curscope->setDisplayName(displayName);
decoder.closeElement(subId);
}
decoder.closeElement(elemId);
return curscope;
}
} // End namespace ghidra

View file

@ -176,6 +176,7 @@ class Symbol {
protected:
Scope *scope; ///< The scope that owns this symbol
string name; ///< The local name of the symbol
string displayName; ///< Name to use when displaying symbol in output
Datatype *type; ///< The symbol's data-type
uint4 nameDedup; ///< id to distinguish symbols with the same name
uint4 flags; ///< Varnode-like properties of the symbol
@ -218,6 +219,7 @@ public:
Symbol(Scope *sc,const string &nm,Datatype *ct); ///< Construct given a name and data-type
Symbol(Scope *sc); ///< Construct for use with decode()
const string &getName(void) const { return name; } ///< Get the local name of the symbol
const string &getDisplayName(void) const { return displayName; } ///< Get the name to display in output
Datatype *getType(void) const { return type; } ///< Get the data-type
uint8 getId(void) const { return symbolId; } ///< Get a unique id for the symbol
uint4 getFlags(void) const { return flags; } ///< Get the boolean properties of the Symbol
@ -469,6 +471,7 @@ class Scope {
protected:
Architecture *glb; ///< Architecture of \b this scope
string name; ///< Name of \b this scope
string displayName; ///< Name to display in output
Funcdata *fd; ///< (If non-null) the function which \b this is the local Scope for
uint8 uniqueId; ///< Unique id for the scope, for deduping scope names, assigning symbol ids
static const Scope *stackAddr(const Scope *scope1,
@ -551,6 +554,7 @@ protected:
const RangeList &uselim)=0;
SymbolEntry *addMap(SymbolEntry &entry); ///< Integrate a SymbolEntry into the range maps
void setSymbolId(Symbol *sym,uint8 id) const { sym->symbolId = id; } ///< Adjust the id associated with a symbol
void setDisplayName(const string &nm) { displayName = nm; } ///< Change name displayed in output
public:
#ifdef OPACTION_DEBUG
mutable bool debugon;
@ -559,7 +563,7 @@ public:
#endif
/// \brief Construct an empty scope, given a name and Architecture
Scope(uint8 id,const string &nm,Architecture *g,Scope *own) {
uniqueId = id; name = nm; glb = g; parent = (Scope *)0; fd = (Funcdata *)0; owner=own;
uniqueId = id; name = nm; displayName = nm; glb = g; parent = (Scope *)0; fd = (Funcdata *)0; owner=own;
#ifdef OPACTION_DEBUG
debugon = false;
#endif
@ -732,6 +736,7 @@ public:
const Address &addr,const Address &usepoint);
const string &getName(void) const { return name; } ///< Get the name of the Scope
const string &getDisplayName(void) const { return displayName; } ///< Get name displayed in output
uint8 getId(void) const { return uniqueId; } ///< Get the globally unique id
bool isGlobal(void) const { return (fd == (Funcdata *)0); } ///< Return \b true if \b this scope is global
@ -938,7 +943,8 @@ public:
const partmap<Address,uint4> &getProperties(void) const { return flagbase; } ///< Get the entire property map
void encode(Encoder &encoder) const; ///< Encode the whole Database to a stream
void decode(Decoder &decoder); ///< Decode the whole database from a stream
void decodeScope(Decoder &decoder,Scope *newScope); ///< Register and fill out a single Scope from an XML \<scope> tag
void decodeScope(Decoder &decoder,Scope *newScope); ///< Register and fill out a single Scope from an XML \<scope> tag
Scope *decodeScopePath(Decoder &decoder); ///< Decode a namespace path and make sure each namespace exists
};
/// \param sc is the scope containing the new symbol
@ -949,6 +955,7 @@ inline Symbol::Symbol(Scope *sc,const string &nm,Datatype *ct)
{
scope=sc;
name=nm;
displayName = nm;
nameDedup=0;
type=ct;
flags=0;

View file

@ -42,7 +42,7 @@ ScopeGhidra::~ScopeGhidra(void)
/// The Ghidra client reports a \e namespace id associated with
/// Symbol. Determine if a matching \e namespace Scope already exists in the cache and build
/// it if it isn't. This may mean creating a new \e namespace Scope.
/// it if it isn't. This may mean creating the \e namespace Scope and its ancestors.
/// \param id is the ID associated with the Ghidra namespace
/// \return the Scope matching the id.
Scope *ScopeGhidra::reresolveScope(uint8 id) const
@ -58,19 +58,7 @@ Scope *ScopeGhidra::reresolveScope(uint8 id) const
if (!ghidra->getNamespacePath(id,decoder))
throw LowlevelError("Could not get namespace info");
Scope *curscope = symboltab->getGlobalScope(); // Get pointer to ourselves (which is not const)
uint4 elemId = decoder.openElement();
uint4 subId = decoder.openElement();
decoder.closeElementSkipping(subId); // Skip element describing the root scope
for(;;) {
subId = decoder.openElement();
if (subId == 0) break;
uint8 scopeId = decoder.readUnsignedInteger(ATTRIB_ID);
curscope = symboltab->findCreateScope(scopeId, decoder.readString(ATTRIB_CONTENT), curscope);
decoder.closeElement(subId);
}
decoder.closeElement(elemId);
return curscope;
return symboltab->decodeScopePath(decoder);
}
/// The Ghidra client can respond to a query negatively by sending a

View file

@ -1398,8 +1398,9 @@ void FlowInfo::recoverJumpTables(vector<JumpTable *> &newTables,vector<PcodeOp *
s1 << data.getName() << "@@jump@";
op->getAddr().printRaw(s1);
string nm = s1.str();
// Prepare partial Funcdata object for analysis if necessary
Funcdata partial(s1.str(),data.getScopeLocal()->getParent(),data.getAddress(),(FunctionSymbol *)0);
Funcdata partial(nm,nm,data.getScopeLocal()->getParent(),data.getAddress(),(FunctionSymbol *)0);
for(int4 i=0;i<tablelist.size();++i) {
op = tablelist[i];

View file

@ -4668,8 +4668,8 @@ void FuncCallSpecs::setFuncdata(Funcdata *f)
fd = f;
if (fd != (Funcdata *)0) {
entryaddress = fd->getAddress();
if (fd->getName().size() != 0)
name = fd->getName();
if (fd->getDisplayName().size() != 0)
name = fd->getDisplayName();
}
}
@ -5130,7 +5130,7 @@ void FuncCallSpecs::deindirect(Funcdata &data,Funcdata *newfd)
{
entryaddress = newfd->getAddress();
name = newfd->getName();
name = newfd->getDisplayName();
fd = newfd;
Varnode *vn = data.newVarnodeCallSpecs(this);

View file

@ -30,7 +30,7 @@ ElementId ELEM_VARNODES = ElementId("varnodes",119);
/// \param addr is the entry address for the function
/// \param sym is the symbol representing the function
/// \param sz is the number of bytes (of code) in the function body
Funcdata::Funcdata(const string &nm,Scope *scope,const Address &addr,FunctionSymbol *sym,int4 sz)
Funcdata::Funcdata(const string &nm,const string &disp,Scope *scope,const Address &addr,FunctionSymbol *sym,int4 sz)
: baseaddr(addr),
funcp(),
vbank(scope->getArch()),
@ -47,6 +47,7 @@ Funcdata::Funcdata(const string &nm,Scope *scope,const Address &addr,FunctionSym
glb = scope->getArch();
minLanedSize = glb->getMinimumLanedRegisterSize();
name = nm;
displayName = disp;
size = sz;
AddrSpace *stackid = glb->getStackSpace();
@ -734,9 +735,13 @@ uint8 Funcdata::decode(Decoder &decoder)
if (decoder.readBool())
flags |= no_code;
}
else if (attribId == ATTRIB_LABEL)
displayName = decoder.readString();
}
if (name.size() == 0)
throw LowlevelError("Missing function name");
if (displayName.size() == 0)
displayName = name;
if (size == -1)
throw LowlevelError("Missing function size");
baseaddr = Address::decode( decoder );

View file

@ -79,6 +79,7 @@ class Funcdata {
Architecture *glb; ///< Global configuration data
FunctionSymbol *functionSymbol; ///< The symbol representing \b this function
string name; ///< Name of function
string displayName; ///< Name to display in output
Address baseaddr; ///< Starting code address of binary data
FuncProto funcp; ///< Prototype of this function
ScopeLocal *localmap; ///< Local variables (symbols in the function scope)
@ -136,9 +137,10 @@ class Funcdata {
static PcodeOp *findPrimaryBranch(PcodeOpTree::const_iterator iter,PcodeOpTree::const_iterator enditer,
bool findbranch,bool findcall,bool findreturn);
public:
Funcdata(const string &nm,Scope *conf,const Address &addr,FunctionSymbol *sym,int4 sz=0); ///< Constructor
Funcdata(const string &nm,const string &disp,Scope *conf,const Address &addr,FunctionSymbol *sym,int4 sz=0); ///< Constructor
~Funcdata(void); ///< Destructor
const string &getName(void) const { return name; } ///< Get the function's local symbol name
const string &getDisplayName(void) const { return displayName; } ///< Get the name to display in output
const Address &getAddress(void) const { return baseaddr; } ///< Get the entry point address
int4 getSize(void) const { return size; } ///< Get the function body size in bytes
Architecture *getArch(void) const { return glb; } ///< Get the program/architecture owning \b this function

View file

@ -222,7 +222,7 @@ void PrintC::pushSymbolScope(const Symbol *symbol)
pushOp(&scope, (PcodeOp *)0);
}
for(int4 i=scopedepth-1;i>=0;--i) {
pushAtom(Atom(scopeList[i]->getName(),syntax,EmitMarkup::global_color,(PcodeOp *)0,(Varnode *)0));
pushAtom(Atom(scopeList[i]->getDisplayName(),syntax,EmitMarkup::global_color,(PcodeOp *)0,(Varnode *)0));
}
}
}
@ -252,7 +252,7 @@ void PrintC::emitSymbolScope(const Symbol *symbol)
point = point->getParent();
}
for(int4 i=scopedepth-1;i>=0;--i) {
emit->print(scopeList[i]->getName(), EmitMarkup::global_color);
emit->print(scopeList[i]->getDisplayName(), EmitMarkup::global_color);
emit->print(scope.print1, EmitMarkup::no_color);
}
}
@ -285,7 +285,7 @@ void PrintC::pushTypeStart(const Datatype *ct,bool noident)
}
else {
pushOp(tok,(const PcodeOp *)0);
pushAtom(Atom(ct->getName(),typetoken,EmitMarkup::type_color,ct));
pushAtom(Atom(ct->getDisplayName(),typetoken,EmitMarkup::type_color,ct));
}
for(int4 i=typestack.size()-2;i>=0;--i) {
ct = typestack[i];
@ -661,7 +661,7 @@ void PrintC::opConstructor(const PcodeOp *op,bool withNew)
if (dt->getMetatype() == TYPE_PTR) {
dt = ((TypePointer *)dt)->getPtrTo();
}
string nm = dt->getName();
string nm = dt->getDisplayName();
pushOp(&function_call,op);
pushAtom(Atom(nm,optoken,EmitMarkup::funcname_color,op));
// implied vn's pushed on in reverse order for efficiency
@ -1112,7 +1112,7 @@ void PrintC::opCpoolRefOp(const PcodeOp *op)
pushAtom(Atom(rec->getToken(),functoken,EmitMarkup::funcname_color,op,outvn));
pushOp(&comma,(const PcodeOp *)0);
pushVn(vn0,op,mods);
pushAtom(Atom(dt->getName(),syntax,EmitMarkup::type_color,op,outvn));
pushAtom(Atom(dt->getDisplayName(),syntax,EmitMarkup::type_color,op,outvn));
break;
}
case CPoolRecord::primitive: // Should be eliminated
@ -1163,7 +1163,7 @@ void PrintC::opNewOp(const PcodeOp *op)
while (dt->getMetatype() == TYPE_PTR) {
dt = ((TypePointer *)dt)->getPtrTo();
}
nm = dt->getName();
nm = dt->getDisplayName();
}
pushOp(&subscript,op);
pushAtom(Atom(nm,optoken,EmitMarkup::type_color,op));
@ -1658,7 +1658,7 @@ bool PrintC::pushPtrCodeConstant(uintb val,const TypePointer *ct,
val = AddrSpace::addressToByte(val,spc->getWordSize());
fd = glb->symboltab->getGlobalScope()->queryFunction( Address(spc,val));
if (fd != (Funcdata *)0) {
pushAtom(Atom(fd->getName(),functoken,EmitMarkup::funcname_color,op,fd));
pushAtom(Atom(fd->getDisplayName(),functoken,EmitMarkup::funcname_color,op,fd));
return true;
}
return false;
@ -1839,7 +1839,7 @@ void PrintC::pushSymbol(const Symbol *sym,const Varnode *vn,const PcodeOp *op)
HighVariable *high = vn->getHigh();
if (high->isUnmerged()) {
ostringstream s;
s << sym->getName();
s << sym->getDisplayName();
SymbolEntry *entry = high->getSymbolEntry();
if (entry != (SymbolEntry *)0) {
s << '$' << dec << entry->getSymbol()->getMapEntryPosition(entry);
@ -1850,7 +1850,7 @@ void PrintC::pushSymbol(const Symbol *sym,const Varnode *vn,const PcodeOp *op)
return;
}
}
pushAtom(Atom(sym->getName(),vartoken,tokenColor,op,vn));
pushAtom(Atom(sym->getDisplayName(),vartoken,tokenColor,op,vn));
}
void PrintC::pushUnnamedLocation(const Address &addr,
@ -1984,7 +1984,7 @@ void PrintC::pushMismatchSymbol(const Symbol *sym,int4 off,int4 sz,
// We prepend an underscore to indicate a close
// but not quite match
string nm = '_'+sym->getName();
string nm = '_'+sym->getDisplayName();
pushAtom(Atom(nm,vartoken,EmitMarkup::var_color,op,vn));
}
else
@ -2057,7 +2057,7 @@ void PrintC::emitStructDefinition(const TypeStruct *ct)
emit->tagLine();
emit->print(CLOSE_CURLY);
emit->spaces(1);
emit->print(ct->getName());
emit->print(ct->getDisplayName());
emit->print(SEMICOLON);
}
@ -2100,7 +2100,7 @@ void PrintC::emitEnumDefinition(const TypeEnum *ct)
emit->tagLine();
emit->print(CLOSE_CURLY);
emit->spaces(1);
emit->print(ct->getName());
emit->print(ct->getDisplayName());
emit->print(SEMICOLON);
}
@ -2507,7 +2507,7 @@ void PrintC::emitFunctionDeclaration(const Funcdata *fd)
}
int4 id1 = emit->openGroup();
emitSymbolScope(fd->getSymbol());
emit->tagFuncName(fd->getName(),EmitMarkup::funcname_color,fd,(PcodeOp *)0);
emit->tagFuncName(fd->getDisplayName(),EmitMarkup::funcname_color,fd,(PcodeOp *)0);
emit->spaces(function_call.spacing,function_call.bump);
int4 id2 = emit->openParen(OPEN_PAREN);
@ -3122,7 +3122,7 @@ void PrintC::emitLabel(const FlowBlock *bl)
const Scope *symScope = ((const BlockBasic *)bb)->getFuncdata()->getScopeLocal();
Symbol *sym = symScope->queryCodeLabel(addr);
if (sym != (Symbol *)0) {
emit->tagLabel(sym->getName(),EmitMarkup::no_color,spc,off);
emit->tagLabel(sym->getDisplayName(),EmitMarkup::no_color,spc,off);
return;
}
}

View file

@ -107,7 +107,7 @@ void PrintJava::pushTypeStart(const Datatype *ct,bool noident)
pushAtom(Atom(nm,typetoken,EmitMarkup::type_color,ct));
}
else {
pushAtom(Atom(ct->getName(),typetoken,EmitMarkup::type_color,ct));
pushAtom(Atom(ct->getDisplayName(),typetoken,EmitMarkup::type_color,ct));
}
for(int4 i=0;i<arrayCount;++i)
pushAtom(Atom(EMPTY_STRING,blanktoken,EmitMarkup::no_color)); // Fill in the blank array index
@ -332,7 +332,7 @@ void PrintJava::opCpoolRefOp(const PcodeOp *op)
}
pushOp(&instanceof,op);
pushVn(vn0,op,mods);
pushAtom(Atom(dt->getName(),syntax,EmitMarkup::type_color,op,outvn));
pushAtom(Atom(dt->getDisplayName(),syntax,EmitMarkup::type_color,op,outvn));
break;
}
case CPoolRecord::primitive: // Should be eliminated

View file

@ -544,6 +544,9 @@ void Datatype::decodeBasic(Decoder &decoder)
uint4 val = encodeIntegerFormat(decoder.readString());
setDisplayFormat(val);
}
else if (attrib == ATTRIB_LABEL) {
displayName = decoder.readString();
}
}
if (size < 0)
throw LowlevelError("Bad size for type "+name);
@ -554,6 +557,8 @@ void Datatype::decodeBasic(Decoder &decoder)
// Id needs to be unique compared to another data-type with the same name
id = hashSize(id, size);
}
if (displayName.empty())
displayName = name;
}
/// If a type id is explicitly provided for a data-type, this routine is used
@ -3003,6 +3008,7 @@ Datatype *TypeFactory::setName(Datatype *ct,const string &n)
nametree.erase( ct ); // Erase any name reference
tree.erase(ct); // Remove new type completely from trees
ct->name = n; // Change the name
ct->displayName = n;
if (ct->id == 0)
ct->id = Datatype::hashName(n);
// Insert type with new name
@ -3215,7 +3221,7 @@ TypeVoid *TypeFactory::getTypeVoid(void)
if (ct != (TypeVoid *)0)
return ct;
TypeVoid tv;
tv.id = Datatype::hashName(tv.getName());
tv.id = Datatype::hashName(tv.name);
ct = (TypeVoid *)tv.clone();
tree.insert(ct);
nametree.insert(ct);
@ -3332,6 +3338,7 @@ TypeCode *TypeFactory::getTypeCode(const string &nm)
if (nm.size()==0) return getTypeCode();
TypeCode tmp; // Generic code data-type
tmp.name = nm; // with a name
tmp.displayName = nm;
tmp.id = Datatype::hashName(nm);
tmp.markComplete(); // considered complete
return (TypeCode *) findAdd(tmp);
@ -3384,6 +3391,7 @@ Datatype *TypeFactory::getTypedef(Datatype *ct,const string &name,uint8 id,uint4
}
res = ct->clone(); // Clone everything
res->name = name; // But a new name
res->displayName = name;
res->id = id; // and new id
res->flags &= ~((uint4)Datatype::coretype); // Not a core type
res->typedefImm = ct;
@ -3438,6 +3446,7 @@ TypePointer *TypeFactory::getTypePointer(int4 s,Datatype *pt,uint4 ws,const stri
pt = pt->getStripped();
TypePointer tmp(s,pt,ws);
tmp.name = n;
tmp.displayName = n;
tmp.id = Datatype::hashName(n);
return (TypePointer *) findAdd(tmp);
}
@ -3485,6 +3494,7 @@ TypeStruct *TypeFactory::getTypeStruct(const string &n)
{
TypeStruct tmp;
tmp.name = n;
tmp.displayName = n;
tmp.id = Datatype::hashName(n);
return (TypeStruct *) findAdd(tmp);
}
@ -3505,6 +3515,7 @@ TypeUnion *TypeFactory::getTypeUnion(const string &n)
{
TypeUnion tmp;
tmp.name = n;
tmp.displayName = n;
tmp.id = Datatype::hashName(n);
return (TypeUnion *) findAdd(tmp);
}
@ -3587,6 +3598,7 @@ TypePointerRel *TypeFactory::getTypePointerRel(int4 sz,Datatype *parent,Datatype
{
TypePointerRel tp(sz,ptrTo,ws,parent,off);
tp.name = nm;
tp.displayName = nm;
tp.id = Datatype::hashName(nm);
TypePointerRel *res = (TypePointerRel *)findAdd(tp);
return res;
@ -3605,6 +3617,7 @@ TypePointer *TypeFactory::getTypePointerWithSpace(Datatype *ptrTo,AddrSpace *spc
{
TypePointer tp(ptrTo,spc);
tp.name = nm;
tp.displayName = nm;
tp.id = Datatype::hashName(nm);
TypePointer *res = (TypePointer *)findAdd(tp);
return res;

View file

@ -159,12 +159,13 @@ protected:
};
friend class TypeFactory;
friend struct DatatypeCompare;
uint8 id; ///< A unique id for the type (or 0 if an id is not assigned)
int4 size; ///< Size (of variable holding a value of this type)
uint4 flags; ///< Boolean properties of the type
string name; ///< Name of type
string displayName; ///< Name to display in output
type_metatype metatype; ///< Meta-type - type disregarding size
sub_metatype submeta; ///< Sub-type of of the meta-type, for comparisons
uint4 flags; ///< Boolean properties of the type
uint8 id; ///< A unique id for the type (or 0 if an id is not assigned)
Datatype *typedefImm; ///< The immediate data-type being typedefed by \e this
void decodeBasic(Decoder &decoder); ///< Recover basic data-type properties
void encodeBasic(type_metatype meta,Encoder &encoder) const; ///< Encode basic data-type properties
@ -176,8 +177,8 @@ protected:
static uint8 hashSize(uint8 id,int4 size); ///< Reversibly hash size into id
public:
/// Construct the base data-type copying low-level properties of another
Datatype(const Datatype &op) { size = op.size; name=op.name; metatype=op.metatype; submeta=op.submeta; flags=op.flags;
id=op.id; typedefImm=op.typedefImm; }
Datatype(const Datatype &op) { size = op.size; name=op.name; displayName=op.displayName; metatype=op.metatype;
submeta=op.submeta; flags=op.flags; id=op.id; typedefImm=op.typedefImm; }
/// Construct the base data-type providing size and meta-type
Datatype(int4 s,type_metatype m) { size=s; metatype=m; submeta=base2sub[m]; flags=0; id=0; typedefImm=(Datatype *)0; }
virtual ~Datatype(void) {} ///< Destructor
@ -203,6 +204,7 @@ public:
uint8 getId(void) const { return id; } ///< Get the type id
int4 getSize(void) const { return size; } ///< Get the type size
const string &getName(void) const { return name; } ///< Get the type name
const string &getDisplayName(void) const { return displayName; } ///< Get string to use in display
Datatype *getTypedef(void) const { return typedefImm; } ///< Get the data-type immediately typedefed by \e this (or null)
virtual void printRaw(ostream &s) const; ///< Print a description of the type to stream
virtual const TypeField *findTruncation(int4 off,int4 sz,const PcodeOp *op,int4 slot,int4 &newoff) const;
@ -279,7 +281,7 @@ public:
/// Construct TypeBase from a size and meta-type
TypeBase(int4 s,type_metatype m) : Datatype(s,m) {}
/// Construct TypeBase from a size, meta-type, and name
TypeBase(int4 s,type_metatype m,const string &n) : Datatype(s,m) { name = n; }
TypeBase(int4 s,type_metatype m,const string &n) : Datatype(s,m) { name = n; displayName = n; }
virtual Datatype *clone(void) const { return new TypeBase(*this); }
};
@ -326,7 +328,7 @@ public:
/// Construct from another TypeVoid
TypeVoid(const TypeVoid &op) : Datatype(op) { flags |= Datatype::coretype; }
/// Constructor
TypeVoid(void) : Datatype(0,TYPE_VOID) { name = "void"; flags |= Datatype::coretype; }
TypeVoid(void) : Datatype(0,TYPE_VOID) { name = "void"; displayName = name; flags |= Datatype::coretype; }
virtual Datatype *clone(void) const { return new TypeVoid(*this); }
virtual void encode(Encoder &encoder) const;
};