From: teawater <teawater@gmail.com>
To: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: [multiprocess] Linux-nat multiprocess switch
Date: Thu, 27 Nov 2008 09:44:00 -0000 [thread overview]
Message-ID: <daef60380811260704k5e1b4f11wde135f3a9f3a9aa1@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1524 bytes --]
Hi,
I got and test the multiprocess branch. And can't find a interface to
switch the process.
So I make this example patch make multiprocess be switched in
linux-nat. It still have a lot of bugs.
I will make it better if you guys like it.
Example:
(gdb) list
During symbol reading, DW_AT_name missing from DW_TAG_base_type.
5 #include <unistd.h>
6 #include <errno.h>
7 #include <sys/stat.h>
8 #include <fcntl.h>
9 #include <stdint.h>
10
11 int
12 main(int argc,char *argv[],char *envp[])
13 {
14 pid_t pid = fork ();
(gdb)
15
16 if (pid == 0) {
17 while (1) {
18 printf ("%d: C\n", getpid ());
19 sleep (2);
20 }
21 }
22 else {
23 while (1) {
24 printf ("%d: F\n", getpid ());
(gdb)
25 sleep (2);
26 }
27 }
28
29 return (0);
30 }
31
(gdb) set detach-on-fork off
(gdb) set follow-fork-mode child
(gdb) r
Starting program: /home/teawater/multiprocess/a.out
9004: C
9001: F
9004: C
9001: F
9004: C
9001: F
Program received signal SIGINT, Interrupt.
0xb7fe3410 in __kernel_vsyscall ()
(gdb) info inferiors
3 9004 a.out
* 2 9001 a.out
1 0 #a.out# /home/teawater/multiprocess/a.out
(gdb) b 18
Breakpoint 1 at 0x8048433: file 1.c, line 18.
(gdb) c
Continuing.
9004: C
9001: F
9004: C
9001: F
Program received signal SIGINT, Interrupt.
0xb7fe3410 in __kernel_vsyscall ()
(gdb) switch-inferior 3
(gdb) c
Continuing.
9001: F
Breakpoint 1, main (argc=<value optimized out>, argv=<value optimized out>,
envp=<value optimized out>) at 1.c:18
18 printf ("%d: C\n", getpid ());
Thanks,
Hui
[-- Attachment #2: inferior-switch.txt --]
[-- Type: text/plain, Size: 1421 bytes --]
--- gdb.orig/inferior.c
+++ gdb/inferior.c
@@ -26,6 +26,7 @@
#include "gdbthread.h"
#include "ui-out.h"
#include "observer.h"
+#include "regcache.h"
void _initialize_inferiors (void);
@@ -1124,6 +1125,29 @@
}
void
+switch_inferior_command (char *args, int from_tty)
+{
+ struct inferior *inf;
+ int pid;
+ ptid_t ptid;
+
+ /* Get ptid. */
+ get_inferior_or_pid (args, &inf, &pid);
+ if (pid <= 0)
+ {
+ printf_unfiltered (_("Can't switch to inferior %s\n"), args);
+ }
+ ptid = ptid_build (pid, pid, 0);
+
+ if (ptid_equal (ptid, inferior_ptid))
+ return;
+
+ inferior_ptid = ptid;
+ reinit_frame_cache ();
+ registers_changed ();
+}
+
+void
_initialize_inferiors (void)
{
add_com ("add-inferior", no_class, add_inferior_command, _("\
@@ -1132,6 +1156,9 @@
add_com ("remove-inferior", no_class, remove_inferior_command, _("\
Remove the inferiors in ITSET."));
+ add_com ("switch-inferior", no_class, switch_inferior_command, _("\
+Switch the inferiors in ITSET."));
+
add_com ("name-inferior", no_class, name_inferior_command, _("\
Change the name of inferior OLDNAME to NEWNAME."));
--- gdb.orig/linux-nat.c
+++ gdb/linux-nat.c
@@ -1127,11 +1127,11 @@
{
struct lwp_info *lp;
- init_lwp_list ();
+ //init_lwp_list ();
lp = add_lwp (new_ptid);
lp->stopped = 1;
- init_thread_list ();
+ //init_thread_list ();
add_thread_silent (new_ptid);
}
next reply other threads:[~2008-11-26 15:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-27 9:44 teawater [this message]
2008-11-27 9:54 ` Stan Shebs
2008-11-27 17:27 ` teawater
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=daef60380811260704k5e1b4f11wde135f3a9f3a9aa1@mail.gmail.com \
--to=teawater@gmail.com \
--cc=gdb-patches@sourceware.org \
/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