This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] PR python/11407


On 06/25/2010 07:56 AM, Phil Muldoon wrote:
> On 06/24/2010 11:01 PM, Phil Muldoon wrote:
>> On 06/24/2010 07:10 PM, Tom Tromey wrote:
>>>>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:
>>>
>>> Phil> This patch is for PR 11407. It also cures the ills in Jan's
>>> Phil> test-case from last night:
>>>
>>> Phil> 2010-06-24  Phil Muldoon  <pmuldoon@redhat.com>
>>> Phil> 	PR python/11407
>>> Phil> 	* printcmd.c (print_variable_and_value): Print error message on
>>> Phil> 	caught exception.
>>>
>>> This is ok with the changes Jan suggested.
>>>
>>> I think the MI commands -stack-list-variables and friends will need
>>> similar treatment.  See mi-cmd-stack.c:list_args_or_locals.
>>
>> Sorry for missing this, I was running 'info locals' in the MI
>> interpreter.  The MI -stack-list-locals case (as you noted) takes a
>> different direction from the CLI in printing these cases.
> 
>>
>> WDYT?
> 
> Oops in the last patch, I forgot to include
> 
>  ui_out_field_stream (uiout, "value", stb);
> 
> in both cases.  Here is a corrected patch:

Sorry for yet another reply on top on this. I hope this will be the last.

Jan and I were discussing this change on IRC and we decided it probably
needed a testcase.  I've adapted Jan's test inferiors/case to the MI
model.  Patch attached.

What do you think?

Cheers,

Phil

--

2010-06-25  Phil Muldoon  <pmuldoon@redhat.com>

	* mi/mi-cmd-stack.c (list_args_or_locals): Catch exceptions from
	read_var_value and common_val_print and print a warning.

2010-06-23  Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Phil Muldoon  <pmuldoon@redhat.com>

	* gdb.mi/dw2-ref-missing-frame-func.c: New File.
	* gdb.mi/dw2-ref-missing-frame-main.c New File.
	* gdb.mi/dw2-ref-missing-frame.S New File.
	* gdb.mi/dw2-ref-missing-frame.exp New File.

--

diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
index 6797055..6d8623b 100644
--- a/gdb/mi/mi-cmd-stack.c
+++ b/gdb/mi/mi-cmd-stack.c
@@ -31,7 +31,7 @@
 #include "gdb_string.h"
 #include "language.h"
 #include "valprint.h"
-
+#include "exceptions.h"
 
 enum what_to_list { locals, arguments, all };
 
@@ -334,27 +334,43 @@ list_args_or_locals (enum what_to_list what, int values, struct frame_info *fi)
 		      && TYPE_CODE (type) != TYPE_CODE_STRUCT
 		      && TYPE_CODE (type) != TYPE_CODE_UNION)
 		    {
-		      struct value_print_options opts;
-
-		      val = read_var_value (sym2, fi);
-		      get_raw_print_options (&opts);
-		      opts.deref_ref = 1;
-		      common_val_print
-			(val, stb->stream, 0, &opts,
-			 language_def (SYMBOL_LANGUAGE (sym2)));
+		      volatile struct gdb_exception except;
+
+		      TRY_CATCH (except, RETURN_MASK_ERROR)
+			{
+			  struct value_print_options opts;
+
+			  val = read_var_value (sym2, fi);
+			  get_raw_print_options (&opts);
+			  opts.deref_ref = 1;
+			  common_val_print
+			    (val, stb->stream, 0, &opts,
+			     language_def (SYMBOL_LANGUAGE (sym2)));
+			}
+		      if (except.reason < 0)
+			warning (_("<error reading variable>"));
+
 		      ui_out_field_stream (uiout, "value", stb);
 		    }
 		  break;
 		case PRINT_ALL_VALUES:
 		  {
-		    struct value_print_options opts;
-
-		    val = read_var_value (sym2, fi);
-		    get_raw_print_options (&opts);
-		    opts.deref_ref = 1;
-		    common_val_print
-		      (val, stb->stream, 0, &opts,
-		       language_def (SYMBOL_LANGUAGE (sym2)));
+		    volatile struct gdb_exception except;
+
+		    TRY_CATCH (except, RETURN_MASK_ERROR)
+		      {
+			struct value_print_options opts;
+
+			val = read_var_value (sym2, fi);
+			get_raw_print_options (&opts);
+			opts.deref_ref = 1;
+			common_val_print
+			  (val, stb->stream, 0, &opts,
+			   language_def (SYMBOL_LANGUAGE (sym2)));
+		      }
+		    if (except.reason < 0)
+		      warning (_("<error reading variable>"));
+
 		    ui_out_field_stream (uiout, "value", stb);
 		  }
 		  break;
