From patchwork Wed Oct 22 05:29:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Kamensky X-Patchwork-Id: 3319 Received: (qmail 3038 invoked by alias); 22 Oct 2014 05:29:52 -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 3015 invoked by uid 89); 22 Oct 2014 05:29:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pd0-f182.google.com Received: from mail-pd0-f182.google.com (HELO mail-pd0-f182.google.com) (209.85.192.182) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 22 Oct 2014 05:29:51 +0000 Received: by mail-pd0-f182.google.com with SMTP id y10so2781513pdj.41 for ; Tue, 21 Oct 2014 22:29:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=+lcqCfudYxJFgaa/sxAqiJnLZbjJ5ZKk95C48hpyoBk=; b=cgQQ2pEP8kcUmqFnGh/Ee14LX33ip9g5aX+fNXYyyv/pOmYdVX8J4YJsQKhOn4bIiZ utT0EMt+yyUvHcGeaFpbjMrLuEQ0mfRcnqMOwYuouYGiwcU2V1hbaNUrXFXasnifRxAI TYE95kPVVaPiaAAPpXDM7ykfOStv6VOWmCeIkw5SoB/Nl6ZsnleUce7BdVOCt1QioSXr UkAfHEWc1R4QHFVYOLCQvCmgSPZRAAHVUoe6LYNiCiUCArnxpAXjuaRqwfGrqTuNE1vx sC7vfkP0EuCRmWEBbOdYe3GQ9roUrUQM1p/Kw8Vp15+/gum0YV8rooYMTQmhNOMuuZDE ixGQ== X-Gm-Message-State: ALoCoQkysWsWLdkYoxan76sdSOchh9R7MuGLG7nfAfusNm6bSz9h35h33Y6jvmGGmqcd/aEOYfYg X-Received: by 10.70.38.201 with SMTP id i9mr15830514pdk.127.1413955789300; Tue, 21 Oct 2014 22:29:49 -0700 (PDT) Received: from kamensky-w530.hsd1.ca.comcast.net ([24.6.79.41]) by mx.google.com with ESMTPSA id ty8sm13522576pab.26.2014.10.21.22.29.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Oct 2014 22:29:48 -0700 (PDT) From: Victor Kamensky To: gdb-patches@sourceware.org Cc: victor.kamensky@linaro.org Subject: [RFC PATCH] fix xfer from section that ends at max of CORE_ADDR Date: Tue, 21 Oct 2014 22:29:41 -0700 Message-Id: <1413955781-5130-1-git-send-email-victor.kamensky@linaro.org> Fix section_table_xfer_memory_partial function to deals with section entry that may have its endaddr at 0, because that section ends at max of CORE_ADDR and address next after it would be 0 once stored back to CORE_ADDR (overflow). bigcore.exp test run into this issue while running in ARM V7 rootfs on top of ARM V8 kernel (compat mode). In that core file the following section existed (from readelf -a execute on core file): LOAD 0xffe23000 0xffff1000 0x00000000 0x0f000 0x0f000 RW 0x1000 and gdb could not read from it. gdb/ChangeLog: 2014-10-21 Victor Kamensky * exec.c (section_table_xfer_memory_partial): Use ULONGEST for section start and end addresses to handle section that may has its end at max of CORE_ADDR and therefore such section endaddr field would be 0. --- gdb/exec.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/gdb/exec.c b/gdb/exec.c index f32589b..7c9b4b6 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -697,11 +697,18 @@ section_table_xfer_memory_partial (gdb_byte *readbuf, const gdb_byte *writebuf, struct bfd_section *asect = p->the_bfd_section; bfd *abfd = asect->owner; + /* To deals with possible overflow where p->endaddr is 0, + because of section ends on max of CORE_ADDR, copy section + addr and endaddr to ULONGEST type. Recover section length + first, and use it to determine section_endaddr. */ + ULONGEST section_addr = p->addr; + ULONGEST section_endaddr = section_addr + (p->endaddr - p->addr); + if (section_name && strcmp (section_name, asect->name) != 0) continue; /* not the section we need. */ - if (memaddr >= p->addr) + if (memaddr >= section_addr) { - if (memend <= p->endaddr) + if (memend <= section_endaddr) { /* Entire transfer is within this section. */ if (writebuf) @@ -721,7 +728,7 @@ section_table_xfer_memory_partial (gdb_byte *readbuf, const gdb_byte *writebuf, else return TARGET_XFER_EOF; } - else if (memaddr >= p->endaddr) + else if (memaddr >= section_endaddr) { /* This section ends before the transfer starts. */ continue;