[gdb/exp] Fix exception when printing optimized out vla
authorTom de Vries <tdevries@suse.de>
Fri, 20 Jul 2018 14:41:00 +0000 (16:41 +0200)
committerTom de Vries <tdevries@suse.de>
Wed, 25 Jul 2018 19:25:16 +0000 (21:25 +0200)
When compiling vla-optimized-out.c with -O3 and a recent gcc, and trying to
print the vla a in f1, we run into this gdb exception:
...
Cannot find matching parameter at DW_TAG_call_site 0x4003be at main
...

This is a regression introduced by 42dc7699a2 "[gdb/exp] Fix printing of type
of optimized out vla".

This patch fixes the regression by wrapping the ctx.eval call in
dwarf2_locexpr_baton_eval in try/catch, similar to what is done in
dwarf2_evaluate_loc_desc_full.

Build and reg-tested on x86_64-linux.

2018-07-25  Tom de Vries  <tdevries@suse.de>

* dwarf2loc.c (dwarf2_locexpr_baton_eval): Wrap ctx.eval call in
try/catch.

* gdb.base/vla-optimized-out-o3.exp: New file.  Reuse
vla-optimized-out.c.

gdb/ChangeLog
gdb/dwarf2loc.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/vla-optimized-out-o3.exp [new file with mode: 0644]

index e6f8e5b149c28c7febf43acba4b526a30c29124e..d6d96db62a70cb6f49b472fa339d10362bdd7449 100644 (file)
@@ -1,3 +1,8 @@
+2018-07-25  Tom de Vries  <tdevries@suse.de>
+
+       * dwarf2loc.c (dwarf2_locexpr_baton_eval): Wrap ctx.eval call in
+       try/catch.
+
 2018-07-25  Jan Vrany  <jan.vrany@fit.cvut.cz>
 
        * breakpoint.c (enable_disable_bp_num_loc): Notify observers.
 2018-07-25  Jan Vrany  <jan.vrany@fit.cvut.cz>
 
        * breakpoint.c (enable_disable_bp_num_loc): Notify observers.
index 730934fe6e6c35a9f72172f247bcd62b031f142a..a98b676b30304a2986e62361729b6dd6e9be9a2e 100644 (file)
@@ -2573,7 +2573,26 @@ dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton,
   ctx.ref_addr_size = dwarf2_per_cu_ref_addr_size (dlbaton->per_cu);
   ctx.offset = dwarf2_per_cu_text_offset (dlbaton->per_cu);
 
   ctx.ref_addr_size = dwarf2_per_cu_ref_addr_size (dlbaton->per_cu);
   ctx.offset = dwarf2_per_cu_text_offset (dlbaton->per_cu);
 
-  ctx.eval (dlbaton->data, dlbaton->size);
+  TRY
+    {
+      ctx.eval (dlbaton->data, dlbaton->size);
+    }
+  CATCH (ex, RETURN_MASK_ERROR)
+    {
+      if (ex.error == NOT_AVAILABLE_ERROR)
+       {
+         return 0;
+       }
+      else if (ex.error == NO_ENTRY_VALUE_ERROR)
+       {
+         if (entry_values_debug)
+           exception_print (gdb_stdout, ex);
+         return 0;
+       }
+      else
+       throw_exception (ex);
+    }
+  END_CATCH
 
   switch (ctx.location)
     {
 
   switch (ctx.location)
     {
index 80c99a8f071995e422dbe79292fe579b8e3443e4..ab50f70e28c09762aaf632880b4688d16c122fd6 100644 (file)
@@ -1,3 +1,8 @@
+2018-07-25  Tom de Vries  <tdevries@suse.de>
+
+       * gdb.base/vla-optimized-out-o3.exp: New file.  Reuse
+       vla-optimized-out.c.
+
 2018-07-25  Jan Vrany  <jan.vrany@fit.cvut.cz>
 
        * gdb.mi/mi-breakpoint-location-ena-dis.cc: New file.
 2018-07-25  Jan Vrany  <jan.vrany@fit.cvut.cz>
 
        * gdb.mi/mi-breakpoint-location-ena-dis.cc: New file.
diff --git a/gdb/testsuite/gdb.base/vla-optimized-out-o3.exp b/gdb/testsuite/gdb.base/vla-optimized-out-o3.exp
new file mode 100644 (file)
index 0000000..60707e7
--- /dev/null
@@ -0,0 +1,36 @@
+# Copyright 2018 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/>.
+
+# Check whether we can print an optimized-out vla.
+
+standard_testfile
+
+if { [prepare_for_testing "failed to prepare" $testfile "vla-optimized-out.c" \
+         {debug optimize=-O3}] } {
+    return -1
+}
+
+proc vla_optimized_out { } {
+    if ![runto f1] {
+       fail "can't run to f1"
+       return
+    }
+
+    gdb_test "p a" \
+       { = <optimized out>} \
+       "printed optimized out vla"
+}
+
+vla_optimized_out
This page took 0.039109 seconds and 4 git commands to generate.