2010-09-16 Phil Muldoon <pmuldoon@redhat.com>
authorPhil Muldoon <pmuldoon@redhat.com>
Thu, 16 Sep 2010 13:47:55 +0000 (13:47 +0000)
committerPhil Muldoon <pmuldoon@redhat.com>
Thu, 16 Sep 2010 13:47:55 +0000 (13:47 +0000)
PR mi/11407
* mi/mi-cmd-stack.c (list_args_or_locals): Catch exceptions from
read_var_value and common_val_print and print a warning.

2010-09-16  Phil Muldoon  <pmuldoon@redhat.com>
            Jan Kratochvil  <jan.kratochvil@redhat.com>

PR mi/11407
* 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.

gdb/ChangeLog
gdb/mi/mi-cmd-stack.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.mi/dw2-ref-missing-frame-func.c [new file with mode: 0644]
gdb/testsuite/gdb.mi/dw2-ref-missing-frame-main.c [new file with mode: 0644]
gdb/testsuite/gdb.mi/dw2-ref-missing-frame.S [new file with mode: 0644]
gdb/testsuite/gdb.mi/dw2-ref-missing-frame.exp [new file with mode: 0644]

index 2edf5fbf8e1c771f4df6d1d1ebb5324b7cce306d..85e69738b340c0ee64b674a3596e069371ddd67c 100644 (file)
@@ -1,3 +1,9 @@
+2010-09-16  Phil Muldoon  <pmuldoon@redhat.com>
+
+       PR mi/11407
+       * mi/mi-cmd-stack.c (list_args_or_locals): Catch exceptions from
+       read_var_value and common_val_print and print a warning.
+
 2010-09-15  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
        * MAINTAINERS (GLOBAL MAINTAINERS) <Jan Kratochvil>: Move the entry to
index 67970558c0d7f8f1ae70330b2f2c211efc560fc1..7ee075cb8b2a98270129dfcdf831256d5cdc0cd8 100644 (file)
@@ -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;
index dad5befe6050278d64edca907348971f2e2c6ce8..fc645fe026e6e9874fa21389c39d857e23e91b43 100644 (file)
@@ -1,3 +1,12 @@
+2010-09-16  Phil Muldoon  <pmuldoon@redhat.com>
+            Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+       PR mi/11407
+       * 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.
+
 2010-09-14  Tom Tromey  <tromey@redhat.com>
 
        PR symtab/8399:
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 (file)
index 0000000..10ddd81
--- /dev/null
@@ -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 (file)
index 0000000..b3ec33a
--- /dev/null
@@ -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 (file)
index 0000000..a93b3a6
--- /dev/null
@@ -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 (file)
index 0000000..cd29de5
--- /dev/null
@@ -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"
+}