Skip to content

Commit 0b0cafc

Browse files
committed
[Sanitizer] Print column number in SUMMARY line if it's available.
llvm-svn: 230721
1 parent 5339a52 commit 0b0cafc

File tree

6 files changed

+32
-30
lines changed

6 files changed

+32
-30
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_common.cc

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "sanitizer_flags.h"
1717
#include "sanitizer_libc.h"
1818
#include "sanitizer_placement_new.h"
19+
#include "sanitizer_symbolizer.h"
1920

2021
namespace __sanitizer {
2122

@@ -230,15 +231,18 @@ void ReportErrorSummary(const char *error_message) {
230231
__sanitizer_report_error_summary(buff.data());
231232
}
232233

233-
void ReportErrorSummary(const char *error_type, const char *file,
234-
int line, const char *function) {
234+
void ReportErrorSummary(const char *error_type, const AddressInfo &info) {
235235
if (!common_flags()->print_summary)
236236
return;
237237
InternalScopedString buff(kMaxSummaryLength);
238-
buff.append("%s %s:%d %s", error_type,
239-
file ? StripPathPrefix(file, common_flags()->strip_path_prefix)
240-
: "??",
241-
line, function ? function : "??");
238+
buff.append(
239+
"%s %s:%d", error_type,
240+
info.file ? StripPathPrefix(info.file, common_flags()->strip_path_prefix)
241+
: "??",
242+
info.line);
243+
if (info.column > 0)
244+
buff.append(":%d", info.column);
245+
buff.append(" %s", info.function ? info.function : "??");
242246
ReportErrorSummary(buff.data());
243247
}
244248

compiler-rt/lib/sanitizer_common/sanitizer_common.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
namespace __sanitizer {
2727
struct StackTrace;
28+
struct AddressInfo;
2829

2930
// Constants.
3031
const uptr kWordSize = SANITIZER_WORDSIZE / 8;
@@ -288,9 +289,9 @@ const int kMaxSummaryLength = 1024;
288289
// and pass it to __sanitizer_report_error_summary.
289290
void ReportErrorSummary(const char *error_message);
290291
// Same as above, but construct error_message as:
291-
// error_type file:line function
292-
void ReportErrorSummary(const char *error_type, const char *file,
293-
int line, const char *function);
292+
// error_type file:line[:column][ function]
293+
void ReportErrorSummary(const char *error_type, const AddressInfo &info);
294+
// Same as above, but obtains AddressInfo by symbolizing top stack trace frame.
294295
void ReportErrorSummary(const char *error_type, StackTrace *trace);
295296

296297
// Math

compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cc

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,14 @@ void SetSandboxingCallback(void (*f)()) {
4444
void ReportErrorSummary(const char *error_type, StackTrace *stack) {
4545
if (!common_flags()->print_summary)
4646
return;
47-
#if !SANITIZER_GO
48-
if (stack->size > 0 && Symbolizer::GetOrInit()->CanReturnFileLineInfo()) {
49-
// Currently, we include the first stack frame into the report summary.
50-
// Maybe sometimes we need to choose another frame (e.g. skip memcpy/etc).
51-
uptr pc = StackTrace::GetPreviousInstructionPc(stack->trace[0]);
52-
SymbolizedStack *frame = Symbolizer::GetOrInit()->SymbolizePC(pc);
53-
const AddressInfo &ai = frame->info;
54-
ReportErrorSummary(error_type, ai.file, ai.line, ai.function);
55-
frame->ClearAll();
56-
}
57-
#else
58-
AddressInfo ai;
59-
ReportErrorSummary(error_type, ai.file, ai.line, ai.function);
60-
#endif
47+
if (stack->size == 0 || !Symbolizer::GetOrInit()->CanReturnFileLineInfo())
48+
return;
49+
// Currently, we include the first stack frame into the report summary.
50+
// Maybe sometimes we need to choose another frame (e.g. skip memcpy/etc).
51+
uptr pc = StackTrace::GetPreviousInstructionPc(stack->trace[0]);
52+
SymbolizedStack *frame = Symbolizer::GetOrInit()->SymbolizePC(pc);
53+
ReportErrorSummary(error_type, frame->info);
54+
frame->ClearAll();
6155
}
6256

6357
static void (*SoftRssLimitExceededCallback)(bool exceeded);

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,8 @@ void PrintReport(const ReportDesc *rep) {
335335
Printf(" And %d more similar thread leaks.\n\n", rep->count - 1);
336336

337337
if (ReportStack *stack = ChooseSummaryStack(rep)) {
338-
if (SymbolizedStack *frame = SkipTsanInternalFrames(stack->frames)) {
339-
const AddressInfo &info = frame->info;
340-
ReportErrorSummary(rep_typ_str, info.file, info.line, info.function);
341-
}
338+
if (SymbolizedStack *frame = SkipTsanInternalFrames(stack->frames))
339+
ReportErrorSummary(rep_typ_str, frame->info);
342340
}
343341

344342
Printf("==================\n");

compiler-rt/lib/ubsan/ubsan_diag.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,13 @@ static void MaybeReportErrorSummary(Location Loc) {
4949
if (Loc.isSourceLocation()) {
5050
SourceLocation SLoc = Loc.getSourceLocation();
5151
if (!SLoc.isInvalid()) {
52-
ReportErrorSummary("undefined-behavior", SLoc.getFilename(),
53-
SLoc.getLine(), "");
52+
AddressInfo AI;
53+
AI.file = internal_strdup(SLoc.getFilename());
54+
AI.line = SLoc.getLine();
55+
AI.column = SLoc.getColumn();
56+
AI.function = internal_strdup(""); // Avoid printing ?? as function name.
57+
ReportErrorSummary("undefined-behavior", AI);
58+
AI.Clear();
5459
return;
5560
}
5661
}

compiler-rt/test/ubsan/TestCases/Integer/summary.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55

66
int main() {
77
(void)(uint64_t(10000000000000000000ull) + uint64_t(9000000000000000000ull));
8-
// CHECK: SUMMARY: AddressSanitizer: undefined-behavior {{.*}}summary.cpp:[[@LINE-1]]
8+
// CHECK: SUMMARY: AddressSanitizer: undefined-behavior {{.*}}summary.cpp:[[@LINE-1]]:44
99
return 0;
1010
}

0 commit comments

Comments
 (0)