diff --git a/gdb/testsuite/gdb.mi/dw2-ref-missing-frame-func.c b/gdb/testsuite/gdb.mi/dw2-ref-missing-frame-func.c
new file mode 100644
index 0000000..10ddd81
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/dw2-ref-missing-frame-func.c
@@ -0,0 +1,54 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2010 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+asm (".globl cu_text_start");
+asm ("cu_text_start:");
+
+asm (".globl func_nofb_start");
+asm ("func_nofb_start:");
+
+void
+func_nofb (void)
+{
+  /* int func_nofb_var; */
+  /* int func_nofb_var2; */
+
+  extern void func_nofb_marker (void);
+  func_nofb_marker ();
+}
+
+asm (".globl func_nofb_end");
+asm ("func_nofb_end:");
+
+asm (".globl func_loopfb_start");
+asm ("func_loopfb_start:");
+
+void
+func_loopfb (void)
+{
+  /* int func_loopfb_var; */
+  /* int func_loopfb_var2; */
+
+  extern void func_loopfb_marker (void);
+  func_loopfb_marker ();
+}
+
+asm (".globl func_loopfb_end");
+asm ("func_loopfb_end:");
+
+asm (".globl cu_text_end");
+asm ("cu_text_end:");
diff --git a/gdb/testsuite/gdb.mi/dw2-ref-missing-frame-main.c b/gdb/testsuite/gdb.mi/dw2-ref-missing-frame-main.c
new file mode 100644
index 0000000..b3ec33a
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/dw2-ref-missing-frame-main.c
@@ -0,0 +1,40 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2009, 2010 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+extern void func_nofb (void);
+extern void func_loopfb (void);
+
+void
+func_nofb_marker (void)
+{
+}
+
+void
+func_loopfb_marker (void)
+{
+}
+
+int
+main (void)
+{
+  int main_var = 1;
+
+  func_nofb ();
+  func_loopfb ();
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.mi/dw2-ref-missing-frame.S b/gdb/testsuite/gdb.mi/dw2-ref-missing-frame.S
new file mode 100644
index 0000000..a93b3a6
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/dw2-ref-missing-frame.S
@@ -0,0 +1,165 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Debug information */
+
+	.section .debug_info
+.Lcu1_begin:
+	/* CU header */
+	.4byte	.Lcu1_end - .Lcu1_start		/* Length of Compilation Unit */
+.Lcu1_start:
+	.2byte	2				/* DWARF Version */
+	.4byte	.Labbrev1_begin			/* Offset into abbrev section */
+	.byte	4				/* Pointer size */
+
+	/* CU die */
+	.uleb128 1				/* Abbrev: DW_TAG_compile_unit */
+	.4byte	cu_text_end			/* DW_AT_high_pc */
+	.4byte	cu_text_start			/* DW_AT_low_pc */
+	.ascii	"file1.txt\0"			/* DW_AT_name */
+	.ascii	"GNU C 3.3.3\0"			/* DW_AT_producer */
+	.byte	1				/* DW_AT_language (C) */
+
+.Ltype_int:
+	.uleb128	3			/* Abbrev: DW_TAG_base_type */
+	.ascii		"int\0"			/* DW_AT_name */
+	.byte		4			/* DW_AT_byte_size */
+	.byte		5			/* DW_AT_encoding */
+
+	/* func_nofb */
+	.uleb128	5			/* Abbrev: DW_TAG_subprogram (no fb) */
+	.ascii		"func_nofb\0"		/* DW_AT_name */
+	.4byte		func_nofb_start		/* DW_AT_low_pc */
+	.4byte		func_nofb_end		/* DW_AT_high_pc */
+
+	.uleb128	7			/* Abbrev: DW_TAG_variable (location) */
+	.ascii		"func_nofb_var\0"	/* DW_AT_name */
+	.byte		2f - 1f			/* DW_AT_location */
+1:	.byte		0x91			/*   DW_OP_fbreg */
+	.sleb128	0			/*   0 */
+2:	.4byte		.Ltype_int-.Lcu1_begin	/* DW_AT_type */
+
+	.uleb128	7			/* Abbrev: DW_TAG_variable (location) */
+	.ascii		"func_nofb_var2\0"	/* DW_AT_name */
+	.byte		2f - 1f			/* DW_AT_location */
+1:	.byte		0x91			/*   DW_OP_fbreg */
+	.sleb128	0			/*   0 */
+2:	.4byte		.Ltype_int-.Lcu1_begin	/* DW_AT_type */
+
+	.byte		0			/* End of children of func */
+
+	/* func_loopfb */
+	.uleb128	6			/* Abbrev: DW_TAG_subprogram (loop fb) */
+	.ascii		"func_loopfb\0"		/* DW_AT_name */
+	.4byte		func_loopfb_start	/* DW_AT_low_pc */
+	.4byte		func_loopfb_end		/* DW_AT_high_pc */
+	.byte		2f - 1f			/* DW_AT_frame_base */
+1:	.byte		0x91			/*   DW_OP_fbreg */
+	.sleb128	0			/*   0 */
+2:
+
+	.uleb128	7			/* Abbrev: DW_TAG_variable (location) */
+	.ascii		"func_loopfb_var\0"	/* DW_AT_name */
+	.byte		2f - 1f			/* DW_AT_location */
+1:	.byte		0x91			/*   DW_OP_fbreg */
+	.sleb128	0			/*   0 */
+2:	.4byte		.Ltype_int-.Lcu1_begin	/* DW_AT_type */
+
+	.uleb128	7			/* Abbrev: DW_TAG_variable (location) */
+	.ascii		"func_loopfb_var2\0"	/* DW_AT_name */
+	.byte		2f - 1f			/* DW_AT_location */
+1:	.byte		0x91			/*   DW_OP_fbreg */
+	.sleb128	0			/*   0 */
+2:	.4byte		.Ltype_int-.Lcu1_begin	/* DW_AT_type */
+
+	.byte		0			/* End of children of func */
+
+	.byte		0			/* End of children of CU */
+
+.Lcu1_end:
+
+/* Abbrev table */
+	.section .debug_abbrev
+.Labbrev1_begin:
+	.uleb128	1			/* Abbrev code */
+	.uleb128	0x11			/* DW_TAG_compile_unit */
+	.byte		1			/* has_children */
+	.uleb128	0x12			/* DW_AT_high_pc */
+	.uleb128	0x1			/* DW_FORM_addr */
+	.uleb128	0x11			/* DW_AT_low_pc */
+	.uleb128	0x1			/* DW_FORM_addr */
+	.uleb128	0x3			/* DW_AT_name */
+	.uleb128	0x8			/* DW_FORM_string */
+	.uleb128	0x25			/* DW_AT_producer */
+	.uleb128	0x8			/* DW_FORM_string */
+	.uleb128	0x13			/* DW_AT_language */
+	.uleb128	0xb			/* DW_FORM_data1 */
+	.byte		0x0			/* Terminator */
+	.byte		0x0			/* Terminator */
+
+	.uleb128	3			/* Abbrev code */
+	.uleb128	0x24			/* DW_TAG_base_type */
+	.byte		0			/* has_children */
+	.uleb128	0x3			/* DW_AT_name */
+	.uleb128	0x8			/* DW_FORM_string */
+	.uleb128	0xb			/* DW_AT_byte_size */
+	.uleb128	0xb			/* DW_FORM_data1 */
+	.uleb128	0x3e			/* DW_AT_encoding */
+	.uleb128	0xb			/* DW_FORM_data1 */
+	.byte		0x0			/* Terminator */
+	.byte		0x0			/* Terminator */
+
+	.uleb128	5			/* Abbrev code */
+	.uleb128	0x2e			/* DW_TAG_subprogram (no fb) */
+	.byte		1			/* has_children */
+	.uleb128	0x3			/* DW_AT_name */
+	.uleb128	0x8			/* DW_FORM_string */
+	.uleb128	0x11			/* DW_AT_low_pc */
+	.uleb128	0x1			/* DW_FORM_addr */
+	.uleb128	0x12			/* DW_AT_high_pc */
+	.uleb128	0x1			/* DW_FORM_addr */
+	.byte		0x0			/* Terminator */
+	.byte		0x0			/* Terminator */
+
+	.uleb128	6			/* Abbrev code */
+	.uleb128	0x2e			/* DW_TAG_subprogram (loop fb) */
+	.byte		1			/* has_children */
+	.uleb128	0x3			/* DW_AT_name */
+	.uleb128	0x8			/* DW_FORM_string */
+	.uleb128	0x11			/* DW_AT_low_pc */
+	.uleb128	0x1			/* DW_FORM_addr */
+	.uleb128	0x12			/* DW_AT_high_pc */
+	.uleb128	0x1			/* DW_FORM_addr */
+	.uleb128	0x40			/* DW_AT_frame_base */
+	.uleb128	0xa			/* DW_FORM_block1 */
+	.byte		0x0			/* Terminator */
+	.byte		0x0			/* Terminator */
+
+	.uleb128	7			/* Abbrev code (location) */
+	.uleb128	0x34			/* DW_TAG_variable */
+	.byte		0			/* has_children */
+	.uleb128	0x3			/* DW_AT_name */
+	.uleb128	0x8			/* DW_FORM_string */
+	.uleb128	0x2			/* DW_AT_location */
+	.uleb128	0xa			/* DW_FORM_block1 */
+	.uleb128	0x49			/* DW_AT_type */
+	.uleb128	0x13			/* DW_FORM_ref4 */
+	.byte		0x0			/* Terminator */
+	.byte		0x0			/* Terminator */
+
+	.byte		0x0			/* Terminator */
+	.byte		0x0			/* Terminator */
diff --git a/gdb/testsuite/gdb.mi/dw2-ref-missing-frame.exp b/gdb/testsuite/gdb.mi/dw2-ref-missing-frame.exp
new file mode 100644
index 0000000..355ee34
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/dw2-ref-missing-frame.exp
@@ -0,0 +1,73 @@
+# Copyright 2008, 2009, 2010 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# This test can only be run on targets which support DWARF-2 and use gas.
+# For now pick a sampling of likely targets.
+load_lib mi-support.exp
+set MIFLAGS "-i=mi"
+
+if {![istarget *-*-linux*]
+    && ![istarget *-*-gnu*]
+    && ![istarget *-*-elf*]
+    && ![istarget *-*-openbsd*]
+    && ![istarget arm-*-eabi*]
+    && ![istarget powerpc-*-eabi*]} {
+    return 0
+}
+
+set testfile "dw2-ref-missing-frame"
+set srcsfile ${testfile}.S
+set objsfile ${objdir}/${subdir}/${testfile}.o
+set srcfuncfile ${testfile}-func.c
+set objfuncfile ${objdir}/${subdir}/${testfile}-func.o
+set srcmainfile ${testfile}-main.c
+set objmainfile ${objdir}/${subdir}/${testfile}-main.o
+set executable ${testfile}
+set binfile ${objdir}/${subdir}/${executable}
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcsfile}" $objsfile object {}] != ""
+     || [gdb_compile "${srcdir}/${subdir}/${srcfuncfile}" $objfuncfile object {}] != ""
+     || [gdb_compile "${srcdir}/${subdir}/${srcmainfile}" $objmainfile object {debug}] != ""
+     || [gdb_compile "$objsfile $objfuncfile $objmainfile" $binfile executable {}] != "" } {
+    return -1
+}
+
+if [mi_gdb_start] {
+    continue
+}
+
+mi_delete_breakpoints
+mi_gdb_reinitialize_dir $srcdir/$subdir
+mi_gdb_load ${binfile}
+
+if [mi_runto func_nofb_marker] {
+    # First try referencing DW_AT_frame_base which is not defined.
+    mi_gdb_test "300-stack-list-locals --thread 1 --frame 1 --all-values" "&\"warning: <error reading variable>.*&\"warning: <error reading variable>.*300\\^done,locals=\\\[\{name=\"func_nofb_var\",value=\"\"\},\{name=\"func_nofb_var2\",value=\"\"\}\\\]"  "func_nofb locals"
+}
+
+# GDB could have crashed.
+mi_gdb_exit
+if [mi_gdb_start] {
+    continue
+}
+mi_delete_breakpoints
+mi_gdb_reinitialize_dir $srcdir/$subdir
+mi_gdb_load ${binfile}
+
+# And now try referencing DW_AT_frame_base defined using a self-reference
+# (DW_OP_fbreg).
+if [mi_runto func_loopfb_marker] {
+    mi_gdb_test "301-stack-list-locals --thread 1 --frame 1 --all-values" "&\"warning: <error reading variable>.*&\"warning: <error reading variable>.*301\\^done,locals=\\\[\{name=\"func_loopfb_var\",value=\"\"\},\{name=\"func_loopfb_var2\",value=\"\"\}\\\]"  "func_loopfb locals"
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]