Bug 31449 - TUI crash with debuginfod support
Summary: TUI crash with debuginfod support
Status: NEW
Alias: None
Product: gdb
Classification: Unclassified
Component: tui (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-03-05 01:54 UTC by Tom Tromey
Modified: 2024-03-12 21:57 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Tromey 2024-03-05 01:54:14 UTC
I noticed this when looking at the tui-missing-src.exp test case.
If I "gdb -nx ...exe-from-that-test", then at the first
prompt type "tui enable", gdb will crash.

#7  0x0000000000c82d7d in tui_inject_newline_into_command_window () at ../../binutils-gdb/gdb/tui/tui-io.c:1065
#8  0x0000000000c548d7 in show_history_filename (file=0x7ffeb152c460, from_tty=0, c=0x2e03930, 
    value=0x200000000 <error: Cannot access memory at address 0x200000000>) at ../../binutils-gdb/gdb/top.c:901
#9  0x0000000000786517 in gdb_rl_callback_handler (rl=0x2e03590 "n") at ../../binutils-gdb/gdb/event-top.c:259
#10 0x0000000000d752e5 in _rl_callback_newline () at ../../../binutils-gdb/readline/readline/callback.c:95
#11 0x00007f9ed8002ea0 in ?? ()
#12 0x00007ffeb152c540 in ?? ()
#13 0x0000000000786366 in gdb_rl_callback_read_char_wrapper_noexcept () at ../../binutils-gdb/gdb/event-top.c:195
#14 0x000000000078641c in gdb_rl_callback_read_char_wrapper (client_data=0x2a8c770) at ../../binutils-gdb/gdb/event-top.c:234
#15 0x0000000000cad582 in ui::ui (this=0x7f9ed8002ea0, instream_=0x7ffeb152c590, outstream_=0x787738 <default_quit_handler()+9>, errstream_=0x0)
    at ../../binutils-gdb/gdb/ui.c:53
#16 0x000000000122ff4f in delete_file_handler (fd=0) at ../../binutils-gdb/gdbsupport/event-loop.cc:458
#17 0x00000000012304fb in gdb_wait_for_event (block=1) at ../../binutils-gdb/gdbsupport/event-loop.cc:632
#18 0x000000000122f47d in internal_warning_loc (file=0x100000001 <error: Cannot access memory at address 0x100000001>, line=32766, 
    fmt=0x12304fb <gdb_wait_for_event(int)+453> "\001H\211\005\215\006G\001H\211\025\216\006G\001H\213\005\017\005G\001H\213\025\020\005G\001H\211\005\201\006G\001H\211\025\202\006G\001H\213\005\003\005G\001H\213\025\004\005G\001H\211\005u\006G\001H\211\025v\006G\001H\213\005\367\004G\001H\213\025\370\004G\001H\211\005i\006G\001H\211\025j\006G\001H\213\005\353\004G\001H\213\025\354\004G\001H\211\005]\006G\001H\211\025^\006G\001H\213\005\337\004G\001H\213\025\340\004G\001H\211\005Q\006G\001H\211\025R\006G\001H\213\005\323\004G\001H\213\025\324\004G\001H\211\005E\006G\001H\211\025F\006G\001H\213\005\307\004G\001H\213\025\310\004G\001H\211\005"...) at ../../binutils-gdb/gdbsupport/errors.cc:69
#19 0x0000000000c549a1 in gdb_readline_wrapper (prompt=0x2ebf710 "Enable debuginfod for this session? (y or [n]) ") at ../../binutils-gdb/gdb/top.c:1038
#20 0x0000000000ce9125 in maybe_quit () at ../../binutils-gdb/gdb/utils.c:693
#21 0x0000000000ce937f in defaulted_query(const char *, char, typedef __va_list_tag __va_list_tag *) (
    ctlstr=0xce937f <defaulted_query(const char *, char, typedef __va_list_tag __va_list_tag *)+343> "\030\377\377\377H\211\316H\211\307\3506#", 
    defchar=-2 '\376', args=0x0) at ../../binutils-gdb/gdb/utils.c:847
#22 0x000000000069030c in debuginfod_is_enabled () at ../../binutils-gdb/gdb/debuginfod-support.c:268
#23 0x00000000006904a3 in debuginfod_source_query (build_id=0x2de9f18 "\320Ou\033\223A\236\004T\302\364\344\026\305 4A\"\337O", build_id_len=20, 
    srcpath=0x2e03240 "/home/tromey/gdb/build/gdb/testsuite/outputs/gdb.tui/tui-missing-src/main.c", destname=0x7ffeb152cb08)
    at ../../binutils-gdb/gdb/debuginfod-support.c:311
#24 0x0000000000ba3d99 in open_source_file (s=0x2df3370) at ../../binutils-gdb/gdb/source.c:1180
#25 0x0000000000ba4015 in symtab_to_fullname (s=0x2df3370) at ../../binutils-gdb/gdb/source.c:1242
#26 0x0000000000bf8bed in find_line_symtab (sym_tab=0x2df3370, line=1, index=0x7ffeb152ccf4, exact_match=0x0) at ../../binutils-gdb/gdb/symtab.c:3439
#27 0x0000000000bf90d6 in find_pcs_for_symtab_line (symtab=0x7ffeb152cd10, line=0, best_item=0x7ffeb152cce0) at ../../binutils-gdb/gdb/symtab.c:3544
#28 0x0000000000c76630 in tui_disasm_window::set_contents (this=0x50266bd58, arch=0x2df3880, sal=...) at ../../binutils-gdb/gdb/tui/tui-disasm.c:388
#29 0x0000000000c9dd14 in tui_source_window_base::tui_source_window_base (
    this=0xa5c3f5 <std::get<0ul, _win_st*, curses_deleter>(std::tuple<_win_st*, curses_deleter> const&)+24>)
    at ../../binutils-gdb/gdb/tui/tui-winsource.c:423
#30 0x0000000000c87219 in tui_win_info::resize (this=0x2e903e0, height_=24, width_=158, origin_x_=0, origin_y_=0)
    at ../../binutils-gdb/gdb/tui/tui-layout.c:294
#31 0x0000000000c87981 in tui_layout_window::apply (this=0x2de8a30, x_=0, y_=0, width_=158, height_=24, preserve_cmd_win_size_p=false)
    at ../../binutils-gdb/gdb/tui/tui-layout.c:429
#32 0x0000000000c89bf4 in tui_layout_split::apply (this=0x2e035b0, x_=0, y_=0, width_=158, height_=38, preserve_cmd_win_size_p=false)
    at ../../binutils-gdb/gdb/tui/tui-layout.c:1031
#33 0x0000000000c867f2 in tui_apply_current_layout (preserve_cmd_win_size_p=false) at ../../binutils-gdb/gdb/tui/tui-layout.c:71
#34 0x0000000000c86c64 in tui_set_layout (layout=0x2bd5fe0) at ../../binutils-gdb/gdb/tui/tui-layout.c:134
#35 0x0000000000c86f0d in tui_next_layout () at ../../binutils-gdb/gdb/tui/tui-layout.c:195
#36 0x0000000000c9ff90 in tui_ensure_readline_initialized () at ../../binutils-gdb/gdb/tui/tui.c:342
#37 0x0000000000ca0245 in tui_enable () at ../../binutils-gdb/gdb/tui/tui.c:424
Comment 1 Tom Tromey 2024-03-05 17:04:14 UTC
I sort of wish the debuginfod 'ask' approach didn't even exist.
It would fix this bug for one thing.
Comment 2 Aaron Merey 2024-03-06 21:25:00 UTC
This is caused by attempting to divide by a width of 0 in tui_inject_newline_into_command_window.  The width is 0 because the windows are not fully initialized during the debuginfod prompt.

To fix this we could simply raise the debuginfod prompt at the very beginning of tui_enable_command when debuginfod 'ask' is set.  Otherwise a fix might involve more intricate changes to tui's initialization.

(In reply to Tom Tromey from comment #1)
> I sort of wish the debuginfod 'ask' approach didn't even exist.
> It would fix this bug for one thing.

Agreed, I'd prefer a simple text notice instead of the y/n prompt.  Something like, "This GDB will auto-download debuginfo from the following URLs... To disable, use the commmand 'set debuginfod enabled off' or add this command to .gdbinit."

The prompt was originally motivated by debuginfod getting enabled by default in Fedora.  The idea was to give users an additional chance to opt out.  I think now there is generally less of a need for this much notice since debuginfod has been around for a while and users are more familiar with it.

Plus when the .gdb_index downloading feature that's currently under review [1] gets merged, there will be much less for gdb to download at start up.  Since the cost to leaving debuginfod accidentally enabled will be significantly reduced, it should be ok to replace the prompt with a notice IMO.

[1] https://sourceware.org/pipermail/gdb-patches/2024-January/205953.html
Comment 3 Aaron Merey 2024-03-12 21:57:47 UTC
I posted a patch for this PR:

https://sourceware.org/pipermail/gdb-patches/2024-March/207224.html