-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[lldb-dap] Adding support for well typed events. #130104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| //===-- EventHandler.h ----------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLDB_TOOLS_LLDB_DAP_EVENTS_EVENT_HANDLER | ||
| #define LLDB_TOOLS_LLDB_DAP_EVENTS_EVENT_HANDLER | ||
|
|
||
| #include "DAP.h" | ||
| #include "Protocol/ProtocolBase.h" | ||
| #include "Protocol/ProtocolEvents.h" | ||
| #include "lldb/API/SBProcess.h" | ||
|
|
||
| namespace lldb_dap { | ||
|
|
||
| template <typename Body, typename... Args> class BaseEventHandler { | ||
| public: | ||
| BaseEventHandler(DAP &dap) : dap(dap) {} | ||
|
|
||
| virtual ~BaseEventHandler() = default; | ||
|
|
||
| virtual llvm::StringLiteral getEvent() const = 0; | ||
| virtual Body Handler(Args...) const = 0; | ||
|
|
||
| void operator()(Args... args) const { | ||
| Body body = Handler(args...); | ||
| protocol::Event event{/*event=*/getEvent().str(), /*body=*/std::move(body)}; | ||
| dap.Send(event); | ||
| } | ||
|
|
||
| protected: | ||
| DAP &dap; | ||
| }; | ||
|
|
||
| /// Handler for the event indicates that the debuggee has exited and returns its | ||
| /// exit code. | ||
| class ExitedEventHandler : public BaseEventHandler<protocol::ExitedEventBody> { | ||
| public: | ||
| using BaseEventHandler::BaseEventHandler; | ||
| llvm::StringLiteral getEvent() const override { return "exited"; } | ||
| protocol::ExitedEventBody Handler() const override; | ||
| }; | ||
|
|
||
| class ProcessEventHandler | ||
| : public BaseEventHandler<protocol::ProcessEventBody> { | ||
| public: | ||
| using BaseEventHandler::BaseEventHandler; | ||
| llvm::StringLiteral getEvent() const override { return "process"; } | ||
| protocol::ProcessEventBody Handler() const override; | ||
| }; | ||
|
|
||
| } // end namespace lldb_dap | ||
|
|
||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //===-- ExitedEventHandler.cpp --------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "Events/EventHandler.h" | ||
| #include "lldb/API/SBProcess.h" | ||
|
|
||
| namespace lldb_dap { | ||
|
|
||
| protocol::ExitedEventBody ExitedEventHandler::Handler() const { | ||
| protocol::ExitedEventBody body; | ||
| body.exitCode = dap.target.GetProcess().GetExitStatus(); | ||
| return body; | ||
| } | ||
|
|
||
| } // namespace lldb_dap |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| //===-- ProcessEventHandler.cpp -------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "Events/EventHandler.h" | ||
| #include "Protocol/ProtocolEvents.h" | ||
| #include "lldb/API/SBProcess.h" | ||
| #include "lldb/API/SBTarget.h" | ||
|
|
||
| using namespace llvm; | ||
| using namespace lldb_dap::protocol; | ||
|
|
||
| namespace lldb_dap { | ||
|
|
||
| ProcessEventBody ProcessEventHandler::Handler() const { | ||
| ProcessEventBody body; | ||
|
|
||
| char path[PATH_MAX] = {0}; | ||
| dap.target.GetExecutable().GetPath(path, sizeof(path)); | ||
| body.name = path; | ||
| body.systemProcessId = dap.target.GetProcess().GetProcessID(); | ||
| body.isLocalProcess = dap.target.GetPlatform().GetName() == | ||
| lldb::SBPlatform::GetHostPlatform().GetName(); | ||
| body.startMethod = dap.is_attach ? ProcessEventBody::StartMethod::attach | ||
| : ProcessEventBody::StartMethod::launch; | ||
| body.pointerSize = dap.target.GetAddressByteSize(); | ||
| return body; | ||
| } | ||
|
|
||
| } // namespace lldb_dap |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| //===-- ProtocolEvents.cpp ------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "Protocol/ProtocolEvents.h" | ||
| #include "llvm/Support/JSON.h" | ||
|
|
||
| using namespace llvm; | ||
|
|
||
| namespace lldb_dap::protocol { | ||
|
|
||
| json::Value toJSON(const ExitedEventBody &EEB) { | ||
| return json::Object{{"exitCode", EEB.exitCode}}; | ||
| } | ||
|
|
||
| json::Value toJSON(const ProcessEventBody::StartMethod &m) { | ||
| switch (m) { | ||
| case ProcessEventBody::StartMethod::launch: | ||
| return "launch"; | ||
| case ProcessEventBody::StartMethod::attach: | ||
| return "attach"; | ||
| case ProcessEventBody::StartMethod::attachForSuspendedLaunch: | ||
| return "attachForSuspendedLaunch"; | ||
| } | ||
| } | ||
|
|
||
| json::Value toJSON(const ProcessEventBody &PEB) { | ||
| json::Object result{{"name", PEB.name}}; | ||
|
|
||
| if (PEB.systemProcessId) | ||
| result.insert({"systemProcessId", PEB.systemProcessId}); | ||
| if (PEB.isLocalProcess) | ||
| result.insert({"isLocalProcess", PEB.isLocalProcess}); | ||
| if (PEB.startMethod) | ||
| result.insert({"startMethod", PEB.startMethod}); | ||
| if (PEB.pointerSize) | ||
| result.insert({"pointerSize", PEB.pointerSize}); | ||
|
|
||
| return std::move(result); | ||
| } | ||
|
|
||
| } // namespace lldb_dap::protocol |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be using
Body.getEvent()instead? Afaict, we wouldn't need a virtual call togetEventthen