/work/obj-fuzz/dist/include/shared-libraries.h
Line | Count | Source (jump to first uncovered line) |
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 | | class SharedLibrary { |
24 | | public: |
25 | | |
26 | | SharedLibrary(uintptr_t aStart, |
27 | | uintptr_t aEnd, |
28 | | uintptr_t aOffset, |
29 | | const nsCString& aBreakpadId, |
30 | | const nsString& aModuleName, |
31 | | const nsString& aModulePath, |
32 | | const nsString& aDebugName, |
33 | | const nsString& aDebugPath, |
34 | | const nsCString& aVersion, |
35 | | const char* aArch) |
36 | | : 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 | | , mArch(aArch) |
46 | 0 | {} |
47 | | |
48 | | SharedLibrary(const SharedLibrary& aEntry) |
49 | | : mStart(aEntry.mStart) |
50 | | , mEnd(aEntry.mEnd) |
51 | | , 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 | | , mArch(aEntry.mArch) |
59 | 0 | {} |
60 | | |
61 | | SharedLibrary& operator=(const SharedLibrary& aEntry) |
62 | 0 | { |
63 | 0 | // Gracefully handle self assignment |
64 | 0 | if (this == &aEntry) return *this; |
65 | 0 | |
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 | 0 | } |
78 | | |
79 | | bool operator==(const SharedLibrary& other) const |
80 | 0 | { |
81 | 0 | return (mStart == other.mStart) && |
82 | 0 | (mEnd == other.mEnd) && |
83 | 0 | (mOffset == other.mOffset) && |
84 | 0 | (mModuleName == other.mModuleName) && |
85 | 0 | (mModulePath == other.mModulePath) && |
86 | 0 | (mDebugName == other.mDebugName) && |
87 | 0 | (mDebugPath == other.mDebugPath) && |
88 | 0 | (mBreakpadId == other.mBreakpadId) && |
89 | 0 | (mVersion == other.mVersion) && |
90 | 0 | (mArch == other.mArch); |
91 | 0 | } |
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 nsCString &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 | 0 |
|
102 | 0 | NS_CopyUnicodeToNative(mDebugPath, debugPathStr); |
103 | 0 |
|
104 | 0 | return debugPathStr.get(); |
105 | 0 | } |
106 | 0 | const nsString &GetDebugName() const { return mDebugName; } |
107 | 0 | const nsString &GetDebugPath() const { return mDebugPath; } |
108 | 0 | const nsCString &GetVersion() const { return mVersion; } |
109 | 0 | const std::string &GetArch() const { return mArch; } |
110 | | |
111 | | private: |
112 | 0 | SharedLibrary() : mStart{0}, mEnd{0}, mOffset{0} {} |
113 | | |
114 | | uintptr_t mStart; |
115 | | uintptr_t mEnd; |
116 | | uintptr_t mOffset; |
117 | | nsCString mBreakpadId; |
118 | | nsString mModuleName; |
119 | | nsString mModulePath; |
120 | | nsString mDebugName; |
121 | | nsString mDebugPath; |
122 | | nsCString mVersion; |
123 | | std::string mArch; |
124 | | }; |
125 | | |
126 | | static bool |
127 | | CompareAddresses(const SharedLibrary& first, const SharedLibrary& second) |
128 | 0 | { |
129 | 0 | return first.GetStart() < second.GetStart(); |
130 | 0 | } Unexecuted instantiation: shared-libraries-linux.cc:CompareAddresses(SharedLibrary const&, SharedLibrary const&) Unexecuted instantiation: Unified_cpp_tools_profiler0.cpp:CompareAddresses(SharedLibrary const&, SharedLibrary const&) Unexecuted instantiation: Unified_cpp_tools_profiler1.cpp:CompareAddresses(SharedLibrary const&, SharedLibrary const&) Unexecuted instantiation: Unified_cpp_ackgroundhangmonitor0.cpp:CompareAddresses(SharedLibrary const&, SharedLibrary const&) Unexecuted instantiation: Telemetry.cpp:CompareAddresses(SharedLibrary const&, SharedLibrary const&) Unexecuted instantiation: ProcessedStack.cpp:CompareAddresses(SharedLibrary const&, SharedLibrary const&) |
131 | | |
132 | | class SharedLibraryInfo { |
133 | | public: |
134 | | static SharedLibraryInfo GetInfoForSelf(); |
135 | | static void Initialize(); |
136 | | |
137 | 0 | SharedLibraryInfo() {} |
138 | | |
139 | | void AddSharedLibrary(SharedLibrary entry) |
140 | 0 | { |
141 | 0 | mEntries.push_back(entry); |
142 | 0 | } |
143 | | |
144 | | const SharedLibrary& GetEntry(size_t i) const |
145 | 0 | { |
146 | 0 | return mEntries[i]; |
147 | 0 | } |
148 | | |
149 | | SharedLibrary& GetMutableEntry(size_t i) |
150 | 0 | { |
151 | 0 | return mEntries[i]; |
152 | 0 | } |
153 | | |
154 | | // Removes items in the range [first, last) |
155 | | // i.e. element at the "last" index is not removed |
156 | | void RemoveEntries(size_t first, size_t last) |
157 | 0 | { |
158 | 0 | mEntries.erase(mEntries.begin() + first, mEntries.begin() + last); |
159 | 0 | } |
160 | | |
161 | | bool Contains(const SharedLibrary& searchItem) const |
162 | 0 | { |
163 | 0 | return (mEntries.end() != |
164 | 0 | std::find(mEntries.begin(), mEntries.end(), searchItem)); |
165 | 0 | } |
166 | | |
167 | | size_t GetSize() const |
168 | 0 | { |
169 | 0 | return mEntries.size(); |
170 | 0 | } |
171 | | |
172 | | void SortByAddress() |
173 | 0 | { |
174 | 0 | std::sort(mEntries.begin(), mEntries.end(), CompareAddresses); |
175 | 0 | } |
176 | | |
177 | | void Clear() |
178 | 0 | { |
179 | 0 | mEntries.clear(); |
180 | 0 | } |
181 | | |
182 | | private: |
183 | | std::vector<SharedLibrary> mEntries; |
184 | | }; |
185 | | |
186 | | #endif |