From 146ec4dbcf11fdac62a9f7174f214e6abb5d36dc Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Fri, 6 Sep 2013 18:10:39 +0000 Subject: [PATCH] remote-sim.c: Don't install a deprecated_xfer_memory method. Manually tested with a --target=arm-eabi build, and doing things like: $ arm-eabi-gcc ~/gdb/tests/main.c -o a.out -c -g $ ./gdb a.out ... (gdb) tar sim (gdb) load (gdb) disassemble 0 Dump of assembler code for function main: 0x00000000 <+0>: mov r12, sp 0x00000004 <+4>: push {r11, r12, lr, pc} 0x00000008 <+8>: sub r11, r12, #4 0x0000000c <+12>: sub sp, sp, #8 0x00000010 <+16>: str r0, [r11, #-16] 0x00000014 <+20>: str r1, [r11, #-20] 0x00000018 <+24>: mov r3, #0 0x0000001c <+28>: mov r0, r3 0x00000020 <+32>: sub sp, r11, #12 0x00000024 <+36>: ldm sp, {r11, sp, pc} End of assembler dump. (gdb) p *0 = 1 0x00000001 gdb/ 2013-09-06 Pedro Alves * remote-sim.c (dump_mem): Constify buf parameter. gdbsim_xfer_inferior_memory): Rename to ... (gdbsim_xfer_memory): ... this. Adjust interface as target_xfer_partial helper. (gdbsim_xfer_partial): New function. (init_gdbsim_ops): Don't install a deprecated_xfer_memory hook. Install a to_xfer_partial hook. Send output to gdb_stdlog. --- gdb/ChangeLog | 10 ++++++++++ gdb/remote-sim.c | 57 ++++++++++++++++++++++++++++++++++---------------------- 2 files changed, 45 insertions(+), 22 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 2c7b655..f4ede3c 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,15 @@ 2013-09-06 Pedro Alves + * remote-sim.c (dump_mem): Constify buf parameter. + gdbsim_xfer_inferior_memory): Rename to ... + (gdbsim_xfer_memory): ... this. Adjust interface as + target_xfer_partial helper. + (gdbsim_xfer_partial): New function. + (init_gdbsim_ops): Don't install a deprecated_xfer_memory hook. + Install a to_xfer_partial hook. Send output to gdb_stdlog. + +2013-09-06 Pedro Alves + * remote-sim.c (gdbsim_xfer_inferior_memory): Use host_address_to_string, and send debug output to gdb_stdlog. diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c index 49e2581..dda0045 100644 --- a/gdb/remote-sim.c +++ b/gdb/remote-sim.c @@ -46,8 +46,6 @@ extern void _initialize_remote_sim (void); -static void dump_mem (gdb_byte *buf, int len); - static void init_callbacks (void); static void end_callbacks (void); @@ -271,7 +269,7 @@ sim_inferior_data_cleanup (struct inferior *inf, void *data) } static void -dump_mem (gdb_byte *buf, int len) +dump_mem (const gdb_byte *buf, int len) { printf_filtered ("\t"); @@ -1054,16 +1052,13 @@ gdbsim_prepare_to_store (struct regcache *regcache) /* Do nothing, since we can store individual regs. */ } -/* Transfer LEN bytes between GDB address MYADDR and target address - MEMADDR. If WRITE is non-zero, transfer them to the target, - otherwise transfer them from the target. TARGET is unused. - - Returns the number of bytes transferred. */ +/* Helper for gdbsim_xfer_partial that handles memory transfers. + Arguments are like target_xfer_partial. */ -static int -gdbsim_xfer_inferior_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, - int write, struct mem_attrib *attrib, - struct target_ops *target) +static LONGEST +gdbsim_xfer_memory (struct target_ops *target, + gdb_byte *readbuf, const gdb_byte *writebuf, + ULONGEST memaddr, LONGEST len) { struct sim_inferior_data *sim_data = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NOT_NEEDED); @@ -1087,27 +1082,45 @@ gdbsim_xfer_inferior_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, if (remote_debug) fprintf_unfiltered (gdb_stdlog, - "gdbsim_xfer_inferior_memory: myaddr %s, " - "memaddr %s, len %d, write %d\n", - host_address_to_string (myaddr), + "gdbsim_xfer_memory: readbuf %s, writebuf %s, " + "memaddr %s, len %s\n", + host_address_to_string (readbuf), + host_address_to_string (writebuf), paddress (target_gdbarch (), memaddr), - len, write); + plongest (len)); - if (write) + if (writebuf) { if (remote_debug && len > 0) - dump_mem (myaddr, len); - len = sim_write (sim_data->gdbsim_desc, memaddr, myaddr, len); + dump_mem (writebuf, len); + len = sim_write (sim_data->gdbsim_desc, memaddr, writebuf, len); } else { - len = sim_read (sim_data->gdbsim_desc, memaddr, myaddr, len); + len = sim_read (sim_data->gdbsim_desc, memaddr, readbuf, len); if (remote_debug && len > 0) - dump_mem (myaddr, len); + dump_mem (readbuf, len); } return len; } +/* Target to_xfer_partial implementation. */ + +static LONGEST +gdbsim_xfer_partial (struct target_ops *ops, enum target_object object, + const char *annex, gdb_byte *readbuf, + const gdb_byte *writebuf, ULONGEST offset, LONGEST len) +{ + switch (object) + { + case TARGET_OBJECT_MEMORY: + return gdbsim_xfer_memory (ops, readbuf, writebuf, offset, len); + + default: + return -1; + } +} + static void gdbsim_files_info (struct target_ops *target) { @@ -1283,7 +1296,7 @@ init_gdbsim_ops (void) gdbsim_ops.to_fetch_registers = gdbsim_fetch_register; gdbsim_ops.to_store_registers = gdbsim_store_register; gdbsim_ops.to_prepare_to_store = gdbsim_prepare_to_store; - gdbsim_ops.deprecated_xfer_memory = gdbsim_xfer_inferior_memory; + gdbsim_ops.to_xfer_partial = gdbsim_xfer_partial; gdbsim_ops.to_files_info = gdbsim_files_info; gdbsim_ops.to_insert_breakpoint = memory_insert_breakpoint; gdbsim_ops.to_remove_breakpoint = memory_remove_breakpoint; -- 2.7.4