From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6988 invoked by alias); 9 Jun 2012 12:47:19 -0000 Received: (qmail 6912 invoked by uid 22791); 9 Jun 2012 12:47:17 -0000 X-SWARE-Spam-Status: No, hits=-3.3 required=5.0 tests=AWL,BAYES_00,FROM_12LTRDOM,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 09 Jun 2012 12:46:55 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1SdL4B-0005MA-Eh from Yao_Qi@mentor.com for gdb-patches@sourceware.org; Sat, 09 Jun 2012 05:46:55 -0700 Received: from SVR-ORW-FEM-02.mgc.mentorg.com ([147.34.96.206]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Sat, 9 Jun 2012 05:46:23 -0700 Received: from localhost.localdomain (147.34.91.1) by svr-orw-fem-02.mgc.mentorg.com (147.34.96.168) with Microsoft SMTP Server id 14.1.289.1; Sat, 9 Jun 2012 05:46:54 -0700 From: Yao Qi To: Subject: [PATCH 3/4] New agent command 'kill' and used by gdbserver Date: Sat, 09 Jun 2012 12:47:00 -0000 Message-ID: <1339246002-1987-4-git-send-email-yao@codesourcery.com> In-Reply-To: <1339246002-1987-1-git-send-email-yao@codesourcery.com> References: <1339246002-1987-1-git-send-email-yao@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-06/txt/msg00259.txt.bz2 When GDB or GDBserver terminated inferior, agent has no chance to remove socket file, even in atexit hook. This patch adds a call to send command 'kill' to agent in function kill_inferior, in order to tell agent that inferior will be killed, and then agent can do cleanup. Of course, new agent command 'kill' is added and documented. When GDB or GDBserver sends 'kill' command to an older agent, in which 'kill is not known, and it will be ignored. gdb/gdbserver: 2012-06-09 Yao Qi * server.h: Declare run_inferior_command. * target.c (kill_inferior): New. Send command 'kill'. * target.h (kill_inferior): Removed macro. * tracepoint.c (run_inferior_command): Remove static. Handle command 'kill'. gdb/doc: 2012-06-09 Yao Qi * gdb.texinfo (IPA Protocol Commands): Document new command 'kill'. --- gdb/doc/gdb.texinfo | 4 ++++ gdb/gdbserver/server.h | 1 + gdb/gdbserver/target.c | 8 ++++++++ gdb/gdbserver/target.h | 5 ++--- gdb/gdbserver/tracepoint.c | 17 +++++++++++++++-- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index ad227a4..09339e5 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -33585,6 +33585,10 @@ for an error @end table +@item kill +Kills in-process agent. Usually, this command is sent when @value{GDBN} +or GDBserver is about to kill inferiors. + @item qTfSTM @xref{qTfSTM}. @item qTsSTM diff --git a/gdb/gdbserver/server.h b/gdb/gdbserver/server.h index 02dfa29..452e400 100644 --- a/gdb/gdbserver/server.h +++ b/gdb/gdbserver/server.h @@ -558,4 +558,5 @@ int emit_error; extern const char version[]; extern const char host_name[]; +int run_inferior_command (char *cmd, int len); #endif /* SERVER_H */ diff --git a/gdb/gdbserver/target.c b/gdb/gdbserver/target.c index 7539476..35aaecd 100644 --- a/gdb/gdbserver/target.c +++ b/gdb/gdbserver/target.c @@ -182,3 +182,11 @@ target_waitstatus_to_string (const struct target_waitstatus *ws) return buf; } + +int +kill_inferior(int pid) +{ + run_inferior_command ("kill", strlen ("kill")); + + return (*the_target->kill) (pid); +} diff --git a/gdb/gdbserver/target.h b/gdb/gdbserver/target.h index 0cf5687..101c3c4 100644 --- a/gdb/gdbserver/target.h +++ b/gdb/gdbserver/target.h @@ -409,9 +409,6 @@ void set_target_ops (struct target_ops *); #define myattach(pid) \ (*the_target->attach) (pid) -#define kill_inferior(pid) \ - (*the_target->kill) (pid) - #define detach_inferior(pid) \ (*the_target->detach) (pid) @@ -555,4 +552,6 @@ const char *target_pid_to_str (ptid_t); const char *target_waitstatus_to_string (const struct target_waitstatus *); +int kill_inferior (int); + #endif /* TARGET_H */ diff --git a/gdb/gdbserver/tracepoint.c b/gdb/gdbserver/tracepoint.c index 4e6c3ec..bb2df8f 100644 --- a/gdb/gdbserver/tracepoint.c +++ b/gdb/gdbserver/tracepoint.c @@ -412,7 +412,7 @@ static int flush_trace_buffer_handler (CORE_ADDR); static void download_trace_state_variables (void); static void upload_fast_traceframes (void); -static int run_inferior_command (char *cmd, int len); +int run_inferior_command (char *cmd, int len); static int read_inferior_integer (CORE_ADDR symaddr, int *val) @@ -6662,7 +6662,7 @@ static struct ltt_available_probe gdb_ust_probe = thread by means of direct memory xfering, and a socket for synchronization. */ -static int +int run_inferior_command (char *cmd, int len) { int err = -1; @@ -7053,6 +7053,17 @@ gdb_agent_helper_thread (void *arg) if (cmd_buf[0]) { + if (strncmp ("kill", cmd_buf, 4) == 0) + { + ret = write (fd, buf, 1); + close (fd); + + close (listen_fd); + unlink (agent_socket_name); + + return NULL; + } + else #ifdef HAVE_UST if (strcmp ("qTfSTM", cmd_buf) == 0) { @@ -7080,7 +7091,9 @@ gdb_agent_helper_thread (void *arg) { cmd_qtstmat (cmd_buf); } + else #endif /* HAVE_UST */ + {} } /* Fix compiler's warning: ignoring return value of 'write'. */ -- 1.7.0.4