-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[lldb][lldb-dap] Added support for "WriteMemory" request. #131820
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
Merged
Changes from 129 commits
Commits
Show all changes
156 commits
Select commit
Hold shift + click to select a range
960351c
[lldb][test] Add the ability to extract the variable value out of the…
94c7680
Merge branch 'llvm:main' into main
santhoshe447 3235090
Merge branch 'llvm:main' into main
santhoshe447 ff9077f
Merge branch 'llvm:main' into main
santhoshe447 fa762d2
Merge branch 'llvm:main' into main
santhoshe447 09ff158
Merge branch 'llvm:main' into main
santhoshe447 ab44a69
[lldb-dap] Added "port" property to vscode "attach" command.
ef4f016
Merge branch 'llvm:main' into main
santhoshe447 35ba7f7
Merge branch 'llvm:main' into main
santhoshe447 bd38f88
Merge branch 'llvm:main' into main
santhoshe447 f65a580
Merge branch 'llvm:main' into main
santhoshe447 5763225
Merge branch 'llvm:main' into main
santhoshe447 bb18d6d
Merge branch 'llvm:main' into main
santhoshe447 1b1ae2b
Merge branch 'llvm:main' into main
santhoshe447 a2e4580
Merge branch 'llvm:main' into main
santhoshe447 3795dcd
Merge branch 'llvm:main' into main
santhoshe447 628fa40
Merge branch 'llvm:main' into main
santhoshe447 4e2e524
[lldb-dap] Added "port" property to vscode "attach" command.
4774f58
Merge branch 'llvm:main' into main
santhoshe447 175f1d3
[lldb-dap] Added "port" property to vscode "attach" command.
a6e9f66
Merge branch 'llvm:main' into main
santhoshe447 e5c0aed
Resolved code format issue.
c502203
Resolved code format errors.
89800a8
Merge branch 'llvm:main' into main
santhoshe447 c1bf2bd
[lldb-dap] Added "port" property to vscode "attach" command - Address…
5590afc
[lldb-dap] Added "port" property to vscode "attach" command - fix cod…
afcce33
Merge branch 'llvm:main' into main
santhoshe447 281c281
Merge branch 'llvm:main' into main
santhoshe447 624b789
Merge branch 'llvm:main' into main
santhoshe447 023b51e
[lldb-dap] Added "port" property to vscode "attach" command - resolve…
d19eb88
[lldb-dap] Added "port" property to vscode "attach" command -resolved…
16c37cd
Merge branch 'llvm:main' into main
santhoshe447 599a5ca
Merge branch 'llvm:main' into main
santhoshe447 fe9a4b6
[lldb-dap] Added "port" property to vscode "attach" command. #91570
c91b02d
[lldb-dap] Added "port" property to vscode "attach" command.
35ad541
Merge branch 'llvm:main' into main
santhoshe447 8e3f3a5
Merge branch 'llvm:main' into main
santhoshe447 de29728
[lldb-dap] Added "port" property to vscode "attach" command - address…
ac84b53
[lldb-dap] Added "port" property to vscode "attach" command - resolve…
7d1319c
Merge branch 'llvm:main' into main
santhoshe447 2a0eb9d
Merge branch 'llvm:main' into main
santhoshe447 08f40aa
[lldb-dap] Added "port" property to vscode "attach" command - fixed …
2a0bc63
[lldb-dap] Added "port" property to vscode "attach" command - resolve…
656c34a
[lldb-dap] Added "port" property to vscode "attach" command.
673ae34
Merge branch 'llvm:main' into main
santhoshe447 c6e552a
Merge branch 'llvm:main' into main
santhoshe447 043895d
Merge branch 'llvm:main' into main
santhoshe447 fe36e25
[lldb-dap] Updated README.md for newly added attach properties.
2011cb5
Merge branch 'llvm:main' into main
santhoshe447 03e4c20
Merge branch 'llvm:main' into main
santhoshe447 10d16b8
[lldb-dap] Updated README.md for newly added attach properties. #99926
a6c4895
Merge branch 'llvm:main' into main
santhoshe447 58affe7
[lldb-dap] Bump the version to 0.2.3
033c6a1
Merge branch 'llvm:main' into main
santhoshe447 7c96402
Merge branch 'llvm:main' into main
santhoshe447 17a99a7
Merge branch 'llvm:main' into main
santhoshe447 1e7d5f0
Merge branch 'llvm:main' into main
santhoshe447 e6fa6a8
Merge branch 'llvm:main' into main
santhoshe447 5069297
Merge branch 'llvm:main' into main
santhoshe447 7e22182
[lldb-dap] Enabling instruction breakpoint support to lldb-dap.
santhoshe447 ffe8dbc
[lldb-dap] Enabling instruction breakpoint support to lldb-dap.
santhoshe447 4d87a93
[lldb-dap] Enabling instruction breakpoint support to lldb-dap.
santhoshe447 18bcb03
[lldb-dap] Enabling instruction breakpoint support to lldb-dap.
santhoshe447 9893985
[lldb-dap] Enabling instruction breakpoint support to lldb-dap.
santhoshe447 e0101c1
[lldb-dap] Enabling instruction breakpoint support to lldb-dap.
santhoshe447 17f8c6d
[lldb-dap] Enabling instruction breakpoint support to lldb-dap.
santhoshe447 8c19498
[lldb-dap] Enabling instruction breakpoint support to lldb-dap.
santhoshe447 5031df9
Merge branch 'main' into main
santhoshe447 27d668f
Merge branch 'llvm:main' into main
santhoshe447 dbad4c5
[lldb-dap] Enabling instruction breakpoint support to lldb-dap.
santhoshe447 bac086e
[lldb-dap] Enabling instruction breakpoint support to lldb-dap.
santhoshe447 5401fbe
[lldb-dap] Enabling instruction breakpoint support to lldb-dap.
santhoshe447 3523cef
[lldb-dap] Enabling instruction breakpoint support to lldb-dap.
santhoshe447 ab68b22
[lldb-dap] Enabling instruction breakpoint support to lldb-dap.
santhoshe447 fc30dd1
Merge branch 'llvm:main' into main
santhoshe447 724e679
Merge branch 'llvm:main' into main
santhoshe447 76168c5
Merge branch 'llvm:main' into main
santhoshe447 e17a0fa
[lldb-dap] XFailed TestDAP_instruction_breakpoint.py for windows.
santhoshe447 466c75a
Merge branch 'llvm:main' into main
santhoshe447 a34fe4b
Merge branch 'llvm:main' into main
santhoshe447 a9dad2e
Merge branch 'llvm:main' into main
santhoshe447 d096a4e
Merge branch 'llvm:main' into main
santhoshe447 dbd26f5
Merge branch 'llvm:main' into main
santhoshe447 be23e48
Merge branch 'llvm:main' into main
santhoshe447 c22c9e0
Merge branch 'llvm:main' into main
santhoshe447 4d3c68d
Merge branch 'llvm:main' into main
santhoshe447 626ecee
Merge branch 'llvm:main' into main
santhoshe447 90bc8c0
Merge branch 'llvm:main' into main
santhoshe447 fa0a7c6
Merge branch 'llvm:main' into main
santhoshe447 684b1e7
Merge branch 'llvm:main' into main
santhoshe447 8959322
[lldb-dap] Fix for missing 'raw_string_ostream::flush' removal in Pro…
santhoshe447 698a4b1
Merge branch 'llvm:main' into main
santhoshe447 5400b68
Merge branch 'llvm:main' into main
santhoshe447 e5e2908
Merge branch 'llvm:main' into main
santhoshe447 cd186a8
Merge branch 'llvm:main' into main
santhoshe447 98db394
Merge branch 'llvm:main' into main
santhoshe447 8764180
Merge branch 'llvm:main' into main
santhoshe447 55a67cd
Merge branch 'llvm:main' into main
santhoshe447 ef23ddc
[lldb][lldb-dap] Added WriteMemory support
santhoshe447 c55eece
[lldb][lldb-dap] Added WriteMemory support
santhoshe447 0a8140e
Merge branch 'main' of github.com:santhoshe447/llvm-project into main
santhoshe447 9a6d643
Merge branch 'llvm:main' into main
santhoshe447 b428148
[lldb][lldb-dap] Added readMemory and WriteMemory, var type correctio…
santhoshe447 dcdaa07
Merge branch 'main' of github.com:santhoshe447/llvm-project into main
santhoshe447 6d0d08f
Merge branch 'main' of github.com:santhoshe447/llvm-project into main
santhoshe447 895b78e
[lldb][lldb-dap] Added support for "WriteMemory" request. #131820
santhoshe447 d14ac94
[lldb][lldb-dap] Added support for "WriteMemory" request. #131820
santhoshe447 9a88226
Merge branch 'main' of github.com:santhoshe447/llvm-project into main
santhoshe447 6ca125a
Merge branch 'main' into main
santhoshe447 a1d75c6
Merge branch 'llvm:main' into main
santhoshe447 27ecce0
Merge branch 'llvm:main' into main
santhoshe447 7311866
Merge branch 'main' of github.com:santhoshe447/llvm-project into main
santhoshe447 2122c2e
Merge branch 'llvm:main' into main
santhoshe447 f7e9af8
[lldb][lldb-dap] Added support for "WriteMemory" request. #131820
santhoshe447 683d775
Merge branch 'main' of github.com:santhoshe447/llvm-project into main
santhoshe447 32f4823
Merge branch 'main' of github.com:santhoshe447/llvm-project into main
santhoshe447 f5b7cf3
Merge branch 'main' of github.com:santhoshe447/llvm-project into main
santhoshe447 f65902a
[lldb][lldb-dap] Added support for "WriteMemory" request. #131820
santhoshe447 1f77293
Merge branch 'main' of github.com:santhoshe447/llvm-project into main
santhoshe447 6f676bb
[lldb][lldb-dap] Added support for "WriteMemory" request. #131820
santhoshe447 b342a42
Merge branch 'main' of github.com:santhoshe447/llvm-project into main
santhoshe447 50a2bc2
Merge branch 'main' of github.com:santhoshe447/llvm-project into main
santhoshe447 898327f
Merge branch 'main' of github.com:santhoshe447/llvm-project into main
santhoshe447 9149f89
[lldb][lldb-dap] Added support for "WriteMemory" request. #131820
santhoshe447 1b84b53
Merge branch 'llvm:main' into main
santhoshe447 cd70ba3
[lldb][lldb-dap] Added support for "WriteMemory" request. #131820
santhoshe447 4f2163e
Merge branch 'main' into main
santhoshe447 001dcd7
[lldb][lldb-dap] Added support for "WriteMemory" request. #131820
santhoshe447 6417816
Merge branch 'llvm:main' into main
santhoshe447 359a365
Merge branch 'llvm:main' into main
santhoshe447 285f07d
[lldb][lldb-dap] Added support for "WriteMemory" request. #131820
santhoshe447 cd7145c
Merge branch 'llvm:main' into main
santhoshe447 b9bc76b
[lldb][lldb-dap] Added support for "WriteMemory" request. #156761
santhoshe447 dccb38f
[lldb][lldb-dap] Added support for "WriteMemory" request. #157136
santhoshe447 e8feef2
[lldb][lldb-dap] Added support for "WriteMemory" request. #131820
santhoshe447 cb8e204
Merge branch 'main' into main
santhoshe447 8b358b8
Merge branch 'llvm:main' into main
santhoshe447 b8a5631
Merge branch 'llvm:main' into main
santhoshe447 fb9f136
Merge branch 'llvm:main' into main
santhoshe447 d0f95bd
Merge branch 'llvm:main' into main
santhoshe447 15fed53
Merge branch 'llvm:main' into main
santhoshe447 2eebc3d
Merge branch 'llvm:main' into main
santhoshe447 a5e0830
Merge branch 'llvm:main' into main
santhoshe447 20fc36c
Merge branch 'llvm:main' into main
santhoshe447 75c2fe5
Resolved merge conflicts.
santhoshe447 fc8fe46
Merge branch 'llvm:main' into main
santhoshe447 440987f
Merge branch 'llvm:main' into main
santhoshe447 652405a
Merge branch 'main' into main
santhoshe447 150222e
Merge branch 'llvm:main' into main
santhoshe447 7d25017
Merge branch 'llvm:main' into main
santhoshe447 cdbecca
Merge branch 'llvm:main' into main
santhoshe447 d9fccd7
Merge branch 'llvm:main' into main
santhoshe447 2930a70
[lldb][lldb-dap] Added support for "WriteMemory" request.
santhoshe447 77ad557
Merge branch 'llvm:main' into main
santhoshe447 582ab01
Merge branch 'main' into main
santhoshe447 492f5c0
Update ProtocolRequests.cpp
santhoshe447 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| int main() { | ||
| int not_a_ptr = 666; | ||
| const char *rawptr = "dead"; | ||
| // Immutable variable, .rodata region. | ||
| static const int nonWritable = 100; | ||
| // Breakpoint | ||
| return 0; | ||
| } |
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
175 changes: 175 additions & 0 deletions
175
lldb/tools/lldb-dap/Handler/WriteMemoryRequestHandler.cpp
|
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. This is probably worth mentioning in the release notes, in |
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,175 @@ | ||
| //===-- WriteMemoryRequestHandler.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 "JSONUtils.h" | ||
| #include "RequestHandler.h" | ||
| #include "lldb/API/SBMemoryRegionInfo.h" | ||
| #include "llvm/ADT/StringExtras.h" | ||
| #include "llvm/Support/Base64.h" | ||
|
|
||
| namespace lldb_dap { | ||
|
|
||
| // "WriteMemoryRequest": { | ||
| // "allOf": [ { "$ref": "#/definitions/Request" }, { | ||
| // "type": "object", | ||
| // "description": "Writes bytes to memory at the provided location.\n | ||
| // Clients should only call this request if the corresponding | ||
| // capability `supportsWriteMemoryRequest` is true.", | ||
| // "properties": { | ||
| // "command": { | ||
| // "type": "string", | ||
| // "enum": [ "writeMemory" ] | ||
| // }, | ||
| // "arguments": { | ||
| // "$ref": "#/definitions/WriteMemoryArguments" | ||
| // } | ||
| // }, | ||
| // "required": [ "command", "arguments" ] | ||
| // }] | ||
| // }, | ||
| // "WriteMemoryArguments": { | ||
| // "type": "object", | ||
| // "description": "Arguments for `writeMemory` request.", | ||
| // "properties": { | ||
| // "memoryReference": { | ||
| // "type": "string", | ||
| // "description": "Memory reference to the base location to which | ||
| // data should be written." | ||
| // }, | ||
| // "offset": { | ||
| // "type": "integer", | ||
| // "description": "Offset (in bytes) to be applied to the reference | ||
| // location before writing data. Can be negative." | ||
| // }, | ||
| // "allowPartial": { | ||
| // "type": "boolean", | ||
| // "description": "Property to control partial writes. If true, the | ||
| // debug adapter should attempt to write memory even if the entire | ||
| // memory region is not writable. In such a case the debug adapter | ||
| // should stop after hitting the first byte of memory that cannot be | ||
| // written and return the number of bytes written in the response | ||
| // via the `offset` and `bytesWritten` properties.\nIf false or | ||
| // missing, a debug adapter should attempt to verify the region is | ||
| // writable before writing, and fail the response if it is not." | ||
| // }, | ||
| // "data": { | ||
| // "type": "string", | ||
| // "description": "Bytes to write, encoded using base64." | ||
| // } | ||
| // }, | ||
| // "required": [ "memoryReference", "data" ] | ||
| // }, | ||
| // "WriteMemoryResponse": { | ||
| // "allOf": [ { "$ref": "#/definitions/Response" }, { | ||
| // "type": "object", | ||
| // "description": "Response to `writeMemory` request.", | ||
| // "properties": { | ||
| // "body": { | ||
| // "type": "object", | ||
| // "properties": { | ||
| // "offset": { | ||
| // "type": "integer", | ||
| // "description": "Property that should be returned when | ||
| // `allowPartial` is true to indicate the offset of the first | ||
| // byte of data successfully written. Can be negative." | ||
| // }, | ||
| // "bytesWritten": { | ||
| // "type": "integer", | ||
| // "description": "Property that should be returned when | ||
| // `allowPartial` is true to indicate the number of bytes | ||
| // starting from address that were successfully written." | ||
| // } | ||
| // } | ||
| // } | ||
| // } | ||
| // }] | ||
| // }, | ||
| void WriteMemoryRequestHandler::operator()( | ||
| const llvm::json::Object &request) const { | ||
| llvm::json::Object response; | ||
| FillResponse(request, response); | ||
|
|
||
| auto arguments = request.getObject("arguments"); | ||
| llvm::StringRef memoryReference = | ||
santhoshe447 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| GetString(arguments, "memoryReference").value_or(""); | ||
|
|
||
| auto addr_opt = DecodeMemoryReference(memoryReference); | ||
| if (!addr_opt.has_value()) { | ||
| dap.SendErrorResponse(response, "Malformed memory reference: " + | ||
| memoryReference.str()); | ||
| return; | ||
| } | ||
| lldb::addr_t address = | ||
| *addr_opt + GetInteger<uint64_t>(arguments, "offset").value_or(0); | ||
|
|
||
| llvm::StringRef data64 = GetString(arguments, "data").value_or(""); | ||
santhoshe447 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (data64.empty()) { | ||
| dap.SendErrorResponse(response, | ||
| "Data cannot be empty value. Provide valid data"); | ||
| return; | ||
| } | ||
|
|
||
| // The VSCode IDE or other DAP clients send memory data as a Base64 string. | ||
| // This function decodes it into raw binary before writing it to the target | ||
| // process memory. | ||
| std::vector<char> output; | ||
| auto decode_error = llvm::decodeBase64(data64, output); | ||
|
|
||
| if (decode_error) { | ||
| dap.SendErrorResponse(response, | ||
| llvm::toString(std::move(decode_error)).c_str()); | ||
| return; | ||
| } | ||
|
|
||
| bool allowPartial = GetBoolean(arguments, "allowPartial").value_or(true); | ||
santhoshe447 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| lldb::SBError write_error; | ||
| uint64_t bytes_written = 0; | ||
|
|
||
| // Write the memory. | ||
| if (!output.empty()) { | ||
santhoshe447 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| lldb::SBProcess process = dap.target.GetProcess(); | ||
| // If 'allowPartial' is false or missing, a debug adapter should attempt to | ||
| // verify the region is writable before writing, and fail the response if it | ||
| // is not. | ||
| if (!allowPartial) { | ||
| // Compute the end of the write range. | ||
| lldb::addr_t end_address = address + output.size(); | ||
santhoshe447 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // Get memory region info for the given address. | ||
| // This provides the region's base, end, and permissions | ||
| // (read/write/executable). | ||
| lldb::SBMemoryRegionInfo region_info; | ||
| lldb::SBError error = process.GetMemoryRegionInfo(address, region_info); | ||
| // Fail if the region info retrieval fails, is not writable, or the range | ||
| // exceeds the region. | ||
| if (!error.Success() || !region_info.IsWritable() || | ||
santhoshe447 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| end_address > region_info.GetRegionEnd()) { | ||
| dap.SendErrorResponse(response, "Memory 0x" + llvm::utohexstr(address) + | ||
| " region is not writable"); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| bytes_written = | ||
| process.WriteMemory(address, static_cast<void *>(output.data()), | ||
| output.size(), write_error); | ||
| } | ||
|
|
||
| if (bytes_written == 0) { | ||
| dap.SendErrorResponse(response, write_error.GetCString()); | ||
| return; | ||
| } | ||
|
|
||
| llvm::json::Object body; | ||
| body.try_emplace("bytesWritten", std::move(bytes_written)); | ||
|
|
||
| response.try_emplace("body", std::move(body)); | ||
| 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
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.
I would prefer if we would directly use the non-legacy approach here
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.
What is non legacy handler approach ?