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: */
|
2011-12-15 04:31:41 -08:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is the Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2011
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Jeff Muizelaar <jmuizelaar@mozilla.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
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>
|
|
|
|
#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,
|
|
|
|
#ifdef XP_WIN
|
|
|
|
nsID aPdbSignature,
|
|
|
|
unsigned long aPdbAge,
|
2012-03-19 16:05:25 -07:00
|
|
|
char *aPdbName,
|
2012-03-12 04:07:05 -07:00
|
|
|
#endif
|
|
|
|
char *aName)
|
2011-12-15 04:31:41 -08:00
|
|
|
: mStart(aStart)
|
|
|
|
, mEnd(aEnd)
|
|
|
|
, mOffset(aOffset)
|
2012-03-12 04:07:05 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
, mPdbSignature(aPdbSignature)
|
|
|
|
, mPdbAge(aPdbAge)
|
2012-03-19 16:05:25 -07:00
|
|
|
, mPdbName(strdup(aPdbName))
|
2012-03-12 04:07:05 -07:00
|
|
|
#endif
|
2011-12-15 04:31:41 -08:00
|
|
|
, mName(strdup(aName))
|
|
|
|
{}
|
|
|
|
|
|
|
|
SharedLibrary(const SharedLibrary& aEntry)
|
|
|
|
: mStart(aEntry.mStart)
|
|
|
|
, mEnd(aEntry.mEnd)
|
|
|
|
, mOffset(aEntry.mOffset)
|
2012-03-12 04:07:05 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
, mPdbSignature(aEntry.mPdbSignature)
|
|
|
|
, mPdbAge(aEntry.mPdbAge)
|
2012-03-19 16:05:25 -07:00
|
|
|
, mPdbName(strdup(aEntry.mPdbName))
|
2012-03-12 04:07:05 -07:00
|
|
|
#endif
|
2011-12-15 04:31:41 -08:00
|
|
|
, mName(strdup(aEntry.mName))
|
|
|
|
{}
|
|
|
|
|
|
|
|
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;
|
2012-03-12 04:07:05 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
mPdbSignature = aEntry.mPdbSignature;
|
|
|
|
mPdbAge = aEntry.mPdbAge;
|
2012-03-19 16:05:25 -07:00
|
|
|
if (mPdbName)
|
|
|
|
free(mPdbName);
|
|
|
|
mPdbName = strdup(aEntry.mPdbName);
|
2012-03-12 04:07:05 -07:00
|
|
|
#endif
|
2012-01-05 15:11:29 -08:00
|
|
|
if (mName)
|
|
|
|
free(mName);
|
2011-12-15 04:31:41 -08:00
|
|
|
mName = strdup(aEntry.mName);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2012-03-12 04:07:05 -07:00
|
|
|
bool operator==(const SharedLibrary& other) const
|
|
|
|
{
|
|
|
|
bool equal = ((mStart == other.mStart) &&
|
|
|
|
(mEnd == other.mEnd) &&
|
|
|
|
(mOffset == other.mOffset) &&
|
|
|
|
(mName && other.mName && (strcmp(mName, other.mName) == 0)));
|
|
|
|
#ifdef XP_WIN
|
|
|
|
equal = equal &&
|
|
|
|
(mPdbSignature.Equals(other.mPdbSignature)) &&
|
2012-03-19 16:05:25 -07:00
|
|
|
(mPdbAge == other.mPdbAge) &&
|
|
|
|
(mPdbName && other.mPdbName && (strcmp(mPdbName, other.mPdbName) == 0));
|
2012-03-12 04:07:05 -07:00
|
|
|
#endif
|
|
|
|
return equal;
|
|
|
|
}
|
|
|
|
|
2011-12-15 04:31:41 -08:00
|
|
|
~SharedLibrary()
|
|
|
|
{
|
2012-03-19 16:05:25 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
free(mPdbName);
|
|
|
|
mPdbName = NULL;
|
|
|
|
#endif
|
2011-12-15 04:31:41 -08:00
|
|
|
free(mName);
|
2012-03-12 04:07:05 -07:00
|
|
|
mName = NULL;
|
2011-12-15 04:31:41 -08:00
|
|
|
}
|
|
|
|
|
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; }
|
2012-03-12 04:07:05 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
nsID GetPdbSignature() const { return mPdbSignature; }
|
|
|
|
uint32_t GetPdbAge() const { return mPdbAge; }
|
2012-03-19 16:05:25 -07:00
|
|
|
char* GetPdbName() const { return mPdbName; }
|
2012-03-12 04:07:05 -07:00
|
|
|
#endif
|
|
|
|
char* GetName() const { return mName; }
|
2011-12-15 04:31:41 -08:00
|
|
|
|
|
|
|
private:
|
|
|
|
explicit SharedLibrary() {}
|
|
|
|
|
|
|
|
uintptr_t mStart;
|
|
|
|
uintptr_t mEnd;
|
|
|
|
uintptr_t mOffset;
|
2012-03-12 04:07:05 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
// Windows-specific PDB file identifiers
|
|
|
|
nsID mPdbSignature;
|
|
|
|
uint32_t mPdbAge;
|
2012-03-19 16:05:25 -07:00
|
|
|
char *mPdbName;
|
2012-03-12 04:07:05 -07:00
|
|
|
#endif
|
2011-12-15 04:31:41 -08:00
|
|
|
char *mName;
|
|
|
|
};
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
SharedLibrary& GetEntry(size_t i)
|
|
|
|
{
|
|
|
|
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
|