decompiler  1.0.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CommentDatabaseGhidra Class Reference

An implementation of CommentDatabase backed by a Ghidra client. More...

#include <comment_ghidra.hh>

Inheritance diagram for CommentDatabaseGhidra:
CommentDatabase

Public Member Functions

 CommentDatabaseGhidra (ArchitectureGhidra *g)
 Constructor.
 
virtual void clear (void)
 Clear all comments from this container.
 
virtual void clearType (const Address &fad, uint4 tp)
 Clear all comments matching (one of) the indicated types. More...
 
virtual void addComment (uint4 tp, const Address &fad, const Address &ad, const string &txt)
 
virtual bool addCommentNoDuplicate (uint4 tp, const Address &fad, const Address &ad, const string &txt)
 Add a new comment to the container, making sure there is no duplicate. More...
 
virtual void deleteComment (Comment *com)
 Remove the given Comment object from the container. More...
 
virtual CommentSet::const_iterator beginComment (const Address &fad) const
 Get an iterator to the beginning of comments for a single function. More...
 
virtual CommentSet::const_iterator endComment (const Address &fad) const
 Get an iterator to the ending of comments for a single function. More...
 
virtual void saveXml (ostream &s) const
 Save all comments in the container to an XML stream. More...
 
virtual void restoreXml (const Element *el, const AddrSpaceManager *trans)
 Restore all comments from XML. More...
 
- Public Member Functions inherited from CommentDatabase
 CommentDatabase (void)
 Constructor.
 
virtual ~CommentDatabase (void)
 Destructor.
 

Private Member Functions

void fillCache (const Address &fad) const
 Fetch comments for the given function. More...
 

Private Attributes

ArchitectureGhidraghidra
 The Architecture and connection to the Ghidra client.
 
CommentDatabaseInternal cache
 A cache of Comment objects received from the Ghidra client.
 
bool cachefilled
 Set to true if comments for the current function have been fetched.
 

Detailed Description

An implementation of CommentDatabase backed by a Ghidra client.

Comment information about particular functions is obtained by querying a Ghidra client. All comments for a single function are queried at once, and results are cached in this object. The cache needs to be cleared between functions using the clear() method.

Member Function Documentation

void CommentDatabaseGhidra::addComment ( uint4  tp,
const Address fad,
const Address ad,
const string &  txt 
)
virtual

For the Ghidra implementation of CommentDatabase, addComment() is currently only called by the warning routines which generates the warning and warningheader comment types. Neither of these types is intended to be a permanent comment in the database, so we only add the comment to the cache

Implements CommentDatabase.

References CommentDatabaseInternal::addComment(), and cache.

Referenced by clearType().

bool CommentDatabaseGhidra::addCommentNoDuplicate ( uint4  tp,
const Address fad,
const Address ad,
const string &  txt 
)
virtual

Add a new comment to the container, making sure there is no duplicate.

If there is already a comment at the same address with the same body, no new comment is added.

Parameters
tpis a set of properties to associate with the new comment (may be zero)
fadis the address of the function to which the comment belongs
adis the address to which the comment is attached
txtis the body of the comment
Returns
true if a new Comment was created, false if there was a duplicate

Implements CommentDatabase.

References CommentDatabaseInternal::addCommentNoDuplicate(), and cache.

Referenced by clearType().

CommentSet::const_iterator CommentDatabaseGhidra::beginComment ( const Address fad) const
virtual

Get an iterator to the beginning of comments for a single function.

Parameters
fadis the address of the function
Returns
the beginning iterator

Implements CommentDatabase.

References CommentDatabaseInternal::beginComment(), cache, and fillCache().

Referenced by deleteComment().

virtual void CommentDatabaseGhidra::clearType ( const Address fad,
uint4  tp 
)
inlinevirtual

Clear all comments matching (one of) the indicated types.

Clearing is restricted to comments belonging to a specific function and matching at least one of the given properties

Parameters
fadis the address of the owning function
tpis a set of one or more properties

Implements CommentDatabase.

References addComment(), addCommentNoDuplicate(), and CommentDatabaseInternal::clearType().

virtual void CommentDatabaseGhidra::deleteComment ( Comment com)
inlinevirtual

Remove the given Comment object from the container.

Parameters
comis the given Comment

Implements CommentDatabase.

References beginComment(), and endComment().

CommentSet::const_iterator CommentDatabaseGhidra::endComment ( const Address fad) const
virtual

Get an iterator to the ending of comments for a single function.

Parameters
fadis the address of the function
Returns
the ending iterator

Implements CommentDatabase.

References cache, and CommentDatabaseInternal::endComment().

Referenced by deleteComment().

void CommentDatabaseGhidra::fillCache ( const Address fad) const
private

Fetch comments for the given function.

Fetch all comments for the function in one chunk. Deserialize them and store the Comment objects in the cache

Parameters
fadis the address of the given function

References CommentDatabaseInternal::beginComment(), cache, cachefilled, CommentDatabaseInternal::endComment(), ArchitectureGhidra::getComments(), PrintLanguage::getHeaderComment(), PrintLanguage::getInstructionComment(), Document::getRoot(), ghidra, Architecture::print, and CommentDatabaseInternal::restoreXml().

Referenced by beginComment().

virtual void CommentDatabaseGhidra::restoreXml ( const Element el,
const AddrSpaceManager manage 
)
inlinevirtual

Restore all comments from XML.

Parameters
elis the root <commentdb> element
manageis a manager for resolving address space references

Implements CommentDatabase.

virtual void CommentDatabaseGhidra::saveXml ( ostream &  s) const
inlinevirtual

Save all comments in the container to an XML stream.

Writes a <commentdb> tag, with <comment> sub-tags for each Comment object.

Parameters
sis the output stream

Implements CommentDatabase.


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