]> git.pld-linux.org Git - packages/gdb.git/blob - gdb-6.8-attach-signalled-detach-stopped.patch
- update some patches from gdb-7.2-51.fc14 (this fixes at least artifical arrays...
[packages/gdb.git] / gdb-6.8-attach-signalled-detach-stopped.patch
1 Index: gdb-7.0.50.20100115/gdb/linux-nat.c
2 ===================================================================
3 --- gdb-7.0.50.20100115.orig/gdb/linux-nat.c    2010-01-15 11:53:34.000000000 +0100
4 +++ gdb-7.0.50.20100115/gdb/linux-nat.c 2010-01-15 12:13:53.000000000 +0100
5 @@ -208,6 +208,9 @@ blocked.  */
6  static struct target_ops *linux_ops;
7  static struct target_ops linux_ops_saved;
8  
9 +/* PID of the inferior stopped by SIGSTOP before attaching (or zero).  */
10 +static pid_t pid_was_stopped;
11 +
12  /* The method to call, if any, when a new thread is attached.  */
13  static void (*linux_nat_new_thread) (ptid_t);
14  
15 @@ -933,7 +936,14 @@ Attaching after process %d fork to child
16           parent_inf->waiting_for_vfork_done = 0;
17         }
18        else if (detach_fork)
19 -       target_detach (NULL, 0);
20 +       {
21 +         /* We should check PID_WAS_STOPPED and detach it stopped accordingly.
22 +            In this point of code it cannot be 1 as we would not get FORK
23 +            executed without CONTINUE first which resets PID_WAS_STOPPED.
24 +            We would have to first TARGET_STOP and WAITPID it as with running
25 +            inferior PTRACE_DETACH, SIGSTOP will ignore the signal.  */
26 +         target_detach (NULL, 0);
27 +       }
28  
29        /* Note that the detach above makes PARENT_INF dangling.  */
30  
31 @@ -1427,6 +1437,7 @@ linux_nat_post_attach_wait (ptid_t ptid,
32        if (debug_linux_nat)
33         fprintf_unfiltered (gdb_stdlog,
34                             "LNPAW: Attaching to a stopped process\n");
35 +      pid_was_stopped = GET_PID (ptid);
36  
37        /* The process is definitely stopped.  It is in a job control
38          stop, unless the kernel predates the TASK_STOPPED /
39 @@ -1757,6 +1768,9 @@ GPT: lwp %s had signal %s, but it is in 
40                             target_signal_to_string (signo));
41      }
42  
43 +  if (*status == 0 && GET_PID (lp->ptid) == pid_was_stopped)
44 +    *status = W_STOPCODE (SIGSTOP);
45 +
46    return 0;
47  }
48  
49 @@ -1866,6 +1880,8 @@ linux_nat_detach (struct target_ops *ops
50      }
51    else
52      linux_ops->to_detach (ops, args, from_tty);
53 +
54 +  pid_was_stopped = 0;
55  }
56  
57  /* Resume LP.  */
58 @@ -2031,6 +2047,14 @@ linux_nat_resume (struct target_ops *ops
59       resume_callback.  */
60    lp->stopped = 0;
61  
62 +  /* At this point, we are going to resume the inferior and if we
63 +     have attached to a stopped process, we no longer should leave
64 +     it as stopped if the user detaches.  PTID variable has PID set to LWP
65 +     while we need to check the real PID here.  */
66 +
67 +  if (!step && lp && pid_was_stopped == GET_PID (lp->ptid))
68 +    pid_was_stopped = 0;
69 +
70    if (resume_many)
71      iterate_over_lwps (ptid, resume_callback, NULL);
72  
73 @@ -3923,6 +3947,8 @@ linux_nat_mourn_inferior (struct target_
74         there are other viable forks to debug.  Delete the exiting
75         one and context-switch to the first available.  */
76      linux_fork_mourn_inferior ();
77 +
78 +  pid_was_stopped = 0;
79  }
80  
81  /* Convert a native/host siginfo object, into/from the siginfo in the
82 Index: gdb-7.0.50.20100115/gdb/linux-nat.c
83 ===================================================================
84 --- gdb-7.0.50.20100115.orig/gdb/linux-nat.c    2010-01-15 22:19:27.000000000 +0100
85 +++ gdb-7.0.50.20100115/gdb/linux-nat.c 2010-01-15 22:19:55.000000000 +0100
86 @@ -1768,8 +1768,22 @@ GPT: lwp %s had signal %s, but it is in 
87                             target_signal_to_string (signo));
88      }
89  
90 -  if (*status == 0 && GET_PID (lp->ptid) == pid_was_stopped)
91 -    *status = W_STOPCODE (SIGSTOP);
92 +  /* Workaround RHEL-5 kernel which has unreliable PTRACE_DETACH, SIGSTOP (that
93 +     many TIDs are left unstopped).  See RH Bug 496732.  */
94 +  if (GET_PID (lp->ptid) == pid_was_stopped)
95 +    {
96 +      int err;
97 +
98 +      errno = 0;
99 +      err = kill_lwp (GET_LWP (lp->ptid), SIGSTOP);
100 +      if (debug_linux_nat)
101 +       {
102 +         fprintf_unfiltered (gdb_stdlog,
103 +                             "SC:  lwp kill %d %s\n",
104 +                             err,
105 +                             errno ? safe_strerror (errno) : "ERRNO-OK");
106 +       }
107 +    }
108  
109    return 0;
110  }
111 Index: gdb-7.0.50.20100115/gdb/testsuite/gdb.threads/attach-stopped.exp
112 ===================================================================
113 --- gdb-7.0.50.20100115.orig/gdb/testsuite/gdb.threads/attach-stopped.exp       2010-01-01 08:32:06.000000000 +0100
114 +++ gdb-7.0.50.20100115/gdb/testsuite/gdb.threads/attach-stopped.exp    2010-01-15 11:54:57.000000000 +0100
115 @@ -62,7 +62,65 @@ proc corefunc { threadtype } {
116      gdb_reinitialize_dir $srcdir/$subdir
117      gdb_load ${binfile}
118  
119 -    # Verify that we can attach to the stopped process.
120 +    # Verify that we can attach to the process by first giving its
121 +    # executable name via the file command, and using attach with the
122 +    # process ID.
123 +
124 +    set test "$threadtype: set file, before attach1 to stopped process"
125 +    gdb_test_multiple "file $binfile" "$test" {
126 +       -re "Load new symbol table from.*y or n. $" {
127 +           gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
128 +                   "$test (re-read)"
129 +       }
130 +       -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
131 +           pass "$test"
132 +       }
133 +    }
134 +
135 +    set test "$threadtype: attach1 to stopped, after setting file"
136 +    gdb_test_multiple "attach $testpid" "$test" {
137 +       -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
138 +           pass "$test"
139 +       }
140 +    }
141 +
142 +    # ".*sleep.*clone.*" would fail on s390x as bt stops at START_THREAD there.
143 +    if {[string equal $threadtype threaded]} {
144 +       gdb_test "thread apply all bt" ".*sleep.*start_thread.*" "$threadtype: attach1 to stopped bt"
145 +    } else {
146 +       gdb_test "bt" ".*sleep.*main.*" "$threadtype: attach1 to stopped bt"
147 +    }
148 +
149 +    # Exit and detach the process.
150 +       
151 +    gdb_exit
152 +
153 +    # Avoid some race:
154 +    sleep 2
155 +
156 +    if [catch {open /proc/${testpid}/status r} fileid] {
157 +       set line2 "NOTFOUND"
158 +    } else {
159 +       gets $fileid line1;
160 +       gets $fileid line2;
161 +       close $fileid;
162 +    }
163 +
164 +    set test "$threadtype: attach1, exit leaves process stopped"
165 +    if {[string match "*(stopped)*" $line2]} {
166 +      pass $test
167 +    } else {
168 +      fail $test
169 +    }
170 +
171 +    # At this point, the process should still be stopped
172 +
173 +    gdb_start
174 +    gdb_reinitialize_dir $srcdir/$subdir
175 +    gdb_load ${binfile}
176 +
177 +    # Verify that we can attach to the process just by giving the
178 +    # process ID.
179         
180      set test "$threadtype: attach2 to stopped, after setting file"
181      gdb_test_multiple "attach $testpid" "$test" {
182 Index: gdb-7.0.50.20100115/gdb/testsuite/gdb.threads/attachstop-mt.exp
183 ===================================================================
184 --- gdb-7.0.50.20100115.orig/gdb/testsuite/gdb.threads/attachstop-mt.exp        2010-01-01 08:32:06.000000000 +0100
185 +++ gdb-7.0.50.20100115/gdb/testsuite/gdb.threads/attachstop-mt.exp     2010-01-15 11:54:57.000000000 +0100
186 @@ -176,12 +176,23 @@ gdb_test "bt" ".*sleep.*(func|main).*" "
187  # Exit and detach the process.
188  gdb_exit
189  
190 -# Stop the program 
191 -remote_exec build "kill -s STOP ${testpid}"
192 -
193  # No race
194  sleep 2
195  
196 +set fileid3 [open $status2 r];
197 +gets $fileid3 line1;
198 +gets $fileid3 line2;
199 +close $fileid3;
200 +
201 +set test "attach3, exit leaves process stopped"
202 +if {[string match "*(stopped)*" $line2]} {
203 +  pass $test
204 +} else {
205 +  fail $test
206 +}
207 +
208 +# At this point, the process should still be stopped
209 +
210  # Continue the test as we would hit another expected bug regarding
211  #      Program received signal SIGSTOP, Stopped (signal).
212  # across NPTL threads.
This page took 0.038761 seconds and 3 git commands to generate.