2012-08-30 18:02:48 +08:00
|
|
|
//===-- sanitizer_stackdepot.h ----------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2015-09-30 02:23:36 +08:00
|
|
|
|
2012-08-30 18:02:48 +08:00
|
|
|
#ifndef SANITIZER_STACKDEPOT_H
|
|
|
|
#define SANITIZER_STACKDEPOT_H
|
|
|
|
|
2013-08-26 21:24:43 +08:00
|
|
|
#include "sanitizer_common.h"
|
2013-01-30 21:12:08 +08:00
|
|
|
#include "sanitizer_internal_defs.h"
|
2014-10-26 11:35:14 +08:00
|
|
|
#include "sanitizer_stacktrace.h"
|
2012-08-30 18:02:48 +08:00
|
|
|
|
|
|
|
namespace __sanitizer {
|
|
|
|
|
|
|
|
// StackDepot efficiently stores huge amounts of stack traces.
|
2014-05-21 17:02:13 +08:00
|
|
|
struct StackDepotNode;
|
|
|
|
struct StackDepotHandle {
|
|
|
|
StackDepotNode *node_;
|
2015-09-30 02:23:36 +08:00
|
|
|
StackDepotHandle() : node_(nullptr) {}
|
2014-05-21 17:02:13 +08:00
|
|
|
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-08-30 18:02:48 +08:00
|
|
|
|
2014-05-21 17:02:13 +08:00
|
|
|
StackDepotStats *StackDepotGetStats();
|
2014-10-26 14:23:07 +08:00
|
|
|
u32 StackDepotPut(StackTrace stack);
|
|
|
|
StackDepotHandle StackDepotPut_WithHandle(StackTrace stack);
|
2012-08-30 18:02:48 +08:00
|
|
|
// Retrieves a stored stack trace by the id.
|
2014-10-26 11:35:14 +08:00
|
|
|
StackTrace StackDepotGet(u32 id);
|
2012-08-30 18:02:48 +08:00
|
|
|
|
2014-09-04 18:36:14 +08:00
|
|
|
void StackDepotLockAll();
|
|
|
|
void StackDepotUnlockAll();
|
|
|
|
|
2013-08-26 21:24:43 +08: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-10-26 14:23:07 +08:00
|
|
|
StackTrace Get(u32 id);
|
2013-08-26 21:24:43 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct IdDescPair {
|
2013-08-28 19:26:09 +08:00
|
|
|
u32 id;
|
2014-05-21 17:02:13 +08:00
|
|
|
StackDepotNode *desc;
|
2013-08-26 21:24:43 +08:00
|
|
|
|
2013-08-28 19:26:09 +08:00
|
|
|
static bool IdComparator(const IdDescPair &a, const IdDescPair &b);
|
2013-08-26 21:24:43 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
InternalMmapVector<IdDescPair> map_;
|
|
|
|
|
|
|
|
// Disallow evil constructors.
|
|
|
|
StackDepotReverseMap(const StackDepotReverseMap&);
|
|
|
|
void operator=(const StackDepotReverseMap&);
|
|
|
|
};
|
2014-05-21 17:02:13 +08:00
|
|
|
|
2015-09-30 02:23:36 +08:00
|
|
|
} // namespace __sanitizer
|
2012-08-30 18:02:48 +08:00
|
|
|
|
2015-09-30 02:23:36 +08:00
|
|
|
#endif // SANITIZER_STACKDEPOT_H
|