1e0e6236fSjeffreytan81""" 2e0e6236fSjeffreytan81Test SBTarget.GetStatistics() reporting for dwo files. 3e0e6236fSjeffreytan81""" 4e0e6236fSjeffreytan81 5e0e6236fSjeffreytan81import json 6e0e6236fSjeffreytan81import os 7e0e6236fSjeffreytan81 8e0e6236fSjeffreytan81from lldbsuite.test import lldbtest, lldbutil 9e0e6236fSjeffreytan81from lldbsuite.test.decorators import * 10e0e6236fSjeffreytan81from lldbsuite.test_event.build_exception import BuildError 11e0e6236fSjeffreytan81 12e0e6236fSjeffreytan81 13e0e6236fSjeffreytan81SKELETON_DEBUGINFO_SIZE = 602 14e0e6236fSjeffreytan81MAIN_DWO_DEBUGINFO_SIZE = 385 15e0e6236fSjeffreytan81FOO_DWO_DEBUGINFO_SIZE = 380 16e0e6236fSjeffreytan81 17e0e6236fSjeffreytan81 18e0e6236fSjeffreytan81class TestDebugInfoSize(lldbtest.TestBase): 19e0e6236fSjeffreytan81 # Concurrency is the primary test factor here, not debug info variants. 20e0e6236fSjeffreytan81 NO_DEBUG_INFO_TESTCASE = True 21e0e6236fSjeffreytan81 22e0e6236fSjeffreytan81 def get_output_from_yaml(self): 23e0e6236fSjeffreytan81 exe = self.getBuildArtifact("a.out") 24e0e6236fSjeffreytan81 main_dwo = self.getBuildArtifact("a.out-main.dwo") 25e0e6236fSjeffreytan81 foo_dwo = self.getBuildArtifact("a.out-foo.dwo") 26e0e6236fSjeffreytan81 27e0e6236fSjeffreytan81 src_dir = self.getSourceDir() 28e0e6236fSjeffreytan81 exe_yaml_path = os.path.join(src_dir, "a.out.yaml") 29e0e6236fSjeffreytan81 self.yaml2obj(exe_yaml_path, exe) 30e0e6236fSjeffreytan81 31e0e6236fSjeffreytan81 main_dwo_yaml_path = os.path.join(src_dir, "a.out-main.dwo.yaml") 32e0e6236fSjeffreytan81 self.yaml2obj(main_dwo_yaml_path, main_dwo) 33e0e6236fSjeffreytan81 34e0e6236fSjeffreytan81 foo_dwo_yaml_path = os.path.join(src_dir, "a.out-foo.dwo.yaml") 35e0e6236fSjeffreytan81 self.yaml2obj(foo_dwo_yaml_path, foo_dwo) 36e0e6236fSjeffreytan81 return (exe, main_dwo, foo_dwo) 37e0e6236fSjeffreytan81 38e0e6236fSjeffreytan81 @add_test_categories(["dwo"]) 39e0e6236fSjeffreytan81 def test_dwo(self): 40e0e6236fSjeffreytan81 (exe, main_dwo, foo_dwo) = self.get_output_from_yaml() 41e0e6236fSjeffreytan81 42e0e6236fSjeffreytan81 # Make sure dwo files exist 43e0e6236fSjeffreytan81 self.assertTrue(os.path.exists(main_dwo), f'Make sure "{main_dwo}" file exists') 44e0e6236fSjeffreytan81 self.assertTrue(os.path.exists(foo_dwo), f'Make sure "{foo_dwo}" file exists') 45e0e6236fSjeffreytan81 46e0e6236fSjeffreytan81 target = self.dbg.CreateTarget(exe) 47e0e6236fSjeffreytan81 self.assertTrue(target, lldbtest.VALID_TARGET) 48e0e6236fSjeffreytan81 49e0e6236fSjeffreytan81 stats = target.GetStatistics() 50e0e6236fSjeffreytan81 stream = lldb.SBStream() 51e0e6236fSjeffreytan81 res = stats.GetAsJSON(stream) 52e0e6236fSjeffreytan81 debug_stats = json.loads(stream.GetData()) 53e0e6236fSjeffreytan81 self.assertIn( 54e0e6236fSjeffreytan81 "totalDebugInfoByteSize", 55e0e6236fSjeffreytan81 debug_stats, 56e0e6236fSjeffreytan81 'Make sure the "totalDebugInfoByteSize" key is in target.GetStatistics()', 57e0e6236fSjeffreytan81 ) 58e0e6236fSjeffreytan81 self.assertEqual( 59e0e6236fSjeffreytan81 debug_stats["totalDebugInfoByteSize"], 60e0e6236fSjeffreytan81 SKELETON_DEBUGINFO_SIZE + MAIN_DWO_DEBUGINFO_SIZE + FOO_DWO_DEBUGINFO_SIZE, 61e0e6236fSjeffreytan81 ) 62e0e6236fSjeffreytan81 63e0e6236fSjeffreytan81 @add_test_categories(["dwo"]) 64e0e6236fSjeffreytan81 def test_only_load_skeleton_debuginfo(self): 65e0e6236fSjeffreytan81 (exe, main_dwo, foo_dwo) = self.get_output_from_yaml() 66e0e6236fSjeffreytan81 67e0e6236fSjeffreytan81 # REMOVE one of the dwo files 68e0e6236fSjeffreytan81 os.unlink(main_dwo) 69e0e6236fSjeffreytan81 os.unlink(foo_dwo) 70e0e6236fSjeffreytan81 71e0e6236fSjeffreytan81 target = self.dbg.CreateTarget(exe) 72e0e6236fSjeffreytan81 self.assertTrue(target, lldbtest.VALID_TARGET) 73e0e6236fSjeffreytan81 74e0e6236fSjeffreytan81 stats = target.GetStatistics() 75e0e6236fSjeffreytan81 stream = lldb.SBStream() 76e0e6236fSjeffreytan81 res = stats.GetAsJSON(stream) 77e0e6236fSjeffreytan81 debug_stats = json.loads(stream.GetData()) 78e0e6236fSjeffreytan81 self.assertIn( 79e0e6236fSjeffreytan81 "totalDebugInfoByteSize", 80e0e6236fSjeffreytan81 debug_stats, 81e0e6236fSjeffreytan81 'Make sure the "totalDebugInfoByteSize" key is in target.GetStatistics()', 82e0e6236fSjeffreytan81 ) 83e0e6236fSjeffreytan81 self.assertEqual(debug_stats["totalDebugInfoByteSize"], SKELETON_DEBUGINFO_SIZE) 84e0e6236fSjeffreytan81 85e0e6236fSjeffreytan81 @add_test_categories(["dwo"]) 86e0e6236fSjeffreytan81 def test_load_partial_dwos(self): 87e0e6236fSjeffreytan81 (exe, main_dwo, foo_dwo) = self.get_output_from_yaml() 88e0e6236fSjeffreytan81 89e0e6236fSjeffreytan81 # REMOVE one of the dwo files 90e0e6236fSjeffreytan81 os.unlink(main_dwo) 91e0e6236fSjeffreytan81 92e0e6236fSjeffreytan81 target = self.dbg.CreateTarget(exe) 93e0e6236fSjeffreytan81 self.assertTrue(target, lldbtest.VALID_TARGET) 94e0e6236fSjeffreytan81 95e0e6236fSjeffreytan81 stats = target.GetStatistics() 96e0e6236fSjeffreytan81 stream = lldb.SBStream() 97e0e6236fSjeffreytan81 res = stats.GetAsJSON(stream) 98e0e6236fSjeffreytan81 debug_stats = json.loads(stream.GetData()) 99e0e6236fSjeffreytan81 self.assertIn( 100e0e6236fSjeffreytan81 "totalDebugInfoByteSize", 101e0e6236fSjeffreytan81 debug_stats, 102e0e6236fSjeffreytan81 'Make sure the "totalDebugInfoByteSize" key is in target.GetStatistics()', 103e0e6236fSjeffreytan81 ) 104e0e6236fSjeffreytan81 self.assertEqual( 105e0e6236fSjeffreytan81 debug_stats["totalDebugInfoByteSize"], 106e0e6236fSjeffreytan81 SKELETON_DEBUGINFO_SIZE + FOO_DWO_DEBUGINFO_SIZE, 107e0e6236fSjeffreytan81 ) 108e0e6236fSjeffreytan81 109e0e6236fSjeffreytan81 @add_test_categories(["dwo"]) 110e0e6236fSjeffreytan81 def test_dwos_loaded_symbols_on_demand(self): 111e0e6236fSjeffreytan81 (exe, main_dwo, foo_dwo) = self.get_output_from_yaml() 112e0e6236fSjeffreytan81 113e0e6236fSjeffreytan81 # Make sure dwo files exist 114e0e6236fSjeffreytan81 self.assertTrue(os.path.exists(main_dwo), f'Make sure "{main_dwo}" file exists') 115e0e6236fSjeffreytan81 self.assertTrue(os.path.exists(foo_dwo), f'Make sure "{foo_dwo}" file exists') 116e0e6236fSjeffreytan81 117e0e6236fSjeffreytan81 # Load symbols on-demand 118e0e6236fSjeffreytan81 self.runCmd("settings set symbols.load-on-demand true") 119e0e6236fSjeffreytan81 120e0e6236fSjeffreytan81 target = self.dbg.CreateTarget(exe) 121e0e6236fSjeffreytan81 self.assertTrue(target, lldbtest.VALID_TARGET) 122e0e6236fSjeffreytan81 123*dd7386d8SWanyi # By default dwo files will not be loaded 124e0e6236fSjeffreytan81 stats = target.GetStatistics() 125e0e6236fSjeffreytan81 stream = lldb.SBStream() 126e0e6236fSjeffreytan81 res = stats.GetAsJSON(stream) 127e0e6236fSjeffreytan81 debug_stats = json.loads(stream.GetData()) 128e0e6236fSjeffreytan81 self.assertIn( 129e0e6236fSjeffreytan81 "totalDebugInfoByteSize", 130e0e6236fSjeffreytan81 debug_stats, 131e0e6236fSjeffreytan81 'Make sure the "totalDebugInfoByteSize" key is in target.GetStatistics()', 132e0e6236fSjeffreytan81 ) 133*dd7386d8SWanyi self.assertEqual(debug_stats["totalDebugInfoByteSize"], SKELETON_DEBUGINFO_SIZE) 134*dd7386d8SWanyi 135*dd7386d8SWanyi # Force loading all the dwo files 136*dd7386d8SWanyi stats_options = lldb.SBStatisticsOptions() 137*dd7386d8SWanyi stats_options.SetReportAllAvailableDebugInfo(True) 138*dd7386d8SWanyi stats = target.GetStatistics(stats_options) 139*dd7386d8SWanyi stream = lldb.SBStream() 140*dd7386d8SWanyi stats.GetAsJSON(stream) 141*dd7386d8SWanyi debug_stats = json.loads(stream.GetData()) 142e0e6236fSjeffreytan81 self.assertEqual( 143e0e6236fSjeffreytan81 debug_stats["totalDebugInfoByteSize"], 144e0e6236fSjeffreytan81 SKELETON_DEBUGINFO_SIZE + MAIN_DWO_DEBUGINFO_SIZE + FOO_DWO_DEBUGINFO_SIZE, 145e0e6236fSjeffreytan81 ) 146