Line data Source code
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 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef SHARED_LIBRARIES_H_
8 : #define SHARED_LIBRARIES_H_
9 :
10 : #ifndef MOZ_GECKO_PROFILER
11 : #error This header does not have a useful implementation on your platform!
12 : #endif
13 :
14 : #include <algorithm>
15 : #include <vector>
16 : #include <string>
17 : #include <stdlib.h>
18 : #include <stdint.h>
19 : #include <nsID.h>
20 : #include "nsString.h"
21 : #include "nsNativeCharsetUtils.h"
22 :
23 0 : class SharedLibrary {
24 : public:
25 :
26 0 : SharedLibrary(uintptr_t aStart,
27 : uintptr_t aEnd,
28 : uintptr_t aOffset,
29 : const std::string& aBreakpadId,
30 : const nsString& aModuleName,
31 : const nsString& aModulePath,
32 : const nsString& aDebugName,
33 : const nsString& aDebugPath,
34 : const std::string& aVersion,
35 : const char* aArch)
36 0 : : mStart(aStart)
37 : , mEnd(aEnd)
38 : , mOffset(aOffset)
39 : , mBreakpadId(aBreakpadId)
40 : , mModuleName(aModuleName)
41 : , mModulePath(aModulePath)
42 : , mDebugName(aDebugName)
43 : , mDebugPath(aDebugPath)
44 : , mVersion(aVersion)
45 0 : , mArch(aArch)
46 0 : {}
47 :
48 0 : SharedLibrary(const SharedLibrary& aEntry)
49 0 : : mStart(aEntry.mStart)
50 0 : , mEnd(aEntry.mEnd)
51 0 : , mOffset(aEntry.mOffset)
52 : , mBreakpadId(aEntry.mBreakpadId)
53 : , mModuleName(aEntry.mModuleName)
54 : , mModulePath(aEntry.mModulePath)
55 : , mDebugName(aEntry.mDebugName)
56 : , mDebugPath(aEntry.mDebugPath)
57 : , mVersion(aEntry.mVersion)
58 0 : , mArch(aEntry.mArch)
59 0 : {}
60 :
61 0 : SharedLibrary& operator=(const SharedLibrary& aEntry)
62 : {
63 : // Gracefully handle self assignment
64 0 : if (this == &aEntry) return *this;
65 :
66 0 : mStart = aEntry.mStart;
67 0 : mEnd = aEntry.mEnd;
68 0 : mOffset = aEntry.mOffset;
69 0 : mBreakpadId = aEntry.mBreakpadId;
70 0 : mModuleName = aEntry.mModuleName;
71 0 : mModulePath = aEntry.mModulePath;
72 0 : mDebugName = aEntry.mDebugName;
73 0 : mDebugPath = aEntry.mDebugPath;
74 0 : mVersion = aEntry.mVersion;
75 0 : mArch = aEntry.mArch;
76 0 : return *this;
77 : }
78 :
79 : bool operator==(const SharedLibrary& other) const
80 : {
81 : return (mStart == other.mStart) &&
82 : (mEnd == other.mEnd) &&
83 : (mOffset == other.mOffset) &&
84 : (mModuleName == other.mModuleName) &&
85 : (mModulePath == other.mModulePath) &&
86 : (mDebugName == other.mDebugName) &&
87 : (mDebugPath == other.mDebugPath) &&
88 : (mBreakpadId == other.mBreakpadId) &&
89 : (mVersion == other.mVersion) &&
90 : (mArch == other.mArch);
91 : }
92 :
93 0 : uintptr_t GetStart() const { return mStart; }
94 0 : uintptr_t GetEnd() const { return mEnd; }
95 0 : uintptr_t GetOffset() const { return mOffset; }
96 0 : const std::string &GetBreakpadId() const { return mBreakpadId; }
97 0 : const nsString &GetModuleName() const { return mModuleName; }
98 0 : const nsString &GetModulePath() const { return mModulePath; }
99 0 : const std::string GetNativeDebugPath() const {
100 0 : nsAutoCString debugPathStr;
101 :
102 0 : NS_CopyUnicodeToNative(mDebugPath, debugPathStr);
103 :
104 0 : return debugPathStr.get();
105 : }
106 0 : const nsString &GetDebugName() const { return mDebugName; }
107 0 : const nsString &GetDebugPath() const { return mDebugPath; }
108 0 : const std::string &GetVersion() const { return mVersion; }
109 0 : const std::string &GetArch() const { return mArch; }
110 :
111 : private:
112 : SharedLibrary() {}
113 :
114 : uintptr_t mStart;
115 : uintptr_t mEnd;
116 : uintptr_t mOffset;
117 : std::string mBreakpadId;
118 : nsString mModuleName;
119 : nsString mModulePath;
120 : nsString mDebugName;
121 : nsString mDebugPath;
122 : std::string mVersion;
123 : std::string mArch;
124 : };
125 :
126 : static bool
127 0 : CompareAddresses(const SharedLibrary& first, const SharedLibrary& second)
128 : {
129 0 : return first.GetStart() < second.GetStart();
130 : }
131 :
132 0 : class SharedLibraryInfo {
133 : public:
134 : static SharedLibraryInfo GetInfoForSelf();
135 : static void Initialize();
136 :
137 0 : SharedLibraryInfo() {}
138 :
139 0 : void AddSharedLibrary(SharedLibrary entry)
140 : {
141 0 : mEntries.push_back(entry);
142 0 : }
143 :
144 0 : const SharedLibrary& GetEntry(size_t i) const
145 : {
146 0 : return mEntries[i];
147 : }
148 :
149 0 : SharedLibrary& GetMutableEntry(size_t i)
150 : {
151 0 : return mEntries[i];
152 : }
153 :
154 : // Removes items in the range [first, last)
155 : // i.e. element at the "last" index is not removed
156 0 : void RemoveEntries(size_t first, size_t last)
157 : {
158 0 : mEntries.erase(mEntries.begin() + first, mEntries.begin() + last);
159 0 : }
160 :
161 : bool Contains(const SharedLibrary& searchItem) const
162 : {
163 : return (mEntries.end() !=
164 : std::find(mEntries.begin(), mEntries.end(), searchItem));
165 : }
166 :
167 0 : size_t GetSize() const
168 : {
169 0 : return mEntries.size();
170 : }
171 :
172 0 : void SortByAddress()
173 : {
174 0 : std::sort(mEntries.begin(), mEntries.end(), CompareAddresses);
175 0 : }
176 :
177 : void Clear()
178 : {
179 : mEntries.clear();
180 : }
181 :
182 : private:
183 : std::vector<SharedLibrary> mEntries;
184 : };
185 :
186 : #endif
|