GeorgeHuyubo created this revision.
Herald added a project: All.
GeorgeHuyubo requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138077

Files:
  lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
  lldb/test/API/tools/lldb-vscode/eventStatistic/Makefile
  lldb/test/API/tools/lldb-vscode/eventStatistic/TestVSCode_eventStatistic.py
  lldb/test/API/tools/lldb-vscode/eventStatistic/foo.cpp
  lldb/test/API/tools/lldb-vscode/eventStatistic/foo.h
  lldb/test/API/tools/lldb-vscode/eventStatistic/main.cpp
  lldb/test/API/tools/lldb-vscode/terminated-event/Makefile
  lldb/test/API/tools/lldb-vscode/terminated-event/TestVSCode_terminatedEvent.py
  lldb/test/API/tools/lldb-vscode/terminated-event/foo.cpp
  lldb/test/API/tools/lldb-vscode/terminated-event/foo.h
  lldb/test/API/tools/lldb-vscode/terminated-event/main.cpp
  lldb/tools/lldb-vscode/JSONUtils.cpp
  lldb/tools/lldb-vscode/JSONUtils.h
  lldb/tools/lldb-vscode/lldb-vscode.cpp

Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===================================================================
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -687,7 +687,7 @@
   g_vsc.SendJSON(llvm::json::Value(std::move(response)));
   if (error.Success()) {
     SendProcessEvent(Attach);
-    g_vsc.SendJSON(CreateEventObject("initialized"));
+    g_vsc.SendJSON(CreateInitializedEventObject());
   }
 }
 
@@ -1754,7 +1754,7 @@
     SendProcessEvent(Attach); // this happens when doing runInTerminal
   else
     SendProcessEvent(Launch);
-  g_vsc.SendJSON(llvm::json::Value(CreateEventObject("initialized")));
+  g_vsc.SendJSON(CreateInitializedEventObject());
 }
 
 // "NextRequest": {
Index: lldb/tools/lldb-vscode/JSONUtils.h
===================================================================
--- lldb/tools/lldb-vscode/JSONUtils.h
+++ lldb/tools/lldb-vscode/JSONUtils.h
@@ -491,6 +491,12 @@
 ///     A body JSON object with debug info and breakpoint info
 llvm::json::Object CreateTerminatedEventObject();
 
+/// Create a "Initialized" JSON object that contains statistics
+///
+/// \return
+///     A body JSON object with debug info
+llvm::json::Object CreateInitializedEventObject();
+
 /// Convert a given JSON object to a string.
 std::string JSONToString(const llvm::json::Value &json);
 
Index: lldb/tools/lldb-vscode/JSONUtils.cpp
===================================================================
--- lldb/tools/lldb-vscode/JSONUtils.cpp
+++ lldb/tools/lldb-vscode/JSONUtils.cpp
@@ -1209,6 +1209,12 @@
   return event;
 }
 
