-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[lldb-dap] Use protocol types for modules request and events. #146966
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
Open
da-viper
wants to merge
5
commits into
llvm:main
Choose a base branch
from
da-viper:use-protocol-modules
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+522
−242
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8ece855
[lldb-dap] Use protocol-types for modules request
da-viper 6f030c1
[lldb-dap] update events
da-viper e2c1810
[lldb-dap] update vscode extension
da-viper 475a615
[lldb-dap] add unit tests
da-viper 4a9dd25
[lldb-dap] Create a function for target events.
da-viper 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
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 |
---|---|---|
|
@@ -7,64 +7,43 @@ | |
//===----------------------------------------------------------------------===// | ||
|
||
#include "DAP.h" | ||
#include "EventHelper.h" | ||
#include "JSONUtils.h" | ||
#include "ProtocolUtils.h" | ||
#include "RequestHandler.h" | ||
|
||
using namespace lldb_dap::protocol; | ||
namespace lldb_dap { | ||
|
||
// "modulesRequest": { | ||
// "allOf": [ { "$ref": "#/definitions/Request" }, { | ||
// "type": "object", | ||
// "description": "Modules request; value of command field is | ||
// 'modules'.", | ||
// "properties": { | ||
// "command": { | ||
// "type": "string", | ||
// "enum": [ "modules" ] | ||
// }, | ||
// }, | ||
// "required": [ "command" ] | ||
// }] | ||
// }, | ||
// "modulesResponse": { | ||
// "allOf": [ { "$ref": "#/definitions/Response" }, { | ||
// "type": "object", | ||
// "description": "Response to 'modules' request.", | ||
// "properties": { | ||
// "body": { | ||
// "description": "Response to 'modules' request. Array of | ||
// module objects." | ||
// } | ||
// } | ||
// }] | ||
// } | ||
void ModulesRequestHandler::operator()( | ||
const llvm::json::Object &request) const { | ||
llvm::json::Object response; | ||
FillResponse(request, response); | ||
|
||
llvm::json::Array modules; | ||
|
||
{ | ||
std::lock_guard<std::mutex> guard(dap.modules_mutex); | ||
for (size_t i = 0; i < dap.target.GetNumModules(); i++) { | ||
lldb::SBModule module = dap.target.GetModuleAtIndex(i); | ||
if (!module.IsValid()) | ||
continue; | ||
|
||
llvm::StringRef module_id = module.GetUUIDString(); | ||
if (!module_id.empty()) | ||
dap.modules.insert(module_id); | ||
|
||
modules.emplace_back(CreateModule(dap.target, module)); | ||
/// Modules can be retrieved from the debug adapter with this request which can | ||
/// either return all modules or a range of modules to support paging. | ||
/// | ||
/// Clients should only call this request if the corresponding capability | ||
/// `supportsModulesRequest` is true. | ||
Comment on lines
+19
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Support for paging is another functional change that's orthogonal to switching over to the protocol types. |
||
llvm::Expected<ModulesResponseBody> | ||
ModulesRequestHandler::Run(const std::optional<ModulesArguments> &args) const { | ||
ModulesResponseBody response; | ||
const auto [start_module, module_count] = args.value_or({}); | ||
|
||
std::vector<Module> &modules = response.modules; | ||
std::lock_guard<std::mutex> guard(dap.modules_mutex); | ||
const uint32_t total_modules = dap.target.GetNumModules(); | ||
const uint32_t max_num_module = | ||
module_count == 0 ? total_modules | ||
: std::min(start_module + module_count, total_modules); | ||
modules.reserve(max_num_module); | ||
|
||
response.totalModules = total_modules; | ||
|
||
for (uint32_t i = start_module; i < max_num_module; i++) { | ||
lldb::SBModule module = dap.target.GetModuleAtIndex(i); | ||
|
||
std::optional<Module> result = CreateModule(dap.target, module); | ||
if (result && !result->id.empty()) { | ||
dap.modules.insert(result->id); | ||
modules.emplace_back(std::move(result).value()); | ||
} | ||
} | ||
|
||
llvm::json::Object body; | ||
body.try_emplace("modules", std::move(modules)); | ||
response.try_emplace("body", std::move(body)); | ||
dap.SendJSON(llvm::json::Value(std::move(response))); | ||
return response; | ||
} | ||
|
||
} // 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
Oops, something went wrong.
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.
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.
This change seems orthogonal to the protocol types change and should probably be its own (small) PR.