2012-01-16 12:28:10 +00:00
|
|
|
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
2011-10-05 05:20:07 +00:00
|
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
2012-01-17 10:29:24 +00:00
|
|
|
#include "platform/assert.h"
|
|
|
|
|
2012-01-16 13:23:40 +00:00
|
|
|
#include "platform/globals.h"
|
2016-01-11 18:35:00 +00:00
|
|
|
#include "vm/os.h"
|
2016-07-29 20:29:25 +00:00
|
|
|
#include "vm/profiler.h"
|
2011-10-05 05:20:07 +00:00
|
|
|
|
|
|
|
namespace dart {
|
|
|
|
|
2016-09-06 17:10:40 +00:00
|
|
|
bool DynamicAssertionHelper::failed_ = false;
|
2011-10-05 05:20:07 +00:00
|
|
|
|
|
|
|
void DynamicAssertionHelper::Fail(const char* format, ...) {
|
2016-06-21 19:50:43 +00:00
|
|
|
// Take only the last 1KB of the file name if it is longer.
|
|
|
|
const intptr_t file_len = strlen(file_);
|
|
|
|
const intptr_t file_offset = (file_len > (1 * KB)) ? file_len - (1 * KB) : 0;
|
|
|
|
const char* file = file_ + file_offset;
|
|
|
|
|
|
|
|
// Print the file and line number into the buffer.
|
|
|
|
char buffer[4 * KB];
|
2016-10-05 23:54:18 +00:00
|
|
|
MSAN_UNPOISON(buffer, sizeof(buffer));
|
2016-06-21 19:50:43 +00:00
|
|
|
intptr_t file_and_line_length =
|
|
|
|
snprintf(buffer, sizeof(buffer), "%s: %d: error: ", file, line_);
|
2011-10-05 05:20:07 +00:00
|
|
|
|
2016-06-21 19:50:43 +00:00
|
|
|
// Print the error message into the buffer.
|
2011-10-05 05:20:07 +00:00
|
|
|
va_list arguments;
|
|
|
|
va_start(arguments, format);
|
2016-06-21 19:50:43 +00:00
|
|
|
vsnprintf(buffer + file_and_line_length,
|
|
|
|
sizeof(buffer) - file_and_line_length,
|
|
|
|
format,
|
|
|
|
arguments);
|
2011-10-05 05:20:07 +00:00
|
|
|
va_end(arguments);
|
|
|
|
|
2016-07-08 21:18:44 +00:00
|
|
|
// Print the buffer on stderr and/or syslog.
|
|
|
|
OS::PrintErr("%s\n", buffer);
|
2011-10-05 05:20:07 +00:00
|
|
|
|
|
|
|
// In case of failed assertions, abort right away. Otherwise, wait
|
|
|
|
// until the program is exiting before producing a non-zero exit
|
|
|
|
// code through abort.
|
|
|
|
if (kind_ == ASSERT) {
|
2016-07-29 20:29:25 +00:00
|
|
|
NOT_IN_PRODUCT(Profiler::DumpStackTrace(true /* native_stack_trace */));
|
2016-01-11 18:35:00 +00:00
|
|
|
OS::Abort();
|
2011-10-05 05:20:07 +00:00
|
|
|
}
|
2016-09-06 17:10:40 +00:00
|
|
|
failed_ = true;
|
2011-10-05 05:20:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dart
|