[LLVMdev] gdb + clang/llvm

Roland Leißa leissa at cs.uni-saarland.de
Mon Apr 23 16:25:37 PDT 2012


Hi Jim,

thanks for replying. As mentioned in my earlier mail, I have to specify -emit-obj along with -cc1 in order to trigger codegen. This solves the problem for me. 
As I learned from the last email, specifying -v is a good starting point in order to see what actually is happening and tackle such problems.

-- 
Roland

----- Original Message -----
> From: "Jim Grosbach" <grosbach at apple.com>
> To: "Roland Leißa" <leissa at cs.uni-saarland.de>
> Cc: LLVMdev at cs.uiuc.edu
> Sent: Montag, 23. April 2012 14:45:42
> Subject: Re: [LLVMdev] gdb + clang/llvm
> 
> 
> On Apr 23, 2012, at 2:14 PM, Roland Leißa <leissa at cs.uni-saarland.de>
> wrote:
> 
> >>> ok, I now have a problem in the code generator.
> >>> Let's say I want to set a breakpoint somewhere in
> >>> clang/lib/CodeGen/CGExprScalar.cpp
> >>> 
> >>> What do I have to do in order to trigger breakpoints, see
> >>> backtraces and so on?
> >> 
> >> You set a breakpoint and ask to see a backtrace?
> >> 
> >> -eric
> > 
> > haha, OK, I think I should be more specific.
> > 
> > So, I configured the project with:
> >    ../llvm/configure --prefix=PROJECT_DIR/install_debug
> >    --enable-expensive-checks --enable-targets=host
> >    --enable-debug-runtime --enable-shared CXX=g++ CC=gcc
> > 
> > note that I'm  using gcc
> > 
> > then I run
> >    make
> >    make install
> > 
> > next I fire up gdb
> > setting a breakpoint somewhere in clang/lib/Sema  only works if
> > executing clang with -cc1
> > Now the code generation of clang doesn't seem to happen just with
> > -cc1, so I have to elide the switch when having problems somewhere
> > in this area.
> 
> Eh? Codegen most certainly should happen when run with cc1.
> 
> Eliding the option is never the right choice when debugging, unless
> you're debugging the driver itself.
> 
> 
> > Let's say I have a  problem in
> >    clang/lib/CodeGen/CGExprScalar.cpp, line 2742
> > I put
> >    llvm::errs() << "test\n";
> > there in order to verify that this line is really getting executed.
> > Then, I set the breakpoint
> >    break CGExprScalar.cpp :2742
> > and run clang:
> >    r -std=c++11 simple.cpp
> > 
> > 
> > I'm getting this output:
> > 
> > Starting program:
> > /home/rleissa/projects/test/build_debug/Debug+Asserts+Checks/bin/clang
> > -std=c++11 simple.cpp
> > [Thread debugging using libthread_db enabled]
> > Using host libthread_db library "/lib/libthread_db.so.1".
> > test
> > clang:
> > /home/rleissa/projects/test/llvm/lib/VMCore/Instructions.cpp:1475:
> > llvm::InsertElementInst::InsertElementInst(llvm::Value*,
> > llvm::Value*, llvm::Value*, const llvm::Twine&,
> > llvm::Instruction*): Assertion `isValidOperands(Vec, Elt, Index)
> > && "Invalid insertelement instruction operands!"' failed.
> > 0  libLLVM-3.2svn.so 0x00007ffff686f9bd
> > 1  libLLVM-3.2svn.so 0x00007ffff686f715
> > 2  libpthread.so.0   0x00007ffff586f140
> > 3  libc.so.6         0x00007ffff4ae1c35 gsignal + 53
> > 4  libc.so.6         0x00007ffff4ae30b8 abort + 328
> > 5  libc.so.6         0x00007ffff4adac12
> > 6  libc.so.6         0x00007ffff4adacc2
> > 7  libLLVM-3.2svn.so 0x00007ffff6a1a7b3
> > llvm::InsertElementInst::InsertElementInst(llvm::Value*,
> > llvm::Value*, llvm::Value*, llvm::Twine const&,
> > llvm::Instruction*) + 175
> > 8  clang             0x0000000000b64b35
> > 9  clang             0x0000000000b66e5e
> > 10 clang             0x0000000000b997b7
> > 11 clang             0x0000000000ba386d
> > 12 clang             0x0000000000ba2c91
> > 13 clang             0x0000000000b9496d
> > 14 clang             0x0000000000ba1a40
> > clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr
> > const*, bool) + 176
> > 15 clang             0x0000000000c03875
> > clang::CodeGen::CodeGenFunction::EmitReturnStmt(clang::ReturnStmt
> > const&) + 683
> > 16 clang             0x0000000000c01084
> > clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*) +
> > 742
> > 17 clang             0x0000000000c014ff
> > clang::CodeGen::CodeGenFunction::EmitCompoundStmt(clang::CompoundStmt
> > const&, bool, clang::CodeGen::AggValueSlot) + 241
> > 18 clang             0x0000000000c012d6
> > clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt
> > const*) + 226
> > 19 clang             0x0000000000c00de9
> > clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*) + 75
> > 20 clang             0x0000000000c19808
> > clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::CodeGen::FunctionArgList&)
> > + 154
> > 21 clang             0x0000000000c19d11
> > clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl,
> > llvm::Function*, clang::CodeGen::CGFunctionInfo const&) + 971
> > 22 clang             0x0000000000a9025f
> > clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl)
> > + 847
> > 23 clang             0x0000000000a8d2c3
> > clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl)
> > + 445
> > 24 clang             0x0000000000a8cbd2
> > clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) + 754
> > 25 clang             0x0000000000a932ba
> > clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) +
> > 320
> > 26 clang             0x0000000000a8628f
> > 27 clang             0x0000000000a8444c
> > 28 clang             0x0000000000c40b68
> > clang::ParseAST(clang::Sema&, bool, bool) + 453
> > 29 clang             0x00000000008c4dfc
> > clang::ASTFrontendAction::ExecuteAction() + 298
> > 30 clang             0x0000000000a839bc
> > clang::CodeGenAction::ExecuteAction() + 1200
> > 31 clang             0x00000000008c4a31
> > clang::FrontendAction::Execute() + 245
> > 32 clang             0x00000000008982ec
> > clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) +
> > 718
> > 33 clang             0x000000000085f3bc
> > clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 1011
> > 34 clang             0x0000000000847bc1 cc1_main(char const**, char
> > const**, char const*, void*) + 987
> > 35 clang             0x0000000000857ee7 main + 555
> > 36 libc.so.6         0x00007ffff4ace455 __libc_start_main + 245
> > 37 clang             0x0000000000846ca9
> > Stack dump:
> > 0.      Program arguments:
> > /home/rleissa/projects/test/build_debug/Debug+Asserts+Checks/bin/clang
> > -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all
> > -disable-free -main-file-name simple.cpp -mrelocation-model static
> > -mdisable-fp-elim -masm-verbose -mconstructor-aliases
> > -munwind-tables -target-cpu x86-64 -target-linker-version
> > 2.22.0.20120323 -momit-leaf-frame-pointer -resource-dir
> > /home/rleissa/projects/test/build_debug/Debug+Asserts+Checks/bin/../lib/clang/3.2
> > -fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem
> > /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0
> > -internal-isystem
> > /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/x86_64-unknown-linux-gnu
> > -internal-isystem
> > /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/backward
> > -internal-isystem /usr/local/include -internal-isystem
> > /home/rleissa/projects/test/build_debug/Debug+Asserts+Checks/bin/../lib/clang/3.2/include
> > -internal-e!
> > xternc-isystem /include -internal-externc-isystem /usr/include
> > -std=c++11 -fdeprecated-macro -fdebug-compilation-dir
> > /home/rleissa/projects/test/libtest -ferror-limit 19
> > -fmessage-length 274 -mstackrealign -fgnu-runtime
> > -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-fragile-abi
> > -fcxx-exceptions -fexceptions -fdiagnostics-show-option
> > -fcolor-diagnostics -o /tmp/simple-QlxJIj.o -x c++ simple.cpp
> > 1.      <eof> parser at end of file
> > 2.      simple.cpp:22:14: LLVM IR generation of declaration 'test'
> > 3.      simple.cpp:22:14: Generating code for declaration 'test'
> > 4.      simple.cpp:22:53: LLVM IR generation of compound statement
> > ('{}')
> > clang: error: unable to execute command: Aborted
> > clang: error: clang frontend command failed due to signal (use -v
> > to see invocation)
> > clang: note: diagnostic msg: Please submit a bug report to
> > http://llvm.org/bugs/ and include command line arguments and all
> > diagnostic information.
> > clang: note: diagnostic msg: Preprocessed source(s) and associated
> > run script(s) are located at:
> > clang: note: diagnostic msg: /tmp/simple-Rkocwp.ii
> > clang: note: diagnostic msg: /tmp/simple-Rkocwp.sh
> > [Inferior 1 (process 8392) exited with code 0376]
> > 
> > 
> > As you can see the line is question is executed but the breakpoint
> > is not triggered. Apparently, clang executes the code generation
> > in a different process. What do I have to do in order to debug
> > this process?
> > 
> > --
> > Roland
> > 
> > _______________________________________________
> > LLVM Developers mailing list
> > LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> 
> 




More information about the llvm-dev mailing list