jarin created this revision. jarin added a reviewer: teemperor. jarin added a project: LLDB. Herald added a subscriber: lldb-commits.
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. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D76650 Files: lldb/source/Core/ValueObject.cpp 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 Index: lldb/test/API/functionalities/data-formatter/cstring-utf8-summary/main.cpp =================================================================== --- /dev/null +++ lldb/test/API/functionalities/data-formatter/cstring-utf8-summary/main.cpp @@ -0,0 +1,4 @@ +int main() { + const char *s = "é"; + return 0; // break here +} Index: lldb/test/API/functionalities/data-formatter/cstring-utf8-summary/TestCstringUnicode.py =================================================================== --- /dev/null +++ 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", substrs=['"é"']) + self.expect("expr (const char*)s", substrs=['"é"']) Index: lldb/test/API/functionalities/data-formatter/cstring-utf8-summary/Makefile =================================================================== --- /dev/null +++ lldb/test/API/functionalities/data-formatter/cstring-utf8-summary/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules Index: lldb/source/Core/ValueObject.cpp =================================================================== --- lldb/source/Core/ValueObject.cpp +++ lldb/source/Core/ValueObject.cpp @@ -764,7 +764,7 @@ 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); }
Index: lldb/test/API/functionalities/data-formatter/cstring-utf8-summary/main.cpp =================================================================== --- /dev/null +++ lldb/test/API/functionalities/data-formatter/cstring-utf8-summary/main.cpp @@ -0,0 +1,4 @@ +int main() { + const char *s = "é"; + return 0; // break here +} Index: lldb/test/API/functionalities/data-formatter/cstring-utf8-summary/TestCstringUnicode.py =================================================================== --- /dev/null +++ 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", substrs=['"é"']) + self.expect("expr (const char*)s", substrs=['"é"']) Index: lldb/test/API/functionalities/data-formatter/cstring-utf8-summary/Makefile =================================================================== --- /dev/null +++ lldb/test/API/functionalities/data-formatter/cstring-utf8-summary/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules Index: lldb/source/Core/ValueObject.cpp =================================================================== --- lldb/source/Core/ValueObject.cpp +++ lldb/source/Core/ValueObject.cpp @@ -764,7 +764,7 @@ 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); }
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits