From: Simon Marchi <simon.marchi@polymtl.ca>
To: Ali Tamur <tamur@google.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] DWARF 5 support: Handle line table and file indexes
Date: Wed, 16 Oct 2019 03:04:00 -0000 [thread overview]
Message-ID: <99f8963b76221d747d0564919217a2eb@polymtl.ca> (raw)
In-Reply-To: <20191015201927.60124-1-tamur@google.com>
On 2019-10-15 16:19, Ali Tamur wrote:
>> > -enum class file_name_index : unsigned int {};
>> > +typedef int file_name_index;
>>
>> Is there a reason you changed these? Â The reason why these were of
>> enum
>> class type (or "strong typedef") still seems valid to me. Â We don't
>> want
>> some code accessing the vectors blindy using these indices, so it
>> encourages people to use the right accessor method instead.
> I respectfully disagree. We do "index - 1" calculation in file_name_at
> and
> include_dir_at methods. If we are going to cast back and forth to
> integers
> anyways, having an enum loses its appeal.
Ok, I guess that if we access the vector through these accessor
functions, it should be safe.
I'd still suggest adding a gdb_assert to verify that in the case of
DWARF <= 4, index should be > 0.
> @@ -11717,16 +11735,16 @@ dwarf2_cu::setup_type_unit_groups (struct
> die_info *die)
> process_full_type_unit still needs to know if this is the first
> time. */
>
> - tu_group->num_symtabs = line_header->file_names.size ();
> + tu_group->num_symtabs = line_header->file_names_size ();
> tu_group->symtabs = XNEWVEC (struct symtab *,
> - line_header->file_names.size ());
> + line_header->file_names_size ());
>
> - for (i = 0; i < line_header->file_names.size (); ++i)
> + auto &file_names = line_header->file_names ();
> + for (i = 0; i < file_names.size (); ++i)
> {
> - file_entry &fe = line_header->file_names[i];
> -
> - dwarf2_start_subfile (this, fe.name,
> - fe.include_dir (line_header));
> + file_entry *fe = &file_names[i];
In these various loops, the `fe` variable can stay a reference, unless
there's a specific reason why you changed them to pointers.
> @@ -20286,9 +20304,9 @@ line_header::add_include_dir (const char
> *include_dir)
> {
> if (dwarf_line_debug >= 2)
> fprintf_unfiltered (gdb_stdlog, "Adding dir %zu: %s\n",
> - include_dirs.size () + 1, include_dir);
> + m_include_dirs.size () + 1, include_dir);
I think this debug message showing the index should be 0 based in
DWARF5, and 1 based before.
>
> - include_dirs.push_back (include_dir);
> + m_include_dirs.push_back (include_dir);
> }
>
> void
> @@ -20299,9 +20317,9 @@ line_header::add_file_name (const char *name,
> {
> if (dwarf_line_debug >= 2)
> fprintf_unfiltered (gdb_stdlog, "Adding file %u: %s\n",
> - (unsigned) file_names.size () + 1, name);
> + (unsigned) file_names_size () + 1, name);
Likewise.
> @@ -20651,18 +20677,17 @@ dwarf_decode_line_header (sect_offset
> sect_off, struct dwarf2_cu *cu)
> Returns NULL if FILE_INDEX should be ignored, i.e., it is
> pst->filename. */
>
> static const char *
> -psymtab_include_file_name (const struct line_header *lh, int
> file_index,
> +psymtab_include_file_name (const struct line_header *lh, const
> file_entry *fe,
Pass `fe` by const reference instead?
> @@ -21367,13 +21392,14 @@ dwarf_decode_lines (struct line_header *lh,
> const char *comp_dir,
>
> /* Now that we're done scanning the Line Header Program, we can
> create the psymtab of each included file. */
> - for (file_index = 0; file_index < lh->file_names.size ();
> file_index++)
> - if (lh->file_names[file_index].included_p == 1)
> + auto &file_names = lh->file_names ();
> + for (file_index = 0; file_index < file_names.size ();
> file_index++)
> + if (file_names[file_index].included_p == 1)
Whenever you can iterate using a range-for (when you don't need the
iteration index), please do so:
for (const file_entry &fe : lh->file_names ())
{
...
}
Simon
next prev parent reply other threads:[~2019-10-16 3:04 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-01 4:53 Ali Tamur via gdb-patches
2019-10-02 1:52 ` Ali Tamur via gdb-patches
2019-10-08 1:05 ` Ali Tamur via gdb-patches
2019-10-10 3:14 ` Simon Marchi
2019-10-15 20:19 ` Ali Tamur via gdb-patches
2019-10-16 3:04 ` Simon Marchi [this message]
2019-10-18 19:31 ` Ali Tamur via gdb-patches
2019-10-21 5:55 ` Simon Marchi
2019-10-21 19:47 ` Ali Tamur via gdb-patches
2019-10-21 20:07 ` Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=99f8963b76221d747d0564919217a2eb@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=gdb-patches@sourceware.org \
--cc=tamur@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox