[Lldb-commits] [PATCH] D11102: Set the compiler's language options using the language of the current frame's CU, and fix ObjC evaluation.

Dawn Perchik dawn+llvm at burble.org
Fri Jul 10 10:54:33 PDT 2015


dawn created this revision.
dawn added reviewers: clayborg, spyffe, zturner.
dawn added a subscriber: lldb-commits.
dawn set the repository for this revision to rL LLVM.

The main purpose of this patch is to be able to get the frame's context (instead of just the target's) when evaluating, so that the language of the frame's CU can be used to select the compiler and/or compiler options to use when parsing the expression.  This allows for modules built with mixed languages to be parsed in the context of their frame.  (Note: an override option may be forthcoming to specify a different language to use if needed).

Changes to ObjC options were required as part of this patch.  The lldb tests require the C++ language option to be set in order to evaluate the ObjC expressions in the tests, see below for an explanation.  Assuming this is desirable, this patch works around the problem by setting CPlusPlus = 1 for ObjC.  Alternatively, someone who understands ObjC better may wish to fix the tests so they pass without this.   

Example from failing test case test/lang/objc/foundation/TestConstStrings.py:
    ./dotest.py -v -t --executable $LLDB_EXEC -f ConstStringTestCase.test_break_with_dwarf
with_dwarf
Test manually as:
    cd $llvm/tools/lldb/test/lang/objc/foundation
    make MAKE_DSYM=NO ARCH=x86_64 CC="clang" OBJC_SOURCES='const-strings.m'
    $LLDB_EXEC /Users/dawn/llvm_delphi/tools/lldb/test/lang/objc/foundation/a.out
    (lldb) b const-strings.m:20
    (lldb) r
    (lldb) expression (int)[str compare:@"hello"]
Compiler options (from getLangOpts()) are set as follows:
    if frame's CU is eLanguageTypeObjC:
        CPlusPlus = 0
        CPlusPlus11 = 0
        CPlusPlus14 = 0
        CPlusPlus1z = 0
        ObjC1 = 1
        ObjC2 = 1
    if frame's CU is eLanguageTypeUnknown:
        CPlusPlus = 1
        CPlusPlus11 = 1
        CPlusPlus14 = 0
        CPlusPlus1z = 0
        ObjC1 = 1
        ObjC2 = 1
At 14th call to Parser::ParseDirectDeclarator the callstacks look like:
    if frame's CU is eLanguageTypeObjC:
        ->Parser::ParseDeclarationOrFunctionDefinition Parser.cpp:940
        ->Parser::ParseDeclOrFunctionDefInternal Parser.cpp:924
        ->...->Parser::ParseDirectDeclarator
        # Tok=(Loc = 641, UintData = 3, PtrData = 0x00007fa53282860f, Kind = string_literal, Flags = 2)
        results in:
            error: expected identifier or '('
            error: use of undeclared identifier 'str'
            error: 2 errors parsing expression
    if frame's CU is eLanguageTypeUnknown:
        ->Parser::ParseDeclarationOrFunctionDefinition Parser.cpp:940
        ->*Parser::ParseDeclOrFunctionDefInternal Parser.cpp:920
            # code diverges at line 917:
            #     if (getLangOpts().CPlusPlus && isTokenStringLiteral() &&
            #         ...
            # because the syntax is only accepted under C++.
        ->*Parser::ParseLinkage ParseDeclCXX.cpp:380
        ->*Parser::ParseExternalDeclaration Parser.cpp:798
        ->*Parser::ParseDeclarationOrFunctionDefinition Parser.cpp:940
        ->Parser::ParseDeclOrFunctionDefInternal Parser.cpp:924
        ->...->Parser::ParseDirectDeclarator
        # Tok=(Loc = 655, UintData = 6, PtrData = 0x00007fecf3471d20, Kind = identifier, Flags = 2)

Repository:
  rL LLVM

http://reviews.llvm.org/D11102

Files:
  source/Commands/CommandObjectExpression.cpp
  source/Expression/ClangExpressionParser.cpp

Index: source/Expression/ClangExpressionParser.cpp
===================================================================
--- source/Expression/ClangExpressionParser.cpp
+++ source/Expression/ClangExpressionParser.cpp
@@ -214,6 +214,9 @@
     case lldb::eLanguageTypeObjC:
         m_compiler->getLangOpts().ObjC1 = true;
         m_compiler->getLangOpts().ObjC2 = true;
+        // ObjC++ syntax is allowed when debugging ObjC code, so we
+        // set it here as well.
+        m_compiler->getLangOpts().CPlusPlus = true;
         break;
     case lldb::eLanguageTypeC_plus_plus:
         m_compiler->getLangOpts().CPlusPlus = true;
Index: source/Commands/CommandObjectExpression.cpp
===================================================================
--- source/Commands/CommandObjectExpression.cpp
+++ source/Commands/CommandObjectExpression.cpp
@@ -296,6 +296,20 @@
         options.SetTryAllThreads(m_command_options.try_all_threads);
         options.SetDebug(m_command_options.debug);
         
+        // If the language is unknown, set it to the langage of the
+        // frame's CU.
+        if (options.GetLanguage() == lldb::eLanguageTypeUnknown &&
+            exe_ctx.HasFrameScope())
+        {
+            StackFrame *frame = exe_ctx.GetFramePtr();
+            if (frame)
+            {
+                CompileUnit *cu = frame->GetSymbolContext(eSymbolContextCompUnit).comp_unit;
+                if (cu)
+                    options.SetLanguage(cu->GetLanguage());
+            }
+        }
+
         // If there is any chance we are going to stop and want to see
         // what went wrong with our expression, we should generate debug info
         if (!m_command_options.ignore_breakpoints ||


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11102.29454.patch
Type: text/x-patch
Size: 1720 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150710/ba963b4a/attachment.bin>


More information about the lldb-commits mailing list