From patchwork Sun Dec 31 05:50:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 25160 Received: (qmail 106211 invoked by alias); 31 Dec 2017 06:01:15 -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 85750 invoked by uid 89); 31 Dec 2017 05:53:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No 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, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: sesbmg23.ericsson.net Received: from sesbmg23.ericsson.net (HELO sesbmg23.ericsson.net) (193.180.251.37) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 31 Dec 2017 05:53:15 +0000 Received: from ESESSHC005.ericsson.se (Unknown_Domain [153.88.183.33]) by sesbmg23.ericsson.net (Symantec Mail Security) with SMTP id 5F.17.13339.84B784A5; Sun, 31 Dec 2017 06:53:12 +0100 (CET) Received: from EUR01-VE1-obe.outbound.protection.outlook.com (153.88.183.145) by oa.msg.ericsson.com (153.88.183.33) with Microsoft SMTP Server (TLS) id 14.3.352.0; Sun, 31 Dec 2017 06:51:41 +0100 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=simon.marchi@ericsson.com; Received: from elxacz23q12.lan (192.222.251.162) by DBXPR07MB318.eurprd07.prod.outlook.com (2a01:111:e400:941d::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.386.4; Sun, 31 Dec 2017 05:51:14 +0000 From: Simon Marchi To: CC: Simon Marchi Subject: [PATCH 3/3] Make linux_nat_detach/thread_db_detach use the inferior parameter Date: Sun, 31 Dec 2017 00:50:54 -0500 Message-ID: <1514699454-18587-3-git-send-email-simon.marchi@ericsson.com> In-Reply-To: <1514699454-18587-1-git-send-email-simon.marchi@ericsson.com> References: <1514699454-18587-1-git-send-email-simon.marchi@ericsson.com> MIME-Version: 1.0 X-ClientProxiedBy: BN6PR16CA0042.namprd16.prod.outlook.com (2603:10b6:405:14::28) To DBXPR07MB318.eurprd07.prod.outlook.com (2a01:111:e400:941d::12) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dd5fadab-a6eb-4c68-d4be-08d550128138 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060); SRVR:DBXPR07MB318; X-Microsoft-Exchange-Diagnostics: 1; DBXPR07MB318; 3:xPUhC9UhOY9VHZWYaq4cAFQHGLvGazHYkvDtqmeG1EyJSdaPTN8X0L5QQRM1lfAtjzn/juDeaQaLSc6apK5g1gh1Y9u4speAwlmBpufXxBy8Fqw1TVIBDz4LhteOARfuUhUDm8WBJvUXAIZNdvkqoU348KTUhyEhgJD51wD+Z2zXBHRbEGfd12oBzoDdaMCR7yklOfSfkdTg7RQdMgBJ0ub9AL0R7Ld8pM9bYHFYrtRdVQRO+npXTYYAxXWRvKVn; 25:3SotdcozuU116O9w+Rp8IFpPZoQwhMbiWxWOko/OBYZLMhQW5jXMRTkV/cJ1dSWTuJ4S89dePlPvBWxyOe+0My3/1vHodPonNNkPg+5sukN2I53yKgod2OGb00AEBOkB0E/98vR48xJH05GpoEu3KnC8s5GZAk56VBp/y4xQJ/90OjAXTXhPmNYkA6M/JgN9RULBNl5uT3AuA/CVKqrAMP7EG27BVYVO+KuH90Q/YPYsG0wTTOwQES5Q+GGrZSuasa9lwOJNQ8g2kS8eg9UJWfv847YJVqojOqwXaHrN0pwGMxZSP1jYNCDV4j7r9ZM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5PikV5fzT6HsOOm79IdtrSwwUyTYI5/Jcq2kAInTuyOazJxMz0mw5nZnyw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040470)(2401047)(8121501046)(5005006)(3231023)(944501075)(93006095)(93001095)(10201501046)(3002001)(6041268)(20161123564045)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(6072148)(201708071742011); SRVR:DBXPR07MB318; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:DBXPR07MB318; X-Forefront-PRVS: 0538A71254 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(366004)(376002)(346002)(39860400002)(396003)(39380400002)(199004)(189003)(54534003)(316002)(21086003)(53936002)(81156014)(2906002)(305945005)(8676002)(81166006)(5660300001)(48376002)(7736002)(16526018)(4326008)(2351001)(25786009)(16586007)(2950100002)(478600001)(107886003)(6486002)(86362001)(50466002)(2361001)(105586002)(6666003)(68736007)(106356001)(6916009)(69596002)(50226002)(386003)(36756003)(6116002)(8936002)(76176011)(66066001)(3846002)(47776003)(97736004)(52116002)(59450400001)(6506007)(51416003)(6512007); DIR:OUT; SFP:1101; SCL:1; SRVR:DBXPR07MB318; H:elxacz23q12.lan; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: ericsson.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DBXPR07MB318; 23:LqKABhVV3g3rpJ9p1mA4dBKrn1BjXlc/Emf3IBMuCI?= =?us-ascii?Q?5aAvQuy9NKpYdTDvJLwvDo6HZHOZFPcVLtMKda3k/I0pFZx9tS1b5KOB7/Sh?= =?us-ascii?Q?kr1kxne7Cdv/JA6v3bLKINva9lI1uhfClr8HezOuZF8QzBAe+uY1dx6Rqlhu?= =?us-ascii?Q?KCWvZVT2dBGr+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RceIPBIwDA4YowprRKPMYGeakj8rnOU3MiWinpbqhiCoy12mj0fcm5WCz1w31DOOi78Sixpa8YnYcCnZzUQrdrENgHPM8COxHwSA/ZalGL5C5WABq2zs12G2RTONW SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Dec 2017 05:51:14.5099 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dd5fadab-a6eb-4c68-d4be-08d550128138 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 92e84ceb-fbfd-47ab-be52-080c6b87953f X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBXPR07MB318 X-OriginatorOrg: ericsson.com X-IsSubscribed: yes This patch makes these two functions actually use the inferior parameter added by the previous patch, instead of reading inferior_ptid. I chose these two, because they are the one actually used when I detach on my GNU/Linux system, so they were easy to test. I took the opportunity to pass the inferior being detached to inf_ptrace_detach_success, so it could use it too. From there, it made sense to add an overload of detach_inferior that takes the inferior directly rather than the pid, to avoid having to pass inf->pid only for the callee to look up the inferior structure by pid. gdb/ChangeLog: * inf-ptrace.c (inf_ptrace_detach): Adjust call to inf_ptrace_detach_success. (inf_ptrace_detach_success): Add inferior parameter, use it instead of inferior_ptid, pass it to detach_inferior. * inf-ptrace.h (inf_ptrace_detach_success): Add inferior parameter. * inferior.c (detach_inferior): Add overload that takes an inferior object. * inferior.h (detach_inferior): Likewise. * linux-nat.c (linux_nat_detach): Use the inf parameter, don't use inferior_ptid, adjust call to inf_ptrace_detach_success. * linux-thread-db.c (thread_db_detach): Use inf parameter. --- gdb/inf-ptrace.c | 8 +++----- gdb/inf-ptrace.h | 2 +- gdb/inferior.c | 15 +++++++++++++-- gdb/inferior.h | 3 +++ gdb/linux-nat.c | 8 +++----- gdb/linux-thread-db.c | 2 +- 6 files changed, 24 insertions(+), 14 deletions(-) diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c index 766a660..c6318d4 100644 --- a/gdb/inf-ptrace.c +++ b/gdb/inf-ptrace.c @@ -263,18 +263,16 @@ inf_ptrace_detach (struct target_ops *ops, inferior *inf, int from_tty) error (_("This system does not support detaching from a process")); #endif - inf_ptrace_detach_success (ops); + inf_ptrace_detach_success (ops, inf); } /* See inf-ptrace.h. */ void -inf_ptrace_detach_success (struct target_ops *ops) +inf_ptrace_detach_success (struct target_ops *ops, inferior *inf) { - pid_t pid = ptid_get_pid (inferior_ptid); - inferior_ptid = null_ptid; - detach_inferior (pid); + detach_inferior (inf); inf_child_maybe_unpush_target (ops); } diff --git a/gdb/inf-ptrace.h b/gdb/inf-ptrace.h index 3f27efe..61dc091 100644 --- a/gdb/inf-ptrace.h +++ b/gdb/inf-ptrace.h @@ -40,6 +40,6 @@ extern pid_t get_ptrace_pid (ptid_t); /* Cleanup the inferior after a successful ptrace detach. */ -extern void inf_ptrace_detach_success (struct target_ops *ops); +extern void inf_ptrace_detach_success (struct target_ops *ops, inferior *inf); #endif diff --git a/gdb/inferior.c b/gdb/inferior.c index 9b3043d..2db358e 100644 --- a/gdb/inferior.c +++ b/gdb/inferior.c @@ -253,10 +253,13 @@ exit_inferior_num_silent (int num) exit_inferior_1 (inf, 1); } +/* See inferior.h. */ + void -detach_inferior (int pid) +detach_inferior (inferior *inf) { - struct inferior *inf = find_inferior_pid (pid); + /* Save the pid, since exit_inferior_1 will reset it. */ + int pid = inf->pid; exit_inferior_1 (inf, 0); @@ -264,6 +267,14 @@ detach_inferior (int pid) printf_unfiltered (_("[Inferior %d detached]\n"), pid); } +/* See inferior.h. */ + +void +detach_inferior (int pid) +{ + detach_inferior (find_inferior_pid (pid)); +} + void inferior_appeared (struct inferior *inf, int pid) { diff --git a/gdb/inferior.h b/gdb/inferior.h index 0705dd9..dd4addf 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -458,6 +458,9 @@ extern struct inferior *add_inferior_silent (int pid); extern void delete_inferior (struct inferior *todel); /* Delete an existing inferior list entry, due to inferior detaching. */ +extern void detach_inferior (inferior *inf); + +/* Same as the above, but with the inferior specified by PID. */ extern void detach_inferior (int pid); extern void exit_inferior (int pid); diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 9a54397..a8793d8 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -1509,10 +1509,8 @@ detach_callback (struct lwp_info *lp, void *data) static void linux_nat_detach (struct target_ops *ops, inferior *inf, int from_tty) { - int pid; struct lwp_info *main_lwp; - - pid = ptid_get_pid (inferior_ptid); + int pid = inf->pid; /* Don't unregister from the event loop, as there may be other inferiors running. */ @@ -1527,7 +1525,7 @@ linux_nat_detach (struct target_ops *ops, inferior *inf, int from_tty) iterate_over_lwps (pid_to_ptid (pid), detach_callback, NULL); /* Only the initial process should be left right now. */ - gdb_assert (num_lwps (ptid_get_pid (inferior_ptid)) == 1); + gdb_assert (num_lwps (pid) == 1); main_lwp = find_lwp_pid (pid_to_ptid (pid)); @@ -1548,7 +1546,7 @@ linux_nat_detach (struct target_ops *ops, inferior *inf, int from_tty) detach_one_lwp (main_lwp, &signo); - inf_ptrace_detach_success (ops); + inf_ptrace_detach_success (ops, inf); } } diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c index ddb010e..eb5e49b 100644 --- a/gdb/linux-thread-db.c +++ b/gdb/linux-thread-db.c @@ -1094,7 +1094,7 @@ thread_db_detach (struct target_ops *ops, inferior *inf, int from_tty) { struct target_ops *target_beneath = find_target_beneath (ops); - delete_thread_db_info (ptid_get_pid (inferior_ptid)); + delete_thread_db_info (inf->pid); target_beneath->to_detach (target_beneath, inf, from_tty);