Skip to content

Commit 8c45bad

Browse files
ivanivanov884jeffmahoney
authored andcommitted
gdb-gnat-dwarf-crash-3of3.patch
;; Fix crash of -readnow /usr/lib/debug/usr/bin/gnatbind.debug (BZ 1069211). ;;=push+jan http://sourceware.org/ml/gdb-patches/2014-02/msg00731.html --6TrnltStXW4iwmi0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, PR 16581: GDB crash on inherit_abstract_dies infinite recursion https://sourceware.org/bugzilla/show_bug.cgi?id=16581 fixed crash from an infinite recursion. But in rare cases the new code can now gdb_assert() due to weird DWARF file. I do not yet fully understand why the DWARF is as it is but just GDB should never crash due to invalid DWARF anyway. The "invalid" DWARF I see only in Fedora GCC build, not in FSF GCC build, more info at: https://bugzilla.redhat.com/show_bug.cgi?id=1069382 http://people.redhat.com/jkratoch/gcc-debuginfo-4.8.2-7.fc20.x86_64-gnatbind.debug Thanks, Jan --6TrnltStXW4iwmi0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline; filename="complaint.patch" gdb/ 2014-02-24 Jan Kratochvil <[email protected]> * dwarf2read.c (process_die): Change gdb_assert to complaint.
1 parent 00d1e2a commit 8c45bad

File tree

4 files changed

+119
-1
lines changed

4 files changed

+119
-1
lines changed

gdb/dwarf2read.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10586,6 +10586,13 @@ class process_die_scope
1058610586
static void
1058710587
process_die (struct die_info *die, struct dwarf2_cu *cu)
1058810588
{
10589+
if (die->in_process)
10590+
{
10591+
complaint (_("DIE at 0x%s attempted to be processed twice"),
10592+
sect_offset_str (die->sect_off));
10593+
return;
10594+
}
10595+
1058910596
process_die_scope scope (die, cu);
1059010597

1059110598
switch (die->tag)

gdb/infrun.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,13 @@ holding the child stopped. Try \"set detach-on-fork\" or \
610610
target_pid_to_str (process_ptid).c_str ());
611611
}
612612

613+
#ifdef NEED_DETACH_SIGSTOP
614+
/* We should check PID_WAS_STOPPED and detach it stopped accordingly.
615+
In this point of code it cannot be 1 as we would not get FORK
616+
executed without CONTINUE first which resets PID_WAS_STOPPED.
617+
We would have to first TARGET_STOP and WAITPID it as with running
618+
inferior PTRACE_DETACH, SIGSTOP will ignore the signal. */
619+
#endif
613620
target_detach (parent_inf, 0);
614621
}
615622

gdb/linux-nat.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ struct linux_nat_target *linux_target;
192192
/* Does the current host support PTRACE_GETREGSET? */
193193
enum tribool have_ptrace_getregset = TRIBOOL_UNKNOWN;
194194

195+
#ifdef NEED_DETACH_SIGSTOP
196+
/* PID of the inferior stopped by SIGSTOP before attaching (or zero). */
197+
static pid_t pid_was_stopped;
198+
199+
#endif
200+
195201
static unsigned int debug_linux_nat;
196202
static void
197203
show_debug_linux_nat (struct ui_file *file, int from_tty,
@@ -1036,6 +1042,9 @@ linux_nat_post_attach_wait (ptid_t ptid, int *signalled)
10361042
if (debug_linux_nat)
10371043
fprintf_unfiltered (gdb_stdlog,
10381044
"LNPAW: Attaching to a stopped process\n");
1045+
#ifdef NEED_DETACH_SIGSTOP
1046+
pid_was_stopped = ptid.pid ();
1047+
#endif
10391048

10401049
/* The process is definitely stopped. It is in a job control
10411050
stop, unless the kernel predates the TASK_STOPPED /
@@ -1367,6 +1376,25 @@ get_detach_signal (struct lwp_info *lp)
13671376
return gdb_signal_to_host (signo);
13681377
}
13691378

1379+
#ifdef NEED_DETACH_SIGSTOP
1380+
/* Workaround RHEL-5 kernel which has unreliable PTRACE_DETACH, SIGSTOP (that
1381+
many TIDs are left unstopped). See RH Bug 496732. */
1382+
if (lp->ptid.pid () == pid_was_stopped)
1383+
{
1384+
int err;
1385+
1386+
errno = 0;
1387+
err = kill_lwp (lp->ptid.lwp (), SIGSTOP);
1388+
if (debug_linux_nat)
1389+
{
1390+
fprintf_unfiltered (gdb_stdlog,
1391+
"SC: lwp kill %d %s\n",
1392+
err,
1393+
errno ? safe_strerror (errno) : "ERRNO-OK");
1394+
}
1395+
}
1396+
1397+
#endif
13701398
return 0;
13711399
}
13721400

