From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id A4ED23858D35 for ; Tue, 23 May 2023 20:55:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A4ED23858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684875355; 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=cajKDNgLYQD4kzCNtD9LYmrc2ctwmc0lfmhKRJ9cS3A=; b=CO7eqTva0vAT4rAr1NWiIsoJIRs9wKeuwTHG+C7+V9KfPIV0I32kv5OCs2MSiTPk+zbK0k WmuWIzdKlyQVwsso6BgbuYOVbSjaKhErqYEcD7e0HAPlG+l/z5xV+ALOMP11lbkNfepHS6 qchqQnziHrHRwaLye1mfv37PsCV7JtU= Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-522-bRlle47cMvy7OiniQ1SBbQ-1; Tue, 23 May 2023 16:55:53 -0400 X-MC-Unique: bRlle47cMvy7OiniQ1SBbQ-1 Received: by mail-pj1-f72.google.com with SMTP id 98e67ed59e1d1-25374bd718eso72927a91.1 for ; Tue, 23 May 2023 13:55:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684875352; x=1687467352; 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=cajKDNgLYQD4kzCNtD9LYmrc2ctwmc0lfmhKRJ9cS3A=; b=KYaC51kx6Si8izIUWzE+51aRhTBBA4t/kfybjy4f6x9m6/gUnm5x6ssMhDTENoB8qP 7pXpux548UATEZHmmhzspxrqG9kCmM678eU1vFvy3d39eGhR2/jRxTUhB7RHmPfVS57a 5mtsTZsnU+0hwUB1SBaPj8cIpJGFmv5dJs3PA94arqhHeqnM6q1TgJBePr7AlZXGqS/O e0FnkRa/zEORlFIxwJop6GMcSBLv1UQhh09cLXD4+08Zg0lCf+fVLUWdzwo85G3KlS3h DWnjuzoWjqYHET/uc9oHQ3foqIb39tDbujwlMRs67fTSiLj+CK9EF5kpejrEIfgTHibS d6og== X-Gm-Message-State: AC+VfDzcII7RfeuPWaZOTi4rrhz6YJHSzkUfeCS5zW/1+lpsMov35uT4 JO0oPXm25BTj4ltJwVImzyMQhuVH19kq8lWd73l70Eq5+8Z75amT9v+pfYztOEtM2/SeSGM7a33 MHvNUVHT+uBfROS008mS3xamAeBwZQtde3+D18gMYn0dJ X-Received: by 2002:a17:90b:1bc7:b0:253:828a:28f8 with SMTP id oa7-20020a17090b1bc700b00253828a28f8mr14467607pjb.25.1684875352372; Tue, 23 May 2023 13:55:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5hAjGKNCS6561c5m9hoYu99AuvLErZk0M4fJOEktHQeJNxivu6R6rf0F2fDd6gj2Z7fsD4MQOI8wi2437zr1Q= X-Received: by 2002:a17:90b:1bc7:b0:253:828a:28f8 with SMTP id oa7-20020a17090b1bc700b00253828a28f8mr14467575pjb.25.1684875351691; Tue, 23 May 2023 13:55:51 -0700 (PDT) MIME-Version: 1.0 References: <20230417180743.1213952-1-amerey@redhat.com> In-Reply-To: From: Aaron Merey Date: Tue, 23 May 2023 16:55:40 -0400 Message-ID: Subject: Re: [PING*4][PATCH 7/7 v2] gdb/debuginfod: Add .debug_line downloading To: gdb-patches@sourceware.org Cc: Tom Tromey 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.2 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_MSPIKE_H2,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 List-Id: Ping Thanks, Aaron On Tue, May 16, 2023 at 10:50=E2=80=AFAM Aaron Merey wr= ote: > > Ping > > Thanks, > Aaron > > On Tue, May 9, 2023 at 9:49=E2=80=AFAM Aaron Merey wr= ote: > > > > Ping > > > > Thanks, > > Aaron > > > > On Tue, May 2, 2023 at 10:25=E2=80=AFAM Aaron Merey = wrote: > > > > > > Ping > > > > > > Thanks, > > > Aaron > > > > > > On Mon, Apr 17, 2023 at 2:07=E2=80=AFPM Aaron Merey wrote: > > > > > > > > v1 can be found here: > > > > https://sourceware.org/pipermail/gdb-patches/2023-February/197459.h= tml > > > > > > > > v2 merges dwarf_decode_line_header_separate with > > > > dwarf_decode_line_header and read_formatted_entries_separate with > > > > read_formatted_entries in order to reduce code duplication. > > > > > > > > --- > > > > > > > > 'set debuginfod enabled lazy' allows gdb to download .gdb_index fil= es in > > > > order to defer full debuginfo downloads. However .gdb_index does n= ot > > > > contain any information regarding source filenames. When a gdb com= mand > > > > includes a filename argument (ex. 'break main.c:50'), this results = in > > > > the mass downloading of all deferred debuginfo so gdb can search th= e > > > > debuginfo for matching source filenames. This can result in unnece= ssary > > > > downloading. > > > > > > > > To improve this, have gdb instead download each debuginfo's .debug_= line > > > > (and .debug_line_str if using DWARF5) when executing these commands= . > > > > Download full debuginfo only when its .debug_line contains a matchi= ng > > > > filename. > > > > > > > > Since the combined size of .debug_line and .debug_line_str is only = about > > > > 1% the size of the corresponding debuginfo, significant time can be= saved > > > > by checking these sections before choosing to download a deferred d= ebuginfo. > > > > --- > > > > gdb/dwarf2/line-header.c | 215 +++++++++++++++++++++++---------= ---- > > > > gdb/dwarf2/line-header.h | 10 ++ > > > > gdb/dwarf2/read-gdb-index.c | 27 +++++ > > > > gdb/dwarf2/read.c | 165 +++++++++++++++++++++++++++ > > > > gdb/dwarf2/read.h | 31 ++++++ > > > > 5 files changed, 371 insertions(+), 77 deletions(-) > > > > > > > > diff --git a/gdb/dwarf2/line-header.c b/gdb/dwarf2/line-header.c > > > > index 9d74c8fe75b..5eaff9c5a48 100644 > > > > --- a/gdb/dwarf2/line-header.c > > > > +++ b/gdb/dwarf2/line-header.c > > > > @@ -102,50 +102,57 @@ read_checked_initial_length_and_offset (bfd *= abfd, 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; > > > > } > > > > > > > > -/* Read directory or file name entry format, starting with byte of > > > > - format count entries, ULEB128 pairs of entry formats, ULEB128 o= f > > > > - entries count and the entries themselves in the described entry > > > > - format. */ > > > > + > > > > +/* Like read_formatted_entries but the .debug_line and .debug_line= _str > > > > + are stored in LINE_BUFP and LINE_STR_DATA. This is used for ca= ses > > > > + where these sections are read from separate files without neces= sarily > > > > + having access to the entire debuginfo file they originate from.= */ > > > > > > > > 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 *parent_bfd, 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; > > > > > > > > - format_count =3D read_1_byte (abfd, buf); > > > > + format_count =3D read_1_byte (parent_bfd, buf); > > > > buf +=3D 1; > > > > format_header_data =3D buf; > > > > for (formati =3D 0; formati < format_count; formati++) > > > > { > > > > - read_unsigned_leb128 (abfd, buf, &bytes_read); > > > > + read_unsigned_leb128 (parent_bfd, buf, &bytes_read); > > > > buf +=3D bytes_read; > > > > - read_unsigned_leb128 (abfd, buf, &bytes_read); > > > > + read_unsigned_leb128 (parent_bfd, buf, &bytes_read); > > > > buf +=3D bytes_read; > > > > } > > > > > > > > - data_count =3D read_unsigned_leb128 (abfd, buf, &bytes_read); > > > > + data_count =3D read_unsigned_leb128 (parent_bfd, buf, &bytes_rea= d); > > > > buf +=3D bytes_read; > > > > for (datai =3D 0; datai < data_count; datai++) > > > > { > > > > @@ -154,10 +161,10 @@ read_formatted_entries (dwarf2_per_objfile *p= er_objfile, bfd *abfd, > > > > > > > > for (formati =3D 0; formati < format_count; formati++) > > > > { > > > > - ULONGEST content_type =3D read_unsigned_leb128 (abfd, for= mat, &bytes_read); > > > > + ULONGEST content_type =3D read_unsigned_leb128 (parent_bf= d, format, &bytes_read); > > > > format +=3D bytes_read; > > > > > > > > - ULONGEST form =3D read_unsigned_leb128 (abfd, format, &b= ytes_read); > > > > + ULONGEST form =3D read_unsigned_leb128 (parent_bfd, form= at, &bytes_read); > > > > format +=3D bytes_read; > > > > > > > > gdb::optional string; > > > > @@ -166,36 +173,48 @@ read_formatted_entries (dwarf2_per_objfile *p= er_objfile, bfd *abfd, > > > > switch (form) > > > > { > > > > case DW_FORM_string: > > > > - string.emplace (read_direct_string (abfd, buf, &bytes= _read)); > > > > + string.emplace (read_direct_string (parent_bfd, buf, = &bytes_read)); > > > > buf +=3D bytes_read; > > > > break; > > > > > > > > case DW_FORM_line_strp: > > > > { > > > > - const char *str > > > > - =3D per_objfile->read_line_string (buf, offset_si= ze); > > > > + if (line_str_data.empty ()) > > > > + error (_("Dwarf Error: DW_FORM_line_strp used wit= hout " \ > > > > + "required section")); > > > > + if (line_str_data.size () <=3D offset_size) > > > > + error (_("Dwarf Error: DW_FORM_line_strp pointing= outside " \ > > > > + "of section .debug_line")); > > > > + > > > > + ULONGEST str_offset =3D read_offset (parent_bfd, bu= f, offset_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)); > > > > + uint.emplace (read_1_byte (parent_bfd, buf)); > > > > buf +=3D 1; > > > > break; > > > > > > > > case DW_FORM_data2: > > > > - uint.emplace (read_2_bytes (abfd, buf)); > > > > + uint.emplace (read_2_bytes (parent_bfd, buf)); > > > > buf +=3D 2; > > > > break; > > > > > > > > case DW_FORM_data4: > > > > - uint.emplace (read_4_bytes (abfd, buf)); > > > > + uint.emplace (read_4_bytes (parent_bfd, buf)); > > > > buf +=3D 4; > > > > break; > > > > > > > > case DW_FORM_data8: > > > > - uint.emplace (read_8_bytes (abfd, buf)); > > > > + uint.emplace (read_8_bytes (parent_bfd, buf)); > > > > buf +=3D 8; > > > > break; > > > > > > > > @@ -205,7 +224,7 @@ read_formatted_entries (dwarf2_per_objfile *per= _objfile, bfd *abfd, > > > > break; > > > > > > > > case DW_FORM_udata: > > > > - uint.emplace (read_unsigned_leb128 (abfd, buf, &bytes= _read)); > > > > + uint.emplace (read_unsigned_leb128 (parent_bfd, buf, = &bytes_read)); > > > > buf +=3D bytes_read; > > > > break; > > > > > > > > @@ -244,28 +263,30 @@ read_formatted_entries (dwarf2_per_objfile *p= er_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 *parent_bfd, > > > > + gdb::array_view line_data= , > > > > + gdb::array_view line_str_= data, > > > > + 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 fie= ld. > > > > That could be 12 bytes long, but we're just going to fudge th= at. */ > > > > - 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; > > > > @@ -273,62 +294,65 @@ dwarf_decode_line_header (sect_offset sect_o= ff, 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= _header, > > > > + =3D read_checked_initial_length_and_offset (parent_bfd, buf, c= u_header, > > > > &bytes_read, &offset_= size); > > > > - 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); > > > > + lh->version =3D read_2_bytes (parent_bfd, line_ptr); > > > > line_ptr +=3D 2; > > > > if (lh->version > 5) > > > > { > > > > /* This is a version we don't understand. The format could = have > > > > 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) > > > > { > > > > gdb_byte segment_selector_size; > > > > > > > > /* Skip address size. */ > > > > - read_1_byte (abfd, line_ptr); > > > > + read_1_byte (parent_bfd, line_ptr); > > > > line_ptr +=3D 1; > > > > > > > > - segment_selector_size =3D read_1_byte (abfd, line_ptr); > > > > + segment_selector_size =3D read_1_byte (parent_bfd, line_ptr)= ; > > > > line_ptr +=3D 1; > > > > if (segment_selector_size !=3D 0) > > > > { > > > > 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_si= ze); > > > > + LONGEST header_length =3D read_offset (parent_bfd, line_ptr, off= set_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); > > > > + > > > > + lh->minimum_instruction_length =3D read_1_byte (parent_bfd, line= _ptr); > > > > line_ptr +=3D 1; > > > > > > > > if (lh->version >=3D 4) > > > > { > > > > - lh->maximum_ops_per_instruction =3D read_1_byte (abfd, line_= ptr); > > > > + lh->maximum_ops_per_instruction =3D read_1_byte (parent_bfd,= line_ptr); > > > > line_ptr +=3D 1; > > > > } > > > > else > > > > @@ -341,41 +365,47 @@ dwarf_decode_line_header (sect_offset sect_o= ff, bool is_dwz, > > > > "in `.debug_line' section")); > > > > } > > > > > > > > - lh->default_is_stmt =3D read_1_byte (abfd, line_ptr); > > > > + lh->default_is_stmt =3D read_1_byte (parent_bfd, line_ptr); > > > > line_ptr +=3D 1; > > > > - lh->line_base =3D read_1_signed_byte (abfd, line_ptr); > > > > + > > > > + lh->line_base =3D read_1_signed_byte (parent_bfd, line_ptr); > > > > line_ptr +=3D 1; > > > > - lh->line_range =3D read_1_byte (abfd, line_ptr); > > > > + > > > > + lh->line_range =3D read_1_byte (parent_bfd, line_ptr); > > > > line_ptr +=3D 1; > > > > - lh->opcode_base =3D read_1_byte (abfd, line_ptr); > > > > + > > > > + lh->opcode_base =3D read_1_byte (parent_bfd, line_ptr); > > > > line_ptr +=3D 1; > > > > + > > > > lh->standard_opcode_lengths.reset (new unsigned char[lh->opcode_= base]); > > > > > > > > lh->standard_opcode_lengths[0] =3D 1; /* This should never be u= sed anyway. */ > > > > for (i =3D 1; i < lh->opcode_base; ++i) > > > > { > > > > - lh->standard_opcode_lengths[i] =3D read_1_byte (abfd, line_p= tr); > > > > + lh->standard_opcode_lengths[i] =3D read_1_byte (parent_bfd, = line_ptr); > > > > line_ptr +=3D 1; > > > > } > > > > > > > > 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= char *name, > > > > - dir_index d_index, unsigned int m= od_time, > > > > - unsigned int length) > > > > + read_formatted_entries > > > > + (parent_bfd, &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= char *name, > > > > - dir_index d_index, unsigned int m= od_time, > > > > - unsigned int length) > > > > + read_formatted_entries > > > > + (parent_bfd, &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); > > > > }); > > > > @@ -383,7 +413,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, &byt= es_read)) !=3D NULL) > > > > + while ((cur_dir =3D read_direct_string (parent_bfd, line_ptr= , &bytes_read)) !=3D nullptr) > > > > { > > > > line_ptr +=3D bytes_read; > > > > lh->add_include_dir (cur_dir); > > > > @@ -391,17 +421,17 @@ dwarf_decode_line_header (sect_offset sect_o= ff, bool is_dwz, > > > > line_ptr +=3D bytes_read; > > > > > > > > /* Read file name table. */ > > > > - while ((cur_file =3D read_direct_string (abfd, line_ptr, &by= tes_read)) !=3D NULL) > > > > + while ((cur_file =3D read_direct_string (parent_bfd, line_pt= r, &bytes_read)) !=3D nullptr) > > > > { > > > > unsigned int mod_time, length; > > > > dir_index d_index; > > > > > > > > line_ptr +=3D bytes_read; > > > > - d_index =3D (dir_index) read_unsigned_leb128 (abfd, line_= ptr, &bytes_read); > > > > + d_index =3D (dir_index) read_unsigned_leb128 (parent_bfd,= line_ptr, &bytes_read); > > > > line_ptr +=3D bytes_read; > > > > - mod_time =3D read_unsigned_leb128 (abfd, line_ptr, &bytes= _read); > > > > + mod_time =3D read_unsigned_leb128 (parent_bfd, line_ptr, = &bytes_read); > > > > line_ptr +=3D bytes_read; > > > > - length =3D read_unsigned_leb128 (abfd, line_ptr, &bytes_r= ead); > > > > + length =3D read_unsigned_leb128 (parent_bfd, line_ptr, &b= ytes_read); > > > > line_ptr +=3D bytes_read; > > > > > > > > lh->add_file_name (cur_file, d_index, mod_time, length); > > > > @@ -409,9 +439,40 @@ dwarf_decode_line_header (sect_offset sect_of= f, 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_siz= e); > > > > + > > > > + /* 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_= off); > > > > + > > > > + 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 59a42e336f5..44e32828ddb 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_hea= d *cu_header, > > > > const char *comp_dir); > > > > > > > > +/* Like above but the .debug_line and .debug_line_str are stored i= n > > > > + 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 *parent_bfd, 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-inde= x.c > > > > index 895fbede7c2..fe33f23fdfa 100644 > > > > --- a/gdb/dwarf2/read-gdb-index.c > > > > +++ b/gdb/dwarf2/read-gdb-index.c > > > > @@ -128,6 +128,9 @@ struct mapped_gdb_index final : public mapped_i= ndex_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. > > > > @@ -179,6 +182,15 @@ struct dwarf2_gdb_index : public dwarf2_base_i= ndex_functions > > > > /* Calls dwarf2_base_index_functions::find_last_source_symtab an= d downloads > > > > debuginfo if necessary. */ > > > > struct symtab *find_last_source_symtab (struct objfile *objfile)= override; > > > > + > > > > + /* Filename information related to this .gdb_index. */ > > > > + mapped_debug_line_up mdl; > > > > + > > > > + /* Return true if any of the filenames in this .gdb_index's .deb= ug_line > > > > + mapping match FILE_MATCHER. Initializes the mapping if neces= sary. */ > > > > + bool filename_in_debug_line > > > > + (objfile *objfile, > > > > + gdb::function_view file_matc= her); > > > > }; > > > > > > > > void > > > > @@ -588,6 +600,17 @@ dwarf2_gdb_index::do_expand_symtabs_matching > > > > return result; > > > > } > > > > > > > > +bool > > > > +dwarf2_gdb_index::filename_in_debug_line > > > > + (objfile *objfile, > > > > + gdb::function_view file_matc= her) > > > > +{ > > > > + 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, > > > > @@ -616,6 +639,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 e561ec035e7..39ee56d7204 100644 > > > > --- a/gdb/dwarf2/read.c > > > > +++ b/gdb/dwarf2/read.c > > > > @@ -81,6 +81,7 @@ > > > > #include "gdbsupport/gdb_optional.h" > > > > #include "gdbsupport/underlying.h" > > > > #include "gdbsupport/hash_enum.h" > > > > +#include "gdbsupport/scoped_mmap.h" > > > > #include "filename-seen-cache.h" > > > > #include "producer.h" > > > > #include > > > > @@ -2110,6 +2111,170 @@ dw2_get_file_names (dwarf2_per_cu_data *thi= s_cu, > > > > return this_cu->file_names; > > > > } > > > > > > > > +#if !HAVE_SYS_MMAN_H > > > > + > > > > +bool > > > > +mapped_debug_line::contains_matching_filename > > > > + (gdb::function_view file_matc= her) > > > > +{ > > > > + return false; > > > > +} > > > > + > > > > +gdb::array_view > > > > +mapped_debug_line::read_debug_line_separate > > > > + (char *filename, std::unique_ptr *resource= ) > > > > +{ > > > > + return {}; > > > > +} > > > > + > > > > +bool > > > > +mapped_debug_line::read_debug_line_from_debuginfod (objfile *objfi= le) > > > > +{ > > > > + return false; > > > > +} > > > > + > > > > +#else /* !HAVE_SYS_MMAN_H */ > > > > + > > > > +struct line_resource_mmap final : public index_cache_resource > > > > +{ > > > > + /* Try to mmap FILENAME. Throw an exception on failure, includi= ng 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_matc= her) > > > > +{ > > > > + 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), = true); > > > > + > > > > + if (!basenames_may_differ && !basename_match) > > > > + continue; > > > > + > > > > + /* DW_AT_comp_dir is not explicitly mentioned in the .debug= _line > > > > + until DWARF5. Since we don't have access to the CU at t= his > > > > + point we just check for a partial match on the filename. > > > > + If there is a match, the full debuginfo will be download= ed > > > > + 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 + filen= ame; > > > > + > > > > + 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. */ > > > > + > > > > +gdb::array_view > > > > +mapped_debug_line::read_debug_line_separate > > > > + (char *filename, std::unique_ptr *resource= ) > > > > +{ > > > > + 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 *objfi= le) > > > > +{ > > > > + const bfd_build_id *build_id =3D build_id_bfd_get (objfile->obfd= .get ()); > > > > + 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.ge= t ()), > > > > + ".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->da= ta, > > > > + build_id->size, > > > > + bfd_get_filenam= e > > > > + (objfile->obf= d.get ()), > > > > + ".debug_line_st= r", > > > > + &line_str_path)= ; > > > > + > > > > + line_data =3D read_debug_line_separate (line_path.get (), &line_= resource); > > > > + 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 (lh.release ()); > > > > + } > > > > + > > > > + 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 th= e > > > > real path for a given file name from the line table. */ > > > > > > > > diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h > > > > index e3131693b81..b8a8b76bde0 100644 > > > > --- a/gdb/dwarf2/read.h > > > > +++ b/gdb/dwarf2/read.h > > > > @@ -34,6 +34,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; > > > > @@ -952,4 +953,34 @@ extern bool read_addrmap_from_aranges (dwarf2_= per_objfile *per_objfile, > > > > extern void read_full_dwarf_from_debuginfod (struct objfile *, > > > > dwarf2_base_index_func= tions *); > > > > > > > > +struct mapped_debug_line > > > > +{ > > > > + mapped_debug_line (objfile *objfile); > > > > + > > > > + /* Return true if any of the mapped .debug_line's filenames matc= h > > > > + FILE_MATCHER. */ > > > > + > > > > + bool contains_matching_filename > > > > + (gdb::function_view file_ma= tcher); > > > > + > > > > +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 = OBJFILE > > > > + and populate line_headers. */ > > > > + > > > > + bool read_debug_line_from_debuginfod (objfile *objfile); > > > > + > > > > + /* Initialize line_data and line_str_data with the .debug_line a= nd > > > > + .debug_line_str downloaded read_debug_line_from_debuginfod. *= / > > > > + > > > > + gdb::array_view read_debug_line_separate > > > > + (char *filename, std::unique_ptr *resour= ce); > > > > +}; > > > > #endif /* DWARF2READ_H */ > > > > -- > > > > 2.39.2 > > > >