/* Select target systems and architectures at runtime for GDB.
- Copyright (C) 1990-2015 Free Software Foundation, Inc.
+ Copyright (C) 1990-2016 Free Software Foundation, Inc.
Contributed by Cygnus Support.
#include "agent.h"
#include "auxv.h"
#include "target-debug.h"
+#include "top.h"
+#include "event-top.h"
static void target_info (char *, int);
static void
open_target (char *args, int from_tty, struct cmd_list_element *command)
{
- struct target_ops *ops = get_cmd_context (command);
+ struct target_ops *ops = (struct target_ops *) get_cmd_context (command);
if (targetdebug)
fprintf_unfiltered (gdb_stdlog, "-> %s->to_open (...)\n",
/* See target.h. */
+int
+target_terminal_is_ours (void)
+{
+ return (terminal_state == terminal_is_ours);
+}
+
+/* See target.h. */
+
void
target_terminal_inferior (void)
{
+ struct ui *ui = current_ui;
+
/* A background resume (``run&'') should leave GDB in control of the
- terminal. Use target_can_async_p, not target_is_async_p, since at
- this point the target is not async yet. However, if sync_execution
- is not set, we know it will become async prior to resume. */
- if (target_can_async_p () && !sync_execution)
+ terminal. */
+ if (ui->prompt_state != PROMPT_BLOCKED)
+ return;
+
+ /* Always delete the current UI's input file handler, regardless of
+ terminal_state, because terminal_state is only valid for the main
+ UI. */
+ delete_file_handler (ui->input_fd);
+
+ /* Since we always run the inferior in the main console (unless "set
+ inferior-tty" is in effect), when some UI other than the main one
+ calls target_terminal_inferior/target_terminal_inferior, then we
+ only register/unregister the UI's input from the event loop, but
+ leave the main UI's terminal settings as is. */
+ if (ui != main_ui)
return;
if (terminal_state == terminal_is_inferior)
inferior's terminal modes. */
(*current_target.to_terminal_inferior) (¤t_target);
terminal_state = terminal_is_inferior;
+
+ /* If the user hit C-c before, pretend that it was hit right
+ here. */
+ if (check_quit_flag ())
+ target_pass_ctrlc ();
}
/* See target.h. */
void
target_terminal_ours (void)
{
+ struct ui *ui = current_ui;
+
+ /* Always add the current UI's input file handler, regardless of
+ terminal_state, because terminal_state is only valid for the main
+ UI. */
+ add_file_handler (ui->input_fd, stdin_event_handler, ui);
+
+ /* See target_terminal_inferior. */
+ if (ui != main_ui)
+ return;
+
if (terminal_state == terminal_is_ours)
return;
void
target_terminal_ours_for_output (void)
{
+ struct ui *ui = current_ui;
+
+ /* See target_terminal_inferior. */
+ if (ui != main_ui)
+ return;
+
if (terminal_state != terminal_is_inferior)
return;
(*current_target.to_terminal_ours_for_output) (¤t_target);
static void
cleanup_restore_target_terminal (void *arg)
{
- enum terminal_state *previous_state = arg;
+ enum terminal_state *previous_state = (enum terminal_state *) arg;
switch (*previous_state)
{
return 1;
}
+/* Unpush TARGET and assert that it worked. */
+
+static void
+unpush_target_and_assert (struct target_ops *target)
+{
+ if (!unpush_target (target))
+ {
+ fprintf_unfiltered (gdb_stderr,
+ "pop_all_targets couldn't find target %s\n",
+ target->to_shortname);
+ internal_error (__FILE__, __LINE__,
+ _("failed internal consistency check"));
+ }
+}
+
void
pop_all_targets_above (enum strata above_stratum)
{
while ((int) (current_target.to_stratum) > (int) above_stratum)
- {
- if (!unpush_target (target_stack))
- {
- fprintf_unfiltered (gdb_stderr,
- "pop_all_targets couldn't find target %s\n",
- target_stack->to_shortname);
- internal_error (__FILE__, __LINE__,
- _("failed internal consistency check"));
- break;
- }
- }
+ unpush_target_and_assert (target_stack);
+}
+
+/* See target.h. */
+
+void
+pop_all_targets_at_and_above (enum strata stratum)
+{
+ while ((int) (current_target.to_stratum) >= (int) stratum)
+ unpush_target_and_assert (target_stack);
}
void
/* Small for testing. */
buffer_allocated = 4;
- buffer = xmalloc (buffer_allocated);
+ buffer = (char *) xmalloc (buffer_allocated);
bufptr = buffer;
while (len > 0)
bytes = bufptr - buffer;
buffer_allocated *= 2;
- buffer = xrealloc (buffer, buffer_allocated);
+ buffer = (char *) xrealloc (buffer, buffer_allocated);
bufptr = buffer + bytes;
}
}
else
{
- void *buf;
+ gdb_byte *buf;
struct cleanup *old_chain;
/* A large write request is likely to be partially satisfied
by memory_xfer_partial_1. We will continually malloc
and free a copy of the entire write request for breakpoint
shadow handling even though we only end up writing a small
- subset of it. Cap writes to 4KB to mitigate this. */
- len = min (4096, len);
+ subset of it. Cap writes to a limit specified by the target
+ to mitigate this. */
+ len = min (ops->to_get_memory_xfer_limit (ops), len);
- buf = xmalloc (len);
+ buf = (gdb_byte *) xmalloc (len);
old_chain = make_cleanup (xfree, buf);
memcpy (buf, writebuf, len);
/* Read LEN bytes of target memory at address MEMADDR, placing the
results in GDB's memory at MYADDR. Returns either 0 for success or
- TARGET_XFER_E_IO if any error occurs.
+ -1 if any error occurs.
If an error occurs, no guarantee is made about the contents of the data at
MYADDR. In particular, the caller should not depend upon partial reads
myaddr, memaddr, len) == len)
return 0;
else
- return TARGET_XFER_E_IO;
+ return -1;
}
/* See target/target.h. */
myaddr, memaddr, len) == len)
return 0;
else
- return TARGET_XFER_E_IO;
+ return -1;
}
/* Like target_read_memory, but specify explicitly that this is a read from
myaddr, memaddr, len) == len)
return 0;
else
- return TARGET_XFER_E_IO;
+ return -1;
}
/* Like target_read_memory, but specify explicitly that this is a read from
myaddr, memaddr, len) == len)
return 0;
else
- return TARGET_XFER_E_IO;
+ return -1;
}
/* Write LEN bytes from MYADDR to target memory at address MEMADDR.
- Returns either 0 for success or TARGET_XFER_E_IO if any
- error occurs. If an error occurs, no guarantee is made about how
- much data got written. Callers that can deal with partial writes
- should call target_write. */
+ Returns either 0 for success or -1 if any error occurs. If an
+ error occurs, no guarantee is made about how much data got written.
+ Callers that can deal with partial writes should call
+ target_write. */
int
target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
myaddr, memaddr, len) == len)
return 0;
else
- return TARGET_XFER_E_IO;
+ return -1;
}
/* Write LEN bytes from MYADDR to target raw memory at address
- MEMADDR. Returns either 0 for success or TARGET_XFER_E_IO
- if any error occurs. If an error occurs, no guarantee is made
- about how much data got written. Callers that can deal with
- partial writes should call target_write. */
+ MEMADDR. Returns either 0 for success or -1 if any error occurs.
+ If an error occurs, no guarantee is made about how much data got
+ written. Callers that can deal with partial writes should call
+ target_write. */
int
target_write_raw_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
myaddr, memaddr, len) == len)
return 0;
else
- return TARGET_XFER_E_IO;
+ return -1;
}
/* Fetch the target's memory map. */
VEC(mem_region_s) *result;
struct mem_region *last_one, *this_one;
int ix;
- struct target_ops *t;
-
result = current_target.to_memory_map (¤t_target);
if (result == NULL)
return NULL;
int unit_size,
VEC(memory_read_result_s) **result)
{
- gdb_byte *buf = xmalloc (end - begin);
+ gdb_byte *buf = (gdb_byte *) xmalloc (end - begin);
ULONGEST current_begin = begin;
ULONGEST current_end = end;
int forward;
/* The [current_end, end) range has been read. */
LONGEST region_len = end - current_end;
- r.data = xmalloc (region_len * unit_size);
+ r.data = (gdb_byte *) xmalloc (region_len * unit_size);
memcpy (r.data, buf + (current_end - begin) * unit_size,
region_len * unit_size);
r.begin = current_end;
void
free_memory_read_result_vector (void *x)
{
- VEC(memory_read_result_s) *v = x;
+ VEC(memory_read_result_s) **v = (VEC(memory_read_result_s) **) x;
memory_read_result_s *current;
int ix;
- for (ix = 0; VEC_iterate (memory_read_result_s, v, ix, current); ++ix)
+ for (ix = 0; VEC_iterate (memory_read_result_s, *v, ix, current); ++ix)
{
xfree (current->data);
}
- VEC_free (memory_read_result_s, v);
+ VEC_free (memory_read_result_s, *v);
}
VEC(memory_read_result_s) *
{
VEC(memory_read_result_s) *result = 0;
int unit_size = gdbarch_addressable_memory_unit_size (target_gdbarch ());
+ struct cleanup *cleanup = make_cleanup (free_memory_read_result_vector,
+ &result);
LONGEST xfered_total = 0;
while (xfered_total < len)
{
LONGEST to_read = min (len - xfered_total, region_len);
gdb_byte *buffer = (gdb_byte *) xmalloc (to_read * unit_size);
+ struct cleanup *inner_cleanup = make_cleanup (xfree, buffer);
LONGEST xfered_partial =
target_read (ops, TARGET_OBJECT_MEMORY, NULL,
{
/* Got an error reading full chunk. See if maybe we can read
some subrange. */
- xfree (buffer);
- read_whatever_is_readable (ops, offset + xfered_total, unit_size,
- offset + xfered_total + to_read, &result);
+ do_cleanups (inner_cleanup);
+ read_whatever_is_readable (ops, offset + xfered_total,
+ offset + xfered_total + to_read,
+ unit_size, &result);
xfered_total += to_read;
}
else
{
struct memory_read_result r;
+
+ discard_cleanups (inner_cleanup);
r.data = buffer;
r.begin = offset + xfered_total;
r.end = r.begin + xfered_partial;
QUIT;
}
}
+
+ discard_cleanups (cleanup);
return result;
}
/* Start by reading up to 4K at a time. The target will throttle
this number down if necessary. */
buf_alloc = 4096;
- buf = xmalloc (buf_alloc);
+ buf = (gdb_byte *) xmalloc (buf_alloc);
buf_pos = 0;
while (1)
{
if (buf_alloc < buf_pos * 2)
{
buf_alloc *= 2;
- buf = xrealloc (buf, buf_alloc);
+ buf = (gdb_byte *) xrealloc (buf, buf_alloc);
}
QUIT;
the inferior was attached to. */
current_inferior ()->attach_flag = 0;
+ current_inferior ()->highest_thread_num = 0;
+
agent_capability_invalidate ();
}
void
target_detach (const char *args, int from_tty)
{
- struct target_ops* t;
-
if (gdbarch_has_global_breakpoints (target_gdbarch ()))
/* Don't remove global breakpoints here. They're removed on
disconnection from the target. */
return (*current_target.to_pid_to_str) (¤t_target, ptid);
}
-char *
+const char *
target_thread_name (struct thread_info *info)
{
return current_target.to_thread_name (¤t_target, info);
void
target_resume (ptid_t ptid, int step, enum gdb_signal signal)
{
- struct target_ops *t;
-
target_dcache_invalidate ();
current_target.to_resume (¤t_target, ptid, step, signal);
if (search_space_len < search_buf_size)
search_buf_size = search_space_len;
- search_buf = malloc (search_buf_size);
+ search_buf = (gdb_byte *) malloc (search_buf_size);
if (search_buf == NULL)
error (_("Unable to allocate memory to perform the search."));
old_cleanups = make_cleanup (free_current_contents, &search_buf);
gdb_byte *found_ptr;
unsigned nr_search_bytes = min (search_space_len, search_buf_size);
- found_ptr = memmem (search_buf, nr_search_bytes,
- pattern, pattern_len);
+ found_ptr = (gdb_byte *) memmem (search_buf, nr_search_bytes,
+ pattern, pattern_len);
if (found_ptr != NULL)
{
static int
acquire_fileio_fd (struct target_ops *t, int fd)
{
- fileio_fh_t *fh, buf;
+ fileio_fh_t *fh;
gdb_assert (!is_closed_fileio_fh (fd));
/* Start by reading up to 4K at a time. The target will throttle
this number down if necessary. */
buf_alloc = 4096;
- buf = xmalloc (buf_alloc);
+ buf = (gdb_byte *) xmalloc (buf_alloc);
buf_pos = 0;
while (1)
{
if (buf_alloc < buf_pos * 2)
{
buf_alloc *= 2;
- buf = xrealloc (buf, buf_alloc);
+ buf = (gdb_byte *) xrealloc (buf, buf_alloc);
}
QUIT;
}
\f
+
+/* See target.h */
+
+void
+target_announce_detach (int from_tty)
+{
+ pid_t pid;
+ char *exec_file;
+
+ if (!from_tty)
+ return;
+
+ exec_file = get_exec_file (0);
+ if (exec_file == NULL)
+ exec_file = "";
+
+ pid = ptid_get_pid (inferior_ptid);
+ printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file,
+ target_pid_to_str (pid_to_ptid (pid)));
+ gdb_flush (gdb_stdout);
+}
+
/* The inferior process has died. Long live the inferior! */
void
/* See target.h. */
void
-target_check_pending_interrupt (void)
+target_pass_ctrlc (void)
{
- (*current_target.to_check_pending_interrupt) (¤t_target);
+ (*current_target.to_pass_ctrlc) (¤t_target);
+}
+
+/* See target.h. */
+
+void
+default_target_pass_ctrlc (struct target_ops *ops)
+{
+ target_interrupt (inferior_ptid);
}
/* See target/target.h. */
void
target_store_registers (struct regcache *regcache, int regno)
{
- struct target_ops *t;
-
if (!may_write_registers)
error (_("Writing to registers is not allowed (regno %d)"), regno);
target.h. */
int
-target_insert_mask_watchpoint (CORE_ADDR addr, CORE_ADDR mask, int rw)
+target_insert_mask_watchpoint (CORE_ADDR addr, CORE_ADDR mask,
+ enum target_hw_bp_type rw)
{
return current_target.to_insert_mask_watchpoint (¤t_target,
addr, mask, rw);
target.h. */
int
-target_remove_mask_watchpoint (CORE_ADDR addr, CORE_ADDR mask, int rw)
+target_remove_mask_watchpoint (CORE_ADDR addr, CORE_ADDR mask,
+ enum target_hw_bp_type rw)
{
return current_target.to_remove_mask_watchpoint (¤t_target,
addr, mask, rw);
/* See target.h. */
+int
+target_record_will_replay (ptid_t ptid, int dir)
+{
+ return current_target.to_record_will_replay (¤t_target, ptid, dir);
+}
+
+/* See target.h. */
+
+void
+target_record_stop_replaying (void)
+{
+ current_target.to_record_stop_replaying (¤t_target);
+}
+
+/* See target.h. */
+
void
target_goto_record_begin (void)
{
current_target.to_async (¤t_target, enable);
}
+/* See target.h. */
+
+void
+target_thread_events (int enable)
+{
+ current_target.to_thread_events (¤t_target, enable);
+}
+
/* Controls if targets can report that they can/are async. This is
just for maintainers to use when debugging gdb. */
int target_async_permitted = 1;