This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC 2/2] Move gdb's xmalloc and friends to new file


On 5/30/19 10:30 PM, Tom Tromey wrote:
> When "common" becomes a library, linking will cause a symbol clash,
> because "xmalloc" and some related symbols are defined in that
> library, libiberty, and readline.
> 
> To work around this problem, this patch moves the clashing symbols to
> a new file, which is then compiled separately for both gdb and
> gdbserver.
> 
> gdb/ChangeLog
> 2019-05-30  Tom Tromey  <tom@tromey.com>
> 
> 	* common/common-utils.c (xmalloc, xrealloc, xcalloc)
> 	(xmalloc_failed): Move to alloc.c.
> 	* alloc.c: New file.
> 	* Makefile.in (COMMON_SFILES): Add alloc.c.
> 
> gdb/gdbserver/ChangeLog
> 2019-05-30  Tom Tromey  <tom@tromey.com>
> 
> 	* Makefile.in (SFILES): Add alloc.c.
> 	(OBS): Add alloc.o.
> 	(IPA_OBJS): Add alloc-ipa.o.
> 	(alloc-ipa.o): New target.
> 	(%.o: ../%.c): New pattern rule.

This will be the first case of gdbserver building a file
from gdb/ .  I suppose we could preserve the gdb/common/
directory for such files.  But I guess moving it out of the
way until gdb/common/ moves to top level helps.

> +++ b/gdb/alloc.c
> @@ -0,0 +1,95 @@
> +/* Shared allocation functions for GDB, the GNU debugger.
> +
> +   Copyright (C) 2019 Free Software Foundation, Inc.

The file is new, but the contents aren't, and it's the contents
that matter wrt to copyright years.

There should be some comment here about why this is in a separate file
instead of living in the common library, to help people that read
the code from the tree without having this commit in context.

> +
> +#include "common/common-defs.h"

There should also be a comment explaining why this includes common-defs.h
instead of defs.h.

> +#include "libiberty.h"
> +#include <cstdlib>

Including <cstdlib> looks strange, given common-defs.h includes stdlib.h.
Why did you need this?

> +#include "common/errors.h"
> +
> +/* The xmalloc() (libiberty.h) family of memory management routines.
> +

Thanks,
Pedro Alves


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]