diff options
author | Doug Evans <dje@google.com> | 2014-02-19 15:28:50 -0800 |
---|---|---|
committer | Doug Evans <dje@google.com> | 2014-02-19 15:30:38 -0800 |
commit | 649ebbcaef0f8e58146e62be0d3f22da5f82446c (patch) | |
tree | d0edcf3f841dc18f2f61d519d4e71d4ba4e2cc8a /gdb/gdbserver/inferiors.c | |
parent | b5ad007edc349b3ff44db422273a5efda5f04a15 (diff) | |
download | fsf-binutils-gdb-649ebbcaef0f8e58146e62be0d3f22da5f82446c.zip fsf-binutils-gdb-649ebbcaef0f8e58146e62be0d3f22da5f82446c.tar.gz fsf-binutils-gdb-649ebbcaef0f8e58146e62be0d3f22da5f82446c.tar.bz2 |
Replace code accessing list implementation details with API calls.
* dll.c (clear_dlls): Replace accessing list implemention details
with API function.
* gdbthread.h (get_first_thread): Declare.
* inferiors.c (for_each_inferior_with_data): New function.
(get_first_thread): New function.
(find_thread_ptid): Simplify.
(get_first_inferior): New function.
(clear_list): Delete.
(one_inferior_p): New function.
(clear_inferior_list): New function.
(clear_inferiors): Update.
* inferiors.h (for_each_inferior_with_data): Declare.
(clear_inferior_list): Declare.
(one_inferior_p): Declare.
(get_first_inferior): Declare.
* linux-low.c (linux_wait_for_event): Replace accessing list
implemention details with API function.
* server.c (target_running): Ditto.
(accumulate_file_name_length): New function.
(emit_dll_description): New function.
(handle_qxfer_libraries): Replace accessing list implemention
details with API function.
(handle_qxfer_threads_worker): New function.
(handle_qxfer_threads_proper): Replace accessing list implemention
details with API function.
(handle_query): Ditto.
(visit_actioned_threads_callback_ftype): New typedef.
(visit_actioned_threads_data): New struct.
(visit_actioned_threads): Rewrite to be find_inferior callback.
(resume): Call find_inferior.
(handle_status): Replace accessing list implemention
details with API function.
(process_serial_event): Replace accessing list implemention details
with API function.
* target.c (set_desired_inferior): Replace accessing list implemention
details with API function.
* tracepoint.c (same_process_p): New function.
(gdb_agent_about_to_close): Replace accessing list implemention
details with API function.
* win32-low.c (child_delete_thread): Replace accessing list
implemention details with API function.
(match_dll_by_basename): New function.
(dll_is_loaded_by_basename): New function.
(win32_ensure_ntdll_loaded): Replace accessing list implemention
details call to dll_is_loaded_by_basename.
Diffstat (limited to 'gdb/gdbserver/inferiors.c')
-rw-r--r-- | gdb/gdbserver/inferiors.c | 70 |
1 files changed, 56 insertions, 14 deletions
diff --git a/gdb/gdbserver/inferiors.c b/gdb/gdbserver/inferiors.c index e3d28ea..c709b36 100644 --- a/gdb/gdbserver/inferiors.c +++ b/gdb/gdbserver/inferiors.c @@ -59,6 +59,24 @@ for_each_inferior (struct inferior_list *list, } } +/* Invoke ACTION for each inferior in LIST, passing DATA to ACTION. */ + +void +for_each_inferior_with_data (struct inferior_list *list, + void (*action) (struct inferior_list_entry *, + void *), + void *data) +{ + struct inferior_list_entry *cur = list->head, *next; + + while (cur != NULL) + { + next = cur->next; + (*action) (cur, data); + cur = next; + } +} + void remove_inferior (struct inferior_list *list, struct inferior_list_entry *entry) @@ -111,20 +129,18 @@ thread_to_gdb_id (struct thread_info *thread) return thread->entry.id; } +/* Wrapper around get_first_inferior to return a struct thread_info *. */ + struct thread_info * -find_thread_ptid (ptid_t ptid) +get_first_thread (void) { - struct inferior_list_entry *inf = all_threads.head; - - while (inf != NULL) - { - struct thread_info *thread = get_thread (inf); - if (ptid_equal (thread->entry.id, ptid)) - return thread; - inf = inf->next; - } + return (struct thread_info *) get_first_inferior (&all_threads); +} - return NULL; +struct thread_info * +find_thread_ptid (ptid_t ptid) +{ + return (struct thread_info *) find_inferior_id (&all_threads, ptid); } ptid_t @@ -153,6 +169,18 @@ remove_thread (struct thread_info *thread) free_one_thread (&thread->entry); } +/* Return a pointer to the first inferior in LIST, or NULL if there isn't one. + This is for cases where the caller needs a thread, but doesn't care + which one. */ + +struct inferior_list_entry * +get_first_inferior (struct inferior_list *list) +{ + if (all_threads.head != NULL) + return all_threads.head; + return NULL; +} + /* Find the first inferior_list_entry E in LIST for which FUNC (E, ARG) returns non-zero. If no entry is found then return NULL. */ @@ -214,14 +242,28 @@ set_inferior_regcache_data (struct thread_info *inferior, void *data) inferior->regcache_data = data; } -#define clear_list(LIST) \ - do { (LIST)->head = (LIST)->tail = NULL; } while (0) +/* Return true if LIST has exactly one entry. */ + +int +one_inferior_p (struct inferior_list *list) +{ + return list->head != NULL && list->head == list->tail; +} + +/* Reset head,tail of LIST, assuming all entries have already been freed. */ + +void +clear_inferior_list (struct inferior_list *list) +{ + list->head = NULL; + list->tail = NULL; +} void clear_inferiors (void) { for_each_inferior (&all_threads, free_one_thread); - clear_list (&all_threads); + clear_inferior_list (&all_threads); clear_dlls (); |