From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by sourceware.org (Postfix) with ESMTPS id CAA963846410 for ; Thu, 25 Apr 2024 12:48:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CAA963846410 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CAA963846410 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714049305; cv=none; b=epA3NSwv5j43yp1K7cqCU/3JcC5NwgnlRMzLF/JNv8MpbUfvxY9zR/J499RG4QPVQRAhTLVxUqDX1SZoZVJHUWfck+xkuOuRqxNGmZaifQDdgOOv7GynVRQXASl0KOmxtH/JuuDE1SwNLw5EfWtKRbLmJwJudzJh7DDsy8qHmQA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714049305; c=relaxed/simple; bh=qPcHU6PsN9UIJc17K6vs51PnxXZSS8kOCJyFylL5roo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=aLYfZvlCAskMO35GGr+UCyMH4ZcEpgzf6D6CHuDAzyuWY6xrqb9adgqU6y4uf2OpfQKbXbDrM4WbeBSgEBvz6BetllSQF8ZdLhbPMLpnOQm6klZ0E+aSKp8GEwCKw6qu+oU2ijOLw7ZImILEUtozXVK9W7LLRA1ecoqE4NKBehU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1e5715a9ebdso7301245ad.2 for ; Thu, 25 Apr 2024 05:48:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1714049292; x=1714654092; darn=sourceware.org; h=mime-version:message-id:date:user-agent:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=jaFqLzj5/ulqRj4GwvUIW5MfhKuYKUrCMB3xjNzMU5g=; b=Y7rOa/mBINOcadUa8lBpDM3OBqR9JOm2DDc366hOnh2utg0fSFwUZPU1YxOh+Pc5Ta J47zBGXcY9de5zXO6qgDLtpJV8laU+MmuIWjPoTYq391nTkDYojWdHG1zC0DLGMwbXvH 4ARbt020O7cAZ2NSJ9U7k7s7urkRxK6SCq1ImkY7AWtSWH+D6J+6JWogWNqBNcd06d7a bpsbEsD8i4sl5MCrzvp07WL38zdu00ojoAJV+aEvjy3j/9ptyIrNX+Hb3pAZb9PSIMYB zh+A/CLira32uW2BrQ/2i9+tOzA9+Bx1uQqjzBloYDFcgRZ9FGNim58Cu6WV9Fuud2zh viWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714049292; x=1714654092; h=mime-version:message-id:date:user-agent:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=jaFqLzj5/ulqRj4GwvUIW5MfhKuYKUrCMB3xjNzMU5g=; b=QT16IRJt1jurauhpXawtDcmUScXoichU9trDEIaTz4CXGGY214eH+BDDNwLTEZAW8q nejjusIAJIo2kL5Mxh4OhJNZLp9521utVDyx07yhnPGNbPwgg8n2iq3t9Oa9AlOP2gbv wMOPjxZgVpq+SyXbWhjRVoqqCxipLJuiKVTCuQ4OXF6WfhUB0NqCa93j8gJgiqxHPMy+ dm/oZhZiZ1ci7A8BmkXVVpdf4qDKMS1BW82Nv+OnkL90/0NkLNYyPxWderbGy6BoiQwc ivq5JeVKZ8c4k8rzbze2K3Loyo2+T97RfBb2lID3HSa+YsydafWs/B7aNbPHQd7gToM+ PKFA== X-Gm-Message-State: AOJu0YwoS529vR6pBoTgTePHHMb1dOyQ4DDB1nuwSe0LFGuCaFmMwWjb nmwCOUWl2iUEzq+n/4dk+U0mRE9IHCkpyFBDWv4FuOczMvP2VVxZFLe96p4ELKI= X-Google-Smtp-Source: AGHT+IH5gy6ELzBrVBwTNLGHzzmKdudEI7vjVJ52pDRNK9Yshxfrc8Oze6OFUarA1JAjvQK7P6txBA== X-Received: by 2002:a17:902:aa96:b0:1e3:e022:1dd9 with SMTP id d22-20020a170902aa9600b001e3e0221dd9mr5776684plr.40.1714049292219; Thu, 25 Apr 2024 05:48:12 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8470:4679:db60:86de:9cf5]) by smtp.gmail.com with ESMTPSA id w5-20020a1709029a8500b001e435350a7bsm13633271plp.259.2024.04.25.05.48.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 05:48:11 -0700 (PDT) From: Thiago Jung Bauermann To: Luis Machado Cc: gdb-patches@sourceware.org, Christophe Lyon , Pedro Alves Subject: Re: [PATCH v3 2/3] gdb/nat: Factor linux_proc_get_stat_field out of linux_common_core_of_thread In-Reply-To: (Luis Machado's message of "Thu, 25 Apr 2024 10:04:56 +0100") References: <20240424231551.1577518-1-thiago.bauermann@linaro.org> <20240424231551.1577518-3-thiago.bauermann@linaro.org> <4f0352e1-dc25-48ee-8366-0a3135cbc353@arm.com> User-Agent: mu4e 1.12.4; emacs 29.3 Date: Thu, 25 Apr 2024 09:48:09 -0300 Message-ID: <87y1911ud2.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hello Luis, Luis Machado writes: > On 4/25/24 09:59, Luis Machado wrote: >> On 4/25/24 00:15, Thiago Jung Bauermann wrote: >>> diff --git a/gdb/nat/linux-procfs.c b/gdb/nat/linux-procfs.c >>> index e2086952ce6b..c11eaf3cc6fd 100644 >>> --- a/gdb/nat/linux-procfs.c >>> +++ b/gdb/nat/linux-procfs.c >>> @@ -230,6 +230,50 @@ linux_proc_pid_is_zombie (pid_t pid) >>> >>> /* See linux-procfs.h. */ >>> >>> +std::optional >>> +linux_proc_get_stat_field (ptid_t ptid, int field) >>> +{ >>> + /* We never need to read PID from the stat file, and there's >>> + command_from_pid to read the comm field. */ >>> + gdb_assert (field >= LINUX_PROC_STAT_STATE); >>> + >>> + std::string filename = string_printf ("/proc/%ld/task/%ld/stat", >>> + (long) ptid.pid (), (long) ptid.lwp ()); >>> + >>> + std::optional content >>> + = read_text_file_to_string (filename.c_str ()); >>> + if (!content.has_value ()) >>> + return {}; >>> + >>> + /* ps command also relies on no trailing fields ever contain ')'. */ >> >> Probably an existing typo, but s/contain/containing? >> >> No need to send a v5 for this though. >> > > Eh, or v4 rather. :-) I think you're right. Fixed locally. >>> + std::string::size_type pos = content->find_last_of (')'); >>> + if (pos == std::string::npos) >>> + return {}; >>> + >>> + /* The first field after program name is LINUX_PROC_STAT_STATE. */ >>> + for (int i = LINUX_PROC_STAT_STATE; i <= field; ++i) >>> + { >>> + /* Find separator. */ >>> + pos = content->find_first_of (' ', pos); >>> + if (pos == std::string::npos) >>> + return {}; >>> + >>> + /* Find beginning of field. */ >>> + pos = content->find_first_not_of (' ', pos); >>> + if (pos == std::string::npos) >>> + return {}; >>> + } >>> + >>> + /* Find end of field. */ >>> + std::string::size_type end_pos = content->find_first_of (' ', pos); >>> + if (end_pos == std::string::npos) >>> + return content->substr (pos); >>> + else >>> + return content->substr (pos, end_pos - pos); >>> +} >> Otherwise looks OK. Thanks! -- Thiago