The field ‘totalFrames’ which is total number of frames available, is mandatory in...
authorSerhiy Redko <serhiy.redko@oculus.com>
Sun, 8 Dec 2019 04:11:35 +0000 (20:11 -0800)
committerNathan Lanza <nathan@lanza.io>
Mon, 9 Dec 2019 18:43:50 +0000 (10:43 -0800)
"The debug adapter supports the delayed loading of parts of the stack,
which requires that both the 'startFrame' and 'levels' arguments and the
'totalFrames' result of the 'StackTrace' request are supported."

Lack of this field makes VSCode incorrectly display stack traces information

D71034

lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/stackTrace/TestVSCode_stackTrace.py
lldb/tools/lldb-vscode/lldb-vscode.cpp

index b0f69b2..9f8047d 100644 (file)
@@ -132,15 +132,29 @@ class VSCodeTestCaseBase(TestBase):
                                     key, key_path, d))
         return value
 
-    def get_stackFrames(self, threadId=None, startFrame=None, levels=None,
-                        dump=False):
+    def get_stackFrames_and_totalFramesCount(self, threadId=None, startFrame=None, 
+                        levels=None, dump=False):
         response = self.vscode.request_stackTrace(threadId=threadId,
                                                   startFrame=startFrame,
                                                   levels=levels,
                                                   dump=dump)
         if response:
-            return self.get_dict_value(response, ['body', 'stackFrames'])
-        return None
+            stackFrames = self.get_dict_value(response, ['body', 'stackFrames'])
+            totalFrames = self.get_dict_value(response, ['body', 'totalFrames'])
+            self.assertTrue(totalFrames > 0,
+                    'verify totalFrames count is provided by extension that supports '
+                    'async frames loading')
+            return (stackFrames, totalFrames)
+        return (None, 0)
+
+    def get_stackFrames(self, threadId=None, startFrame=None, levels=None,
+                        dump=False):
+        (stackFrames, totalFrames) = self.get_stackFrames_and_totalFramesCount(
+                                                threadId=threadId,
+                                                startFrame=startFrame,
+                                                levels=levels,
+                                                dump=dump)
+        return stackFrames
 
     def get_source_and_line(self, threadId=None, frameIndex=0):
         stackFrames = self.get_stackFrames(threadId=threadId,
index 4aca14f..723c09e 100644 (file)
@@ -76,10 +76,12 @@ class TestVSCode_stackTrace(lldbvscode_testcase.VSCodeTestCaseBase):
         self.continue_to_breakpoints(breakpoint_ids)
         startFrame = 0
         # Verify we get all stack frames with no arguments
-        stackFrames = self.get_stackFrames()
+        (stackFrames, totalFrames) = self.get_stackFrames_and_totalFramesCount()
         frameCount = len(stackFrames)
         self.assertTrue(frameCount >= 20,
                         'verify we get at least 20 frames for all frames')
+        self.assertTrue(totalFrames == frameCount,
+                        'verify we get correct value for totalFrames count')
         self.verify_stackFrames(startFrame, stackFrames)
 
         # Verify all stack frames by specifying startFrame = 0 and levels not
@@ -133,11 +135,15 @@ class TestVSCode_stackTrace(lldbvscode_testcase.VSCodeTestCaseBase):
         # Verify we cap things correctly when we ask for too many frames
         startFrame = 5
         levels = 1000
-        stackFrames = self.get_stackFrames(startFrame=startFrame,
-                                           levels=levels)
+        (stackFrames, totalFrames) = self.get_stackFrames_and_totalFramesCount(
+                                            startFrame=startFrame,
+                                            levels=levels)
         self.assertTrue(len(stackFrames) == frameCount - startFrame,
                         ('verify less than 1000 frames with startFrame=%i and'
                          ' levels=%i') % (startFrame, levels))
+        self.assertTrue(totalFrames == frameCount,
+                        'verify we get correct value for totalFrames count '
+                        'when requested frames not from 0 index')
         self.verify_stackFrames(startFrame, stackFrames)
 
         # Verify level=0 works with non-zerp start frame
index db734ad..6d638a6 100644 (file)
@@ -2166,6 +2166,8 @@ void request_stackTrace(const llvm::json::Object &request) {
         break;
       stackFrames.emplace_back(CreateStackFrame(frame));
     }
+    const auto totalFrames = thread.GetNumFrames();
+    body.try_emplace("totalFrames", totalFrames);
   }
   body.try_emplace("stackFrames", std::move(stackFrames));
   response.try_emplace("body", std::move(body));