[llvm] r290597 - Allow setting multiple debug types
Eugene Leviant via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 27 01:31:20 PST 2016
Author: evgeny777
Date: Tue Dec 27 03:31:20 2016
New Revision: 290597
URL: http://llvm.org/viewvc/llvm-project?rev=290597&view=rev
Log:
Allow setting multiple debug types
Differential revision: https://reviews.llvm.org/D28109
Added:
llvm/trunk/unittests/Support/DebugTest.cpp
Modified:
llvm/trunk/include/llvm/Support/Debug.h
llvm/trunk/lib/Support/Debug.cpp
llvm/trunk/unittests/Support/CMakeLists.txt
Modified: llvm/trunk/include/llvm/Support/Debug.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Debug.h?rev=290597&r1=290596&r2=290597&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Debug.h (original)
+++ llvm/trunk/include/llvm/Support/Debug.h Tue Dec 27 03:31:20 2016
@@ -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 *Typ
#else
#define isCurrentDebugType(X) (false)
#define setCurrentDebugType(X)
+#define setCurrentDebugTypes(X, N)
#define DEBUG_WITH_TYPE(TYPE, X) do { } while (false)
#endif
Modified: llvm/trunk/lib/Support/Debug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Debug.cpp?rev=290597&r1=290596&r2=290597&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Debug.cpp (original)
+++ llvm/trunk/lib/Support/Debug.cpp Tue Dec 27 03:31:20 2016
@@ -63,10 +63,14 @@ bool isCurrentDebugType(const char *Debu
/// 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.
Modified: llvm/trunk/unittests/Support/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/CMakeLists.txt?rev=290597&r1=290596&r2=290597&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/CMakeLists.txt (original)
+++ llvm/trunk/unittests/Support/CMakeLists.txt Tue Dec 27 03:31:20 2016
@@ -14,6 +14,7 @@ add_llvm_unittest(SupportTests
CompressionTest.cpp
ConvertUTFTest.cpp
DataExtractorTest.cpp
+ DebugTest.cpp
DwarfTest.cpp
EndianStreamTest.cpp
EndianTest.cpp
Added: llvm/trunk/unittests/Support/DebugTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/DebugTest.cpp?rev=290597&view=auto
==============================================================================
--- llvm/trunk/unittests/Support/DebugTest.cpp (added)
+++ llvm/trunk/unittests/Support/DebugTest.cpp Tue Dec 27 03:31:20 2016
@@ -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());
+}
More information about the llvm-commits
mailing list