-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[lldb-dap] Refactor stepping related request handlers (NFC) #128453
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
Merged
JDevlieghere
merged 2 commits into
llvm:main
from
JDevlieghere:stepping-request-handlers
Feb 24, 2025
Merged
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| //===-- NextRequestHandler.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 "DAP.h" | ||
| #include "EventHelper.h" | ||
| #include "JSONUtils.h" | ||
| #include "RequestHandler.h" | ||
|
|
||
| namespace lldb_dap { | ||
|
|
||
| // "NextRequest": { | ||
| // "allOf": [ { "$ref": "#/definitions/Request" }, { | ||
| // "type": "object", | ||
| // "description": "Next request; value of command field is 'next'. The | ||
| // request starts the debuggee to run again for one step. | ||
| // The debug adapter first sends the NextResponse and then | ||
| // a StoppedEvent (event type 'step') after the step has | ||
| // completed.", | ||
| // "properties": { | ||
| // "command": { | ||
| // "type": "string", | ||
| // "enum": [ "next" ] | ||
| // }, | ||
| // "arguments": { | ||
| // "$ref": "#/definitions/NextArguments" | ||
| // } | ||
| // }, | ||
| // "required": [ "command", "arguments" ] | ||
| // }] | ||
| // }, | ||
| // "NextArguments": { | ||
| // "type": "object", | ||
| // "description": "Arguments for 'next' request.", | ||
| // "properties": { | ||
| // "threadId": { | ||
| // "type": "integer", | ||
| // "description": "Execute 'next' for this thread." | ||
| // }, | ||
| // "granularity": { | ||
| // "$ref": "#/definitions/SteppingGranularity", | ||
| // "description": "Stepping granularity. If no granularity is specified, a | ||
| // granularity of `statement` is assumed." | ||
| // } | ||
| // }, | ||
| // "required": [ "threadId" ] | ||
| // }, | ||
| // "NextResponse": { | ||
| // "allOf": [ { "$ref": "#/definitions/Response" }, { | ||
| // "type": "object", | ||
| // "description": "Response to 'next' request. This is just an | ||
| // acknowledgement, so no body field is required." | ||
| // }] | ||
| // } | ||
| void NextRequestHandler::operator()(const llvm::json::Object &request) { | ||
| llvm::json::Object response; | ||
| FillResponse(request, response); | ||
| const auto *arguments = request.getObject("arguments"); | ||
| lldb::SBThread thread = dap.GetLLDBThread(*arguments); | ||
| if (thread.IsValid()) { | ||
| // Remember the thread ID that caused the resume so we can set the | ||
| // "threadCausedFocus" boolean value in the "stopped" events. | ||
| dap.focus_tid = thread.GetThreadID(); | ||
| if (HasInstructionGranularity(*arguments)) { | ||
| thread.StepInstruction(/*step_over=*/true); | ||
| } else { | ||
| thread.StepOver(); | ||
| } | ||
| } else { | ||
| response["success"] = llvm::json::Value(false); | ||
| } | ||
| dap.SendJSON(llvm::json::Value(std::move(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
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,96 @@ | ||
| //===-- StepInRequestHandler.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 "DAP.h" | ||
| #include "EventHelper.h" | ||
| #include "JSONUtils.h" | ||
| #include "RequestHandler.h" | ||
|
|
||
| namespace lldb_dap { | ||
|
|
||
| // "StepInRequest": { | ||
| // "allOf": [ { "$ref": "#/definitions/Request" }, { | ||
| // "type": "object", | ||
| // "description": "StepIn request; value of command field is 'stepIn'. The | ||
| // request starts the debuggee to step into a function/method if possible. | ||
| // If it cannot step into a target, 'stepIn' behaves like 'next'. The debug | ||
| // adapter first sends the StepInResponse and then a StoppedEvent (event | ||
| // type 'step') after the step has completed. If there are multiple | ||
| // function/method calls (or other targets) on the source line, the optional | ||
| // argument 'targetId' can be used to control into which target the 'stepIn' | ||
| // should occur. The list of possible targets for a given source line can be | ||
| // retrieved via the 'stepInTargets' request.", "properties": { | ||
| // "command": { | ||
| // "type": "string", | ||
| // "enum": [ "stepIn" ] | ||
| // }, | ||
| // "arguments": { | ||
| // "$ref": "#/definitions/StepInArguments" | ||
| // } | ||
| // }, | ||
| // "required": [ "command", "arguments" ] | ||
| // }] | ||
| // }, | ||
| // "StepInArguments": { | ||
| // "type": "object", | ||
| // "description": "Arguments for 'stepIn' request.", | ||
| // "properties": { | ||
| // "threadId": { | ||
| // "type": "integer", | ||
| // "description": "Execute 'stepIn' for this thread." | ||
| // }, | ||
| // "targetId": { | ||
| // "type": "integer", | ||
| // "description": "Optional id of the target to step into." | ||
| // }, | ||
| // "granularity": { | ||
| // "$ref": "#/definitions/SteppingGranularity", | ||
| // "description": "Stepping granularity. If no granularity is specified, a | ||
| // granularity of `statement` is assumed." | ||
| // } | ||
| // }, | ||
| // "required": [ "threadId" ] | ||
| // }, | ||
| // "StepInResponse": { | ||
| // "allOf": [ { "$ref": "#/definitions/Response" }, { | ||
| // "type": "object", | ||
| // "description": "Response to 'stepIn' request. This is just an | ||
| // acknowledgement, so no body field is required." | ||
| // }] | ||
| // } | ||
| void StepInRequestHandler::operator()(const llvm::json::Object &request) { | ||
| llvm::json::Object response; | ||
| FillResponse(request, response); | ||
| const auto *arguments = request.getObject("arguments"); | ||
|
|
||
| std::string step_in_target; | ||
| uint64_t target_id = GetUnsigned(arguments, "targetId", 0); | ||
| auto it = dap.step_in_targets.find(target_id); | ||
| if (it != dap.step_in_targets.end()) | ||
| step_in_target = it->second; | ||
|
|
||
| const bool single_thread = GetBoolean(arguments, "singleThread", false); | ||
| lldb::RunMode run_mode = | ||
| single_thread ? lldb::eOnlyThisThread : lldb::eOnlyDuringStepping; | ||
| lldb::SBThread thread = dap.GetLLDBThread(*arguments); | ||
| if (thread.IsValid()) { | ||
| // Remember the thread ID that caused the resume so we can set the | ||
| // "threadCausedFocus" boolean value in the "stopped" events. | ||
| dap.focus_tid = thread.GetThreadID(); | ||
| if (HasInstructionGranularity(*arguments)) { | ||
| thread.StepInstruction(/*step_over=*/false); | ||
| } else { | ||
| thread.StepInto(step_in_target.c_str(), run_mode); | ||
| } | ||
| } else { | ||
| response["success"] = llvm::json::Value(false); | ||
| } | ||
| dap.SendJSON(llvm::json::Value(std::move(response))); | ||
| } | ||
|
|
||
| } // namespace lldb_dap |
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.