X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Ftarget.c;h=ac66a3a8993407219dddfa59318df78b5d83cd39;hb=e42de8c7f8e7326d284f8b53f3bd6971fbf6e7b7;hp=ea541aae4a0ce2eedd7a9256bdf1617f017b07b1;hpb=e9756d52bea3834ffb31d0a907944bd022250ed8;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/target.c b/gdb/target.c index ea541aae4a..ac66a3a899 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -1,6 +1,6 @@ /* 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. @@ -347,7 +347,7 @@ complete_target_initialization (struct target_ops *t) 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", @@ -466,6 +466,14 @@ target_terminal_is_inferior (void) /* See target.h. */ +int +target_terminal_is_ours (void) +{ + return (terminal_state == terminal_is_ours); +} + +/* See target.h. */ + void target_terminal_inferior (void) { @@ -531,7 +539,7 @@ target_supports_terminal_ours (void) 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) { @@ -746,21 +754,35 @@ unpush_target (struct target_ops *t) 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 @@ -926,7 +948,7 @@ target_read_string (CORE_ADDR memaddr, char **string, int len, int *errnop) /* Small for testing. */ buffer_allocated = 4; - buffer = xmalloc (buffer_allocated); + buffer = (char *) xmalloc (buffer_allocated); bufptr = buffer; while (len > 0) @@ -953,7 +975,7 @@ target_read_string (CORE_ADDR memaddr, char **string, int len, int *errnop) bytes = bufptr - buffer; buffer_allocated *= 2; - buffer = xrealloc (buffer, buffer_allocated); + buffer = (char *) xrealloc (buffer, buffer_allocated); bufptr = buffer + bytes; } @@ -1235,7 +1257,7 @@ memory_xfer_partial (struct target_ops *ops, enum target_object object, } else { - void *buf; + gdb_byte *buf; struct cleanup *old_chain; /* A large write request is likely to be partially satisfied @@ -1245,7 +1267,7 @@ memory_xfer_partial (struct target_ops *ops, enum target_object object, subset of it. Cap writes to 4KB to mitigate this. */ len = min (4096, len); - buf = xmalloc (len); + buf = (gdb_byte *) xmalloc (len); old_chain = make_cleanup (xfree, buf); memcpy (buf, writebuf, len); @@ -1380,7 +1402,7 @@ target_xfer_partial (struct target_ops *ops, /* 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 @@ -1399,7 +1421,7 @@ target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len) myaddr, memaddr, len) == len) return 0; else - return TARGET_XFER_E_IO; + return -1; } /* See target/target.h. */ @@ -1431,7 +1453,7 @@ target_read_raw_memory (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len) 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 @@ -1446,7 +1468,7 @@ target_read_stack (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len) 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 @@ -1461,14 +1483,14 @@ target_read_code (CORE_ADDR memaddr, 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 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) @@ -1479,14 +1501,14 @@ 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) @@ -1497,7 +1519,7 @@ 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. */ @@ -1655,7 +1677,7 @@ read_whatever_is_readable (struct target_ops *ops, 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; @@ -1755,7 +1777,7 @@ read_whatever_is_readable (struct target_ops *ops, /* 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; @@ -1768,7 +1790,7 @@ read_whatever_is_readable (struct target_ops *ops, 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; @@ -1822,8 +1844,9 @@ read_memory_robust (struct target_ops *ops, /* 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); + read_whatever_is_readable (ops, offset + xfered_total, + offset + xfered_total + to_read, + unit_size, &result); xfered_total += to_read; } else @@ -1923,7 +1946,7 @@ target_read_alloc_1 (struct target_ops *ops, enum target_object object, /* 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) { @@ -1956,7 +1979,7 @@ target_read_alloc_1 (struct target_ops *ops, enum target_object object, if (buf_alloc < buf_pos * 2) { buf_alloc *= 2; - buf = xrealloc (buf, buf_alloc); + buf = (gdb_byte *) xrealloc (buf, buf_alloc); } QUIT; @@ -2142,6 +2165,8 @@ target_pre_inferior (int from_tty) the inferior was attached to. */ current_inferior ()->attach_flag = 0; + current_inferior ()->highest_thread_num = 0; + agent_capability_invalidate (); } @@ -2233,13 +2258,24 @@ target_wait (ptid_t ptid, struct target_waitstatus *status, int options) return (current_target.to_wait) (¤t_target, ptid, status, options); } +/* See target.h. */ + +ptid_t +default_target_wait (struct target_ops *ops, + ptid_t ptid, struct target_waitstatus *status, + int options) +{ + status->kind = TARGET_WAITKIND_IGNORE; + return minus_one_ptid; +} + char * target_pid_to_str (ptid_t ptid) { 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); @@ -2293,6 +2329,14 @@ target_follow_fork (int follow_child, int detach_fork) follow_child, detach_fork); } +/* Target wrapper for follow exec hook. */ + +void +target_follow_exec (struct inferior *inf, char *execd_pathname) +{ + current_target.to_follow_exec (¤t_target, inf, execd_pathname); +} + static void default_mourn_inferior (struct target_ops *self) { @@ -2344,7 +2388,7 @@ simple_search_memory (struct target_ops *ops, 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); @@ -2372,8 +2416,8 @@ simple_search_memory (struct target_ops *ops, 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) { @@ -3030,7 +3074,7 @@ target_fileio_read_alloc_1 (struct inferior *inf, const char *filename, /* 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) { @@ -3061,7 +3105,7 @@ target_fileio_read_alloc_1 (struct inferior *inf, const char *filename, if (buf_alloc < buf_pos * 2) { buf_alloc *= 2; - buf = xrealloc (buf, buf_alloc); + buf = (gdb_byte *) xrealloc (buf, buf_alloc); } QUIT; @@ -3510,7 +3554,8 @@ target_verify_memory (const gdb_byte *data, CORE_ADDR memaddr, ULONGEST size) 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); @@ -3520,7 +3565,8 @@ target_insert_mask_watchpoint (CORE_ADDR addr, CORE_ADDR mask, int 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); @@ -3637,9 +3683,25 @@ target_delete_record (void) /* See target.h. */ int -target_record_is_replaying (void) +target_record_is_replaying (ptid_t ptid) { - return current_target.to_record_is_replaying (¤t_target); + return current_target.to_record_is_replaying (¤t_target, ptid); +} + +/* 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. */ @@ -3798,6 +3860,14 @@ target_async (int enable) 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;