Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Ser <contact@emersion.fr>
To: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Cc: John Baldwin <jhb@FreeBSD.org>
Subject: Re: [PATCH v5] Generate NT_PROCSTAT_{AUXV,VMMAP,PS_STRINGS} in FreeBSD coredumps
Date: Sun, 02 Sep 2018 20:02:00 -0000	[thread overview]
Message-ID: <6iz9XpK7m-0Fumt1t9LmZGLgi6vpQ8dIh21if-zu7fbvUH51Ef4YYAjZHt80Cy2YmoviGYM9Igaebc8024iHdtxKDGBNQOJpKhKrFD5lnjw=@emersion.fr> (raw)
In-Reply-To: <h3x9R8eOcXQBRVyDqS1d2dSBbWjK755lzNGO8KjTlTMnyKZgKltVJToxgowu8o8MxqAhmiPv0FqYmc7nvcZGoM_wawX5-6dTDZFuriS9_2o=@emersion.fr>

Hi John,

Did you have time to have a look at this new version ?

Thanks,
---
Simon Ser
https://emersion.fr

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On 23 August 2018 7:10 PM, Simon Ser <contact@emersion.fr> wrote:

> gcore generates NT_AUXV and NT_FILE notes for Linux targets. On
> FreeBSD auxv is stored in a NT_PROCSTAT_AUXV section, virtual memory
> mappings are stored in a NT_PROCSTAT_VMMAP and both are prefixed with
> the struct size.
>
> 2018-08-23 Simon Ser contact@emersion.fr
>
>         * target.h (enum target_object): add FreeBSD-specific
>         TARGET_OBJECT_FREEBSD_VMMAP and TARGET_OBJECT_FREEBSD_PS_STRINGS
>         * fbsd-nat.c (fbsd_nat_target::xfer_partial): add support for
>         TARGET_OBJECT_FREEBSD_VMMAP and TARGET_OBJECT_FREEBSD_PS_STRINGS
>         * fbsd-tdep.c (fbsd_make_corefile_notes): write NT_PROCSTAT_AUXV,
>         NT_PROCSTAT_VMMAP and NT_PROCSTAT_PS_STRINGS notes
>
>
> Changes from v4 to v5:
>
> -   Fixed buflen too large before sysctl
>
>     gdb/fbsd-nat.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++
>     gdb/fbsd-tdep.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++
>     gdb/target.h | 4 ++++
>     3 files changed, 113 insertions(+)
>
>     diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c
>     index 115deac0..3c1904a1 100644
>     --- a/gdb/fbsd-nat.c
>     +++ b/gdb/fbsd-nat.c
>     @@ -751,6 +751,61 @@ fbsd_nat_target::xfer_partial (enum target_object object,
>     }
>     return TARGET_XFER_E_IO;
>     }
>
>
> -   case TARGET_OBJECT_FREEBSD_VMMAP:
>
> -   case TARGET_OBJECT_FREEBSD_PS_STRINGS:
>
> -        {
>
>
> -   gdb::byte_vector buf_storage;
>
> -   gdb_byte *buf;
>
> -   size_t buflen;
>
> -   int mib[4];
>
> -
> -   int proc_target;
>
> -   uint32_t struct_size;
>
> -   switch (object)
>
> -       {
>
>
> -       case TARGET_OBJECT_FREEBSD_VMMAP:
>
>
> -         proc_target = KERN_PROC_VMMAP;
>
>
> -         struct_size = sizeof (struct kinfo_vmentry);
>
>
> -         break;
>
>
> -       case TARGET_OBJECT_FREEBSD_PS_STRINGS:
>
>
> -         proc_target = KERN_PROC_PS_STRINGS;
>
>
> -         struct_size = sizeof (void *);
>
>
> -         break;
>
>
> -       }
>
>
> -
> -   if (writebuf != NULL)
>
> -       return TARGET_XFER_E_IO;
>
>
> -
> -   mib[0] = CTL_KERN;
>
> -   mib[1] = KERN_PROC;
>
> -   mib[2] = proc_target;
>
> -   mib[3] = pid;
>
> -
> -   if (sysctl (mib, 4, NULL, &buflen, NULL, 0) != 0)
>
> -       return TARGET_XFER_E_IO;
>
>
> -   buflen += sizeof (struct_size);
>
> -
> -   if (offset >= buflen)
>
> -       {
>
>
> -         *xfered_len = 0;
>
>
> -         return TARGET_XFER_EOF;
>
>
> -       }
>
>
> -
> -   buf_storage.resize (buflen);
>
> -   buf = buf_storage.data ();
>
> -
> -   memcpy (buf, &struct_size, sizeof (struct_size));
>
> -   buflen -= sizeof (struct_size);
>
> -   if (sysctl (mib, 4, buf + sizeof (struct_size), &buflen, NULL, 0) != 0)
>
> -       return TARGET_XFER_E_IO;
>
>
> -   buflen += sizeof (struct_size);
>
> -
> -   if (offset + len > buflen)
>
> -       len = buflen - offset;
>
>
> -   memcpy (readbuf, buf + offset, len);
>
> -   *xfered_len = len;
>
> -   return TARGET_XFER_OK;
>
> -        }
>
>
>     default:
>     return inf_ptrace_target::xfer_partial (object, annex,
>     readbuf, writebuf, offset,
>     diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c
>     index 9cea0098..9242c244 100644
>     --- a/gdb/fbsd-tdep.c
>     +++ b/gdb/fbsd-tdep.c
>     @@ -512,6 +512,23 @@ fbsd_corefile_thread (struct thread_info *info,
>     args->note_size, args->stop_signal);
>
>
> }
>
> +static gdb::optionalgdb::byte_vector
> +fbsd_make_note_desc (enum target_object object, uint32_t structsize)
> +{
>
> -   gdb::optionalgdb::byte_vector buf =
>
> -   target_read_alloc (current_top_target (), object, NULL);
>
> -   if (!buf || buf->empty ())
>
> -   return {};
>
> -
> -   if (structsize == 0)
>
> -   return buf;
>
> -
> -   gdb::byte_vector desc (sizeof (structsize) + buf->size ());
>
> -   memcpy (desc.data (), &structsize, sizeof (structsize));
>
> -   memcpy (desc.data () + sizeof (structsize), buf->data (), buf->size ());
>
> -   return desc;
>     +}
>
> -
>
> /* Create appropriate note sections for a corefile, returning them in
> allocated memory. */
>
> @@ -586,6 +603,43 @@ fbsd_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
>
> note_data = thread_args.note_data;
>
> -   pid_t pid = inferior_ptid.pid ();
>
> -
> -   /* Auxiliary vector. */
>
> -   uint32_t structsize = gdbarch_ptr_bit (gdbarch) / 4; /* Elf_Auxinfo */
>
> -   gdb::optionalgdb::byte_vector note_desc =
>
> -   fbsd_make_note_desc (TARGET_OBJECT_AUXV, structsize);
>
> -   if (note_desc && !note_desc->empty ())
>
> -   {
>
> -        note_data = elfcore_write_note (obfd, note_data, note_size,
>
>
> -         		      "FreeBSD", NT_FREEBSD_PROCSTAT_AUXV,
>
>
> -         		      note_desc->data (), note_desc->size ());
>
>
> -        if (!note_data)
>
>
> -   return NULL;
>
> -   }
>
> -
> -   /* Virtual memory mappings */
>
> -   note_desc = fbsd_make_note_desc (TARGET_OBJECT_FREEBSD_VMMAP, 0);
>
> -   if (note_desc && !note_desc->empty ())
>
> -   {
>
> -        note_data = elfcore_write_note (obfd, note_data, note_size,
>
>
> -         		      "FreeBSD", NT_FREEBSD_PROCSTAT_VMMAP,
>
>
> -         		      note_desc->data (), note_desc->size ());
>
>
> -        if (!note_data)
>
>
> -   return NULL;
>
> -   }
>
> -
> -   note_desc =
>
> -   fbsd_make_note_desc (TARGET_OBJECT_FREEBSD_PS_STRINGS, 0);
>
> -   if (note_desc && !note_desc->empty ())
>
> -   {
>
> -        note_data = elfcore_write_note (obfd, note_data, note_size, "FreeBSD",
>
>
> -         		      NT_FREEBSD_PROCSTAT_PSSTRINGS,
>
>
> -         		      note_desc->data (), note_desc->size ());
>
>
> -        if (!note_data)
>
>
> -   return NULL;
>
> -   }
>
> -   return note_data;
>     }
>
>     diff --git a/gdb/target.h b/gdb/target.h
>     index 18c4a84c..c584af54 100644
>     --- a/gdb/target.h
>     +++ b/gdb/target.h
>     @@ -203,6 +203,10 @@ enum target_object
>     of the process ID of the process in question, in hexadecimal
>     format. */
>     TARGET_OBJECT_EXEC_FILE,
>
> -   /* FreeBSD virtual memory mappings */
>
> -   TARGET_OBJECT_FREEBSD_VMMAP,
>
> -   /* FreeBSD process strings */
>
> -   TARGET_OBJECT_FREEBSD_PS_STRINGS,
>     /* Possible future objects: TARGET_OBJECT_FILE, ... */
>     };
>
>     --
>     2.18.0
>



  reply	other threads:[~2018-09-02 20:02 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-11 12:35 [PATCH] Generate NT_PROCSTAT_{AUXV,VMMAP} " Simon Ser
2018-07-11 16:16 ` John Baldwin
2018-07-11 16:40   ` Simon Ser
2018-07-16 13:39 ` [PATCH v2] Generate NT_PROCSTAT_{AUXV,VMMAP,PS_STRINGS} " Simon Ser
2018-07-24  7:53   ` Simon Ser
2018-08-01 16:33     ` Simon Ser
2018-08-01 18:16   ` John Baldwin
2018-08-21 14:45   ` [PATCH v3] " Simon Ser
2018-08-23 10:40     ` John Baldwin
2018-08-23 14:02     ` [PATCH v4] " Simon Ser
2018-08-23 16:16       ` John Baldwin
2018-08-23 17:11       ` [PATCH v5] " Simon Ser
2018-09-02 20:02         ` Simon Ser [this message]
2018-09-06 22:12           ` 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='6iz9XpK7m-0Fumt1t9LmZGLgi6vpQ8dIh21if-zu7fbvUH51Ef4YYAjZHt80Cy2YmoviGYM9Igaebc8024iHdtxKDGBNQOJpKhKrFD5lnjw=@emersion.fr' \
    --to=contact@emersion.fr \
    --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