<div dir="ltr">Hi Alexey,<br><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature">On Fri, Feb 6, 2015 at 1:17 PM, Alexey Samsonov <span dir="ltr"><<a href="mailto:vonosmas@gmail.com" target="_blank">vonosmas@gmail.com</a>></span> wrote:<br></div></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Filipe,<div><br></div><div>First of all, did you notice it by code inspection, or actually observed noticable memory leak in your program?</div></div></blockquote><div>It was reported to us after we shipped UBSan for testing. Programs just crash.</div><div>This makes sense if you take into account that you might have errors in each frame of a game, which runs at 60fps. Memory usage grows rapidly :-)</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>I remember this problem, and it wasn't fixed until now, because this memory leak happens during error reporting, and can only be noticed if your program has a significant<br></div><div>number of different UBSan error reports. That said, we should of course fix it :)</div></div></blockquote><div>That was the idea I had after seeing the code :-)</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>I don't really understand your suggestion, though. Location destructor already calls destructor for MemoryLocation. The problem is ModuleLocation::ModuleName (and, similar SourceLocation::Filename):<br></div></div></blockquote><div>Yes. The “clear the objects” would be the freeing of whatever we could, which is what's missing (ModuleName and Filename).</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div></div><div>they can point to either constant string literals, or global data, or dynamically allocated strings (e.g. via internal_strdup). We should only call InternalFree() on these string buffers in the latter case.</div></div></blockquote><div>Ah, I forgot about the string literal case.</div><div>I wonder if it's more worth it to make the SourceLocation (and friends) class manage their strings a bit better, or if it would be worth it to have the StackFrames objects not fully free each of the module's names (We're leaking because we generate a FallbackLoc with the module name).</div><div><br></div><div>Any clues on where it would be better to start? You know much more about what you need for location info outside of ubsan.</div><div><br></div><div>Thank you,</div><div><br></div><div> Filipe</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><span style="color:rgb(80,0,80)">On Thu, Feb 5, 2015 at 7:02 PM, Filipe Cabecinhas </span><span dir="ltr" style="color:rgb(80,0,80)"><<a href="mailto:filcab@gmail.com" target="_blank">filcab@gmail.com</a>></span><span style="color:rgb(80,0,80)"> wrote:</span><br></div><div><div><div class="gmail_extra"><div><div class="h5"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Alexey!<div><br></div><div>This still has a memory leak: (ubsan_diag.cc)</div><span><div><span style="font-size:12.8000001907349px">+ if (!Info.file) {</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">+ ModuleLocation MLoc(internal_strdup(Info.</span><span style="font-size:12.8000001907349px">module), Info.module_offset);</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">+ Frames->ClearAll();</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">+ return MLoc;</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">+ }</span><br></div></span><div><span style="font-size:12.8000001907349px">^^ You're doing an strdup, but later the ModuleLocation only gets used to feed a Location, which is only used when Diag calls renderLocation. After that, it gets leaked away.</span></div><div><br></div><div>One could fix this by making SourceLoc, ModuleLoc, and MemoryLoc, inside class Location (ubsan_diag.h) pointers, and clear the objects in the Location destructor.</div><div>If you're ok with this let me know and I can submit the patch, otherwise, can you fix it?</div><div>(I'm not sure about the uses in tsan and other sanitizers, so I don't know if they also leak)</div><div><br></div><div>Thanks,</div><div><div class="gmail_extra"><br clear="all"><div><div> Filipe<br></div></div><div><div>
<br><div class="gmail_quote">On Tue, Dec 2, 2014 at 11:48 AM, Alexey Samsonov <span dir="ltr"><<a>vonosmas@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: samsonov<br>
Date: Tue Dec 2 13:48:40 2014<br>
New Revision: 223145<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=223145&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=223145&view=rev</a><br>
Log:<br>
Simplify Symbolizer::SymbolizePC() interface.<br>
<br>
Return a linked list of AddressInfo objects, instead of using an array of<br>
these objects as an output parameter. This simplifies the code in callers<br>
of this function (especially TSan).<br>
<br>
Fix a few memory leaks from internal allocator, when the returned<br>
AddressInfo objects were not properly cleared.<br>
<br>
Modified:<br>
compiler-rt/trunk/lib/lsan/lsan_common.cc<br>
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc<br>
compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc<br>
compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc<br>
compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h<br>
compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_libbacktrace.cc<br>
compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_libbacktrace.h<br>
compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc<br>
compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_win.cc<br>
compiler-rt/trunk/lib/tsan/go/buildgo.sh<br>
compiler-rt/trunk/lib/tsan/go/tsan_go.cc<br>
compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc<br>
compiler-rt/trunk/lib/tsan/rtl/tsan_report.h<br>
compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h<br>
compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc<br>
compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc<br>
compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize.cc<br>
compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize.h<br>
compiler-rt/trunk/lib/ubsan/ubsan_diag.cc<br>
<br>
Modified: compiler-rt/trunk/lib/lsan/lsan_common.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_common.cc?rev=223145&r1=223144&r2=223145&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_common.cc?rev=223145&r1=223144&r2=223145&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/lsan/lsan_common.cc (original)<br>
+++ compiler-rt/trunk/lib/lsan/lsan_common.cc Tue Dec 2 13:48:40 2014<br>
@@ -457,30 +457,27 @@ void DoLeakCheck() {<br>
}<br>
<br>
static Suppression *GetSuppressionForAddr(uptr addr) {<br>
- Suppression *s;<br>
+ Suppression *s = nullptr;<br>
<br>
// Suppress by module name.<br>
const char *module_name;<br>
uptr module_offset;<br>
- if (Symbolizer::GetOrInit()<br>
- ->GetModuleNameAndOffsetForPC(addr, &module_name, &module_offset) &&<br>
+ if (Symbolizer::GetOrInit()->GetModuleNameAndOffsetForPC(addr, &module_name,<br>
+ &module_offset) &&<br>
SuppressionContext::Get()->Match(module_name, SuppressionLeak, &s))<br>
return s;<br>
<br>
// Suppress by file or function name.<br>
- static const uptr kMaxAddrFrames = 16;<br>
- InternalScopedBuffer<AddressInfo> addr_frames(kMaxAddrFrames);<br>
- for (uptr i = 0; i < kMaxAddrFrames; i++) new (&addr_frames[i]) AddressInfo();<br>
- uptr addr_frames_num = Symbolizer::GetOrInit()->SymbolizePC(<br>
- addr, addr_frames.data(), kMaxAddrFrames);<br>
- for (uptr i = 0; i < addr_frames_num; i++) {<br>
- if (SuppressionContext::Get()->Match(addr_frames[i].function,<br>
- SuppressionLeak, &s) ||<br>
- SuppressionContext::Get()->Match(addr_frames[i].file, SuppressionLeak,<br>
- &s))<br>
- return s;<br>
+ SymbolizedStack *frames = Symbolizer::GetOrInit()->SymbolizePC(addr);<br>
+ for (SymbolizedStack *cur = frames; cur; cur = cur->next) {<br>
+ if (SuppressionContext::Get()->Match(cur->info.function, SuppressionLeak,<br>
+ &s) ||<br>
+ SuppressionContext::Get()->Match(cur->info.file, SuppressionLeak, &s)) {<br>
+ break;<br>
+ }<br>
}<br>
- return 0;<br>
+ frames->ClearAll();<br>
+ return s;<br>
}<br>
<br>
static Suppression *GetSuppressionForStack(u32 stack_trace_id) {<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc?rev=223145&r1=223144&r2=223145&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc?rev=223145&r1=223144&r2=223145&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc Tue Dec 2 13:48:40 2014<br>
@@ -52,16 +52,20 @@ void SetSandboxingCallback(void (*f)())<br>
void ReportErrorSummary(const char *error_type, StackTrace *stack) {<br>
if (!common_flags()->print_summary)<br>
return;<br>
- AddressInfo ai;<br>
#if !SANITIZER_GO<br>
if (stack->size > 0 && Symbolizer::GetOrInit()->CanReturnFileLineInfo()) {<br>
// Currently, we include the first stack frame into the report summary.<br>
// Maybe sometimes we need to choose another frame (e.g. skip memcpy/etc).<br>
uptr pc = StackTrace::GetPreviousInstructionPc(stack->trace[0]);<br>
- Symbolizer::GetOrInit()->SymbolizePC(pc, &ai, 1);<br>
+ SymbolizedStack *frame = Symbolizer::GetOrInit()->SymbolizePC(pc);<br>
+ const AddressInfo &ai = frame->info;<br>
+ ReportErrorSummary(error_type, ai.file, ai.line, ai.function);<br>
+ frame->ClearAll();<br>
}<br>
-#endif<br>
+#else<br>
+ AddressInfo ai;<br>
ReportErrorSummary(error_type, ai.file, ai.line, ai.function);<br>
+#endif<br>
}<br>
<br>
} // namespace __sanitizer<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc?rev=223145&r1=223144&r2=223145&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc?rev=223145&r1=223144&r2=223145&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc Tue Dec 2 13:48:40 2014<br>
@@ -24,30 +24,21 @@ void StackTrace::Print() const {<br>
Printf(" <empty stack>\n\n");<br>
return;<br>
}<br>
- const int kMaxAddrFrames = 64;<br>
- InternalScopedBuffer<AddressInfo> addr_frames(kMaxAddrFrames);<br>
- for (uptr i = 0; i < kMaxAddrFrames; i++)<br>
- new(&addr_frames[i]) AddressInfo();<br>
InternalScopedString frame_desc(GetPageSizeCached() * 2);<br>
uptr frame_num = 0;<br>
for (uptr i = 0; i < size && trace[i]; i++) {<br>
// PCs in stack traces are actually the return addresses, that is,<br>
// addresses of the next instructions after the call.<br>
uptr pc = GetPreviousInstructionPc(trace[i]);<br>
- uptr addr_frames_num = Symbolizer::GetOrInit()->SymbolizePC(<br>
- pc, addr_frames.data(), kMaxAddrFrames);<br>
- if (addr_frames_num == 0) {<br>
- addr_frames[0].address = pc;<br>
- addr_frames_num = 1;<br>
- }<br>
- for (uptr j = 0; j < addr_frames_num; j++) {<br>
- AddressInfo &info = addr_frames[j];<br>
+ SymbolizedStack *frames = Symbolizer::GetOrInit()->SymbolizePC(pc);<br>
+ CHECK(frames);<br>
+ for (SymbolizedStack *cur = frames; cur; cur = cur->next) {<br>
frame_desc.clear();<br>
RenderFrame(&frame_desc, common_flags()->stack_trace_format, frame_num++,<br>
- info, common_flags()->strip_path_prefix);<br>
+ cur->info, common_flags()->strip_path_prefix);<br>
Printf("%s\n", frame_desc.data());<br>
- info.Clear();<br>
}<br>
+ frames->ClearAll();<br>
}<br>
// Always print a trailing empty line after stack trace.<br>
Printf("\n");<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc?rev=223145&r1=223144&r2=223145&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc?rev=223145&r1=223144&r2=223145&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc Tue Dec 2 13:48:40 2014<br>
@@ -11,13 +11,61 @@<br>
// run-time libraries.<br>
//===----------------------------------------------------------------------===//<br>
<br>
+#include "sanitizer_allocator_internal.h"<br>
#include "sanitizer_platform.h"<br>
#include "sanitizer_internal_defs.h"<br>
+#include "sanitizer_libc.h"<br>
#include "sanitizer_placement_new.h"<br>
#include "sanitizer_symbolizer.h"<br>
<br>
namespace __sanitizer {<br>
<br>
+AddressInfo::AddressInfo() {<br>
+ internal_memset(this, 0, sizeof(AddressInfo));<br>
+ function_offset = kUnknown;<br>
+}<br>
+<br>
+void AddressInfo::Clear() {<br>
+ InternalFree(module);<br>
+ InternalFree(function);<br>
+ InternalFree(file);<br>
+ internal_memset(this, 0, sizeof(AddressInfo));<br>
+ function_offset = kUnknown;<br>
+}<br>
+<br>
+void AddressInfo::FillAddressAndModuleInfo(uptr addr, const char *mod_name,<br>
+ uptr mod_offset) {<br>
+ address = addr;<br>
+ module = internal_strdup(mod_name);<br>
+ module_offset = mod_offset;<br>
+}<br>
+<br>
+SymbolizedStack::SymbolizedStack() : next(nullptr), info() {}<br>
+<br>
+SymbolizedStack *SymbolizedStack::New(uptr addr) {<br>
+ void *mem = InternalAlloc(sizeof(SymbolizedStack));<br>
+ SymbolizedStack *res = new(mem) SymbolizedStack();<br>
+ res->info.address = addr;<br>
+ return res;<br>
+}<br>
+<br>
+void SymbolizedStack::ClearAll() {<br>
+ info.Clear();<br>
+ if (next)<br>
+ next->ClearAll();<br>
+ InternalFree(this);<br>
+}<br>
+<br>
+DataInfo::DataInfo() {<br>
+ internal_memset(this, 0, sizeof(DataInfo));<br>
+}<br>
+<br>
+void DataInfo::Clear() {<br>
+ InternalFree(module);<br>
+ InternalFree(name);<br>
+ internal_memset(this, 0, sizeof(DataInfo));<br>
+}<br>
+<br>
Symbolizer *Symbolizer::symbolizer_;<br>
StaticSpinMutex Symbolizer::init_mu_;<br>
LowLevelAllocator Symbolizer::symbolizer_allocator_;<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h?rev=223145&r1=223144&r2=223145&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h?rev=223145&r1=223144&r2=223145&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h Tue Dec 2 13:48:40 2014<br>
@@ -19,13 +19,14 @@<br>
#ifndef SANITIZER_SYMBOLIZER_H<br>
#define SANITIZER_SYMBOLIZER_H<br>
<br>
-#include "sanitizer_allocator_internal.h"<br>
-#include "sanitizer_internal_defs.h"<br>
-#include "sanitizer_libc.h"<br>
+#include "sanitizer_common.h"<br>
+#include "sanitizer_mutex.h"<br>
<br>
namespace __sanitizer {<br>
<br>
struct AddressInfo {<br>
+ // Owns all the string members. Storage for them is<br>
+ // (de)allocated using sanitizer internal allocator.<br>
uptr address;<br>
<br>
char *module;<br>
@@ -39,45 +40,38 @@ struct AddressInfo {<br>
int line;<br>
int column;<br>
<br>
- AddressInfo() {<br>
- internal_memset(this, 0, sizeof(AddressInfo));<br>
- function_offset = kUnknown;<br>
- }<br>
-<br>
+ AddressInfo();<br>
// Deletes all strings and resets all fields.<br>
- void Clear() {<br>
- InternalFree(module);<br>
- InternalFree(function);<br>
- InternalFree(file);<br>
- internal_memset(this, 0, sizeof(AddressInfo));<br>
- function_offset = kUnknown;<br>
- }<br>
-<br>
+ void Clear();<br>
void FillAddressAndModuleInfo(uptr addr, const char *mod_name,<br>
- uptr mod_offset) {<br>
- address = addr;<br>
- module = internal_strdup(mod_name);<br>
- module_offset = mod_offset;<br>
- }<br>
+ uptr mod_offset);<br>
+};<br>
+<br>
+// Linked list of symbolized frames (each frame is described by AddressInfo).<br>
+struct SymbolizedStack {<br>
+ SymbolizedStack *next;<br>
+ AddressInfo info;<br>
+ static SymbolizedStack *New(uptr addr);<br>
+ // Deletes current, and all subsequent frames in the linked list.<br>
+ // The object cannot be accessed after the call to this function.<br>
+ void ClearAll();<br>
+<br>
+ private:<br>
+ SymbolizedStack();<br>
};<br>
<br>
// For now, DataInfo is used to describe global variable.<br>
struct DataInfo {<br>
+ // Owns all the string members. Storage for them is<br>
+ // (de)allocated using sanitizer internal allocator.<br>
char *module;<br>
uptr module_offset;<br>
char *name;<br>
uptr start;<br>
uptr size;<br>
<br>
- DataInfo() {<br>
- internal_memset(this, 0, sizeof(DataInfo));<br>
- }<br>
-<br>
- void Clear() {<br>
- InternalFree(module);<br>
- InternalFree(name);<br>
- internal_memset(this, 0, sizeof(DataInfo));<br>
- }<br>
+ DataInfo();<br>
+ void Clear();<br>
};<br>
<br>
class Symbolizer {<br>
@@ -85,11 +79,10 @@ class Symbolizer {<br>
/// Initialize and return platform-specific implementation of symbolizer<br>
/// (if it wasn't already initialized).<br>
static Symbolizer *GetOrInit();<br>
- // Fills at most "max_frames" elements of "frames" with descriptions<br>
- // for a given address (in all inlined functions). Returns the number<br>
- // of descriptions actually filled.<br>
- virtual uptr SymbolizePC(uptr address, AddressInfo *frames, uptr max_frames) {<br>
- return 0;<br>
+ // Returns a list of symbolized frames for a given address (containing<br>
+ // all inlined functions, if necessary).<br>
+ virtual SymbolizedStack *SymbolizePC(uptr address) {<br>
+ return SymbolizedStack::New(address);<br>
}<br>
virtual bool SymbolizeData(uptr address, DataInfo *info) {<br>
return false;<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_libbacktrace.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_libbacktrace.cc?rev=223145&r1=223144&r2=223145&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_libbacktrace.cc?rev=223145&r1=223144&r2=223145&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_libbacktrace.cc (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_libbacktrace.cc Tue Dec 2 13:48:40 2014<br>
@@ -83,44 +83,52 @@ char *CplusV3Demangle(const char *name)<br>
}<br>
# endif // SANITIZER_CP_DEMANGLE<br>
<br>
-struct SymbolizeCodeData {<br>
- AddressInfo *frames;<br>
- uptr n_frames;<br>
- uptr max_frames;<br>
+struct SymbolizeCodeCallbackArg {<br>
+ SymbolizedStack *first;<br>
+ SymbolizedStack *last;<br>
const char *module_name;<br>
uptr module_offset;<br>
+<br>
+ void append(SymbolizedStack *f) {<br>
+ if (last != nullptr) {<br>
+ last->next = f;<br>
+ last = f;<br>
+ } else {<br>
+ first = f;<br>
+ last = f;<br>
+ }<br>
+ }<br>
};<br>
<br>
extern "C" {<br>
static int SymbolizeCodePCInfoCallback(void *vdata, uintptr_t addr,<br>
const char *filename, int lineno,<br>
const char *function) {<br>
- SymbolizeCodeData *cdata = (SymbolizeCodeData *)vdata;<br>
+ SymbolizeCodeCallbackArg *cdata = (SymbolizeCodeCallbackArg *)vdata;<br>
if (function) {<br>
- AddressInfo *info = &cdata->frames[cdata->n_frames++];<br>
- info->Clear();<br>
+ SymbolizedStack *cur = SymbolizedStack::New(addr);<br>
+ cdata->append(cur);<br>
+ AddressInfo *info = &cur->info;<br>
info->FillAddressAndModuleInfo(addr, cdata->module_name,<br>
cdata->module_offset);<br>
info->function = LibbacktraceSymbolizer::Demangle(function, true);<br>
if (filename)<br>
info->file = internal_strdup(filename);<br>
info->line = lineno;<br>
- if (cdata->n_frames == cdata->max_frames)<br>
- return 1;<br>
}<br>
return 0;<br>
}<br>
<br>
static void SymbolizeCodeCallback(void *vdata, uintptr_t addr,<br>
const char *symname, uintptr_t, uintptr_t) {<br>
- SymbolizeCodeData *cdata = (SymbolizeCodeData *)vdata;<br>
+ SymbolizeCodeCallbackArg *cdata = (SymbolizeCodeCallbackArg *)vdata;<br>
if (symname) {<br>
- AddressInfo *info = &cdata->frames[0];<br>
- info->Clear();<br>
+ SymbolizedStack *cur = SymbolizedStack::New(addr);<br>
+ cdata->append(cur);<br>
+ AddressInfo *info = &cur->info;<br>
info->FillAddressAndModuleInfo(addr, cdata->module_name,<br>
cdata->module_offset);<br>
info->function = LibbacktraceSymbolizer::Demangle(symname, true);<br>
- cdata->n_frames = 1;<br>
}<br>
}<br>
<br>
@@ -148,23 +156,21 @@ LibbacktraceSymbolizer *LibbacktraceSymb<br>
return new(*alloc) LibbacktraceSymbolizer(state);<br>
}<br>
<br>
-uptr LibbacktraceSymbolizer::SymbolizeCode(uptr addr, AddressInfo *frames,<br>
- uptr max_frames,<br>
- const char *module_name,<br>
- uptr module_offset) {<br>
- SymbolizeCodeData data;<br>
- data.frames = frames;<br>
- data.n_frames = 0;<br>
- data.max_frames = max_frames;<br>
+SymbolizedStack *LibbacktraceSymbolizer::SymbolizeCode(uptr addr,<br>
+ const char *module_name,<br>
+ uptr module_offset) {<br>
+ SymbolizeCodeCallbackArg data;<br>
+ data.first = nullptr;<br>
+ data.last = nullptr;<br>
data.module_name = module_name;<br>
data.module_offset = module_offset;<br>
backtrace_pcinfo((backtrace_state *)state_, addr, SymbolizeCodePCInfoCallback,<br>
ErrorCallback, &data);<br>
- if (data.n_frames)<br>
- return data.n_frames;<br>
+ if (data.first)<br>
+ return data.first;<br>
backtrace_syminfo((backtrace_state *)state_, addr, SymbolizeCodeCallback,<br>
ErrorCallback, &data);<br>
- return data.n_frames;<br>
+ return data.first;<br>
}<br>
<br>
bool LibbacktraceSymbolizer::SymbolizeData(DataInfo *info) {<br>
@@ -179,12 +185,11 @@ LibbacktraceSymbolizer *LibbacktraceSymb<br>
return 0;<br>
}<br>
<br>
-uptr LibbacktraceSymbolizer::SymbolizeCode(uptr addr, AddressInfo *frames,<br>
- uptr max_frames,<br>
- const char *module_name,<br>
- uptr module_offset) {<br>
+SymbolizedStack *LibbacktraceSymbolizer::SymbolizeCode(uptr addr,<br>
+ const char *module_name,<br>
+ uptr module_offset) {<br>
(void)state_;<br>
- return 0;<br>
+ return nullptr;<br>
}<br>
<br>
bool LibbacktraceSymbolizer::SymbolizeData(DataInfo *info) {<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_libbacktrace.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_libbacktrace.h?rev=223145&r1=223144&r2=223145&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_libbacktrace.h?rev=223145&r1=223144&r2=223145&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_libbacktrace.h (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_libbacktrace.h Tue Dec 2 13:48:40 2014<br>
@@ -32,8 +32,8 @@ class LibbacktraceSymbolizer {<br>
public:<br>
static LibbacktraceSymbolizer *get(LowLevelAllocator *alloc);<br>
<br>
- uptr SymbolizeCode(uptr addr, AddressInfo *frames, uptr max_frames,<br>
- const char *module_name, uptr module_offset);<br>
+ SymbolizedStack *SymbolizeCode(uptr addr, const char *module_name,<br>
+ uptr module_offset);<br>
<br>
bool SymbolizeData(DataInfo *info);<br>
<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc?rev=223145&r1=223144&r2=223145&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc?rev=223145&r1=223144&r2=223145&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc Tue Dec 2 13:48:40 2014<br>
@@ -514,34 +514,32 @@ class POSIXSymbolizer : public Symbolize<br>
internal_symbolizer_(internal_symbolizer),<br>
libbacktrace_symbolizer_(libbacktrace_symbolizer) {}<br>
<br>
- uptr SymbolizePC(uptr addr, AddressInfo *frames, uptr max_frames) override {<br>
+ SymbolizedStack *SymbolizePC(uptr addr) override {<br>
BlockingMutexLock l(&mu_);<br>
- if (max_frames == 0)<br>
- return 0;<br>
const char *module_name;<br>
uptr module_offset;<br>
if (!FindModuleNameAndOffsetForAddress(addr, &module_name, &module_offset))<br>
- return 0;<br>
+ return SymbolizedStack::New(addr);<br>
// First, try to use libbacktrace symbolizer (if it's available).<br>
if (libbacktrace_symbolizer_ != 0) {<br>
mu_.CheckLocked();<br>
- uptr res = libbacktrace_symbolizer_->SymbolizeCode(<br>
- addr, frames, max_frames, module_name, module_offset);<br>
- if (res > 0)<br>
+ if (SymbolizedStack *res = libbacktrace_symbolizer_->SymbolizeCode(<br>
+ addr, module_name, module_offset))<br>
return res;<br>
}<br>
+ // Always fill data about module name and offset.<br>
+ SymbolizedStack *res = SymbolizedStack::New(addr);<br>
+ res->info.FillAddressAndModuleInfo(addr, module_name, module_offset);<br>
+<br>
const char *str = SendCommand(false, module_name, module_offset);<br>
if (str == 0) {<br>
- // Symbolizer was not initialized or failed. Fill only data<br>
- // about module name and offset.<br>
- AddressInfo *info = &frames[0];<br>
- info->Clear();<br>
- info->FillAddressAndModuleInfo(addr, module_name, module_offset);<br>
- return 1;<br>
+ // Symbolizer was not initialized or failed.<br>
+ return res;<br>
}<br>
- uptr frame_id = 0;<br>
- for (frame_id = 0; frame_id < max_frames; frame_id++) {<br>
- AddressInfo *info = &frames[frame_id];<br>
+<br>
+ bool top_frame = true;<br>
+ SymbolizedStack *last = res;<br>
+ while (true) {<br>
char *function_name = 0;<br>
str = ExtractToken(str, "\n", &function_name);<br>
CHECK(function_name);<br>
@@ -549,8 +547,18 @@ class POSIXSymbolizer : public Symbolize<br>
// There are no more frames.<br>
break;<br>
}<br>
- info->Clear();<br>
- info->FillAddressAndModuleInfo(addr, module_name, module_offset);<br>
+ SymbolizedStack *cur;<br>
+ if (top_frame) {<br>
+ cur = res;<br>
+ top_frame = false;<br>
+ } else {<br>
+ cur = SymbolizedStack::New(addr);<br>
+ cur->info.FillAddressAndModuleInfo(addr, module_name, module_offset);<br>
+ last->next = cur;<br>
+ last = cur;<br>
+ }<br>
+<br>
+ AddressInfo *info = &cur->info;<br>
info->function = function_name;<br>
// Parse <file>:<line>:<column> buffer.<br>
char *file_line_info = 0;<br>
@@ -572,14 +580,7 @@ class POSIXSymbolizer : public Symbolize<br>
info->file = 0;<br>
}<br>
}<br>
- if (frame_id == 0) {<br>
- // Make sure we return at least one frame.<br>
- AddressInfo *info = &frames[0];<br>
- info->Clear();<br>
- info->FillAddressAndModuleInfo(addr, module_name, module_offset);<br>
- frame_id = 1;<br>
- }<br>
- return frame_id;<br>
+ return res;<br>
}<br>
<br>
bool SymbolizeData(uptr addr, DataInfo *info) override {<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_win.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_win.cc?rev=223145&r1=223144&r2=223145&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_win.cc?rev=223145&r1=223144&r2=223145&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_win.cc (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_win.cc Tue Dec 2 13:48:40 2014<br>
@@ -26,9 +26,8 @@ class WinSymbolizer : public Symbolizer<br>
public:<br>
WinSymbolizer() : initialized_(false) {}<br>
<br>
- uptr SymbolizePC(uptr addr, AddressInfo *frames, uptr max_frames) override {<br>
- if (max_frames == 0)<br>
- return 0;<br>
+ SymbolizedStack *SymbolizePC(uptr addr) override {<br>
+ SymbolizedStack *frame = SymbolizedStack::New(addr);<br>
<br>
BlockingMutexLock l(&dbghelp_mu_);<br>
if (!initialized_) {<br>
@@ -60,29 +59,27 @@ class WinSymbolizer : public Symbolizer<br>
BOOL got_objname = SymFromAddr(GetCurrentProcess(),<br>
(DWORD64)addr, &offset, symbol);<br>
if (!got_objname)<br>
- return 0;<br>
+ return frame;<br>
<br>
DWORD unused;<br>
IMAGEHLP_LINE64 line_info;<br>
line_info.SizeOfStruct = sizeof(IMAGEHLP_LINE64);<br>
BOOL got_fileline = SymGetLineFromAddr64(GetCurrentProcess(), (DWORD64)addr,<br>
&unused, &line_info);<br>
- AddressInfo *info = &frames[0];<br>
- info->Clear();<br>
- info->function = internal_strdup(symbol->Name);<br>
- info->function_offset = (uptr)offset;<br>
+ frame->info.function = internal_strdup(symbol->Name);<br>
+ frame->info.function_offset = (uptr)offset;<br>
if (got_fileline) {<br>
- info->file = internal_strdup(line_info.FileName);<br>
- info->line = line_info.LineNumber;<br>
+ frame->info.file = internal_strdup(line_info.FileName);<br>
+ frame->info.line = line_info.LineNumber;<br>
}<br>
<br>
IMAGEHLP_MODULE64 mod_info;<br>
internal_memset(&mod_info, 0, sizeof(mod_info));<br>
mod_info.SizeOfStruct = sizeof(mod_info);<br>
if (SymGetModuleInfo64(GetCurrentProcess(), addr, &mod_info))<br>
- info->FillAddressAndModuleInfo(addr, mod_info.ImageName,<br>
- addr - (uptr)mod_info.BaseOfImage);<br>
- return 1;<br>
+ frame->info.FillAddressAndModuleInfo(addr, mod_info.ImageName,<br>
+ addr - (uptr)mod_info.BaseOfImage);<br>
+ return frame;<br>
}<br>
<br>
bool CanReturnFileLineInfo() override {<br>
<br>
Modified: compiler-rt/trunk/lib/tsan/go/buildgo.sh<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/go/buildgo.sh?rev=223145&r1=223144&r2=223145&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/go/buildgo.sh?rev=223145&r1=223144&r2=223145&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/tsan/go/buildgo.sh (original)<br>
+++ compiler-rt/trunk/lib/tsan/go/buildgo.sh Tue Dec 2 13:48:40 2014<br>
@@ -27,6 +27,7 @@ SRCS="<br>
../../sanitizer_common/sanitizer_thread_registry.cc<br>
../../sanitizer_common/sanitizer_stackdepot.cc<br>
../../sanitizer_common/sanitizer_stacktrace.cc<br>
+ ../../sanitizer_common/sanitizer_symbolizer.cc<br>
"<br>
<br>
if [ "`uname -a | grep Linux`" != "" ]; then<br>
<br>
Modified: compiler-rt/trunk/lib/tsan/go/tsan_go.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/go/tsan_go.cc?rev=223145&r1=223144&r2=223145&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/go/tsan_go.cc?rev=223145&r1=223144&r2=223145&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/tsan/go/tsan_go.cc (original)<br>
+++ compiler-rt/trunk/lib/tsan/go/tsan_go.cc Tue Dec 2 13:48:40 2014<br>
@@ -59,18 +59,19 @@ struct SymbolizeContext {<br>
// Callback into Go.<br>
static void (*symbolize_cb)(SymbolizeContext *ctx);<br>
<br>
-ReportStack *SymbolizeCode(uptr addr) {<br>
- ReportStack *s = ReportStack::New(addr);<br>
+SymbolizedStack *SymbolizeCode(uptr addr) {<br>
+ SymbolizedStack *s = SymbolizedStack::New(addr);<br>
SymbolizeContext ctx;<br>
internal_memset(&ctx, 0, sizeof(ctx));<br>
ctx.pc = addr;<br>
symbolize_cb(&ctx);<br>
if (ctx.res) {<br>
- s->info.module_offset = ctx.off;<br>
- s->info.function = internal_strdup(ctx.func ? ctx.func : "??");<br>
- s->info.file = internal_strdup(ctx.file ? ctx.file : "-");<br>
- s->info.line = ctx.line;<br>
- s->info.column = 0;<br>
+ AddressInfo &info = s->info;<br>
+ info.module_offset = ctx.off;<br>
+ info.function = internal_strdup(ctx.func ? ctx.func : "??");<br>
+ info.file = internal_strdup(ctx.file ? ctx.file : "-");<br>
+ info.line = ctx.line;<br>
+ info.column = 0;<br>
}<br>
return s;<br>
}<br>
<br>
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc?rev=223145&r1=223144&r2=223145&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc?rev=223145&r1=223144&r2=223145&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc (original)<br>
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc Tue Dec 2 13:48:40 2014<br>
@@ -19,13 +19,11 @@<br>
<br>
namespace __tsan {<br>
<br>
-ReportStack::ReportStack() : next(nullptr), info(), suppressable(false) {}<br>
+ReportStack::ReportStack() : frames(nullptr), suppressable(false) {}<br>
<br>
-ReportStack *ReportStack::New(uptr addr) {<br>
+ReportStack *ReportStack::New() {<br>
void *mem = internal_alloc(MBlockReportStack, sizeof(ReportStack));<br>
- ReportStack *res = new(mem) ReportStack();<br>
- res->info.address = addr;<br>
- return res;<br>
+ return new(mem) ReportStack();<br>
}<br>
<br>
ReportLocation::ReportLocation(ReportLocationType type)<br>
@@ -114,13 +112,14 @@ static const char *ReportTypeString(Repo<br>
}<br>
<br>
void PrintStack(const ReportStack *ent) {<br>
- if (ent == 0) {<br>
+ if (ent == 0 || ent->frames == 0) {<br>
Printf(" [failed to restore the stack]\n\n");<br>
return;<br>
}<br>
- for (int i = 0; ent && ent->info.address; ent = ent->next, i++) {<br>
+ SymbolizedStack *frame = ent->frames;<br>
+ for (int i = 0; frame && frame->info.address; frame = frame->next, i++) {<br>
InternalScopedString res(2 * GetPageSizeCached());<br>
- RenderFrame(&res, common_flags()->stack_trace_format, i, ent->info,<br>
+ RenderFrame(&res, common_flags()->stack_trace_format, i, frame->info,<br>
common_flags()->strip_path_prefix, "__interceptor_");<br>
Printf("%s\n", res.data());<br>
}<br>
@@ -252,10 +251,20 @@ static ReportStack *ChooseSummaryStack(c<br>
return 0;<br>
}<br>
<br>
-ReportStack *SkipTsanInternalFrames(ReportStack *ent) {<br>
- while (FrameIsInternal(ent) && ent->next)<br>
- ent = ent->next;<br>
- return ent;<br>
+static bool FrameIsInternal(const SymbolizedStack *frame) {<br>
+ if (frame == 0)<br>
+ return false;<br>
+ const char *file = frame->info.file;<br>
+ return file != 0 &&<br>
+ (internal_strstr(file, "tsan_interceptors.cc") ||<br>
+ internal_strstr(file, "sanitizer_common_interceptors.inc") ||<br>
+ internal_strstr(file, "tsan_interface_"));<br>
+}<br>
+<br>
+static SymbolizedStack *SkipTsanInternalFrames(SymbolizedStack *frames) {<br>
+ while (FrameIsInternal(frames) && frames->next)<br>
+ frames = frames->next;<br>
+ return frames;<br>
}<br>
<br>
void PrintReport(const ReportDesc *rep) {<br>
@@ -325,9 +334,11 @@ void PrintReport(const ReportDesc *rep)<br>
if (rep->typ == ReportTypeThreadLeak && rep->count > 1)<br>
Printf(" And %d more similar thread leaks.\n\n", rep->count - 1);<br>
<br>
- if (ReportStack *ent = SkipTsanInternalFrames(ChooseSummaryStack(rep))) {<br>
- const AddressInfo &info = ent->info;<br>
- ReportErrorSummary(rep_typ_str, info.file, info.line, info.function);<br>
+ if (ReportStack *stack = ChooseSummaryStack(rep)) {<br>
+ if (SymbolizedStack *frame = SkipTsanInternalFrames(stack->frames)) {<br>
+ const AddressInfo &info = frame->info;<br>
+ ReportErrorSummary(rep_typ_str, info.file, info.line, info.function);<br>
+ }<br>
}<br>
<br>
Printf("==================\n");<br>
@@ -338,12 +349,13 @@ void PrintReport(const ReportDesc *rep)<br>
const int kMainThreadId = 1;<br>
<br>
void PrintStack(const ReportStack *ent) {<br>
- if (ent == 0) {<br>
+ if (ent == 0 || ent->frames == 0) {<br>
Printf(" [failed to restore the stack]\n");<br>
return;<br>
}<br>
- for (int i = 0; ent; ent = ent->next, i++) {<br>
- const AddressInfo &info = ent->info;<br>
+ SymbolizedStack *frame = ent->frames;<br>
+ for (int i = 0; frame; frame = frame->next, i++) {<br>
+ const AddressInfo &info = frame->info;<br>
Printf(" %s()\n %s:%d +0x%zx\n", info.function, info.file, info.line,<br>
(void *)info.module_offset);<br>
}<br>
<br>
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_report.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_report.h?rev=223145&r1=223144&r2=223145&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_report.h?rev=223145&r1=223144&r2=223145&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/tsan/rtl/tsan_report.h (original)<br>
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_report.h Tue Dec 2 13:48:40 2014<br>
@@ -36,10 +36,9 @@ enum ReportType {<br>
};<br>
<br>
struct ReportStack {<br>
- ReportStack *next;<br>
- AddressInfo info;<br>
+ SymbolizedStack *frames;<br>
bool suppressable;<br>
- static ReportStack *New(uptr addr);<br>
+ static ReportStack *New();<br>
<br>
private:<br>
ReportStack();<br>
<br>
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h?rev=223145&r1=223144&r2=223145&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h?rev=223145&r1=223144&r2=223145&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h (original)<br>
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h Tue Dec 2 13:48:40 2014<br>
@@ -568,8 +568,6 @@ bool IsFiredSuppression(Context *ctx, co<br>
StackTrace trace);<br>
bool IsExpectedReport(uptr addr, uptr size);<br>
void PrintMatchedBenignRaces();<br>
-bool FrameIsInternal(const ReportStack *frame);<br>
-ReportStack *SkipTsanInternalFrames(ReportStack *ent);<br>
<br>
#if defined(TSAN_DEBUG_OUTPUT) && TSAN_DEBUG_OUTPUT >= 1<br>
# define DPrintf Printf<br>
<br>
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc?rev=223145&r1=223144&r2=223145&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc?rev=223145&r1=223144&r2=223145&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc (original)<br>
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc Tue Dec 2 13:48:40 2014<br>
@@ -56,40 +56,43 @@ bool WEAK OnReport(const ReportDesc *rep<br>
}<br>
#endif<br>
<br>
-static void StackStripMain(ReportStack *stack) {<br>
- ReportStack *last_frame = 0;<br>
- ReportStack *last_frame2 = 0;<br>
- for (ReportStack *ent = stack; ent; ent = ent->next) {<br>
+static void StackStripMain(SymbolizedStack *frames) {<br>
+ SymbolizedStack *last_frame = nullptr;<br>
+ SymbolizedStack *last_frame2 = nullptr;<br>
+ for (SymbolizedStack *cur = frames; cur; cur = cur->next) {<br>
last_frame2 = last_frame;<br>
- last_frame = ent;<br>
+ last_frame = cur;<br>
}<br>
<br>
if (last_frame2 == 0)<br>
return;<br>
- const char *last = last_frame->info.function;<br>
#ifndef TSAN_GO<br>
+ const char *last = last_frame->info.function;<br>
const char *last2 = last_frame2->info.function;<br>
// Strip frame above 'main'<br>
if (last2 && 0 == internal_strcmp(last2, "main")) {<br>
- last_frame2->next = 0;<br>
+ last_frame->ClearAll();<br>
+ last_frame2->next = nullptr;<br>
// Strip our internal thread start routine.<br>
} else if (last && 0 == internal_strcmp(last, "__tsan_thread_start_func")) {<br>
- last_frame2->next = 0;<br>
+ last_frame->ClearAll();<br>
+ last_frame2->next = nullptr;<br>
// Strip global ctors init.<br>
} else if (last && 0 == internal_strcmp(last, "__do_global_ctors_aux")) {<br>
- last_frame2->next = 0;<br>
+ last_frame->ClearAll();<br>
+ last_frame2->next = nullptr;<br>
// If both are 0, then we probably just failed to symbolize.<br>
} else if (last || last2) {<br>
// Ensure that we recovered stack completely. Trimmed stack<br>
// can actually happen if we do not instrument some code,<br>
// so it's only a debug print. However we must try hard to not miss it<br>
// due to our fault.<br>
- DPrintf("Bottom stack frame of stack %zx is missed\n", stack->pc);<br>
+ DPrintf("Bottom stack frame of stack %zx is missed\n", stack->info.address);<br>
}<br>
#else<br>
// The last frame always point into runtime (gosched0, goexit0, runtime.main).<br>
- last_frame2->next = 0;<br>
- (void)last;<br>
+ last_frame->ClearAll();<br>
+ last_frame2->next = nullptr;<br>
#endif<br>
}<br>
<br>
@@ -105,12 +108,12 @@ ReportStack *SymbolizeStackId(u32 stack_<br>
static ReportStack *SymbolizeStack(StackTrace trace) {<br>
if (trace.size == 0)<br>
return 0;<br>
- ReportStack *stack = 0;<br>
+ SymbolizedStack *top = nullptr;<br>
for (uptr si = 0; si < trace.size; si++) {<br>
const uptr pc = trace.trace[si];<br>
#ifndef TSAN_GO<br>
- // We obtain the return address, that is, address of the next instruction,<br>
- // so offset it by 1 byte.<br>
+ // We obtain the return address, but we're interested in the previous<br>
+ // instruction.<br>
const uptr pc1 = StackTrace::GetPreviousInstructionPc(pc);<br>
#else<br>
// FIXME(dvyukov): Go sometimes uses address of a function as top pc.<br>
@@ -118,18 +121,21 @@ static ReportStack *SymbolizeStack(Stack<br>
if (si != trace.size - 1)<br>
pc1 -= 1;<br>
#endif<br>
- ReportStack *ent = SymbolizeCode(pc1);<br>
+ SymbolizedStack *ent = SymbolizeCode(pc1);<br>
CHECK_NE(ent, 0);<br>
- ReportStack *last = ent;<br>
+ SymbolizedStack *last = ent;<br>
while (last->next) {<br>
last->info.address = pc; // restore original pc for report<br>
last = last->next;<br>
}<br>
last->info.address = pc; // restore original pc for report<br>
- last->next = stack;<br>
- stack = ent;<br>
+ last->next = top;<br>
+ top = ent;<br>
}<br>
- StackStripMain(stack);<br>
+ StackStripMain(top);<br>
+<br>
+ ReportStack *stack = ReportStack::New();<br>
+ stack->frames = top;<br>
return stack;<br>
}<br>
<br>
@@ -547,16 +553,6 @@ static bool IsFiredSuppression(Context *<br>
return false;<br>
}<br>
<br>
-bool FrameIsInternal(const ReportStack *frame) {<br>
- if (frame == 0)<br>
- return false;<br>
- const char *file = frame->info.file;<br>
- return file != 0 &&<br>
- (internal_strstr(file, "tsan_interceptors.cc") ||<br>
- internal_strstr(file, "sanitizer_common_interceptors.inc") ||<br>
- internal_strstr(file, "tsan_interface_"));<br>
-}<br>
-<br>
static bool RaceBetweenAtomicAndFree(ThreadState *thr) {<br>
Shadow s0(thr->racy_state[0]);<br>
Shadow s1(thr->racy_state[1]);<br>
<br>
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc?rev=223145&r1=223144&r2=223145&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc?rev=223145&r1=223144&r2=223145&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc (original)<br>
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc Tue Dec 2 13:48:40 2014<br>
@@ -92,7 +92,8 @@ uptr IsSuppressed(ReportType typ, const<br>
if (stype == SuppressionNone)<br>
return 0;<br>
Suppression *s;<br>
- for (const ReportStack *frame = stack; frame; frame = frame->next) {<br>
+ for (const SymbolizedStack *frame = stack->frames; frame;<br>
+ frame = frame->next) {<br>
const AddressInfo &info = frame->info;<br>
if (SuppressionContext::Get()->Match(info.function, stype, &s) ||<br>
SuppressionContext::Get()->Match(info.file, stype, &s) ||<br>
<br>
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize.cc?rev=223145&r1=223144&r2=223145&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize.cc?rev=223145&r1=223144&r2=223145&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize.cc (original)<br>
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize.cc Tue Dec 2 13:48:40 2014<br>
@@ -55,7 +55,7 @@ bool __tsan_symbolize_external(uptr pc,<br>
return false;<br>
}<br>
<br>
-ReportStack *SymbolizeCode(uptr addr) {<br>
+SymbolizedStack *SymbolizeCode(uptr addr) {<br>
// Check if PC comes from non-native land.<br>
if (addr & kExternalPCBit) {<br>
// Declare static to not consume too much stack space.<br>
@@ -63,36 +63,17 @@ ReportStack *SymbolizeCode(uptr addr) {<br>
static char func_buf[1024];<br>
static char file_buf[1024];<br>
int line, col;<br>
- ReportStack *ent = ReportStack::New(addr);<br>
- if (!__tsan_symbolize_external(addr, func_buf, sizeof(func_buf),<br>
- file_buf, sizeof(file_buf), &line, &col))<br>
- return ent;<br>
- ent->info.function = internal_strdup(func_buf);<br>
- ent->info.file = internal_strdup(file_buf);<br>
- ent->info.line = line;<br>
- ent->info.column = col;<br>
- return ent;<br>
+ SymbolizedStack *frame = SymbolizedStack::New(addr);<br>
+ if (__tsan_symbolize_external(addr, func_buf, sizeof(func_buf), file_buf,<br>
+ sizeof(file_buf), &line, &col)) {<br>
+ frame->info.function = internal_strdup(func_buf);<br>
+ frame->info.file = internal_strdup(file_buf);<br>
+ frame->info.line = line;<br>
+ frame->info.column = col;<br>
+ }<br>
+ return frame;<br>
}<br>
- static const uptr kMaxAddrFrames = 16;<br>
- InternalScopedBuffer<AddressInfo> addr_frames(kMaxAddrFrames);<br>
- for (uptr i = 0; i < kMaxAddrFrames; i++)<br>
- new(&addr_frames[i]) AddressInfo();<br>
- uptr addr_frames_num = Symbolizer::GetOrInit()->SymbolizePC(<br>
- addr, addr_frames.data(), kMaxAddrFrames);<br>
- if (addr_frames_num == 0)<br>
- return ReportStack::New(addr);<br>
- ReportStack *top = 0;<br>
- ReportStack *bottom = 0;<br>
- for (uptr i = 0; i < addr_frames_num; i++) {<br>
- ReportStack *cur_entry = ReportStack::New(addr);<br>
- cur_entry->info = addr_frames[i];<br>
- if (i == 0)<br>
- top = cur_entry;<br>
- else<br>
- bottom->next = cur_entry;<br>
- bottom = cur_entry;<br>
- }<br>
- return top;<br>
+ return Symbolizer::GetOrInit()->SymbolizePC(addr);<br>
}<br>
<br>
ReportLocation *SymbolizeData(uptr addr) {<br>
<br>
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize.h?rev=223145&r1=223144&r2=223145&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize.h?rev=223145&r1=223144&r2=223145&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize.h (original)<br>
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize.h Tue Dec 2 13:48:40 2014<br>
@@ -20,7 +20,7 @@ namespace __tsan {<br>
<br>
void EnterSymbolizer();<br>
void ExitSymbolizer();<br>
-ReportStack *SymbolizeCode(uptr addr);<br>
+SymbolizedStack *SymbolizeCode(uptr addr);<br>
ReportLocation *SymbolizeData(uptr addr);<br>
void SymbolizeFlush();<br>
<br>
<br>
Modified: compiler-rt/trunk/lib/ubsan/ubsan_diag.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_diag.cc?rev=223145&r1=223144&r2=223145&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_diag.cc?rev=223145&r1=223144&r2=223145&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/ubsan/ubsan_diag.cc (original)<br>
+++ compiler-rt/trunk/lib/ubsan/ubsan_diag.cc Tue Dec 2 13:48:40 2014<br>
@@ -79,18 +79,26 @@ Location __ubsan::getFunctionLocation(up<br>
return Location();<br>
InitIfNecessary();<br>
<br>
- AddressInfo Info;<br>
- if (!Symbolizer::GetOrInit()->SymbolizePC(Loc, &Info, 1) || !Info.module ||<br>
- !*Info.module)<br>
+ SymbolizedStack *Frames = Symbolizer::GetOrInit()->SymbolizePC(Loc);<br>
+ const AddressInfo &Info = Frames->info;<br>
+<br>
+ if (!Info.module) {<br>
+ Frames->ClearAll();<br>
return Location(Loc);<br>
+ }<br>
<br>
if (FName && Info.function)<br>
- *FName = Info.function;<br>
+ *FName = internal_strdup(Info.function);<br>
<br>
- if (!Info.file)<br>
- return ModuleLocation(Info.module, Info.module_offset);<br>
+ if (!Info.file) {<br>
+ ModuleLocation MLoc(internal_strdup(Info.module), Info.module_offset);<br>
+ Frames->ClearAll();<br>
+ return MLoc;<br>
+ }<br>
<br>
- return SourceLocation(Info.file, Info.line, Info.column);<br>
+ SourceLocation SLoc(internal_strdup(Info.file), Info.line, Info.column);<br>
+ Frames->ClearAll();<br>
+ return SLoc;<br>
}<br>
<br>
Diag &Diag::operator<<(const TypeDescriptor &V) {<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a>llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div></div></div></div><span><font color="#888888">
<br><br>-- <br> F<br><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br><div><div dir="ltr">Alexey Samsonov<br><a href="mailto:vonosmas@gmail.com" target="_blank">vonosmas@gmail.com</a></div></div>
</font></span></div></div></div></div>
</blockquote></div><br></div></div>