[Cmake-commits] [cmake-commits] king committed cmELF.cxx 1.8 1.9 cmELF.h 1.4 1.5

cmake-commits at cmake.org cmake-commits at cmake.org
Mon Apr 14 15:02:26 EDT 2008


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv27671/Source

Modified Files:
	cmELF.cxx cmELF.h 
Log Message:
ENH: Added cmELF methods to get information about DYNAMIC section entries.


Index: cmELF.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmELF.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -C 2 -d -r1.4 -r1.5
*** cmELF.h	2 Mar 2008 21:19:40 -0000	1.4
--- cmELF.h	14 Apr 2008 19:02:24 -0000	1.5
***************
*** 69,72 ****
--- 69,75 ----
      // allocated for one or more null terminators.
      unsigned long Size;
+ 
+     // The index of the section entry referencing the string.
+     int IndexInSection;
    };
  
***************
*** 77,80 ****
--- 80,94 ----
    unsigned int GetNumberOfSections() const;
  
+   /** Get the number of DYNAMIC section entries before the first
+       DT_NULL.  Returns zero on error.  */
+   unsigned int GetDynamicEntryCount() const;
+ 
+   /** Get the position of a DYNAMIC section header entry.  Returns
+       zero on error.  */
+   unsigned long GetDynamicEntryPosition(int index) const;
+ 
+   /** Read bytes from the file.  */
+   bool ReadBytes(unsigned long pos, unsigned long size, char* buf) const;
+ 
    /** Get the SONAME field if any.  */
    bool GetSOName(std::string& soname);

Index: cmELF.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmELF.cxx,v
retrieving revision 1.8
retrieving revision 1.9
diff -C 2 -d -r1.8 -r1.9
*** cmELF.cxx	3 Mar 2008 13:48:37 -0000	1.8
--- cmELF.cxx	14 Apr 2008 19:02:24 -0000	1.9
***************
*** 99,105 ****
--- 99,114 ----
    // Forward to the per-class implementation.
    virtual unsigned int GetNumberOfSections() const = 0;
+   virtual unsigned int GetDynamicEntryCount() = 0;
+   virtual unsigned long GetDynamicEntryPosition(int j) = 0;
    virtual StringEntry const* GetDynamicSectionString(int tag) = 0;
    virtual void PrintInfo(std::ostream& os) const = 0;
  
+   bool ReadBytes(unsigned long pos, unsigned long size, char* buf)
+     {
+     this->Stream.seekg(pos);
+     this->Stream.read(buf, size);
+     return this->Stream?true:false;
+     }
+ 
    // Lookup the SONAME in the DYNAMIC section.
    StringEntry const* GetSOName()
***************
*** 202,205 ****
--- 211,218 ----
      }
  
+   // Get the file position and size of a dynamic section entry.
+   virtual unsigned int GetDynamicEntryCount();
+   virtual unsigned long GetDynamicEntryPosition(int j);
+ 
    // Lookup a string from the dynamic section with the given tag.
    virtual StringEntry const* GetDynamicSectionString(int tag);
***************
*** 553,556 ****
--- 566,603 ----
  //----------------------------------------------------------------------------
  template <class Types>
+ unsigned int cmELFInternalImpl<Types>::GetDynamicEntryCount()
+ {
+   if(!this->LoadDynamicSection())
+     {
+     return 0;
+     }
+   for(unsigned int i = 0; i < this->DynamicSectionEntries.size(); ++i)
+     {
+     if(this->DynamicSectionEntries[i].d_tag == DT_NULL)
+       {
+       return i;
+       }
+     }
+   return this->DynamicSectionEntries.size();
+ }
+ 
+ //----------------------------------------------------------------------------
+ template <class Types>
+ unsigned long cmELFInternalImpl<Types>::GetDynamicEntryPosition(int j)
+ {
+   if(!this->LoadDynamicSection())
+     {
+     return 0;
+     }
+   if(j < 0 || j >= this->DynamicSectionEntries.size())
+     {
+     return 0;
+     }
+   ELF_Shdr const& sec = this->SectionHeaders[this->DynamicSectionIndex];
+   return sec.sh_offset + sec.sh_entsize*j;
+ }
+ 
+ //----------------------------------------------------------------------------
+ template <class Types>
  cmELF::StringEntry const*
  cmELFInternalImpl<Types>::GetDynamicSectionString(int tag)
***************
*** 572,575 ****
--- 619,623 ----
    se.Position = 0;
    se.Size = 0;
+   se.IndexInSection = -1;
  
    // Try reading the dynamic section.
***************
*** 642,645 ****
--- 690,694 ----
        se.Position = static_cast<unsigned long>(strtab.sh_offset + first);
        se.Size = last - first;
+       se.IndexInSection = di - this->DynamicSectionEntries.begin();
        return &se;
        }
***************
*** 763,766 ****
--- 812,854 ----
  
  //----------------------------------------------------------------------------
+ unsigned int cmELF::GetDynamicEntryCount() const
+ {
+   if(this->Valid())
+     {
+     return this->Internal->GetDynamicEntryCount();
+     }
+   else
+     {
+     return 0;
+     }
+ }
+ 
+ //----------------------------------------------------------------------------
+ unsigned long cmELF::GetDynamicEntryPosition(int index) const
+ {
+   if(this->Valid())
+     {
+     return this->Internal->GetDynamicEntryPosition(index);
+     }
+   else
+     {
+     return 0;
+     }
+ }
+ 
+ //----------------------------------------------------------------------------
+ bool cmELF::ReadBytes(unsigned long pos, unsigned long size, char* buf) const
+ {
+   if(this->Valid())
+     {
+     return this->Internal->ReadBytes(pos, size, buf);
+     }
+   else
+     {
+     return false;
+     }
+ }
+ 
+ //----------------------------------------------------------------------------
  bool cmELF::GetSOName(std::string& soname)
  {



More information about the Cmake-commits mailing list