gdb sources

André Pönitz
Fri Sep 12 15:13:00 GMT 2008

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";
      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?


More information about the Gdb mailing list