[Sanitizer] Print column number in SUMMARY line if it's available.

llvm-svn: 230721
This commit is contained in:
Alexey Samsonov 2015-02-27 02:29:25 +00:00
parent 5339a52c9a
commit 0b0cafc8fc
6 changed files with 32 additions and 30 deletions

View File

@ -16,6 +16,7 @@
#include "sanitizer_flags.h"
#include "sanitizer_libc.h"
#include "sanitizer_placement_new.h"
#include "sanitizer_symbolizer.h"
namespace __sanitizer {
@ -230,15 +231,18 @@ void ReportErrorSummary(const char *error_message) {
__sanitizer_report_error_summary(buff.data());
}
void ReportErrorSummary(const char *error_type, const char *file,
int line, const char *function) {
void ReportErrorSummary(const char *error_type, const AddressInfo &info) {
if (!common_flags()->print_summary)
return;
InternalScopedString buff(kMaxSummaryLength);
buff.append("%s %s:%d %s", error_type,
file ? StripPathPrefix(file, common_flags()->strip_path_prefix)
buff.append(
"%s %s:%d", error_type,
info.file ? StripPathPrefix(info.file, common_flags()->strip_path_prefix)
: "??",
line, function ? function : "??");
info.line);
if (info.column > 0)
buff.append(":%d", info.column);
buff.append(" %s", info.function ? info.function : "??");
ReportErrorSummary(buff.data());
}

View File

@ -25,6 +25,7 @@
namespace __sanitizer {
struct StackTrace;
struct AddressInfo;
// Constants.
const uptr kWordSize = SANITIZER_WORDSIZE / 8;
@ -288,9 +289,9 @@ const int kMaxSummaryLength = 1024;
// and pass it to __sanitizer_report_error_summary.
void ReportErrorSummary(const char *error_message);
// Same as above, but construct error_message as:
// error_type file:line function
void ReportErrorSummary(const char *error_type, const char *file,
int line, const char *function);
// error_type file:line[:column][ function]
void ReportErrorSummary(const char *error_type, const AddressInfo &info);
// Same as above, but obtains AddressInfo by symbolizing top stack trace frame.
void ReportErrorSummary(const char *error_type, StackTrace *trace);
// Math

View File

@ -44,20 +44,14 @@ void SetSandboxingCallback(void (*f)()) {
void ReportErrorSummary(const char *error_type, StackTrace *stack) {
if (!common_flags()->print_summary)
return;
#if !SANITIZER_GO
if (stack->size > 0 && Symbolizer::GetOrInit()->CanReturnFileLineInfo()) {
if (stack->size == 0 || !Symbolizer::GetOrInit()->CanReturnFileLineInfo())
return;
// Currently, we include the first stack frame into the report summary.
// Maybe sometimes we need to choose another frame (e.g. skip memcpy/etc).
uptr pc = StackTrace::GetPreviousInstructionPc(stack->trace[0]);
SymbolizedStack *frame = Symbolizer::GetOrInit()->SymbolizePC(pc);
const AddressInfo &ai = frame->info;
ReportErrorSummary(error_type, ai.file, ai.line, ai.function);
ReportErrorSummary(error_type, frame->info);
frame->ClearAll();
}
#else
AddressInfo ai;
ReportErrorSummary(error_type, ai.file, ai.line, ai.function);
#endif
}
static void (*SoftRssLimitExceededCallback)(bool exceeded);

View File

@ -335,10 +335,8 @@ void PrintReport(const ReportDesc *rep) {
Printf(" And %d more similar thread leaks.\n\n", rep->count - 1);
if (ReportStack *stack = ChooseSummaryStack(rep)) {
if (SymbolizedStack *frame = SkipTsanInternalFrames(stack->frames)) {
const AddressInfo &info = frame->info;
ReportErrorSummary(rep_typ_str, info.file, info.line, info.function);
}
if (SymbolizedStack *frame = SkipTsanInternalFrames(stack->frames))
ReportErrorSummary(rep_typ_str, frame->info);
}
Printf("==================\n");

View File

@ -49,8 +49,13 @@ static void MaybeReportErrorSummary(Location Loc) {
if (Loc.isSourceLocation()) {
SourceLocation SLoc = Loc.getSourceLocation();
if (!SLoc.isInvalid()) {
ReportErrorSummary("undefined-behavior", SLoc.getFilename(),
SLoc.getLine(), "");
AddressInfo AI;
AI.file = internal_strdup(SLoc.getFilename());
AI.line = SLoc.getLine();
AI.column = SLoc.getColumn();
AI.function = internal_strdup(""); // Avoid printing ?? as function name.
ReportErrorSummary("undefined-behavior", AI);
AI.Clear();
return;
}
}

View File

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