From: Pedro Alves <palves@redhat.com>
To: Hui Zhu <hui_zhu@mentor.com>
Cc: gdb-patches ml <gdb-patches@sourceware.org>
Subject: Re: [PATCH 0/1] Fix internal warning when "gdb -p xxx"
Date: Mon, 17 Mar 2014 16:57:00 -0000 [thread overview]
Message-ID: <53272958.1080605@redhat.com> (raw)
In-Reply-To: <53271ED2.6010707@redhat.com>
On 03/17/2014 04:12 PM, Pedro Alves wrote:
> On 03/17/2014 04:00 PM, Hui Zhu wrote:
>
>> The most of the pid_to_exec_file target_ops method for some platforms will
>> allocate memory for exec_file and add them to cleanup.
>
> Which platforms?
OK, I see several do that, including linux-nat.c.
IMO, that ends up being a silly interface. The current
interface is documented as:
/* Attempts to find the pathname of the executable file
that was run to create a specified process.
The process PID must be stopped when this operation is used.
If the executable file cannot be determined, NULL is returned.
Else, a pointer to a character string containing the pathname
is returned. This string should be copied into a buffer by
the client if the string will not be immediately used, or if
it must persist. */
#define target_pid_to_exec_file(pid) \
(current_target.to_pid_to_exec_file) (¤t_target, pid)
The "This string should be copied into a buffer by the client if
the string will not be immediately used, or if it must persist."
part hints that the implementation is supposed to return a pointer
to a static buffer, like e.g., target_pid_to_str, paddress, and
friends, etc.
Either we make target_pid_to_exec_file return a pointer to
a malloc buffer that the caller is responsible for xfree'ing (and
adjust the interface comments in target.h) or we make targets
indeed return a pointer to a static buffer, as the current
method's description hints at. Returning a malloced buffer, and
installing a cleanup like that is a silly interface, IMO. Note
that GDB used to have more random memory-release cleanups installed
like this, but we've removed most, I believe. Although it's really
not harmful to install a cleanup that just releases memory
later at any random time, OTOH, it potentially makes debugging
nasty cleanup issues harder, so we've moved away from doing that,
and we now have that warning.
Bummer that we don't have a test that caught this. :-(
--
Pedro Alves
next prev parent reply other threads:[~2014-03-17 16:57 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-17 16:00 Hui Zhu
2014-03-17 16:02 ` [PATCH 1/1] Fix memleak of the pid_to_exec_file target_ops method for some platforms Hui Zhu
2014-03-18 7:39 ` Hui Zhu
2014-03-17 16:12 ` [PATCH 0/1] Fix internal warning when "gdb -p xxx" Pedro Alves
2014-03-17 16:57 ` Pedro Alves [this message]
2014-03-18 7:38 ` Hui Zhu
2014-03-18 10:14 ` Pedro Alves
2014-03-19 3:58 ` Hui Zhu
2014-03-19 10:16 ` Pedro Alves
2014-03-20 2:58 ` Hui Zhu
2014-03-20 3:27 ` Hui Zhu
2014-03-20 12:56 ` Pedro Alves
2014-03-21 3:14 ` Hui Zhu
2014-03-19 4:03 ` [PATCH 1/1] Fix internal warning when "gdb -p xxx" (test) Hui Zhu
2014-03-19 10:28 ` Pedro Alves
2014-03-20 3:16 ` Hui Zhu
2014-03-20 12:23 ` Pedro Alves
2014-03-21 3:27 ` Hui Zhu
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=53272958.1080605@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=hui_zhu@mentor.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