Permalink
Browse files

Log output can be controled by env

  • Loading branch information...
1 parent 5e2db92 commit 23457288a96e25d1b71f967bb624223992010926 @shinh committed Mar 25, 2011
Showing with 89 additions and 18 deletions.
  1. +3 −3 Makefile
  2. +9 −0 env_flags.h
  3. +1 −8 ld-mac.cc
  4. +30 −0 log.cc
  5. +45 −0 log.h
  6. +1 −7 mach-o.cc
View
@@ -1,4 +1,4 @@
-GCCFLAGS=-g -Iinclude -Wall -MMD -fno-omit-frame-pointer -DNOLOG
+GCCFLAGS=-g -Iinclude -Wall -MMD -fno-omit-frame-pointer
CXXFLAGS=$(GCCFLAGS) -W -Werror
CFLAGS=$(GCCFLAGS) -fPIC
@@ -50,10 +50,10 @@ $(MACTXTS): %.txt: %.bin
extract: extract.o fat.o
$(CXX) $^ -o $@ -g -I. -W -Wall
-macho2elf: macho2elf.o mach-o.o fat.o
+macho2elf: macho2elf.o mach-o.o fat.o log.o
$(CXX) $^ -o $@ -g
-ld-mac: ld-mac.o mach-o.o fat.o
+ld-mac: ld-mac.o mach-o.o fat.o log.o
$(CXX) $^ -o $@ -g -ldl -lpthread
# TODO(hamaji): autotoolize?
View
@@ -34,12 +34,21 @@
#define LD_MAC_EnvToBool(envname, dflt) \
(!getenv(envname) ? (dflt) : memchr("tTyY1\0", getenv(envname)[0], 6) != NULL)
+#define LD_MAC_DECLARE_VARIABLE(type, name, tn) \
+ namespace FLAG__namespace_do_not_use_directly_use_LD_MAC_DECLARE_##tn##_instead { \
+ extern type FLAGS_##name; \
+ } \
+ using FLAG__namespace_do_not_use_directly_use_LD_MAC_DECLARE_##tn##_instead::FLAGS_##name
+
#define LD_MAC_DEFINE_VARIABLE(type, name, value, meaning, tn) \
namespace FLAG__namespace_do_not_use_directly_use_LD_MAC_DECLARE_##tn##_instead { \
type FLAGS_##name(value); \
} \
using FLAG__namespace_do_not_use_directly_use_LD_MAC_DECLARE_##tn##_instead::FLAGS_##name;
+#define DECLARE_bool(name) \
+ LD_MAC_DECLARE_VARIABLE(bool, name, bool)
+
#define DEFINE_bool(name, value, meaning) \
LD_MAC_DEFINE_VARIABLE(bool, name, LD_MAC_EnvToBool("LD_MAC_" #name, value), \
meaning, bool)
View
@@ -52,16 +52,9 @@
#include "env_flags.h"
#include "fat.h"
+#include "log.h"
#include "mach-o.h"
-#ifdef NOLOG
-# define LOG if (0) cout
-//# define LOG cerr
-#else
-# define LOG cerr
-#endif
-#define ERR cerr
-
using namespace std;
DEFINE_bool(TRACE_FUNCTIONS, false, "Show calling functions");
View
30 log.cc
@@ -0,0 +1,30 @@
+// Copyright 2011 Shinichiro Hamaji. All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// 1. Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials
+// provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY Shinichiro Hamaji ``AS IS'' AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Shinichiro Hamaji OR
+// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE.
+
+#include "env_flags.h"
+
+DEFINE_bool(LOG, false, "Output bunch of logs");
View
45 log.h
@@ -0,0 +1,45 @@
+// Copyright 2011 Shinichiro Hamaji. All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// 1. Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials
+// provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY Shinichiro Hamaji ``AS IS'' AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Shinichiro Hamaji OR
+// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE.
+
+#ifndef LOG_H_
+#define LOG_H_
+
+#include "env_flags.h"
+
+DECLARE_bool(LOG);
+
+#ifdef NOLOG
+# define LOG if (0) cout
+# define LOGF(...) if (0) fprintf(stderr, __VA_ARGS__)
+#else
+# define LOG if (FLAGS_LOG) cerr
+# define LOGF(...) if (FLAGS_LOG) fprintf(stderr, __VA_ARGS__)
+#endif
+
+#define ERR cerr
+
+#endif
View
@@ -38,16 +38,10 @@
#include <unistd.h>
#include "fat.h"
+#include "log.h"
#include "mach-o.h"
#include "mach-o/loader.h"
-#ifdef NOLOG
-# define LOGF(...) if (0) fprintf(stderr, __VA_ARGS__)
-//# define LOGF(...) fprintf(stderr, __VA_ARGS__)
-#else
-# define LOGF(...) fprintf(stderr, __VA_ARGS__)
-#endif
-
typedef long long ll;
typedef unsigned long long ull;

0 comments on commit 2345728

Please sign in to comment.