From patchwork Fri Nov 29 10:25:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Simon Marchi (Code Review)" X-Patchwork-Id: 36373 Received: (qmail 11177 invoked by alias); 29 Nov 2019 10:25:28 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 11123 invoked by uid 89); 29 Nov 2019 10:25:28 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=champion, baris, tankutbarisaktemurintelcom, tankut X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 29 Nov 2019 10:25:26 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id A5750203AC; Fri, 29 Nov 2019 05:25:22 -0500 (EST) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [IPv6:2620:52:3:1:5054:ff:fe06:16ca]) by mx1.osci.io (Postfix) with ESMTP id 6749F201F1 for ; Fri, 29 Nov 2019 05:25:21 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id 4331820AF6 for ; Fri, 29 Nov 2019 05:25:21 -0500 (EST) X-Gerrit-PatchSet: 1 Date: Fri, 29 Nov 2019 05:25:21 -0500 From: "Tankut Baris Aktemur (Code Review)" To: gdb-patches@sourceware.org Message-ID: Auto-Submitted: auto-generated X-Gerrit-MessageType: newchange Subject: [review] gdb: fix segfault in overload resolution debug output X-Gerrit-Change-Id: Ia623f9637e82ec332bfeac23eb6b0f2ffdcdde27 X-Gerrit-Change-Number: 734 X-Gerrit-ChangeURL: X-Gerrit-Commit: d7b5255d5aaa8e982cef2f848aaa95e9baf1834e References: Reply-To: tankut.baris.aktemur@intel.com, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3-79-g83ff7f88f1 Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/734 ...................................................................... gdb: fix segfault in overload resolution debug output 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 * valops.c (find_oload_champ): Print part of debug messages before the badness vector is std::move'd. Change-Id: Ia623f9637e82ec332bfeac23eb6b0f2ffdcdde27 --- M gdb/valops.c 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/gdb/valops.c b/gdb/valops.c index cbb1f30..8af53de 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -3023,6 +3023,28 @@ 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 @@ 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;