decompiler  1.0.0
Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
ghidra::SymbolEntry Class Reference

A storage location for a particular Symbol. More...

#include <database.hh>

Classes

class  EntryInitData
 Initialization data for a SymbolEntry to facilitate a rangemap. More...
 
class  EntrySubsort
 Class for sub-sorting different SymbolEntry objects at the same address. More...
 

Public Types

typedef uintb linetype
 The linear element for a rangemap of SymbolEntry.
 
typedef EntrySubsort subsorttype
 The sub-sort object for a rangemap.
 
typedef EntryInitData inittype
 Initialization data for a SymbolEntry in a rangemap.
 

Public Member Functions

 SymbolEntry (const EntryInitData &data, uintb a, uintb b)
 Fully initialize this. More...
 
 SymbolEntry (Symbol *sym, uint4 exfl, uint8 h, int4 off, int4 sz, const RangeList &rnglist)
 Construct a dynamic SymbolEntry. More...
 
bool isPiece (void) const
 Is this a high or low piece of the whole Symbol.
 
bool isDynamic (void) const
 Is storage dynamic.
 
bool isInvalid (void) const
 Is this storage invalid.
 
uint4 getAllFlags (void) const
 Get all Varnode flags for this storage. More...
 
int4 getOffset (void) const
 Get offset of this within the Symbol.
 
uintb getFirst (void) const
 Get the first offset of this storage location.
 
uintb getLast (void) const
 Get the last offset of this storage location.
 
subsorttype getSubsort (void) const
 Get the sub-sort object. More...
 
SymbolgetSymbol (void) const
 Get the Symbol associated with this.
 
const AddressgetAddr (void) const
 Get the starting address of this storage.
 
uint8 getHash (void) const
 Get the hash used to identify this storage.
 
int4 getSize (void) const
 Get the number of bytes consumed by this storage.
 
bool inUse (const Address &usepoint) const
 Is this storage valid for the given code address. More...
 
const RangeListgetUseLimit (void) const
 Get the set of valid code addresses for this storage.
 
Address getFirstUseAddress (void) const
 Get the first code address where this storage is valid.
 
void setUseLimit (const RangeList &uselim)
 Set the range of code addresses where this is valid.
 
bool isAddrTied (void) const
 Is this storage address tied.
 
bool updateType (Varnode *vn) const
 Update a Varnode data-type from this. More...
 
DatatypegetSizedType (const Address &addr, int4 sz) const
 Get the data-type associated with (a piece of) this. More...
 
void printEntry (ostream &s) const
 Dump a description of this to a stream. More...
 
void encode (Encoder &encoder) const
 Encode this to a stream. More...
 
void decode (Decoder &decoder)
 Decode this from a stream. More...
 

Private Member Functions

 SymbolEntry (Symbol *sym)
 Construct a mapping for a Symbol without an address. More...
 

Private Attributes

Symbolsymbol
 Symbol object being mapped.
 
uint4 extraflags
 Varnode flags specific to this storage location.
 
Address addr
 Starting address of the storage location.
 
uint8 hash
 A dynamic storage address (an alternative to addr for dynamic symbols)
 
int4 offset
 Offset into the Symbol that this covers.
 
int4 size
 Number of bytes consumed by this (piece of the) storage.
 
RangeList uselimit
 Code address ranges where this storage is valid.
 

Friends

class Scope
 

Detailed Description

A storage location for a particular Symbol.

Where a Symbol is stored, as a byte address and a size, is of particular importance to the decompiler. This class encapsulates this storage meta-data. A single Symbol split across multiple storage locations is supported by the offset and size fields. The hash field supports dynamic storage, where a Symbol is represented by a constant or a temporary register. In this case, storage must be tied to the particular p-code operators using the value.

A particular memory address does not have to represent the symbol across all code. Storage may get recycled for different Symbols at different points in the code. The uselimit object defines the range of instruction addresses over which a particular memory address does represent a Symbol, with the convention that an empty uselimit indicates the storage holds the Symbol across all code.

Constructor & Destructor Documentation

◆ SymbolEntry() [1/3]

ghidra::SymbolEntry::SymbolEntry ( Symbol sym)
private

Construct a mapping for a Symbol without an address.

This SymbolEntry is unintegrated. An address or hash must be provided either directly or via decode().

Parameters
symis the Symbol this will be a map for

References extraflags, hash, offset, and size.

◆ SymbolEntry() [2/3]

ghidra::SymbolEntry::SymbolEntry ( const EntryInitData data,
uintb  a,
uintb  b 
)

Fully initialize this.

Establish the boundary offsets and fill in additional data

Parameters
datacontains the raw initialization data
ais the starting offset of the entry
bis the ending offset of the entry

References addr, extraflags, ghidra::SymbolEntry::EntryInitData::extraflags, offset, ghidra::SymbolEntry::EntryInitData::offset, size, ghidra::SymbolEntry::EntryInitData::space, symbol, ghidra::SymbolEntry::EntryInitData::symbol, uselimit, and ghidra::SymbolEntry::EntryInitData::uselimit.

◆ SymbolEntry() [3/3]

ghidra::SymbolEntry::SymbolEntry ( Symbol sym,
uint4  exfl,
uint8  h,
int4  off,
int4  sz,
const RangeList rnglist 
)

Construct a dynamic SymbolEntry.

This is used specifically for dynamic Symbol objects, where the storage location is attached to a temporary register or a constant. The main address field (addr) is set to invalid, and the hash becomes the primary location information.

Parameters
symis the underlying Symbol
exflare the Varnode flags associated with the storage location
his the the hash
offif the offset into the Symbol for this (piece of) storage
szis the size in bytes of this (piece of) storage
rnglistis the set of code addresses where this SymbolEntry represents the Symbol

