summaryrefslogtreecommitdiffstats
path: root/packages/Python/lldbsuite/test/python_api/value/change_values
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2016-01-06 20:12:03 +0000
committerdim <dim@FreeBSD.org>2016-01-06 20:12:03 +0000
commit78b9749c0a4ea980a8b934645da6ae98fcc665e8 (patch)
treedd2a1ddf0476664c2b823409c36cbccd52662ca7 /packages/Python/lldbsuite/test/python_api/value/change_values
parent60cb593f9d55fa5ca7a5372b731f2330345b4b9a (diff)
downloadFreeBSD-src-78b9749c0a4ea980a8b934645da6ae98fcc665e8.zip
FreeBSD-src-78b9749c0a4ea980a8b934645da6ae98fcc665e8.tar.gz
Vendor import of lldb trunk r256945:
https://llvm.org/svn/llvm-project/lldb/trunk@256945
Diffstat (limited to 'packages/Python/lldbsuite/test/python_api/value/change_values')
-rw-r--r--packages/Python/lldbsuite/test/python_api/value/change_values/Makefile5
-rw-r--r--packages/Python/lldbsuite/test/python_api/value/change_values/TestChangeValueAPI.py148
-rw-r--r--packages/Python/lldbsuite/test/python_api/value/change_values/main.c29
3 files changed, 182 insertions, 0 deletions
diff --git a/packages/Python/lldbsuite/test/python_api/value/change_values/Makefile b/packages/Python/lldbsuite/test/python_api/value/change_values/Makefile
new file mode 100644
index 0000000..b09a579
--- /dev/null
+++ b/packages/Python/lldbsuite/test/python_api/value/change_values/Makefile
@@ -0,0 +1,5 @@
+LEVEL = ../../../make
+
+C_SOURCES := main.c
+
+include $(LEVEL)/Makefile.rules
diff --git a/packages/Python/lldbsuite/test/python_api/value/change_values/TestChangeValueAPI.py b/packages/Python/lldbsuite/test/python_api/value/change_values/TestChangeValueAPI.py
new file mode 100644
index 0000000..77aefe0
--- /dev/null
+++ b/packages/Python/lldbsuite/test/python_api/value/change_values/TestChangeValueAPI.py
@@ -0,0 +1,148 @@
+"""
+Test some SBValue APIs.
+"""
+
+from __future__ import print_function
+
+
+
+import os, time
+import re
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+
+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')
+
+ @expectedFailureWindows("llvm.org/pr24772")
+ @add_test_categories(['pyapi'])
+ def test_change_value(self):
+ """Exercise the SBValue::SetValueFromCString API."""
+ d = {'EXE': self.exe_name}
+ self.build(dictionary=d)
+ self.setTearDownCleanup(dictionary=d)
+ exe = os.path.join(os.getcwd(), 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 == None, "We should not have managed to hit our second breakpoint with sp == 1")
+
+ process.Kill()
diff --git a/packages/Python/lldbsuite/test/python_api/value/change_values/main.c b/packages/Python/lldbsuite/test/python_api/value/change_values/main.c
new file mode 100644
index 0000000..01455c0
--- /dev/null
+++ b/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
+}
OpenPOWER on IntegriCloud