]> granicus.if.org Git - llvm/commitdiff
Allow setting multiple debug types
authorEugene Leviant <eleviant@accesssoftek.com>
Tue, 27 Dec 2016 09:31:20 +0000 (09:31 +0000)
committerEugene Leviant <eleviant@accesssoftek.com>
Tue, 27 Dec 2016 09:31:20 +0000 (09:31 +0000)
Differential revision: https://reviews.llvm.org/D28109

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290597 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/Debug.h
lib/Support/Debug.cpp
unittests/Support/CMakeLists.txt
unittests/Support/DebugTest.cpp [new file with mode: 0644]

index dc42379f61a344a0da81d4e564e8b048b4e2f5dc..3465c403361f9535f57c18580b7381155228cc59 100644 (file)
@@ -51,6 +51,12 @@ bool isCurrentDebugType(const char *Type);
 ///
 void setCurrentDebugType(const char *Type);
 
+/// setCurrentDebugTypes - Set the current debug type, as if the
+/// -debug-only=X,Y,Z option were specified. Note that DebugFlag
+/// also needs to be set to true for debug output to be produced.
+///
+void setCurrentDebugTypes(const char **Types, unsigned Count);
+
 /// DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug
 /// information.  In the '-debug' option is specified on the commandline, and if
 /// this is a debug build, then the code specified as the option to the macro
@@ -67,6 +73,7 @@ void setCurrentDebugType(const char *Type);
 #else
 #define isCurrentDebugType(X) (false)
 #define setCurrentDebugType(X)
+#define setCurrentDebugTypes(X, N)
 #define DEBUG_WITH_TYPE(TYPE, X) do { } while (false)
 #endif
 
index 323d53279b45319ae44ae18572e86001f1f8e62c..a78acf0f69ca8dcd65b811688b399cb6aab3f63d 100644 (file)
@@ -63,10 +63,14 @@ bool isCurrentDebugType(const char *DebugType) {
 /// debug output to be produced.
 ///
 void setCurrentDebugType(const char *Type) {
-  CurrentDebugType->clear();
-  CurrentDebugType->push_back(Type);
+  setCurrentDebugTypes(&Type, 1);
 }
 
+void setCurrentDebugTypes(const char **Types, unsigned Count) {
+  CurrentDebugType->clear();
+  for (size_t T = 0; T < Count; ++T)
+    CurrentDebugType->push_back(Types[T]);
+}
 } // namespace llvm
 
 // All Debug.h functionality is a no-op in NDEBUG mode.
index 51b3c4711ca2c8488411d28425a81828bee11ac2..2ffedab82acbbff26328ff9e9082ba332e8abe4b 100644 (file)
@@ -14,6 +14,7 @@ add_llvm_unittest(SupportTests
   CompressionTest.cpp
   ConvertUTFTest.cpp
   DataExtractorTest.cpp
+  DebugTest.cpp
   DwarfTest.cpp
   EndianStreamTest.cpp
   EndianTest.cpp
diff --git a/unittests/Support/DebugTest.cpp b/unittests/Support/DebugTest.cpp
new file mode 100644 (file)
index 0000000..ed228f5
--- /dev/null
@@ -0,0 +1,32 @@
+//===- llvm/unittest/Support/DebugTest.cpp --------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/raw_ostream.h"
+#include "gtest/gtest.h"
+
+#include <string>
+using namespace llvm;
+
+TEST(DebugTest, Basic) {
+  std::string s1, s2;
+  raw_string_ostream os1(s1), os2(s2);
+  static const char *DT[] = {"A", "B"};  
+  
+  llvm::DebugFlag = true;
+  setCurrentDebugTypes(DT, 2);
+  DEBUG_WITH_TYPE("A", os1 << "A");
+  DEBUG_WITH_TYPE("B", os1 << "B");
+  EXPECT_EQ("AB", os1.str());
+
+  setCurrentDebugType("A");
+  DEBUG_WITH_TYPE("A", os2 << "A");
+  DEBUG_WITH_TYPE("B", os2 << "B");
+  EXPECT_EQ("A", os2.str());
+}