From patchwork Fri Jan 10 13:49:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aktemur, Tankut Baris" X-Patchwork-Id: 37285 Received: (qmail 63963 invoked by alias); 10 Jan 2020 13:49:13 -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 63933 invoked by uid 89); 10 Jan 2020 13:49:12 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=Excellent, gdb.multi, UD:multi, UD:gdb.multi X-HELO: mga11.intel.com Received: from mga11.intel.com (HELO mga11.intel.com) (192.55.52.93) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 10 Jan 2020 13:49:10 +0000 Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Jan 2020 05:49:08 -0800 Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by orsmga006.jf.intel.com with ESMTP; 10 Jan 2020 05:49:07 -0800 Received: from fmsmsx152.amr.corp.intel.com (10.18.125.5) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 10 Jan 2020 05:49:07 -0800 Received: from FMSEDG002.ED.cps.intel.com (10.1.192.134) by FMSMSX152.amr.corp.intel.com (10.18.125.5) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 10 Jan 2020 05:49:07 -0800 Received: from NAM04-SN1-obe.outbound.protection.outlook.com (104.47.44.58) by edgegateway.intel.com (192.55.55.69) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 10 Jan 2020 05:49:07 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dG/UV3luA/3pGusE7u29g5Gb5WuQDZcRz7A08G73CGd9IeVqqj4ay/vcoKR3mEyCjLwba52k4K4qquXwvzcK69d6FDzHRNjxLhl0urGtsM/5S0HGHoQdKaS9eH4LPwUBDWANbKU612e9WEurbEYLr6wuroHfztJlKjCCb47M0ogqevK9bzoqOIL6E9Jfc+LiRY6d9YaT2PDZiXPy4H4vjJjZGb4qLOr5XPWa6+Yjs8mYgKp1TRChs8lHYQ7tJ5yxbFvivvG0dMTV4o+pU1joq0eiKvHRru8rcwxhB3prYzxvKR8zmT8y6r3/tluvEmNyC/j9hdWujYEA1OV4hDc7ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Rj2m6rQskfQTcVsJiU0qJMePw+rVflKpwIAXTMaf7Yg=; b=eaM6kdyBeT3tuOyQfax9TTVpCjKAs0tNHVC24dHodbTGSY0ZKDkDuNJgxwuPWrG0HEWIjFK5i3xIEhNQx510I7jCQ/hymcVnOmux6Nw3a60tYdZDL1Xd4yN47FIVwC2xCmH7jbP6JOadpeakk8kSvZ3XzIkK6tUEscEp8i0e+ImTGMWiZXME0sLEuRLKTpCAQGL+Db/N4rgHQa5SKvQVpBnO/g5k8yVW+LovvlHTsDBpYuHmJlQs7S6Br4IaN9M8aNKDd8h/gIZTgVuMumDJyorJeOfLu1N/a7BMoZ3Umu8X5MaXkH6vut/FdtTqhb8zimVBMf1NFjhmmbn2rJW/JA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Rj2m6rQskfQTcVsJiU0qJMePw+rVflKpwIAXTMaf7Yg=; b=nm+pxCUlqvXRtCkWVQTJhKFWw3qRfjrj2yI+TTtgtmHPV4lfb/hVGa4w0meV7XgWRUoEO846i4lrfuJdWyQfAvZ0DQSM+c068YCw0HJHNUy2UpdlpX1cBSoPtOKMPpqQL93kxgwMMRpZw04Mg5AG9p8ZojDluXAZF7mdKBCKZrk= Received: from BYAPR11MB3030.namprd11.prod.outlook.com (20.177.225.91) by BYAPR11MB2599.namprd11.prod.outlook.com (52.135.227.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2602.10; Fri, 10 Jan 2020 13:49:05 +0000 Received: from BYAPR11MB3030.namprd11.prod.outlook.com ([fe80::2c94:a4bd:2d9c:30b]) by BYAPR11MB3030.namprd11.prod.outlook.com ([fe80::2c94:a4bd:2d9c:30b%6]) with mapi id 15.20.2602.017; Fri, 10 Jan 2020 13:49:05 +0000 From: "Aktemur, Tankut Baris" To: Pedro Alves CC: "gdb-patches@sourceware.org" Subject: RE: [PATCH v2 00/24] Multi-target support Date: Fri, 10 Jan 2020 13:49:05 +0000 Message-ID: References: <20191017225026.30496-1-palves@redhat.com> <20a1459c-e705-99e9-9277-51cec32b28c5@FreeBSD.org> <33f04418-380c-8a56-b80e-82c7139b9cd1@redhat.com> In-Reply-To: <33f04418-380c-8a56-b80e-82c7139b9cd1@redhat.com> authentication-results: spf=none (sender IP is ) smtp.mailfrom=tankut.baris.aktemur@intel.com; x-ms-oob-tlc-oobclassifiers: OLM:8273; x-ms-exchange-senderadcheck: 1 x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: fZgFoW2navjUIH+32G/KYSOeoGbeRhxkVBOXhhZ8s39pd1EWAKqdA+NN2n/xP4VjRfkO5KAT5U044uNOTxzmJPh8aOxpLuelxSI+QZhYOmw= Return-Path: tankut.baris.aktemur@intel.com X-IsSubscribed: yes On Thursday, January 9, 2020 8:50 PM, Pedro Alves wrote: > > Excellent! I think I'll be merging this soon, just need to > address Aktemur's latest comments. > > Thanks, > Pedro Alves There is one more minor thing, I think. The "info inferiors" command iterates over the list of inferiors and prints their info. One piece of information is the inferior id, which is printed through the target. This means that for each inferior, the target of the current inferior is used, potentially yielding incorrect output. To fix, inferior can be switched temporarily before printing its id. Please see the patches below for details. The second one attempts to modify the multi-target.exp test to check correct output. Thanks -Baris From efa9736da4d5545232fd3c3f8c65e297963d556f Mon Sep 17 00:00:00 2001 From: Tankut Baris Aktemur Date: Fri, 10 Jan 2020 14:27:55 +0100 Subject: [PATCH 1/2] Switch the inferior before outputting its id in "info inferiors" GDB uses the 'current_top_target' when displaying the description of an inferior. This leads to same target being used for each inferior and, in turn, yields incorrect output when the inferior has a target that is supposed to give a specialized output. For instance, the remote target outputs "Remote target" instead of "process XYZ" as the description if the multi-process feature is not supported or turned off. E.g.: Suppose we have a native and a remote target, and the native is the current inferior. The remote target does not support multi-process. For "info inferiors", we would expect to see: ~~~ (gdb) i inferiors Num Description Connection Executable * 1 process 29060 1 (native) /a/path 2 Remote target 2 (remote ...) ~~~ but instead we get ~~~ (gdb) i inferiors Num Description Connection Executable * 1 process 29060 1 (native) /a/path 2 process 42000 2 (remote ...) ~~~ Similarly, if the current inferior is the remote one, we would expect to see ~~~ (gdb) i inferiors Num Description Connection Executable 1 process 29060 1 (native) /a/path * 2 Remote target 2 (remote ...) ~~~ but we get ~~~ (gdb) i inferiors Num Description Connection Executable * 1 Remote target 1 (native) /a/path 2 Remote target 2 (remote ...) ~~~ With this patch, we switch to the inferior when outputting its description, so that the current_top_target will be aligned to the inferior we are displaying. --- gdb/inferior.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) -- 2.17.1 Intel Deutschland GmbH Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany Tel: +49 89 99 8853-0, www.intel.de Managing Directors: Christin Eisenschmid, Gary Kershaw Chairperson of the Supervisory Board: Nicole Lau Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928 diff --git a/gdb/inferior.c b/gdb/inferior.c index 3ce43860f7..ef91e74e89 100644 --- a/gdb/inferior.c +++ b/gdb/inferior.c @@ -494,6 +494,11 @@ print_inferior (struct ui_out *uiout, const char *requested_inferiors) uiout->table_header (17, ui_left, "exec", "Executable"); uiout->table_body (); + + /* Restore the current thread after the loop because we switch the + inferior in the loop. */ + scoped_restore_current_pspace_and_thread restore_pspace_thread; + inferior *current_inf = current_inferior (); for (inferior *inf : all_inferiors ()) { if (!number_is_in_list (requested_inferiors, inf->num)) @@ -501,13 +506,17 @@ print_inferior (struct ui_out *uiout, const char *requested_inferiors) ui_out_emit_tuple tuple_emitter (uiout, NULL); - if (inf == current_inferior ()) + if (inf == current_inf) uiout->field_string ("current", "*"); else uiout->field_skip ("current"); uiout->field_signed ("number", inf->num); + /* Because the pid_to_str uses current_top_target, + switch the inferior. */ + switch_to_inferior_no_thread (inf); + uiout->field_string ("target-id", inferior_pid_to_str (inf->pid)); std::string conn = uiout_field_connection (inf->process_target ()); -- 2.17.1 From 0779c90c63359abb2574aa02647969296d944791 Mon Sep 17 00:00:00 2001 From: Tankut Baris Aktemur Date: Fri, 10 Jan 2020 14:27:54 +0100 Subject: [PATCH 2/2] testsuite: enhance "info inferiors" test for multi-target Expand the "info inferiors" test for the multi-target feature. The test was checking for the output of the info commands after setup, only when the current inferior is the last added inferior. This patch does the following: 1. The "info inferiors" and "info connections" test is extracted out from the "setup" procedure to a separate procedure. 2. The test is enriched to check the output after switching to each inferior, not just the last one. 3. The test is performed twice; one for when the multi-process feature is turned on, one for off. --- gdb/testsuite/gdb.multi/multi-target.exp | 111 +++++++++++++++++------ 1 file changed, 84 insertions(+), 27 deletions(-) diff --git a/gdb/testsuite/gdb.multi/multi-target.exp b/gdb/testsuite/gdb.multi/multi-target.exp index be466c110b..63a7a287d1 100644 --- a/gdb/testsuite/gdb.multi/multi-target.exp +++ b/gdb/testsuite/gdb.multi/multi-target.exp @@ -137,33 +137,6 @@ proc setup {non-stop} { return 0 } - set ws "\[ \t\]+" - global decimal - - # Test "info connections" and "info inferior"'s "Connection" - # column, while at it. - - gdb_test "info connections" \ - [multi_line \ - "Num${ws}What${ws}Description${ws}" \ - " 1${ws}native${ws}Native process${ws}" \ - " 2${ws}extended-remote localhost:$decimal${ws}Extended remote serial target in gdb-specific protocol${ws}" \ - " 3${ws}core${ws}Local core dump file${ws}" \ - " 4${ws}extended-remote localhost:$decimal${ws}Extended remote serial target in gdb-specific protocol${ws}" \ - "\\* 5${ws}core${ws}Local core dump file${ws}" \ - ] - - gdb_test "info inferiors" \ - [multi_line \ - "Num${ws}Description${ws}Connection${ws}Executable${ws}" \ - " 1${ws}process ${decimal}${ws}1 \\(native\\)${ws}${binfile}${ws}" \ - " 2${ws}process ${decimal}${ws}2 \\(extended-remote localhost:$decimal\\)${ws}${binfile}${ws}" \ - " 3${ws}process ${decimal}${ws}3 \\(core\\)${ws}${binfile}${ws}" \ - " 4${ws}process ${decimal}${ws}1 \\(native\\)${ws}${binfile}${ws}" \ - " 5${ws}process ${decimal}${ws}4 \\(extended-remote localhost:$decimal\\)${ws}${binfile}${ws}" \ - "\\* 6${ws}process ${decimal}${ws}5 \\(core\\)${ws}${binfile}${ws}" \ - ] - # For debugging. gdb_test "info threads" ".*" @@ -365,6 +338,83 @@ proc test_ping_pong_next {} { } } +# Test "info inferiors" and "info connections" where the multi-process +# feature of remote targets is turned off or on. +proc test_info_inferiors {multi_process} { + setup "off" + + gdb_test_no_output \ + "set remote multiprocess-feature-packet $multi_process" + + # Get the description for inferior INF for when the current + # inferior id is CURRENT. + proc inf_desc {inf current} { + set ws "\[ \t\]+" + global decimal + upvar multi_process multi_process + + if {($multi_process == "off") && ($inf == 2 || $inf == 5)} { + set desc "Remote target" + } else { + set desc "process ${decimal}" + } + + set desc "${inf}${ws}${desc}${ws}" + if {$inf == $current} { + return "\\* $desc" + } else { + return " $desc" + } + } + + # Get the "Num" column for CONNECTION for when the current + # inferior id is CURRENT_INF + proc connection_num {connection current_inf} { + switch $current_inf { + "4" { set current_connection "1"} + "5" { set current_connection "4"} + "6" { set current_connection "5"} + default { set current_connection $current_inf} + } + if {$connection == $current_connection} { + return "\\* $connection" + } else { + return " $connection" + } + } + + set ws "\[ \t\]+" + global decimal binfile + + # Test "info connections" and "info inferior" by switching to each + # inferior one by one. + for {set inf 1} {$inf <= 6} {incr inf} { + gdb_test "inferior $inf" "Switching to inferior $inf.*" \ + "inferior switch ($inf)" + + gdb_test "info connections" \ + [multi_line \ + "Num${ws}What${ws}Description${ws}" \ + "[connection_num 1 $inf]${ws}native${ws}Native process${ws}" \ + "[connection_num 2 $inf]${ws}extended-remote localhost:$decimal${ws}Extended remote serial target in gdb-specific protocol${ws}" \ + "[connection_num 3 $inf]${ws}core${ws}Local core dump file${ws}" \ + "[connection_num 4 $inf]${ws}extended-remote localhost:$decimal${ws}Extended remote serial target in gdb-specific protocol${ws}" \ + "[connection_num 5 $inf]${ws}core${ws}Local core dump file${ws}" \ + ] "info connections ($inf)" + + gdb_test "info inferiors" \ + [multi_line \ + "Num${ws}Description${ws}Connection${ws}Executable${ws}" \ + "[inf_desc 1 $inf]1 \\(native\\)${ws}${binfile}${ws}" \ + "[inf_desc 2 $inf]2 \\(extended-remote localhost:$decimal\\)${ws}${binfile}${ws}" \ + "[inf_desc 3 $inf]3 \\(core\\)${ws}${binfile}${ws}" \ + "[inf_desc 4 $inf]1 \\(native\\)${ws}${binfile}${ws}" \ + "[inf_desc 5 $inf]4 \\(extended-remote localhost:$decimal\\)${ws}${binfile}${ws}" \ + "[inf_desc 6 $inf]5 \\(core\\)${ws}${binfile}${ws}" \ + ] "info inferiors ($inf)" + } +} + # Make a core file with two threads upfront. Several tests load the # same core file. prepare_core @@ -385,3 +435,10 @@ with_test_prefix "interrupt" { with_test_prefix "ping-pong" { test_ping_pong_next } + +# Test "info inferiors" and "info connections" commands +with_test_prefix "info-inferiors" { + foreach_with_prefix multi_process {"on" "off"} { + test_info_inferiors $multi_process + } +}