References addr, extraflags, hash, offset, size, symbol, and uselimit.

Member Function Documentation

◆ decode()

void ghidra::SymbolEntry::decode ( Decoder decoder)

Decode this from a stream.

Parse either an <addr> element for storage information or a <hash> element if the symbol is dynamic. Then parse the uselimit describing the valid range of code addresses.

Parameters
decoderis the stream decoder
Returns
the advanced iterator

References addr, ghidra::Decoder::closeElement(), ghidra::Address::decode(), ghidra::RangeList::decode(), hash, ghidra::Decoder::openElement(), ghidra::Decoder::peekElement(), ghidra::Decoder::readUnsignedInteger(), and uselimit.

Referenced by ghidra::Scope::addMapSym(), ghidra::UnionFacetSymbol::getFieldNumber(), ghidra::Symbol::getMapEntry(), ghidra::Database::getProperties(), ghidra::ExternRefSymbol::getRefAddr(), ghidra::EquateSymbol::getValue(), ghidra::Scope::inScope(), and setUseLimit().

◆ encode()

void ghidra::SymbolEntry::encode ( Encoder encoder) const

Encode this to a stream.

This writes elements internal to the <mapsym> element associated with the Symbol. It encodes the address element (or the <hash> element for dynamic symbols) and a <rangelist> element associated with the uselimit.

Parameters
encoderis the stream encoder

References addr, ghidra::Encoder::closeElement(), ghidra::Address::encode(), ghidra::RangeList::encode(), hash, ghidra::Address::isInvalid(), isPiece(), ghidra::Encoder::openElement(), uselimit, and ghidra::Encoder::writeUnsignedInteger().

Referenced by ghidra::ScopeInternal::encode(), ghidra::UnionFacetSymbol::getFieldNumber(), ghidra::Symbol::getMapEntry(), ghidra::Database::getProperties(), ghidra::ExternRefSymbol::getRefAddr(), ghidra::EquateSymbol::getValue(), ghidra::Scope::inScope(), and setUseLimit().

◆ getAllFlags()

uint4 ghidra::SymbolEntry::getAllFlags ( void  ) const
inline

Get all Varnode flags for this storage.

Retrieve the (union of) Varnode flags specific to the Symbol and specific to this storage.

Returns
all Varnode flags that apply

References ghidra::SymbolEntry::EntryInitData::extraflags, ghidra::Symbol::getFlags(), and ghidra::SymbolEntry::EntryInitData::symbol.

Referenced by isInvalid(), ghidra::Scope::queryProperties(), ghidra::Varnode::setSymbolProperties(), and ghidra::Funcdata::syncVarnodesWithSymbols().

◆ getSizedType()

Datatype * ghidra::SymbolEntry::getSizedType ( const Address inaddr,
int4  sz 
) const

Get the data-type associated with (a piece of) this.

Return the data-type that matches the given size and address within this storage. NULL is returned if there is no valid sub-type matching the size.

Parameters
inaddris the given address
szis the given size (in bytes)
Returns
the matching data-type or NULL

References addr, ghidra::Scope::getArch(), ghidra::TypeFactory::getExactPiece(), ghidra::Address::getOffset(), ghidra::Symbol::getScope(), ghidra::Symbol::getType(), isDynamic(), offset, symbol, and ghidra::Architecture::types.

Referenced by ghidra::TypeOpCallother::getInputLocal(), ghidra::TypeOpCallother::getOutputLocal(), setUseLimit(), ghidra::Funcdata::syncVarnodesWithSymbols(), and updateType().

◆ getSubsort()

SymbolEntry::subsorttype ghidra::SymbolEntry::getSubsort ( void  ) const

◆ inUse()

bool ghidra::SymbolEntry::inUse ( const Address usepoint) const

Is this storage valid for the given code address.

This storage location may only hold the Symbol value for a limited portion of the code.

Parameters
usepointis the given code address to test
Returns
true if this storage is valid at the given address

References ghidra::RangeList::inRange(), isAddrTied(), ghidra::Address::isInvalid(), and uselimit.

Referenced by ghidra::ScopeInternal::findAddr(), ghidra::ScopeInternal::findClosestFit(), ghidra::ScopeInternal::findCodeLabel(), ghidra::ScopeInternal::findContainer(), ghidra::Funcdata::findLinkedVarnode(), ghidra::Funcdata::findLinkedVarnodes(), and getSize().

◆ printEntry()

void ghidra::SymbolEntry::printEntry ( ostream &  s) const

Dump a description of this to a stream.

Give a contained one-line description of this storage, suitable for a debug console

Parameters
sis the output stream

References addr, ghidra::Symbol::getName(), ghidra::Address::getShortcut(), ghidra::Datatype::getSize(), ghidra::Symbol::getType(), ghidra::Address::isInvalid(), ghidra::RangeList::printBounds(), ghidra::Address::printRaw(), ghidra::Datatype::printRaw(), symbol, and uselimit.

Referenced by setUseLimit().

◆ updateType()

bool ghidra::SymbolEntry::updateType ( Varnode vn) const

Update a Varnode data-type from this.

If the Symbol associated with this is type-locked, change the given Varnode's attached data-type to match the Symbol

Parameters
vnis the Varnode to modify
Returns
true if the data-type was changed

References ghidra::Varnode::getAddr(), ghidra::Symbol::getFlags(), ghidra::Varnode::getSize(), getSizedType(), symbol, ghidra::Varnode::typelock, and ghidra::Varnode::updateType().

Referenced by ghidra::Varnode::setSymbolProperties(), and setUseLimit().


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