[Lldb-commits] [lldb] 177dd63 - Data formatters: fix detection of C strings
Raphael Isemann via lldb-commits
lldb-commits at lists.llvm.org
Tue Mar 24 06:26:19 PDT 2020
Author: Jaroslav Sevcik
Date: 2020-03-24T14:25:59+01:00
New Revision: 177dd63c8d742250dac6ea365e7c30f0fbab3257
URL: https://github.com/llvm/llvm-project/commit/177dd63c8d742250dac6ea365e7c30f0fbab3257
DIFF: https://github.com/llvm/llvm-project/commit/177dd63c8d742250dac6ea365e7c30f0fbab3257.diff
LOG: Data formatters: fix detection of C strings
Summary:
Detection of C strings does not work well for pointers. If the value object holding a (char*) pointer does not have an address (e.g., if it is a temp), the value is not considered a C string and its formatting is left to DumpDataExtractor rather than the special handling in ValueObject::DumpPrintableRepresentation. This leads to inconsistent outputs, e.g., in escaping non-ASCII characters. See the test for an example; the second test expectation is not met (without this patch). With this patch, the C string detection only insists that the pointer value is valid. The patch makes the code consistent with how the pointer is obtained in ValueObject::ReadPointedString.
Reviewers: teemperor
Reviewed By: teemperor
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D76650
Added:
lldb/test/API/functionalities/data-formatter/cstring-utf8-summary/Makefile
lldb/test/API/functionalities/data-formatter/cstring-utf8-summary/TestCstringUnicode.py
lldb/test/API/functionalities/data-formatter/cstring-utf8-summary/main.cpp
Modified:
lldb/source/Core/ValueObject.cpp
Removed:
################################################################################
diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp
index 4c9c44ea15f4..9e20ba76dccb 100644
--- a/lldb/source/Core/ValueObject.cpp
+++ b/lldb/source/Core/ValueObject.cpp
@@ -764,7 +764,7 @@ bool ValueObject::IsCStringContainer(bool check_pointer) {
return true;
addr_t cstr_address = LLDB_INVALID_ADDRESS;
AddressType cstr_address_type = eAddressTypeInvalid;
- cstr_address = GetAddressOf(true, &cstr_address_type);
+ cstr_address = GetPointerValue(&cstr_address_type);
return (cstr_address != LLDB_INVALID_ADDRESS);
}
diff --git a/lldb/test/API/functionalities/data-formatter/cstring-utf8-summary/Makefile b/lldb/test/API/functionalities/data-formatter/cstring-utf8-summary/Makefile
new file mode 100644
index 000000000000..99998b20bcb0
--- /dev/null
+++ b/lldb/test/API/functionalities/data-formatter/cstring-utf8-summary/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
diff --git a/lldb/test/API/functionalities/data-formatter/cstring-utf8-summary/TestCstringUnicode.py b/lldb/test/API/functionalities/data-formatter/cstring-utf8-summary/TestCstringUnicode.py
new file mode 100644
index 000000000000..c05e9e9b06ba
--- /dev/null
+++ b/lldb/test/API/functionalities/data-formatter/cstring-utf8-summary/TestCstringUnicode.py
@@ -0,0 +1,18 @@
+# coding=utf8
+
+import lldb
+from lldbsuite.test.lldbtest import *
+import lldbsuite.test.lldbutil as lldbutil
+
+
+class CstringUnicodeTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+ NO_DEBUG_INFO_TESTCASE = True
+
+ def test_cstring_unicode(self):
+ self.build()
+ lldbutil.run_to_source_breakpoint(self, "// break here",
+ lldb.SBFileSpec("main.cpp", False))
+ self.expect_expr("s", result_summary='"🔥"')
+ self.expect_expr("(const char*)s", result_summary='"🔥"')
diff --git a/lldb/test/API/functionalities/data-formatter/cstring-utf8-summary/main.cpp b/lldb/test/API/functionalities/data-formatter/cstring-utf8-summary/main.cpp
new file mode 100644
index 000000000000..c1e8bcf242f4
--- /dev/null
+++ b/lldb/test/API/functionalities/data-formatter/cstring-utf8-summary/main.cpp
@@ -0,0 +1,4 @@
+int main() {
+ const char *s = u8"🔥";
+ return 0; // break here
+}
More information about the lldb-commits
mailing list