[Lldb-commits] [lldb] r295821 - Add format_provider for the MemoryRegionInfo::OptionalBool enum

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Wed Feb 22 02:37:57 PST 2017


Author: labath
Date: Wed Feb 22 04:37:57 2017
New Revision: 295821

URL: http://llvm.org/viewvc/llvm-project?rev=295821&view=rev
Log:
Add format_provider for the MemoryRegionInfo::OptionalBool enum

Added:
    lldb/trunk/unittests/Target/MemoryRegionInfoTest.cpp
Modified:
    lldb/trunk/include/lldb/Target/MemoryRegionInfo.h
    lldb/trunk/unittests/Target/CMakeLists.txt

Modified: lldb/trunk/include/lldb/Target/MemoryRegionInfo.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/MemoryRegionInfo.h?rev=295821&r1=295820&r2=295821&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/MemoryRegionInfo.h (original)
+++ lldb/trunk/include/lldb/Target/MemoryRegionInfo.h Wed Feb 22 04:37:57 2017
@@ -12,6 +12,7 @@
 #define lldb_MemoryRegionInfo_h
 
 #include "lldb/Core/RangeMap.h"
+#include "llvm/Support/FormatProviders.h"
 #include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/Range.h"
 
@@ -100,4 +101,24 @@ protected:
 };
 }
 
+namespace llvm {
+template <>
+struct format_provider<lldb_private::MemoryRegionInfo::OptionalBool> {
+  static void format(const lldb_private::MemoryRegionInfo::OptionalBool &B,
+                     raw_ostream &OS, StringRef Options) {
+    switch(B) {
+    case lldb_private::MemoryRegionInfo::eNo:
+      OS << "no";
+      return;
+    case lldb_private::MemoryRegionInfo::eYes:
+      OS << "yes";
+      return;
+    case lldb_private::MemoryRegionInfo::eDontKnow:
+      OS << "don't know";
+      return;
+    }
+  }
+};
+}
+
 #endif // #ifndef lldb_MemoryRegionInfo_h

Modified: lldb/trunk/unittests/Target/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Target/CMakeLists.txt?rev=295821&r1=295820&r2=295821&view=diff
==============================================================================
--- lldb/trunk/unittests/Target/CMakeLists.txt (original)
+++ lldb/trunk/unittests/Target/CMakeLists.txt Wed Feb 22 04:37:57 2017
@@ -1,4 +1,5 @@
 add_lldb_unittest(TargetTests
+  MemoryRegionInfoTest.cpp
   ModuleCacheTest.cpp
 
   LINK_LIBS

Added: lldb/trunk/unittests/Target/MemoryRegionInfoTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Target/MemoryRegionInfoTest.cpp?rev=295821&view=auto
==============================================================================
--- lldb/trunk/unittests/Target/MemoryRegionInfoTest.cpp (added)
+++ lldb/trunk/unittests/Target/MemoryRegionInfoTest.cpp Wed Feb 22 04:37:57 2017
@@ -0,0 +1,20 @@
+//===-- MemoryRegionInfoTest.cpp --------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Target/MemoryRegionInfo.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "gtest/gtest.h"
+
+using namespace lldb_private;
+
+TEST(MemoryRegionInfoTest, Formatv) {
+  EXPECT_EQ("yes", llvm::formatv("{0}", MemoryRegionInfo::eYes).str());
+  EXPECT_EQ("no", llvm::formatv("{0}", MemoryRegionInfo::eNo).str());
+  EXPECT_EQ("don't know", llvm::formatv("{0}", MemoryRegionInfo::eDontKnow).str());
+}




More information about the lldb-commits mailing list