Message ID | 20170321221744.20567-1-simon.marchi@ericsson.com |
---|---|
State | New, archived |
Headers |
Received: (qmail 90111 invoked by alias); 21 Mar 2017 22:18:12 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: <gdb-patches.sourceware.org> List-Unsubscribe: <mailto:gdb-patches-unsubscribe-##L=##H@sourceware.org> List-Subscribe: <mailto:gdb-patches-subscribe@sourceware.org> List-Archive: <http://sourceware.org/ml/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-help@sourceware.org>, <http://sourceware.org/ml/#faqs> Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 90095 invoked by uid 89); 21 Mar 2017 22:18:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.8 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.2 spammy=Hx-languages-length:2834, H*MI:20170321221744 X-HELO: sesbmg22.ericsson.net Received: from sesbmg22.ericsson.net (HELO sesbmg22.ericsson.net) (193.180.251.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 21 Mar 2017 22:18:10 +0000 Received: from ESESSHC013.ericsson.se (Unknown_Domain [153.88.183.57]) by (Symantec Mail Security) with SMTP id D9.66.25230.0A6A1D85; Tue, 21 Mar 2017 23:18:08 +0100 (CET) Received: from EUR03-DB5-obe.outbound.protection.outlook.com (153.88.183.145) by oa.msg.ericsson.com (153.88.183.57) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 21 Mar 2017 23:18:07 +0100 Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=ericsson.com; Received: from elxcz23q12-y4.ca.am.ericsson.se (192.75.88.130) by VI1PR07MB1728.eurprd07.prod.outlook.com (10.166.143.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.991.4; Tue, 21 Mar 2017 22:18:03 +0000 From: Simon Marchi <simon.marchi@ericsson.com> To: <gdb-patches@sourceware.org> CC: Simon Marchi <simon.marchi@polymtl.ca> Subject: [PATCH] Remove lwp -> pid conversion in linux_nat_xfer_partial Date: Tue, 21 Mar 2017 18:17:44 -0400 Message-ID: <20170321221744.20567-1-simon.marchi@ericsson.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-ClientProxiedBy: BN6PR03CA0035.namprd03.prod.outlook.com (10.175.124.21) To VI1PR07MB1728.eurprd07.prod.outlook.com (10.166.143.24) X-MS-Office365-Filtering-Correlation-Id: 74f52022-8596-4d34-cc24-08d470a82495 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:VI1PR07MB1728; X-Microsoft-Exchange-Diagnostics: 1; VI1PR07MB1728; 3:TLqNipKei8FZc6sMRNVoaHMXc0azRECQ7Wn3Y+sPLquUaZsi7s7XXHTuHoWuVOFsbPlhgiIYl2ZjrxgjMGGk/SoQK1rJ03sbauaA5pp6yaNmnWmk4Z1u7elSEJhuofOUOuhZWH0DCne2fZMGdULlWK8nfJ7zZZ/dqtoKB99bC6HKPHQgp/V5vgKrhoUvLtopMD6k5C/0/cZa8QhopqQQ+TOFWzuuWsY/HBH+1tS81G2EaEH+5TQHnDQerO3hPC41jdoiJdhUErakzXoMaV/7RA==; 25:7b50z2cPIPfoCejWIIUe3PXu/CONPB+Zd9Jw0kkqfGJwksQcIjjWtD+W6IIJUkyy+gvQHLUfZBVhRmKgx2hUevtB8/Fa+nwpJOtw/nA4ggdsxZFU7Dv+JuUWXVNfdVe552QjXBZF9NDF40zBO63t8Z4TDd4t/jcrci9dCbU3ZNkkeDxUHSU/Z0Cr6CNMCEVT51IDA5hkLOUcyhb6WvrUfs+z+6PqwQPIC1xUrucuSMGbZqB2Mn8NQHEe2ZTivqViOvnwZkxB4BQn6lN1Lvv970KrejMBuw0+B/D+mKGB1UeC7/dauK1Qc1zUpPo4d3ihO2zxckZVnV2jO2rkvbGQCisl6LkBf91YYP55++sDuq32x0u5T1iJnt6r2kol/LnsvxPbLfXEbXNqG0SRuMUZjg0N9HJOeEJ9++orH/jukhhapz3gbBUMiB5WAVfbpP/EhnGPATT5Hgh6+KThOj2dyw== X-Microsoft-Exchange-Diagnostics: 1; VI1PR07MB1728; 31:ZLp0FUEIQ4xq582ch2GSMU24O66DPc6oRf0wcVfKLL3IeLg1ZS+R2cMyOLUduKVopfeIhTefb9jtaw1kuY9XFmjqga4JQIzrRzkNlJGctLrg3TNt0D3l7uC/TvrW4Mp2WdyJadZLyFvUA7956lcNiLkPm99WE/ccPIFTIxX0zi+53duo+dYApEzwVrXXwSOfeqsiupT1ZHWW4jiRSyiB+RnH/qaMJOTxSrzFKFkFsH8seeaoWS2JMhOqL1cVs49cB4XcIzDcTQ4kCshBLw9iOQ==; 20:RYhNmouKAH+yx2SQCDD9v6xNM+fiOQ+ZU1VfrTSQb21oYUXHmODTh2jBcqXPHZVYLr7Oigk8I6zmn7p1XiF8OOtp3V2hX9PWwAC2aU7SA6M0tuB58tERVzQ4840ueZqK9RFZYGcHbWxsE9b5dizMpzS1b1ftfSQ2gIvZxJt86Kw+MjySYhRP3qd/tqfoYagGP+Yn1rKzarSEno2C5TkO5j//63qMPEGuSYQOCWDGk7E7DuVMYILaAC5VCiCo38xAhzSG7I7NBdIREFEcy+TTmOBG68LWafWw2/Fduue6Ycy73c7bpzCHRkSuidp3b2jKCFksPsfWqsfdSJHgLgZII5eYXoNwALZvkJhK1z5VUgfAxq0rXApI7kTFOBInmlYm9IA2+ll1An72LcJytnNefU5tR+aelP+rkJvM4UKL4UUzrxBoX0ZSYsvTf+dGExBS6PHv6FXPJ52zUys0uYWHIOx05ZOFZBMClVcI1e1pXsPBvCRD3yjVM2/R7F/l+bRx X-Microsoft-Antispam-PRVS: <VI1PR07MB172813DA88E34F07F52DBBA3ED3D0@VI1PR07MB1728.eurprd07.prod.outlook.com> X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6041248)(20161123555025)(20161123560025)(20161123562025)(20161123564025)(20161123558025)(6072148); SRVR:VI1PR07MB1728; BCL:0; PCL:0; RULEID:; SRVR:VI1PR07MB1728; X-Microsoft-Exchange-Diagnostics: 1; VI1PR07MB1728; 4:e9ssL523wSS3mBusOARSOO+GYMauLkp9e6CW3ejLhdhm+rpF1I3nrsqPEy/joe9TxZgeXbo45tXnquHXVXniBvsEJhXX12IgEDg3/ulkHlpkwYR2yzJEtLTBwQfCMJ6HXlC82wBViqf8hG2hAlXTu8E9tCO50+9z1l0CIipytmYulYqBQ80v5+8NI6TNR1W6aWs1C8xMuL4uNP2JIupuoUEJo1KPqp3WaR+r9d5j1TgDhgzH29EQ5VO4fO5IaYRIH12OaCXnzHimPqG+E4QIJHSiHx4uGo8Fp6nLJ3DLATTZEIqWnIHqubArmJspVnimoImO8GAFowQwn45lTRxozNe57xjPyFtueoa6HlFZ3IUT1zKhVn/YVPNv+Wpgw+OpSlND+8P9SipcerRaWuY4ZUqUaWStfyxNoEgQdY7YKV4vCEuQ8+mVtdCfbNTJEkn1ziImiXOwWP+5HKLpcAs1mtABWHEMQwPzAwY4KqFWNYJcbMJej4NcUFNlO8Q9nFFLnN8zT63jCl+TJ2vxALtO8nMFLMFLU2vkXdsFre+qt8zRtMOBVbsm7k3RXeHZ6f3b53rgsrB0PlzjgQPVpJehR7B9+0O3qG/sKk+BoBDwqek= X-Forefront-PRVS: 02530BD3AA X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(39450400003)(6486002)(6916009)(50986999)(42186005)(36756003)(47776003)(1076002)(25786009)(23676002)(7736002)(6666003)(6506006)(2906002)(66066001)(50466002)(189998001)(5660300001)(2351001)(575784001)(86362001)(38730400002)(110136004)(6306002)(33646002)(81166006)(3846002)(6512007)(8676002)(6116002)(53936002)(2870700001)(4326008)(50226002)(305945005); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR07MB1728; H:elxcz23q12-y4.ca.am.ericsson.se; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; VI1PR07MB1728; 23:/k62sQ6Vk7RN4eFJxlhg4sFh92L/SPoSsneQtKzxzf//RYTSoxnqNJdvCm7zcShKCnpvQOZCHmK+65AnXDJLK6F1RlG5W77PsD0don1PrQN9T5KCuKxSDQ7+fPS1OwxmoMmuHYE0FglxF0FEygf4qmuRZZOct6LZcZWSnyAfFuhmBGAlYJmS8C8m3ae+15S+GJcghqYhwiuAq+mIf2qpJNZBSVnhK3LiZ8J1ootn4HOSxCpZPySFUOKo5mCsfXZxmjhrrqd4MXYqXnBmvyGWbucfm8mMYg8qmIPE1UqSU8q0f9ZsiA8f01JZk7cffE2Rp3ADsNcoJw7ntIeUQYOZBK0Tgay4Tf3+xOP0fEy8UShQMxvu3WYlhxJmKxK+r+OXKMeN+JTdDzz56C9+uy6Z36dCUpZS04HV1kqm0VkpaSaXEsIxnxJ+3KzIsei0D0UjJR80crq/ABoBH3eaYcuG6yxQBiS8ca5KL5SiLWj11e5l3sxtw1b5hKE3g0ItF191VXc6AsUREwYS/v5WT9J4nEAZdinH7GDD+UCobHezLJnR0N2BSwAsdp0RDXf14WTGsFbRKD8INcJ60NrzR9IjpotT+2xL5+IMQCijBjNLOkU47y0vPhjjzsLshQwhFjQlID2lC8AIP0pR6o60U0DXFLOXdiTwWCNL38PH++aAGiMAfJJuGw/SqFzAMEoOwj1A4D4PippXX6L1bdfs2KJbxQzL8SwCi0IEIPdDejrRokTlkOh9gEAs0ahpYTdUvxl1C1nkDIlTJFdQ2hXgGFVv64HsY+YoiRJwh9ljc892IgNfHiu3R62YIMkG4Tdo/svTzhyggniNugcQIrHsr5OvcLuF+L6GQgsryuWeWgI8cKk9i2Rnee8rDMH10/LU7zNQlBMmMCzmboOLOaxUPxbXcpjlMf4D6oOY4s6UXBqgWt4= X-Microsoft-Exchange-Diagnostics: 1; VI1PR07MB1728; 6:5ZWwKT7Rhukt8mIdj46zsijOMfSzMiFI05MxF6UV14mrnqKT60eFrzpG7Lq9QiChRMkJ/po6QlyH/+sEXwFv3yjgUIbBRvRPHt0dqDtYU23tJoz348MYxMacroxk6cZLVqBAS9J98cVLyKPut5RW71K+4H/3QNs4klDBcqX1w3bjxGgzvYVE+OWaaXvpHDru+j81slJodqosqvo3Ql0aXr5rnz/SUxgskqFBhkn4cpIWxB69tZcPmJI77u9Y/z+gmp2VaP45dqBU6XsR6twIpPCDNg2u9XSD75AhSmvKwlTLGFa89M/lYIXmV+M0Y/iuZMG5TI9sIB6+fKBjWNlucGf7fvE6Dpbw1ZNH6dZf2vKcd8bu7RBbCFXCg3UovjPJb9nYXHyYgcD+1eYRYAwIXg==; 5:8UlcD//oeIMYcpVR5hfD8PWm9XLQpV4Hp5TR4gpDC2pegG38NWNG2tO14QwPQ0UOYieW1OKy7GbiGlbWRLCybN+JrtKYr1tt8tF8OSLCRYrroTvaFAd8Vm1UJA9JhZ94nczfo9oDouZduelE2G3peA==; 24:6thQLdoyK4rnC+21U/MvNpBBvDA0oydDQammLF5dPm1U/+T6ZYmB6ok8mvNsRcLBJK3UKdbV2GvBHscmmQrfXFq39Q1lZJgiyzVItukQDEQ= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR07MB1728; 7:gjvtTRqlLOzhaq7wov3eAqBqdsq39qk8x5SLF9lkJV6L3/nh6s2V2mcPtX/NdHpdNEjiwV9yucbH8YHxE7+Jb2bjQTSE6sVXD2X8nnCy4Z0fadeSInfh+ruemRRrT61ROEugUokKEtyjps06hDFLHvFUmVUhRzLqassxL3uFTwFFoJHx/BFvz/T5UY1M+qo3yVaPI7aYBm4h7VqysfhTee8EBYsQe7bodJHAdqVmzYgS4riqmnVfhBeOe0RtfkP0UenHT2yHoGlo7oPNnsReBZyjSRpsKXsHsIW07yAOXivRPa4OkqrZR3anyw0eq9GREaD5W2/Nb2xepc1sTGI+bw== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Mar 2017 22:18:03.1211 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR07MB1728 X-OriginatorOrg: ericsson.com X-IsSubscribed: yes |
Commit Message
Simon Marchi
March 21, 2017, 10:17 p.m. UTC
From: Simon Marchi <simon.marchi@polymtl.ca>
When inferior_ptid represents a lwp, linux_nat_xfer_partial converts it
to a ptid with only the pid field set. For example, if
inferior_ptid is:
{ .pid = 1234, .lwp = 1235 }
it will change it to:
{ .pid = 1235, .lwp = 0 }
This is presumably because not all implementations of to_xfer_partial
that might be called down the line know how to handle a ptid with a lwp.
From what I found, it's been like this for a long long time, I traced
the original implementation at least to this commit (1999)
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=gdb/lin-thread.c;h=2f255c0e54a0387f1b7994c0bf808f4320b9b054;hb=ed9a39e#l1241
It looks like a hack to me, I think it's simpler if we just make all
implementations handle ptids correctly. The only place I found that
needed fixing is inf_ptrace_xfer_partial.
There is also linux_proc_xfer_partial and linux_proc_xfer_spu, which
both only use the pid field of inferior_ptid and ignore lwp. However,
since they use "/proc/<pid>", using the id of any thread in the process
will give the same result (AFAIK).
The testsuite found no regression on native amd64 linux.
gdb/ChangeLog:
* inf-ptrace.c (inf_ptrace_xfer_partial): Get pid from ptid
using get_ptrace_pid.
* linux-nat.c (linux_nat_xfer_partial): Don't set/restore
inferior_ptid.
---
gdb/inf-ptrace.c | 2 +-
gdb/linux-nat.c | 7 -------
2 files changed, 1 insertion(+), 8 deletions(-)
Comments
On 03/21/2017 10:17 PM, Simon Marchi wrote: > From: Simon Marchi <simon.marchi@polymtl.ca> > > When inferior_ptid represents a lwp, linux_nat_xfer_partial converts it > to a ptid with only the pid field set. For example, if > inferior_ptid is: > > { .pid = 1234, .lwp = 1235 } > > it will change it to: > > { .pid = 1235, .lwp = 0 } > > This is presumably because not all implementations of to_xfer_partial > that might be called down the line know how to handle a ptid with a lwp. > From what I found, it's been like this for a long long time, I traced > the original implementation at least to this commit (1999) > > https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=gdb/lin-thread.c;h=2f255c0e54a0387f1b7994c0bf808f4320b9b054;hb=ed9a39e#l1241 > > It looks like a hack to me, I think it's simpler if we just make all > implementations handle ptids correctly. The only place I found that > needed fixing is inf_ptrace_xfer_partial. Yeah... The stuffing of lwpids in the inferior_pid integer global was clearly a hack. But when later GDB grew the "ptid" structure, this shuffling made some sense -- way back then, when we had LinuxThreads instead of NTPL, the kernel didn't really have any concept of "threads" or "lwps". Threads were really each a heavy weight process. So in that sense, in the abstract, it made some sense to have inf-ptrace.c only ever think about processes. But, over the years we've been running into issues with that, and over time the inf-ptrace.c layer as been adjusted to understand these ptids. Commit 90ad5e1d4f34d0 ("Linux/ptrace: don't convert ptids when asking inf-ptrace layer to resume LWP") is one that comes to mind. You've running into some left overs of a long slow conversion... > > There is also linux_proc_xfer_partial and linux_proc_xfer_spu, which > both only use the pid field of inferior_ptid and ignore lwp. However, > since they use "/proc/<pid>", using the id of any thread in the process > will give the same result (AFAIK). It's generally better to use the lwp id: - some files under /proc/<pid>/ may not work if the <pid> thread is running, just like ptrace requires a stopped thread. The current thread's lwp id is more likely to be in the necessary state (stopped). - if the leader exits, and goes zombie, then several files under "/proc/<pid>" won't work, though using "/proc/<pid>/task/<tid>" would. (try poking at leader-exit.exp a bit.) The latter path form is also generally better for being robust in the case TID exits and is reused in another process, much like tkill vs tgkill. So if possible to switch those spots too, I'd recommend/prefer it. > > The testsuite found no regression on native amd64 linux. > > gdb/ChangeLog: > > * inf-ptrace.c (inf_ptrace_xfer_partial): Get pid from ptid > using get_ptrace_pid. > * linux-nat.c (linux_nat_xfer_partial): Don't set/restore > inferior_ptid. Looks good to me. Thanks, Pedro Alves
On 2017-03-21 19:58, Pedro Alves wrote: > Yeah... The stuffing of lwpids in the inferior_pid integer global was > clearly > a hack. But when later GDB grew the "ptid" structure, this shuffling > made some sense -- way back then, when we had LinuxThreads instead of > NTPL, the > kernel didn't really have any concept of "threads" or "lwps". Threads > were really each a heavy weight process. So in that sense, in the > abstract, > it made some sense to have inf-ptrace.c only ever think about > processes. But, > over the years we've been running into issues with that, and over time > the inf-ptrace.c layer as been adjusted to understand these ptids. > Commit 90ad5e1d4f34d0 > ("Linux/ptrace: don't convert ptids when asking inf-ptrace layer to > resume LWP") > is one that comes to mind. You've running into some left overs of a > long > slow conversion... Ok, thanks for the history bits. >> There is also linux_proc_xfer_partial and linux_proc_xfer_spu, which >> both only use the pid field of inferior_ptid and ignore lwp. However, >> since they use "/proc/<pid>", using the id of any thread in the >> process >> will give the same result (AFAIK). > > It's generally better to use the lwp id: > > - some files under /proc/<pid>/ may not work if the <pid> thread is > running, just like ptrace requires a stopped thread. The current > thread's lwp id is more likely to be in the necessary state > (stopped). > > - if the leader exits, and goes zombie, then several files under > "/proc/<pid>" won't work, though using "/proc/<pid>/task/<tid>" > would. > (try poking at leader-exit.exp a bit.) > The latter path form is also generally better for being robust in > the case TID exits and is reused in another process, much like > tkill vs tgkill. I thought that the process exited whenever the main thread exits, that's not the case? I guess not if there's a test for it... > So if possible to switch those spots too, I'd recommend/prefer it. Ok, I'll just replace ptid_get_pid with get_ptrace_pid* in this patch and look at using /proc/<pid>/task/<tid> after. When doing the latter, do I still have to consider cases where ptid is a single-process/thread ptid (lwp == 0)? From my experience, there's always a lwp on Linux, but perhaps there are some setups I don't know about with which it can happen? * using get_ptrace_pid is an abuse of terminology, since we're not using ptrace, but it does what we want. Thanks, Simon
On 03/22/2017 12:42 AM, Simon Marchi wrote: >>> There is also linux_proc_xfer_partial and linux_proc_xfer_spu, which >>> both only use the pid field of inferior_ptid and ignore lwp. However, >>> since they use "/proc/<pid>", using the id of any thread in the process >>> will give the same result (AFAIK). >> >> It's generally better to use the lwp id: >> >> - some files under /proc/<pid>/ may not work if the <pid> thread is >> running, just like ptrace requires a stopped thread. The current >> thread's lwp id is more likely to be in the necessary state (stopped). >> >> - if the leader exits, and goes zombie, then several files under >> "/proc/<pid>" won't work, though using "/proc/<pid>/task/<tid>" would. >> (try poking at leader-exit.exp a bit.) >> The latter path form is also generally better for being robust in >> the case TID exits and is reused in another process, much like >> tkill vs tgkill. > > I thought that the process exited whenever the main thread exits, that's > not the case? I guess not if there's a test for it... Nope. If you call "exit", then yes. The kernel kills the whole thread group in response to that system call. If the leader does pthread_exit, then no, the thread group stays around until all children exit too. The kernel won't report the main thread's exit status (i.e., we can't reap that zombie, and we'd hang if we tried a blocking waitpid) until all the children are reaped first. That's why we have linux-nat.c:check_zombie_leaders (and the equivalent in gdbserver). >> So if possible to switch those spots too, I'd recommend/prefer it. > > Ok, I'll just replace ptid_get_pid with get_ptrace_pid* in this patch Since this is linux-specific code, you should be able to use ptid_get_lwp directly. > and look at using /proc/<pid>/task/<tid> after. When doing the latter, > do I still have to consider cases where ptid is a single-process/thread > ptid (lwp == 0)? From my experience, there's always a lwp on Linux, but > perhaps there are some setups I don't know about with which it can happen? Right, on Linux there's always an lwp. Before NPTL, the /proc/<pid>/task/<tid> path didn't exist at all, but we no longer support LinuxThreads. Thanks, Pedro Alves
On 03/22/2017 01:00 AM, Pedro Alves wrote: >> and look at using /proc/<pid>/task/<tid> after. When doing the latter, >> do I still have to consider cases where ptid is a single-process/thread >> ptid (lwp == 0)? From my experience, there's always a lwp on Linux, but >> perhaps there are some setups I don't know about with which it can happen? > > Right, on Linux there's always an lwp. Before NPTL, the > /proc/<pid>/task/<tid> path didn't exist at all, but we no longer > support LinuxThreads. I think I read the question all backwards. I understood you were asking whether the <tid> in that /proc patch would be 0 in some cases... Sorry. So trying again: In linux-nat.c, you only see a ptid without an lwp filled in during early child process startup, either while attaching (see thread_change_ptid call in linux_nat_attach), or while doing the first iteration of the fork-child.c:startup_inferior dance. The lwp is filled in at the top of linux_nat_wait_1 [1]. I don't think we access /proc between the initial fork and that spot. If we did, we'd be accessing the process while it was still executing the shell, and startup_inferior was invented exactly to prevent that sort of inadvertent access. [1] And that is another inferior_ptid hack that we should get rid of ... somehow ... Thanks, Pedro Alves
On 2017-03-21 21:00, Pedro Alves wrote: > Nope. If you call "exit", then yes. The kernel kills the whole thread > group in response to that system call. If the leader does > pthread_exit, then no, the thread group stays around until all children > exit too. The kernel won't report the main thread's exit status (i.e., > we can't reap that zombie, and we'd hang if we tried a blocking > waitpid) > until all the children are reaped first. That's why we have > linux-nat.c:check_zombie_leaders (and the equivalent in gdbserver). Oh ok, in my testing I was just letting main return, but I guess it reaches a point where the libc calls the exit syscall. When I call pthread_exit, the process stays alive. >>> So if possible to switch those spots too, I'd recommend/prefer it. >> >> Ok, I'll just replace ptid_get_pid with get_ptrace_pid* in this patch > > Since this is linux-specific code, you should be able to use > ptid_get_lwp directly. Ok. >> and look at using /proc/<pid>/task/<tid> after. When doing the >> latter, >> do I still have to consider cases where ptid is a >> single-process/thread >> ptid (lwp == 0)? From my experience, there's always a lwp on Linux, >> but >> perhaps there are some setups I don't know about with which it can >> happen? > > Right, on Linux there's always an lwp. Before NPTL, the > /proc/<pid>/task/<tid> path didn't exist at all, but we no longer > support LinuxThreads. Thanks, I'm sending an updated patch. Simon
diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c index 61d24269a8..f912d28088 100644 --- a/gdb/inf-ptrace.c +++ b/gdb/inf-ptrace.c @@ -520,7 +520,7 @@ inf_ptrace_xfer_partial (struct target_ops *ops, enum target_object object, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) { - pid_t pid = ptid_get_pid (inferior_ptid); + pid_t pid = get_ptrace_pid (inferior_ptid); switch (object) { diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 73ef2d4947..0827f546a8 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -3890,7 +3890,6 @@ linux_nat_xfer_partial (struct target_ops *ops, enum target_object object, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) { - struct cleanup *old_chain; enum target_xfer_status xfer; if (object == TARGET_OBJECT_SIGNAL_INFO) @@ -3903,15 +3902,9 @@ linux_nat_xfer_partial (struct target_ops *ops, enum target_object object, if (object == TARGET_OBJECT_MEMORY && ptid_equal (inferior_ptid, null_ptid)) return TARGET_XFER_EOF; - old_chain = save_inferior_ptid (); - - if (ptid_lwp_p (inferior_ptid)) - inferior_ptid = pid_to_ptid (ptid_get_lwp (inferior_ptid)); - xfer = linux_ops->to_xfer_partial (ops, object, annex, readbuf, writebuf, offset, len, xfered_len); - do_cleanups (old_chain); return xfer; }