debugging a pass for LTO

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?

btw, "llvm-gcc -use-gold-plugin" works fine when I compile my program.

Thanks very much.

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.

Sorry I don't know if I‘m correct here. I'm a beginner with llvm.

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