[3/5] dwarf2read.c: Make dir_index and file_name_index strong typedefs
Commit Message
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(-)
@@ -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;