[LLVMdev] assert when mixing static and non-static members with an external AST source

Thirumurthi, Ashok ashok.thirumurthi at intel.com
Fri Feb 15 07:00:42 PST 2013


FYI, this turned out to be an error of omission in LLDB in SymbolFileDWARF, because the case of a non-defining external (i.e. a static member variable) wasn't being handled with a variable lookup to dig up the location.  I'll put a patch together for lldb-commits,


-        Ashok

From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of Thirumurthi, Ashok
Sent: Friday, February 08, 2013 5:59 PM
To: llvmdev at cs.uiuc.edu
Cc: Greg Clayton
Subject: [LLVMdev] assert when mixing static and non-static members with an external AST source

So, when performing expression evaluation, lldb trips over an assert in clang/lib/AST/RecordLayoutBuilder because ExternalFieldOffsets doesn't contain a FieldDecl that updateExternalFieldOffset expected.  I found that the assert occurs when both static and non-static member variables are present.  For instance, with the following, the lldb command 'expr my_test.length()' does not assert unless m_a is declared:

class test
{
    static const int npos = -1;
    int m_a;

public:
    int length() { return npos; }
};

The problem reproduces with Linux x86_64 targets, but not on Darwin.  The issue was introduced in the last month or so, but I'm not sure if it's an issue with lldb or clang.  The problem isn't related to the order of the definition of npos and m_a.  It reproduces with "static int npos" as well.  Any thoughts on how to dig deeper into this interaction would be appreciated.  Some steps to reproduce and stack trace below.  Thanks,


-        Ashok Thirumurthi

clang++ -gdwarf-2 -O0     -c -o main.o main.cpp
clang++ -gdwarf-2 -O0    -arch x86_64  main.o  -o "a.out"

$ lldb a.out
(lldb) b main.cpp:13
(lldb) r
   10        int main (int argc, char const *argv[])
   11        {
   12            test my_test;
-> 13          my_test.length();
   14        }
