[Lldb-commits] [PATCH] D15116: Fix for evaluating a function with an ambiguous symbol

Ewan Crawford via lldb-commits lldb-commits at lists.llvm.org
Tue Dec 1 08:47:55 PST 2015


EwanCrawford created this revision.
EwanCrawford added a reviewer: spyffe.
EwanCrawford added a subscriber: lldb-commits.
EwanCrawford set the repository for this revision to rL LLVM.

I came across a bug for calling functions using expression evaluation, where the function name also matches a symbol from another compile unit.
The attached test case recreates it when compiled with gcc. Clang however doesn't seem to export a conflicting .rodata symbol so the bug doesn't appear.

Currently trying to call the function gives the following error in the test case.
   
```
 (lldb) expr overloaded_symbol(1)
 error: warning: got name from symbols: overloaded_symbol
 error: reference to 'overloaded_symbol' is ambiguous
 note: candidate found by name lookup is 'overloaded_symbol'
 note: candidate found by name lookup is 'overloaded_symbol'
 error: 1 errors parsing expression
```
	
This patch in the clang expression parser stops us turning the symbol into a global variable declaration if we've already found
a matching function. I'm not familiar with this code, so if there's a better way to fix this please let me know.

Repository:
  rL LLVM

http://reviews.llvm.org/D15116

Files:
  packages/Python/lldbsuite/test/expression_command/overloaded_symbol/Makefile
  packages/Python/lldbsuite/test/expression_command/overloaded_symbol/TestCallSymbolConflict.py
  packages/Python/lldbsuite/test/expression_command/overloaded_symbol/main.cpp
  packages/Python/lldbsuite/test/expression_command/overloaded_symbol/overload.cpp
  source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp

Index: source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
===================================================================
--- source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -1576,7 +1576,7 @@
                 } while (0);
             }
 
-            if (target && !context.m_found.variable && !namespace_decl)
+            if (target && !context.m_found.variable && !context.m_found.function && !context.m_found.function_with_type_info && !namespace_decl)
             {
                 // We couldn't find a non-symbol variable for this.  Now we'll hunt for a generic
                 // data symbol, and -- if it is found -- treat it as a variable.
Index: packages/Python/lldbsuite/test/expression_command/overloaded_symbol/overload.cpp
===================================================================
--- packages/Python/lldbsuite/test/expression_command/overloaded_symbol/overload.cpp
+++ packages/Python/lldbsuite/test/expression_command/overloaded_symbol/overload.cpp
@@ -0,0 +1,6 @@
+const int overloaded_symbol = 2;
+
+int return_global()
+{
+    return overloaded_symbol;
+}
Index: packages/Python/lldbsuite/test/expression_command/overloaded_symbol/main.cpp
===================================================================
--- packages/Python/lldbsuite/test/expression_command/overloaded_symbol/main.cpp
+++ packages/Python/lldbsuite/test/expression_command/overloaded_symbol/main.cpp
@@ -0,0 +1,12 @@
+int return_global();
+
+int overloaded_symbol(int x)
+{
+    return x + 1;
+}
+
+int main()
+{
+    int my_local = return_global(); // break here
+    return overloaded_symbol(my_local);
+}
Index: packages/Python/lldbsuite/test/expression_command/overloaded_symbol/TestCallSymbolConflict.py
===================================================================
--- packages/Python/lldbsuite/test/expression_command/overloaded_symbol/TestCallSymbolConflict.py
+++ packages/Python/lldbsuite/test/expression_command/overloaded_symbol/TestCallSymbolConflict.py
@@ -0,0 +1,36 @@
+"""
+Test calling function which has a name conflicting with a .rodata symbol
+"""
+
+from __future__ import print_function
+
+
+
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+
+class ExprCommandCallSymbolConfict(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    def setUp(self):
+        # Call super's setUp().
+        TestBase.setUp(self)
+        # Find the line number to break for main.c.
+        self.line = line_number('main.cpp', '// break here')
+
+    @expectedFlakeyDsym("llvm.org/pr20274")
+    @expectedFailureWindows("llvm.org/pr24489: Name lookup not working correctly on Windows")
+    def test(self):
+        """Test return value of call to function whose name conflicts with another symbol."""
+        self.build()
+
+        # Set breakpoint in main and run exe
+        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
+        lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=-1, loc_exact=True)
+
+        self.runCmd("run", RUN_SUCCEEDED)
+
+        # Function semantics are simply to return the incremented integer parameter
+        self.expect("expr overloaded_symbol(5)", substrs = ['$0 = 6'])
Index: packages/Python/lldbsuite/test/expression_command/overloaded_symbol/Makefile
===================================================================
--- packages/Python/lldbsuite/test/expression_command/overloaded_symbol/Makefile
+++ packages/Python/lldbsuite/test/expression_command/overloaded_symbol/Makefile
@@ -0,0 +1,8 @@
+LEVEL = ../../make
+
+CXX_SOURCES := main.cpp overload.cpp
+
+include $(LEVEL)/Makefile.rules
+
+overload.o: overload.cpp
+	$(CXX) -c overload.cpp


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15116.41508.patch
Type: text/x-patch
Size: 3819 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20151201/27c17f8b/attachment.bin>


More information about the lldb-commits mailing list