[lldb-dev] A bit of extra-polish for my lldb plugin

Jim Ingham via lldb-dev lldb-dev at lists.llvm.org
Wed May 31 11:40:44 PDT 2017

Pavel, can you say more about your idea?  

In both ObjC and C++ methods, you can refer to an ivar either as "this->ivar" or just "ivar".  But the DWARF for C++ doesn't tell lldb that a particular language supports referring to ivars transparently this way.  It will say that the "this" parameter is artificial, and that it is the "object pointer".  But it doesn't so far as I can tell record the fact that elements of that parameter can be transparently accessed.

I think it would be confusing for the debug information to record the transparently accessed ivars as pseudo-locals, the duplication would confuse folks, and that isn't how they are understood by the person writing the code.  It might be good to propose a "DW_AT_transparent" attribute, and mark the ivars or maybe the parameter that way.  I guessing that wasn't done because it was assumed that the debugger would know this sort of rule from the language in question.

As I understand it, problem here is that Nat's runtime has extra rules for transparent access that lldb doesn't know about.


> On May 31, 2017, at 3:20 AM, Pavel Labath <labath at google.com> wrote:
> I think the cleanest solution would be to actually modify the compiler
> to emit "correct" dwarf (as in, dwarf representing the code as it
> actually looks like to user, and not some internal intermediate
> representation). The dwarf expression in DW_AT_location can easily
> handle the lookup of some field in a struct. Of course, this is
> assuming you are actually able to modify the compiler.
> (disclaimer: I know next to nothing, when it comes to objc)
> On 26 May 2017 at 23:25, Jim Ingham via lldb-dev
> <lldb-dev at lists.llvm.org> wrote:
>> Because we try as much as possible to let the compiler figure this sort of thing out for us, we implement the transparent lookups for this & self by compiling our expression in a context that poses as a method of the class whose method we are stopped in.  For instance, for ObjC, we construct a category on the class, and put the expression text in a method in that category, and then compile all that and call the method.
>> That's done in ExpressionSourceCode::GetText.
>> The one hitch to this is that this works because the compiler that is linked into lldb knows about the ObjC model we are emulating.  An unmodified clang won't do transparent lookup into some random argument that happens to be called _param.  So you would have to build lldb with a version of clang that understands your lookup rules for this to work.
>> If that's not possible then you can try to do this by monkeying with the lookup rules implemented by lldb's ClangASTSource to return "_param.a" when it is just looking up "a".  That's how we inject variables and types that are present in the local context into the expression as it is getting parsed.  But at that point you are getting your hands into some fairly deep magic, and clang's Aslan is not as forgiving as Narnia's...
>> Jim
>>> On May 26, 2017, at 2:27 PM, Nat! via lldb-dev <lldb-dev at lists.llvm.org> wrote:
>>> Let me show you a snippet of a lldb debug session in progress in my ObjC
>>> variant:
>>> ```
>>> -100000,100000,v,18.48
>>> Process 45774 stopped
>>> * thread #1, queue = 'com.apple.main-thread', stop reason = step in
>>>   frame #0: 0x0000000100000e2a multiple.debug`+[Foo
>>> long:int:char:float:](self=Foo, _cmd=<no value available>,
>>> _param=0x00007fff5fbff948) at multiple.m:15
>>>  12                   char:(char) c
>>>  13                  float:(float) d
>>>  14          {
>>>  15             printf( "%ld,%d,%c,%.2f\n", a, b, c, d);
>>> -> 16         }
>>>  17
>>>  18          @end
>>> (lldb) p *_param
>>> (p.long:int:char:float:) $2 = (a = -100000, b = 100000, c = 'v', d =
>>> 18.4799995)
>>> ```
>>> You can see that the parameter values `a,b,c,d` are actually fields of
>>> a struct parameter `_param`. `_param` uniformly appears as the third
>>> parameter after `self` and `_cmd`. `p _param->a` works of course, but it
>>> would be nice to be able to say 'p a', since in the source code one sees
>>> only `a`. `_param` is more or less an implementation detail.
>>> A clue how to achieve this, would be very much appreciated.
>>> Ciao
>>>  Nat!
>>> [*] except, if it's a picture of thousand words :)
>>> https://www.mulle-kybernetik.com/weblog/2015/mulle_objc_meta_call_convention.html
>>> _______________________________________________
>>> lldb-dev mailing list
>>> lldb-dev at lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev
>> _______________________________________________
>> lldb-dev mailing list
>> lldb-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev

More information about the lldb-dev mailing list