diff options
author | Zachary Turner <zturner@google.com> | 2015-10-28 17:43:26 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2015-10-28 17:43:26 +0000 |
commit | c432c8f856e0bd84de980a9d9bb2d31b06fa95b1 (patch) | |
tree | 4efa528e074a6e2df782345e4cd97f5d85d038c4 /lldb/packages/Python/lldbsuite/test/lang/c/global_variables | |
parent | a8a3bd210086b50242903ed95048fe5e53897878 (diff) | |
download | bcm5719-llvm-c432c8f856e0bd84de980a9d9bb2d31b06fa95b1.tar.gz bcm5719-llvm-c432c8f856e0bd84de980a9d9bb2d31b06fa95b1.zip |
Move lldb/test to lldb/packages/Python/lldbsuite/test.
This is the conclusion of an effort to get LLDB's Python code
structured into a bona-fide Python package. This has a number
of benefits, but most notably the ability to more easily share
Python code between different but related pieces of LLDB's Python
infrastructure (for example, `scripts` can now share code with
`test`).
llvm-svn: 251532
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/lang/c/global_variables')
5 files changed, 126 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/lang/c/global_variables/Makefile b/lldb/packages/Python/lldbsuite/test/lang/c/global_variables/Makefile new file mode 100644 index 00000000000..b1b77dacc01 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/c/global_variables/Makefile @@ -0,0 +1,8 @@ +LEVEL = ../../../make + +C_SOURCES := main.c + +DYLIB_NAME := a +DYLIB_C_SOURCES := a.c + +include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/lang/c/global_variables/TestGlobalVariables.py b/lldb/packages/Python/lldbsuite/test/lang/c/global_variables/TestGlobalVariables.py new file mode 100644 index 00000000000..b75ef4fa38d --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/c/global_variables/TestGlobalVariables.py @@ -0,0 +1,77 @@ +"""Show global variables and check that they do indeed have global scopes.""" + +from __future__ import print_function + +import use_lldb_suite + +import os, time +import lldb +from lldbtest import * +import lldbutil + +class GlobalVariablesTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break inside main(). + self.source = 'main.c' + self.line = line_number(self.source, '// Set break point at this line.') + self.shlib_names = ["a"] + + @expectedFailureWindows("llvm.org/pr24764") + def test(self): + """Test 'frame variable --scope --no-args' which omits args and shows scopes.""" + self.build() + + # Create a target by the debugger. + target = self.dbg.CreateTarget("a.out") + self.assertTrue(target, VALID_TARGET) + + # Break inside the main. + lldbutil.run_break_set_by_file_and_line (self, self.source, self.line, num_expected_locations=1, loc_exact=True) + + # Register our shared libraries for remote targets so they get automatically uploaded + environment = self.registerSharedLibrariesWithTarget(target, self.shlib_names) + + # Now launch the process, and do not stop at entry point. + process = target.LaunchSimple (None, environment, self.get_process_working_directory()) + self.assertTrue(process, PROCESS_IS_VALID) + + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs = ['stopped', + 'stop reason = breakpoint']) + + # The breakpoint should have a hit count of 1. + self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, + substrs = [' resolved, hit count = 1']) + + # Check that GLOBAL scopes are indicated for the variables. + self.expect("frame variable --show-types --scope --show-globals --no-args", VARIABLES_DISPLAYED_CORRECTLY, + substrs = ['GLOBAL: (int) g_file_global_int = 42', + 'GLOBAL: (const char *) g_file_global_cstr', + '"g_file_global_cstr"', + 'STATIC: (const char *) g_file_static_cstr', + '"g_file_static_cstr"', + 'GLOBAL: (int) g_common_1 = 21']) + + # 'frame variable' should support address-of operator. + self.runCmd("frame variable &g_file_global_int") + + # Exercise the 'target variable' command to display globals in a.c file. + self.expect("target variable g_a", VARIABLES_DISPLAYED_CORRECTLY, + substrs = ['g_a', '123']) + self.expect("target variable g_marked_spot.x", VARIABLES_DISPLAYED_CORRECTLY, + substrs = ['g_marked_spot.x', '20']) + + # rdar://problem/9747668 + # runCmd: target variable g_marked_spot.y + # output: (int) g_marked_spot.y = <a.o[0x214] can't be resolved, in not currently loaded. + # > + self.expect("target variable g_marked_spot.y", VARIABLES_DISPLAYED_CORRECTLY, + substrs = ['g_marked_spot.y', '21']) + self.expect("target variable g_marked_spot.y", VARIABLES_DISPLAYED_CORRECTLY, matching=False, + substrs = ["can't be resolved"]) diff --git a/lldb/packages/Python/lldbsuite/test/lang/c/global_variables/a.c b/lldb/packages/Python/lldbsuite/test/lang/c/global_variables/a.c new file mode 100644 index 00000000000..d169d5d6324 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/c/global_variables/a.c @@ -0,0 +1,15 @@ +//===-- a.c -----------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +int g_a = 123; +struct Point { + int x; + int y; +}; +struct Point g_marked_spot = { 20, 21 }; + diff --git a/lldb/packages/Python/lldbsuite/test/lang/c/global_variables/cmds.txt b/lldb/packages/Python/lldbsuite/test/lang/c/global_variables/cmds.txt new file mode 100644 index 00000000000..6906a0729ae --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/c/global_variables/cmds.txt @@ -0,0 +1,3 @@ +break main.c:5 +continue +var -global g_a -global g_global_int diff --git a/lldb/packages/Python/lldbsuite/test/lang/c/global_variables/main.c b/lldb/packages/Python/lldbsuite/test/lang/c/global_variables/main.c new file mode 100644 index 00000000000..d0ac6a9534f --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/c/global_variables/main.c @@ -0,0 +1,23 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +#include <stdio.h> + +int g_common_1; // Not initialized on purpose to cause it to be undefined external in .o file +int g_file_global_int = 42; +const char *g_file_global_cstr = "g_file_global_cstr"; +static const char *g_file_static_cstr = "g_file_static_cstr"; + +extern int g_a; +int main (int argc, char const *argv[]) +{ + g_common_1 = g_file_global_int / 2; + static const char *g_func_static_cstr = "g_func_static_cstr"; + printf ("%s %s\n", g_file_global_cstr, g_file_static_cstr); + return g_file_global_int + g_a + g_common_1; // Set break point at this line. //// break $source:$line; continue; var -global g_a -global g_global_int +} |