2012-11-12 16:53:47 +01:00
|
|
|
//===-- sanitizer_stackdepot.h ----------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is shared between AddressSanitizer and ThreadSanitizer
|
|
|
|
// run-time libraries.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SANITIZER_STACKDEPOT_H
|
|
|
|
#define SANITIZER_STACKDEPOT_H
|
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
#include "sanitizer_common.h"
|
2013-02-13 11:46:01 +01:00
|
|
|
#include "sanitizer_internal_defs.h"
|
2014-11-13 21:41:38 +01:00
|
|
|
#include "sanitizer_stacktrace.h"
|
2012-11-12 16:53:47 +01:00
|
|
|
|
|
|
|
namespace __sanitizer {
|
|
|
|
|
|
|
|
// StackDepot efficiently stores huge amounts of stack traces.
|
2014-09-23 19:59:53 +02:00
|
|
|
struct StackDepotNode;
|
|
|
|
struct StackDepotHandle {
|
|
|
|
StackDepotNode *node_;
|
|
|
|
StackDepotHandle() : node_(0) {}
|
|
|
|
explicit StackDepotHandle(StackDepotNode *node) : node_(node) {}
|
|
|
|
bool valid() { return node_; }
|
|
|
|
u32 id();
|
|
|
|
int use_count();
|
|
|
|
void inc_use_count_unsafe();
|
|
|
|
};
|
|
|
|
|
|
|
|
const int kStackDepotMaxUseCount = 1U << 20;
|
2012-11-12 16:53:47 +01:00
|
|
|
|
2014-09-23 19:59:53 +02:00
|
|
|
StackDepotStats *StackDepotGetStats();
|
2014-11-13 21:41:38 +01:00
|
|
|
u32 StackDepotPut(StackTrace stack);
|
|
|
|
StackDepotHandle StackDepotPut_WithHandle(StackTrace stack);
|
2012-11-12 16:53:47 +01:00
|
|
|
// Retrieves a stored stack trace by the id.
|
2014-11-13 21:41:38 +01:00
|
|
|
StackTrace StackDepotGet(u32 id);
|
2012-11-12 16:53:47 +01:00
|
|
|
|
2014-09-23 19:59:53 +02:00
|
|
|
void StackDepotLockAll();
|
|
|
|
void StackDepotUnlockAll();
|
2013-11-04 22:33:31 +01:00
|
|
|
|
|
|
|
// Instantiating this class creates a snapshot of StackDepot which can be
|
|
|
|
// efficiently queried with StackDepotGet(). You can use it concurrently with
|
|
|
|
// StackDepot, but the snapshot is only guaranteed to contain those stack traces
|
|
|
|
// which were stored before it was instantiated.
|
|
|
|
class StackDepotReverseMap {
|
|
|
|
public:
|
|
|
|
StackDepotReverseMap();
|
2014-11-13 21:41:38 +01:00
|
|
|
StackTrace Get(u32 id);
|
2013-11-04 22:33:31 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct IdDescPair {
|
|
|
|
u32 id;
|
2014-09-23 19:59:53 +02:00
|
|
|
StackDepotNode *desc;
|
2013-11-04 22:33:31 +01:00
|
|
|
|
|
|
|
static bool IdComparator(const IdDescPair &a, const IdDescPair &b);
|
|
|
|
};
|
|
|
|
|
|
|
|
InternalMmapVector<IdDescPair> map_;
|
|
|
|
|
|
|
|
// Disallow evil constructors.
|
|
|
|
StackDepotReverseMap(const StackDepotReverseMap&);
|
|
|
|
void operator=(const StackDepotReverseMap&);
|
|
|
|
};
|
2014-09-23 19:59:53 +02:00
|
|
|
|
2012-11-12 16:53:47 +01:00
|
|
|
} // namespace __sanitizer
|
|
|
|
|
|
|
|
#endif // SANITIZER_STACKDEPOT_H
|