diff options
author | Simon Marchi <simon.marchi@polymtl.ca> | 2017-10-14 09:10:42 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@ericsson.com> | 2017-10-14 09:10:42 -0400 |
commit | 9179355e655d78cf44ffdfb432e134eabceaebab (patch) | |
tree | 6fd72bc62e2cb3d02cc8d343dfdb21b8de15e848 /gdb/gdbserver/inferiors.c | |
parent | c9cb8905b489d094c6c42e103d4bc6e231e00cf0 (diff) | |
download | fsf-binutils-gdb-9179355e655d78cf44ffdfb432e134eabceaebab.zip fsf-binutils-gdb-9179355e655d78cf44ffdfb432e134eabceaebab.tar.gz fsf-binutils-gdb-9179355e655d78cf44ffdfb432e134eabceaebab.tar.bz2 |
gdbserver: Use std::list for all_processes
Remove the usage of inferior_list for the all_processes list in
gdbserver, replace it with an std::list. The entry field in process_info
is removed, and replaced by a simple pid field.
The pid_of macro, used for both processes and threads, is replaced with
separate functions. For completeness, I changed ptid_of and lwpid_of to
functions as well.
gdb/gdbserver/ChangeLog:
* gdbthread.h (ptid_of, pid_of, lwpid_of): New functions.
* inferiors.h: Include <list>.
(struct process_info) <entry>: Remove field.
<pid>: New field.
(pid_of): Change macro to function.
(ptid_of, lwpid_of): Remove macro.
(all_processes): Change type to std::list<process_info *>.
(ALL_PROCESSES): Remove macro.
(for_each_process, find_process): New function.
* inferiors.c (all_processes): Change type to
std::list<process_info *>.
(find_thread_process): Adjust.
(add_process): Likewise.
(remove_process): Likewise.
(find_process_pid): Likewise.
(get_first_process): Likewise.
(started_inferior_callback): Remove.
(have_started_inferiors_p): Adjust.
(attached_inferior_callback): Remove.
(have_attached_inferiors_p): Adjust.
* linux-low.c (check_zombie_leaders): Likewise.
* linux-x86-low.c (x86_arch_setup_process_callback): Remove.
(x86_linux_update_xmltarget): Adjust.
* server.c (handle_query): Likewise.
(gdb_reattached_process): Remove.
(handle_status): Adjust.
(kill_inferior_callback): Likewise.
(detach_or_kill_inferior): Remove.
(print_started_pid): Likewise.
(print_attached_pid): Likewise.
(detach_or_kill_for_exit): Update.
(process_serial_event): Likewise.
* linux-arm-low.c (arm_new_fork): Likewise.
Diffstat (limited to 'gdb/gdbserver/inferiors.c')
-rw-r--r-- | gdb/gdbserver/inferiors.c | 57 |
1 files changed, 21 insertions, 36 deletions
diff --git a/gdb/gdbserver/inferiors.c b/gdb/gdbserver/inferiors.c index 154c167..13ee8c9 100644 --- a/gdb/gdbserver/inferiors.c +++ b/gdb/gdbserver/inferiors.c @@ -22,7 +22,7 @@ #include "gdbthread.h" #include "dll.h" -struct inferior_list all_processes; +std::list<process_info *> all_processes; struct inferior_list all_threads; struct thread_info *current_thread; @@ -144,7 +144,7 @@ find_thread_ptid (ptid_t ptid) static struct thread_info * find_thread_process (const struct process_info *const process) { - return find_any_thread_of_pid (process->entry.id.pid ()); + return find_any_thread_of_pid (process->pid); } /* Helper for find_any_thread_of_pid. Returns true if a thread @@ -336,10 +336,10 @@ add_process (int pid, int attached) { struct process_info *process = XCNEW (struct process_info); - process->entry.id = pid_to_ptid (pid); + process->pid = pid; process->attached = attached; - add_inferior_to_list (&all_processes, &process->entry); + all_processes.push_back (process); return process; } @@ -354,35 +354,28 @@ remove_process (struct process_info *process) clear_symbol_cache (&process->symbol_cache); free_all_breakpoints (process); gdb_assert (find_thread_process (process) == NULL); - remove_inferior (&all_processes, &process->entry); + all_processes.remove (process); VEC_free (int, process->syscalls_to_catch); free (process); } -struct process_info * +process_info * find_process_pid (int pid) { - return (struct process_info *) - find_inferior_id (&all_processes, pid_to_ptid (pid)); + return find_process ([&] (process_info *process) { + return process->pid == pid; + }); } -/* Wrapper around get_first_inferior to return a struct process_info *. */ +/* Get the first process in the process list, or NULL if the list is empty. */ -struct process_info * +process_info * get_first_process (void) { - return (struct process_info *) get_first_inferior (&all_processes); -} - -/* Return non-zero if INF, a struct process_info, was started by us, - i.e. not attached to. */ - -static int -started_inferior_callback (struct inferior_list_entry *entry, void *args) -{ - struct process_info *process = (struct process_info *) entry; - - return ! process->attached; + if (!all_processes.empty ()) + return all_processes.front (); + else + return NULL; } /* Return non-zero if there are any inferiors that we have created @@ -391,18 +384,9 @@ started_inferior_callback (struct inferior_list_entry *entry, void *args) int have_started_inferiors_p (void) { - return (find_inferior (&all_processes, started_inferior_callback, NULL) - != NULL); -} - -/* Return non-zero if INF, a struct process_info, was attached to. */ - -static int -attached_inferior_callback (struct inferior_list_entry *entry, void *args) -{ - struct process_info *process = (struct process_info *) entry; - - return process->attached; + return find_process ([] (process_info *process) { + return !process->attached; + }) != NULL; } /* Return non-zero if there are any inferiors that we have attached to. */ @@ -410,8 +394,9 @@ attached_inferior_callback (struct inferior_list_entry *entry, void *args) int have_attached_inferiors_p (void) { - return (find_inferior (&all_processes, attached_inferior_callback, NULL) - != NULL); + return find_process ([] (process_info *process) { + return process->attached; + }) != NULL; } struct process_info * |