Printing while developing on LLVM/Clang code

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Printing while developing on LLVM/Clang code

Deep Majumder via cfe-dev
Hi everyone,
I have found that `print <expr>` often doesn't work while running a debug build of clang in lldb. So I have to resort to print statements. Since <iostream> is not used inside LLVM/Clang code, I have to include it in manually and remember to remove it before committing. Is there a better way to do this, either in lldb or insert print statements?
Warm regards,
Deep

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] Printing while developing on LLVM/Clang code

Deep Majumder via cfe-dev
On 2/11/2021 13:20, Deep Majumder via llvm-dev wrote:
> Hi everyone,
> I have found that `print <expr>` often doesn't work while running a
> debug build of clang in lldb. So I have to resort to print statements.
> Since <iostream> is not used inside LLVM/Clang code, I have to include
> it in manually and remember to remove it before committing. Is there a
> better way to do this, either in lldb or insert print statements?

Depending on the type of <expr> it's also worth trying `print
<expr>.dump()` or `print <expr>.print()`.

See: https://bholt.org/posts/llvm-debugging.html,
https://llvm.org/docs/WritingAnLLVMPass.html#the-print-method,
https://clang.llvm.org/hacking.html#debugging

Otherwise this may come in handy:
LLVM_DEBUG(dbgs() << "I am here!\n");

See:
https://llvm.org/docs/ProgrammersManual.html#the-llvm-debug-macro-and-debug-option

Don't forget to enable it: "One additional nice thing about the
LLVM_DEBUG() macro is that you can enable or disable it directly in gdb.
Just use “set DebugFlag=0” or “set DebugFlag=1” from the gdb if the
program is running. If the program hasn’t been started yet, you can
always just run it with -debug."

Best,
Matt
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] Printing while developing on LLVM/Clang code

Deep Majumder via cfe-dev
In reply to this post by Deep Majumder via cfe-dev
dump functions, as Matt mentioned, are probably the immediate go-to.
Otherwise if you want to improve 'print <expr>' support, it probably
involves writing pretty printers like/in here:
llvm/utils/lldbDataFormatters.py

On Thu, Feb 11, 2021 at 4:20 AM Deep Majumder via llvm-dev
<[hidden email]> wrote:
>
> Hi everyone,
> I have found that `print <expr>` often doesn't work while running a debug build of clang in lldb. So I have to resort to print statements. Since <iostream> is not used inside LLVM/Clang code, I have to include it in manually and remember to remove it before committing. Is there a better way to do this, either in lldb or insert print statements?
> Warm regards,
> Deep
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev