[LLVMdev] debugging a pass for LTO

Nick Lewycky nicholas at mxc.ca
Sun Jan 24 11:30:30 PST 2010


jiaqi zhang wrote:
> Thank you very much for your suggestions. That's very helpful.
>
> However, since I'm trying to compile several somewhat large projects,
> I assume generating bitcode for each single file and linking them
> together might be painful (I don't want to modify too much the project
> makefiles). So I hope my pass can be used just with simple compilation
> command like
>
> "llvm-gcc -use-gold-plugin"
>
> instead of first generating bitcode, linking them, and then applying
> the pass with opt.

If what you want to do is debug your pass then the easiest thing to do 
is to run just your pass over the appropriate bitcode using 'opt 
-mypassname' under gdb, as that runs only your pass over your input file 
without any other complex code (like a linker) involved. You should also 
make sure you're familiar with bugpoint and how you can apply it to 
solve your testcase-reduction problems.

To add your pass to the set used by the gold plugin, add it to 
createStandardLTOPasses in include/llvm/Support/StandardPasses.h. 
Running 'llvm-gcc' under gdb won't help, as it just turns around and 
forks collect2 and other programs. Run llvm-gcc with the -v flag to see 
what it's actually running and figure out how to run 'ld' directly, so 
that you can launch it from gdb.

Nick

> Sorry I don't know if I‘m correct here. I'm a beginner with llvm.
>
> On Fri, Jan 22, 2010 at 11:50 AM, John Criswell<criswell at uiuc.edu>  wrote:
>> jiaqi zhang wrote:
>>>
>>> Hi,
>>>
>>> I'm trying to write a pass for LTO, and now I want to debug it using
>>> gdb. I use ld as my target file, but when I run the program in gdb, it
>>> reports
>>>
>>> [Thread debugging using libthread_db enabled]
>>> Cannot find new threads: generic error
>>>
>>> at
>>>
>>> Plugin::load()
>>> {
>>> #ifdef ENABLE_PLUGINS
>>>   this->handle_ = dlopen(this->filename_.c_str(), RTLD_NOW);
>>>
>>> in binutil/src/gold/plugin.cc
>>>
>>> The gdb version is 7.0.1. I tried it with other multi-threaded
>>> programs without any problem. Have I missed something? Or I shouldn't
>>> debug my pass this way at all?
>>>
>>
>> Probably the best approach is to use llvm-ld to link the bitcode files
>> together and then run your pass using opt or bugpoint to try to debug it.
>>
>> This approach can be very useful as you can use bugpoint to reduce the test
>> case.
>>
>> -- John T.
>>
>>> btw, "llvm-gcc -use-gold-plugin" works fine when I compile my program.
>>>
>>>
>>>
>>>
>>>
>>> Thanks very much.
>>>
>>>
>>>
>>
>>
>
>
>




More information about the llvm-dev mailing list