[lldb-dev] [Bug 21662] New: LLDB's name lookup is completely wrong for C++

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Nov 24 19:52:11 PST 2014


http://llvm.org/bugs/show_bug.cgi?id=21662

            Bug ID: 21662
           Summary: LLDB's name lookup is completely wrong for C++
           Product: lldb
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: lldb-dev at cs.uiuc.edu
          Reporter: chandlerc at gmail.com
    Classification: Unclassified

I noticed a name lookup bug in LLDB, so I wrote a simple test case:

% cat x.cpp
namespace N { volatile int x; }
namespace M { volatile int x; }

void f(int N, int M) {
  ::N::x = N;
  ::M::x = M;
}

int main() {
  f(1, 2);
}

% lldb -- x
(lldb) target create "x"
Current executable set to 'x' (x86_64).
(lldb) b f
Breakpoint 1: where = x`f(int, int) + 10 at x.cpp:5, address =
0x00000000004005ca
(lldb) r
Process 11011 launching

Process 11011 launched: '/usr/local/google/home/chandlerc/src/llvm/build/x'
(x86_64)
Process 11011 stopped
* thread #1: tid = 11011, 0x00000000004005ca x`f(N=1, M=2) + 10 at x.cpp:5,
name = 'x', stop reason = breakpoint 1.1
    frame #0: 0x00000000004005ca x`f(N=1, M=2) + 10 at x.cpp:5
   2    namespace M { volatile int x; }
   3   
   4    void f(int N, int M) {
-> 5      ::N::x = N;
   6      ::M::x = M;
   7    }
   8   
(lldb) p N
(int) $0 = 1
(lldb) p M
(int) $1 = 2

So far, so good.

(lldb) p ::N::x
error: 'N' is not a class, namespace, or scoped enumeration
note: 'N' declared here
error: 1 errors parsing expression

Bug: N is a namespace, but LLDB thinks it is a local variable. You can see how
deeply LLDB thinks this is a local variable:

(lldb) p ::N
(int) $2 = 1
(lldb) p &::N
(int *) $3 = 0x00007fffffffdddc
(lldb) p &N
(int *) $4 = 0x00007fffffffdddc

Yikes.


But this isn't even the bug I hit. Try on a slightly more complicated example:

% cat y.cpp
namespace N {
namespace M1 { namespace M2 { volatile int x; } }

struct S2;
struct S1 {
  void f(S2 &M1);
};

struct S2 { int x; };

}

using namespace N;

void S1::f(S2 &M1) {
  N::M1::M2::x = M1.x;
}

int main() {
  S1 s1;
  S2 s2 = { 42 };
  s1.f(s2);
}

% clang++ -g -o y y.cpp
% lldb -- y                  
(lldb) target create "y"
Current executable set to 'y' (x86_64).
(lldb) b f
Breakpoint 1: where = y`N::S1::f(N::S2&) + 12 at y.cpp:16, address =
0x00000000004005cc
(lldb) r
Process 11167 launching

Process 11167 launched: '/usr/local/google/home/chandlerc/src/llvm/build/y'
(x86_64)
Process 11167 stopped
* thread #1: tid = 11167, 0x00000000004005cc
y`N::S1::f(this=0x00007fffffffdde8, M1=0x00007fffffffdde0) + 12 at y.cpp:16,
name = 'y', stop reason = breakpoint 1.1
    frame #0: 0x00000000004005cc y`N::S1::f(this=0x00007fffffffdde8,
M1=0x00007fffffffdde0) + 12 at y.cpp:16
   13   using namespace N;
   14  
   15   void S1::f(S2 &M1) {
-> 16     N::M1::M2::x = M1.x;
   17   }
   18  
   19   int main() {
(lldb) p M1
error: unexpected namespace name 'M1': expected expression
error: 1 errors parsing expression

Bug: M1 is an expression!

This pattern shows up pretty frequently in LLVM and other codebases, and makes
using LLDB really hard because I have to go grabbing the address of parameters
and manually casting that to memory and printing. Yikes.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20141125/ec608a0a/attachment.html>


More information about the lldb-dev mailing list