2012-01-05 15:11:29 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-12-15 04:31:41 -08:00
|
|
|
|
2012-03-14 19:58:18 -07:00
|
|
|
#ifndef SHARED_LIBRARIES_H_
|
|
|
|
#define SHARED_LIBRARIES_H_
|
|
|
|
|
|
|
|
#ifndef MOZ_ENABLE_PROFILER_SPS
|
|
|
|
#error This header does not have a useful implementation on your platform!
|
|
|
|
#endif
|
|
|
|
|
2012-03-12 04:07:05 -07:00
|
|
|
#include <algorithm>
|
2011-12-15 04:31:41 -08:00
|
|
|
#include <vector>
|
2013-01-09 12:05:00 -08:00
|
|
|
#include <string>
|
2011-12-15 04:31:41 -08:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2012-02-29 19:56:43 -08:00
|
|
|
#include <mozilla/StandardInteger.h>
|
2012-03-12 04:07:05 -07:00
|
|
|
#include <nsID.h>
|
2011-12-15 04:31:41 -08:00
|
|
|
|
|
|
|
class SharedLibrary {
|
|
|
|
public:
|
2012-03-12 04:07:05 -07:00
|
|
|
|
|
|
|
SharedLibrary(unsigned long aStart,
|
|
|
|
unsigned long aEnd,
|
|
|
|
unsigned long aOffset,
|
2013-01-09 12:05:00 -08:00
|
|
|
const std::string &aBreakpadId,
|
2013-01-16 17:38:22 -08:00
|
|
|
const std::string &aName)
|
2011-12-15 04:31:41 -08:00
|
|
|
: mStart(aStart)
|
|
|
|
, mEnd(aEnd)
|
|
|
|
, mOffset(aOffset)
|
2013-01-09 12:05:00 -08:00
|
|
|
, mBreakpadId(aBreakpadId)
|
2013-01-16 17:38:22 -08:00
|
|
|
, mName(aName)
|
2011-12-15 04:31:41 -08:00
|
|
|
{}
|
|
|
|
|
|
|
|
SharedLibrary(const SharedLibrary& aEntry)
|
|
|
|
: mStart(aEntry.mStart)
|
|
|
|
, mEnd(aEntry.mEnd)
|
|
|
|
, mOffset(aEntry.mOffset)
|
2013-01-09 12:05:00 -08:00
|
|
|
, mBreakpadId(aEntry.mBreakpadId)
|
2013-01-16 17:38:22 -08:00
|
|
|
, mName(aEntry.mName)
|
2011-12-15 04:31:41 -08:00
|
|
|
{}
|
|
|
|
|
|
|
|
SharedLibrary& operator=(const SharedLibrary& aEntry)
|
|
|
|
{
|
2012-01-05 15:11:29 -08:00
|
|
|
// Gracefully handle self assignment
|
|
|
|
if (this == &aEntry) return *this;
|
|
|
|
|
2011-12-15 04:31:41 -08:00
|
|
|
mStart = aEntry.mStart;
|
|
|
|
mEnd = aEntry.mEnd;
|
|
|
|
mOffset = aEntry.mOffset;
|
2013-01-09 12:05:00 -08:00
|
|
|
mBreakpadId = aEntry.mBreakpadId;
|
2013-01-16 17:38:22 -08:00
|
|
|
mName = aEntry.mName;
|
2011-12-15 04:31:41 -08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2012-03-12 04:07:05 -07:00
|
|
|
bool operator==(const SharedLibrary& other) const
|
|
|
|
{
|
2013-01-09 12:05:00 -08:00
|
|
|
return (mStart == other.mStart) &&
|
|
|
|
(mEnd == other.mEnd) &&
|
|
|
|
(mOffset == other.mOffset) &&
|
2013-01-16 17:38:22 -08:00
|
|
|
(mName == other.mName) &&
|
2013-01-09 12:05:00 -08:00
|
|
|
(mBreakpadId == other.mBreakpadId);
|
2012-03-12 04:07:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
uintptr_t GetStart() const { return mStart; }
|
|
|
|
uintptr_t GetEnd() const { return mEnd; }
|
2012-04-13 13:33:53 -07:00
|
|
|
uintptr_t GetOffset() const { return mOffset; }
|
2013-01-09 12:05:00 -08:00
|
|
|
const std::string &GetBreakpadId() const { return mBreakpadId; }
|
2013-01-16 17:38:22 -08:00
|
|
|
const std::string &GetName() const { return mName; }
|
2011-12-15 04:31:41 -08:00
|
|
|
|
|
|
|
private:
|
2013-01-16 20:26:46 -08:00
|
|
|
SharedLibrary() {}
|
2011-12-15 04:31:41 -08:00
|
|
|
|
|
|
|
uintptr_t mStart;
|
|
|
|
uintptr_t mEnd;
|
|
|
|
uintptr_t mOffset;
|
2013-01-09 12:05:00 -08:00
|
|
|
std::string mBreakpadId;
|
2013-01-16 17:38:22 -08:00
|
|
|
std::string mName;
|
2011-12-15 04:31:41 -08:00
|
|
|
};
|
|
|
|
|
2012-03-12 04:07:05 -07:00
|
|
|
static bool
|
|
|
|
CompareAddresses(const SharedLibrary& first, const SharedLibrary& second)
|
|
|
|
{
|
|
|
|
return first.GetStart() < second.GetStart();
|
|
|
|
}
|
|
|
|
|
2011-12-15 04:31:41 -08:00
|
|
|
class SharedLibraryInfo {
|
|
|
|
public:
|
|
|
|
static SharedLibraryInfo GetInfoForSelf();
|
|
|
|
SharedLibraryInfo() {}
|
|
|
|
|
|
|
|
void AddSharedLibrary(SharedLibrary entry)
|
|
|
|
{
|
|
|
|
mEntries.push_back(entry);
|
|
|
|
}
|
|
|
|
|
2012-08-21 14:14:38 -07:00
|
|
|
const SharedLibrary& GetEntry(size_t i) const
|
2011-12-15 04:31:41 -08:00
|
|
|
{
|
|
|
|
return mEntries[i];
|
|
|
|
}
|
|
|
|
|
2012-03-12 04:07:05 -07:00
|
|
|
// Removes items in the range [first, last)
|
|
|
|
// i.e. element at the "last" index is not removed
|
|
|
|
void RemoveEntries(size_t first, size_t last)
|
|
|
|
{
|
|
|
|
mEntries.erase(mEntries.begin() + first, mEntries.begin() + last);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Contains(const SharedLibrary& searchItem) const
|
|
|
|
{
|
|
|
|
return (mEntries.end() !=
|
|
|
|
std::find(mEntries.begin(), mEntries.end(), searchItem));
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t GetSize() const
|
2011-12-15 04:31:41 -08:00
|
|
|
{
|
|
|
|
return mEntries.size();
|
|
|
|
}
|
2012-03-12 04:07:05 -07:00
|
|
|
|
|
|
|
void SortByAddress()
|
|
|
|
{
|
|
|
|
std::sort(mEntries.begin(), mEntries.end(), CompareAddresses);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clear()
|
|
|
|
{
|
|
|
|
mEntries.clear();
|
|
|
|
}
|
|
|
|
|
2011-12-15 04:31:41 -08:00
|
|
|
private:
|
|
|
|
std::vector<SharedLibrary> mEntries;
|
|
|
|
};
|
2012-03-14 19:58:18 -07:00
|
|
|
|
|
|
|
#endif
|