From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31187 invoked by alias); 8 Nov 2017 02:32:50 -0000 Mailing-List: contact archer-commits-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: Received: (qmail 30244 invoked by uid 440); 8 Nov 2017 02:32:49 -0000 Date: Wed, 08 Nov 2017 02:32:00 -0000 Message-ID: <20171108023249.30030.qmail@sourceware.org> From: scox@sourceware.org To: archer-commits@sourceware.org Subject: [SCM] scox/gdbserver-multi-client: Consolidate gdbserver global variables X-Git-Refname: refs/heads/scox/gdbserver-multi-client X-Git-Reftype: branch X-Git-Oldrev: 016f5a3777ab6ce33616917be7795a7501f29dd7 X-Git-Newrev: 37e2b1e4e11410819a8e862c6ab3c0fe27298f57 X-SW-Source: 2017-q4/txt/msg00002.txt.bz2 List-Id: The branch, scox/gdbserver-multi-client has been updated via 37e2b1e4e11410819a8e862c6ab3c0fe27298f57 (commit) from 016f5a3777ab6ce33616917be7795a7501f29dd7 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit 37e2b1e4e11410819a8e862c6ab3c0fe27298f57 Author: Stan Cox Date: Tue Nov 7 21:30:04 2017 -0500 Consolidate gdbserver global variables * server.h (client_breakpoints): Use a set. Change all users. (multi_client_states.cs): Use a map. Change all users. * mem-break.c (has_client_breakpoint_at): Move from here.. * server.c (multi_client_states::has_client_breakpoint_at): ..to here (client_state::client_state): New constructor. (multi_client_states::set_client_state): Use it. Use client states map. (multi_client_states::add_client_breakpoint): Use client breaks set. ----------------------------------------------------------------------- Summary of changes: gdb/gdbserver/ChangeLog | 12 ++ gdb/gdbserver/event-loop.c | 3 + gdb/gdbserver/fork-child.c | 2 +- gdb/gdbserver/gdbthread.h | 4 +- gdb/gdbserver/hostio.c | 2 - gdb/gdbserver/inferiors.c | 6 +- gdb/gdbserver/inferiors.h | 4 - gdb/gdbserver/linux-low.c | 40 ++-- gdb/gdbserver/linux-low.h | 2 +- gdb/gdbserver/remote-utils.c | 124 ++++++------ gdb/gdbserver/remote-utils.h | 5 +- gdb/gdbserver/server.c | 439 +++++++++++++++++++++++++----------------- gdb/gdbserver/server.h | 235 +++++++++++++++++++---- gdb/nat/linux-personality.h | 2 +- 14 files changed, 566 insertions(+), 314 deletions(-) First 500 lines of diff: diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index eaf6a68..5a84e82 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -2,6 +2,18 @@ * config.in, configure: Regenerate. +2017-11-03 Stan Cox + + * server.h (client_breakpoints): Use a set. Change all users. + (multi_client_states.cs): Use a map. Change all users. + * mem-break.c (has_client_breakpoint_at): Move from here.. + * server.c (multi_client_states::has_client_breakpoint_at): ..to here + (client_state::client_state): New constructor. + (multi_client_states::set_client_state): Use it. Use client + states map. + (multi_client_states::add_client_breakpoint): Use client breaks + set. + 2017-10-27 Simon Marchi * target.c (struct thread_search): Remove. diff --git a/gdb/gdbserver/event-loop.c b/gdb/gdbserver/event-loop.c index b391e2e..b9bd166 100644 --- a/gdb/gdbserver/event-loop.c +++ b/gdb/gdbserver/event-loop.c @@ -385,6 +385,9 @@ delete_file_handler (gdb_fildes_t fd) ; prev_ptr->next_file = file_ptr->next_file; } + + struct multi_client_states *client_states = get_client_states(); + client_states->delete_client_state (fd); free (file_ptr); } diff --git a/gdb/gdbserver/fork-child.c b/gdb/gdbserver/fork-child.c index 1002620..aaf01e4 100644 --- a/gdb/gdbserver/fork-child.c +++ b/gdb/gdbserver/fork-child.c @@ -108,7 +108,7 @@ post_fork_inferior (int pid, const char *program) startup_inferior (pid, START_INFERIOR_TRAPS_EXPECTED, &last_status, &last_ptid); current_thread->last_resume_kind = resume_stop; - current_thread->last_status = last_status; + current_thread->last_waitstatus = last_status; signal_pid = pid; target_post_create_inferior (); fprintf (stderr, "Process %s created; pid = %d\n", program, pid); diff --git a/gdb/gdbserver/gdbthread.h b/gdb/gdbserver/gdbthread.h index b82d5b0..4ff2a69 100644 --- a/gdb/gdbserver/gdbthread.h +++ b/gdb/gdbserver/gdbthread.h @@ -39,7 +39,7 @@ struct thread_info enum resume_kind last_resume_kind; /* The last wait status reported for this thread. */ - struct target_waitstatus last_status; + struct target_waitstatus last_waitstatus; /* True if LAST_STATUS hasn't been reported to GDB yet. */ int status_pending_p; @@ -73,8 +73,6 @@ struct thread_info struct btrace_target_info *btrace; }; -extern std::list all_threads; - void remove_thread (struct thread_info *thread); struct thread_info *add_thread (ptid_t ptid, void *target_data); diff --git a/gdb/gdbserver/hostio.c b/gdb/gdbserver/hostio.c index cd40e28..6638623 100644 --- a/gdb/gdbserver/hostio.c +++ b/gdb/gdbserver/hostio.c @@ -29,8 +29,6 @@ #include #include "fileio.h" -extern int remote_debug; - struct fd_list { int fd; diff --git a/gdb/gdbserver/inferiors.c b/gdb/gdbserver/inferiors.c index a0ece4d..1518ac0 100644 --- a/gdb/gdbserver/inferiors.c +++ b/gdb/gdbserver/inferiors.c @@ -22,10 +22,6 @@ #include "gdbthread.h" #include "dll.h" -std::list all_processes; -std::list all_threads; - -struct thread_info *current_thread; /* The current working directory used to start the inferior. */ static const char *current_inferior_cwd = NULL; @@ -94,7 +90,7 @@ add_thread (ptid_t thread_id, void *target_data) new_thread->id = thread_id; new_thread->last_resume_kind = resume_continue; - new_thread->last_status.kind = TARGET_WAITKIND_IGNORE; + new_thread->last_waitstatus.kind = TARGET_WAITKIND_IGNORE; all_threads.push_back (new_thread); diff --git a/gdb/gdbserver/inferiors.h b/gdb/gdbserver/inferiors.h index fb0e2fd..6a64df7 100644 --- a/gdb/gdbserver/inferiors.h +++ b/gdb/gdbserver/inferiors.h @@ -81,8 +81,6 @@ pid_of (const process_info *proc) struct process_info *current_process (void); struct process_info *get_thread_process (const struct thread_info *); -extern std::list all_processes; - /* Invoke FUNC for each process. */ template @@ -123,8 +121,6 @@ find_process (Func func) return NULL; } -extern struct thread_info *current_thread; - /* Return the first process in the processes list. */ struct process_info *get_first_process (void); diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index b367e53..d068cc6 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -545,7 +545,7 @@ handle_extended_wait (struct lwp_info **orig_event_lwp, int wstat) child_lwp->status_pending_p = 0; child_thr = get_lwp_thread (child_lwp); child_thr->last_resume_kind = resume_stop; - child_thr->last_status.kind = TARGET_WAITKIND_STOPPED; + child_thr->last_waitstatus.kind = TARGET_WAITKIND_STOPPED; /* If we're suspending all threads, leave this one suspended too. If the fork/clone parent is stepping over a breakpoint, @@ -723,7 +723,7 @@ handle_extended_wait (struct lwp_info **orig_event_lwp, int wstat) event_lwp->status_pending_p = 1; event_lwp->status_pending = wstat; event_thr->last_resume_kind = resume_continue; - event_thr->last_status.kind = TARGET_WAITKIND_IGNORE; + event_thr->last_waitstatus.kind = TARGET_WAITKIND_IGNORE; /* Update syscall state in the new lwp, effectively mid-syscall too. */ event_lwp->syscall_state = TARGET_WAITKIND_SYSCALL_ENTRY; @@ -994,14 +994,14 @@ linux_ptrace_fun () static int linux_create_inferior (const char *program, - const std::vector &program_args) + const std::vector &p_program_args) { struct lwp_info *new_lwp; int pid; ptid_t ptid; struct cleanup *restore_personality = maybe_disable_address_space_randomization (disable_randomization); - std::string str_program_args = stringify_argv (program_args); + std::string str_program_args = stringify_argv (p_program_args); pid = fork_inferior (program, str_program_args.c_str (), @@ -1441,13 +1441,13 @@ get_detach_signal (struct thread_info *thread) /* If the thread had been suspended by gdbserver, and it stopped cleanly, then it'll have stopped with SIGSTOP. But we don't want to deliver that SIGSTOP. */ - if (thread->last_status.kind != TARGET_WAITKIND_STOPPED - || thread->last_status.value.sig == GDB_SIGNAL_0) + if (thread->last_waitstatus.kind != TARGET_WAITKIND_STOPPED + || thread->last_waitstatus.value.sig == GDB_SIGNAL_0) return 0; /* Otherwise, we may need to deliver the signal we intercepted. */ - status = lp->last_status; + status = lp->last_waitstatus; } if (!WIFSTOPPED (status)) @@ -1741,7 +1741,7 @@ thread_still_has_status_pending_p (struct thread_info *thread) CORE_ADDR pc; int discard = 0; - gdb_assert (lp->last_status != 0); + gdb_assert (lp->last_waitstatus != 0); pc = get_pc (lp); @@ -1803,7 +1803,7 @@ lwp_resumed (struct lwp_info *lwp) corresponding stop to gdb yet? If so, the thread is still resumed/running from gdb's perspective. */ if (thread->last_resume_kind == resume_stop - && thread->last_status.kind == TARGET_WAITKIND_IGNORE) + && thread->last_waitstatus.kind == TARGET_WAITKIND_IGNORE) return 1; return 0; @@ -2478,7 +2478,7 @@ linux_low_filter_event (int lwpid, int wstat) child->stopped = 1; - child->last_status = wstat; + child->last_waitstatus = wstat; /* Check if the thread has exited. */ if ((WIFEXITED (wstat) || WIFSIGNALED (wstat))) @@ -2657,7 +2657,7 @@ resume_stopped_resumed_lwps (thread_info *thread) if (lp->stopped && !lp->suspended && !lp->status_pending_p - && thread->last_status.kind == TARGET_WAITKIND_IGNORE) + && thread->last_waitstatus.kind == TARGET_WAITKIND_IGNORE) { int step = 0; @@ -2899,7 +2899,7 @@ count_events_callback (thread_info *thread, void *data) gdb_assert (count != NULL); /* Count only resumed LWPs that have an event pending. */ - if (thread->last_status.kind == TARGET_WAITKIND_IGNORE + if (thread->last_waitstatus.kind == TARGET_WAITKIND_IGNORE && lp->status_pending_p) (*count)++; @@ -2913,7 +2913,7 @@ select_singlestep_lwp_callback (thread_info *thread, void *data) { struct lwp_info *lp = get_thread_lwp (thread); - if (thread->last_status.kind == TARGET_WAITKIND_IGNORE + if (thread->last_waitstatus.kind == TARGET_WAITKIND_IGNORE && thread->last_resume_kind == resume_step && lp->status_pending_p) return 1; @@ -2932,7 +2932,7 @@ select_event_lwp_callback (thread_info *thread, void *data) gdb_assert (selector != NULL); /* Select only resumed LWPs that have an event pending. */ - if (thread->last_status.kind == TARGET_WAITKIND_IGNORE + if (thread->last_waitstatus.kind == TARGET_WAITKIND_IGNORE && lp->status_pending_p) if ((*selector)-- == 0) return 1; @@ -4661,7 +4661,7 @@ linux_set_resume_request (thread_info *thread, void *arg) { if (debug_threads) debug_printf ("already %s LWP %ld at GDB's request\n", - (thread->last_status.kind + (thread->last_waitstatus.kind == TARGET_WAITKIND_STOPPED) ? "stopped" : "stopping", @@ -5101,7 +5101,7 @@ linux_resume_one_thread (thread_info *thread, void *arg) /* For stop requests, we're done. */ lwp->resume = NULL; - thread->last_status.kind = TARGET_WAITKIND_IGNORE; + thread->last_waitstatus.kind = TARGET_WAITKIND_IGNORE; return 0; } @@ -5124,8 +5124,8 @@ linux_resume_one_thread (thread_info *thread, void *arg) /* If this is the same signal we were previously stopped by, make sure to queue its siginfo. */ - if (WIFSTOPPED (lwp->last_status) - && WSTOPSIG (lwp->last_status) == lwp->resume->sig + if (WIFSTOPPED (lwp->last_waitstatus) + && WSTOPSIG (lwp->last_waitstatus) == lwp->resume->sig && ptrace (PTRACE_GETSIGINFO, lwpid_of (thread), (PTRACE_TYPE_ARG3) 0, &info) == 0) info_p = &info; @@ -5148,7 +5148,7 @@ linux_resume_one_thread (thread_info *thread, void *arg) debug_printf ("leaving LWP %ld stopped\n", lwpid_of (thread)); } - thread->last_status.kind = TARGET_WAITKIND_IGNORE; + thread->last_waitstatus.kind = TARGET_WAITKIND_IGNORE; lwp->resume = NULL; return 0; } @@ -5251,7 +5251,7 @@ proceed_one_lwp (thread_info *thread, void *except) } if (thread->last_resume_kind == resume_stop - && thread->last_status.kind != TARGET_WAITKIND_IGNORE) + && thread->last_waitstatus.kind != TARGET_WAITKIND_IGNORE) { if (debug_threads) debug_printf (" client wants LWP to remain %ld stopped\n", diff --git a/gdb/gdbserver/linux-low.h b/gdb/gdbserver/linux-low.h index eda452f..f2381f3 100644 --- a/gdb/gdbserver/linux-low.h +++ b/gdb/gdbserver/linux-low.h @@ -302,7 +302,7 @@ struct lwp_info enum target_waitkind syscall_state; /* When stopped is set, the last wait status recorded for this lwp. */ - int last_status; + int last_waitstatus; /* If WAITSTATUS->KIND != TARGET_WAITKIND_IGNORE, the waitstatus for this LWP's last event, to pass to GDB without any further diff --git a/gdb/gdbserver/remote-utils.c b/gdb/gdbserver/remote-utils.c index 54f27f4..0b060f3 100644 --- a/gdb/gdbserver/remote-utils.c +++ b/gdb/gdbserver/remote-utils.c @@ -103,7 +103,6 @@ struct sym_cache struct sym_cache *next; }; -int remote_debug = 0; struct ui_file *gdb_stdlog; static int remote_is_stdio = 0; @@ -115,17 +114,19 @@ static gdb_fildes_t listen_desc = INVALID_DESCRIPTOR; extern int using_threads; extern int debug_threads; -/* If true, then GDB has requested noack mode. */ -int noack_mode = 0; -/* If true, then we tell GDB to use noack mode by default. */ -int transport_is_reliable = 0; - #ifdef USE_WIN32API # define read(fd, buf, len) recv (fd, (char *) buf, len, 0) # define write(fd, buf, len) send (fd, (char *) buf, len, 0) #endif int +get_remote_desc (void) +{ + return remote_desc; +} + + +int gdb_connected (void) { return remote_desc != INVALID_DESCRIPTOR; @@ -167,6 +168,9 @@ handle_accept_event (int err, gdb_client_data client_data) if (remote_desc == -1) perror_with_name ("Accept failed"); + struct multi_client_states *client_states = get_client_states(); + client_states->set_client_state (remote_desc); + /* Enable TCP keep alive process. */ tmp = 1; setsockopt (remote_desc, SOL_SOCKET, SO_KEEPALIVE, @@ -841,14 +845,6 @@ initialize_async_io (void) #endif } -/* Internal buffer used by readchar. - These are global to readchar because reschedule_remote needs to be - able to tell whether the buffer is empty. */ - -static unsigned char readchar_buf[BUFSIZ]; -static int readchar_bufcnt = 0; -static unsigned char *readchar_bufp; - /* Returns next char from remote GDB. -1 if error. */ static int @@ -1459,14 +1455,14 @@ look_up_one_symbol (const char *name, CORE_ADDR *addrp, int may_ask_gdb) return 0; /* Send the request. */ - strcpy (own_buf, "qSymbol:"); - bin2hex ((const gdb_byte *) name, own_buf + strlen ("qSymbol:"), + strcpy (own_buffer, "qSymbol:"); + bin2hex ((const gdb_byte *) name, own_buffer + strlen ("qSymbol:"), strlen (name)); - if (putpkt (own_buf) < 0) + if (putpkt (own_buffer) < 0) return -1; /* FIXME: Eventually add buffer overflow checking (to getpkt?) */ - len = getpkt (own_buf); + len = getpkt (own_buffer); if (len < 0) return -1; @@ -1477,45 +1473,45 @@ look_up_one_symbol (const char *name, CORE_ADDR *addrp, int may_ask_gdb) while it figures out the address of the symbol. */ while (1) { - if (own_buf[0] == 'm') + if (own_buffer[0] == 'm') { CORE_ADDR mem_addr; - unsigned char *mem_buf; + unsigned char *mem_buffer; unsigned int mem_len; - decode_m_packet (&own_buf[1], &mem_addr, &mem_len); - mem_buf = (unsigned char *) xmalloc (mem_len); - if (read_inferior_memory (mem_addr, mem_buf, mem_len) == 0) - bin2hex (mem_buf, own_buf, mem_len); + decode_m_packet (&own_buffer[1], &mem_addr, &mem_len); + mem_buffer = (unsigned char *) xmalloc (mem_len); + if (read_inferior_memory (mem_addr, mem_buffer, mem_len) == 0) + bin2hex (mem_buffer, own_buffer, mem_len); else - write_enn (own_buf); - free (mem_buf); - if (putpkt (own_buf) < 0) + write_enn (own_buffer); + free (mem_buffer); + if (putpkt (own_buffer) < 0) return -1; } - else if (own_buf[0] == 'v') + else if (own_buffer[0] == 'v') { int new_len = -1; - handle_v_requests (own_buf, len, &new_len); + handle_v_requests (own_buffer, len, &new_len); if (new_len != -1) - putpkt_binary (own_buf, new_len); + putpkt_binary (own_buffer, new_len); else - putpkt (own_buf); + putpkt (own_buffer); } else break; - len = getpkt (own_buf); + len = getpkt (own_buffer); if (len < 0) return -1; } - if (!startswith (own_buf, "qSymbol:")) + if (!startswith (own_buffer, "qSymbol:")) { - warning ("Malformed response to qSymbol, ignoring: %s\n", own_buf); + warning ("Malformed response to qSymbol, ignoring: %s\n", own_buffer); return -1; } - p = own_buf + strlen ("qSymbol:"); + p = own_buffer + strlen ("qSymbol:"); q = p; while (*q && *q != ':') q++; @@ -1555,13 +1551,13 @@ relocate_instruction (CORE_ADDR *to, CORE_ADDR oldloc) ULONGEST written = 0; /* Send the request. */ - sprintf (own_buf, "qRelocInsn:%s;%s", paddress (oldloc), + sprintf (own_buffer, "qRelocInsn:%s;%s", paddress (oldloc), paddress (*to)); - if (putpkt (own_buf) < 0) + if (putpkt (own_buffer) < 0) return -1; /* FIXME: Eventually add buffer overflow checking (to getpkt?) */ - len = getpkt (own_buf); + len = getpkt (own_buffer); if (len < 0) return -1; @@ -1569,61 +1565,61 @@ relocate_instruction (CORE_ADDR *to, CORE_ADDR oldloc) wait for the qRelocInsn "response". That requires re-entering the main loop. For now, this is an adequate approximation; allow GDB to access memory. */ - while (own_buf[0] == 'm' || own_buf[0] == 'M' || own_buf[0] == 'X') + while (own_buffer[0] == 'm' || own_buffer[0] == 'M' || own_buffer[0] == 'X') { CORE_ADDR mem_addr; - unsigned char *mem_buf = NULL; + unsigned char *mem_buffer = NULL; unsigned int mem_len; - if (own_buf[0] == 'm') + if (own_buffer[0] == 'm') { - decode_m_packet (&own_buf[1], &mem_addr, &mem_len); - mem_buf = (unsigned char *) xmalloc (mem_len); - if (read_inferior_memory (mem_addr, mem_buf, mem_len) == 0) - bin2hex (mem_buf, own_buf, mem_len); + decode_m_packet (&own_buffer[1], &mem_addr, &mem_len); + mem_buffer = (unsigned char *) xmalloc (mem_len); + if (read_inferior_memory (mem_addr, mem_buffer, mem_len) == 0) + bin2hex (mem_buffer, own_buffer, mem_len); else - write_enn (own_buf); + write_enn (own_buffer); } - else if (own_buf[0] == 'X') + else if (own_buffer[0] == 'X') hooks/post-receive -- Repository for Project Archer.