summaryrefslogtreecommitdiff
path: root/lldb/test/API/commands/target/debuginfo/TestDebugInfoSize.py
blob: ef56fa654065b86e093c92d7191545c88fd133b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
"""
Test SBTarget.GetStatistics() reporting for dwo files.
"""

import json
import os

from lldbsuite.test import lldbtest, lldbutil
from lldbsuite.test.decorators import *
from lldbsuite.test_event.build_exception import BuildError


SKELETON_DEBUGINFO_SIZE = 602
MAIN_DWO_DEBUGINFO_SIZE = 385
FOO_DWO_DEBUGINFO_SIZE = 380


class TestDebugInfoSize(lldbtest.TestBase):
    # Concurrency is the primary test factor here, not debug info variants.
    NO_DEBUG_INFO_TESTCASE = True

    def get_output_from_yaml(self):
        exe = self.getBuildArtifact("a.out")
        main_dwo = self.getBuildArtifact("a.out-main.dwo")
        foo_dwo = self.getBuildArtifact("a.out-foo.dwo")

        src_dir = self.getSourceDir()
        exe_yaml_path = os.path.join(src_dir, "a.out.yaml")
        self.yaml2obj(exe_yaml_path, exe)

        main_dwo_yaml_path = os.path.join(src_dir, "a.out-main.dwo.yaml")
        self.yaml2obj(main_dwo_yaml_path, main_dwo)

        foo_dwo_yaml_path = os.path.join(src_dir, "a.out-foo.dwo.yaml")
        self.yaml2obj(foo_dwo_yaml_path, foo_dwo)
        return (exe, main_dwo, foo_dwo)

    @add_test_categories(["dwo"])
    def test_dwo(self):
        (exe, main_dwo, foo_dwo) = self.get_output_from_yaml()

        # Make sure dwo files exist
        self.assertTrue(os.path.exists(main_dwo), f'Make sure "{main_dwo}" file exists')
        self.assertTrue(os.path.exists(foo_dwo), f'Make sure "{foo_dwo}" file exists')

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, lldbtest.VALID_TARGET)

        stats = target.GetStatistics()
        stream = lldb.SBStream()
        res = stats.GetAsJSON(stream)
        debug_stats = json.loads(stream.GetData())
        self.assertIn(
            "totalDebugInfoByteSize",
            debug_stats,
            'Make sure the "totalDebugInfoByteSize" key is in target.GetStatistics()',
        )
        self.assertEqual(
            debug_stats["totalDebugInfoByteSize"],
            SKELETON_DEBUGINFO_SIZE + MAIN_DWO_DEBUGINFO_SIZE + FOO_DWO_DEBUGINFO_SIZE,
        )

    @add_test_categories(["dwo"])
    def test_only_load_skeleton_debuginfo(self):
        (exe, main_dwo, foo_dwo) = self.get_output_from_yaml()

        # REMOVE one of the dwo files
        os.unlink(main_dwo)
        os.unlink(foo_dwo)

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, lldbtest.VALID_TARGET)

        stats = target.GetStatistics()
        stream = lldb.SBStream()
        res = stats.GetAsJSON(stream)
        debug_stats = json.loads(stream.GetData())
        self.assertIn(
            "totalDebugInfoByteSize",
            debug_stats,
            'Make sure the "totalDebugInfoByteSize" key is in target.GetStatistics()',
        )
        self.assertEqual(debug_stats["totalDebugInfoByteSize"], SKELETON_DEBUGINFO_SIZE)

    @add_test_categories(["dwo"])
    def test_load_partial_dwos(self):
        (exe, main_dwo, foo_dwo) = self.get_output_from_yaml()

        # REMOVE one of the dwo files
        os.unlink(main_dwo)

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, lldbtest.VALID_TARGET)

        stats = target.GetStatistics()
        stream = lldb.SBStream()
        res = stats.GetAsJSON(stream)
        debug_stats = json.loads(stream.GetData())
        self.assertIn(
            "totalDebugInfoByteSize",
            debug_stats,
            'Make sure the "totalDebugInfoByteSize" key is in target.GetStatistics()',
        )
        self.assertEqual(
            debug_stats["totalDebugInfoByteSize"],
            SKELETON_DEBUGINFO_SIZE + FOO_DWO_DEBUGINFO_SIZE,
        )

    @add_test_categories(["dwo"])
    def test_dwos_loaded_symbols_on_demand(self):
        (exe, main_dwo, foo_dwo) = self.get_output_from_yaml()

        # Make sure dwo files exist
        self.assertTrue(os.path.exists(main_dwo), f'Make sure "{main_dwo}" file exists')
        self.assertTrue(os.path.exists(foo_dwo), f'Make sure "{foo_dwo}" file exists')

        # Load symbols on-demand
        self.runCmd("settings set symbols.load-on-demand true")

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, lldbtest.VALID_TARGET)

        # By default dwo files will not be loaded
        stats = target.GetStatistics()
        stream = lldb.SBStream()
        res = stats.GetAsJSON(stream)
        debug_stats = json.loads(stream.GetData())
        self.assertIn(
            "totalDebugInfoByteSize",
            debug_stats,
            'Make sure the "totalDebugInfoByteSize" key is in target.GetStatistics()',
        )
        self.assertEqual(debug_stats["totalDebugInfoByteSize"], SKELETON_DEBUGINFO_SIZE)

        # Force loading all the dwo files
        stats_options = lldb.SBStatisticsOptions()
        stats_options.SetReportAllAvailableDebugInfo(True)
        stats = target.GetStatistics(stats_options)
        stream = lldb.SBStream()
        stats.GetAsJSON(stream)
        debug_stats = json.loads(stream.GetData())
        self.assertEqual(
            debug_stats["totalDebugInfoByteSize"],
            SKELETON_DEBUGINFO_SIZE + MAIN_DWO_DEBUGINFO_SIZE + FOO_DWO_DEBUGINFO_SIZE,
        )