[Lldb-commits] [lldb] 8da5d11 - [lldb] DumpDataExtractor tests for item byte size errors

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Fri Apr 30 08:49:11 PDT 2021


Author: David Spickett
Date: 2021-04-30T16:49:04+01:00
New Revision: 8da5d111a5d2f795d5c32ef194f2e93c8ac0ec3f

URL: https://github.com/llvm/llvm-project/commit/8da5d111a5d2f795d5c32ef194f2e93c8ac0ec3f
DIFF: https://github.com/llvm/llvm-project/commit/8da5d111a5d2f795d5c32ef194f2e93c8ac0ec3f.diff

LOG: [lldb] DumpDataExtractor tests for item byte size errors

Reviewed By: teemperor

Differential Revision: https://reviews.llvm.org/D101631

Added: 
    

Modified: 
    lldb/unittests/Core/DumpDataExtractorTest.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/unittests/Core/DumpDataExtractorTest.cpp b/lldb/unittests/Core/DumpDataExtractorTest.cpp
index 83da4dd53887..d4c413859a04 100644
--- a/lldb/unittests/Core/DumpDataExtractorTest.cpp
+++ b/lldb/unittests/Core/DumpDataExtractorTest.cpp
@@ -202,9 +202,7 @@ TEST(DumpDataExtractorTest, Formats) {
   // Input not written in hex form because that requires C++17.
   TestDump<float>(10, lldb::Format::eFormatHexFloat, "0x1.4p3");
   TestDump<double>(10, lldb::Format::eFormatHexFloat, "0x1.4p3");
-  // Long double we don't support and format an error saying so.
-  // However sizeof(long double) is 8/12/16 depending on the host so not tested
-  // here.
+  // long double not supported, see ItemByteSizeErrors.
 
   // Can't disassemble without an execution context.
   TestDump<uint32_t>(0xcafef00d, lldb::Format::eFormatInstruction,
@@ -301,3 +299,46 @@ TEST(DumpDataExtractorTest, MultiLine) {
                     lldb::Format::eFormatBytesWithASCII, 3,
                     expected_chars_2_lines);
 }
+
+void TestDumpWithItemByteSize(size_t item_byte_size, lldb::Format format,
+                              llvm::StringRef expected) {
+  // We won't be reading this data so anything will do.
+  uint8_t dummy = 0;
+  TestDumpImpl(&dummy, 1, item_byte_size, 1, 1, LLDB_INVALID_ADDRESS, format,
+               expected);
+}
+
+TEST(DumpDataExtractorTest, ItemByteSizeErrors) {
+  TestDumpWithItemByteSize(
+      16, lldb::Format::eFormatBoolean,
+      "error: unsupported byte size (16) for boolean format");
+  TestDumpWithItemByteSize(21, lldb::Format::eFormatChar,
+                           "error: unsupported byte size (21) for char format");
+  TestDumpWithItemByteSize(
+      18, lldb::Format::eFormatComplexInteger,
+      "error: unsupported byte size (18) for complex integer format");
+
+  // The code uses sizeof(long double) for these checks. This changes by host
+  // but we know it won't be >16.
+  TestDumpWithItemByteSize(
+      34, lldb::Format::eFormatComplex,
+      "error: unsupported byte size (34) for complex float format");
+  TestDumpWithItemByteSize(
+      18, lldb::Format::eFormatFloat,
+      "error: unsupported byte size (18) for float format");
+
+  // We want sizes to exactly match one of float/double.
+  TestDumpWithItemByteSize(
+      14, lldb::Format::eFormatComplex,
+      "error: unsupported byte size (14) for complex float format");
+  TestDumpWithItemByteSize(3, lldb::Format::eFormatFloat,
+                           "error: unsupported byte size (3) for float format");
+
+  // We only allow float and double size.
+  TestDumpWithItemByteSize(
+      1, lldb::Format::eFormatHexFloat,
+      "error: unsupported byte size (1) for hex float format");
+  TestDumpWithItemByteSize(
+      17, lldb::Format::eFormatHexFloat,
+      "error: unsupported byte size (17) for hex float format");
+}


        


More information about the lldb-commits mailing list