Prevent steps into cast operators.
authorMikhail Kurinnoi <m.kurinnoi@samsung.com>
Thu, 11 Jan 2024 14:49:13 +0000 (17:49 +0300)
committerGleb Balykov/Advanced System SW Lab /SRR/Staff Engineer/Samsung Electronics <g.balykov@samsung.com>
Tue, 23 Jan 2024 19:15:59 +0000 (22:15 +0300)
Related to https://github.com/Samsung/netcoredbg/issues/154

src/debugger/steppers.cpp
test-suite/MITestStepping/Program.cs
test-suite/VSCodeTestStepping/Program.cs

index 763cf1a35abb48b464cece83fa89efb66418d2c2..6a2939a8810d1491587f397f06373b541cfd973c 100644 (file)
@@ -15,6 +15,9 @@ namespace netcoredbg
 // From ECMA-335\r
 static const std::unordered_set<WSTRING> g_operatorMethodNames\r
 {\r
+// Cast operators\r
+    W("op_Implicit"),\r
+    W("op_Explicit"),\r
 // Unary operators\r
     W("op_Decrement"),                    // --\r
     W("op_Increment"),                    // ++\r
index fa4a8ea09a2f1b0a0a14c96a5aad2255a08f5ac0..d34cbbaff79d5e3c695cc368abb10122afc9a37a 100644 (file)
@@ -217,6 +217,24 @@ namespace NetcoreDbgTest.Script
 
 namespace MITestStepping
 {
+    public readonly struct Digit
+    {
+        private readonly byte digit;
+
+        public Digit(byte digit)
+        {
+            this.digit = digit;
+        }
+        public static implicit operator byte(Digit d)
+        {
+            return d.digit;
+        }
+        public static explicit operator Digit(byte b)
+        {
+            return new Digit(b);
+        }
+    }
+
     class Program
     {
         static void Main(string[] args)
@@ -319,7 +337,7 @@ namespace MITestStepping
             res = TestImplHolder.getImpl2().Calc1();                        Label.Breakpoint("test_step_through2");
             Console.WriteLine("Test step through end.");                    Label.Breakpoint("test_step_through_end");
 
-            Label.Checkpoint("test_step_through", "finish", (Object context) => {
+            Label.Checkpoint("test_step_through", "test_step_cast", (Object context) => {
                 Context Context = (Context)context;
                 Context.WasStep(@"__FILE__:__LINE__", "test_step_through1");
                 Context.StepIn(@"__FILE__:__LINE__");
@@ -336,6 +354,26 @@ namespace MITestStepping
                 Context.StepOut(@"__FILE__:__LINE__");
 
                 Context.WasStep(@"__FILE__:__LINE__", "test_step_through_end");
+                Context.StepOver(@"__FILE__:__LINE__");
+            });
+
+            // Test steps for casts.
+
+            var d = new Digit(100);                                         Label.Breakpoint("test_step_cast1");
+            byte byte_var = d;                                              Label.Breakpoint("test_step_cast2");
+            Digit digit_var = (Digit)byte_var;                              Label.Breakpoint("test_step_cast3");
+            Console.WriteLine("Test steps for casts end.");                 Label.Breakpoint("test_step_cast_end");
+
+            Label.Checkpoint("test_step_cast", "finish", (Object context) => {
+                Context Context = (Context)context;
+                Context.WasStep(@"__FILE__:__LINE__", "test_step_cast1");
+                Context.StepOver(@"__FILE__:__LINE__");
+                Context.WasStep(@"__FILE__:__LINE__", "test_step_cast2");
+                Context.StepIn(@"__FILE__:__LINE__");
+                Context.WasStep(@"__FILE__:__LINE__", "test_step_cast3");
+                Context.StepIn(@"__FILE__:__LINE__");
+
+                Context.WasStep(@"__FILE__:__LINE__", "test_step_cast_end");
                 Context.StepOut(@"__FILE__:__LINE__");
             });
 
index bc45625894cfd55cd4ffc6e911c993c58c47ac71..98888f795ad40ec1ee311e9cbae2cce7042cc4da 100644 (file)
@@ -228,6 +228,24 @@ namespace NetcoreDbgTest.Script
 
 namespace VSCodeTestStepping
 {
+    public readonly struct Digit
+    {
+        private readonly byte digit;
+
+        public Digit(byte digit)
+        {
+            this.digit = digit;
+        }
+        public static implicit operator byte(Digit d)
+        {
+            return d.digit;
+        }
+        public static explicit operator Digit(byte b)
+        {
+            return new Digit(b);
+        }
+    }
+
     class Program
     {
         static void Main(string[] args)
@@ -332,7 +350,7 @@ namespace VSCodeTestStepping
             res = TestImplHolder.getImpl2().Calc1();                        Label.Breakpoint("test_step_through2");
             Console.WriteLine("Test step through end.");                    Label.Breakpoint("test_step_through_end");
 
-            Label.Checkpoint("test_step_through", "finish", (Object context) => {
+            Label.Checkpoint("test_step_through", "test_step_cast", (Object context) => {
                 Context Context = (Context)context;
                 Context.WasStep(@"__FILE__:__LINE__", "test_step_through1");
                 Context.StepIn(@"__FILE__:__LINE__");
@@ -349,6 +367,26 @@ namespace VSCodeTestStepping
                 Context.StepOut(@"__FILE__:__LINE__");
 
                 Context.WasStep(@"__FILE__:__LINE__", "test_step_through_end");
+                Context.StepOver(@"__FILE__:__LINE__");
+            });
+
+            // Test steps for casts.
+
+            var d = new Digit(100);                                         Label.Breakpoint("test_step_cast1");
+            byte byte_var = d;                                              Label.Breakpoint("test_step_cast2");
+            Digit digit_var = (Digit)byte_var;                              Label.Breakpoint("test_step_cast3");
+            Console.WriteLine("Test steps for casts end.");                 Label.Breakpoint("test_step_cast_end");
+
+            Label.Checkpoint("test_step_cast", "finish", (Object context) => {
+                Context Context = (Context)context;
+                Context.WasStep(@"__FILE__:__LINE__", "test_step_cast1");
+                Context.StepOver(@"__FILE__:__LINE__");
+                Context.WasStep(@"__FILE__:__LINE__", "test_step_cast2");
+                Context.StepIn(@"__FILE__:__LINE__");
+                Context.WasStep(@"__FILE__:__LINE__", "test_step_cast3");
+                Context.StepIn(@"__FILE__:__LINE__");
+
+                Context.WasStep(@"__FILE__:__LINE__", "test_step_cast_end");
                 Context.StepOut(@"__FILE__:__LINE__");
             });