From patchwork Tue Apr 4 18:54:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 19847 Received: (qmail 13289 invoked by alias); 4 Apr 2017 18:54:51 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 13243 invoked by uid 89); 4 Apr 2017 18:54:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=pushing, sk:include X-HELO: mail-wr0-f173.google.com Received: from mail-wr0-f173.google.com (HELO mail-wr0-f173.google.com) (209.85.128.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 04 Apr 2017 18:54:47 +0000 Received: by mail-wr0-f173.google.com with SMTP id w43so220961216wrb.0 for ; Tue, 04 Apr 2017 11:54:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=w0fBKhx+lYQcvxoYk8no2lyCtcrEu9yIP7qDuSSZmU8=; b=PhB4tXoX4X5MK10/kdA+z/TrS3nxhZjRejDhuC2rKrRqsIZ4pwAZzPYgXKRsmLObMO Sdky1Beuf0XOazQOUVAPnchtYRLdKygQvHEmst7MfSRFFd5hP+90lV17mPfDFhre2WVI xMp/OtYxSuKbLPF9oAn7X4E0g4An33TGb6yj1EBjGgeNm/TObJpRFYQuXIMqfoab4PRA gQLjPYDPVQmRI4BlwdzuXbPu90L3ZguBL/uFuT2xjehoWEQk8Rz92OdYoZnPD0Id6pC8 P0bL+TNZjXIT9xZFSttZbTrXw/kk+zhb1Qo3/8yqec+avw1eIK0rxpf7N3demB1eZpE1 mo3Q== X-Gm-Message-State: AFeK/H2twcfm5R3Z74YydmeFJTCYsPU5nswFOFK/ZkNwSp9vHs8R1I/Q+Uf5NXIkwHuyXLqr X-Received: by 10.223.152.237 with SMTP id w100mr22741512wrb.72.1491332086965; Tue, 04 Apr 2017 11:54:46 -0700 (PDT) Received: from [192.168.43.236] ([95.69.91.145]) by smtp.gmail.com with ESMTPSA id w85sm19384903wmw.1.2017.04.04.11.54.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Apr 2017 11:54:46 -0700 (PDT) Subject: Re: [PATCH 3/5] dwarf2read.c: Make dir_index and file_name_index strong typedefs To: Simon Marchi References: <1490754298-9455-1-git-send-email-palves@redhat.com> <1490754298-9455-4-git-send-email-palves@redhat.com> Cc: gdb-patches@sourceware.org From: Pedro Alves Message-ID: <879a6d0d-93a5-21db-aeb6-673bf3961c61@redhat.com> Date: Tue, 4 Apr 2017 19:54:44 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: 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 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_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;