From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 70948 invoked by alias); 15 Nov 2016 18:58:02 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 69026 invoked by uid 89); 15 Nov 2016 18:58:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 spammy=clumsy X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0b-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.158.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 15 Nov 2016 18:58:00 +0000 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id uAFIs4cv070628 for ; Tue, 15 Nov 2016 13:57:57 -0500 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0b-001b2d01.pphosted.com with ESMTP id 26r2qs82sm-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 15 Nov 2016 13:57:57 -0500 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 15 Nov 2016 18:57:55 -0000 Received: from d06dlp02.portsmouth.uk.ibm.com (9.149.20.14) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 15 Nov 2016 18:57:54 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id 0386B2190023 for ; Tue, 15 Nov 2016 18:57:06 +0000 (GMT) Received: from d06av02.portsmouth.uk.ibm.com (d06av02.portsmouth.uk.ibm.com [9.149.37.228]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id uAFIvr2n43974820 for ; Tue, 15 Nov 2016 18:57:53 GMT Received: from d06av02.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id uAFIvrjX031546 for ; Tue, 15 Nov 2016 11:57:53 -0700 Received: from oc1027705133.ibm.com (dyn-9-152-212-182.boeblingen.de.ibm.com [9.152.212.182]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id uAFIvoMA031543 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 15 Nov 2016 11:57:53 -0700 From: Andreas Arnez To: gdb-patches@sourceware.org Subject: Re: [PATCH 2/3] Fix copy_bitwise() References: <1479135786-31150-1-git-send-email-arnez@linux.vnet.ibm.com> <1479135786-31150-3-git-send-email-arnez@linux.vnet.ibm.com> Date: Tue, 15 Nov 2016 18:58:00 -0000 In-Reply-To: <1479135786-31150-3-git-send-email-arnez@linux.vnet.ibm.com> (Andreas Arnez's message of "Mon, 14 Nov 2016 16:02:25 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16111518-0040-0000-0000-00000306B240 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16111518-0041-0000-0000-00001DE132CC Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-11-15_06:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609300000 definitions=main-1611150322 X-IsSubscribed: yes X-SW-Source: 2016-11/txt/msg00387.txt.bz2 --=-=-= Content-Type: text/plain Content-length: 288 On Mon, Nov 14 2016, Andreas Arnez wrote: [...] > diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c > index 93aec1f..3a241a8 100644 > --- a/gdb/dwarf2loc.c > +++ b/gdb/dwarf2loc.c [...] For reference, since the patch itself might be a bit clumsy to read, here's the resulting function: --=-=-= Content-Type: text/plain Content-Disposition: inline Content-Description: copy_bitwise.c Content-length: 1870 /* Copy NBITS bits from SOURCE to DEST starting at the given bit offsets. Use the bit order as specified by BITS_BIG_ENDIAN. Source and destination buffers must not overlap. */ static void copy_bitwise (gdb_byte *dest, ULONGEST dest_offset, const gdb_byte *source, ULONGEST source_offset, ULONGEST nbits, int bits_big_endian) { unsigned int buf, avail; if (nbits == 0) return; if (bits_big_endian) { /* Start from the end, then work backwards. */ dest_offset += nbits - 1; dest += dest_offset / 8; dest_offset = 7 - dest_offset % 8; source_offset += nbits - 1; source += source_offset / 8; source_offset = 7 - source_offset % 8; } else { dest += dest_offset / 8; dest_offset %= 8; source += source_offset / 8; source_offset %= 8; } /* Fill BUF with DEST_OFFSET bits from the destination and 8 - SOURCE_OFFSET bits from the source. */ buf = *(bits_big_endian ? source-- : source++) >> source_offset; buf <<= dest_offset; buf |= *dest & ((1 << dest_offset) - 1); /* NBITS: bits yet to be written; AVAIL: BUF's fill level. */ nbits += dest_offset; avail = dest_offset + 8 - source_offset; /* Flush 8 bits from BUF, if appropriate. */ if (nbits >= 8 && avail >= 8) { *(bits_big_endian ? dest-- : dest++) = buf; buf >>= 8; avail -= 8; nbits -= 8; } /* Copy the middle part. */ if (nbits >= 8) { size_t len = nbits / 8; while (len--) { buf |= *(bits_big_endian ? source-- : source++) << avail; *(bits_big_endian ? dest-- : dest++) = buf; buf >>= 8; } nbits %= 8; } /* Write the last byte. */ if (nbits) { if (avail < nbits) buf |= *source << avail; buf &= (1 << nbits) - 1; *dest = (*dest & (~0 << nbits)) | buf; } } --=-=-=--