[PATCH 4/8] Avoid shadowing in linux-tdep.c
Kevin Buettner
kevinb@redhat.com
Fri Oct 12 04:50:00 GMT 2018
On Sat, 22 Sep 2018 22:08:10 -0600
Tom Tromey <tom@tromey.com> wrote:
> This is one of the uglier changes to avoid local shadowing. Because
> obstack.h uses statement expressions, in some cases a nested obstack
> call will result in shadowing. Rather than try to fix obstack.h, this
> patch simply works around the one instance of this problem.
>
> gdb/ChangeLog
> 2018-09-22 Tom Tromey <tom@tromey.com>
>
> * linux-tdep.c (linux_make_mappings_corefile_notes): Introduce new
> variable "size".
> ---
> gdb/ChangeLog | 5 +++++
> gdb/linux-tdep.c | 3 ++-
> 2 files changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
> index 8c76ec316b..352114943f 100644
> --- a/gdb/linux-tdep.c
> +++ b/gdb/linux-tdep.c
> @@ -1547,8 +1547,9 @@ linux_make_mappings_corefile_notes (struct gdbarch *gdbarch, bfd *obfd,
> long_type, mapping_data.file_count);
>
> /* Copy the filenames to the data obstack. */
> + int size = obstack_object_size (&filename_obstack);
> obstack_grow (&data_obstack, obstack_base (&filename_obstack),
> - obstack_object_size (&filename_obstack));
> + size);
>
> note_data = elfcore_write_note (obfd, note_data, note_size,
> "CORE", NT_FILE,
> --
> 2.17.1
It took me a while to understand this one. IIUC, the problem is that __o
in obstack_object_size will shadow __o in obstack_grow.
Yeah, this is ugly. But I can't think of a better way to fix it short
of mucking about in obstack.h.
My only suggestion is to add a brief comment on the matter so that
someone else doesn't rewrite this code back to the way it was before
this patch. Otherwise, LGTM.
Kevin
More information about the Gdb-patches
mailing list