Skip to content

Commit 94e40c8

Browse files
committed
Add test case.
1 parent b8c64e2 commit 94e40c8

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CXX_SOURCES := main.cpp
2+
3+
include Makefile.rules
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""
2+
Make sure the frame variable -g, -a, and -l flags work.
3+
"""
4+
5+
6+
import lldb
7+
import lldbsuite.test.lldbutil as lldbutil
8+
from lldbsuite.test.decorators import *
9+
from lldbsuite.test.lldbtest import *
10+
import os
11+
import shutil
12+
import time
13+
14+
15+
class TestFrameVarAnonStruct(TestBase):
16+
# If your test case doesn't stress debug info, then
17+
# set this to true. That way it won't be run once for
18+
# each debug info format.
19+
NO_DEBUG_INFO_TESTCASE = True
20+
21+
def test_frame_var(self):
22+
self.build()
23+
self.do_test()
24+
25+
def do_test(self):
26+
target = self.createTestTarget()
27+
28+
# Now create a breakpoint in main.c at the source matching
29+
# "Set a breakpoint here"
30+
breakpoint = target.BreakpointCreateBySourceRegex(
31+
"Set a breakpoint here", lldb.SBFileSpec("main.cpp")
32+
)
33+
self.assertTrue(
34+
breakpoint and breakpoint.GetNumLocations() >= 1, VALID_BREAKPOINT
35+
)
36+
37+
error = lldb.SBError()
38+
# This is the launch info. If you want to launch with arguments or
39+
# environment variables, add them using SetArguments or
40+
# SetEnvironmentEntries
41+
42+
launch_info = target.GetLaunchInfo()
43+
process = target.Launch(launch_info, error)
44+
self.assertTrue(process, PROCESS_IS_VALID)
45+
46+
# Did we hit our breakpoint?
47+
from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint
48+
49+
threads = get_threads_stopped_at_breakpoint(process, breakpoint)
50+
self.assertEqual(
51+
len(threads), 1, "There should be a thread stopped at our breakpoint"
52+
)
53+
54+
# The hit count for the breakpoint should be 1.
55+
self.assertEqual(breakpoint.GetHitCount(), 1)
56+
57+
frame = threads[0].GetFrameAtIndex(0)
58+
command_result = lldb.SBCommandReturnObject()
59+
interp = self.dbg.GetCommandInterpreter()
60+
61+
# Verify that we don't crash in this case.
62+
self.expect("frame variable 'b.x'", error=True,
63+
substrs=['"x" is not a member of "(B) b"'])
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
int main(int argc, char** argv)
2+
{
3+
struct A {
4+
struct {
5+
int x = 1;
6+
};
7+
int y = 2;
8+
} a;
9+
10+
struct B {
11+
// Anonymous struct inherits another struct.
12+
struct : public A {
13+
int z = 3;
14+
};
15+
int w = 4;
16+
A a;
17+
} b;
18+
19+
return 0; // Set a breakpoint here
20+
}

0 commit comments

Comments
 (0)