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

Unified Diff: tools/relocation_packer/src/relocation_packer_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: Created 6 years, 7 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: tools/relocation_packer/src/relocation_packer_debug.h
diff --git a/tools/relocation_packer/src/relocation_packer_debug.h b/tools/relocation_packer/src/relocation_packer_debug.h
new file mode 100644
index 0000000000000000000000000000000000000000..220ac0ae66d53c3138e9dfde548008a612332593
--- /dev/null
+++ b/tools/relocation_packer/src/relocation_packer_debug.h
@@ -0,0 +1,81 @@
+// 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)
rmcilroy 2014/06/02 15:16:35 VLOG()
simonb (inactive) 2014/06/04 16:40:35 Done.
+// 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.
+//
+
+#ifndef RELOCATION_PACKER_DEBUG_H
+#define RELOCATION_PACKER_DEBUG_H
+
+#undef NDEBUG
rmcilroy 2014/06/02 15:16:35 I don't think you should be undef'ing NDEBUG in a
simonb (inactive) 2014/06/04 16:40:35 Done.
+#include <assert.h>
+#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() { ::memset(this, 0, sizeof(*this)); }
rmcilroy 2014/06/02 15:16:35 no need for "::" global namespace prefix (througho
simonb (inactive) 2014/06/04 16:40:35 Done.
+ ~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.
+ static Logger* GetInstance();
+ static Logger* instance_;
+};
+
+} // namespace relocation_packer
+
+#endif // RELOCATION_PACKER_DEBUG_H

Powered by Google App Engine
This is Rietveld 408576698