[Lldb-commits] [PATCH] D77153: [lldb/DataFormatters] Display null C++ pointers as nullptr
Frederic Riss via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Tue Mar 31 10:53:02 PDT 2020
friss created this revision.
friss added reviewers: jingham, labath.
Herald added a project: LLDB.
friss added a comment.
I haven't tested the libstdc++ part, would be great if someone could confirm this works.
The original motivation for this patch was to display a null
std::string pointer as nullptr instead of "", but the fix
seemed generic enough to be done for all C++ summary providers.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D77153
Files:
lldb/source/DataFormatters/TypeSummary.cpp
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/main.cpp
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp
===================================================================
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp
@@ -10,6 +10,7 @@
std::string q("hello world");
std::string Q("quite a long std::strin with lots of info inside it");
std::basic_string<unsigned char> uchar(5, 'a');
+ std::string *null = nullptr;
S.assign(L"!!!!!"); // Set break point at this line.
return 0;
}
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py
===================================================================
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py
@@ -59,6 +59,7 @@
var_q = self.frame().FindVariable('q')
var_Q = self.frame().FindVariable('Q')
var_uchar = self.frame().FindVariable('uchar')
+ var_null = self.frame().FindVariable('null')
self.assertEqual(var_wempty.GetSummary(), 'L""', "wempty summary wrong")
self.assertEqual(
@@ -76,6 +77,7 @@
var_Q.GetSummary(), '"quite a long std::strin with lots of info inside it"',
"Q summary wrong")
self.assertEqual(var_uchar.GetSummary(), '"aaaaa"', "u summary wrong")
+ self.assertEqual(var_null.GetSummary(), 'nullptr', "null summary wrong")
self.runCmd("next")
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/main.cpp
===================================================================
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/main.cpp
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/main.cpp
@@ -71,6 +71,7 @@
std::u32string u32_string(U"🍄🍅🍆🍌");
std::u32string u32_empty(U"");
std::basic_string<unsigned char> uchar(5, 'a');
+ std::string *null = nullptr;
#if _LIBCPP_ABI_VERSION == 1
std::string garbage1, garbage2, garbage3, garbage4, garbage5;
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py
===================================================================
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py
@@ -77,6 +77,7 @@
'(%s::u32string) u32_empty = ""'%ns,
'(%s::basic_string<unsigned char, %s::char_traits<unsigned char>, '
'%s::allocator<unsigned char> >) uchar = "aaaaa"'%(ns,ns,ns),
+ '(std::string *) null = nullptr',
])
self.runCmd("n")
@@ -114,6 +115,7 @@
'(%s::u32string) u32_empty = ""'%ns,
'(%s::basic_string<unsigned char, %s::char_traits<unsigned char>, '
'%s::allocator<unsigned char> >) uchar = "aaaaa"'%(ns,ns,ns),
+ '(std::string *) null = nullptr',
])
# The test assumes that std::string is in its cap-size-data layout.
Index: lldb/source/DataFormatters/TypeSummary.cpp
===================================================================
--- lldb/source/DataFormatters/TypeSummary.cpp
+++ lldb/source/DataFormatters/TypeSummary.cpp
@@ -123,6 +123,17 @@
std::string &dest,
const TypeSummaryOptions &options) {
dest.clear();
+
+ if (valobj && valobj->IsPointerType()) {
+ bool success = true;
+ if (!valobj->GetValueAsUnsigned(0, &success)) {
+ if (!success)
+ return false;
+ dest = "nullptr";
+ return true;
+ }
+ }
+
StreamString stream;
if (!m_impl || !m_impl(*valobj, stream, options))
return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77153.253927.patch
Type: text/x-patch
Size: 4210 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200331/430c5b05/attachment-0001.bin>
More information about the lldb-commits
mailing list