Hi Enrico/Greg,
Can you help me to understand what is the difference between "p" and "fr v"
command to print local variables? My data formatter works fine in all cases
of "fr v", and will fail for "p" command in some case(implementation at the
end). In the debug log output below, you can see, when I use "fr v" command
the "char[24]" object is summarized correctly, while "p" command fail to
recognize it. I suspect "char32_t [] summary provider" may have failed in
"p" case, but could not understand why.
(lldb) p small
folly_stl_string_formatter: $2 $2
folly_fbstring_core: store_ $2.store_ [115L, 109L, 97L, 108L, 108L, 0L, 0L,
0L, 235L, 46L, 64L, 0L, 0L, 0L, 0L, 0L, 80L, 213L, 255L, 255L, 255L, 127L,
0L, 18L]
category: 0
obj: (char [24]) small_ = {
[0] = 's'
[1] = 'm'
[2] = 'a'
[3] = 'l'
[4] = 'l'
[5] = '\0'
[6] = '\0'
[7] = '\0'
[8] = '\xeb'
[9] = '.'
[10] = '@'
[11] = '\0'
[12] = '\0'
[13] = '\0'
[14] = '\0'
[15] = '\0'
[16] = 'P'
[17] = '\xd5'
[18] = '\xff'
[19] = '\xff'
[20] = '\xff'
[21] = '\x7f'
[22] = '\0'
[23] = '\x12'
}, None, None
(std::string) $2 = None
(lldb) fr v small
folly_stl_string_formatter: small small
folly_fbstring_core: store_ small.store_ [115L, 109L, 97L, 108L, 108L, 0L,
0L, 0L, 235L, 46L, 64L, 0L, 0L, 0L, 0L, 0L, 80L, 213L, 255L, 255L, 255L,
127L, 0L, 18L]
category: 0
obj: (char [24]) small_ = "small", "small", None
(std::string) small = "small"
===
import lldb
target_byte_order = lldb.target.GetByteOrder()
def get_category_value(category_sbvalue, category_extract_mask):
return category_sbvalue.unsigned & category_extract_mask
def folly_stl_string_formatter(valobj, internal_dict):
'''Type summary formatter for std::string implemented by folly
fbstring_core.
'''
print 'folly_stl_string_formatter: %s %s' % (valobj.name, valobj.path)
folly_fbstring_sbvalue = valobj.GetValueForExpressionPath('.store_')
return folly_fbstring_core_formatter(folly_fbstring_sbvalue,
internal_dict)
def folly_fbstring_core_formatter(valobj, internal_dict):
'''Type summary formatter for folly fbstring_core.
Please refer to
https://github.com/facebook/folly/blob/master/folly/FBString.h
for implementation details.
'''
print 'folly_fbstring_core: %s %s %s' % (valobj.name, valobj.path,
str(valobj.data.uint8s))
capacity_sbvalue = valobj.GetValueForExpressionPath('.ml_.capacity_')
category_extract_mask = 0x3 if target_byte_order == lldb.eByteOrderBig
else \
(0xC000 if capacity_sbvalue.size == 4 else 0xC000)
class Category:
Small = 0
Medium = (0x2 if target_byte_order == lldb.eByteOrderBig else
(0x8000 if capacity_sbvalue.size == 4 else
0x8000))
Large = (0x2 if target_byte_order == lldb.eByteOrderBig else
(0x4000 if capacity_sbvalue.size == 4 else
0x4000))
category = get_category_value(capacity_sbvalue, category_extract_mask)
print 'category: %s' % category
if category == Category.Small:
obj = valobj.GetValueForExpressionPath('.small_')
print 'obj: %s, %s, %s' % (obj, obj.summary, obj.description)
return valobj.GetValueForExpressionPath('.small_').GetSummary()
else:
assert category == Category.Medium or category == Category.Large, \
'Unknown category: %d' % category
return valobj.GetValueForExpressionPath('.ml_.data_').GetSummary()
def __lldb_init_module(debugger, internal_dict):
debugger.HandleCommand('type summary add -F
data_formatter.folly_fbstring_core_formatter \
std::fbstring_core')
debugger.HandleCommand('type summary add -F
data_formatter.folly_fbstring_core_formatter \
std::fbstring_core')
debugger.HandleCommand('type summary add -F
data_formatter.folly_stl_string_formatter \
std::string')
debugger.HandleCommand('type summary add -F
data_formatter.folly_stl_string_formatter \
std::wstring')
On Wed, Apr 20, 2016 at 4:02 PM, Jeffrey Tan
wrote:
> After removing the "-x" and apply the formatter to "std::string" instead
> of fbstring_core, it works fine now. Thanks!
>
> On Wed, Apr 20, 2016 at 3:24 PM, Enrico Granata
> wrote:
>
>>
>> On Apr 20, 2016, at 3:08 PM, Jeffrey Tan wrote:
>>
>> Hi Enrico,
>>
>> Instead of trying function-evaluation c_str(), I decided to decode the
>> information from fbstring_core fields. I got it working but have two
>> questions for it.
>>
>> type summary add -F data_formatter.folly_string_formatter -x
>> "std::fbstring_core"
>>
>> Here is the output:
>>
>> fr v -T small
>> (std::string) small = "small"
>>
>> fr v -T small.store_
>> (std::fbstring_core) small.store_ = None
>>
>> fr v -T small.store_.ml_
>> (std::fbstring_core::MediumLarge) small.store_.ml_ = None
>>
>> Questions:
>> 1. Even I only added formatter for std::fbstring_core why does it
>> work for std::string?
>> 2. Why the later small.store_ and smal