From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 104461 invoked by alias); 4 Nov 2015 19:36:34 -0000 Mailing-List: contact archer-commits-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: Received: (qmail 104442 invoked by uid 440); 4 Nov 2015 19:36:34 -0000 Date: Wed, 04 Nov 2015 19:36:00 -0000 Message-ID: <20151104193634.104414.qmail@sourceware.org> From: scox@sourceware.org To: archer-commits@sourceware.org Subject: [SCM] scox/globalstate: Differentiate client_state members by "_" suffix X-Git-Refname: refs/heads/scox/globalstate X-Git-Reftype: branch X-Git-Oldrev: f5936a9aa6a56493123550de032fcd93f26e57c2 X-Git-Newrev: 0bee029c99922ca26020016079c299fe2b01df59 X-SW-Source: 2015-q4/txt/msg00001.txt.bz2 List-Id: The branch, scox/globalstate has been updated via 0bee029c99922ca26020016079c299fe2b01df59 (commit) from f5936a9aa6a56493123550de032fcd93f26e57c2 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit 0bee029c99922ca26020016079c299fe2b01df59 Author: Stan Cox Date: Wed Nov 4 14:34:56 2015 -0500 Differentiate client_state members by "_" suffix gdb/gdbserver/Changelog * server.h (client_state): Remove executable and all its references. Remove all extern dcls for items now in client_state. Add _ suffix for those items. * server.c (add_client_by_pid): Use general_thread not last_ptid. (add_client_by_exe): Remove. (have_multiple_clients): Use attach_count. (handle_qxfer_threads_worker): Attached client is multiple inferior agnostic. (handle_v_attach): Attach of non-stop multiple client should only ok. ----------------------------------------------------------------------- Summary of changes: gdb/gdbserver/ChangeLog | 13 ++ gdb/gdbserver/event-loop.c | 2 +- gdb/gdbserver/server.c | 160 ++++++++++-------------- gdb/gdbserver/server.h | 192 ++++++++++++----------------- gdb/testsuite/ChangeLog | 4 + gdb/testsuite/gdb.server/multi-client.exp | 98 +++++++++++++-- 6 files changed, 247 insertions(+), 222 deletions(-) First 500 lines of diff: diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index c8e33f7..3ac724f 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,3 +1,16 @@ +2015-11-04 Stan Cox + + * server.h (client_state): Remove executable and all its references. + Remove all extern dcls for items now in client_state. Add _ + suffix for those members. + + * server.c (add_client_by_pid): Use general_thread not last_ptid. + (add_client_by_exe): Remove. + (have_multiple_clients): Use attach_count. + (handle_qxfer_threads_worker): Attached client is multiple + inferior agnostic. + (handle_v_attach): Attach of non-stop multiple client should only ok. + 2015-10-06 Stan Cox * server.c (setup_multiplexing): Insure we always have a waitee. diff --git a/gdb/gdbserver/event-loop.c b/gdb/gdbserver/event-loop.c index 92287c2..1679464 100644 --- a/gdb/gdbserver/event-loop.c +++ b/gdb/gdbserver/event-loop.c @@ -428,7 +428,7 @@ handle_file_event (gdb_fildes_t event_file_desc) if (mask != 0) { /* Don't change client states if we have multiple clients */ - if (have_multiple_clients () || get_client_state()->executable == 0) + if (have_multiple_clients (file_ptr->fd) || ptid_equal (general_thread, null_ptid)) set_client_state (file_ptr->fd); if ((*file_ptr->proc) (file_ptr->error, file_ptr->client_data) < 0) diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c index 5e04a1e..cb552ec 100644 --- a/gdb/gdbserver/server.c +++ b/gdb/gdbserver/server.c @@ -109,7 +109,7 @@ set_client_state (gdb_fildes_t fd) * fd = F add client state for fd F */ - client_state *csidx; + client_state *csidx, *cs; /* add/return initial client state */ if (fd == -1) @@ -142,36 +142,26 @@ set_client_state (gdb_fildes_t fd) } /* add client state S for fd F */ - if (client_states.current_fd == -1 && client_states.current_cs->executable != NULL) - { - client_states.current_cs = XCNEW (client_state); - *client_states.current_cs = *client_states.first; - } - else - { - client_state *cs; - client_states.current_cs = XCNEW (client_state); - *client_states.current_cs = *csidx; - client_states.current_cs->ss = XCNEW (server_state); - *client_states.current_cs->ss = *csidx->ss; - cs = client_states.current_cs; - cs->packet_type = other_packet; - cs->executable = NULL; - cs->client_breakpoints = NULL; - in_buffer = NULL; - wrapper_argv = NULL; - get_client_state()->ss->attach_count = 0; - cont_thread = null_ptid; - general_thread = null_ptid; - signal_pid = 0; - last_ptid = null_ptid; - last_status.kind = TARGET_WAITKIND_IGNORE; - current_thread = NULL; - all_processes.head = NULL; - all_processes.tail = NULL; - all_threads.head = NULL; - all_threads.tail = NULL; - } + client_states.current_cs = XCNEW (client_state); + *client_states.current_cs = *csidx; + client_states.current_cs->ss = XCNEW (server_state); + *client_states.current_cs->ss = *csidx->ss; + cs = client_states.current_cs; + cs->packet_type = other_packet; + cs->client_breakpoints = NULL; + in_buffer = NULL; + wrapper_argv = NULL; + get_client_state()->ss->attach_count_ = 0; + cont_thread = null_ptid; + general_thread = null_ptid; + signal_pid = 0; + last_ptid = null_ptid; + last_status.kind = TARGET_WAITKIND_IGNORE; + current_thread = NULL; + all_processes.head = NULL; + all_processes.tail = NULL; + all_threads.head = NULL; + all_threads.tail = NULL; client_states.current_cs->file_desc = fd; own_buffer = xmalloc (PBUFSIZ + 1); client_states.current_fd = fd; @@ -252,16 +242,13 @@ static void free_client_state (client_state *cs) client_state *csi; for (csi = client_states.first; csi != NULL; csi = csi->next) { - if (csi->executable && csi != cs && csi->ss == cs->ss) + if (ptid_equal (csi->ss->general_thread_, null_ptid) && csi != cs && csi->ss == cs->ss) break; } delete_client_breakpoint (0); if (csi == NULL) - { - XDELETE (cs->ss); - if (get_client_state()->executable) - xfree (get_client_state()->executable); - } + XDELETE (cs->ss); + if (in_buffer) xfree (in_buffer); xfree (own_buffer); @@ -280,19 +267,22 @@ dump_client_state (const char *comment) if (! debug_threads) return; - debug_printf ("Dumping client state from %s\n", comment); - + debug_printf ("***Begin Dumping client state from %s\n", comment); for (cs = client_states.first; cs != NULL; cs = cs->next) { client_states.current_cs = cs; - debug_printf ("%s %d cont_thr %#lx gen thr %#lx attached? %d\n", - cs->executable, cs->file_desc, (long unsigned)cont_thread.pid, - (long unsigned)general_thread.pid, cs->ss->attach_count); - debug_printf ("%d all procs %#lx all thrs %#lx curr thr %#lx %s/%s/%s\n", - (int)last_ptid.pid, (unsigned long)all_processes.head, - (unsigned long)all_threads.head, (unsigned long)current_thread, - packet_types_str[cs->packet_type], packet_types_str[cs->last_packet_type], pending_types_str[cs->pending]); - } + debug_printf ("%d %#lx(%d)/%#lx/%#lx #=%d %s %s %s\n", + cs->file_desc, + (long unsigned)general_thread.pid, + (int)general_thread.pid, + (long unsigned)cont_thread.pid, + (long unsigned)last_ptid.pid, + cs->ss->attach_count_, + packet_types_str[cs->packet_type], + packet_types_str[cs->last_packet_type], + pending_types_str[cs->pending]); + } + debug_printf ("***End Dumping client state from %s\n", comment); client_states.current_cs = save_cs; } @@ -307,15 +297,12 @@ add_client_by_pid (int pid) for (matched_cs = client_states.first; matched_cs != NULL; matched_cs = matched_cs->next) { - if (cs != matched_cs && matched_cs->ss->last_ptid_.pid == pid) + if (cs != matched_cs && matched_cs->ss->general_thread_.pid == pid) { - matched_cs->ss->attach_count += 1; - xfree (cs->executable); - cs->executable = matched_cs->executable; XDELETE (cs->ss); /* reuse the matched server state */ cs->ss = matched_cs->ss; - cs->ss->attach_count += 1; + cs->ss->attach_count_ += 1; return cs; } } @@ -323,30 +310,6 @@ add_client_by_pid (int pid) } -/* Add another client for EXECUTABLE to the 1 server -> N client list. */ - -client_state * -add_client_by_exe (char *executable) -{ - client_state *csi; - char *new_executable; - client_state *cs = get_client_state (); - - dump_client_state(__FUNCTION__); - - for (csi = client_states.first; csi != NULL; csi = csi->next) - { - if (csi->executable && strcmp (csi->executable, executable) == 0 && csi != cs) - break; - } - - new_executable = xmalloc (strlen (executable) + 1); - strcpy (new_executable, executable); - cs->executable = new_executable; - return NULL; -} - - /* Return the first active client state */ gdb_fildes_t @@ -355,10 +318,8 @@ get_first_client_fd () client_state *cs; for (cs = client_states.first; cs != NULL; cs = cs->next) { - if (cs->file_desc > 0 && cs->executable != NULL) - { - return cs->file_desc; - } + if (cs->file_desc > 0 && cs->attached_to_client == 1) + return cs->file_desc; } return -1; } @@ -367,16 +328,15 @@ get_first_client_fd () /* Is there more than one active client? */ int -have_multiple_clients () +have_multiple_clients (gdb_fildes_t fd) { client_state *cs; - int n_client_states= 0; + dump_client_state(__FUNCTION__); + for (cs = client_states.first; cs != NULL; cs = cs->next) - { - if (cs->file_desc > 0 && cs->executable != NULL) - n_client_states += 1; - } - return n_client_states > 1; + if (cs->file_desc == fd) + return (cs->ss->attach_count_ > 0); + return 0; } @@ -408,7 +368,7 @@ delete_client_state (gdb_fildes_t fd) { if (cs->ss == ss) { - cs->ss->attach_count -= 1; + cs->ss->attach_count_ -= 1; set_client_state (cs->file_desc); } } @@ -500,6 +460,8 @@ setup_multiplexing (client_state *cs, char *ch) dump_client_state (__FUNCTION__); + cs->attached_to_client = 1; + for (csidx = client_states.first; csidx != NULL; csidx = csidx->next) { /* another client is attached to the cs process */ @@ -777,8 +739,6 @@ start_inferior (char **argv) debug_flush (); } - add_client_by_exe (new_argv[0]); - #ifdef SIGTTOU signal (SIGTTOU, SIG_DFL); signal (SIGTTIN, SIG_DFL); @@ -2034,6 +1994,11 @@ handle_qxfer_threads_worker (struct inferior_list_entry *inf, void *arg) int core = target_core_of_thread (ptid); char core_s[21]; + // TODO an attached client does not know about multiple inferiors + if (ptid_get_pid (inf->id) != ptid_get_pid (general_thread) + && attach_count > 0) + return; + write_ptid (ptid_s, ptid); if (core != -1) @@ -2952,7 +2917,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p) return; } - strcpy (own_buf, process->attached || get_client_state()->ss->attach_count ? "1" : "0"); + strcpy (own_buf, process->attached || get_client_state()->ss->attach_count_ ? "1" : "0"); return; } @@ -3238,8 +3203,13 @@ handle_v_attach (char *own_buf) pid = strtol (own_buf + 8, NULL, 16); if (add_client_by_pid (pid)) { - strcpy (own_buf, "?"); - handle_status (own_buf); + if (! non_stop) + { + strcpy (own_buf, "?"); + handle_status (own_buf); + } + else + write_ok (own_buf); return 1; } else if (pid != 0 && attach_inferior (pid) == 0) @@ -4441,7 +4411,7 @@ process_serial_event (void) fprintf (stderr, "Detaching from process %d\n", pid); stop_tracing (); - if (cs->ss->attach_count > 0) + if (cs->ss->attach_count_ > 0) write_ok (own_buffer); else if (detach_inferior (pid) != 0) write_enn (own_buffer); @@ -4452,7 +4422,7 @@ process_serial_event (void) if (extended_protocol) { - if (cs->ss->attach_count == 0) + if (cs->ss->attach_count_ == 0) { /* Treat this like a normal program exit. */ last_status.kind = TARGET_WAITKIND_EXITED; diff --git a/gdb/gdbserver/server.h b/gdb/gdbserver/server.h index 48b18ab..a17ecc5 100644 --- a/gdb/gdbserver/server.h +++ b/gdb/gdbserver/server.h @@ -67,41 +67,11 @@ int vsnprintf(char *str, size_t size, const char *format, va_list ap); void initialize_low (); -/* Public variables in server.c */ - -extern ptid_t cont_thread; -extern ptid_t general_thread; - -extern int server_waiting; -extern int pass_signals[]; -extern int program_signals[]; -extern int program_signals_p; - extern int disable_packet_vCont; extern int disable_packet_Tthread; extern int disable_packet_qC; extern int disable_packet_qfThreadInfo; -extern int run_once; -extern int multi_process; -extern int report_fork_events; -extern int report_vfork_events; -extern int non_stop; -extern int extended_protocol; - -/* True if the "swbreak+" feature is active. In that case, GDB wants - us to report whether a trap is explained by a software breakpoint - and for the server to handle PC adjustment if necessary on this - target. Only enabled if the target supports it. */ -extern int swbreak_feature; - -/* True if the "hwbreak+" feature is active. In that case, GDB wants - us to report whether a trap is explained by a hardware breakpoint. - Only enabled if the target supports it. */ -extern int hwbreak_feature; - -extern int disable_randomization; - #if USE_WIN32API #include typedef SOCKET gdb_fildes_t; @@ -136,11 +106,11 @@ extern void discard_queued_stop_replies (ptid_t ptid); /* Description of the remote protocol state for the currently connected target. This is per-target state, and independent of the - selected architecture. The unions allow bypassing the access macros.\ */ + selected architecture. */ struct server_state { - int attach_count; + int attach_count_; /* From server.c */ /* The thread set with an `Hc' packet. `Hc' is deprecated in favor of `vCont'. Note the multi-process extensions made `vCont' a @@ -148,40 +118,31 @@ struct server_state CONT_THREAD can be null_ptid for no `Hc' thread, minus_one_ptid for resuming all threads of the process (again, `Hc' isn't used for multi-process), or a specific thread ptid_t. */ - ptid_t cont_thread; + ptid_t cont_thread_; /* The thread set with an `Hg' packet. */ - ptid_t general_thread; + ptid_t general_thread_; /* The PID of the originally created or attached inferior. Used to send signals to the process when GDB sends us an asynchronous interrupt (user hitting Control-C in the client), and to wait for the child to exit when no longer debugging it. */ - unsigned long signal_pid; + unsigned long signal_pid_; /* Last status reported to GDB. */ - union { - struct target_waitstatus last_status; - struct target_waitstatus last_status_; - }; - union { - ptid_t last_ptid; - ptid_t last_ptid_; - }; - unsigned char *mem_buf; + struct target_waitstatus last_status_; + ptid_t last_ptid_; + unsigned char *mem_buf_; /* from remote-utils.c */ /* Internal buffer used by readchar. These are global to readchar because reschedule_remote needs to be able to tell whether the buffer is empty. */ - unsigned char readchar_buf[BUFSIZ]; - int readchar_bufcnt; - unsigned char *readchar_bufp; + unsigned char readchar_buf_[BUFSIZ]; + int readchar_bufcnt_; + unsigned char *readchar_bufp_; /* from inferiors.c */ - struct inferior_list all_processes; - struct inferior_list all_threads; - union { - struct thread_info *current_thread; - struct thread_info *current_thread_; - }; + struct inferior_list all_processes_; + struct inferior_list all_threads_; + struct thread_info *current_thread_; }; typedef struct server_state server_state; @@ -198,46 +159,48 @@ typedef enum packet_types packet_types; struct client_state { gdb_fildes_t file_desc; - char *executable; + int attached_to_client; int packet_type; int last_packet_type; int pending; /* From server.c */ - int server_waiting; + int server_waiting_; - int extended_protocol; - int response_needed; - union { - int exit_requested; - int exit_requested_; - }; + int extended_protocol_; + int response_needed_; + int exit_requested_; /* --once: Exit after the first connection has closed. */ - int run_once; - - int multi_process; - int report_fork_events; - int report_vfork_events; - int non_stop; - int swbreak_feature; - int hwbreak_feature; + int run_once_; + + int multi_process_; + int report_fork_events_; + int report_vfork_events_; + int non_stop_; + /* True if the "swbreak+" feature is active. In that case, GDB wants + us to report whether a trap is explained by a software breakpoint + and for the server to handle PC adjustment if necessary on this + target. Only enabled if the target supports it. */ + int swbreak_feature_; + /* True if the "hwbreak+" feature is active. In that case, GDB wants + us to report whether a trap is explained by a hardware breakpoint. + Only enabled if the target supports it. */ + int hwbreak_feature_; /* Whether we should attempt to disable the operating system's address space randomization feature before starting an inferior. */ - int disable_randomization; - - char **program_argv, **wrapper_argv; - int packet_length; - - int pass_signals[GDB_SIGNAL_LAST]; - int program_signals[GDB_SIGNAL_LAST]; - int program_signals_p; - char *in_buffer; - union { - char *own_buffer; - char *own_buffer_; hooks/post-receive -- Repository for Project Archer.