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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Symbolizer is intended to be used by both
|
|
|
|
// AddressSanitizer and ThreadSanitizer to symbolize a given
|
|
|
|
// address. It is an analogue of addr2line utility and allows to map
|
|
|
|
// instruction address to a location in source code at run-time.
|
|
|
|
//
|
|
|
|
// Symbolizer is planned to use debug information (in DWARF format)
|
|
|
|
// in a binary via interface defined in "llvm/DebugInfo/DIContext.h"
|
|
|
|
//
|
|
|
|
// Symbolizer code should be called from the run-time library of
|
|
|
|
// dynamic tools, and generally should not call memory allocation
|
|
|
|
// routines or other system library functions intercepted by those tools.
|
|
|
|
// Instead, Symbolizer code should use their replacements, defined in
|
|
|
|
// "compiler-rt/lib/sanitizer_common/sanitizer_libc.h".
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SANITIZER_SYMBOLIZER_H
|
|
|
|
#define SANITIZER_SYMBOLIZER_H
|
|
|
|
|
2012-06-05 22:25:27 +08:00
|
|
|
#include "sanitizer_internal_defs.h"
|
2012-06-01 14:11:13 +08:00
|
|
|
#include "sanitizer_libc.h"
|
|
|
|
// WARNING: Do not include system headers here. See details above.
|
|
|
|
|
|
|
|
namespace __sanitizer {
|
|
|
|
|
|
|
|
struct AddressInfo {
|
|
|
|
uptr address;
|
|
|
|
char *module;
|
|
|
|
uptr module_offset;
|
|
|
|
char *function;
|
|
|
|
char *file;
|
|
|
|
int line;
|
|
|
|
int column;
|
|
|
|
|
2012-06-15 22:00:25 +08:00
|
|
|
AddressInfo() {
|
|
|
|
internal_memset(this, 0, sizeof(AddressInfo));
|
|
|
|
}
|
|
|
|
// Deletes all strings and sets all fields to zero.
|
2012-06-01 14:11:13 +08:00
|
|
|
void Clear();
|
2012-09-04 23:34:43 +08:00
|
|
|
|
|
|
|
void FillAddressAndModuleInfo(uptr addr, const char *mod_name,
|
|
|
|
uptr mod_offset) {
|
|
|
|
address = addr;
|
|
|
|
module = internal_strdup(mod_name);
|
|
|
|
module_offset = mod_offset;
|
|
|
|
}
|
2012-06-01 14:11:13 +08:00
|
|
|
};
|
|
|
|
|
2012-06-15 22:00:25 +08:00
|
|
|
// Fills at most "max_frames" elements of "frames" with descriptions
|
|
|
|
// for a given address (in all inlined functions). Returns the number
|
|
|
|
// of descriptions actually filled.
|
|
|
|
// This function should NOT be called from two threads simultaneously.
|
|
|
|
uptr SymbolizeCode(uptr address, AddressInfo *frames, uptr max_frames);
|
2012-12-03 19:45:34 +08:00
|
|
|
bool SymbolizeData(uptr address, AddressInfo *frame);
|
2012-06-01 14:11:13 +08:00
|
|
|
|
2012-08-23 15:32:06 +08:00
|
|
|
// Starts external symbolizer program in a subprocess. Sanitizer communicates
|
|
|
|
// with external symbolizer via pipes.
|
|
|
|
bool InitializeExternalSymbolizer(const char *path_to_symbolizer);
|
2012-07-31 19:51:26 +08:00
|
|
|
|
2012-08-23 15:32:06 +08:00
|
|
|
class LoadedModule {
|
2012-07-03 16:24:14 +08:00
|
|
|
public:
|
2012-08-23 15:32:06 +08:00
|
|
|
LoadedModule(const char *module_name, uptr base_address);
|
2012-07-03 16:24:14 +08:00
|
|
|
void addAddressRange(uptr beg, uptr end);
|
|
|
|
bool containsAddress(uptr address) const;
|
|
|
|
|
|
|
|
const char *full_name() const { return full_name_; }
|
2012-08-23 15:32:06 +08:00
|
|
|
uptr base_address() const { return base_address_; }
|
2012-07-03 16:24:14 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct AddressRange {
|
|
|
|
uptr beg;
|
|
|
|
uptr end;
|
|
|
|
};
|
|
|
|
char *full_name_;
|
|
|
|
uptr base_address_;
|
2012-10-17 21:12:23 +08:00
|
|
|
static const uptr kMaxNumberOfAddressRanges = 6;
|
2012-07-03 16:24:14 +08:00
|
|
|
AddressRange ranges_[kMaxNumberOfAddressRanges];
|
|
|
|
uptr n_ranges_;
|
|
|
|
};
|
|
|
|
|
2012-08-23 15:32:06 +08:00
|
|
|
// Creates external symbolizer connected via pipe, user should write
|
|
|
|
// to output_fd and read from input_fd.
|
|
|
|
bool StartSymbolizerSubprocess(const char *path_to_symbolizer,
|
|
|
|
int *input_fd, int *output_fd);
|
|
|
|
|
|
|
|
// OS-dependent function that fills array with descriptions of at most
|
|
|
|
// "max_modules" currently loaded modules. Returns the number of
|
|
|
|
// initialized modules.
|
|
|
|
uptr GetListOfModules(LoadedModule *modules, uptr max_modules);
|
2012-07-03 16:24:14 +08:00
|
|
|
|
2012-06-01 14:11:13 +08:00
|
|
|
} // namespace __sanitizer
|
|
|
|
|
|
|
|
#endif // SANITIZER_SYMBOLIZER_H
|