(lldb) expr my_test.length()
lldb: /home/athirumurthi/git/lldb/tools/clang/lib/AST/RecordLayoutBuilder.cpp:2269: uint64_t <anonymous namespace>::RecordLayoutBuilder::updateExternalFieldOffset(const clang::FieldDecl *, uint64_t): Assertion `ExternalFieldOffsets.find(Field) != ExternalFieldOffsets.end() && "Field does not have an external offset"' failed.


#3  0x00007ffff27c5192 in __GI___assert_fail (
    assertion=0x7ffff69416ce "ExternalFieldOffsets.find(Field) != ExternalFieldOffsets.end() && \"Field does not have an external offset\"",
    file=0x7ffff693e8fe "/home/athirumurthi/git/lldb/tools/clang/lib/AST/RecordLayoutBuilder.cpp", line=2269,
    function=0x7ffff6941739 "uint64_t <anonymous namespace>::RecordLayoutBuilder::updateExternalFieldOffset(const clang::FieldDecl *, uint64_t)") at assert.c:103
#4  0x00007ffff49f136a in (anonymous namespace)::RecordLayoutBuilder::updateExternalFieldOffset (this=0x7fffffff5328, Field=0xbedad0, ComputedOffset=0)
    at /home/athirumurthi/git/lldb/tools/clang/lib/AST/RecordLayoutBuilder.cpp:2268
#5  0x00007ffff49f00a0 in (anonymous namespace)::RecordLayoutBuilder::LayoutField (this=0x7fffffff5328, D=0xbedad0)
    at /home/athirumurthi/git/lldb/tools/clang/lib/AST/RecordLayoutBuilder.cpp:2134
#6  0x00007ffff49f3669 in (anonymous namespace)::RecordLayoutBuilder::LayoutFields (this=0x7fffffff5328, D=0xbed9c0)
    at /home/athirumurthi/git/lldb/tools/clang/lib/AST/RecordLayoutBuilder.cpp:1833
#7  0x00007ffff49ed73e in (anonymous namespace)::RecordLayoutBuilder::Layout (this=0x7fffffff5328, RD=0xbed9c0)
    at /home/athirumurthi/git/lldb/tools/clang/lib/AST/RecordLayoutBuilder.cpp:1649
#8  0x00007ffff49ed151 in clang::ASTContext::getASTRecordLayout (this=0xbc8820, D=0xbed9c0)
    at /home/athirumurthi/git/lldb/tools/clang/lib/AST/RecordLayoutBuilder.cpp:2430
#9  0x00007ffff433d48f in lldb_private::ClangASTSource::layoutRecordType (this=0xcb6f00, record=0xd6a140, size=@0x7fffffff6388: 4, alignment=@0x7fffffff6390: 29,
    field_offsets=..., base_offsets=..., virtual_base_offsets=...) at /home/athirumurthi/git/lldb/tools/lldb/source/Expression/ClangASTSource.cpp:1456
#10 0x00007ffff436b0ff in lldb_private::ClangASTSource::ClangASTSourceProxy::layoutRecordType(clang::RecordDecl const*, unsigned long&, unsigned long&, llvm::DenseMap<clang::FieldDecl const*, unsigned long, llvm::DenseMapInfo<clang::FieldDecl const*> >&, llvm::DenseMap<clang::CXXRecordDecl const*, clang::CharUnits, llvm::DenseMapInfo<clang::CXXRecordDecl const*> >&, llvm::DenseMap<clang::CXXRecordDecl const*, clang::CharUnits, llvm::DenseMapInfo<clang::CXXRecordDecl const*> >&) ()
   from /home/athirumurthi/git/lldb/install/bin/../lib/liblldb.so
#11 0x00007ffff49ef879 in (anonymous namespace)::RecordLayoutBuilder::InitializeLayout (this=0x7fffffff60d8, D=0xd6a140)
    at /home/athirumurthi/git/lldb/tools/clang/lib/AST/RecordLayoutBuilder.cpp:1615
#12 0x00007ffff49ed71b in (anonymous namespace)::RecordLayoutBuilder::Layout (this=0x7fffffff60d8, RD=0xd6a140)
    at /home/athirumurthi/git/lldb/tools/clang/lib/AST/RecordLayoutBuilder.cpp:1644
#13 0x00007ffff49ed151 in clang::ASTContext::getASTRecordLayout (this=0xd52ce0, D=0xd6a140)
    at /home/athirumurthi/git/lldb/tools/clang/lib/AST/RecordLayoutBuilder.cpp:2430
#14 0x00007ffff4c46af0 in (anonymous namespace)::CGRecordLayoutBuilder::Layout (this=0x7fffffff66a8, D=0xd6a140)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp:208
#15 0x00007ffff4c461ab in clang::CodeGen::CodeGenTypes::ComputeRecordLayout (this=0xd63d90, D=0xd6a140, Ty=0xd65c10)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp:969
#16 0x00007ffff4cce43f in clang::CodeGen::CodeGenTypes::ConvertRecordDeclType (this=0xd63d90, RD=0xd6a140)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CodeGenTypes.cpp:637
#17 0x00007ffff4ccce5e in clang::CodeGen::CodeGenTypes::ConvertType (this=0xd63d90, T=...) at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CodeGenTypes.cpp:295
#18 0x00007ffff4cccd67 in clang::CodeGen::CodeGenTypes::ConvertTypeForMem (this=0xd63d90, T=...)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CodeGenTypes.cpp:88
#19 0x00007ffff4ccd201 in clang::CodeGen::CodeGenTypes::ConvertType (this=0xd63d90, T=...) at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CodeGenTypes.cpp:403
#20 0x00007ffff4cccd67 in clang::CodeGen::CodeGenTypes::ConvertTypeForMem (this=0xd63d90, T=...)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CodeGenTypes.cpp:88
#21 0x00007ffff4c7bb64 in clang::CodeGen::CodeGenModule::GetAddrOfGlobalVar (this=0xd63cf0, D=0xd6a500, Ty=0x0)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CodeGenModule.cpp:1490
#22 0x00007ffff4b92ae9 in EmitGlobalVarDeclLValue (CGF=..., E=0xd6a558, VD=0xd6a500) at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CGExpr.cpp:1586
#23 0x00007ffff4b8abd7 in clang::CodeGen::CodeGenFunction::EmitDeclRefLValue (this=0x7fffffff9198, E=0xd6a558)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CGExpr.cpp:1659
#24 0x00007ffff4b851aa in clang::CodeGen::CodeGenFunction::EmitLValue (this=0x7fffffff9198, E=0xd6a558)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CGExpr.cpp:723
#25 0x00007ffff4baaf35 in clang::CodeGen::CodeGenFunction::EmitCXXMemberCallExpr (this=0x7fffffff9198, CE=0xd6a5b0, ReturnValue=...)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CGExprCXX.cpp:234
#26 0x00007ffff4b94c41 in clang::CodeGen::CodeGenFunction::EmitCallExpr (this=0x7fffffff9198, E=0xd6a5b0, ReturnValue=...)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CGExpr.cpp:2696
#27 0x00007ffff4bdbbe4 in (anonymous namespace)::ScalarExprEmitter::VisitCallExpr (this=0x7fffffff7d98, E=0xd6a5b0)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CGExprScalar.cpp:282
#28 0x00007ffff4bdbc68 in clang::StmtVisitorBase<clang::make_ptr, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::VisitCXXMemberCallExpr (this=0x7fffffff7d98,
    S=0xd6a5b0) at /home/athirumurthi/git/lldb/build/tools/clang/lib/CodeGen/../../include/clang/AST/StmtNodes.inc:283
#29 0x00007ffff4bd7bb5 in clang::StmtVisitorBase<clang::make_ptr, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit (this=0x7fffffff7d98, S=0xd6a5b0)
    at /home/athirumurthi/git/lldb/build/tools/clang/lib/CodeGen/../../include/clang/AST/StmtNodes.inc:283
#30 0x00007ffff4bce7b8 in (anonymous namespace)::ScalarExprEmitter::Visit (this=0x7fffffff7d98, E=0xd6a5b0)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CGExprScalar.cpp:162
#31 0x00007ffff4bce758 in clang::CodeGen::CodeGenFunction::EmitScalarExpr (this=0x7fffffff9198, E=0xd6a5b0, IgnoreResultAssign=false)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CGExprScalar.cpp:3042
#32 0x00007ffff4b6b751 in clang::CodeGen::CodeGenFunction::EmitScalarInit (this=0x7fffffff9198, init=0xd6a5b0, D=0xd6a630, lvalue=..., capturedByInit=false)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CGDecl.cpp:536
#33 0x00007ffff4b75d22 in EmitDeclInit (CGF=..., D=..., DeclPtr=0xd83068) at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CGDeclCXX.cpp:46
#34 0x00007ffff4b758c7 in clang::CodeGen::CodeGenFunction::EmitCXXGlobalVarDeclInit (this=0x7fffffff9198, D=..., DeclPtr=0xd83068, PerformInit=true)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CGDeclCXX.cpp:134
#35 0x00007ffff4cd726f in (anonymous namespace)::ItaniumCXXABI::EmitGuardedInit (this=0xd64510, CGF=..., D=..., var=0xd83068, shouldPerformInit=true)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/ItaniumCXXABI.cpp:1117
#36 0x00007ffff4b766ce in clang::CodeGen::CodeGenFunction::EmitCXXGuardedInit (this=0x7fffffff9198, D=..., DeclPtr=0xd83068, PerformInit=true)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CGDeclCXX.cpp:215
#37 0x00007ffff4b6b3da in clang::CodeGen::CodeGenFunction::AddInitializerToStaticVarDecl (this=0x7fffffff9198, D=..., GV=0xd83068)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CGDecl.cpp:232
#38 0x00007ffff4b6a94c in clang::CodeGen::CodeGenFunction::EmitStaticVarDecl (this=0x7fffffff9198, D=..., Linkage=llvm::GlobalValue::InternalLinkage)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CGDecl.cpp:311
#39 0x00007ffff4b6a6f6 in clang::CodeGen::CodeGenFunction::EmitVarDecl (this=0x7fffffff9198, D=...) at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CGDecl.cpp:128
#40 0x00007ffff4b6a4e7 in clang::CodeGen::CodeGenFunction::EmitDecl (this=0x7fffffff9198, D=...) at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CGDecl.cpp:93
#41 0x00007ffff4c52a65 in clang::CodeGen::CodeGenFunction::EmitDeclStmt (this=0x7fffffff9198, S=...)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CGStmt.cpp:809
#42 0x00007ffff4c4e2a5 in clang::CodeGen::CodeGenFunction::EmitSimpleStmt (this=0x7fffffff9198, S=0xd6a688)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CGStmt.cpp:176
#43 0x00007ffff4c4dbb7 in clang::CodeGen::CodeGenFunction::EmitStmt (this=0x7fffffff9198, S=0xd6a688)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CGStmt.cpp:47
#44 0x00007ffff4c5288e in clang::CodeGen::CodeGenFunction::EmitCompoundStmt (this=0x7fffffff9198, S=..., GetLast=false, AggSlot=...)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CGStmt.cpp:203
#45 0x00007ffff4c4e283 in clang::CodeGen::CodeGenFunction::EmitSimpleStmt (this=0x7fffffff9198, S=0xd6a608)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CodeGenFunction.h:2005
#46 0x00007ffff4c4dbb7 in clang::CodeGen::CodeGenFunction::EmitStmt (this=0x7fffffff9198, S=0xd6a608)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CGStmt.cpp:47
#47 0x00007ffff4c6ca7e in clang::CodeGen::CodeGenFunction::EmitFunctionBody (this=0x7fffffff9198, Args=...)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CodeGenFunction.cpp:489
#48 0x00007ffff4c6ce8d in clang::CodeGen::CodeGenFunction::GenerateCode (this=0x7fffffff9198, GD=..., Fn=0xd61b30, FnInfo=...)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CodeGenFunction.cpp:557
#49 0x00007ffff4c7ab86 in clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition (this=0xd63cf0, GD=...)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CodeGenModule.cpp:2115
#50 0x00007ffff4c77e17 in clang::CodeGen::CodeGenModule::EmitGlobalDefinition (this=0xd63cf0, GD=...)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CodeGenModule.cpp:1204
#51 0x00007ffff4c79fd5 in clang::CodeGen::CodeGenModule::EmitGlobal (this=0xd63cf0, GD=...) at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CodeGenModule.cpp:1080
#52 0x00007ffff4c80143 in clang::CodeGen::CodeGenModule::EmitTopLevelDecl (this=0xd63cf0, D=0xd6a090)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/CodeGenModule.cpp:2783
#53 0x00007ffff4cdaf54 in (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl (this=0xd5cde0, DG=...)
    at /home/athirumurthi/git/lldb/tools/clang/lib/CodeGen/ModuleBuilder.cpp:69
#54 0x00007ffff4332dd3 in lldb_private::ASTResultSynthesizer::HandleTopLevelDecl (this=0xd5e320, D=...)
    at /home/athirumurthi/git/lldb/tools/lldb/source/Expression/ASTResultSynthesizer.cpp:125
#55 0x00007ffff4ef055c in clang::ParseAST (S=..., PrintStats=false, SkipFunctionBodies=false) at /home/athirumurthi/git/lldb/tools/clang/lib/Parse/ParseAST.cpp:131
#56 0x00007ffff4ef032a in clang::ParseAST (PP=..., Consumer=0xd5e320, Ctx=..., PrintStats=false, TUKind=clang::TU_Complete, CompletionConsumer=0x0,
    SkipFunctionBodies=false) at /home/athirumurthi/git/lldb/tools/clang/lib/Parse/ParseAST.cpp:85
#57 0x00007ffff4362a6a in lldb_private::ClangExpressionParser::Parse (this=0x7fffffffa658, stream=...)
    at /home/athirumurthi/git/lldb/tools/lldb/source/Expression/ClangExpressionParser.cpp:393
#58 0x00007ffff4372546 in lldb_private::ClangUserExpression::Parse (this=0xcb4020, error_stream=..., exe_ctx=...,
    execution_policy=lldb_private::eExecutionPolicyOnlyWhenNeeded, keep_result_in_memory=true)
    at /home/athirumurthi/git/lldb/tools/lldb/source/Expression/ClangUserExpression.cpp:449
#59 0x00007ffff4373dad in lldb_private::ClangUserExpression::EvaluateWithError (exe_ctx=..., execution_policy=lldb_private::eExecutionPolicyOnlyWhenNeeded,
    language=lldb::eLanguageTypeUnknown, desired_type=lldb_private::ClangExpression::eResultTypeAny, unwind_on_error=false, ignore_breakpoints=false,
    expr_cstr=0xc3d558 "my_test.length()", expr_prefix=0x0, result_valobj_sp=..., error=..., run_others=true, timeout_usec=0)
    at /home/athirumurthi/git/lldb/tools/lldb/source/Expression/ClangUserExpression.cpp:862
#60 0x00007ffff4373b4c in lldb_private::ClangUserExpression::Evaluate (exe_ctx=..., execution_policy=lldb_private::eExecutionPolicyOnlyWhenNeeded,
    language=lldb::eLanguageTypeUnknown, desired_type=lldb_private::ClangExpression::eResultTypeAny, unwind_on_error=false, ignore_breakpoints=false,
    expr_cstr=0xc3d558 "my_test.length()", expr_prefix=0x0, result_valobj_sp=..., run_others=true, timeout_usec=0)
    at /home/athirumurthi/git/lldb/tools/lldb/source/Expression/ClangUserExpression.cpp:803
#61 0x00007ffff46ddfa4 in lldb_private::Target::EvaluateExpression (this=0x69af90, expr_cstr=0xc3d558 "my_test.length()", frame=0x7fffd004a920, result_valobj_sp=...,
    options=...) at /home/athirumurthi/git/lldb/tools/lldb/source/Target/Target.cpp:1841
#62 0x00007ffff419a180 in lldb_private::CommandObjectExpression::EvaluateExpression (this=0x62efb0, expr=0xc3d558 "my_test.length()", output_stream=0x9f2860,
    error_stream=0x9f28c8, result=0x9f2860) at /home/athirumurthi/git/lldb/tools/lldb/source/Commands/CommandObjectExpression.cpp:340
#63 0x00007ffff419ac2d in lldb_private::CommandObjectExpression::DoExecute (this=0x62efb0, command=0xc3d558 "my_test.length()", result=...)
    at /home/athirumurthi/git/lldb/tools/lldb/source/Commands/CommandObjectExpression.cpp:540
#64 0x00007ffff43df604 in lldb_private::CommandObjectRaw::Execute (this=0x62efb0, args_string=0xc3d558 "my_test.length()", result=...)
    at /home/athirumurthi/git/lldb/tools/lldb/source/Interpreter/CommandObject.cpp:999
#65 0x00007ffff43d1c9b in lldb_private::CommandInterpreter::HandleCommand (this=0x626ca0, command_line=0x7fffe8000ea8 "expr my_test.length()",
    lazy_add_to_history=lldb_private::eLazyBoolYes, result=..., override_context=0x0, repeat_on_empty_command=true, no_context_switching=false)
    at /home/athirumurthi/git/lldb/tools/lldb/source/Interpreter/CommandInterpreter.cpp:1747
#66 0x00007ffff40f1a85 in lldb::SBCommandInterpreter::HandleCommand (this=0x7fffffffb5c0, command_line=0x7fffe8000ea8 "expr my_test.length()", result=...,
    add_to_history=true) at /home/athirumurthi/git/lldb/tools/lldb/source/API/SBCommandInterpreter.cpp:122
#67 0x000000000040c986 in Driver::HandleIOEvent (this=0x7fffffffe270, event=...) at /home/athirumurthi/git/lldb/tools/lldb/tools/driver/Driver.cpp:1051
#68 0x000000000040e2aa in Driver::MainLoop (this=0x7fffffffe270) at /home/athirumurthi/git/lldb/tools/lldb/tools/driver/Driver.cpp:1516
#69 0x000000000040ea0b in main (argc=2, argv=0x7fffffffe478, envp=0x7fffffffe490) at /home/athirumurthi/git/lldb/tools/lldb/tools/driver/Driver.cpp:1672

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130215/91691633/attachment.html>


More information about the llvm-dev mailing list