2010-11-19 04:35:54 +08:00
|
|
|
"""
|
|
|
|
Test display and Python APIs on file and class static variables.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os, time
|
|
|
|
import unittest2
|
|
|
|
import lldb
|
|
|
|
from lldbtest import *
|
|
|
|
|
|
|
|
class StaticVariableTestCase(TestBase):
|
|
|
|
|
2011-06-26 04:43:57 +08:00
|
|
|
mydir = os.path.join("lang", "cpp", "class_static")
|
2010-11-19 04:35:54 +08:00
|
|
|
|
|
|
|
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
|
|
|
|
def test_with_dsym_and_run_command(self):
|
|
|
|
"""Test that file and class static variables display correctly."""
|
|
|
|
self.buildDsym()
|
|
|
|
self.static_variable_commands()
|
|
|
|
|
|
|
|
def test_with_dwarf_and_run_command(self):
|
2010-11-19 07:33:43 +08:00
|
|
|
"""Test that file and class static variables display correctly."""
|
2010-11-19 04:35:54 +08:00
|
|
|
self.buildDwarf()
|
|
|
|
self.static_variable_commands()
|
|
|
|
|
2010-11-19 07:33:43 +08:00
|
|
|
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
|
2010-12-10 09:21:27 +08:00
|
|
|
@python_api_test
|
2010-11-19 07:33:43 +08:00
|
|
|
def test_with_dsym_and_python_api(self):
|
|
|
|
"""Test Python APIs on file and class static variables."""
|
|
|
|
self.buildDsym()
|
|
|
|
self.static_variable_python()
|
|
|
|
|
2010-12-10 09:21:27 +08:00
|
|
|
@python_api_test
|
2010-11-19 07:33:43 +08:00
|
|
|
def test_with_dwarf_and_python_api(self):
|
|
|
|
"""Test Python APIs on file and class static variables."""
|
|
|
|
self.buildDwarf()
|
|
|
|
self.static_variable_python()
|
|
|
|
|
2010-11-19 04:35:54 +08:00
|
|
|
def setUp(self):
|
|
|
|
# Call super's setUp().
|
|
|
|
TestBase.setUp(self)
|
|
|
|
# Find the line number to break at.
|
|
|
|
self.line = line_number('main.cpp', '// Set break point at this line.')
|
|
|
|
|
|
|
|
def static_variable_commands(self):
|
2010-11-19 07:33:43 +08:00
|
|
|
"""Test that that file and class static variables display correctly."""
|
2010-11-19 04:35:54 +08:00
|
|
|
self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
|
|
|
|
|
|
|
|
self.expect("breakpoint set -f main.cpp -l %d" % self.line,
|
|
|
|
BREAKPOINT_CREATED,
|
|
|
|
startstr = "Breakpoint created: 1: file ='main.cpp', line = %d, locations = 1" %
|
|
|
|
self.line)
|
|
|
|
|
|
|
|
self.runCmd("run", RUN_SUCCEEDED)
|
|
|
|
|
|
|
|
# The stop reason of the thread should be breakpoint.
|
|
|
|
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
|
Centralized a lot of the status information for processes,
threads, and stack frame down in the lldb_private::Process,
lldb_private::Thread, lldb_private::StackFrameList and the
lldb_private::StackFrame classes. We had some command line
commands that had duplicate versions of the process status
output ("thread list" and "process status" for example).
Removed the "file" command and placed it where it should
have been: "target create". Made an alias for "file" to
"target create" so we stay compatible with GDB commands.
We can now have multple usable targets in lldb at the
same time. This is nice for comparing two runs of a program
or debugging more than one binary at the same time. The
new command is "target select <target-idx>" and also to see
a list of the current targets you can use the new "target list"
command. The flow in a debug session can be:
(lldb) target create /path/to/exe/a.out
(lldb) breakpoint set --name main
(lldb) run
... hit breakpoint
(lldb) target create /bin/ls
(lldb) run /tmp
Process 36001 exited with status = 0 (0x00000000)
(lldb) target list
Current targets:
target #0: /tmp/args/a.out ( arch=x86_64-apple-darwin, platform=localhost, pid=35999, state=stopped )
* target #1: /bin/ls ( arch=x86_64-apple-darwin, platform=localhost, pid=36001, state=exited )
(lldb) target select 0
Current targets:
* target #0: /tmp/args/a.out ( arch=x86_64-apple-darwin, platform=localhost, pid=35999, state=stopped )
target #1: /bin/ls ( arch=x86_64-apple-darwin, platform=localhost, pid=36001, state=exited )
(lldb) bt
* thread #1: tid = 0x2d03, 0x0000000100000b9a a.out`main + 42 at main.c:16, stop reason = breakpoint 1.1
frame #0: 0x0000000100000b9a a.out`main + 42 at main.c:16
frame #1: 0x0000000100000b64 a.out`start + 52
Above we created a target for "a.out" and ran and hit a
breakpoint at "main". Then we created a new target for /bin/ls
and ran it. Then we listed the targest and selected our original
"a.out" program, so we showed two concurent debug sessions
going on at the same time.
llvm-svn: 129695
2011-04-18 16:33:37 +08:00
|
|
|
substrs = ['stopped',
|
2010-11-19 04:35:54 +08:00
|
|
|
'stop reason = breakpoint'])
|
|
|
|
|
|
|
|
# On Mac OS X, gcc 4.2 emits the wrong debug info for A::g_points.
|
|
|
|
slist = ['(PointType [2]) g_points', 'A::g_points']
|
|
|
|
|
2011-07-07 12:38:25 +08:00
|
|
|
# global variables are no longer displayed with the "frame variable" command.
|
|
|
|
# add tests for the "target variable" command soon
|
2010-11-19 04:35:54 +08:00
|
|
|
# 'frame variable -G' finds and displays global variable(s) by name.
|
2011-07-07 12:38:25 +08:00
|
|
|
# self.expect('frame variable -G g_points', VARIABLES_DISPLAYED_CORRECTLY,
|
|
|
|
# substrs = slist)
|
2010-11-19 04:35:54 +08:00
|
|
|
|
|
|
|
# A::g_points is an array of two elements.
|
|
|
|
if sys.platform.startswith("darwin") and self.getCompiler() in ['clang', 'llvm-gcc']:
|
|
|
|
self.expect("frame variable A::g_points[1].x", VARIABLES_DISPLAYED_CORRECTLY,
|
|
|
|
startstr = "(int) A::g_points[1].x = 11")
|
|
|
|
|
2010-11-19 07:33:43 +08:00
|
|
|
def static_variable_python(self):
|
|
|
|
"""Test Python APIs on file and class static variables."""
|
|
|
|
exe = os.path.join(os.getcwd(), "a.out")
|
|
|
|
|
|
|
|
target = self.dbg.CreateTarget(exe)
|
2011-05-25 02:22:45 +08:00
|
|
|
self.assertTrue(target, VALID_TARGET)
|
2010-11-19 07:33:43 +08:00
|
|
|
|
|
|
|
breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line)
|
2011-05-25 02:22:45 +08:00
|
|
|
self.assertTrue(breakpoint, VALID_BREAKPOINT)
|
2010-11-19 07:33:43 +08:00
|
|
|
|
|
|
|
# Now launch the process, and do not stop at entry point.
|
2011-06-16 06:14:12 +08:00
|
|
|
process = target.LaunchSimple(None, None, os.getcwd())
|
|
|
|
self.assertTrue(process, PROCESS_IS_VALID)
|
2010-11-19 07:33:43 +08:00
|
|
|
|
|
|
|
# The stop reason of the thread should be breakpoint.
|
2011-06-16 06:14:12 +08:00
|
|
|
thread = process.GetThreadAtIndex(0)
|
2010-11-19 07:33:43 +08:00
|
|
|
if thread.GetStopReason() != lldb.eStopReasonBreakpoint:
|
2011-04-28 01:43:07 +08:00
|
|
|
from lldbutil import stop_reason_to_str
|
2010-11-19 07:33:43 +08:00
|
|
|
self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS %
|
2011-04-28 01:43:07 +08:00
|
|
|
stop_reason_to_str(thread.GetStopReason()))
|
2010-11-19 07:33:43 +08:00
|
|
|
|
|
|
|
# Get the SBValue of 'A::g_points' and 'g_points'.
|
|
|
|
frame = thread.GetFrameAtIndex(0)
|
|
|
|
|
|
|
|
# arguments => False
|
|
|
|
# locals => False
|
|
|
|
# statics => True
|
|
|
|
# in_scope_only => False
|
|
|
|
valList = frame.GetVariables(False, False, True, False)
|
|
|
|
|
2011-04-29 06:57:01 +08:00
|
|
|
for val in valList:
|
2010-11-19 07:33:43 +08:00
|
|
|
self.DebugSBValue(frame, val)
|
|
|
|
self.assertTrue(val.GetValueType() == lldb.eValueTypeVariableGlobal)
|
|
|
|
name = val.GetName()
|
|
|
|
self.assertTrue(name in ['g_points', 'A::g_points'])
|
|
|
|
if name == 'g_points':
|
|
|
|
self.assertTrue(val.GetNumChildren() == 2)
|
|
|
|
elif name == 'A::g_points' and self.getCompiler() in ['clang', 'llvm-gcc']:
|
2010-11-30 07:58:04 +08:00
|
|
|
# On Mac OS X, gcc 4.2 emits the wrong debug info for A::g_points.
|
2010-11-19 07:33:43 +08:00
|
|
|
self.assertTrue(val.GetNumChildren() == 2)
|
|
|
|
child1 = val.GetChildAtIndex(1)
|
|
|
|
self.DebugSBValue(frame, child1)
|
|
|
|
child1_x = child1.GetChildAtIndex(0)
|
|
|
|
self.DebugSBValue(frame, child1_x)
|
|
|
|
self.assertTrue(child1_x.GetTypeName() == 'int' and
|
|
|
|
child1_x.GetValue(frame) == '11')
|
|
|
|
|
2010-12-15 02:59:15 +08:00
|
|
|
# SBFrame.FindValue() should also work.
|
|
|
|
val = frame.FindValue("A::g_points", lldb.eValueTypeVariableGlobal)
|
2010-11-20 02:07:14 +08:00
|
|
|
self.DebugSBValue(frame, val)
|
|
|
|
self.assertTrue(val.GetName() == 'A::g_points')
|
|
|
|
|
|
|
|
# Also exercise the "parameter" and "local" scopes while we are at it.
|
2010-12-15 02:59:15 +08:00
|
|
|
val = frame.FindValue("argc", lldb.eValueTypeVariableArgument)
|
2010-11-20 02:07:14 +08:00
|
|
|
self.DebugSBValue(frame, val)
|
|
|
|
self.assertTrue(val.GetName() == 'argc')
|
|
|
|
|
2010-12-15 02:59:15 +08:00
|
|
|
val = frame.FindValue("argv", lldb.eValueTypeVariableArgument)
|
2010-11-20 02:07:14 +08:00
|
|
|
self.DebugSBValue(frame, val)
|
|
|
|
self.assertTrue(val.GetName() == 'argv')
|
|
|
|
|
2010-12-15 02:59:15 +08:00
|
|
|
val = frame.FindValue("hello_world", lldb.eValueTypeVariableLocal)
|
2010-11-20 02:07:14 +08:00
|
|
|
self.DebugSBValue(frame, val)
|
|
|
|
self.assertTrue(val.GetName() == 'hello_world')
|
2010-11-19 07:33:43 +08:00
|
|
|
|
2010-11-19 04:35:54 +08:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import atexit
|
|
|
|
lldb.SBDebugger.Initialize()
|
|
|
|
atexit.register(lambda: lldb.SBDebugger.Terminate())
|
|
|
|
unittest2.main()
|