[lldb-dev] Supporting new source languages

Carlo Kok ck at remobjects.com
Thu Jan 16 13:05:49 PST 2014


On Thu, 16 Jan 2014 21:59:42 +0100, Greg Clayton <gclayton at apple.com>  
wrote:

>> Just an idea anyway. I've been trying to see how to fit my (pascal)  
>> language into lldb, but due to the way it's designed (the compiler),  
>> it's not feasible to compile a single expression/method into IR and  
>> transfer it over (Besides that, it's written in another language than  
>> c++).
>
> That means creating your own expression parser that won't be language  
> compliant, and is the whole reason we are generating clang AST types  
> from DWARF: to avoid having top write an expression parser when the  
> compiler is the best expression parser we could ever have.
>
> Things we can do in our expression parser that other debuggers can't:
> - create expression local variables ("int i = 12; int j = 23; i+j")
> - use flow control (if/then/else, while, do/while, switch, etc)
> - create types and use them in the expression ("struct foo { int x;  
> float y; }; foo = { 123, 2.3 }; foo")
> - much much more!
>
> So the one great thing we can do, is just re-compile clang and we get  
> all the new language features (C++11, etc) for free. If we maintain a  
> separate expression parser that isn't in the compiler, then you do all  
> this work manually. We also use the clang expression parser to avoid  
> running into errors when calling functions as it is very complex to  
> figure out which arguments go where in expressions. When we call a  
> function in the JIT, we give clang a structure in memory that contains  
> all arguments and let it call the function correctly. So there is way  
> too much stuff we would need to re-code, so the hard fight to translate  
> DWARF into compiler types ends up being well worth it on the long run.

Hrmm true yes. Maybe there could be a way to generate clang expressions  
 from code (not string) and accessing the "clang" type info tables the  
clang expressions have access to? So languages could start with (or stay  
with?) using clang structures as a fairly simple api for expression  
evaluators?

-- 
Carlo Kok
RemObjects Software



More information about the lldb-dev mailing list