From: Yao Qi <yao@codesourcery.com>
To: Pedro Alves <palves@redhat.com>
Cc: <gdb-patches@sourceware.org>
Subject: Re: [PATCH 3/4] New agent command 'kill' and used by gdbserver
Date: Thu, 14 Jun 2012 14:50:00 -0000 [thread overview]
Message-ID: <201206142250.01331.yao@codesourcery.com> (raw)
In-Reply-To: <4FD76ADB.7090302@redhat.com>
On Wednesday 13 June 2012 00:14:19 Pedro Alves wrote:
> > + run_inferior_command ("kill", strlen ("kill"));
>
> - Missing space before parens.
>
> - What happens if there's no IPA to talk to?
>
> - Also, all callers of run_inferior_command command currently
> pass "cmd, strlen (cmd) + 1".
>
> - The kill_inferior function takes a PID as argument. It's not
> right to assume that PID is the current process. IOW, in a
> multi-process scenario, you may well run the inferior command
> on the wrong inferior as is.
This new patch addresses all your comments except this one above. IMO, the
whole agent work in GDBserver doesn't consider much about multi-process, so
this problem shall be addressed as a whole, when we start to support agent in
multi-process. I leave a FIXME in comment there. WDYT?
gdb/gdbserver:
2012-06-14 Yao Qi <yao@codesourcery.com>
* server.h: Declare run_inferior_command and
maybe_write_ipa_not_loaded.
* target.c (kill_inferior): Include "agent.h".
New. Send command 'kill'.
* target.h (kill_inferior): Removed macro.
* tracepoint.c (run_inferior_command): Remove 'static'.
(kill_inferior): New.
(maybe_write_ipa_not_loaded): Remove 'static'.
(gdb_agent_helper_thread): Handle command 'close'.
Wait endlessly until the inferior stops.
gdb/doc:
2012-06-14 Yao Qi <yao@codesourcery.com>
* gdb.texinfo (IPA Protocol Commands): Document new command
'close'.
---
gdb/doc/gdb.texinfo | 4 ++++
gdb/gdbserver/server.h | 3 +++
gdb/gdbserver/target.c | 18 ++++++++++++++++++
gdb/gdbserver/target.h | 3 +--
gdb/gdbserver/tracepoint.c | 27 ++++++++++++++++++++++-----
5 files changed, 48 insertions(+), 7 deletions(-)
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index ad227a4..8dd1bf7 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -33585,6 +33585,10 @@ for an error
@end table
+@item close
+Closes the in-process agent. 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..d5fa867 100644
--- a/gdb/gdbserver/server.h
+++ b/gdb/gdbserver/server.h
@@ -467,6 +467,8 @@ void stop_tracing (void);
int claim_trampoline_space (ULONGEST used, CORE_ADDR *trampoline);
int have_fast_tracepoint_trampoline_buffer (char *msgbuf);
+
+int maybe_write_ipa_not_loaded (char *buffer);
#endif
struct traceframe;
@@ -558,4 +560,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..6148e1c 100644
--- a/gdb/gdbserver/target.c
+++ b/gdb/gdbserver/target.c
@@ -20,6 +20,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "server.h"
+#include "agent.h"
struct target_ops *the_target;
@@ -182,3 +183,20 @@ target_waitstatus_to_string (const struct target_waitstatus *ws)
return buf;
}
+
+int
+kill_inferior (int pid)
+{
+ char buf[IPA_CMD_BUF_SIZE];
+
+ if (!maybe_write_ipa_not_loaded (buf))
+ {
+ strcpy (buf, "close");
+ /* FIXME: It is wrong to assume PID is the current process. In
+ a multiple-process scenario, we may run inferior command on
+ the wrong process. */
+ run_inferior_command (buf, strlen (buf) + 1);
+ }
+
+ return (*the_target->kill) (pid);
+}
diff --git a/gdb/gdbserver/target.h b/gdb/gdbserver/target.h
index 0cf5687..9f96e04 100644
--- a/gdb/gdbserver/target.h
+++ b/gdb/gdbserver/target.h
@@ -409,8 +409,7 @@ void set_target_ops (struct target_ops *);
#define myattach(pid) \
(*the_target->attach) (pid)
-#define kill_inferior(pid) \
- (*the_target->kill) (pid)
+int kill_inferior (int);
#define detach_inferior(pid) \
(*the_target->detach) (pid)
diff --git a/gdb/gdbserver/tracepoint.c b/gdb/gdbserver/tracepoint.c
index 8fcaa46..df69508 100644
--- a/gdb/gdbserver/tracepoint.c
+++ b/gdb/gdbserver/tracepoint.c
@@ -281,7 +281,7 @@ write_e_ust_not_loaded (char *buffer)
/* If the in-process agent library isn't loaded in the inferior, write
an error to BUFFER, and return 1. Otherwise, return 0. */
-static int
+int
maybe_write_ipa_not_loaded (char *buffer)
{
if (!agent_loaded_p ())
@@ -412,8 +412,6 @@ 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);
-
static int
read_inferior_integer (CORE_ADDR symaddr, int *val)
{
@@ -6662,7 +6660,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;
@@ -7033,6 +7031,7 @@ gdb_agent_helper_thread (void *arg)
int fd;
char buf[1];
int ret;
+ int stop_loop = 0;
tmp = sizeof (sockaddr);
@@ -7065,8 +7064,12 @@ gdb_agent_helper_thread (void *arg)
if (cmd_buf[0])
{
+ if (strncmp ("close", cmd_buf, 5) == 0)
+ {
+ stop_loop = 1;
+ }
#ifdef HAVE_UST
- if (strcmp ("qTfSTM", cmd_buf) == 0)
+ else if (strcmp ("qTfSTM", cmd_buf) == 0)
{
cmd_qtfstm (cmd_buf);
}
@@ -7098,6 +7101,20 @@ gdb_agent_helper_thread (void *arg)
/* Fix compiler's warning: ignoring return value of 'write'. */
ret = write (fd, buf, 1);
close (fd);
+
+ if (stop_loop)
+ {
+ close (listen_fd);
+ unlink (agent_socket_name);
+
+ /* Sleep endlessly to wait the whole inferior stops. This
+ thread can not exit because GDB or GDBserver may still need
+ 'current_inferior' (representing this thread) to access
+ inferior memory. Otherwise, this thread exits earlier than
+ other threads, and 'current_inferior' is set to NULL. */
+ while (1)
+ sleep (10);
+ }
}
}
--
1.7.0.4
next prev parent reply other threads:[~2012-06-14 14:50 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-09 12:47 [PATCH 0/4] PR14161: a partial fix Yao Qi
2012-06-09 12:47 ` [PATCH 1/4] New test for removing socket file in gdb.trace/strace.exp Yao Qi
2012-06-12 14:51 ` Pedro Alves
2012-06-14 14:39 ` Yao Qi
2012-06-15 19:00 ` Pedro Alves
2012-06-20 13:46 ` Yao Qi
2012-06-21 15:56 ` Pedro Alves
2012-06-27 3:55 ` Yao Qi
2012-06-09 12:47 ` [PATCH 2/4] Remove socket file at exit Yao Qi
2012-06-12 15:14 ` Pedro Alves
2012-06-14 14:44 ` Yao Qi
2012-06-15 19:02 ` Pedro Alves
2012-06-09 12:47 ` [PATCH 3/4] New agent command 'kill' and used by gdbserver Yao Qi
2012-06-09 13:11 ` Eli Zaretskii
2012-06-12 16:14 ` Pedro Alves
2012-06-14 14:50 ` Yao Qi [this message]
2012-06-14 16:37 ` Eli Zaretskii
2012-06-15 19:25 ` Pedro Alves
2012-06-20 13:49 ` Yao Qi
2012-06-21 16:05 ` Pedro Alves
2012-06-09 12:47 ` [PATCH 4/4] gdb: kfail for PR14161 Yao Qi
2012-06-12 16:21 ` Pedro Alves
2012-06-14 15:01 ` Yao Qi
2012-06-15 19:33 ` Pedro Alves
2012-06-20 13:55 ` Yao Qi
2012-07-27 8:19 ` [committed] : [PATCH 0/4] PR14161: a partial fix Yao Qi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201206142250.01331.yao@codesourcery.com \
--to=yao@codesourcery.com \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox