declaration.
* breakpoint.c (breakpoint_restore_shadows): New.
(read_memory_nobpt): Delete.
* gdbcore.h (read_memory_nobpt): Delete declaration.
* target.c (memory_xfer_partial): Call
breakpoint_restore_shadows.
(restore_show_memory_breakpoints)
(make_show_memory_beakpoints_cleanup): New.
(show_memory_breakpoints): New.
* target.h (make_show_memory_beakpoints_cleanup): Declare.
* ppc-linux-tdep.c (ppc_linux_memory_remove_breakpoint):
Make sure we see memory breakpoints when checking if
breakpoint is still there.
* alpha-tdep.c, alphanbsd-tdep.c, frame.c, frv-tdep.c,
hppa-linux-tdep.c, hppa-tdep.c, i386-linux-nat.c, i386-tdep.c,
m68klinux-tdep.c, mips-tdep.c, mn10300-tdep.c, s390-tdep.c,
sparc-tdep.c: Use target_read_memory instead of read_memory_nobpt.
+2008-03-13 Vladimir Prus <vladimir@codesourcery.com>
+ Daniel Jacobowitz <dan@codesourcery.com>
+
+ * breakpoint.h (breakpoint_restore_shadows): New
+ declaration.
+ * breakpoint.c (breakpoint_restore_shadows): New.
+ (read_memory_nobpt): Delete.
+ * gdbcore.h (read_memory_nobpt): Delete declaration.
+ * target.c (memory_xfer_partial): Call
+ breakpoint_restore_shadows.
+ (restore_show_memory_breakpoints)
+ (make_show_memory_beakpoints_cleanup): New.
+ (show_memory_breakpoints): New.
+ * target.h (make_show_memory_beakpoints_cleanup): Declare.
+ * ppc-linux-tdep.c (ppc_linux_memory_remove_breakpoint):
+ Make sure we see memory breakpoints when checking if
+ breakpoint is still there.
+ * alpha-tdep.c, alphanbsd-tdep.c, frame.c, frv-tdep.c,
+ hppa-linux-tdep.c, hppa-tdep.c, i386-linux-nat.c, i386-tdep.c,
+ m68klinux-tdep.c, mips-tdep.c, mn10300-tdep.c, s390-tdep.c,
+ sparc-tdep.c: Use target_read_memory instead of read_memory_nobpt.
+
2008-03-12 Pedro Alves <pedro@codesourcery.com>
* thread.c (add_thread): Use printf_unfiltered to print.
target.o: target.c $(defs_h) $(gdb_string_h) $(target_h) $(gdbcmd_h) \
$(symtab_h) $(inferior_h) $(bfd_h) $(symfile_h) $(objfiles_h) \
$(gdb_wait_h) $(dcache_h) $(regcache_h) $(gdb_assert_h) $(gdbcore_h) \
- $(exceptions_h) $(target_descriptions_h)
+ $(exceptions_h) $(target_descriptions_h) $(gdb_stdint_h)
target-descriptions.o: target-descriptions.c $(defs_h) $(arch_utils_h) \
$(target_h) $(target_descriptions_h) $(vec_h) $(xml_tdesc_h) \
$(gdbcmd_h) $(gdb_assert_h) $(gdbtypes_h) $(reggroups_h) \
gdb_byte buf[ALPHA_INSN_SIZE];
int status;
- status = read_memory_nobpt (pc, buf, sizeof (buf));
+ status = target_read_memory (pc, buf, sizeof (buf));
if (status)
memory_error (status, pc);
return extract_unsigned_integer (buf, sizeof (buf));
LONGEST off;
int i;
- if (read_memory_nobpt (pc, (char *) w, 4) != 0)
+ if (target_read_memory (pc, (char *) w, 4) != 0)
return -1;
for (i = 0; i < RETCODE_NWORDS; i++)
off = i * 4;
pc -= off;
- if (read_memory_nobpt (pc, (char *) ret, sizeof (ret)) != 0)
+ if (target_read_memory (pc, (char *) ret, sizeof (ret)) != 0)
return -1;
if (memcmp (ret, sigtramp_retcode, RETCODE_SIZE) == 0)
error (_("No breakpoint number %d."), bnum);
}
\f
-/* Like target_read_memory() but if breakpoints are inserted, return
- the shadow contents instead of the breakpoints themselves.
+/* Update BUF, which is LEN bytes read from the target address MEMADDR,
+ by replacing any memory breakpoints with their shadowed contents. */
- Read "memory data" from whatever target or inferior we have.
- Returns zero if successful, errno value if not. EIO is used
- for address out of bounds. If breakpoints are inserted, returns
- shadow contents, not the breakpoints themselves. From breakpoint.c. */
-
-int
-read_memory_nobpt (CORE_ADDR memaddr, gdb_byte *myaddr, unsigned len)
+void
+breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len)
{
- int status;
- const struct bp_location *b;
+ struct bp_location *b;
CORE_ADDR bp_addr = 0;
int bp_size = 0;
-
- if (gdbarch_breakpoint_from_pc (current_gdbarch, &bp_addr, &bp_size) == NULL)
- /* No breakpoints on this machine. */
- return target_read_memory (memaddr, myaddr, len);
+ int bptoffset = 0;
ALL_BP_LOCATIONS (b)
{
if (bp_size == 0)
/* bp isn't valid, or doesn't shadow memory. */
continue;
+
if (bp_addr + bp_size <= memaddr)
/* The breakpoint is entirely before the chunk of memory we
are reading. */
continue;
+
if (bp_addr >= memaddr + len)
/* The breakpoint is entirely after the chunk of memory we are
reading. */
continue;
- /* Copy the breakpoint from the shadow contents, and recurse for
- the things before and after. */
- {
- /* Offset within shadow_contents. */
- int bptoffset = 0;
-
- if (bp_addr < memaddr)
- {
- /* Only copy the second part of the breakpoint. */
- bp_size -= memaddr - bp_addr;
- bptoffset = memaddr - bp_addr;
- bp_addr = memaddr;
- }
-
- if (bp_addr + bp_size > memaddr + len)
- {
- /* Only copy the first part of the breakpoint. */
- bp_size -= (bp_addr + bp_size) - (memaddr + len);
- }
- memcpy (myaddr + bp_addr - memaddr,
- b->target_info.shadow_contents + bptoffset, bp_size);
+ /* Offset within shadow_contents. */
+ if (bp_addr < memaddr)
+ {
+ /* Only copy the second part of the breakpoint. */
+ bp_size -= memaddr - bp_addr;
+ bptoffset = memaddr - bp_addr;
+ bp_addr = memaddr;
+ }
- if (bp_addr > memaddr)
- {
- /* Copy the section of memory before the breakpoint. */
- status = read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr);
- if (status != 0)
- return status;
- }
+ if (bp_addr + bp_size > memaddr + len)
+ {
+ /* Only copy the first part of the breakpoint. */
+ bp_size -= (bp_addr + bp_size) - (memaddr + len);
+ }
- if (bp_addr + bp_size < memaddr + len)
- {
- /* Copy the section of memory after the breakpoint. */
- status = read_memory_nobpt (bp_addr + bp_size,
- myaddr + bp_addr + bp_size - memaddr,
- memaddr + len - (bp_addr + bp_size));
- if (status != 0)
- return status;
- }
- return 0;
- }
+ memcpy (buf + bp_addr - memaddr,
+ b->target_info.shadow_contents + bptoffset, bp_size);
}
- /* Nothing overlaps. Just call read_memory_noerr. */
- return target_read_memory (memaddr, myaddr, len);
}
\f
/* Adjust the breakpoint's address prior to allocating a location.
Once we call allocate_bp_location(), that mostly uninitialized
location will be placed on the location chain. Adjustment of the
- breakpoint may cause read_memory_nobpt() to be called and we do
+ breakpoint may cause target_read_memory() to be called and we do
not want its scan of the location chain to find a breakpoint and
location that's only been partially initialized. */
adjusted_address = adjust_breakpoint_address (sal.pc, bptype);
target. */
int watchpoints_triggered (struct target_waitstatus *);
+/* Update BUF, which is LEN bytes read from the target address MEMADDR,
+ by replacing any memory breakpoints with their shadowed contents. */
+void breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr,
+ LONGEST len);
+
#endif /* !defined (BREAKPOINT_H) */
safe_frame_unwind_memory (struct frame_info *this_frame,
CORE_ADDR addr, gdb_byte *buf, int len)
{
- /* NOTE: read_memory_nobpt returns zero on success! */
- return !read_memory_nobpt (addr, buf, len);
+ /* NOTE: target_read_memory returns zero on success! */
+ return !target_read_memory (addr, buf, len);
}
/* Architecture method. */
char instr[frv_instr_size];
int status;
- status = read_memory_nobpt (addr, instr, sizeof instr);
+ status = target_read_memory (addr, instr, sizeof instr);
if (status != 0)
break;
extern int have_core_file_p (void);
-/* Read "memory data" from whatever target or inferior we have.
- Returns zero if successful, errno value if not. EIO is used for
- address out of bounds. If breakpoints are inserted, returns shadow
- contents, not the breakpoints themselves. From breakpoint.c. */
-
-/* NOTE: cagney/2004-06-10: Code reading from a live inferior can use
- the get_frame_memory methods, code reading from an exec can use the
- target methods. */
-
-extern int read_memory_nobpt (CORE_ADDR memaddr, gdb_byte *myaddr,
- unsigned len);
-
/* Report a memory error with error(). */
extern void memory_error (int status, CORE_ADDR memaddr);
{
char buf[4];
- read_memory_nobpt (npc, buf, 4);
+ target_read_memory (npc, buf, 4);
insn[i] = extract_unsigned_integer (buf, 4);
if ((insn[i] & pattern[i].mask) == pattern[i].data)
npc += 4;
char buf[4];
int off;
- status = read_memory_nobpt (pc, buf, 4);
+ status = target_read_memory (pc, buf, 4);
if (status != 0)
return 0;
old_save_sp = save_sp;
old_stack_remaining = stack_remaining;
- status = read_memory_nobpt (pc, buf, 4);
+ status = target_read_memory (pc, buf, 4);
inst = extract_unsigned_integer (buf, 4);
/* Yow! */
&& reg_num <= 26)
{
pc += 4;
- status = read_memory_nobpt (pc, buf, 4);
+ status = target_read_memory (pc, buf, 4);
inst = extract_unsigned_integer (buf, 4);
if (status != 0)
return pc;
reg_num = inst_saves_fr (inst);
save_fr &= ~(1 << reg_num);
- status = read_memory_nobpt (pc + 4, buf, 4);
+ status = target_read_memory (pc + 4, buf, 4);
next_inst = extract_unsigned_integer (buf, 4);
/* Yow! */
<= (gdbarch_ptr_bit (gdbarch) == 64 ? 11 : 7))
{
pc += 8;
- status = read_memory_nobpt (pc, buf, 4);
+ status = target_read_memory (pc, buf, 4);
inst = extract_unsigned_integer (buf, 4);
if (status != 0)
return pc;
if ((inst & 0xfc000000) != 0x34000000)
break;
- status = read_memory_nobpt (pc + 4, buf, 4);
+ status = target_read_memory (pc + 4, buf, 4);
next_inst = extract_unsigned_integer (buf, 4);
if (status != 0)
return pc;
{
gdb_byte buf[HPPA_INSN_SIZE];
- read_memory_nobpt (npc, buf, HPPA_INSN_SIZE);
+ target_read_memory (npc, buf, HPPA_INSN_SIZE);
insn[i] = extract_unsigned_integer (buf, HPPA_INSN_SIZE);
if ((insn[i] & pattern[i].mask) == pattern[i].data)
npc += 4;
that's about to be restored, and set the trace flag there. */
/* First check if PC is at a system call. */
- if (read_memory_nobpt (pc, buf, LINUX_SYSCALL_LEN) == 0
+ if (target_read_memory (pc, buf, LINUX_SYSCALL_LEN) == 0
&& memcmp (buf, linux_syscall, LINUX_SYSCALL_LEN) == 0)
{
ULONGEST syscall;
long delta = 0;
int data16 = 0;
- read_memory_nobpt (pc, &op, 1);
+ target_read_memory (pc, &op, 1);
if (op == 0x66)
{
data16 = 1;
if (current_pc <= pc)
return pc;
- read_memory_nobpt (pc, &op, 1);
+ target_read_memory (pc, &op, 1);
if (op != 0x58) /* popl %eax */
return pc;
- read_memory_nobpt (pc + 1, buf, 4);
+ target_read_memory (pc + 1, buf, 4);
if (memcmp (buf, proto1, 3) != 0 && memcmp (buf, proto2, 4) != 0)
return pc;
gdb_byte buf[8];
gdb_byte op;
- read_memory_nobpt (pc, &op, 1);
+ target_read_memory (pc, &op, 1);
if (op == 0x68 || op == 0x6a)
{
struct i386_insn *insn;
gdb_byte op;
- read_memory_nobpt (pc, &op, 1);
+ target_read_memory (pc, &op, 1);
for (insn = skip_insns; insn->len > 0; insn++)
{
gdb_assert (insn->len > 1);
gdb_assert (insn->len <= I386_MAX_INSN_LEN);
- read_memory_nobpt (pc + 1, buf, insn->len - 1);
+ target_read_memory (pc + 1, buf, insn->len - 1);
for (i = 1; i < insn->len; i++)
{
if ((buf[i - 1] & insn->mask[i]) != insn->insn[i])
gdb_byte op;
int check = 1;
- read_memory_nobpt (pc, &op, 1);
+ target_read_memory (pc, &op, 1);
while (check)
{
if (op == 0x90)
{
pc += 1;
- read_memory_nobpt (pc, &op, 1);
+ target_read_memory (pc, &op, 1);
check = 1;
}
/* Ignore no-op instruction `mov %edi, %edi'.
else if (op == 0x8b)
{
- read_memory_nobpt (pc + 1, &op, 1);
+ target_read_memory (pc + 1, &op, 1);
if (op == 0xff)
{
pc += 2;
- read_memory_nobpt (pc, &op, 1);
+ target_read_memory (pc, &op, 1);
check = 1;
}
}
if (limit <= pc)
return limit;
- read_memory_nobpt (pc, &op, 1);
+ target_read_memory (pc, &op, 1);
if (op == 0x55) /* pushl %ebp */
{
if (limit <= pc + skip)
return limit;
- read_memory_nobpt (pc + skip, &op, 1);
+ target_read_memory (pc + skip, &op, 1);
/* Check for `movl %esp, %ebp' -- can be written in two ways. */
switch (op)
NOTE: You can't subtract a 16-bit immediate from a 32-bit
reg, so we don't have to worry about a data16 prefix. */
- read_memory_nobpt (pc, &op, 1);
+ target_read_memory (pc, &op, 1);
if (op == 0x83)
{
/* `subl' with 8-bit immediate. */
offset -= cache->locals;
for (i = 0; i < 8 && pc < current_pc; i++)
{
- read_memory_nobpt (pc, &op, 1);
+ target_read_memory (pc, &op, 1);
if (op < 0x50 || op > 0x57)
break;
for (i = 0; i < 6; i++)
{
- read_memory_nobpt (pc + i, &op, 1);
+ target_read_memory (pc + i, &op, 1);
if (pic_pat[i] != op)
break;
}
{
int delta = 6;
- read_memory_nobpt (pc + delta, &op, 1);
+ target_read_memory (pc + delta, &op, 1);
if (op == 0x89) /* movl %ebx, x(%ebp) */
{
else /* Unexpected instruction. */
delta = 0;
- read_memory_nobpt (pc + delta, &op, 1);
+ target_read_memory (pc + delta, &op, 1);
}
/* addl y,%ebx */
char buf[12];
unsigned long insn0, insn1, insn2;
- if (read_memory_nobpt (pc - 4, buf, sizeof (buf)))
+ if (target_read_memory (pc - 4, buf, sizeof (buf)))
return 0;
insn1 = extract_unsigned_integer (buf + 4, 4);
insn2 = extract_unsigned_integer (buf + 8, 4);
}
else
instlen = MIPS_INSN32_SIZE;
- status = read_memory_nobpt (addr, buf, instlen);
+ status = target_read_memory (addr, buf, instlen);
if (status)
memory_error (status, addr);
return extract_unsigned_integer (buf, instlen);
goto finish_prologue;
/* Get the next two bytes so the prologue scan can continue. */
- status = read_memory_nobpt (addr, buf, 2);
+ status = target_read_memory (addr, buf, 2);
if (status != 0)
goto finish_prologue;
}
if (!fmov_found)
{
addr = restore_addr;
- status = read_memory_nobpt (addr, buf, 2);
+ status = target_read_memory (addr, buf, 2);
if (status != 0)
goto finish_prologue;
stack_extra_size = 0;
int val;
int bplen;
gdb_byte old_contents[BREAKPOINT_MAX];
+ struct cleanup *cleanup;
/* Determine appropriate breakpoint contents and size for this address. */
bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen);
if (bp == NULL)
error (_("Software breakpoints not implemented for this target."));
+ /* Make sure we see the memory breakpoints. */
+ cleanup = make_show_memory_breakpoints_cleanup (1);
val = target_read_memory (addr, old_contents, bplen);
/* If our breakpoint is no longer at the address, this means that the
if (val == 0 && memcmp (bp, old_contents, bplen) == 0)
val = target_write_memory (addr, bp_tgt->shadow_contents, bplen);
+ do_cleanups (cleanup);
return val;
}
static int s390_instrlen[] = { 2, 4, 4, 6 };
int instrlen;
- if (read_memory_nobpt (at, &instr[0], 2))
+ if (target_read_memory (at, &instr[0], 2))
return -1;
instrlen = s390_instrlen[instr[0] >> 6];
if (instrlen > 2)
{
- if (read_memory_nobpt (at + 2, &instr[2], instrlen - 2))
+ if (target_read_memory (at + 2, &instr[2], instrlen - 2))
return -1;
}
return instrlen;
int d2;
if (word_size == 4
- && !read_memory_nobpt (pc - 4, insn, 4)
+ && !target_read_memory (pc - 4, insn, 4)
&& is_rs (insn, op_lm, &r1, &r3, &d2, &b2)
&& r3 == S390_SP_REGNUM - S390_R0_REGNUM)
return 1;
if (word_size == 4
- && !read_memory_nobpt (pc - 6, insn, 6)
+ && !target_read_memory (pc - 6, insn, 6)
&& is_rsy (insn, op1_lmy, op2_lmy, &r1, &r3, &d2, &b2)
&& r3 == S390_SP_REGNUM - S390_R0_REGNUM)
return 1;
if (word_size == 8
- && !read_memory_nobpt (pc - 6, insn, 6)
+ && !target_read_memory (pc - 6, insn, 6)
&& is_rsy (insn, op1_lmg, op2_lmg, &r1, &r3, &d2, &b2)
&& r3 == S390_SP_REGNUM - S390_R0_REGNUM)
return 1;
CORE_ADDR pc = frame_pc_unwind (next_frame);
bfd_byte sigreturn[2];
- if (read_memory_nobpt (pc, sigreturn, 2))
+ if (target_read_memory (pc, sigreturn, 2))
return NULL;
if (sigreturn[0] != 0x0a /* svc */)
int i;
/* If we can't read the instruction at PC, return zero. */
- if (read_memory_nobpt (pc, buf, sizeof (buf)))
+ if (target_read_memory (pc, buf, sizeof (buf)))
return 0;
insn = 0;
#include "gdbcore.h"
#include "exceptions.h"
#include "target-descriptions.h"
+#include "gdb_stdint.h"
static void target_info (char *, int);
static int trust_readonly = 0;
+/* Nonzero if we should show true memory content including
+ memory breakpoint inserted by gdb. */
+
+static int show_memory_breakpoints = 0;
+
/* Non-zero if we want to see trace of target level stuff. */
static int targetdebug = 0;
if (res <= 0)
return -1;
else
- return res;
+ {
+ if (readbuf && !show_memory_breakpoints)
+ breakpoint_restore_shadows (readbuf, memaddr, reg_len);
+ return res;
+ }
}
/* If none of those methods found the memory we wanted, fall back
res = ops->to_xfer_partial (ops, TARGET_OBJECT_MEMORY, NULL,
readbuf, writebuf, memaddr, reg_len);
if (res > 0)
- return res;
+ break;
/* We want to continue past core files to executables, but not
past a running target's memory. */
if (ops->to_has_all_memory)
- return res;
+ break;
ops = ops->beneath;
}
while (ops != NULL);
+ if (readbuf && !show_memory_breakpoints)
+ breakpoint_restore_shadows (readbuf, memaddr, reg_len);
+
/* If we still haven't got anything, return the last error. We
give up. */
return res;
}
+static void
+restore_show_memory_breakpoints (void *arg)
+{
+ show_memory_breakpoints = (uintptr_t) arg;
+}
+
+struct cleanup *
+make_show_memory_breakpoints_cleanup (int show)
+{
+ int current = show_memory_breakpoints;
+ show_memory_breakpoints = show;
+
+ return make_cleanup (restore_show_memory_breakpoints,
+ (void *) (uintptr_t) current);
+}
+
static LONGEST
target_xfer_partial (struct target_ops *ops,
enum target_object object, const char *annex,
/* Any target can call this to switch to remote protocol (in remote.c). */
extern void push_remote_target (char *name, int from_tty);
+
+/* Set the show memory breakpoints mode to show, and installs a cleanup
+ to restore it back to the current value. */
+extern struct cleanup *make_show_memory_breakpoints_cleanup (int show);
+
\f
/* Imported from machine dependent code */