llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-lldb Author: None (GeorgeHuyubo) <details> <summary>Changes</summary> Re-attemp landing of old commit: https://github.com/llvm/llvm-project/commit/7fe3586cda5b683766ec6b6d5ca2d98c2baaf162 --- Full diff: https://github.com/llvm/llvm-project/pull/178978.diff 9 Files Affected: - (modified) lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py (+2) - (added) lldb/test/API/tools/lldb-dap/eventStatistic/Makefile (+17) - (added) lldb/test/API/tools/lldb-dap/eventStatistic/TestVSCode_eventStatistic.py (+76) - (added) lldb/test/API/tools/lldb-dap/eventStatistic/foo.cpp (+1) - (added) lldb/test/API/tools/lldb-dap/eventStatistic/foo.h (+1) - (added) lldb/test/API/tools/lldb-dap/eventStatistic/main.cpp (+8) - (modified) lldb/tools/lldb-dap/Handler/RequestHandler.h (+2-2) - (modified) lldb/tools/lldb-dap/JSONUtils.cpp (+6) - (modified) lldb/tools/lldb-dap/JSONUtils.h (+6) ``````````diff diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py index 14391db74302c..8719baff6bf8b 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py @@ -309,6 +309,7 @@ def __init__( # trigger enqueue thread self._recv_thread.start() + self.initialized_event = None @classmethod def encode_content(cls, s: str) -> bytes: @@ -515,6 +516,7 @@ def _handle_event(self, packet: Event) -> None: self.output[category] = output elif event == "initialized": self.initialized = True + self.initialized_event = packet elif event == "process": # When a new process is attached or launched, remember the # details that are available in the body of the event diff --git a/lldb/test/API/tools/lldb-dap/eventStatistic/Makefile b/lldb/test/API/tools/lldb-dap/eventStatistic/Makefile new file mode 100644 index 0000000000000..b30baf48b972e --- /dev/null +++ b/lldb/test/API/tools/lldb-dap/eventStatistic/Makefile @@ -0,0 +1,17 @@ +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 diff --git a/lldb/test/API/tools/lldb-dap/eventStatistic/TestVSCode_eventStatistic.py b/lldb/test/API/tools/lldb-dap/eventStatistic/TestVSCode_eventStatistic.py new file mode 100644 index 0000000000000..59a0bbcb5370e --- /dev/null +++ b/lldb/test/API/tools/lldb-dap/eventStatistic/TestVSCode_eventStatistic.py @@ -0,0 +1,76 @@ +""" +Test lldb-dap terminated event +""" + +import dap_server +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +import json +import re + +import lldbdap_testcase +from lldbsuite.test import lldbutil + + +class TestDAP_eventStatistic(lldbdap_testcase.DAPTestCaseBase): + """ + + Test case that captures both initialized and terminated events. + + META-ONLY: Intended to succeed TestDAP_terminatedEvent.py, but upstream keeps updating that file, so both that and this file will probably exist for a while. + + """ + + def check_statistics_summary(self, statistics): + self.assertTrue(statistics["totalDebugInfoByteSize"] > 0) + self.assertTrue(statistics["totalDebugInfoEnabled"] > 0) + self.assertTrue(statistics["totalModuleCountHasDebugInfo"] > 0) + + self.assertNotIn("modules", statistics.keys()) + + def check_target_summary(self, statistics): + # lldb-dap debugs one target at a time + target = json.loads(statistics["targets"])[0] + self.assertIn("totalSharedLibraryEventHitCount", target) + + @skipIfWindows + @skipIfRemote + def test_terminated_event(self): + """ + Terminated Event + Now contains the statistics of a debug session: + metatdata: + totalDebugInfoByteSize > 0 + totalDebugInfoEnabled > 0 + totalModuleCountHasDebugInfo > 0 + ... + """ + + program_basename = "a.out.stripped" + program = self.getBuildArtifact(program_basename) + self.build_and_launch(program) + self.continue_to_exit() + + statistics = self.dap_server.wait_for_terminated()["body"]["$__lldb_statistics"] + self.check_statistics_summary(statistics) + self.check_target_summary(statistics) + + @skipIfWindows + @skipIfRemote + def test_initialized_event(self): + """ + Initialized Event + Now contains the statistics of a debug session: + totalDebugInfoByteSize > 0 + totalDebugInfoEnabled > 0 + totalModuleCountHasDebugInfo > 0 + ... + """ + + program_basename = "a.out" + program = self.getBuildArtifact(program_basename) + self.build_and_launch(program) + self.dap_server.wait_for_event("initialized") + statistics = self.dap_server.initialized_event["body"]["$__lldb_statistics"] + self.check_statistics_summary(statistics) + self.continue_to_exit() diff --git a/lldb/test/API/tools/lldb-dap/eventStatistic/foo.cpp b/lldb/test/API/tools/lldb-dap/eventStatistic/foo.cpp new file mode 100644 index 0000000000000..b6f33b8e070a4 --- /dev/null +++ b/lldb/test/API/tools/lldb-dap/eventStatistic/foo.cpp @@ -0,0 +1 @@ +int foo() { return 12; } diff --git a/lldb/test/API/tools/lldb-dap/eventStatistic/foo.h b/lldb/test/API/tools/lldb-dap/eventStatistic/foo.h new file mode 100644 index 0000000000000..5d5f8f0c9e786 --- /dev/null +++ b/lldb/test/API/tools/lldb-dap/eventStatistic/foo.h @@ -0,0 +1 @@ +int foo(); diff --git a/lldb/test/API/tools/lldb-dap/eventStatistic/main.cpp b/lldb/test/API/tools/lldb-dap/eventStatistic/main.cpp new file mode 100644 index 0000000000000..86044f561d257 --- /dev/null +++ b/lldb/test/API/tools/lldb-dap/eventStatistic/main.cpp @@ -0,0 +1,8 @@ +#include "foo.h" +#include <iostream> + +int main(int argc, char const *argv[]) { + std::cout << "Hello World!" << std::endl; + foo(); + return 0; +} diff --git a/lldb/tools/lldb-dap/Handler/RequestHandler.h b/lldb/tools/lldb-dap/Handler/RequestHandler.h index f435257d4dcce..9feb636fd5c28 100644 --- a/lldb/tools/lldb-dap/Handler/RequestHandler.h +++ b/lldb/tools/lldb-dap/Handler/RequestHandler.h @@ -11,6 +11,7 @@ #include "DAP.h" #include "DAPError.h" +#include "JSONUtils.h" #include "Protocol/ProtocolBase.h" #include "Protocol/ProtocolRequests.h" #include "Protocol/ProtocolTypes.h" @@ -197,8 +198,7 @@ class DelayedResponseRequestHandler : public BaseRequestHandler { // The 'configurationDone' request is not sent until after 'initialized' // triggers the breakpoints being sent and 'configurationDone' is the last // message in the chain. - protocol::Event initialized{"initialized"}; - dap.Send(initialized); + dap.SendJSON(CreateInitializedEventObject(dap.target)); }; protected: diff --git a/lldb/tools/lldb-dap/JSONUtils.cpp b/lldb/tools/lldb-dap/JSONUtils.cpp index 9c32e3fac64ae..abebaf5ee25be 100644 --- a/lldb/tools/lldb-dap/JSONUtils.cpp +++ b/lldb/tools/lldb-dap/JSONUtils.cpp @@ -747,6 +747,12 @@ llvm::json::Object CreateTerminatedEventObject(lldb::SBTarget &target) { return event; } +llvm::json::Object CreateInitializedEventObject(lldb::SBTarget &target) { + llvm::json::Object event(CreateEventObject("initialized")); + addStatistic(target, 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-dap/JSONUtils.h b/lldb/tools/lldb-dap/JSONUtils.h index 15449d6ece62a..9bdd1ccd9270b 100644 --- a/lldb/tools/lldb-dap/JSONUtils.h +++ b/lldb/tools/lldb-dap/JSONUtils.h @@ -363,6 +363,12 @@ llvm::json::Object CreateRunInTerminalReverseRequest( /// A body JSON object with debug info and breakpoint info llvm::json::Object CreateTerminatedEventObject(lldb::SBTarget &target); +/// Create a "Initialized" JSON object that contains statistics +/// +/// \return +/// A body JSON object with debug info +llvm::json::Object CreateInitializedEventObject(lldb::SBTarget &target); + /// Convert a given JSON object to a string. std::string JSONToString(const llvm::json::Value &json); `````````` </details> https://github.com/llvm/llvm-project/pull/178978 _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
