michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et cindent: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef SHARED_LIBRARIES_H_ michael@0: #define SHARED_LIBRARIES_H_ michael@0: michael@0: #ifndef MOZ_ENABLE_PROFILER_SPS michael@0: #error This header does not have a useful implementation on your platform! michael@0: #endif michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: class SharedLibrary { michael@0: public: michael@0: michael@0: SharedLibrary(uintptr_t aStart, michael@0: uintptr_t aEnd, michael@0: uintptr_t aOffset, michael@0: const std::string& aBreakpadId, michael@0: const std::string& aName) michael@0: : mStart(aStart) michael@0: , mEnd(aEnd) michael@0: , mOffset(aOffset) michael@0: , mBreakpadId(aBreakpadId) michael@0: , mName(aName) michael@0: {} michael@0: michael@0: SharedLibrary(const SharedLibrary& aEntry) michael@0: : mStart(aEntry.mStart) michael@0: , mEnd(aEntry.mEnd) michael@0: , mOffset(aEntry.mOffset) michael@0: , mBreakpadId(aEntry.mBreakpadId) michael@0: , mName(aEntry.mName) michael@0: {} michael@0: michael@0: SharedLibrary& operator=(const SharedLibrary& aEntry) michael@0: { michael@0: // Gracefully handle self assignment michael@0: if (this == &aEntry) return *this; michael@0: michael@0: mStart = aEntry.mStart; michael@0: mEnd = aEntry.mEnd; michael@0: mOffset = aEntry.mOffset; michael@0: mBreakpadId = aEntry.mBreakpadId; michael@0: mName = aEntry.mName; michael@0: return *this; michael@0: } michael@0: michael@0: bool operator==(const SharedLibrary& other) const michael@0: { michael@0: return (mStart == other.mStart) && michael@0: (mEnd == other.mEnd) && michael@0: (mOffset == other.mOffset) && michael@0: (mName == other.mName) && michael@0: (mBreakpadId == other.mBreakpadId); michael@0: } michael@0: michael@0: uintptr_t GetStart() const { return mStart; } michael@0: uintptr_t GetEnd() const { return mEnd; } michael@0: uintptr_t GetOffset() const { return mOffset; } michael@0: const std::string &GetBreakpadId() const { return mBreakpadId; } michael@0: const std::string &GetName() const { return mName; } michael@0: michael@0: private: michael@0: SharedLibrary() {} michael@0: michael@0: uintptr_t mStart; michael@0: uintptr_t mEnd; michael@0: uintptr_t mOffset; michael@0: std::string mBreakpadId; michael@0: std::string mName; michael@0: }; michael@0: michael@0: static bool michael@0: CompareAddresses(const SharedLibrary& first, const SharedLibrary& second) michael@0: { michael@0: return first.GetStart() < second.GetStart(); michael@0: } michael@0: michael@0: class SharedLibraryInfo { michael@0: public: michael@0: static SharedLibraryInfo GetInfoForSelf(); michael@0: SharedLibraryInfo() {} michael@0: michael@0: void AddSharedLibrary(SharedLibrary entry) michael@0: { michael@0: mEntries.push_back(entry); michael@0: } michael@0: michael@0: const SharedLibrary& GetEntry(size_t i) const michael@0: { michael@0: return mEntries[i]; michael@0: } michael@0: michael@0: // Removes items in the range [first, last) michael@0: // i.e. element at the "last" index is not removed michael@0: void RemoveEntries(size_t first, size_t last) michael@0: { michael@0: mEntries.erase(mEntries.begin() + first, mEntries.begin() + last); michael@0: } michael@0: michael@0: bool Contains(const SharedLibrary& searchItem) const michael@0: { michael@0: return (mEntries.end() != michael@0: std::find(mEntries.begin(), mEntries.end(), searchItem)); michael@0: } michael@0: michael@0: size_t GetSize() const michael@0: { michael@0: return mEntries.size(); michael@0: } michael@0: michael@0: void SortByAddress() michael@0: { michael@0: std::sort(mEntries.begin(), mEntries.end(), CompareAddresses); michael@0: } michael@0: michael@0: void Clear() michael@0: { michael@0: mEntries.clear(); michael@0: } michael@0: michael@0: private: michael@0: std::vector mEntries; michael@0: }; michael@0: michael@0: #endif