Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Unified Diff: third_party/crazy_linker/crazy_linker/src/crazy_linker_debug.cpp

Issue 23717023: Android: Add chrome-specific dynamic linker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove findbugs issues. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/crazy_linker/crazy_linker/src/crazy_linker_debug.cpp
diff --git a/third_party/crazy_linker/crazy_linker/src/crazy_linker_debug.cpp b/third_party/crazy_linker/crazy_linker/src/crazy_linker_debug.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..352fb7c5b6318de52d5dcf0a58d686e3f1f3a1b2
--- /dev/null
+++ b/third_party/crazy_linker/crazy_linker/src/crazy_linker_debug.cpp
@@ -0,0 +1,66 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "crazy_linker_debug.h"
+
+#include <errno.h>
+#include <string.h>
+
+#ifdef __ANDROID__
+#include <android/log.h>
+#endif
+#include <stdarg.h>
+#include <stdio.h>
+
+namespace crazy {
+
+#if CRAZY_DEBUG
+
+namespace {
+
+void LogArgs(const char* fmt, va_list args, bool print_error, int error) {
+ char buffer[4096];
bulach 2013/09/09 16:14:15 is the stack big enough at this depth? perhaps all
digit1 2013/09/10 09:23:30 I have no reason to think that the stack would be
+ int ret;
+
+ ret = vsnprintf(buffer, sizeof(buffer), fmt, args);
+ if (ret >= static_cast<int>(sizeof(buffer)))
+ ret = static_cast<int>(sizeof(buffer)) - 1;
+
+ if (print_error) {
+ strlcat(buffer, ": ", sizeof(buffer));
+ strlcat(buffer, strerror(error), sizeof(buffer));
+ }
+
+ // First, send to stderr.
+ fprintf(stderr, "%.*s", ret, buffer);
+
+#ifdef __ANDROID__
+ // Then to the Android log.
+ __android_log_write(ANDROID_LOG_INFO, "crazy_linker", buffer);
+#endif
+}
+
+} // namespace
+
+void Log(const char* fmt, ...) {
+ int old_errno = errno;
+ va_list args;
+ va_start(args, fmt);
+ LogArgs(fmt, args, false, -1);
+ va_end(args);
+ errno = old_errno;
+}
+
+void LogErrno(const char* fmt, ...) {
+ int old_errno = errno;
+ va_list args;
+ va_start(args, fmt);
+ LogArgs(fmt, args, true, old_errno);
+ va_end(args);
+ errno = old_errno;
+}
+
+#endif // CRAZY_DEBUG
+
+} // namespace crazy

Powered by Google App Engine
This is Rietveld 408576698