From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29040 invoked by alias); 7 Sep 2010 14:19:05 -0000 Received: (qmail 28794 invoked by uid 22791); 7 Sep 2010 14:18:50 -0000 X-SWARE-Spam-Status: No, hits=2.3 required=5.0 tests=AWL,BAYES_40,TW_BJ X-Spam-Check-By: sourceware.org Received: from mv-drv-hcb003.ocn.ad.jp (HELO mv-drv-hcb003.ocn.ad.jp) (118.23.109.133) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 07 Sep 2010 14:18:05 +0000 Received: from vcmba.ocn.ne.jp (localhost.localdomain [127.0.0.1]) by mv-drv-hcb003.ocn.ad.jp (Postfix) with ESMTP id A4F4656423B for ; Tue, 7 Sep 2010 23:17:50 +0900 (JST) Received: from localhost (softbank221040169135.bbtec.net [221.40.169.135]) by vcmba.ocn.ne.jp (Postfix) with ESMTP for ; Tue, 7 Sep 2010 23:17:50 +0900 (JST) Date: Tue, 07 Sep 2010 14:19:00 -0000 Message-Id: <20100907.231749.260982118.anemo@mba.ocn.ne.jp> To: insight@sourceware.org Subject: segfault on opening a register window From: Atsushi Nemoto X-Fingerprint: 6ACA 1623 39BD 9A94 9B1A B746 CA77 FE94 2874 D52F X-Pgp-Public-Key: http://wwwkeys.pgp.net/pks/lookup?op=get&search=0x2874D52F Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Mailing-List: contact insight-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: insight-owner@sourceware.org X-SW-Source: 2010-q3/txt/msg00030.txt.bz2 The insight crashes with segfault when opening a register window after connecting to a remote ARM target. I confirmed the problem with 7.0.1, 7.1 and current CVS. The crash happened here: Program received signal SIGSEGV, Segmentation fault. get_register (regnum=0, arg={integer = 0, ptr = 0x0}) at ../../insight/src/gdb/gdbtk/generic/gdbtk-register.c:341 341 if ((TYPE_CODE (reg_vtype) == TYPE_CODE_UNION) (gdb) p reg_vtype $1 = (struct type *) 0x66 The reg_vtype pointer had a wrong value. I realized that contents of regtype[] array are corrupted. This is because current gdbarch was changed but regformat or regtype array was not reconstructed. 1. start insight. 2. setup_architecture_data() was called. 3. connecting to a remote target, then gdbarch (also numregs) changed. 4. gdb_regformat() was called and write to outside of allocated regformat, regtype array. The problem is setup_architecture_data() is not called when gdbarch was changed. If I opened the register window _before_ connecting to a remote target, setup_architecture_data() is called via gdb_reg_arch_changed. But it seems gdb_reg_arch_changed is called only if the register windows was opened. Here is a quick workaround. Is there good way to call setup_architecture_data() automatically if current arch was changed? Or other good fix? --- gdb/gdbtk/generic/gdbtk-register.c.org 2010-09-07 23:06:48.000000000 +0900 +++ gdb/gdbtk/generic/gdbtk-register.c 2010-09-07 23:06:59.000000000 +0900 @@ -65,6 +65,7 @@ static void get_register_types (int regn static char *old_regs = NULL; static int *regformat = (int *)NULL; static struct type **regtype = (struct type **)NULL; +static struct gdbarch *cur_gdbarch = NULL; int Gdbtk_Register_Init (Tcl_Interp *interp) @@ -149,6 +150,10 @@ gdb_register_info (ClientData clientData return TCL_ERROR; } + /* Check gdbarch change to avoid corruption of regformat/regtype array */ + if (cur_gdbarch != get_current_arch ()) + setup_architecture_data (); + /* Skip the option */ objc -= 2; objv += 2; @@ -469,6 +474,7 @@ setup_architecture_data () { int numregs; + cur_gdbarch = get_current_arch (); xfree (old_regs); xfree (regformat); xfree (regtype); --- Atsushi Nemoto