[compiler-rt] r190686 - [msan] Add source file:line to stack origin reports.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Fri Sep 13 05:49:14 PDT 2013


Author: eugenis
Date: Fri Sep 13 07:49:13 2013
New Revision: 190686

URL: http://llvm.org/viewvc/llvm-project?rev=190686&view=rev
Log:
[msan] Add source file:line to stack origin reports.

Runtime library part.

Modified:
    compiler-rt/trunk/lib/msan/msan.cc
    compiler-rt/trunk/lib/msan/msan.h
    compiler-rt/trunk/lib/msan/msan_interface_internal.h
    compiler-rt/trunk/lib/msan/msan_report.cc

Modified: compiler-rt/trunk/lib/msan/msan.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan.cc?rev=190686&r1=190685&r2=190686&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan.cc (original)
+++ compiler-rt/trunk/lib/msan/msan.cc Fri Sep 13 07:49:13 2013
@@ -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::Resto
 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, up
 // 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, u
     *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, u
 }
 
 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;

Modified: compiler-rt/trunk/lib/msan/msan.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan.h?rev=190686&r1=190685&r2=190686&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan.h (original)
+++ compiler-rt/trunk/lib/msan/msan.h Fri Sep 13 07:49:13 2013
@@ -51,6 +51,8 @@ void InstallTrapHandler();
 void InstallAtExitHandler();
 void ReplaceOperatorsNewAndDelete();
 
+const char *GetOriginDescrIfStack(u32 id, uptr *pc);
+
 void EnterSymbolizer();
 void ExitSymbolizer();
 bool IsInSymbolizer();

Modified: compiler-rt/trunk/lib/msan/msan_interface_internal.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interface_internal.h?rev=190686&r1=190685&r2=190686&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interface_internal.h (original)
+++ compiler-rt/trunk/lib/msan/msan_interface_internal.h Fri Sep 13 07:49:13 2013
@@ -73,6 +73,8 @@ void __msan_set_origin(const void *a, up
 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

Modified: compiler-rt/trunk/lib/msan/msan_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_report.cc?rev=190686&r1=190685&r2=190686&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_report.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_report.cc Fri Sep 13 07:49:13 2013
@@ -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);





More information about the llvm-commits mailing list