Files
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

107 lines
3.7 KiB
C++

//===-- 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 "EventHelper.h"
#include "JSONUtils.h"
#include "Protocol/ProtocolEvents.h"
#include "RequestHandler.h"
#include "lldb/API/SBMemoryRegionInfo.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Base64.h"
using namespace lldb_dap::protocol;
namespace lldb_dap {
// Writes bytes to memory at the provided location.
//
// Clients should only call this request if the corresponding capability
// supportsWriteMemoryRequest is true.
llvm::Expected<WriteMemoryResponseBody>
WriteMemoryRequestHandler::Run(const WriteMemoryArguments &args) const {
const lldb::addr_t address = args.memoryReference + args.offset;
if (dap.ProcessIsNotStopped())
return llvm::make_error<NotStoppedError>();
if (args.data.empty()) {
return llvm::make_error<DAPError>(
"Data cannot be empty value. Provide valid data");
}
// 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(args.data, output);
if (decode_error) {
return llvm::make_error<DAPError>(
llvm::toString(std::move(decode_error)).c_str());
}
lldb::SBError write_error;
uint64_t bytes_written = 0;
// Write the memory.
if (!output.empty()) {
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 (!args.allowPartial) {
// Start checking from the initial write address.
lldb::addr_t start_address = address;
// Compute the end of the write range.
lldb::addr_t end_address = start_address + output.size() - 1;
while (start_address <= end_address) {
// 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(start_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()) {
return llvm::make_error<DAPError>(
"Memory 0x" + llvm::utohexstr(args.memoryReference) +
" region is not writable");
}
// If the current region covers the full requested range, stop further
// iterations.
if (end_address <= region_info.GetRegionEnd()) {
break;
}
// Move to the start of the next memory region.
start_address = region_info.GetRegionEnd() + 1;
}
}
bytes_written =
process.WriteMemory(address, static_cast<void *>(output.data()),
output.size(), write_error);
}
if (bytes_written == 0) {
return llvm::make_error<DAPError>(write_error.GetCString());
}
WriteMemoryResponseBody response;
response.bytesWritten = bytes_written;
// Also send invalidated event to signal client that some things
// (e.g. variables) can be changed.
SendInvalidatedEvent(dap, {InvalidatedEventBody::eAreaAll});
return response;
}
} // namespace lldb_dap