Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@ericsson.com>
To: John Baldwin <jhb@FreeBSD.org>, <gdb-patches@sourceware.org>
Subject: Re: [PATCH 3/5] Add support for 'info proc files' on FreeBSD core dumps.
Date: Sat, 08 Sep 2018 22:54:00 -0000	[thread overview]
Message-ID: <26938c44-7bab-3951-ff2f-d0567d3aee39@ericsson.com> (raw)
In-Reply-To: <20180908003659.37482-4-jhb@FreeBSD.org>

On 2018-09-08 01:36 AM, John Baldwin wrote:
> Walk the list of struct kinfo_file objects in the
> NT_FREEBSD_PROCSTAT_FILES core dump note outputting a description of
> each open file descriptor.  For sockets, the local and remote socket
> addresses are displayed in place of the file name field.  For UNIX
> local domain sockets, only a single address is displayed since most
> UNIX sockets only have one valid address and printing both pathnames
> could be quite long.  The output format was somewhat inspired by the
> output of the "procstat -f" command on FreeBSD, but with a few less
> details and some fields were condensed.

Just some nits, LGTM otherwise.
> diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c
> index 9e6d7276c4..a8b5b2f146 100644
> --- a/gdb/fbsd-tdep.c
> +++ b/gdb/fbsd-tdep.c
> @@ -90,18 +90,115 @@
>  #define	KF_STRUCTSIZE		0x0
>  #define	KF_TYPE			0x4
>  #define	KF_FD			0x8
> +#define	KF_FLAGS		0x10
> +#define	KF_OFFSET		0x18

In sys/user.h, it says:

 /* XXX Hidden alignment padding here on amd64 */

Does that mean the field offsets can be different for other arches?

> +/* Constats for socket types.  These match SOCK_* constants in

"Constats"

> +/* Helper function to print out an IPv6 socket address.  The address
> +   is formatted similar to inet_ntop.  */
> +
> +static void
> +fbsd_print_sockaddr_in6 (void *sockaddr)
> +{
> +  struct fbsd_sockaddr_in6 *sin6 =
> +    reinterpret_cast<struct fbsd_sockaddr_in6 *>(sockaddr);
> +  uint16_t words[ARRAY_SIZE(sin6->sin6_addr) / 2];
> +
> +  /* Populate the array of 16-bit words from network-order bytes.  */
> +  for (int i = 0; i < ARRAY_SIZE(words); i++)
> +    words[i] = (sin6->sin6_addr[i * 2] << 8) | sin6->sin6_addr[i * 2 + 1];
> +
> +  /* Find the longest run of zero words.  */
> +  int best, bestlen, current, len;
> +
> +  best = -1;
> +  bestlen = 0;
> +  current = -1;
> +  len = 0;
> +  for (int i = 0; i < ARRAY_SIZE(words); i++)
> +    {
> +      if (words[i] == 0)
> +	{
> +	  if (current >= 0)
> +	    len++;
> +	  else
> +	    {
> +	      current = i;
> +	      len = 1;
> +	    }
> +	}
> +      else
> +	{
> +	  if (current >= 0 && len > bestlen)
> +	    {
> +	      best = current;
> +	      bestlen = len;
> +	    }
> +	  current = -1;
> +	  len = 0;
> +	}
> +    }
> +  if (current >= 0 && len > bestlen)
> +    {
> +      best = current;
> +      bestlen = len;
> +    }
> +  if (bestlen < 2)
> +    best = -1;
> +
> +  for (int i = 0; i < ARRAY_SIZE(words); i++)
> +    {
> +      if (best >= 0 && i >= best && i < best + bestlen)
> +	{
> +	  if (i == best || i == ARRAY_SIZE(words) - 1)
> +	    printf_filtered (":");
> +	}
> +      else
> +	{
> +	  if (i != 0)
> +	    printf_filtered (":");
> +	  printf_filtered ("%x", words[i]);
> +	}
> +    }
> +  printf_filtered (".%u", (sin6->sin6_port[0] << 8) | sin6->sin6_port[1]);
> +}

