"""
Make sure 'frame var' using DIL parser/evaultor works for local variables.
"""

import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
from lldbsuite.test import lldbutil


class TestFrameVarDILLocalVars(TestBase):
    # If your test case doesn't stress debug info, then
    # set this to true.  That way it won't be run once for
    # each debug info format.
    NO_DEBUG_INFO_TESTCASE = True

    def test_frame_var(self):
        self.build()
        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
            self, "Set a breakpoint here", lldb.SBFileSpec("main.cpp")
        )

        self.runCmd("settings set target.experimental.use-DIL true")
        self.expect_var_path("a", value="1")
        self.expect_var_path("b", value="2")
        self.expect_var_path("c", value="'\\xfd'")
        self.expect_var_path("s", value="4")

        # Check that identifiers are allowed in both simple and legacy modes
        frame = thread.GetFrameAtIndex(0)
        simple = frame.GetValueForVariablePath("a", lldb.eDILModeSimple)
        legacy = frame.GetValueForVariablePath("a", lldb.eDILModeLegacy)
        self.assertSuccess(simple.GetError())
        self.assertSuccess(legacy.GetError())
