decompiler  1.0.0
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
Symbol Class Reference

The base class for a symbol in a symbol table or scope. More...

#include <database.hh>

Inheritance diagram for Symbol:
EquateSymbol ExternRefSymbol FunctionSymbol LabSymbol

Public Types

enum  {
  force_hex = 1, force_dec = 2, force_oct = 3, force_bin = 4,
  force_char = 5, size_typelock = 8, isolate = 16, merge_problems = 32,
  is_this_ptr = 64
}
 Possible display (dispflag) properties for a Symbol. More...
 

Public Member Functions

 Symbol (Scope *sc, const string &nm, Datatype *ct)
 Construct given a name and data-type. More...
 
 Symbol (Scope *sc)
 Construct for use with restoreXml() More...
 
const string & getName (void) const
 Get the local name of the symbol.
 
DatatypegetType (void) const
 Get the data-type.
 
uint8 getId (void) const
 Get a unique id for the symbol.
 
uint4 getFlags (void) const
 Get the boolean properties of the Symbol.
 
uint4 getDisplayFormat (void) const
 Get the format to display the Symbol in.
 
int2 getCategory (void) const
 Get the Symbol category.
 
uint2 getCategoryIndex (void) const
 Get the position of the Symbol within its category.
 
bool isTypeLocked (void) const
 Is the Symbol type-locked.
 
bool isNameLocked (void) const
 Is the Symbol name-locked.
 
bool isSizeTypeLocked (void) const
 Is the Symbol size type-locked.
 
bool isThisPointer (void) const
 Is this the "this" pointer.
 
bool isIndirectStorage (void) const
 Is storage really a pointer to the true Symbol.
 
bool isHiddenReturn (void) const
 Is this a reference to the function return value.
 
bool isNameUndefined (void) const
 Does this have an undefined name. More...
 
bool isMultiEntry (void) const
 Does this have more than one entire mapping.
 
bool hasMergeProblems (void) const
 Were some SymbolEntrys not merged.
 
void setMergeProblems (void)
 Mark that some SymbolEntrys could not be merged.
 
bool isIsolated (void) const
 Return true if this is isolated from speculative merging.
 
void setIsolated (bool val)
 Set whether this Symbol should be speculatively merged. More...
 
ScopegetScope (void) const
 Get the scope owning this Symbol.
 
SymbolEntrygetFirstWholeMap (void) const
 Get the first entire mapping of the symbol. More...
 
SymbolEntrygetMapEntry (const Address &addr) const
 Get first mapping of the symbol that contains the given Address. More...
 
int4 numEntries (void) const
 Return the number of SymbolEntrys.
 
SymbolEntrygetMapEntry (int4 i) const
 Return the i-th SymbolEntry for this Symbol.
 
int4 getMapEntryPosition (const SymbolEntry *entry) const
 Position of given SymbolEntry within this multi-entry Symbol. More...
 
int4 getResolutionDepth (const Scope *useScope) const
 Get number of scope names needed to resolve this symbol. More...
 
void saveXmlHeader (ostream &s) const
 Save basic Symbol properties as XML attributes. More...
 
void restoreXmlHeader (const Element *el)
 Restore basic Symbol properties from XML. More...
 
void saveXmlBody (ostream &s) const
 Save details of the Symbol to XML. More...
 
void restoreXmlBody (List::const_iterator iter)
 Restore details of the Symbol from XML. More...
 
virtual void saveXml (ostream &s) const
 Save this Symbol to an XML stream. More...
 
virtual void restoreXml (const Element *el)
 Restore this Symbol from an XML stream. More...
 
virtual int4 getBytesConsumed (void) const
 Get number of bytes consumed within the address->symbol map. More...
 

Static Public Attributes

static uint8 ID_BASE = 0x4000000000000000L
 Base of internal ID's.
 

Protected Member Functions

virtual ~Symbol (void)
 Destructor.
 
