From: Kamil Rytarowski <n54@gmx.com>
To: Simon Marchi <simark@simark.ca>, gdb-patches@sourceware.org
Cc: tom@tromey.com
Subject: Re: [PATCH v3] Implement "info proc mappings" for NetBSD
Date: Sat, 11 Apr 2020 23:28:09 +0200 [thread overview]
Message-ID: <154c0a3c-b59e-1e9b-504e-27bd7e47b2a6@gmx.com> (raw)
In-Reply-To: <5d7ee373-df4f-6a05-fda3-d8d6f4d1efcc@simark.ca>
On 11.04.2020 23:05, Simon Marchi wrote:
> On 2020-04-06 5:37 a.m., Kamil Rytarowski wrote:
>> @@ -39,3 +42,148 @@ nbsd_nat_target::pid_to_exec_file (int pid)
>> return NULL;
>> return buf;
>> }
>> +
>> +/* Retrieve all the memory regions in the specified process. */
>> +
>> +static gdb::unique_xmalloc_ptr<struct kinfo_vmentry[]>
>> +nbsd_kinfo_get_vmmap (pid_t pid, size_t *size)
>> +{
>> + int mib[5] = {CTL_VM, VM_PROC, VM_PROC_MAP, pid,
>> + sizeof (struct kinfo_vmentry)};
>> +
>> + size_t length = 0;
>> + if (sysctl (mib, ARRAY_SIZE (mib), NULL, &length, NULL, 0))
>> + {
>> + *size = 0;
>> + return NULL;
>> + }
>> +
>> + /* Prereserve more space. */
>> + length = length * 5 / 3;
>
> Why is this needed?
>
This length is volatile and can be larger on the 2nd sysctl(3) call. We
can call this function against a running process that can enlarge its
usage of address space in this time window.
>> +
>> + gdb::unique_xmalloc_ptr<struct kinfo_vmentry[]> kiv
>> + ((struct kinfo_vmentry *) xcalloc (length, 1));
>
> Let's use XCNEWVAR here. It doesn't matter in this case, but for consistency. It does
> check that we are not trying to allocate space for a non-POD type. You can use like:
>
> XCNEWVAR (kinfo_vmentry, length)
>
> You can also use XNEWVAR if you don't care about the buffer being initialized to zeros.
>
OK.
>> diff --git a/gdb/nbsd-tdep.h b/gdb/nbsd-tdep.h
>> index c99a8b537b6..81bdb2510f5 100644
>> --- a/gdb/nbsd-tdep.h
>> +++ b/gdb/nbsd-tdep.h
>> @@ -25,4 +25,22 @@ struct link_map_offsets *nbsd_lp64_solib_svr4_fetch_link_map_offsets (void);
>>
>> int nbsd_pc_in_sigtramp (CORE_ADDR, const char *);
>>
>> +/* Output the header for "info proc mappings". ADDR_BIT is the size
>> + of a virtual address in bits. */
>> +
>> +extern void nbsd_info_proc_mappings_header (int addr_bit);
>> +
>> +/* Output description of a single memory range for "info proc
>> + mappings". ADDR_BIT is the size of a virtual address in bits. The
>> + KVE_START, KVE_END, KVE_OFFSET, KVE_FLAGS, and KVE_PROTECTION
>> + parameters should contain the value of the corresponding fields in
>> + a 'struct kinfo_vmentry'. The KVE_PATH parameter should contain a
>> + pointer to the 'kve_path' field in a 'struct kinfo_vmentry'. */
>> +
>> +extern void nbsd_info_proc_mappings_entry (int addr_bit, ULONGEST kve_start,
>> + ULONGEST kve_end,
>> + ULONGEST kve_offset,
>> + int kve_flags, int kve_protection,
>> + const void *kve_path);
>
> I'd make the last parameter a `const char *` directly, since this is what the function
> expects to receive. And remove the reinterpret_casts.
>
OK.
> Simon
>
next prev parent reply other threads:[~2020-04-11 21:29 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-16 17:34 [PATCH] " Kamil Rytarowski
2020-03-19 13:07 ` Kamil Rytarowski
2020-03-20 15:36 ` Tom Tromey
2020-03-20 16:58 ` Kamil Rytarowski
2020-03-20 18:50 ` Tom Tromey
2020-03-20 19:13 ` Kamil Rytarowski
2020-03-25 16:36 ` John Baldwin
2020-03-26 23:24 ` Kamil Rytarowski
2020-03-20 16:58 ` [PATCH v2] " Kamil Rytarowski
2020-04-02 20:09 ` Kamil Rytarowski
2020-04-03 1:12 ` Kamil Rytarowski
2020-04-06 9:37 ` [PATCH v3] " Kamil Rytarowski
2020-04-10 10:20 ` Kamil Rytarowski
2020-04-11 21:05 ` Simon Marchi
2020-04-11 21:28 ` Kamil Rytarowski [this message]
2020-04-11 21:53 ` Simon Marchi
2020-04-11 23:45 ` [PATCH v4] " Kamil Rytarowski
2020-04-11 23:49 ` Simon Marchi
2020-04-12 0:09 ` Kamil Rytarowski
2020-04-12 0:09 ` [PATCH v5] " Kamil Rytarowski
2020-04-12 0:56 ` Simon Marchi
2020-04-12 10:17 ` Kamil Rytarowski
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=154c0a3c-b59e-1e9b-504e-27bd7e47b2a6@gmx.com \
--to=n54@gmx.com \
--cc=gdb-patches@sourceware.org \
--cc=simark@simark.ca \
--cc=tom@tromey.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).