diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py +++ b/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 diff --git a/lldb/test/API/tools/lldb-vscode/terminated-event/Makefile b/lldb/test/API/tools/lldb-vscode/eventStatistic/Makefile rename from lldb/test/API/tools/lldb-vscode/terminated-event/Makefile rename to lldb/test/API/tools/lldb-vscode/eventStatistic/Makefile diff --git a/lldb/test/API/tools/lldb-vscode/terminated-event/TestVSCode_terminatedEvent.py b/lldb/test/API/tools/lldb-vscode/eventStatistic/TestVSCode_eventStatistic.py rename from lldb/test/API/tools/lldb-vscode/terminated-event/TestVSCode_terminatedEvent.py rename to lldb/test/API/tools/lldb-vscode/eventStatistic/TestVSCode_eventStatistic.py --- a/lldb/test/API/tools/lldb-vscode/terminated-event/TestVSCode_terminatedEvent.py +++ b/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() diff --git a/lldb/test/API/tools/lldb-vscode/terminated-event/foo.h b/lldb/test/API/tools/lldb-vscode/eventStatistic/foo.h rename from lldb/test/API/tools/lldb-vscode/terminated-event/foo.h rename to lldb/test/API/tools/lldb-vscode/eventStatistic/foo.h diff --git a/lldb/test/API/tools/lldb-vscode/terminated-event/foo.cpp b/lldb/test/API/tools/lldb-vscode/eventStatistic/foo.cpp rename from lldb/test/API/tools/lldb-vscode/terminated-event/foo.cpp rename to lldb/test/API/tools/lldb-vscode/eventStatistic/foo.cpp diff --git a/lldb/test/API/tools/lldb-vscode/terminated-event/main.cpp b/lldb/test/API/tools/lldb-vscode/eventStatistic/main.cpp rename from lldb/test/API/tools/lldb-vscode/terminated-event/main.cpp rename to lldb/test/API/tools/lldb-vscode/eventStatistic/main.cpp diff --git a/lldb/tools/lldb-vscode/JSONUtils.h b/lldb/tools/lldb-vscode/JSONUtils.h --- a/lldb/tools/lldb-vscode/JSONUtils.h +++ b/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); diff --git a/lldb/tools/lldb-vscode/JSONUtils.cpp b/lldb/tools/lldb-vscode/JSONUtils.cpp --- a/lldb/tools/lldb-vscode/JSONUtils.cpp +++ b/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); diff --git a/lldb/tools/lldb-vscode/lldb-vscode.cpp b/lldb/tools/lldb-vscode/lldb-vscode.cpp --- a/lldb/tools/lldb-vscode/lldb-vscode.cpp +++ b/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": {