From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 35491 invoked by alias); 7 Mar 2019 13:10:51 -0000 Mailing-List: contact dwz-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Post: List-Help: List-Subscribe: Sender: dwz-owner@sourceware.org Received: (qmail 35478 invoked by uid 89); 7 Mar 2019 13:10:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.100.2 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.1 spammy= X-Spam-Status: No, score=-25.7 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on sourceware.org X-Spam-Level: X-HELO: mx1.suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Date: Tue, 01 Jan 2019 00:00:00 -0000 From: Tom de Vries To: dwz@sourceware.org, jakub@redhat.com Subject: [PATCH, 1/2] Factor out skip_attr Message-ID: <20190307131127.GA6319@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-SW-Source: 2019-q1/txt/msg00099.txt.bz2 Hi, This patch factors out new function skip_attr. OK for trunk? Thanks, - Tom Factor out skip_attr 2019-02-05 Tom de Vries * dwz.c (skip_attr): Factor out of ... (get_AT, skip_attrs): ... here. --- dwz.c | 216 +++++++++++++++++++++++++----------------------------------------- 1 file changed, 82 insertions(+), 134 deletions(-) diff --git a/dwz.c b/dwz.c index 476807a..e4e5d5c 100644 --- a/dwz.c +++ b/dwz.c @@ -1227,6 +1227,82 @@ off_htab_lookup (dw_cu_ref cu, unsigned int die_offset) return (dw_die_ref) htab_find_with_hash (off_htab, &die, die_offset); } +/* Return pointer after the attribute ATTR of a die in CU which starts at + PTR. */ +static inline unsigned char * +skip_attr (dw_cu_ref cu, struct abbrev_attr *attr, unsigned char *ptr) +{ + uint32_t form = attr->form; + size_t len = 0; + + while (form == DW_FORM_indirect) + form = read_uleb128 (ptr); + switch (form) + { + case DW_FORM_ref_addr: + ptr += cu->cu_version == 2 ? ptr_size : 4; + break; + case DW_FORM_addr: + ptr += ptr_size; + break; + case DW_FORM_flag_present: + break; + case DW_FORM_ref1: + case DW_FORM_flag: + case DW_FORM_data1: + ++ptr; + break; + case DW_FORM_ref2: + case DW_FORM_data2: + ptr += 2; + break; + case DW_FORM_ref4: + case DW_FORM_data4: + case DW_FORM_sec_offset: + case DW_FORM_strp: + ptr += 4; + break; + case DW_FORM_ref8: + case DW_FORM_data8: + case DW_FORM_ref_sig8: + ptr += 8; + break; + case DW_FORM_sdata: + case DW_FORM_ref_udata: + case DW_FORM_udata: + read_uleb128 (ptr); + break; + case DW_FORM_string: + ptr = (unsigned char *) strchr ((char *)ptr, '\0') + 1; + break; + case DW_FORM_indirect: + abort (); + case DW_FORM_block1: + len = *ptr++; + break; + case DW_FORM_block2: + len = read_16 (ptr); + form = DW_FORM_block1; + break; + case DW_FORM_block4: + len = read_32 (ptr); + form = DW_FORM_block1; + break; + case DW_FORM_block: + case DW_FORM_exprloc: + len = read_uleb128 (ptr); + form = DW_FORM_block1; + break; + default: + abort (); + } + + if (form == DW_FORM_block1) + ptr += len; + + return ptr; +} + /* Return a pointer at which DIE's attribute AT is encoded, and fill in its form into *FORMP. Return NULL if the attribute is not present. */ static unsigned char * @@ -1246,78 +1322,17 @@ get_AT (dw_die_ref die, enum dwarf_attribute at, enum dwarf_form *formp) read_uleb128 (ptr); for (i = 0; i < t->nattr; ++i) { - uint32_t form = t->attr[i].form; - size_t len = 0; - - while (form == DW_FORM_indirect) - form = read_uleb128 (ptr); if (t->attr[i].attr == at) { + uint32_t form = t->attr[i].form; + while (form == DW_FORM_indirect) + form = read_uleb128 (ptr); + *formp = form; return ptr; } - switch (form) - { - case DW_FORM_ref_addr: - ptr += cu->cu_version == 2 ? ptr_size : 4; - break; - case DW_FORM_addr: - ptr += ptr_size; - break; - case DW_FORM_flag_present: - break; - case DW_FORM_ref1: - case DW_FORM_flag: - case DW_FORM_data1: - ++ptr; - break; - case DW_FORM_ref2: - case DW_FORM_data2: - ptr += 2; - break; - case DW_FORM_ref4: - case DW_FORM_data4: - case DW_FORM_sec_offset: - case DW_FORM_strp: - ptr += 4; - break; - case DW_FORM_ref8: - case DW_FORM_data8: - case DW_FORM_ref_sig8: - ptr += 8; - break; - case DW_FORM_sdata: - case DW_FORM_ref_udata: - case DW_FORM_udata: - read_uleb128 (ptr); - break; - case DW_FORM_string: - ptr = (unsigned char *) strchr ((char *)ptr, '\0') + 1; - break; - case DW_FORM_indirect: - abort (); - case DW_FORM_block1: - len = *ptr++; - break; - case DW_FORM_block2: - len = read_16 (ptr); - form = DW_FORM_block1; - break; - case DW_FORM_block4: - len = read_32 (ptr); - form = DW_FORM_block1; - break; - case DW_FORM_block: - case DW_FORM_exprloc: - len = read_uleb128 (ptr); - form = DW_FORM_block1; - break; - default: - abort (); - } - if (form == DW_FORM_block1) - ptr += len; + ptr = skip_attr (cu, &t->attr[i], ptr); } return NULL; } @@ -2692,75 +2707,8 @@ skip_attrs (dw_cu_ref cu, struct abbrev_tag *t, unsigned char *ptr) { unsigned int i; for (i = 0; i < t->nattr; ++i) - { - uint32_t form = t->attr[i].form; - size_t len = 0; + ptr = skip_attr (cu, &t->attr[i], ptr); - while (form == DW_FORM_indirect) - form = read_uleb128 (ptr); - switch (form) - { - case DW_FORM_ref_addr: - ptr += cu->cu_version == 2 ? ptr_size : 4; - break; - case DW_FORM_addr: - ptr += ptr_size; - break; - case DW_FORM_flag_present: - break; - case DW_FORM_ref1: - case DW_FORM_flag: - case DW_FORM_data1: - ++ptr; - break; - case DW_FORM_ref2: - case DW_FORM_data2: - ptr += 2; - break; - case DW_FORM_ref4: - case DW_FORM_data4: - case DW_FORM_sec_offset: - case DW_FORM_strp: - ptr += 4; - break; - case DW_FORM_ref8: - case DW_FORM_data8: - case DW_FORM_ref_sig8: - ptr += 8; - break; - case DW_FORM_sdata: - case DW_FORM_ref_udata: - case DW_FORM_udata: - read_uleb128 (ptr); - break; - case DW_FORM_string: - ptr = (unsigned char *) strchr ((char *)ptr, '\0') + 1; - break; - case DW_FORM_indirect: - abort (); - case DW_FORM_block1: - len = *ptr++; - break; - case DW_FORM_block2: - len = read_16 (ptr); - form = DW_FORM_block1; - break; - case DW_FORM_block4: - len = read_32 (ptr); - form = DW_FORM_block1; - break; - case DW_FORM_block: - case DW_FORM_exprloc: - len = read_uleb128 (ptr); - form = DW_FORM_block1; - break; - default: - abort (); - } - - if (form == DW_FORM_block1) - ptr += len; - } return ptr; }