public inbox for insight@sourceware.org
 help / color / mirror / Atom feed
* Re: segfault on opening a register window
@ 2011-12-13 16:22 Yurij Grechishhev
  0 siblings, 0 replies; 2+ messages in thread
From: Yurij Grechishhev @ 2011-12-13 16:22 UTC (permalink / raw)
  To: insight, anemo

I had the same problem for insight-6.8-1 after specifying the target
registers using XML file (set tdesc filename).
It's my variant for insight-6.8-1 patch (the get_current_arch()
function is not supported):

--- insight-6.8-1/gdb/gdbtk/generic/gdbtk-register.c	
+++ insight-6.8-1/gdb/gdbtk/generic/gdbtk-register.c
@@ -62,6 +62,7 @@
 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)
@@ -146,6 +147,10 @@
       return TCL_ERROR;
     }

+    /* Check gdbarch change to avoid corruption of regformat/regtype array */
+    if (cur_gdbarch != current_gdbarch)
+      setup_architecture_data ();
+
   /* Skip the option */
   objc -= 2;
   objv += 2;
@@ -459,6 +464,7 @@
 {
   int numregs;

+  cur_gdbarch = current_gdbarch;
   xfree (old_regs);
   xfree (regformat);
   xfree (regtype);




-- 
With best regards!
____________________________

Yurij Grechishhev
Bauman State Technical University,
Department of Computer Systems and Networks

^ permalink raw reply	[flat|nested] 2+ messages in thread

* segfault on opening a register window
@ 2010-09-07 14:19 Atsushi Nemoto
  0 siblings, 0 replies; 2+ messages in thread
From: Atsushi Nemoto @ 2010-09-07 14:19 UTC (permalink / raw)
  To: insight

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-12-13 16:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-13 16:22 segfault on opening a register window Yurij Grechishhev
  -- strict thread matches above, loose matches on Subject: below --
2010-09-07 14:19 Atsushi Nemoto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).