summaryrefslogtreecommitdiffstats
path: root/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value
diff options
context:
space:
mode:
authorpatrick <patrick@openbsd.org>2020-08-03 14:33:06 +0000
committerpatrick <patrick@openbsd.org>2020-08-03 14:33:06 +0000
commit061da546b983eb767bad15e67af1174fb0bcf31c (patch)
tree83c78b820819d70aa40c36d90447978b300078c5 /gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value
parentImport LLVM 10.0.0 release including clang, lld and lldb. (diff)
downloadwireguard-openbsd-061da546b983eb767bad15e67af1174fb0bcf31c.tar.xz
wireguard-openbsd-061da546b983eb767bad15e67af1174fb0bcf31c.zip
Import LLVM 10.0.0 release including clang, lld and lldb.
ok hackroom tested by plenty
Diffstat (limited to 'gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value')
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/Makefile3
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/TestValueAPI.py193
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/change_values/Makefile3
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/change_values/TestChangeValueAPI.py181
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/change_values/main.c29
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/empty_class/Makefile3
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/empty_class/TestValueAPIEmptyClass.py56
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/empty_class/main.cpp15
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/linked_list/Makefile3
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/linked_list/TestValueAPILinkedList.py142
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/linked_list/main.cpp55
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/main.c55
12 files changed, 738 insertions, 0 deletions
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/Makefile
new file mode 100644
index 00000000000..10495940055
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/Makefile
@@ -0,0 +1,3 @@
+C_SOURCES := main.c
+
+include Makefile.rules
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/TestValueAPI.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/TestValueAPI.py
new file mode 100644
index 00000000000..bf8cbe34320
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/TestValueAPI.py
@@ -0,0 +1,193 @@
+"""
+Test some SBValue APIs.
+"""
+
+from __future__ import print_function
+
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class ValueAPITestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # We'll use the test method name as the exe_name.
+ self.exe_name = self.testMethodName
+ # Find the line number to of function 'c'.
+ self.line = line_number('main.c', '// Break at this line')
+
+ @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24772")
+ @add_test_categories(['pyapi'])
+ def test(self):
+ """Exercise some SBValue APIs."""
+ d = {'EXE': self.exe_name}
+ self.build(dictionary=d)
+ self.setTearDownCleanup(dictionary=d)
+ exe = self.getBuildArtifact(self.exe_name)
+
+ # Create a target by the debugger.
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+
+ # Create the breakpoint inside function 'main'.
+ breakpoint = target.BreakpointCreateByLocation('main.c', self.line)
+ self.assertTrue(breakpoint, VALID_BREAKPOINT)
+
+ # Now launch the process, and do not stop at entry point.
+ process = target.LaunchSimple(
+ None, None, self.get_process_working_directory())
+ self.assertTrue(process, PROCESS_IS_VALID)
+
+ # Get Frame #0.
+ self.assertTrue(process.GetState() == lldb.eStateStopped)
+ thread = lldbutil.get_stopped_thread(
+ process, lldb.eStopReasonBreakpoint)
+ self.assertTrue(
+ thread.IsValid(),
+ "There should be a thread stopped due to breakpoint condition")
+ frame0 = thread.GetFrameAtIndex(0)
+
+ # Get global variable 'days_of_week'.
+ list = target.FindGlobalVariables('days_of_week', 1)
+ days_of_week = list.GetValueAtIndex(0)
+ self.assertTrue(days_of_week, VALID_VARIABLE)
+ self.assertEqual(days_of_week.GetNumChildren(), 7, VALID_VARIABLE)
+ self.DebugSBValue(days_of_week)
+
+ # Use this to test the "child" and "children" accessors:
+ children = days_of_week.children
+ self.assertEqual(len(children), 7, VALID_VARIABLE)
+ for i in range(0, len(children)):
+ day = days_of_week.child[i]
+ list_day = children[i]
+ self.assertNotEqual(day, None)
+ self.assertNotEqual(list_day, None)
+ self.assertEqual(day.GetSummary(), list_day.GetSummary(), VALID_VARIABLE)
+
+ # Spot check the actual value:
+ first_day = days_of_week.child[1]
+ self.assertEqual(first_day.GetSummary(), '"Monday"', VALID_VARIABLE)
+
+ # Get global variable 'weekdays'.
+ list = target.FindGlobalVariables('weekdays', 1)
+ weekdays = list.GetValueAtIndex(0)
+ self.assertTrue(weekdays, VALID_VARIABLE)
+ self.assertTrue(weekdays.GetNumChildren() == 5, VALID_VARIABLE)
+ self.DebugSBValue(weekdays)
+
+ # Get global variable 'g_table'.
+ list = target.FindGlobalVariables('g_table', 1)
+ g_table = list.GetValueAtIndex(0)
+ self.assertTrue(g_table, VALID_VARIABLE)
+ self.assertTrue(g_table.GetNumChildren() == 2, VALID_VARIABLE)
+ self.DebugSBValue(g_table)
+
+ fmt = lldbutil.BasicFormatter()
+ cvf = lldbutil.ChildVisitingFormatter(indent_child=2)
+ rdf = lldbutil.RecursiveDecentFormatter(indent_child=2)
+ if self.TraceOn():
+ print(fmt.format(days_of_week))
+ print(cvf.format(days_of_week))
+ print(cvf.format(weekdays))
+ print(rdf.format(g_table))
+
+ # Get variable 'my_int_ptr'.
+ value = frame0.FindVariable('my_int_ptr')
+ self.assertTrue(value, VALID_VARIABLE)
+ self.DebugSBValue(value)
+
+ # Get what 'my_int_ptr' points to.
+ pointed = value.GetChildAtIndex(0)
+ self.assertTrue(pointed, VALID_VARIABLE)
+ self.DebugSBValue(pointed)
+
+ # While we are at it, verify that 'my_int_ptr' points to 'g_my_int'.
+ symbol = target.ResolveLoadAddress(
+ int(pointed.GetLocation(), 0)).GetSymbol()
+ self.assertTrue(symbol)
+ self.expect(symbol.GetName(), exe=False,
+ startstr='g_my_int')
+
+ # Get variable 'str_ptr'.
+ value = frame0.FindVariable('str_ptr')
+ self.assertTrue(value, VALID_VARIABLE)
+ self.DebugSBValue(value)
+
+ # SBValue::TypeIsPointerType() should return true.
+ self.assertTrue(value.TypeIsPointerType())
+
+ # Verify the SBValue::GetByteSize() API is working correctly.
+ arch = self.getArchitecture()
+ if arch == 'i386':
+ self.assertTrue(value.GetByteSize() == 4)
+ elif arch == 'x86_64':
+ self.assertTrue(value.GetByteSize() == 8)
+
+ # Get child at index 5 => 'Friday'.
+ child = value.GetChildAtIndex(5, lldb.eNoDynamicValues, True)
+ self.assertTrue(child, VALID_VARIABLE)
+ self.DebugSBValue(child)
+
+ self.expect(child.GetSummary(), exe=False,
+ substrs=['Friday'])
+
+ # Now try to get at the same variable using GetValueForExpressionPath().
+ # These two SBValue objects should have the same value.
+ val2 = value.GetValueForExpressionPath('[5]')
+ self.assertTrue(val2, VALID_VARIABLE)
+ self.DebugSBValue(val2)
+ self.assertTrue(child.GetValue() == val2.GetValue() and
+ child.GetSummary() == val2.GetSummary())
+
+ val_i = target.EvaluateExpression('i')
+ val_s = target.EvaluateExpression('s')
+ val_a = target.EvaluateExpression('a')
+ self.assertTrue(
+ val_s.GetChildMemberWithName('a').GetAddress().IsValid(),
+ VALID_VARIABLE)
+ self.assertTrue(
+ val_s.GetChildMemberWithName('a').AddressOf(),
+ VALID_VARIABLE)
+ self.assertTrue(
+ val_a.Cast(
+ val_i.GetType()).AddressOf(),
+ VALID_VARIABLE)
+
+ # Check that lldb.value implements truth testing.
+ self.assertFalse(lldb.value(frame0.FindVariable('bogus')))
+ self.assertTrue(lldb.value(frame0.FindVariable('uinthex')))
+
+ self.assertTrue(int(lldb.value(frame0.FindVariable('uinthex')))
+ == 3768803088, 'uinthex == 3768803088')
+ self.assertTrue(int(lldb.value(frame0.FindVariable('sinthex')))
+ == -526164208, 'sinthex == -526164208')
+
+ # Check value_iter works correctly.
+ for v in [
+ lldb.value(frame0.FindVariable('uinthex')),
+ lldb.value(frame0.FindVariable('sinthex'))
+ ]:
+ self.assertTrue(v)
+
+ self.assertTrue(
+ frame0.FindVariable('uinthex').GetValueAsUnsigned() == 3768803088,
+ 'unsigned uinthex == 3768803088')
+ self.assertTrue(
+ frame0.FindVariable('sinthex').GetValueAsUnsigned() == 3768803088,
+ 'unsigned sinthex == 3768803088')
+
+ self.assertTrue(
+ frame0.FindVariable('uinthex').GetValueAsSigned() == -
+ 526164208,
+ 'signed uinthex == -526164208')
+ self.assertTrue(
+ frame0.FindVariable('sinthex').GetValueAsSigned() == -
+ 526164208,
+ 'signed sinthex == -526164208')
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/change_values/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/change_values/Makefile
new file mode 100644
index 00000000000..10495940055
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/change_values/Makefile
@@ -0,0 +1,3 @@
+C_SOURCES := main.c
+
+include Makefile.rules
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/change_values/TestChangeValueAPI.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/change_values/TestChangeValueAPI.py
new file mode 100644
index 00000000000..6f0dee21af6
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/change_values/TestChangeValueAPI.py
@@ -0,0 +1,181 @@
+"""
+Test some SBValue APIs.
+"""
+
+
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class ChangeValueAPITestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # We'll use the test method name as the exe_name.
+ self.exe_name = self.testMethodName
+ # Find the line number to of function 'c'.
+ self.line = line_number('main.c', '// Stop here and set values')
+ self.check_line = line_number(
+ 'main.c', '// Stop here and check values')
+ self.end_line = line_number(
+ 'main.c', '// Set a breakpoint here at the end')
+
+ @add_test_categories(['pyapi'])
+ @expectedFlakeyLinux("llvm.org/pr25652")
+ @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24772")
+ def test_change_value(self):
+ """Exercise the SBValue::SetValueFromCString API."""
+ d = {'EXE': self.exe_name}
+ self.build(dictionary=d)
+ self.setTearDownCleanup(dictionary=d)
+ exe = self.getBuildArtifact(self.exe_name)
+
+ # Create a target by the debugger.
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+
+ # Create the breakpoint inside function 'main'.
+ breakpoint = target.BreakpointCreateByLocation('main.c', self.line)
+ self.assertTrue(breakpoint, VALID_BREAKPOINT)
+
+ # Create the breakpoint inside the function 'main'
+ check_breakpoint = target.BreakpointCreateByLocation(
+ 'main.c', self.check_line)
+ self.assertTrue(check_breakpoint, VALID_BREAKPOINT)
+
+ # Create the breakpoint inside function 'main'.
+ end_breakpoint = target.BreakpointCreateByLocation(
+ 'main.c', self.end_line)
+ self.assertTrue(end_breakpoint, VALID_BREAKPOINT)
+
+ # Now launch the process, and do not stop at entry point.
+ process = target.LaunchSimple(
+ None, None, self.get_process_working_directory())
+ self.assertTrue(process, PROCESS_IS_VALID)
+
+ # Get Frame #0.
+ self.assertTrue(process.GetState() == lldb.eStateStopped)
+ thread = lldbutil.get_stopped_thread(
+ process, lldb.eStopReasonBreakpoint)
+ self.assertTrue(
+ thread.IsValid(),
+ "There should be a thread stopped due to breakpoint condition")
+ frame0 = thread.GetFrameAtIndex(0)
+ self.assertTrue(frame0.IsValid(), "Got a valid frame.")
+
+ # Get the val variable and change it:
+ error = lldb.SBError()
+
+ val_value = frame0.FindVariable("val")
+ self.assertTrue(val_value.IsValid(), "Got the SBValue for val")
+ actual_value = val_value.GetValueAsSigned(error, 0)
+ self.assertTrue(error.Success(), "Got a value from val")
+ self.assertTrue(actual_value == 100, "Got the right value from val")
+
+ result = val_value.SetValueFromCString("12345")
+ self.assertTrue(result, "Setting val returned True.")
+ actual_value = val_value.GetValueAsSigned(error, 0)
+ self.assertTrue(error.Success(), "Got a changed value from val")
+ self.assertTrue(
+ actual_value == 12345,
+ "Got the right changed value from val")
+
+ # Now check that we can set a structure element:
+
+ mine_value = frame0.FindVariable("mine")
+ self.assertTrue(mine_value.IsValid(), "Got the SBValue for mine")
+
+ mine_second_value = mine_value.GetChildMemberWithName("second_val")
+ self.assertTrue(
+ mine_second_value.IsValid(),
+ "Got second_val from mine")
+ actual_value = mine_second_value.GetValueAsUnsigned(error, 0)
+ self.assertTrue(
+ error.Success(),
+ "Got an unsigned value for second_val")
+ self.assertTrue(actual_value == 5555)
+
+ result = mine_second_value.SetValueFromCString("98765")
+ self.assertTrue(result, "Success setting mine.second_value.")
+ actual_value = mine_second_value.GetValueAsSigned(error, 0)
+ self.assertTrue(
+ error.Success(),
+ "Got a changed value from mine.second_val")
+ self.assertTrue(actual_value == 98765,
+ "Got the right changed value from mine.second_val")
+
+ # Next do the same thing with the pointer version.
+ ptr_value = frame0.FindVariable("ptr")
+ self.assertTrue(ptr_value.IsValid(), "Got the SBValue for ptr")
+
+ ptr_second_value = ptr_value.GetChildMemberWithName("second_val")
+ self.assertTrue(ptr_second_value.IsValid(), "Got second_val from ptr")
+ actual_value = ptr_second_value.GetValueAsUnsigned(error, 0)
+ self.assertTrue(
+ error.Success(),
+ "Got an unsigned value for ptr->second_val")
+ self.assertTrue(actual_value == 6666)
+
+ result = ptr_second_value.SetValueFromCString("98765")
+ self.assertTrue(result, "Success setting ptr->second_value.")
+ actual_value = ptr_second_value.GetValueAsSigned(error, 0)
+ self.assertTrue(
+ error.Success(),
+ "Got a changed value from ptr->second_val")
+ self.assertTrue(actual_value == 98765,
+ "Got the right changed value from ptr->second_val")
+
+ # gcc may set multiple locations for breakpoint
+ breakpoint.SetEnabled(False)
+
+ # Now continue, grab the stdout and make sure we changed the real
+ # values as well...
+ process.Continue()
+
+ self.assertTrue(process.GetState() == lldb.eStateStopped)
+ thread = lldbutil.get_stopped_thread(
+ process, lldb.eStopReasonBreakpoint)
+ self.assertTrue(
+ thread.IsValid(),
+ "There should be a thread stopped due to breakpoint condition")
+
+ expected_value = "Val - 12345 Mine - 55, 98765, 55555555. Ptr - 66, 98765, 66666666"
+ stdout = process.GetSTDOUT(1000)
+ self.assertTrue(
+ expected_value in stdout,
+ "STDOUT showed changed values.")
+
+ # Finally, change the stack pointer to 0, and we should not make it to
+ # our end breakpoint.
+ frame0 = thread.GetFrameAtIndex(0)
+ self.assertTrue(frame0.IsValid(), "Second time: got a valid frame.")
+ sp_value = frame0.FindValue("sp", lldb.eValueTypeRegister)
+ self.assertTrue(sp_value.IsValid(), "Got a stack pointer value")
+ result = sp_value.SetValueFromCString("1")
+ self.assertTrue(result, "Setting sp returned true.")
+ actual_value = sp_value.GetValueAsUnsigned(error, 0)
+ self.assertTrue(error.Success(), "Got a changed value for sp")
+ self.assertTrue(
+ actual_value == 1,
+ "Got the right changed value for sp.")
+
+ # Boundary condition test the SBValue.CreateValueFromExpression() API.
+ # LLDB should not crash!
+ nosuchval = mine_value.CreateValueFromExpression(None, None)
+
+ process.Continue()
+
+ self.assertTrue(process.GetState() == lldb.eStateStopped)
+ thread = lldbutil.get_stopped_thread(
+ process, lldb.eStopReasonBreakpoint)
+ self.assertTrue(
+ thread is None,
+ "We should not have managed to hit our second breakpoint with sp == 1")
+
+ process.Kill()
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/change_values/main.c b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/change_values/main.c
new file mode 100644
index 00000000000..01455c01964
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/change_values/main.c
@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+struct foo
+{
+ uint8_t first_val;
+ uint32_t second_val;
+ uint64_t third_val;
+};
+
+int main ()
+{
+ int val = 100;
+ struct foo mine = {55, 5555, 55555555};
+ struct foo *ptr = (struct foo *) malloc (sizeof (struct foo));
+ ptr->first_val = 66;
+ ptr->second_val = 6666;
+ ptr->third_val = 66666666;
+
+ // Stop here and set values
+ printf ("Val - %d Mine - %d, %d, %llu. Ptr - %d, %d, %llu\n", val,
+ mine.first_val, mine.second_val, mine.third_val,
+ ptr->first_val, ptr->second_val, ptr->third_val);
+
+ // Stop here and check values
+ printf ("This is just another call which we won't make it over %d.", val);
+ return 0; // Set a breakpoint here at the end
+}
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/empty_class/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/empty_class/Makefile
new file mode 100644
index 00000000000..99998b20bcb
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/empty_class/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/empty_class/TestValueAPIEmptyClass.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/empty_class/TestValueAPIEmptyClass.py
new file mode 100644
index 00000000000..c7197e51c23
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/empty_class/TestValueAPIEmptyClass.py
@@ -0,0 +1,56 @@
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class ValueAPIEmptyClassTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @add_test_categories(['pyapi'])
+ def test(self):
+ self.build()
+ exe = self.getBuildArtifact("a.out")
+ line = line_number('main.cpp', '// Break at this line')
+
+ # Create a target by the debugger.
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+
+ # Create the breakpoint inside function 'main'.
+ breakpoint = target.BreakpointCreateByLocation('main.cpp', line)
+ self.assertTrue(breakpoint, VALID_BREAKPOINT)
+
+ # Now launch the process, and do not stop at entry point.
+ process = target.LaunchSimple(
+ None, None, self.get_process_working_directory())
+ self.assertTrue(process, PROCESS_IS_VALID)
+
+ # Get Frame #0.
+ self.assertTrue(process.GetState() == lldb.eStateStopped)
+ thread = lldbutil.get_stopped_thread(
+ process, lldb.eStopReasonBreakpoint)
+ self.assertTrue(
+ thread.IsValid(),
+ "There should be a thread stopped due to breakpoint condition")
+ frame0 = thread.GetFrameAtIndex(0)
+
+ # Verify that we can access to a frame variable with an empty class type
+ e = frame0.FindVariable('e')
+ self.assertTrue(e.IsValid(), VALID_VARIABLE)
+ self.DebugSBValue(e)
+ self.assertEqual(e.GetNumChildren(), 0)
+
+ # Verify that we can acces to a frame variable what is a pointer to an
+ # empty class
+ ep = frame0.FindVariable('ep')
+ self.assertTrue(ep.IsValid(), VALID_VARIABLE)
+ self.DebugSBValue(ep)
+
+ # Verify that we can dereference a pointer to an empty class
+ epd = ep.Dereference()
+ self.assertTrue(epd.IsValid(), VALID_VARIABLE)
+ self.DebugSBValue(epd)
+ self.assertEqual(epd.GetNumChildren(), 0)
+
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/empty_class/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/empty_class/main.cpp
new file mode 100644
index 00000000000..483a57ee5c0
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/empty_class/main.cpp
@@ -0,0 +1,15 @@
+//===-- main.cpp ------------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+class Empty {};
+
+int main (int argc, char const *argv[]) {
+ Empty e;
+ Empty* ep = new Empty;
+ return 0; // Break at this line
+}
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/linked_list/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/linked_list/Makefile
new file mode 100644
index 00000000000..99998b20bcb
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/linked_list/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/linked_list/TestValueAPILinkedList.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/linked_list/TestValueAPILinkedList.py
new file mode 100644
index 00000000000..b45186a3150
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/linked_list/TestValueAPILinkedList.py
@@ -0,0 +1,142 @@
+"""
+Test SBValue API linked_list_iter which treats the SBValue as a linked list and
+supports iteration till the end of list is reached.
+"""
+
+from __future__ import print_function
+
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class ValueAsLinkedListTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+ NO_DEBUG_INFO_TESTCASE = True
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # We'll use the test method name as the exe_name.
+ self.exe_name = self.testMethodName
+ # Find the line number to break at.
+ self.line = line_number('main.cpp', '// Break at this line')
+
+ # Py3 asserts due to a bug in SWIG. A fix for this was upstreamed into
+ # SWIG 3.0.8.
+ @skipIf(py_version=['>=', (3, 0)], swig_version=['<', (3, 0, 8)])
+ @add_test_categories(['pyapi'])
+ def test(self):
+ """Exercise SBValue API linked_list_iter."""
+ d = {'EXE': self.exe_name}
+ self.build(dictionary=d)
+ self.setTearDownCleanup(dictionary=d)
+ exe = self.getBuildArtifact(self.exe_name)
+
+ # Create a target by the debugger.
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+
+ # Create the breakpoint inside function 'main'.
+ breakpoint = target.BreakpointCreateByLocation('main.cpp', self.line)
+ self.assertTrue(breakpoint, VALID_BREAKPOINT)
+
+ # Now launch the process, and do not stop at entry point.
+ process = target.LaunchSimple(
+ None, None, self.get_process_working_directory())
+ self.assertTrue(process, PROCESS_IS_VALID)
+
+ # Get Frame #0.
+ self.assertTrue(process.GetState() == lldb.eStateStopped)
+ thread = lldbutil.get_stopped_thread(
+ process, lldb.eStopReasonBreakpoint)
+ self.assertTrue(
+ thread.IsValid(),
+ "There should be a thread stopped due to breakpoint condition")
+ frame0 = thread.GetFrameAtIndex(0)
+
+ # Get variable 'task_head'.
+ task_head = frame0.FindVariable('task_head')
+ self.assertTrue(task_head, VALID_VARIABLE)
+ self.DebugSBValue(task_head)
+
+ # By design (see main.cpp), the visited id's are: [1, 2, 4, 5].
+ visitedIDs = [1, 2, 4, 5]
+ list = []
+
+ cvf = lldbutil.ChildVisitingFormatter(indent_child=2)
+ for t in task_head.linked_list_iter('next'):
+ self.assertTrue(t, VALID_VARIABLE)
+ # Make sure that 'next' corresponds to an SBValue with pointer
+ # type.
+ self.assertTrue(t.TypeIsPointerType())
+ if self.TraceOn():
+ print(cvf.format(t))
+ list.append(int(t.GetChildMemberWithName("id").GetValue()))
+
+ # Sanity checks that the we visited all the items (no more, no less).
+ if self.TraceOn():
+ print("visited IDs:", list)
+ self.assertTrue(visitedIDs == list)
+
+ # Let's exercise the linked_list_iter() API again, this time supplying
+ # our end of list test function.
+ def eol(val):
+ """Test function to determine end of list."""
+ # End of list is reached if either the value object is invalid
+ # or it corresponds to a null pointer.
+ if not val or int(val.GetValue(), 16) == 0:
+ return True
+ # Also check the "id" for correct semantics. If id <= 0, the item
+ # is corrupted, let's return True to signify end of list.
+ if int(val.GetChildMemberWithName("id").GetValue(), 0) <= 0:
+ return True
+
+ # Otherwise, return False.
+ return False
+
+ list = []
+ for t in task_head.linked_list_iter('next', eol):
+ self.assertTrue(t, VALID_VARIABLE)
+ # Make sure that 'next' corresponds to an SBValue with pointer
+ # type.
+ self.assertTrue(t.TypeIsPointerType())
+ if self.TraceOn():
+ print(cvf.format(t))
+ list.append(int(t.GetChildMemberWithName("id").GetValue()))
+
+ # Sanity checks that the we visited all the items (no more, no less).
+ if self.TraceOn():
+ print("visited IDs:", list)
+ self.assertTrue(visitedIDs == list)
+
+ # Get variable 'empty_task_head'.
+ empty_task_head = frame0.FindVariable('empty_task_head')
+ self.assertTrue(empty_task_head, VALID_VARIABLE)
+ self.DebugSBValue(empty_task_head)
+
+ list = []
+ # There is no iterable item from empty_task_head.linked_list_iter().
+ for t in empty_task_head.linked_list_iter('next', eol):
+ if self.TraceOn():
+ print(cvf.format(t))
+ list.append(int(t.GetChildMemberWithName("id").GetValue()))
+
+ self.assertTrue(len(list) == 0)
+
+ # Get variable 'task_evil'.
+ task_evil = frame0.FindVariable('task_evil')
+ self.assertTrue(task_evil, VALID_VARIABLE)
+ self.DebugSBValue(task_evil)
+
+ list = []
+ # There 3 iterable items from task_evil.linked_list_iter(). :-)
+ for t in task_evil.linked_list_iter('next'):
+ if self.TraceOn():
+ print(cvf.format(t))
+ list.append(int(t.GetChildMemberWithName("id").GetValue()))
+
+ self.assertTrue(len(list) == 3)
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/linked_list/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/linked_list/main.cpp
new file mode 100644
index 00000000000..edd175ae266
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/linked_list/main.cpp
@@ -0,0 +1,55 @@
+//===-- main.c --------------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+#include <stdio.h>
+
+class Task {
+public:
+ int id;
+ Task *next;
+ Task(int i, Task *n):
+ id(i),
+ next(n)
+ {}
+};
+
+
+int main (int argc, char const *argv[])
+{
+ Task *task_head = NULL;
+ Task *task1 = new Task(1, NULL);
+ Task *task2 = new Task(2, NULL);
+ Task *task3 = new Task(3, NULL); // Orphaned.
+ Task *task4 = new Task(4, NULL);
+ Task *task5 = new Task(5, NULL);
+
+ task_head = task1;
+ task1->next = task2;
+ task2->next = task4;
+ task4->next = task5;
+
+ int total = 0;
+ Task *t = task_head;
+ while (t != NULL) {
+ if (t->id >= 0)
+ ++total;
+ t = t->next;
+ }
+ printf("We have a total number of %d tasks\n", total);
+
+ // This corresponds to an empty task list.
+ Task *empty_task_head = NULL;
+
+ Task *task_evil = new Task(1, NULL);
+ Task *task_2 = new Task(2, NULL);
+ Task *task_3 = new Task(3, NULL);
+ task_evil->next = task_2;
+ task_2->next = task_3;
+ task_3->next = task_evil; // In order to cause inifinite loop. :-)
+
+ return 0; // Break at this line
+}
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/main.c b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/main.c
new file mode 100644
index 00000000000..68b3c12cce4
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/value/main.c
@@ -0,0 +1,55 @@
+//===-- main.c --------------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+#include <stdio.h>
+#include <stdint.h>
+
+// This simple program is to test the lldb Python API SBValue.GetChildAtIndex().
+
+int g_my_int = 100;
+
+const char *days_of_week[7] = { "Sunday",
+ "Monday",
+ "Tuesday",
+ "Wednesday",
+ "Thursday",
+ "Friday",
+ "Saturday" };
+
+const char *weekdays[5] = { "Monday",
+ "Tuesday",
+ "Wednesday",
+ "Thursday",
+ "Friday" };
+
+const char **g_table[2] = { days_of_week, weekdays };
+
+typedef int MyInt;
+
+struct MyStruct
+{
+ int a;
+ int b;
+};
+
+int main (int argc, char const *argv[])
+{
+ uint32_t uinthex = 0xE0A35F10;
+ int32_t sinthex = 0xE0A35F10;
+
+ int i;
+ MyInt a = 12345;
+ struct MyStruct s = { 11, 22 };
+ int *my_int_ptr = &g_my_int;
+ printf("my_int_ptr points to location %p\n", my_int_ptr);
+ const char **str_ptr = days_of_week;
+ for (i = 0; i < 7; ++i)
+ printf("%s\n", str_ptr[i]); // Break at this line
+ // and do str_ptr_val.GetChildAtIndex(5, lldb.eNoDynamicValues, True).
+
+ return 0;
+}