LCOV - app.info - objdir/dist/include/shared-libraries.h

LCOV - code coverage report
| Current view: | directory - objdir/dist/include - shared-libraries.h (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 3 | 0 | 0.0 %
| Date: | 2012-04-07 | Functions: | 2 | 0 | 0.0 %

           1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
           2                 : /* vim:set ts=2 sw=2 sts=2 et cindent: */
           3                 : /* ***** BEGIN LICENSE BLOCK *****
           4                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
           5                 :  *
           6                 :  * The contents of this file are subject to the Mozilla Public License Version
           7                 :  * 1.1 (the "License"); you may not use this file except in compliance with
           8                 :  * the License. You may obtain a copy of the License at
           9                 :  * http://www.mozilla.org/MPL/
          10                 :  *
          11                 :  * Software distributed under the License is distributed on an "AS IS" basis,
          12                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
          13                 :  * for the specific language governing rights and limitations under the
          14                 :  * License.
          15                 :  *
          16                 :  * The Original Code is Mozilla code.
          17                 :  *
          18                 :  * The Initial Developer of the Original Code is the Mozilla Foundation.
          19                 :  * Portions created by the Initial Developer are Copyright (C) 2011
          20                 :  * the Initial Developer. All Rights Reserved.
          21                 :  *
          22                 :  * Contributor(s):
          23                 :  *  Jeff Muizelaar <jmuizelaar@mozilla.com>
          24                 :  *
          25                 :  * Alternatively, the contents of this file may be used under the terms of
          26                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
          27                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
          28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
          29                 :  * of those above. If you wish to allow use of your version of this file only
          30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
          31                 :  * use your version of this file under the terms of the MPL, indicate your
          32                 :  * decision by deleting the provisions above and replace them with the notice
          33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
          34                 :  * the provisions above, a recipient may use your version of this file under
          35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
          36                 :  *
          37                 :  * ***** END LICENSE BLOCK ***** */
          38                 :
          39                 : #ifndef SHARED_LIBRARIES_H_
          40                 : #define SHARED_LIBRARIES_H_
          41                 :
          42                 : #ifndef MOZ_ENABLE_PROFILER_SPS
          43                 : #error This header does not have a useful implementation on your platform!
          44                 : #endif
          45                 :
          46                 : #include <algorithm>
          47                 : #include <vector>
          48                 : #include <string.h>
          49                 : #include <stdlib.h>
          50                 : #include <mozilla/StandardInteger.h>
          51                 : #include <nsID.h>
          52                 :
          53                 : class SharedLibrary {
          54                 : public:
          55                 :
          56                 :   SharedLibrary(unsigned long aStart,
          57                 :                 unsigned long aEnd,
          58                 :                 unsigned long aOffset,
          59                 : #ifdef XP_WIN
          60                 :                 nsID aPdbSignature,
          61                 :                 unsigned long aPdbAge,
          62                 :                 char *aPdbName,
          63                 : #endif
          64                 :                 char *aName)
          65                 :     : mStart(aStart)
          66                 :     , mEnd(aEnd)
          67                 :     , mOffset(aOffset)
          68                 : #ifdef XP_WIN
          69                 :     , mPdbSignature(aPdbSignature)
          70                 :     , mPdbAge(aPdbAge)
          71                 :     , mPdbName(strdup(aPdbName))
          72                 : #endif
          73                 :     , mName(strdup(aName))
          74                 :   {}
          75                 :
          76                 :   SharedLibrary(const SharedLibrary& aEntry)
          77                 :     : mStart(aEntry.mStart)
          78                 :     , mEnd(aEntry.mEnd)
          79                 :     , mOffset(aEntry.mOffset)
          80                 : #ifdef XP_WIN
          81                 :     , mPdbSignature(aEntry.mPdbSignature)
          82                 :     , mPdbAge(aEntry.mPdbAge)
          83                 :     , mPdbName(strdup(aEntry.mPdbName))
          84                 : #endif
          85                 :     , mName(strdup(aEntry.mName))
          86                 :   {}
          87                 :
          88                 :   SharedLibrary& operator=(const SharedLibrary& aEntry)
          89                 :   {
          90                 :     // Gracefully handle self assignment
          91                 :     if (this == &aEntry) return *this;
          92                 :
          93                 :     mStart = aEntry.mStart;
          94                 :     mEnd = aEntry.mEnd;
          95                 :     mOffset = aEntry.mOffset;
          96                 : #ifdef XP_WIN
          97                 :     mPdbSignature = aEntry.mPdbSignature;
          98                 :     mPdbAge = aEntry.mPdbAge;
          99                 :     if (mPdbName)
         100                 :       free(mPdbName);
         101                 :     mPdbName = strdup(aEntry.mPdbName);
         102                 : #endif
         103                 :     if (mName)
         104                 :       free(mName);
         105                 :     mName = strdup(aEntry.mName);
         106                 :     return *this;
         107                 :   }
         108                 :
         109                 :   bool operator==(const SharedLibrary& other) const
         110                 :   {
         111                 :     bool equal = ((mStart == other.mStart) &&
         112                 :                   (mEnd == other.mEnd) &&
         113                 :                   (mOffset == other.mOffset) &&
         114                 :                   (mName && other.mName && (strcmp(mName, other.mName) == 0)));
         115                 : #ifdef XP_WIN
         116                 :     equal = equal &&
         117                 :             (mPdbSignature.Equals(other.mPdbSignature)) &&
         118                 :             (mPdbAge == other.mPdbAge) &&
         119                 :             (mPdbName && other.mPdbName && (strcmp(mPdbName, other.mPdbName) == 0));
         120                 : #endif
         121                 :     return equal;
         122                 :   }
         123                 :
         124                 :   ~SharedLibrary()
         125                 :   {
         126                 : #ifdef XP_WIN
         127                 :     free(mPdbName);
         128                 :     mPdbName = NULL;
         129                 : #endif
         130                 :     free(mName);
         131                 :     mName = NULL;
         132                 :   }
         133                 :
         134               0 :   uintptr_t GetStart() const { return mStart; }
         135                 :   uintptr_t GetEnd() const { return mEnd; }
         136                 : #ifdef XP_WIN
         137                 :   nsID GetPdbSignature() const { return mPdbSignature; }
         138                 :   uint32_t GetPdbAge() const { return mPdbAge; }
         139                 :   char* GetPdbName() const { return mPdbName; }
         140                 : #endif
         141                 :   char* GetName() const { return mName; }
         142                 :
         143                 : private:
         144                 :   explicit SharedLibrary() {}
         145                 :
         146                 :   uintptr_t mStart;
         147                 :   uintptr_t mEnd;
         148                 :   uintptr_t mOffset;
         149                 : #ifdef XP_WIN
         150                 :   // Windows-specific PDB file identifiers
         151                 :   nsID mPdbSignature;
         152                 :   uint32_t mPdbAge;
         153                 :   char *mPdbName;
         154                 : #endif
         155                 :   char *mName;
         156                 : };
         157                 :
         158                 : static bool
         159               0 : CompareAddresses(const SharedLibrary& first, const SharedLibrary& second)
         160                 : {
         161               0 :   return first.GetStart() < second.GetStart();
         162                 : }
         163                 :
         164                 : class SharedLibraryInfo {
         165                 : public:
         166                 :   static SharedLibraryInfo GetInfoForSelf();
         167                 :   SharedLibraryInfo() {}
         168                 :
         169                 :   void AddSharedLibrary(SharedLibrary entry)
         170                 :   {
         171                 :     mEntries.push_back(entry);
         172                 :   }
         173                 :
         174                 :   SharedLibrary& GetEntry(size_t i)
         175                 :   {
         176                 :     return mEntries[i];
         177                 :   }
         178                 :
         179                 :   // Removes items in the range [first, last)
         180                 :   // i.e. element at the "last" index is not removed
         181                 :   void RemoveEntries(size_t first, size_t last)
         182                 :   {
         183                 :     mEntries.erase(mEntries.begin() + first, mEntries.begin() + last);
         184                 :   }
         185                 :
         186                 :   bool Contains(const SharedLibrary& searchItem) const
         187                 :   {
         188                 :     return (mEntries.end() !=
         189                 :               std::find(mEntries.begin(), mEntries.end(), searchItem));
         190                 :   }
         191                 :
         192                 :   size_t GetSize() const
         193                 :   {
         194                 :     return mEntries.size();
         195                 :   }
         196                 :
         197                 :   void SortByAddress()
         198                 :   {
         199                 :     std::sort(mEntries.begin(), mEntries.end(), CompareAddresses);
         200                 :   }
         201                 :
         202                 :   void Clear()
         203                 :   {
         204                 :     mEntries.clear();
         205                 :   }
         206                 :
         207                 : private:
         208                 :   std::vector<SharedLibrary> mEntries;
         209                 : };
         210                 :
         211                 : #endif

Generated by: LCOV version 1.7