[dwarf2_mark_helper patch] Re: [PATCH] Make interrupting tab-completion safe.

Jan Kratochvil
2011-07-12T11:15:08Z

[-- Attachment #1: Type: text/plain, Size: 2391 bytes --]

On Mon, 11 Jul 2011 23:36:24 +0200, Sterling Augustine wrote:
> On head, synced this morning, I still get the failure.

OK, this is a different kind of crash than I reproduced before.
Re-posting back to the list with the off-list mail attached (+reformatted).

It is reproducible only for:
* either cross-CU DIE reference by its offset but that is never produced by
GCC so I do not consider it here.
* or .debug_types, therefore -gdwarf-4 possibly with -fdebug-types-section.

And then also it must have:
* missing DW_AT_MIPS_linkage_name which I guess only Google is using.
One can simulate it in gdb by -ex 'set debug check-physname'.
Otherwise C++ parameters printing would not get called.

And for the artificial reproducibility:
* The referenced CUs must contain C++ parameters.
To make possibly CTRL-C application while reading them in.
* The referencing CU should not contain C++ parameters.
Otherwise CTRL-C could apply too early.

Recommending some `ulimit -v 2000000' otherwise GDB can eat out the memory.

perl -le '$n=1000;print "class C$_ { public: void m (C$_ *c) {} } c$_;" for 1..$n;print "int main () { ";print "c$_.m (&c$_);" for 1..$n;print "}";'|g++ -gdwarf-4 -fdebug-types-section -Wall -x c++ -;./gdb -nx -ex 'set debug check-physname' ./a.out
g++ (GCC) 4.7.0 20110712 (experimental)
GNU gdb (GDB) 7.3.50.20110711-cvs
(gdb) b ^CQuit
(gdb) b <SEGV>
by:
(gdb) b <tab><fast ctrl-c>
(gdb) b <tab>

One can also use $n=10000 to have more than 1sec for <ctrl-c>.

> The segmentation fault happens because per_cu->cu == NULL.

While the fix is doing just the straightforward thing I do not see what better
fix could be made.

Thanks,
Jan

gdb/
2011-07-12 Jan Kratochvil <jan.kratochvil@redhat.com>

Fix occasional crash of CTRL-C during DWARF read in.
* dwarf2read.c (dwarf2_mark_helper): Return on NULL CU.

--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -15455,6 +15455,13 @@ dwarf2_mark_helper (void **slot, void *data)
struct dwarf2_per_cu_data *per_cu;

per_cu = (struct dwarf2_per_cu_data *) *slot;
+
+ /* cu->dependencies references may not yet have been ever read if QUIT aborts
+ reading of the chain. As such dependencies remain valid there is not much
+ useful to track and undo them during QUIT cleanups. */
+ if (per_cu->cu == NULL)
+ return 1;
+
if (per_cu->cu->mark)
return 1;
per_cu->cu->mark = 1;

[-- Attachment #2: cu-trace --]
[-- Type: text/plain, Size: 11462 bytes --]

On Mon, Jul 11, 2011 at 11:53 AM, Jan Kratochvil <jan.kratochvil@redhat.com> wrote:
> If you still have it reproducible with FSF GDB HEAD or 7.3 snapshots please
> provide some backtrace etc.

On head, synced this morning, I still get the failure. Two stack
traces are below. The first is a trace from the actual successful quit
call. The second is the actual crash.

After each "b" on the command line, I type <tab><tab>, which of course
doesn't show up in the log.

The segmentation fault happens because per_cu->cu == NULL.

Sterling

*******

Starting program:
/usr/local/google/users/saugustine/gdb-tot/build/gdb/gdb
really_big_program
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/libthread_db.so.1".
GNU gdb (GDB) 7.3.50.20110711-cvs
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from really_big_program...done.
warning: Missing auto-load scripts referenced in section .debug_gdb_scripts
of file really_big_program
Use `info auto-load-scripts [REGEXP]' to list them.
(gdb) b
Program received signal SIGINT, Interrupt.
^C
Program received signal SIGINT, Interrupt.

Breakpoint 1, quit () at /home/saugustine/tot-gdb/src/gdb/utils.c:1192
1192 {
(top) where
#0 quit () at /home/saugustine/tot-gdb/src/gdb/utils.c:1192
#1 0x00000000005f890f in c_type_print_base (type=0x1bcb0290, stream=0x19ff6d00, show=-1, level=0) at /home/saugustine/tot-gdb/src/gdb/c-typeprint.c:730
#2 0x00000000005fa5f9 in c_print_type (type=0x1bcb0290, varstring=0x70622b "", stream=0x19ff6d00, show=-1, level=0) at /home/saugustine/tot-gdb/src/gdb/c-typeprint.c:63
#3 0x00000000005fa7c6 in c_type_print_args (type=0x1bd8f610, stream=0x19ff6d00, linkage_name=<optimized out>, language=language_cplus) at /home/saugustine/tot-gdb/src/gdb/c-typeprint.c:439
#4 0x00000000005b1fc2 in dwarf2_compute_name (name=<optimized out>, die=0x1bc9d8c0, cu=0x169a83e0, physname=1) at /home/saugustine/tot-gdb/src/gdb/dwarf2read.c:5121
#5 0x00000000005b23dc in dwarf2_physname (name=0x7fffdcd38bfe "scoped_ptr", die=0x1bc9d8c0, cu=0x169a83e0) at /home/saugustine/tot-gdb/src/gdb/dwarf2read.c:5241
#6 0x00000000005b6276 in compute_delayed_physnames (cu=<optimized out>) at /home/saugustine/tot-gdb/src/gdb/dwarf2read.c:4651
#7 process_full_comp_unit (per_cu=<optimized out>) at /home/saugustine/tot-gdb/src/gdb/dwarf2read.c:4729
#8 process_queue (objfile=<optimized out>) at /home/saugustine/tot-gdb/src/gdb/dwarf2read.c:4445
#9 dw2_do_instantiate_symtab (objfile=<optimized out>, per_cu=<optimized out>) at /home/saugustine/tot-gdb/src/gdb/dwarf2read.c:1812
#10 0x00000000005b6f73 in dwarf2_psymtab_to_symtab (pst=0x15c475a0) at /home/saugustine/tot-gdb/src/gdb/dwarf2read.c:4402
#11 0x0000000000543954 in psymtab_to_symtab (pst=0x15c475a0) at /home/saugustine/tot-gdb/src/gdb/psymtab.c:752
#12 0x00000000005448dd in expand_symtabs_matching_via_partial (objfile=0xc68ed0, file_matcher=0, name_matcher=<optimized out>, kind=ALL_DOMAIN, data=<optimized out>) at /home/saugustine/tot-gdb/src/gdb/psymtab.c:1271
#13 0x0000000000543573 in expand_partial_symbol_names (fun=0x53cbe0 <expand_partial_symbol_name>, data=0x7fffffffd8e0) at /home/saugustine/tot-gdb/src/gdb/psymtab.c:1913
#14 0x0000000000540385 in default_make_symbol_completion_list_break_on (text=0x7fffffffd9c2 "", word=0x7fffffffd9c2 "", break_on=0x70622b "") at /home/saugustine/tot-gdb/src/gdb/symtab.c:3897
#15 0x0000000000574059 in location_completer (ignore=<optimized out>, text=0x7fffffffd9c2 "", word=0x7fffffffd9c2 "") at /home/saugustine/tot-gdb/src/gdb/completer.c:286
#16 0x0000000000573623 in complete_line_internal (text=<optimized out>, line_buffer=<optimized out>, point=<optimized out>, reason=handle_completions) at /home/saugustine/tot-gdb/src/gdb/completer.c:791
#17 0x0000000000573afc in line_completion_function (point=<optimized out>, line_buffer=<optimized out>, matches=<optimized out>, text=<optimized out>) at /home/saugustine/tot-gdb/src/gdb/completer.c:885
#18 readline_line_completion_function (text=0x364b130 "", matches=<optimized out>) at /home/saugustine/tot-gdb/src/gdb/completer.c:102
#19 0x000000000063d673 in rl_completion_matches (text=0x364b130 "", entry_function=<optimized out>) at /home/saugustine/tot-gdb/src/readline/complete.c:1997
#20 0x000000000063ec5b in rl_complete_internal (what_to_do=9) at /home/saugustine/tot-gdb/src/readline/complete.c:1835
#21 0x00000000006366db in _rl_dispatch_subseq (key=9, map=0xab0400, got_subseq=0) at /home/saugustine/tot-gdb/src/readline/readline.c:774
#22 0x0000000000636eb7 in readline_internal_char () at /home/saugustine/tot-gdb/src/readline/readline.c:552
#23 0x000000000064b145 in rl_callback_read_char () at /home/saugustine/tot-gdb/src/readline/callback.c:201
#24 0x0000000000571f89 in rl_callback_read_char_wrapper (client_data=0x1bcb0290) at /home/saugustine/tot-gdb/src/gdb/event-top.c:177
#25 0x0000000000570818 in process_event () at /home/saugustine/tot-gdb/src/gdb/event-loop.c:402
#26 0x0000000000571c1a in gdb_do_one_event (data=<optimized out>) at /home/saugustine/tot-gdb/src/gdb/event-loop.c:467
#27 0x000000000056b9db in catch_errors (func=<optimized out>, func_args=<optimized out>, errstring=<optimized out>, mask=<optimized out>) at /home/saugustine/tot-gdb/src/gdb/exceptions.c:506
#28 0x00000000004df7d0 in tui_command_loop (data=<optimized out>) at /home/saugustine/tot-gdb/src/gdb/tui/tui-interp.c:172
#29 0x0000000000458069 in captured_command_loop (data=0x1bcb0290) at /home/saugustine/tot-gdb/src/gdb/main.c:230
#30 0x000000000056b9db in catch_errors (func=<optimized out>, func_args=<optimized out>, errstring=<optimized out>, mask=<optimized out>) at /home/saugustine/tot-gdb/src/gdb/exceptions.c:506
#31 0x0000000000458ca6 in captured_main (data=<optimized out>) at /home/saugustine/tot-gdb/src/gdb/main.c:937
#32 0x000000000056b9db in catch_errors (func=<optimized out>, func_args=<optimized out>, errstring=<optimized out>, mask=<optimized out>) at /home/saugustine/tot-gdb/src/gdb/exceptions.c:506
#33 0x0000000000458054 in gdb_main (args=0x19ff6d00) at /home/saugustine/tot-gdb/src/gdb/main.c:946
#34 0x000000000045801e in main (argc=<optimized out>, argv=0x19ff6d00) at /home/saugustine/tot-gdb/src/gdb/gdb.c:35
(top) c
Continuing.
Quit
(gdb) b
Program received signal SIGSEGV, Segmentation fault.
0x00000000005a757b in dwarf2_mark_helper (slot=0x1bae5e20, data=0x0)
at /home/saugustine/tot-gdb/src/gdb/dwarf2read.c:15462
15462 if (per_cu->cu->mark)
(top) where
#0 0x00000000005a757b in dwarf2_mark_helper (slot=0x1bae5e20, data=0x0) at /home/saugustine/tot-gdb/src/gdb/dwarf2read.c:15462
#1 0x00000000006e36f8 in htab_traverse_noresize (htab=<optimized out>, callback=0x5a7570 <dwarf2_mark_helper>, info=0x0) at /home/saugustine/tot-gdb/src/libiberty/hashtab.c:784
#2 0x00000000005a75a8 in dwarf2_mark_helper (slot=<optimized out>, data=<optimized out>) at /home/saugustine/tot-gdb/src/gdb/dwarf2read.c:15467
#3 0x00000000006e36f8 in htab_traverse_noresize (htab=<optimized out>, callback=0x5a7570 <dwarf2_mark_helper>, info=0x0) at /home/saugustine/tot-gdb/src/libiberty/hashtab.c:784
#4 0x00000000005a74a8 in dwarf2_mark (cu=<optimized out>) at /home/saugustine/tot-gdb/src/gdb/dwarf2read.c:15482
#5 age_cached_comp_units () at /home/saugustine/tot-gdb/src/gdb/dwarf2read.c:15228
#6 0x00000000005b6408 in dw2_do_instantiate_symtab (objfile=0x0, per_cu=0x9b6a780) at /home/saugustine/tot-gdb/src/gdb/dwarf2read.c:1816
#7 0x00000000005b6f73 in dwarf2_psymtab_to_symtab (pst=0x15c46a50) at /home/saugustine/tot-gdb/src/gdb/dwarf2read.c:4402
#8 0x0000000000543954 in psymtab_to_symtab (pst=0x15c46a50) at /home/saugustine/tot-gdb/src/gdb/psymtab.c:752
#9 0x00000000005448dd in expand_symtabs_matching_via_partial (objfile=0xc68ed0, file_matcher=0, name_matcher=<optimized out>, kind=ALL_DOMAIN, data=<optimized out>) at /home/saugustine/tot-gdb/src/gdb/psymtab.c:1271
#10 0x0000000000543573 in expand_partial_symbol_names (fun=0x53cbe0 <expand_partial_symbol_name>, data=0x7fffffffd8e0) at /home/saugustine/tot-gdb/src/gdb/psymtab.c:1913
#11 0x0000000000540385 in default_make_symbol_completion_list_break_on (text=0x7fffffffd9c2 "", word=0x7fffffffd9c2 "", break_on=0x70622b "") at /home/saugustine/tot-gdb/src/gdb/symtab.c:3897
#12 0x0000000000574059 in location_completer (ignore=<optimized out>, text=0x7fffffffd9c2 "", word=0x7fffffffd9c2 "") at /home/saugustine/tot-gdb/src/gdb/completer.c:286
#13 0x0000000000573623 in complete_line_internal (text=<optimized out>, line_buffer=<optimized out>, point=<optimized out>, reason=handle_completions) at /home/saugustine/tot-gdb/src/gdb/completer.c:791
#14 0x0000000000573afc in line_completion_function (point=<optimized out>, line_buffer=<optimized out>, matches=<optimized out>, text=<optimized out>) at /home/saugustine/tot-gdb/src/gdb/completer.c:885
#15 readline_line_completion_function (text=0xe5675f0 "", matches=<optimized out>) at /home/saugustine/tot-gdb/src/gdb/completer.c:102
#16 0x000000000063d673 in rl_completion_matches (text=0xe5675f0 "", entry_function=<optimized out>) at /home/saugustine/tot-gdb/src/readline/complete.c:1997
#17 0x000000000063ec5b in rl_complete_internal (what_to_do=9) at /home/saugustine/tot-gdb/src/readline/complete.c:1835
#18 0x00000000006366db in _rl_dispatch_subseq (key=9, map=0xab0400, got_subseq=0) at /home/saugustine/tot-gdb/src/readline/readline.c:774
#19 0x0000000000636eb7 in readline_internal_char () at /home/saugustine/tot-gdb/src/readline/readline.c:552
#20 0x000000000064b145 in rl_callback_read_char () at /home/saugustine/tot-gdb/src/readline/callback.c:201
#21 0x0000000000571f89 in rl_callback_read_char_wrapper (client_data=0x1bae5e20) at /home/saugustine/tot-gdb/src/gdb/event-top.c:177
#22 0x0000000000570818 in process_event () at /home/saugustine/tot-gdb/src/gdb/event-loop.c:402
#23 0x0000000000571c1a in gdb_do_one_event (data=<optimized out>) at /home/saugustine/tot-gdb/src/gdb/event-loop.c:467
#24 0x000000000056b9db in catch_errors (func=<optimized out>, func_args=<optimized out>, errstring=<optimized out>, mask=<optimized out>) at /home/saugustine/tot-gdb/src/gdb/exceptions.c:506
#25 0x00000000004df7d0 in tui_command_loop (data=<optimized out>) at /home/saugustine/tot-gdb/src/gdb/tui/tui-interp.c:172
#26 0x0000000000458069 in captured_command_loop (data=0x1bae5e20) at /home/saugustine/tot-gdb/src/gdb/main.c:230
#27 0x000000000056b9db in catch_errors (func=<optimized out>, func_args=<optimized out>, errstring=<optimized out>, mask=<optimized out>) at /home/saugustine/tot-gdb/src/gdb/exceptions.c:506
#28 0x0000000000458ca6 in captured_main (data=<optimized out>) at /home/saugustine/tot-gdb/src/gdb/main.c:937
#29 0x000000000056b9db in catch_errors (func=<optimized out>, func_args=<optimized out>, errstring=<optimized out>, mask=<optimized out>) at /home/saugustine/tot-gdb/src/gdb/exceptions.c:506
#30 0x0000000000458054 in gdb_main (args=0x0) at /home/saugustine/tot-gdb/src/gdb/main.c:946
#31 0x000000000045801e in main (argc=<optimized out>, argv=0x0) at /home/saugustine/tot-gdb/src/gdb/gdb.c:35
(top)