This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 1/2] Fix wrong length computed in mi_cmd_data_write_memory_bytes.


On 09/26/2012 11:20 PM, Tom Tromey wrote:
> Yao> I happen to see that MI command '-data-write-memory-bytes' doesn't write
> Yao> contents correctly to memory, for example,
> Yao>   -data-write-memory-bytes &x "1"
> 
> I think that this is invalid input.
> 
> The argument to -data-write-memory-bytes is encoded as hex.
> So, it has to be a multiple of 2 characters.

Right, the content is hex-encoded, but I forgot that hex-encoded string must
have an even number of chars.

> 
> I guess we could still go with this patch, but I think it would require
> a discussion about why it is preferable to do this as opposed to simply
> giving an error.

I prefer to give an error here, because doc says that content is 'the
hex-encoded bytes to write.', or I don't mind drop this patch :)

-- 
Yao

gdb:

2012-09-27  Yao Qi  <yao@codesourcery.com>

	* mi/mi-main.c (mi_cmd_data_write_memory_bytes): Emit error
	when the length of content is not an even number.
---
 gdb/mi/mi-main.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index f1d21bc..f73d4f8 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1672,6 +1672,10 @@ mi_cmd_data_write_memory_bytes (char *command, char **argv, int argc)
 
   addr = parse_and_eval_address (argv[0]);
   cdata = argv[1];
+  if (strlen (cdata) % 2)
+    error (_("Hex-encoded '%s' must have an even number of characters."),
+	   cdata);
+
   len = strlen (cdata)/2;
 
   data = xmalloc (len);
-- 
1.7.7.6


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]