<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - LLDB's name lookup is completely wrong for C++"
href="http://llvm.org/bugs/show_bug.cgi?id=21662">21662</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>LLDB's name lookup is completely wrong for C++
</td>
</tr>
<tr>
<th>Product</th>
<td>lldb
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>All Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>lldb-dev@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Reporter</th>
<td>chandlerc@gmail.com
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>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.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are the assignee for the bug.</li>
</ul>
</body>
</html>