2012-06-04 17:33:06 +08:00
|
|
|
//===-- sanitizer_symbolizer.h ----------------------------------*- C++ -*-===//
|
2012-06-01 14:11:13 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2013-10-31 01:17:35 +08:00
|
|
|
// Symbolizer is used by sanitizers to map instruction address to a location in
|
|
|
|
// source code at run-time. Symbolizer either uses __sanitizer_symbolize_*
|
|
|
|
// defined in the program, or (if they are missing) tries to find and
|
|
|
|
// launch "llvm-symbolizer" commandline tool in a separate process and
|
|
|
|
// communicate with it.
|
2012-06-01 14:11:13 +08:00
|
|
|
//
|
2013-10-31 01:17:35 +08:00
|
|
|
// Generally we should try to avoid calling system library functions during
|
|
|
|
// symbolization (and use their replacements from sanitizer_libc.h instead).
|
2012-06-01 14:11:13 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SANITIZER_SYMBOLIZER_H
|
|
|
|
#define SANITIZER_SYMBOLIZER_H
|
|
|
|
|
2014-12-03 03:48:40 +08:00
|
|
|
#include "sanitizer_common.h"
|
|
|
|
#include "sanitizer_mutex.h"
|
2012-06-01 14:11:13 +08:00
|
|
|
|
|
|
|
namespace __sanitizer {
|
|
|
|
|
|
|
|
struct AddressInfo {
|
2014-12-03 03:48:40 +08:00
|
|
|
// Owns all the string members. Storage for them is
|
|
|
|
// (de)allocated using sanitizer internal allocator.
|
2012-06-01 14:11:13 +08:00
|
|
|
uptr address;
|
2013-12-18 22:29:16 +08:00
|
|
|
|
2012-06-01 14:11:13 +08:00
|
|
|
char *module;
|
|
|
|
uptr module_offset;
|
2013-12-18 22:29:16 +08:00
|
|
|
|
|
|
|
static const uptr kUnknown = ~(uptr)0;
|
2012-06-01 14:11:13 +08:00
|
|
|
char *function;
|
2013-12-18 22:29:16 +08:00
|
|
|
uptr function_offset;
|
|
|
|
|
2012-06-01 14:11:13 +08:00
|
|
|
char *file;
|
|
|
|
int line;
|
|
|
|
int column;
|
|
|
|
|
2014-12-03 03:48:40 +08:00
|
|
|
AddressInfo();
|
2013-12-18 22:29:16 +08:00
|
|
|
// Deletes all strings and resets all fields.
|
2014-12-03 03:48:40 +08:00
|
|
|
void Clear();
|
2015-03-03 17:18:44 +08:00
|
|
|
void FillModuleInfo(const char *mod_name, uptr mod_offset);
|
2014-12-03 03:48:40 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Linked list of symbolized frames (each frame is described by AddressInfo).
|
|
|
|
struct SymbolizedStack {
|
|
|
|
SymbolizedStack *next;
|
|
|
|
AddressInfo info;
|
|
|
|
static SymbolizedStack *New(uptr addr);
|
|
|
|
// Deletes current, and all subsequent frames in the linked list.
|
|
|
|
// The object cannot be accessed after the call to this function.
|
|
|
|
void ClearAll();
|
|
|
|
|
|
|
|
private:
|
|
|
|
SymbolizedStack();
|
2012-06-01 14:11:13 +08:00
|
|
|
};
|
|
|
|
|
2014-11-05 05:26:56 +08:00
|
|
|
// For now, DataInfo is used to describe global variable.
|
2013-01-11 15:23:51 +08:00
|
|
|
struct DataInfo {
|
2014-12-03 03:48:40 +08:00
|
|
|
// Owns all the string members. Storage for them is
|
|
|
|
// (de)allocated using sanitizer internal allocator.
|
2013-01-11 15:23:51 +08:00
|
|
|
char *module;
|
|
|
|
uptr module_offset;
|
|
|
|
char *name;
|
|
|
|
uptr start;
|
|
|
|
uptr size;
|
2014-11-05 05:26:56 +08:00
|
|
|
|
2014-12-03 03:48:40 +08:00
|
|
|
DataInfo();
|
|
|
|
void Clear();
|
2013-01-11 15:23:51 +08:00
|
|
|
};
|
|
|
|
|
2013-10-26 07:03:29 +08:00
|
|
|
class Symbolizer {
|
2012-07-03 16:24:14 +08:00
|
|
|
public:
|
2014-07-26 09:37:23 +08:00
|
|
|
/// Initialize and return platform-specific implementation of symbolizer
|
|
|
|
/// (if it wasn't already initialized).
|
2013-10-26 07:03:29 +08:00
|
|
|
static Symbolizer *GetOrInit();
|
2014-12-03 03:48:40 +08:00
|
|
|
// Returns a list of symbolized frames for a given address (containing
|
|
|
|
// all inlined functions, if necessary).
|
|
|
|
virtual SymbolizedStack *SymbolizePC(uptr address) {
|
|
|
|
return SymbolizedStack::New(address);
|
2013-09-10 22:36:16 +08:00
|
|
|
}
|
|
|
|
virtual bool SymbolizeData(uptr address, DataInfo *info) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-26 04:15:46 +08:00
|
|
|
virtual bool GetModuleNameAndOffsetForPC(uptr pc, const char **module_name,
|
|
|
|
uptr *module_address) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-25 15:09:44 +08:00
|
|
|
virtual bool CanReturnFileLineInfo() {
|
2013-10-26 07:03:29 +08:00
|
|
|
return false;
|
|
|
|
}
|
2013-09-10 22:36:16 +08:00
|
|
|
// Release internal caches (if any).
|
|
|
|
virtual void Flush() {}
|
|
|
|
// Attempts to demangle the provided C++ mangled name.
|
|
|
|
virtual const char *Demangle(const char *name) {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
virtual void PrepareForSandboxing() {}
|
2012-07-03 16:24:14 +08:00
|
|
|
|
2013-11-01 05:44:07 +08:00
|
|
|
// Allow user to install hooks that would be called before/after Symbolizer
|
|
|
|
// does the actual file/line info fetching. Specific sanitizers may need this
|
|
|
|
// to distinguish system library calls made in user code from calls made
|
|
|
|
// during in-process symbolization.
|
|
|
|
typedef void (*StartSymbolizationHook)();
|
|
|
|
typedef void (*EndSymbolizationHook)();
|
|
|
|
// May be called at most once.
|
|
|
|
void AddHooks(StartSymbolizationHook start_hook,
|
|
|
|
EndSymbolizationHook end_hook);
|
|
|
|
|
2013-10-26 07:03:29 +08:00
|
|
|
private:
|
|
|
|
/// Platform-specific function for creating a Symbolizer object.
|
2014-07-26 09:37:23 +08:00
|
|
|
static Symbolizer *PlatformInit();
|
2013-12-17 19:15:39 +08:00
|
|
|
/// Initialize the symbolizer in a disabled state. Not thread safe.
|
|
|
|
static Symbolizer *Disable();
|
2013-10-26 07:03:29 +08:00
|
|
|
|
2013-10-31 01:05:37 +08:00
|
|
|
static Symbolizer *symbolizer_;
|
|
|
|
static StaticSpinMutex init_mu_;
|
2013-10-26 07:03:29 +08:00
|
|
|
|
|
|
|
protected:
|
2013-11-01 05:44:07 +08:00
|
|
|
Symbolizer();
|
|
|
|
|
2013-10-26 07:03:29 +08:00
|
|
|
static LowLevelAllocator symbolizer_allocator_;
|
2013-11-01 05:44:07 +08:00
|
|
|
|
|
|
|
StartSymbolizationHook start_hook_;
|
|
|
|
EndSymbolizationHook end_hook_;
|
|
|
|
class SymbolizerScope {
|
|
|
|
public:
|
|
|
|
explicit SymbolizerScope(const Symbolizer *sym);
|
|
|
|
~SymbolizerScope();
|
|
|
|
private:
|
|
|
|
const Symbolizer *sym_;
|
|
|
|
};
|
2013-10-26 07:03:29 +08:00
|
|
|
};
|
2013-05-23 19:53:36 +08:00
|
|
|
|
2012-06-01 14:11:13 +08:00
|
|
|
} // namespace __sanitizer
|
|
|
|
|
|
|
|
#endif // SANITIZER_SYMBOLIZER_H
|