// Stash the command line for later use. We can use /proc/self/cmdline on Linux to recover this, // but we don't have that luxury on the Mac, and there are a couple of argv[0] variants that are // commonly used. if (argv != nullptr) {
gCmdLine.reset(new std::string(argv[0])); for (size_t i = 1; argv[i] != nullptr; ++i) {
gCmdLine->append(" ");
gCmdLine->append(argv[i]);
}
gProgramInvocationName.reset(new std::string(argv[0])); constchar* last_slash = strrchr(argv[0], '/');
gProgramInvocationShortName.reset(new std::string((last_slash != nullptr) ? last_slash + 1
: argv[0]));
} else { // TODO: fall back to /proc/self/cmdline when argv is null on Linux.
gCmdLine.reset(new std::string("<unset>"));
}
// These log function defaults should match those in android-base/logging.h. #ifdef ART_TARGET_ANDROID #define INIT_LOGGING_DEFAULT_LOGGER android::base::LogdLogger() #else #define INIT_LOGGING_DEFAULT_LOGGER android::base::StderrLogger #endif
android::base::InitLogging(argv, INIT_LOGGING_DEFAULT_LOGGER,
std::move<AbortFunction>(abort_function)); #undef INIT_LOGGING_DEFAULT_LOGGER
}
#ifdef ART_TARGET_ANDROID staticconst android_LogPriority kLogSeverityToAndroidLogPriority[] = {
ANDROID_LOG_VERBOSE, ANDROID_LOG_DEBUG, ANDROID_LOG_INFO, ANDROID_LOG_WARN,
ANDROID_LOG_ERROR, ANDROID_LOG_FATAL, ANDROID_LOG_FATAL
};
static_assert(arraysize(kLogSeverityToAndroidLogPriority) == ::android::base::FATAL + 1, "Mismatch in size of kLogSeverityToAndroidLogPriority and values in LogSeverity"); #endif
void LogHelper::LogLineLowStack(constchar* file, unsignedint line,
LogSeverity log_severity, constchar* message) { #ifdef ART_TARGET_ANDROID // Use android_writeLog() to avoid stack-based buffers used by android_printLog(). constchar* tag = ProgramInvocationShortName(); int priority = kLogSeverityToAndroidLogPriority[static_cast<size_t>(log_severity)]; char* buf = nullptr;
size_t buf_size = 0u; if (priority == ANDROID_LOG_FATAL) { // Allocate buffer for snprintf(buf, buf_size, "%s:%u] %s", file, line, message) below. // If allocation fails, fall back to printing only the message.
buf_size = strlen(file) + 1/* ':' */ + std::numeric_limits<decltype(line)>::max_digits10 + 2/* "] " */ + strlen(message) + 1 /* terminating 0 */;
buf = reinterpret_cast<char*>(malloc(buf_size));
} if (buf != nullptr) {
snprintf(buf, buf_size, "%s:%u] %s", file, line, message);
android_writeLog(priority, tag, buf);
free(buf);
} else {
android_writeLog(priority, tag, message);
} #else static constexpr char kLogCharacters[] = { 'V', 'D', 'I', 'W', 'E', 'F', 'F' };
static_assert(
arraysize(kLogCharacters) == static_cast<size_t>(::android::base::FATAL) + 1, "Wrong character array size");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.