2#ifndef ROSE_SgAsmGenericFile_H
3#define ROSE_SgAsmGenericFile_H
5#include <Cxx_GrammarDeclarations.h>
6#include <SgAsmExecutableFileFormat.h>
27#include <Rose/BinaryAnalysis/MemoryMap.h>
28#include <Rose/BinaryAnalysis/AddressIntervalSet.h>
30#include "DataConversion.h"
31#include "StatSerializer.h"
33#ifdef ROSE_SgAsmGenericFile_IMPL
34#include <SgAsmDwarfCompilationUnitList.h>
35#include <SgAsmGenericSectionList.h>
36#include <SgAsmGenericHeaderList.h>
44#if !defined(DOCUMENTATION)
59#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
61 friend class boost::serialization::access;
67 s & BOOST_SERIALIZATION_NVP(p_dwarfInfo);
68 s & BOOST_SERIALIZATION_NVP(p_name);
69 s & BOOST_SERIALIZATION_NVP(p_sb);
70 s & BOOST_SERIALIZATION_NVP(p_data);
71 s & BOOST_SERIALIZATION_NVP(p_headers);
72 s & BOOST_SERIALIZATION_NVP(p_holes);
73 s & BOOST_SERIALIZATION_NVP(p_truncateZeros);
74 s & BOOST_SERIALIZATION_NVP(p_trackingReferences);
75 s & BOOST_SERIALIZATION_NVP(p_referencedExtents);
76 s & BOOST_SERIALIZATION_NVP(p_neuter);
86 ADDRSP_MEMORY = 0x0001,
114 std::string
const&
get_name()
const;
124 int const& get_fd()
const;
125 void set_fd(
int const&);
129 struct stat const& get_sb()
const;
164 bool const& get_truncateZeros()
const;
165 void set_truncateZeros(
bool const&);
172 bool const& get_trackingReferences()
const;
173 void set_trackingReferences(
bool const&);
188 bool const& get_neuter()
const;
189 void set_neuter(
bool const&);
213 void unparse(std::ostream&)
const;
216 void extendToEof(std::ostream&)
const;
219 void dump(FILE*)
const;
227 void dumpAll(
bool in_cwd=
true,
const char *ext=NULL);
230 void dumpAll(
const std::string& dumpname);
236 void markReferencedExtent(rose_addr_t start_rva, rose_addr_t size);
248 rose_addr_t get_currentSize()
const;
251 rose_addr_t get_originalSize()
const;
260 size_t readContent(rose_addr_t offset,
void *dst_buf, rose_addr_t size,
bool strict=
true);
269 rose_addr_t size,
bool strict=
true);
287 std::string readContentString(rose_addr_t abs_offset,
bool strict=
true);
301 SgAsmGenericSectionPtrList get_mappedSections()
const;
304 SgAsmGenericSectionPtrList get_sections(
bool include_holes=
true)
const;
307 SgAsmGenericSectionPtrList get_sectionsById(
int id)
const;
310 SgAsmGenericSectionPtrList get_sectionsByName(std::string,
char sep=
'\0')
const;
316 SgAsmGenericSectionPtrList get_sectionsByOffset(rose_addr_t offset, rose_addr_t size)
const;
322 SgAsmGenericSectionPtrList get_sectionsByRva(rose_addr_t rva)
const;
328 SgAsmGenericSectionPtrList get_sectionsByVa(rose_addr_t va)
const;
341 SgAsmGenericSection *get_sectionByName(
const std::string&,
char sep=0,
size_t *nfound=0)
const;
347 SgAsmGenericSection *get_sectionByOffset(rose_addr_t offset, rose_addr_t size,
size_t *nfound=0)
const;
378 static SgAsmGenericSection *bestSectionByVa(
const SgAsmGenericSectionPtrList §ions, rose_addr_t va);
419 void shiftExtend(
SgAsmGenericSection*, rose_addr_t sa, rose_addr_t sn, AddressSpace, Elasticity);
427 rose_addr_t get_nextSectionOffset(rose_addr_t offset);
464 const char *formatName()
const;
476 bool get_truncate_zeros() const ROSE_DEPRECATED("use get_truncateZeros");
477 void set_truncate_zeros(
bool) ROSE_DEPRECATED("use set_truncateZeros");
478 bool get_tracking_references() const ROSE_DEPRECATED("use get_trackingReferences");
479 void set_tracking_references(
bool) ROSE_DEPRECATED("use set_trackingReferences");
480 const
Rose::BinaryAnalysis::AddressIntervalSet& get_referenced_extents() const ROSE_DEPRECATED("use get_referencedExtents");
481 void set_referenced_extents(const
Rose::BinaryAnalysis::AddressIntervalSet&) ROSE_DEPRECATED("use set_referencedExtents");
482 void extend_to_eof(std::ostream&) const ROSE_DEPRECATED("use extendToEof");
483 void dump_all(
bool in_cwd=true, const
char *ext=NULL) ROSE_DEPRECATED("use dumpAll");
484 void dump_all(const std::
string& dumpname) ROSE_DEPRECATED("use dumpAll");
485 const
Rose::BinaryAnalysis::AddressIntervalSet& get_unreferenced_extents() const ROSE_DEPRECATED("use get_unreferencedExtents");
486 void mark_referenced_extent(rose_addr_t, rose_addr_t) ROSE_DEPRECATED("use markReferencedExtent");
487 DataConverter* get_data_converter() const ROSE_DEPRECATED("use get_dataConverter");
488 void set_data_converter(
DataConverter*) ROSE_DEPRECATED("use set_dataConverter");
489 rose_addr_t get_current_size() const ROSE_DEPRECATED("use get_currentSize");
490 rose_addr_t get_orig_size() const ROSE_DEPRECATED("use get_originalSize");
491 size_t read_content(rose_addr_t,
void*, rose_addr_t,
bool=true) ROSE_DEPRECATED("use readContent");
492 size_t read_content(const
Rose::BinaryAnalysis::MemoryMap::Ptr&, rose_addr_t,
void*, rose_addr_t,
bool=true)
493 ROSE_DEPRECATED("use readContent");
494 std::
string read_content_str(const
Rose::BinaryAnalysis::MemoryMap::Ptr&, rose_addr_t,
bool=true)
495 ROSE_DEPRECATED("use readContentString");
496 std::
string read_content_str(rose_addr_t,
bool=true) ROSE_DEPRECATED("use readContentString");
497 SgAsmGenericSectionPtrList get_mapped_sections() const ROSE_DEPRECATED("use get_mappedSections");
498 SgAsmGenericSectionPtrList get_sections_by_id(
int id) const ROSE_DEPRECATED("use get_sectionById");
499 SgAsmGenericSectionPtrList get_sections_by_name(std::
string,
char='\0') const ROSE_DEPRECATED("use get_sectionsByName");
500 SgAsmGenericSectionPtrList get_sections_by_offset(rose_addr_t, rose_addr_t) const ROSE_DEPRECATED("use get_sectionsByOffset");
501 SgAsmGenericSectionPtrList get_sections_by_rva(rose_addr_t) const ROSE_DEPRECATED("use get_sectionsByRva");
502 SgAsmGenericSectionPtrList get_sections_by_va(rose_addr_t) const ROSE_DEPRECATED("use get_sectionsByVa");
503 SgAsmGenericSection *get_section_by_id(
int,
size_t* =
nullptr) const ROSE_DEPRECATED("use get_sectionById");
504 SgAsmGenericSection *get_section_by_name(const std::
string&,
char=0,
size_t* =
nullptr) const
505 ROSE_DEPRECATED("use get_sectionByName");
506 SgAsmGenericSection *get_section_by_offset(rose_addr_t, rose_addr_t,
size_t* =
nullptr) const
507 ROSE_DEPRECATED("use get_sectionByOffset");
508 SgAsmGenericSection *get_section_by_rva(rose_addr_t,
size_t* =
nullptr) const ROSE_DEPRECATED("use get_sectionByRva");
509 SgAsmGenericSection *get_section_by_va(rose_addr_t,
size_t* =
nullptr) const ROSE_DEPRECATED("use get_sectionByVa");
510 SgAsmGenericSection *get_best_section_by_va(rose_addr_t,
size_t* =
nullptr) const ROSE_DEPRECATED("use get_bestSectionByVa");
511 static
SgAsmGenericSection *best_section_by_va(const SgAsmGenericSectionPtrList&, rose_addr_t)
512 ROSE_DEPRECATED("use bestSectionByVa");
513 void shift_extend(
SgAsmGenericSection*, rose_addr_t, rose_addr_t, AddressSpace, Elasticity) ROSE_DEPRECATED("use shiftExtend");
514 void shift_extend(
SgAsmGenericSection*, rose_addr_t, rose_addr_t) ROSE_DEPRECATED("use shiftExtend");
515 rose_addr_t get_next_section_offset(rose_addr_t) ROSE_DEPRECATED("use get_nextSectionOffset");
518 void fill_holes() ROSE_DEPRECATED("use fillHoles");
519 void unfill_holes() ROSE_DEPRECATED("use unfillHoles");
522 const
char *format_name() const ROSE_DEPRECATED("use formatName");
538 void initializeProperties();
557 virtual std::
string class_name() const override;
560 virtual VariantT variantT() const override;
565 enum { static_variant = V_SgAsmGenericFile };
580 static const unsigned pool_size;
582 static std::vector<unsigned char *> pools;
587 static unsigned long initializeStorageClassArray(SgAsmGenericFileStorageClass *);
590 static void clearMemoryPool();
591 static void deleteMemoryPool();
594 static void extendMemoryPoolForFileIO();
599 static SgAsmGenericFile * getPointerFromGlobalIndex(AstSpecificDataManagingClass *,
unsigned long);
602 static unsigned long getNumberOfValidNodesAndSetGlobalIndexInFreepointer(
unsigned long);
604 static void resetValidFreepointers();
606 static unsigned long getNumberOfLastValidPointer();
609#if defined(INLINE_FUNCTIONS)
611 inline void *
operator new (
size_t size);
614 void *
operator new (
size_t size);
617 void operator delete (
void* pointer,
size_t size);
620 void operator delete (
void* pointer)
666#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
669 virtual RTIReturnType
roseRTI()
override;
683 virtual const char*
sage_class_name() const override ROSE_DEPRECATED_FUNCTION;
689 virtual int variant() const ROSE_DEPRECATED_FUNCTION;
871 friend class SgAsmGenericFileStorageClass;
874 friend class AstSpecificDataManagingClass;
877 friend class AstSpecificDataManagingClassStorageClass;
909#define BUILD_ATERM_SUPPORT 0
910 #if BUILD_ATERM_SUPPORT
911 #ifdef ROSE_USE_ROSE_ATERM_SUPPORT
923 virtual ATerm generate_ATerm()
override;
926 virtual void generate_ATerm_Annotation(ATerm & term)
override;
994bool p_trackingReferences;
Class holding static data and functions supporting File I/O.
Attribute containing a regex expression as a string.
Encodes and decodes a buffer using an algorithm defined in subclasses.
Base class for binary files.
List of pointers to file sections.
Contiguous region of a file.
Supporting class from copy mechanism within ROSE.
This class represents the base class for all IR nodes within Sage III.
virtual size_t get_numberOfTraversalSuccessors()
return number of children in the traversal successor list
virtual RTIReturnType roseRTI()
return C++ Runtime-Time-Information
virtual std::vector< std::string > get_traversalSuccessorNamesContainer()
container of names of variables or container indices used used in the traversal to access AST success...
virtual void debugSerializationEnd(const char *className)
Called by generated serializers.
static std::string getNodeIdString(SgNode *sgnode)
compute the NodeId for a particular SgNode*.
virtual bool isInMemoryPool()
FOR INTERNAL USE This is used in internal tests to verify that all IR nodes are allocated from the he...
int variant() const
Older version function returns enum value "NODE".
virtual void processDataMemberReferenceToPointers(ReferenceToPointerHandler *)
FOR INTERNAL USE Processes pairs of references to SgNode* and strings for use in AST tools
virtual long getChildIndex(SgNode *childNode) const
FOR INTERNAL USE Returns a unique index value for the childNode in the list of children at this IR no...
virtual size_t get_childIndex(SgNode *child)
index-based access to traversal successors by child node
virtual void debugSerializationBegin(const char *className)
Called by generated serializers.
virtual std::vector< SgNode * > get_traversalSuccessorContainer()
container of pointers to AST successor nodes used in the traversal overridden in every class by gener...
static void visitRepresentativeNode(ROSE_VisitTraversal &visit)
FOR INTERNAL USE Support for type-based traversal.
virtual void checkDataMemberPointersIfInMemoryPool()
FOR INTERNAL USE This is used in internal tests to verify that all IR nodes are allocated from the he...
static size_t numberOfNodes()
Returns the total number of IR nodes of this type.
virtual void accept(ROSE_VisitorPattern &visitor)
support for the classic visitor pattern done in GoF
virtual SgNode * get_traversalSuccessorByIndex(size_t idx)
index-based access to traversal successors by index number
static void traverseMemoryPoolVisitorPattern(ROSE_VisitorPattern &visitor)
FOR INTERNAL USE Support for visitor pattern.
void executeVisitorMemberFunction(ROSE_VisitorPattern &visitor)
FOR INTERNAL USE Support for visitor pattern.
static SgNode * getNodeByNodeId(VariantT variantT, size_t poolIdx, size_t itemIdx)
Find a node by its variant type, pool index, and item index.
static size_t memoryUsage()
Returns the size in bytes of the total memory allocated for all IR nodes of this type.
static void traverseMemoryPoolNodes(ROSE_VisitTraversal &visit)
FOR INTERNAL USE Support for visitor pattern over all IR nodes by type of IR node.
virtual const char * sage_class_name() const
generates string representing the class name: (e.g. for SgNode returns "SgNode").
virtual std::vector< std::pair< SgNode *, std::string > > returnDataMemberPointers() const
FOR INTERNAL USE Returns STL vector of pairs of SgNode* and strings for use in AST tools
static SgNode * getNodeByNodeIdInternal(size_t poolIdx, size_t itemIdx)
FOR INTERNAL USE Find an SgNode from its memory pool and location therin.
SgNode * addRegExpAttribute(std::string s, AstRegExAttribute *a)
Support for AST matching using regular expression.
virtual void destructorHelper()
This gets called by all Rosebud-generated destructors.
void parse(SgAsmGenericFile *)
Main function to parse DWARF information.
void serialize(std::ostream &output, Graph &graph)
Serialize a graph into a stream of bytes.
ROSE_DLL_API int set_name(SgInitializedName *initializedNameNode, SgName new_name)
set_name of symbol in symbol table.
std::string get_name(const SgNode *node)
Generate a useful name to describe the SgNode.
void copy(const Word *src, const BitRange &srcRange, Word *dst, const BitRange &dstRange)
Copy some bits.
const char * Elasticity(int64_t)
Convert SgAsmGenericFile::Elasticity enum constant to a string.
const char * AddressSpace(int64_t)
Convert SgAsmGenericFile::AddressSpace enum constant to a string.