Skip to content

Commit 2652243

Browse files
authored
[NFC][tsan] Move SkipInternalFrames into sanitizer_common (#77146)
1 parent 4df5662 commit 2652243

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct AddressInfo;
3232
struct BufferedStackTrace;
3333
struct SignalContext;
3434
struct StackTrace;
35+
struct SymbolizedStack;
3536

3637
// Constants.
3738
const uptr kWordSize = SANITIZER_WORDSIZE / 8;
@@ -393,6 +394,8 @@ void ReportErrorSummary(const char *error_type, const AddressInfo &info,
393394
// Same as above, but obtains AddressInfo by symbolizing top stack trace frame.
394395
void ReportErrorSummary(const char *error_type, const StackTrace *trace,
395396
const char *alt_tool_name = nullptr);
397+
// Skips frames which we consider internal and not usefull to the users.
398+
SymbolizedStack *SkipInternalFrames(SymbolizedStack *frames);
396399

397400
void ReportMmapWriteExec(int prot, int mflags);
398401

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,26 @@
2828
namespace __sanitizer {
2929

3030
#if !SANITIZER_GO
31+
32+
static bool FrameIsInternal(const SymbolizedStack *frame) {
33+
if (!frame)
34+
return true;
35+
const char *file = frame->info.file;
36+
const char *module = frame->info.module;
37+
if (file && (internal_strstr(file, "/compiler-rt/lib/")))
38+
return true;
39+
if (module && (internal_strstr(module, "libclang_rt.")))
40+
return true;
41+
return false;
42+
}
43+
44+
SymbolizedStack *SkipInternalFrames(SymbolizedStack *frames) {
45+
for (SymbolizedStack *f = frames; f; f = f->next)
46+
if (!FrameIsInternal(f))
47+
return f;
48+
return nullptr;
49+
}
50+
3151
void ReportErrorSummary(const char *error_type, const AddressInfo &info,
3252
const char *alt_tool_name) {
3353
if (!common_flags()->print_summary) return;

compiler-rt/lib/tsan/rtl/tsan_report.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -273,22 +273,9 @@ static ReportStack *ChooseSummaryStack(const ReportDesc *rep) {
273273
return 0;
274274
}
275275

276-
static bool FrameIsInternal(const SymbolizedStack *frame) {
277-
if (!frame)
278-
return true;
279-
const char *file = frame->info.file;
280-
const char *module = frame->info.module;
281-
if (file && (internal_strstr(file, "/compiler-rt/lib/")))
282-
return true;
283-
if (module && (internal_strstr(module, "libclang_rt.")))
284-
return true;
285-
return false;
286-
}
287-
288276
static SymbolizedStack *SkipTsanInternalFrames(SymbolizedStack *frames) {
289-
for (SymbolizedStack *f = frames; f; f = f->next)
290-
if (!FrameIsInternal(f))
291-
return f;
277+
if (SymbolizedStack *f = SkipInternalFrames(frames))
278+
return f;
292279
return frames; // Fallback to the top frame.
293280
}
294281

0 commit comments

Comments
 (0)