199451b44SJordan Rupprecht""" 299451b44SJordan RupprechtMake sure the getting a variable path works and doesn't crash. 399451b44SJordan Rupprecht""" 499451b44SJordan Rupprecht 599451b44SJordan Rupprecht 699451b44SJordan Rupprechtimport lldb 799451b44SJordan Rupprechtimport lldbsuite.test.lldbutil as lldbutil 8f2a86617SMuhammad Omair Javaidfrom lldbsuite.test.decorators import * 999451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import * 1099451b44SJordan Rupprecht 1199451b44SJordan Rupprecht 1299451b44SJordan Rupprechtclass TestVarPath(TestBase): 13c6ad6901SVenkata Ramanaiah Nalamothu # If your test case doesn't stress debug info, then 1499451b44SJordan Rupprecht # set this to true. That way it won't be run once for 1599451b44SJordan Rupprecht # each debug info format. 1699451b44SJordan Rupprecht NO_DEBUG_INFO_TESTCASE = True 1799451b44SJordan Rupprecht 1899451b44SJordan Rupprecht def test_frame_var(self): 1999451b44SJordan Rupprecht self.build() 2099451b44SJordan Rupprecht self.do_test() 2199451b44SJordan Rupprecht 2299451b44SJordan Rupprecht def verify_point(self, frame, var_name, var_typename, x_value, y_value): 2399451b44SJordan Rupprecht v = frame.GetValueForVariablePath(var_name) 24779bbbf2SDave Lee self.assertSuccess(v.GetError(), "Make sure we find '%s'" % (var_name)) 25*80fcecb1SJonas Devlieghere self.assertEqual( 262238dcc3SJonas Devlieghere v.GetType().GetName(), 272238dcc3SJonas Devlieghere var_typename, 282238dcc3SJonas Devlieghere "Make sure '%s' has type '%s'" % (var_name, var_typename), 292238dcc3SJonas Devlieghere ) 3099451b44SJordan Rupprecht 312238dcc3SJonas Devlieghere if "*" in var_typename: 322238dcc3SJonas Devlieghere valid_prefix = var_name + "->" 332238dcc3SJonas Devlieghere invalid_prefix = var_name + "." 3499451b44SJordan Rupprecht else: 352238dcc3SJonas Devlieghere valid_prefix = var_name + "." 362238dcc3SJonas Devlieghere invalid_prefix = var_name + "->" 3799451b44SJordan Rupprecht 382238dcc3SJonas Devlieghere valid_x_path = valid_prefix + "x" 392238dcc3SJonas Devlieghere valid_y_path = valid_prefix + "y" 402238dcc3SJonas Devlieghere invalid_x_path = invalid_prefix + "x" 412238dcc3SJonas Devlieghere invalid_y_path = invalid_prefix + "y" 422238dcc3SJonas Devlieghere invalid_m_path = invalid_prefix + "m" 4399451b44SJordan Rupprecht 4499451b44SJordan Rupprecht v = frame.GetValueForVariablePath(valid_x_path) 45779bbbf2SDave Lee self.assertSuccess(v.GetError(), "Make sure we find '%s'" % (valid_x_path)) 46*80fcecb1SJonas Devlieghere self.assertEqual( 472238dcc3SJonas Devlieghere v.GetValue(), 482238dcc3SJonas Devlieghere str(x_value), 492238dcc3SJonas Devlieghere "Make sure '%s' has a value of %i" % (valid_x_path, x_value), 502238dcc3SJonas Devlieghere ) 51*80fcecb1SJonas Devlieghere self.assertEqual( 522238dcc3SJonas Devlieghere v.GetType().GetName(), 532238dcc3SJonas Devlieghere "int", 542238dcc3SJonas Devlieghere "Make sure '%s' has type 'int'" % (valid_x_path), 552238dcc3SJonas Devlieghere ) 5699451b44SJordan Rupprecht v = frame.GetValueForVariablePath(invalid_x_path) 572238dcc3SJonas Devlieghere self.assertTrue( 582238dcc3SJonas Devlieghere v.GetError().Fail(), "Make sure we don't find '%s'" % (invalid_x_path) 592238dcc3SJonas Devlieghere ) 6099451b44SJordan Rupprecht 6199451b44SJordan Rupprecht v = frame.GetValueForVariablePath(valid_y_path) 62779bbbf2SDave Lee self.assertSuccess(v.GetError(), "Make sure we find '%s'" % (valid_y_path)) 63*80fcecb1SJonas Devlieghere self.assertEqual( 642238dcc3SJonas Devlieghere v.GetValue(), 652238dcc3SJonas Devlieghere str(y_value), 662238dcc3SJonas Devlieghere "Make sure '%s' has a value of %i" % (valid_y_path, y_value), 672238dcc3SJonas Devlieghere ) 68*80fcecb1SJonas Devlieghere self.assertEqual( 692238dcc3SJonas Devlieghere v.GetType().GetName(), 702238dcc3SJonas Devlieghere "int", 712238dcc3SJonas Devlieghere "Make sure '%s' has type 'int'" % (valid_y_path), 722238dcc3SJonas Devlieghere ) 7399451b44SJordan Rupprecht v = frame.GetValueForVariablePath(invalid_y_path) 742238dcc3SJonas Devlieghere self.assertTrue( 752238dcc3SJonas Devlieghere v.GetError().Fail(), "Make sure we don't find '%s'" % (invalid_y_path) 762238dcc3SJonas Devlieghere ) 7799451b44SJordan Rupprecht 7899451b44SJordan Rupprecht v = frame.GetValueForVariablePath(invalid_m_path) 792238dcc3SJonas Devlieghere self.assertTrue( 802238dcc3SJonas Devlieghere v.GetError().Fail(), "Make sure we don't find '%s'" % (invalid_m_path) 812238dcc3SJonas Devlieghere ) 8299451b44SJordan Rupprecht 8399451b44SJordan Rupprecht def do_test(self): 8499451b44SJordan Rupprecht (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( 852238dcc3SJonas Devlieghere self, "// Set a breakpoint here", lldb.SBFileSpec("main.cpp") 862238dcc3SJonas Devlieghere ) 8799451b44SJordan Rupprecht 8899451b44SJordan Rupprecht frame = thread.GetFrameAtIndex(0) 892238dcc3SJonas Devlieghere v = frame.GetValueForVariablePath("no_such_variable") 902238dcc3SJonas Devlieghere self.assertTrue( 912238dcc3SJonas Devlieghere v.GetError().Fail(), "Make sure we don't find 'no_such_variable'" 922238dcc3SJonas Devlieghere ) 9399451b44SJordan Rupprecht 9499451b44SJordan Rupprecht # Test an instance 952238dcc3SJonas Devlieghere self.verify_point(frame, "pt", "Point", 1, 2) 9699451b44SJordan Rupprecht # Test a pointer 972238dcc3SJonas Devlieghere self.verify_point(frame, "pt_ptr", "Point *", 3030, 4040) 9899451b44SJordan Rupprecht # Test using a pointer as an array 992238dcc3SJonas Devlieghere self.verify_point(frame, "pt_ptr[-1]", "Point", 1010, 2020) 1002238dcc3SJonas Devlieghere self.verify_point(frame, "pt_ptr[0]", "Point", 3030, 4040) 1012238dcc3SJonas Devlieghere self.verify_point(frame, "pt_ptr[1]", "Point", 5050, 6060) 10299451b44SJordan Rupprecht # Test arrays 1032238dcc3SJonas Devlieghere v = frame.GetValueForVariablePath("points") 104779bbbf2SDave Lee self.assertSuccess(v.GetError(), "Make sure we find 'points'") 1052238dcc3SJonas Devlieghere self.verify_point(frame, "points[0]", "Point", 1010, 2020) 1062238dcc3SJonas Devlieghere self.verify_point(frame, "points[1]", "Point", 3030, 4040) 1072238dcc3SJonas Devlieghere self.verify_point(frame, "points[2]", "Point", 5050, 6060) 1082238dcc3SJonas Devlieghere v = frame.GetValueForVariablePath("points[0]+5") 1092238dcc3SJonas Devlieghere self.assertTrue( 1102238dcc3SJonas Devlieghere v.GetError().Fail(), 1112238dcc3SJonas Devlieghere "Make sure we do not ignore characters between ']' and the end", 1122238dcc3SJonas Devlieghere ) 11399451b44SJordan Rupprecht # Test a reference 1142238dcc3SJonas Devlieghere self.verify_point(frame, "pt_ref", "Point &", 1, 2) 1152238dcc3SJonas Devlieghere v = frame.GetValueForVariablePath("pt_sp") 116779bbbf2SDave Lee self.assertSuccess(v.GetError(), "Make sure we find 'pt_sp'") 11799451b44SJordan Rupprecht # Make sure we don't crash when looking for non existant child 11899451b44SJordan Rupprecht # in type with synthetic children. This used to cause a crash. 119f2a86617SMuhammad Omair Javaid if not self.isAArch64Windows(): 1202238dcc3SJonas Devlieghere v = frame.GetValueForVariablePath("pt_sp->not_valid_child") 121ab855530SJonas Devlieghere self.assertTrue( 122ab855530SJonas Devlieghere v.GetError().Fail(), "Make sure we don't find 'pt_sp->not_valid_child'" 123ab855530SJonas Devlieghere ) 124