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:25 PM, Tom Tromey wrote:
>>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:
> 
> Phil> I'm not sure what to do in this case.  There seems to be no direct
> Phil> equivalent of converting an exception to error output on a stream in MI
> Phil> (or any cases of TRY ... exception handlers).  There are many cases of
> Phil> MI raising an error() though, so I thought it appropriate in our case
> Phil> to raise a warning() instead.  Because of the peculiarities of the MI
> Phil> cases I just report a warning generically and move on.  This is not
> Phil> totally ideal, but it does allow the error/warning preamble followed
> Phil> by the actual locals information.
> 
> I'm not convinced a warning is the best thing.
> 
> Why not catch the exception and print the text of it as the variable's
> value?  Something like  <error reading variable: %s>
> I think this will work ok with existing front ends.

Here is a patch that does that.  

What do you think?

Cheers,

Phil

--

diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
index 6797055..7ee075c 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,47 @@ 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)
+			fprintf_filtered (stb->stream,
+					  _("<error reading variable: %s>"),
+					  except.message);
+
 		      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)
+		      fprintf_filtered (stb->stream,
+					_("<error reading variable: %s>"),
+					except.message);
+
 		    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..cd29de5
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/dw2-ref-missing-frame.exp
@@ -0,0 +1,77 @@
+# 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" \
+	"300\\^done,locals=\\\[\{name=\"func_nofb_var\",value=\"\\\<error reading variable: Could not find the frame base for \\\\\"func_nofb\\\\\"\\\.\\\>\"\},\{name=\"func_nofb_var2\",value=\"\\\<error reading variable: Could not find the frame base for \\\\\"func_nofb\\\\\"\\\.\\\>\"\}\\\].*" \
+	"test func_nofb_marker"
+}
+
+# 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" \
+	"301\\^done,locals=\\\[\{name=\"func_loopfb_var\",value=\"\\\<error reading variable: DWARF-2 expression error: Loop detected.*\"\},\{name=\"func_loopfb_var2\",value=\"\\\<error reading variable: DWARF-2 expression error: Loop detected.*\"\}\\\]" \
+	"test func_loopfb_var"
+}


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