Depends on: * https://github.com/llvm/llvm-project/pull/174385 (only last commit is relevant for this review) The `${var%s}` format isn't capable of formatting references to C-strings. So the summary for those becomes `<no value available>`. This patch prevents the system C-string formatter from applying to references, which means the summary for such types will be empty. This prompts LLDB to instead print the child, which is the referenced C-string. Before: ``` (lldb) v ref (const char *&) ref = 0x000000016fdfe960 <no value available> ``` After: ``` (lldb) v ref (const char *&) ref = 0x000000016fdfec40 (&ref = "hi") ``` An alternative would be to support references in the `ValueObject` dump methods. We assume C-string are pointers/arrays in a lot of places, so such a fix would be a more intrusive undertaking, and I'm not sure we would want to support references there in the first place. So for now I went with the fallback logic in this PR.
68 lines
2.3 KiB
Python
68 lines
2.3 KiB
Python
import lldb
|
|
from lldbsuite.test.lldbtest import *
|
|
from lldbsuite.test import lldbutil
|
|
|
|
|
|
class TestStringPrinter(TestBase):
|
|
def test(self):
|
|
self.build()
|
|
|
|
self.addTearDownHook(
|
|
lambda x: x.runCmd("setting set escape-non-printables true")
|
|
)
|
|
|
|
lldbutil.run_to_source_breakpoint(
|
|
self, "Break here", lldb.SBFileSpec("main.cpp", False)
|
|
)
|
|
|
|
self.expect_var_path(
|
|
"charwithtabs",
|
|
summary='"Hello\\t\\tWorld\\nI am here\\t\\tto say hello\\n"',
|
|
)
|
|
self.expect_var_path("a.data", summary='"FOOB"')
|
|
self.expect_var_path("b.data", summary=r'"FO\0B"')
|
|
self.expect_var_path("c.data", summary=r'"F\0O"')
|
|
self.expect_var_path("manytrailingnuls", summary=r'"F\0OO\0BA\0R"')
|
|
|
|
for c in ["", "const"]:
|
|
for v in ["", "volatile"]:
|
|
for s in ["", "unsigned"]:
|
|
summary = '"' + c + v + s + 'char"'
|
|
self.expect_var_path(c + v + s + "chararray", summary=summary)
|
|
# These should be printed normally
|
|
self.expect_var_path(c + v + s + "charstar", summary=summary)
|
|
|
|
Schar5 = self.expect_var_path(
|
|
"Schar5", children=[ValueCheck(name="x", value="0")]
|
|
)
|
|
self.assertIsNone(Schar5.GetSummary())
|
|
Scharstar = self.expect_var_path(
|
|
"Scharstar", children=[ValueCheck(name="x", value="0")]
|
|
)
|
|
self.assertIsNone(Scharstar.GetSummary())
|
|
|
|
self.runCmd("setting set escape-non-printables false")
|
|
self.expect_var_path(
|
|
"charwithtabs", summary='"Hello\t\tWorld\nI am here\t\tto say hello\n"'
|
|
)
|
|
self.assertTrue(
|
|
self.frame().FindVariable("longconstcharstar").GetSummary().endswith('"...')
|
|
)
|
|
|
|
# FIXME: make "b.data" and "c.data" work sanely
|
|
|
|
self.expect("frame variable ref", substrs=['(&ref = "Hello")'])
|
|
self.expect_var_path(
|
|
"ref",
|
|
summary=None,
|
|
children=[ValueCheck(name="&ref", summary='"Hello"')],
|
|
)
|
|
|
|
# FIXME: should LLDB use "&&refref" for the name here?
|
|
self.expect("frame variable refref", substrs=['(&refref = "Hi")'])
|
|
self.expect_var_path(
|
|
"refref",
|
|
summary=None,
|
|
children=[ValueCheck(name="&refref", summary='"Hi"')],
|
|
)
|