void setDisplayFormat (uint4 val)
 Set the display format for this Symbol. More...
 
void checkSizeTypeLock (void)
 Calculate if size_typelock property is on. More...
 
void setThisPointer (bool val)
 Toggle whether this is the "this" pointer for a class method. More...
 

Protected Attributes

Scopescope
 The scope that owns this symbol.
 
string name
 The local name of the symbol.
 
Datatypetype
 The symbol's data-type.
 
uint4 nameDedup
 id to distinguish symbols with the same name
 
uint4 flags
 Varnode-like properties of the symbol.
 
uint4 dispflags
 Flags affecting the display of this symbol.
 
int2 category
 Special category (-1==none 0=parameter 1=equate)
 
uint2 catindex
 Index within category.
 
uint8 symbolId
 Unique id, 0=unassigned.
 
vector< list< SymbolEntry >::iterator > mapentry
 List of storage locations labeled with this Symbol.
 
const ScopedepthScope
 Scope associated with current depth resolution.
 
int4 depthResolution
 Number of namespace elements required to resolve symbol in current scope.
 
uint4 wholeCount
 Number of SymbolEntries that map to the whole Symbol.
 

Friends

class Scope
 
class ScopeInternal
 
class SymbolCompareName
 

Detailed Description

The base class for a symbol in a symbol table or scope.

At its most basic, a Symbol is a name and a data-type. Practically a Symbol knows what Scope its in, how it should be displayed, and the symbols category. A category is a subset of symbols that are stored together for quick access. The category field can be:

Member Enumeration Documentation

anonymous enum

Possible display (dispflag) properties for a Symbol.

Enumerator
force_hex 

Force hexadecimal printing of constant symbol.

force_dec 

Force decimal printing of constant symbol.

force_oct 

Force octal printing of constant symbol.

force_bin 

Force binary printing of constant symbol.

force_char 

Force integer to be printed as a character constant.

size_typelock 

Only the size of the symbol is typelocked.

isolate 

Symbol should not speculatively merge automatically.

merge_problems 

Set if some SymbolEntrys did not get merged.

is_this_ptr 

We are the "this" symbol for a class method.

Constructor & Destructor Documentation

Symbol::Symbol ( Scope sc,
const string &  nm,
Datatype ct 
)
inline

Construct given a name and data-type.

Parameters
scis the scope containing the new symbol
nmis the local name of the symbol
ctis the data-type of the symbol

Referenced by Scope::addDynamicSymbol(), Scope::addMapSym(), and Scope::addSymbol().

Symbol::Symbol ( Scope sc)
inline

Construct for use with restoreXml()

Parameters
scis the scope containing the new symbol

Member Function Documentation

void Symbol::checkSizeTypeLock ( void  )
protected

Calculate if size_typelock property is on.

Examine the data-type to decide if the Symbol has the special property called size_typelock, which indicates the size of the Symbol is locked, but the data-type is not locked (and can float)

References TYPE_UNKNOWN.

Referenced by EquateSymbol::restoreXml(), and ScopeInternal::retypeSymbol().

int4 Symbol::getBytesConsumed ( void  ) const
virtual

Get number of bytes consumed within the address->symbol map.

Get the number of bytes consumed by a SymbolEntry representing this Symbol. By default, this is the number of bytes consumed by the Symbol's data-type. This gives the amount of leeway a search has when the address queried does not match the exact address of the Symbol. With functions, the bytes consumed by a SymbolEntry may not match the data-type size.

Returns
the number of bytes in a default SymbolEntry

Reimplemented in FunctionSymbol.

Referenced by Scope::addMap().

SymbolEntry * Symbol::getFirstWholeMap ( void  ) const
SymbolEntry * Symbol::getMapEntry ( const Address addr) const

Get first mapping of the symbol that contains the given Address.

This method may return a partial entry, where the SymbolEntry is only holding part of the whole Symbol.

Parameters
addris an address within the desired storage location of the Symbol
Returns
the first matching SymbolEntry

References SymbolEntry::getAddr(), Address::getOffset(), SymbolEntry::getSize(), and Address::getSpace().

Referenced by Scope::buildDefaultName(), ScopeGhidra::findAddr(), ScopeGhidra::findContainer(), and Merge::mergeMultiEntry().

int4 Symbol::getMapEntryPosition ( const SymbolEntry entry) const

Position of given SymbolEntry within this multi-entry Symbol.

Among all the SymbolEntrys that map this entire Symbol, calculate the position of the given SymbolEntry within the list.

Parameters
entryis the given SymbolEntry
Returns
its position within the list or -1 if it is not in the list

References SymbolEntry::getSize().

Referenced by PrintC::pushSymbol().

int4 Symbol::getResolutionDepth ( const Scope useScope) const

Get number of scope names needed to resolve this symbol.

For a given context scope where this Symbol is used, determine how many elements of the full namespace path need to be printed to correctly distinguish it. A value of 0 means the base symbol name is visible and not overridden in the context scope. A value of 1 means the base name may be overridden, but the parent scope name is not. The minimal number of names that distinguishes the symbol name uniquely within the use scope is returned.

Parameters
useScopeis the given scope where the symbol is being used
Returns
the number of (extra) names needed to distinguish the symbol

References Scope::findDistinguishingScope(), Scope::getName(), Scope::getParent(), and Scope::isNameUsed().

Referenced by PrintC::emitSymbolScope(), and PrintC::pushSymbolScope().

bool Symbol::isNameUndefined ( void  ) const
void Symbol::restoreXml ( const Element el)
virtual

Restore this Symbol from an XML stream.

Parameters
elis the root XML tag of the symbol

Reimplemented in ExternRefSymbol, LabSymbol, EquateSymbol, and FunctionSymbol.

References Element::getChildren().

Referenced by Scope::addMapSym().

void Symbol::restoreXmlBody ( List::const_iterator  iter)

Restore details of the Symbol from XML.

Parameters
iteriterates over XML children of the root <symbol> tag
void Symbol::restoreXmlHeader ( const Element el)
void Symbol::saveXml ( ostream &  s) const
virtual

Save this Symbol to an XML stream.

Parameters
sis the output stream

Reimplemented in ExternRefSymbol, LabSymbol, EquateSymbol, and FunctionSymbol.

Referenced by ScopeInternal::saveXml().

void Symbol::saveXmlBody ( ostream &  s) const

Save details of the Symbol to XML.

Save the data-type for the Symbol

Parameters
sis the output stream
void Symbol::saveXmlHeader ( ostream &  s) const

Save basic Symbol properties as XML attributes.

Parameters
sis the output stream

References a_v(), a_v_b(), a_v_i(), a_v_u(), Varnode::hiddenretparm, Varnode::indirectstorage, Varnode::namelock, Varnode::readonly, Varnode::typelock, and Varnode::volatil.

Referenced by EquateSymbol::saveXml(), and LabSymbol::saveXml().

void Symbol::setDisplayFormat ( uint4  val)
inlineprotected

Set the display format for this Symbol.

Force a specific display format for constant symbols

Parameters
valis the format: force_hex, force_dec, force_oct, etc.

Referenced by ScopeInternal::setDisplayFormat().

void Symbol::setIsolated ( bool  val)

Set whether this Symbol should be speculatively merged.

If the given value is true, any Varnodes that map directly to this Symbol, will not be speculatively merged with other Varnodes. (Required merges will still happen).

Parameters
valis the given boolean value

References Varnode::typelock.

void Symbol::setThisPointer ( bool  val)
protected

Toggle whether this is the "this" pointer for a class method.

Parameters
valis true if we are the "this" pointer

Referenced by Scope::setThisPointer().


The documentation for this class was generated from the following files: