From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 83531 invoked by alias); 2 Nov 2015 18:42:00 -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 83517 invoked by uid 89); 2 Nov 2015 18:41:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL,BAYES_00,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: xyzzy.0x04.net Received: from xyzzy.0x04.net (HELO xyzzy.0x04.net) (109.74.193.254) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 02 Nov 2015 18:41:57 +0000 Received: from hogfather.0x04.net (89-65-84-110.dynamic.chello.pl [89.65.84.110]) by xyzzy.0x04.net (Postfix) with ESMTPS id 3C45A3FED8 for ; Mon, 2 Nov 2015 19:42:13 +0100 (CET) Received: by hogfather.0x04.net (Postfix, from userid 1000) id 4986C5800D4; Mon, 2 Nov 2015 19:41:48 +0100 (CET) From: =?UTF-8?q?Marcin=20Ko=C5=9Bcielnicki?= To: gdb-patches@sourceware.org Cc: =?UTF-8?q?Marcin=20Ko=C5=9Bcielnicki?= Subject: [PATCH] gdb/record-full: Use xmalloc instead of alloca for large buffers. Date: Mon, 02 Nov 2015 18:42:00 -0000 Message-Id: <1446489704-3173-1-git-send-email-koriakin@0x04.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SW-Source: 2015-11/txt/msg00021.txt.bz2 On the newly added s390 target, it's possible for a single instruction to write practically unbounded amount of memory (eg. MVCLE). This caused a stack overflow when alloca was used. gdb/ChangeLog: * record-full.c (record_full_exec_insn): Use xmalloc for large buffers. --- gdb/ChangeLog | 4 ++++ gdb/record-full.c | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 38a42ea..f4c0f57 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,7 @@ +2015-11-02 Marcin Kościelnicki + + * record-full.c (record_full_exec_insn): Use xmalloc for large buffers. + 2015-10-30 Pedro Alves * breakpoint.c (breakpoint_in_range_p) diff --git a/gdb/record-full.c b/gdb/record-full.c index 595e357..04d64ba 100644 --- a/gdb/record-full.c +++ b/gdb/record-full.c @@ -65,6 +65,8 @@ #define RECORD_FULL_FILE_MAGIC netorder32(0x20091016) +#define RECORD_MEMORY_XMALLOC_THRESHOLD 0x1000 + /* These are the core structs of the process record functionality. A record_full_entry is a record of the value change of a register @@ -726,7 +728,11 @@ record_full_exec_insn (struct regcache *regcache, /* Nothing to do if the entry is flagged not_accessible. */ if (!entry->u.mem.mem_entry_not_accessible) { - gdb_byte *mem = (gdb_byte *) alloca (entry->u.mem.len); + gdb_byte *mem; + if (entry->u.mem.len >= RECORD_MEMORY_XMALLOC_THRESHOLD) + mem = (gdb_byte *) xmalloc (entry->u.mem.len); + else + mem = (gdb_byte *) alloca (entry->u.mem.len); if (record_debug > 1) fprintf_unfiltered (gdb_stdlog, @@ -771,6 +777,9 @@ record_full_exec_insn (struct regcache *regcache, record_full_stop_reason = TARGET_STOPPED_BY_WATCHPOINT; } } + + if (entry->u.mem.len >= RECORD_MEMORY_XMALLOC_THRESHOLD) + xfree(mem); } } break; -- 2.6.2