gdb: fix segfault in overload resolution debug output
authorTankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Fri, 29 Nov 2019 11:17:36 +0000 (12:17 +0100)
committerTankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Fri, 29 Nov 2019 11:18:21 +0000 (12:18 +0100)
A segfault occurs if overload resolution debug mode is turned on via
the 'set debug overload' command.  E.g.:

~~~
$ gdb ./a.out
...
(gdb) start
...
(gdb) set debug overload 1
(gdb) print foo(5)
-- Arg is int [8], parm is double [9]
Overloaded function instance (null) # of parms 1
Segmentation fault
$
~~~

The problem is, GDB tries to print the badness vector after it has
been std::move'd.  Fix the problem by printing the vector before it is
moved.

gdb/ChangeLog:
2019-11-29  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

* valops.c (find_oload_champ): Print part of debug messages
before the badness vector is std::move'd.

Change-Id: Ia623f9637e82ec332bfeac23eb6b0f2ffdcdde27

gdb/ChangeLog
gdb/valops.c

index bc61c35064eff09f0619c6059d7cbf658bff9d10..a3c06705d970bab80ff31a5588a2dc2119c92477 100644 (file)
@@ -1,3 +1,8 @@
+2019-11-29  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
+
+       * valops.c (find_oload_champ): Print part of debug messages
+       before the badness vector is std::move'd.
+
 2019-11-28  Tom Tromey  <tom@tromey.com>
 
        * value.c (creal_internal_fn): Fix comment.
index cbb1f30e71b40882a7bb12f4e3a4fb8810669f6d..8af53deaa6f8c36c59b9e1af591fe070c2156279 100644 (file)
@@ -3023,6 +3023,28 @@ find_oload_champ (gdb::array_view<value *> args,
       bv = rank_function (parm_types,
                          args.slice (static_offset));
 
+      if (overload_debug)
+       {
+         if (methods != NULL)
+           fprintf_filtered (gdb_stderr,
+                             "Overloaded method instance %s, # of parms %d\n",
+                             methods[ix].physname, (int) parm_types.size ());
+         else if (xmethods != NULL)
+           fprintf_filtered (gdb_stderr,
+                             "Xmethod worker, # of parms %d\n",
+                             (int) parm_types.size ());
+         else
+           fprintf_filtered (gdb_stderr,
+                             "Overloaded function instance "
+                             "%s # of parms %d\n",
+                             functions[ix]->demangled_name (),
+                             (int) parm_types.size ());
+         for (jj = 0; jj < args.size () - static_offset; jj++)
+           fprintf_filtered (gdb_stderr,
+                             "...Badness @ %d : %d\n",
+                             jj, bv[jj].rank);
+       }
+
       if (oload_champ_bv->empty ())
        {
          *oload_champ_bv = std::move (bv);
@@ -3048,29 +3070,9 @@ find_oload_champ (gdb::array_view<value *> args,
            break;
          }
       if (overload_debug)
-       {
-         if (methods != NULL)
-           fprintf_filtered (gdb_stderr,
-                             "Overloaded method instance %s, # of parms %d\n",
-                             methods[ix].physname, (int) parm_types.size ());
-         else if (xmethods != NULL)
-           fprintf_filtered (gdb_stderr,
-                             "Xmethod worker, # of parms %d\n",
-                             (int) parm_types.size ());
-         else
-           fprintf_filtered (gdb_stderr,
-                             "Overloaded function instance "
-                             "%s # of parms %d\n",
-                             functions[ix]->demangled_name (),
-                             (int) parm_types.size ());
-         for (jj = 0; jj < args.size () - static_offset; jj++)
-           fprintf_filtered (gdb_stderr,
-                             "...Badness @ %d : %d\n", 
-                             jj, bv[jj].rank);
-         fprintf_filtered (gdb_stderr, "Overload resolution "
-                           "champion is %d, ambiguous? %d\n", 
-                           oload_champ, oload_ambiguous);
-       }
+       fprintf_filtered (gdb_stderr, "Overload resolution "
+                         "champion is %d, ambiguous? %d\n",
+                         oload_champ, oload_ambiguous);
     }
 
   return oload_champ;
This page took 0.057187 seconds and 4 git commands to generate.