Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* gdb sources
@ 2008-09-12 15:13 André Pönitz
  2008-09-12 15:36 ` Daniel Jacobowitz
  0 siblings, 1 reply; 2+ messages in thread
From: André Pönitz @ 2008-09-12 15:13 UTC (permalink / raw)
  To: gdb



Hi all.

I browsed a bit through gdb sources and came across a few 
question I can not answer. Maybe some kind soul can help ;-)

(1)  There is e.g.

static void
make_command (const char *arg, int from_tty)
{
  char *p;

  if (arg == 0)
    p = "make";
  else
    {
      p = xmalloc (sizeof ("make ") + strlen (arg));
      strcpy (p, "make ");
      strcpy (p + sizeof ("make ") - 1, arg);
    }

  shell_escape (p, from_tty);
}

In one branch, p points to a literal, in the other to the heap.
shell_escape() does not seem to release any memory (would
also be wrong in the literal case...), so if the else branch is
taken it's a leak, no?

(2) Most of the "strings" in gdb are "char *", even if they are
conceptionally "const char *" (i.e. coming from literal, or not
intended to be changed). Why? In some places "const" is also
used, so the reason can't be "gdb supports compilers that
don't know about 'const'". Is it "just legacy"? If so, would patches
replacing "char *" by "const char *" if appropriate be welcome?

(3) Most of the declarations in command.h are repeated in
cli/cli-decode.h even though cli-decode.h #include's command.h.
Couldn't the duplicates just be removed?

Andre'


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: gdb sources
  2008-09-12 15:13 gdb sources André Pönitz
@ 2008-09-12 15:36 ` Daniel Jacobowitz
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Jacobowitz @ 2008-09-12 15:36 UTC (permalink / raw)
  To: André Pönitz; +Cc: gdb

On Fri, Sep 12, 2008 at 05:12:50PM +0200, André Pönitz wrote:
> In one branch, p points to a literal, in the other to the heap.
> shell_escape() does not seem to release any memory (would
> also be wrong in the literal case...), so if the else branch is
> taken it's a leak, no?

Yes, looks like a leak.

> (2) Most of the "strings" in gdb are "char *", even if they are
> conceptionally "const char *" (i.e. coming from literal, or not
> intended to be changed). Why? In some places "const" is also
> used, so the reason can't be "gdb supports compilers that
> don't know about 'const'". Is it "just legacy"? If so, would patches
> replacing "char *" by "const char *" if appropriate be welcome?

Yes, constifying patches are welcome.  It's just that gdb _used_ to
support compilers that didn't know const, and may even predate
const in places.

> (3) Most of the declarations in command.h are repeated in
> cli/cli-decode.h even though cli-decode.h #include's command.h.
> Couldn't the duplicates just be removed?

Probably; I don't know the history of it.

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-09-12 15:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-12 15:13 gdb sources André Pönitz
2008-09-12 15:36 ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox