From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id uGP8GTfU8GVLaQQAWB0awg (envelope-from ) for ; Tue, 12 Mar 2024 18:16:23 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=NizwxzPu; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 641C81E0D2; Tue, 12 Mar 2024 18:16:23 -0400 (EDT) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 4722D1E030 for ; Tue, 12 Mar 2024 18:16:21 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D1FBB3857C7D for ; Tue, 12 Mar 2024 22:16:20 +0000 (GMT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id CF7B13858C3A for ; Tue, 12 Mar 2024 22:15:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CF7B13858C3A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CF7B13858C3A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710281755; cv=none; b=dFM8jdcEHYa/K4xFfQEcIQPwQK0BZO0f4UDHMCf6LUqG/PrZgz2B7MBV0Qtqk1lEI/uBblCra2V07r3/fbfN7umf1+uidR+tHxHJyxacTwiioSBXfD+oBFIIXkHmuAIePoN3fRYfrXQvYWG9GJCRn3s9rkh79S8ARlbqUOkF9+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710281755; c=relaxed/simple; bh=BoPkh5OtANWtF5XSfYEsoNDuEE4hVX4q7L3YsQ2zYfA=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=jOKvnfsaQCTCusdazpaHk+2hy3t+OK+tA+pX51LLHRRlI9upXxsUdMapZeM0NA5vBA6B1nvKuuzaYRKAPjDvvJ1F1tHAGmknltjFIObdG1Vzz2ImDM6zErc55RYNG0Fqjx8cOxEIT/uFrMM7Y99k+8fuT78bsT0JcYFOeQSx1QE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710281747; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=z8q4XMse4t5OIeRPHFL6gBhHovcuo+xsBlQ8gKpZx8o=; b=NizwxzPugloydT3P3NKMisSUgXWf+n4+Esa+GQHo9upO9ep0wViM/pEr759OfAo4+4o2W1 t0hLiEwqZKi3dkOqNCV3TTnKAmuHxUIViQrQ4P/dOtQ0xI7RSNpreFkNZRk+gFq3re+Ype f44fTv2jSC+UH4ZokjJafQs7XF/QhdI= Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-127-e2ASCW4hP62xEZW6LeQ9pQ-1; Tue, 12 Mar 2024 18:15:45 -0400 X-MC-Unique: e2ASCW4hP62xEZW6LeQ9pQ-1 Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-1dd916d7d55so3612255ad.2 for ; Tue, 12 Mar 2024 15:15:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710281744; x=1710886544; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=z8q4XMse4t5OIeRPHFL6gBhHovcuo+xsBlQ8gKpZx8o=; b=FQpKqeowZPqojHGFf5suPam9a7OplDFnSDoIE0PRtmBPNQyZHkYxfjkt1a4mI8y4sS gcw5eUU9O6quBL+KUc4NwBzzRVuztfRZLggHJ8MeQkBQ1QW8IttW4uHN3egDj1NNAfJK aCLjrj5mYOaRLPkoza/HuMS1AxTT7WhO5N1G0lHmi/p8s8CnGwX99QyGnDimS+XulFzY VaAtMgdjVvaicRlFEKHoBuO6ECo52aIQjr4Au/Z5dPQRZOYvEMKkbZlWQnGypMCFSzVd ftljntHZrITmSUo3XECphxhEZcKPi8oIjmEEvgmdUVSXnxTM04DL3t+dMPtZpB7UAFbL TTXA== X-Gm-Message-State: AOJu0Yz/e/k+UtdnTCNJkxWPRL4iOzZzxfJlZduhruswO+RIjw2iQ276 yDTcf9MtuiXyJWVBgeeSRNAHknHwj9m5Fd51oY+yuQVcA1M4af6XscNc/OLzLcOMikTgDePHZdR baWasG+kJqsQqdOfC5TL6gpeyqCcVZK/gQp6c3V5ZmFiVwvCvQ1UjmDpVKU9TKtieMWzKDQSXNx wHcilE6XAMqxEurhFrrk0A/7+SPmCVs4Tc+PmOaXTT X-Received: by 2002:a17:902:ecc8:b0:1dc:81a4:4c73 with SMTP id a8-20020a170902ecc800b001dc81a44c73mr1958112plh.0.1710281744241; Tue, 12 Mar 2024 15:15:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHwzdNGSyYpeIE7dj7akmuKHukf/dLkguV+0OmyGt4wwwhwaOt8esClvEpwgkMZ2D4DTUsP9dfnOERm6Y/hKGk= X-Received: by 2002:a17:902:ecc8:b0:1dc:81a4:4c73 with SMTP id a8-20020a170902ecc800b001dc81a44c73mr1958078plh.0.1710281743611; Tue, 12 Mar 2024 15:15:43 -0700 (PDT) MIME-Version: 1.0 References: <20240117154855.2057850-1-amerey@redhat.com> <20240117154855.2057850-5-amerey@redhat.com> In-Reply-To: From: Aaron Merey Date: Tue, 12 Mar 2024 18:15:32 -0400 Message-ID: Subject: [PING*3][PATCH 4/4 v6] gdb/debuginfod: Add .debug_line downloading To: gdb-patches@sourceware.org Cc: Andrew Burgess , Thiago Jung Bauermann X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_WEB, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Ping Thanks, Aaron On Thu, Feb 22, 2024 at 5:23=E2=80=AFPM Aaron Merey wro= te: > > Ping > > Thanks, > Aaron > > On Wed, Feb 7, 2024 at 4:25=E2=80=AFPM Aaron Merey wr= ote: > > > > Ping, > > > > Thanks, > > Aaron > > > > On Wed, Jan 17, 2024 at 10:49=E2=80=AFAM Aaron Merey wrote: > > > > > > v6 adds a testcase for downloads during autocompletion. It also > > > implements the suggestions from Thiago's review: > > > https://sourceware.org/pipermail/gdb-patches/2023-December/205507.htm= l > > > > > > ELF/DWARF section downloading allows gdb to download .gdb_index files= in > > > order to defer full debuginfo downloads. However .gdb_index does not > > > contain any information regarding source filenames. When a gdb comma= nd > > > includes a filename argument (ex. 'break main.c:50'), this results in > > > the mass downloading of all deferred debuginfo so that gdb can search= the > > > debuginfo for matching source filenames. This can result in unnecess= ary > > > downloads. > > > > > > To improve this, have gdb instead download each debuginfo's .debug_li= ne > > > (and .debug_line_str if using DWARF5) when executing these commands. > > > Download full debuginfo only when its .debug_line contains a matching > > > filename. > > > > > > Since the combined size of .debug_line and .debug_line_str is only ab= out > > > 1% the size of the corresponding debuginfo, significant time can be s= aved > > > by checking these sections before choosing to download an entire debu= ginfo. > > > > > > This patch also redirects stdout and stderr of the debuginfod server > > > used by testsuite/gdb.debuginfod tests to a server_log standard outpu= t > > > file. While adding tests for this patch I ran into an issue where th= e > > > test server would block when logging to stderr, presumably because th= e > > > stderr buffer filled up and wasn't being read from. Redirecting the > > > log to a file fixes this and also makes the server log more accessibl= e > > > when debugging test failures. > > > --- > > > gdb/cli-out.c | 11 +- > > > gdb/completer.c | 18 +- > > > gdb/dwarf2/line-header.c | 161 ++++++++++++------ > > > gdb/dwarf2/line-header.h | 10 ++ > > > gdb/dwarf2/read-gdb-index.c | 60 +++++++ > > > gdb/dwarf2/read.c | 208 +++++++++++++++++++++= ++ > > > gdb/dwarf2/read.h | 37 ++++ > > > gdb/mi/mi-out.c | 9 +- > > > gdb/testsuite/gdb.debuginfod/section.exp | 27 +++ > > > gdb/ui-out.c | 3 + > > > gdb/ui-out.h | 20 +++ > > > 11 files changed, 511 insertions(+), 53 deletions(-) > > > > > > diff --git a/gdb/cli-out.c b/gdb/cli-out.c > > > index b4c7a657423..79f61eed62c 100644 > > > --- a/gdb/cli-out.c > > > +++ b/gdb/cli-out.c > > > @@ -307,16 +307,23 @@ cli_ui_out::do_progress_notify (const std::stri= ng &msg, > > > > > > if (info.state =3D=3D progress_update::START) > > > { > > > + std::string prefix; > > > + if (cur_prefix_state =3D=3D prefix_state_t::NEWLINE_NEEDED) > > > + { > > > + prefix =3D "\n"; > > > + cur_prefix_state =3D prefix_state_t::NEWLINE_PRINTED; > > > + } > > > + > > > if (stream->isatty () > > > && current_ui->input_interactive_p () > > > && chars_per_line >=3D MIN_CHARS_PER_LINE) > > > { > > > - gdb_printf (stream, "%s\n", msg.c_str ()); > > > + gdb_printf (stream, "%s\n", (prefix + msg).c_str ()); > > > info.state =3D progress_update::BAR; > > > } > > > else > > > { > > > - gdb_printf (stream, "%s...\n", msg.c_str ()); > > > + gdb_printf (stream, "%s...\n", (prefix + msg).c_str ()); > > > info.state =3D progress_update::WORKING; > > > } > > > } > > > diff --git a/gdb/completer.c b/gdb/completer.c > > > index 8e2f031f13a..6d453d0d197 100644 > > > --- a/gdb/completer.c > > > +++ b/gdb/completer.c > > > @@ -1362,6 +1362,10 @@ complete_line_internal_1 (completion_tracker &= tracker, > > > { > > > /* We've recognized a full command. */ > > > > > > + /* Disable pagination since responding to the pagination promp= t > > > + overwrites rl_line_buffer. */ > > > + scoped_restore pag_restore =3D make_scoped_restore (&paginatio= n_enabled, false); > > > + > > > if (p =3D=3D tmp_command + point) > > > { > > > /* There is no non-whitespace in the line beyond the > > > @@ -1461,7 +1465,8 @@ complete_line_internal_1 (completion_tracker &t= racker, > > > } > > > > > > /* Wrapper around complete_line_internal_1 to handle > > > - MAX_COMPLETIONS_REACHED_ERROR. */ > > > + MAX_COMPLETIONS_REACHED_ERROR and possible progress update > > > + interactions. */ > > > > > > static void > > > complete_line_internal (completion_tracker &tracker, > > > @@ -1469,6 +1474,11 @@ complete_line_internal (completion_tracker &tr= acker, > > > const char *line_buffer, int point, > > > complete_line_internal_reason reason) > > > { > > > + scoped_restore restore_prefix_state > > > + =3D make_scoped_restore > > > + (&cur_prefix_state, > > > + ui_out::progress_update::prefix_state::NEWLINE_NEEDED); > > > + > > > try > > > { > > > complete_line_internal_1 (tracker, text, line_buffer, point, r= eason); > > > @@ -1478,6 +1488,12 @@ complete_line_internal (completion_tracker &tr= acker, > > > if (except.error !=3D MAX_COMPLETIONS_REACHED_ERROR) > > > throw; > > > } > > > + > > > + /* If progress update messages printed, then the text being comple= ted > > > + needs to be printed again. */ > > > + if (cur_prefix_state > > > + =3D=3D ui_out::progress_update::prefix_state::NEWLINE_PRINTED) > > > + rl_forced_update_display (); > > > } > > > > > > /* See completer.h. */ > > > diff --git a/gdb/dwarf2/line-header.c b/gdb/dwarf2/line-header.c > > > index ddaf7e4a527..aec02b3e1f7 100644 > > > --- a/gdb/dwarf2/line-header.c > > > +++ b/gdb/dwarf2/line-header.c > > > @@ -102,12 +102,15 @@ read_checked_initial_length_and_offset (bfd *ab= fd, const gdb_byte *buf, > > > { > > > LONGEST length =3D read_initial_length (abfd, buf, bytes_read); > > > > > > - gdb_assert (cu_header->initial_length_size =3D=3D 4 > > > - || cu_header->initial_length_size =3D=3D 8 > > > - || cu_header->initial_length_size =3D=3D 12); > > > + if (cu_header !=3D nullptr) > > > + { > > > + gdb_assert (cu_header->initial_length_size =3D=3D 4 > > > + || cu_header->initial_length_size =3D=3D 8 > > > + || cu_header->initial_length_size =3D=3D 12); > > > > > > - if (cu_header->initial_length_size !=3D *bytes_read) > > > - complaint (_("intermixed 32-bit and 64-bit DWARF sections")); > > > + if (cu_header->initial_length_size !=3D *bytes_read) > > > + complaint (_("intermixed 32-bit and 64-bit DWARF sections")); > > > + } > > > > > > *offset_size =3D (*bytes_read =3D=3D 4) ? 4 : 8; > > > return length; > > > @@ -116,21 +119,27 @@ read_checked_initial_length_and_offset (bfd *ab= fd, const gdb_byte *buf, > > > /* Read directory or file name entry format, starting with byte of > > > format count entries, ULEB128 pairs of entry formats, ULEB128 of > > > entries count and the entries themselves in the described entry > > > - format. */ > > > + format. > > > + > > > + .debug_line and .debug_line_str sections are stored in LINE_BUFP > > > + and LINE_STR_DATA respectively. */ > > > > > > static void > > > -read_formatted_entries (dwarf2_per_objfile *per_objfile, bfd *abfd, > > > - const gdb_byte **bufp, struct line_header *lh= , > > > - unsigned int offset_size, > > > - void (*callback) (struct line_header *lh, > > > - const char *name, > > > - dir_index d_index, > > > - unsigned int mod_time, > > > - unsigned int length)) > > > +read_formatted_entries > > > + (bfd *abfd, const gdb_byte **line_bufp, > > > + const gdb::array_view line_str_data, > > > + struct line_header *lh, > > > + unsigned int offset_size, > > > + void (*callback) (struct line_header *lh, > > > + const char *name, > > > + dir_index d_index, > > > + unsigned int mod_time, > > > + unsigned int length)) > > > { > > > gdb_byte format_count, formati; > > > ULONGEST data_count, datai; > > > - const gdb_byte *buf =3D *bufp; > > > + const gdb_byte *buf =3D *line_bufp; > > > + const gdb_byte *str_buf =3D line_str_data.data (); > > > const gdb_byte *format_header_data; > > > unsigned int bytes_read; > > > > > > @@ -157,7 +166,7 @@ read_formatted_entries (dwarf2_per_objfile *per_o= bjfile, bfd *abfd, > > > ULONGEST content_type =3D read_unsigned_leb128 (abfd, forma= t, &bytes_read); > > > format +=3D bytes_read; > > > > > > - ULONGEST form =3D read_unsigned_leb128 (abfd, format, &byt= es_read); > > > + ULONGEST form =3D read_unsigned_leb128 (abfd, format, &byte= s_read); > > > format +=3D bytes_read; > > > > > > std::optional string; > > > @@ -172,12 +181,24 @@ read_formatted_entries (dwarf2_per_objfile *per= _objfile, bfd *abfd, > > > > > > case DW_FORM_line_strp: > > > { > > > - const char *str > > > - =3D per_objfile->read_line_string (buf, offset_size= ); > > > + if (line_str_data.empty ()) > > > + warning (_("Dwarf Error: DW_FORM_line_strp used wit= hout " \ > > > + "required section")); > > > + > > > + if (line_str_data.size () <=3D offset_size) > > > + warning (_("Dwarf Error: DW_FORM_line_strp pointing= outside " \ > > > + "of section .debug_line_str")); > > > + > > > + ULONGEST str_offset =3D read_offset (abfd, buf, offse= t_size); > > > + const char *str; > > > + if (str_buf[str_offset] =3D=3D '\0') > > > + str =3D nullptr; > > > + else > > > + str =3D (const char *) (str_buf + str_offset); > > > string.emplace (str); > > > buf +=3D offset_size; > > > + break; > > > } > > > - break; > > > > > > case DW_FORM_data1: > > > uint.emplace (read_1_byte (abfd, buf)); > > > @@ -248,28 +269,30 @@ read_formatted_entries (dwarf2_per_objfile *per= _objfile, bfd *abfd, > > > callback (lh, fe.name, fe.d_index, fe.mod_time, fe.length); > > > } > > > > > > - *bufp =3D buf; > > > + *line_bufp =3D buf; > > > } > > > > > > /* See line-header.h. */ > > > > > > line_header_up > > > -dwarf_decode_line_header (sect_offset sect_off, bool is_dwz, > > > - dwarf2_per_objfile *per_objfile, > > > - struct dwarf2_section_info *section, > > > - const struct comp_unit_head *cu_header, > > > - const char *comp_dir) > > > +dwarf_decode_line_header (bfd *abfd, > > > + gdb::array_view line_data, > > > + gdb::array_view line_str_da= ta, > > > + const gdb_byte **debug_line_ptr, > > > + bool is_dwz, > > > + const struct comp_unit_head *cu_header, > > > + const char *comp_dir) > > > { > > > - const gdb_byte *line_ptr; > > > + const gdb_byte *line_ptr, *buf; > > > unsigned int bytes_read, offset_size; > > > int i; > > > const char *cur_dir, *cur_file; > > > > > > - bfd *abfd =3D section->get_bfd_owner (); > > > + buf =3D *debug_line_ptr; > > > > > > /* Make sure that at least there's room for the total_length field= . > > > That could be 12 bytes long, but we're just going to fudge that= . */ > > > - if (to_underlying (sect_off) + 4 >=3D section->size) > > > + if (buf + 4 >=3D line_data.data () + line_data.size ()) > > > { > > > dwarf2_statement_list_fits_in_line_number_section_complaint ()= ; > > > return 0; > > > @@ -277,24 +300,26 @@ dwarf_decode_line_header (sect_offset sect_off= , bool is_dwz, > > > > > > line_header_up lh (new line_header (comp_dir)); > > > > > > - lh->sect_off =3D sect_off; > > > + lh->sect_off =3D (sect_offset) (buf - line_data.data ()); > > > lh->offset_in_dwz =3D is_dwz; > > > > > > - line_ptr =3D section->buffer + to_underlying (sect_off); > > > + line_ptr =3D buf; > > > > > > /* Read in the header. */ > > > LONGEST unit_length > > > - =3D read_checked_initial_length_and_offset (abfd, line_ptr, cu_h= eader, > > > + =3D read_checked_initial_length_and_offset (abfd, buf, cu_header= , > > > &bytes_read, &offset_si= ze); > > > - line_ptr +=3D bytes_read; > > > > > > - const gdb_byte *start_here =3D line_ptr; > > > + line_ptr +=3D bytes_read; > > > > > > - if (line_ptr + unit_length > (section->buffer + section->size)) > > > + if (line_ptr + unit_length > buf + line_data.size ()) > > > { > > > dwarf2_statement_list_fits_in_line_number_section_complaint ()= ; > > > return 0; > > > } > > > + > > > + const gdb_byte *start_here =3D line_ptr; > > > + > > > lh->statement_program_end =3D start_here + unit_length; > > > lh->version =3D read_2_bytes (abfd, line_ptr); > > > line_ptr +=3D 2; > > > @@ -303,7 +328,7 @@ dwarf_decode_line_header (sect_offset sect_off, = bool is_dwz, > > > /* This is a version we don't understand. The format could ha= ve > > > changed in ways we don't handle properly so just punt. */ > > > complaint (_("unsupported version in .debug_line section")); > > > - return NULL; > > > + return nullptr; > > > } > > > if (lh->version >=3D 5) > > > { > > > @@ -320,13 +345,14 @@ dwarf_decode_line_header (sect_offset sect_off= , bool is_dwz, > > > complaint (_("unsupported segment selector size %u " > > > "in .debug_line section"), > > > segment_selector_size); > > > - return NULL; > > > + return nullptr; > > > } > > > } > > > > > > LONGEST header_length =3D read_offset (abfd, line_ptr, offset_size= ); > > > line_ptr +=3D offset_size; > > > lh->statement_program_start =3D line_ptr + header_length; > > > + > > > lh->minimum_instruction_length =3D read_1_byte (abfd, line_ptr); > > > line_ptr +=3D 1; > > > > > > @@ -347,12 +373,16 @@ dwarf_decode_line_header (sect_offset sect_off= , bool is_dwz, > > > > > > lh->default_is_stmt =3D read_1_byte (abfd, line_ptr); > > > line_ptr +=3D 1; > > > + > > > lh->line_base =3D read_1_signed_byte (abfd, line_ptr); > > > line_ptr +=3D 1; > > > + > > > lh->line_range =3D read_1_byte (abfd, line_ptr); > > > line_ptr +=3D 1; > > > + > > > lh->opcode_base =3D read_1_byte (abfd, line_ptr); > > > line_ptr +=3D 1; > > > + > > > lh->standard_opcode_lengths.reset (new unsigned char[lh->opcode_ba= se]); > > > > > > lh->standard_opcode_lengths[0] =3D 1; /* This should never be use= d anyway. */ > > > @@ -365,21 +395,23 @@ dwarf_decode_line_header (sect_offset sect_off= , bool is_dwz, > > > if (lh->version >=3D 5) > > > { > > > /* Read directory table. */ > > > - read_formatted_entries (per_objfile, abfd, &line_ptr, lh.get (= ), > > > - offset_size, > > > - [] (struct line_header *header, const c= har *name, > > > - dir_index d_index, unsigned int mod= _time, > > > - unsigned int length) > > > + read_formatted_entries > > > + (abfd, &line_ptr, line_str_data, > > > + lh.get (), offset_size, > > > + [] (struct line_header *header, const char *name, > > > + dir_index d_index, unsigned int mod_time, > > > + unsigned int length) > > > { > > > header->add_include_dir (name); > > > }); > > > > > > /* Read file name table. */ > > > - read_formatted_entries (per_objfile, abfd, &line_ptr, lh.get (= ), > > > - offset_size, > > > - [] (struct line_header *header, const c= har *name, > > > - dir_index d_index, unsigned int mod= _time, > > > - unsigned int length) > > > + read_formatted_entries > > > + (abfd, &line_ptr, line_str_data, > > > + lh.get (), offset_size, > > > + [] (struct line_header *header, const char *name, > > > + dir_index d_index, unsigned int mod_time, > > > + unsigned int length) > > > { > > > header->add_file_name (name, d_index, mod_time, length); > > > }); > > > @@ -387,7 +419,7 @@ dwarf_decode_line_header (sect_offset sect_off, = bool is_dwz, > > > else > > > { > > > /* Read directory table. */ > > > - while ((cur_dir =3D read_direct_string (abfd, line_ptr, &bytes= _read)) !=3D NULL) > > > + while ((cur_dir =3D read_direct_string (abfd, line_ptr, &bytes= _read)) !=3D nullptr) > > > { > > > line_ptr +=3D bytes_read; > > > lh->add_include_dir (cur_dir); > > > @@ -395,7 +427,7 @@ dwarf_decode_line_header (sect_offset sect_off, = bool is_dwz, > > > line_ptr +=3D bytes_read; > > > > > > /* Read file name table. */ > > > - while ((cur_file =3D read_direct_string (abfd, line_ptr, &byte= s_read)) !=3D NULL) > > > + while ((cur_file =3D read_direct_string (abfd, line_ptr, &byte= s_read)) !=3D nullptr) > > > { > > > unsigned int mod_time, length; > > > dir_index d_index; > > > @@ -413,9 +445,40 @@ dwarf_decode_line_header (sect_offset sect_off,= bool is_dwz, > > > line_ptr +=3D bytes_read; > > > } > > > > > > - if (line_ptr > (section->buffer + section->size)) > > > + if (line_ptr > (buf + line_data.size ())) > > > complaint (_("line number info header doesn't " > > > "fit in `.debug_line' section")); > > > > > > + *debug_line_ptr +=3D unit_length + offset_size; > > > return lh; > > > } > > > + > > > +line_header_up > > > +dwarf_decode_line_header (sect_offset sect_off, bool is_dwz, > > > + dwarf2_per_objfile *per_objfile, > > > + struct dwarf2_section_info *section, > > > + const struct comp_unit_head *cu_header, > > > + const char *comp_dir) > > > +{ > > > + struct objfile *objfile =3D per_objfile->objfile; > > > + struct dwarf2_per_bfd *per_bfd =3D per_objfile->per_bfd; > > > + > > > + /* Read .debug_line. */ > > > + dwarf2_section_info *line_sec =3D &per_bfd->line; > > > + bfd_size_type line_size =3D line_sec->get_size (objfile); > > > + > > > + gdb::array_view line (line_sec->buffer, line_size)= ; > > > + > > > + /* Read .debug_line_str. */ > > > + dwarf2_section_info *line_str_sec =3D &per_bfd->line_str; > > > + bfd_size_type line_str_size =3D line_str_sec->get_size (objfile); > > > + > > > + gdb::array_view line_str (line_str_sec->buffer, > > > + line_str_size); > > > + > > > + const gdb_byte *line_ptr =3D line.data () + to_underlying (sect_of= f); > > > + > > > + return dwarf_decode_line_header > > > + (per_bfd->obfd, line, line_str, &line_ptr, > > > + is_dwz, cu_header, comp_dir); > > > +} > > > diff --git a/gdb/dwarf2/line-header.h b/gdb/dwarf2/line-header.h > > > index 06d2eec573b..1dffb7c7e5e 100644 > > > --- a/gdb/dwarf2/line-header.h > > > +++ b/gdb/dwarf2/line-header.h > > > @@ -217,4 +217,14 @@ extern line_header_up dwarf_decode_line_header > > > struct dwarf2_section_info *section, const struct comp_unit_head = *cu_header, > > > const char *comp_dir); > > > > > > +/* Like above but the .debug_line and .debug_line_str are stored in > > > + LINE_DATA and LINE_STR_DATA. *DEBUG_LINE_PTR should point to a > > > + statement program header within LINE_DATA. */ > > > + > > > +extern line_header_up dwarf_decode_line_header > > > + (bfd *abfd, gdb::array_view line_data, > > > + gdb::array_view line_str_data, > > > + const gdb_byte **debug_line_ptr, bool is_dwz, > > > + const comp_unit_head *cu_header, const char *comp_dir); > > > + > > > #endif /* DWARF2_LINE_HEADER_H */ > > > diff --git a/gdb/dwarf2/read-gdb-index.c b/gdb/dwarf2/read-gdb-index.= c > > > index 55b04391eb5..3d75678d7dc 100644 > > > --- a/gdb/dwarf2/read-gdb-index.c > > > +++ b/gdb/dwarf2/read-gdb-index.c > > > @@ -131,6 +131,9 @@ struct mapped_gdb_index final : public mapped_ind= ex_base > > > } > > > }; > > > > > > +struct mapped_debug_line; > > > +typedef std::unique_ptr mapped_debug_line_up; > > > + > > > struct dwarf2_gdb_index : public dwarf2_base_index_functions > > > { > > > /* This dumps minimal information about the index. > > > @@ -162,6 +165,15 @@ struct dwarf2_gdb_index : public dwarf2_base_ind= ex_functions > > > domain_enum domain, > > > enum search_domain kind); > > > > > > + /* If OBJFILE's debuginfo download has been deferred, use a mapped_= debug_line > > > + to generate filenames. > > > + > > > + Otherwise call dwarf2_base_index_functions::map_symbol_filenames= . */ > > > + > > > + void map_symbol_filenames (struct objfile *objfile, > > > + gdb::function_view fun, > > > + bool need_fullname) override; > > > + > > > /* Calls dwarf2_base_index_functions::expand_all_symtabs and downl= oads > > > debuginfo if necessary. */ > > > void expand_all_symtabs (struct objfile *objfile) override; > > > @@ -169,6 +181,15 @@ struct dwarf2_gdb_index : public dwarf2_base_ind= ex_functions > > > /* Calls dwarf2_base_index_functions::find_last_source_symtab and = downloads > > > debuginfo if necessary. */ > > > struct symtab *find_last_source_symtab (struct objfile *objfile) o= verride; > > > + > > > + /* Filename information related to this .gdb_index. */ > > > + mapped_debug_line_up mdl; > > > + > > > + /* Return true if any of the filenames in this .gdb_index's .debug= _line > > > + mapping match FILE_MATCHER. Initializes the mapping if necessa= ry. */ > > > + bool filename_in_debug_line > > > + (objfile *objfile, > > > + gdb::function_view file_matc= her); > > > }; > > > > > > void > > > @@ -204,6 +225,30 @@ dwarf2_gdb_index::find_last_source_symtab (struc= t objfile *objfile) > > > } > > > } > > > > > > +void > > > +dwarf2_gdb_index::map_symbol_filenames > > > + (struct objfile *objfile, > > > + gdb::function_view fun, > > > + bool need_fullname) > > > +{ > > > + try > > > + { > > > + dwarf2_base_index_functions::map_symbol_filenames (objfile, fu= n, > > > + need_fullnam= e); > > > + } > > > + catch (const gdb_exception &e) > > > + { > > > + if ((objfile->flags & OBJF_DOWNLOAD_DEFERRED) =3D=3D 0) > > > + exception_print (gdb_stderr, e); > > > + else > > > + { > > > + if (mdl =3D=3D nullptr) > > > + mdl.reset (new mapped_debug_line (objfile)); > > > + mdl->map_filenames (fun, need_fullname); > > > + } > > > + } > > > +} > > > + > > > /* This dumps minimal information about the index. > > > It is called via "mt print objfiles". > > > One use is to verify .gdb_index has been loaded by the > > > @@ -371,6 +416,17 @@ dwarf2_gdb_index::do_expand_symtabs_matching > > > return result; > > > } > > > > > > +bool > > > +dwarf2_gdb_index::filename_in_debug_line > > > + (objfile *objfile, > > > + gdb::function_view file_matche= r) > > > +{ > > > + if (mdl =3D=3D nullptr) > > > + mdl.reset (new mapped_debug_line (objfile)); > > > + > > > + return mdl->contains_matching_filename (file_matcher); > > > +} > > > + > > > bool > > > dwarf2_gdb_index::expand_symtabs_matching > > > (struct objfile *objfile, > > > @@ -399,6 +455,10 @@ dwarf2_gdb_index::expand_symtabs_matching > > > return false; > > > } > > > > > > + if (file_matcher !=3D nullptr > > > + && !filename_in_debug_line (objfile, file_matcher)) > > > + return true; > > > + > > > read_full_dwarf_from_debuginfod (objfile, this); > > > return true; > > > } > > > diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c > > > index 8725a2fbcdb..4af83728c63 100644 > > > --- a/gdb/dwarf2/read.c > > > +++ b/gdb/dwarf2/read.c > > > @@ -82,6 +82,7 @@ > > > #include > > > #include "gdbsupport/underlying.h" > > > #include "gdbsupport/hash_enum.h" > > > +#include "gdbsupport/scoped_mmap.h" > > > #include "filename-seen-cache.h" > > > #include "producer.h" > > > #include > > > @@ -1950,6 +1951,213 @@ dw2_get_file_names (dwarf2_per_cu_data *this_= cu, > > > return this_cu->file_names; > > > } > > > > > > +#if !HAVE_SYS_MMAN_H > > > + > > > +bool > > > +mapped_debug_line::contains_matching_filename > > > + (gdb::function_view file_matche= r) > > > +{ > > > + return false; > > > +} > > > + > > > +gdb::array_view > > > +mapped_debug_line::read_debug_line_separate > > > + (const char *filename, std::unique_ptr *reso= urce) > > > +{ > > > + return {}; > > > +} > > > + > > > +bool > > > +mapped_debug_line::read_debug_line_from_debuginfod (objfile *objfile= ) > > > +{ > > > + return false; > > > +} > > > + > > > +void > > > +mapped_debug_line::map_filenames > > > + (gdb::function_view fun, > > > + bool need_fullname) > > > +{ > > > + return; > > > +} > > > + > > > +#else /* !HAVE_SYS_MMAN_H */ > > > + > > > +struct line_resource_mmap final : public index_cache_resource > > > +{ > > > + /* Try to mmap FILENAME. Throw an exception on failure, including= if the > > > + file doesn't exist. */ > > > + line_resource_mmap (const char *filename) > > > + : mapping (mmap_file (filename)) > > > + {} > > > + > > > + scoped_mmap mapping; > > > +}; > > > + > > > +/* See read.h. */ > > > + > > > +bool > > > +mapped_debug_line::contains_matching_filename > > > + (gdb::function_view file_matche= r) > > > +{ > > > + for (line_header_up &lh : line_headers) > > > + for (file_entry &fe : lh->file_names ()) > > > + { > > > + const char *filename =3D fe.name; > > > + > > > + if (file_matcher (fe.name, false)) > > > + return true; > > > + > > > + bool basename_match =3D file_matcher (lbasename (fe.name), tr= ue); > > > + > > > + if (!basenames_may_differ && !basename_match) > > > + continue; > > > + > > > + /* DW_AT_comp_dir is not explicitly mentioned in the .debug_l= ine > > > + until DWARF5. Since we don't have access to the CU at thi= s > > > + point we just check for a partial match on the filename. > > > + If there is a match, the full debuginfo will be downloaded > > > + ane the match will be re-evalute with DW_AT_comp_dir. */ > > > + if (lh->version < 5 && fe.d_index =3D=3D 0) > > > + return basename_match; > > > + > > > + const char *dirname =3D fe.include_dir (&*lh); > > > + std::string fullname; > > > + > > > + if (dirname =3D=3D nullptr || IS_ABSOLUTE_PATH (filename)) > > > + fullname =3D filename; > > > + else > > > + fullname =3D std::string (dirname) + SLASH_STRING + filenam= e; > > > + > > > + gdb::unique_xmalloc_ptr rewritten > > > + =3D rewrite_source_path (fullname.c_str ()); > > > + if (rewritten !=3D nullptr) > > > + fullname =3D rewritten.release (); > > > + > > > + if (file_matcher (fullname.c_str (), false)) > > > + return true; > > > + } > > > + > > > + return false; > > > +} > > > + > > > +/* See read.h. */ > > > + > > > +void > > > +mapped_debug_line::map_filenames > > > + (gdb::function_view fun, > > > + bool need_fullname) > > > +{ > > > + for (line_header_up &lh : line_headers) > > > + for (file_entry &fe : lh->file_names ()) > > > + { > > > + const char *filename =3D fe.name; > > > + > > > + if (!need_fullname) > > > + { > > > + fun (filename, nullptr); > > > + continue; > > > + } > > > + > > > + const char *dirname =3D fe.include_dir (&*lh); > > > + std::string fullname; > > > + > > > + if (dirname =3D=3D nullptr || IS_ABSOLUTE_PATH (filename)) > > > + fullname =3D filename; > > > + else > > > + fullname =3D std::string (dirname) + SLASH_STRING + filenam= e; > > > + > > > + gdb::unique_xmalloc_ptr rewritten > > > + =3D rewrite_source_path (fullname.c_str ()); > > > + if (rewritten !=3D nullptr) > > > + fullname =3D rewritten.release (); > > > + > > > + fun (filename, fullname.c_str ()); > > > + } > > > +} > > > + > > > +/* See read.h. */ > > > + > > > +gdb::array_view > > > +mapped_debug_line::read_debug_line_separate > > > + (const char *filename, std::unique_ptr *reso= urce) > > > +{ > > > + if (filename =3D=3D nullptr) > > > + return {}; > > > + > > > + try > > > + { > > > + line_resource_mmap *mmap_resource > > > + =3D new line_resource_mmap (filename); > > > + > > > + resource->reset (mmap_resource); > > > + > > > + return gdb::array_view > > > + ((const gdb_byte *) mmap_resource->mapping.get (), > > > + mmap_resource->mapping.size ()); > > > + } > > > + catch (const gdb_exception &except) > > > + { > > > + exception_print (gdb_stderr, except); > > > + } > > > + > > > + return {}; > > > +} > > > + > > > +/* See read.h. */ > > > + > > > +bool > > > +mapped_debug_line::read_debug_line_from_debuginfod (objfile *objfile= ) > > > +{ > > > + const bfd_build_id *build_id =3D build_id_bfd_get (objfile->obfd.g= et ()); > > > + if (build_id =3D=3D nullptr) > > > + return false; > > > + > > > + gdb::unique_xmalloc_ptr line_path; > > > + scoped_fd line_fd =3D debuginfod_section_query (build_id->data, > > > + build_id->size, > > > + bfd_get_filename > > > + (objfile->obfd.get = ()), > > > + ".debug_line", > > > + &line_path); > > > + > > > + if (line_fd.get () < 0) > > > + return false; > > > + > > > + gdb::unique_xmalloc_ptr line_str_path; > > > + scoped_fd line_str_fd =3D debuginfod_section_query (build_id->data= , > > > + build_id->size, > > > + bfd_get_filename > > > + (objfile->obfd.= get ()), > > > + ".debug_line_str"= , > > > + &line_str_path); > > > + > > > + line_data =3D read_debug_line_separate (line_path.get (), &line_re= source); > > > + line_str_data =3D read_debug_line_separate (line_str_path.get (), > > > + &line_str_resource); > > > + > > > + const gdb_byte *line_ptr =3D line_data.data (); > > > + > > > + while (line_ptr < line_data.data () + line_data.size ()) > > > + { > > > + line_header_up lh > > > + =3D dwarf_decode_line_header (objfile->obfd.get (), > > > + line_data, line_str_data, > > > + &line_ptr, false, > > > + nullptr, nullptr); > > > + line_headers.emplace_back (std::move (lh)); > > > + } > > > + > > > + return true; > > > +} > > > +#endif /* !HAVE_SYS_MMAN_H */ > > > + > > > +mapped_debug_line::mapped_debug_line (objfile *objfile) > > > +{ > > > + if (!read_debug_line_from_debuginfod (objfile)) > > > + line_headers.clear (); > > > +} > > > + > > > /* A helper for the "quick" functions which computes and caches the > > > real path for a given file name from the line table. */ > > > > > > diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h > > > index 8b6f1864458..db16160b43e 100644 > > > --- a/gdb/dwarf2/read.h > > > +++ b/gdb/dwarf2/read.h > > > @@ -33,6 +33,7 @@ > > > #include "gdbsupport/hash_enum.h" > > > #include "gdbsupport/function-view.h" > > > #include "gdbsupport/packed.h" > > > +#include "dwarf2/line-header.h" > > > > > > /* Hold 'maintenance (set|show) dwarf' commands. */ > > > extern struct cmd_list_element *set_dwarf_cmdlist; > > > @@ -982,4 +983,40 @@ extern htab_up create_quick_file_names_table (un= signed int nr_initial_entries); > > > extern void read_full_dwarf_from_debuginfod (struct objfile *, > > > dwarf2_base_index_functi= ons *); > > > > > > +struct mapped_debug_line > > > +{ > > > + mapped_debug_line (objfile *objfile); > > > + > > > + /* Return true if any of the mapped .debug_line's filenames match > > > + FILE_MATCHER. */ > > > + > > > + bool contains_matching_filename > > > + (gdb::function_view file_matc= her); > > > + > > > + /* Call FUN with each filename in this mapped .debug_line. Includ= e > > > + each file's fullname if NEED_FULLNAME is true. */ > > > + > > > + void map_filenames (gdb::function_view fun, > > > + bool need_fullname); > > > + > > > +private: > > > + std::vector line_headers; > > > + > > > + gdb::array_view line_data; > > > + gdb::array_view line_str_data; > > > + > > > + std::unique_ptr line_resource; > > > + std::unique_ptr line_str_resource; > > > + > > > + /* Download the .debug_line and .debug_line_str associated with OB= JFILE > > > + and populate line_headers. */ > > > + > > > + bool read_debug_line_from_debuginfod (objfile *objfile); > > > + > > > + /* Initialize line_data and line_str_data with the .debug_line and > > > + .debug_line_str downloaded read_debug_line_from_debuginfod. */ > > > + > > > + gdb::array_view read_debug_line_separate > > > + (const char *filename, std::unique_ptr *re= source); > > > +}; > > > #endif /* DWARF2READ_H */ > > > diff --git a/gdb/mi/mi-out.c b/gdb/mi/mi-out.c > > > index 0bc13f963bc..ab955a0fc05 100644 > > > --- a/gdb/mi/mi-out.c > > > +++ b/gdb/mi/mi-out.c > > > @@ -278,7 +278,14 @@ mi_ui_out::do_progress_notify (const std::string= &msg, const char *unit, > > > > > > if (info.state =3D=3D progress_update::START) > > > { > > > - gdb_printf ("%s...\n", msg.c_str ()); > > > + std::string prefix; > > > + if (cur_prefix_state =3D=3D prefix_state_t::NEWLINE_NEEDED) > > > + { > > > + prefix =3D "\n"; > > > + cur_prefix_state =3D prefix_state_t::NEWLINE_PRINTED; > > > + } > > > + > > > + gdb_printf ("%s...\n", (prefix + msg).c_str ()); > > > info.state =3D progress_update::WORKING; > > > } > > > } > > > diff --git a/gdb/testsuite/gdb.debuginfod/section.exp b/gdb/testsuite= /gdb.debuginfod/section.exp > > > index c3872ecdfc9..3ac11152daa 100644 > > > --- a/gdb/testsuite/gdb.debuginfod/section.exp > > > +++ b/gdb/testsuite/gdb.debuginfod/section.exp > > > @@ -18,6 +18,7 @@ > > > standard_testfile > > > > > > load_lib debuginfod-support.exp > > > +load_lib completion-support.exp > > > > > > require allow_debuginfod_tests > > > > > > @@ -159,6 +160,32 @@ proc_with_prefix local_url { } { > > > # Hit the breakpoint. > > > set res ".*Breakpoint 2, libsection2_test.*\"In ${libfile2}\\\\n= \".*" > > > gdb_test "c" $res "break continue" > > > + > > > + clean_restart_with_prompt $sectexec "line 1" > > > + > > > + # List source file using .debug_line download. > > > + set res ".*\.debug_line.*$lib_sl1.*21.*extern void libsection2_t= est.*" > > > + gdb_test "list $libsrc1:21" $res "line 1 list" > > > + > > > + clean_restart_with_prompt $sectexec "line 2" > > > + > > > + # Set breakpoint using .debug_line download. > > > + set res ".*section \.debug_line for $lib_sl1.*Breakpoint 2 at.*$= libsrc1.*" > > > + gdb_test "br $libsrc1:41" $res "line 2 br" > > > + > > > + # Continue to breakpoint. > > > + set res "Breakpoint 2, libsection1_test.*\"Cancelling thread\\\\= n\".*" > > > + gdb_test "c" $res "line 2 continue" > > > + > > > + # Check that download progress message is correctly formatted > > > + # when printing threads. > > > + set res ".*separate debug info for $lib_sl2\.\.\.\r\n.* 2 Thr= ead.*" > > > + gdb_test "info thr" $res "line thread" > > > + > > > + clean_restart_with_prompt $sectexec "autocomplete" > > > + > > > + # Download debuginfo during autocompletion. > > > + test_gdb_complete_tab_unique "br lib" ".*Downloading separate de= bug.*" "" > > > } > > > > > > # Create CACHE and DB directories ready for debuginfod to use. > > > diff --git a/gdb/ui-out.c b/gdb/ui-out.c > > > index 75f9f1612cb..d9a620b70e8 100644 > > > --- a/gdb/ui-out.c > > > +++ b/gdb/ui-out.c > > > @@ -32,6 +32,9 @@ > > > #include > > > #include > > > > > > +/* Current state of newline prefixing for progress update messages. = */ > > > +prefix_state_t cur_prefix_state =3D prefix_state_t::NEWLINE_OFF; > > > + > > > namespace { > > > > > > /* A header of a ui_out_table. */ > > > diff --git a/gdb/ui-out.h b/gdb/ui-out.h > > > index 2934d3a6b34..2c21603f1a7 100644 > > > --- a/gdb/ui-out.h > > > +++ b/gdb/ui-out.h > > > @@ -296,6 +296,21 @@ class ui_out > > > BAR > > > }; > > > > > > + /* Used to communicate the status of a newline prefix for the ne= xt progress > > > + update message. */ > > > + enum prefix_state > > > + { > > > + /* Do not modify the next progress update message. */ > > > + NEWLINE_OFF, > > > + > > > + /* The next progress update message should include a newline p= refix. */ > > > + NEWLINE_NEEDED, > > > + > > > + /* A newline prefix was included in a debuginfod progress upda= te > > > + message. */ > > > + NEWLINE_PRINTED > > > + }; > > > + > > > /* SHOULD_PRINT indicates whether something should be printed fo= r a tty. */ > > > progress_update () > > > { > > > @@ -393,6 +408,11 @@ class ui_out > > > ui_out_level *current_level () const; > > > }; > > > > > > +typedef ui_out::progress_update::prefix_state prefix_state_t; > > > + > > > +/* Current state of the newline prefix. */ > > > +extern prefix_state_t cur_prefix_state; > > > + > > > /* Start a new tuple or list on construction, and end it on > > > destruction. Normally this is used via the typedefs > > > ui_out_emit_tuple and ui_out_emit_list. */ > > > -- > > > 2.43.0 > > >