Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Kamil Rytarowski <n54@gmx.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Implement IP_STAT on NetBSD
Date: Mon, 13 Apr 2020 16:11:49 -0400	[thread overview]
Message-ID: <52edb779-5a48-ccd0-4873-67551aa89eac@simark.ca> (raw)
In-Reply-To: <4671cd7b-b081-1aad-88c3-f40aaefa38f5@gmx.com>

On 2020-04-13 3:43 p.m., Kamil Rytarowski wrote:
>>> @@ -433,6 +568,149 @@ nbsd_nat_target::info_proc (const char *args, enum info_proc_what what)
>>>        else
>>>  	warning (_("unable to fetch virtual memory map"));
>>>      }
>>> +  if (do_stat)
>>> +    {
>>> +      /* First, try with Linux-compat /proc/<pid>/stat. */
>>> +      char filename[100];
>>> +      xsnprintf (filename, sizeof filename, "/proc/%d/stat", pid);
>>
>> Use
>>
>>   std::string filename = string_printf (...);
>>
> 
> OK. Meanwhile linux-tdep.c could be upgraded by a Linux maintainer.

Ok

>>> +      gdb::unique_xmalloc_ptr<char> statstr
>>> +	= target_fileio_read_stralloc (NULL, filename);
>>> +
>>> +      /* Then fallback to emulating /proc/<pid>/stat with sysctl(3).  */
>>> +      if (statstr == nullptr)
>>> +	statstr = nbsd_pid_to_statstr (pid);
>>
>> I find it a bit strange to take the route of formatting the contents of kinfo_proc2,
>> only to parse it here.  I think it would have been more natural to do:
>>
>> - If /proc/#/stat is available: string -> struct some_internal_struct -> print function
>> - If /proc/#/stat is available: kinfo_proc2 -> struct some_internal_struct -> print function
>>
> 
> 
> This compat shim is only to emulate Linux... it's possible to follow the
> FreeBSD case and just print local kinfo_proc2 as-is (that is fully
> OS-specific).
> 
> What do you think?
> 
> The same question applies to IP_STATUS.

When you put it like this... it just seems useless to read the info from /proc.

If sysctl is guaranteed to always be there and is the blessed way of getting the
information, then let's just use that.  The goal is not to emulate Linux, but to
use each OS's interface to get the required information.
>>> +#if 0	/* Don't know how architecture-dependent the rest is...
>>> +	   Anyway the signal bitmap info is available from "status".  */
>>
>> Either figure out how to print this correctly, or let's just leave it out.
>>
> 
> This comment was copied as-is from gdb/linux-tdep.c.

In my opinion it's not great to leave this as-is in linux-tdep.c either, so I'd
suggest to avoid spreading it.

Simon


  reply	other threads:[~2020-04-13 20:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-13 18:19 Kamil Rytarowski
2020-04-13 19:16 ` Simon Marchi
2020-04-13 19:43   ` Kamil Rytarowski
2020-04-13 20:11     ` Simon Marchi [this message]
2020-04-13 20:26       ` Kamil Rytarowski
2020-04-13 20:43         ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52edb779-5a48-ccd0-4873-67551aa89eac@simark.ca \
    --to=simark@simark.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=n54@gmx.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox