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

Unified Diff: tools/relocation_packer/src/debug.h

Issue 310483003: Add a host tool to pack R_ARM_RELATIVE relocations in libchrome.<ver>.so. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove binary test data files, dcommit separately. Created 6 years, 6 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
« no previous file with comments | « tools/relocation_packer/relocation_packer.gyp ('k') | tools/relocation_packer/src/debug.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/relocation_packer/src/debug.h
diff --git a/tools/relocation_packer/src/debug.h b/tools/relocation_packer/src/debug.h
new file mode 100644
index 0000000000000000000000000000000000000000..47ee96ae4d9531e7cd2a94a47fdf11d7e02903c7
--- /dev/null
+++ b/tools/relocation_packer/src/debug.h
@@ -0,0 +1,88 @@
+// Copyright 2014 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.
+
+// Logging and checks.
+//
+// Log messages to stdout. LOG() prints normal user messages, VLOG()
+// is verbose, for tracing and debugging. SetVerbose() enables/disables
+// VLOG() output.
+//
+// LOG() and VLOG() are printf-like, and arguments are checked by gcc.
+// LOG_IF() and VLOG_IF() call LOG/VLOG if their predicate is true.
+// CHECK() aborts if its predicate is false. NOTREACHED() always aborts.
+// Logging is not thread-safe.
+//
+
+#ifndef TOOLS_RELOCATION_PACKER_SRC_DEBUG_H_
+#define TOOLS_RELOCATION_PACKER_SRC_DEBUG_H_
+
+#ifdef NDEBUG
+#undef NDEBUG
+#include <assert.h>
+#define NDEBUG
+#else
+#include <assert.h>
+#endif
+
+#include <stdarg.h>
+#include <string.h>
+
+namespace relocation_packer {
+
+// If gcc, define PRINTF_ATTRIBUTE so that gcc checks Log() as printf-like.
+#if defined(__GNUC__) && (__GNUC__ >= 3)
+#define PRINTF_ATTRIBUTE(string_index, first_to_check) \
+ __attribute__((__format__(__printf__, string_index, first_to_check)))
+#else
+#define PRINTF_ATTRIBUTE(string_index, first_to_check)
+#endif
+
+// Logging and checking macros.
+#define LOG(...) ::relocation_packer::Logger::Log(__VA_ARGS__)
+#define VLOG(...) ::relocation_packer::Logger::VLog(__VA_ARGS__)
+#define LOG_IF(cond, ...) \
+ do { \
+ if ((cond)) \
+ LOG(__VA_ARGS__); \
+ } while (0)
+#define VLOG_IF(cond, ...) \
+ do { \
+ if ((cond)) \
+ VLOG(__VA_ARGS__); \
+ } while (0)
+
+#define CHECK(expr) assert((expr))
+#define NOTREACHED(_) assert(false)
+
+class Logger {
+ public:
+ // Log and verbose log to stdout.
+ // |format| is a printf format string.
+ static void Log(const char* format, ...) PRINTF_ATTRIBUTE(1, 2);
+ static void VLog(const char* format, ...) PRINTF_ATTRIBUTE(1, 2);
+
+ // Set verbose mode.
+ // |flag| is true to enable verbose logging, false to disable it.
+ static void SetVerbose(bool flag);
+
+ private:
+ Logger() : is_verbose_(false) { }
+ ~Logger() {}
+
+ // Implementation of log to stdout.
+ // |format| is a printf format string.
+ // |args| is a varargs list of printf arguments.
+ void Log(const char* format, va_list args);
+
+ // If set, VLOG is enabled, otherwise it is a no-op.
+ bool is_verbose_;
+
+ // Singleton support. Not thread-safe.
+ static Logger* GetInstance();
+ static Logger* instance_;
+};
+
+} // namespace relocation_packer
+
+#endif // TOOLS_RELOCATION_PACKER_SRC_DEBUG_H_
« no previous file with comments | « tools/relocation_packer/relocation_packer.gyp ('k') | tools/relocation_packer/src/debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698