From: Pedro Alves <palves@redhat.com>
To: Simon Marchi <simon.marchi@polymtl.ca>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 3/5] dwarf2read.c: Make dir_index and file_name_index strong typedefs
Date: Tue, 04 Apr 2017 18:54:00 -0000 [thread overview]
Message-ID: <879a6d0d-93a5-21db-aeb6-673bf3961c61@redhat.com> (raw)
In-Reply-To: <bdb989bd0be163890db3d02b0931664a@polymtl.ca>
On 03/29/2017 04:35 PM, Simon Marchi wrote:
> On 2017-03-28 22:24, Pedro Alves wrote:
>> @@ -1169,7 +1179,7 @@ file_entry::include_dir (const line_header *lh)
>> const
>> {
>> /* lh->include_dirs is 0-based, but the directory index numbers in
>> the statement program are 1-based. */
>> - return lh->include_dir_at (dir_index - 1);
>> + return lh->include_dir_at (to_underlying (d_index) - 1);
>
> Should include_dir_at's parameter be a dir_index? At this point,
> exposing a zero based index in the line_header interface is exposing its
> internal implementation. Same for file_name_at.
You're right. I don't know what I was thinking...
Thanks, here's what I'm squashing before pushing.
From 2ee1360f37c05080f2d1084a458b7218cdaffc2b Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Tue, 4 Apr 2017 19:31:12 +0100
Subject: [PATCH] index
---
gdb/dwarf2read.c | 36 +++++++++++++++++++++---------------
1 file changed, 21 insertions(+), 15 deletions(-)
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index cd137c9..f18c072 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -1112,22 +1112,30 @@ struct line_header
void add_file_name (const char *name, dir_index d_index,
unsigned int mod_time, unsigned int length);
- /* Return the include dir at INDEX (0-based). Returns NULL if INDEX
+ /* Return the include dir at INDEX (1-based). Returns NULL if INDEX
is out of bounds. */
- const char *include_dir_at (unsigned int index) const
+ const char *include_dir_at (dir_index index) const
{
- if (index >= include_dirs.size ())
+ /* Convert directory index number (1-based) to vector index
+ (0-based). */
+ size_t vec_index = to_underlying (index) - 1;
+
+ if (vec_index >= include_dirs.size ())
return NULL;
- return include_dirs[index];
+ return include_dirs[vec_index];
}
- /* Return the file name at INDEX (0-based). Returns NULL if INDEX
+ /* Return the file name at INDEX (1-based). Returns NULL if INDEX
is out of bounds. */
- file_entry *file_name_at (unsigned int index)
+ file_entry *file_name_at (file_name_index index)
{
- if (index >= file_names.size ())
+ /* Convert file name index number (1-based) to vector index
+ (0-based). */
+ size_t vec_index = to_underlying (index) - 1;
+
+ if (vec_index >= file_names.size ())
return NULL;
- return &file_names[index];
+ return &file_names[vec_index];
}
/* Const version of the above. */
@@ -1177,9 +1185,7 @@ typedef std::unique_ptr<line_header> line_header_up;
const char *
file_entry::include_dir (const line_header *lh) const
{
- /* lh->include_dirs is 0-based, but the directory index numbers in
- the statement program are 1-based. */
- return lh->include_dir_at (to_underlying (d_index) - 1);
+ return lh->include_dir_at (d_index);
}
/* When we construct a partial symbol table entry we only
@@ -18053,7 +18059,7 @@ struct lnp_state_machine
{
/* lh->file_names is 0-based, but the file name numbers in the
statement program are 1-based. */
- return the_line_header->file_name_at (to_underlying (file) - 1);
+ return the_line_header->file_name_at (file);
}
/* The line number header. */
@@ -18885,11 +18891,11 @@ new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
cu);
if (attr)
{
- unsigned int file_index = DW_UNSND (attr);
+ file_name_index file_index = (file_name_index) DW_UNSND (attr);
struct file_entry *fe;
- if (cu->line_header != NULL && file_index > 0)
- fe = cu->line_header->file_name_at (file_index - 1);
+ if (cu->line_header != NULL)
+ fe = cu->line_header->file_name_at (file_index);
else
fe = NULL;
--
2.5.5
next prev parent reply other threads:[~2017-04-04 18:54 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-29 2:25 [PATCH 0/5] dwarf2read.c: Some C++fycation Pedro Alves
2017-03-29 2:25 ` [PATCH 5/5] dwarf2read.c: C++fy lnp_state_machine Pedro Alves
2017-03-29 2:25 ` [PATCH 3/5] dwarf2read.c: Make dir_index and file_name_index strong typedefs Pedro Alves
2017-03-29 15:36 ` Simon Marchi
2017-04-04 18:54 ` Pedro Alves [this message]
2017-04-04 19:06 ` Pedro Alves
2017-03-29 2:25 ` [PATCH 1/5] dwarf2read.c: Some C++fycation, use std::vector, std::unique_ptr Pedro Alves
[not found] ` <ef286ec115c7c1986e41dd08ecf14fcf@polymtl.ca>
2017-04-04 18:57 ` Pedro Alves
2017-03-29 2:25 ` [PATCH 2/5] gdb::optional: Add observers Pedro Alves
2017-03-29 2:32 ` [PATCH 4/5] Make sect_offset and cu_offset strong typedefs instead of structs Pedro Alves
2017-03-29 15:46 ` Simon Marchi
2017-04-05 15:13 ` Pedro Alves
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=879a6d0d-93a5-21db-aeb6-673bf3961c61@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@polymtl.ca \
/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