[msan] Add source file:line to stack origin reports.

Runtime library part.

llvm-svn: 190686
This commit is contained in:
Evgeniy Stepanov 2013-09-13 12:49:13 +00:00
parent eb03a37cfa
commit ac5ac34cf7
4 changed files with 29 additions and 7 deletions

View File

@ -114,6 +114,7 @@ int msan_report_count = 0;
// FIXME: make it resizable.
static const uptr kNumStackOriginDescrs = 1024 * 1024;
static const char *StackOriginDescr[kNumStackOriginDescrs];
static uptr StackOriginPC[kNumStackOriginDescrs];
static atomic_uint32_t NumStackOriginDescrs;
static void ParseFlagsFromString(Flags *f, const char *str) {
@ -256,6 +257,14 @@ void ScopedThreadLocalStateBackup::Restore() {
void UnpoisonThreadLocalState() {
}
const char *GetOriginDescrIfStack(u32 id, uptr *pc) {
if ((id >> 31) == 0) return 0;
id &= (1U << 31) - 1;
CHECK_LT(id, kNumStackOriginDescrs);
if (pc) *pc = StackOriginPC[id];
return StackOriginDescr[id];
}
} // namespace __msan
// Interface.
@ -466,6 +475,10 @@ void __msan_set_origin(const void *a, uptr size, u32 origin) {
// When we see descr for the first time we replace '----' with a uniq id
// and set the origin to (id | (31-th bit)).
void __msan_set_alloca_origin(void *a, uptr size, const char *descr) {
__msan_set_alloca_origin4(a, size, descr, 0);
}
void __msan_set_alloca_origin4(void *a, uptr size, const char *descr, uptr pc) {
static const u32 dash = '-';
static const u32 first_timer =
dash + (dash << 8) + (dash << 16) + (dash << 24);
@ -478,8 +491,9 @@ void __msan_set_alloca_origin(void *a, uptr size, const char *descr) {
*id_ptr = id;
CHECK_LT(id, kNumStackOriginDescrs);
StackOriginDescr[id] = descr + 4;
StackOriginPC[id] = pc;
if (print)
Printf("First time: id=%d %s \n", id, descr + 4);
Printf("First time: id=%d %s %p \n", id, descr + 4, pc);
}
id |= 1U << 31;
if (print)
@ -488,13 +502,9 @@ void __msan_set_alloca_origin(void *a, uptr size, const char *descr) {
}
const char *__msan_get_origin_descr_if_stack(u32 id) {
if ((id >> 31) == 0) return 0;
id &= (1U << 31) - 1;
CHECK_LT(id, kNumStackOriginDescrs);
return StackOriginDescr[id];
return GetOriginDescrIfStack(id, 0);
}
u32 __msan_get_origin(const void *a) {
if (!__msan_get_track_origins()) return 0;
uptr x = (uptr)a;

View File

@ -51,6 +51,8 @@ void InstallTrapHandler();
void InstallAtExitHandler();
void ReplaceOperatorsNewAndDelete();
const char *GetOriginDescrIfStack(u32 id, uptr *pc);
void EnterSymbolizer();
void ExitSymbolizer();
bool IsInSymbolizer();

View File

@ -73,6 +73,8 @@ void __msan_set_origin(const void *a, uptr size, u32 origin);
SANITIZER_INTERFACE_ATTRIBUTE
void __msan_set_alloca_origin(void *a, uptr size, const char *descr);
SANITIZER_INTERFACE_ATTRIBUTE
void __msan_set_alloca_origin4(void *a, uptr size, const char *descr, uptr pc);
SANITIZER_INTERFACE_ATTRIBUTE
u32 __msan_get_origin(const void *a);
SANITIZER_INTERFACE_ATTRIBUTE

View File

@ -44,7 +44,8 @@ static void DescribeOrigin(u32 origin) {
Decorator d;
if (flags()->verbosity)
Printf(" raw origin id: %d\n", origin);
if (const char *so = __msan_get_origin_descr_if_stack(origin)) {
uptr pc;
if (const char *so = GetOriginDescrIfStack(origin, &pc)) {
char* s = internal_strdup(so);
char* sep = internal_strchr(s, '@');
CHECK(sep);
@ -55,6 +56,13 @@ static void DescribeOrigin(u32 origin) {
d.Origin(), d.Name(), s, d.Origin(), d.Name(),
getSymbolizer()->Demangle(sep + 1), d.Origin(), d.End());
InternalFree(s);
if (pc) {
// For some reason function address in LLVM IR is 1 less then the address
// of the first instruction.
pc += 1;
PrintStack(&pc, 1);
}
} else {
uptr size = 0;
const uptr *trace = StackDepotGet(origin, &size);