[PATCH] D28109: Allow setting multiple debug types
Eugene Leviant via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 26 07:12:38 PST 2016
evgeny777 updated this revision to Diff 82503.
evgeny777 added a comment.
Herald added a subscriber: mgorny.
Added unit test. Thanks for a hint!
Repository:
rL LLVM
https://reviews.llvm.org/D28109
Files:
include/llvm/Support/Debug.h
lib/Support/Debug.cpp
unittests/Support/CMakeLists.txt
unittests/Support/DebugTest.cpp
Index: unittests/Support/DebugTest.cpp
===================================================================
--- unittests/Support/DebugTest.cpp
+++ unittests/Support/DebugTest.cpp
@@ -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());
+}
Index: unittests/Support/CMakeLists.txt
===================================================================
--- unittests/Support/CMakeLists.txt
+++ unittests/Support/CMakeLists.txt
@@ -14,6 +14,7 @@
CompressionTest.cpp
ConvertUTFTest.cpp
DataExtractorTest.cpp
+ DebugTest.cpp
DwarfTest.cpp
EndianStreamTest.cpp
EndianTest.cpp
Index: lib/Support/Debug.cpp
===================================================================
--- lib/Support/Debug.cpp
+++ lib/Support/Debug.cpp
@@ -63,10 +63,14 @@
/// 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: include/llvm/Support/Debug.h
===================================================================
--- include/llvm/Support/Debug.h
+++ include/llvm/Support/Debug.h
@@ -51,6 +51,12 @@
///
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 @@
#else
#define isCurrentDebugType(X) (false)
#define setCurrentDebugType(X)
+#define setCurrentDebugTypes(X, N)
#define DEBUG_WITH_TYPE(TYPE, X) do { } while (false)
#endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28109.82503.patch
Type: text/x-patch
Size: 3045 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161226/eabe64a0/attachment.bin>
More information about the llvm-commits
mailing list