Skip to content

Commit 0bade02

Browse files
author
Johnny Chen
committed
Add a test script for verifying that the convenience variables:
o lldb.debugger o lldb.target o lldb.process o lldb.thread o lldb.frame "just works" when we stop at a breakpoint. llvm-svn: 130904
1 parent baa878c commit 0bade02

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
LEVEL = ../make
2+
3+
C_SOURCES := main.c
4+
5+
include $(LEVEL)/Makefile.rules
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
"""Test convenience variables when you drop in from lldb prompt into an embedded interpreter."""
2+
3+
import os
4+
import unittest2
5+
import lldb
6+
import pexpect
7+
from lldbtest import *
8+
9+
class ConvenienceVariablesCase(TestBase):
10+
11+
mydir = "embedded_interpreter"
12+
13+
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
14+
def test_with_dsym_and_run_command(self):
15+
"""Test convenience variables lldb.debugger, lldb.target, lldb.process, lldb.thread, and lldb.frame."""
16+
self.buildDsym()
17+
self.convenience_variables()
18+
19+
@python_api_test
20+
def test_with_dwarf_and_process_launch_api(self):
21+
"""Test convenience variables lldb.debugger, lldb.target, lldb.process, lldb.thread, and lldb.frame."""
22+
self.buildDwarf()
23+
self.convenience_variables()
24+
25+
def setUp(self):
26+
# Call super's setUp().
27+
TestBase.setUp(self)
28+
# Find the line number to break on inside main.cpp.
29+
self.line = line_number('main.c', 'Hello world.')
30+
31+
def convenience_variables(self):
32+
"""Test convenience variables lldb.debugger, lldb.target, lldb.process, lldb.thread, and lldb.frame."""
33+
exe = os.path.join(os.getcwd(), "a.out")
34+
prompt = "(lldb) "
35+
python_prompt = ">>> "
36+
37+
# So that the child gets torn down after the test.
38+
self.child = pexpect.spawn('%s %s' % (self.lldbExec, exe))
39+
child = self.child
40+
# Turn on logging for what the child sends back.
41+
if self.TraceOn():
42+
child.logfile_read = sys.stdout
43+
44+
# Set the breakpoint, run the inferior, when it breaks, issue print on
45+
# the various convenience variables.
46+
child.expect_exact(prompt)
47+
child.sendline('breakpoint set -f main.c -l %d' % self.line)
48+
child.expect_exact(prompt)
49+
child.sendline('run')
50+
child.expect_exact(prompt)
51+
child.sendline('script')
52+
child.expect_exact(python_prompt)
53+
54+
# Set a flag so that we know during teardown time, we need to exit the
55+
# Python interpreter, then the lldb interpreter.
56+
self.child_in_script_interpreter = True
57+
58+
child.sendline('print lldb.debugger')
59+
child.expect_exact(python_prompt)
60+
self.expect(child.before, exe=False,
61+
patterns = ['Debugger \(instance: .*, id: \d\)'])
62+
63+
child.sendline('print lldb.target')
64+
child.expect_exact(python_prompt)
65+
self.expect(child.before, exe=False,
66+
substrs = ['a.out'])
67+
68+
child.sendline('print lldb.process')
69+
child.expect_exact(python_prompt)
70+
self.expect(child.before, exe=False,
71+
patterns = ['SBProcess: pid = \d+, state = stopped, threads = \d, executable = a.out'])
72+
73+
child.sendline('print lldb.thread')
74+
child.expect_exact(python_prompt)
75+
self.expect(child.before, exe=False,
76+
patterns = ['SBThread: tid = 0x[0-9a-f]+'])
77+
78+
child.sendline('print lldb.frame')
79+
child.expect_exact(python_prompt)
80+
self.expect(child.before, exe=False,
81+
substrs = ['frame #0', 'main.c:%d' % self.line])
82+
83+
84+
if __name__ == '__main__':
85+
import atexit
86+
lldb.SBDebugger.Initialize()
87+
atexit.register(lambda: lldb.SBDebugger.Terminate())
88+
unittest2.main()

lldb/test/embedded_interpreter/main.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <stdio.h>
2+
3+
int main(int argc, char const *argv[]) {
4+
printf("Hello world.\n");
5+
return 0;
6+
}

lldb/test/lldbtest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ def setUp(self):
529529
# This is for the case of directly spawning 'lldb' and interacting with it
530530
# using pexpect.
531531
self.child = None
532+
self.child_in_script_interpreter = False
532533

533534
# There is no process associated with the debugger as yet.
534535
# See also self.tearDown() where it checks whether self.process has a
@@ -682,6 +683,9 @@ def tearDown(self):
682683
if self.child and self.child.isalive():
683684
with recording(self, traceAlways) as sbuf:
684685
print >> sbuf, "tearing down the child process...."
686+
if self.child_in_script_interpreter:
687+
self.child.sendline('quit()')
688+
self.child.expect_exact('(lldb) ')
685689
self.child.sendline('quit')
686690
try:
687691
self.child.expect(pexpect.EOF)

0 commit comments

Comments
 (0)