Hmm, I suppose we'll want to re-use this ipv6 address printing code for the Linux...
We can take care of moving it to a common file then.

> +/* Implement "info proc files" for a corefile.  */
> +
> +static void
> +fbsd_core_info_proc_files (struct gdbarch *gdbarch)
> +{
> +  asection *section;
> +  unsigned char *descdata, *descend;
> +  size_t note_size;

Don't hesitate to declare them variables at the point you use the the first time :).
> +
> +  section = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.files");
> +  if (section == NULL)
> +    {
> +      warning (_("unable to find open files in core file"));
> +      return;
> +    }
> +
> +  note_size = bfd_get_section_size (section);
> +  if (note_size < 4)
> +    error (_("malformed core note - too short for header"));
> +
> +  gdb::def_vector<unsigned char> contents (note_size);
> +  if (!bfd_get_section_contents (core_bfd, section, contents.data (),
> +				 0, note_size))
> +    error (_("could not get core note contents"));
> +
> +  descdata = contents.data ();
> +  descend = descdata + note_size;
> +
> +  /* Skip over the structure size.  */
> +  descdata += 4;
> +
> +  printf_filtered (_("Open files:\n\n"));
> +  printf_filtered ("  %6s %6s %10s %9s %s\n",
> +		   "FD", "Type", "Offset", "Flags  ", "Name");
> +
> +  while (descdata + KF_PATH < descend)
> +    {
> +      LONGEST fd, flags, offset, type, vnode_type;
> +      ULONGEST structsize;
> +
> +      structsize = bfd_get_32 (core_bfd, descdata + KF_STRUCTSIZE);
> +      if (structsize < KF_PATH)
> +	error (_("malformed core note - vmmap entry too small"));

Copy pasta?  Actually, there seems to be the same mistake in fbsd_core_vnode_path.

Simon


  reply	other threads:[~2018-09-08 22:54 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-08  0:38 [PATCH 0/5] Add a new 'info proc files' command John Baldwin
2018-09-08  0:38 ` [PATCH 3/5] Add support for 'info proc files' on FreeBSD core dumps John Baldwin
2018-09-08 22:54   ` Simon Marchi [this message]
2018-09-10 19:37     ` John Baldwin
2018-09-13 15:08       ` Tom Tromey
2018-09-13 18:42         ` John Baldwin
2018-09-08  0:38 ` [PATCH 1/5] Use KF_PATH to verify the size of a struct kinfo_file John Baldwin
2018-09-08 22:25   ` Simon Marchi
2018-09-08  0:38 ` [PATCH 2/5] Add a new 'info proc files' subcommand of 'info proc' John Baldwin
2018-09-08  6:49   ` Eli Zaretskii
2018-09-08 22:31     ` Simon Marchi
2018-09-09  5:23       ` Eli Zaretskii
2018-09-10 18:43         ` John Baldwin
2018-09-10 19:11           ` Eli Zaretskii
2018-09-08 22:32   ` Simon Marchi
2018-09-08  0:46 ` [PATCH 5/5] Document the 'info proc files' command John Baldwin
2018-09-08  7:01   ` Eli Zaretskii
2018-09-10 18:43     ` John Baldwin
2018-09-10 19:13       ` Eli Zaretskii
2018-09-10 18:52     ` John Baldwin
2018-09-08  0:46 ` [PATCH 4/5] Support 'info proc files' on live FreeBSD processes John Baldwin
2018-09-08 23:01   ` Simon Marchi
2018-09-10 18:30     ` John Baldwin
2018-09-10 19:03       ` Simon Marchi
2018-09-12 22:38         ` John Baldwin

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=26938c44-7bab-3951-ff2f-d0567d3aee39@ericsson.com \
    --to=simon.marchi@ericsson.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jhb@FreeBSD.org \
    /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