@@ -1515,6 +1543,10 @@ linux_nat_target::detach (inferior *inf, int from_tty)
15151543
detach_one_lwp (main_lwp, &signo);
15161544

15171545
detach_success (inf);
1546+
1547+
#ifdef NEED_DETACH_SIGSTOP
1548+
pid_was_stopped = 0;
1549+
#endif
15181550
}
15191551
}
15201552

@@ -1772,6 +1804,16 @@ linux_nat_target::resume (ptid_t ptid, int step, enum gdb_signal signo)
17721804
return;
17731805
}
17741806

1807+
#ifdef NEED_DETACH_SIGSTOP
1808+
/* At this point, we are going to resume the inferior and if we
1809+
have attached to a stopped process, we no longer should leave
1810+
it as stopped if the user detaches. PTID variable has PID set to LWP
1811+
while we need to check the real PID here. */
1812+
1813+
if (!step && lp && pid_was_stopped == lp->ptid.pid ())
1814+
pid_was_stopped = 0;
1815+
1816+
#endif
17751817
if (resume_many)
17761818
iterate_over_lwps (ptid, [=] (struct lwp_info *info)
17771819
{
@@ -3773,6 +3815,10 @@ linux_nat_target::mourn_inferior ()
37733815

37743816
/* Let the arch-specific native code know this process is gone. */
37753817
linux_target->low_forget_process (pid);
3818+
#ifdef NEED_DETACH_SIGSTOP
3819+
3820+
pid_was_stopped = 0;
3821+
#endif
37763822
}
37773823

37783824
/* Convert a native/host siginfo object, into/from the siginfo in the

gdb/testsuite/gdb.threads/attach-stopped.exp

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,65 @@ proc corefunc { threadtype } {
5656
gdb_reinitialize_dir $srcdir/$subdir
5757
gdb_load ${binfile}
5858

59-
# Verify that we can attach to the stopped process.
59+
# Verify that we can attach to the process by first giving its
60+
# executable name via the file command, and using attach with the
61+
# process ID.
62+
63+
set test "$threadtype: set file, before attach1 to stopped process"
64+
gdb_test_multiple "file $binfile" "$test" {
65+
-re "Load new symbol table from.*y or n. $" {
66+
gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
67+
"$test (re-read)"
68+
}
69+
-re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
70+
pass "$test"
71+
}
72+
}
73+
74+
set test "$threadtype: attach1 to stopped, after setting file"
75+
gdb_test_multiple "attach $testpid" "$test" {
76+
-re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
77+
pass "$test"
78+
}
79+
}
80+
81+
# ".*sleep.*clone.*" would fail on s390x as bt stops at START_THREAD there.
82+
if {[string equal $threadtype threaded]} {
83+
gdb_test "thread apply all bt" ".*sleep.*start_thread.*" "$threadtype: attach1 to stopped bt"
84+
} else {
85+
gdb_test "bt" ".*sleep.*main.*" "$threadtype: attach1 to stopped bt"
86+
}
87+
88+
# Exit and detach the process.
89+
90+
gdb_exit
91+
92+
# Avoid some race:
93+
sleep 2
94+
95+
if [catch {open /proc/${testpid}/status r} fileid] {
96+
set line2 "NOTFOUND"
97+
} else {
98+
gets $fileid line1;
99+
gets $fileid line2;
100+
close $fileid;
101+
}
102+
103+
set test "$threadtype: attach1, exit leaves process stopped"
104+
if {[string match "*(stopped)*" $line2]} {
105+
pass $test
106+
} else {
107+
fail $test
108+
}
109+
110+
# At this point, the process should still be stopped
111+
112+
gdb_start
113+
gdb_reinitialize_dir $srcdir/$subdir
114+
gdb_load ${binfile}
115+
116+
# Verify that we can attach to the process just by giving the
117+
# process ID.
60118

61119
set test "$threadtype: attach2 to stopped, after setting file"
62120
gdb_test_multiple "attach $testpid" "$test" {

0 commit comments

Comments
 (0)