+llvm::json::Object CreateInitializedEventObject() {
+  llvm::json::Object event(CreateEventObject("initialized"));
+  addStatistic(event);
+  return event;
+}
+
 std::string JSONToString(const llvm::json::Value &json) {
   std::string data;
   llvm::raw_string_ostream os(data);
Index: lldb/test/API/tools/lldb-vscode/terminated-event/main.cpp
===================================================================
--- /dev/null
+++ lldb/test/API/tools/lldb-vscode/terminated-event/main.cpp
@@ -1,8 +0,0 @@
-#include <iostream>
-#include "foo.h"
-
-int main(int argc, char const *argv[]) {
-  std::cout << "Hello World!" << std::endl; // main breakpoint 1
-  foo();
-  return 0;
-}
Index: lldb/test/API/tools/lldb-vscode/terminated-event/foo.h
===================================================================
--- /dev/null
+++ lldb/test/API/tools/lldb-vscode/terminated-event/foo.h
@@ -1 +0,0 @@
-int foo();
Index: lldb/test/API/tools/lldb-vscode/terminated-event/foo.cpp
===================================================================
--- /dev/null
+++ lldb/test/API/tools/lldb-vscode/terminated-event/foo.cpp
@@ -1,3 +0,0 @@
-int foo() {
-    return 12;
-}
Index: lldb/test/API/tools/lldb-vscode/eventStatistic/TestVSCode_eventStatistic.py
===================================================================
--- lldb/test/API/tools/lldb-vscode/eventStatistic/TestVSCode_eventStatistic.py
+++ lldb/test/API/tools/lldb-vscode/eventStatistic/TestVSCode_eventStatistic.py
@@ -10,7 +10,27 @@
 import re
 import json
 
-class TestVSCode_terminatedEvent(lldbvscode_testcase.VSCodeTestCaseBase):
+class TestVSCode_eventStatistic(lldbvscode_testcase.VSCodeTestCaseBase):
+
+    def check_statistic(self, statistics):
+        self.assertTrue(statistics['totalDebugInfoByteSize'] > 0)
+        self.assertTrue(statistics['totalDebugInfoEnabled'] > 0)
+        self.assertTrue(statistics['totalModuleCountHasDebugInfo'] > 0)
+
+        self.assertIsNotNone(statistics['memory'])
+        self.assertNotIn('modules', statistics.keys())
+
+    def check_target(self, statistics):
+        # lldb-vscode debugs one target at a time
+        target = json.loads(statistics['targets'])[0]
+        self.assertTrue(target['totalBreakpointResolveTime'] > 0)
+
+        breakpoints = target['breakpoints']
+        self.assertIn('foo',
+                      breakpoints[0]['details']['Breakpoint']['BKPTResolver']['Options']['SymbolNames'],
+                      'foo is a symbol breakpoint')
+        self.assertTrue(breakpoints[1]['details']['Breakpoint']['BKPTResolver']['Options']['FileName'].endswith('main.cpp'),
+                        'target has source line breakpoint in main.cpp')
 
     @skipIfWindows
     @skipIfRemote
@@ -45,20 +65,33 @@
         self.continue_to_exit()
 
         statistics = self.vscode.wait_for_terminated()['statistics']
-        self.assertTrue(statistics['totalDebugInfoByteSize'] > 0)
-        self.assertTrue(statistics['totalDebugInfoEnabled'] > 0)
-        self.assertTrue(statistics['totalModuleCountHasDebugInfo'] > 0)
+        self.check_statistic(statistics)
+        self.check_target(statistics)
 
-        self.assertIsNotNone(statistics['memory'])
-        self.assertNotIn('modules', statistics.keys())
+    @skipIfWindows
+    @skipIfRemote
+    def test_initialized_event(self):
+        '''
+            Initialized Event
+            Now contains the statistics of a debug session:
+                totalDebugInfoByteSize > 0
+                totalDebugInfoEnabled > 0
+                totalModuleCountHasDebugInfo > 0
+                totalBreakpointResolveTime > 0
+                ...
+        '''
 
-        # lldb-vscode debugs one target at a time
-        target = json.loads(statistics['targets'])[0]
-        self.assertTrue(target['totalBreakpointResolveTime'] > 0)
+        program_basename = "a.out.stripped"
+        program = self.getBuildArtifact(program_basename)
+        self.build_and_launch(program)
+        # Set breakpoints
+        functions = ['foo']
+        breakpoint_ids = self.set_function_breakpoints(functions)
+        self.assertEquals(len(breakpoint_ids), len(functions), 'expect one breakpoint')
+        main_bp_line = line_number('main.cpp', '// main breakpoint 1')
+        breakpoint_ids.append(self.set_source_breakpoints('main.cpp', [main_bp_line]))
 
-        breakpoints = target['breakpoints']
-        self.assertIn('foo',
-                      breakpoints[0]['details']['Breakpoint']['BKPTResolver']['Options']['SymbolNames'],
-                      'foo is a symbol breakpoint')
-        self.assertTrue(breakpoints[1]['details']['Breakpoint']['BKPTResolver']['Options']['FileName'].endswith('main.cpp'),
-                        'target has source line breakpoint in main.cpp')
+        self.continue_to_breakpoints(breakpoint_ids)
+        statistics = self.vscode.initialized_event['statistics']
+        self.check_statistic(statistics)
+        self.continue_to_exit()
Index: lldb/test/API/tools/lldb-vscode/terminated-event/Makefile
===================================================================
--- /dev/null
+++ lldb/test/API/tools/lldb-vscode/terminated-event/Makefile
@@ -1,17 +0,0 @@
-DYLIB_NAME := foo
-DYLIB_CXX_SOURCES := foo.cpp
-CXX_SOURCES := main.cpp
-
-LD_EXTRAS := -Wl,-rpath "-Wl,$(shell pwd)"
-USE_LIBDL :=1
-
-include Makefile.rules
-
-all: a.out.stripped
-
-a.out.stripped:
-	strip -o a.out.stripped a.out
-
-ifneq "$(CODESIGN)" ""
-	$(CODESIGN) -fs - a.out.stripped
-endif
\ No newline at end of file
Index: lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
+++ lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
@@ -134,6 +134,7 @@
         self.configuration_done_sent = False
         self.frame_scopes = {}
         self.init_commands = init_commands
+        self.initialized_event = None
 
     @classmethod
     def encode_content(cls, s):
@@ -231,6 +232,8 @@
                 self._process_stopped()
                 tid = body['threadId']
                 self.thread_stop_reasons[tid] = body
+            elif event == 'initialized':
+                self.initialized_event = packet
             elif event == 'breakpoint':
                 # Breakpoint events come in when a breakpoint has locations
                 # added or removed. Keep track of them so we can look for them
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to