[lldb-dev] synthetic for std::wstring

Enrico Granata granata.enrico at gmail.com
Tue Feb 28 08:59:37 PST 2012


Hi. Replies are inlined.

On Feb 28, 2012, at 7:55 AM, Nino Kettlitz wrote:

> Hi,
> 
> are there any Python scripts to debug a std::wstring (i.e. std::basic_string<int> in osx)?
> It would be very useful, especially when debugging a vector of strings (i.estd::vector< std::wstring >)
> 
> After searching a while in the internet I found nothing, so I started to write my own Python class for generating synthetic children (exactly one chiled, i.e. the string itself),

Since you're only really producing one child value, it looks like you may want to provide a summary for the wstring instead of synthetic children.

> but there are several problems I could not solve.
> 
> My test programm looks as follows:
> 
>    std::vector< std::wstring > aWideStringVector;
>    aWideStringVector.push_back(L"Filter/EQ");
>    aWideStringVector.push_back(L"Lowpass Filter");
>    aWideStringVector.push_back(L"Wah Wah");
>    aWideStringVector.push_back(L"Pitch Shift");
>    aWideStringVector.push_back(L"Highpass Filter");
>    aWideStringVector.push_back(L"Bandpass Filter");
> 
> I registered the synthetic children class with type synthetic add -x "^(std::)?basic_string<.+>" --python-class wstring.StdWStringSynthProvider but
> 

You are trying to bind a synthetic children provider to *every* std::basic_string<T>? Why?
Again, I think a summary for std::wstring (and std::basic_string<wchar_t>) would be enough for the purpose.

> frame variable aWideStringVector
> 
> gives me
> 
> (vector<std::basic_string<wchar_t>, std::allocator<std::basic_string<wchar_t> > >) aWideStringVector = {
> }
> 

What version of LLDB are you using? (LLDB has a "version" command you can use) This looks like an issue with the built-in synthetic children provider for class std::vector.

In order to test *your* wstring provider, you should have a single variable of type std::wstring and try to "frame variable" that one variable. Here, your entry point is the synthetic children provider for std::vector.

> and
> 
> frame variable aWideStringVector[0]
> 
> gives me
> 
> error: array index 0 is not valid for "(vector<std::basic_string<wchar_t>, std::allocator<std::basic_string<wchar_t> > >) aWideStringVector"
> 

again, what you're doing here is asking the std::vector synthetic children provider (built into LLDB) to provide you with child at index 0 - your wstring provider is not being invoked at this moment.

> Am I doing something wrong?
> Is it in general a good idea to debug a std::wstring with synthetic children?
> 

1) Probably not - if you're using a recent version of LLDB then this issue might need further testing. Otherwise, it seems a good idea to retry this with TOT
2) Again, I would just use a summary string provider. On LLDB TOT, the attached Python file (which is a very slightly modified version of what you sent) works well in providing a summary for std::wstring

(lldb) command script import wstring.py
(lldb) type summary add --python-function wstring.wstring_summary std::wstring
(lldb) frame variable
(std::wstring) foo = hello world

> thanks,
> Nino
> <wstring.py>_______________________________________________
> lldb-dev mailing list
> lldb-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wstring.py
Type: text/x-python-script
Size: 448 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20120228/392d5093/attachment.bin>


More information about the lldb-dev mailing list