[SAoC] MLIR Support for LDC

Stefanos Baziotis sdi1600105 at di.uoa.gr
Wed Sep 25 21:51:31 UTC 2019

On Wednesday, 25 September 2019 at 13:30:20 UTC, Roberto 
Rosmaninho wrote:
> On Wednesday, 25 September 2019 at 10:42:46 UTC, Stefanos 
> Baziotis wrote:
> Thanks a lot!! It'll make my work much easier!!

I'm glad!

> This seems powerful due the huge time to compile LDC just 
> because of single modification. I'll try it!

Yes, for me it was crucial. You can do the same thing for more 
Basically, as long as you change only LDC files.

> I have set up my project on Ubuntu as well, so if you know 
> something about debugging on Linux and can explain it in 
> greater detail it'll help anyway!

IMO, for the most part the debugging experience on Linux is 
horrible. :)
If you're lucky, because LDC is mostly C++, you may be able to get
CLion to work. Or make Visual Studio Code work as a GUI for GDB 
(I have not
done either of those, so I can't provide further info, but 
there's info
on the Internet).
The common case though is that you're stuck with GDB, which while 
its terminal interface personally drives me crazy.

But, enough with bashing on GDB. I debug LDC mostly with printfs, 
but when
these don't work, here's what I do:

Note: I will cover some basics in case you know nothing about GDB.
I'm not a GDB guru anyway, but these will help you in most 

== Case 1 - You want to break in LDC / LLVM code ==

This is the easiest case. You just run the executable through 
gdb, then
break on a specific line by specifying the _full_ path. For 
example, I
have my ldc repo in: /home/stefanos/dlang/ldc/

$ gdb /home/stefanos/dlang/ldc/build/bin/ldc2
... GDB opens. Inside GDB:
$ break /home/stefanos/dlang/ldc/gen/statements.cpp:289

to break on line 289 on gen/statements.cpp

You can similarly break into a function, e.g.

$ break ToIRVisitor::visit(IfStatement*)

using tab for autocomplete.

Similarly, you can break in LLVM code, e.g.:

$ break llvm::BasicBlock::Create(llvm::LLVMContext&, llvm::Twine 
const&, llvm::Function*, llvm::BasicBlock*)

again using autocomplete.

== Case 2 - You want to break in DMD code ==

For that, I'd recommend using the dmd executable, built with dmd.
Basically, doing what you would do if you were working on DMD. 
So, you download
the DMD version you want and do the same debugging steps.
You just have better debugging experience when DMD is built with 

For now, you can forget what I said about listing functions and 
stuff. I can't remember why I had needed that.

Best regards,

More information about the Digitalmars-d mailing list