From 6cdfe5505c11c511e26d619a4b476cf01f15dfdc Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Mon, 13 Dec 2010 23:27:59 +0000 Subject: [PATCH] Add write counterparts to debug_read_memory/debug_read_memory_partial. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39843 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/debug/debug_support.h | 4 ++ src/kits/debug/debug_support.cpp | 66 +++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/headers/private/debug/debug_support.h b/headers/private/debug/debug_support.h index 0ed3c6e6ee..aa8165228d 100644 --- a/headers/private/debug/debug_support.h +++ b/headers/private/debug/debug_support.h @@ -33,6 +33,10 @@ ssize_t debug_read_memory(debug_context *context, const void *address, void *buffer, size_t size); ssize_t debug_read_string(debug_context *context, const void *_address, char *buffer, size_t size); +ssize_t debug_write_memory_partial(debug_context *context, const void *address, + void *buffer, size_t size); +ssize_t debug_write_memory(debug_context *context, const void *address, + void *buffer, size_t size); status_t debug_get_cpu_state(debug_context *context, thread_id thread, debug_debugger_message *messageCode, debug_cpu_state *cpuState); diff --git a/src/kits/debug/debug_support.cpp b/src/kits/debug/debug_support.cpp index 1389899249..961a218acd 100644 --- a/src/kits/debug/debug_support.cpp +++ b/src/kits/debug/debug_support.cpp @@ -1,5 +1,6 @@ /* * Copyright 2005-2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Copyright 2010, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ @@ -216,6 +217,71 @@ debug_read_string(debug_context *context, const void *_address, char *buffer, return sumRead; } +// debug_write_memory_partial +ssize_t +debug_write_memory_partial(debug_context *context, const void *address, + void *buffer, size_t size) +{ + if (!context) + return B_BAD_VALUE; + + if (size == 0) + return 0; + if (size > B_MAX_READ_WRITE_MEMORY_SIZE) + size = B_MAX_READ_WRITE_MEMORY_SIZE; + + // prepare the message + debug_nub_write_memory message; + message.reply_port = context->reply_port; + message.address = (void*)address; + message.size = size; + + // send the message + debug_nub_write_memory_reply reply; + status_t error = send_debug_message(context, B_DEBUG_MESSAGE_WRITE_MEMORY, + &message, sizeof(message), &reply, sizeof(reply)); + + if (error != B_OK) + return error; + if (reply.error != B_OK) + return reply.error; + + return reply.size; +} + +// debug_write_memory +ssize_t +debug_write_memory(debug_context *context, const void *_address, void *_buffer, + size_t size) +{ + const char *address = (const char *)_address; + char *buffer = (char*)_buffer; + + // check parameters + if (!context || !address || !buffer) + return B_BAD_VALUE; + if (size == 0) + return 0; + + ssize_t sumWritten = 0; + while (size > 0) { + ssize_t bytesWritten = debug_write_memory_partial(context, address, buffer, + size); + if (bytesWritten < 0) { + if (sumWritten > 0) + return sumWritten; + return bytesWritten; + } + + address += bytesWritten; + buffer += bytesWritten; + sumWritten += bytesWritten; + size -= bytesWritten; + } + + return sumWritten; +} + // debug_get_cpu_state status_t debug_get_cpu_state(debug_context *context, thread_id thread,