binutils-gdb/gdb/cp-support.c

2201 lines
63 KiB
C
Raw Normal View History

/* Helper routines for C++ support in GDB.
Copyright (C) 2002-2020 Free Software Foundation, Inc.
Contributed by MontaVista Software.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
#include "cp-support.h"
#include "demangle.h"
Revert the header-sorting patch Andreas Schwab and John Baldwin pointed out some bugs in the header sorting patch; and I noticed that the output was not correct when limited to a subset of files (a bug in my script). So, I'm reverting the patch. I may try again after fixing the issues pointed out. gdb/ChangeLog 2019-04-05 Tom Tromey <tom@tromey.com> Revert the header-sorting patch. * ft32-tdep.c: Revert. * frv-tdep.c: Revert. * frv-linux-tdep.c: Revert. * frame.c: Revert. * frame-unwind.c: Revert. * frame-base.c: Revert. * fork-child.c: Revert. * findvar.c: Revert. * findcmd.c: Revert. * filesystem.c: Revert. * filename-seen-cache.h: Revert. * filename-seen-cache.c: Revert. * fbsd-tdep.c: Revert. * fbsd-nat.h: Revert. * fbsd-nat.c: Revert. * f-valprint.c: Revert. * f-typeprint.c: Revert. * f-lang.c: Revert. * extension.h: Revert. * extension.c: Revert. * extension-priv.h: Revert. * expprint.c: Revert. * exec.h: Revert. * exec.c: Revert. * exceptions.c: Revert. * event-top.c: Revert. * event-loop.c: Revert. * eval.c: Revert. * elfread.c: Revert. * dwarf2read.h: Revert. * dwarf2read.c: Revert. * dwarf2loc.c: Revert. * dwarf2expr.h: Revert. * dwarf2expr.c: Revert. * dwarf2-frame.c: Revert. * dwarf2-frame-tailcall.c: Revert. * dwarf-index-write.h: Revert. * dwarf-index-write.c: Revert. * dwarf-index-common.c: Revert. * dwarf-index-cache.h: Revert. * dwarf-index-cache.c: Revert. * dummy-frame.c: Revert. * dtrace-probe.c: Revert. * disasm.h: Revert. * disasm.c: Revert. * disasm-selftests.c: Revert. * dictionary.c: Revert. * dicos-tdep.c: Revert. * demangle.c: Revert. * dcache.h: Revert. * dcache.c: Revert. * darwin-nat.h: Revert. * darwin-nat.c: Revert. * darwin-nat-info.c: Revert. * d-valprint.c: Revert. * d-namespace.c: Revert. * d-lang.c: Revert. * ctf.c: Revert. * csky-tdep.c: Revert. * csky-linux-tdep.c: Revert. * cris-tdep.c: Revert. * cris-linux-tdep.c: Revert. * cp-valprint.c: Revert. * cp-support.c: Revert. * cp-namespace.c: Revert. * cp-abi.c: Revert. * corelow.c: Revert. * corefile.c: Revert. * continuations.c: Revert. * completer.h: Revert. * completer.c: Revert. * complaints.c: Revert. * coffread.c: Revert. * coff-pe-read.c: Revert. * cli-out.h: Revert. * cli-out.c: Revert. * charset.c: Revert. * c-varobj.c: Revert. * c-valprint.c: Revert. * c-typeprint.c: Revert. * c-lang.c: Revert. * buildsym.c: Revert. * buildsym-legacy.c: Revert. * build-id.h: Revert. * build-id.c: Revert. * btrace.c: Revert. * bsd-uthread.c: Revert. * breakpoint.h: Revert. * breakpoint.c: Revert. * break-catch-throw.c: Revert. * break-catch-syscall.c: Revert. * break-catch-sig.c: Revert. * blockframe.c: Revert. * block.c: Revert. * bfin-tdep.c: Revert. * bfin-linux-tdep.c: Revert. * bfd-target.c: Revert. * bcache.c: Revert. * ax-general.c: Revert. * ax-gdb.h: Revert. * ax-gdb.c: Revert. * avr-tdep.c: Revert. * auxv.c: Revert. * auto-load.c: Revert. * arm-wince-tdep.c: Revert. * arm-tdep.c: Revert. * arm-symbian-tdep.c: Revert. * arm-pikeos-tdep.c: Revert. * arm-obsd-tdep.c: Revert. * arm-nbsd-tdep.c: Revert. * arm-nbsd-nat.c: Revert. * arm-linux-tdep.c: Revert. * arm-linux-nat.c: Revert. * arm-fbsd-tdep.c: Revert. * arm-fbsd-nat.c: Revert. * arm-bsd-tdep.c: Revert. * arch-utils.c: Revert. * arc-tdep.c: Revert. * arc-newlib-tdep.c: Revert. * annotate.h: Revert. * annotate.c: Revert. * amd64-windows-tdep.c: Revert. * amd64-windows-nat.c: Revert. * amd64-tdep.c: Revert. * amd64-sol2-tdep.c: Revert. * amd64-obsd-tdep.c: Revert. * amd64-obsd-nat.c: Revert. * amd64-nbsd-tdep.c: Revert. * amd64-nbsd-nat.c: Revert. * amd64-nat.c: Revert. * amd64-linux-tdep.c: Revert. * amd64-linux-nat.c: Revert. * amd64-fbsd-tdep.c: Revert. * amd64-fbsd-nat.c: Revert. * amd64-dicos-tdep.c: Revert. * amd64-darwin-tdep.c: Revert. * amd64-bsd-nat.c: Revert. * alpha-tdep.c: Revert. * alpha-obsd-tdep.c: Revert. * alpha-nbsd-tdep.c: Revert. * alpha-mdebug-tdep.c: Revert. * alpha-linux-tdep.c: Revert. * alpha-linux-nat.c: Revert. * alpha-bsd-tdep.c: Revert. * alpha-bsd-nat.c: Revert. * aix-thread.c: Revert. * agent.c: Revert. * addrmap.c: Revert. * ada-varobj.c: Revert. * ada-valprint.c: Revert. * ada-typeprint.c: Revert. * ada-tasks.c: Revert. * ada-lang.c: Revert. * aarch64-tdep.c: Revert. * aarch64-ravenscar-thread.c: Revert. * aarch64-newlib-tdep.c: Revert. * aarch64-linux-tdep.c: Revert. * aarch64-linux-nat.c: Revert. * aarch64-fbsd-tdep.c: Revert. * aarch64-fbsd-nat.c: Revert. * aarch32-linux-nat.c: Revert.
2019-04-06 21:38:10 +02:00
#include "gdbcmd.h"
#include "dictionary.h"
Revert the header-sorting patch Andreas Schwab and John Baldwin pointed out some bugs in the header sorting patch; and I noticed that the output was not correct when limited to a subset of files (a bug in my script). So, I'm reverting the patch. I may try again after fixing the issues pointed out. gdb/ChangeLog 2019-04-05 Tom Tromey <tom@tromey.com> Revert the header-sorting patch. * ft32-tdep.c: Revert. * frv-tdep.c: Revert. * frv-linux-tdep.c: Revert. * frame.c: Revert. * frame-unwind.c: Revert. * frame-base.c: Revert. * fork-child.c: Revert. * findvar.c: Revert. * findcmd.c: Revert. * filesystem.c: Revert. * filename-seen-cache.h: Revert. * filename-seen-cache.c: Revert. * fbsd-tdep.c: Revert. * fbsd-nat.h: Revert. * fbsd-nat.c: Revert. * f-valprint.c: Revert. * f-typeprint.c: Revert. * f-lang.c: Revert. * extension.h: Revert. * extension.c: Revert. * extension-priv.h: Revert. * expprint.c: Revert. * exec.h: Revert. * exec.c: Revert. * exceptions.c: Revert. * event-top.c: Revert. * event-loop.c: Revert. * eval.c: Revert. * elfread.c: Revert. * dwarf2read.h: Revert. * dwarf2read.c: Revert. * dwarf2loc.c: Revert. * dwarf2expr.h: Revert. * dwarf2expr.c: Revert. * dwarf2-frame.c: Revert. * dwarf2-frame-tailcall.c: Revert. * dwarf-index-write.h: Revert. * dwarf-index-write.c: Revert. * dwarf-index-common.c: Revert. * dwarf-index-cache.h: Revert. * dwarf-index-cache.c: Revert. * dummy-frame.c: Revert. * dtrace-probe.c: Revert. * disasm.h: Revert. * disasm.c: Revert. * disasm-selftests.c: Revert. * dictionary.c: Revert. * dicos-tdep.c: Revert. * demangle.c: Revert. * dcache.h: Revert. * dcache.c: Revert. * darwin-nat.h: Revert. * darwin-nat.c: Revert. * darwin-nat-info.c: Revert. * d-valprint.c: Revert. * d-namespace.c: Revert. * d-lang.c: Revert. * ctf.c: Revert. * csky-tdep.c: Revert. * csky-linux-tdep.c: Revert. * cris-tdep.c: Revert. * cris-linux-tdep.c: Revert. * cp-valprint.c: Revert. * cp-support.c: Revert. * cp-namespace.c: Revert. * cp-abi.c: Revert. * corelow.c: Revert. * corefile.c: Revert. * continuations.c: Revert. * completer.h: Revert. * completer.c: Revert. * complaints.c: Revert. * coffread.c: Revert. * coff-pe-read.c: Revert. * cli-out.h: Revert. * cli-out.c: Revert. * charset.c: Revert. * c-varobj.c: Revert. * c-valprint.c: Revert. * c-typeprint.c: Revert. * c-lang.c: Revert. * buildsym.c: Revert. * buildsym-legacy.c: Revert. * build-id.h: Revert. * build-id.c: Revert. * btrace.c: Revert. * bsd-uthread.c: Revert. * breakpoint.h: Revert. * breakpoint.c: Revert. * break-catch-throw.c: Revert. * break-catch-syscall.c: Revert. * break-catch-sig.c: Revert. * blockframe.c: Revert. * block.c: Revert. * bfin-tdep.c: Revert. * bfin-linux-tdep.c: Revert. * bfd-target.c: Revert. * bcache.c: Revert. * ax-general.c: Revert. * ax-gdb.h: Revert. * ax-gdb.c: Revert. * avr-tdep.c: Revert. * auxv.c: Revert. * auto-load.c: Revert. * arm-wince-tdep.c: Revert. * arm-tdep.c: Revert. * arm-symbian-tdep.c: Revert. * arm-pikeos-tdep.c: Revert. * arm-obsd-tdep.c: Revert. * arm-nbsd-tdep.c: Revert. * arm-nbsd-nat.c: Revert. * arm-linux-tdep.c: Revert. * arm-linux-nat.c: Revert. * arm-fbsd-tdep.c: Revert. * arm-fbsd-nat.c: Revert. * arm-bsd-tdep.c: Revert. * arch-utils.c: Revert. * arc-tdep.c: Revert. * arc-newlib-tdep.c: Revert. * annotate.h: Revert. * annotate.c: Revert. * amd64-windows-tdep.c: Revert. * amd64-windows-nat.c: Revert. * amd64-tdep.c: Revert. * amd64-sol2-tdep.c: Revert. * amd64-obsd-tdep.c: Revert. * amd64-obsd-nat.c: Revert. * amd64-nbsd-tdep.c: Revert. * amd64-nbsd-nat.c: Revert. * amd64-nat.c: Revert. * amd64-linux-tdep.c: Revert. * amd64-linux-nat.c: Revert. * amd64-fbsd-tdep.c: Revert. * amd64-fbsd-nat.c: Revert. * amd64-dicos-tdep.c: Revert. * amd64-darwin-tdep.c: Revert. * amd64-bsd-nat.c: Revert. * alpha-tdep.c: Revert. * alpha-obsd-tdep.c: Revert. * alpha-nbsd-tdep.c: Revert. * alpha-mdebug-tdep.c: Revert. * alpha-linux-tdep.c: Revert. * alpha-linux-nat.c: Revert. * alpha-bsd-tdep.c: Revert. * alpha-bsd-nat.c: Revert. * aix-thread.c: Revert. * agent.c: Revert. * addrmap.c: Revert. * ada-varobj.c: Revert. * ada-valprint.c: Revert. * ada-typeprint.c: Revert. * ada-tasks.c: Revert. * ada-lang.c: Revert. * aarch64-tdep.c: Revert. * aarch64-ravenscar-thread.c: Revert. * aarch64-newlib-tdep.c: Revert. * aarch64-linux-tdep.c: Revert. * aarch64-linux-nat.c: Revert. * aarch64-fbsd-tdep.c: Revert. * aarch64-fbsd-nat.c: Revert. * aarch32-linux-nat.c: Revert.
2019-04-06 21:38:10 +02:00
#include "objfiles.h"
#include "frame.h"
Revert the header-sorting patch Andreas Schwab and John Baldwin pointed out some bugs in the header sorting patch; and I noticed that the output was not correct when limited to a subset of files (a bug in my script). So, I'm reverting the patch. I may try again after fixing the issues pointed out. gdb/ChangeLog 2019-04-05 Tom Tromey <tom@tromey.com> Revert the header-sorting patch. * ft32-tdep.c: Revert. * frv-tdep.c: Revert. * frv-linux-tdep.c: Revert. * frame.c: Revert. * frame-unwind.c: Revert. * frame-base.c: Revert. * fork-child.c: Revert. * findvar.c: Revert. * findcmd.c: Revert. * filesystem.c: Revert. * filename-seen-cache.h: Revert. * filename-seen-cache.c: Revert. * fbsd-tdep.c: Revert. * fbsd-nat.h: Revert. * fbsd-nat.c: Revert. * f-valprint.c: Revert. * f-typeprint.c: Revert. * f-lang.c: Revert. * extension.h: Revert. * extension.c: Revert. * extension-priv.h: Revert. * expprint.c: Revert. * exec.h: Revert. * exec.c: Revert. * exceptions.c: Revert. * event-top.c: Revert. * event-loop.c: Revert. * eval.c: Revert. * elfread.c: Revert. * dwarf2read.h: Revert. * dwarf2read.c: Revert. * dwarf2loc.c: Revert. * dwarf2expr.h: Revert. * dwarf2expr.c: Revert. * dwarf2-frame.c: Revert. * dwarf2-frame-tailcall.c: Revert. * dwarf-index-write.h: Revert. * dwarf-index-write.c: Revert. * dwarf-index-common.c: Revert. * dwarf-index-cache.h: Revert. * dwarf-index-cache.c: Revert. * dummy-frame.c: Revert. * dtrace-probe.c: Revert. * disasm.h: Revert. * disasm.c: Revert. * disasm-selftests.c: Revert. * dictionary.c: Revert. * dicos-tdep.c: Revert. * demangle.c: Revert. * dcache.h: Revert. * dcache.c: Revert. * darwin-nat.h: Revert. * darwin-nat.c: Revert. * darwin-nat-info.c: Revert. * d-valprint.c: Revert. * d-namespace.c: Revert. * d-lang.c: Revert. * ctf.c: Revert. * csky-tdep.c: Revert. * csky-linux-tdep.c: Revert. * cris-tdep.c: Revert. * cris-linux-tdep.c: Revert. * cp-valprint.c: Revert. * cp-support.c: Revert. * cp-namespace.c: Revert. * cp-abi.c: Revert. * corelow.c: Revert. * corefile.c: Revert. * continuations.c: Revert. * completer.h: Revert. * completer.c: Revert. * complaints.c: Revert. * coffread.c: Revert. * coff-pe-read.c: Revert. * cli-out.h: Revert. * cli-out.c: Revert. * charset.c: Revert. * c-varobj.c: Revert. * c-valprint.c: Revert. * c-typeprint.c: Revert. * c-lang.c: Revert. * buildsym.c: Revert. * buildsym-legacy.c: Revert. * build-id.h: Revert. * build-id.c: Revert. * btrace.c: Revert. * bsd-uthread.c: Revert. * breakpoint.h: Revert. * breakpoint.c: Revert. * break-catch-throw.c: Revert. * break-catch-syscall.c: Revert. * break-catch-sig.c: Revert. * blockframe.c: Revert. * block.c: Revert. * bfin-tdep.c: Revert. * bfin-linux-tdep.c: Revert. * bfd-target.c: Revert. * bcache.c: Revert. * ax-general.c: Revert. * ax-gdb.h: Revert. * ax-gdb.c: Revert. * avr-tdep.c: Revert. * auxv.c: Revert. * auto-load.c: Revert. * arm-wince-tdep.c: Revert. * arm-tdep.c: Revert. * arm-symbian-tdep.c: Revert. * arm-pikeos-tdep.c: Revert. * arm-obsd-tdep.c: Revert. * arm-nbsd-tdep.c: Revert. * arm-nbsd-nat.c: Revert. * arm-linux-tdep.c: Revert. * arm-linux-nat.c: Revert. * arm-fbsd-tdep.c: Revert. * arm-fbsd-nat.c: Revert. * arm-bsd-tdep.c: Revert. * arch-utils.c: Revert. * arc-tdep.c: Revert. * arc-newlib-tdep.c: Revert. * annotate.h: Revert. * annotate.c: Revert. * amd64-windows-tdep.c: Revert. * amd64-windows-nat.c: Revert. * amd64-tdep.c: Revert. * amd64-sol2-tdep.c: Revert. * amd64-obsd-tdep.c: Revert. * amd64-obsd-nat.c: Revert. * amd64-nbsd-tdep.c: Revert. * amd64-nbsd-nat.c: Revert. * amd64-nat.c: Revert. * amd64-linux-tdep.c: Revert. * amd64-linux-nat.c: Revert. * amd64-fbsd-tdep.c: Revert. * amd64-fbsd-nat.c: Revert. * amd64-dicos-tdep.c: Revert. * amd64-darwin-tdep.c: Revert. * amd64-bsd-nat.c: Revert. * alpha-tdep.c: Revert. * alpha-obsd-tdep.c: Revert. * alpha-nbsd-tdep.c: Revert. * alpha-mdebug-tdep.c: Revert. * alpha-linux-tdep.c: Revert. * alpha-linux-nat.c: Revert. * alpha-bsd-tdep.c: Revert. * alpha-bsd-nat.c: Revert. * aix-thread.c: Revert. * agent.c: Revert. * addrmap.c: Revert. * ada-varobj.c: Revert. * ada-valprint.c: Revert. * ada-typeprint.c: Revert. * ada-tasks.c: Revert. * ada-lang.c: Revert. * aarch64-tdep.c: Revert. * aarch64-ravenscar-thread.c: Revert. * aarch64-newlib-tdep.c: Revert. * aarch64-linux-tdep.c: Revert. * aarch64-linux-nat.c: Revert. * aarch64-fbsd-tdep.c: Revert. * aarch64-fbsd-nat.c: Revert. * aarch32-linux-nat.c: Revert.
2019-04-06 21:38:10 +02:00
#include "symtab.h"
#include "block.h"
#include "complaints.h"
#include "gdbtypes.h"
Revert the header-sorting patch Andreas Schwab and John Baldwin pointed out some bugs in the header sorting patch; and I noticed that the output was not correct when limited to a subset of files (a bug in my script). So, I'm reverting the patch. I may try again after fixing the issues pointed out. gdb/ChangeLog 2019-04-05 Tom Tromey <tom@tromey.com> Revert the header-sorting patch. * ft32-tdep.c: Revert. * frv-tdep.c: Revert. * frv-linux-tdep.c: Revert. * frame.c: Revert. * frame-unwind.c: Revert. * frame-base.c: Revert. * fork-child.c: Revert. * findvar.c: Revert. * findcmd.c: Revert. * filesystem.c: Revert. * filename-seen-cache.h: Revert. * filename-seen-cache.c: Revert. * fbsd-tdep.c: Revert. * fbsd-nat.h: Revert. * fbsd-nat.c: Revert. * f-valprint.c: Revert. * f-typeprint.c: Revert. * f-lang.c: Revert. * extension.h: Revert. * extension.c: Revert. * extension-priv.h: Revert. * expprint.c: Revert. * exec.h: Revert. * exec.c: Revert. * exceptions.c: Revert. * event-top.c: Revert. * event-loop.c: Revert. * eval.c: Revert. * elfread.c: Revert. * dwarf2read.h: Revert. * dwarf2read.c: Revert. * dwarf2loc.c: Revert. * dwarf2expr.h: Revert. * dwarf2expr.c: Revert. * dwarf2-frame.c: Revert. * dwarf2-frame-tailcall.c: Revert. * dwarf-index-write.h: Revert. * dwarf-index-write.c: Revert. * dwarf-index-common.c: Revert. * dwarf-index-cache.h: Revert. * dwarf-index-cache.c: Revert. * dummy-frame.c: Revert. * dtrace-probe.c: Revert. * disasm.h: Revert. * disasm.c: Revert. * disasm-selftests.c: Revert. * dictionary.c: Revert. * dicos-tdep.c: Revert. * demangle.c: Revert. * dcache.h: Revert. * dcache.c: Revert. * darwin-nat.h: Revert. * darwin-nat.c: Revert. * darwin-nat-info.c: Revert. * d-valprint.c: Revert. * d-namespace.c: Revert. * d-lang.c: Revert. * ctf.c: Revert. * csky-tdep.c: Revert. * csky-linux-tdep.c: Revert. * cris-tdep.c: Revert. * cris-linux-tdep.c: Revert. * cp-valprint.c: Revert. * cp-support.c: Revert. * cp-namespace.c: Revert. * cp-abi.c: Revert. * corelow.c: Revert. * corefile.c: Revert. * continuations.c: Revert. * completer.h: Revert. * completer.c: Revert. * complaints.c: Revert. * coffread.c: Revert. * coff-pe-read.c: Revert. * cli-out.h: Revert. * cli-out.c: Revert. * charset.c: Revert. * c-varobj.c: Revert. * c-valprint.c: Revert. * c-typeprint.c: Revert. * c-lang.c: Revert. * buildsym.c: Revert. * buildsym-legacy.c: Revert. * build-id.h: Revert. * build-id.c: Revert. * btrace.c: Revert. * bsd-uthread.c: Revert. * breakpoint.h: Revert. * breakpoint.c: Revert. * break-catch-throw.c: Revert. * break-catch-syscall.c: Revert. * break-catch-sig.c: Revert. * blockframe.c: Revert. * block.c: Revert. * bfin-tdep.c: Revert. * bfin-linux-tdep.c: Revert. * bfd-target.c: Revert. * bcache.c: Revert. * ax-general.c: Revert. * ax-gdb.h: Revert. * ax-gdb.c: Revert. * avr-tdep.c: Revert. * auxv.c: Revert. * auto-load.c: Revert. * arm-wince-tdep.c: Revert. * arm-tdep.c: Revert. * arm-symbian-tdep.c: Revert. * arm-pikeos-tdep.c: Revert. * arm-obsd-tdep.c: Revert. * arm-nbsd-tdep.c: Revert. * arm-nbsd-nat.c: Revert. * arm-linux-tdep.c: Revert. * arm-linux-nat.c: Revert. * arm-fbsd-tdep.c: Revert. * arm-fbsd-nat.c: Revert. * arm-bsd-tdep.c: Revert. * arch-utils.c: Revert. * arc-tdep.c: Revert. * arc-newlib-tdep.c: Revert. * annotate.h: Revert. * annotate.c: Revert. * amd64-windows-tdep.c: Revert. * amd64-windows-nat.c: Revert. * amd64-tdep.c: Revert. * amd64-sol2-tdep.c: Revert. * amd64-obsd-tdep.c: Revert. * amd64-obsd-nat.c: Revert. * amd64-nbsd-tdep.c: Revert. * amd64-nbsd-nat.c: Revert. * amd64-nat.c: Revert. * amd64-linux-tdep.c: Revert. * amd64-linux-nat.c: Revert. * amd64-fbsd-tdep.c: Revert. * amd64-fbsd-nat.c: Revert. * amd64-dicos-tdep.c: Revert. * amd64-darwin-tdep.c: Revert. * amd64-bsd-nat.c: Revert. * alpha-tdep.c: Revert. * alpha-obsd-tdep.c: Revert. * alpha-nbsd-tdep.c: Revert. * alpha-mdebug-tdep.c: Revert. * alpha-linux-tdep.c: Revert. * alpha-linux-nat.c: Revert. * alpha-bsd-tdep.c: Revert. * alpha-bsd-nat.c: Revert. * aix-thread.c: Revert. * agent.c: Revert. * addrmap.c: Revert. * ada-varobj.c: Revert. * ada-valprint.c: Revert. * ada-typeprint.c: Revert. * ada-tasks.c: Revert. * ada-lang.c: Revert. * aarch64-tdep.c: Revert. * aarch64-ravenscar-thread.c: Revert. * aarch64-newlib-tdep.c: Revert. * aarch64-linux-tdep.c: Revert. * aarch64-linux-nat.c: Revert. * aarch64-fbsd-tdep.c: Revert. * aarch64-fbsd-nat.c: Revert. * aarch32-linux-nat.c: Revert.
2019-04-06 21:38:10 +02:00
#include "expression.h"
#include "value.h"
#include "cp-abi.h"
[Ada] Add support for subprogram renamings Consider the following declaration: function Foo (I : Integer) return Integer renames Pack.Bar; As Foo is not materialized as a routine whose name is derived from Foo, GDB currently cannot use it: (gdb) print foo(0) No definition of "foo" in current context. However, compilers can emit DW_TAG_imported_declaration in order to materialize the fact that Foo is actually another name for Pack.Bar. This commit enhances the DWARF reader to record global renamings (it used to put global ones in a static block) and enhances the Ada engine to leverage this information during symbol lookup. gdb/ChangeLog: * ada-lang.c: Include namespace.h (aux_add_nonlocal_symbols): Fix a function name in comment. (ada_add_block_renamings): New. (add_nonlocal_symbols): Add global renamings handling. (ada_lookup_symbol_list_worker): Move the symbol lookup part to... (ada_add_all_symbols): ... this new function. (ada_add_block_symbols): Try to match the input name against the "using directives list", perform a recursive symbol lookup on the matched declarations. * block.h (struct block): Move the_namespace to top-level as namespace_info. Remove the language_specific field. (BLOCK_NAMESPACE): Update access to the namespace_info field. * buildsym.h (using_directives): Rename into... (local_using_directives): ... this. (global_using_directives): New. (struct context_stack): Rename the using_directives field into local_using_directives. * buildsym.c (finish_block_internal): Deal with the proper using directives repository (local or global). (prepare_for_building): Reset local_using_directives. Assert that there is no pending global using directive. (reset_symtab_globals): Reset global_using_directives and local_using_directives. (end_symtab_get_static_block): Don't ignore symtabs that have only using directives. (push_context): Update references to local_using_directives. (buildsym_init): Do not reset using_directives. * cp-support.c: Include namespace.h. * cp-support.h (struct using_direct): Move to namespace.h. (cp_add_using_directives): Move to namespace.h. * cp-namespace.c: Include namespace.h (cp_add_using_directive): Move to namespace.c, rename it to add_using_directive, add a "using_directives" argument and use it as the pending using directives repository. All callers updated. * dwarf2read.c (using_directives): New. (read_import_statement): Call using_directives. (read_func_scope): Update references to local_using_directives. (read_lexical_block_scope): Likewise. (read_namespace): Update the heading comment, call using_directives. * namespace.h: New file. * namespace.c: New file. * Makefile.in (SFILES): Add namespace.c. (COMMON_OBS): Add namespace.o gdb/testsuite/ChangeLog: * gdb.ada/fun_renaming.exp: New testcase. * gdb.ada/fun_renaming/fun_renaming.adb: New file. * gdb.ada/fun_renaming/pack.adb: New file. * gdb.ada/fun_renaming/pack.ads: New file. Tested on x86_64-linux. Support for this in GCC is in the pipeline: see <https://gcc.gnu.org/ml/gcc-patches/2015-07/msg02166.html>.
2015-07-22 15:30:57 +02:00
#include "namespace.h"
Revert the header-sorting patch Andreas Schwab and John Baldwin pointed out some bugs in the header sorting patch; and I noticed that the output was not correct when limited to a subset of files (a bug in my script). So, I'm reverting the patch. I may try again after fixing the issues pointed out. gdb/ChangeLog 2019-04-05 Tom Tromey <tom@tromey.com> Revert the header-sorting patch. * ft32-tdep.c: Revert. * frv-tdep.c: Revert. * frv-linux-tdep.c: Revert. * frame.c: Revert. * frame-unwind.c: Revert. * frame-base.c: Revert. * fork-child.c: Revert. * findvar.c: Revert. * findcmd.c: Revert. * filesystem.c: Revert. * filename-seen-cache.h: Revert. * filename-seen-cache.c: Revert. * fbsd-tdep.c: Revert. * fbsd-nat.h: Revert. * fbsd-nat.c: Revert. * f-valprint.c: Revert. * f-typeprint.c: Revert. * f-lang.c: Revert. * extension.h: Revert. * extension.c: Revert. * extension-priv.h: Revert. * expprint.c: Revert. * exec.h: Revert. * exec.c: Revert. * exceptions.c: Revert. * event-top.c: Revert. * event-loop.c: Revert. * eval.c: Revert. * elfread.c: Revert. * dwarf2read.h: Revert. * dwarf2read.c: Revert. * dwarf2loc.c: Revert. * dwarf2expr.h: Revert. * dwarf2expr.c: Revert. * dwarf2-frame.c: Revert. * dwarf2-frame-tailcall.c: Revert. * dwarf-index-write.h: Revert. * dwarf-index-write.c: Revert. * dwarf-index-common.c: Revert. * dwarf-index-cache.h: Revert. * dwarf-index-cache.c: Revert. * dummy-frame.c: Revert. * dtrace-probe.c: Revert. * disasm.h: Revert. * disasm.c: Revert. * disasm-selftests.c: Revert. * dictionary.c: Revert. * dicos-tdep.c: Revert. * demangle.c: Revert. * dcache.h: Revert. * dcache.c: Revert. * darwin-nat.h: Revert. * darwin-nat.c: Revert. * darwin-nat-info.c: Revert. * d-valprint.c: Revert. * d-namespace.c: Revert. * d-lang.c: Revert. * ctf.c: Revert. * csky-tdep.c: Revert. * csky-linux-tdep.c: Revert. * cris-tdep.c: Revert. * cris-linux-tdep.c: Revert. * cp-valprint.c: Revert. * cp-support.c: Revert. * cp-namespace.c: Revert. * cp-abi.c: Revert. * corelow.c: Revert. * corefile.c: Revert. * continuations.c: Revert. * completer.h: Revert. * completer.c: Revert. * complaints.c: Revert. * coffread.c: Revert. * coff-pe-read.c: Revert. * cli-out.h: Revert. * cli-out.c: Revert. * charset.c: Revert. * c-varobj.c: Revert. * c-valprint.c: Revert. * c-typeprint.c: Revert. * c-lang.c: Revert. * buildsym.c: Revert. * buildsym-legacy.c: Revert. * build-id.h: Revert. * build-id.c: Revert. * btrace.c: Revert. * bsd-uthread.c: Revert. * breakpoint.h: Revert. * breakpoint.c: Revert. * break-catch-throw.c: Revert. * break-catch-syscall.c: Revert. * break-catch-sig.c: Revert. * blockframe.c: Revert. * block.c: Revert. * bfin-tdep.c: Revert. * bfin-linux-tdep.c: Revert. * bfd-target.c: Revert. * bcache.c: Revert. * ax-general.c: Revert. * ax-gdb.h: Revert. * ax-gdb.c: Revert. * avr-tdep.c: Revert. * auxv.c: Revert. * auto-load.c: Revert. * arm-wince-tdep.c: Revert. * arm-tdep.c: Revert. * arm-symbian-tdep.c: Revert. * arm-pikeos-tdep.c: Revert. * arm-obsd-tdep.c: Revert. * arm-nbsd-tdep.c: Revert. * arm-nbsd-nat.c: Revert. * arm-linux-tdep.c: Revert. * arm-linux-nat.c: Revert. * arm-fbsd-tdep.c: Revert. * arm-fbsd-nat.c: Revert. * arm-bsd-tdep.c: Revert. * arch-utils.c: Revert. * arc-tdep.c: Revert. * arc-newlib-tdep.c: Revert. * annotate.h: Revert. * annotate.c: Revert. * amd64-windows-tdep.c: Revert. * amd64-windows-nat.c: Revert. * amd64-tdep.c: Revert. * amd64-sol2-tdep.c: Revert. * amd64-obsd-tdep.c: Revert. * amd64-obsd-nat.c: Revert. * amd64-nbsd-tdep.c: Revert. * amd64-nbsd-nat.c: Revert. * amd64-nat.c: Revert. * amd64-linux-tdep.c: Revert. * amd64-linux-nat.c: Revert. * amd64-fbsd-tdep.c: Revert. * amd64-fbsd-nat.c: Revert. * amd64-dicos-tdep.c: Revert. * amd64-darwin-tdep.c: Revert. * amd64-bsd-nat.c: Revert. * alpha-tdep.c: Revert. * alpha-obsd-tdep.c: Revert. * alpha-nbsd-tdep.c: Revert. * alpha-mdebug-tdep.c: Revert. * alpha-linux-tdep.c: Revert. * alpha-linux-nat.c: Revert. * alpha-bsd-tdep.c: Revert. * alpha-bsd-nat.c: Revert. * aix-thread.c: Revert. * agent.c: Revert. * addrmap.c: Revert. * ada-varobj.c: Revert. * ada-valprint.c: Revert. * ada-typeprint.c: Revert. * ada-tasks.c: Revert. * ada-lang.c: Revert. * aarch64-tdep.c: Revert. * aarch64-ravenscar-thread.c: Revert. * aarch64-newlib-tdep.c: Revert. * aarch64-linux-tdep.c: Revert. * aarch64-linux-nat.c: Revert. * aarch64-fbsd-tdep.c: Revert. * aarch64-fbsd-nat.c: Revert. * aarch32-linux-nat.c: Revert.
2019-04-06 21:38:10 +02:00
#include <signal.h>
Rename common to gdbsupport This is the next patch in the ongoing series to move gdbsever to the top level. This patch just renames the "common" directory. The idea is to do this move in two parts: first rename the directory (this patch), then move the directory to the top. This approach makes the patches a bit more tractable. I chose the name "gdbsupport" for the directory. However, as this patch was largely written by sed, we could pick a new name without too much difficulty. Tested by the buildbot. gdb/ChangeLog 2019-07-09 Tom Tromey <tom@tromey.com> * contrib/ari/gdb_ari.sh: Change common to gdbsupport. * configure: Rebuild. * configure.ac: Change common to gdbsupport. * gdbsupport: Rename from common. * acinclude.m4: Change common to gdbsupport. * Makefile.in (CONFIG_SRC_SUBDIR, COMMON_SFILES) (HFILES_NO_SRCDIR, stamp-version, ALLDEPFILES): Change common to gdbsupport. * aarch64-tdep.c, ada-lang.c, ada-lang.h, agent.c, alloc.c, amd64-darwin-tdep.c, amd64-dicos-tdep.c, amd64-fbsd-nat.c, amd64-fbsd-tdep.c, amd64-linux-nat.c, amd64-linux-tdep.c, amd64-nbsd-tdep.c, amd64-obsd-tdep.c, amd64-sol2-tdep.c, amd64-tdep.c, amd64-windows-tdep.c, arch-utils.c, arch/aarch64-insn.c, arch/aarch64.c, arch/aarch64.h, arch/amd64.c, arch/amd64.h, arch/arm-get-next-pcs.c, arch/arm-linux.c, arch/arm.c, arch/i386.c, arch/i386.h, arch/ppc-linux-common.c, arch/riscv.c, arch/riscv.h, arch/tic6x.c, arm-tdep.c, auto-load.c, auxv.c, ax-gdb.c, ax-general.c, ax.h, breakpoint.c, breakpoint.h, btrace.c, btrace.h, build-id.c, build-id.h, c-lang.h, charset.c, charset.h, cli/cli-cmds.c, cli/cli-cmds.h, cli/cli-decode.c, cli/cli-dump.c, cli/cli-option.h, cli/cli-script.c, coff-pe-read.c, command.h, compile/compile-c-support.c, compile/compile-c.h, compile/compile-cplus-symbols.c, compile/compile-cplus-types.c, compile/compile-cplus.h, compile/compile-loc2c.c, compile/compile.c, completer.c, completer.h, contrib/ari/gdb_ari.sh, corefile.c, corelow.c, cp-support.c, cp-support.h, cp-valprint.c, csky-tdep.c, ctf.c, darwin-nat.c, debug.c, defs.h, disasm-selftests.c, disasm.c, disasm.h, dtrace-probe.c, dwarf-index-cache.c, dwarf-index-cache.h, dwarf-index-write.c, dwarf2-frame.c, dwarf2expr.c, dwarf2loc.c, dwarf2read.c, event-loop.c, event-top.c, exceptions.c, exec.c, extension.h, fbsd-nat.c, features/aarch64-core.c, features/aarch64-fpu.c, features/aarch64-pauth.c, features/aarch64-sve.c, features/i386/32bit-avx.c, features/i386/32bit-avx512.c, features/i386/32bit-core.c, features/i386/32bit-linux.c, features/i386/32bit-mpx.c, features/i386/32bit-pkeys.c, features/i386/32bit-segments.c, features/i386/32bit-sse.c, features/i386/64bit-avx.c, features/i386/64bit-avx512.c, features/i386/64bit-core.c, features/i386/64bit-linux.c, features/i386/64bit-mpx.c, features/i386/64bit-pkeys.c, features/i386/64bit-segments.c, features/i386/64bit-sse.c, features/i386/x32-core.c, features/riscv/32bit-cpu.c, features/riscv/32bit-csr.c, features/riscv/32bit-fpu.c, features/riscv/64bit-cpu.c, features/riscv/64bit-csr.c, features/riscv/64bit-fpu.c, features/tic6x-c6xp.c, features/tic6x-core.c, features/tic6x-gp.c, filename-seen-cache.h, findcmd.c, findvar.c, fork-child.c, gcore.c, gdb_bfd.c, gdb_bfd.h, gdb_proc_service.h, gdb_regex.c, gdb_select.h, gdb_usleep.c, gdbarch-selftests.c, gdbthread.h, gdbtypes.h, gnu-nat.c, go32-nat.c, guile/guile.c, guile/scm-ports.c, guile/scm-safe-call.c, guile/scm-type.c, i386-fbsd-nat.c, i386-fbsd-tdep.c, i386-go32-tdep.c, i386-linux-nat.c, i386-linux-tdep.c, i386-tdep.c, i387-tdep.c, ia64-libunwind-tdep.c, ia64-linux-nat.c, inf-child.c, inf-ptrace.c, infcall.c, infcall.h, infcmd.c, inferior-iter.h, inferior.c, inferior.h, inflow.c, inflow.h, infrun.c, infrun.h, inline-frame.c, language.h, linespec.c, linux-fork.c, linux-nat.c, linux-tdep.c, linux-thread-db.c, location.c, machoread.c, macrotab.h, main.c, maint.c, maint.h, memattr.c, memrange.h, mi/mi-cmd-break.h, mi/mi-cmd-env.c, mi/mi-cmd-stack.c, mi/mi-cmd-var.c, mi/mi-interp.c, mi/mi-main.c, mi/mi-parse.h, minsyms.c, mips-linux-tdep.c, namespace.h, nat/aarch64-linux-hw-point.c, nat/aarch64-linux-hw-point.h, nat/aarch64-linux.c, nat/aarch64-sve-linux-ptrace.c, nat/amd64-linux-siginfo.c, nat/fork-inferior.c, nat/linux-btrace.c, nat/linux-btrace.h, nat/linux-namespaces.c, nat/linux-nat.h, nat/linux-osdata.c, nat/linux-personality.c, nat/linux-procfs.c, nat/linux-ptrace.c, nat/linux-ptrace.h, nat/linux-waitpid.c, nat/mips-linux-watch.c, nat/mips-linux-watch.h, nat/ppc-linux.c, nat/x86-dregs.c, nat/x86-dregs.h, nat/x86-linux-dregs.c, nat/x86-linux.c, nto-procfs.c, nto-tdep.c, objfile-flags.h, objfiles.c, objfiles.h, obsd-nat.c, observable.h, osdata.c, p-valprint.c, parse.c, parser-defs.h, ppc-linux-nat.c, printcmd.c, probe.c, proc-api.c, procfs.c, producer.c, progspace.h, psymtab.h, python/py-framefilter.c, python/py-inferior.c, python/py-ref.h, python/py-type.c, python/python.c, record-btrace.c, record-full.c, record.c, record.h, regcache-dump.c, regcache.c, regcache.h, remote-fileio.c, remote-fileio.h, remote-sim.c, remote.c, riscv-tdep.c, rs6000-aix-tdep.c, rust-exp.y, s12z-tdep.c, selftest-arch.c, ser-base.c, ser-event.c, ser-pipe.c, ser-tcp.c, ser-unix.c, skip.c, solib-aix.c, solib-target.c, solib.c, source-cache.c, source.c, source.h, sparc-nat.c, spu-linux-nat.c, stack.c, stap-probe.c, symfile-add-flags.h, symfile.c, symfile.h, symtab.c, symtab.h, target-descriptions.c, target-descriptions.h, target-memory.c, target.c, target.h, target/waitstatus.c, target/waitstatus.h, thread-iter.h, thread.c, tilegx-tdep.c, top.c, top.h, tracefile-tfile.c, tracefile.c, tracepoint.c, tracepoint.h, tui/tui-io.c, ui-file.c, ui-out.h, unittests/array-view-selftests.c, unittests/child-path-selftests.c, unittests/cli-utils-selftests.c, unittests/common-utils-selftests.c, unittests/copy_bitwise-selftests.c, unittests/environ-selftests.c, unittests/format_pieces-selftests.c, unittests/function-view-selftests.c, unittests/lookup_name_info-selftests.c, unittests/memory-map-selftests.c, unittests/memrange-selftests.c, unittests/mkdir-recursive-selftests.c, unittests/observable-selftests.c, unittests/offset-type-selftests.c, unittests/optional-selftests.c, unittests/parse-connection-spec-selftests.c, unittests/ptid-selftests.c, unittests/rsp-low-selftests.c, unittests/scoped_fd-selftests.c, unittests/scoped_mmap-selftests.c, unittests/scoped_restore-selftests.c, unittests/string_view-selftests.c, unittests/style-selftests.c, unittests/tracepoint-selftests.c, unittests/unpack-selftests.c, unittests/utils-selftests.c, unittests/xml-utils-selftests.c, utils.c, utils.h, valarith.c, valops.c, valprint.c, value.c, value.h, varobj.c, varobj.h, windows-nat.c, x86-linux-nat.c, xml-support.c, xml-support.h, xml-tdesc.h, xstormy16-tdep.c, xtensa-linux-nat.c, dwarf2read.h: Change common to gdbsupport. gdb/gdbserver/ChangeLog 2019-07-09 Tom Tromey <tom@tromey.com> * configure: Rebuild. * configure.ac: Change common to gdbsupport. * acinclude.m4: Change common to gdbsupport. * Makefile.in (SFILES, OBS, GDBREPLAY_OBS, IPA_OBJS) (version-generated.c, gdbsupport/%-ipa.o, gdbsupport/%.o): Change common to gdbsupport. * ax.c, event-loop.c, fork-child.c, gdb_proc_service.h, gdbreplay.c, gdbthread.h, hostio-errno.c, hostio.c, i387-fp.c, inferiors.c, inferiors.h, linux-aarch64-tdesc-selftest.c, linux-amd64-ipa.c, linux-i386-ipa.c, linux-low.c, linux-tic6x-low.c, linux-x86-low.c, linux-x86-tdesc-selftest.c, linux-x86-tdesc.c, lynx-i386-low.c, lynx-low.c, mem-break.h, nto-x86-low.c, regcache.c, regcache.h, remote-utils.c, server.c, server.h, spu-low.c, symbol.c, target.h, tdesc.c, tdesc.h, thread-db.c, tracepoint.c, win32-i386-low.c, win32-low.c: Change common to gdbsupport.
2019-05-06 04:29:24 +02:00
#include "gdbsupport/gdb_setjmp.h"
#include "safe-ctype.h"
Rename common to gdbsupport This is the next patch in the ongoing series to move gdbsever to the top level. This patch just renames the "common" directory. The idea is to do this move in two parts: first rename the directory (this patch), then move the directory to the top. This approach makes the patches a bit more tractable. I chose the name "gdbsupport" for the directory. However, as this patch was largely written by sed, we could pick a new name without too much difficulty. Tested by the buildbot. gdb/ChangeLog 2019-07-09 Tom Tromey <tom@tromey.com> * contrib/ari/gdb_ari.sh: Change common to gdbsupport. * configure: Rebuild. * configure.ac: Change common to gdbsupport. * gdbsupport: Rename from common. * acinclude.m4: Change common to gdbsupport. * Makefile.in (CONFIG_SRC_SUBDIR, COMMON_SFILES) (HFILES_NO_SRCDIR, stamp-version, ALLDEPFILES): Change common to gdbsupport. * aarch64-tdep.c, ada-lang.c, ada-lang.h, agent.c, alloc.c, amd64-darwin-tdep.c, amd64-dicos-tdep.c, amd64-fbsd-nat.c, amd64-fbsd-tdep.c, amd64-linux-nat.c, amd64-linux-tdep.c, amd64-nbsd-tdep.c, amd64-obsd-tdep.c, amd64-sol2-tdep.c, amd64-tdep.c, amd64-windows-tdep.c, arch-utils.c, arch/aarch64-insn.c, arch/aarch64.c, arch/aarch64.h, arch/amd64.c, arch/amd64.h, arch/arm-get-next-pcs.c, arch/arm-linux.c, arch/arm.c, arch/i386.c, arch/i386.h, arch/ppc-linux-common.c, arch/riscv.c, arch/riscv.h, arch/tic6x.c, arm-tdep.c, auto-load.c, auxv.c, ax-gdb.c, ax-general.c, ax.h, breakpoint.c, breakpoint.h, btrace.c, btrace.h, build-id.c, build-id.h, c-lang.h, charset.c, charset.h, cli/cli-cmds.c, cli/cli-cmds.h, cli/cli-decode.c, cli/cli-dump.c, cli/cli-option.h, cli/cli-script.c, coff-pe-read.c, command.h, compile/compile-c-support.c, compile/compile-c.h, compile/compile-cplus-symbols.c, compile/compile-cplus-types.c, compile/compile-cplus.h, compile/compile-loc2c.c, compile/compile.c, completer.c, completer.h, contrib/ari/gdb_ari.sh, corefile.c, corelow.c, cp-support.c, cp-support.h, cp-valprint.c, csky-tdep.c, ctf.c, darwin-nat.c, debug.c, defs.h, disasm-selftests.c, disasm.c, disasm.h, dtrace-probe.c, dwarf-index-cache.c, dwarf-index-cache.h, dwarf-index-write.c, dwarf2-frame.c, dwarf2expr.c, dwarf2loc.c, dwarf2read.c, event-loop.c, event-top.c, exceptions.c, exec.c, extension.h, fbsd-nat.c, features/aarch64-core.c, features/aarch64-fpu.c, features/aarch64-pauth.c, features/aarch64-sve.c, features/i386/32bit-avx.c, features/i386/32bit-avx512.c, features/i386/32bit-core.c, features/i386/32bit-linux.c, features/i386/32bit-mpx.c, features/i386/32bit-pkeys.c, features/i386/32bit-segments.c, features/i386/32bit-sse.c, features/i386/64bit-avx.c, features/i386/64bit-avx512.c, features/i386/64bit-core.c, features/i386/64bit-linux.c, features/i386/64bit-mpx.c, features/i386/64bit-pkeys.c, features/i386/64bit-segments.c, features/i386/64bit-sse.c, features/i386/x32-core.c, features/riscv/32bit-cpu.c, features/riscv/32bit-csr.c, features/riscv/32bit-fpu.c, features/riscv/64bit-cpu.c, features/riscv/64bit-csr.c, features/riscv/64bit-fpu.c, features/tic6x-c6xp.c, features/tic6x-core.c, features/tic6x-gp.c, filename-seen-cache.h, findcmd.c, findvar.c, fork-child.c, gcore.c, gdb_bfd.c, gdb_bfd.h, gdb_proc_service.h, gdb_regex.c, gdb_select.h, gdb_usleep.c, gdbarch-selftests.c, gdbthread.h, gdbtypes.h, gnu-nat.c, go32-nat.c, guile/guile.c, guile/scm-ports.c, guile/scm-safe-call.c, guile/scm-type.c, i386-fbsd-nat.c, i386-fbsd-tdep.c, i386-go32-tdep.c, i386-linux-nat.c, i386-linux-tdep.c, i386-tdep.c, i387-tdep.c, ia64-libunwind-tdep.c, ia64-linux-nat.c, inf-child.c, inf-ptrace.c, infcall.c, infcall.h, infcmd.c, inferior-iter.h, inferior.c, inferior.h, inflow.c, inflow.h, infrun.c, infrun.h, inline-frame.c, language.h, linespec.c, linux-fork.c, linux-nat.c, linux-tdep.c, linux-thread-db.c, location.c, machoread.c, macrotab.h, main.c, maint.c, maint.h, memattr.c, memrange.h, mi/mi-cmd-break.h, mi/mi-cmd-env.c, mi/mi-cmd-stack.c, mi/mi-cmd-var.c, mi/mi-interp.c, mi/mi-main.c, mi/mi-parse.h, minsyms.c, mips-linux-tdep.c, namespace.h, nat/aarch64-linux-hw-point.c, nat/aarch64-linux-hw-point.h, nat/aarch64-linux.c, nat/aarch64-sve-linux-ptrace.c, nat/amd64-linux-siginfo.c, nat/fork-inferior.c, nat/linux-btrace.c, nat/linux-btrace.h, nat/linux-namespaces.c, nat/linux-nat.h, nat/linux-osdata.c, nat/linux-personality.c, nat/linux-procfs.c, nat/linux-ptrace.c, nat/linux-ptrace.h, nat/linux-waitpid.c, nat/mips-linux-watch.c, nat/mips-linux-watch.h, nat/ppc-linux.c, nat/x86-dregs.c, nat/x86-dregs.h, nat/x86-linux-dregs.c, nat/x86-linux.c, nto-procfs.c, nto-tdep.c, objfile-flags.h, objfiles.c, objfiles.h, obsd-nat.c, observable.h, osdata.c, p-valprint.c, parse.c, parser-defs.h, ppc-linux-nat.c, printcmd.c, probe.c, proc-api.c, procfs.c, producer.c, progspace.h, psymtab.h, python/py-framefilter.c, python/py-inferior.c, python/py-ref.h, python/py-type.c, python/python.c, record-btrace.c, record-full.c, record.c, record.h, regcache-dump.c, regcache.c, regcache.h, remote-fileio.c, remote-fileio.h, remote-sim.c, remote.c, riscv-tdep.c, rs6000-aix-tdep.c, rust-exp.y, s12z-tdep.c, selftest-arch.c, ser-base.c, ser-event.c, ser-pipe.c, ser-tcp.c, ser-unix.c, skip.c, solib-aix.c, solib-target.c, solib.c, source-cache.c, source.c, source.h, sparc-nat.c, spu-linux-nat.c, stack.c, stap-probe.c, symfile-add-flags.h, symfile.c, symfile.h, symtab.c, symtab.h, target-descriptions.c, target-descriptions.h, target-memory.c, target.c, target.h, target/waitstatus.c, target/waitstatus.h, thread-iter.h, thread.c, tilegx-tdep.c, top.c, top.h, tracefile-tfile.c, tracefile.c, tracepoint.c, tracepoint.h, tui/tui-io.c, ui-file.c, ui-out.h, unittests/array-view-selftests.c, unittests/child-path-selftests.c, unittests/cli-utils-selftests.c, unittests/common-utils-selftests.c, unittests/copy_bitwise-selftests.c, unittests/environ-selftests.c, unittests/format_pieces-selftests.c, unittests/function-view-selftests.c, unittests/lookup_name_info-selftests.c, unittests/memory-map-selftests.c, unittests/memrange-selftests.c, unittests/mkdir-recursive-selftests.c, unittests/observable-selftests.c, unittests/offset-type-selftests.c, unittests/optional-selftests.c, unittests/parse-connection-spec-selftests.c, unittests/ptid-selftests.c, unittests/rsp-low-selftests.c, unittests/scoped_fd-selftests.c, unittests/scoped_mmap-selftests.c, unittests/scoped_restore-selftests.c, unittests/string_view-selftests.c, unittests/style-selftests.c, unittests/tracepoint-selftests.c, unittests/unpack-selftests.c, unittests/utils-selftests.c, unittests/xml-utils-selftests.c, utils.c, utils.h, valarith.c, valops.c, valprint.c, value.c, value.h, varobj.c, varobj.h, windows-nat.c, x86-linux-nat.c, xml-support.c, xml-support.h, xml-tdesc.h, xstormy16-tdep.c, xtensa-linux-nat.c, dwarf2read.h: Change common to gdbsupport. gdb/gdbserver/ChangeLog 2019-07-09 Tom Tromey <tom@tromey.com> * configure: Rebuild. * configure.ac: Change common to gdbsupport. * acinclude.m4: Change common to gdbsupport. * Makefile.in (SFILES, OBS, GDBREPLAY_OBS, IPA_OBJS) (version-generated.c, gdbsupport/%-ipa.o, gdbsupport/%.o): Change common to gdbsupport. * ax.c, event-loop.c, fork-child.c, gdb_proc_service.h, gdbreplay.c, gdbthread.h, hostio-errno.c, hostio.c, i387-fp.c, inferiors.c, inferiors.h, linux-aarch64-tdesc-selftest.c, linux-amd64-ipa.c, linux-i386-ipa.c, linux-low.c, linux-tic6x-low.c, linux-x86-low.c, linux-x86-tdesc-selftest.c, linux-x86-tdesc.c, lynx-i386-low.c, lynx-low.c, mem-break.h, nto-x86-low.c, regcache.c, regcache.h, remote-utils.c, server.c, server.h, spu-low.c, symbol.c, target.h, tdesc.c, tdesc.h, thread-db.c, tracepoint.c, win32-i386-low.c, win32-low.c: Change common to gdbsupport.
2019-05-06 04:29:24 +02:00
#include "gdbsupport/selftest.h"
Add RAII class for blocking gdb signals This adds configury support and an RAII class that can be used to temporarily block signals that are used by gdb. (This class is not used in this patch, but it split out for easier review.) The idea of this patch is that these signals should only be delivered to the main thread. So, when creating a background thread, they are temporarily blocked; the blocked state is inherited by the new thread. The sigprocmask man page says: The use of sigprocmask() is unspecified in a multithreaded process; see pthread_sigmask(3). This patch changes gdb to use pthread_sigmask when appropriate, by introducing a convenience define. I've updated gdbserver as well, because I had to touch gdbsupport, and because the threading patches will make it link against the thread library. I chose not to touch the NTO code, because I don't know anything about that platform and because I cannot test it. Finally, this modifies an existing spot in the Guile layer to use the new facility. gdb/ChangeLog 2019-11-26 Tom Tromey <tom@tromey.com> * gdbsupport/signals-state-save-restore.c (original_signal_mask): Remove comment. (save_original_signals_state, restore_original_signals_state): Use gdb_sigmask. * linux-nat.c (block_child_signals, restore_child_signals_mask) (_initialize_linux_nat): Use gdb_sigmask. * guile/guile.c (_initialize_guile): Use block_signals. * Makefile.in (HFILES_NO_SRCDIR): Add gdb-sigmask.h. * gdbsupport/gdb-sigmask.h: New file. * event-top.c (async_sigtstp_handler): Use gdb_sigmask. * cp-support.c (gdb_demangle): Use gdb_sigmask. * gdbsupport/common.m4 (GDB_AC_COMMON): Check for pthread_sigmask. * configure, config.in: Rebuild. * gdbsupport/block-signals.h: New file. gdb/gdbserver/ChangeLog 2019-11-26 Tom Tromey <tom@tromey.com> * remote-utils.c (block_unblock_async_io): Use gdb_sigmask. * linux-low.c (linux_wait_for_event_filtered, linux_async): Use gdb_sigmask. * configure, config.in: Rebuild. Change-Id: If3f37dc57dd859c226e9e4d79458a0514746e8c6
2019-09-29 16:50:15 +02:00
#include "gdbsupport/gdb-sigmask.h"
#include <atomic>
#include "event-top.h"
#include "run-on-main-thread.h"
#define d_left(dc) (dc)->u.s_binary.left
#define d_right(dc) (dc)->u.s_binary.right
/* Functions related to demangled name parsing. */
static unsigned int cp_find_first_component_aux (const char *name,
int permissive);
static void demangled_name_complaint (const char *name);
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
/* Functions related to overload resolution. */
static void overload_list_add_symbol (struct symbol *sym,
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
const char *oload_name,
std::vector<symbol *> *overload_list);
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
static void add_symbol_overload_list_using
(const char *func_name, const char *the_namespace,
std::vector<symbol *> *overload_list);
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
static void add_symbol_overload_list_qualified
(const char *func_name,
std::vector<symbol *> *overload_list);
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
/* The list of "maint cplus" commands. */
2003-09-11 David Carlton <carlton@kealia.com> * gdbtypes.h: Add TYPE_CODE_NAMESPACE. * gdbtypes.c (init_type): Handle TYPE_CODE_NAMESPACE. (recursive_dump_type): Ditto. * printcmd.c (print_formatted): Ditto. * typeprint.c (print_type_scalar): Ditto. * c-typeprint.c (c_type_print_varspec_prefix): Ditto. (c_type_print_varspec_suffix, c_type_print_base): Ditto. * cp-support.h: Declare cp_check_possible_namespace_symbols, maint_cplus_cmd_list. * cp-support.c: Make maint_cplus_cmd_list extern. * cp-namespace.c: Include objfiles.h, gdbtypes.h, dictionary.h, command.h. (lookup_symbol_file): Look in possible namespace blocks when appropriate. (initialize_namespace_symtab): New. (get_possible_namespace_block, free_namespace_block) (check_possible_namespace_symbols) (check_possible_namespace_symbols_loop) (check_one_possible_namespace_symbol) (lookup_possible_namespace_symbol, maintenance_cplus_namespace) (_initialize_cp_namespace): Ditto. * block.h: Declare allocate_block. * block.c (allocate_block): New. * jv-lang.c (get_java_class_symtab): Allocate blocks via allocate_block. * symfile.h: Update declaration of add_psymbol_to_list. * symfile.c (add_psymbol_to_list): Return the partial symbol in question. * dwarf2read.c (dwarf2_build_psymtabs_hard): Add argument to scan_partial_symbols_call. (scan_partial_symbols): Add NAMESPACE argument; update calls to helper functions. (add_partial_symbol): If necessary, scan mangled names for names of namespaces. (add_partial_namespace): Add NAMESPACE argument; generate partial symbols associated to namespaces. (add_partial_enumeration): Add NAMESPACE argument. (new_symbol): Allow namespace syms. (read_namespace): Generate namespace syms. * objfiles.h: Add opaque declaration of struct symtab. (struct objfile): Add cp_namespace_symtab member. * objfiles.c (allocate_objfile): Set objfile->cp_namespace_symtab. * Makefile.in (cp-namespace.o): Depend on objfiles_h, gdbtypes_h, dictionary_h, command_h. 2003-09-11 David Carlton <carlton@kealia.com> * gdb.c++/namespace.exp: Add tests for namespace types. * gdb.c++/maint.exp (test_help): Test 'help maint cp namespace'. (test_namespace): New.
2003-09-11 21:49:20 +02:00
struct cmd_list_element *maint_cplus_cmd_list = NULL;
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
/* A list of typedefs which should not be substituted by replace_typedefs. */
static const char * const ignore_typedefs[] =
{
"std::istream", "std::iostream", "std::ostream", "std::string"
};
static void
replace_typedefs (struct demangle_parse_info *info,
struct demangle_component *ret_comp,
canonicalization_ftype *finder,
void *data);
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
/* A convenience function to copy STRING into OBSTACK, returning a pointer
to the newly allocated string and saving the number of bytes saved in LEN.
It does not copy the terminating '\0' byte! */
static char *
copy_string_to_obstack (struct obstack *obstack, const char *string,
long *len)
{
*len = strlen (string);
Add casts to memory allocation related calls Most allocation functions (if not all) return a void* pointing to the allocated memory. In C++, we need to add an explicit cast when assigning the result to a pointer to another type (which is the case more often than not). The content of this patch is taken from Pedro's branch, from commit "(mostly) auto-generated patch to insert casts needed for C++". I validated that the changes make sense and manually reflowed the code to make it respect the coding style. I also found multiple places where I could use XNEW/XNEWVEC/XRESIZEVEC/etc. Thanks a lot to whoever did that automated script to insert casts, doing it completely by hand would have taken a ridiculous amount of time. Only files built on x86 with --enable-targets=all are modified. This means that all other -nat.c files are untouched and will have to be dealt with later by using appropiate compilers. Or maybe we can try to build them with a regular g++ just to know where to add casts, I don't know. I built-tested this with --enable-targets=all and reg-tested. Here's the changelog entry, which was not too bad to make despite the size, thanks to David Malcom's script. I fixed some bits by hand, but there might be some wrong parts left (hopefully not). gdb/ChangeLog: * aarch64-linux-tdep.c (aarch64_stap_parse_special_token): Add cast to allocation result assignment. * ada-exp.y (write_object_renaming): Likewise. (write_ambiguous_var): Likewise. (ada_nget_field_index): Likewise. (write_var_or_type): Likewise. * ada-lang.c (ada_decode_symbol): Likewise. (ada_value_assign): Likewise. (value_pointer): Likewise. (cache_symbol): Likewise. (add_nonlocal_symbols): Likewise. (ada_name_for_lookup): Likewise. (symbol_completion_add): Likewise. (ada_to_fixed_type_1): Likewise. (ada_get_next_arg): Likewise. (defns_collected): Likewise. * ada-lex.l (processId): Likewise. (processString): Likewise. * ada-tasks.c (read_known_tasks_array): Likewise. (read_known_tasks_list): Likewise. * ada-typeprint.c (decoded_type_name): Likewise. * addrmap.c (addrmap_mutable_create_fixed): Likewise. * amd64-tdep.c (amd64_push_arguments): Likewise. (amd64_displaced_step_copy_insn): Likewise. (amd64_classify_insn_at): Likewise. (amd64_relocate_instruction): Likewise. * amd64obsd-tdep.c (amd64obsd_sigtramp_p): Likewise. * arch-utils.c (simple_displaced_step_copy_insn): Likewise. (initialize_current_architecture): Likewise. * arm-linux-tdep.c (arm_stap_parse_special_token): Likewise. * arm-symbian-tdep.c (arm_symbian_osabi_sniffer): Likewise. * arm-tdep.c (arm_exidx_new_objfile): Likewise. (arm_push_dummy_call): Likewise. (extend_buffer_earlier): Likewise. (arm_adjust_breakpoint_address): Likewise. (arm_skip_stub): Likewise. * auto-load.c (filename_is_in_pattern): Likewise. (maybe_add_script_file): Likewise. (maybe_add_script_text): Likewise. (auto_load_objfile_script_1): Likewise. * auxv.c (ld_so_xfer_auxv): Likewise. * ax-general.c (new_agent_expr): Likewise. (grow_expr): Likewise. (ax_reg_mask): Likewise. * bcache.c (bcache_full): Likewise. * breakpoint.c (program_breakpoint_here_p): Likewise. * btrace.c (parse_xml_raw): Likewise. * build-id.c (build_id_to_debug_bfd): Likewise. * buildsym.c (end_symtab_with_blockvector): Likewise. * c-exp.y (string_exp): Likewise. (qualified_name): Likewise. (write_destructor_name): Likewise. (operator_stoken): Likewise. (parse_number): Likewise. (scan_macro_expansion): Likewise. (yylex): Likewise. (c_print_token): Likewise. * c-lang.c (c_get_string): Likewise. (emit_numeric_character): Likewise. * charset.c (wchar_iterate): Likewise. * cli/cli-cmds.c (complete_command): Likewise. (make_command): Likewise. * cli/cli-dump.c (restore_section_callback): Likewise. (restore_binary_file): Likewise. * cli/cli-interp.c (cli_interpreter_exec): Likewise. * cli/cli-script.c (execute_control_command): Likewise. * cli/cli-setshow.c (do_set_command): Likewise. * coff-pe-read.c (add_pe_forwarded_sym): Likewise. (read_pe_exported_syms): Likewise. * coffread.c (coff_read_struct_type): Likewise. (coff_read_enum_type): Likewise. * common/btrace-common.c (btrace_data_append): Likewise. * common/buffer.c (buffer_grow): Likewise. * common/filestuff.c (gdb_fopen_cloexec): Likewise. * common/format.c (parse_format_string): Likewise. * common/gdb_vecs.c (delim_string_to_char_ptr_vec_append): Likewise. * common/xml-utils.c (xml_escape_text): Likewise. * compile/compile-object-load.c (copy_sections): Likewise. (compile_object_load): Likewise. * compile/compile-object-run.c (compile_object_run): Likewise. * completer.c (filename_completer): Likewise. * corefile.c (read_memory_typed_address): Likewise. (write_memory_unsigned_integer): Likewise. (write_memory_signed_integer): Likewise. (complete_set_gnutarget): Likewise. * corelow.c (get_core_register_section): Likewise. * cp-name-parser.y (d_grab): Likewise. (allocate_info): Likewise. (cp_new_demangle_parse_info): Likewise. * cp-namespace.c (cp_scan_for_anonymous_namespaces): Likewise. (cp_lookup_symbol_in_namespace): Likewise. (lookup_namespace_scope): Likewise. (find_symbol_in_baseclass): Likewise. (cp_lookup_nested_symbol): Likewise. (cp_lookup_transparent_type_loop): Likewise. * cp-support.c (copy_string_to_obstack): Likewise. (make_symbol_overload_list): Likewise. (make_symbol_overload_list_namespace): Likewise. (make_symbol_overload_list_adl_namespace): Likewise. (first_component_command): Likewise. * cp-valprint.c (cp_print_value): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * d-exp.y (StringExp): Likewise. * d-namespace.c (d_lookup_symbol_in_module): Likewise. (lookup_module_scope): Likewise. (find_symbol_in_baseclass): Likewise. (d_lookup_nested_symbol): Likewise. * dbxread.c (find_stab_function_addr): Likewise. (read_dbx_symtab): Likewise. (dbx_end_psymtab): Likewise. (cp_set_block_scope): Likewise. * dcache.c (dcache_alloc): Likewise. * demangle.c (_initialize_demangler): Likewise. * dicos-tdep.c (dicos_load_module_p): Likewise. * dictionary.c (dict_create_hashed_expandable): Likewise. (dict_create_linear_expandable): Likewise. (expand_hashtable): Likewise. (add_symbol_linear_expandable): Likewise. * dwarf2-frame.c (add_cie): Likewise. (add_fde): Likewise. (dwarf2_build_frame_info): Likewise. * dwarf2expr.c (dwarf_expr_grow_stack): Likewise. (dwarf_expr_fetch_address): Likewise. (add_piece): Likewise. (execute_stack_op): Likewise. * dwarf2loc.c (chain_candidate): Likewise. (dwarf_entry_parameter_to_value): Likewise. (read_pieced_value): Likewise. (write_pieced_value): Likewise. * dwarf2read.c (dwarf2_read_section): Likewise. (add_type_unit): Likewise. (read_comp_units_from_section): Likewise. (fixup_go_packaging): Likewise. (dwarf2_compute_name): Likewise. (dwarf2_physname): Likewise. (create_dwo_unit_in_dwp_v1): Likewise. (create_dwo_unit_in_dwp_v2): Likewise. (read_func_scope): Likewise. (read_call_site_scope): Likewise. (dwarf2_attach_fields_to_type): Likewise. (process_structure_scope): Likewise. (mark_common_block_symbol_computed): Likewise. (read_common_block): Likewise. (abbrev_table_read_table): Likewise. (guess_partial_die_structure_name): Likewise. (fixup_partial_die): Likewise. (add_file_name): Likewise. (dwarf2_const_value_data): Likewise. (dwarf2_const_value_attr): Likewise. (build_error_marker_type): Likewise. (guess_full_die_structure_name): Likewise. (anonymous_struct_prefix): Likewise. (typename_concat): Likewise. (dwarf2_canonicalize_name): Likewise. (dwarf2_name): Likewise. (write_constant_as_bytes): Likewise. (dwarf2_fetch_constant_bytes): Likewise. (copy_string): Likewise. (parse_macro_definition): Likewise. * elfread.c (elf_symfile_segments): Likewise. (elf_rel_plt_read): Likewise. (elf_gnu_ifunc_resolve_by_cache): Likewise. (elf_gnu_ifunc_resolve_by_got): Likewise. (elf_read_minimal_symbols): Likewise. (elf_gnu_ifunc_record_cache): Likewise. * event-top.c (top_level_prompt): Likewise. (command_line_handler): Likewise. * exec.c (resize_section_table): Likewise. * expprint.c (print_subexp_standard): Likewise. * fbsd-tdep.c (fbsd_collect_regset_section_cb): Likewise. * findcmd.c (parse_find_args): Likewise. * findvar.c (address_from_register): Likewise. * frame.c (get_prev_frame_always): Likewise. * gdb_bfd.c (gdb_bfd_ref): Likewise. (get_section_descriptor): Likewise. * gdb_obstack.c (obconcat): Likewise. (obstack_strdup): Likewise. * gdbtypes.c (lookup_function_type_with_arguments): Likewise. (create_set_type): Likewise. (lookup_unsigned_typename): Likewise. (lookup_signed_typename): Likewise. (resolve_dynamic_union): Likewise. (resolve_dynamic_struct): Likewise. (add_dyn_prop): Likewise. (copy_dynamic_prop_list): Likewise. (arch_flags_type): Likewise. (append_composite_type_field_raw): Likewise. * gdbtypes.h (INIT_FUNC_SPECIFIC): Likewise. * gnu-v3-abi.c (gnuv3_rtti_type): Likewise. * go-exp.y (string_exp): Likewise. * go-lang.c (go_demangle): Likewise. * guile/guile.c (compute_scheme_string): Likewise. * guile/scm-cmd.c (gdbscm_parse_command_name): Likewise. (gdbscm_canonicalize_command_name): Likewise. * guile/scm-ports.c (ioscm_init_stdio_buffers): Likewise. (ioscm_init_memory_port): Likewise. (ioscm_reinit_memory_port): Likewise. * guile/scm-utils.c (gdbscm_gc_xstrdup): Likewise. (gdbscm_gc_dup_argv): Likewise. * h8300-tdep.c (h8300_push_dummy_call): Likewise. * hppa-tdep.c (internalize_unwinds): Likewise. (read_unwind_info): Likewise. * i386-cygwin-tdep.c (core_process_module_section): Likewise. (windows_core_xfer_shared_libraries): Likewise. * i386-tdep.c (i386_displaced_step_copy_insn): Likewise. (i386_stap_parse_special_token_triplet): Likewise. (i386_stap_parse_special_token_three_arg_disp): Likewise. * i386obsd-tdep.c (i386obsd_sigtramp_p): Likewise. * inf-child.c (inf_child_fileio_readlink): Likewise. * inf-ptrace.c (inf_ptrace_fetch_register): Likewise. (inf_ptrace_store_register): Likewise. * infrun.c (follow_exec): Likewise. (displaced_step_prepare_throw): Likewise. (save_stop_context): Likewise. (save_infcall_suspend_state): Likewise. * jit.c (jit_read_descriptor): Likewise. (jit_read_code_entry): Likewise. (jit_symtab_line_mapping_add_impl): Likewise. (finalize_symtab): Likewise. (jit_unwind_reg_get_impl): Likewise. * jv-exp.y (QualifiedName): Likewise. * jv-lang.c (get_java_utf8_name): Likewise. (type_from_class): Likewise. (java_demangle_type_signature): Likewise. (java_class_name_from_physname): Likewise. * jv-typeprint.c (java_type_print_base): Likewise. * jv-valprint.c (java_value_print): Likewise. * language.c (add_language): Likewise. * linespec.c (add_sal_to_sals_basic): Likewise. (add_sal_to_sals): Likewise. (decode_objc): Likewise. (find_linespec_symbols): Likewise. * linux-fork.c (fork_save_infrun_state): Likewise. * linux-nat.c (linux_nat_detach): Likewise. (linux_nat_fileio_readlink): Likewise. * linux-record.c (record_linux_sockaddr): Likewise. (record_linux_msghdr): Likewise. (Do): Likewise. * linux-tdep.c (linux_core_info_proc_mappings): Likewise. (linux_collect_regset_section_cb): Likewise. (linux_get_siginfo_data): Likewise. * linux-thread-db.c (try_thread_db_load_from_pdir_1): Likewise. (try_thread_db_load_from_dir): Likewise. (thread_db_load_search): Likewise. (info_auto_load_libthread_db): Likewise. * m32c-tdep.c (m32c_m16c_address_to_pointer): Likewise. (m32c_m16c_pointer_to_address): Likewise. * m68hc11-tdep.c (m68hc11_pseudo_register_write): Likewise. * m68k-tdep.c (m68k_get_longjmp_target): Likewise. * machoread.c (macho_check_dsym): Likewise. * macroexp.c (resize_buffer): Likewise. (gather_arguments): Likewise. (maybe_expand): Likewise. * macrotab.c (new_macro_key): Likewise. (new_source_file): Likewise. (new_macro_definition): Likewise. * mdebugread.c (parse_symbol): Likewise. (parse_type): Likewise. (parse_partial_symbols): Likewise. (psymtab_to_symtab_1): Likewise. * mem-break.c (default_memory_insert_breakpoint): Likewise. * mi/mi-cmd-break.c (mi_argv_to_format): Likewise. * mi/mi-main.c (mi_cmd_data_read_memory): Likewise. (mi_cmd_data_read_memory_bytes): Likewise. (mi_cmd_data_write_memory_bytes): Likewise. (mi_cmd_trace_frame_collected): Likewise. * mi/mi-parse.c (mi_parse_argv): Likewise. (mi_parse): Likewise. * minidebug.c (lzma_open): Likewise. (lzma_pread): Likewise. * mips-tdep.c (mips_read_fp_register_single): Likewise. (mips_print_fp_register): Likewise. * mipsnbsd-tdep.c (mipsnbsd_get_longjmp_target): Likewise. * mipsread.c (read_alphacoff_dynamic_symtab): Likewise. * mt-tdep.c (mt_register_name): Likewise. (mt_registers_info): Likewise. (mt_push_dummy_call): Likewise. * namespace.c (add_using_directive): Likewise. * nat/linux-btrace.c (perf_event_read): Likewise. (linux_enable_bts): Likewise. * nat/linux-osdata.c (linux_common_core_of_thread): Likewise. * nat/linux-ptrace.c (linux_ptrace_test_ret_to_nx): Likewise. * nto-tdep.c (nto_find_and_open_solib): Likewise. (nto_parse_redirection): Likewise. * objc-lang.c (objc_demangle): Likewise. (find_methods): Likewise. * objfiles.c (get_objfile_bfd_data): Likewise. (set_objfile_main_name): Likewise. (allocate_objfile): Likewise. (objfile_relocate): Likewise. (update_section_map): Likewise. * osabi.c (generic_elf_osabi_sniff_abi_tag_sections): Likewise. * p-exp.y (exp): Likewise. (yylex): Likewise. * p-valprint.c (pascal_object_print_value): Likewise. * parse.c (initialize_expout): Likewise. (mark_completion_tag): Likewise. (copy_name): Likewise. (parse_float): Likewise. (type_stack_reserve): Likewise. * ppc-linux-tdep.c (ppc_stap_parse_special_token): Likewise. (ppu2spu_prev_register): Likewise. * ppc-ravenscar-thread.c (supply_register_at_address): Likewise. * printcmd.c (printf_wide_c_string): Likewise. (printf_pointer): Likewise. * probe.c (parse_probes): Likewise. * python/py-cmd.c (gdbpy_parse_command_name): Likewise. (cmdpy_init): Likewise. * python/py-gdb-readline.c (gdbpy_readline_wrapper): Likewise. * python/py-symtab.c (set_sal): Likewise. * python/py-unwind.c (pyuw_sniffer): Likewise. * python/python.c (python_interactive_command): Likewise. (compute_python_string): Likewise. * ravenscar-thread.c (get_running_thread_id): Likewise. * record-full.c (record_full_exec_insn): Likewise. (record_full_core_open_1): Likewise. * regcache.c (regcache_raw_read_signed): Likewise. (regcache_raw_read_unsigned): Likewise. (regcache_cooked_read_signed): Likewise. (regcache_cooked_read_unsigned): Likewise. * remote-fileio.c (remote_fileio_func_open): Likewise. (remote_fileio_func_rename): Likewise. (remote_fileio_func_unlink): Likewise. (remote_fileio_func_stat): Likewise. (remote_fileio_func_system): Likewise. * remote-mips.c (mips_xfer_memory): Likewise. (mips_load_srec): Likewise. (pmon_end_download): Likewise. * remote.c (new_remote_state): Likewise. (map_regcache_remote_table): Likewise. (remote_register_number_and_offset): Likewise. (init_remote_state): Likewise. (get_memory_packet_size): Likewise. (remote_pass_signals): Likewise. (remote_program_signals): Likewise. (remote_start_remote): Likewise. (remote_check_symbols): Likewise. (remote_query_supported): Likewise. (extended_remote_attach): Likewise. (process_g_packet): Likewise. (store_registers_using_G): Likewise. (putpkt_binary): Likewise. (read_frame): Likewise. (compare_sections_command): Likewise. (remote_hostio_pread): Likewise. (remote_hostio_readlink): Likewise. (remote_file_put): Likewise. (remote_file_get): Likewise. (remote_pid_to_exec_file): Likewise. (_initialize_remote): Likewise. * rs6000-aix-tdep.c (rs6000_aix_ld_info_to_xml): Likewise. (rs6000_aix_core_xfer_shared_libraries_aix): Likewise. * rs6000-tdep.c (ppc_displaced_step_copy_insn): Likewise. (bfd_uses_spe_extensions): Likewise. * s390-linux-tdep.c (s390_displaced_step_copy_insn): Likewise. * score-tdep.c (score7_malloc_and_get_memblock): Likewise. * solib-dsbt.c (decode_loadmap): Likewise. (fetch_loadmap): Likewise. (scan_dyntag): Likewise. (enable_break): Likewise. (dsbt_relocate_main_executable): Likewise. * solib-frv.c (fetch_loadmap): Likewise. (enable_break2): Likewise. (frv_relocate_main_executable): Likewise. * solib-spu.c (spu_relocate_main_executable): Likewise. (spu_bfd_open): Likewise. * solib-svr4.c (lm_info_read): Likewise. (read_program_header): Likewise. (find_program_interpreter): Likewise. (scan_dyntag): Likewise. (elf_locate_base): Likewise. (open_symbol_file_object): Likewise. (read_program_headers_from_bfd): Likewise. (svr4_relocate_main_executable): Likewise. * solib-target.c (solib_target_relocate_section_addresses): Likewise. * solib.c (solib_find_1): Likewise. (exec_file_find): Likewise. (solib_find): Likewise. * source.c (openp): Likewise. (print_source_lines_base): Likewise. (forward_search_command): Likewise. * sparc-ravenscar-thread.c (supply_register_at_address): Likewise. * spu-tdep.c (spu2ppu_prev_register): Likewise. (spu_get_overlay_table): Likewise. * stabsread.c (patch_block_stabs): Likewise. (define_symbol): Likewise. (again:): Likewise. (read_member_functions): Likewise. (read_one_struct_field): Likewise. (read_enum_type): Likewise. (common_block_start): Likewise. * stack.c (read_frame_arg): Likewise. (backtrace_command): Likewise. * stap-probe.c (stap_parse_register_operand): Likewise. * symfile.c (syms_from_objfile_1): Likewise. (find_separate_debug_file): Likewise. (load_command): Likewise. (load_progress): Likewise. (load_section_callback): Likewise. (reread_symbols): Likewise. (add_filename_language): Likewise. (allocate_compunit_symtab): Likewise. (read_target_long_array): Likewise. (simple_read_overlay_table): Likewise. * symtab.c (symbol_set_names): Likewise. (resize_symbol_cache): Likewise. (rbreak_command): Likewise. (completion_list_add_name): Likewise. (completion_list_objc_symbol): Likewise. (add_filename_to_list): Likewise. * target-descriptions.c (maint_print_c_tdesc_cmd): Likewise. * target-memory.c (target_write_memory_blocks): Likewise. * target.c (target_read_string): Likewise. (read_whatever_is_readable): Likewise. (target_read_alloc_1): Likewise. (simple_search_memory): Likewise. (target_fileio_read_alloc_1): Likewise. * tilegx-tdep.c (tilegx_push_dummy_call): Likewise. * top.c (command_line_input): Likewise. * tracefile-tfile.c (tfile_fetch_registers): Likewise. * tracefile.c (tracefile_fetch_registers): Likewise. * tracepoint.c (add_memrange): Likewise. (init_collection_list): Likewise. (add_aexpr): Likewise. (trace_dump_actions): Likewise. (parse_trace_status): Likewise. (parse_tracepoint_definition): Likewise. (parse_tsv_definition): Likewise. (parse_static_tracepoint_marker_definition): Likewise. * tui/tui-file.c (tui_sfileopen): Likewise. (tui_file_adjust_strbuf): Likewise. * tui/tui-io.c (tui_expand_tabs): Likewise. * tui/tui-source.c (tui_set_source_content): Likewise. * typeprint.c (find_global_typedef): Likewise. * ui-file.c (do_ui_file_xstrdup): Likewise. (ui_file_obsavestring): Likewise. (mem_file_write): Likewise. * utils.c (make_hex_string): Likewise. (get_regcomp_error): Likewise. (puts_filtered_tabular): Likewise. (gdb_realpath_keepfile): Likewise. (ldirname): Likewise. (gdb_bfd_errmsg): Likewise. (substitute_path_component): Likewise. * valops.c (search_struct_method): Likewise. (find_oload_champ_namespace_loop): Likewise. * valprint.c (print_decimal_chars): Likewise. (read_string): Likewise. (generic_emit_char): Likewise. * varobj.c (varobj_delete): Likewise. (varobj_value_get_print_value): Likewise. * vaxobsd-tdep.c (vaxobsd_sigtramp_sniffer): Likewise. * windows-tdep.c (display_one_tib): Likewise. * xcoffread.c (read_xcoff_symtab): Likewise. (process_xcoff_symbol): Likewise. (swap_sym): Likewise. (scan_xcoff_symtab): Likewise. (xcoff_initial_scan): Likewise. * xml-support.c (gdb_xml_end_element): Likewise. (xml_process_xincludes): Likewise. (xml_fetch_content_from_file): Likewise. * xml-syscall.c (xml_list_of_syscalls): Likewise. * xstormy16-tdep.c (xstormy16_push_dummy_call): Likewise. gdb/gdbserver/ChangeLog: * ax.c (gdb_parse_agent_expr): Add cast to allocation result assignment. (gdb_unparse_agent_expr): Likewise. * hostio.c (require_data): Likewise. (handle_pread): Likewise. * linux-low.c (disable_regset): Likewise. (fetch_register): Likewise. (store_register): Likewise. (get_dynamic): Likewise. (linux_qxfer_libraries_svr4): Likewise. * mem-break.c (delete_fast_tracepoint_jump): Likewise. (set_fast_tracepoint_jump): Likewise. (uninsert_fast_tracepoint_jumps_at): Likewise. (reinsert_fast_tracepoint_jumps_at): Likewise. (validate_inserted_breakpoint): Likewise. (clone_agent_expr): Likewise. * regcache.c (init_register_cache): Likewise. * remote-utils.c (putpkt_binary_1): Likewise. (decode_M_packet): Likewise. (decode_X_packet): Likewise. (look_up_one_symbol): Likewise. (relocate_instruction): Likewise. (monitor_output): Likewise. * server.c (handle_search_memory): Likewise. (handle_qxfer_exec_file): Likewise. (handle_qxfer_libraries): Likewise. (handle_qxfer): Likewise. (handle_query): Likewise. (handle_v_cont): Likewise. (handle_v_run): Likewise. (captured_main): Likewise. * target.c (write_inferior_memory): Likewise. * thread-db.c (try_thread_db_load_from_dir): Likewise. * tracepoint.c (init_trace_buffer): Likewise. (add_tracepoint_action): Likewise. (add_traceframe): Likewise. (add_traceframe_block): Likewise. (cmd_qtdpsrc): Likewise. (cmd_qtdv): Likewise. (cmd_qtstatus): Likewise. (response_source): Likewise. (response_tsv): Likewise. (cmd_qtnotes): Likewise. (gdb_collect): Likewise. (initialize_tracepoint): Likewise.
2015-09-25 20:08:06 +02:00
return (char *) obstack_copy (obstack, string, *len);
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
}
/* Return 1 if STRING is clearly already in canonical form. This
function is conservative; things which it does not recognize are
assumed to be non-canonical, and the parser will sort them out
afterwards. This speeds up the critical path for alphanumeric
identifiers. */
static int
cp_already_canonical (const char *string)
{
/* Identifier start character [a-zA-Z_]. */
if (!ISIDST (string[0]))
return 0;
/* These are the only two identifiers which canonicalize to other
than themselves or an error: unsigned -> unsigned int and
signed -> int. */
if (string[0] == 'u' && strcmp (&string[1], "nsigned") == 0)
return 0;
else if (string[0] == 's' && strcmp (&string[1], "igned") == 0)
return 0;
/* Identifier character [a-zA-Z0-9_]. */
while (ISIDNUM (string[1]))
string++;
if (string[1] == '\0')
return 1;
else
return 0;
}
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
/* Inspect the given RET_COMP for its type. If it is a typedef,
replace the node with the typedef's tree.
Returns 1 if any typedef substitutions were made, 0 otherwise. */
static int
inspect_type (struct demangle_parse_info *info,
struct demangle_component *ret_comp,
canonicalization_ftype *finder,
void *data)
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
{
char *name;
struct symbol *sym;
/* Copy the symbol's name from RET_COMP and look it up
in the symbol table. */
name = (char *) alloca (ret_comp->u.s_name.len + 1);
memcpy (name, ret_comp->u.s_name.s, ret_comp->u.s_name.len);
name[ret_comp->u.s_name.len] = '\0';
/* Ignore any typedefs that should not be substituted. */
Simple -Wshadow=local fixes This fixes all the straightforward -Wshadow=local warnings in gdb. A few standard approaches are used here: * Renaming an inner (or outer, but more commonly inner) variable; * Lowering a declaration to avoid a clash; * Moving a declaration into a more inner scope to avoid a clash, including the special case of moving a declaration into a loop header. I did not consider any of the changes in this patch to be particularly noteworthy, though of course they should all still be examined. gdb/ChangeLog 2018-10-04 Tom Tromey <tom@tromey.com> * ctf.c (SET_ARRAY_FIELD): Rename "u32". * p-valprint.c (pascal_val_print): Split inner "i" variable. * xtensa-tdep.c (xtensa_push_dummy_call): Declare "i" in loop header. * xstormy16-tdep.c (xstormy16_push_dummy_call): Declare "val" in more inner scope. * xcoffread.c (read_xcoff_symtab): Rename inner "symbol". * varobj.c (varobj_update): Rename inner "newobj", "type_changed". * valprint.c (generic_emit_char): Rename inner "buf". * valops.c (find_overload_match): Rename inner "temp". (value_struct_elt_for_reference): Declare "v" in more inner scope. * v850-tdep.c (v850_push_dummy_call): Rename "len". * unittests/array-view-selftests.c (run_tests): Rename inner "vec". * tui/tui-stack.c (tui_show_frame_info): Declare "i" in loop header. * tracepoint.c (merge_uploaded_trace_state_variables): Declare "tsv" in more inner scope. (print_one_static_tracepoint_marker): Rename inner "tuple_emitter". * tic6x-tdep.c (tic6x_analyze_prologue): Declare "inst" lower. (tic6x_push_dummy_call): Don't redeclare "addr". * target-float.c: Declare "dto" lower. * symtab.c (lookup_local_symbol): Rename inner "sym". (find_pc_sect_line): Rename inner "pc". * stack.c (print_frame): Don't redeclare "gdbarch". (return_command): Rename inner "gdbarch". * s390-tdep.c (s390_prologue_frame_unwind_cache): Renam inner "sp". * rust-lang.c (rust_internal_print_type): Declare "i" in loop header. * rs6000-tdep.c (ppc_process_record): Rename inner "addr". * riscv-tdep.c (riscv_push_dummy_call): Declare "info" in inner scope. * remote.c (remote_target::update_thread_list): Don't redeclare "tp". (remote_target::process_initial_stop_replies): Rename inner "thread". (remote_target::remote_parse_stop_reply): Don't redeclare "p". (remote_target::wait_as): Don't redeclare "stop_reply". (remote_target::get_thread_local_address): Rename inner "result". (remote_target::get_tib_address): Likewise.
2018-04-22 00:16:27 +02:00
for (int i = 0; i < ARRAY_SIZE (ignore_typedefs); ++i)
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
{
if (strcmp (name, ignore_typedefs[i]) == 0)
return 0;
}
sym = NULL;
Rewrite TRY/CATCH This rewrites gdb's TRY/CATCH to plain C++ try/catch. The patch was largely written by script, though one change (to a comment in common-exceptions.h) was reverted by hand. gdb/ChangeLog 2019-04-08 Tom Tromey <tom@tromey.com> * xml-support.c: Use C++ exception handling. * x86-linux-nat.c: Use C++ exception handling. * windows-nat.c: Use C++ exception handling. * varobj.c: Use C++ exception handling. * value.c: Use C++ exception handling. * valprint.c: Use C++ exception handling. * valops.c: Use C++ exception handling. * unittests/parse-connection-spec-selftests.c: Use C++ exception handling. * unittests/cli-utils-selftests.c: Use C++ exception handling. * typeprint.c: Use C++ exception handling. * tui/tui.c: Use C++ exception handling. * tracefile-tfile.c: Use C++ exception handling. * top.c: Use C++ exception handling. * thread.c: Use C++ exception handling. * target.c: Use C++ exception handling. * symmisc.c: Use C++ exception handling. * symfile-mem.c: Use C++ exception handling. * stack.c: Use C++ exception handling. * sparc64-linux-tdep.c: Use C++ exception handling. * solib.c: Use C++ exception handling. * solib-svr4.c: Use C++ exception handling. * solib-spu.c: Use C++ exception handling. * solib-frv.c: Use C++ exception handling. * solib-dsbt.c: Use C++ exception handling. * selftest-arch.c: Use C++ exception handling. * s390-tdep.c: Use C++ exception handling. * rust-lang.c: Use C++ exception handling. * rust-exp.y: Use C++ exception handling. * rs6000-tdep.c: Use C++ exception handling. * rs6000-aix-tdep.c: Use C++ exception handling. * riscv-tdep.c: Use C++ exception handling. * remote.c: Use C++ exception handling. * remote-fileio.c: Use C++ exception handling. * record-full.c: Use C++ exception handling. * record-btrace.c: Use C++ exception handling. * python/python.c: Use C++ exception handling. * python/py-value.c: Use C++ exception handling. * python/py-utils.c: Use C++ exception handling. * python/py-unwind.c: Use C++ exception handling. * python/py-type.c: Use C++ exception handling. * python/py-symbol.c: Use C++ exception handling. * python/py-record.c: Use C++ exception handling. * python/py-record-btrace.c: Use C++ exception handling. * python/py-progspace.c: Use C++ exception handling. * python/py-prettyprint.c: Use C++ exception handling. * python/py-param.c: Use C++ exception handling. * python/py-objfile.c: Use C++ exception handling. * python/py-linetable.c: Use C++ exception handling. * python/py-lazy-string.c: Use C++ exception handling. * python/py-infthread.c: Use C++ exception handling. * python/py-inferior.c: Use C++ exception handling. * python/py-gdb-readline.c: Use C++ exception handling. * python/py-framefilter.c: Use C++ exception handling. * python/py-frame.c: Use C++ exception handling. * python/py-finishbreakpoint.c: Use C++ exception handling. * python/py-cmd.c: Use C++ exception handling. * python/py-breakpoint.c: Use C++ exception handling. * python/py-arch.c: Use C++ exception handling. * printcmd.c: Use C++ exception handling. * ppc-linux-tdep.c: Use C++ exception handling. * parse.c: Use C++ exception handling. * p-valprint.c: Use C++ exception handling. * objc-lang.c: Use C++ exception handling. * mi/mi-main.c: Use C++ exception handling. * mi/mi-interp.c: Use C++ exception handling. * mi/mi-cmd-stack.c: Use C++ exception handling. * mi/mi-cmd-break.c: Use C++ exception handling. * main.c: Use C++ exception handling. * linux-thread-db.c: Use C++ exception handling. * linux-tdep.c: Use C++ exception handling. * linux-nat.c: Use C++ exception handling. * linux-fork.c: Use C++ exception handling. * linespec.c: Use C++ exception handling. * language.c: Use C++ exception handling. * jit.c: Use C++ exception handling. * infrun.c: Use C++ exception handling. * infcmd.c: Use C++ exception handling. * infcall.c: Use C++ exception handling. * inf-loop.c: Use C++ exception handling. * i386-tdep.c: Use C++ exception handling. * i386-linux-tdep.c: Use C++ exception handling. * guile/scm-value.c: Use C++ exception handling. * guile/scm-type.c: Use C++ exception handling. * guile/scm-symtab.c: Use C++ exception handling. * guile/scm-symbol.c: Use C++ exception handling. * guile/scm-pretty-print.c: Use C++ exception handling. * guile/scm-ports.c: Use C++ exception handling. * guile/scm-param.c: Use C++ exception handling. * guile/scm-math.c: Use C++ exception handling. * guile/scm-lazy-string.c: Use C++ exception handling. * guile/scm-frame.c: Use C++ exception handling. * guile/scm-disasm.c: Use C++ exception handling. * guile/scm-cmd.c: Use C++ exception handling. * guile/scm-breakpoint.c: Use C++ exception handling. * guile/scm-block.c: Use C++ exception handling. * guile/guile-internal.h: Use C++ exception handling. * gnu-v3-abi.c: Use C++ exception handling. * gdbtypes.c: Use C++ exception handling. * frame.c: Use C++ exception handling. * frame-unwind.c: Use C++ exception handling. * fbsd-tdep.c: Use C++ exception handling. * f-valprint.c: Use C++ exception handling. * exec.c: Use C++ exception handling. * event-top.c: Use C++ exception handling. * event-loop.c: Use C++ exception handling. * eval.c: Use C++ exception handling. * dwarf2read.c: Use C++ exception handling. * dwarf2loc.c: Use C++ exception handling. * dwarf2-frame.c: Use C++ exception handling. * dwarf2-frame-tailcall.c: Use C++ exception handling. * dwarf-index-write.c: Use C++ exception handling. * dwarf-index-cache.c: Use C++ exception handling. * dtrace-probe.c: Use C++ exception handling. * disasm-selftests.c: Use C++ exception handling. * darwin-nat.c: Use C++ exception handling. * cp-valprint.c: Use C++ exception handling. * cp-support.c: Use C++ exception handling. * cp-abi.c: Use C++ exception handling. * corelow.c: Use C++ exception handling. * completer.c: Use C++ exception handling. * compile/compile-object-run.c: Use C++ exception handling. * compile/compile-object-load.c: Use C++ exception handling. * compile/compile-cplus-symbols.c: Use C++ exception handling. * compile/compile-c-symbols.c: Use C++ exception handling. * common/selftest.c: Use C++ exception handling. * common/new-op.c: Use C++ exception handling. * cli/cli-script.c: Use C++ exception handling. * cli/cli-interp.c: Use C++ exception handling. * cli/cli-cmds.c: Use C++ exception handling. * c-varobj.c: Use C++ exception handling. * btrace.c: Use C++ exception handling. * breakpoint.c: Use C++ exception handling. * break-catch-throw.c: Use C++ exception handling. * arch-utils.c: Use C++ exception handling. * amd64-tdep.c: Use C++ exception handling. * ada-valprint.c: Use C++ exception handling. * ada-typeprint.c: Use C++ exception handling. * ada-lang.c: Use C++ exception handling. * aarch64-tdep.c: Use C++ exception handling. gdb/gdbserver/ChangeLog 2019-04-08 Tom Tromey <tom@tromey.com> * server.c: Use C++ exception handling. * linux-low.c: Use C++ exception handling. * gdbreplay.c: Use C++ exception handling.
2019-04-04 00:02:42 +02:00
try
Split TRY_CATCH into TRY + CATCH This patch splits the TRY_CATCH macro into three, so that we go from this: ~~~ volatile gdb_exception ex; TRY_CATCH (ex, RETURN_MASK_ERROR) { } if (ex.reason < 0) { } ~~~ to this: ~~~ TRY { } CATCH (ex, RETURN_MASK_ERROR) { } END_CATCH ~~~ Thus, we'll be getting rid of the local volatile exception object, and declaring the caught exception in the catch block. This allows reimplementing TRY/CATCH in terms of C++ exceptions when building in C++ mode, while still allowing to build GDB in C mode (using setjmp/longjmp), as a transition step. TBC, after this patch, is it _not_ valid to have code between the TRY and the CATCH blocks, like: TRY { } // some code here. CATCH (ex, RETURN_MASK_ERROR) { } END_CATCH Just like it isn't valid to do that with C++'s native try/catch. By switching to creating the exception object inside the CATCH block scope, we can get rid of all the explicitly allocated volatile exception objects all over the tree, and map the CATCH block more directly to C++'s catch blocks. The majority of the TRY_CATCH -> TRY+CATCH+END_CATCH conversion was done with a script, rerun from scratch at every rebase, no manual editing involved. After the mechanical conversion, a few places needed manual intervention, to fix preexisting cases where we were using the exception object outside of the TRY_CATCH block, and cases where we were using "else" after a 'if (ex.reason) < 0)' [a CATCH after this patch]. The result was folded into this patch so that GDB still builds at each incremental step. END_CATCH is necessary for two reasons: First, because we name the exception object in the CATCH block, which requires creating a scope, which in turn must be closed somewhere. Declaring the exception variable in the initializer field of a for block, like: #define CATCH(EXCEPTION, mask) \ for (struct gdb_exception EXCEPTION; \ exceptions_state_mc_catch (&EXCEPTION, MASK); \ EXCEPTION = exception_none) would avoid needing END_CATCH, but alas, in C mode, we build with C90, which doesn't allow mixed declarations and code. Second, because when TRY/CATCH are wired to real C++ try/catch, as long as we need to handle cleanup chains, even if there's no CATCH block that wants to catch the exception, we need for stop at every frame in the unwind chain and run cleanups, then rethrow. That will be done in END_CATCH. After we require C++, we'll still need TRY/CATCH/END_CATCH until cleanups are completely phased out -- TRY/CATCH in C++ mode will save/restore the current cleanup chain, like in C mode, and END_CATCH catches otherwise uncaugh exceptions, runs cleanups and rethrows, so that C++ cleanups and exceptions can coexist. IMO, this still makes the TRY/CATCH code look a bit more like a newcomer would expect, so IMO worth it even if we weren't considering C++. gdb/ChangeLog. 2015-03-07 Pedro Alves <palves@redhat.com> * common/common-exceptions.c (struct catcher) <exception>: No longer a pointer to volatile exception. Now an exception value. <mask>: Delete field. (exceptions_state_mc_init): Remove all parameters. Adjust. (exceptions_state_mc): No longer pop the catcher here. (exceptions_state_mc_catch): New function. (throw_exception): Adjust. * common/common-exceptions.h (exceptions_state_mc_init): Remove all parameters. (exceptions_state_mc_catch): Declare. (TRY_CATCH): Rename to ... (TRY): ... this. Remove EXCEPTION and MASK parameters. (CATCH, END_CATCH): New. All callers adjusted. gdb/gdbserver/ChangeLog: 2015-03-07 Pedro Alves <palves@redhat.com> Adjust all callers of TRY_CATCH to use TRY/CATCH/END_CATCH instead.
2015-03-07 16:14:14 +01:00
{
Replace the block_found global with explicit data-flow As Pedro suggested on gdb-patches@ (see https://sourceware.org/ml/gdb-patches/2015-05/msg00714.html), this change makes symbol lookup functions return a structure that includes both the symbol found and the block in which it was found. This makes it possible to get rid of the block_found global variable and thus makes block hunting explicit. gdb/ * ada-exp.y (write_object_renaming): Replace struct ada_symbol_info with struct block_symbol. Update field references accordingly. (block_lookup, select_possible_type_sym): Likewise. (find_primitive_type): Likewise. Also update call to ada_lookup_symbol to extract the symbol itself. (write_var_or_type, write_name_assoc): Likewise. * ada-lang.h (struct ada_symbol_info): Remove. (ada_lookup_symbol_list): Replace struct ada_symbol_info with struct block_symbol. (ada_lookup_encoded_symbol, user_select_syms): Likewise. (ada_lookup_symbol): Return struct block_symbol instead of a mere symbol. * ada-lang.c (defns_collected): Replace struct ada_symbol_info with struct block_symbol. (resolve_subexp, ada_resolve_function, sort_choices, user_select_syms, is_nonfunction, add_defn_to_vec, num_defns_collected, defns_collected, symbols_are_identical_enums, remove_extra_symbols, remove_irrelevant_renamings, add_lookup_symbol_list_worker, ada_lookup_symbol_list, ada_iterate_over_symbols, ada_lookup_encoded_symbol, get_var_value): Likewise. (ada_lookup_symbol): Return a block_symbol instead of a mere symbol. Replace struct ada_symbol_info with struct block_symbol. (ada_lookup_symbol_nonlocal): Likewise. (standard_lookup): Make block passing explicit through lookup_symbol_in_language. * ada-tasks.c (get_tcb_types_info): Update the calls to lookup_symbol_in_language to extract the mere symbol out of the returned value. (ada_tasks_inferior_data_sniffer): Likewise. * ax-gdb.c (gen_static_field): Likewise for the call to lookup_symbol. (gen_maybe_namespace_elt): Deal with struct symbol_in_block from lookup functions. (gen_expr): Likewise. * c-exp.y: Likewise. Remove uses of block_found. (lex_one_token, classify_inner_name, c_print_token): Likewise. (classify_name): Likewise. Rename the "sym" local variable to "bsym". * c-valprint.c (print_unpacked_pointer): Likewise. * compile/compile-c-symbols.c (convert_symbol_sym): Promote the "sym" parameter from struct symbol * to struct block_symbol. Use it to remove uses of block_found. Deal with struct symbol_in_block from lookup functions. (gcc_convert_symbol): Likewise. Update the call to convert_symbol_sym. * compile/compile-object-load.c (compile_object_load): Deal with struct symbol_in_block from lookup functions. * cp-namespace.c (cp_lookup_nested_symbol_1, cp_lookup_nested_symbol, cp_lookup_bare_symbol, cp_search_static_and_baseclasses, cp_lookup_symbol_in_namespace, cp_lookup_symbol_via_imports, cp_lookup_symbol_imports_or_template, cp_lookup_symbol_via_all_imports, cp_lookup_symbol_namespace, lookup_namespace_scope, cp_lookup_nonlocal, find_symbol_in_baseclass): Return struct symbol_in_block instead of mere symbols and deal with struct symbol_in_block from lookup functions. * cp-support.c (inspect_type, replace_typedefs, cp_lookup_rtti_type): Deal with struct symbol_in_block from lookup functions. * cp-support.h (cp_lookup_symbol_nonlocal, cp_lookup_symbol_from_namespace, cp_lookup_symbol_imports_or_template, cp_lookup_nested_symbol): Return struct symbol_in_block instead of mere symbols. * d-exp.y (d_type_from_name, d_module_from_name, push_variable, push_module_name): Deal with struct symbol_in_block from lookup functions. Remove uses of block_found. * eval.c (evaluate_subexp_standard): Update call to cp_lookup_symbol_namespace. * f-exp.y: Deal with struct symbol_in_block from lookup functions. Remove uses of block_found. (yylex): Likewise. * gdbtypes.c (lookup_typename, lookup_struct, lookup_union, lookup_enum, lookup_template_type, check_typedef): Deal with struct symbol_in_block from lookup functions. * guile/scm-frame.c (gdbscm_frame_read_var): Likewise. * guile/scm-symbol.c (gdbscm_lookup_symbol): Likewise. (gdbscm_lookup_global_symbol): Likewise. * gnu-v3-abi.c (gnuv3_get_typeid_type): Likewise. * go-exp.y: Likewise. Remove uses of block_found. (package_name_p, classify_packaged_name, classify_name): Likewise. * infrun.c (insert_exception_resume_breakpoint): Likewise. * jv-exp.y (push_variable): Likewise. * jv-lang.c (java_lookup_class, get_java_object_type): Likewise. * language.c (language_bool_type): Likewise. * language.h (struct language_defn): Update la_lookup_symbol_nonlocal to return a struct symbol_in_block rather than a mere symbol. * linespec.c (find_label_symbols): Deal with struct symbol_in_block from lookup functions. * m2-exp.y: Likewise. Remove uses of block_found. (yylex): Likewise. * mi/mi-cmd-stack.c (list_args_or_locals): Likewise. * objc-lang.c (lookup_struct_typedef, find_imps): Likewise. * p-exp.y: Likewise. Remove uses of block_found. (yylex): Likewise. * p-valprint.c (pascal_val_print): Likewise. * parse.c (write_dollar_variable): Likewise. Remove uses of block_found. * parser-defs.h (struct symtoken): Turn the SYM field into a struct symbol_in_block. * printcmd.c (address_info): Deal with struct symbol_in_block from lookup functions. * python/py-frame.c (frapy_read_var): Likewise. * python/py-symbol.c (gdbpy_lookup_symbol, gdbpy_lookup_global_symbol): Likewise. * skip.c (skip_function_command): Likewise. * solib-darwin.c (darwin_lookup_lib_symbol): Return a struct symbol_in_block instead of a mere symbol. * solib-spu.c (spu_lookup_lib_symbol): Likewise. * solib-svr4.c (elf_lookup_lib_symbol): Likewise. * solib.c (solib_global_lookup): Likewise. * solist.h (solib_global_lookup): Likewise. (struct target_so_ops): Update lookup_lib_global_symbol to return a struct symbol_in_block rather than a mere symbol. * source.c (select_source_symtab): Deal with struct symbol_in_block from lookup functions. * stack.c (print_frame_args, iterate_over_block_arg_vars): Likewise. * symfile.c (set_initial_language): Likewise. * symtab.c (SYMBOL_LOOKUP_FAILED): Turn into a struct symbol_in_block. (SYMBOL_LOOKUP_FAILED_P): New predicate as a macro. (struct symbol_cache_slot): Turn the FOUND field into a struct symbol_in_block. (block_found): Remove. (eq_symbol_entry): Update to deal with struct symbol_in_block in cache slots. (symbol_cache_lookup): Return a struct symbol_in_block rather than a mere symbol. (symbol_cache_mark_found): Add a BLOCK parameter to fill appropriately the cache slots. Update callers. (symbol_cache_dump): Update cache slots handling to the type change. (lookup_symbol_in_language, lookup_symbol, lookup_language_this, lookup_symbol_aux, lookup_local_symbol, lookup_symbol_in_objfile, lookup_global_symbol_from_objfile, lookup_symbol_in_objfile_symtabs, lookup_symbol_in_objfile_from_linkage_name, lookup_symbol_via_quick_fns, basic_lookup_symbol_nonlocal, lookup_symbol_in_static_block, lookup_static_symbol, lookup_global_symbol): Return a struct symbol_in_block rather than a mere symbol. Deal with struct symbol_in_block from other lookup functions. Remove uses of block_found. (lookup_symbol_in_block): Remove uses of block_found. (struct global_sym_lookup_data): Turn the RESULT field into a struct symbol_in_block. (lookup_symbol_global_iterator_cb): Update references to the RESULT field. (search_symbols): Deal with struct symbol_in_block from lookup functions. * symtab.h (struct symbol_in_block): New structure. (block_found): Remove. (lookup_symbol_in_language, lookup_symbol, basic_lookup_symbol_nonlocal, lookup_symbol_in_static_block, looku_static_symbol, lookup_global_symbol, lookup_symbol_in_block, lookup_language_this, lookup_global_symbol_from_objfile): Return a struct symbol_in_block rather than just a mere symbol. Update comments to remove mentions of block_found. * valops.c (find_function_in_inferior, value_struct_elt_for_reference, value_maybe_namespace_elt, value_of_this): Deal with struct symbol_in_block from lookup functions. * value.c (value_static_field, value_fn_field): Likewise.
2015-07-21 17:02:15 +02:00
sym = lookup_symbol (name, 0, VAR_DOMAIN, 0).symbol;
Split TRY_CATCH into TRY + CATCH This patch splits the TRY_CATCH macro into three, so that we go from this: ~~~ volatile gdb_exception ex; TRY_CATCH (ex, RETURN_MASK_ERROR) { } if (ex.reason < 0) { } ~~~ to this: ~~~ TRY { } CATCH (ex, RETURN_MASK_ERROR) { } END_CATCH ~~~ Thus, we'll be getting rid of the local volatile exception object, and declaring the caught exception in the catch block. This allows reimplementing TRY/CATCH in terms of C++ exceptions when building in C++ mode, while still allowing to build GDB in C mode (using setjmp/longjmp), as a transition step. TBC, after this patch, is it _not_ valid to have code between the TRY and the CATCH blocks, like: TRY { } // some code here. CATCH (ex, RETURN_MASK_ERROR) { } END_CATCH Just like it isn't valid to do that with C++'s native try/catch. By switching to creating the exception object inside the CATCH block scope, we can get rid of all the explicitly allocated volatile exception objects all over the tree, and map the CATCH block more directly to C++'s catch blocks. The majority of the TRY_CATCH -> TRY+CATCH+END_CATCH conversion was done with a script, rerun from scratch at every rebase, no manual editing involved. After the mechanical conversion, a few places needed manual intervention, to fix preexisting cases where we were using the exception object outside of the TRY_CATCH block, and cases where we were using "else" after a 'if (ex.reason) < 0)' [a CATCH after this patch]. The result was folded into this patch so that GDB still builds at each incremental step. END_CATCH is necessary for two reasons: First, because we name the exception object in the CATCH block, which requires creating a scope, which in turn must be closed somewhere. Declaring the exception variable in the initializer field of a for block, like: #define CATCH(EXCEPTION, mask) \ for (struct gdb_exception EXCEPTION; \ exceptions_state_mc_catch (&EXCEPTION, MASK); \ EXCEPTION = exception_none) would avoid needing END_CATCH, but alas, in C mode, we build with C90, which doesn't allow mixed declarations and code. Second, because when TRY/CATCH are wired to real C++ try/catch, as long as we need to handle cleanup chains, even if there's no CATCH block that wants to catch the exception, we need for stop at every frame in the unwind chain and run cleanups, then rethrow. That will be done in END_CATCH. After we require C++, we'll still need TRY/CATCH/END_CATCH until cleanups are completely phased out -- TRY/CATCH in C++ mode will save/restore the current cleanup chain, like in C mode, and END_CATCH catches otherwise uncaugh exceptions, runs cleanups and rethrows, so that C++ cleanups and exceptions can coexist. IMO, this still makes the TRY/CATCH code look a bit more like a newcomer would expect, so IMO worth it even if we weren't considering C++. gdb/ChangeLog. 2015-03-07 Pedro Alves <palves@redhat.com> * common/common-exceptions.c (struct catcher) <exception>: No longer a pointer to volatile exception. Now an exception value. <mask>: Delete field. (exceptions_state_mc_init): Remove all parameters. Adjust. (exceptions_state_mc): No longer pop the catcher here. (exceptions_state_mc_catch): New function. (throw_exception): Adjust. * common/common-exceptions.h (exceptions_state_mc_init): Remove all parameters. (exceptions_state_mc_catch): Declare. (TRY_CATCH): Rename to ... (TRY): ... this. Remove EXCEPTION and MASK parameters. (CATCH, END_CATCH): New. All callers adjusted. gdb/gdbserver/ChangeLog: 2015-03-07 Pedro Alves <palves@redhat.com> Adjust all callers of TRY_CATCH to use TRY/CATCH/END_CATCH instead.
2015-03-07 16:14:14 +01:00
}
Rename gdb exception types This renames the gdb exception types. The old types were only needed due to the macros in common-exception.h that are now gone. The intermediate layer of gdb_exception_RETURN_MASK_ALL did not seem needed, so this patch removes it entirely. gdb/ChangeLog 2019-04-08 Tom Tromey <tom@tromey.com> * common/common-exceptions.h (gdb_exception_RETURN_MASK_ALL): Remove. (gdb_exception_error): Rename from gdb_exception_RETURN_MASK_ERROR. (gdb_exception_quit): Rename from gdb_exception_RETURN_MASK_QUIT. (gdb_quit_bad_alloc): Update. * aarch64-tdep.c: Update. * ada-lang.c: Update. * ada-typeprint.c: Update. * ada-valprint.c: Update. * amd64-tdep.c: Update. * arch-utils.c: Update. * break-catch-throw.c: Update. * breakpoint.c: Update. * btrace.c: Update. * c-varobj.c: Update. * cli/cli-cmds.c: Update. * cli/cli-interp.c: Update. * cli/cli-script.c: Update. * common/common-exceptions.c: Update. * common/new-op.c: Update. * common/selftest.c: Update. * compile/compile-c-symbols.c: Update. * compile/compile-cplus-symbols.c: Update. * compile/compile-object-load.c: Update. * compile/compile-object-run.c: Update. * completer.c: Update. * corelow.c: Update. * cp-abi.c: Update. * cp-support.c: Update. * cp-valprint.c: Update. * darwin-nat.c: Update. * disasm-selftests.c: Update. * dtrace-probe.c: Update. * dwarf-index-cache.c: Update. * dwarf-index-write.c: Update. * dwarf2-frame-tailcall.c: Update. * dwarf2-frame.c: Update. * dwarf2loc.c: Update. * dwarf2read.c: Update. * eval.c: Update. * event-loop.c: Update. * event-top.c: Update. * exec.c: Update. * f-valprint.c: Update. * fbsd-tdep.c: Update. * frame-unwind.c: Update. * frame.c: Update. * gdbtypes.c: Update. * gnu-v3-abi.c: Update. * guile/guile-internal.h: Update. * guile/scm-block.c: Update. * guile/scm-breakpoint.c: Update. * guile/scm-cmd.c: Update. * guile/scm-disasm.c: Update. * guile/scm-frame.c: Update. * guile/scm-lazy-string.c: Update. * guile/scm-math.c: Update. * guile/scm-param.c: Update. * guile/scm-ports.c: Update. * guile/scm-pretty-print.c: Update. * guile/scm-symbol.c: Update. * guile/scm-symtab.c: Update. * guile/scm-type.c: Update. * guile/scm-value.c: Update. * i386-linux-tdep.c: Update. * i386-tdep.c: Update. * inf-loop.c: Update. * infcall.c: Update. * infcmd.c: Update. * infrun.c: Update. * jit.c: Update. * language.c: Update. * linespec.c: Update. * linux-fork.c: Update. * linux-nat.c: Update. * linux-tdep.c: Update. * linux-thread-db.c: Update. * main.c: Update. * mi/mi-cmd-break.c: Update. * mi/mi-cmd-stack.c: Update. * mi/mi-interp.c: Update. * mi/mi-main.c: Update. * objc-lang.c: Update. * p-valprint.c: Update. * parse.c: Update. * ppc-linux-tdep.c: Update. * printcmd.c: Update. * python/py-arch.c: Update. * python/py-breakpoint.c: Update. * python/py-cmd.c: Update. * python/py-finishbreakpoint.c: Update. * python/py-frame.c: Update. * python/py-framefilter.c: Update. * python/py-gdb-readline.c: Update. * python/py-inferior.c: Update. * python/py-infthread.c: Update. * python/py-lazy-string.c: Update. * python/py-linetable.c: Update. * python/py-objfile.c: Update. * python/py-param.c: Update. * python/py-prettyprint.c: Update. * python/py-progspace.c: Update. * python/py-record-btrace.c: Update. * python/py-record.c: Update. * python/py-symbol.c: Update. * python/py-type.c: Update. * python/py-unwind.c: Update. * python/py-utils.c: Update. * python/py-value.c: Update. * python/python.c: Update. * record-btrace.c: Update. * record-full.c: Update. * remote-fileio.c: Update. * remote.c: Update. * riscv-tdep.c: Update. * rs6000-aix-tdep.c: Update. * rs6000-tdep.c: Update. * rust-exp.y: Update. * rust-lang.c: Update. * s390-tdep.c: Update. * selftest-arch.c: Update. * solib-dsbt.c: Update. * solib-frv.c: Update. * solib-spu.c: Update. * solib-svr4.c: Update. * solib.c: Update. * sparc64-linux-tdep.c: Update. * stack.c: Update. * symfile-mem.c: Update. * symmisc.c: Update. * target.c: Update. * thread.c: Update. * top.c: Update. * tracefile-tfile.c: Update. * tui/tui.c: Update. * typeprint.c: Update. * unittests/cli-utils-selftests.c: Update. * unittests/parse-connection-spec-selftests.c: Update. * valops.c: Update. * valprint.c: Update. * value.c: Update. * varobj.c: Update. * windows-nat.c: Update. * x86-linux-nat.c: Update. * xml-support.c: Update. gdb/gdbserver/ChangeLog 2019-04-08 Tom Tromey <tom@tromey.com> * gdbreplay.c: Update. * linux-low.c: Update. * server.c: Update.
2019-04-03 23:59:07 +02:00
catch (const gdb_exception &except)
Split TRY_CATCH into TRY + CATCH This patch splits the TRY_CATCH macro into three, so that we go from this: ~~~ volatile gdb_exception ex; TRY_CATCH (ex, RETURN_MASK_ERROR) { } if (ex.reason < 0) { } ~~~ to this: ~~~ TRY { } CATCH (ex, RETURN_MASK_ERROR) { } END_CATCH ~~~ Thus, we'll be getting rid of the local volatile exception object, and declaring the caught exception in the catch block. This allows reimplementing TRY/CATCH in terms of C++ exceptions when building in C++ mode, while still allowing to build GDB in C mode (using setjmp/longjmp), as a transition step. TBC, after this patch, is it _not_ valid to have code between the TRY and the CATCH blocks, like: TRY { } // some code here. CATCH (ex, RETURN_MASK_ERROR) { } END_CATCH Just like it isn't valid to do that with C++'s native try/catch. By switching to creating the exception object inside the CATCH block scope, we can get rid of all the explicitly allocated volatile exception objects all over the tree, and map the CATCH block more directly to C++'s catch blocks. The majority of the TRY_CATCH -> TRY+CATCH+END_CATCH conversion was done with a script, rerun from scratch at every rebase, no manual editing involved. After the mechanical conversion, a few places needed manual intervention, to fix preexisting cases where we were using the exception object outside of the TRY_CATCH block, and cases where we were using "else" after a 'if (ex.reason) < 0)' [a CATCH after this patch]. The result was folded into this patch so that GDB still builds at each incremental step. END_CATCH is necessary for two reasons: First, because we name the exception object in the CATCH block, which requires creating a scope, which in turn must be closed somewhere. Declaring the exception variable in the initializer field of a for block, like: #define CATCH(EXCEPTION, mask) \ for (struct gdb_exception EXCEPTION; \ exceptions_state_mc_catch (&EXCEPTION, MASK); \ EXCEPTION = exception_none) would avoid needing END_CATCH, but alas, in C mode, we build with C90, which doesn't allow mixed declarations and code. Second, because when TRY/CATCH are wired to real C++ try/catch, as long as we need to handle cleanup chains, even if there's no CATCH block that wants to catch the exception, we need for stop at every frame in the unwind chain and run cleanups, then rethrow. That will be done in END_CATCH. After we require C++, we'll still need TRY/CATCH/END_CATCH until cleanups are completely phased out -- TRY/CATCH in C++ mode will save/restore the current cleanup chain, like in C mode, and END_CATCH catches otherwise uncaugh exceptions, runs cleanups and rethrows, so that C++ cleanups and exceptions can coexist. IMO, this still makes the TRY/CATCH code look a bit more like a newcomer would expect, so IMO worth it even if we weren't considering C++. gdb/ChangeLog. 2015-03-07 Pedro Alves <palves@redhat.com> * common/common-exceptions.c (struct catcher) <exception>: No longer a pointer to volatile exception. Now an exception value. <mask>: Delete field. (exceptions_state_mc_init): Remove all parameters. Adjust. (exceptions_state_mc): No longer pop the catcher here. (exceptions_state_mc_catch): New function. (throw_exception): Adjust. * common/common-exceptions.h (exceptions_state_mc_init): Remove all parameters. (exceptions_state_mc_catch): Declare. (TRY_CATCH): Rename to ... (TRY): ... this. Remove EXCEPTION and MASK parameters. (CATCH, END_CATCH): New. All callers adjusted. gdb/gdbserver/ChangeLog: 2015-03-07 Pedro Alves <palves@redhat.com> Adjust all callers of TRY_CATCH to use TRY/CATCH/END_CATCH instead.
2015-03-07 16:14:14 +01:00
{
return 0;
}
if (sym != NULL)
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
{
struct type *otype = SYMBOL_TYPE (sym);
if (finder != NULL)
{
const char *new_name = (*finder) (otype, data);
if (new_name != NULL)
{
ret_comp->u.s_name.s = new_name;
ret_comp->u.s_name.len = strlen (new_name);
return 1;
}
return 0;
}
/* If the type is a typedef or namespace alias, replace it. */
if (TYPE_CODE (otype) == TYPE_CODE_TYPEDEF
|| TYPE_CODE (otype) == TYPE_CODE_NAMESPACE)
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
{
long len;
int is_anon;
struct type *type;
std::unique_ptr<demangle_parse_info> i;
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
/* Get the real type of the typedef. */
type = check_typedef (otype);
/* If the symbol name is the same as the original type name,
don't substitute. That would cause infinite recursion in
symbol lookups, as the typedef symbol is often the first
found symbol in the symbol table.
However, this can happen in a number of situations, such as:
If the symbol is a namespace and its type name is no different
than the name we looked up, this symbol is not a namespace
alias and does not need to be substituted.
If the symbol is typedef and its type name is the same
as the symbol's name, e.g., "typedef struct foo foo;". */
if (TYPE_NAME (type) != nullptr
&& strcmp (TYPE_NAME (type), name) == 0)
return 0;
Remove TYPE_TAG_NAME TYPE_TAG_NAME has been an occasional source of confusion and bugs. It seems to me that it is only useful for C and C++ -- but even there, not so much, because at least with DWARF there doesn't seem to be any way to wind up with a type where the name and the tag name are both non-NULL and different. So, this patch removes TYPE_TAG_NAME entirely. This should save a little memory, but more importantly, it simplifies this part of gdb. A few minor test suite adjustments were needed. In some situations the new code does not yield identical output to the old code. gdb/ChangeLog 2018-06-01 Tom Tromey <tom@tromey.com> * valops.c (enum_constant_from_type, value_namespace_elt) (value_maybe_namespace_elt): Update. * valarith.c (find_size_for_pointer_math): Update. * target-descriptions.c (make_gdb_type): Update. * symmisc.c (print_symbol): Update. * stabsread.c (define_symbol, read_type) (complain_about_struct_wipeout, add_undefined_type) (cleanup_undefined_types_1): Update. * rust-lang.c (rust_tuple_type_p, rust_slice_type_p) (rust_range_type_p, val_print_struct, rust_print_struct_def) (rust_internal_print_type, rust_composite_type) (rust_evaluate_funcall, rust_evaluate_subexp) (rust_inclusive_range_type_p): Update. * python/py-type.c (typy_get_tag): Update. * p-typeprint.c (pascal_type_print_base): Update. * mdebugread.c (parse_symbol, parse_type): Update. * m2-typeprint.c (m2_long_set, m2_record_fields, m2_enum): Update. * guile/scm-type.c (gdbscm_type_tag): Update. * go-lang.c (sixg_string_p): Update. * gnu-v3-abi.c (build_gdb_vtable_type, build_std_type_info_type): Update. * gdbtypes.h (struct main_type) <tag_name>: Remove. (TYPE_TAG_NAME): Remove. * gdbtypes.c (type_name_no_tag): Simplify. (check_typedef, check_types_equal, recursive_dump_type) (copy_type_recursive, arch_composite_type): Update. * f-typeprint.c (f_type_print_base): Update. Print "Type" prefix in summary mode when needed. * eval.c (evaluate_funcall): Update. * dwarf2read.c (fixup_go_packaging, read_structure_type) (process_structure_scope, read_enumeration_type) (read_namespace_type, read_module_type, determine_prefix): Update. * cp-support.c (inspect_type): Update. * coffread.c (process_coff_symbol, decode_base_type): Update. * c-varobj.c (c_is_path_expr_parent): Update. * c-typeprint.c (c_type_print_base_struct_union): Update. (c_type_print_base_1): Update. Print struct/class/union/enum in summary when using C language. * ax-gdb.c (gen_struct_ref, gen_namespace_elt) (gen_maybe_namespace_elt): Update. * ada-lang.c (ada_type_name): Simplify. (empty_record, ada_template_to_fixed_record_type_1) (template_to_static_fixed_type) (to_record_with_fixed_variant_part, ada_check_typedef): Update. gdb/testsuite/ChangeLog 2018-06-01 Tom Tromey <tom@tromey.com> * gdb.xml/tdesc-regs.exp (load_description): Update expected results. * gdb.dwarf2/method-ptr.exp: Set language to C++. * gdb.dwarf2/member-ptr-forwardref.exp: Set language to C++. * gdb.cp/typeid.exp (do_typeid_tests): Update type_re. * gdb.base/maint.exp (maint_pass_if): Update.
2018-04-17 21:51:24 +02:00
is_anon = (TYPE_NAME (type) == NULL
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
&& (TYPE_CODE (type) == TYPE_CODE_ENUM
|| TYPE_CODE (type) == TYPE_CODE_STRUCT
|| TYPE_CODE (type) == TYPE_CODE_UNION));
if (is_anon)
{
struct type *last = otype;
/* Find the last typedef for the type. */
while (TYPE_TARGET_TYPE (last) != NULL
&& (TYPE_CODE (TYPE_TARGET_TYPE (last))
== TYPE_CODE_TYPEDEF))
last = TYPE_TARGET_TYPE (last);
/* If there is only one typedef for this anonymous type,
do not substitute it. */
if (type == otype)
return 0;
else
/* Use the last typedef seen as the type for this
anonymous type. */
type = last;
}
Eliminate make_cleanup_ui_file_delete / make ui_file a class hierarchy This patch starts from the desire to eliminate make_cleanup_ui_file_delete, but then goes beyond. It makes ui_file & friends a real C++ class hierarchy, and switches temporary ui_file-like objects to stack-based allocation. - mem_fileopen -> string_file mem_fileopen is replaced with a new string_file class that is treated as a value class created on the stack. This alone eliminates most make_cleanup_ui_file_delete calls, and, simplifies code a whole lot (diffstat shows around 1k loc dropped.) string_file's internal buffer is a std::string, thus the "string" in the name. This simplifies the implementation much, compared to mem_fileopen, which managed growing its internal buffer manually. - ui_file_as_string, ui_file_strdup, ui_file_obsavestring all gone The new string_file class has a string() method that provides direct writable access to the internal std::string buffer. This replaced ui_file_as_string, which forced a copy of the same data the stream had inside. With direct access via a writable reference, we can instead move the string out of the string_stream, avoiding deep string copying. Related, ui_file_xstrdup calls are replaced with xstrdup'ping the stream's string, and ui_file_obsavestring is replaced by obstack_copy0. With all those out of the way, getting rid of the weird ui_file_put mechanism was possible. - New ui_file::printf, ui_file::puts, etc. methods These simplify / clarify client code. I considered splitting client-code changes, like these, e.g.: - stb = mem_fileopen (); - fprintf_unfiltered (stb, "%s%s%s", - _("The valid values are:\n"), - regdesc, - _("The default is \"std\".")); + string_file stb; + stb.printf ("%s%s%s", + _("The valid values are:\n"), + regdesc, + _("The default is \"std\".")); In two steps, with the first step leaving fprintf_unfiltered (etc.) calls in place, and only afterwards do a pass to change all those to call stb.printf etc.. I didn't do that split, because (when I tried), it turned out to be pointless make-work: the first pass would have to touch the fprintf_unfiltered line anyway, to replace "stb" with "&stb". - gdb_fopen replaced with stack-based objects This avoids the need for cleanups or unique_ptr's. I.e., this: struct ui_file *file = gdb_fopen (filename, "w"); if (filename == NULL) perror_with_name (filename); cleanups = make_cleanup_ui_file_delete (file); // use file. do_cleanups (cleanups); is replaced with this: stdio_file file; if (!file.open (filename, "w")) perror_with_name (filename); // use file. - odd contorsions in null_file_write / null_file_fputs around when to call to_fputs / to_write eliminated. - Global null_stream object A few places that were allocating a ui_file in order to print to "nowhere" are adjusted to instead refer to a new 'null_stream' global stream. - TUI's tui_sfileopen eliminated. TUI's ui_file much simplified The TUI's ui_file was serving a dual purpose. It supported being used as string buffer, and supported being backed by a stdio FILE. The string buffer part is gone, replaced by using of string_file. The 'FILE *' support is now much simplified, by making the TUI's ui_file inherit from stdio_file. gdb/ChangeLog: 2017-02-02 Pedro Alves <palves@redhat.com> * ada-lang.c (type_as_string): Use string_file. * ada-valprint.c (ada_print_floating): Use string_file. * ada-varobj.c (ada_varobj_scalar_image) (ada_varobj_get_value_image): Use string_file. * aix-thread.c (aix_thread_extra_thread_info): Use string_file. * arm-tdep.c (_initialize_arm_tdep): Use string_printf. * breakpoint.c (update_inserted_breakpoint_locations) (insert_breakpoint_locations, reattach_breakpoints) (print_breakpoint_location, print_one_detail_ranged_breakpoint) (print_it_watchpoint): Use string_file. (save_breakpoints): Use stdio_file. * c-exp.y (oper): Use string_file. * cli/cli-logging.c (set_logging_redirect): Use ui_file_up and tee_file. (pop_output_files): Use delete. (handle_redirections): Use stdio_file and tee_file. * cli/cli-setshow.c (do_show_command): Use string_file. * compile/compile-c-support.c (c_compute_program): Use string_file. * compile/compile-c-symbols.c (generate_vla_size): Take a 'string_file &' instead of a 'ui_file *'. (generate_c_for_for_one_variable): Take a 'string_file &' instead of a 'ui_file *'. Use string_file. (generate_c_for_variable_locations): Take a 'string_file &' instead of a 'ui_file *'. * compile/compile-internal.h (generate_c_for_for_one_variable): Take a 'string_file &' instead of a 'ui_file *'. * compile/compile-loc2c.c (push, pushf, unary, binary) (print_label, pushf_register_address, pushf_register) (do_compile_dwarf_expr_to_c): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * compile/compile.c (compile_to_object): Use string_file. * compile/compile.h (compile_dwarf_expr_to_c) (compile_dwarf_bounds_to_c): Take a 'string_file &' instead of a 'ui_file *'. * cp-support.c (inspect_type): Use string_file and obstack_copy0. (replace_typedefs_qualified_name): Use string_file and obstack_copy0. * disasm.c (gdb_pretty_print_insn): Use string_file. (gdb_disassembly): Adjust reference the null_stream global. (do_ui_file_delete): Delete. (gdb_insn_length): Use null_stream. * dummy-frame.c (maintenance_print_dummy_frames): Use stdio_file. * dwarf2loc.c (dwarf2_compile_property_to_c) (locexpr_generate_c_location, loclist_generate_c_location): Take a 'string_file &' instead of a 'ui_file *'. * dwarf2loc.h (dwarf2_compile_property_to_c): Likewise. * dwarf2read.c (do_ui_file_peek_last): Delete. (dwarf2_compute_name): Use string_file. * event-top.c (gdb_setup_readline): Use stdio_file. * gdbarch.sh (verify_gdbarch): Use string_file. * gdbtypes.c (safe_parse_type): Use null_stream. * guile/scm-breakpoint.c (gdbscm_breakpoint_commands): Use string_file. * guile/scm-disasm.c (gdbscm_print_insn_from_port): Take a 'string_file *' instead of a 'ui_file *'. (gdbscm_arch_disassemble): Use string_file. * guile/scm-frame.c (frscm_print_frame_smob): Use string_file. * guile/scm-ports.c (class ioscm_file_port): Now a class that inherits from ui_file. (ioscm_file_port_delete, ioscm_file_port_rewind) (ioscm_file_port_put): Delete. (ioscm_file_port_write): Rename to ... (ioscm_file_port::write): ... this. Remove file_port_magic checks. (ioscm_file_port_new): Delete. (ioscm_with_output_to_port_worker): Use ioscm_file_port and ui_file_up. * guile/scm-type.c (tyscm_type_name): Use string_file. * guile/scm-value.c (vlscm_print_value_smob, gdbscm_value_print): Use string_file. * infcmd.c (print_return_value_1): Use string_file. * infrun.c (print_target_wait_results): Use string_file. * language.c (add_language): Use string_file. * location.c (explicit_to_string_internal): Use string_file. * main.c (captured_main_1): Use null_file. * maint.c (maintenance_print_architecture): Use stdio_file. * mi/mi-cmd-stack.c (list_arg_or_local): Use string_file. * mi/mi-common.h (struct mi_interp) <out, err, log, targ, event_channel>: Change type to mi_console_file pointer. * mi/mi-console.c (mi_console_file_fputs, mi_console_file_flush) (mi_console_file_delete): Delete. (struct mi_console_file): Delete. (mi_console_file_magic): Delete. (mi_console_file_new): Delete. (mi_console_file::mi_console_file): New. (mi_console_file_delete): Delete. (mi_console_file_fputs): Delete. (mi_console_file::write): New. (mi_console_raw_packet): Delete. (mi_console_file::flush): New. (mi_console_file_flush): Delete. (mi_console_set_raw): Rename to ... (mi_console_file::set_raw): ... this. * mi/mi-console.h (class mi_console_file): New class. (mi_console_file_new, mi_console_set_raw): Delete. * mi/mi-interp.c (mi_interpreter_init): Use mi_console_file. (mi_set_logging): Use delete and tee_file. Adjust. * mi/mi-main.c (output_register): Use string_file. (mi_cmd_data_evaluate_expression): Use string_file. (mi_cmd_data_read_memory): Use string_file. (mi_cmd_execute, print_variable_or_computed): Use string_file. * mi/mi-out.c (mi_ui_out::main_stream): New. (mi_ui_out::rewind): Use main_stream and string_file. (mi_ui_out::put): Use main_stream and string_file. (mi_ui_out::mi_ui_out): Remove 'stream' parameter. Allocate a 'string_file' instead. (mi_out_new): Don't allocate a mem_fileopen stream here. * mi/mi-out.h (mi_ui_out::mi_ui_out): Remove 'stream' parameter. (mi_ui_out::main_stream): Declare method. * printcmd.c (eval_command): Use string_file. * psymtab.c (maintenance_print_psymbols): Use stdio_file. * python/py-arch.c (archpy_disassemble): Use string_file. * python/py-breakpoint.c (bppy_get_commands): Use string_file. * python/py-frame.c (frapy_str): Use string_file. * python/py-framefilter.c (py_print_type, py_print_single_arg): Use string_file. * python/py-type.c (typy_str): Use string_file. * python/py-unwind.c (unwind_infopy_str): Use string_file. * python/py-value.c (valpy_str): Use string_file. * record-btrace.c (btrace_insn_history): Use string_file. * regcache.c (regcache_print): Use stdio_file. * reggroups.c (maintenance_print_reggroups): Use stdio_file. * remote.c (escape_buffer): Use string_file. * rust-lang.c (rust_get_disr_info): Use string_file. * serial.c (serial_open_ops_1): Use stdio_file. (do_serial_close): Use delete. * stack.c (print_frame_arg): Use string_file. (print_frame_args): Remove local mem_fileopen stream, not used. (print_frame): Use string_file. * symmisc.c (maintenance_print_symbols): Use stdio_file. * symtab.h (struct symbol_computed_ops) <generate_c_location>: Take a 'string_file *' instead of a 'ui_file *'. * top.c (new_ui): Use stdio_file and stderr_file. (free_ui): Use delete. (execute_command_to_string): Use string_file. (quit_confirm): Use string_file. * tracepoint.c (collection_list::append_exp): Use string_file. * tui/tui-disasm.c (tui_disassemble): Use string_file. * tui/tui-file.c: Don't include "ui-file.h". (enum streamtype, struct tui_stream): Delete. (tui_file_new, tui_file_delete, tui_fileopen, tui_sfileopen) (tui_file_isatty, tui_file_rewind, tui_file_put): Delete. (tui_file::tui_file): New method. (tui_file_fputs): Delete. (tui_file_get_strbuf): Delete. (tui_file::puts): New method. (tui_file_adjust_strbuf): Delete. (tui_file_flush): Delete. (tui_file::flush): New method. * tui/tui-file.h: Tweak intro comment. Include ui-file.h. (tui_fileopen, tui_sfileopen, tui_file_get_strbuf) (tui_file_adjust_strbuf): Delete declarations. (class tui_file): New class. * tui/tui-io.c (tui_initialize_io): Use tui_file. * tui/tui-regs.c (tui_restore_gdbout): Use delete. (tui_register_format): Use string_stream. * tui/tui-stack.c (tui_make_status_line): Use string_file. (tui_get_function_from_frame): Use string_file. * typeprint.c (type_to_string): Use string_file. * ui-file.c (struct ui_file, ui_file_magic, ui_file_new): Delete. (null_stream): New global. (ui_file_delete): Delete. (ui_file::ui_file): New. (null_file_isatty): Delete. (ui_file::~ui_file): New. (null_file_rewind): Delete. (ui_file::printf): New. (null_file_put): Delete. (null_file_flush): Delete. (ui_file::putstr): New. (null_file_write): Delete. (ui_file::putstrn): New. (null_file_read): Delete. (ui_file::putc): New. (null_file_fputs): Delete. (null_file_write_async_safe): Delete. (ui_file::vprintf): New. (null_file_delete): Delete. (null_file::write): New. (null_file_fseek): Delete. (null_file::puts): New. (ui_file_data): Delete. (null_file::write_async_safe): New. (gdb_flush, ui_file_isatty): Adjust. (ui_file_put, ui_file_rewind): Delete. (ui_file_write): Adjust. (ui_file_write_for_put): Delete. (ui_file_write_async_safe, ui_file_read): Adjust. (ui_file_fseek): Delete. (fputs_unfiltered): Adjust. (set_ui_file_flush, set_ui_file_isatty, set_ui_file_rewind) (set_ui_file_put, set_ui_file_write, set_ui_file_write_async_safe) (set_ui_file_read, set_ui_file_fputs, set_ui_file_fseek) (set_ui_file_data): Delete. (string_file::~string_file, string_file::write) (struct accumulated_ui_file, do_ui_file_xstrdup, ui_file_xstrdup) (do_ui_file_as_string, ui_file_as_string): Delete. (do_ui_file_obsavestring, ui_file_obsavestring): Delete. (struct mem_file): Delete. (mem_file_new): Delete. (stdio_file::stdio_file): New. (mem_file_delete): Delete. (stdio_file::stdio_file): New. (mem_fileopen): Delete. (stdio_file::~stdio_file): New. (mem_file_rewind): Delete. (stdio_file::set_stream): New. (mem_file_put): Delete. (stdio_file::open): New. (mem_file_write): Delete. (stdio_file_magic, struct stdio_file): Delete. (stdio_file_new, stdio_file_delete, stdio_file_flush): Delete. (stdio_file::flush): New. (stdio_file_read): Rename to ... (stdio_file::read): ... this. Adjust. (stdio_file_write): Rename to ... (stdio_file::write): ... this. Adjust. (stdio_file_write_async_safe): Rename to ... (stdio_file::write_async_safe) ... this. Adjust. (stdio_file_fputs): Rename to ... (stdio_file::puts) ... this. Adjust. (stdio_file_isatty): Delete. (stdio_file_fseek): Delete. (stdio_file::isatty): New. (stderr_file_write): Rename to ... (stderr_file::write) ... this. Adjust. (stderr_file_fputs): Rename to ... (stderr_file::puts) ... this. Adjust. (stderr_fileopen, stdio_fileopen, gdb_fopen): Delete. (stderr_file::stderr_file): New. (tee_file_magic): Delete. (struct tee_file): Delete. (tee_file::tee_file): New. (tee_file_new): Delete. (tee_file::~tee_file): New. (tee_file_delete): Delete. (tee_file_flush): Rename to ... (tee_file::flush): ... this. Adjust. (tee_file_write): Rename to ... (tee_file::write): ... this. Adjust. (tee_file::write_async_safe): New. (tee_file_fputs): Rename to ... (tee_file::puts): ... this. Adjust. (tee_file_isatty): Rename to ... (tee_file::isatty): ... this. Adjust. * ui-file.h (struct obstack, struct ui_file): Don't forward-declare. (ui_file_new, ui_file_flush_ftype, set_ui_file_flush) (ui_file_write_ftype) (set_ui_file_write, ui_file_fputs_ftype, set_ui_file_fputs) (ui_file_write_async_safe_ftype, set_ui_file_write_async_safe) (ui_file_read_ftype, set_ui_file_read, ui_file_isatty_ftype) (set_ui_file_isatty, ui_file_rewind_ftype, set_ui_file_rewind) (ui_file_put_method_ftype, ui_file_put_ftype, set_ui_file_put) (ui_file_delete_ftype, set_ui_file_data, ui_file_fseek_ftype) (set_ui_file_fseek): Delete. (ui_file_data, ui_file_delete, ui_file_rewind) (struct ui_file): New. (ui_file_up): New. (class null_file): New. (null_stream): Declare. (ui_file_write_for_put, ui_file_put): Delete. (ui_file_xstrdup, ui_file_as_string, ui_file_obsavestring): Delete. (ui_file_fseek, mem_fileopen, stdio_fileopen, stderr_fileopen) (gdb_fopen, tee_file_new): Delete. (struct string_file): New. (struct stdio_file): New. (stdio_file_up): New. (struct stderr_file): New. (class tee_file): New. * ui-out.c (ui_out::field_stream): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * ui-out.h (class ui_out) <field_stream>: Likewise. * utils.c (do_ui_file_delete, make_cleanup_ui_file_delete) (null_stream): Delete. (error_stream): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * utils.h (struct ui_file): Delete forward declaration.. (make_cleanup_ui_file_delete, null_stream): Delete declarations. (error_stream): Take a 'string_file &' instead of a 'ui_file *'. * varobj.c (varobj_value_get_print_value): Use string_file. * xtensa-tdep.c (xtensa_verify_config): Use string_file. * gdbarch.c: Regenerate.
2017-02-02 12:11:47 +01:00
string_file buf;
Rewrite TRY/CATCH This rewrites gdb's TRY/CATCH to plain C++ try/catch. The patch was largely written by script, though one change (to a comment in common-exceptions.h) was reverted by hand. gdb/ChangeLog 2019-04-08 Tom Tromey <tom@tromey.com> * xml-support.c: Use C++ exception handling. * x86-linux-nat.c: Use C++ exception handling. * windows-nat.c: Use C++ exception handling. * varobj.c: Use C++ exception handling. * value.c: Use C++ exception handling. * valprint.c: Use C++ exception handling. * valops.c: Use C++ exception handling. * unittests/parse-connection-spec-selftests.c: Use C++ exception handling. * unittests/cli-utils-selftests.c: Use C++ exception handling. * typeprint.c: Use C++ exception handling. * tui/tui.c: Use C++ exception handling. * tracefile-tfile.c: Use C++ exception handling. * top.c: Use C++ exception handling. * thread.c: Use C++ exception handling. * target.c: Use C++ exception handling. * symmisc.c: Use C++ exception handling. * symfile-mem.c: Use C++ exception handling. * stack.c: Use C++ exception handling. * sparc64-linux-tdep.c: Use C++ exception handling. * solib.c: Use C++ exception handling. * solib-svr4.c: Use C++ exception handling. * solib-spu.c: Use C++ exception handling. * solib-frv.c: Use C++ exception handling. * solib-dsbt.c: Use C++ exception handling. * selftest-arch.c: Use C++ exception handling. * s390-tdep.c: Use C++ exception handling. * rust-lang.c: Use C++ exception handling. * rust-exp.y: Use C++ exception handling. * rs6000-tdep.c: Use C++ exception handling. * rs6000-aix-tdep.c: Use C++ exception handling. * riscv-tdep.c: Use C++ exception handling. * remote.c: Use C++ exception handling. * remote-fileio.c: Use C++ exception handling. * record-full.c: Use C++ exception handling. * record-btrace.c: Use C++ exception handling. * python/python.c: Use C++ exception handling. * python/py-value.c: Use C++ exception handling. * python/py-utils.c: Use C++ exception handling. * python/py-unwind.c: Use C++ exception handling. * python/py-type.c: Use C++ exception handling. * python/py-symbol.c: Use C++ exception handling. * python/py-record.c: Use C++ exception handling. * python/py-record-btrace.c: Use C++ exception handling. * python/py-progspace.c: Use C++ exception handling. * python/py-prettyprint.c: Use C++ exception handling. * python/py-param.c: Use C++ exception handling. * python/py-objfile.c: Use C++ exception handling. * python/py-linetable.c: Use C++ exception handling. * python/py-lazy-string.c: Use C++ exception handling. * python/py-infthread.c: Use C++ exception handling. * python/py-inferior.c: Use C++ exception handling. * python/py-gdb-readline.c: Use C++ exception handling. * python/py-framefilter.c: Use C++ exception handling. * python/py-frame.c: Use C++ exception handling. * python/py-finishbreakpoint.c: Use C++ exception handling. * python/py-cmd.c: Use C++ exception handling. * python/py-breakpoint.c: Use C++ exception handling. * python/py-arch.c: Use C++ exception handling. * printcmd.c: Use C++ exception handling. * ppc-linux-tdep.c: Use C++ exception handling. * parse.c: Use C++ exception handling. * p-valprint.c: Use C++ exception handling. * objc-lang.c: Use C++ exception handling. * mi/mi-main.c: Use C++ exception handling. * mi/mi-interp.c: Use C++ exception handling. * mi/mi-cmd-stack.c: Use C++ exception handling. * mi/mi-cmd-break.c: Use C++ exception handling. * main.c: Use C++ exception handling. * linux-thread-db.c: Use C++ exception handling. * linux-tdep.c: Use C++ exception handling. * linux-nat.c: Use C++ exception handling. * linux-fork.c: Use C++ exception handling. * linespec.c: Use C++ exception handling. * language.c: Use C++ exception handling. * jit.c: Use C++ exception handling. * infrun.c: Use C++ exception handling. * infcmd.c: Use C++ exception handling. * infcall.c: Use C++ exception handling. * inf-loop.c: Use C++ exception handling. * i386-tdep.c: Use C++ exception handling. * i386-linux-tdep.c: Use C++ exception handling. * guile/scm-value.c: Use C++ exception handling. * guile/scm-type.c: Use C++ exception handling. * guile/scm-symtab.c: Use C++ exception handling. * guile/scm-symbol.c: Use C++ exception handling. * guile/scm-pretty-print.c: Use C++ exception handling. * guile/scm-ports.c: Use C++ exception handling. * guile/scm-param.c: Use C++ exception handling. * guile/scm-math.c: Use C++ exception handling. * guile/scm-lazy-string.c: Use C++ exception handling. * guile/scm-frame.c: Use C++ exception handling. * guile/scm-disasm.c: Use C++ exception handling. * guile/scm-cmd.c: Use C++ exception handling. * guile/scm-breakpoint.c: Use C++ exception handling. * guile/scm-block.c: Use C++ exception handling. * guile/guile-internal.h: Use C++ exception handling. * gnu-v3-abi.c: Use C++ exception handling. * gdbtypes.c: Use C++ exception handling. * frame.c: Use C++ exception handling. * frame-unwind.c: Use C++ exception handling. * fbsd-tdep.c: Use C++ exception handling. * f-valprint.c: Use C++ exception handling. * exec.c: Use C++ exception handling. * event-top.c: Use C++ exception handling. * event-loop.c: Use C++ exception handling. * eval.c: Use C++ exception handling. * dwarf2read.c: Use C++ exception handling. * dwarf2loc.c: Use C++ exception handling. * dwarf2-frame.c: Use C++ exception handling. * dwarf2-frame-tailcall.c: Use C++ exception handling. * dwarf-index-write.c: Use C++ exception handling. * dwarf-index-cache.c: Use C++ exception handling. * dtrace-probe.c: Use C++ exception handling. * disasm-selftests.c: Use C++ exception handling. * darwin-nat.c: Use C++ exception handling. * cp-valprint.c: Use C++ exception handling. * cp-support.c: Use C++ exception handling. * cp-abi.c: Use C++ exception handling. * corelow.c: Use C++ exception handling. * completer.c: Use C++ exception handling. * compile/compile-object-run.c: Use C++ exception handling. * compile/compile-object-load.c: Use C++ exception handling. * compile/compile-cplus-symbols.c: Use C++ exception handling. * compile/compile-c-symbols.c: Use C++ exception handling. * common/selftest.c: Use C++ exception handling. * common/new-op.c: Use C++ exception handling. * cli/cli-script.c: Use C++ exception handling. * cli/cli-interp.c: Use C++ exception handling. * cli/cli-cmds.c: Use C++ exception handling. * c-varobj.c: Use C++ exception handling. * btrace.c: Use C++ exception handling. * breakpoint.c: Use C++ exception handling. * break-catch-throw.c: Use C++ exception handling. * arch-utils.c: Use C++ exception handling. * amd64-tdep.c: Use C++ exception handling. * ada-valprint.c: Use C++ exception handling. * ada-typeprint.c: Use C++ exception handling. * ada-lang.c: Use C++ exception handling. * aarch64-tdep.c: Use C++ exception handling. gdb/gdbserver/ChangeLog 2019-04-08 Tom Tromey <tom@tromey.com> * server.c: Use C++ exception handling. * linux-low.c: Use C++ exception handling. * gdbreplay.c: Use C++ exception handling.
2019-04-04 00:02:42 +02:00
try
Eliminate make_cleanup_ui_file_delete / make ui_file a class hierarchy This patch starts from the desire to eliminate make_cleanup_ui_file_delete, but then goes beyond. It makes ui_file & friends a real C++ class hierarchy, and switches temporary ui_file-like objects to stack-based allocation. - mem_fileopen -> string_file mem_fileopen is replaced with a new string_file class that is treated as a value class created on the stack. This alone eliminates most make_cleanup_ui_file_delete calls, and, simplifies code a whole lot (diffstat shows around 1k loc dropped.) string_file's internal buffer is a std::string, thus the "string" in the name. This simplifies the implementation much, compared to mem_fileopen, which managed growing its internal buffer manually. - ui_file_as_string, ui_file_strdup, ui_file_obsavestring all gone The new string_file class has a string() method that provides direct writable access to the internal std::string buffer. This replaced ui_file_as_string, which forced a copy of the same data the stream had inside. With direct access via a writable reference, we can instead move the string out of the string_stream, avoiding deep string copying. Related, ui_file_xstrdup calls are replaced with xstrdup'ping the stream's string, and ui_file_obsavestring is replaced by obstack_copy0. With all those out of the way, getting rid of the weird ui_file_put mechanism was possible. - New ui_file::printf, ui_file::puts, etc. methods These simplify / clarify client code. I considered splitting client-code changes, like these, e.g.: - stb = mem_fileopen (); - fprintf_unfiltered (stb, "%s%s%s", - _("The valid values are:\n"), - regdesc, - _("The default is \"std\".")); + string_file stb; + stb.printf ("%s%s%s", + _("The valid values are:\n"), + regdesc, + _("The default is \"std\".")); In two steps, with the first step leaving fprintf_unfiltered (etc.) calls in place, and only afterwards do a pass to change all those to call stb.printf etc.. I didn't do that split, because (when I tried), it turned out to be pointless make-work: the first pass would have to touch the fprintf_unfiltered line anyway, to replace "stb" with "&stb". - gdb_fopen replaced with stack-based objects This avoids the need for cleanups or unique_ptr's. I.e., this: struct ui_file *file = gdb_fopen (filename, "w"); if (filename == NULL) perror_with_name (filename); cleanups = make_cleanup_ui_file_delete (file); // use file. do_cleanups (cleanups); is replaced with this: stdio_file file; if (!file.open (filename, "w")) perror_with_name (filename); // use file. - odd contorsions in null_file_write / null_file_fputs around when to call to_fputs / to_write eliminated. - Global null_stream object A few places that were allocating a ui_file in order to print to "nowhere" are adjusted to instead refer to a new 'null_stream' global stream. - TUI's tui_sfileopen eliminated. TUI's ui_file much simplified The TUI's ui_file was serving a dual purpose. It supported being used as string buffer, and supported being backed by a stdio FILE. The string buffer part is gone, replaced by using of string_file. The 'FILE *' support is now much simplified, by making the TUI's ui_file inherit from stdio_file. gdb/ChangeLog: 2017-02-02 Pedro Alves <palves@redhat.com> * ada-lang.c (type_as_string): Use string_file. * ada-valprint.c (ada_print_floating): Use string_file. * ada-varobj.c (ada_varobj_scalar_image) (ada_varobj_get_value_image): Use string_file. * aix-thread.c (aix_thread_extra_thread_info): Use string_file. * arm-tdep.c (_initialize_arm_tdep): Use string_printf. * breakpoint.c (update_inserted_breakpoint_locations) (insert_breakpoint_locations, reattach_breakpoints) (print_breakpoint_location, print_one_detail_ranged_breakpoint) (print_it_watchpoint): Use string_file. (save_breakpoints): Use stdio_file. * c-exp.y (oper): Use string_file. * cli/cli-logging.c (set_logging_redirect): Use ui_file_up and tee_file. (pop_output_files): Use delete. (handle_redirections): Use stdio_file and tee_file. * cli/cli-setshow.c (do_show_command): Use string_file. * compile/compile-c-support.c (c_compute_program): Use string_file. * compile/compile-c-symbols.c (generate_vla_size): Take a 'string_file &' instead of a 'ui_file *'. (generate_c_for_for_one_variable): Take a 'string_file &' instead of a 'ui_file *'. Use string_file. (generate_c_for_variable_locations): Take a 'string_file &' instead of a 'ui_file *'. * compile/compile-internal.h (generate_c_for_for_one_variable): Take a 'string_file &' instead of a 'ui_file *'. * compile/compile-loc2c.c (push, pushf, unary, binary) (print_label, pushf_register_address, pushf_register) (do_compile_dwarf_expr_to_c): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * compile/compile.c (compile_to_object): Use string_file. * compile/compile.h (compile_dwarf_expr_to_c) (compile_dwarf_bounds_to_c): Take a 'string_file &' instead of a 'ui_file *'. * cp-support.c (inspect_type): Use string_file and obstack_copy0. (replace_typedefs_qualified_name): Use string_file and obstack_copy0. * disasm.c (gdb_pretty_print_insn): Use string_file. (gdb_disassembly): Adjust reference the null_stream global. (do_ui_file_delete): Delete. (gdb_insn_length): Use null_stream. * dummy-frame.c (maintenance_print_dummy_frames): Use stdio_file. * dwarf2loc.c (dwarf2_compile_property_to_c) (locexpr_generate_c_location, loclist_generate_c_location): Take a 'string_file &' instead of a 'ui_file *'. * dwarf2loc.h (dwarf2_compile_property_to_c): Likewise. * dwarf2read.c (do_ui_file_peek_last): Delete. (dwarf2_compute_name): Use string_file. * event-top.c (gdb_setup_readline): Use stdio_file. * gdbarch.sh (verify_gdbarch): Use string_file. * gdbtypes.c (safe_parse_type): Use null_stream. * guile/scm-breakpoint.c (gdbscm_breakpoint_commands): Use string_file. * guile/scm-disasm.c (gdbscm_print_insn_from_port): Take a 'string_file *' instead of a 'ui_file *'. (gdbscm_arch_disassemble): Use string_file. * guile/scm-frame.c (frscm_print_frame_smob): Use string_file. * guile/scm-ports.c (class ioscm_file_port): Now a class that inherits from ui_file. (ioscm_file_port_delete, ioscm_file_port_rewind) (ioscm_file_port_put): Delete. (ioscm_file_port_write): Rename to ... (ioscm_file_port::write): ... this. Remove file_port_magic checks. (ioscm_file_port_new): Delete. (ioscm_with_output_to_port_worker): Use ioscm_file_port and ui_file_up. * guile/scm-type.c (tyscm_type_name): Use string_file. * guile/scm-value.c (vlscm_print_value_smob, gdbscm_value_print): Use string_file. * infcmd.c (print_return_value_1): Use string_file. * infrun.c (print_target_wait_results): Use string_file. * language.c (add_language): Use string_file. * location.c (explicit_to_string_internal): Use string_file. * main.c (captured_main_1): Use null_file. * maint.c (maintenance_print_architecture): Use stdio_file. * mi/mi-cmd-stack.c (list_arg_or_local): Use string_file. * mi/mi-common.h (struct mi_interp) <out, err, log, targ, event_channel>: Change type to mi_console_file pointer. * mi/mi-console.c (mi_console_file_fputs, mi_console_file_flush) (mi_console_file_delete): Delete. (struct mi_console_file): Delete. (mi_console_file_magic): Delete. (mi_console_file_new): Delete. (mi_console_file::mi_console_file): New. (mi_console_file_delete): Delete. (mi_console_file_fputs): Delete. (mi_console_file::write): New. (mi_console_raw_packet): Delete. (mi_console_file::flush): New. (mi_console_file_flush): Delete. (mi_console_set_raw): Rename to ... (mi_console_file::set_raw): ... this. * mi/mi-console.h (class mi_console_file): New class. (mi_console_file_new, mi_console_set_raw): Delete. * mi/mi-interp.c (mi_interpreter_init): Use mi_console_file. (mi_set_logging): Use delete and tee_file. Adjust. * mi/mi-main.c (output_register): Use string_file. (mi_cmd_data_evaluate_expression): Use string_file. (mi_cmd_data_read_memory): Use string_file. (mi_cmd_execute, print_variable_or_computed): Use string_file. * mi/mi-out.c (mi_ui_out::main_stream): New. (mi_ui_out::rewind): Use main_stream and string_file. (mi_ui_out::put): Use main_stream and string_file. (mi_ui_out::mi_ui_out): Remove 'stream' parameter. Allocate a 'string_file' instead. (mi_out_new): Don't allocate a mem_fileopen stream here. * mi/mi-out.h (mi_ui_out::mi_ui_out): Remove 'stream' parameter. (mi_ui_out::main_stream): Declare method. * printcmd.c (eval_command): Use string_file. * psymtab.c (maintenance_print_psymbols): Use stdio_file. * python/py-arch.c (archpy_disassemble): Use string_file. * python/py-breakpoint.c (bppy_get_commands): Use string_file. * python/py-frame.c (frapy_str): Use string_file. * python/py-framefilter.c (py_print_type, py_print_single_arg): Use string_file. * python/py-type.c (typy_str): Use string_file. * python/py-unwind.c (unwind_infopy_str): Use string_file. * python/py-value.c (valpy_str): Use string_file. * record-btrace.c (btrace_insn_history): Use string_file. * regcache.c (regcache_print): Use stdio_file. * reggroups.c (maintenance_print_reggroups): Use stdio_file. * remote.c (escape_buffer): Use string_file. * rust-lang.c (rust_get_disr_info): Use string_file. * serial.c (serial_open_ops_1): Use stdio_file. (do_serial_close): Use delete. * stack.c (print_frame_arg): Use string_file. (print_frame_args): Remove local mem_fileopen stream, not used. (print_frame): Use string_file. * symmisc.c (maintenance_print_symbols): Use stdio_file. * symtab.h (struct symbol_computed_ops) <generate_c_location>: Take a 'string_file *' instead of a 'ui_file *'. * top.c (new_ui): Use stdio_file and stderr_file. (free_ui): Use delete. (execute_command_to_string): Use string_file. (quit_confirm): Use string_file. * tracepoint.c (collection_list::append_exp): Use string_file. * tui/tui-disasm.c (tui_disassemble): Use string_file. * tui/tui-file.c: Don't include "ui-file.h". (enum streamtype, struct tui_stream): Delete. (tui_file_new, tui_file_delete, tui_fileopen, tui_sfileopen) (tui_file_isatty, tui_file_rewind, tui_file_put): Delete. (tui_file::tui_file): New method. (tui_file_fputs): Delete. (tui_file_get_strbuf): Delete. (tui_file::puts): New method. (tui_file_adjust_strbuf): Delete. (tui_file_flush): Delete. (tui_file::flush): New method. * tui/tui-file.h: Tweak intro comment. Include ui-file.h. (tui_fileopen, tui_sfileopen, tui_file_get_strbuf) (tui_file_adjust_strbuf): Delete declarations. (class tui_file): New class. * tui/tui-io.c (tui_initialize_io): Use tui_file. * tui/tui-regs.c (tui_restore_gdbout): Use delete. (tui_register_format): Use string_stream. * tui/tui-stack.c (tui_make_status_line): Use string_file. (tui_get_function_from_frame): Use string_file. * typeprint.c (type_to_string): Use string_file. * ui-file.c (struct ui_file, ui_file_magic, ui_file_new): Delete. (null_stream): New global. (ui_file_delete): Delete. (ui_file::ui_file): New. (null_file_isatty): Delete. (ui_file::~ui_file): New. (null_file_rewind): Delete. (ui_file::printf): New. (null_file_put): Delete. (null_file_flush): Delete. (ui_file::putstr): New. (null_file_write): Delete. (ui_file::putstrn): New. (null_file_read): Delete. (ui_file::putc): New. (null_file_fputs): Delete. (null_file_write_async_safe): Delete. (ui_file::vprintf): New. (null_file_delete): Delete. (null_file::write): New. (null_file_fseek): Delete. (null_file::puts): New. (ui_file_data): Delete. (null_file::write_async_safe): New. (gdb_flush, ui_file_isatty): Adjust. (ui_file_put, ui_file_rewind): Delete. (ui_file_write): Adjust. (ui_file_write_for_put): Delete. (ui_file_write_async_safe, ui_file_read): Adjust. (ui_file_fseek): Delete. (fputs_unfiltered): Adjust. (set_ui_file_flush, set_ui_file_isatty, set_ui_file_rewind) (set_ui_file_put, set_ui_file_write, set_ui_file_write_async_safe) (set_ui_file_read, set_ui_file_fputs, set_ui_file_fseek) (set_ui_file_data): Delete. (string_file::~string_file, string_file::write) (struct accumulated_ui_file, do_ui_file_xstrdup, ui_file_xstrdup) (do_ui_file_as_string, ui_file_as_string): Delete. (do_ui_file_obsavestring, ui_file_obsavestring): Delete. (struct mem_file): Delete. (mem_file_new): Delete. (stdio_file::stdio_file): New. (mem_file_delete): Delete. (stdio_file::stdio_file): New. (mem_fileopen): Delete. (stdio_file::~stdio_file): New. (mem_file_rewind): Delete. (stdio_file::set_stream): New. (mem_file_put): Delete. (stdio_file::open): New. (mem_file_write): Delete. (stdio_file_magic, struct stdio_file): Delete. (stdio_file_new, stdio_file_delete, stdio_file_flush): Delete. (stdio_file::flush): New. (stdio_file_read): Rename to ... (stdio_file::read): ... this. Adjust. (stdio_file_write): Rename to ... (stdio_file::write): ... this. Adjust. (stdio_file_write_async_safe): Rename to ... (stdio_file::write_async_safe) ... this. Adjust. (stdio_file_fputs): Rename to ... (stdio_file::puts) ... this. Adjust. (stdio_file_isatty): Delete. (stdio_file_fseek): Delete. (stdio_file::isatty): New. (stderr_file_write): Rename to ... (stderr_file::write) ... this. Adjust. (stderr_file_fputs): Rename to ... (stderr_file::puts) ... this. Adjust. (stderr_fileopen, stdio_fileopen, gdb_fopen): Delete. (stderr_file::stderr_file): New. (tee_file_magic): Delete. (struct tee_file): Delete. (tee_file::tee_file): New. (tee_file_new): Delete. (tee_file::~tee_file): New. (tee_file_delete): Delete. (tee_file_flush): Rename to ... (tee_file::flush): ... this. Adjust. (tee_file_write): Rename to ... (tee_file::write): ... this. Adjust. (tee_file::write_async_safe): New. (tee_file_fputs): Rename to ... (tee_file::puts): ... this. Adjust. (tee_file_isatty): Rename to ... (tee_file::isatty): ... this. Adjust. * ui-file.h (struct obstack, struct ui_file): Don't forward-declare. (ui_file_new, ui_file_flush_ftype, set_ui_file_flush) (ui_file_write_ftype) (set_ui_file_write, ui_file_fputs_ftype, set_ui_file_fputs) (ui_file_write_async_safe_ftype, set_ui_file_write_async_safe) (ui_file_read_ftype, set_ui_file_read, ui_file_isatty_ftype) (set_ui_file_isatty, ui_file_rewind_ftype, set_ui_file_rewind) (ui_file_put_method_ftype, ui_file_put_ftype, set_ui_file_put) (ui_file_delete_ftype, set_ui_file_data, ui_file_fseek_ftype) (set_ui_file_fseek): Delete. (ui_file_data, ui_file_delete, ui_file_rewind) (struct ui_file): New. (ui_file_up): New. (class null_file): New. (null_stream): Declare. (ui_file_write_for_put, ui_file_put): Delete. (ui_file_xstrdup, ui_file_as_string, ui_file_obsavestring): Delete. (ui_file_fseek, mem_fileopen, stdio_fileopen, stderr_fileopen) (gdb_fopen, tee_file_new): Delete. (struct string_file): New. (struct stdio_file): New. (stdio_file_up): New. (struct stderr_file): New. (class tee_file): New. * ui-out.c (ui_out::field_stream): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * ui-out.h (class ui_out) <field_stream>: Likewise. * utils.c (do_ui_file_delete, make_cleanup_ui_file_delete) (null_stream): Delete. (error_stream): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * utils.h (struct ui_file): Delete forward declaration.. (make_cleanup_ui_file_delete, null_stream): Delete declarations. (error_stream): Take a 'string_file &' instead of a 'ui_file *'. * varobj.c (varobj_value_get_print_value): Use string_file. * xtensa-tdep.c (xtensa_verify_config): Use string_file. * gdbarch.c: Regenerate.
2017-02-02 12:11:47 +01:00
{
type_print (type, "", &buf, -1);
}
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
/* If type_print threw an exception, there is little point
in continuing, so just bow out gracefully. */
Rename gdb exception types This renames the gdb exception types. The old types were only needed due to the macros in common-exception.h that are now gone. The intermediate layer of gdb_exception_RETURN_MASK_ALL did not seem needed, so this patch removes it entirely. gdb/ChangeLog 2019-04-08 Tom Tromey <tom@tromey.com> * common/common-exceptions.h (gdb_exception_RETURN_MASK_ALL): Remove. (gdb_exception_error): Rename from gdb_exception_RETURN_MASK_ERROR. (gdb_exception_quit): Rename from gdb_exception_RETURN_MASK_QUIT. (gdb_quit_bad_alloc): Update. * aarch64-tdep.c: Update. * ada-lang.c: Update. * ada-typeprint.c: Update. * ada-valprint.c: Update. * amd64-tdep.c: Update. * arch-utils.c: Update. * break-catch-throw.c: Update. * breakpoint.c: Update. * btrace.c: Update. * c-varobj.c: Update. * cli/cli-cmds.c: Update. * cli/cli-interp.c: Update. * cli/cli-script.c: Update. * common/common-exceptions.c: Update. * common/new-op.c: Update. * common/selftest.c: Update. * compile/compile-c-symbols.c: Update. * compile/compile-cplus-symbols.c: Update. * compile/compile-object-load.c: Update. * compile/compile-object-run.c: Update. * completer.c: Update. * corelow.c: Update. * cp-abi.c: Update. * cp-support.c: Update. * cp-valprint.c: Update. * darwin-nat.c: Update. * disasm-selftests.c: Update. * dtrace-probe.c: Update. * dwarf-index-cache.c: Update. * dwarf-index-write.c: Update. * dwarf2-frame-tailcall.c: Update. * dwarf2-frame.c: Update. * dwarf2loc.c: Update. * dwarf2read.c: Update. * eval.c: Update. * event-loop.c: Update. * event-top.c: Update. * exec.c: Update. * f-valprint.c: Update. * fbsd-tdep.c: Update. * frame-unwind.c: Update. * frame.c: Update. * gdbtypes.c: Update. * gnu-v3-abi.c: Update. * guile/guile-internal.h: Update. * guile/scm-block.c: Update. * guile/scm-breakpoint.c: Update. * guile/scm-cmd.c: Update. * guile/scm-disasm.c: Update. * guile/scm-frame.c: Update. * guile/scm-lazy-string.c: Update. * guile/scm-math.c: Update. * guile/scm-param.c: Update. * guile/scm-ports.c: Update. * guile/scm-pretty-print.c: Update. * guile/scm-symbol.c: Update. * guile/scm-symtab.c: Update. * guile/scm-type.c: Update. * guile/scm-value.c: Update. * i386-linux-tdep.c: Update. * i386-tdep.c: Update. * inf-loop.c: Update. * infcall.c: Update. * infcmd.c: Update. * infrun.c: Update. * jit.c: Update. * language.c: Update. * linespec.c: Update. * linux-fork.c: Update. * linux-nat.c: Update. * linux-tdep.c: Update. * linux-thread-db.c: Update. * main.c: Update. * mi/mi-cmd-break.c: Update. * mi/mi-cmd-stack.c: Update. * mi/mi-interp.c: Update. * mi/mi-main.c: Update. * objc-lang.c: Update. * p-valprint.c: Update. * parse.c: Update. * ppc-linux-tdep.c: Update. * printcmd.c: Update. * python/py-arch.c: Update. * python/py-breakpoint.c: Update. * python/py-cmd.c: Update. * python/py-finishbreakpoint.c: Update. * python/py-frame.c: Update. * python/py-framefilter.c: Update. * python/py-gdb-readline.c: Update. * python/py-inferior.c: Update. * python/py-infthread.c: Update. * python/py-lazy-string.c: Update. * python/py-linetable.c: Update. * python/py-objfile.c: Update. * python/py-param.c: Update. * python/py-prettyprint.c: Update. * python/py-progspace.c: Update. * python/py-record-btrace.c: Update. * python/py-record.c: Update. * python/py-symbol.c: Update. * python/py-type.c: Update. * python/py-unwind.c: Update. * python/py-utils.c: Update. * python/py-value.c: Update. * python/python.c: Update. * record-btrace.c: Update. * record-full.c: Update. * remote-fileio.c: Update. * remote.c: Update. * riscv-tdep.c: Update. * rs6000-aix-tdep.c: Update. * rs6000-tdep.c: Update. * rust-exp.y: Update. * rust-lang.c: Update. * s390-tdep.c: Update. * selftest-arch.c: Update. * solib-dsbt.c: Update. * solib-frv.c: Update. * solib-spu.c: Update. * solib-svr4.c: Update. * solib.c: Update. * sparc64-linux-tdep.c: Update. * stack.c: Update. * symfile-mem.c: Update. * symmisc.c: Update. * target.c: Update. * thread.c: Update. * top.c: Update. * tracefile-tfile.c: Update. * tui/tui.c: Update. * typeprint.c: Update. * unittests/cli-utils-selftests.c: Update. * unittests/parse-connection-spec-selftests.c: Update. * valops.c: Update. * valprint.c: Update. * value.c: Update. * varobj.c: Update. * windows-nat.c: Update. * x86-linux-nat.c: Update. * xml-support.c: Update. gdb/gdbserver/ChangeLog 2019-04-08 Tom Tromey <tom@tromey.com> * gdbreplay.c: Update. * linux-low.c: Update. * server.c: Update.
2019-04-03 23:59:07 +02:00
catch (const gdb_exception_error &except)
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
{
return 0;
}
Eliminate make_cleanup_ui_file_delete / make ui_file a class hierarchy This patch starts from the desire to eliminate make_cleanup_ui_file_delete, but then goes beyond. It makes ui_file & friends a real C++ class hierarchy, and switches temporary ui_file-like objects to stack-based allocation. - mem_fileopen -> string_file mem_fileopen is replaced with a new string_file class that is treated as a value class created on the stack. This alone eliminates most make_cleanup_ui_file_delete calls, and, simplifies code a whole lot (diffstat shows around 1k loc dropped.) string_file's internal buffer is a std::string, thus the "string" in the name. This simplifies the implementation much, compared to mem_fileopen, which managed growing its internal buffer manually. - ui_file_as_string, ui_file_strdup, ui_file_obsavestring all gone The new string_file class has a string() method that provides direct writable access to the internal std::string buffer. This replaced ui_file_as_string, which forced a copy of the same data the stream had inside. With direct access via a writable reference, we can instead move the string out of the string_stream, avoiding deep string copying. Related, ui_file_xstrdup calls are replaced with xstrdup'ping the stream's string, and ui_file_obsavestring is replaced by obstack_copy0. With all those out of the way, getting rid of the weird ui_file_put mechanism was possible. - New ui_file::printf, ui_file::puts, etc. methods These simplify / clarify client code. I considered splitting client-code changes, like these, e.g.: - stb = mem_fileopen (); - fprintf_unfiltered (stb, "%s%s%s", - _("The valid values are:\n"), - regdesc, - _("The default is \"std\".")); + string_file stb; + stb.printf ("%s%s%s", + _("The valid values are:\n"), + regdesc, + _("The default is \"std\".")); In two steps, with the first step leaving fprintf_unfiltered (etc.) calls in place, and only afterwards do a pass to change all those to call stb.printf etc.. I didn't do that split, because (when I tried), it turned out to be pointless make-work: the first pass would have to touch the fprintf_unfiltered line anyway, to replace "stb" with "&stb". - gdb_fopen replaced with stack-based objects This avoids the need for cleanups or unique_ptr's. I.e., this: struct ui_file *file = gdb_fopen (filename, "w"); if (filename == NULL) perror_with_name (filename); cleanups = make_cleanup_ui_file_delete (file); // use file. do_cleanups (cleanups); is replaced with this: stdio_file file; if (!file.open (filename, "w")) perror_with_name (filename); // use file. - odd contorsions in null_file_write / null_file_fputs around when to call to_fputs / to_write eliminated. - Global null_stream object A few places that were allocating a ui_file in order to print to "nowhere" are adjusted to instead refer to a new 'null_stream' global stream. - TUI's tui_sfileopen eliminated. TUI's ui_file much simplified The TUI's ui_file was serving a dual purpose. It supported being used as string buffer, and supported being backed by a stdio FILE. The string buffer part is gone, replaced by using of string_file. The 'FILE *' support is now much simplified, by making the TUI's ui_file inherit from stdio_file. gdb/ChangeLog: 2017-02-02 Pedro Alves <palves@redhat.com> * ada-lang.c (type_as_string): Use string_file. * ada-valprint.c (ada_print_floating): Use string_file. * ada-varobj.c (ada_varobj_scalar_image) (ada_varobj_get_value_image): Use string_file. * aix-thread.c (aix_thread_extra_thread_info): Use string_file. * arm-tdep.c (_initialize_arm_tdep): Use string_printf. * breakpoint.c (update_inserted_breakpoint_locations) (insert_breakpoint_locations, reattach_breakpoints) (print_breakpoint_location, print_one_detail_ranged_breakpoint) (print_it_watchpoint): Use string_file. (save_breakpoints): Use stdio_file. * c-exp.y (oper): Use string_file. * cli/cli-logging.c (set_logging_redirect): Use ui_file_up and tee_file. (pop_output_files): Use delete. (handle_redirections): Use stdio_file and tee_file. * cli/cli-setshow.c (do_show_command): Use string_file. * compile/compile-c-support.c (c_compute_program): Use string_file. * compile/compile-c-symbols.c (generate_vla_size): Take a 'string_file &' instead of a 'ui_file *'. (generate_c_for_for_one_variable): Take a 'string_file &' instead of a 'ui_file *'. Use string_file. (generate_c_for_variable_locations): Take a 'string_file &' instead of a 'ui_file *'. * compile/compile-internal.h (generate_c_for_for_one_variable): Take a 'string_file &' instead of a 'ui_file *'. * compile/compile-loc2c.c (push, pushf, unary, binary) (print_label, pushf_register_address, pushf_register) (do_compile_dwarf_expr_to_c): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * compile/compile.c (compile_to_object): Use string_file. * compile/compile.h (compile_dwarf_expr_to_c) (compile_dwarf_bounds_to_c): Take a 'string_file &' instead of a 'ui_file *'. * cp-support.c (inspect_type): Use string_file and obstack_copy0. (replace_typedefs_qualified_name): Use string_file and obstack_copy0. * disasm.c (gdb_pretty_print_insn): Use string_file. (gdb_disassembly): Adjust reference the null_stream global. (do_ui_file_delete): Delete. (gdb_insn_length): Use null_stream. * dummy-frame.c (maintenance_print_dummy_frames): Use stdio_file. * dwarf2loc.c (dwarf2_compile_property_to_c) (locexpr_generate_c_location, loclist_generate_c_location): Take a 'string_file &' instead of a 'ui_file *'. * dwarf2loc.h (dwarf2_compile_property_to_c): Likewise. * dwarf2read.c (do_ui_file_peek_last): Delete. (dwarf2_compute_name): Use string_file. * event-top.c (gdb_setup_readline): Use stdio_file. * gdbarch.sh (verify_gdbarch): Use string_file. * gdbtypes.c (safe_parse_type): Use null_stream. * guile/scm-breakpoint.c (gdbscm_breakpoint_commands): Use string_file. * guile/scm-disasm.c (gdbscm_print_insn_from_port): Take a 'string_file *' instead of a 'ui_file *'. (gdbscm_arch_disassemble): Use string_file. * guile/scm-frame.c (frscm_print_frame_smob): Use string_file. * guile/scm-ports.c (class ioscm_file_port): Now a class that inherits from ui_file. (ioscm_file_port_delete, ioscm_file_port_rewind) (ioscm_file_port_put): Delete. (ioscm_file_port_write): Rename to ... (ioscm_file_port::write): ... this. Remove file_port_magic checks. (ioscm_file_port_new): Delete. (ioscm_with_output_to_port_worker): Use ioscm_file_port and ui_file_up. * guile/scm-type.c (tyscm_type_name): Use string_file. * guile/scm-value.c (vlscm_print_value_smob, gdbscm_value_print): Use string_file. * infcmd.c (print_return_value_1): Use string_file. * infrun.c (print_target_wait_results): Use string_file. * language.c (add_language): Use string_file. * location.c (explicit_to_string_internal): Use string_file. * main.c (captured_main_1): Use null_file. * maint.c (maintenance_print_architecture): Use stdio_file. * mi/mi-cmd-stack.c (list_arg_or_local): Use string_file. * mi/mi-common.h (struct mi_interp) <out, err, log, targ, event_channel>: Change type to mi_console_file pointer. * mi/mi-console.c (mi_console_file_fputs, mi_console_file_flush) (mi_console_file_delete): Delete. (struct mi_console_file): Delete. (mi_console_file_magic): Delete. (mi_console_file_new): Delete. (mi_console_file::mi_console_file): New. (mi_console_file_delete): Delete. (mi_console_file_fputs): Delete. (mi_console_file::write): New. (mi_console_raw_packet): Delete. (mi_console_file::flush): New. (mi_console_file_flush): Delete. (mi_console_set_raw): Rename to ... (mi_console_file::set_raw): ... this. * mi/mi-console.h (class mi_console_file): New class. (mi_console_file_new, mi_console_set_raw): Delete. * mi/mi-interp.c (mi_interpreter_init): Use mi_console_file. (mi_set_logging): Use delete and tee_file. Adjust. * mi/mi-main.c (output_register): Use string_file. (mi_cmd_data_evaluate_expression): Use string_file. (mi_cmd_data_read_memory): Use string_file. (mi_cmd_execute, print_variable_or_computed): Use string_file. * mi/mi-out.c (mi_ui_out::main_stream): New. (mi_ui_out::rewind): Use main_stream and string_file. (mi_ui_out::put): Use main_stream and string_file. (mi_ui_out::mi_ui_out): Remove 'stream' parameter. Allocate a 'string_file' instead. (mi_out_new): Don't allocate a mem_fileopen stream here. * mi/mi-out.h (mi_ui_out::mi_ui_out): Remove 'stream' parameter. (mi_ui_out::main_stream): Declare method. * printcmd.c (eval_command): Use string_file. * psymtab.c (maintenance_print_psymbols): Use stdio_file. * python/py-arch.c (archpy_disassemble): Use string_file. * python/py-breakpoint.c (bppy_get_commands): Use string_file. * python/py-frame.c (frapy_str): Use string_file. * python/py-framefilter.c (py_print_type, py_print_single_arg): Use string_file. * python/py-type.c (typy_str): Use string_file. * python/py-unwind.c (unwind_infopy_str): Use string_file. * python/py-value.c (valpy_str): Use string_file. * record-btrace.c (btrace_insn_history): Use string_file. * regcache.c (regcache_print): Use stdio_file. * reggroups.c (maintenance_print_reggroups): Use stdio_file. * remote.c (escape_buffer): Use string_file. * rust-lang.c (rust_get_disr_info): Use string_file. * serial.c (serial_open_ops_1): Use stdio_file. (do_serial_close): Use delete. * stack.c (print_frame_arg): Use string_file. (print_frame_args): Remove local mem_fileopen stream, not used. (print_frame): Use string_file. * symmisc.c (maintenance_print_symbols): Use stdio_file. * symtab.h (struct symbol_computed_ops) <generate_c_location>: Take a 'string_file *' instead of a 'ui_file *'. * top.c (new_ui): Use stdio_file and stderr_file. (free_ui): Use delete. (execute_command_to_string): Use string_file. (quit_confirm): Use string_file. * tracepoint.c (collection_list::append_exp): Use string_file. * tui/tui-disasm.c (tui_disassemble): Use string_file. * tui/tui-file.c: Don't include "ui-file.h". (enum streamtype, struct tui_stream): Delete. (tui_file_new, tui_file_delete, tui_fileopen, tui_sfileopen) (tui_file_isatty, tui_file_rewind, tui_file_put): Delete. (tui_file::tui_file): New method. (tui_file_fputs): Delete. (tui_file_get_strbuf): Delete. (tui_file::puts): New method. (tui_file_adjust_strbuf): Delete. (tui_file_flush): Delete. (tui_file::flush): New method. * tui/tui-file.h: Tweak intro comment. Include ui-file.h. (tui_fileopen, tui_sfileopen, tui_file_get_strbuf) (tui_file_adjust_strbuf): Delete declarations. (class tui_file): New class. * tui/tui-io.c (tui_initialize_io): Use tui_file. * tui/tui-regs.c (tui_restore_gdbout): Use delete. (tui_register_format): Use string_stream. * tui/tui-stack.c (tui_make_status_line): Use string_file. (tui_get_function_from_frame): Use string_file. * typeprint.c (type_to_string): Use string_file. * ui-file.c (struct ui_file, ui_file_magic, ui_file_new): Delete. (null_stream): New global. (ui_file_delete): Delete. (ui_file::ui_file): New. (null_file_isatty): Delete. (ui_file::~ui_file): New. (null_file_rewind): Delete. (ui_file::printf): New. (null_file_put): Delete. (null_file_flush): Delete. (ui_file::putstr): New. (null_file_write): Delete. (ui_file::putstrn): New. (null_file_read): Delete. (ui_file::putc): New. (null_file_fputs): Delete. (null_file_write_async_safe): Delete. (ui_file::vprintf): New. (null_file_delete): Delete. (null_file::write): New. (null_file_fseek): Delete. (null_file::puts): New. (ui_file_data): Delete. (null_file::write_async_safe): New. (gdb_flush, ui_file_isatty): Adjust. (ui_file_put, ui_file_rewind): Delete. (ui_file_write): Adjust. (ui_file_write_for_put): Delete. (ui_file_write_async_safe, ui_file_read): Adjust. (ui_file_fseek): Delete. (fputs_unfiltered): Adjust. (set_ui_file_flush, set_ui_file_isatty, set_ui_file_rewind) (set_ui_file_put, set_ui_file_write, set_ui_file_write_async_safe) (set_ui_file_read, set_ui_file_fputs, set_ui_file_fseek) (set_ui_file_data): Delete. (string_file::~string_file, string_file::write) (struct accumulated_ui_file, do_ui_file_xstrdup, ui_file_xstrdup) (do_ui_file_as_string, ui_file_as_string): Delete. (do_ui_file_obsavestring, ui_file_obsavestring): Delete. (struct mem_file): Delete. (mem_file_new): Delete. (stdio_file::stdio_file): New. (mem_file_delete): Delete. (stdio_file::stdio_file): New. (mem_fileopen): Delete. (stdio_file::~stdio_file): New. (mem_file_rewind): Delete. (stdio_file::set_stream): New. (mem_file_put): Delete. (stdio_file::open): New. (mem_file_write): Delete. (stdio_file_magic, struct stdio_file): Delete. (stdio_file_new, stdio_file_delete, stdio_file_flush): Delete. (stdio_file::flush): New. (stdio_file_read): Rename to ... (stdio_file::read): ... this. Adjust. (stdio_file_write): Rename to ... (stdio_file::write): ... this. Adjust. (stdio_file_write_async_safe): Rename to ... (stdio_file::write_async_safe) ... this. Adjust. (stdio_file_fputs): Rename to ... (stdio_file::puts) ... this. Adjust. (stdio_file_isatty): Delete. (stdio_file_fseek): Delete. (stdio_file::isatty): New. (stderr_file_write): Rename to ... (stderr_file::write) ... this. Adjust. (stderr_file_fputs): Rename to ... (stderr_file::puts) ... this. Adjust. (stderr_fileopen, stdio_fileopen, gdb_fopen): Delete. (stderr_file::stderr_file): New. (tee_file_magic): Delete. (struct tee_file): Delete. (tee_file::tee_file): New. (tee_file_new): Delete. (tee_file::~tee_file): New. (tee_file_delete): Delete. (tee_file_flush): Rename to ... (tee_file::flush): ... this. Adjust. (tee_file_write): Rename to ... (tee_file::write): ... this. Adjust. (tee_file::write_async_safe): New. (tee_file_fputs): Rename to ... (tee_file::puts): ... this. Adjust. (tee_file_isatty): Rename to ... (tee_file::isatty): ... this. Adjust. * ui-file.h (struct obstack, struct ui_file): Don't forward-declare. (ui_file_new, ui_file_flush_ftype, set_ui_file_flush) (ui_file_write_ftype) (set_ui_file_write, ui_file_fputs_ftype, set_ui_file_fputs) (ui_file_write_async_safe_ftype, set_ui_file_write_async_safe) (ui_file_read_ftype, set_ui_file_read, ui_file_isatty_ftype) (set_ui_file_isatty, ui_file_rewind_ftype, set_ui_file_rewind) (ui_file_put_method_ftype, ui_file_put_ftype, set_ui_file_put) (ui_file_delete_ftype, set_ui_file_data, ui_file_fseek_ftype) (set_ui_file_fseek): Delete. (ui_file_data, ui_file_delete, ui_file_rewind) (struct ui_file): New. (ui_file_up): New. (class null_file): New. (null_stream): Declare. (ui_file_write_for_put, ui_file_put): Delete. (ui_file_xstrdup, ui_file_as_string, ui_file_obsavestring): Delete. (ui_file_fseek, mem_fileopen, stdio_fileopen, stderr_fileopen) (gdb_fopen, tee_file_new): Delete. (struct string_file): New. (struct stdio_file): New. (stdio_file_up): New. (struct stderr_file): New. (class tee_file): New. * ui-out.c (ui_out::field_stream): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * ui-out.h (class ui_out) <field_stream>: Likewise. * utils.c (do_ui_file_delete, make_cleanup_ui_file_delete) (null_stream): Delete. (error_stream): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * utils.h (struct ui_file): Delete forward declaration.. (make_cleanup_ui_file_delete, null_stream): Delete declarations. (error_stream): Take a 'string_file &' instead of a 'ui_file *'. * varobj.c (varobj_value_get_print_value): Use string_file. * xtensa-tdep.c (xtensa_verify_config): Use string_file. * gdbarch.c: Regenerate.
2017-02-02 12:11:47 +01:00
len = buf.size ();
name = obstack_strdup (&info->obstack, buf.string ());
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
/* Turn the result into a new tree. Note that this
tree will contain pointers into NAME, so NAME cannot
be free'd until all typedef conversion is done and
the final result is converted into a string. */
i = cp_demangled_name_to_comp (name, NULL);
if (i != NULL)
{
/* Merge the two trees. */
cp_merge_demangle_parse_infos (info, ret_comp, i.get ());
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
/* Replace any newly introduced typedefs -- but not
if the type is anonymous (that would lead to infinite
looping). */
if (!is_anon)
replace_typedefs (info, ret_comp, finder, data);
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
}
else
{
/* This shouldn't happen unless the type printer has
output something that the name parser cannot grok.
Nonetheless, an ounce of prevention...
Canonicalize the name again, and store it in the
current node (RET_COMP). */
Use ui_file_as_string throughout more This replaces most of the remaining ui_file_xstrdup calls with ui_file_as_string calls. Whenever a call was replaced, that led to a cascade of other necessary adjustments throughout, to make the code use std::string instead of raw pointers. And then whenever I added a std::string as member of a struct, I needed to adjust allocation/destruction of said struct to use new/delete instead of xmalloc/xfree. The stopping point was once gdb built again. These doesn't seem to be a way to reasonably split this out further. Maybe-not-obvious changes: - demangle_for_lookup returns a cleanup today. To get rid of that, and avoid unnecessary string dupping/copying, this introduces a demangle_result_storage type that the caller instantiates and passes to demangle_for_lookup. - Many methods returned a "char *" to indicate that the caller owns the memory and must free it. Those are switched to return a std::string instead. Methods that return a "view" into some internal string return a "const char *" instead. I.e., we only copy/allocate when necessary. gdb/ChangeLog: 2016-11-08 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_name_for_lookup, type_as_string): Use and return std::string. (type_as_string_and_cleanup): Delete. (ada_lookup_struct_elt_type): Use type_as_string. * ada-lang.h (ada_name_for_lookup): Now returns std::string. * ada-varobj.c (ada_varobj_scalar_image): Return a std::string. (ada_varobj_describe_child): Make 'child_name' and 'child_path_expr' parameters std::string pointers. (ada_varobj_describe_struct_child, ada_varobj_describe_ptr_child): Likewise, and use string_printf. (ada_varobj_describe_simple_array_child) (ada_varobj_describe_child): Likewise. (ada_varobj_get_name_of_child, ada_varobj_get_path_expr_of_child) (ada_varobj_get_value_image) (ada_varobj_get_value_of_array_variable) (ada_varobj_get_value_of_variable, ada_name_of_variable) (ada_name_of_child, ada_path_expr_of_child) (ada_value_of_variable): Now returns std::string. Use string_printf. (ada_value_of_child): Adjust. * break-catch-throw.c (check_status_exception_catchpoint): Adjust to use std::string. * breakpoint.c (watch_command_1): Adjust to use std::string. * c-lang.c (c_get_string): Adjust to use std::string. * c-typeprint.c (print_name_maybe_canonical): Use std::string. * c-varobj.c (varobj_is_anonymous_child): Use ==/!= std::string operators. (c_name_of_variable): Now returns a std::string. (c_describe_child): The 'cname' and 'cfull_expression' output parameters are now std::string pointers. Adjust. (c_name_of_child, c_path_expr_of_child, c_value_of_variable) (cplus_number_of_children): Adjust to use std::string and string_printf. (cplus_name_of_variable): Now returns a std::string. (cplus_describe_child): The 'cname' and 'cfull_expression' output parameters are now std::string pointers. Adjust. (cplus_name_of_child, cplus_path_expr_of_child) (cplus_value_of_variable): Now returns a std::string. * cp-abi.c (cplus_typename_from_type_info): Return std::string. * cp-abi.h (cplus_typename_from_type_info): Return std::string. (struct cp_abi_ops) <get_typename_from_type_info>: Return std::string. * cp-support.c (inspect_type): Use std::string. (cp_canonicalize_string_full, cp_canonicalize_string_no_typedefs) (cp_canonicalize_string): Return std::string and adjust. * cp-support.h (cp_canonicalize_string) (cp_canonicalize_string_no_typedefs, cp_canonicalize_string_full): Return std::string. * dbxread.c (read_dbx_symtab): Use std::string. * dwarf2read.c (dwarf2_canonicalize_name): Adjust to use std::string. * gdbcmd.h (lookup_struct_elt_type): Adjust to use std::string. * gnu-v3-abi.c (gnuv3_get_typeid): Use std::string. (gnuv3_get_typename_from_type_info): Return a std::string and adjust. (gnuv3_get_type_from_type_info): Adjust to use std::string. * guile/guile.c (gdbscm_execute_gdb_command): Adjust to use std::string. * infcmd.c (print_return_value_1): Adjust to use std::string. * linespec.c (find_linespec_symbols): Adjust to demangle_for_lookup API change. Use std::string. * mi/mi-cmd-var.c (print_varobj, mi_cmd_var_set_format) (mi_cmd_var_info_type, mi_cmd_var_info_path_expression) (mi_cmd_var_info_expression, mi_cmd_var_evaluate_expression) (mi_cmd_var_assign, varobj_update_one): Adjust to use std::string. * minsyms.c (lookup_minimal_symbol): Use std::string. * python/py-varobj.c (py_varobj_iter_next): Use new instead of XNEW. vitem->name is a std::string now, adjust. * rust-exp.y (convert_ast_to_type, convert_name): Adjust to use std::string. * stabsread.c (define_symbol): Adjust to use std::string. * symtab.c (demangle_for_lookup): Now returns 'const char *'. Add a demangle_result_storage parameter. Use it for storage. (lookup_symbol_in_language) (lookup_symbol_in_objfile_from_linkage_name): Adjust to new demangle_for_lookup API. * symtab.h (struct demangle_result_storage): New type. (demangle_for_lookup): Now returns 'const char *'. Add a demangle_result_storage parameter. * typeprint.c (type_to_string): Return std::string and use ui_file_as_string. * value.h (type_to_string): Change return type to std::string. * varobj-iter.h (struct varobj_item) <name>: Now a std::string. (varobj_iter_delete): Use delete instead of xfree. * varobj.c (create_child): Return std::string instead of char * in output parameter. (name_of_variable, name_of_child, my_value_of_variable): Return std::string instead of char *. (varobj_create, varobj_get_handle): Constify 'objname' parameter. Adjust to std::string fields. (varobj_get_objname): Return a const char * instead of a char *. (varobj_get_expression): Return a std::string. (varobj_list_children): Adjust to use std::string. (varobj_get_type): Return a std::string. (varobj_get_path_expr): Return a const char * instead of a char *. Adjust to std::string fields. (varobj_get_formatted_value, varobj_get_value): Return a std::string. (varobj_set_value): Change type of 'expression' parameter to std::string. Use std::string. (install_new_value): Use std::string. (delete_variable_1): Adjust to use std::string. (create_child): Change the 'name' parameter to a std::string reference. Swap it into the new item's name. (create_child_with_value): Swap item's name into the new child's name. Use string_printf. (new_variable): Use new instead of XNEW. (free_variable): Don't xfree fields that are now std::string. (name_of_variable, name_of_child): Now returns std::string. (value_of_root): Adjust to use std::string. (my_value_of_variable, varobj_value_get_print_value): Return and use std::string. (varobj_value_get_print_value): Adjust to use ui_file_as_string and std::string. * varobj.h (struct varobj) <name, path_expr, obj_name, print_value>: Now std::string's. <name_of_variable, name_of_child, path_expr_of_child, value_of_variable>: Return std::string. (varobj_create, varobj_get_handle): Constify 'objname' parameter. (varobj_get_objname): Return a const char * instead of a char *. (varobj_get_expression, varobj_get_type): Return a std::string. (varobj_get_path_expr): Return a const char * instead of a char *. (varobj_get_formatted_value, varobj_get_value): Return a std::string. (varobj_set_value): Constify 'expression' parameter. (varobj_value_get_print_value): Return a std::string.
2016-11-08 16:26:47 +01:00
std::string canon = cp_canonicalize_string_no_typedefs (name);
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
Use ui_file_as_string throughout more This replaces most of the remaining ui_file_xstrdup calls with ui_file_as_string calls. Whenever a call was replaced, that led to a cascade of other necessary adjustments throughout, to make the code use std::string instead of raw pointers. And then whenever I added a std::string as member of a struct, I needed to adjust allocation/destruction of said struct to use new/delete instead of xmalloc/xfree. The stopping point was once gdb built again. These doesn't seem to be a way to reasonably split this out further. Maybe-not-obvious changes: - demangle_for_lookup returns a cleanup today. To get rid of that, and avoid unnecessary string dupping/copying, this introduces a demangle_result_storage type that the caller instantiates and passes to demangle_for_lookup. - Many methods returned a "char *" to indicate that the caller owns the memory and must free it. Those are switched to return a std::string instead. Methods that return a "view" into some internal string return a "const char *" instead. I.e., we only copy/allocate when necessary. gdb/ChangeLog: 2016-11-08 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_name_for_lookup, type_as_string): Use and return std::string. (type_as_string_and_cleanup): Delete. (ada_lookup_struct_elt_type): Use type_as_string. * ada-lang.h (ada_name_for_lookup): Now returns std::string. * ada-varobj.c (ada_varobj_scalar_image): Return a std::string. (ada_varobj_describe_child): Make 'child_name' and 'child_path_expr' parameters std::string pointers. (ada_varobj_describe_struct_child, ada_varobj_describe_ptr_child): Likewise, and use string_printf. (ada_varobj_describe_simple_array_child) (ada_varobj_describe_child): Likewise. (ada_varobj_get_name_of_child, ada_varobj_get_path_expr_of_child) (ada_varobj_get_value_image) (ada_varobj_get_value_of_array_variable) (ada_varobj_get_value_of_variable, ada_name_of_variable) (ada_name_of_child, ada_path_expr_of_child) (ada_value_of_variable): Now returns std::string. Use string_printf. (ada_value_of_child): Adjust. * break-catch-throw.c (check_status_exception_catchpoint): Adjust to use std::string. * breakpoint.c (watch_command_1): Adjust to use std::string. * c-lang.c (c_get_string): Adjust to use std::string. * c-typeprint.c (print_name_maybe_canonical): Use std::string. * c-varobj.c (varobj_is_anonymous_child): Use ==/!= std::string operators. (c_name_of_variable): Now returns a std::string. (c_describe_child): The 'cname' and 'cfull_expression' output parameters are now std::string pointers. Adjust. (c_name_of_child, c_path_expr_of_child, c_value_of_variable) (cplus_number_of_children): Adjust to use std::string and string_printf. (cplus_name_of_variable): Now returns a std::string. (cplus_describe_child): The 'cname' and 'cfull_expression' output parameters are now std::string pointers. Adjust. (cplus_name_of_child, cplus_path_expr_of_child) (cplus_value_of_variable): Now returns a std::string. * cp-abi.c (cplus_typename_from_type_info): Return std::string. * cp-abi.h (cplus_typename_from_type_info): Return std::string. (struct cp_abi_ops) <get_typename_from_type_info>: Return std::string. * cp-support.c (inspect_type): Use std::string. (cp_canonicalize_string_full, cp_canonicalize_string_no_typedefs) (cp_canonicalize_string): Return std::string and adjust. * cp-support.h (cp_canonicalize_string) (cp_canonicalize_string_no_typedefs, cp_canonicalize_string_full): Return std::string. * dbxread.c (read_dbx_symtab): Use std::string. * dwarf2read.c (dwarf2_canonicalize_name): Adjust to use std::string. * gdbcmd.h (lookup_struct_elt_type): Adjust to use std::string. * gnu-v3-abi.c (gnuv3_get_typeid): Use std::string. (gnuv3_get_typename_from_type_info): Return a std::string and adjust. (gnuv3_get_type_from_type_info): Adjust to use std::string. * guile/guile.c (gdbscm_execute_gdb_command): Adjust to use std::string. * infcmd.c (print_return_value_1): Adjust to use std::string. * linespec.c (find_linespec_symbols): Adjust to demangle_for_lookup API change. Use std::string. * mi/mi-cmd-var.c (print_varobj, mi_cmd_var_set_format) (mi_cmd_var_info_type, mi_cmd_var_info_path_expression) (mi_cmd_var_info_expression, mi_cmd_var_evaluate_expression) (mi_cmd_var_assign, varobj_update_one): Adjust to use std::string. * minsyms.c (lookup_minimal_symbol): Use std::string. * python/py-varobj.c (py_varobj_iter_next): Use new instead of XNEW. vitem->name is a std::string now, adjust. * rust-exp.y (convert_ast_to_type, convert_name): Adjust to use std::string. * stabsread.c (define_symbol): Adjust to use std::string. * symtab.c (demangle_for_lookup): Now returns 'const char *'. Add a demangle_result_storage parameter. Use it for storage. (lookup_symbol_in_language) (lookup_symbol_in_objfile_from_linkage_name): Adjust to new demangle_for_lookup API. * symtab.h (struct demangle_result_storage): New type. (demangle_for_lookup): Now returns 'const char *'. Add a demangle_result_storage parameter. * typeprint.c (type_to_string): Return std::string and use ui_file_as_string. * value.h (type_to_string): Change return type to std::string. * varobj-iter.h (struct varobj_item) <name>: Now a std::string. (varobj_iter_delete): Use delete instead of xfree. * varobj.c (create_child): Return std::string instead of char * in output parameter. (name_of_variable, name_of_child, my_value_of_variable): Return std::string instead of char *. (varobj_create, varobj_get_handle): Constify 'objname' parameter. Adjust to std::string fields. (varobj_get_objname): Return a const char * instead of a char *. (varobj_get_expression): Return a std::string. (varobj_list_children): Adjust to use std::string. (varobj_get_type): Return a std::string. (varobj_get_path_expr): Return a const char * instead of a char *. Adjust to std::string fields. (varobj_get_formatted_value, varobj_get_value): Return a std::string. (varobj_set_value): Change type of 'expression' parameter to std::string. Use std::string. (install_new_value): Use std::string. (delete_variable_1): Adjust to use std::string. (create_child): Change the 'name' parameter to a std::string reference. Swap it into the new item's name. (create_child_with_value): Swap item's name into the new child's name. Use string_printf. (new_variable): Use new instead of XNEW. (free_variable): Don't xfree fields that are now std::string. (name_of_variable, name_of_child): Now returns std::string. (value_of_root): Adjust to use std::string. (my_value_of_variable, varobj_value_get_print_value): Return and use std::string. (varobj_value_get_print_value): Adjust to use ui_file_as_string and std::string. * varobj.h (struct varobj) <name, path_expr, obj_name, print_value>: Now std::string's. <name_of_variable, name_of_child, path_expr_of_child, value_of_variable>: Return std::string. (varobj_create, varobj_get_handle): Constify 'objname' parameter. (varobj_get_objname): Return a const char * instead of a char *. (varobj_get_expression, varobj_get_type): Return a std::string. (varobj_get_path_expr): Return a const char * instead of a char *. (varobj_get_formatted_value, varobj_get_value): Return a std::string. (varobj_set_value): Constify 'expression' parameter. (varobj_value_get_print_value): Return a std::string.
2016-11-08 16:26:47 +01:00
if (!canon.empty ())
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
{
Use ui_file_as_string throughout more This replaces most of the remaining ui_file_xstrdup calls with ui_file_as_string calls. Whenever a call was replaced, that led to a cascade of other necessary adjustments throughout, to make the code use std::string instead of raw pointers. And then whenever I added a std::string as member of a struct, I needed to adjust allocation/destruction of said struct to use new/delete instead of xmalloc/xfree. The stopping point was once gdb built again. These doesn't seem to be a way to reasonably split this out further. Maybe-not-obvious changes: - demangle_for_lookup returns a cleanup today. To get rid of that, and avoid unnecessary string dupping/copying, this introduces a demangle_result_storage type that the caller instantiates and passes to demangle_for_lookup. - Many methods returned a "char *" to indicate that the caller owns the memory and must free it. Those are switched to return a std::string instead. Methods that return a "view" into some internal string return a "const char *" instead. I.e., we only copy/allocate when necessary. gdb/ChangeLog: 2016-11-08 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_name_for_lookup, type_as_string): Use and return std::string. (type_as_string_and_cleanup): Delete. (ada_lookup_struct_elt_type): Use type_as_string. * ada-lang.h (ada_name_for_lookup): Now returns std::string. * ada-varobj.c (ada_varobj_scalar_image): Return a std::string. (ada_varobj_describe_child): Make 'child_name' and 'child_path_expr' parameters std::string pointers. (ada_varobj_describe_struct_child, ada_varobj_describe_ptr_child): Likewise, and use string_printf. (ada_varobj_describe_simple_array_child) (ada_varobj_describe_child): Likewise. (ada_varobj_get_name_of_child, ada_varobj_get_path_expr_of_child) (ada_varobj_get_value_image) (ada_varobj_get_value_of_array_variable) (ada_varobj_get_value_of_variable, ada_name_of_variable) (ada_name_of_child, ada_path_expr_of_child) (ada_value_of_variable): Now returns std::string. Use string_printf. (ada_value_of_child): Adjust. * break-catch-throw.c (check_status_exception_catchpoint): Adjust to use std::string. * breakpoint.c (watch_command_1): Adjust to use std::string. * c-lang.c (c_get_string): Adjust to use std::string. * c-typeprint.c (print_name_maybe_canonical): Use std::string. * c-varobj.c (varobj_is_anonymous_child): Use ==/!= std::string operators. (c_name_of_variable): Now returns a std::string. (c_describe_child): The 'cname' and 'cfull_expression' output parameters are now std::string pointers. Adjust. (c_name_of_child, c_path_expr_of_child, c_value_of_variable) (cplus_number_of_children): Adjust to use std::string and string_printf. (cplus_name_of_variable): Now returns a std::string. (cplus_describe_child): The 'cname' and 'cfull_expression' output parameters are now std::string pointers. Adjust. (cplus_name_of_child, cplus_path_expr_of_child) (cplus_value_of_variable): Now returns a std::string. * cp-abi.c (cplus_typename_from_type_info): Return std::string. * cp-abi.h (cplus_typename_from_type_info): Return std::string. (struct cp_abi_ops) <get_typename_from_type_info>: Return std::string. * cp-support.c (inspect_type): Use std::string. (cp_canonicalize_string_full, cp_canonicalize_string_no_typedefs) (cp_canonicalize_string): Return std::string and adjust. * cp-support.h (cp_canonicalize_string) (cp_canonicalize_string_no_typedefs, cp_canonicalize_string_full): Return std::string. * dbxread.c (read_dbx_symtab): Use std::string. * dwarf2read.c (dwarf2_canonicalize_name): Adjust to use std::string. * gdbcmd.h (lookup_struct_elt_type): Adjust to use std::string. * gnu-v3-abi.c (gnuv3_get_typeid): Use std::string. (gnuv3_get_typename_from_type_info): Return a std::string and adjust. (gnuv3_get_type_from_type_info): Adjust to use std::string. * guile/guile.c (gdbscm_execute_gdb_command): Adjust to use std::string. * infcmd.c (print_return_value_1): Adjust to use std::string. * linespec.c (find_linespec_symbols): Adjust to demangle_for_lookup API change. Use std::string. * mi/mi-cmd-var.c (print_varobj, mi_cmd_var_set_format) (mi_cmd_var_info_type, mi_cmd_var_info_path_expression) (mi_cmd_var_info_expression, mi_cmd_var_evaluate_expression) (mi_cmd_var_assign, varobj_update_one): Adjust to use std::string. * minsyms.c (lookup_minimal_symbol): Use std::string. * python/py-varobj.c (py_varobj_iter_next): Use new instead of XNEW. vitem->name is a std::string now, adjust. * rust-exp.y (convert_ast_to_type, convert_name): Adjust to use std::string. * stabsread.c (define_symbol): Adjust to use std::string. * symtab.c (demangle_for_lookup): Now returns 'const char *'. Add a demangle_result_storage parameter. Use it for storage. (lookup_symbol_in_language) (lookup_symbol_in_objfile_from_linkage_name): Adjust to new demangle_for_lookup API. * symtab.h (struct demangle_result_storage): New type. (demangle_for_lookup): Now returns 'const char *'. Add a demangle_result_storage parameter. * typeprint.c (type_to_string): Return std::string and use ui_file_as_string. * value.h (type_to_string): Change return type to std::string. * varobj-iter.h (struct varobj_item) <name>: Now a std::string. (varobj_iter_delete): Use delete instead of xfree. * varobj.c (create_child): Return std::string instead of char * in output parameter. (name_of_variable, name_of_child, my_value_of_variable): Return std::string instead of char *. (varobj_create, varobj_get_handle): Constify 'objname' parameter. Adjust to std::string fields. (varobj_get_objname): Return a const char * instead of a char *. (varobj_get_expression): Return a std::string. (varobj_list_children): Adjust to use std::string. (varobj_get_type): Return a std::string. (varobj_get_path_expr): Return a const char * instead of a char *. Adjust to std::string fields. (varobj_get_formatted_value, varobj_get_value): Return a std::string. (varobj_set_value): Change type of 'expression' parameter to std::string. Use std::string. (install_new_value): Use std::string. (delete_variable_1): Adjust to use std::string. (create_child): Change the 'name' parameter to a std::string reference. Swap it into the new item's name. (create_child_with_value): Swap item's name into the new child's name. Use string_printf. (new_variable): Use new instead of XNEW. (free_variable): Don't xfree fields that are now std::string. (name_of_variable, name_of_child): Now returns std::string. (value_of_root): Adjust to use std::string. (my_value_of_variable, varobj_value_get_print_value): Return and use std::string. (varobj_value_get_print_value): Adjust to use ui_file_as_string and std::string. * varobj.h (struct varobj) <name, path_expr, obj_name, print_value>: Now std::string's. <name_of_variable, name_of_child, path_expr_of_child, value_of_variable>: Return std::string. (varobj_create, varobj_get_handle): Constify 'objname' parameter. (varobj_get_objname): Return a const char * instead of a char *. (varobj_get_expression, varobj_get_type): Return a std::string. (varobj_get_path_expr): Return a const char * instead of a char *. (varobj_get_formatted_value, varobj_get_value): Return a std::string. (varobj_set_value): Constify 'expression' parameter. (varobj_value_get_print_value): Return a std::string.
2016-11-08 16:26:47 +01:00
/* Copy the canonicalization into the obstack. */
name = copy_string_to_obstack (&info->obstack, canon.c_str (), &len);
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
}
ret_comp->u.s_name.s = name;
ret_comp->u.s_name.len = len;
}
return 1;
}
}
return 0;
}
/* Replace any typedefs appearing in the qualified name
(DEMANGLE_COMPONENT_QUAL_NAME) represented in RET_COMP for the name parse
given in INFO. */
static void
replace_typedefs_qualified_name (struct demangle_parse_info *info,
struct demangle_component *ret_comp,
canonicalization_ftype *finder,
void *data)
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
{
Eliminate make_cleanup_ui_file_delete / make ui_file a class hierarchy This patch starts from the desire to eliminate make_cleanup_ui_file_delete, but then goes beyond. It makes ui_file & friends a real C++ class hierarchy, and switches temporary ui_file-like objects to stack-based allocation. - mem_fileopen -> string_file mem_fileopen is replaced with a new string_file class that is treated as a value class created on the stack. This alone eliminates most make_cleanup_ui_file_delete calls, and, simplifies code a whole lot (diffstat shows around 1k loc dropped.) string_file's internal buffer is a std::string, thus the "string" in the name. This simplifies the implementation much, compared to mem_fileopen, which managed growing its internal buffer manually. - ui_file_as_string, ui_file_strdup, ui_file_obsavestring all gone The new string_file class has a string() method that provides direct writable access to the internal std::string buffer. This replaced ui_file_as_string, which forced a copy of the same data the stream had inside. With direct access via a writable reference, we can instead move the string out of the string_stream, avoiding deep string copying. Related, ui_file_xstrdup calls are replaced with xstrdup'ping the stream's string, and ui_file_obsavestring is replaced by obstack_copy0. With all those out of the way, getting rid of the weird ui_file_put mechanism was possible. - New ui_file::printf, ui_file::puts, etc. methods These simplify / clarify client code. I considered splitting client-code changes, like these, e.g.: - stb = mem_fileopen (); - fprintf_unfiltered (stb, "%s%s%s", - _("The valid values are:\n"), - regdesc, - _("The default is \"std\".")); + string_file stb; + stb.printf ("%s%s%s", + _("The valid values are:\n"), + regdesc, + _("The default is \"std\".")); In two steps, with the first step leaving fprintf_unfiltered (etc.) calls in place, and only afterwards do a pass to change all those to call stb.printf etc.. I didn't do that split, because (when I tried), it turned out to be pointless make-work: the first pass would have to touch the fprintf_unfiltered line anyway, to replace "stb" with "&stb". - gdb_fopen replaced with stack-based objects This avoids the need for cleanups or unique_ptr's. I.e., this: struct ui_file *file = gdb_fopen (filename, "w"); if (filename == NULL) perror_with_name (filename); cleanups = make_cleanup_ui_file_delete (file); // use file. do_cleanups (cleanups); is replaced with this: stdio_file file; if (!file.open (filename, "w")) perror_with_name (filename); // use file. - odd contorsions in null_file_write / null_file_fputs around when to call to_fputs / to_write eliminated. - Global null_stream object A few places that were allocating a ui_file in order to print to "nowhere" are adjusted to instead refer to a new 'null_stream' global stream. - TUI's tui_sfileopen eliminated. TUI's ui_file much simplified The TUI's ui_file was serving a dual purpose. It supported being used as string buffer, and supported being backed by a stdio FILE. The string buffer part is gone, replaced by using of string_file. The 'FILE *' support is now much simplified, by making the TUI's ui_file inherit from stdio_file. gdb/ChangeLog: 2017-02-02 Pedro Alves <palves@redhat.com> * ada-lang.c (type_as_string): Use string_file. * ada-valprint.c (ada_print_floating): Use string_file. * ada-varobj.c (ada_varobj_scalar_image) (ada_varobj_get_value_image): Use string_file. * aix-thread.c (aix_thread_extra_thread_info): Use string_file. * arm-tdep.c (_initialize_arm_tdep): Use string_printf. * breakpoint.c (update_inserted_breakpoint_locations) (insert_breakpoint_locations, reattach_breakpoints) (print_breakpoint_location, print_one_detail_ranged_breakpoint) (print_it_watchpoint): Use string_file. (save_breakpoints): Use stdio_file. * c-exp.y (oper): Use string_file. * cli/cli-logging.c (set_logging_redirect): Use ui_file_up and tee_file. (pop_output_files): Use delete. (handle_redirections): Use stdio_file and tee_file. * cli/cli-setshow.c (do_show_command): Use string_file. * compile/compile-c-support.c (c_compute_program): Use string_file. * compile/compile-c-symbols.c (generate_vla_size): Take a 'string_file &' instead of a 'ui_file *'. (generate_c_for_for_one_variable): Take a 'string_file &' instead of a 'ui_file *'. Use string_file. (generate_c_for_variable_locations): Take a 'string_file &' instead of a 'ui_file *'. * compile/compile-internal.h (generate_c_for_for_one_variable): Take a 'string_file &' instead of a 'ui_file *'. * compile/compile-loc2c.c (push, pushf, unary, binary) (print_label, pushf_register_address, pushf_register) (do_compile_dwarf_expr_to_c): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * compile/compile.c (compile_to_object): Use string_file. * compile/compile.h (compile_dwarf_expr_to_c) (compile_dwarf_bounds_to_c): Take a 'string_file &' instead of a 'ui_file *'. * cp-support.c (inspect_type): Use string_file and obstack_copy0. (replace_typedefs_qualified_name): Use string_file and obstack_copy0. * disasm.c (gdb_pretty_print_insn): Use string_file. (gdb_disassembly): Adjust reference the null_stream global. (do_ui_file_delete): Delete. (gdb_insn_length): Use null_stream. * dummy-frame.c (maintenance_print_dummy_frames): Use stdio_file. * dwarf2loc.c (dwarf2_compile_property_to_c) (locexpr_generate_c_location, loclist_generate_c_location): Take a 'string_file &' instead of a 'ui_file *'. * dwarf2loc.h (dwarf2_compile_property_to_c): Likewise. * dwarf2read.c (do_ui_file_peek_last): Delete. (dwarf2_compute_name): Use string_file. * event-top.c (gdb_setup_readline): Use stdio_file. * gdbarch.sh (verify_gdbarch): Use string_file. * gdbtypes.c (safe_parse_type): Use null_stream. * guile/scm-breakpoint.c (gdbscm_breakpoint_commands): Use string_file. * guile/scm-disasm.c (gdbscm_print_insn_from_port): Take a 'string_file *' instead of a 'ui_file *'. (gdbscm_arch_disassemble): Use string_file. * guile/scm-frame.c (frscm_print_frame_smob): Use string_file. * guile/scm-ports.c (class ioscm_file_port): Now a class that inherits from ui_file. (ioscm_file_port_delete, ioscm_file_port_rewind) (ioscm_file_port_put): Delete. (ioscm_file_port_write): Rename to ... (ioscm_file_port::write): ... this. Remove file_port_magic checks. (ioscm_file_port_new): Delete. (ioscm_with_output_to_port_worker): Use ioscm_file_port and ui_file_up. * guile/scm-type.c (tyscm_type_name): Use string_file. * guile/scm-value.c (vlscm_print_value_smob, gdbscm_value_print): Use string_file. * infcmd.c (print_return_value_1): Use string_file. * infrun.c (print_target_wait_results): Use string_file. * language.c (add_language): Use string_file. * location.c (explicit_to_string_internal): Use string_file. * main.c (captured_main_1): Use null_file. * maint.c (maintenance_print_architecture): Use stdio_file. * mi/mi-cmd-stack.c (list_arg_or_local): Use string_file. * mi/mi-common.h (struct mi_interp) <out, err, log, targ, event_channel>: Change type to mi_console_file pointer. * mi/mi-console.c (mi_console_file_fputs, mi_console_file_flush) (mi_console_file_delete): Delete. (struct mi_console_file): Delete. (mi_console_file_magic): Delete. (mi_console_file_new): Delete. (mi_console_file::mi_console_file): New. (mi_console_file_delete): Delete. (mi_console_file_fputs): Delete. (mi_console_file::write): New. (mi_console_raw_packet): Delete. (mi_console_file::flush): New. (mi_console_file_flush): Delete. (mi_console_set_raw): Rename to ... (mi_console_file::set_raw): ... this. * mi/mi-console.h (class mi_console_file): New class. (mi_console_file_new, mi_console_set_raw): Delete. * mi/mi-interp.c (mi_interpreter_init): Use mi_console_file. (mi_set_logging): Use delete and tee_file. Adjust. * mi/mi-main.c (output_register): Use string_file. (mi_cmd_data_evaluate_expression): Use string_file. (mi_cmd_data_read_memory): Use string_file. (mi_cmd_execute, print_variable_or_computed): Use string_file. * mi/mi-out.c (mi_ui_out::main_stream): New. (mi_ui_out::rewind): Use main_stream and string_file. (mi_ui_out::put): Use main_stream and string_file. (mi_ui_out::mi_ui_out): Remove 'stream' parameter. Allocate a 'string_file' instead. (mi_out_new): Don't allocate a mem_fileopen stream here. * mi/mi-out.h (mi_ui_out::mi_ui_out): Remove 'stream' parameter. (mi_ui_out::main_stream): Declare method. * printcmd.c (eval_command): Use string_file. * psymtab.c (maintenance_print_psymbols): Use stdio_file. * python/py-arch.c (archpy_disassemble): Use string_file. * python/py-breakpoint.c (bppy_get_commands): Use string_file. * python/py-frame.c (frapy_str): Use string_file. * python/py-framefilter.c (py_print_type, py_print_single_arg): Use string_file. * python/py-type.c (typy_str): Use string_file. * python/py-unwind.c (unwind_infopy_str): Use string_file. * python/py-value.c (valpy_str): Use string_file. * record-btrace.c (btrace_insn_history): Use string_file. * regcache.c (regcache_print): Use stdio_file. * reggroups.c (maintenance_print_reggroups): Use stdio_file. * remote.c (escape_buffer): Use string_file. * rust-lang.c (rust_get_disr_info): Use string_file. * serial.c (serial_open_ops_1): Use stdio_file. (do_serial_close): Use delete. * stack.c (print_frame_arg): Use string_file. (print_frame_args): Remove local mem_fileopen stream, not used. (print_frame): Use string_file. * symmisc.c (maintenance_print_symbols): Use stdio_file. * symtab.h (struct symbol_computed_ops) <generate_c_location>: Take a 'string_file *' instead of a 'ui_file *'. * top.c (new_ui): Use stdio_file and stderr_file. (free_ui): Use delete. (execute_command_to_string): Use string_file. (quit_confirm): Use string_file. * tracepoint.c (collection_list::append_exp): Use string_file. * tui/tui-disasm.c (tui_disassemble): Use string_file. * tui/tui-file.c: Don't include "ui-file.h". (enum streamtype, struct tui_stream): Delete. (tui_file_new, tui_file_delete, tui_fileopen, tui_sfileopen) (tui_file_isatty, tui_file_rewind, tui_file_put): Delete. (tui_file::tui_file): New method. (tui_file_fputs): Delete. (tui_file_get_strbuf): Delete. (tui_file::puts): New method. (tui_file_adjust_strbuf): Delete. (tui_file_flush): Delete. (tui_file::flush): New method. * tui/tui-file.h: Tweak intro comment. Include ui-file.h. (tui_fileopen, tui_sfileopen, tui_file_get_strbuf) (tui_file_adjust_strbuf): Delete declarations. (class tui_file): New class. * tui/tui-io.c (tui_initialize_io): Use tui_file. * tui/tui-regs.c (tui_restore_gdbout): Use delete. (tui_register_format): Use string_stream. * tui/tui-stack.c (tui_make_status_line): Use string_file. (tui_get_function_from_frame): Use string_file. * typeprint.c (type_to_string): Use string_file. * ui-file.c (struct ui_file, ui_file_magic, ui_file_new): Delete. (null_stream): New global. (ui_file_delete): Delete. (ui_file::ui_file): New. (null_file_isatty): Delete. (ui_file::~ui_file): New. (null_file_rewind): Delete. (ui_file::printf): New. (null_file_put): Delete. (null_file_flush): Delete. (ui_file::putstr): New. (null_file_write): Delete. (ui_file::putstrn): New. (null_file_read): Delete. (ui_file::putc): New. (null_file_fputs): Delete. (null_file_write_async_safe): Delete. (ui_file::vprintf): New. (null_file_delete): Delete. (null_file::write): New. (null_file_fseek): Delete. (null_file::puts): New. (ui_file_data): Delete. (null_file::write_async_safe): New. (gdb_flush, ui_file_isatty): Adjust. (ui_file_put, ui_file_rewind): Delete. (ui_file_write): Adjust. (ui_file_write_for_put): Delete. (ui_file_write_async_safe, ui_file_read): Adjust. (ui_file_fseek): Delete. (fputs_unfiltered): Adjust. (set_ui_file_flush, set_ui_file_isatty, set_ui_file_rewind) (set_ui_file_put, set_ui_file_write, set_ui_file_write_async_safe) (set_ui_file_read, set_ui_file_fputs, set_ui_file_fseek) (set_ui_file_data): Delete. (string_file::~string_file, string_file::write) (struct accumulated_ui_file, do_ui_file_xstrdup, ui_file_xstrdup) (do_ui_file_as_string, ui_file_as_string): Delete. (do_ui_file_obsavestring, ui_file_obsavestring): Delete. (struct mem_file): Delete. (mem_file_new): Delete. (stdio_file::stdio_file): New. (mem_file_delete): Delete. (stdio_file::stdio_file): New. (mem_fileopen): Delete. (stdio_file::~stdio_file): New. (mem_file_rewind): Delete. (stdio_file::set_stream): New. (mem_file_put): Delete. (stdio_file::open): New. (mem_file_write): Delete. (stdio_file_magic, struct stdio_file): Delete. (stdio_file_new, stdio_file_delete, stdio_file_flush): Delete. (stdio_file::flush): New. (stdio_file_read): Rename to ... (stdio_file::read): ... this. Adjust. (stdio_file_write): Rename to ... (stdio_file::write): ... this. Adjust. (stdio_file_write_async_safe): Rename to ... (stdio_file::write_async_safe) ... this. Adjust. (stdio_file_fputs): Rename to ... (stdio_file::puts) ... this. Adjust. (stdio_file_isatty): Delete. (stdio_file_fseek): Delete. (stdio_file::isatty): New. (stderr_file_write): Rename to ... (stderr_file::write) ... this. Adjust. (stderr_file_fputs): Rename to ... (stderr_file::puts) ... this. Adjust. (stderr_fileopen, stdio_fileopen, gdb_fopen): Delete. (stderr_file::stderr_file): New. (tee_file_magic): Delete. (struct tee_file): Delete. (tee_file::tee_file): New. (tee_file_new): Delete. (tee_file::~tee_file): New. (tee_file_delete): Delete. (tee_file_flush): Rename to ... (tee_file::flush): ... this. Adjust. (tee_file_write): Rename to ... (tee_file::write): ... this. Adjust. (tee_file::write_async_safe): New. (tee_file_fputs): Rename to ... (tee_file::puts): ... this. Adjust. (tee_file_isatty): Rename to ... (tee_file::isatty): ... this. Adjust. * ui-file.h (struct obstack, struct ui_file): Don't forward-declare. (ui_file_new, ui_file_flush_ftype, set_ui_file_flush) (ui_file_write_ftype) (set_ui_file_write, ui_file_fputs_ftype, set_ui_file_fputs) (ui_file_write_async_safe_ftype, set_ui_file_write_async_safe) (ui_file_read_ftype, set_ui_file_read, ui_file_isatty_ftype) (set_ui_file_isatty, ui_file_rewind_ftype, set_ui_file_rewind) (ui_file_put_method_ftype, ui_file_put_ftype, set_ui_file_put) (ui_file_delete_ftype, set_ui_file_data, ui_file_fseek_ftype) (set_ui_file_fseek): Delete. (ui_file_data, ui_file_delete, ui_file_rewind) (struct ui_file): New. (ui_file_up): New. (class null_file): New. (null_stream): Declare. (ui_file_write_for_put, ui_file_put): Delete. (ui_file_xstrdup, ui_file_as_string, ui_file_obsavestring): Delete. (ui_file_fseek, mem_fileopen, stdio_fileopen, stderr_fileopen) (gdb_fopen, tee_file_new): Delete. (struct string_file): New. (struct stdio_file): New. (stdio_file_up): New. (struct stderr_file): New. (class tee_file): New. * ui-out.c (ui_out::field_stream): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * ui-out.h (class ui_out) <field_stream>: Likewise. * utils.c (do_ui_file_delete, make_cleanup_ui_file_delete) (null_stream): Delete. (error_stream): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * utils.h (struct ui_file): Delete forward declaration.. (make_cleanup_ui_file_delete, null_stream): Delete declarations. (error_stream): Take a 'string_file &' instead of a 'ui_file *'. * varobj.c (varobj_value_get_print_value): Use string_file. * xtensa-tdep.c (xtensa_verify_config): Use string_file. * gdbarch.c: Regenerate.
2017-02-02 12:11:47 +01:00
string_file buf;
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
struct demangle_component *comp = ret_comp;
/* Walk each node of the qualified name, reconstructing the name of
this element. With every node, check for any typedef substitutions.
If a substitution has occurred, replace the qualified name node
with a DEMANGLE_COMPONENT_NAME node representing the new, typedef-
substituted name. */
while (comp->type == DEMANGLE_COMPONENT_QUAL_NAME)
{
if (d_left (comp)->type == DEMANGLE_COMPONENT_NAME)
{
struct demangle_component newobj;
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
Eliminate make_cleanup_ui_file_delete / make ui_file a class hierarchy This patch starts from the desire to eliminate make_cleanup_ui_file_delete, but then goes beyond. It makes ui_file & friends a real C++ class hierarchy, and switches temporary ui_file-like objects to stack-based allocation. - mem_fileopen -> string_file mem_fileopen is replaced with a new string_file class that is treated as a value class created on the stack. This alone eliminates most make_cleanup_ui_file_delete calls, and, simplifies code a whole lot (diffstat shows around 1k loc dropped.) string_file's internal buffer is a std::string, thus the "string" in the name. This simplifies the implementation much, compared to mem_fileopen, which managed growing its internal buffer manually. - ui_file_as_string, ui_file_strdup, ui_file_obsavestring all gone The new string_file class has a string() method that provides direct writable access to the internal std::string buffer. This replaced ui_file_as_string, which forced a copy of the same data the stream had inside. With direct access via a writable reference, we can instead move the string out of the string_stream, avoiding deep string copying. Related, ui_file_xstrdup calls are replaced with xstrdup'ping the stream's string, and ui_file_obsavestring is replaced by obstack_copy0. With all those out of the way, getting rid of the weird ui_file_put mechanism was possible. - New ui_file::printf, ui_file::puts, etc. methods These simplify / clarify client code. I considered splitting client-code changes, like these, e.g.: - stb = mem_fileopen (); - fprintf_unfiltered (stb, "%s%s%s", - _("The valid values are:\n"), - regdesc, - _("The default is \"std\".")); + string_file stb; + stb.printf ("%s%s%s", + _("The valid values are:\n"), + regdesc, + _("The default is \"std\".")); In two steps, with the first step leaving fprintf_unfiltered (etc.) calls in place, and only afterwards do a pass to change all those to call stb.printf etc.. I didn't do that split, because (when I tried), it turned out to be pointless make-work: the first pass would have to touch the fprintf_unfiltered line anyway, to replace "stb" with "&stb". - gdb_fopen replaced with stack-based objects This avoids the need for cleanups or unique_ptr's. I.e., this: struct ui_file *file = gdb_fopen (filename, "w"); if (filename == NULL) perror_with_name (filename); cleanups = make_cleanup_ui_file_delete (file); // use file. do_cleanups (cleanups); is replaced with this: stdio_file file; if (!file.open (filename, "w")) perror_with_name (filename); // use file. - odd contorsions in null_file_write / null_file_fputs around when to call to_fputs / to_write eliminated. - Global null_stream object A few places that were allocating a ui_file in order to print to "nowhere" are adjusted to instead refer to a new 'null_stream' global stream. - TUI's tui_sfileopen eliminated. TUI's ui_file much simplified The TUI's ui_file was serving a dual purpose. It supported being used as string buffer, and supported being backed by a stdio FILE. The string buffer part is gone, replaced by using of string_file. The 'FILE *' support is now much simplified, by making the TUI's ui_file inherit from stdio_file. gdb/ChangeLog: 2017-02-02 Pedro Alves <palves@redhat.com> * ada-lang.c (type_as_string): Use string_file. * ada-valprint.c (ada_print_floating): Use string_file. * ada-varobj.c (ada_varobj_scalar_image) (ada_varobj_get_value_image): Use string_file. * aix-thread.c (aix_thread_extra_thread_info): Use string_file. * arm-tdep.c (_initialize_arm_tdep): Use string_printf. * breakpoint.c (update_inserted_breakpoint_locations) (insert_breakpoint_locations, reattach_breakpoints) (print_breakpoint_location, print_one_detail_ranged_breakpoint) (print_it_watchpoint): Use string_file. (save_breakpoints): Use stdio_file. * c-exp.y (oper): Use string_file. * cli/cli-logging.c (set_logging_redirect): Use ui_file_up and tee_file. (pop_output_files): Use delete. (handle_redirections): Use stdio_file and tee_file. * cli/cli-setshow.c (do_show_command): Use string_file. * compile/compile-c-support.c (c_compute_program): Use string_file. * compile/compile-c-symbols.c (generate_vla_size): Take a 'string_file &' instead of a 'ui_file *'. (generate_c_for_for_one_variable): Take a 'string_file &' instead of a 'ui_file *'. Use string_file. (generate_c_for_variable_locations): Take a 'string_file &' instead of a 'ui_file *'. * compile/compile-internal.h (generate_c_for_for_one_variable): Take a 'string_file &' instead of a 'ui_file *'. * compile/compile-loc2c.c (push, pushf, unary, binary) (print_label, pushf_register_address, pushf_register) (do_compile_dwarf_expr_to_c): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * compile/compile.c (compile_to_object): Use string_file. * compile/compile.h (compile_dwarf_expr_to_c) (compile_dwarf_bounds_to_c): Take a 'string_file &' instead of a 'ui_file *'. * cp-support.c (inspect_type): Use string_file and obstack_copy0. (replace_typedefs_qualified_name): Use string_file and obstack_copy0. * disasm.c (gdb_pretty_print_insn): Use string_file. (gdb_disassembly): Adjust reference the null_stream global. (do_ui_file_delete): Delete. (gdb_insn_length): Use null_stream. * dummy-frame.c (maintenance_print_dummy_frames): Use stdio_file. * dwarf2loc.c (dwarf2_compile_property_to_c) (locexpr_generate_c_location, loclist_generate_c_location): Take a 'string_file &' instead of a 'ui_file *'. * dwarf2loc.h (dwarf2_compile_property_to_c): Likewise. * dwarf2read.c (do_ui_file_peek_last): Delete. (dwarf2_compute_name): Use string_file. * event-top.c (gdb_setup_readline): Use stdio_file. * gdbarch.sh (verify_gdbarch): Use string_file. * gdbtypes.c (safe_parse_type): Use null_stream. * guile/scm-breakpoint.c (gdbscm_breakpoint_commands): Use string_file. * guile/scm-disasm.c (gdbscm_print_insn_from_port): Take a 'string_file *' instead of a 'ui_file *'. (gdbscm_arch_disassemble): Use string_file. * guile/scm-frame.c (frscm_print_frame_smob): Use string_file. * guile/scm-ports.c (class ioscm_file_port): Now a class that inherits from ui_file. (ioscm_file_port_delete, ioscm_file_port_rewind) (ioscm_file_port_put): Delete. (ioscm_file_port_write): Rename to ... (ioscm_file_port::write): ... this. Remove file_port_magic checks. (ioscm_file_port_new): Delete. (ioscm_with_output_to_port_worker): Use ioscm_file_port and ui_file_up. * guile/scm-type.c (tyscm_type_name): Use string_file. * guile/scm-value.c (vlscm_print_value_smob, gdbscm_value_print): Use string_file. * infcmd.c (print_return_value_1): Use string_file. * infrun.c (print_target_wait_results): Use string_file. * language.c (add_language): Use string_file. * location.c (explicit_to_string_internal): Use string_file. * main.c (captured_main_1): Use null_file. * maint.c (maintenance_print_architecture): Use stdio_file. * mi/mi-cmd-stack.c (list_arg_or_local): Use string_file. * mi/mi-common.h (struct mi_interp) <out, err, log, targ, event_channel>: Change type to mi_console_file pointer. * mi/mi-console.c (mi_console_file_fputs, mi_console_file_flush) (mi_console_file_delete): Delete. (struct mi_console_file): Delete. (mi_console_file_magic): Delete. (mi_console_file_new): Delete. (mi_console_file::mi_console_file): New. (mi_console_file_delete): Delete. (mi_console_file_fputs): Delete. (mi_console_file::write): New. (mi_console_raw_packet): Delete. (mi_console_file::flush): New. (mi_console_file_flush): Delete. (mi_console_set_raw): Rename to ... (mi_console_file::set_raw): ... this. * mi/mi-console.h (class mi_console_file): New class. (mi_console_file_new, mi_console_set_raw): Delete. * mi/mi-interp.c (mi_interpreter_init): Use mi_console_file. (mi_set_logging): Use delete and tee_file. Adjust. * mi/mi-main.c (output_register): Use string_file. (mi_cmd_data_evaluate_expression): Use string_file. (mi_cmd_data_read_memory): Use string_file. (mi_cmd_execute, print_variable_or_computed): Use string_file. * mi/mi-out.c (mi_ui_out::main_stream): New. (mi_ui_out::rewind): Use main_stream and string_file. (mi_ui_out::put): Use main_stream and string_file. (mi_ui_out::mi_ui_out): Remove 'stream' parameter. Allocate a 'string_file' instead. (mi_out_new): Don't allocate a mem_fileopen stream here. * mi/mi-out.h (mi_ui_out::mi_ui_out): Remove 'stream' parameter. (mi_ui_out::main_stream): Declare method. * printcmd.c (eval_command): Use string_file. * psymtab.c (maintenance_print_psymbols): Use stdio_file. * python/py-arch.c (archpy_disassemble): Use string_file. * python/py-breakpoint.c (bppy_get_commands): Use string_file. * python/py-frame.c (frapy_str): Use string_file. * python/py-framefilter.c (py_print_type, py_print_single_arg): Use string_file. * python/py-type.c (typy_str): Use string_file. * python/py-unwind.c (unwind_infopy_str): Use string_file. * python/py-value.c (valpy_str): Use string_file. * record-btrace.c (btrace_insn_history): Use string_file. * regcache.c (regcache_print): Use stdio_file. * reggroups.c (maintenance_print_reggroups): Use stdio_file. * remote.c (escape_buffer): Use string_file. * rust-lang.c (rust_get_disr_info): Use string_file. * serial.c (serial_open_ops_1): Use stdio_file. (do_serial_close): Use delete. * stack.c (print_frame_arg): Use string_file. (print_frame_args): Remove local mem_fileopen stream, not used. (print_frame): Use string_file. * symmisc.c (maintenance_print_symbols): Use stdio_file. * symtab.h (struct symbol_computed_ops) <generate_c_location>: Take a 'string_file *' instead of a 'ui_file *'. * top.c (new_ui): Use stdio_file and stderr_file. (free_ui): Use delete. (execute_command_to_string): Use string_file. (quit_confirm): Use string_file. * tracepoint.c (collection_list::append_exp): Use string_file. * tui/tui-disasm.c (tui_disassemble): Use string_file. * tui/tui-file.c: Don't include "ui-file.h". (enum streamtype, struct tui_stream): Delete. (tui_file_new, tui_file_delete, tui_fileopen, tui_sfileopen) (tui_file_isatty, tui_file_rewind, tui_file_put): Delete. (tui_file::tui_file): New method. (tui_file_fputs): Delete. (tui_file_get_strbuf): Delete. (tui_file::puts): New method. (tui_file_adjust_strbuf): Delete. (tui_file_flush): Delete. (tui_file::flush): New method. * tui/tui-file.h: Tweak intro comment. Include ui-file.h. (tui_fileopen, tui_sfileopen, tui_file_get_strbuf) (tui_file_adjust_strbuf): Delete declarations. (class tui_file): New class. * tui/tui-io.c (tui_initialize_io): Use tui_file. * tui/tui-regs.c (tui_restore_gdbout): Use delete. (tui_register_format): Use string_stream. * tui/tui-stack.c (tui_make_status_line): Use string_file. (tui_get_function_from_frame): Use string_file. * typeprint.c (type_to_string): Use string_file. * ui-file.c (struct ui_file, ui_file_magic, ui_file_new): Delete. (null_stream): New global. (ui_file_delete): Delete. (ui_file::ui_file): New. (null_file_isatty): Delete. (ui_file::~ui_file): New. (null_file_rewind): Delete. (ui_file::printf): New. (null_file_put): Delete. (null_file_flush): Delete. (ui_file::putstr): New. (null_file_write): Delete. (ui_file::putstrn): New. (null_file_read): Delete. (ui_file::putc): New. (null_file_fputs): Delete. (null_file_write_async_safe): Delete. (ui_file::vprintf): New. (null_file_delete): Delete. (null_file::write): New. (null_file_fseek): Delete. (null_file::puts): New. (ui_file_data): Delete. (null_file::write_async_safe): New. (gdb_flush, ui_file_isatty): Adjust. (ui_file_put, ui_file_rewind): Delete. (ui_file_write): Adjust. (ui_file_write_for_put): Delete. (ui_file_write_async_safe, ui_file_read): Adjust. (ui_file_fseek): Delete. (fputs_unfiltered): Adjust. (set_ui_file_flush, set_ui_file_isatty, set_ui_file_rewind) (set_ui_file_put, set_ui_file_write, set_ui_file_write_async_safe) (set_ui_file_read, set_ui_file_fputs, set_ui_file_fseek) (set_ui_file_data): Delete. (string_file::~string_file, string_file::write) (struct accumulated_ui_file, do_ui_file_xstrdup, ui_file_xstrdup) (do_ui_file_as_string, ui_file_as_string): Delete. (do_ui_file_obsavestring, ui_file_obsavestring): Delete. (struct mem_file): Delete. (mem_file_new): Delete. (stdio_file::stdio_file): New. (mem_file_delete): Delete. (stdio_file::stdio_file): New. (mem_fileopen): Delete. (stdio_file::~stdio_file): New. (mem_file_rewind): Delete. (stdio_file::set_stream): New. (mem_file_put): Delete. (stdio_file::open): New. (mem_file_write): Delete. (stdio_file_magic, struct stdio_file): Delete. (stdio_file_new, stdio_file_delete, stdio_file_flush): Delete. (stdio_file::flush): New. (stdio_file_read): Rename to ... (stdio_file::read): ... this. Adjust. (stdio_file_write): Rename to ... (stdio_file::write): ... this. Adjust. (stdio_file_write_async_safe): Rename to ... (stdio_file::write_async_safe) ... this. Adjust. (stdio_file_fputs): Rename to ... (stdio_file::puts) ... this. Adjust. (stdio_file_isatty): Delete. (stdio_file_fseek): Delete. (stdio_file::isatty): New. (stderr_file_write): Rename to ... (stderr_file::write) ... this. Adjust. (stderr_file_fputs): Rename to ... (stderr_file::puts) ... this. Adjust. (stderr_fileopen, stdio_fileopen, gdb_fopen): Delete. (stderr_file::stderr_file): New. (tee_file_magic): Delete. (struct tee_file): Delete. (tee_file::tee_file): New. (tee_file_new): Delete. (tee_file::~tee_file): New. (tee_file_delete): Delete. (tee_file_flush): Rename to ... (tee_file::flush): ... this. Adjust. (tee_file_write): Rename to ... (tee_file::write): ... this. Adjust. (tee_file::write_async_safe): New. (tee_file_fputs): Rename to ... (tee_file::puts): ... this. Adjust. (tee_file_isatty): Rename to ... (tee_file::isatty): ... this. Adjust. * ui-file.h (struct obstack, struct ui_file): Don't forward-declare. (ui_file_new, ui_file_flush_ftype, set_ui_file_flush) (ui_file_write_ftype) (set_ui_file_write, ui_file_fputs_ftype, set_ui_file_fputs) (ui_file_write_async_safe_ftype, set_ui_file_write_async_safe) (ui_file_read_ftype, set_ui_file_read, ui_file_isatty_ftype) (set_ui_file_isatty, ui_file_rewind_ftype, set_ui_file_rewind) (ui_file_put_method_ftype, ui_file_put_ftype, set_ui_file_put) (ui_file_delete_ftype, set_ui_file_data, ui_file_fseek_ftype) (set_ui_file_fseek): Delete. (ui_file_data, ui_file_delete, ui_file_rewind) (struct ui_file): New. (ui_file_up): New. (class null_file): New. (null_stream): Declare. (ui_file_write_for_put, ui_file_put): Delete. (ui_file_xstrdup, ui_file_as_string, ui_file_obsavestring): Delete. (ui_file_fseek, mem_fileopen, stdio_fileopen, stderr_fileopen) (gdb_fopen, tee_file_new): Delete. (struct string_file): New. (struct stdio_file): New. (stdio_file_up): New. (struct stderr_file): New. (class tee_file): New. * ui-out.c (ui_out::field_stream): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * ui-out.h (class ui_out) <field_stream>: Likewise. * utils.c (do_ui_file_delete, make_cleanup_ui_file_delete) (null_stream): Delete. (error_stream): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * utils.h (struct ui_file): Delete forward declaration.. (make_cleanup_ui_file_delete, null_stream): Delete declarations. (error_stream): Take a 'string_file &' instead of a 'ui_file *'. * varobj.c (varobj_value_get_print_value): Use string_file. * xtensa-tdep.c (xtensa_verify_config): Use string_file. * gdbarch.c: Regenerate.
2017-02-02 12:11:47 +01:00
buf.write (d_left (comp)->u.s_name.s, d_left (comp)->u.s_name.len);
newobj.type = DEMANGLE_COMPONENT_NAME;
newobj.u.s_name.s = obstack_strdup (&info->obstack, buf.string ());
newobj.u.s_name.len = buf.size ();
if (inspect_type (info, &newobj, finder, data))
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
{
char *s;
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
long slen;
/* A typedef was substituted in NEW. Convert it to a
string and replace the top DEMANGLE_COMPONENT_QUAL_NAME
node. */
Eliminate make_cleanup_ui_file_delete / make ui_file a class hierarchy This patch starts from the desire to eliminate make_cleanup_ui_file_delete, but then goes beyond. It makes ui_file & friends a real C++ class hierarchy, and switches temporary ui_file-like objects to stack-based allocation. - mem_fileopen -> string_file mem_fileopen is replaced with a new string_file class that is treated as a value class created on the stack. This alone eliminates most make_cleanup_ui_file_delete calls, and, simplifies code a whole lot (diffstat shows around 1k loc dropped.) string_file's internal buffer is a std::string, thus the "string" in the name. This simplifies the implementation much, compared to mem_fileopen, which managed growing its internal buffer manually. - ui_file_as_string, ui_file_strdup, ui_file_obsavestring all gone The new string_file class has a string() method that provides direct writable access to the internal std::string buffer. This replaced ui_file_as_string, which forced a copy of the same data the stream had inside. With direct access via a writable reference, we can instead move the string out of the string_stream, avoiding deep string copying. Related, ui_file_xstrdup calls are replaced with xstrdup'ping the stream's string, and ui_file_obsavestring is replaced by obstack_copy0. With all those out of the way, getting rid of the weird ui_file_put mechanism was possible. - New ui_file::printf, ui_file::puts, etc. methods These simplify / clarify client code. I considered splitting client-code changes, like these, e.g.: - stb = mem_fileopen (); - fprintf_unfiltered (stb, "%s%s%s", - _("The valid values are:\n"), - regdesc, - _("The default is \"std\".")); + string_file stb; + stb.printf ("%s%s%s", + _("The valid values are:\n"), + regdesc, + _("The default is \"std\".")); In two steps, with the first step leaving fprintf_unfiltered (etc.) calls in place, and only afterwards do a pass to change all those to call stb.printf etc.. I didn't do that split, because (when I tried), it turned out to be pointless make-work: the first pass would have to touch the fprintf_unfiltered line anyway, to replace "stb" with "&stb". - gdb_fopen replaced with stack-based objects This avoids the need for cleanups or unique_ptr's. I.e., this: struct ui_file *file = gdb_fopen (filename, "w"); if (filename == NULL) perror_with_name (filename); cleanups = make_cleanup_ui_file_delete (file); // use file. do_cleanups (cleanups); is replaced with this: stdio_file file; if (!file.open (filename, "w")) perror_with_name (filename); // use file. - odd contorsions in null_file_write / null_file_fputs around when to call to_fputs / to_write eliminated. - Global null_stream object A few places that were allocating a ui_file in order to print to "nowhere" are adjusted to instead refer to a new 'null_stream' global stream. - TUI's tui_sfileopen eliminated. TUI's ui_file much simplified The TUI's ui_file was serving a dual purpose. It supported being used as string buffer, and supported being backed by a stdio FILE. The string buffer part is gone, replaced by using of string_file. The 'FILE *' support is now much simplified, by making the TUI's ui_file inherit from stdio_file. gdb/ChangeLog: 2017-02-02 Pedro Alves <palves@redhat.com> * ada-lang.c (type_as_string): Use string_file. * ada-valprint.c (ada_print_floating): Use string_file. * ada-varobj.c (ada_varobj_scalar_image) (ada_varobj_get_value_image): Use string_file. * aix-thread.c (aix_thread_extra_thread_info): Use string_file. * arm-tdep.c (_initialize_arm_tdep): Use string_printf. * breakpoint.c (update_inserted_breakpoint_locations) (insert_breakpoint_locations, reattach_breakpoints) (print_breakpoint_location, print_one_detail_ranged_breakpoint) (print_it_watchpoint): Use string_file. (save_breakpoints): Use stdio_file. * c-exp.y (oper): Use string_file. * cli/cli-logging.c (set_logging_redirect): Use ui_file_up and tee_file. (pop_output_files): Use delete. (handle_redirections): Use stdio_file and tee_file. * cli/cli-setshow.c (do_show_command): Use string_file. * compile/compile-c-support.c (c_compute_program): Use string_file. * compile/compile-c-symbols.c (generate_vla_size): Take a 'string_file &' instead of a 'ui_file *'. (generate_c_for_for_one_variable): Take a 'string_file &' instead of a 'ui_file *'. Use string_file. (generate_c_for_variable_locations): Take a 'string_file &' instead of a 'ui_file *'. * compile/compile-internal.h (generate_c_for_for_one_variable): Take a 'string_file &' instead of a 'ui_file *'. * compile/compile-loc2c.c (push, pushf, unary, binary) (print_label, pushf_register_address, pushf_register) (do_compile_dwarf_expr_to_c): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * compile/compile.c (compile_to_object): Use string_file. * compile/compile.h (compile_dwarf_expr_to_c) (compile_dwarf_bounds_to_c): Take a 'string_file &' instead of a 'ui_file *'. * cp-support.c (inspect_type): Use string_file and obstack_copy0. (replace_typedefs_qualified_name): Use string_file and obstack_copy0. * disasm.c (gdb_pretty_print_insn): Use string_file. (gdb_disassembly): Adjust reference the null_stream global. (do_ui_file_delete): Delete. (gdb_insn_length): Use null_stream. * dummy-frame.c (maintenance_print_dummy_frames): Use stdio_file. * dwarf2loc.c (dwarf2_compile_property_to_c) (locexpr_generate_c_location, loclist_generate_c_location): Take a 'string_file &' instead of a 'ui_file *'. * dwarf2loc.h (dwarf2_compile_property_to_c): Likewise. * dwarf2read.c (do_ui_file_peek_last): Delete. (dwarf2_compute_name): Use string_file. * event-top.c (gdb_setup_readline): Use stdio_file. * gdbarch.sh (verify_gdbarch): Use string_file. * gdbtypes.c (safe_parse_type): Use null_stream. * guile/scm-breakpoint.c (gdbscm_breakpoint_commands): Use string_file. * guile/scm-disasm.c (gdbscm_print_insn_from_port): Take a 'string_file *' instead of a 'ui_file *'. (gdbscm_arch_disassemble): Use string_file. * guile/scm-frame.c (frscm_print_frame_smob): Use string_file. * guile/scm-ports.c (class ioscm_file_port): Now a class that inherits from ui_file. (ioscm_file_port_delete, ioscm_file_port_rewind) (ioscm_file_port_put): Delete. (ioscm_file_port_write): Rename to ... (ioscm_file_port::write): ... this. Remove file_port_magic checks. (ioscm_file_port_new): Delete. (ioscm_with_output_to_port_worker): Use ioscm_file_port and ui_file_up. * guile/scm-type.c (tyscm_type_name): Use string_file. * guile/scm-value.c (vlscm_print_value_smob, gdbscm_value_print): Use string_file. * infcmd.c (print_return_value_1): Use string_file. * infrun.c (print_target_wait_results): Use string_file. * language.c (add_language): Use string_file. * location.c (explicit_to_string_internal): Use string_file. * main.c (captured_main_1): Use null_file. * maint.c (maintenance_print_architecture): Use stdio_file. * mi/mi-cmd-stack.c (list_arg_or_local): Use string_file. * mi/mi-common.h (struct mi_interp) <out, err, log, targ, event_channel>: Change type to mi_console_file pointer. * mi/mi-console.c (mi_console_file_fputs, mi_console_file_flush) (mi_console_file_delete): Delete. (struct mi_console_file): Delete. (mi_console_file_magic): Delete. (mi_console_file_new): Delete. (mi_console_file::mi_console_file): New. (mi_console_file_delete): Delete. (mi_console_file_fputs): Delete. (mi_console_file::write): New. (mi_console_raw_packet): Delete. (mi_console_file::flush): New. (mi_console_file_flush): Delete. (mi_console_set_raw): Rename to ... (mi_console_file::set_raw): ... this. * mi/mi-console.h (class mi_console_file): New class. (mi_console_file_new, mi_console_set_raw): Delete. * mi/mi-interp.c (mi_interpreter_init): Use mi_console_file. (mi_set_logging): Use delete and tee_file. Adjust. * mi/mi-main.c (output_register): Use string_file. (mi_cmd_data_evaluate_expression): Use string_file. (mi_cmd_data_read_memory): Use string_file. (mi_cmd_execute, print_variable_or_computed): Use string_file. * mi/mi-out.c (mi_ui_out::main_stream): New. (mi_ui_out::rewind): Use main_stream and string_file. (mi_ui_out::put): Use main_stream and string_file. (mi_ui_out::mi_ui_out): Remove 'stream' parameter. Allocate a 'string_file' instead. (mi_out_new): Don't allocate a mem_fileopen stream here. * mi/mi-out.h (mi_ui_out::mi_ui_out): Remove 'stream' parameter. (mi_ui_out::main_stream): Declare method. * printcmd.c (eval_command): Use string_file. * psymtab.c (maintenance_print_psymbols): Use stdio_file. * python/py-arch.c (archpy_disassemble): Use string_file. * python/py-breakpoint.c (bppy_get_commands): Use string_file. * python/py-frame.c (frapy_str): Use string_file. * python/py-framefilter.c (py_print_type, py_print_single_arg): Use string_file. * python/py-type.c (typy_str): Use string_file. * python/py-unwind.c (unwind_infopy_str): Use string_file. * python/py-value.c (valpy_str): Use string_file. * record-btrace.c (btrace_insn_history): Use string_file. * regcache.c (regcache_print): Use stdio_file. * reggroups.c (maintenance_print_reggroups): Use stdio_file. * remote.c (escape_buffer): Use string_file. * rust-lang.c (rust_get_disr_info): Use string_file. * serial.c (serial_open_ops_1): Use stdio_file. (do_serial_close): Use delete. * stack.c (print_frame_arg): Use string_file. (print_frame_args): Remove local mem_fileopen stream, not used. (print_frame): Use string_file. * symmisc.c (maintenance_print_symbols): Use stdio_file. * symtab.h (struct symbol_computed_ops) <generate_c_location>: Take a 'string_file *' instead of a 'ui_file *'. * top.c (new_ui): Use stdio_file and stderr_file. (free_ui): Use delete. (execute_command_to_string): Use string_file. (quit_confirm): Use string_file. * tracepoint.c (collection_list::append_exp): Use string_file. * tui/tui-disasm.c (tui_disassemble): Use string_file. * tui/tui-file.c: Don't include "ui-file.h". (enum streamtype, struct tui_stream): Delete. (tui_file_new, tui_file_delete, tui_fileopen, tui_sfileopen) (tui_file_isatty, tui_file_rewind, tui_file_put): Delete. (tui_file::tui_file): New method. (tui_file_fputs): Delete. (tui_file_get_strbuf): Delete. (tui_file::puts): New method. (tui_file_adjust_strbuf): Delete. (tui_file_flush): Delete. (tui_file::flush): New method. * tui/tui-file.h: Tweak intro comment. Include ui-file.h. (tui_fileopen, tui_sfileopen, tui_file_get_strbuf) (tui_file_adjust_strbuf): Delete declarations. (class tui_file): New class. * tui/tui-io.c (tui_initialize_io): Use tui_file. * tui/tui-regs.c (tui_restore_gdbout): Use delete. (tui_register_format): Use string_stream. * tui/tui-stack.c (tui_make_status_line): Use string_file. (tui_get_function_from_frame): Use string_file. * typeprint.c (type_to_string): Use string_file. * ui-file.c (struct ui_file, ui_file_magic, ui_file_new): Delete. (null_stream): New global. (ui_file_delete): Delete. (ui_file::ui_file): New. (null_file_isatty): Delete. (ui_file::~ui_file): New. (null_file_rewind): Delete. (ui_file::printf): New. (null_file_put): Delete. (null_file_flush): Delete. (ui_file::putstr): New. (null_file_write): Delete. (ui_file::putstrn): New. (null_file_read): Delete. (ui_file::putc): New. (null_file_fputs): Delete. (null_file_write_async_safe): Delete. (ui_file::vprintf): New. (null_file_delete): Delete. (null_file::write): New. (null_file_fseek): Delete. (null_file::puts): New. (ui_file_data): Delete. (null_file::write_async_safe): New. (gdb_flush, ui_file_isatty): Adjust. (ui_file_put, ui_file_rewind): Delete. (ui_file_write): Adjust. (ui_file_write_for_put): Delete. (ui_file_write_async_safe, ui_file_read): Adjust. (ui_file_fseek): Delete. (fputs_unfiltered): Adjust. (set_ui_file_flush, set_ui_file_isatty, set_ui_file_rewind) (set_ui_file_put, set_ui_file_write, set_ui_file_write_async_safe) (set_ui_file_read, set_ui_file_fputs, set_ui_file_fseek) (set_ui_file_data): Delete. (string_file::~string_file, string_file::write) (struct accumulated_ui_file, do_ui_file_xstrdup, ui_file_xstrdup) (do_ui_file_as_string, ui_file_as_string): Delete. (do_ui_file_obsavestring, ui_file_obsavestring): Delete. (struct mem_file): Delete. (mem_file_new): Delete. (stdio_file::stdio_file): New. (mem_file_delete): Delete. (stdio_file::stdio_file): New. (mem_fileopen): Delete. (stdio_file::~stdio_file): New. (mem_file_rewind): Delete. (stdio_file::set_stream): New. (mem_file_put): Delete. (stdio_file::open): New. (mem_file_write): Delete. (stdio_file_magic, struct stdio_file): Delete. (stdio_file_new, stdio_file_delete, stdio_file_flush): Delete. (stdio_file::flush): New. (stdio_file_read): Rename to ... (stdio_file::read): ... this. Adjust. (stdio_file_write): Rename to ... (stdio_file::write): ... this. Adjust. (stdio_file_write_async_safe): Rename to ... (stdio_file::write_async_safe) ... this. Adjust. (stdio_file_fputs): Rename to ... (stdio_file::puts) ... this. Adjust. (stdio_file_isatty): Delete. (stdio_file_fseek): Delete. (stdio_file::isatty): New. (stderr_file_write): Rename to ... (stderr_file::write) ... this. Adjust. (stderr_file_fputs): Rename to ... (stderr_file::puts) ... this. Adjust. (stderr_fileopen, stdio_fileopen, gdb_fopen): Delete. (stderr_file::stderr_file): New. (tee_file_magic): Delete. (struct tee_file): Delete. (tee_file::tee_file): New. (tee_file_new): Delete. (tee_file::~tee_file): New. (tee_file_delete): Delete. (tee_file_flush): Rename to ... (tee_file::flush): ... this. Adjust. (tee_file_write): Rename to ... (tee_file::write): ... this. Adjust. (tee_file::write_async_safe): New. (tee_file_fputs): Rename to ... (tee_file::puts): ... this. Adjust. (tee_file_isatty): Rename to ... (tee_file::isatty): ... this. Adjust. * ui-file.h (struct obstack, struct ui_file): Don't forward-declare. (ui_file_new, ui_file_flush_ftype, set_ui_file_flush) (ui_file_write_ftype) (set_ui_file_write, ui_file_fputs_ftype, set_ui_file_fputs) (ui_file_write_async_safe_ftype, set_ui_file_write_async_safe) (ui_file_read_ftype, set_ui_file_read, ui_file_isatty_ftype) (set_ui_file_isatty, ui_file_rewind_ftype, set_ui_file_rewind) (ui_file_put_method_ftype, ui_file_put_ftype, set_ui_file_put) (ui_file_delete_ftype, set_ui_file_data, ui_file_fseek_ftype) (set_ui_file_fseek): Delete. (ui_file_data, ui_file_delete, ui_file_rewind) (struct ui_file): New. (ui_file_up): New. (class null_file): New. (null_stream): Declare. (ui_file_write_for_put, ui_file_put): Delete. (ui_file_xstrdup, ui_file_as_string, ui_file_obsavestring): Delete. (ui_file_fseek, mem_fileopen, stdio_fileopen, stderr_fileopen) (gdb_fopen, tee_file_new): Delete. (struct string_file): New. (struct stdio_file): New. (stdio_file_up): New. (struct stderr_file): New. (class tee_file): New. * ui-out.c (ui_out::field_stream): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * ui-out.h (class ui_out) <field_stream>: Likewise. * utils.c (do_ui_file_delete, make_cleanup_ui_file_delete) (null_stream): Delete. (error_stream): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * utils.h (struct ui_file): Delete forward declaration.. (make_cleanup_ui_file_delete, null_stream): Delete declarations. (error_stream): Take a 'string_file &' instead of a 'ui_file *'. * varobj.c (varobj_value_get_print_value): Use string_file. * xtensa-tdep.c (xtensa_verify_config): Use string_file. * gdbarch.c: Regenerate.
2017-02-02 12:11:47 +01:00
buf.clear ();
gdb::unique_xmalloc_ptr<char> n
= cp_comp_to_string (&newobj, 100);
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
if (n == NULL)
{
/* If something went astray, abort typedef substitutions. */
return;
}
s = copy_string_to_obstack (&info->obstack, n.get (), &slen);
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
d_left (ret_comp)->type = DEMANGLE_COMPONENT_NAME;
d_left (ret_comp)->u.s_name.s = s;
d_left (ret_comp)->u.s_name.len = slen;
d_right (ret_comp) = d_right (comp);
comp = ret_comp;
continue;
}
}
else
{
/* The current node is not a name, so simply replace any
typedefs in it. Then print it to the stream to continue
checking for more typedefs in the tree. */
replace_typedefs (info, d_left (comp), finder, data);
gdb::unique_xmalloc_ptr<char> name
= cp_comp_to_string (d_left (comp), 100);
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
if (name == NULL)
{
/* If something went astray, abort typedef substitutions. */
return;
}
buf.puts (name.get ());
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
}
Eliminate make_cleanup_ui_file_delete / make ui_file a class hierarchy This patch starts from the desire to eliminate make_cleanup_ui_file_delete, but then goes beyond. It makes ui_file & friends a real C++ class hierarchy, and switches temporary ui_file-like objects to stack-based allocation. - mem_fileopen -> string_file mem_fileopen is replaced with a new string_file class that is treated as a value class created on the stack. This alone eliminates most make_cleanup_ui_file_delete calls, and, simplifies code a whole lot (diffstat shows around 1k loc dropped.) string_file's internal buffer is a std::string, thus the "string" in the name. This simplifies the implementation much, compared to mem_fileopen, which managed growing its internal buffer manually. - ui_file_as_string, ui_file_strdup, ui_file_obsavestring all gone The new string_file class has a string() method that provides direct writable access to the internal std::string buffer. This replaced ui_file_as_string, which forced a copy of the same data the stream had inside. With direct access via a writable reference, we can instead move the string out of the string_stream, avoiding deep string copying. Related, ui_file_xstrdup calls are replaced with xstrdup'ping the stream's string, and ui_file_obsavestring is replaced by obstack_copy0. With all those out of the way, getting rid of the weird ui_file_put mechanism was possible. - New ui_file::printf, ui_file::puts, etc. methods These simplify / clarify client code. I considered splitting client-code changes, like these, e.g.: - stb = mem_fileopen (); - fprintf_unfiltered (stb, "%s%s%s", - _("The valid values are:\n"), - regdesc, - _("The default is \"std\".")); + string_file stb; + stb.printf ("%s%s%s", + _("The valid values are:\n"), + regdesc, + _("The default is \"std\".")); In two steps, with the first step leaving fprintf_unfiltered (etc.) calls in place, and only afterwards do a pass to change all those to call stb.printf etc.. I didn't do that split, because (when I tried), it turned out to be pointless make-work: the first pass would have to touch the fprintf_unfiltered line anyway, to replace "stb" with "&stb". - gdb_fopen replaced with stack-based objects This avoids the need for cleanups or unique_ptr's. I.e., this: struct ui_file *file = gdb_fopen (filename, "w"); if (filename == NULL) perror_with_name (filename); cleanups = make_cleanup_ui_file_delete (file); // use file. do_cleanups (cleanups); is replaced with this: stdio_file file; if (!file.open (filename, "w")) perror_with_name (filename); // use file. - odd contorsions in null_file_write / null_file_fputs around when to call to_fputs / to_write eliminated. - Global null_stream object A few places that were allocating a ui_file in order to print to "nowhere" are adjusted to instead refer to a new 'null_stream' global stream. - TUI's tui_sfileopen eliminated. TUI's ui_file much simplified The TUI's ui_file was serving a dual purpose. It supported being used as string buffer, and supported being backed by a stdio FILE. The string buffer part is gone, replaced by using of string_file. The 'FILE *' support is now much simplified, by making the TUI's ui_file inherit from stdio_file. gdb/ChangeLog: 2017-02-02 Pedro Alves <palves@redhat.com> * ada-lang.c (type_as_string): Use string_file. * ada-valprint.c (ada_print_floating): Use string_file. * ada-varobj.c (ada_varobj_scalar_image) (ada_varobj_get_value_image): Use string_file. * aix-thread.c (aix_thread_extra_thread_info): Use string_file. * arm-tdep.c (_initialize_arm_tdep): Use string_printf. * breakpoint.c (update_inserted_breakpoint_locations) (insert_breakpoint_locations, reattach_breakpoints) (print_breakpoint_location, print_one_detail_ranged_breakpoint) (print_it_watchpoint): Use string_file. (save_breakpoints): Use stdio_file. * c-exp.y (oper): Use string_file. * cli/cli-logging.c (set_logging_redirect): Use ui_file_up and tee_file. (pop_output_files): Use delete. (handle_redirections): Use stdio_file and tee_file. * cli/cli-setshow.c (do_show_command): Use string_file. * compile/compile-c-support.c (c_compute_program): Use string_file. * compile/compile-c-symbols.c (generate_vla_size): Take a 'string_file &' instead of a 'ui_file *'. (generate_c_for_for_one_variable): Take a 'string_file &' instead of a 'ui_file *'. Use string_file. (generate_c_for_variable_locations): Take a 'string_file &' instead of a 'ui_file *'. * compile/compile-internal.h (generate_c_for_for_one_variable): Take a 'string_file &' instead of a 'ui_file *'. * compile/compile-loc2c.c (push, pushf, unary, binary) (print_label, pushf_register_address, pushf_register) (do_compile_dwarf_expr_to_c): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * compile/compile.c (compile_to_object): Use string_file. * compile/compile.h (compile_dwarf_expr_to_c) (compile_dwarf_bounds_to_c): Take a 'string_file &' instead of a 'ui_file *'. * cp-support.c (inspect_type): Use string_file and obstack_copy0. (replace_typedefs_qualified_name): Use string_file and obstack_copy0. * disasm.c (gdb_pretty_print_insn): Use string_file. (gdb_disassembly): Adjust reference the null_stream global. (do_ui_file_delete): Delete. (gdb_insn_length): Use null_stream. * dummy-frame.c (maintenance_print_dummy_frames): Use stdio_file. * dwarf2loc.c (dwarf2_compile_property_to_c) (locexpr_generate_c_location, loclist_generate_c_location): Take a 'string_file &' instead of a 'ui_file *'. * dwarf2loc.h (dwarf2_compile_property_to_c): Likewise. * dwarf2read.c (do_ui_file_peek_last): Delete. (dwarf2_compute_name): Use string_file. * event-top.c (gdb_setup_readline): Use stdio_file. * gdbarch.sh (verify_gdbarch): Use string_file. * gdbtypes.c (safe_parse_type): Use null_stream. * guile/scm-breakpoint.c (gdbscm_breakpoint_commands): Use string_file. * guile/scm-disasm.c (gdbscm_print_insn_from_port): Take a 'string_file *' instead of a 'ui_file *'. (gdbscm_arch_disassemble): Use string_file. * guile/scm-frame.c (frscm_print_frame_smob): Use string_file. * guile/scm-ports.c (class ioscm_file_port): Now a class that inherits from ui_file. (ioscm_file_port_delete, ioscm_file_port_rewind) (ioscm_file_port_put): Delete. (ioscm_file_port_write): Rename to ... (ioscm_file_port::write): ... this. Remove file_port_magic checks. (ioscm_file_port_new): Delete. (ioscm_with_output_to_port_worker): Use ioscm_file_port and ui_file_up. * guile/scm-type.c (tyscm_type_name): Use string_file. * guile/scm-value.c (vlscm_print_value_smob, gdbscm_value_print): Use string_file. * infcmd.c (print_return_value_1): Use string_file. * infrun.c (print_target_wait_results): Use string_file. * language.c (add_language): Use string_file. * location.c (explicit_to_string_internal): Use string_file. * main.c (captured_main_1): Use null_file. * maint.c (maintenance_print_architecture): Use stdio_file. * mi/mi-cmd-stack.c (list_arg_or_local): Use string_file. * mi/mi-common.h (struct mi_interp) <out, err, log, targ, event_channel>: Change type to mi_console_file pointer. * mi/mi-console.c (mi_console_file_fputs, mi_console_file_flush) (mi_console_file_delete): Delete. (struct mi_console_file): Delete. (mi_console_file_magic): Delete. (mi_console_file_new): Delete. (mi_console_file::mi_console_file): New. (mi_console_file_delete): Delete. (mi_console_file_fputs): Delete. (mi_console_file::write): New. (mi_console_raw_packet): Delete. (mi_console_file::flush): New. (mi_console_file_flush): Delete. (mi_console_set_raw): Rename to ... (mi_console_file::set_raw): ... this. * mi/mi-console.h (class mi_console_file): New class. (mi_console_file_new, mi_console_set_raw): Delete. * mi/mi-interp.c (mi_interpreter_init): Use mi_console_file. (mi_set_logging): Use delete and tee_file. Adjust. * mi/mi-main.c (output_register): Use string_file. (mi_cmd_data_evaluate_expression): Use string_file. (mi_cmd_data_read_memory): Use string_file. (mi_cmd_execute, print_variable_or_computed): Use string_file. * mi/mi-out.c (mi_ui_out::main_stream): New. (mi_ui_out::rewind): Use main_stream and string_file. (mi_ui_out::put): Use main_stream and string_file. (mi_ui_out::mi_ui_out): Remove 'stream' parameter. Allocate a 'string_file' instead. (mi_out_new): Don't allocate a mem_fileopen stream here. * mi/mi-out.h (mi_ui_out::mi_ui_out): Remove 'stream' parameter. (mi_ui_out::main_stream): Declare method. * printcmd.c (eval_command): Use string_file. * psymtab.c (maintenance_print_psymbols): Use stdio_file. * python/py-arch.c (archpy_disassemble): Use string_file. * python/py-breakpoint.c (bppy_get_commands): Use string_file. * python/py-frame.c (frapy_str): Use string_file. * python/py-framefilter.c (py_print_type, py_print_single_arg): Use string_file. * python/py-type.c (typy_str): Use string_file. * python/py-unwind.c (unwind_infopy_str): Use string_file. * python/py-value.c (valpy_str): Use string_file. * record-btrace.c (btrace_insn_history): Use string_file. * regcache.c (regcache_print): Use stdio_file. * reggroups.c (maintenance_print_reggroups): Use stdio_file. * remote.c (escape_buffer): Use string_file. * rust-lang.c (rust_get_disr_info): Use string_file. * serial.c (serial_open_ops_1): Use stdio_file. (do_serial_close): Use delete. * stack.c (print_frame_arg): Use string_file. (print_frame_args): Remove local mem_fileopen stream, not used. (print_frame): Use string_file. * symmisc.c (maintenance_print_symbols): Use stdio_file. * symtab.h (struct symbol_computed_ops) <generate_c_location>: Take a 'string_file *' instead of a 'ui_file *'. * top.c (new_ui): Use stdio_file and stderr_file. (free_ui): Use delete. (execute_command_to_string): Use string_file. (quit_confirm): Use string_file. * tracepoint.c (collection_list::append_exp): Use string_file. * tui/tui-disasm.c (tui_disassemble): Use string_file. * tui/tui-file.c: Don't include "ui-file.h". (enum streamtype, struct tui_stream): Delete. (tui_file_new, tui_file_delete, tui_fileopen, tui_sfileopen) (tui_file_isatty, tui_file_rewind, tui_file_put): Delete. (tui_file::tui_file): New method. (tui_file_fputs): Delete. (tui_file_get_strbuf): Delete. (tui_file::puts): New method. (tui_file_adjust_strbuf): Delete. (tui_file_flush): Delete. (tui_file::flush): New method. * tui/tui-file.h: Tweak intro comment. Include ui-file.h. (tui_fileopen, tui_sfileopen, tui_file_get_strbuf) (tui_file_adjust_strbuf): Delete declarations. (class tui_file): New class. * tui/tui-io.c (tui_initialize_io): Use tui_file. * tui/tui-regs.c (tui_restore_gdbout): Use delete. (tui_register_format): Use string_stream. * tui/tui-stack.c (tui_make_status_line): Use string_file. (tui_get_function_from_frame): Use string_file. * typeprint.c (type_to_string): Use string_file. * ui-file.c (struct ui_file, ui_file_magic, ui_file_new): Delete. (null_stream): New global. (ui_file_delete): Delete. (ui_file::ui_file): New. (null_file_isatty): Delete. (ui_file::~ui_file): New. (null_file_rewind): Delete. (ui_file::printf): New. (null_file_put): Delete. (null_file_flush): Delete. (ui_file::putstr): New. (null_file_write): Delete. (ui_file::putstrn): New. (null_file_read): Delete. (ui_file::putc): New. (null_file_fputs): Delete. (null_file_write_async_safe): Delete. (ui_file::vprintf): New. (null_file_delete): Delete. (null_file::write): New. (null_file_fseek): Delete. (null_file::puts): New. (ui_file_data): Delete. (null_file::write_async_safe): New. (gdb_flush, ui_file_isatty): Adjust. (ui_file_put, ui_file_rewind): Delete. (ui_file_write): Adjust. (ui_file_write_for_put): Delete. (ui_file_write_async_safe, ui_file_read): Adjust. (ui_file_fseek): Delete. (fputs_unfiltered): Adjust. (set_ui_file_flush, set_ui_file_isatty, set_ui_file_rewind) (set_ui_file_put, set_ui_file_write, set_ui_file_write_async_safe) (set_ui_file_read, set_ui_file_fputs, set_ui_file_fseek) (set_ui_file_data): Delete. (string_file::~string_file, string_file::write) (struct accumulated_ui_file, do_ui_file_xstrdup, ui_file_xstrdup) (do_ui_file_as_string, ui_file_as_string): Delete. (do_ui_file_obsavestring, ui_file_obsavestring): Delete. (struct mem_file): Delete. (mem_file_new): Delete. (stdio_file::stdio_file): New. (mem_file_delete): Delete. (stdio_file::stdio_file): New. (mem_fileopen): Delete. (stdio_file::~stdio_file): New. (mem_file_rewind): Delete. (stdio_file::set_stream): New. (mem_file_put): Delete. (stdio_file::open): New. (mem_file_write): Delete. (stdio_file_magic, struct stdio_file): Delete. (stdio_file_new, stdio_file_delete, stdio_file_flush): Delete. (stdio_file::flush): New. (stdio_file_read): Rename to ... (stdio_file::read): ... this. Adjust. (stdio_file_write): Rename to ... (stdio_file::write): ... this. Adjust. (stdio_file_write_async_safe): Rename to ... (stdio_file::write_async_safe) ... this. Adjust. (stdio_file_fputs): Rename to ... (stdio_file::puts) ... this. Adjust. (stdio_file_isatty): Delete. (stdio_file_fseek): Delete. (stdio_file::isatty): New. (stderr_file_write): Rename to ... (stderr_file::write) ... this. Adjust. (stderr_file_fputs): Rename to ... (stderr_file::puts) ... this. Adjust. (stderr_fileopen, stdio_fileopen, gdb_fopen): Delete. (stderr_file::stderr_file): New. (tee_file_magic): Delete. (struct tee_file): Delete. (tee_file::tee_file): New. (tee_file_new): Delete. (tee_file::~tee_file): New. (tee_file_delete): Delete. (tee_file_flush): Rename to ... (tee_file::flush): ... this. Adjust. (tee_file_write): Rename to ... (tee_file::write): ... this. Adjust. (tee_file::write_async_safe): New. (tee_file_fputs): Rename to ... (tee_file::puts): ... this. Adjust. (tee_file_isatty): Rename to ... (tee_file::isatty): ... this. Adjust. * ui-file.h (struct obstack, struct ui_file): Don't forward-declare. (ui_file_new, ui_file_flush_ftype, set_ui_file_flush) (ui_file_write_ftype) (set_ui_file_write, ui_file_fputs_ftype, set_ui_file_fputs) (ui_file_write_async_safe_ftype, set_ui_file_write_async_safe) (ui_file_read_ftype, set_ui_file_read, ui_file_isatty_ftype) (set_ui_file_isatty, ui_file_rewind_ftype, set_ui_file_rewind) (ui_file_put_method_ftype, ui_file_put_ftype, set_ui_file_put) (ui_file_delete_ftype, set_ui_file_data, ui_file_fseek_ftype) (set_ui_file_fseek): Delete. (ui_file_data, ui_file_delete, ui_file_rewind) (struct ui_file): New. (ui_file_up): New. (class null_file): New. (null_stream): Declare. (ui_file_write_for_put, ui_file_put): Delete. (ui_file_xstrdup, ui_file_as_string, ui_file_obsavestring): Delete. (ui_file_fseek, mem_fileopen, stdio_fileopen, stderr_fileopen) (gdb_fopen, tee_file_new): Delete. (struct string_file): New. (struct stdio_file): New. (stdio_file_up): New. (struct stderr_file): New. (class tee_file): New. * ui-out.c (ui_out::field_stream): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * ui-out.h (class ui_out) <field_stream>: Likewise. * utils.c (do_ui_file_delete, make_cleanup_ui_file_delete) (null_stream): Delete. (error_stream): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * utils.h (struct ui_file): Delete forward declaration.. (make_cleanup_ui_file_delete, null_stream): Delete declarations. (error_stream): Take a 'string_file &' instead of a 'ui_file *'. * varobj.c (varobj_value_get_print_value): Use string_file. * xtensa-tdep.c (xtensa_verify_config): Use string_file. * gdbarch.c: Regenerate.
2017-02-02 12:11:47 +01:00
buf.write ("::", 2);
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
comp = d_right (comp);
}
/* If the next component is DEMANGLE_COMPONENT_NAME, save the qualified
name assembled above and append the name given by COMP. Then use this
reassembled name to check for a typedef. */
if (comp->type == DEMANGLE_COMPONENT_NAME)
{
Eliminate make_cleanup_ui_file_delete / make ui_file a class hierarchy This patch starts from the desire to eliminate make_cleanup_ui_file_delete, but then goes beyond. It makes ui_file & friends a real C++ class hierarchy, and switches temporary ui_file-like objects to stack-based allocation. - mem_fileopen -> string_file mem_fileopen is replaced with a new string_file class that is treated as a value class created on the stack. This alone eliminates most make_cleanup_ui_file_delete calls, and, simplifies code a whole lot (diffstat shows around 1k loc dropped.) string_file's internal buffer is a std::string, thus the "string" in the name. This simplifies the implementation much, compared to mem_fileopen, which managed growing its internal buffer manually. - ui_file_as_string, ui_file_strdup, ui_file_obsavestring all gone The new string_file class has a string() method that provides direct writable access to the internal std::string buffer. This replaced ui_file_as_string, which forced a copy of the same data the stream had inside. With direct access via a writable reference, we can instead move the string out of the string_stream, avoiding deep string copying. Related, ui_file_xstrdup calls are replaced with xstrdup'ping the stream's string, and ui_file_obsavestring is replaced by obstack_copy0. With all those out of the way, getting rid of the weird ui_file_put mechanism was possible. - New ui_file::printf, ui_file::puts, etc. methods These simplify / clarify client code. I considered splitting client-code changes, like these, e.g.: - stb = mem_fileopen (); - fprintf_unfiltered (stb, "%s%s%s", - _("The valid values are:\n"), - regdesc, - _("The default is \"std\".")); + string_file stb; + stb.printf ("%s%s%s", + _("The valid values are:\n"), + regdesc, + _("The default is \"std\".")); In two steps, with the first step leaving fprintf_unfiltered (etc.) calls in place, and only afterwards do a pass to change all those to call stb.printf etc.. I didn't do that split, because (when I tried), it turned out to be pointless make-work: the first pass would have to touch the fprintf_unfiltered line anyway, to replace "stb" with "&stb". - gdb_fopen replaced with stack-based objects This avoids the need for cleanups or unique_ptr's. I.e., this: struct ui_file *file = gdb_fopen (filename, "w"); if (filename == NULL) perror_with_name (filename); cleanups = make_cleanup_ui_file_delete (file); // use file. do_cleanups (cleanups); is replaced with this: stdio_file file; if (!file.open (filename, "w")) perror_with_name (filename); // use file. - odd contorsions in null_file_write / null_file_fputs around when to call to_fputs / to_write eliminated. - Global null_stream object A few places that were allocating a ui_file in order to print to "nowhere" are adjusted to instead refer to a new 'null_stream' global stream. - TUI's tui_sfileopen eliminated. TUI's ui_file much simplified The TUI's ui_file was serving a dual purpose. It supported being used as string buffer, and supported being backed by a stdio FILE. The string buffer part is gone, replaced by using of string_file. The 'FILE *' support is now much simplified, by making the TUI's ui_file inherit from stdio_file. gdb/ChangeLog: 2017-02-02 Pedro Alves <palves@redhat.com> * ada-lang.c (type_as_string): Use string_file. * ada-valprint.c (ada_print_floating): Use string_file. * ada-varobj.c (ada_varobj_scalar_image) (ada_varobj_get_value_image): Use string_file. * aix-thread.c (aix_thread_extra_thread_info): Use string_file. * arm-tdep.c (_initialize_arm_tdep): Use string_printf. * breakpoint.c (update_inserted_breakpoint_locations) (insert_breakpoint_locations, reattach_breakpoints) (print_breakpoint_location, print_one_detail_ranged_breakpoint) (print_it_watchpoint): Use string_file. (save_breakpoints): Use stdio_file. * c-exp.y (oper): Use string_file. * cli/cli-logging.c (set_logging_redirect): Use ui_file_up and tee_file. (pop_output_files): Use delete. (handle_redirections): Use stdio_file and tee_file. * cli/cli-setshow.c (do_show_command): Use string_file. * compile/compile-c-support.c (c_compute_program): Use string_file. * compile/compile-c-symbols.c (generate_vla_size): Take a 'string_file &' instead of a 'ui_file *'. (generate_c_for_for_one_variable): Take a 'string_file &' instead of a 'ui_file *'. Use string_file. (generate_c_for_variable_locations): Take a 'string_file &' instead of a 'ui_file *'. * compile/compile-internal.h (generate_c_for_for_one_variable): Take a 'string_file &' instead of a 'ui_file *'. * compile/compile-loc2c.c (push, pushf, unary, binary) (print_label, pushf_register_address, pushf_register) (do_compile_dwarf_expr_to_c): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * compile/compile.c (compile_to_object): Use string_file. * compile/compile.h (compile_dwarf_expr_to_c) (compile_dwarf_bounds_to_c): Take a 'string_file &' instead of a 'ui_file *'. * cp-support.c (inspect_type): Use string_file and obstack_copy0. (replace_typedefs_qualified_name): Use string_file and obstack_copy0. * disasm.c (gdb_pretty_print_insn): Use string_file. (gdb_disassembly): Adjust reference the null_stream global. (do_ui_file_delete): Delete. (gdb_insn_length): Use null_stream. * dummy-frame.c (maintenance_print_dummy_frames): Use stdio_file. * dwarf2loc.c (dwarf2_compile_property_to_c) (locexpr_generate_c_location, loclist_generate_c_location): Take a 'string_file &' instead of a 'ui_file *'. * dwarf2loc.h (dwarf2_compile_property_to_c): Likewise. * dwarf2read.c (do_ui_file_peek_last): Delete. (dwarf2_compute_name): Use string_file. * event-top.c (gdb_setup_readline): Use stdio_file. * gdbarch.sh (verify_gdbarch): Use string_file. * gdbtypes.c (safe_parse_type): Use null_stream. * guile/scm-breakpoint.c (gdbscm_breakpoint_commands): Use string_file. * guile/scm-disasm.c (gdbscm_print_insn_from_port): Take a 'string_file *' instead of a 'ui_file *'. (gdbscm_arch_disassemble): Use string_file. * guile/scm-frame.c (frscm_print_frame_smob): Use string_file. * guile/scm-ports.c (class ioscm_file_port): Now a class that inherits from ui_file. (ioscm_file_port_delete, ioscm_file_port_rewind) (ioscm_file_port_put): Delete. (ioscm_file_port_write): Rename to ... (ioscm_file_port::write): ... this. Remove file_port_magic checks. (ioscm_file_port_new): Delete. (ioscm_with_output_to_port_worker): Use ioscm_file_port and ui_file_up. * guile/scm-type.c (tyscm_type_name): Use string_file. * guile/scm-value.c (vlscm_print_value_smob, gdbscm_value_print): Use string_file. * infcmd.c (print_return_value_1): Use string_file. * infrun.c (print_target_wait_results): Use string_file. * language.c (add_language): Use string_file. * location.c (explicit_to_string_internal): Use string_file. * main.c (captured_main_1): Use null_file. * maint.c (maintenance_print_architecture): Use stdio_file. * mi/mi-cmd-stack.c (list_arg_or_local): Use string_file. * mi/mi-common.h (struct mi_interp) <out, err, log, targ, event_channel>: Change type to mi_console_file pointer. * mi/mi-console.c (mi_console_file_fputs, mi_console_file_flush) (mi_console_file_delete): Delete. (struct mi_console_file): Delete. (mi_console_file_magic): Delete. (mi_console_file_new): Delete. (mi_console_file::mi_console_file): New. (mi_console_file_delete): Delete. (mi_console_file_fputs): Delete. (mi_console_file::write): New. (mi_console_raw_packet): Delete. (mi_console_file::flush): New. (mi_console_file_flush): Delete. (mi_console_set_raw): Rename to ... (mi_console_file::set_raw): ... this. * mi/mi-console.h (class mi_console_file): New class. (mi_console_file_new, mi_console_set_raw): Delete. * mi/mi-interp.c (mi_interpreter_init): Use mi_console_file. (mi_set_logging): Use delete and tee_file. Adjust. * mi/mi-main.c (output_register): Use string_file. (mi_cmd_data_evaluate_expression): Use string_file. (mi_cmd_data_read_memory): Use string_file. (mi_cmd_execute, print_variable_or_computed): Use string_file. * mi/mi-out.c (mi_ui_out::main_stream): New. (mi_ui_out::rewind): Use main_stream and string_file. (mi_ui_out::put): Use main_stream and string_file. (mi_ui_out::mi_ui_out): Remove 'stream' parameter. Allocate a 'string_file' instead. (mi_out_new): Don't allocate a mem_fileopen stream here. * mi/mi-out.h (mi_ui_out::mi_ui_out): Remove 'stream' parameter. (mi_ui_out::main_stream): Declare method. * printcmd.c (eval_command): Use string_file. * psymtab.c (maintenance_print_psymbols): Use stdio_file. * python/py-arch.c (archpy_disassemble): Use string_file. * python/py-breakpoint.c (bppy_get_commands): Use string_file. * python/py-frame.c (frapy_str): Use string_file. * python/py-framefilter.c (py_print_type, py_print_single_arg): Use string_file. * python/py-type.c (typy_str): Use string_file. * python/py-unwind.c (unwind_infopy_str): Use string_file. * python/py-value.c (valpy_str): Use string_file. * record-btrace.c (btrace_insn_history): Use string_file. * regcache.c (regcache_print): Use stdio_file. * reggroups.c (maintenance_print_reggroups): Use stdio_file. * remote.c (escape_buffer): Use string_file. * rust-lang.c (rust_get_disr_info): Use string_file. * serial.c (serial_open_ops_1): Use stdio_file. (do_serial_close): Use delete. * stack.c (print_frame_arg): Use string_file. (print_frame_args): Remove local mem_fileopen stream, not used. (print_frame): Use string_file. * symmisc.c (maintenance_print_symbols): Use stdio_file. * symtab.h (struct symbol_computed_ops) <generate_c_location>: Take a 'string_file *' instead of a 'ui_file *'. * top.c (new_ui): Use stdio_file and stderr_file. (free_ui): Use delete. (execute_command_to_string): Use string_file. (quit_confirm): Use string_file. * tracepoint.c (collection_list::append_exp): Use string_file. * tui/tui-disasm.c (tui_disassemble): Use string_file. * tui/tui-file.c: Don't include "ui-file.h". (enum streamtype, struct tui_stream): Delete. (tui_file_new, tui_file_delete, tui_fileopen, tui_sfileopen) (tui_file_isatty, tui_file_rewind, tui_file_put): Delete. (tui_file::tui_file): New method. (tui_file_fputs): Delete. (tui_file_get_strbuf): Delete. (tui_file::puts): New method. (tui_file_adjust_strbuf): Delete. (tui_file_flush): Delete. (tui_file::flush): New method. * tui/tui-file.h: Tweak intro comment. Include ui-file.h. (tui_fileopen, tui_sfileopen, tui_file_get_strbuf) (tui_file_adjust_strbuf): Delete declarations. (class tui_file): New class. * tui/tui-io.c (tui_initialize_io): Use tui_file. * tui/tui-regs.c (tui_restore_gdbout): Use delete. (tui_register_format): Use string_stream. * tui/tui-stack.c (tui_make_status_line): Use string_file. (tui_get_function_from_frame): Use string_file. * typeprint.c (type_to_string): Use string_file. * ui-file.c (struct ui_file, ui_file_magic, ui_file_new): Delete. (null_stream): New global. (ui_file_delete): Delete. (ui_file::ui_file): New. (null_file_isatty): Delete. (ui_file::~ui_file): New. (null_file_rewind): Delete. (ui_file::printf): New. (null_file_put): Delete. (null_file_flush): Delete. (ui_file::putstr): New. (null_file_write): Delete. (ui_file::putstrn): New. (null_file_read): Delete. (ui_file::putc): New. (null_file_fputs): Delete. (null_file_write_async_safe): Delete. (ui_file::vprintf): New. (null_file_delete): Delete. (null_file::write): New. (null_file_fseek): Delete. (null_file::puts): New. (ui_file_data): Delete. (null_file::write_async_safe): New. (gdb_flush, ui_file_isatty): Adjust. (ui_file_put, ui_file_rewind): Delete. (ui_file_write): Adjust. (ui_file_write_for_put): Delete. (ui_file_write_async_safe, ui_file_read): Adjust. (ui_file_fseek): Delete. (fputs_unfiltered): Adjust. (set_ui_file_flush, set_ui_file_isatty, set_ui_file_rewind) (set_ui_file_put, set_ui_file_write, set_ui_file_write_async_safe) (set_ui_file_read, set_ui_file_fputs, set_ui_file_fseek) (set_ui_file_data): Delete. (string_file::~string_file, string_file::write) (struct accumulated_ui_file, do_ui_file_xstrdup, ui_file_xstrdup) (do_ui_file_as_string, ui_file_as_string): Delete. (do_ui_file_obsavestring, ui_file_obsavestring): Delete. (struct mem_file): Delete. (mem_file_new): Delete. (stdio_file::stdio_file): New. (mem_file_delete): Delete. (stdio_file::stdio_file): New. (mem_fileopen): Delete. (stdio_file::~stdio_file): New. (mem_file_rewind): Delete. (stdio_file::set_stream): New. (mem_file_put): Delete. (stdio_file::open): New. (mem_file_write): Delete. (stdio_file_magic, struct stdio_file): Delete. (stdio_file_new, stdio_file_delete, stdio_file_flush): Delete. (stdio_file::flush): New. (stdio_file_read): Rename to ... (stdio_file::read): ... this. Adjust. (stdio_file_write): Rename to ... (stdio_file::write): ... this. Adjust. (stdio_file_write_async_safe): Rename to ... (stdio_file::write_async_safe) ... this. Adjust. (stdio_file_fputs): Rename to ... (stdio_file::puts) ... this. Adjust. (stdio_file_isatty): Delete. (stdio_file_fseek): Delete. (stdio_file::isatty): New. (stderr_file_write): Rename to ... (stderr_file::write) ... this. Adjust. (stderr_file_fputs): Rename to ... (stderr_file::puts) ... this. Adjust. (stderr_fileopen, stdio_fileopen, gdb_fopen): Delete. (stderr_file::stderr_file): New. (tee_file_magic): Delete. (struct tee_file): Delete. (tee_file::tee_file): New. (tee_file_new): Delete. (tee_file::~tee_file): New. (tee_file_delete): Delete. (tee_file_flush): Rename to ... (tee_file::flush): ... this. Adjust. (tee_file_write): Rename to ... (tee_file::write): ... this. Adjust. (tee_file::write_async_safe): New. (tee_file_fputs): Rename to ... (tee_file::puts): ... this. Adjust. (tee_file_isatty): Rename to ... (tee_file::isatty): ... this. Adjust. * ui-file.h (struct obstack, struct ui_file): Don't forward-declare. (ui_file_new, ui_file_flush_ftype, set_ui_file_flush) (ui_file_write_ftype) (set_ui_file_write, ui_file_fputs_ftype, set_ui_file_fputs) (ui_file_write_async_safe_ftype, set_ui_file_write_async_safe) (ui_file_read_ftype, set_ui_file_read, ui_file_isatty_ftype) (set_ui_file_isatty, ui_file_rewind_ftype, set_ui_file_rewind) (ui_file_put_method_ftype, ui_file_put_ftype, set_ui_file_put) (ui_file_delete_ftype, set_ui_file_data, ui_file_fseek_ftype) (set_ui_file_fseek): Delete. (ui_file_data, ui_file_delete, ui_file_rewind) (struct ui_file): New. (ui_file_up): New. (class null_file): New. (null_stream): Declare. (ui_file_write_for_put, ui_file_put): Delete. (ui_file_xstrdup, ui_file_as_string, ui_file_obsavestring): Delete. (ui_file_fseek, mem_fileopen, stdio_fileopen, stderr_fileopen) (gdb_fopen, tee_file_new): Delete. (struct string_file): New. (struct stdio_file): New. (stdio_file_up): New. (struct stderr_file): New. (class tee_file): New. * ui-out.c (ui_out::field_stream): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * ui-out.h (class ui_out) <field_stream>: Likewise. * utils.c (do_ui_file_delete, make_cleanup_ui_file_delete) (null_stream): Delete. (error_stream): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * utils.h (struct ui_file): Delete forward declaration.. (make_cleanup_ui_file_delete, null_stream): Delete declarations. (error_stream): Take a 'string_file &' instead of a 'ui_file *'. * varobj.c (varobj_value_get_print_value): Use string_file. * xtensa-tdep.c (xtensa_verify_config): Use string_file. * gdbarch.c: Regenerate.
2017-02-02 12:11:47 +01:00
buf.write (comp->u.s_name.s, comp->u.s_name.len);
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
/* Replace the top (DEMANGLE_COMPONENT_QUAL_NAME) node
with a DEMANGLE_COMPONENT_NAME node containing the whole
name. */
ret_comp->type = DEMANGLE_COMPONENT_NAME;
ret_comp->u.s_name.s = obstack_strdup (&info->obstack, buf.string ());
ret_comp->u.s_name.len = buf.size ();
inspect_type (info, ret_comp, finder, data);
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
}
else
replace_typedefs (info, comp, finder, data);
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
}
/* A function to check const and volatile qualifiers for argument types.
"Parameter declarations that differ only in the presence
or absence of `const' and/or `volatile' are equivalent."
C++ Standard N3290, clause 13.1.3 #4. */
static void
check_cv_qualifiers (struct demangle_component *ret_comp)
{
while (d_left (ret_comp) != NULL
&& (d_left (ret_comp)->type == DEMANGLE_COMPONENT_CONST
|| d_left (ret_comp)->type == DEMANGLE_COMPONENT_VOLATILE))
{
d_left (ret_comp) = d_left (d_left (ret_comp));
}
}
/* Walk the parse tree given by RET_COMP, replacing any typedefs with
their basic types. */
static void
replace_typedefs (struct demangle_parse_info *info,
struct demangle_component *ret_comp,
canonicalization_ftype *finder,
void *data)
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
{
if (ret_comp)
{
if (finder != NULL
&& (ret_comp->type == DEMANGLE_COMPONENT_NAME
|| ret_comp->type == DEMANGLE_COMPONENT_QUAL_NAME
|| ret_comp->type == DEMANGLE_COMPONENT_TEMPLATE
|| ret_comp->type == DEMANGLE_COMPONENT_BUILTIN_TYPE))
{
gdb::unique_xmalloc_ptr<char> local_name
= cp_comp_to_string (ret_comp, 10);
if (local_name != NULL)
{
Split TRY_CATCH into TRY + CATCH This patch splits the TRY_CATCH macro into three, so that we go from this: ~~~ volatile gdb_exception ex; TRY_CATCH (ex, RETURN_MASK_ERROR) { } if (ex.reason < 0) { } ~~~ to this: ~~~ TRY { } CATCH (ex, RETURN_MASK_ERROR) { } END_CATCH ~~~ Thus, we'll be getting rid of the local volatile exception object, and declaring the caught exception in the catch block. This allows reimplementing TRY/CATCH in terms of C++ exceptions when building in C++ mode, while still allowing to build GDB in C mode (using setjmp/longjmp), as a transition step. TBC, after this patch, is it _not_ valid to have code between the TRY and the CATCH blocks, like: TRY { } // some code here. CATCH (ex, RETURN_MASK_ERROR) { } END_CATCH Just like it isn't valid to do that with C++'s native try/catch. By switching to creating the exception object inside the CATCH block scope, we can get rid of all the explicitly allocated volatile exception objects all over the tree, and map the CATCH block more directly to C++'s catch blocks. The majority of the TRY_CATCH -> TRY+CATCH+END_CATCH conversion was done with a script, rerun from scratch at every rebase, no manual editing involved. After the mechanical conversion, a few places needed manual intervention, to fix preexisting cases where we were using the exception object outside of the TRY_CATCH block, and cases where we were using "else" after a 'if (ex.reason) < 0)' [a CATCH after this patch]. The result was folded into this patch so that GDB still builds at each incremental step. END_CATCH is necessary for two reasons: First, because we name the exception object in the CATCH block, which requires creating a scope, which in turn must be closed somewhere. Declaring the exception variable in the initializer field of a for block, like: #define CATCH(EXCEPTION, mask) \ for (struct gdb_exception EXCEPTION; \ exceptions_state_mc_catch (&EXCEPTION, MASK); \ EXCEPTION = exception_none) would avoid needing END_CATCH, but alas, in C mode, we build with C90, which doesn't allow mixed declarations and code. Second, because when TRY/CATCH are wired to real C++ try/catch, as long as we need to handle cleanup chains, even if there's no CATCH block that wants to catch the exception, we need for stop at every frame in the unwind chain and run cleanups, then rethrow. That will be done in END_CATCH. After we require C++, we'll still need TRY/CATCH/END_CATCH until cleanups are completely phased out -- TRY/CATCH in C++ mode will save/restore the current cleanup chain, like in C mode, and END_CATCH catches otherwise uncaugh exceptions, runs cleanups and rethrows, so that C++ cleanups and exceptions can coexist. IMO, this still makes the TRY/CATCH code look a bit more like a newcomer would expect, so IMO worth it even if we weren't considering C++. gdb/ChangeLog. 2015-03-07 Pedro Alves <palves@redhat.com> * common/common-exceptions.c (struct catcher) <exception>: No longer a pointer to volatile exception. Now an exception value. <mask>: Delete field. (exceptions_state_mc_init): Remove all parameters. Adjust. (exceptions_state_mc): No longer pop the catcher here. (exceptions_state_mc_catch): New function. (throw_exception): Adjust. * common/common-exceptions.h (exceptions_state_mc_init): Remove all parameters. (exceptions_state_mc_catch): Declare. (TRY_CATCH): Rename to ... (TRY): ... this. Remove EXCEPTION and MASK parameters. (CATCH, END_CATCH): New. All callers adjusted. gdb/gdbserver/ChangeLog: 2015-03-07 Pedro Alves <palves@redhat.com> Adjust all callers of TRY_CATCH to use TRY/CATCH/END_CATCH instead.
2015-03-07 16:14:14 +01:00
struct symbol *sym = NULL;
sym = NULL;
Rewrite TRY/CATCH This rewrites gdb's TRY/CATCH to plain C++ try/catch. The patch was largely written by script, though one change (to a comment in common-exceptions.h) was reverted by hand. gdb/ChangeLog 2019-04-08 Tom Tromey <tom@tromey.com> * xml-support.c: Use C++ exception handling. * x86-linux-nat.c: Use C++ exception handling. * windows-nat.c: Use C++ exception handling. * varobj.c: Use C++ exception handling. * value.c: Use C++ exception handling. * valprint.c: Use C++ exception handling. * valops.c: Use C++ exception handling. * unittests/parse-connection-spec-selftests.c: Use C++ exception handling. * unittests/cli-utils-selftests.c: Use C++ exception handling. * typeprint.c: Use C++ exception handling. * tui/tui.c: Use C++ exception handling. * tracefile-tfile.c: Use C++ exception handling. * top.c: Use C++ exception handling. * thread.c: Use C++ exception handling. * target.c: Use C++ exception handling. * symmisc.c: Use C++ exception handling. * symfile-mem.c: Use C++ exception handling. * stack.c: Use C++ exception handling. * sparc64-linux-tdep.c: Use C++ exception handling. * solib.c: Use C++ exception handling. * solib-svr4.c: Use C++ exception handling. * solib-spu.c: Use C++ exception handling. * solib-frv.c: Use C++ exception handling. * solib-dsbt.c: Use C++ exception handling. * selftest-arch.c: Use C++ exception handling. * s390-tdep.c: Use C++ exception handling. * rust-lang.c: Use C++ exception handling. * rust-exp.y: Use C++ exception handling. * rs6000-tdep.c: Use C++ exception handling. * rs6000-aix-tdep.c: Use C++ exception handling. * riscv-tdep.c: Use C++ exception handling. * remote.c: Use C++ exception handling. * remote-fileio.c: Use C++ exception handling. * record-full.c: Use C++ exception handling. * record-btrace.c: Use C++ exception handling. * python/python.c: Use C++ exception handling. * python/py-value.c: Use C++ exception handling. * python/py-utils.c: Use C++ exception handling. * python/py-unwind.c: Use C++ exception handling. * python/py-type.c: Use C++ exception handling. * python/py-symbol.c: Use C++ exception handling. * python/py-record.c: Use C++ exception handling. * python/py-record-btrace.c: Use C++ exception handling. * python/py-progspace.c: Use C++ exception handling. * python/py-prettyprint.c: Use C++ exception handling. * python/py-param.c: Use C++ exception handling. * python/py-objfile.c: Use C++ exception handling. * python/py-linetable.c: Use C++ exception handling. * python/py-lazy-string.c: Use C++ exception handling. * python/py-infthread.c: Use C++ exception handling. * python/py-inferior.c: Use C++ exception handling. * python/py-gdb-readline.c: Use C++ exception handling. * python/py-framefilter.c: Use C++ exception handling. * python/py-frame.c: Use C++ exception handling. * python/py-finishbreakpoint.c: Use C++ exception handling. * python/py-cmd.c: Use C++ exception handling. * python/py-breakpoint.c: Use C++ exception handling. * python/py-arch.c: Use C++ exception handling. * printcmd.c: Use C++ exception handling. * ppc-linux-tdep.c: Use C++ exception handling. * parse.c: Use C++ exception handling. * p-valprint.c: Use C++ exception handling. * objc-lang.c: Use C++ exception handling. * mi/mi-main.c: Use C++ exception handling. * mi/mi-interp.c: Use C++ exception handling. * mi/mi-cmd-stack.c: Use C++ exception handling. * mi/mi-cmd-break.c: Use C++ exception handling. * main.c: Use C++ exception handling. * linux-thread-db.c: Use C++ exception handling. * linux-tdep.c: Use C++ exception handling. * linux-nat.c: Use C++ exception handling. * linux-fork.c: Use C++ exception handling. * linespec.c: Use C++ exception handling. * language.c: Use C++ exception handling. * jit.c: Use C++ exception handling. * infrun.c: Use C++ exception handling. * infcmd.c: Use C++ exception handling. * infcall.c: Use C++ exception handling. * inf-loop.c: Use C++ exception handling. * i386-tdep.c: Use C++ exception handling. * i386-linux-tdep.c: Use C++ exception handling. * guile/scm-value.c: Use C++ exception handling. * guile/scm-type.c: Use C++ exception handling. * guile/scm-symtab.c: Use C++ exception handling. * guile/scm-symbol.c: Use C++ exception handling. * guile/scm-pretty-print.c: Use C++ exception handling. * guile/scm-ports.c: Use C++ exception handling. * guile/scm-param.c: Use C++ exception handling. * guile/scm-math.c: Use C++ exception handling. * guile/scm-lazy-string.c: Use C++ exception handling. * guile/scm-frame.c: Use C++ exception handling. * guile/scm-disasm.c: Use C++ exception handling. * guile/scm-cmd.c: Use C++ exception handling. * guile/scm-breakpoint.c: Use C++ exception handling. * guile/scm-block.c: Use C++ exception handling. * guile/guile-internal.h: Use C++ exception handling. * gnu-v3-abi.c: Use C++ exception handling. * gdbtypes.c: Use C++ exception handling. * frame.c: Use C++ exception handling. * frame-unwind.c: Use C++ exception handling. * fbsd-tdep.c: Use C++ exception handling. * f-valprint.c: Use C++ exception handling. * exec.c: Use C++ exception handling. * event-top.c: Use C++ exception handling. * event-loop.c: Use C++ exception handling. * eval.c: Use C++ exception handling. * dwarf2read.c: Use C++ exception handling. * dwarf2loc.c: Use C++ exception handling. * dwarf2-frame.c: Use C++ exception handling. * dwarf2-frame-tailcall.c: Use C++ exception handling. * dwarf-index-write.c: Use C++ exception handling. * dwarf-index-cache.c: Use C++ exception handling. * dtrace-probe.c: Use C++ exception handling. * disasm-selftests.c: Use C++ exception handling. * darwin-nat.c: Use C++ exception handling. * cp-valprint.c: Use C++ exception handling. * cp-support.c: Use C++ exception handling. * cp-abi.c: Use C++ exception handling. * corelow.c: Use C++ exception handling. * completer.c: Use C++ exception handling. * compile/compile-object-run.c: Use C++ exception handling. * compile/compile-object-load.c: Use C++ exception handling. * compile/compile-cplus-symbols.c: Use C++ exception handling. * compile/compile-c-symbols.c: Use C++ exception handling. * common/selftest.c: Use C++ exception handling. * common/new-op.c: Use C++ exception handling. * cli/cli-script.c: Use C++ exception handling. * cli/cli-interp.c: Use C++ exception handling. * cli/cli-cmds.c: Use C++ exception handling. * c-varobj.c: Use C++ exception handling. * btrace.c: Use C++ exception handling. * breakpoint.c: Use C++ exception handling. * break-catch-throw.c: Use C++ exception handling. * arch-utils.c: Use C++ exception handling. * amd64-tdep.c: Use C++ exception handling. * ada-valprint.c: Use C++ exception handling. * ada-typeprint.c: Use C++ exception handling. * ada-lang.c: Use C++ exception handling. * aarch64-tdep.c: Use C++ exception handling. gdb/gdbserver/ChangeLog 2019-04-08 Tom Tromey <tom@tromey.com> * server.c: Use C++ exception handling. * linux-low.c: Use C++ exception handling. * gdbreplay.c: Use C++ exception handling.
2019-04-04 00:02:42 +02:00
try
{
sym = lookup_symbol (local_name.get (), 0,
VAR_DOMAIN, 0).symbol;
}
Rename gdb exception types This renames the gdb exception types. The old types were only needed due to the macros in common-exception.h that are now gone. The intermediate layer of gdb_exception_RETURN_MASK_ALL did not seem needed, so this patch removes it entirely. gdb/ChangeLog 2019-04-08 Tom Tromey <tom@tromey.com> * common/common-exceptions.h (gdb_exception_RETURN_MASK_ALL): Remove. (gdb_exception_error): Rename from gdb_exception_RETURN_MASK_ERROR. (gdb_exception_quit): Rename from gdb_exception_RETURN_MASK_QUIT. (gdb_quit_bad_alloc): Update. * aarch64-tdep.c: Update. * ada-lang.c: Update. * ada-typeprint.c: Update. * ada-valprint.c: Update. * amd64-tdep.c: Update. * arch-utils.c: Update. * break-catch-throw.c: Update. * breakpoint.c: Update. * btrace.c: Update. * c-varobj.c: Update. * cli/cli-cmds.c: Update. * cli/cli-interp.c: Update. * cli/cli-script.c: Update. * common/common-exceptions.c: Update. * common/new-op.c: Update. * common/selftest.c: Update. * compile/compile-c-symbols.c: Update. * compile/compile-cplus-symbols.c: Update. * compile/compile-object-load.c: Update. * compile/compile-object-run.c: Update. * completer.c: Update. * corelow.c: Update. * cp-abi.c: Update. * cp-support.c: Update. * cp-valprint.c: Update. * darwin-nat.c: Update. * disasm-selftests.c: Update. * dtrace-probe.c: Update. * dwarf-index-cache.c: Update. * dwarf-index-write.c: Update. * dwarf2-frame-tailcall.c: Update. * dwarf2-frame.c: Update. * dwarf2loc.c: Update. * dwarf2read.c: Update. * eval.c: Update. * event-loop.c: Update. * event-top.c: Update. * exec.c: Update. * f-valprint.c: Update. * fbsd-tdep.c: Update. * frame-unwind.c: Update. * frame.c: Update. * gdbtypes.c: Update. * gnu-v3-abi.c: Update. * guile/guile-internal.h: Update. * guile/scm-block.c: Update. * guile/scm-breakpoint.c: Update. * guile/scm-cmd.c: Update. * guile/scm-disasm.c: Update. * guile/scm-frame.c: Update. * guile/scm-lazy-string.c: Update. * guile/scm-math.c: Update. * guile/scm-param.c: Update. * guile/scm-ports.c: Update. * guile/scm-pretty-print.c: Update. * guile/scm-symbol.c: Update. * guile/scm-symtab.c: Update. * guile/scm-type.c: Update. * guile/scm-value.c: Update. * i386-linux-tdep.c: Update. * i386-tdep.c: Update. * inf-loop.c: Update. * infcall.c: Update. * infcmd.c: Update. * infrun.c: Update. * jit.c: Update. * language.c: Update. * linespec.c: Update. * linux-fork.c: Update. * linux-nat.c: Update. * linux-tdep.c: Update. * linux-thread-db.c: Update. * main.c: Update. * mi/mi-cmd-break.c: Update. * mi/mi-cmd-stack.c: Update. * mi/mi-interp.c: Update. * mi/mi-main.c: Update. * objc-lang.c: Update. * p-valprint.c: Update. * parse.c: Update. * ppc-linux-tdep.c: Update. * printcmd.c: Update. * python/py-arch.c: Update. * python/py-breakpoint.c: Update. * python/py-cmd.c: Update. * python/py-finishbreakpoint.c: Update. * python/py-frame.c: Update. * python/py-framefilter.c: Update. * python/py-gdb-readline.c: Update. * python/py-inferior.c: Update. * python/py-infthread.c: Update. * python/py-lazy-string.c: Update. * python/py-linetable.c: Update. * python/py-objfile.c: Update. * python/py-param.c: Update. * python/py-prettyprint.c: Update. * python/py-progspace.c: Update. * python/py-record-btrace.c: Update. * python/py-record.c: Update. * python/py-symbol.c: Update. * python/py-type.c: Update. * python/py-unwind.c: Update. * python/py-utils.c: Update. * python/py-value.c: Update. * python/python.c: Update. * record-btrace.c: Update. * record-full.c: Update. * remote-fileio.c: Update. * remote.c: Update. * riscv-tdep.c: Update. * rs6000-aix-tdep.c: Update. * rs6000-tdep.c: Update. * rust-exp.y: Update. * rust-lang.c: Update. * s390-tdep.c: Update. * selftest-arch.c: Update. * solib-dsbt.c: Update. * solib-frv.c: Update. * solib-spu.c: Update. * solib-svr4.c: Update. * solib.c: Update. * sparc64-linux-tdep.c: Update. * stack.c: Update. * symfile-mem.c: Update. * symmisc.c: Update. * target.c: Update. * thread.c: Update. * top.c: Update. * tracefile-tfile.c: Update. * tui/tui.c: Update. * typeprint.c: Update. * unittests/cli-utils-selftests.c: Update. * unittests/parse-connection-spec-selftests.c: Update. * valops.c: Update. * valprint.c: Update. * value.c: Update. * varobj.c: Update. * windows-nat.c: Update. * x86-linux-nat.c: Update. * xml-support.c: Update. gdb/gdbserver/ChangeLog 2019-04-08 Tom Tromey <tom@tromey.com> * gdbreplay.c: Update. * linux-low.c: Update. * server.c: Update.
2019-04-03 23:59:07 +02:00
catch (const gdb_exception &except)
Split TRY_CATCH into TRY + CATCH This patch splits the TRY_CATCH macro into three, so that we go from this: ~~~ volatile gdb_exception ex; TRY_CATCH (ex, RETURN_MASK_ERROR) { } if (ex.reason < 0) { } ~~~ to this: ~~~ TRY { } CATCH (ex, RETURN_MASK_ERROR) { } END_CATCH ~~~ Thus, we'll be getting rid of the local volatile exception object, and declaring the caught exception in the catch block. This allows reimplementing TRY/CATCH in terms of C++ exceptions when building in C++ mode, while still allowing to build GDB in C mode (using setjmp/longjmp), as a transition step. TBC, after this patch, is it _not_ valid to have code between the TRY and the CATCH blocks, like: TRY { } // some code here. CATCH (ex, RETURN_MASK_ERROR) { } END_CATCH Just like it isn't valid to do that with C++'s native try/catch. By switching to creating the exception object inside the CATCH block scope, we can get rid of all the explicitly allocated volatile exception objects all over the tree, and map the CATCH block more directly to C++'s catch blocks. The majority of the TRY_CATCH -> TRY+CATCH+END_CATCH conversion was done with a script, rerun from scratch at every rebase, no manual editing involved. After the mechanical conversion, a few places needed manual intervention, to fix preexisting cases where we were using the exception object outside of the TRY_CATCH block, and cases where we were using "else" after a 'if (ex.reason) < 0)' [a CATCH after this patch]. The result was folded into this patch so that GDB still builds at each incremental step. END_CATCH is necessary for two reasons: First, because we name the exception object in the CATCH block, which requires creating a scope, which in turn must be closed somewhere. Declaring the exception variable in the initializer field of a for block, like: #define CATCH(EXCEPTION, mask) \ for (struct gdb_exception EXCEPTION; \ exceptions_state_mc_catch (&EXCEPTION, MASK); \ EXCEPTION = exception_none) would avoid needing END_CATCH, but alas, in C mode, we build with C90, which doesn't allow mixed declarations and code. Second, because when TRY/CATCH are wired to real C++ try/catch, as long as we need to handle cleanup chains, even if there's no CATCH block that wants to catch the exception, we need for stop at every frame in the unwind chain and run cleanups, then rethrow. That will be done in END_CATCH. After we require C++, we'll still need TRY/CATCH/END_CATCH until cleanups are completely phased out -- TRY/CATCH in C++ mode will save/restore the current cleanup chain, like in C mode, and END_CATCH catches otherwise uncaugh exceptions, runs cleanups and rethrows, so that C++ cleanups and exceptions can coexist. IMO, this still makes the TRY/CATCH code look a bit more like a newcomer would expect, so IMO worth it even if we weren't considering C++. gdb/ChangeLog. 2015-03-07 Pedro Alves <palves@redhat.com> * common/common-exceptions.c (struct catcher) <exception>: No longer a pointer to volatile exception. Now an exception value. <mask>: Delete field. (exceptions_state_mc_init): Remove all parameters. Adjust. (exceptions_state_mc): No longer pop the catcher here. (exceptions_state_mc_catch): New function. (throw_exception): Adjust. * common/common-exceptions.h (exceptions_state_mc_init): Remove all parameters. (exceptions_state_mc_catch): Declare. (TRY_CATCH): Rename to ... (TRY): ... this. Remove EXCEPTION and MASK parameters. (CATCH, END_CATCH): New. All callers adjusted. gdb/gdbserver/ChangeLog: 2015-03-07 Pedro Alves <palves@redhat.com> Adjust all callers of TRY_CATCH to use TRY/CATCH/END_CATCH instead.
2015-03-07 16:14:14 +01:00
{
}
if (sym != NULL)
{
struct type *otype = SYMBOL_TYPE (sym);
const char *new_name = (*finder) (otype, data);
if (new_name != NULL)
{
ret_comp->type = DEMANGLE_COMPONENT_NAME;
ret_comp->u.s_name.s = new_name;
ret_comp->u.s_name.len = strlen (new_name);
return;
}
}
}
}
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
switch (ret_comp->type)
{
case DEMANGLE_COMPONENT_ARGLIST:
check_cv_qualifiers (ret_comp);
/* Fall through */
case DEMANGLE_COMPONENT_FUNCTION_TYPE:
case DEMANGLE_COMPONENT_TEMPLATE:
case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
case DEMANGLE_COMPONENT_TYPED_NAME:
replace_typedefs (info, d_left (ret_comp), finder, data);
replace_typedefs (info, d_right (ret_comp), finder, data);
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
break;
case DEMANGLE_COMPONENT_NAME:
inspect_type (info, ret_comp, finder, data);
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
break;
case DEMANGLE_COMPONENT_QUAL_NAME:
replace_typedefs_qualified_name (info, ret_comp, finder, data);
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
break;
case DEMANGLE_COMPONENT_LOCAL_NAME:
case DEMANGLE_COMPONENT_CTOR:
case DEMANGLE_COMPONENT_ARRAY_TYPE:
case DEMANGLE_COMPONENT_PTRMEM_TYPE:
replace_typedefs (info, d_right (ret_comp), finder, data);
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
break;
case DEMANGLE_COMPONENT_CONST:
case DEMANGLE_COMPONENT_RESTRICT:
case DEMANGLE_COMPONENT_VOLATILE:
case DEMANGLE_COMPONENT_VOLATILE_THIS:
case DEMANGLE_COMPONENT_CONST_THIS:
case DEMANGLE_COMPONENT_RESTRICT_THIS:
case DEMANGLE_COMPONENT_POINTER:
case DEMANGLE_COMPONENT_REFERENCE:
case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
replace_typedefs (info, d_left (ret_comp), finder, data);
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
break;
default:
break;
}
}
}
Use ui_file_as_string throughout more This replaces most of the remaining ui_file_xstrdup calls with ui_file_as_string calls. Whenever a call was replaced, that led to a cascade of other necessary adjustments throughout, to make the code use std::string instead of raw pointers. And then whenever I added a std::string as member of a struct, I needed to adjust allocation/destruction of said struct to use new/delete instead of xmalloc/xfree. The stopping point was once gdb built again. These doesn't seem to be a way to reasonably split this out further. Maybe-not-obvious changes: - demangle_for_lookup returns a cleanup today. To get rid of that, and avoid unnecessary string dupping/copying, this introduces a demangle_result_storage type that the caller instantiates and passes to demangle_for_lookup. - Many methods returned a "char *" to indicate that the caller owns the memory and must free it. Those are switched to return a std::string instead. Methods that return a "view" into some internal string return a "const char *" instead. I.e., we only copy/allocate when necessary. gdb/ChangeLog: 2016-11-08 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_name_for_lookup, type_as_string): Use and return std::string. (type_as_string_and_cleanup): Delete. (ada_lookup_struct_elt_type): Use type_as_string. * ada-lang.h (ada_name_for_lookup): Now returns std::string. * ada-varobj.c (ada_varobj_scalar_image): Return a std::string. (ada_varobj_describe_child): Make 'child_name' and 'child_path_expr' parameters std::string pointers. (ada_varobj_describe_struct_child, ada_varobj_describe_ptr_child): Likewise, and use string_printf. (ada_varobj_describe_simple_array_child) (ada_varobj_describe_child): Likewise. (ada_varobj_get_name_of_child, ada_varobj_get_path_expr_of_child) (ada_varobj_get_value_image) (ada_varobj_get_value_of_array_variable) (ada_varobj_get_value_of_variable, ada_name_of_variable) (ada_name_of_child, ada_path_expr_of_child) (ada_value_of_variable): Now returns std::string. Use string_printf. (ada_value_of_child): Adjust. * break-catch-throw.c (check_status_exception_catchpoint): Adjust to use std::string. * breakpoint.c (watch_command_1): Adjust to use std::string. * c-lang.c (c_get_string): Adjust to use std::string. * c-typeprint.c (print_name_maybe_canonical): Use std::string. * c-varobj.c (varobj_is_anonymous_child): Use ==/!= std::string operators. (c_name_of_variable): Now returns a std::string. (c_describe_child): The 'cname' and 'cfull_expression' output parameters are now std::string pointers. Adjust. (c_name_of_child, c_path_expr_of_child, c_value_of_variable) (cplus_number_of_children): Adjust to use std::string and string_printf. (cplus_name_of_variable): Now returns a std::string. (cplus_describe_child): The 'cname' and 'cfull_expression' output parameters are now std::string pointers. Adjust. (cplus_name_of_child, cplus_path_expr_of_child) (cplus_value_of_variable): Now returns a std::string. * cp-abi.c (cplus_typename_from_type_info): Return std::string. * cp-abi.h (cplus_typename_from_type_info): Return std::string. (struct cp_abi_ops) <get_typename_from_type_info>: Return std::string. * cp-support.c (inspect_type): Use std::string. (cp_canonicalize_string_full, cp_canonicalize_string_no_typedefs) (cp_canonicalize_string): Return std::string and adjust. * cp-support.h (cp_canonicalize_string) (cp_canonicalize_string_no_typedefs, cp_canonicalize_string_full): Return std::string. * dbxread.c (read_dbx_symtab): Use std::string. * dwarf2read.c (dwarf2_canonicalize_name): Adjust to use std::string. * gdbcmd.h (lookup_struct_elt_type): Adjust to use std::string. * gnu-v3-abi.c (gnuv3_get_typeid): Use std::string. (gnuv3_get_typename_from_type_info): Return a std::string and adjust. (gnuv3_get_type_from_type_info): Adjust to use std::string. * guile/guile.c (gdbscm_execute_gdb_command): Adjust to use std::string. * infcmd.c (print_return_value_1): Adjust to use std::string. * linespec.c (find_linespec_symbols): Adjust to demangle_for_lookup API change. Use std::string. * mi/mi-cmd-var.c (print_varobj, mi_cmd_var_set_format) (mi_cmd_var_info_type, mi_cmd_var_info_path_expression) (mi_cmd_var_info_expression, mi_cmd_var_evaluate_expression) (mi_cmd_var_assign, varobj_update_one): Adjust to use std::string. * minsyms.c (lookup_minimal_symbol): Use std::string. * python/py-varobj.c (py_varobj_iter_next): Use new instead of XNEW. vitem->name is a std::string now, adjust. * rust-exp.y (convert_ast_to_type, convert_name): Adjust to use std::string. * stabsread.c (define_symbol): Adjust to use std::string. * symtab.c (demangle_for_lookup): Now returns 'const char *'. Add a demangle_result_storage parameter. Use it for storage. (lookup_symbol_in_language) (lookup_symbol_in_objfile_from_linkage_name): Adjust to new demangle_for_lookup API. * symtab.h (struct demangle_result_storage): New type. (demangle_for_lookup): Now returns 'const char *'. Add a demangle_result_storage parameter. * typeprint.c (type_to_string): Return std::string and use ui_file_as_string. * value.h (type_to_string): Change return type to std::string. * varobj-iter.h (struct varobj_item) <name>: Now a std::string. (varobj_iter_delete): Use delete instead of xfree. * varobj.c (create_child): Return std::string instead of char * in output parameter. (name_of_variable, name_of_child, my_value_of_variable): Return std::string instead of char *. (varobj_create, varobj_get_handle): Constify 'objname' parameter. Adjust to std::string fields. (varobj_get_objname): Return a const char * instead of a char *. (varobj_get_expression): Return a std::string. (varobj_list_children): Adjust to use std::string. (varobj_get_type): Return a std::string. (varobj_get_path_expr): Return a const char * instead of a char *. Adjust to std::string fields. (varobj_get_formatted_value, varobj_get_value): Return a std::string. (varobj_set_value): Change type of 'expression' parameter to std::string. Use std::string. (install_new_value): Use std::string. (delete_variable_1): Adjust to use std::string. (create_child): Change the 'name' parameter to a std::string reference. Swap it into the new item's name. (create_child_with_value): Swap item's name into the new child's name. Use string_printf. (new_variable): Use new instead of XNEW. (free_variable): Don't xfree fields that are now std::string. (name_of_variable, name_of_child): Now returns std::string. (value_of_root): Adjust to use std::string. (my_value_of_variable, varobj_value_get_print_value): Return and use std::string. (varobj_value_get_print_value): Adjust to use ui_file_as_string and std::string. * varobj.h (struct varobj) <name, path_expr, obj_name, print_value>: Now std::string's. <name_of_variable, name_of_child, path_expr_of_child, value_of_variable>: Return std::string. (varobj_create, varobj_get_handle): Constify 'objname' parameter. (varobj_get_objname): Return a const char * instead of a char *. (varobj_get_expression, varobj_get_type): Return a std::string. (varobj_get_path_expr): Return a const char * instead of a char *. (varobj_get_formatted_value, varobj_get_value): Return a std::string. (varobj_set_value): Constify 'expression' parameter. (varobj_value_get_print_value): Return a std::string.
2016-11-08 16:26:47 +01:00
/* Parse STRING and convert it to canonical form, resolving any
typedefs. If parsing fails, or if STRING is already canonical,
return the empty string. Otherwise return the canonical form. If
FINDER is not NULL, then type components are passed to FINDER to be
looked up. DATA is passed verbatim to FINDER. */
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
Use ui_file_as_string throughout more This replaces most of the remaining ui_file_xstrdup calls with ui_file_as_string calls. Whenever a call was replaced, that led to a cascade of other necessary adjustments throughout, to make the code use std::string instead of raw pointers. And then whenever I added a std::string as member of a struct, I needed to adjust allocation/destruction of said struct to use new/delete instead of xmalloc/xfree. The stopping point was once gdb built again. These doesn't seem to be a way to reasonably split this out further. Maybe-not-obvious changes: - demangle_for_lookup returns a cleanup today. To get rid of that, and avoid unnecessary string dupping/copying, this introduces a demangle_result_storage type that the caller instantiates and passes to demangle_for_lookup. - Many methods returned a "char *" to indicate that the caller owns the memory and must free it. Those are switched to return a std::string instead. Methods that return a "view" into some internal string return a "const char *" instead. I.e., we only copy/allocate when necessary. gdb/ChangeLog: 2016-11-08 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_name_for_lookup, type_as_string): Use and return std::string. (type_as_string_and_cleanup): Delete. (ada_lookup_struct_elt_type): Use type_as_string. * ada-lang.h (ada_name_for_lookup): Now returns std::string. * ada-varobj.c (ada_varobj_scalar_image): Return a std::string. (ada_varobj_describe_child): Make 'child_name' and 'child_path_expr' parameters std::string pointers. (ada_varobj_describe_struct_child, ada_varobj_describe_ptr_child): Likewise, and use string_printf. (ada_varobj_describe_simple_array_child) (ada_varobj_describe_child): Likewise. (ada_varobj_get_name_of_child, ada_varobj_get_path_expr_of_child) (ada_varobj_get_value_image) (ada_varobj_get_value_of_array_variable) (ada_varobj_get_value_of_variable, ada_name_of_variable) (ada_name_of_child, ada_path_expr_of_child) (ada_value_of_variable): Now returns std::string. Use string_printf. (ada_value_of_child): Adjust. * break-catch-throw.c (check_status_exception_catchpoint): Adjust to use std::string. * breakpoint.c (watch_command_1): Adjust to use std::string. * c-lang.c (c_get_string): Adjust to use std::string. * c-typeprint.c (print_name_maybe_canonical): Use std::string. * c-varobj.c (varobj_is_anonymous_child): Use ==/!= std::string operators. (c_name_of_variable): Now returns a std::string. (c_describe_child): The 'cname' and 'cfull_expression' output parameters are now std::string pointers. Adjust. (c_name_of_child, c_path_expr_of_child, c_value_of_variable) (cplus_number_of_children): Adjust to use std::string and string_printf. (cplus_name_of_variable): Now returns a std::string. (cplus_describe_child): The 'cname' and 'cfull_expression' output parameters are now std::string pointers. Adjust. (cplus_name_of_child, cplus_path_expr_of_child) (cplus_value_of_variable): Now returns a std::string. * cp-abi.c (cplus_typename_from_type_info): Return std::string. * cp-abi.h (cplus_typename_from_type_info): Return std::string. (struct cp_abi_ops) <get_typename_from_type_info>: Return std::string. * cp-support.c (inspect_type): Use std::string. (cp_canonicalize_string_full, cp_canonicalize_string_no_typedefs) (cp_canonicalize_string): Return std::string and adjust. * cp-support.h (cp_canonicalize_string) (cp_canonicalize_string_no_typedefs, cp_canonicalize_string_full): Return std::string. * dbxread.c (read_dbx_symtab): Use std::string. * dwarf2read.c (dwarf2_canonicalize_name): Adjust to use std::string. * gdbcmd.h (lookup_struct_elt_type): Adjust to use std::string. * gnu-v3-abi.c (gnuv3_get_typeid): Use std::string. (gnuv3_get_typename_from_type_info): Return a std::string and adjust. (gnuv3_get_type_from_type_info): Adjust to use std::string. * guile/guile.c (gdbscm_execute_gdb_command): Adjust to use std::string. * infcmd.c (print_return_value_1): Adjust to use std::string. * linespec.c (find_linespec_symbols): Adjust to demangle_for_lookup API change. Use std::string. * mi/mi-cmd-var.c (print_varobj, mi_cmd_var_set_format) (mi_cmd_var_info_type, mi_cmd_var_info_path_expression) (mi_cmd_var_info_expression, mi_cmd_var_evaluate_expression) (mi_cmd_var_assign, varobj_update_one): Adjust to use std::string. * minsyms.c (lookup_minimal_symbol): Use std::string. * python/py-varobj.c (py_varobj_iter_next): Use new instead of XNEW. vitem->name is a std::string now, adjust. * rust-exp.y (convert_ast_to_type, convert_name): Adjust to use std::string. * stabsread.c (define_symbol): Adjust to use std::string. * symtab.c (demangle_for_lookup): Now returns 'const char *'. Add a demangle_result_storage parameter. Use it for storage. (lookup_symbol_in_language) (lookup_symbol_in_objfile_from_linkage_name): Adjust to new demangle_for_lookup API. * symtab.h (struct demangle_result_storage): New type. (demangle_for_lookup): Now returns 'const char *'. Add a demangle_result_storage parameter. * typeprint.c (type_to_string): Return std::string and use ui_file_as_string. * value.h (type_to_string): Change return type to std::string. * varobj-iter.h (struct varobj_item) <name>: Now a std::string. (varobj_iter_delete): Use delete instead of xfree. * varobj.c (create_child): Return std::string instead of char * in output parameter. (name_of_variable, name_of_child, my_value_of_variable): Return std::string instead of char *. (varobj_create, varobj_get_handle): Constify 'objname' parameter. Adjust to std::string fields. (varobj_get_objname): Return a const char * instead of a char *. (varobj_get_expression): Return a std::string. (varobj_list_children): Adjust to use std::string. (varobj_get_type): Return a std::string. (varobj_get_path_expr): Return a const char * instead of a char *. Adjust to std::string fields. (varobj_get_formatted_value, varobj_get_value): Return a std::string. (varobj_set_value): Change type of 'expression' parameter to std::string. Use std::string. (install_new_value): Use std::string. (delete_variable_1): Adjust to use std::string. (create_child): Change the 'name' parameter to a std::string reference. Swap it into the new item's name. (create_child_with_value): Swap item's name into the new child's name. Use string_printf. (new_variable): Use new instead of XNEW. (free_variable): Don't xfree fields that are now std::string. (name_of_variable, name_of_child): Now returns std::string. (value_of_root): Adjust to use std::string. (my_value_of_variable, varobj_value_get_print_value): Return and use std::string. (varobj_value_get_print_value): Adjust to use ui_file_as_string and std::string. * varobj.h (struct varobj) <name, path_expr, obj_name, print_value>: Now std::string's. <name_of_variable, name_of_child, path_expr_of_child, value_of_variable>: Return std::string. (varobj_create, varobj_get_handle): Constify 'objname' parameter. (varobj_get_objname): Return a const char * instead of a char *. (varobj_get_expression, varobj_get_type): Return a std::string. (varobj_get_path_expr): Return a const char * instead of a char *. (varobj_get_formatted_value, varobj_get_value): Return a std::string. (varobj_set_value): Constify 'expression' parameter. (varobj_value_get_print_value): Return a std::string.
2016-11-08 16:26:47 +01:00
std::string
cp_canonicalize_string_full (const char *string,
canonicalization_ftype *finder,
void *data)
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
{
Use ui_file_as_string throughout more This replaces most of the remaining ui_file_xstrdup calls with ui_file_as_string calls. Whenever a call was replaced, that led to a cascade of other necessary adjustments throughout, to make the code use std::string instead of raw pointers. And then whenever I added a std::string as member of a struct, I needed to adjust allocation/destruction of said struct to use new/delete instead of xmalloc/xfree. The stopping point was once gdb built again. These doesn't seem to be a way to reasonably split this out further. Maybe-not-obvious changes: - demangle_for_lookup returns a cleanup today. To get rid of that, and avoid unnecessary string dupping/copying, this introduces a demangle_result_storage type that the caller instantiates and passes to demangle_for_lookup. - Many methods returned a "char *" to indicate that the caller owns the memory and must free it. Those are switched to return a std::string instead. Methods that return a "view" into some internal string return a "const char *" instead. I.e., we only copy/allocate when necessary. gdb/ChangeLog: 2016-11-08 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_name_for_lookup, type_as_string): Use and return std::string. (type_as_string_and_cleanup): Delete. (ada_lookup_struct_elt_type): Use type_as_string. * ada-lang.h (ada_name_for_lookup): Now returns std::string. * ada-varobj.c (ada_varobj_scalar_image): Return a std::string. (ada_varobj_describe_child): Make 'child_name' and 'child_path_expr' parameters std::string pointers. (ada_varobj_describe_struct_child, ada_varobj_describe_ptr_child): Likewise, and use string_printf. (ada_varobj_describe_simple_array_child) (ada_varobj_describe_child): Likewise. (ada_varobj_get_name_of_child, ada_varobj_get_path_expr_of_child) (ada_varobj_get_value_image) (ada_varobj_get_value_of_array_variable) (ada_varobj_get_value_of_variable, ada_name_of_variable) (ada_name_of_child, ada_path_expr_of_child) (ada_value_of_variable): Now returns std::string. Use string_printf. (ada_value_of_child): Adjust. * break-catch-throw.c (check_status_exception_catchpoint): Adjust to use std::string. * breakpoint.c (watch_command_1): Adjust to use std::string. * c-lang.c (c_get_string): Adjust to use std::string. * c-typeprint.c (print_name_maybe_canonical): Use std::string. * c-varobj.c (varobj_is_anonymous_child): Use ==/!= std::string operators. (c_name_of_variable): Now returns a std::string. (c_describe_child): The 'cname' and 'cfull_expression' output parameters are now std::string pointers. Adjust. (c_name_of_child, c_path_expr_of_child, c_value_of_variable) (cplus_number_of_children): Adjust to use std::string and string_printf. (cplus_name_of_variable): Now returns a std::string. (cplus_describe_child): The 'cname' and 'cfull_expression' output parameters are now std::string pointers. Adjust. (cplus_name_of_child, cplus_path_expr_of_child) (cplus_value_of_variable): Now returns a std::string. * cp-abi.c (cplus_typename_from_type_info): Return std::string. * cp-abi.h (cplus_typename_from_type_info): Return std::string. (struct cp_abi_ops) <get_typename_from_type_info>: Return std::string. * cp-support.c (inspect_type): Use std::string. (cp_canonicalize_string_full, cp_canonicalize_string_no_typedefs) (cp_canonicalize_string): Return std::string and adjust. * cp-support.h (cp_canonicalize_string) (cp_canonicalize_string_no_typedefs, cp_canonicalize_string_full): Return std::string. * dbxread.c (read_dbx_symtab): Use std::string. * dwarf2read.c (dwarf2_canonicalize_name): Adjust to use std::string. * gdbcmd.h (lookup_struct_elt_type): Adjust to use std::string. * gnu-v3-abi.c (gnuv3_get_typeid): Use std::string. (gnuv3_get_typename_from_type_info): Return a std::string and adjust. (gnuv3_get_type_from_type_info): Adjust to use std::string. * guile/guile.c (gdbscm_execute_gdb_command): Adjust to use std::string. * infcmd.c (print_return_value_1): Adjust to use std::string. * linespec.c (find_linespec_symbols): Adjust to demangle_for_lookup API change. Use std::string. * mi/mi-cmd-var.c (print_varobj, mi_cmd_var_set_format) (mi_cmd_var_info_type, mi_cmd_var_info_path_expression) (mi_cmd_var_info_expression, mi_cmd_var_evaluate_expression) (mi_cmd_var_assign, varobj_update_one): Adjust to use std::string. * minsyms.c (lookup_minimal_symbol): Use std::string. * python/py-varobj.c (py_varobj_iter_next): Use new instead of XNEW. vitem->name is a std::string now, adjust. * rust-exp.y (convert_ast_to_type, convert_name): Adjust to use std::string. * stabsread.c (define_symbol): Adjust to use std::string. * symtab.c (demangle_for_lookup): Now returns 'const char *'. Add a demangle_result_storage parameter. Use it for storage. (lookup_symbol_in_language) (lookup_symbol_in_objfile_from_linkage_name): Adjust to new demangle_for_lookup API. * symtab.h (struct demangle_result_storage): New type. (demangle_for_lookup): Now returns 'const char *'. Add a demangle_result_storage parameter. * typeprint.c (type_to_string): Return std::string and use ui_file_as_string. * value.h (type_to_string): Change return type to std::string. * varobj-iter.h (struct varobj_item) <name>: Now a std::string. (varobj_iter_delete): Use delete instead of xfree. * varobj.c (create_child): Return std::string instead of char * in output parameter. (name_of_variable, name_of_child, my_value_of_variable): Return std::string instead of char *. (varobj_create, varobj_get_handle): Constify 'objname' parameter. Adjust to std::string fields. (varobj_get_objname): Return a const char * instead of a char *. (varobj_get_expression): Return a std::string. (varobj_list_children): Adjust to use std::string. (varobj_get_type): Return a std::string. (varobj_get_path_expr): Return a const char * instead of a char *. Adjust to std::string fields. (varobj_get_formatted_value, varobj_get_value): Return a std::string. (varobj_set_value): Change type of 'expression' parameter to std::string. Use std::string. (install_new_value): Use std::string. (delete_variable_1): Adjust to use std::string. (create_child): Change the 'name' parameter to a std::string reference. Swap it into the new item's name. (create_child_with_value): Swap item's name into the new child's name. Use string_printf. (new_variable): Use new instead of XNEW. (free_variable): Don't xfree fields that are now std::string. (name_of_variable, name_of_child): Now returns std::string. (value_of_root): Adjust to use std::string. (my_value_of_variable, varobj_value_get_print_value): Return and use std::string. (varobj_value_get_print_value): Adjust to use ui_file_as_string and std::string. * varobj.h (struct varobj) <name, path_expr, obj_name, print_value>: Now std::string's. <name_of_variable, name_of_child, path_expr_of_child, value_of_variable>: Return std::string. (varobj_create, varobj_get_handle): Constify 'objname' parameter. (varobj_get_objname): Return a const char * instead of a char *. (varobj_get_expression, varobj_get_type): Return a std::string. (varobj_get_path_expr): Return a const char * instead of a char *. (varobj_get_formatted_value, varobj_get_value): Return a std::string. (varobj_set_value): Constify 'expression' parameter. (varobj_value_get_print_value): Return a std::string.
2016-11-08 16:26:47 +01:00
std::string ret;
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
unsigned int estimated_len;
std::unique_ptr<demangle_parse_info> info;
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
estimated_len = strlen (string) * 2;
info = cp_demangled_name_to_comp (string, NULL);
if (info != NULL)
{
/* Replace all the typedefs in the tree. */
replace_typedefs (info.get (), info->tree, finder, data);
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
/* Convert the tree back into a string. */
gdb::unique_xmalloc_ptr<char> us = cp_comp_to_string (info->tree,
estimated_len);
Fix memory leak in cp-support.c The return value of cp_comp_to_string was never freed, creating a sizable memory leak detectable with valgrind. ==21225== 8 bytes in 1 blocks are definitely lost in loss record 4,599 of 10,949^M ==21225== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M ==21225== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M ==21225== by 0x76CB31: d_growable_string_resize (cp-demangle.c:3963)^M ==21225== by 0x76CB31: d_growable_string_init (cp-demangle.c:3942)^M ==21225== by 0x76CB31: cplus_demangle_print (cp-demangle.c:4308)^M ==21225== by 0x4C9535: cp_comp_to_string(demangle_component*, int) (cp-name-parser.y:1972)^M ==21225== by 0x53E1D4: cp_canonicalize_string_full[abi:cxx11](char const*, char const* (*)(type*, void*), void*) (cp-support.c:530)^M ==21225== by 0x53E360: cp_canonicalize_string_no_typedefs[abi:cxx11](char const*) (cp-support.c:548)^M ==21225== by 0x5D51D2: find_linespec_symbols(linespec_state*, VEC_symtab_ptr*, char const*, VEC_symbolp**, VEC_bound_minimal_symbol_d**) (linespec.c:4030)^M ==21225== by 0x5D6CF6: linespec_parse_basic (linespec.c:1907) ==21279== 32 bytes in 1 blocks are definitely lost in loss record 6,066 of 10,947^M ==21279== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M ==21279== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M ==21279== by 0x76CB31: d_growable_string_resize (cp-demangle.c:3963)^M ==21279== by 0x76CB31: d_growable_string_init (cp-demangle.c:3942)^M ==21279== by 0x76CB31: cplus_demangle_print (cp-demangle.c:4308)^M ==21279== by 0x4C9535: cp_comp_to_string(demangle_component*, int) (cp-name-parser.y:1972)^M ==21279== by 0x53EF14: cp_canonicalize_string[abi:cxx11](char const*) (cp-support.c:569)^M ==21279== by 0x561B75: dwarf2_canonicalize_name(char const*, dwarf2_cu*, obstack*) [clone .isra.210] (dwarf2read.c:20159) This patch fixes the leak. It is a regression by 2f408ecb. gdb: 2017-08-09 Alex Lindsay <alexlindsay239@gmail.com> Yao Qi <yao.qi@linaro.org> * cp-support.c (cp_canonicalize_string_full): Use gdb::unique_xmalloc_ptr<char>. (cp_canonicalize_string): Likewise.
2017-08-09 13:39:16 +02:00
gdb_assert (us);
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
Fix memory leak in cp-support.c The return value of cp_comp_to_string was never freed, creating a sizable memory leak detectable with valgrind. ==21225== 8 bytes in 1 blocks are definitely lost in loss record 4,599 of 10,949^M ==21225== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M ==21225== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M ==21225== by 0x76CB31: d_growable_string_resize (cp-demangle.c:3963)^M ==21225== by 0x76CB31: d_growable_string_init (cp-demangle.c:3942)^M ==21225== by 0x76CB31: cplus_demangle_print (cp-demangle.c:4308)^M ==21225== by 0x4C9535: cp_comp_to_string(demangle_component*, int) (cp-name-parser.y:1972)^M ==21225== by 0x53E1D4: cp_canonicalize_string_full[abi:cxx11](char const*, char const* (*)(type*, void*), void*) (cp-support.c:530)^M ==21225== by 0x53E360: cp_canonicalize_string_no_typedefs[abi:cxx11](char const*) (cp-support.c:548)^M ==21225== by 0x5D51D2: find_linespec_symbols(linespec_state*, VEC_symtab_ptr*, char const*, VEC_symbolp**, VEC_bound_minimal_symbol_d**) (linespec.c:4030)^M ==21225== by 0x5D6CF6: linespec_parse_basic (linespec.c:1907) ==21279== 32 bytes in 1 blocks are definitely lost in loss record 6,066 of 10,947^M ==21279== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M ==21279== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M ==21279== by 0x76CB31: d_growable_string_resize (cp-demangle.c:3963)^M ==21279== by 0x76CB31: d_growable_string_init (cp-demangle.c:3942)^M ==21279== by 0x76CB31: cplus_demangle_print (cp-demangle.c:4308)^M ==21279== by 0x4C9535: cp_comp_to_string(demangle_component*, int) (cp-name-parser.y:1972)^M ==21279== by 0x53EF14: cp_canonicalize_string[abi:cxx11](char const*) (cp-support.c:569)^M ==21279== by 0x561B75: dwarf2_canonicalize_name(char const*, dwarf2_cu*, obstack*) [clone .isra.210] (dwarf2read.c:20159) This patch fixes the leak. It is a regression by 2f408ecb. gdb: 2017-08-09 Alex Lindsay <alexlindsay239@gmail.com> Yao Qi <yao.qi@linaro.org> * cp-support.c (cp_canonicalize_string_full): Use gdb::unique_xmalloc_ptr<char>. (cp_canonicalize_string): Likewise.
2017-08-09 13:39:16 +02:00
ret = us.get ();
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
/* Finally, compare the original string with the computed
name, returning NULL if they are the same. */
Use ui_file_as_string throughout more This replaces most of the remaining ui_file_xstrdup calls with ui_file_as_string calls. Whenever a call was replaced, that led to a cascade of other necessary adjustments throughout, to make the code use std::string instead of raw pointers. And then whenever I added a std::string as member of a struct, I needed to adjust allocation/destruction of said struct to use new/delete instead of xmalloc/xfree. The stopping point was once gdb built again. These doesn't seem to be a way to reasonably split this out further. Maybe-not-obvious changes: - demangle_for_lookup returns a cleanup today. To get rid of that, and avoid unnecessary string dupping/copying, this introduces a demangle_result_storage type that the caller instantiates and passes to demangle_for_lookup. - Many methods returned a "char *" to indicate that the caller owns the memory and must free it. Those are switched to return a std::string instead. Methods that return a "view" into some internal string return a "const char *" instead. I.e., we only copy/allocate when necessary. gdb/ChangeLog: 2016-11-08 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_name_for_lookup, type_as_string): Use and return std::string. (type_as_string_and_cleanup): Delete. (ada_lookup_struct_elt_type): Use type_as_string. * ada-lang.h (ada_name_for_lookup): Now returns std::string. * ada-varobj.c (ada_varobj_scalar_image): Return a std::string. (ada_varobj_describe_child): Make 'child_name' and 'child_path_expr' parameters std::string pointers. (ada_varobj_describe_struct_child, ada_varobj_describe_ptr_child): Likewise, and use string_printf. (ada_varobj_describe_simple_array_child) (ada_varobj_describe_child): Likewise. (ada_varobj_get_name_of_child, ada_varobj_get_path_expr_of_child) (ada_varobj_get_value_image) (ada_varobj_get_value_of_array_variable) (ada_varobj_get_value_of_variable, ada_name_of_variable) (ada_name_of_child, ada_path_expr_of_child) (ada_value_of_variable): Now returns std::string. Use string_printf. (ada_value_of_child): Adjust. * break-catch-throw.c (check_status_exception_catchpoint): Adjust to use std::string. * breakpoint.c (watch_command_1): Adjust to use std::string. * c-lang.c (c_get_string): Adjust to use std::string. * c-typeprint.c (print_name_maybe_canonical): Use std::string. * c-varobj.c (varobj_is_anonymous_child): Use ==/!= std::string operators. (c_name_of_variable): Now returns a std::string. (c_describe_child): The 'cname' and 'cfull_expression' output parameters are now std::string pointers. Adjust. (c_name_of_child, c_path_expr_of_child, c_value_of_variable) (cplus_number_of_children): Adjust to use std::string and string_printf. (cplus_name_of_variable): Now returns a std::string. (cplus_describe_child): The 'cname' and 'cfull_expression' output parameters are now std::string pointers. Adjust. (cplus_name_of_child, cplus_path_expr_of_child) (cplus_value_of_variable): Now returns a std::string. * cp-abi.c (cplus_typename_from_type_info): Return std::string. * cp-abi.h (cplus_typename_from_type_info): Return std::string. (struct cp_abi_ops) <get_typename_from_type_info>: Return std::string. * cp-support.c (inspect_type): Use std::string. (cp_canonicalize_string_full, cp_canonicalize_string_no_typedefs) (cp_canonicalize_string): Return std::string and adjust. * cp-support.h (cp_canonicalize_string) (cp_canonicalize_string_no_typedefs, cp_canonicalize_string_full): Return std::string. * dbxread.c (read_dbx_symtab): Use std::string. * dwarf2read.c (dwarf2_canonicalize_name): Adjust to use std::string. * gdbcmd.h (lookup_struct_elt_type): Adjust to use std::string. * gnu-v3-abi.c (gnuv3_get_typeid): Use std::string. (gnuv3_get_typename_from_type_info): Return a std::string and adjust. (gnuv3_get_type_from_type_info): Adjust to use std::string. * guile/guile.c (gdbscm_execute_gdb_command): Adjust to use std::string. * infcmd.c (print_return_value_1): Adjust to use std::string. * linespec.c (find_linespec_symbols): Adjust to demangle_for_lookup API change. Use std::string. * mi/mi-cmd-var.c (print_varobj, mi_cmd_var_set_format) (mi_cmd_var_info_type, mi_cmd_var_info_path_expression) (mi_cmd_var_info_expression, mi_cmd_var_evaluate_expression) (mi_cmd_var_assign, varobj_update_one): Adjust to use std::string. * minsyms.c (lookup_minimal_symbol): Use std::string. * python/py-varobj.c (py_varobj_iter_next): Use new instead of XNEW. vitem->name is a std::string now, adjust. * rust-exp.y (convert_ast_to_type, convert_name): Adjust to use std::string. * stabsread.c (define_symbol): Adjust to use std::string. * symtab.c (demangle_for_lookup): Now returns 'const char *'. Add a demangle_result_storage parameter. Use it for storage. (lookup_symbol_in_language) (lookup_symbol_in_objfile_from_linkage_name): Adjust to new demangle_for_lookup API. * symtab.h (struct demangle_result_storage): New type. (demangle_for_lookup): Now returns 'const char *'. Add a demangle_result_storage parameter. * typeprint.c (type_to_string): Return std::string and use ui_file_as_string. * value.h (type_to_string): Change return type to std::string. * varobj-iter.h (struct varobj_item) <name>: Now a std::string. (varobj_iter_delete): Use delete instead of xfree. * varobj.c (create_child): Return std::string instead of char * in output parameter. (name_of_variable, name_of_child, my_value_of_variable): Return std::string instead of char *. (varobj_create, varobj_get_handle): Constify 'objname' parameter. Adjust to std::string fields. (varobj_get_objname): Return a const char * instead of a char *. (varobj_get_expression): Return a std::string. (varobj_list_children): Adjust to use std::string. (varobj_get_type): Return a std::string. (varobj_get_path_expr): Return a const char * instead of a char *. Adjust to std::string fields. (varobj_get_formatted_value, varobj_get_value): Return a std::string. (varobj_set_value): Change type of 'expression' parameter to std::string. Use std::string. (install_new_value): Use std::string. (delete_variable_1): Adjust to use std::string. (create_child): Change the 'name' parameter to a std::string reference. Swap it into the new item's name. (create_child_with_value): Swap item's name into the new child's name. Use string_printf. (new_variable): Use new instead of XNEW. (free_variable): Don't xfree fields that are now std::string. (name_of_variable, name_of_child): Now returns std::string. (value_of_root): Adjust to use std::string. (my_value_of_variable, varobj_value_get_print_value): Return and use std::string. (varobj_value_get_print_value): Adjust to use ui_file_as_string and std::string. * varobj.h (struct varobj) <name, path_expr, obj_name, print_value>: Now std::string's. <name_of_variable, name_of_child, path_expr_of_child, value_of_variable>: Return std::string. (varobj_create, varobj_get_handle): Constify 'objname' parameter. (varobj_get_objname): Return a const char * instead of a char *. (varobj_get_expression, varobj_get_type): Return a std::string. (varobj_get_path_expr): Return a const char * instead of a char *. (varobj_get_formatted_value, varobj_get_value): Return a std::string. (varobj_set_value): Constify 'expression' parameter. (varobj_value_get_print_value): Return a std::string.
2016-11-08 16:26:47 +01:00
if (ret == string)
return std::string ();
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
}
return ret;
}
/* Like cp_canonicalize_string_full, but always passes NULL for
FINDER. */
Use ui_file_as_string throughout more This replaces most of the remaining ui_file_xstrdup calls with ui_file_as_string calls. Whenever a call was replaced, that led to a cascade of other necessary adjustments throughout, to make the code use std::string instead of raw pointers. And then whenever I added a std::string as member of a struct, I needed to adjust allocation/destruction of said struct to use new/delete instead of xmalloc/xfree. The stopping point was once gdb built again. These doesn't seem to be a way to reasonably split this out further. Maybe-not-obvious changes: - demangle_for_lookup returns a cleanup today. To get rid of that, and avoid unnecessary string dupping/copying, this introduces a demangle_result_storage type that the caller instantiates and passes to demangle_for_lookup. - Many methods returned a "char *" to indicate that the caller owns the memory and must free it. Those are switched to return a std::string instead. Methods that return a "view" into some internal string return a "const char *" instead. I.e., we only copy/allocate when necessary. gdb/ChangeLog: 2016-11-08 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_name_for_lookup, type_as_string): Use and return std::string. (type_as_string_and_cleanup): Delete. (ada_lookup_struct_elt_type): Use type_as_string. * ada-lang.h (ada_name_for_lookup): Now returns std::string. * ada-varobj.c (ada_varobj_scalar_image): Return a std::string. (ada_varobj_describe_child): Make 'child_name' and 'child_path_expr' parameters std::string pointers. (ada_varobj_describe_struct_child, ada_varobj_describe_ptr_child): Likewise, and use string_printf. (ada_varobj_describe_simple_array_child) (ada_varobj_describe_child): Likewise. (ada_varobj_get_name_of_child, ada_varobj_get_path_expr_of_child) (ada_varobj_get_value_image) (ada_varobj_get_value_of_array_variable) (ada_varobj_get_value_of_variable, ada_name_of_variable) (ada_name_of_child, ada_path_expr_of_child) (ada_value_of_variable): Now returns std::string. Use string_printf. (ada_value_of_child): Adjust. * break-catch-throw.c (check_status_exception_catchpoint): Adjust to use std::string. * breakpoint.c (watch_command_1): Adjust to use std::string. * c-lang.c (c_get_string): Adjust to use std::string. * c-typeprint.c (print_name_maybe_canonical): Use std::string. * c-varobj.c (varobj_is_anonymous_child): Use ==/!= std::string operators. (c_name_of_variable): Now returns a std::string. (c_describe_child): The 'cname' and 'cfull_expression' output parameters are now std::string pointers. Adjust. (c_name_of_child, c_path_expr_of_child, c_value_of_variable) (cplus_number_of_children): Adjust to use std::string and string_printf. (cplus_name_of_variable): Now returns a std::string. (cplus_describe_child): The 'cname' and 'cfull_expression' output parameters are now std::string pointers. Adjust. (cplus_name_of_child, cplus_path_expr_of_child) (cplus_value_of_variable): Now returns a std::string. * cp-abi.c (cplus_typename_from_type_info): Return std::string. * cp-abi.h (cplus_typename_from_type_info): Return std::string. (struct cp_abi_ops) <get_typename_from_type_info>: Return std::string. * cp-support.c (inspect_type): Use std::string. (cp_canonicalize_string_full, cp_canonicalize_string_no_typedefs) (cp_canonicalize_string): Return std::string and adjust. * cp-support.h (cp_canonicalize_string) (cp_canonicalize_string_no_typedefs, cp_canonicalize_string_full): Return std::string. * dbxread.c (read_dbx_symtab): Use std::string. * dwarf2read.c (dwarf2_canonicalize_name): Adjust to use std::string. * gdbcmd.h (lookup_struct_elt_type): Adjust to use std::string. * gnu-v3-abi.c (gnuv3_get_typeid): Use std::string. (gnuv3_get_typename_from_type_info): Return a std::string and adjust. (gnuv3_get_type_from_type_info): Adjust to use std::string. * guile/guile.c (gdbscm_execute_gdb_command): Adjust to use std::string. * infcmd.c (print_return_value_1): Adjust to use std::string. * linespec.c (find_linespec_symbols): Adjust to demangle_for_lookup API change. Use std::string. * mi/mi-cmd-var.c (print_varobj, mi_cmd_var_set_format) (mi_cmd_var_info_type, mi_cmd_var_info_path_expression) (mi_cmd_var_info_expression, mi_cmd_var_evaluate_expression) (mi_cmd_var_assign, varobj_update_one): Adjust to use std::string. * minsyms.c (lookup_minimal_symbol): Use std::string. * python/py-varobj.c (py_varobj_iter_next): Use new instead of XNEW. vitem->name is a std::string now, adjust. * rust-exp.y (convert_ast_to_type, convert_name): Adjust to use std::string. * stabsread.c (define_symbol): Adjust to use std::string. * symtab.c (demangle_for_lookup): Now returns 'const char *'. Add a demangle_result_storage parameter. Use it for storage. (lookup_symbol_in_language) (lookup_symbol_in_objfile_from_linkage_name): Adjust to new demangle_for_lookup API. * symtab.h (struct demangle_result_storage): New type. (demangle_for_lookup): Now returns 'const char *'. Add a demangle_result_storage parameter. * typeprint.c (type_to_string): Return std::string and use ui_file_as_string. * value.h (type_to_string): Change return type to std::string. * varobj-iter.h (struct varobj_item) <name>: Now a std::string. (varobj_iter_delete): Use delete instead of xfree. * varobj.c (create_child): Return std::string instead of char * in output parameter. (name_of_variable, name_of_child, my_value_of_variable): Return std::string instead of char *. (varobj_create, varobj_get_handle): Constify 'objname' parameter. Adjust to std::string fields. (varobj_get_objname): Return a const char * instead of a char *. (varobj_get_expression): Return a std::string. (varobj_list_children): Adjust to use std::string. (varobj_get_type): Return a std::string. (varobj_get_path_expr): Return a const char * instead of a char *. Adjust to std::string fields. (varobj_get_formatted_value, varobj_get_value): Return a std::string. (varobj_set_value): Change type of 'expression' parameter to std::string. Use std::string. (install_new_value): Use std::string. (delete_variable_1): Adjust to use std::string. (create_child): Change the 'name' parameter to a std::string reference. Swap it into the new item's name. (create_child_with_value): Swap item's name into the new child's name. Use string_printf. (new_variable): Use new instead of XNEW. (free_variable): Don't xfree fields that are now std::string. (name_of_variable, name_of_child): Now returns std::string. (value_of_root): Adjust to use std::string. (my_value_of_variable, varobj_value_get_print_value): Return and use std::string. (varobj_value_get_print_value): Adjust to use ui_file_as_string and std::string. * varobj.h (struct varobj) <name, path_expr, obj_name, print_value>: Now std::string's. <name_of_variable, name_of_child, path_expr_of_child, value_of_variable>: Return std::string. (varobj_create, varobj_get_handle): Constify 'objname' parameter. (varobj_get_objname): Return a const char * instead of a char *. (varobj_get_expression, varobj_get_type): Return a std::string. (varobj_get_path_expr): Return a const char * instead of a char *. (varobj_get_formatted_value, varobj_get_value): Return a std::string. (varobj_set_value): Constify 'expression' parameter. (varobj_value_get_print_value): Return a std::string.
2016-11-08 16:26:47 +01:00
std::string
cp_canonicalize_string_no_typedefs (const char *string)
{
return cp_canonicalize_string_full (string, NULL, NULL);
}
/* Parse STRING and convert it to canonical form. If parsing fails,
Use ui_file_as_string throughout more This replaces most of the remaining ui_file_xstrdup calls with ui_file_as_string calls. Whenever a call was replaced, that led to a cascade of other necessary adjustments throughout, to make the code use std::string instead of raw pointers. And then whenever I added a std::string as member of a struct, I needed to adjust allocation/destruction of said struct to use new/delete instead of xmalloc/xfree. The stopping point was once gdb built again. These doesn't seem to be a way to reasonably split this out further. Maybe-not-obvious changes: - demangle_for_lookup returns a cleanup today. To get rid of that, and avoid unnecessary string dupping/copying, this introduces a demangle_result_storage type that the caller instantiates and passes to demangle_for_lookup. - Many methods returned a "char *" to indicate that the caller owns the memory and must free it. Those are switched to return a std::string instead. Methods that return a "view" into some internal string return a "const char *" instead. I.e., we only copy/allocate when necessary. gdb/ChangeLog: 2016-11-08 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_name_for_lookup, type_as_string): Use and return std::string. (type_as_string_and_cleanup): Delete. (ada_lookup_struct_elt_type): Use type_as_string. * ada-lang.h (ada_name_for_lookup): Now returns std::string. * ada-varobj.c (ada_varobj_scalar_image): Return a std::string. (ada_varobj_describe_child): Make 'child_name' and 'child_path_expr' parameters std::string pointers. (ada_varobj_describe_struct_child, ada_varobj_describe_ptr_child): Likewise, and use string_printf. (ada_varobj_describe_simple_array_child) (ada_varobj_describe_child): Likewise. (ada_varobj_get_name_of_child, ada_varobj_get_path_expr_of_child) (ada_varobj_get_value_image) (ada_varobj_get_value_of_array_variable) (ada_varobj_get_value_of_variable, ada_name_of_variable) (ada_name_of_child, ada_path_expr_of_child) (ada_value_of_variable): Now returns std::string. Use string_printf. (ada_value_of_child): Adjust. * break-catch-throw.c (check_status_exception_catchpoint): Adjust to use std::string. * breakpoint.c (watch_command_1): Adjust to use std::string. * c-lang.c (c_get_string): Adjust to use std::string. * c-typeprint.c (print_name_maybe_canonical): Use std::string. * c-varobj.c (varobj_is_anonymous_child): Use ==/!= std::string operators. (c_name_of_variable): Now returns a std::string. (c_describe_child): The 'cname' and 'cfull_expression' output parameters are now std::string pointers. Adjust. (c_name_of_child, c_path_expr_of_child, c_value_of_variable) (cplus_number_of_children): Adjust to use std::string and string_printf. (cplus_name_of_variable): Now returns a std::string. (cplus_describe_child): The 'cname' and 'cfull_expression' output parameters are now std::string pointers. Adjust. (cplus_name_of_child, cplus_path_expr_of_child) (cplus_value_of_variable): Now returns a std::string. * cp-abi.c (cplus_typename_from_type_info): Return std::string. * cp-abi.h (cplus_typename_from_type_info): Return std::string. (struct cp_abi_ops) <get_typename_from_type_info>: Return std::string. * cp-support.c (inspect_type): Use std::string. (cp_canonicalize_string_full, cp_canonicalize_string_no_typedefs) (cp_canonicalize_string): Return std::string and adjust. * cp-support.h (cp_canonicalize_string) (cp_canonicalize_string_no_typedefs, cp_canonicalize_string_full): Return std::string. * dbxread.c (read_dbx_symtab): Use std::string. * dwarf2read.c (dwarf2_canonicalize_name): Adjust to use std::string. * gdbcmd.h (lookup_struct_elt_type): Adjust to use std::string. * gnu-v3-abi.c (gnuv3_get_typeid): Use std::string. (gnuv3_get_typename_from_type_info): Return a std::string and adjust. (gnuv3_get_type_from_type_info): Adjust to use std::string. * guile/guile.c (gdbscm_execute_gdb_command): Adjust to use std::string. * infcmd.c (print_return_value_1): Adjust to use std::string. * linespec.c (find_linespec_symbols): Adjust to demangle_for_lookup API change. Use std::string. * mi/mi-cmd-var.c (print_varobj, mi_cmd_var_set_format) (mi_cmd_var_info_type, mi_cmd_var_info_path_expression) (mi_cmd_var_info_expression, mi_cmd_var_evaluate_expression) (mi_cmd_var_assign, varobj_update_one): Adjust to use std::string. * minsyms.c (lookup_minimal_symbol): Use std::string. * python/py-varobj.c (py_varobj_iter_next): Use new instead of XNEW. vitem->name is a std::string now, adjust. * rust-exp.y (convert_ast_to_type, convert_name): Adjust to use std::string. * stabsread.c (define_symbol): Adjust to use std::string. * symtab.c (demangle_for_lookup): Now returns 'const char *'. Add a demangle_result_storage parameter. Use it for storage. (lookup_symbol_in_language) (lookup_symbol_in_objfile_from_linkage_name): Adjust to new demangle_for_lookup API. * symtab.h (struct demangle_result_storage): New type. (demangle_for_lookup): Now returns 'const char *'. Add a demangle_result_storage parameter. * typeprint.c (type_to_string): Return std::string and use ui_file_as_string. * value.h (type_to_string): Change return type to std::string. * varobj-iter.h (struct varobj_item) <name>: Now a std::string. (varobj_iter_delete): Use delete instead of xfree. * varobj.c (create_child): Return std::string instead of char * in output parameter. (name_of_variable, name_of_child, my_value_of_variable): Return std::string instead of char *. (varobj_create, varobj_get_handle): Constify 'objname' parameter. Adjust to std::string fields. (varobj_get_objname): Return a const char * instead of a char *. (varobj_get_expression): Return a std::string. (varobj_list_children): Adjust to use std::string. (varobj_get_type): Return a std::string. (varobj_get_path_expr): Return a const char * instead of a char *. Adjust to std::string fields. (varobj_get_formatted_value, varobj_get_value): Return a std::string. (varobj_set_value): Change type of 'expression' parameter to std::string. Use std::string. (install_new_value): Use std::string. (delete_variable_1): Adjust to use std::string. (create_child): Change the 'name' parameter to a std::string reference. Swap it into the new item's name. (create_child_with_value): Swap item's name into the new child's name. Use string_printf. (new_variable): Use new instead of XNEW. (free_variable): Don't xfree fields that are now std::string. (name_of_variable, name_of_child): Now returns std::string. (value_of_root): Adjust to use std::string. (my_value_of_variable, varobj_value_get_print_value): Return and use std::string. (varobj_value_get_print_value): Adjust to use ui_file_as_string and std::string. * varobj.h (struct varobj) <name, path_expr, obj_name, print_value>: Now std::string's. <name_of_variable, name_of_child, path_expr_of_child, value_of_variable>: Return std::string. (varobj_create, varobj_get_handle): Constify 'objname' parameter. (varobj_get_objname): Return a const char * instead of a char *. (varobj_get_expression, varobj_get_type): Return a std::string. (varobj_get_path_expr): Return a const char * instead of a char *. (varobj_get_formatted_value, varobj_get_value): Return a std::string. (varobj_set_value): Constify 'expression' parameter. (varobj_value_get_print_value): Return a std::string.
2016-11-08 16:26:47 +01:00
or if STRING is already canonical, return the empty string.
Otherwise return the canonical form. */
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
Use ui_file_as_string throughout more This replaces most of the remaining ui_file_xstrdup calls with ui_file_as_string calls. Whenever a call was replaced, that led to a cascade of other necessary adjustments throughout, to make the code use std::string instead of raw pointers. And then whenever I added a std::string as member of a struct, I needed to adjust allocation/destruction of said struct to use new/delete instead of xmalloc/xfree. The stopping point was once gdb built again. These doesn't seem to be a way to reasonably split this out further. Maybe-not-obvious changes: - demangle_for_lookup returns a cleanup today. To get rid of that, and avoid unnecessary string dupping/copying, this introduces a demangle_result_storage type that the caller instantiates and passes to demangle_for_lookup. - Many methods returned a "char *" to indicate that the caller owns the memory and must free it. Those are switched to return a std::string instead. Methods that return a "view" into some internal string return a "const char *" instead. I.e., we only copy/allocate when necessary. gdb/ChangeLog: 2016-11-08 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_name_for_lookup, type_as_string): Use and return std::string. (type_as_string_and_cleanup): Delete. (ada_lookup_struct_elt_type): Use type_as_string. * ada-lang.h (ada_name_for_lookup): Now returns std::string. * ada-varobj.c (ada_varobj_scalar_image): Return a std::string. (ada_varobj_describe_child): Make 'child_name' and 'child_path_expr' parameters std::string pointers. (ada_varobj_describe_struct_child, ada_varobj_describe_ptr_child): Likewise, and use string_printf. (ada_varobj_describe_simple_array_child) (ada_varobj_describe_child): Likewise. (ada_varobj_get_name_of_child, ada_varobj_get_path_expr_of_child) (ada_varobj_get_value_image) (ada_varobj_get_value_of_array_variable) (ada_varobj_get_value_of_variable, ada_name_of_variable) (ada_name_of_child, ada_path_expr_of_child) (ada_value_of_variable): Now returns std::string. Use string_printf. (ada_value_of_child): Adjust. * break-catch-throw.c (check_status_exception_catchpoint): Adjust to use std::string. * breakpoint.c (watch_command_1): Adjust to use std::string. * c-lang.c (c_get_string): Adjust to use std::string. * c-typeprint.c (print_name_maybe_canonical): Use std::string. * c-varobj.c (varobj_is_anonymous_child): Use ==/!= std::string operators. (c_name_of_variable): Now returns a std::string. (c_describe_child): The 'cname' and 'cfull_expression' output parameters are now std::string pointers. Adjust. (c_name_of_child, c_path_expr_of_child, c_value_of_variable) (cplus_number_of_children): Adjust to use std::string and string_printf. (cplus_name_of_variable): Now returns a std::string. (cplus_describe_child): The 'cname' and 'cfull_expression' output parameters are now std::string pointers. Adjust. (cplus_name_of_child, cplus_path_expr_of_child) (cplus_value_of_variable): Now returns a std::string. * cp-abi.c (cplus_typename_from_type_info): Return std::string. * cp-abi.h (cplus_typename_from_type_info): Return std::string. (struct cp_abi_ops) <get_typename_from_type_info>: Return std::string. * cp-support.c (inspect_type): Use std::string. (cp_canonicalize_string_full, cp_canonicalize_string_no_typedefs) (cp_canonicalize_string): Return std::string and adjust. * cp-support.h (cp_canonicalize_string) (cp_canonicalize_string_no_typedefs, cp_canonicalize_string_full): Return std::string. * dbxread.c (read_dbx_symtab): Use std::string. * dwarf2read.c (dwarf2_canonicalize_name): Adjust to use std::string. * gdbcmd.h (lookup_struct_elt_type): Adjust to use std::string. * gnu-v3-abi.c (gnuv3_get_typeid): Use std::string. (gnuv3_get_typename_from_type_info): Return a std::string and adjust. (gnuv3_get_type_from_type_info): Adjust to use std::string. * guile/guile.c (gdbscm_execute_gdb_command): Adjust to use std::string. * infcmd.c (print_return_value_1): Adjust to use std::string. * linespec.c (find_linespec_symbols): Adjust to demangle_for_lookup API change. Use std::string. * mi/mi-cmd-var.c (print_varobj, mi_cmd_var_set_format) (mi_cmd_var_info_type, mi_cmd_var_info_path_expression) (mi_cmd_var_info_expression, mi_cmd_var_evaluate_expression) (mi_cmd_var_assign, varobj_update_one): Adjust to use std::string. * minsyms.c (lookup_minimal_symbol): Use std::string. * python/py-varobj.c (py_varobj_iter_next): Use new instead of XNEW. vitem->name is a std::string now, adjust. * rust-exp.y (convert_ast_to_type, convert_name): Adjust to use std::string. * stabsread.c (define_symbol): Adjust to use std::string. * symtab.c (demangle_for_lookup): Now returns 'const char *'. Add a demangle_result_storage parameter. Use it for storage. (lookup_symbol_in_language) (lookup_symbol_in_objfile_from_linkage_name): Adjust to new demangle_for_lookup API. * symtab.h (struct demangle_result_storage): New type. (demangle_for_lookup): Now returns 'const char *'. Add a demangle_result_storage parameter. * typeprint.c (type_to_string): Return std::string and use ui_file_as_string. * value.h (type_to_string): Change return type to std::string. * varobj-iter.h (struct varobj_item) <name>: Now a std::string. (varobj_iter_delete): Use delete instead of xfree. * varobj.c (create_child): Return std::string instead of char * in output parameter. (name_of_variable, name_of_child, my_value_of_variable): Return std::string instead of char *. (varobj_create, varobj_get_handle): Constify 'objname' parameter. Adjust to std::string fields. (varobj_get_objname): Return a const char * instead of a char *. (varobj_get_expression): Return a std::string. (varobj_list_children): Adjust to use std::string. (varobj_get_type): Return a std::string. (varobj_get_path_expr): Return a const char * instead of a char *. Adjust to std::string fields. (varobj_get_formatted_value, varobj_get_value): Return a std::string. (varobj_set_value): Change type of 'expression' parameter to std::string. Use std::string. (install_new_value): Use std::string. (delete_variable_1): Adjust to use std::string. (create_child): Change the 'name' parameter to a std::string reference. Swap it into the new item's name. (create_child_with_value): Swap item's name into the new child's name. Use string_printf. (new_variable): Use new instead of XNEW. (free_variable): Don't xfree fields that are now std::string. (name_of_variable, name_of_child): Now returns std::string. (value_of_root): Adjust to use std::string. (my_value_of_variable, varobj_value_get_print_value): Return and use std::string. (varobj_value_get_print_value): Adjust to use ui_file_as_string and std::string. * varobj.h (struct varobj) <name, path_expr, obj_name, print_value>: Now std::string's. <name_of_variable, name_of_child, path_expr_of_child, value_of_variable>: Return std::string. (varobj_create, varobj_get_handle): Constify 'objname' parameter. (varobj_get_objname): Return a const char * instead of a char *. (varobj_get_expression, varobj_get_type): Return a std::string. (varobj_get_path_expr): Return a const char * instead of a char *. (varobj_get_formatted_value, varobj_get_value): Return a std::string. (varobj_set_value): Constify 'expression' parameter. (varobj_value_get_print_value): Return a std::string.
2016-11-08 16:26:47 +01:00
std::string
cp_canonicalize_string (const char *string)
{
std::unique_ptr<demangle_parse_info> info;
unsigned int estimated_len;
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
if (cp_already_canonical (string))
Use ui_file_as_string throughout more This replaces most of the remaining ui_file_xstrdup calls with ui_file_as_string calls. Whenever a call was replaced, that led to a cascade of other necessary adjustments throughout, to make the code use std::string instead of raw pointers. And then whenever I added a std::string as member of a struct, I needed to adjust allocation/destruction of said struct to use new/delete instead of xmalloc/xfree. The stopping point was once gdb built again. These doesn't seem to be a way to reasonably split this out further. Maybe-not-obvious changes: - demangle_for_lookup returns a cleanup today. To get rid of that, and avoid unnecessary string dupping/copying, this introduces a demangle_result_storage type that the caller instantiates and passes to demangle_for_lookup. - Many methods returned a "char *" to indicate that the caller owns the memory and must free it. Those are switched to return a std::string instead. Methods that return a "view" into some internal string return a "const char *" instead. I.e., we only copy/allocate when necessary. gdb/ChangeLog: 2016-11-08 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_name_for_lookup, type_as_string): Use and return std::string. (type_as_string_and_cleanup): Delete. (ada_lookup_struct_elt_type): Use type_as_string. * ada-lang.h (ada_name_for_lookup): Now returns std::string. * ada-varobj.c (ada_varobj_scalar_image): Return a std::string. (ada_varobj_describe_child): Make 'child_name' and 'child_path_expr' parameters std::string pointers. (ada_varobj_describe_struct_child, ada_varobj_describe_ptr_child): Likewise, and use string_printf. (ada_varobj_describe_simple_array_child) (ada_varobj_describe_child): Likewise. (ada_varobj_get_name_of_child, ada_varobj_get_path_expr_of_child) (ada_varobj_get_value_image) (ada_varobj_get_value_of_array_variable) (ada_varobj_get_value_of_variable, ada_name_of_variable) (ada_name_of_child, ada_path_expr_of_child) (ada_value_of_variable): Now returns std::string. Use string_printf. (ada_value_of_child): Adjust. * break-catch-throw.c (check_status_exception_catchpoint): Adjust to use std::string. * breakpoint.c (watch_command_1): Adjust to use std::string. * c-lang.c (c_get_string): Adjust to use std::string. * c-typeprint.c (print_name_maybe_canonical): Use std::string. * c-varobj.c (varobj_is_anonymous_child): Use ==/!= std::string operators. (c_name_of_variable): Now returns a std::string. (c_describe_child): The 'cname' and 'cfull_expression' output parameters are now std::string pointers. Adjust. (c_name_of_child, c_path_expr_of_child, c_value_of_variable) (cplus_number_of_children): Adjust to use std::string and string_printf. (cplus_name_of_variable): Now returns a std::string. (cplus_describe_child): The 'cname' and 'cfull_expression' output parameters are now std::string pointers. Adjust. (cplus_name_of_child, cplus_path_expr_of_child) (cplus_value_of_variable): Now returns a std::string. * cp-abi.c (cplus_typename_from_type_info): Return std::string. * cp-abi.h (cplus_typename_from_type_info): Return std::string. (struct cp_abi_ops) <get_typename_from_type_info>: Return std::string. * cp-support.c (inspect_type): Use std::string. (cp_canonicalize_string_full, cp_canonicalize_string_no_typedefs) (cp_canonicalize_string): Return std::string and adjust. * cp-support.h (cp_canonicalize_string) (cp_canonicalize_string_no_typedefs, cp_canonicalize_string_full): Return std::string. * dbxread.c (read_dbx_symtab): Use std::string. * dwarf2read.c (dwarf2_canonicalize_name): Adjust to use std::string. * gdbcmd.h (lookup_struct_elt_type): Adjust to use std::string. * gnu-v3-abi.c (gnuv3_get_typeid): Use std::string. (gnuv3_get_typename_from_type_info): Return a std::string and adjust. (gnuv3_get_type_from_type_info): Adjust to use std::string. * guile/guile.c (gdbscm_execute_gdb_command): Adjust to use std::string. * infcmd.c (print_return_value_1): Adjust to use std::string. * linespec.c (find_linespec_symbols): Adjust to demangle_for_lookup API change. Use std::string. * mi/mi-cmd-var.c (print_varobj, mi_cmd_var_set_format) (mi_cmd_var_info_type, mi_cmd_var_info_path_expression) (mi_cmd_var_info_expression, mi_cmd_var_evaluate_expression) (mi_cmd_var_assign, varobj_update_one): Adjust to use std::string. * minsyms.c (lookup_minimal_symbol): Use std::string. * python/py-varobj.c (py_varobj_iter_next): Use new instead of XNEW. vitem->name is a std::string now, adjust. * rust-exp.y (convert_ast_to_type, convert_name): Adjust to use std::string. * stabsread.c (define_symbol): Adjust to use std::string. * symtab.c (demangle_for_lookup): Now returns 'const char *'. Add a demangle_result_storage parameter. Use it for storage. (lookup_symbol_in_language) (lookup_symbol_in_objfile_from_linkage_name): Adjust to new demangle_for_lookup API. * symtab.h (struct demangle_result_storage): New type. (demangle_for_lookup): Now returns 'const char *'. Add a demangle_result_storage parameter. * typeprint.c (type_to_string): Return std::string and use ui_file_as_string. * value.h (type_to_string): Change return type to std::string. * varobj-iter.h (struct varobj_item) <name>: Now a std::string. (varobj_iter_delete): Use delete instead of xfree. * varobj.c (create_child): Return std::string instead of char * in output parameter. (name_of_variable, name_of_child, my_value_of_variable): Return std::string instead of char *. (varobj_create, varobj_get_handle): Constify 'objname' parameter. Adjust to std::string fields. (varobj_get_objname): Return a const char * instead of a char *. (varobj_get_expression): Return a std::string. (varobj_list_children): Adjust to use std::string. (varobj_get_type): Return a std::string. (varobj_get_path_expr): Return a const char * instead of a char *. Adjust to std::string fields. (varobj_get_formatted_value, varobj_get_value): Return a std::string. (varobj_set_value): Change type of 'expression' parameter to std::string. Use std::string. (install_new_value): Use std::string. (delete_variable_1): Adjust to use std::string. (create_child): Change the 'name' parameter to a std::string reference. Swap it into the new item's name. (create_child_with_value): Swap item's name into the new child's name. Use string_printf. (new_variable): Use new instead of XNEW. (free_variable): Don't xfree fields that are now std::string. (name_of_variable, name_of_child): Now returns std::string. (value_of_root): Adjust to use std::string. (my_value_of_variable, varobj_value_get_print_value): Return and use std::string. (varobj_value_get_print_value): Adjust to use ui_file_as_string and std::string. * varobj.h (struct varobj) <name, path_expr, obj_name, print_value>: Now std::string's. <name_of_variable, name_of_child, path_expr_of_child, value_of_variable>: Return std::string. (varobj_create, varobj_get_handle): Constify 'objname' parameter. (varobj_get_objname): Return a const char * instead of a char *. (varobj_get_expression, varobj_get_type): Return a std::string. (varobj_get_path_expr): Return a const char * instead of a char *. (varobj_get_formatted_value, varobj_get_value): Return a std::string. (varobj_set_value): Constify 'expression' parameter. (varobj_value_get_print_value): Return a std::string.
2016-11-08 16:26:47 +01:00
return std::string ();
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
info = cp_demangled_name_to_comp (string, NULL);
if (info == NULL)
Use ui_file_as_string throughout more This replaces most of the remaining ui_file_xstrdup calls with ui_file_as_string calls. Whenever a call was replaced, that led to a cascade of other necessary adjustments throughout, to make the code use std::string instead of raw pointers. And then whenever I added a std::string as member of a struct, I needed to adjust allocation/destruction of said struct to use new/delete instead of xmalloc/xfree. The stopping point was once gdb built again. These doesn't seem to be a way to reasonably split this out further. Maybe-not-obvious changes: - demangle_for_lookup returns a cleanup today. To get rid of that, and avoid unnecessary string dupping/copying, this introduces a demangle_result_storage type that the caller instantiates and passes to demangle_for_lookup. - Many methods returned a "char *" to indicate that the caller owns the memory and must free it. Those are switched to return a std::string instead. Methods that return a "view" into some internal string return a "const char *" instead. I.e., we only copy/allocate when necessary. gdb/ChangeLog: 2016-11-08 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_name_for_lookup, type_as_string): Use and return std::string. (type_as_string_and_cleanup): Delete. (ada_lookup_struct_elt_type): Use type_as_string. * ada-lang.h (ada_name_for_lookup): Now returns std::string. * ada-varobj.c (ada_varobj_scalar_image): Return a std::string. (ada_varobj_describe_child): Make 'child_name' and 'child_path_expr' parameters std::string pointers. (ada_varobj_describe_struct_child, ada_varobj_describe_ptr_child): Likewise, and use string_printf. (ada_varobj_describe_simple_array_child) (ada_varobj_describe_child): Likewise. (ada_varobj_get_name_of_child, ada_varobj_get_path_expr_of_child) (ada_varobj_get_value_image) (ada_varobj_get_value_of_array_variable) (ada_varobj_get_value_of_variable, ada_name_of_variable) (ada_name_of_child, ada_path_expr_of_child) (ada_value_of_variable): Now returns std::string. Use string_printf. (ada_value_of_child): Adjust. * break-catch-throw.c (check_status_exception_catchpoint): Adjust to use std::string. * breakpoint.c (watch_command_1): Adjust to use std::string. * c-lang.c (c_get_string): Adjust to use std::string. * c-typeprint.c (print_name_maybe_canonical): Use std::string. * c-varobj.c (varobj_is_anonymous_child): Use ==/!= std::string operators. (c_name_of_variable): Now returns a std::string. (c_describe_child): The 'cname' and 'cfull_expression' output parameters are now std::string pointers. Adjust. (c_name_of_child, c_path_expr_of_child, c_value_of_variable) (cplus_number_of_children): Adjust to use std::string and string_printf. (cplus_name_of_variable): Now returns a std::string. (cplus_describe_child): The 'cname' and 'cfull_expression' output parameters are now std::string pointers. Adjust. (cplus_name_of_child, cplus_path_expr_of_child) (cplus_value_of_variable): Now returns a std::string. * cp-abi.c (cplus_typename_from_type_info): Return std::string. * cp-abi.h (cplus_typename_from_type_info): Return std::string. (struct cp_abi_ops) <get_typename_from_type_info>: Return std::string. * cp-support.c (inspect_type): Use std::string. (cp_canonicalize_string_full, cp_canonicalize_string_no_typedefs) (cp_canonicalize_string): Return std::string and adjust. * cp-support.h (cp_canonicalize_string) (cp_canonicalize_string_no_typedefs, cp_canonicalize_string_full): Return std::string. * dbxread.c (read_dbx_symtab): Use std::string. * dwarf2read.c (dwarf2_canonicalize_name): Adjust to use std::string. * gdbcmd.h (lookup_struct_elt_type): Adjust to use std::string. * gnu-v3-abi.c (gnuv3_get_typeid): Use std::string. (gnuv3_get_typename_from_type_info): Return a std::string and adjust. (gnuv3_get_type_from_type_info): Adjust to use std::string. * guile/guile.c (gdbscm_execute_gdb_command): Adjust to use std::string. * infcmd.c (print_return_value_1): Adjust to use std::string. * linespec.c (find_linespec_symbols): Adjust to demangle_for_lookup API change. Use std::string. * mi/mi-cmd-var.c (print_varobj, mi_cmd_var_set_format) (mi_cmd_var_info_type, mi_cmd_var_info_path_expression) (mi_cmd_var_info_expression, mi_cmd_var_evaluate_expression) (mi_cmd_var_assign, varobj_update_one): Adjust to use std::string. * minsyms.c (lookup_minimal_symbol): Use std::string. * python/py-varobj.c (py_varobj_iter_next): Use new instead of XNEW. vitem->name is a std::string now, adjust. * rust-exp.y (convert_ast_to_type, convert_name): Adjust to use std::string. * stabsread.c (define_symbol): Adjust to use std::string. * symtab.c (demangle_for_lookup): Now returns 'const char *'. Add a demangle_result_storage parameter. Use it for storage. (lookup_symbol_in_language) (lookup_symbol_in_objfile_from_linkage_name): Adjust to new demangle_for_lookup API. * symtab.h (struct demangle_result_storage): New type. (demangle_for_lookup): Now returns 'const char *'. Add a demangle_result_storage parameter. * typeprint.c (type_to_string): Return std::string and use ui_file_as_string. * value.h (type_to_string): Change return type to std::string. * varobj-iter.h (struct varobj_item) <name>: Now a std::string. (varobj_iter_delete): Use delete instead of xfree. * varobj.c (create_child): Return std::string instead of char * in output parameter. (name_of_variable, name_of_child, my_value_of_variable): Return std::string instead of char *. (varobj_create, varobj_get_handle): Constify 'objname' parameter. Adjust to std::string fields. (varobj_get_objname): Return a const char * instead of a char *. (varobj_get_expression): Return a std::string. (varobj_list_children): Adjust to use std::string. (varobj_get_type): Return a std::string. (varobj_get_path_expr): Return a const char * instead of a char *. Adjust to std::string fields. (varobj_get_formatted_value, varobj_get_value): Return a std::string. (varobj_set_value): Change type of 'expression' parameter to std::string. Use std::string. (install_new_value): Use std::string. (delete_variable_1): Adjust to use std::string. (create_child): Change the 'name' parameter to a std::string reference. Swap it into the new item's name. (create_child_with_value): Swap item's name into the new child's name. Use string_printf. (new_variable): Use new instead of XNEW. (free_variable): Don't xfree fields that are now std::string. (name_of_variable, name_of_child): Now returns std::string. (value_of_root): Adjust to use std::string. (my_value_of_variable, varobj_value_get_print_value): Return and use std::string. (varobj_value_get_print_value): Adjust to use ui_file_as_string and std::string. * varobj.h (struct varobj) <name, path_expr, obj_name, print_value>: Now std::string's. <name_of_variable, name_of_child, path_expr_of_child, value_of_variable>: Return std::string. (varobj_create, varobj_get_handle): Constify 'objname' parameter. (varobj_get_objname): Return a const char * instead of a char *. (varobj_get_expression, varobj_get_type): Return a std::string. (varobj_get_path_expr): Return a const char * instead of a char *. (varobj_get_formatted_value, varobj_get_value): Return a std::string. (varobj_set_value): Constify 'expression' parameter. (varobj_value_get_print_value): Return a std::string.
2016-11-08 16:26:47 +01:00
return std::string ();
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
estimated_len = strlen (string) * 2;
Fix memory leak in cp-support.c The return value of cp_comp_to_string was never freed, creating a sizable memory leak detectable with valgrind. ==21225== 8 bytes in 1 blocks are definitely lost in loss record 4,599 of 10,949^M ==21225== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M ==21225== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M ==21225== by 0x76CB31: d_growable_string_resize (cp-demangle.c:3963)^M ==21225== by 0x76CB31: d_growable_string_init (cp-demangle.c:3942)^M ==21225== by 0x76CB31: cplus_demangle_print (cp-demangle.c:4308)^M ==21225== by 0x4C9535: cp_comp_to_string(demangle_component*, int) (cp-name-parser.y:1972)^M ==21225== by 0x53E1D4: cp_canonicalize_string_full[abi:cxx11](char const*, char const* (*)(type*, void*), void*) (cp-support.c:530)^M ==21225== by 0x53E360: cp_canonicalize_string_no_typedefs[abi:cxx11](char const*) (cp-support.c:548)^M ==21225== by 0x5D51D2: find_linespec_symbols(linespec_state*, VEC_symtab_ptr*, char const*, VEC_symbolp**, VEC_bound_minimal_symbol_d**) (linespec.c:4030)^M ==21225== by 0x5D6CF6: linespec_parse_basic (linespec.c:1907) ==21279== 32 bytes in 1 blocks are definitely lost in loss record 6,066 of 10,947^M ==21279== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M ==21279== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M ==21279== by 0x76CB31: d_growable_string_resize (cp-demangle.c:3963)^M ==21279== by 0x76CB31: d_growable_string_init (cp-demangle.c:3942)^M ==21279== by 0x76CB31: cplus_demangle_print (cp-demangle.c:4308)^M ==21279== by 0x4C9535: cp_comp_to_string(demangle_component*, int) (cp-name-parser.y:1972)^M ==21279== by 0x53EF14: cp_canonicalize_string[abi:cxx11](char const*) (cp-support.c:569)^M ==21279== by 0x561B75: dwarf2_canonicalize_name(char const*, dwarf2_cu*, obstack*) [clone .isra.210] (dwarf2read.c:20159) This patch fixes the leak. It is a regression by 2f408ecb. gdb: 2017-08-09 Alex Lindsay <alexlindsay239@gmail.com> Yao Qi <yao.qi@linaro.org> * cp-support.c (cp_canonicalize_string_full): Use gdb::unique_xmalloc_ptr<char>. (cp_canonicalize_string): Likewise.
2017-08-09 13:39:16 +02:00
gdb::unique_xmalloc_ptr<char> us (cp_comp_to_string (info->tree,
estimated_len));
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
Fix memory leak in cp-support.c The return value of cp_comp_to_string was never freed, creating a sizable memory leak detectable with valgrind. ==21225== 8 bytes in 1 blocks are definitely lost in loss record 4,599 of 10,949^M ==21225== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M ==21225== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M ==21225== by 0x76CB31: d_growable_string_resize (cp-demangle.c:3963)^M ==21225== by 0x76CB31: d_growable_string_init (cp-demangle.c:3942)^M ==21225== by 0x76CB31: cplus_demangle_print (cp-demangle.c:4308)^M ==21225== by 0x4C9535: cp_comp_to_string(demangle_component*, int) (cp-name-parser.y:1972)^M ==21225== by 0x53E1D4: cp_canonicalize_string_full[abi:cxx11](char const*, char const* (*)(type*, void*), void*) (cp-support.c:530)^M ==21225== by 0x53E360: cp_canonicalize_string_no_typedefs[abi:cxx11](char const*) (cp-support.c:548)^M ==21225== by 0x5D51D2: find_linespec_symbols(linespec_state*, VEC_symtab_ptr*, char const*, VEC_symbolp**, VEC_bound_minimal_symbol_d**) (linespec.c:4030)^M ==21225== by 0x5D6CF6: linespec_parse_basic (linespec.c:1907) ==21279== 32 bytes in 1 blocks are definitely lost in loss record 6,066 of 10,947^M ==21279== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M ==21279== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M ==21279== by 0x76CB31: d_growable_string_resize (cp-demangle.c:3963)^M ==21279== by 0x76CB31: d_growable_string_init (cp-demangle.c:3942)^M ==21279== by 0x76CB31: cplus_demangle_print (cp-demangle.c:4308)^M ==21279== by 0x4C9535: cp_comp_to_string(demangle_component*, int) (cp-name-parser.y:1972)^M ==21279== by 0x53EF14: cp_canonicalize_string[abi:cxx11](char const*) (cp-support.c:569)^M ==21279== by 0x561B75: dwarf2_canonicalize_name(char const*, dwarf2_cu*, obstack*) [clone .isra.210] (dwarf2read.c:20159) This patch fixes the leak. It is a regression by 2f408ecb. gdb: 2017-08-09 Alex Lindsay <alexlindsay239@gmail.com> Yao Qi <yao.qi@linaro.org> * cp-support.c (cp_canonicalize_string_full): Use gdb::unique_xmalloc_ptr<char>. (cp_canonicalize_string): Likewise.
2017-08-09 13:39:16 +02:00
if (!us)
{
warning (_("internal error: string \"%s\" failed to be canonicalized"),
string);
Use ui_file_as_string throughout more This replaces most of the remaining ui_file_xstrdup calls with ui_file_as_string calls. Whenever a call was replaced, that led to a cascade of other necessary adjustments throughout, to make the code use std::string instead of raw pointers. And then whenever I added a std::string as member of a struct, I needed to adjust allocation/destruction of said struct to use new/delete instead of xmalloc/xfree. The stopping point was once gdb built again. These doesn't seem to be a way to reasonably split this out further. Maybe-not-obvious changes: - demangle_for_lookup returns a cleanup today. To get rid of that, and avoid unnecessary string dupping/copying, this introduces a demangle_result_storage type that the caller instantiates and passes to demangle_for_lookup. - Many methods returned a "char *" to indicate that the caller owns the memory and must free it. Those are switched to return a std::string instead. Methods that return a "view" into some internal string return a "const char *" instead. I.e., we only copy/allocate when necessary. gdb/ChangeLog: 2016-11-08 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_name_for_lookup, type_as_string): Use and return std::string. (type_as_string_and_cleanup): Delete. (ada_lookup_struct_elt_type): Use type_as_string. * ada-lang.h (ada_name_for_lookup): Now returns std::string. * ada-varobj.c (ada_varobj_scalar_image): Return a std::string. (ada_varobj_describe_child): Make 'child_name' and 'child_path_expr' parameters std::string pointers. (ada_varobj_describe_struct_child, ada_varobj_describe_ptr_child): Likewise, and use string_printf. (ada_varobj_describe_simple_array_child) (ada_varobj_describe_child): Likewise. (ada_varobj_get_name_of_child, ada_varobj_get_path_expr_of_child) (ada_varobj_get_value_image) (ada_varobj_get_value_of_array_variable) (ada_varobj_get_value_of_variable, ada_name_of_variable) (ada_name_of_child, ada_path_expr_of_child) (ada_value_of_variable): Now returns std::string. Use string_printf. (ada_value_of_child): Adjust. * break-catch-throw.c (check_status_exception_catchpoint): Adjust to use std::string. * breakpoint.c (watch_command_1): Adjust to use std::string. * c-lang.c (c_get_string): Adjust to use std::string. * c-typeprint.c (print_name_maybe_canonical): Use std::string. * c-varobj.c (varobj_is_anonymous_child): Use ==/!= std::string operators. (c_name_of_variable): Now returns a std::string. (c_describe_child): The 'cname' and 'cfull_expression' output parameters are now std::string pointers. Adjust. (c_name_of_child, c_path_expr_of_child, c_value_of_variable) (cplus_number_of_children): Adjust to use std::string and string_printf. (cplus_name_of_variable): Now returns a std::string. (cplus_describe_child): The 'cname' and 'cfull_expression' output parameters are now std::string pointers. Adjust. (cplus_name_of_child, cplus_path_expr_of_child) (cplus_value_of_variable): Now returns a std::string. * cp-abi.c (cplus_typename_from_type_info): Return std::string. * cp-abi.h (cplus_typename_from_type_info): Return std::string. (struct cp_abi_ops) <get_typename_from_type_info>: Return std::string. * cp-support.c (inspect_type): Use std::string. (cp_canonicalize_string_full, cp_canonicalize_string_no_typedefs) (cp_canonicalize_string): Return std::string and adjust. * cp-support.h (cp_canonicalize_string) (cp_canonicalize_string_no_typedefs, cp_canonicalize_string_full): Return std::string. * dbxread.c (read_dbx_symtab): Use std::string. * dwarf2read.c (dwarf2_canonicalize_name): Adjust to use std::string. * gdbcmd.h (lookup_struct_elt_type): Adjust to use std::string. * gnu-v3-abi.c (gnuv3_get_typeid): Use std::string. (gnuv3_get_typename_from_type_info): Return a std::string and adjust. (gnuv3_get_type_from_type_info): Adjust to use std::string. * guile/guile.c (gdbscm_execute_gdb_command): Adjust to use std::string. * infcmd.c (print_return_value_1): Adjust to use std::string. * linespec.c (find_linespec_symbols): Adjust to demangle_for_lookup API change. Use std::string. * mi/mi-cmd-var.c (print_varobj, mi_cmd_var_set_format) (mi_cmd_var_info_type, mi_cmd_var_info_path_expression) (mi_cmd_var_info_expression, mi_cmd_var_evaluate_expression) (mi_cmd_var_assign, varobj_update_one): Adjust to use std::string. * minsyms.c (lookup_minimal_symbol): Use std::string. * python/py-varobj.c (py_varobj_iter_next): Use new instead of XNEW. vitem->name is a std::string now, adjust. * rust-exp.y (convert_ast_to_type, convert_name): Adjust to use std::string. * stabsread.c (define_symbol): Adjust to use std::string. * symtab.c (demangle_for_lookup): Now returns 'const char *'. Add a demangle_result_storage parameter. Use it for storage. (lookup_symbol_in_language) (lookup_symbol_in_objfile_from_linkage_name): Adjust to new demangle_for_lookup API. * symtab.h (struct demangle_result_storage): New type. (demangle_for_lookup): Now returns 'const char *'. Add a demangle_result_storage parameter. * typeprint.c (type_to_string): Return std::string and use ui_file_as_string. * value.h (type_to_string): Change return type to std::string. * varobj-iter.h (struct varobj_item) <name>: Now a std::string. (varobj_iter_delete): Use delete instead of xfree. * varobj.c (create_child): Return std::string instead of char * in output parameter. (name_of_variable, name_of_child, my_value_of_variable): Return std::string instead of char *. (varobj_create, varobj_get_handle): Constify 'objname' parameter. Adjust to std::string fields. (varobj_get_objname): Return a const char * instead of a char *. (varobj_get_expression): Return a std::string. (varobj_list_children): Adjust to use std::string. (varobj_get_type): Return a std::string. (varobj_get_path_expr): Return a const char * instead of a char *. Adjust to std::string fields. (varobj_get_formatted_value, varobj_get_value): Return a std::string. (varobj_set_value): Change type of 'expression' parameter to std::string. Use std::string. (install_new_value): Use std::string. (delete_variable_1): Adjust to use std::string. (create_child): Change the 'name' parameter to a std::string reference. Swap it into the new item's name. (create_child_with_value): Swap item's name into the new child's name. Use string_printf. (new_variable): Use new instead of XNEW. (free_variable): Don't xfree fields that are now std::string. (name_of_variable, name_of_child): Now returns std::string. (value_of_root): Adjust to use std::string. (my_value_of_variable, varobj_value_get_print_value): Return and use std::string. (varobj_value_get_print_value): Adjust to use ui_file_as_string and std::string. * varobj.h (struct varobj) <name, path_expr, obj_name, print_value>: Now std::string's. <name_of_variable, name_of_child, path_expr_of_child, value_of_variable>: Return std::string. (varobj_create, varobj_get_handle): Constify 'objname' parameter. (varobj_get_objname): Return a const char * instead of a char *. (varobj_get_expression, varobj_get_type): Return a std::string. (varobj_get_path_expr): Return a const char * instead of a char *. (varobj_get_formatted_value, varobj_get_value): Return a std::string. (varobj_set_value): Constify 'expression' parameter. (varobj_value_get_print_value): Return a std::string.
2016-11-08 16:26:47 +01:00
return std::string ();
}
Fix memory leak in cp-support.c The return value of cp_comp_to_string was never freed, creating a sizable memory leak detectable with valgrind. ==21225== 8 bytes in 1 blocks are definitely lost in loss record 4,599 of 10,949^M ==21225== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M ==21225== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M ==21225== by 0x76CB31: d_growable_string_resize (cp-demangle.c:3963)^M ==21225== by 0x76CB31: d_growable_string_init (cp-demangle.c:3942)^M ==21225== by 0x76CB31: cplus_demangle_print (cp-demangle.c:4308)^M ==21225== by 0x4C9535: cp_comp_to_string(demangle_component*, int) (cp-name-parser.y:1972)^M ==21225== by 0x53E1D4: cp_canonicalize_string_full[abi:cxx11](char const*, char const* (*)(type*, void*), void*) (cp-support.c:530)^M ==21225== by 0x53E360: cp_canonicalize_string_no_typedefs[abi:cxx11](char const*) (cp-support.c:548)^M ==21225== by 0x5D51D2: find_linespec_symbols(linespec_state*, VEC_symtab_ptr*, char const*, VEC_symbolp**, VEC_bound_minimal_symbol_d**) (linespec.c:4030)^M ==21225== by 0x5D6CF6: linespec_parse_basic (linespec.c:1907) ==21279== 32 bytes in 1 blocks are definitely lost in loss record 6,066 of 10,947^M ==21279== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M ==21279== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M ==21279== by 0x76CB31: d_growable_string_resize (cp-demangle.c:3963)^M ==21279== by 0x76CB31: d_growable_string_init (cp-demangle.c:3942)^M ==21279== by 0x76CB31: cplus_demangle_print (cp-demangle.c:4308)^M ==21279== by 0x4C9535: cp_comp_to_string(demangle_component*, int) (cp-name-parser.y:1972)^M ==21279== by 0x53EF14: cp_canonicalize_string[abi:cxx11](char const*) (cp-support.c:569)^M ==21279== by 0x561B75: dwarf2_canonicalize_name(char const*, dwarf2_cu*, obstack*) [clone .isra.210] (dwarf2read.c:20159) This patch fixes the leak. It is a regression by 2f408ecb. gdb: 2017-08-09 Alex Lindsay <alexlindsay239@gmail.com> Yao Qi <yao.qi@linaro.org> * cp-support.c (cp_canonicalize_string_full): Use gdb::unique_xmalloc_ptr<char>. (cp_canonicalize_string): Likewise.
2017-08-09 13:39:16 +02:00
std::string ret (us.get ());
Use ui_file_as_string throughout more This replaces most of the remaining ui_file_xstrdup calls with ui_file_as_string calls. Whenever a call was replaced, that led to a cascade of other necessary adjustments throughout, to make the code use std::string instead of raw pointers. And then whenever I added a std::string as member of a struct, I needed to adjust allocation/destruction of said struct to use new/delete instead of xmalloc/xfree. The stopping point was once gdb built again. These doesn't seem to be a way to reasonably split this out further. Maybe-not-obvious changes: - demangle_for_lookup returns a cleanup today. To get rid of that, and avoid unnecessary string dupping/copying, this introduces a demangle_result_storage type that the caller instantiates and passes to demangle_for_lookup. - Many methods returned a "char *" to indicate that the caller owns the memory and must free it. Those are switched to return a std::string instead. Methods that return a "view" into some internal string return a "const char *" instead. I.e., we only copy/allocate when necessary. gdb/ChangeLog: 2016-11-08 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_name_for_lookup, type_as_string): Use and return std::string. (type_as_string_and_cleanup): Delete. (ada_lookup_struct_elt_type): Use type_as_string. * ada-lang.h (ada_name_for_lookup): Now returns std::string. * ada-varobj.c (ada_varobj_scalar_image): Return a std::string. (ada_varobj_describe_child): Make 'child_name' and 'child_path_expr' parameters std::string pointers. (ada_varobj_describe_struct_child, ada_varobj_describe_ptr_child): Likewise, and use string_printf. (ada_varobj_describe_simple_array_child) (ada_varobj_describe_child): Likewise. (ada_varobj_get_name_of_child, ada_varobj_get_path_expr_of_child) (ada_varobj_get_value_image) (ada_varobj_get_value_of_array_variable) (ada_varobj_get_value_of_variable, ada_name_of_variable) (ada_name_of_child, ada_path_expr_of_child) (ada_value_of_variable): Now returns std::string. Use string_printf. (ada_value_of_child): Adjust. * break-catch-throw.c (check_status_exception_catchpoint): Adjust to use std::string. * breakpoint.c (watch_command_1): Adjust to use std::string. * c-lang.c (c_get_string): Adjust to use std::string. * c-typeprint.c (print_name_maybe_canonical): Use std::string. * c-varobj.c (varobj_is_anonymous_child): Use ==/!= std::string operators. (c_name_of_variable): Now returns a std::string. (c_describe_child): The 'cname' and 'cfull_expression' output parameters are now std::string pointers. Adjust. (c_name_of_child, c_path_expr_of_child, c_value_of_variable) (cplus_number_of_children): Adjust to use std::string and string_printf. (cplus_name_of_variable): Now returns a std::string. (cplus_describe_child): The 'cname' and 'cfull_expression' output parameters are now std::string pointers. Adjust. (cplus_name_of_child, cplus_path_expr_of_child) (cplus_value_of_variable): Now returns a std::string. * cp-abi.c (cplus_typename_from_type_info): Return std::string. * cp-abi.h (cplus_typename_from_type_info): Return std::string. (struct cp_abi_ops) <get_typename_from_type_info>: Return std::string. * cp-support.c (inspect_type): Use std::string. (cp_canonicalize_string_full, cp_canonicalize_string_no_typedefs) (cp_canonicalize_string): Return std::string and adjust. * cp-support.h (cp_canonicalize_string) (cp_canonicalize_string_no_typedefs, cp_canonicalize_string_full): Return std::string. * dbxread.c (read_dbx_symtab): Use std::string. * dwarf2read.c (dwarf2_canonicalize_name): Adjust to use std::string. * gdbcmd.h (lookup_struct_elt_type): Adjust to use std::string. * gnu-v3-abi.c (gnuv3_get_typeid): Use std::string. (gnuv3_get_typename_from_type_info): Return a std::string and adjust. (gnuv3_get_type_from_type_info): Adjust to use std::string. * guile/guile.c (gdbscm_execute_gdb_command): Adjust to use std::string. * infcmd.c (print_return_value_1): Adjust to use std::string. * linespec.c (find_linespec_symbols): Adjust to demangle_for_lookup API change. Use std::string. * mi/mi-cmd-var.c (print_varobj, mi_cmd_var_set_format) (mi_cmd_var_info_type, mi_cmd_var_info_path_expression) (mi_cmd_var_info_expression, mi_cmd_var_evaluate_expression) (mi_cmd_var_assign, varobj_update_one): Adjust to use std::string. * minsyms.c (lookup_minimal_symbol): Use std::string. * python/py-varobj.c (py_varobj_iter_next): Use new instead of XNEW. vitem->name is a std::string now, adjust. * rust-exp.y (convert_ast_to_type, convert_name): Adjust to use std::string. * stabsread.c (define_symbol): Adjust to use std::string. * symtab.c (demangle_for_lookup): Now returns 'const char *'. Add a demangle_result_storage parameter. Use it for storage. (lookup_symbol_in_language) (lookup_symbol_in_objfile_from_linkage_name): Adjust to new demangle_for_lookup API. * symtab.h (struct demangle_result_storage): New type. (demangle_for_lookup): Now returns 'const char *'. Add a demangle_result_storage parameter. * typeprint.c (type_to_string): Return std::string and use ui_file_as_string. * value.h (type_to_string): Change return type to std::string. * varobj-iter.h (struct varobj_item) <name>: Now a std::string. (varobj_iter_delete): Use delete instead of xfree. * varobj.c (create_child): Return std::string instead of char * in output parameter. (name_of_variable, name_of_child, my_value_of_variable): Return std::string instead of char *. (varobj_create, varobj_get_handle): Constify 'objname' parameter. Adjust to std::string fields. (varobj_get_objname): Return a const char * instead of a char *. (varobj_get_expression): Return a std::string. (varobj_list_children): Adjust to use std::string. (varobj_get_type): Return a std::string. (varobj_get_path_expr): Return a const char * instead of a char *. Adjust to std::string fields. (varobj_get_formatted_value, varobj_get_value): Return a std::string. (varobj_set_value): Change type of 'expression' parameter to std::string. Use std::string. (install_new_value): Use std::string. (delete_variable_1): Adjust to use std::string. (create_child): Change the 'name' parameter to a std::string reference. Swap it into the new item's name. (create_child_with_value): Swap item's name into the new child's name. Use string_printf. (new_variable): Use new instead of XNEW. (free_variable): Don't xfree fields that are now std::string. (name_of_variable, name_of_child): Now returns std::string. (value_of_root): Adjust to use std::string. (my_value_of_variable, varobj_value_get_print_value): Return and use std::string. (varobj_value_get_print_value): Adjust to use ui_file_as_string and std::string. * varobj.h (struct varobj) <name, path_expr, obj_name, print_value>: Now std::string's. <name_of_variable, name_of_child, path_expr_of_child, value_of_variable>: Return std::string. (varobj_create, varobj_get_handle): Constify 'objname' parameter. (varobj_get_objname): Return a const char * instead of a char *. (varobj_get_expression, varobj_get_type): Return a std::string. (varobj_get_path_expr): Return a const char * instead of a char *. (varobj_get_formatted_value, varobj_get_value): Return a std::string. (varobj_set_value): Constify 'expression' parameter. (varobj_value_get_print_value): Return a std::string.
2016-11-08 16:26:47 +01:00
if (ret == string)
return std::string ();
return ret;
}
/* Convert a mangled name to a demangle_component tree. *MEMORY is
set to the block of used memory that should be freed when finished
with the tree. DEMANGLED_P is set to the char * that should be
freed when finished with the tree, or NULL if none was needed.
OPTIONS will be passed to the demangler. */
static std::unique_ptr<demangle_parse_info>
mangled_name_to_comp (const char *mangled_name, int options,
void **memory, char **demangled_p)
{
char *demangled_name;
/* If it looks like a v3 mangled name, then try to go directly
to trees. */
if (mangled_name[0] == '_' && mangled_name[1] == 'Z')
{
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
struct demangle_component *ret;
ret = cplus_demangle_v3_components (mangled_name,
options, memory);
if (ret)
{
std::unique_ptr<demangle_parse_info> info (new demangle_parse_info);
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
info->tree = ret;
*demangled_p = NULL;
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
return info;
}
}
/* If it doesn't, or if that failed, then try to demangle the
name. */
demangled_name = gdb_demangle (mangled_name, options);
if (demangled_name == NULL)
return NULL;
/* If we could demangle the name, parse it to build the component
tree. */
std::unique_ptr<demangle_parse_info> info
= cp_demangled_name_to_comp (demangled_name, NULL);
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
if (info == NULL)
{
xfree (demangled_name);
return NULL;
}
*demangled_p = demangled_name;
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
return info;
}
/* Return the name of the class containing method PHYSNAME. */
char *
cp_class_name_from_physname (const char *physname)
{
void *storage = NULL;
char *demangled_name = NULL;
gdb::unique_xmalloc_ptr<char> ret;
struct demangle_component *ret_comp, *prev_comp, *cur_comp;
std::unique_ptr<demangle_parse_info> info;
int done;
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
info = mangled_name_to_comp (physname, DMGL_ANSI,
&storage, &demangled_name);
if (info == NULL)
return NULL;
done = 0;
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
ret_comp = info->tree;
/* First strip off any qualifiers, if we have a function or
method. */
while (!done)
switch (ret_comp->type)
{
case DEMANGLE_COMPONENT_CONST:
case DEMANGLE_COMPONENT_RESTRICT:
case DEMANGLE_COMPONENT_VOLATILE:
case DEMANGLE_COMPONENT_CONST_THIS:
case DEMANGLE_COMPONENT_RESTRICT_THIS:
case DEMANGLE_COMPONENT_VOLATILE_THIS:
case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
ret_comp = d_left (ret_comp);
break;
default:
done = 1;
break;
}
/* If what we have now is a function, discard the argument list. */
if (ret_comp->type == DEMANGLE_COMPONENT_TYPED_NAME)
ret_comp = d_left (ret_comp);
/* If what we have now is a template, strip off the template
arguments. The left subtree may be a qualified name. */
if (ret_comp->type == DEMANGLE_COMPONENT_TEMPLATE)
ret_comp = d_left (ret_comp);
/* What we have now should be a name, possibly qualified.
Additional qualifiers could live in the left subtree or the right
subtree. Find the last piece. */
done = 0;
prev_comp = NULL;
cur_comp = ret_comp;
while (!done)
switch (cur_comp->type)
{
case DEMANGLE_COMPONENT_QUAL_NAME:
case DEMANGLE_COMPONENT_LOCAL_NAME:
prev_comp = cur_comp;
cur_comp = d_right (cur_comp);
break;
case DEMANGLE_COMPONENT_TEMPLATE:
case DEMANGLE_COMPONENT_NAME:
case DEMANGLE_COMPONENT_CTOR:
case DEMANGLE_COMPONENT_DTOR:
case DEMANGLE_COMPONENT_OPERATOR:
case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
done = 1;
break;
default:
done = 1;
cur_comp = NULL;
break;
}
if (cur_comp != NULL && prev_comp != NULL)
{
/* We want to discard the rightmost child of PREV_COMP. */
*prev_comp = *d_left (prev_comp);
/* The ten is completely arbitrary; we don't have a good
estimate. */
ret = cp_comp_to_string (ret_comp, 10);
}
xfree (storage);
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
xfree (demangled_name);
return ret.release ();
}
/* Return the child of COMP which is the basename of a method,
variable, et cetera. All scope qualifiers are discarded, but
template arguments will be included. The component tree may be
modified. */
static struct demangle_component *
unqualified_name_from_comp (struct demangle_component *comp)
{
struct demangle_component *ret_comp = comp, *last_template;
int done;
done = 0;
last_template = NULL;
while (!done)
switch (ret_comp->type)
{
case DEMANGLE_COMPONENT_QUAL_NAME:
case DEMANGLE_COMPONENT_LOCAL_NAME:
ret_comp = d_right (ret_comp);
break;
case DEMANGLE_COMPONENT_TYPED_NAME:
ret_comp = d_left (ret_comp);
break;
case DEMANGLE_COMPONENT_TEMPLATE:
gdb_assert (last_template == NULL);
last_template = ret_comp;
ret_comp = d_left (ret_comp);
break;
case DEMANGLE_COMPONENT_CONST:
case DEMANGLE_COMPONENT_RESTRICT:
case DEMANGLE_COMPONENT_VOLATILE:
case DEMANGLE_COMPONENT_CONST_THIS:
case DEMANGLE_COMPONENT_RESTRICT_THIS:
case DEMANGLE_COMPONENT_VOLATILE_THIS:
case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
ret_comp = d_left (ret_comp);
break;
case DEMANGLE_COMPONENT_NAME:
case DEMANGLE_COMPONENT_CTOR:
case DEMANGLE_COMPONENT_DTOR:
case DEMANGLE_COMPONENT_OPERATOR:
case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
done = 1;
break;
default:
return NULL;
break;
}
if (last_template)
{
d_left (last_template) = ret_comp;
return last_template;
}
return ret_comp;
}
/* Return the name of the method whose linkage name is PHYSNAME. */
char *
method_name_from_physname (const char *physname)
{
void *storage = NULL;
char *demangled_name = NULL;
gdb::unique_xmalloc_ptr<char> ret;
struct demangle_component *ret_comp;
std::unique_ptr<demangle_parse_info> info;
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
info = mangled_name_to_comp (physname, DMGL_ANSI,
&storage, &demangled_name);
if (info == NULL)
return NULL;
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
ret_comp = unqualified_name_from_comp (info->tree);
if (ret_comp != NULL)
/* The ten is completely arbitrary; we don't have a good
estimate. */
ret = cp_comp_to_string (ret_comp, 10);
xfree (storage);
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
xfree (demangled_name);
return ret.release ();
}
/* If FULL_NAME is the demangled name of a C++ function (including an
arg list, possibly including namespace/class qualifications),
return a new string containing only the function name (without the
arg list/class qualifications). Otherwise, return NULL. */
gdb::unique_xmalloc_ptr<char>
cp_func_name (const char *full_name)
{
gdb::unique_xmalloc_ptr<char> ret;
struct demangle_component *ret_comp;
std::unique_ptr<demangle_parse_info> info;
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
info = cp_demangled_name_to_comp (full_name, NULL);
if (!info)
return nullptr;
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
ret_comp = unqualified_name_from_comp (info->tree);
if (ret_comp != NULL)
ret = cp_comp_to_string (ret_comp, 10);
return ret;
}
lookup_name_info::make_ignore_params A few places in the completion code look for a "(" to find a function's parameter list, in order to strip it, because psymtabs (and gdb index) don't include parameter info in the symbol names. See compare_symbol_name and default_collect_symbol_completion_matches_break_on. This is too naive. Consider: ns_overload2_test::([TAB] We'd want to complete that to: ns_overload2_test::(anonymous namespace)::struct_overload2_test Or: b (anonymous namespace)::[TAB] That currently completes to: b (anonymous namespace) Which is obviously broken. This patch makes that work. Also, the current compare_symbol_name hack means that while this works: "b function([TAB]" -> "b function()" This does not: "b function ([TAB]" This patch fixes that. Whitespace "ignoring" now Just Works, i.e., assuming a symbol named "function(int, long)", this: b function ( int , lon[TAB] completes to: b function ( int , long) To address all of this, this patch builds on top of the rest of the series, and pushes the responsibility of stripping parameters from a lookup name to the new lookup_name_info object, where we can apply per-language rules. Also note that we now only make a version of the lookup name with parameters stripped out where it's actually required to do that, in the psymtab and GDB index code. For C++, the right way to strip parameters is with "cp_remove_params", which uses a real parser (cp-name-parser.y) to split the name into a component tree and then discards parameters. The trouble for completion is that in that case we have an incomplete name, like "foo::func(int" and thus cp_remove_params throws an error. This patch sorts that by adding a cp_remove_params_if_any variant of cp_remove_params that tries removing characters from the end of the string until cp_remove_params works. So cp_remove_params_if_any behaves like this: With a complete name: "foo::func(int)" => foo::func(int) # cp_remove_params_1 succeeds the first time. With an incomplete name: "foo::func(int" => NULL # cp_remove_params fails the first time. "foo::func(in" => NULL # and again... "foo::func(i" => NULL # and again... "foo::func(" => NULL # and again... "foo::func" => "foo::func" # success! Note that even if this approach removes significant rightmost characters, it's still OK, because this parameter stripping is only necessary for psymtabs and gdb index, where we're determining whether to expand a symbol table. Say cp_remove_params_if_any returned "foo::" above for "foo::func(int". That'd cause us to expand more symtabs than ideal (because we'd expand all symtabs with symbols that start with "foo::", not just "foo::func"), but then when we actually look for completion matches, we'd still use the original lookup name, with parameter information ["foo::func(int"], and thus we'll return no false positive to the user. Whether the stripping works as intended and doesn't strip too much is thus covered by a unit test instead of a testsuite test. The "if_any" part of the name refers to the fact that while cp_remove_params returns NULL if the input name has no parameters in the first place, like: "foo::func" => NULL # cp_remove_params cp_remove_params_if_any still returns the function name: "foo::func" => "foo::func" # cp_remove_params_if_any gdb/ChangeLog: 2017-11-08 Pedro Alves <palves@redhat.com> * Makefile.in (SUBDIR_UNITTESTS_SRCS): Add unittests/lookup_name_info-selftests.c. (SUBDIR_UNITTESTS_OBS): Add lookup_name_info-selftests.o. * cp-support.c: Include "selftest.h". (cp_remove_params_1): Rename from cp_remove_params. Add 'require_param' parameter, and handle it. (cp_remove_params): Reimplement. (cp_remove_params_if_any): New. (selftests::quote): New. (selftests::check_remove_params): New. (selftests::test_cp_remove_params): New. (_initialize_cp_support): Install selftests::test_cp_remove_params. * cp-support.h (cp_remove_params_if_any): Declare. * dwarf2read.c :Include "selftest.h". (dw2_expand_symtabs_matching_symbol): Use lookup_name_info::make_ignore_params. (selftests::dw2_expand_symtabs_matching::mock_mapped_index) (selftests::dw2_expand_symtabs_matching::string_or_null) (selftests::dw2_expand_symtabs_matching::check_match) (selftests::dw2_expand_symtabs_matching::test_symbols) (selftests::dw2_expand_symtabs_matching::run_test): New. (_initialize_dwarf2_read): Register selftests::dw2_expand_symtabs_matching::run_test. * psymtab.c (psym_expand_symtabs_matching): Use lookup_name_info::make_ignore_params. * symtab.c (demangle_for_lookup_info::demangle_for_lookup_info): If the lookup name wants to ignore parameters, strip them. (compare_symbol_name): Remove sym_text/sym_text_len parameters and code handling '('. (completion_list_add_name): Don't pass down sym_text/sym_text_len. (default_collect_symbol_completion_matches_break_on): Don't try to strip parameters. * symtab.h (lookup_name_info::lookup_name_info): Add 'ignore_parameters' parameter. (lookup_name_info::ignore_parameters) (lookup_name_info::make_ignore_params): New methods. (lookup_name_info::m_ignore_parameters): New field. * unittests/lookup_name_info-selftests.c: New file.
2017-11-08 15:49:10 +01:00
/* Helper for cp_remove_params. DEMANGLED_NAME is the name of a
function, including parameters and (optionally) a return type.
Return the name of the function without parameters or return type,
or NULL if we can not parse the name. If REQUIRE_PARAMS is false,
then tolerate a non-existing or unbalanced parameter list. */
lookup_name_info::make_ignore_params A few places in the completion code look for a "(" to find a function's parameter list, in order to strip it, because psymtabs (and gdb index) don't include parameter info in the symbol names. See compare_symbol_name and default_collect_symbol_completion_matches_break_on. This is too naive. Consider: ns_overload2_test::([TAB] We'd want to complete that to: ns_overload2_test::(anonymous namespace)::struct_overload2_test Or: b (anonymous namespace)::[TAB] That currently completes to: b (anonymous namespace) Which is obviously broken. This patch makes that work. Also, the current compare_symbol_name hack means that while this works: "b function([TAB]" -> "b function()" This does not: "b function ([TAB]" This patch fixes that. Whitespace "ignoring" now Just Works, i.e., assuming a symbol named "function(int, long)", this: b function ( int , lon[TAB] completes to: b function ( int , long) To address all of this, this patch builds on top of the rest of the series, and pushes the responsibility of stripping parameters from a lookup name to the new lookup_name_info object, where we can apply per-language rules. Also note that we now only make a version of the lookup name with parameters stripped out where it's actually required to do that, in the psymtab and GDB index code. For C++, the right way to strip parameters is with "cp_remove_params", which uses a real parser (cp-name-parser.y) to split the name into a component tree and then discards parameters. The trouble for completion is that in that case we have an incomplete name, like "foo::func(int" and thus cp_remove_params throws an error. This patch sorts that by adding a cp_remove_params_if_any variant of cp_remove_params that tries removing characters from the end of the string until cp_remove_params works. So cp_remove_params_if_any behaves like this: With a complete name: "foo::func(int)" => foo::func(int) # cp_remove_params_1 succeeds the first time. With an incomplete name: "foo::func(int" => NULL # cp_remove_params fails the first time. "foo::func(in" => NULL # and again... "foo::func(i" => NULL # and again... "foo::func(" => NULL # and again... "foo::func" => "foo::func" # success! Note that even if this approach removes significant rightmost characters, it's still OK, because this parameter stripping is only necessary for psymtabs and gdb index, where we're determining whether to expand a symbol table. Say cp_remove_params_if_any returned "foo::" above for "foo::func(int". That'd cause us to expand more symtabs than ideal (because we'd expand all symtabs with symbols that start with "foo::", not just "foo::func"), but then when we actually look for completion matches, we'd still use the original lookup name, with parameter information ["foo::func(int"], and thus we'll return no false positive to the user. Whether the stripping works as intended and doesn't strip too much is thus covered by a unit test instead of a testsuite test. The "if_any" part of the name refers to the fact that while cp_remove_params returns NULL if the input name has no parameters in the first place, like: "foo::func" => NULL # cp_remove_params cp_remove_params_if_any still returns the function name: "foo::func" => "foo::func" # cp_remove_params_if_any gdb/ChangeLog: 2017-11-08 Pedro Alves <palves@redhat.com> * Makefile.in (SUBDIR_UNITTESTS_SRCS): Add unittests/lookup_name_info-selftests.c. (SUBDIR_UNITTESTS_OBS): Add lookup_name_info-selftests.o. * cp-support.c: Include "selftest.h". (cp_remove_params_1): Rename from cp_remove_params. Add 'require_param' parameter, and handle it. (cp_remove_params): Reimplement. (cp_remove_params_if_any): New. (selftests::quote): New. (selftests::check_remove_params): New. (selftests::test_cp_remove_params): New. (_initialize_cp_support): Install selftests::test_cp_remove_params. * cp-support.h (cp_remove_params_if_any): Declare. * dwarf2read.c :Include "selftest.h". (dw2_expand_symtabs_matching_symbol): Use lookup_name_info::make_ignore_params. (selftests::dw2_expand_symtabs_matching::mock_mapped_index) (selftests::dw2_expand_symtabs_matching::string_or_null) (selftests::dw2_expand_symtabs_matching::check_match) (selftests::dw2_expand_symtabs_matching::test_symbols) (selftests::dw2_expand_symtabs_matching::run_test): New. (_initialize_dwarf2_read): Register selftests::dw2_expand_symtabs_matching::run_test. * psymtab.c (psym_expand_symtabs_matching): Use lookup_name_info::make_ignore_params. * symtab.c (demangle_for_lookup_info::demangle_for_lookup_info): If the lookup name wants to ignore parameters, strip them. (compare_symbol_name): Remove sym_text/sym_text_len parameters and code handling '('. (completion_list_add_name): Don't pass down sym_text/sym_text_len. (default_collect_symbol_completion_matches_break_on): Don't try to strip parameters. * symtab.h (lookup_name_info::lookup_name_info): Add 'ignore_parameters' parameter. (lookup_name_info::ignore_parameters) (lookup_name_info::make_ignore_params): New methods. (lookup_name_info::m_ignore_parameters): New field. * unittests/lookup_name_info-selftests.c: New file.
2017-11-08 15:49:10 +01:00
static gdb::unique_xmalloc_ptr<char>
cp_remove_params_1 (const char *demangled_name, bool require_params)
{
bool done = false;
struct demangle_component *ret_comp;
std::unique_ptr<demangle_parse_info> info;
gdb::unique_xmalloc_ptr<char> ret;
if (demangled_name == NULL)
return NULL;
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
info = cp_demangled_name_to_comp (demangled_name, NULL);
if (info == NULL)
return NULL;
/* First strip off any qualifiers, if we have a function or method. */
PR c++/12266 * cp-name-parser.y (struct demangle_info): Remove unused member PREV. (d_grab): Likewise. (allocate_info): Change return type to struct demangle_info *. Always allocate a new demangle_info. Remove unused PREV pointer. (cp_new_demangle_parse_info): New function. (cp_demangled_name_parse_free): New function. (do_demangled_name_parse_free_cleanup): New function. (make_cleanup_cp_demangled_name_parse_free): New function. (cp_demangled_name_to_comp): Change return type to struct demangle_parse_info *. Allocate a new storage for each call. (main): Update usage for cp_demangled_name_to_comp API change. * cp-support.h (struct demangle_parse_info): New structure. (cp_demangled_name_to_comp): Update API change for return type. (cp_new_demangle_parse_info): Declare. (make_cleanup_cp_demangled_name_parse_free): New declaration. (cp_demangled_name_parse_free): Declare. * cp-support.c (cp_canonicalize_string): Update API change for cp_demangled_name_to_comp. (mangled_name_to_comp): Likewise. Return struct demangle_parse_info, too. (cp_class_name_from_physname): Update mangled_name_to_comp API change. (method_name_from_physname): Likewise. (cp_func_name): Update API change for cp_demangled_name_to_comp. (cp_remove_params): Likewise. * python/py-type.c (typy_legacy_template_argument): Likewise. * cp-support.h (cp_canonicalize_string_no_typedefs): Declare. (cp_merge_demangle_parse_infos): Declare. * cp-support.c (ignore_typedefs): New file global. (copy_string_to_obstack): New function. (inspect_type): New function. (replace_typedefs): New function. (replace_typedefs_qualified_name): New function. (cp_canonicalize_string_no_typedefs): New function. * cp-name-parser.y (cp_merge_demangle_parse_infos): New function. (cp_new_demangle__parse_info): Allocate and initialize the obstack. * linespec.c (find_methods): Use cp_canonicalize_string_no_typedefs instead of cp_canonicalize_string. (find_method): Likewise. (decode_compound): Before looking up the name, call cp_canonicalize_string_no_typedefs. (decode_variable): Likewise.
2011-08-18 18:17:39 +02:00
ret_comp = info->tree;
while (!done)
switch (ret_comp->type)
{
case DEMANGLE_COMPONENT_CONST:
case DEMANGLE_COMPONENT_RESTRICT:
case DEMANGLE_COMPONENT_VOLATILE:
case DEMANGLE_COMPONENT_CONST_THIS:
case DEMANGLE_COMPONENT_RESTRICT_THIS:
case DEMANGLE_COMPONENT_VOLATILE_THIS:
case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
ret_comp = d_left (ret_comp);
break;
default:
done = true;
break;
}
/* What we have now should be a function. Return its name. */
if (ret_comp->type == DEMANGLE_COMPONENT_TYPED_NAME)
ret = cp_comp_to_string (d_left (ret_comp), 10);
lookup_name_info::make_ignore_params A few places in the completion code look for a "(" to find a function's parameter list, in order to strip it, because psymtabs (and gdb index) don't include parameter info in the symbol names. See compare_symbol_name and default_collect_symbol_completion_matches_break_on. This is too naive. Consider: ns_overload2_test::([TAB] We'd want to complete that to: ns_overload2_test::(anonymous namespace)::struct_overload2_test Or: b (anonymous namespace)::[TAB] That currently completes to: b (anonymous namespace) Which is obviously broken. This patch makes that work. Also, the current compare_symbol_name hack means that while this works: "b function([TAB]" -> "b function()" This does not: "b function ([TAB]" This patch fixes that. Whitespace "ignoring" now Just Works, i.e., assuming a symbol named "function(int, long)", this: b function ( int , lon[TAB] completes to: b function ( int , long) To address all of this, this patch builds on top of the rest of the series, and pushes the responsibility of stripping parameters from a lookup name to the new lookup_name_info object, where we can apply per-language rules. Also note that we now only make a version of the lookup name with parameters stripped out where it's actually required to do that, in the psymtab and GDB index code. For C++, the right way to strip parameters is with "cp_remove_params", which uses a real parser (cp-name-parser.y) to split the name into a component tree and then discards parameters. The trouble for completion is that in that case we have an incomplete name, like "foo::func(int" and thus cp_remove_params throws an error. This patch sorts that by adding a cp_remove_params_if_any variant of cp_remove_params that tries removing characters from the end of the string until cp_remove_params works. So cp_remove_params_if_any behaves like this: With a complete name: "foo::func(int)" => foo::func(int) # cp_remove_params_1 succeeds the first time. With an incomplete name: "foo::func(int" => NULL # cp_remove_params fails the first time. "foo::func(in" => NULL # and again... "foo::func(i" => NULL # and again... "foo::func(" => NULL # and again... "foo::func" => "foo::func" # success! Note that even if this approach removes significant rightmost characters, it's still OK, because this parameter stripping is only necessary for psymtabs and gdb index, where we're determining whether to expand a symbol table. Say cp_remove_params_if_any returned "foo::" above for "foo::func(int". That'd cause us to expand more symtabs than ideal (because we'd expand all symtabs with symbols that start with "foo::", not just "foo::func"), but then when we actually look for completion matches, we'd still use the original lookup name, with parameter information ["foo::func(int"], and thus we'll return no false positive to the user. Whether the stripping works as intended and doesn't strip too much is thus covered by a unit test instead of a testsuite test. The "if_any" part of the name refers to the fact that while cp_remove_params returns NULL if the input name has no parameters in the first place, like: "foo::func" => NULL # cp_remove_params cp_remove_params_if_any still returns the function name: "foo::func" => "foo::func" # cp_remove_params_if_any gdb/ChangeLog: 2017-11-08 Pedro Alves <palves@redhat.com> * Makefile.in (SUBDIR_UNITTESTS_SRCS): Add unittests/lookup_name_info-selftests.c. (SUBDIR_UNITTESTS_OBS): Add lookup_name_info-selftests.o. * cp-support.c: Include "selftest.h". (cp_remove_params_1): Rename from cp_remove_params. Add 'require_param' parameter, and handle it. (cp_remove_params): Reimplement. (cp_remove_params_if_any): New. (selftests::quote): New. (selftests::check_remove_params): New. (selftests::test_cp_remove_params): New. (_initialize_cp_support): Install selftests::test_cp_remove_params. * cp-support.h (cp_remove_params_if_any): Declare. * dwarf2read.c :Include "selftest.h". (dw2_expand_symtabs_matching_symbol): Use lookup_name_info::make_ignore_params. (selftests::dw2_expand_symtabs_matching::mock_mapped_index) (selftests::dw2_expand_symtabs_matching::string_or_null) (selftests::dw2_expand_symtabs_matching::check_match) (selftests::dw2_expand_symtabs_matching::test_symbols) (selftests::dw2_expand_symtabs_matching::run_test): New. (_initialize_dwarf2_read): Register selftests::dw2_expand_symtabs_matching::run_test. * psymtab.c (psym_expand_symtabs_matching): Use lookup_name_info::make_ignore_params. * symtab.c (demangle_for_lookup_info::demangle_for_lookup_info): If the lookup name wants to ignore parameters, strip them. (compare_symbol_name): Remove sym_text/sym_text_len parameters and code handling '('. (completion_list_add_name): Don't pass down sym_text/sym_text_len. (default_collect_symbol_completion_matches_break_on): Don't try to strip parameters. * symtab.h (lookup_name_info::lookup_name_info): Add 'ignore_parameters' parameter. (lookup_name_info::ignore_parameters) (lookup_name_info::make_ignore_params): New methods. (lookup_name_info::m_ignore_parameters): New field. * unittests/lookup_name_info-selftests.c: New file.
2017-11-08 15:49:10 +01:00
else if (!require_params
&& (ret_comp->type == DEMANGLE_COMPONENT_NAME
|| ret_comp->type == DEMANGLE_COMPONENT_QUAL_NAME
|| ret_comp->type == DEMANGLE_COMPONENT_TEMPLATE))
ret = cp_comp_to_string (ret_comp, 10);
return ret;
}
lookup_name_info::make_ignore_params A few places in the completion code look for a "(" to find a function's parameter list, in order to strip it, because psymtabs (and gdb index) don't include parameter info in the symbol names. See compare_symbol_name and default_collect_symbol_completion_matches_break_on. This is too naive. Consider: ns_overload2_test::([TAB] We'd want to complete that to: ns_overload2_test::(anonymous namespace)::struct_overload2_test Or: b (anonymous namespace)::[TAB] That currently completes to: b (anonymous namespace) Which is obviously broken. This patch makes that work. Also, the current compare_symbol_name hack means that while this works: "b function([TAB]" -> "b function()" This does not: "b function ([TAB]" This patch fixes that. Whitespace "ignoring" now Just Works, i.e., assuming a symbol named "function(int, long)", this: b function ( int , lon[TAB] completes to: b function ( int , long) To address all of this, this patch builds on top of the rest of the series, and pushes the responsibility of stripping parameters from a lookup name to the new lookup_name_info object, where we can apply per-language rules. Also note that we now only make a version of the lookup name with parameters stripped out where it's actually required to do that, in the psymtab and GDB index code. For C++, the right way to strip parameters is with "cp_remove_params", which uses a real parser (cp-name-parser.y) to split the name into a component tree and then discards parameters. The trouble for completion is that in that case we have an incomplete name, like "foo::func(int" and thus cp_remove_params throws an error. This patch sorts that by adding a cp_remove_params_if_any variant of cp_remove_params that tries removing characters from the end of the string until cp_remove_params works. So cp_remove_params_if_any behaves like this: With a complete name: "foo::func(int)" => foo::func(int) # cp_remove_params_1 succeeds the first time. With an incomplete name: "foo::func(int" => NULL # cp_remove_params fails the first time. "foo::func(in" => NULL # and again... "foo::func(i" => NULL # and again... "foo::func(" => NULL # and again... "foo::func" => "foo::func" # success! Note that even if this approach removes significant rightmost characters, it's still OK, because this parameter stripping is only necessary for psymtabs and gdb index, where we're determining whether to expand a symbol table. Say cp_remove_params_if_any returned "foo::" above for "foo::func(int". That'd cause us to expand more symtabs than ideal (because we'd expand all symtabs with symbols that start with "foo::", not just "foo::func"), but then when we actually look for completion matches, we'd still use the original lookup name, with parameter information ["foo::func(int"], and thus we'll return no false positive to the user. Whether the stripping works as intended and doesn't strip too much is thus covered by a unit test instead of a testsuite test. The "if_any" part of the name refers to the fact that while cp_remove_params returns NULL if the input name has no parameters in the first place, like: "foo::func" => NULL # cp_remove_params cp_remove_params_if_any still returns the function name: "foo::func" => "foo::func" # cp_remove_params_if_any gdb/ChangeLog: 2017-11-08 Pedro Alves <palves@redhat.com> * Makefile.in (SUBDIR_UNITTESTS_SRCS): Add unittests/lookup_name_info-selftests.c. (SUBDIR_UNITTESTS_OBS): Add lookup_name_info-selftests.o. * cp-support.c: Include "selftest.h". (cp_remove_params_1): Rename from cp_remove_params. Add 'require_param' parameter, and handle it. (cp_remove_params): Reimplement. (cp_remove_params_if_any): New. (selftests::quote): New. (selftests::check_remove_params): New. (selftests::test_cp_remove_params): New. (_initialize_cp_support): Install selftests::test_cp_remove_params. * cp-support.h (cp_remove_params_if_any): Declare. * dwarf2read.c :Include "selftest.h". (dw2_expand_symtabs_matching_symbol): Use lookup_name_info::make_ignore_params. (selftests::dw2_expand_symtabs_matching::mock_mapped_index) (selftests::dw2_expand_symtabs_matching::string_or_null) (selftests::dw2_expand_symtabs_matching::check_match) (selftests::dw2_expand_symtabs_matching::test_symbols) (selftests::dw2_expand_symtabs_matching::run_test): New. (_initialize_dwarf2_read): Register selftests::dw2_expand_symtabs_matching::run_test. * psymtab.c (psym_expand_symtabs_matching): Use lookup_name_info::make_ignore_params. * symtab.c (demangle_for_lookup_info::demangle_for_lookup_info): If the lookup name wants to ignore parameters, strip them. (compare_symbol_name): Remove sym_text/sym_text_len parameters and code handling '('. (completion_list_add_name): Don't pass down sym_text/sym_text_len. (default_collect_symbol_completion_matches_break_on): Don't try to strip parameters. * symtab.h (lookup_name_info::lookup_name_info): Add 'ignore_parameters' parameter. (lookup_name_info::ignore_parameters) (lookup_name_info::make_ignore_params): New methods. (lookup_name_info::m_ignore_parameters): New field. * unittests/lookup_name_info-selftests.c: New file.
2017-11-08 15:49:10 +01:00
/* DEMANGLED_NAME is the name of a function, including parameters and
(optionally) a return type. Return the name of the function
without parameters or return type, or NULL if we can not parse the
name. */
gdb::unique_xmalloc_ptr<char>
cp_remove_params (const char *demangled_name)
{
return cp_remove_params_1 (demangled_name, true);
}
/* See cp-support.h. */
gdb::unique_xmalloc_ptr<char>
cp_remove_params_if_any (const char *demangled_name, bool completion_mode)
{
/* Trying to remove parameters from the empty string fails. If
we're completing / matching everything, avoid returning NULL
which would make callers interpret the result as an error. */
if (demangled_name[0] == '\0' && completion_mode)
Introduce and use make_unique_xstrdup Adds an utility function to make it shorter to write the common case of wrapping an xstrdup with a unique_xmalloc_ptr, and uses it throughout. Note: I tried to put this in common/common-utils.h near skip_spaces, etc. but that is included in common/common-defs.h before common/gdb_unique_ptr.h is included, so it would fail to compile because gdb::unique_xmalloc_ptr isn't defined at that point yet. I tried moving the gdb_unique_ptr.h inclusion before common-utils.h, but that doesn't work because gdb_unique_ptr.h depends on common-utils.h for xfree. gdb/ChangeLog: 2019-06-04 Pedro Alves <palves@redhat.com> * common/gdb_unique_ptr.h (make_unique_xstrdup): New. * ada-lang.c (catch_ada_completer): Use make_unique_xstrdup. * breakpoint.c (condition_completer): Likewise. * cli/cli-dump.c (scan_expression): Likewise. * common/filestuff.c (mkdir_recursive): Likewise. * common/gdb_tilde_expand.c (gdb_tilde_expand_up) * common/pathstuff.c (gdb_realpath, gdb_realpath_keepfile) (gdb_abspath): Likewise. * compile/compile-cplus-types.c (compile_cplus_instance::decl_name): Likewise. * completer.c (complete_explicit_location): (signal_completer, reg_or_group_completer_1): Likewise. * cp-support.c (cp_remove_params_if_any): Likewise. * fbsd-tdep.c (fbsd_core_vnode_path): Likewise. * guile/scm-safe-call.c (gdbscm_safe_eval_string): Likewise. * infcmd.c (strip_bg_char): Likewise. * linespec.c (copy_token_string): Likewise. * mi/mi-main.c (output_cores): Likewise. * psymtab.c (psymtab_search_name): * symfile.c (test_set_ext_lang_command): Likewise. * target.c (target_fileio_read_stralloc): Likewise. * tui/tui-regs.c (tui_reggroup_completer): Likewise. * value.c (complete_internalvar): Likewise. gdb/gdbserver/ChangeLog: 2019-06-04 Pedro Alves <palves@redhat.com> * server.c (captured_main): Use make_unique_xstrdup.
2019-06-04 23:40:54 +02:00
return make_unique_xstrdup ("");
lookup_name_info::make_ignore_params A few places in the completion code look for a "(" to find a function's parameter list, in order to strip it, because psymtabs (and gdb index) don't include parameter info in the symbol names. See compare_symbol_name and default_collect_symbol_completion_matches_break_on. This is too naive. Consider: ns_overload2_test::([TAB] We'd want to complete that to: ns_overload2_test::(anonymous namespace)::struct_overload2_test Or: b (anonymous namespace)::[TAB] That currently completes to: b (anonymous namespace) Which is obviously broken. This patch makes that work. Also, the current compare_symbol_name hack means that while this works: "b function([TAB]" -> "b function()" This does not: "b function ([TAB]" This patch fixes that. Whitespace "ignoring" now Just Works, i.e., assuming a symbol named "function(int, long)", this: b function ( int , lon[TAB] completes to: b function ( int , long) To address all of this, this patch builds on top of the rest of the series, and pushes the responsibility of stripping parameters from a lookup name to the new lookup_name_info object, where we can apply per-language rules. Also note that we now only make a version of the lookup name with parameters stripped out where it's actually required to do that, in the psymtab and GDB index code. For C++, the right way to strip parameters is with "cp_remove_params", which uses a real parser (cp-name-parser.y) to split the name into a component tree and then discards parameters. The trouble for completion is that in that case we have an incomplete name, like "foo::func(int" and thus cp_remove_params throws an error. This patch sorts that by adding a cp_remove_params_if_any variant of cp_remove_params that tries removing characters from the end of the string until cp_remove_params works. So cp_remove_params_if_any behaves like this: With a complete name: "foo::func(int)" => foo::func(int) # cp_remove_params_1 succeeds the first time. With an incomplete name: "foo::func(int" => NULL # cp_remove_params fails the first time. "foo::func(in" => NULL # and again... "foo::func(i" => NULL # and again... "foo::func(" => NULL # and again... "foo::func" => "foo::func" # success! Note that even if this approach removes significant rightmost characters, it's still OK, because this parameter stripping is only necessary for psymtabs and gdb index, where we're determining whether to expand a symbol table. Say cp_remove_params_if_any returned "foo::" above for "foo::func(int". That'd cause us to expand more symtabs than ideal (because we'd expand all symtabs with symbols that start with "foo::", not just "foo::func"), but then when we actually look for completion matches, we'd still use the original lookup name, with parameter information ["foo::func(int"], and thus we'll return no false positive to the user. Whether the stripping works as intended and doesn't strip too much is thus covered by a unit test instead of a testsuite test. The "if_any" part of the name refers to the fact that while cp_remove_params returns NULL if the input name has no parameters in the first place, like: "foo::func" => NULL # cp_remove_params cp_remove_params_if_any still returns the function name: "foo::func" => "foo::func" # cp_remove_params_if_any gdb/ChangeLog: 2017-11-08 Pedro Alves <palves@redhat.com> * Makefile.in (SUBDIR_UNITTESTS_SRCS): Add unittests/lookup_name_info-selftests.c. (SUBDIR_UNITTESTS_OBS): Add lookup_name_info-selftests.o. * cp-support.c: Include "selftest.h". (cp_remove_params_1): Rename from cp_remove_params. Add 'require_param' parameter, and handle it. (cp_remove_params): Reimplement. (cp_remove_params_if_any): New. (selftests::quote): New. (selftests::check_remove_params): New. (selftests::test_cp_remove_params): New. (_initialize_cp_support): Install selftests::test_cp_remove_params. * cp-support.h (cp_remove_params_if_any): Declare. * dwarf2read.c :Include "selftest.h". (dw2_expand_symtabs_matching_symbol): Use lookup_name_info::make_ignore_params. (selftests::dw2_expand_symtabs_matching::mock_mapped_index) (selftests::dw2_expand_symtabs_matching::string_or_null) (selftests::dw2_expand_symtabs_matching::check_match) (selftests::dw2_expand_symtabs_matching::test_symbols) (selftests::dw2_expand_symtabs_matching::run_test): New. (_initialize_dwarf2_read): Register selftests::dw2_expand_symtabs_matching::run_test. * psymtab.c (psym_expand_symtabs_matching): Use lookup_name_info::make_ignore_params. * symtab.c (demangle_for_lookup_info::demangle_for_lookup_info): If the lookup name wants to ignore parameters, strip them. (compare_symbol_name): Remove sym_text/sym_text_len parameters and code handling '('. (completion_list_add_name): Don't pass down sym_text/sym_text_len. (default_collect_symbol_completion_matches_break_on): Don't try to strip parameters. * symtab.h (lookup_name_info::lookup_name_info): Add 'ignore_parameters' parameter. (lookup_name_info::ignore_parameters) (lookup_name_info::make_ignore_params): New methods. (lookup_name_info::m_ignore_parameters): New field. * unittests/lookup_name_info-selftests.c: New file.
2017-11-08 15:49:10 +01:00
gdb::unique_xmalloc_ptr<char> without_params
= cp_remove_params_1 (demangled_name, false);
if (without_params == NULL && completion_mode)
{
std::string copy = demangled_name;
while (!copy.empty ())
{
copy.pop_back ();
without_params = cp_remove_params_1 (copy.c_str (), false);
if (without_params != NULL)
break;
}
}
return without_params;
}
/* Here are some random pieces of trivia to keep in mind while trying
to take apart demangled names:
- Names can contain function arguments or templates, so the process
has to be, to some extent recursive: maybe keep track of your
depth based on encountering <> and ().
- Parentheses don't just have to happen at the end of a name: they
can occur even if the name in question isn't a function, because
a template argument might be a type that's a function.
- Conversely, even if you're trying to deal with a function, its
demangled name might not end with ')': it could be a const or
volatile class method, in which case it ends with "const" or
"volatile".
- Parentheses are also used in anonymous namespaces: a variable
'foo' in an anonymous namespace gets demangled as "(anonymous
namespace)::foo".
- And operator names can contain parentheses or angle brackets. */
/* FIXME: carlton/2003-03-13: We have several functions here with
overlapping functionality; can we combine them? Also, do they
handle all the above considerations correctly? */
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
/* This returns the length of first component of NAME, which should be
the demangled name of a C++ variable/function/method/etc.
Specifically, it returns the index of the first colon forming the
boundary of the first component: so, given 'A::foo' or 'A::B::foo'
it returns the 1, and given 'foo', it returns 0. */
/* The character in NAME indexed by the return value is guaranteed to
always be either ':' or '\0'. */
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
/* NOTE: carlton/2003-03-13: This function is currently only intended
for internal use: it's probably not entirely safe when called on
user-generated input, because some of the 'index += 2' lines in
cp_find_first_component_aux might go past the end of malformed
input. */
unsigned int
cp_find_first_component (const char *name)
{
return cp_find_first_component_aux (name, 0);
}
/* Helper function for cp_find_first_component. Like that function,
it returns the length of the first component of NAME, but to make
the recursion easier, it also stops if it reaches an unexpected ')'
or '>' if the value of PERMISSIVE is nonzero. */
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
static unsigned int
cp_find_first_component_aux (const char *name, int permissive)
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
{
unsigned int index = 0;
/* Operator names can show up in unexpected places. Since these can
contain parentheses or angle brackets, they can screw up the
recursion. But not every string 'operator' is part of an
[gdb] Fix more typos in comments (2) Fix typos in comments. NFC. Tested on x86_64-linux. gdb/ChangeLog: 2019-10-26 Tom de Vries <tdevries@suse.de> * aarch64-linux-tdep.c: Fix typos in comments. * aarch64-tdep.c: Same. * ada-lang.c: Same. * amd64-nat.c: Same. * arc-tdep.c: Same. * arch/aarch64-insn.c: Same. * block.c: Same. * breakpoint.h: Same. * btrace.h: Same. * c-varobj.c: Same. * cli/cli-decode.c: Same. * cli/cli-script.c: Same. * cli/cli-utils.h: Same. * coff-pe-read.c: Same. * coffread.c: Same. * compile/compile-cplus-symbols.c: Same. * compile/compile-object-run.c: Same. * completer.c: Same. * corelow.c: Same. * cp-support.c: Same. * demangle.c: Same. * dwarf-index-write.c: Same. * dwarf2-frame.c: Same. * dwarf2-frame.h: Same. * eval.c: Same. * frame-base.h: Same. * frame.h: Same. * gdbcmd.h: Same. * gdbtypes.h: Same. * gnu-nat.c: Same. * guile/scm-objfile.c: Same. * i386-tdep.c: Same. * i386-tdep.h: Same. * infcall.c: Same. * infcall.h: Same. * linux-nat.c: Same. * m68k-tdep.c: Same. * macroexp.c: Same. * memattr.c: Same. * mi/mi-cmd-disas.c: Same. * mi/mi-getopt.h: Same. * mi/mi-main.c: Same. * minsyms.c: Same. * nat/aarch64-sve-linux-sigcontext.h: Same. * objfiles.h: Same. * ppc-linux-nat.c: Same. * ppc-linux-tdep.c: Same. * ppc-tdep.h: Same. * progspace.h: Same. * prologue-value.h: Same. * python/py-evtregistry.c: Same. * python/py-instruction.h: Same. * record-btrace.c: Same. * record-full.c: Same. * remote.c: Same. * rs6000-tdep.c: Same. * ser-tcp.c: Same. * sol-thread.c: Same. * sparc-sol2-tdep.c: Same. * sparc64-tdep.c: Same. * stabsread.c: Same. * symfile.c: Same. * symtab.h: Same. * target.c: Same. * tracepoint.c: Same. * tui/tui-data.h: Same. * tui/tui-io.c: Same. * tui/tui-win.c: Same. * tui/tui.c: Same. * unittests/rsp-low-selftests.c: Same. * user-regs.h: Same. * utils.c: Same. * utils.h: Same. * valarith.c: Same. * valops.c: Same. * valprint.c: Same. * valprint.h: Same. * value.c: Same. * value.h: Same. * varobj.c: Same. * x86-nat.h: Same. * xtensa-tdep.c: Same. gdb/gdbserver/ChangeLog: 2019-10-26 Tom de Vries <tdevries@suse.de> * linux-aarch64-low.c: Fix typos in comments. * linux-arm-low.c: Same. * linux-low.c: Same. * linux-ppc-low.c: Same. * proc-service.c: Same. * regcache.h: Same. * server.c: Same. * tracepoint.c: Same. * win32-low.c: Same. gdb/stubs/ChangeLog: 2019-10-26 Tom de Vries <tdevries@suse.de> * ia64vms-stub.c: Fix typos in comments. * m32r-stub.c: Same. * m68k-stub.c: Same. * sh-stub.c: Same. gdb/testsuite/ChangeLog: 2019-10-26 Tom de Vries <tdevries@suse.de> * gdb.base/bigcore.c: Fix typos in comments. * gdb.base/ctf-ptype.c: Same. * gdb.base/long_long.c: Same. * gdb.dwarf2/dw2-op-out-param.S: Same. * gdb.python/py-evthreads.c: Same. * gdb.reverse/i387-stack-reverse.c: Same. * gdb.trace/tfile.c: Same. * lib/compiler.c: Same. * lib/compiler.cc: Same. Change-Id: I8573d84a577894270179ae30f46c48d806fc1beb
2019-10-26 09:55:32 +02:00
operator name: e.g. you could have a variable 'cooperator'. So
this variable tells us whether or not we should treat the string
'operator' as starting an operator. */
int operator_possible = 1;
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
for (;; ++index)
{
switch (name[index])
{
case '<':
/* Template; eat it up. The calls to cp_first_component
should only return (I hope!) when they reach the '>'
terminating the component or a '::' between two
components. (Hence the '+ 2'.) */
index += 1;
for (index += cp_find_first_component_aux (name + index, 1);
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
name[index] != '>';
index += cp_find_first_component_aux (name + index, 1))
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
{
if (name[index] != ':')
{
demangled_name_complaint (name);
return strlen (name);
}
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
index += 2;
}
operator_possible = 1;
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
break;
case '(':
/* Similar comment as to '<'. */
index += 1;
for (index += cp_find_first_component_aux (name + index, 1);
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
name[index] != ')';
index += cp_find_first_component_aux (name + index, 1))
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
{
if (name[index] != ':')
{
demangled_name_complaint (name);
return strlen (name);
}
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
index += 2;
}
operator_possible = 1;
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
break;
case '>':
case ')':
if (permissive)
2003-06-30 18:23:29 +02:00
return index;
else
{
demangled_name_complaint (name);
return strlen (name);
}
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
case '\0':
return index;
PR 18303, Tolerate malformed input for lookup_symbol-called functions lookup_symbol is often called with user input. Consequently, any function called from lookup_symbol{,_in_language} should attempt to deal with malformed input gracefully. After all, malformed user input is not a programming/API error. This patch does not attempt to find/correct all instances of this. It only fixes locations in the code that trigger test suite failures. This patch fixes PR breakpoints/18303, "Assertion: -breakpoint-insert with windows paths of file in non-current directory". The patch includes three new tests related to this. One is just gdb.linespec/ls-errs.exp copied and converted to use C++ instead of C, and to add a case using a file name containing a Windows-style logical drive specifier. The others include an MI test to provide a regression test for the specific case reported in PR 18303, and a C++ test for proper error handling of access to a program variable when using a file scope specifier that refers to a non-existent file. Tested on x86_64 native Linux. gdb/ChangeLog 2016-01-28 Keith Seitz <keiths@redhat.com> PR breakpoints/18303 * cp-namespace.c (cp_lookup_bare_symbol): Change assertion to look for "::" instead of simply ":". (cp_search_static_and_baseclasses): Return null_block_symbol for malformed input. Remove assertions. * cp-support.c (cp_find_first_component_aux): Do not return a prefix length for ':' unless the next character is also ':'. gdb/testsuite/ChangeLog 2016-01-28 Don Breazeal <donb@codesourcery.com> * gdb.cp/scope-err.cc: New test program. * gdb.cp/scope-err.exp: New test script. * gdb.linespec/ls-errs.c (myfunction): Expanded to have multiple lines and "set breakpoint here" comment. * gdb.linespec/ls-errs.exp: Added C++ testing and new test case. Fixed some whitespace and format issues. * gdb.mi/mi-linespec-err-cp.cc: New test program. * gdb.mi/mi-linespec-err-cp.exp: New test script.
2016-03-15 23:18:28 +01:00
case ':':
/* ':' marks a component iff the next character is also a ':'.
Otherwise it is probably malformed input. */
if (name[index + 1] == ':')
return index;
break;
case 'o':
/* Operator names can screw up the recursion. */
if (operator_possible
&& startswith (name + index, CP_OPERATOR_STR))
{
index += CP_OPERATOR_LEN;
while (ISSPACE(name[index]))
++index;
switch (name[index])
{
Fix cp_find_first_component_aux bug Valgrind catches an out-of-bounds read here: $ gdb ./testsuite/outputs/gdb.cp/method2/method2 (gdb) start [...] Temporary breakpoint 1, main (argc=1, argv=0x7fffffffd958) at src/gdb/testsuite/gdb.cp/method2.cc:26 26 return 0; (gdb) b A::operator ==26907== Invalid read of size 1 ==26907== at 0x75C0AE: cp_find_first_component_aux(char const*, int) (cp-support.c:951) ==26907== by 0x75C084: cp_find_first_component(char const*) (cp-support.c:925) ==26907== by 0x75C3DA: cp_entire_prefix_len(char const*) (cp-support.c:1089) ==26907== by 0x758B16: cp_lookup_symbol_in_namespace(char const*, char const*, block const*, domain_enum_tag, int) (cp-namespace.c:314) ==26907== by 0x75972A: lookup_namespace_scope(language_defn const*, char const*, block const*, domain_enum_tag, char const*, int) (cp-namespace.c:739) ==26907== by 0x7597CB: cp_lookup_symbol_nonlocal(language_defn const*, char const*, block const*, domain_enum_tag) (cp-namespace.c:768) ==26907== by 0x8C1137: lookup_symbol_aux(char const*, block const*, domain_enum_tag, language, field_of_this_result*) (symtab.c:2016) ==26907== by 0x8C098A: lookup_symbol_in_language(char const*, block const*, domain_enum_tag, language, field_of_this_result*) (symtab.c:1824) ==26907== by 0x8C0A04: lookup_symbol(char const*, block const*, domain_enum_tag, field_of_this_result*) (symtab.c:1836) ==26907== by 0x82CBE1: find_label_symbols(linespec_state*, VEC_symbolp*, VEC_symbolp**, char const*) (linespec.c:3390) ==26907== by 0x828FB5: linespec_parse_basic(ls_parser*) (linespec.c:1620) ==26907== by 0x82A78F: parse_linespec(ls_parser*, char const*) (linespec.c:2307) ==26907== Address 0x910f97c is 0 bytes after a block of size 12 alloc'd ==26907== at 0x4C28BF6: malloc (vg_replace_malloc.c:299) ==26907== by 0x74E737: xmalloc (common-utils.c:43) ==26907== by 0x74EAF4: savestring(char const*, unsigned long) (common-utils.c:179) ==26907== by 0x826CEF: copy_token_string(ls_token) (linespec.c:488) ==26907== by 0x828EF6: linespec_parse_basic(ls_parser*) (linespec.c:1599) ==26907== by 0x82A78F: parse_linespec(ls_parser*, char const*) (linespec.c:2307) ==26907== by 0x82AE27: event_location_to_sals(ls_parser*, event_location const*) (linespec.c:2469) ==26907== by 0x82B1CE: decode_line_full(event_location const*, int, program_space*, symtab*, int, linespec_result*, char const*, char const*) (linespec.c:2557) ==26907== by 0x720C8A: parse_breakpoint_sals(event_location const*, linespec_result*) (breakpoint.c:9550) ==26907== by 0x72A2F7: create_sals_from_location_default(event_location const*, linespec_result*, bptype) (breakpoint.c:14484) ==26907== by 0x727F86: bkpt_create_sals_from_location(event_location const*, linespec_result*, bptype) (breakpoint.c:13219) ==26907== by 0x72146D: create_breakpoint(gdbarch*, event_location const*, char*, int, char*, int, int, bptype, int, auto_boolean, breakpoint_ops const*, int, int, int, unsigned int) (breakpoint.c:9759) Tests exercising this will be added further down the series. gdb/ChangeLog: 2017-07-20 Pedro Alves <palves@redhat.com> * cp-support.c (cp_find_first_component_aux): Add missing case for end of string.
2017-07-20 18:58:17 +02:00
case '\0':
return index;
/* Skip over one less than the appropriate number of
characters: the for loop will skip over the last
one. */
case '<':
if (name[index + 1] == '<')
index += 1;
else
index += 0;
break;
case '>':
case '-':
if (name[index + 1] == '>')
index += 1;
else
index += 0;
break;
case '(':
index += 1;
break;
default:
index += 0;
break;
}
}
operator_possible = 0;
break;
case ' ':
case ',':
case '.':
case '&':
case '*':
/* NOTE: carlton/2003-04-18: I'm not sure what the precise
set of relevant characters are here: it's necessary to
include any character that can show up before 'operator'
in a demangled name, and it's safe to include any
character that can't be part of an identifier's name. */
operator_possible = 1;
break;
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
default:
operator_possible = 0;
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
break;
}
}
}
/* Complain about a demangled name that we don't know how to parse.
NAME is the demangled name in question. */
static void
demangled_name_complaint (const char *name)
{
Remove symfile_complaints The complaint system seems to allow for multiple different complaint topics. However, in practice only symfile_complaints has ever been defined. Seeing that complaints.c dates to 1992, and that no new complaints have been added in the intervening years, I think it is reasonable to admit that complaints are specifically related to debuginfo reading. This patch removes symfile_complaints and updates all the callers. Some of these spots should perhaps be calls to warning instead, but I did not make that change. gdb/ChangeLog 2018-05-23 Tom Tromey <tom@tromey.com> * complaints.c (symfile_complaints): Remove. (complaint_internal): Remove "complaints" parameter. (clear_complaints, vcomplaint): Remove "c" parameter. (get_complaints): Remove. * dwarf2read.c (dwarf2_statement_list_fits_in_line_number_section_complaint) (dwarf2_debug_line_missing_file_complaint) (dwarf2_debug_line_missing_end_sequence_complaint) (dwarf2_complex_location_expr_complaint) (dwarf2_const_value_length_mismatch_complaint) (dwarf2_section_buffer_overflow_complaint) (dwarf2_macro_malformed_definition_complaint) (dwarf2_invalid_attrib_class_complaint) (create_addrmap_from_index, dw2_symtab_iter_next) (dw2_expand_marked_cus) (dw2_debug_names_iterator::find_vec_in_debug_names) (dw2_debug_names_iterator::next, dw2_debug_names_iterator::next) (create_debug_type_hash_table, init_cutu_and_read_dies) (partial_die_parent_scope, add_partial_enumeration) (skip_one_die, fixup_go_packaging, quirk_rust_enum, process_die) (dwarf2_compute_name, dwarf2_physname, read_namespace_alias) (read_import_statement, read_file_scope, create_dwo_cu_reader) (create_cus_hash_table, create_dwp_hash_table) (inherit_abstract_dies, read_func_scope, read_call_site_scope) (dwarf2_rnglists_process, dwarf2_ranges_process) (dwarf2_add_type_defn, dwarf2_attach_fields_to_type) (dwarf2_add_member_fn, get_alignment, maybe_set_alignment) (handle_struct_member_die, process_structure_scope) (read_array_type, read_common_block, read_module_type) (read_tag_pointer_type, read_typedef, read_base_type) (read_subrange_type, load_partial_dies, partial_die_info::read) (partial_die_info::read, partial_die_info::read) (partial_die_info::read, read_checked_initial_length_and_offset) (dwarf2_string_attr, read_formatted_entries) (dwarf_decode_line_header) (lnp_state_machine::check_line_address, dwarf_decode_lines_1) (new_symbol, dwarf2_const_value_attr, lookup_die_type) (read_type_die_1, determine_prefix, dwarf2_get_ref_die_offset) (dwarf2_get_attr_constant_value, dwarf2_fetch_constant_bytes) (get_signatured_type, get_DW_AT_signature_type) (decode_locdesc, file_file_name, consume_improper_spaces) (skip_form_bytes, skip_unknown_opcode, dwarf_parse_macro_header) (dwarf_decode_macro_bytes, dwarf_decode_macros) (dwarf2_symbol_mark_computed, set_die_type) (read_attribute_value): Update. * stap-probe.c (handle_stap_probe, get_stap_base_address): Update. * dbxread.c (unknown_symtype_complaint) (lbrac_mismatch_complaint, repeated_header_complaint) (set_namestring, function_outside_compilation_unit_complaint) (read_dbx_symtab, process_one_symbol): Update. * gdbtypes.c (stub_noname_complaint): Update. * windows-nat.c (handle_unload_dll): Update. * coffread.c (coff_symtab_read, enter_linenos, decode_type) (decode_base_type): Update. * xcoffread.c (bf_notfound_complaint, ef_complaint) (eb_complaint, record_include_begin, record_include_end) (enter_line_range, xcoff_next_symbol_text, read_xcoff_symtab) (process_xcoff_symbol, read_symbol) (function_outside_compilation_unit_complaint) (scan_xcoff_symtab): Update. * machoread.c (macho_symtab_read, macho_add_oso_symfile): Update. * buildsym.c (finish_block_internal, make_blockvector) (end_symtab_get_static_block, augment_type_symtab): Update. * dtrace-probe.c (dtrace_process_dof) (dtrace_static_probe_ops::get_probes): Update. * complaints.h (struct complaint): Don't declare. (symfile_complaints): Remove. (complaint_internal): Remove "complaints" parameter. (complaint): Likewise. (clear_complaints): Likewise. * symfile.c (syms_from_objfile_1, finish_new_objfile) (reread_symbols): Update. * dwarf2-frame.c (dwarf2_restore_rule, execute_cfa_program) (dwarf2_frame_cache, decode_frame_entry): Update. * dwarf2loc.c (dwarf_reg_to_regnum): Update. * objc-lang.c (lookup_objc_class, lookup_child_selector) (info_selectors_command): Update. * macrotab.c (macro_include, check_for_redefinition) (macro_undef): Update. * objfiles.c (filter_overlapping_sections): Update. * stabsread.c (invalid_cpp_abbrev_complaint) (reg_value_complaint, stabs_general_complaint, dbx_lookup_type) (define_symbol, error_type, read_type, rs6000_builtin_type) (stabs_method_name_from_physname, read_member_functions) (read_cpp_abbrev, read_baseclasses, read_tilde_fields) (attach_fields_to_type, complain_about_struct_wipeout) (read_range_type, read_args, common_block_start) (common_block_end, cleanup_undefined_types_1, scan_file_globals): Update. * mdebugread.c (index_complaint, unknown_ext_complaint) (basic_type_complaint, bad_tag_guess_complaint) (bad_rfd_entry_complaint, unexpected_type_code_complaint) (reg_value_complaint, parse_symbol, parse_type, upgrade_type) (parse_procedure, parse_lines) (function_outside_compilation_unit_complaint) (parse_partial_symbols, psymtab_to_symtab_1, cross_ref) (bad_tag_guess_complaint, reg_value_complaint): Update. * cp-support.c (demangled_name_complaint): Update. * macroscope.c (sal_macro_scope): Update. * dwarf-index-write.c (class debug_names): Update. gdb/testsuite/ChangeLog 2018-05-23 Tom Tromey <tom@tromey.com> * gdb.gdb/complaints.exp (test_initial_complaints): Don't mention symfile_complaints. (test_short_complaints): Likewise. (test_empty_complaints): Likewise. (test_initial_complaints): Update.
2018-05-17 06:54:44 +02:00
complaint ("unexpected demangled name '%s'", name);
}
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
/* If NAME is the fully-qualified name of a C++
function/variable/method/etc., this returns the length of its
entire prefix: all of the namespaces and classes that make up its
name. Given 'A::foo', it returns 1, given 'A::B::foo', it returns
4, given 'foo', it returns 0. */
unsigned int
cp_entire_prefix_len (const char *name)
{
unsigned int current_len = cp_find_first_component (name);
unsigned int previous_len = 0;
while (name[current_len] != '\0')
{
gdb_assert (name[current_len] == ':');
previous_len = current_len;
/* Skip the '::'. */
current_len += 2;
current_len += cp_find_first_component (name + current_len);
}
return previous_len;
}
/* Overload resolution functions. */
/* Test to see if SYM is a symbol that we haven't seen corresponding
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
to a function named OLOAD_NAME. If so, add it to
OVERLOAD_LIST. */
static void
overload_list_add_symbol (struct symbol *sym,
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
const char *oload_name,
std::vector<symbol *> *overload_list)
{
/* If there is no type information, we can't do anything, so
skip. */
if (SYMBOL_TYPE (sym) == NULL)
return;
/* skip any symbols that we've already considered. */
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
for (symbol *listed_sym : *overload_list)
Replace SYMBOL_*_NAME accessors with member functions Similar to the MSYMBOL version of this patch, improves readability and will eventually allow making name private. gdb/ChangeLog: 2019-11-22 Christian Biesinger <cbiesinger@google.com> * ada-exp.y: Update. * ada-lang.c (sort_choices): Update. (ada_print_symbol_signature): Update. (resolve_subexp): Update. (ada_parse_renaming): Update. (ada_read_renaming_var_value): Update. (lesseq_defined_than): Update. (remove_extra_symbols): Update. (remove_irrelevant_renamings): Update. (ada_add_block_symbols): Update. (ada_collect_symbol_completion_matches): Update. (ada_is_renaming_symbol): Update. (aggregate_assign_from_choices): Update. (ada_evaluate_subexp): Update. (ada_has_this_exception_support): Update. (ada_is_non_standard_exception_sym): Update. (ada_add_exceptions_from_frame): Update. (ada_add_global_exceptions): Update. (ada_print_subexp): Update. * ax-gdb.c (gen_var_ref): Update. (gen_maybe_namespace_elt): Update. (gen_expr_for_cast): Update. (gen_expr): Update. * block.h: Update. * blockframe.c (find_pc_partial_function): Update. * breakpoint.c (print_breakpoint_location): Update. (update_static_tracepoint): Update. * btrace.c (ftrace_print_function_name): Update. (ftrace_function_switched): Update. * buildsym.c (find_symbol_in_list): Update. * c-exp.y: Update. * c-typeprint.c (c_print_typedef): Update. (c_type_print_template_args): Update. * cli/cli-cmds.c (edit_command): Update. (list_command): Update. (print_sal_location): Update. * coffread.c (patch_opaque_types): Update. (process_coff_symbol): Update. (coff_read_enum_type): Update. * compile/compile-c-symbols.c (c_symbol_substitution_name): Update. (convert_one_symbol): Update. (hash_symname): Update. (eq_symname): Update. * compile/compile-cplus-symbols.c (convert_one_symbol): Update. * compile/compile-cplus-types.c (debug_print_scope): Update. * compile/compile-loc2c.c (do_compile_dwarf_expr_to_c): Update. * compile/compile-object-load.c (get_out_value_type): Update. * cp-namespace.c (cp_scan_for_anonymous_namespaces): Update. (search_symbol_list): Update. (cp_lookup_symbol_imports_or_template): Update. * cp-support.c (overload_list_add_symbol): Update. * ctfread.c (psymtab_to_symtab): Update. * dbxread.c (cp_set_block_scope): Update. * dictionary.c (iter_match_first_hashed): Update. (iter_match_next_hashed): Update. (insert_symbol_hashed): Update. (iter_match_next_linear): Update. * dictionary.h: Update. * dwarf2loc.c (func_get_frame_base_dwarf_block): Update. (locexpr_describe_location_piece): Update. (locexpr_describe_location_1): Update. (locexpr_generate_c_location): Update. (loclist_describe_location): Update. (loclist_generate_c_location): Update. * dwarf2read.c (dw2_debug_names_lookup_symbol): Update. (read_func_scope): Update. (process_enumeration_scope): Update. (new_symbol): Update. (dwarf2_const_value): Update. (dwarf2_symbol_mark_computed): Update. * eval.c (evaluate_funcall): Update. (evaluate_subexp_standard): Update. * expprint.c (print_subexp_standard): Update. (dump_subexp_body_standard): Update. * f-valprint.c (info_common_command_for_block): Update. * findvar.c (get_hosting_frame): Update. (default_read_var_value): Update. * go-lang.c (go_symbol_package_name): Update. * guile/scm-block.c (bkscm_print_block_smob): Update. * guile/scm-symbol.c (syscm_print_symbol_smob): Update. (gdbscm_symbol_name): Update. (gdbscm_symbol_linkage_name): Update. (gdbscm_symbol_print_name): Update. * infcall.c (get_function_name): Update. * infcmd.c (jump_command): Update. (finish_command): Update. * infrun.c (insert_exception_resume_breakpoint): Update. * linespec.c (canonicalize_linespec): Update. (create_sals_line_offset): Update. (convert_linespec_to_sals): Update. (complete_label): Update. (find_label_symbols_in_block): Update. * m2-typeprint.c (m2_print_typedef): Update. * mdebugread.c (mdebug_reg_to_regnum): Update. (parse_symbol): Update. (mylookup_symbol): Update. * mi/mi-cmd-stack.c (list_arg_or_local): Update. (list_args_or_locals): Update. * objc-lang.c (compare_selectors): Update. (info_selectors_command): Update. (compare_classes): Update. (info_classes_command): Update. (find_imps): Update. * p-typeprint.c (pascal_print_typedef): Update. * printcmd.c (build_address_symbolic): Update. (info_address_command): Update. (print_variable_and_value): Update. * python/py-framefilter.c (extract_sym): Update. (py_print_single_arg): Update. * python/py-symbol.c (sympy_str): Update. (sympy_get_name): Update. (sympy_get_linkage_name): Update. * python/python.c (gdbpy_rbreak): Update. * record-btrace.c (btrace_get_bfun_name): Update. (btrace_call_history): Update. * rust-lang.c (rust_print_typedef): Update. * solib-frv.c (frv_fdpic_find_canonical_descriptor): Update. * stabsread.c (stab_reg_to_regnum): Update. (define_symbol): Update. (read_enum_type): Update. (common_block_end): Update. (cleanup_undefined_types_1): Update. (scan_file_globals): Update. * stack.c (print_frame_arg): Update. (print_frame_args): Update. (find_frame_funname): Update. (info_frame_command_core): Update. (iterate_over_block_locals): Update. (print_block_frame_labels): Update. (do_print_variable_and_value): Update. (iterate_over_block_arg_vars): Update. (return_command): Update. * symmisc.c (dump_symtab_1): Update. (print_symbol): Update. * symtab.c (eq_symbol_entry): Update. (symbol_cache_dump): Update. (lookup_language_this): Update. (find_pc_sect_line): Update. (skip_prologue_sal): Update. (symbol_search::compare_search_syms): Update. (treg_matches_sym_type_name): Update. (search_symbols): Update. (print_symbol_info): Update. (rbreak_command): Update. (completion_list_add_symbol): Update. (find_gnu_ifunc): Update. (get_symbol_address): Update. (search_module_symbols): Update. (info_module_subcommand): Update. * symtab.h (SYMBOL_NATURAL_NAME): Remove. (SYMBOL_LINKAGE_NAME): Remove. (SYMBOL_DEMANGLED_NAME): Remove. (SYMBOL_PRINT_NAME): Remove. (SYMBOL_SEARCH_NAME): Remove. * tracepoint.c (set_traceframe_context): Update. (validate_actionline): Update. (collection_list::collect_symbol): Update. (encode_actions_1): Update. (info_scope_command): Update. (print_one_static_tracepoint_marker): Update. * typeprint.c (typedef_hash_table::add_template_parameters): Update. * valops.c (address_of_variable): Update. (find_overload_match): Update. (find_oload_champ): Update. Change-Id: I76bdc8b44eea6876bf03af9d351f8e90cc0154b2
2019-11-22 19:05:14 +01:00
if (strcmp (sym->linkage_name (), listed_sym->linkage_name ()) == 0)
return;
/* Get the demangled name without parameters */
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
gdb::unique_xmalloc_ptr<char> sym_name
Replace SYMBOL_*_NAME accessors with member functions Similar to the MSYMBOL version of this patch, improves readability and will eventually allow making name private. gdb/ChangeLog: 2019-11-22 Christian Biesinger <cbiesinger@google.com> * ada-exp.y: Update. * ada-lang.c (sort_choices): Update. (ada_print_symbol_signature): Update. (resolve_subexp): Update. (ada_parse_renaming): Update. (ada_read_renaming_var_value): Update. (lesseq_defined_than): Update. (remove_extra_symbols): Update. (remove_irrelevant_renamings): Update. (ada_add_block_symbols): Update. (ada_collect_symbol_completion_matches): Update. (ada_is_renaming_symbol): Update. (aggregate_assign_from_choices): Update. (ada_evaluate_subexp): Update. (ada_has_this_exception_support): Update. (ada_is_non_standard_exception_sym): Update. (ada_add_exceptions_from_frame): Update. (ada_add_global_exceptions): Update. (ada_print_subexp): Update. * ax-gdb.c (gen_var_ref): Update. (gen_maybe_namespace_elt): Update. (gen_expr_for_cast): Update. (gen_expr): Update. * block.h: Update. * blockframe.c (find_pc_partial_function): Update. * breakpoint.c (print_breakpoint_location): Update. (update_static_tracepoint): Update. * btrace.c (ftrace_print_function_name): Update. (ftrace_function_switched): Update. * buildsym.c (find_symbol_in_list): Update. * c-exp.y: Update. * c-typeprint.c (c_print_typedef): Update. (c_type_print_template_args): Update. * cli/cli-cmds.c (edit_command): Update. (list_command): Update. (print_sal_location): Update. * coffread.c (patch_opaque_types): Update. (process_coff_symbol): Update. (coff_read_enum_type): Update. * compile/compile-c-symbols.c (c_symbol_substitution_name): Update. (convert_one_symbol): Update. (hash_symname): Update. (eq_symname): Update. * compile/compile-cplus-symbols.c (convert_one_symbol): Update. * compile/compile-cplus-types.c (debug_print_scope): Update. * compile/compile-loc2c.c (do_compile_dwarf_expr_to_c): Update. * compile/compile-object-load.c (get_out_value_type): Update. * cp-namespace.c (cp_scan_for_anonymous_namespaces): Update. (search_symbol_list): Update. (cp_lookup_symbol_imports_or_template): Update. * cp-support.c (overload_list_add_symbol): Update. * ctfread.c (psymtab_to_symtab): Update. * dbxread.c (cp_set_block_scope): Update. * dictionary.c (iter_match_first_hashed): Update. (iter_match_next_hashed): Update. (insert_symbol_hashed): Update. (iter_match_next_linear): Update. * dictionary.h: Update. * dwarf2loc.c (func_get_frame_base_dwarf_block): Update. (locexpr_describe_location_piece): Update. (locexpr_describe_location_1): Update. (locexpr_generate_c_location): Update. (loclist_describe_location): Update. (loclist_generate_c_location): Update. * dwarf2read.c (dw2_debug_names_lookup_symbol): Update. (read_func_scope): Update. (process_enumeration_scope): Update. (new_symbol): Update. (dwarf2_const_value): Update. (dwarf2_symbol_mark_computed): Update. * eval.c (evaluate_funcall): Update. (evaluate_subexp_standard): Update. * expprint.c (print_subexp_standard): Update. (dump_subexp_body_standard): Update. * f-valprint.c (info_common_command_for_block): Update. * findvar.c (get_hosting_frame): Update. (default_read_var_value): Update. * go-lang.c (go_symbol_package_name): Update. * guile/scm-block.c (bkscm_print_block_smob): Update. * guile/scm-symbol.c (syscm_print_symbol_smob): Update. (gdbscm_symbol_name): Update. (gdbscm_symbol_linkage_name): Update. (gdbscm_symbol_print_name): Update. * infcall.c (get_function_name): Update. * infcmd.c (jump_command): Update. (finish_command): Update. * infrun.c (insert_exception_resume_breakpoint): Update. * linespec.c (canonicalize_linespec): Update. (create_sals_line_offset): Update. (convert_linespec_to_sals): Update. (complete_label): Update. (find_label_symbols_in_block): Update. * m2-typeprint.c (m2_print_typedef): Update. * mdebugread.c (mdebug_reg_to_regnum): Update. (parse_symbol): Update. (mylookup_symbol): Update. * mi/mi-cmd-stack.c (list_arg_or_local): Update. (list_args_or_locals): Update. * objc-lang.c (compare_selectors): Update. (info_selectors_command): Update. (compare_classes): Update. (info_classes_command): Update. (find_imps): Update. * p-typeprint.c (pascal_print_typedef): Update. * printcmd.c (build_address_symbolic): Update. (info_address_command): Update. (print_variable_and_value): Update. * python/py-framefilter.c (extract_sym): Update. (py_print_single_arg): Update. * python/py-symbol.c (sympy_str): Update. (sympy_get_name): Update. (sympy_get_linkage_name): Update. * python/python.c (gdbpy_rbreak): Update. * record-btrace.c (btrace_get_bfun_name): Update. (btrace_call_history): Update. * rust-lang.c (rust_print_typedef): Update. * solib-frv.c (frv_fdpic_find_canonical_descriptor): Update. * stabsread.c (stab_reg_to_regnum): Update. (define_symbol): Update. (read_enum_type): Update. (common_block_end): Update. (cleanup_undefined_types_1): Update. (scan_file_globals): Update. * stack.c (print_frame_arg): Update. (print_frame_args): Update. (find_frame_funname): Update. (info_frame_command_core): Update. (iterate_over_block_locals): Update. (print_block_frame_labels): Update. (do_print_variable_and_value): Update. (iterate_over_block_arg_vars): Update. (return_command): Update. * symmisc.c (dump_symtab_1): Update. (print_symbol): Update. * symtab.c (eq_symbol_entry): Update. (symbol_cache_dump): Update. (lookup_language_this): Update. (find_pc_sect_line): Update. (skip_prologue_sal): Update. (symbol_search::compare_search_syms): Update. (treg_matches_sym_type_name): Update. (search_symbols): Update. (print_symbol_info): Update. (rbreak_command): Update. (completion_list_add_symbol): Update. (find_gnu_ifunc): Update. (get_symbol_address): Update. (search_module_symbols): Update. (info_module_subcommand): Update. * symtab.h (SYMBOL_NATURAL_NAME): Remove. (SYMBOL_LINKAGE_NAME): Remove. (SYMBOL_DEMANGLED_NAME): Remove. (SYMBOL_PRINT_NAME): Remove. (SYMBOL_SEARCH_NAME): Remove. * tracepoint.c (set_traceframe_context): Update. (validate_actionline): Update. (collection_list::collect_symbol): Update. (encode_actions_1): Update. (info_scope_command): Update. (print_one_static_tracepoint_marker): Update. * typeprint.c (typedef_hash_table::add_template_parameters): Update. * valops.c (address_of_variable): Update. (find_overload_match): Update. (find_oload_champ): Update. Change-Id: I76bdc8b44eea6876bf03af9d351f8e90cc0154b2
2019-11-22 19:05:14 +01:00
= cp_remove_params (sym->natural_name ());
if (!sym_name)
return;
/* skip symbols that cannot match */
if (strcmp (sym_name.get (), oload_name) != 0)
return;
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
overload_list->push_back (sym);
}
/* Return a null-terminated list of pointers to function symbols that
are named FUNC_NAME and are visible within NAMESPACE. */
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
struct std::vector<symbol *>
make_symbol_overload_list (const char *func_name,
const char *the_namespace)
{
const char *name;
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
std::vector<symbol *> overload_list;
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
overload_list.reserve (100);
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
add_symbol_overload_list_using (func_name, the_namespace, &overload_list);
if (the_namespace[0] == '\0')
name = func_name;
else
{
char *concatenated_name
Add casts to memory allocation related calls Most allocation functions (if not all) return a void* pointing to the allocated memory. In C++, we need to add an explicit cast when assigning the result to a pointer to another type (which is the case more often than not). The content of this patch is taken from Pedro's branch, from commit "(mostly) auto-generated patch to insert casts needed for C++". I validated that the changes make sense and manually reflowed the code to make it respect the coding style. I also found multiple places where I could use XNEW/XNEWVEC/XRESIZEVEC/etc. Thanks a lot to whoever did that automated script to insert casts, doing it completely by hand would have taken a ridiculous amount of time. Only files built on x86 with --enable-targets=all are modified. This means that all other -nat.c files are untouched and will have to be dealt with later by using appropiate compilers. Or maybe we can try to build them with a regular g++ just to know where to add casts, I don't know. I built-tested this with --enable-targets=all and reg-tested. Here's the changelog entry, which was not too bad to make despite the size, thanks to David Malcom's script. I fixed some bits by hand, but there might be some wrong parts left (hopefully not). gdb/ChangeLog: * aarch64-linux-tdep.c (aarch64_stap_parse_special_token): Add cast to allocation result assignment. * ada-exp.y (write_object_renaming): Likewise. (write_ambiguous_var): Likewise. (ada_nget_field_index): Likewise. (write_var_or_type): Likewise. * ada-lang.c (ada_decode_symbol): Likewise. (ada_value_assign): Likewise. (value_pointer): Likewise. (cache_symbol): Likewise. (add_nonlocal_symbols): Likewise. (ada_name_for_lookup): Likewise. (symbol_completion_add): Likewise. (ada_to_fixed_type_1): Likewise. (ada_get_next_arg): Likewise. (defns_collected): Likewise. * ada-lex.l (processId): Likewise. (processString): Likewise. * ada-tasks.c (read_known_tasks_array): Likewise. (read_known_tasks_list): Likewise. * ada-typeprint.c (decoded_type_name): Likewise. * addrmap.c (addrmap_mutable_create_fixed): Likewise. * amd64-tdep.c (amd64_push_arguments): Likewise. (amd64_displaced_step_copy_insn): Likewise. (amd64_classify_insn_at): Likewise. (amd64_relocate_instruction): Likewise. * amd64obsd-tdep.c (amd64obsd_sigtramp_p): Likewise. * arch-utils.c (simple_displaced_step_copy_insn): Likewise. (initialize_current_architecture): Likewise. * arm-linux-tdep.c (arm_stap_parse_special_token): Likewise. * arm-symbian-tdep.c (arm_symbian_osabi_sniffer): Likewise. * arm-tdep.c (arm_exidx_new_objfile): Likewise. (arm_push_dummy_call): Likewise. (extend_buffer_earlier): Likewise. (arm_adjust_breakpoint_address): Likewise. (arm_skip_stub): Likewise. * auto-load.c (filename_is_in_pattern): Likewise. (maybe_add_script_file): Likewise. (maybe_add_script_text): Likewise. (auto_load_objfile_script_1): Likewise. * auxv.c (ld_so_xfer_auxv): Likewise. * ax-general.c (new_agent_expr): Likewise. (grow_expr): Likewise. (ax_reg_mask): Likewise. * bcache.c (bcache_full): Likewise. * breakpoint.c (program_breakpoint_here_p): Likewise. * btrace.c (parse_xml_raw): Likewise. * build-id.c (build_id_to_debug_bfd): Likewise. * buildsym.c (end_symtab_with_blockvector): Likewise. * c-exp.y (string_exp): Likewise. (qualified_name): Likewise. (write_destructor_name): Likewise. (operator_stoken): Likewise. (parse_number): Likewise. (scan_macro_expansion): Likewise. (yylex): Likewise. (c_print_token): Likewise. * c-lang.c (c_get_string): Likewise. (emit_numeric_character): Likewise. * charset.c (wchar_iterate): Likewise. * cli/cli-cmds.c (complete_command): Likewise. (make_command): Likewise. * cli/cli-dump.c (restore_section_callback): Likewise. (restore_binary_file): Likewise. * cli/cli-interp.c (cli_interpreter_exec): Likewise. * cli/cli-script.c (execute_control_command): Likewise. * cli/cli-setshow.c (do_set_command): Likewise. * coff-pe-read.c (add_pe_forwarded_sym): Likewise. (read_pe_exported_syms): Likewise. * coffread.c (coff_read_struct_type): Likewise. (coff_read_enum_type): Likewise. * common/btrace-common.c (btrace_data_append): Likewise. * common/buffer.c (buffer_grow): Likewise. * common/filestuff.c (gdb_fopen_cloexec): Likewise. * common/format.c (parse_format_string): Likewise. * common/gdb_vecs.c (delim_string_to_char_ptr_vec_append): Likewise. * common/xml-utils.c (xml_escape_text): Likewise. * compile/compile-object-load.c (copy_sections): Likewise. (compile_object_load): Likewise. * compile/compile-object-run.c (compile_object_run): Likewise. * completer.c (filename_completer): Likewise. * corefile.c (read_memory_typed_address): Likewise. (write_memory_unsigned_integer): Likewise. (write_memory_signed_integer): Likewise. (complete_set_gnutarget): Likewise. * corelow.c (get_core_register_section): Likewise. * cp-name-parser.y (d_grab): Likewise. (allocate_info): Likewise. (cp_new_demangle_parse_info): Likewise. * cp-namespace.c (cp_scan_for_anonymous_namespaces): Likewise. (cp_lookup_symbol_in_namespace): Likewise. (lookup_namespace_scope): Likewise. (find_symbol_in_baseclass): Likewise. (cp_lookup_nested_symbol): Likewise. (cp_lookup_transparent_type_loop): Likewise. * cp-support.c (copy_string_to_obstack): Likewise. (make_symbol_overload_list): Likewise. (make_symbol_overload_list_namespace): Likewise. (make_symbol_overload_list_adl_namespace): Likewise. (first_component_command): Likewise. * cp-valprint.c (cp_print_value): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * d-exp.y (StringExp): Likewise. * d-namespace.c (d_lookup_symbol_in_module): Likewise. (lookup_module_scope): Likewise. (find_symbol_in_baseclass): Likewise. (d_lookup_nested_symbol): Likewise. * dbxread.c (find_stab_function_addr): Likewise. (read_dbx_symtab): Likewise. (dbx_end_psymtab): Likewise. (cp_set_block_scope): Likewise. * dcache.c (dcache_alloc): Likewise. * demangle.c (_initialize_demangler): Likewise. * dicos-tdep.c (dicos_load_module_p): Likewise. * dictionary.c (dict_create_hashed_expandable): Likewise. (dict_create_linear_expandable): Likewise. (expand_hashtable): Likewise. (add_symbol_linear_expandable): Likewise. * dwarf2-frame.c (add_cie): Likewise. (add_fde): Likewise. (dwarf2_build_frame_info): Likewise. * dwarf2expr.c (dwarf_expr_grow_stack): Likewise. (dwarf_expr_fetch_address): Likewise. (add_piece): Likewise. (execute_stack_op): Likewise. * dwarf2loc.c (chain_candidate): Likewise. (dwarf_entry_parameter_to_value): Likewise. (read_pieced_value): Likewise. (write_pieced_value): Likewise. * dwarf2read.c (dwarf2_read_section): Likewise. (add_type_unit): Likewise. (read_comp_units_from_section): Likewise. (fixup_go_packaging): Likewise. (dwarf2_compute_name): Likewise. (dwarf2_physname): Likewise. (create_dwo_unit_in_dwp_v1): Likewise. (create_dwo_unit_in_dwp_v2): Likewise. (read_func_scope): Likewise. (read_call_site_scope): Likewise. (dwarf2_attach_fields_to_type): Likewise. (process_structure_scope): Likewise. (mark_common_block_symbol_computed): Likewise. (read_common_block): Likewise. (abbrev_table_read_table): Likewise. (guess_partial_die_structure_name): Likewise. (fixup_partial_die): Likewise. (add_file_name): Likewise. (dwarf2_const_value_data): Likewise. (dwarf2_const_value_attr): Likewise. (build_error_marker_type): Likewise. (guess_full_die_structure_name): Likewise. (anonymous_struct_prefix): Likewise. (typename_concat): Likewise. (dwarf2_canonicalize_name): Likewise. (dwarf2_name): Likewise. (write_constant_as_bytes): Likewise. (dwarf2_fetch_constant_bytes): Likewise. (copy_string): Likewise. (parse_macro_definition): Likewise. * elfread.c (elf_symfile_segments): Likewise. (elf_rel_plt_read): Likewise. (elf_gnu_ifunc_resolve_by_cache): Likewise. (elf_gnu_ifunc_resolve_by_got): Likewise. (elf_read_minimal_symbols): Likewise. (elf_gnu_ifunc_record_cache): Likewise. * event-top.c (top_level_prompt): Likewise. (command_line_handler): Likewise. * exec.c (resize_section_table): Likewise. * expprint.c (print_subexp_standard): Likewise. * fbsd-tdep.c (fbsd_collect_regset_section_cb): Likewise. * findcmd.c (parse_find_args): Likewise. * findvar.c (address_from_register): Likewise. * frame.c (get_prev_frame_always): Likewise. * gdb_bfd.c (gdb_bfd_ref): Likewise. (get_section_descriptor): Likewise. * gdb_obstack.c (obconcat): Likewise. (obstack_strdup): Likewise. * gdbtypes.c (lookup_function_type_with_arguments): Likewise. (create_set_type): Likewise. (lookup_unsigned_typename): Likewise. (lookup_signed_typename): Likewise. (resolve_dynamic_union): Likewise. (resolve_dynamic_struct): Likewise. (add_dyn_prop): Likewise. (copy_dynamic_prop_list): Likewise. (arch_flags_type): Likewise. (append_composite_type_field_raw): Likewise. * gdbtypes.h (INIT_FUNC_SPECIFIC): Likewise. * gnu-v3-abi.c (gnuv3_rtti_type): Likewise. * go-exp.y (string_exp): Likewise. * go-lang.c (go_demangle): Likewise. * guile/guile.c (compute_scheme_string): Likewise. * guile/scm-cmd.c (gdbscm_parse_command_name): Likewise. (gdbscm_canonicalize_command_name): Likewise. * guile/scm-ports.c (ioscm_init_stdio_buffers): Likewise. (ioscm_init_memory_port): Likewise. (ioscm_reinit_memory_port): Likewise. * guile/scm-utils.c (gdbscm_gc_xstrdup): Likewise. (gdbscm_gc_dup_argv): Likewise. * h8300-tdep.c (h8300_push_dummy_call): Likewise. * hppa-tdep.c (internalize_unwinds): Likewise. (read_unwind_info): Likewise. * i386-cygwin-tdep.c (core_process_module_section): Likewise. (windows_core_xfer_shared_libraries): Likewise. * i386-tdep.c (i386_displaced_step_copy_insn): Likewise. (i386_stap_parse_special_token_triplet): Likewise. (i386_stap_parse_special_token_three_arg_disp): Likewise. * i386obsd-tdep.c (i386obsd_sigtramp_p): Likewise. * inf-child.c (inf_child_fileio_readlink): Likewise. * inf-ptrace.c (inf_ptrace_fetch_register): Likewise. (inf_ptrace_store_register): Likewise. * infrun.c (follow_exec): Likewise. (displaced_step_prepare_throw): Likewise. (save_stop_context): Likewise. (save_infcall_suspend_state): Likewise. * jit.c (jit_read_descriptor): Likewise. (jit_read_code_entry): Likewise. (jit_symtab_line_mapping_add_impl): Likewise. (finalize_symtab): Likewise. (jit_unwind_reg_get_impl): Likewise. * jv-exp.y (QualifiedName): Likewise. * jv-lang.c (get_java_utf8_name): Likewise. (type_from_class): Likewise. (java_demangle_type_signature): Likewise. (java_class_name_from_physname): Likewise. * jv-typeprint.c (java_type_print_base): Likewise. * jv-valprint.c (java_value_print): Likewise. * language.c (add_language): Likewise. * linespec.c (add_sal_to_sals_basic): Likewise. (add_sal_to_sals): Likewise. (decode_objc): Likewise. (find_linespec_symbols): Likewise. * linux-fork.c (fork_save_infrun_state): Likewise. * linux-nat.c (linux_nat_detach): Likewise. (linux_nat_fileio_readlink): Likewise. * linux-record.c (record_linux_sockaddr): Likewise. (record_linux_msghdr): Likewise. (Do): Likewise. * linux-tdep.c (linux_core_info_proc_mappings): Likewise. (linux_collect_regset_section_cb): Likewise. (linux_get_siginfo_data): Likewise. * linux-thread-db.c (try_thread_db_load_from_pdir_1): Likewise. (try_thread_db_load_from_dir): Likewise. (thread_db_load_search): Likewise. (info_auto_load_libthread_db): Likewise. * m32c-tdep.c (m32c_m16c_address_to_pointer): Likewise. (m32c_m16c_pointer_to_address): Likewise. * m68hc11-tdep.c (m68hc11_pseudo_register_write): Likewise. * m68k-tdep.c (m68k_get_longjmp_target): Likewise. * machoread.c (macho_check_dsym): Likewise. * macroexp.c (resize_buffer): Likewise. (gather_arguments): Likewise. (maybe_expand): Likewise. * macrotab.c (new_macro_key): Likewise. (new_source_file): Likewise. (new_macro_definition): Likewise. * mdebugread.c (parse_symbol): Likewise. (parse_type): Likewise. (parse_partial_symbols): Likewise. (psymtab_to_symtab_1): Likewise. * mem-break.c (default_memory_insert_breakpoint): Likewise. * mi/mi-cmd-break.c (mi_argv_to_format): Likewise. * mi/mi-main.c (mi_cmd_data_read_memory): Likewise. (mi_cmd_data_read_memory_bytes): Likewise. (mi_cmd_data_write_memory_bytes): Likewise. (mi_cmd_trace_frame_collected): Likewise. * mi/mi-parse.c (mi_parse_argv): Likewise. (mi_parse): Likewise. * minidebug.c (lzma_open): Likewise. (lzma_pread): Likewise. * mips-tdep.c (mips_read_fp_register_single): Likewise. (mips_print_fp_register): Likewise. * mipsnbsd-tdep.c (mipsnbsd_get_longjmp_target): Likewise. * mipsread.c (read_alphacoff_dynamic_symtab): Likewise. * mt-tdep.c (mt_register_name): Likewise. (mt_registers_info): Likewise. (mt_push_dummy_call): Likewise. * namespace.c (add_using_directive): Likewise. * nat/linux-btrace.c (perf_event_read): Likewise. (linux_enable_bts): Likewise. * nat/linux-osdata.c (linux_common_core_of_thread): Likewise. * nat/linux-ptrace.c (linux_ptrace_test_ret_to_nx): Likewise. * nto-tdep.c (nto_find_and_open_solib): Likewise. (nto_parse_redirection): Likewise. * objc-lang.c (objc_demangle): Likewise. (find_methods): Likewise. * objfiles.c (get_objfile_bfd_data): Likewise. (set_objfile_main_name): Likewise. (allocate_objfile): Likewise. (objfile_relocate): Likewise. (update_section_map): Likewise. * osabi.c (generic_elf_osabi_sniff_abi_tag_sections): Likewise. * p-exp.y (exp): Likewise. (yylex): Likewise. * p-valprint.c (pascal_object_print_value): Likewise. * parse.c (initialize_expout): Likewise. (mark_completion_tag): Likewise. (copy_name): Likewise. (parse_float): Likewise. (type_stack_reserve): Likewise. * ppc-linux-tdep.c (ppc_stap_parse_special_token): Likewise. (ppu2spu_prev_register): Likewise. * ppc-ravenscar-thread.c (supply_register_at_address): Likewise. * printcmd.c (printf_wide_c_string): Likewise. (printf_pointer): Likewise. * probe.c (parse_probes): Likewise. * python/py-cmd.c (gdbpy_parse_command_name): Likewise. (cmdpy_init): Likewise. * python/py-gdb-readline.c (gdbpy_readline_wrapper): Likewise. * python/py-symtab.c (set_sal): Likewise. * python/py-unwind.c (pyuw_sniffer): Likewise. * python/python.c (python_interactive_command): Likewise. (compute_python_string): Likewise. * ravenscar-thread.c (get_running_thread_id): Likewise. * record-full.c (record_full_exec_insn): Likewise. (record_full_core_open_1): Likewise. * regcache.c (regcache_raw_read_signed): Likewise. (regcache_raw_read_unsigned): Likewise. (regcache_cooked_read_signed): Likewise. (regcache_cooked_read_unsigned): Likewise. * remote-fileio.c (remote_fileio_func_open): Likewise. (remote_fileio_func_rename): Likewise. (remote_fileio_func_unlink): Likewise. (remote_fileio_func_stat): Likewise. (remote_fileio_func_system): Likewise. * remote-mips.c (mips_xfer_memory): Likewise. (mips_load_srec): Likewise. (pmon_end_download): Likewise. * remote.c (new_remote_state): Likewise. (map_regcache_remote_table): Likewise. (remote_register_number_and_offset): Likewise. (init_remote_state): Likewise. (get_memory_packet_size): Likewise. (remote_pass_signals): Likewise. (remote_program_signals): Likewise. (remote_start_remote): Likewise. (remote_check_symbols): Likewise. (remote_query_supported): Likewise. (extended_remote_attach): Likewise. (process_g_packet): Likewise. (store_registers_using_G): Likewise. (putpkt_binary): Likewise. (read_frame): Likewise. (compare_sections_command): Likewise. (remote_hostio_pread): Likewise. (remote_hostio_readlink): Likewise. (remote_file_put): Likewise. (remote_file_get): Likewise. (remote_pid_to_exec_file): Likewise. (_initialize_remote): Likewise. * rs6000-aix-tdep.c (rs6000_aix_ld_info_to_xml): Likewise. (rs6000_aix_core_xfer_shared_libraries_aix): Likewise. * rs6000-tdep.c (ppc_displaced_step_copy_insn): Likewise. (bfd_uses_spe_extensions): Likewise. * s390-linux-tdep.c (s390_displaced_step_copy_insn): Likewise. * score-tdep.c (score7_malloc_and_get_memblock): Likewise. * solib-dsbt.c (decode_loadmap): Likewise. (fetch_loadmap): Likewise. (scan_dyntag): Likewise. (enable_break): Likewise. (dsbt_relocate_main_executable): Likewise. * solib-frv.c (fetch_loadmap): Likewise. (enable_break2): Likewise. (frv_relocate_main_executable): Likewise. * solib-spu.c (spu_relocate_main_executable): Likewise. (spu_bfd_open): Likewise. * solib-svr4.c (lm_info_read): Likewise. (read_program_header): Likewise. (find_program_interpreter): Likewise. (scan_dyntag): Likewise. (elf_locate_base): Likewise. (open_symbol_file_object): Likewise. (read_program_headers_from_bfd): Likewise. (svr4_relocate_main_executable): Likewise. * solib-target.c (solib_target_relocate_section_addresses): Likewise. * solib.c (solib_find_1): Likewise. (exec_file_find): Likewise. (solib_find): Likewise. * source.c (openp): Likewise. (print_source_lines_base): Likewise. (forward_search_command): Likewise. * sparc-ravenscar-thread.c (supply_register_at_address): Likewise. * spu-tdep.c (spu2ppu_prev_register): Likewise. (spu_get_overlay_table): Likewise. * stabsread.c (patch_block_stabs): Likewise. (define_symbol): Likewise. (again:): Likewise. (read_member_functions): Likewise. (read_one_struct_field): Likewise. (read_enum_type): Likewise. (common_block_start): Likewise. * stack.c (read_frame_arg): Likewise. (backtrace_command): Likewise. * stap-probe.c (stap_parse_register_operand): Likewise. * symfile.c (syms_from_objfile_1): Likewise. (find_separate_debug_file): Likewise. (load_command): Likewise. (load_progress): Likewise. (load_section_callback): Likewise. (reread_symbols): Likewise. (add_filename_language): Likewise. (allocate_compunit_symtab): Likewise. (read_target_long_array): Likewise. (simple_read_overlay_table): Likewise. * symtab.c (symbol_set_names): Likewise. (resize_symbol_cache): Likewise. (rbreak_command): Likewise. (completion_list_add_name): Likewise. (completion_list_objc_symbol): Likewise. (add_filename_to_list): Likewise. * target-descriptions.c (maint_print_c_tdesc_cmd): Likewise. * target-memory.c (target_write_memory_blocks): Likewise. * target.c (target_read_string): Likewise. (read_whatever_is_readable): Likewise. (target_read_alloc_1): Likewise. (simple_search_memory): Likewise. (target_fileio_read_alloc_1): Likewise. * tilegx-tdep.c (tilegx_push_dummy_call): Likewise. * top.c (command_line_input): Likewise. * tracefile-tfile.c (tfile_fetch_registers): Likewise. * tracefile.c (tracefile_fetch_registers): Likewise. * tracepoint.c (add_memrange): Likewise. (init_collection_list): Likewise. (add_aexpr): Likewise. (trace_dump_actions): Likewise. (parse_trace_status): Likewise. (parse_tracepoint_definition): Likewise. (parse_tsv_definition): Likewise. (parse_static_tracepoint_marker_definition): Likewise. * tui/tui-file.c (tui_sfileopen): Likewise. (tui_file_adjust_strbuf): Likewise. * tui/tui-io.c (tui_expand_tabs): Likewise. * tui/tui-source.c (tui_set_source_content): Likewise. * typeprint.c (find_global_typedef): Likewise. * ui-file.c (do_ui_file_xstrdup): Likewise. (ui_file_obsavestring): Likewise. (mem_file_write): Likewise. * utils.c (make_hex_string): Likewise. (get_regcomp_error): Likewise. (puts_filtered_tabular): Likewise. (gdb_realpath_keepfile): Likewise. (ldirname): Likewise. (gdb_bfd_errmsg): Likewise. (substitute_path_component): Likewise. * valops.c (search_struct_method): Likewise. (find_oload_champ_namespace_loop): Likewise. * valprint.c (print_decimal_chars): Likewise. (read_string): Likewise. (generic_emit_char): Likewise. * varobj.c (varobj_delete): Likewise. (varobj_value_get_print_value): Likewise. * vaxobsd-tdep.c (vaxobsd_sigtramp_sniffer): Likewise. * windows-tdep.c (display_one_tib): Likewise. * xcoffread.c (read_xcoff_symtab): Likewise. (process_xcoff_symbol): Likewise. (swap_sym): Likewise. (scan_xcoff_symtab): Likewise. (xcoff_initial_scan): Likewise. * xml-support.c (gdb_xml_end_element): Likewise. (xml_process_xincludes): Likewise. (xml_fetch_content_from_file): Likewise. * xml-syscall.c (xml_list_of_syscalls): Likewise. * xstormy16-tdep.c (xstormy16_push_dummy_call): Likewise. gdb/gdbserver/ChangeLog: * ax.c (gdb_parse_agent_expr): Add cast to allocation result assignment. (gdb_unparse_agent_expr): Likewise. * hostio.c (require_data): Likewise. (handle_pread): Likewise. * linux-low.c (disable_regset): Likewise. (fetch_register): Likewise. (store_register): Likewise. (get_dynamic): Likewise. (linux_qxfer_libraries_svr4): Likewise. * mem-break.c (delete_fast_tracepoint_jump): Likewise. (set_fast_tracepoint_jump): Likewise. (uninsert_fast_tracepoint_jumps_at): Likewise. (reinsert_fast_tracepoint_jumps_at): Likewise. (validate_inserted_breakpoint): Likewise. (clone_agent_expr): Likewise. * regcache.c (init_register_cache): Likewise. * remote-utils.c (putpkt_binary_1): Likewise. (decode_M_packet): Likewise. (decode_X_packet): Likewise. (look_up_one_symbol): Likewise. (relocate_instruction): Likewise. (monitor_output): Likewise. * server.c (handle_search_memory): Likewise. (handle_qxfer_exec_file): Likewise. (handle_qxfer_libraries): Likewise. (handle_qxfer): Likewise. (handle_query): Likewise. (handle_v_cont): Likewise. (handle_v_run): Likewise. (captured_main): Likewise. * target.c (write_inferior_memory): Likewise. * thread-db.c (try_thread_db_load_from_dir): Likewise. * tracepoint.c (init_trace_buffer): Likewise. (add_tracepoint_action): Likewise. (add_traceframe): Likewise. (add_traceframe_block): Likewise. (cmd_qtdpsrc): Likewise. (cmd_qtdv): Likewise. (cmd_qtstatus): Likewise. (response_source): Likewise. (response_tsv): Likewise. (cmd_qtnotes): Likewise. (gdb_collect): Likewise. (initialize_tracepoint): Likewise.
2015-09-25 20:08:06 +02:00
= (char *) alloca (strlen (the_namespace) + 2 + strlen (func_name) + 1);
strcpy (concatenated_name, the_namespace);
strcat (concatenated_name, "::");
strcat (concatenated_name, func_name);
name = concatenated_name;
}
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
add_symbol_overload_list_qualified (name, &overload_list);
return overload_list;
}
/* Add all symbols with a name matching NAME in BLOCK to the overload
list. */
static void
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
add_symbol_overload_list_block (const char *name,
const struct block *block,
std::vector<symbol *> *overload_list)
{
struct block_iterator iter;
struct symbol *sym;
Introduce lookup_name_info and generalize Ada's FULL/WILD name matching Summary: - This is preparation for supporting wild name matching on C++ too. - This is also preparation for TAB-completion fixes. - Makes symbol name matching (think strcmp_iw) be based on a per-language method. - Merges completion and non-completion name comparison (think language_ops::la_get_symbol_name_cmp generalized). - Avoid re-hashing lookup name multiple times - Centralizes preparing a name for lookup (Ada name encoding / C++ Demangling), both completion and non-completion. - Fixes Ada latent bug with verbatim name matches in expressions - Makes ada-lang.c use common|symtab.c completion code a bit more. Ada's wild matching basically means that "(gdb) break foo" will find all methods named "foo" in all packages. Translating to C++, it's roughly the same as saying that "break klass::method" sets breakpoints on all "klass::method" methods of all classes, no matter the namespace. A following patch will teach GDB about fullname vs wild matching for C++ too. This patch is preparatory work to get there. Another idea here is to do symbol name matching based on the symbol language's algorithm. I.e., avoid dependency on current language set. This allows for example doing (gdb) b foo::bar< int > (<tab> and having gdb name match the C++ symbols correctly even if the current language is C or Assembly (or Rust, or Ada, or ...), which can easily happen if you step into an Assembly/C runtime library frame. By encapsulating all the information related to a lookup name in a class, we can also cache hash computation for a given language in the lookup name object, to avoid recomputing it over and over. Similarly, because we don't really know upfront which languages the lookup name will be matched against, for each language we store the lookup name transformed into a search name. E.g., for C++, that means demangling the name. But for Ada, it means encoding the name. This actually forces us to centralize all the different lookup name encoding in a central place, resulting in clearer code, IMO. See e.g., the new ada_lookup_name_info class. The lookup name -> symbol search name computation is also done only once per language. The old language->la_get_symbol_name_cmp / symbol_name_cmp_ftype are generalized to work with both completion, and normal symbol look up. At some point early on, I had separate completion vs non-completion language vector entry points, but a single method ends up being better IMO for simplifying things -- the more we merge the completion / non-completion name lookup code paths, the less changes for bugs causing completion vs normal lookup finding different symbols. The ada-lex.l change is necessary because when doing (gdb) p <UpperCase> then the name that is passed to write_ write_var_or_type -> ada_lookup_symbol_list misses the "<>", i.e., it's just "UpperCase", and we end up doing a wild match against "UpperCase" lowercased by ada_lookup_name_info's constructor. I.e., "uppercase" wouldn't ever match "UpperCase", and the symbol lookup fails. This wouldn't cause any regression in the testsuite, but I added a new test that would pass before the patch and fail after, if it weren't for that fix. This is latent bug that happens to go unnoticed because that particular path was inconsistent with the rest of Ada symbol lookup by not lowercasing the lookup name. Ada's symbol_completion_add is deleted, replaced by using common code's completion_list_add_name. To make the latter work for Ada, we needed to add a new output parameter, because Ada wants to return back a custom completion candidates that are not the symbol name. With this patch, minimal symbol demangled name hashing is made consistent with regular symbol hashing. I.e., it now goes via the language vector's search_name_hash method too, as I had suggested in a previous patch. dw2_expand_symtabs_matching / .gdb_index symbol names were a challenge. The problem is that we have no way to telling what is the language of each symbol name found in the index, until we expand the corresponding full symbol, which is off course what we're trying to avoid. Language information is simply not considered in the index format... Since the symbol name hashing and comparison routines are per-language, we now have a problem. The patch sorts this out by matching each name against all languages. This is inneficient, and indeed slows down completion several times. E.g., with: $ cat script.cmd set pagination off set $count = 0 while $count < 400 complete b string_prin printf "count = %d\n", $count set $count = $count + 1 end $ time gdb --batch -q ./gdb-with-index -ex "source script-string_printf.cmd" I get, before patch (-O2, x86-64): real 0m1.773s user 0m1.737s sys 0m0.040s While after patch (-O2, x86-64): real 0m9.843s user 0m9.482s sys 0m0.034s However, the following patch will optimize this, and will actually make this use case faster compared to the "before patch" above: real 0m1.321s user 0m1.285s sys 0m0.039s gdb/ChangeLog: 2017-11-08 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_encode): Rename to .. (ada_encode_1): ... this. Add throw_errors parameter and handle it. (ada_encode): Reimplement. (match_name): Delete, folded into full_name. (resolve_subexp): No longer pass the encoded name to ada_lookup_symbol_list. (should_use_wild_match): Delete. (name_match_type_from_name): New. (ada_lookup_simple_minsym): Use lookup_name_info and the language's symbol_name_matcher_ftype. (add_symbols_from_enclosing_procs, ada_add_local_symbols) (ada_add_block_renamings): Adjust to use lookup_name_info. (ada_lookup_name): New. (add_nonlocal_symbols, ada_add_all_symbols) (ada_lookup_symbol_list_worker, ada_lookup_symbol_list) (ada_iterate_over_symbols): Adjust to use lookup_name_info. (ada_name_for_lookup): Delete. (ada_lookup_encoded_symbol): Construct a verbatim name. (wild_match): Reverse sense of return type. Use bool. (full_match): Reverse sense of return type. Inline bits of old match_name here. (ada_add_block_symbols): Adjust to use lookup_name_info. (symbol_completion_match): Delete, folded into... (ada_lookup_name_info::matches): ... .this new method. (symbol_completion_add): Delete. (ada_collect_symbol_completion_matches): Add name_match_type parameter. Adjust to use lookup_name_info and completion_list_add_name. (get_var_value, ada_add_global_exceptions): Adjust to use lookup_name_info. (ada_get_symbol_name_cmp): Delete. (do_wild_match, do_full_match): New functions. (ada_lookup_name_info::ada_lookup_name_info): New method. (ada_symbol_name_matches, ada_get_symbol_name_matcher): New functions. (ada_language_defn): Install ada_get_symbol_name_matcher. * ada-lex.l (processId): If name starts with '<', copy it verbatim. * block.c (block_iter_match_step, block_iter_match_first) (block_iter_match_next, block_lookup_symbol) (block_lookup_symbol_primary, block_find_symbol): Adjust to use lookup_name_info. * block.h (block_iter_match_first, block_iter_match_next) (ALL_BLOCK_SYMBOLS_WITH_NAME): Adjust to use lookup_name_info. * c-lang.c (c_language_defn, cplus_language_defn) (asm_language_defn, minimal_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * completer.c (complete_files_symbols) (collect_explicit_location_matches, symbol_completer): Pass a symbol_name_match_type down. * completer.h (class completion_match, completion_match_result): New classes. (completion_tracker::reset_completion_match_result): New method. (completion_tracker::m_completion_match_result): New field. * cp-support.c (make_symbol_overload_list_block): Adjust to use lookup_name_info. (cp_fq_symbol_name_matches, cp_get_symbol_name_matcher): New functions. * cp-support.h (cp_get_symbol_name_matcher): New declaration. * d-lang.c: Adjust comments to refer to la_get_symbol_name_matcher. * dictionary.c (dict_vector) <iter_match_first, iter_match_next>: Adjust to use lookup_name_info. (dict_iter_match_first, dict_iter_match_next) (iter_match_first_hashed, iter_match_next_hashed) (iter_match_first_linear, iter_match_next_linear): Adjust to work with a lookup_name_info. * dictionary.h (dict_iter_match_first, dict_iter_match_next): Likewise. * dwarf2read.c (dw2_lookup_symbol): Adjust to use lookup_name_info. (dw2_map_matching_symbols): Adjust to use symbol_name_match_type. (gdb_index_symbol_name_matcher): New class. (dw2_expand_symtabs_matching) Adjust to use lookup_name_info and gdb_index_symbol_name_matcher. Accept a NULL symbol_matcher. * f-lang.c (f_collect_symbol_completion_matches): Adjust to work with a symbol_name_match_type. (f_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * go-lang.c (go_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * language.c (default_symbol_name_matcher) (language_get_symbol_name_matcher): New functions. (unknown_language_defn, auto_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * language.h (symbol_name_cmp_ftype): Delete. (language_defn) <la_collect_symbol_completion_matches>: Add match type parameter. <la_get_symbol_name_cmp>: Delete field. <la_get_symbol_name_matcher>: New field. <la_iterate_over_symbols>: Adjust to use lookup_name_info. (default_symbol_name_matcher, language_get_symbol_name_matcher): Declare. * linespec.c (iterate_over_all_matching_symtabs) (iterate_over_file_blocks): Adjust to use lookup_name_info. (find_methods): Add language parameter, and use lookup_name_info and the language's symbol_name_matcher_ftype. (linespec_complete_function): Adjust. (lookup_prefix_sym): Use lookup_name_info. (add_all_symbol_names_from_pspace): Adjust. (find_superclass_methods): Add language parameter and pass it down. (find_method): Pass symbol language down. (find_linespec_symbols): Don't demangle or Ada encode here. (search_minsyms_for_name): Add lookup_name_info parameter. (add_matching_symbols_to_info): Add name_match_type parameter. Use lookup_name_info. * m2-lang.c (m2_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * minsyms.c: Include <algorithm>. (add_minsym_to_demangled_hash_table): Remove table parameter and add objfile parameter. Use search_name_hash, and add language to demangled languages vector. (struct found_minimal_symbols): New struct. (lookup_minimal_symbol_mangled, lookup_minimal_symbol_demangled): New functions. (lookup_minimal_symbol): Adjust to use them. Don't canonicalize input names here. Use lookup_name_info instead. Lookup up demangled names once for each language in the demangled names vector. (iterate_over_minimal_symbols): Use lookup_name_info. Lookup up demangled names once for each language in the demangled names vector. (build_minimal_symbol_hash_tables): Adjust. * minsyms.h (iterate_over_minimal_symbols): Adjust to pass down a lookup_name_info. * objc-lang.c (objc_language_defn): Adjust comment to refer to la_get_symbol_name_matcher. * objfiles.h: Include <vector>. (objfile_per_bfd_storage) <demangled_hash_languages>: New field. * opencl-lang.c (opencl_language_defn): Adjust comment to refer to la_get_symbol_name_matcher. * p-lang.c (pascal_language_defn): Adjust comment to refer to la_get_symbol_name_matcher. * psymtab.c (psym_lookup_symbol): Use lookup_name_info. (match_partial_symbol): Use symbol_name_match_type, lookup_name_info and psymbol_name_matches. (lookup_partial_symbol): Use lookup_name_info. (map_block): Use symbol_name_match_type and lookup_name_info. (psym_map_matching_symbols): Use symbol_name_match_type. (psymbol_name_matches): New. (recursively_search_psymtabs): Use lookup_name_info and psymbol_name_matches. Rename 'kind' parameter to 'domain'. (psym_expand_symtabs_matching): Use lookup_name_info. Rename 'kind' parameter to 'domain'. * rust-lang.c (rust_language_defn): Adjust comment to refer to la_get_symbol_name_matcher. * symfile-debug.c (debug_qf_map_matching_symbols) (debug_qf_map_matching_symbols): Use symbol_name_match_type. (debug_qf_expand_symtabs_matching): Use lookup_name_info. * symfile.c (expand_symtabs_matching): Use lookup_name_info. * symfile.h (quick_symbol_functions) <map_matching_symbols>: Adjust to use symbol_name_match_type. <expand_symtabs_matching>: Adjust to use lookup_name_info. (expand_symtabs_matching): Adjust to use lookup_name_info. * symmisc.c (maintenance_expand_symtabs): Use lookup_name_info::match_any (). * symtab.c (symbol_matches_search_name): New. (eq_symbol_entry): Adjust to use lookup_name_info and the language's matcher. (demangle_for_lookup_info::demangle_for_lookup_info): New. (lookup_name_info::match_any): New. (iterate_over_symbols, search_symbols): Use lookup_name_info. (compare_symbol_name): Add language, lookup_name_info and completion_match_result parameters, and use them. (completion_list_add_name): Make extern. Add language and lookup_name_info parameters. Use them. (completion_list_add_symbol, completion_list_add_msymbol) (completion_list_objc_symbol): Add lookup_name_info parameters and adjust. Pass down language. (completion_list_add_fields): Add lookup_name_info parameters and adjust. Pass down language. (add_symtab_completions): Add lookup_name_info parameters and adjust. (default_collect_symbol_completion_matches_break_on): Add name_match_type parameter, and use it. Use lookup_name_info. (default_collect_symbol_completion_matches) (collect_symbol_completion_matches): Add name_match_type parameter, and pass it down. (collect_symbol_completion_matches_type): Adjust. (collect_file_symbol_completion_matches): Add name_match_type parameter, and use lookup_name_info. * symtab.h: Include <string> and "common/gdb_optional.h". (enum class symbol_name_match_type): New. (class ada_lookup_name_info): New. (struct demangle_for_lookup_info): New. (class lookup_name_info): New. (symbol_name_matcher_ftype): New. (SYMBOL_MATCHES_SEARCH_NAME): Use symbol_matches_search_name. (symbol_matches_search_name): Declare. (MSYMBOL_MATCHES_SEARCH_NAME): Delete. (default_collect_symbol_completion_matches) (collect_symbol_completion_matches) (collect_file_symbol_completion_matches): Add name_match_type parameter. (iterate_over_symbols): Use lookup_name_info. (completion_list_add_name): Declare. * utils.c (enum class strncmp_iw_mode): Moved to utils.h. (strncmp_iw_with_mode): Now extern. * utils.h (enum class strncmp_iw_mode): Moved from utils.c. (strncmp_iw_with_mode): Declare. gdb/testsuite/ChangeLog: 2017-11-08 Pedro Alves <palves@redhat.com> * gdb.ada/complete.exp (p <Exported_Capitalized>): New test. (p Exported_Capitalized): New test. (p exported_capitalized): New test.
2017-11-08 15:22:32 +01:00
lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
ALL_BLOCK_SYMBOLS_WITH_NAME (block, lookup_name, iter, sym)
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
overload_list_add_symbol (sym, name, overload_list);
}
/* Adds the function FUNC_NAME from NAMESPACE to the overload set. */
static void
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
add_symbol_overload_list_namespace (const char *func_name,
const char *the_namespace,
std::vector<symbol *> *overload_list)
{
const char *name;
const struct block *block = NULL;
if (the_namespace[0] == '\0')
name = func_name;
else
{
char *concatenated_name
Add casts to memory allocation related calls Most allocation functions (if not all) return a void* pointing to the allocated memory. In C++, we need to add an explicit cast when assigning the result to a pointer to another type (which is the case more often than not). The content of this patch is taken from Pedro's branch, from commit "(mostly) auto-generated patch to insert casts needed for C++". I validated that the changes make sense and manually reflowed the code to make it respect the coding style. I also found multiple places where I could use XNEW/XNEWVEC/XRESIZEVEC/etc. Thanks a lot to whoever did that automated script to insert casts, doing it completely by hand would have taken a ridiculous amount of time. Only files built on x86 with --enable-targets=all are modified. This means that all other -nat.c files are untouched and will have to be dealt with later by using appropiate compilers. Or maybe we can try to build them with a regular g++ just to know where to add casts, I don't know. I built-tested this with --enable-targets=all and reg-tested. Here's the changelog entry, which was not too bad to make despite the size, thanks to David Malcom's script. I fixed some bits by hand, but there might be some wrong parts left (hopefully not). gdb/ChangeLog: * aarch64-linux-tdep.c (aarch64_stap_parse_special_token): Add cast to allocation result assignment. * ada-exp.y (write_object_renaming): Likewise. (write_ambiguous_var): Likewise. (ada_nget_field_index): Likewise. (write_var_or_type): Likewise. * ada-lang.c (ada_decode_symbol): Likewise. (ada_value_assign): Likewise. (value_pointer): Likewise. (cache_symbol): Likewise. (add_nonlocal_symbols): Likewise. (ada_name_for_lookup): Likewise. (symbol_completion_add): Likewise. (ada_to_fixed_type_1): Likewise. (ada_get_next_arg): Likewise. (defns_collected): Likewise. * ada-lex.l (processId): Likewise. (processString): Likewise. * ada-tasks.c (read_known_tasks_array): Likewise. (read_known_tasks_list): Likewise. * ada-typeprint.c (decoded_type_name): Likewise. * addrmap.c (addrmap_mutable_create_fixed): Likewise. * amd64-tdep.c (amd64_push_arguments): Likewise. (amd64_displaced_step_copy_insn): Likewise. (amd64_classify_insn_at): Likewise. (amd64_relocate_instruction): Likewise. * amd64obsd-tdep.c (amd64obsd_sigtramp_p): Likewise. * arch-utils.c (simple_displaced_step_copy_insn): Likewise. (initialize_current_architecture): Likewise. * arm-linux-tdep.c (arm_stap_parse_special_token): Likewise. * arm-symbian-tdep.c (arm_symbian_osabi_sniffer): Likewise. * arm-tdep.c (arm_exidx_new_objfile): Likewise. (arm_push_dummy_call): Likewise. (extend_buffer_earlier): Likewise. (arm_adjust_breakpoint_address): Likewise. (arm_skip_stub): Likewise. * auto-load.c (filename_is_in_pattern): Likewise. (maybe_add_script_file): Likewise. (maybe_add_script_text): Likewise. (auto_load_objfile_script_1): Likewise. * auxv.c (ld_so_xfer_auxv): Likewise. * ax-general.c (new_agent_expr): Likewise. (grow_expr): Likewise. (ax_reg_mask): Likewise. * bcache.c (bcache_full): Likewise. * breakpoint.c (program_breakpoint_here_p): Likewise. * btrace.c (parse_xml_raw): Likewise. * build-id.c (build_id_to_debug_bfd): Likewise. * buildsym.c (end_symtab_with_blockvector): Likewise. * c-exp.y (string_exp): Likewise. (qualified_name): Likewise. (write_destructor_name): Likewise. (operator_stoken): Likewise. (parse_number): Likewise. (scan_macro_expansion): Likewise. (yylex): Likewise. (c_print_token): Likewise. * c-lang.c (c_get_string): Likewise. (emit_numeric_character): Likewise. * charset.c (wchar_iterate): Likewise. * cli/cli-cmds.c (complete_command): Likewise. (make_command): Likewise. * cli/cli-dump.c (restore_section_callback): Likewise. (restore_binary_file): Likewise. * cli/cli-interp.c (cli_interpreter_exec): Likewise. * cli/cli-script.c (execute_control_command): Likewise. * cli/cli-setshow.c (do_set_command): Likewise. * coff-pe-read.c (add_pe_forwarded_sym): Likewise. (read_pe_exported_syms): Likewise. * coffread.c (coff_read_struct_type): Likewise. (coff_read_enum_type): Likewise. * common/btrace-common.c (btrace_data_append): Likewise. * common/buffer.c (buffer_grow): Likewise. * common/filestuff.c (gdb_fopen_cloexec): Likewise. * common/format.c (parse_format_string): Likewise. * common/gdb_vecs.c (delim_string_to_char_ptr_vec_append): Likewise. * common/xml-utils.c (xml_escape_text): Likewise. * compile/compile-object-load.c (copy_sections): Likewise. (compile_object_load): Likewise. * compile/compile-object-run.c (compile_object_run): Likewise. * completer.c (filename_completer): Likewise. * corefile.c (read_memory_typed_address): Likewise. (write_memory_unsigned_integer): Likewise. (write_memory_signed_integer): Likewise. (complete_set_gnutarget): Likewise. * corelow.c (get_core_register_section): Likewise. * cp-name-parser.y (d_grab): Likewise. (allocate_info): Likewise. (cp_new_demangle_parse_info): Likewise. * cp-namespace.c (cp_scan_for_anonymous_namespaces): Likewise. (cp_lookup_symbol_in_namespace): Likewise. (lookup_namespace_scope): Likewise. (find_symbol_in_baseclass): Likewise. (cp_lookup_nested_symbol): Likewise. (cp_lookup_transparent_type_loop): Likewise. * cp-support.c (copy_string_to_obstack): Likewise. (make_symbol_overload_list): Likewise. (make_symbol_overload_list_namespace): Likewise. (make_symbol_overload_list_adl_namespace): Likewise. (first_component_command): Likewise. * cp-valprint.c (cp_print_value): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * d-exp.y (StringExp): Likewise. * d-namespace.c (d_lookup_symbol_in_module): Likewise. (lookup_module_scope): Likewise. (find_symbol_in_baseclass): Likewise. (d_lookup_nested_symbol): Likewise. * dbxread.c (find_stab_function_addr): Likewise. (read_dbx_symtab): Likewise. (dbx_end_psymtab): Likewise. (cp_set_block_scope): Likewise. * dcache.c (dcache_alloc): Likewise. * demangle.c (_initialize_demangler): Likewise. * dicos-tdep.c (dicos_load_module_p): Likewise. * dictionary.c (dict_create_hashed_expandable): Likewise. (dict_create_linear_expandable): Likewise. (expand_hashtable): Likewise. (add_symbol_linear_expandable): Likewise. * dwarf2-frame.c (add_cie): Likewise. (add_fde): Likewise. (dwarf2_build_frame_info): Likewise. * dwarf2expr.c (dwarf_expr_grow_stack): Likewise. (dwarf_expr_fetch_address): Likewise. (add_piece): Likewise. (execute_stack_op): Likewise. * dwarf2loc.c (chain_candidate): Likewise. (dwarf_entry_parameter_to_value): Likewise. (read_pieced_value): Likewise. (write_pieced_value): Likewise. * dwarf2read.c (dwarf2_read_section): Likewise. (add_type_unit): Likewise. (read_comp_units_from_section): Likewise. (fixup_go_packaging): Likewise. (dwarf2_compute_name): Likewise. (dwarf2_physname): Likewise. (create_dwo_unit_in_dwp_v1): Likewise. (create_dwo_unit_in_dwp_v2): Likewise. (read_func_scope): Likewise. (read_call_site_scope): Likewise. (dwarf2_attach_fields_to_type): Likewise. (process_structure_scope): Likewise. (mark_common_block_symbol_computed): Likewise. (read_common_block): Likewise. (abbrev_table_read_table): Likewise. (guess_partial_die_structure_name): Likewise. (fixup_partial_die): Likewise. (add_file_name): Likewise. (dwarf2_const_value_data): Likewise. (dwarf2_const_value_attr): Likewise. (build_error_marker_type): Likewise. (guess_full_die_structure_name): Likewise. (anonymous_struct_prefix): Likewise. (typename_concat): Likewise. (dwarf2_canonicalize_name): Likewise. (dwarf2_name): Likewise. (write_constant_as_bytes): Likewise. (dwarf2_fetch_constant_bytes): Likewise. (copy_string): Likewise. (parse_macro_definition): Likewise. * elfread.c (elf_symfile_segments): Likewise. (elf_rel_plt_read): Likewise. (elf_gnu_ifunc_resolve_by_cache): Likewise. (elf_gnu_ifunc_resolve_by_got): Likewise. (elf_read_minimal_symbols): Likewise. (elf_gnu_ifunc_record_cache): Likewise. * event-top.c (top_level_prompt): Likewise. (command_line_handler): Likewise. * exec.c (resize_section_table): Likewise. * expprint.c (print_subexp_standard): Likewise. * fbsd-tdep.c (fbsd_collect_regset_section_cb): Likewise. * findcmd.c (parse_find_args): Likewise. * findvar.c (address_from_register): Likewise. * frame.c (get_prev_frame_always): Likewise. * gdb_bfd.c (gdb_bfd_ref): Likewise. (get_section_descriptor): Likewise. * gdb_obstack.c (obconcat): Likewise. (obstack_strdup): Likewise. * gdbtypes.c (lookup_function_type_with_arguments): Likewise. (create_set_type): Likewise. (lookup_unsigned_typename): Likewise. (lookup_signed_typename): Likewise. (resolve_dynamic_union): Likewise. (resolve_dynamic_struct): Likewise. (add_dyn_prop): Likewise. (copy_dynamic_prop_list): Likewise. (arch_flags_type): Likewise. (append_composite_type_field_raw): Likewise. * gdbtypes.h (INIT_FUNC_SPECIFIC): Likewise. * gnu-v3-abi.c (gnuv3_rtti_type): Likewise. * go-exp.y (string_exp): Likewise. * go-lang.c (go_demangle): Likewise. * guile/guile.c (compute_scheme_string): Likewise. * guile/scm-cmd.c (gdbscm_parse_command_name): Likewise. (gdbscm_canonicalize_command_name): Likewise. * guile/scm-ports.c (ioscm_init_stdio_buffers): Likewise. (ioscm_init_memory_port): Likewise. (ioscm_reinit_memory_port): Likewise. * guile/scm-utils.c (gdbscm_gc_xstrdup): Likewise. (gdbscm_gc_dup_argv): Likewise. * h8300-tdep.c (h8300_push_dummy_call): Likewise. * hppa-tdep.c (internalize_unwinds): Likewise. (read_unwind_info): Likewise. * i386-cygwin-tdep.c (core_process_module_section): Likewise. (windows_core_xfer_shared_libraries): Likewise. * i386-tdep.c (i386_displaced_step_copy_insn): Likewise. (i386_stap_parse_special_token_triplet): Likewise. (i386_stap_parse_special_token_three_arg_disp): Likewise. * i386obsd-tdep.c (i386obsd_sigtramp_p): Likewise. * inf-child.c (inf_child_fileio_readlink): Likewise. * inf-ptrace.c (inf_ptrace_fetch_register): Likewise. (inf_ptrace_store_register): Likewise. * infrun.c (follow_exec): Likewise. (displaced_step_prepare_throw): Likewise. (save_stop_context): Likewise. (save_infcall_suspend_state): Likewise. * jit.c (jit_read_descriptor): Likewise. (jit_read_code_entry): Likewise. (jit_symtab_line_mapping_add_impl): Likewise. (finalize_symtab): Likewise. (jit_unwind_reg_get_impl): Likewise. * jv-exp.y (QualifiedName): Likewise. * jv-lang.c (get_java_utf8_name): Likewise. (type_from_class): Likewise. (java_demangle_type_signature): Likewise. (java_class_name_from_physname): Likewise. * jv-typeprint.c (java_type_print_base): Likewise. * jv-valprint.c (java_value_print): Likewise. * language.c (add_language): Likewise. * linespec.c (add_sal_to_sals_basic): Likewise. (add_sal_to_sals): Likewise. (decode_objc): Likewise. (find_linespec_symbols): Likewise. * linux-fork.c (fork_save_infrun_state): Likewise. * linux-nat.c (linux_nat_detach): Likewise. (linux_nat_fileio_readlink): Likewise. * linux-record.c (record_linux_sockaddr): Likewise. (record_linux_msghdr): Likewise. (Do): Likewise. * linux-tdep.c (linux_core_info_proc_mappings): Likewise. (linux_collect_regset_section_cb): Likewise. (linux_get_siginfo_data): Likewise. * linux-thread-db.c (try_thread_db_load_from_pdir_1): Likewise. (try_thread_db_load_from_dir): Likewise. (thread_db_load_search): Likewise. (info_auto_load_libthread_db): Likewise. * m32c-tdep.c (m32c_m16c_address_to_pointer): Likewise. (m32c_m16c_pointer_to_address): Likewise. * m68hc11-tdep.c (m68hc11_pseudo_register_write): Likewise. * m68k-tdep.c (m68k_get_longjmp_target): Likewise. * machoread.c (macho_check_dsym): Likewise. * macroexp.c (resize_buffer): Likewise. (gather_arguments): Likewise. (maybe_expand): Likewise. * macrotab.c (new_macro_key): Likewise. (new_source_file): Likewise. (new_macro_definition): Likewise. * mdebugread.c (parse_symbol): Likewise. (parse_type): Likewise. (parse_partial_symbols): Likewise. (psymtab_to_symtab_1): Likewise. * mem-break.c (default_memory_insert_breakpoint): Likewise. * mi/mi-cmd-break.c (mi_argv_to_format): Likewise. * mi/mi-main.c (mi_cmd_data_read_memory): Likewise. (mi_cmd_data_read_memory_bytes): Likewise. (mi_cmd_data_write_memory_bytes): Likewise. (mi_cmd_trace_frame_collected): Likewise. * mi/mi-parse.c (mi_parse_argv): Likewise. (mi_parse): Likewise. * minidebug.c (lzma_open): Likewise. (lzma_pread): Likewise. * mips-tdep.c (mips_read_fp_register_single): Likewise. (mips_print_fp_register): Likewise. * mipsnbsd-tdep.c (mipsnbsd_get_longjmp_target): Likewise. * mipsread.c (read_alphacoff_dynamic_symtab): Likewise. * mt-tdep.c (mt_register_name): Likewise. (mt_registers_info): Likewise. (mt_push_dummy_call): Likewise. * namespace.c (add_using_directive): Likewise. * nat/linux-btrace.c (perf_event_read): Likewise. (linux_enable_bts): Likewise. * nat/linux-osdata.c (linux_common_core_of_thread): Likewise. * nat/linux-ptrace.c (linux_ptrace_test_ret_to_nx): Likewise. * nto-tdep.c (nto_find_and_open_solib): Likewise. (nto_parse_redirection): Likewise. * objc-lang.c (objc_demangle): Likewise. (find_methods): Likewise. * objfiles.c (get_objfile_bfd_data): Likewise. (set_objfile_main_name): Likewise. (allocate_objfile): Likewise. (objfile_relocate): Likewise. (update_section_map): Likewise. * osabi.c (generic_elf_osabi_sniff_abi_tag_sections): Likewise. * p-exp.y (exp): Likewise. (yylex): Likewise. * p-valprint.c (pascal_object_print_value): Likewise. * parse.c (initialize_expout): Likewise. (mark_completion_tag): Likewise. (copy_name): Likewise. (parse_float): Likewise. (type_stack_reserve): Likewise. * ppc-linux-tdep.c (ppc_stap_parse_special_token): Likewise. (ppu2spu_prev_register): Likewise. * ppc-ravenscar-thread.c (supply_register_at_address): Likewise. * printcmd.c (printf_wide_c_string): Likewise. (printf_pointer): Likewise. * probe.c (parse_probes): Likewise. * python/py-cmd.c (gdbpy_parse_command_name): Likewise. (cmdpy_init): Likewise. * python/py-gdb-readline.c (gdbpy_readline_wrapper): Likewise. * python/py-symtab.c (set_sal): Likewise. * python/py-unwind.c (pyuw_sniffer): Likewise. * python/python.c (python_interactive_command): Likewise. (compute_python_string): Likewise. * ravenscar-thread.c (get_running_thread_id): Likewise. * record-full.c (record_full_exec_insn): Likewise. (record_full_core_open_1): Likewise. * regcache.c (regcache_raw_read_signed): Likewise. (regcache_raw_read_unsigned): Likewise. (regcache_cooked_read_signed): Likewise. (regcache_cooked_read_unsigned): Likewise. * remote-fileio.c (remote_fileio_func_open): Likewise. (remote_fileio_func_rename): Likewise. (remote_fileio_func_unlink): Likewise. (remote_fileio_func_stat): Likewise. (remote_fileio_func_system): Likewise. * remote-mips.c (mips_xfer_memory): Likewise. (mips_load_srec): Likewise. (pmon_end_download): Likewise. * remote.c (new_remote_state): Likewise. (map_regcache_remote_table): Likewise. (remote_register_number_and_offset): Likewise. (init_remote_state): Likewise. (get_memory_packet_size): Likewise. (remote_pass_signals): Likewise. (remote_program_signals): Likewise. (remote_start_remote): Likewise. (remote_check_symbols): Likewise. (remote_query_supported): Likewise. (extended_remote_attach): Likewise. (process_g_packet): Likewise. (store_registers_using_G): Likewise. (putpkt_binary): Likewise. (read_frame): Likewise. (compare_sections_command): Likewise. (remote_hostio_pread): Likewise. (remote_hostio_readlink): Likewise. (remote_file_put): Likewise. (remote_file_get): Likewise. (remote_pid_to_exec_file): Likewise. (_initialize_remote): Likewise. * rs6000-aix-tdep.c (rs6000_aix_ld_info_to_xml): Likewise. (rs6000_aix_core_xfer_shared_libraries_aix): Likewise. * rs6000-tdep.c (ppc_displaced_step_copy_insn): Likewise. (bfd_uses_spe_extensions): Likewise. * s390-linux-tdep.c (s390_displaced_step_copy_insn): Likewise. * score-tdep.c (score7_malloc_and_get_memblock): Likewise. * solib-dsbt.c (decode_loadmap): Likewise. (fetch_loadmap): Likewise. (scan_dyntag): Likewise. (enable_break): Likewise. (dsbt_relocate_main_executable): Likewise. * solib-frv.c (fetch_loadmap): Likewise. (enable_break2): Likewise. (frv_relocate_main_executable): Likewise. * solib-spu.c (spu_relocate_main_executable): Likewise. (spu_bfd_open): Likewise. * solib-svr4.c (lm_info_read): Likewise. (read_program_header): Likewise. (find_program_interpreter): Likewise. (scan_dyntag): Likewise. (elf_locate_base): Likewise. (open_symbol_file_object): Likewise. (read_program_headers_from_bfd): Likewise. (svr4_relocate_main_executable): Likewise. * solib-target.c (solib_target_relocate_section_addresses): Likewise. * solib.c (solib_find_1): Likewise. (exec_file_find): Likewise. (solib_find): Likewise. * source.c (openp): Likewise. (print_source_lines_base): Likewise. (forward_search_command): Likewise. * sparc-ravenscar-thread.c (supply_register_at_address): Likewise. * spu-tdep.c (spu2ppu_prev_register): Likewise. (spu_get_overlay_table): Likewise. * stabsread.c (patch_block_stabs): Likewise. (define_symbol): Likewise. (again:): Likewise. (read_member_functions): Likewise. (read_one_struct_field): Likewise. (read_enum_type): Likewise. (common_block_start): Likewise. * stack.c (read_frame_arg): Likewise. (backtrace_command): Likewise. * stap-probe.c (stap_parse_register_operand): Likewise. * symfile.c (syms_from_objfile_1): Likewise. (find_separate_debug_file): Likewise. (load_command): Likewise. (load_progress): Likewise. (load_section_callback): Likewise. (reread_symbols): Likewise. (add_filename_language): Likewise. (allocate_compunit_symtab): Likewise. (read_target_long_array): Likewise. (simple_read_overlay_table): Likewise. * symtab.c (symbol_set_names): Likewise. (resize_symbol_cache): Likewise. (rbreak_command): Likewise. (completion_list_add_name): Likewise. (completion_list_objc_symbol): Likewise. (add_filename_to_list): Likewise. * target-descriptions.c (maint_print_c_tdesc_cmd): Likewise. * target-memory.c (target_write_memory_blocks): Likewise. * target.c (target_read_string): Likewise. (read_whatever_is_readable): Likewise. (target_read_alloc_1): Likewise. (simple_search_memory): Likewise. (target_fileio_read_alloc_1): Likewise. * tilegx-tdep.c (tilegx_push_dummy_call): Likewise. * top.c (command_line_input): Likewise. * tracefile-tfile.c (tfile_fetch_registers): Likewise. * tracefile.c (tracefile_fetch_registers): Likewise. * tracepoint.c (add_memrange): Likewise. (init_collection_list): Likewise. (add_aexpr): Likewise. (trace_dump_actions): Likewise. (parse_trace_status): Likewise. (parse_tracepoint_definition): Likewise. (parse_tsv_definition): Likewise. (parse_static_tracepoint_marker_definition): Likewise. * tui/tui-file.c (tui_sfileopen): Likewise. (tui_file_adjust_strbuf): Likewise. * tui/tui-io.c (tui_expand_tabs): Likewise. * tui/tui-source.c (tui_set_source_content): Likewise. * typeprint.c (find_global_typedef): Likewise. * ui-file.c (do_ui_file_xstrdup): Likewise. (ui_file_obsavestring): Likewise. (mem_file_write): Likewise. * utils.c (make_hex_string): Likewise. (get_regcomp_error): Likewise. (puts_filtered_tabular): Likewise. (gdb_realpath_keepfile): Likewise. (ldirname): Likewise. (gdb_bfd_errmsg): Likewise. (substitute_path_component): Likewise. * valops.c (search_struct_method): Likewise. (find_oload_champ_namespace_loop): Likewise. * valprint.c (print_decimal_chars): Likewise. (read_string): Likewise. (generic_emit_char): Likewise. * varobj.c (varobj_delete): Likewise. (varobj_value_get_print_value): Likewise. * vaxobsd-tdep.c (vaxobsd_sigtramp_sniffer): Likewise. * windows-tdep.c (display_one_tib): Likewise. * xcoffread.c (read_xcoff_symtab): Likewise. (process_xcoff_symbol): Likewise. (swap_sym): Likewise. (scan_xcoff_symtab): Likewise. (xcoff_initial_scan): Likewise. * xml-support.c (gdb_xml_end_element): Likewise. (xml_process_xincludes): Likewise. (xml_fetch_content_from_file): Likewise. * xml-syscall.c (xml_list_of_syscalls): Likewise. * xstormy16-tdep.c (xstormy16_push_dummy_call): Likewise. gdb/gdbserver/ChangeLog: * ax.c (gdb_parse_agent_expr): Add cast to allocation result assignment. (gdb_unparse_agent_expr): Likewise. * hostio.c (require_data): Likewise. (handle_pread): Likewise. * linux-low.c (disable_regset): Likewise. (fetch_register): Likewise. (store_register): Likewise. (get_dynamic): Likewise. (linux_qxfer_libraries_svr4): Likewise. * mem-break.c (delete_fast_tracepoint_jump): Likewise. (set_fast_tracepoint_jump): Likewise. (uninsert_fast_tracepoint_jumps_at): Likewise. (reinsert_fast_tracepoint_jumps_at): Likewise. (validate_inserted_breakpoint): Likewise. (clone_agent_expr): Likewise. * regcache.c (init_register_cache): Likewise. * remote-utils.c (putpkt_binary_1): Likewise. (decode_M_packet): Likewise. (decode_X_packet): Likewise. (look_up_one_symbol): Likewise. (relocate_instruction): Likewise. (monitor_output): Likewise. * server.c (handle_search_memory): Likewise. (handle_qxfer_exec_file): Likewise. (handle_qxfer_libraries): Likewise. (handle_qxfer): Likewise. (handle_query): Likewise. (handle_v_cont): Likewise. (handle_v_run): Likewise. (captured_main): Likewise. * target.c (write_inferior_memory): Likewise. * thread-db.c (try_thread_db_load_from_dir): Likewise. * tracepoint.c (init_trace_buffer): Likewise. (add_tracepoint_action): Likewise. (add_traceframe): Likewise. (add_traceframe_block): Likewise. (cmd_qtdpsrc): Likewise. (cmd_qtdv): Likewise. (cmd_qtstatus): Likewise. (response_source): Likewise. (response_tsv): Likewise. (cmd_qtnotes): Likewise. (gdb_collect): Likewise. (initialize_tracepoint): Likewise.
2015-09-25 20:08:06 +02:00
= (char *) alloca (strlen (the_namespace) + 2 + strlen (func_name) + 1);
strcpy (concatenated_name, the_namespace);
strcat (concatenated_name, "::");
strcat (concatenated_name, func_name);
name = concatenated_name;
}
/* Look in the static block. */
block = block_static_block (get_selected_block (0));
if (block)
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
add_symbol_overload_list_block (name, block, overload_list);
/* Look in the global block. */
block = block_global_block (block);
if (block)
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
add_symbol_overload_list_block (name, block, overload_list);
}
/* Search the namespace of the given type and namespace of and public
base types. */
static void
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
add_symbol_overload_list_adl_namespace (struct type *type,
const char *func_name,
std::vector<symbol *> *overload_list)
{
char *the_namespace;
* gdbtypes.h (struct main_type): Change type of name,tag_name, and fields.name members from char * to const char *. All uses updated. (struct cplus_struct_type): Change type of fn_fieldlists.name member from char * to const char *. All uses updated. (type_name_no_tag): Update. (lookup_unsigned_typename, lookup_signed_typename): Update. * gdbtypes.c (type_name_no_tag): Change result type from char * to const char *. All callers updated. (lookup_unsigned_typename, lookup_signed_typename): Change type of name parameter from char * to const char *. * symtab.h (struct cplus_specific): Change type of demangled_name member from char * to const char *. All uses updated. (struct general_symbol_info): Change type of name and mangled_lang.demangled_name members from char * to const char *. All uses updated. (symbol_get_demangled_name, symbol_natural_name): Update. (symbol_demangled_name, symbol_search_name): Update. * symtab.c (symbol_get_demangled_name): Change result type from char * to const char *. All callers updated. (symbol_natural_name, symbol_demangled_name): Ditto. (symbol_search_name): Ditto. (completion_list_add_name): Change type of symname,sym_text, text,word parameters from char * to const char *. (completion_list_objc_symbol): Change type of sym_text, text,word parameters from char * to const char *. * ada-lang.c (find_struct_field): Change type of name parameter from char * to const char *. (encoded_ordered_before): Similarly for N0,N1 parameters. (old_renaming_is_invisible): Similarly for function_name parameter. (ada_type_name): Change result type from char * to const char *. All callers updated. * ada-lang.h (ada_type_name): Update. * buildsym.c (hashname): Change type of name parameter from char * to const char *. * buildsym.h (hashname): Update. * dbxread.c (end_psymtab): Change type of include_list parameter from char ** to const char **. * dwarf2read.c (determine_prefix): Change result type from char * to const char *. All callers updated. * f-lang.c (find_common_for_function): Change type of name, funcname parameters from char * to const char *. * f-lang.c (find_common_for_function): Update. * f-valprint.c (list_all_visible_commons): Change type of funcname parameters from char * to const char *. * gdbarch.sh (static_transform_name): Change type of name parameter and result from char * to const char *. * gdbarch.c: Regenerate. * gdbarch.h: Regenerate. * i386-sol2-tdep.c (i386_sol2_static_transform_name): Change type of name parameter from char * to const char *. * jv-lang.c (java_primitive_type_from_name): Ditto. (java_demangled_signature_length): Similarly for signature parameter. (java_demangled_signature_copy): Ditto. (java_demangle_type_signature): Ditto. * jv-lang.h (java_primitive_type_from_name): Update. (java_demangle_type_signature): Update. * objc-lang.c (specialcmp): Change type of a,b parameters from char * to const char *. * p-lang.c (is_pascal_string_type): Change type of arrayname parameter from char * to const char *. All callers updated. * p-lang.h (is_pascal_string_type): Update. * solib-frv.c (find_canonical_descriptor_in_load_object): Change type of name parameter from char * to const char *. * sparc-sol2-tdep.c (sparc_sol2_static_transform_name): Ditto. * utils.c (fprintf_symbol_filtered): Ditto. * defs.h (fprintf_symbol_filtered): Update. * sparc-tdep.h (sparc_sol2_static_transform_name): Update. * stabsread.h (end_psymtab): Update. * stack.c (find_frame_funname): Change type of funname parameter from char ** to const char **. * stack.h (find_frame_funname): Update. * typeprint.c (type_print): Change type of varstring parameter from char * to const char *. * value.h (type_print): Update. * xcoffread.c (xcoff_start_psymtab): Change type of filename parameter from char * to const char *. All callers updated. (xcoff_end_psymtab): Change type of include_list parameter from char ** to const char **. All callers updated. (swap_sym): Similarly for name parameter. All callers updated. * coffread.c (patch_type): Add (char*) cast to xfree parameter. Use xstrdup. (process_coff_symbol): Use xstrdup. * stabsread.c (stabs_method_name_from_physname): Renamed from update_method_name_from_physname. Change result type from void to char *. All callers updated. (read_member_functions): In has_destructor case, store name in objfile obstack instead of malloc space. In !has_stub case, fix mem leak.
2012-02-07 05:48:23 +01:00
const char *type_name;
int i, prefix_len;
while (TYPE_CODE (type) == TYPE_CODE_PTR
Convert lvalue reference type check to general reference type check In almost all contexts (except for overload resolution rules and expression semantics), lvalue and rvalue references are equivalent. That means that in all but these cases we can replace a TYPE_CODE_REF check to a TYPE_IS_REFERENCE check and, for switch statements, add a case label for a rvalue reference type next to a case label for an lvalue reference type. This patch does exactly that. gdb/ChangeLog PR gdb/14441 * aarch64-tdep.c (aarch64_type_align) (aarch64_extract_return_value, aarch64_store_return_value): Change lvalue reference type checks to general reference type checks. * amd64-tdep.c (amd64_classify): Likewise. * amd64-windows-tdep.c (amd64_windows_passed_by_integer_register): Likewise. * arm-tdep.c (arm_type_align, arm_extract_return_value) (arm_store_return_value): Likewise. * ax-gdb.c (gen_fetch, gen_cast): Likewise. * c-typeprint.c (c_print_type): Likewise. * c-varobj.c (adjust_value_for_child_access, c_value_of_variable) (cplus_number_of_children, cplus_describe_child): Likewise. * compile/compile-c-symbols.c (generate_vla_size): Likewise. * completer.c (expression_completer): Likewise. * cp-support.c (make_symbol_overload_list_adl_namespace): Likewise. * darwin-nat-info.c (info_mach_region_command): Likewise. * dwarf2loc.c (entry_data_value_coerce_ref) (value_of_dwarf_reg_entry): Likewise. * eval.c (ptrmath_type_p, evaluate_subexp_standard) (evaluate_subexp_for_address, evaluate_subexp_for_sizeof): Likewise. * findvar.c (extract_typed_address, store_typed_address): Likewise. * gdbtypes.c (rank_one_type): Likewise. * hppa-tdep.c (hppa64_integral_or_pointer_p): Likewise. * infcall.c (value_arg_coerce): Likewise. * language.c (pointer_type): Likewise. * m32c-tdep.c (m32c_reg_arg_type, m32c_m16c_address_to_pointer): Likewise. * m88k-tdep.c (m88k_integral_or_pointer_p): Likewise. * mn10300-tdep.c (mn10300_type_align): Likewise. * msp430-tdep.c (msp430_push_dummy_call): Likewise. * ppc-sysv-tdep.c (do_ppc_sysv_return_value) (ppc64_sysv_abi_push_param, ppc64_sysv_abi_return_value): Likewise. * printcmd.c (print_formatted, x_command): Likewise. * python/py-type.c (typy_get_composite, typy_template_argument): Likewise. * python/py-value.c (valpy_referenced_value) (valpy_get_dynamic_type, value_has_field): Likewise. * s390-linux-tdep.c (s390_function_arg_integer): Likewise. * sparc-tdep.c (sparc_integral_or_pointer_p): Likewise. * sparc64-tdep.c (sparc64_integral_or_pointer_p): Likewise. * spu-tdep.c (spu_scalar_value_p): Likewise. * symtab.c (lookup_symbol_aux): Likewise. * typeprint.c (whatis_exp, print_type_scalar): Likewise. * valarith.c (binop_types_user_defined_p, unop_user_defined_p): Likewise. * valops.c (value_cast_pointers, value_cast) (value_reinterpret_cast, value_dynamic_cast, value_addr, typecmp) (value_struct_elt, value_struct_elt_bitpos) (value_find_oload_method_list, find_overload_match) (value_rtti_indirect_type): Likewise. * valprint.c (val_print_scalar_type_p, generic_val_print): Likewise. * value.c (value_actual_type, value_as_address, unpack_long) (pack_long, pack_unsigned_long, coerce_ref_if_computed) (coerce_ref): Likewise. * varobj.c (varobj_get_value_type): Likewise.
2017-03-20 21:47:54 +01:00
|| TYPE_IS_REFERENCE (type)
|| TYPE_CODE (type) == TYPE_CODE_ARRAY
|| TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
{
if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
type = check_typedef(type);
else
type = TYPE_TARGET_TYPE (type);
}
type_name = TYPE_NAME (type);
if (type_name == NULL)
return;
prefix_len = cp_entire_prefix_len (type_name);
if (prefix_len != 0)
{
Add casts to memory allocation related calls Most allocation functions (if not all) return a void* pointing to the allocated memory. In C++, we need to add an explicit cast when assigning the result to a pointer to another type (which is the case more often than not). The content of this patch is taken from Pedro's branch, from commit "(mostly) auto-generated patch to insert casts needed for C++". I validated that the changes make sense and manually reflowed the code to make it respect the coding style. I also found multiple places where I could use XNEW/XNEWVEC/XRESIZEVEC/etc. Thanks a lot to whoever did that automated script to insert casts, doing it completely by hand would have taken a ridiculous amount of time. Only files built on x86 with --enable-targets=all are modified. This means that all other -nat.c files are untouched and will have to be dealt with later by using appropiate compilers. Or maybe we can try to build them with a regular g++ just to know where to add casts, I don't know. I built-tested this with --enable-targets=all and reg-tested. Here's the changelog entry, which was not too bad to make despite the size, thanks to David Malcom's script. I fixed some bits by hand, but there might be some wrong parts left (hopefully not). gdb/ChangeLog: * aarch64-linux-tdep.c (aarch64_stap_parse_special_token): Add cast to allocation result assignment. * ada-exp.y (write_object_renaming): Likewise. (write_ambiguous_var): Likewise. (ada_nget_field_index): Likewise. (write_var_or_type): Likewise. * ada-lang.c (ada_decode_symbol): Likewise. (ada_value_assign): Likewise. (value_pointer): Likewise. (cache_symbol): Likewise. (add_nonlocal_symbols): Likewise. (ada_name_for_lookup): Likewise. (symbol_completion_add): Likewise. (ada_to_fixed_type_1): Likewise. (ada_get_next_arg): Likewise. (defns_collected): Likewise. * ada-lex.l (processId): Likewise. (processString): Likewise. * ada-tasks.c (read_known_tasks_array): Likewise. (read_known_tasks_list): Likewise. * ada-typeprint.c (decoded_type_name): Likewise. * addrmap.c (addrmap_mutable_create_fixed): Likewise. * amd64-tdep.c (amd64_push_arguments): Likewise. (amd64_displaced_step_copy_insn): Likewise. (amd64_classify_insn_at): Likewise. (amd64_relocate_instruction): Likewise. * amd64obsd-tdep.c (amd64obsd_sigtramp_p): Likewise. * arch-utils.c (simple_displaced_step_copy_insn): Likewise. (initialize_current_architecture): Likewise. * arm-linux-tdep.c (arm_stap_parse_special_token): Likewise. * arm-symbian-tdep.c (arm_symbian_osabi_sniffer): Likewise. * arm-tdep.c (arm_exidx_new_objfile): Likewise. (arm_push_dummy_call): Likewise. (extend_buffer_earlier): Likewise. (arm_adjust_breakpoint_address): Likewise. (arm_skip_stub): Likewise. * auto-load.c (filename_is_in_pattern): Likewise. (maybe_add_script_file): Likewise. (maybe_add_script_text): Likewise. (auto_load_objfile_script_1): Likewise. * auxv.c (ld_so_xfer_auxv): Likewise. * ax-general.c (new_agent_expr): Likewise. (grow_expr): Likewise. (ax_reg_mask): Likewise. * bcache.c (bcache_full): Likewise. * breakpoint.c (program_breakpoint_here_p): Likewise. * btrace.c (parse_xml_raw): Likewise. * build-id.c (build_id_to_debug_bfd): Likewise. * buildsym.c (end_symtab_with_blockvector): Likewise. * c-exp.y (string_exp): Likewise. (qualified_name): Likewise. (write_destructor_name): Likewise. (operator_stoken): Likewise. (parse_number): Likewise. (scan_macro_expansion): Likewise. (yylex): Likewise. (c_print_token): Likewise. * c-lang.c (c_get_string): Likewise. (emit_numeric_character): Likewise. * charset.c (wchar_iterate): Likewise. * cli/cli-cmds.c (complete_command): Likewise. (make_command): Likewise. * cli/cli-dump.c (restore_section_callback): Likewise. (restore_binary_file): Likewise. * cli/cli-interp.c (cli_interpreter_exec): Likewise. * cli/cli-script.c (execute_control_command): Likewise. * cli/cli-setshow.c (do_set_command): Likewise. * coff-pe-read.c (add_pe_forwarded_sym): Likewise. (read_pe_exported_syms): Likewise. * coffread.c (coff_read_struct_type): Likewise. (coff_read_enum_type): Likewise. * common/btrace-common.c (btrace_data_append): Likewise. * common/buffer.c (buffer_grow): Likewise. * common/filestuff.c (gdb_fopen_cloexec): Likewise. * common/format.c (parse_format_string): Likewise. * common/gdb_vecs.c (delim_string_to_char_ptr_vec_append): Likewise. * common/xml-utils.c (xml_escape_text): Likewise. * compile/compile-object-load.c (copy_sections): Likewise. (compile_object_load): Likewise. * compile/compile-object-run.c (compile_object_run): Likewise. * completer.c (filename_completer): Likewise. * corefile.c (read_memory_typed_address): Likewise. (write_memory_unsigned_integer): Likewise. (write_memory_signed_integer): Likewise. (complete_set_gnutarget): Likewise. * corelow.c (get_core_register_section): Likewise. * cp-name-parser.y (d_grab): Likewise. (allocate_info): Likewise. (cp_new_demangle_parse_info): Likewise. * cp-namespace.c (cp_scan_for_anonymous_namespaces): Likewise. (cp_lookup_symbol_in_namespace): Likewise. (lookup_namespace_scope): Likewise. (find_symbol_in_baseclass): Likewise. (cp_lookup_nested_symbol): Likewise. (cp_lookup_transparent_type_loop): Likewise. * cp-support.c (copy_string_to_obstack): Likewise. (make_symbol_overload_list): Likewise. (make_symbol_overload_list_namespace): Likewise. (make_symbol_overload_list_adl_namespace): Likewise. (first_component_command): Likewise. * cp-valprint.c (cp_print_value): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * d-exp.y (StringExp): Likewise. * d-namespace.c (d_lookup_symbol_in_module): Likewise. (lookup_module_scope): Likewise. (find_symbol_in_baseclass): Likewise. (d_lookup_nested_symbol): Likewise. * dbxread.c (find_stab_function_addr): Likewise. (read_dbx_symtab): Likewise. (dbx_end_psymtab): Likewise. (cp_set_block_scope): Likewise. * dcache.c (dcache_alloc): Likewise. * demangle.c (_initialize_demangler): Likewise. * dicos-tdep.c (dicos_load_module_p): Likewise. * dictionary.c (dict_create_hashed_expandable): Likewise. (dict_create_linear_expandable): Likewise. (expand_hashtable): Likewise. (add_symbol_linear_expandable): Likewise. * dwarf2-frame.c (add_cie): Likewise. (add_fde): Likewise. (dwarf2_build_frame_info): Likewise. * dwarf2expr.c (dwarf_expr_grow_stack): Likewise. (dwarf_expr_fetch_address): Likewise. (add_piece): Likewise. (execute_stack_op): Likewise. * dwarf2loc.c (chain_candidate): Likewise. (dwarf_entry_parameter_to_value): Likewise. (read_pieced_value): Likewise. (write_pieced_value): Likewise. * dwarf2read.c (dwarf2_read_section): Likewise. (add_type_unit): Likewise. (read_comp_units_from_section): Likewise. (fixup_go_packaging): Likewise. (dwarf2_compute_name): Likewise. (dwarf2_physname): Likewise. (create_dwo_unit_in_dwp_v1): Likewise. (create_dwo_unit_in_dwp_v2): Likewise. (read_func_scope): Likewise. (read_call_site_scope): Likewise. (dwarf2_attach_fields_to_type): Likewise. (process_structure_scope): Likewise. (mark_common_block_symbol_computed): Likewise. (read_common_block): Likewise. (abbrev_table_read_table): Likewise. (guess_partial_die_structure_name): Likewise. (fixup_partial_die): Likewise. (add_file_name): Likewise. (dwarf2_const_value_data): Likewise. (dwarf2_const_value_attr): Likewise. (build_error_marker_type): Likewise. (guess_full_die_structure_name): Likewise. (anonymous_struct_prefix): Likewise. (typename_concat): Likewise. (dwarf2_canonicalize_name): Likewise. (dwarf2_name): Likewise. (write_constant_as_bytes): Likewise. (dwarf2_fetch_constant_bytes): Likewise. (copy_string): Likewise. (parse_macro_definition): Likewise. * elfread.c (elf_symfile_segments): Likewise. (elf_rel_plt_read): Likewise. (elf_gnu_ifunc_resolve_by_cache): Likewise. (elf_gnu_ifunc_resolve_by_got): Likewise. (elf_read_minimal_symbols): Likewise. (elf_gnu_ifunc_record_cache): Likewise. * event-top.c (top_level_prompt): Likewise. (command_line_handler): Likewise. * exec.c (resize_section_table): Likewise. * expprint.c (print_subexp_standard): Likewise. * fbsd-tdep.c (fbsd_collect_regset_section_cb): Likewise. * findcmd.c (parse_find_args): Likewise. * findvar.c (address_from_register): Likewise. * frame.c (get_prev_frame_always): Likewise. * gdb_bfd.c (gdb_bfd_ref): Likewise. (get_section_descriptor): Likewise. * gdb_obstack.c (obconcat): Likewise. (obstack_strdup): Likewise. * gdbtypes.c (lookup_function_type_with_arguments): Likewise. (create_set_type): Likewise. (lookup_unsigned_typename): Likewise. (lookup_signed_typename): Likewise. (resolve_dynamic_union): Likewise. (resolve_dynamic_struct): Likewise. (add_dyn_prop): Likewise. (copy_dynamic_prop_list): Likewise. (arch_flags_type): Likewise. (append_composite_type_field_raw): Likewise. * gdbtypes.h (INIT_FUNC_SPECIFIC): Likewise. * gnu-v3-abi.c (gnuv3_rtti_type): Likewise. * go-exp.y (string_exp): Likewise. * go-lang.c (go_demangle): Likewise. * guile/guile.c (compute_scheme_string): Likewise. * guile/scm-cmd.c (gdbscm_parse_command_name): Likewise. (gdbscm_canonicalize_command_name): Likewise. * guile/scm-ports.c (ioscm_init_stdio_buffers): Likewise. (ioscm_init_memory_port): Likewise. (ioscm_reinit_memory_port): Likewise. * guile/scm-utils.c (gdbscm_gc_xstrdup): Likewise. (gdbscm_gc_dup_argv): Likewise. * h8300-tdep.c (h8300_push_dummy_call): Likewise. * hppa-tdep.c (internalize_unwinds): Likewise. (read_unwind_info): Likewise. * i386-cygwin-tdep.c (core_process_module_section): Likewise. (windows_core_xfer_shared_libraries): Likewise. * i386-tdep.c (i386_displaced_step_copy_insn): Likewise. (i386_stap_parse_special_token_triplet): Likewise. (i386_stap_parse_special_token_three_arg_disp): Likewise. * i386obsd-tdep.c (i386obsd_sigtramp_p): Likewise. * inf-child.c (inf_child_fileio_readlink): Likewise. * inf-ptrace.c (inf_ptrace_fetch_register): Likewise. (inf_ptrace_store_register): Likewise. * infrun.c (follow_exec): Likewise. (displaced_step_prepare_throw): Likewise. (save_stop_context): Likewise. (save_infcall_suspend_state): Likewise. * jit.c (jit_read_descriptor): Likewise. (jit_read_code_entry): Likewise. (jit_symtab_line_mapping_add_impl): Likewise. (finalize_symtab): Likewise. (jit_unwind_reg_get_impl): Likewise. * jv-exp.y (QualifiedName): Likewise. * jv-lang.c (get_java_utf8_name): Likewise. (type_from_class): Likewise. (java_demangle_type_signature): Likewise. (java_class_name_from_physname): Likewise. * jv-typeprint.c (java_type_print_base): Likewise. * jv-valprint.c (java_value_print): Likewise. * language.c (add_language): Likewise. * linespec.c (add_sal_to_sals_basic): Likewise. (add_sal_to_sals): Likewise. (decode_objc): Likewise. (find_linespec_symbols): Likewise. * linux-fork.c (fork_save_infrun_state): Likewise. * linux-nat.c (linux_nat_detach): Likewise. (linux_nat_fileio_readlink): Likewise. * linux-record.c (record_linux_sockaddr): Likewise. (record_linux_msghdr): Likewise. (Do): Likewise. * linux-tdep.c (linux_core_info_proc_mappings): Likewise. (linux_collect_regset_section_cb): Likewise. (linux_get_siginfo_data): Likewise. * linux-thread-db.c (try_thread_db_load_from_pdir_1): Likewise. (try_thread_db_load_from_dir): Likewise. (thread_db_load_search): Likewise. (info_auto_load_libthread_db): Likewise. * m32c-tdep.c (m32c_m16c_address_to_pointer): Likewise. (m32c_m16c_pointer_to_address): Likewise. * m68hc11-tdep.c (m68hc11_pseudo_register_write): Likewise. * m68k-tdep.c (m68k_get_longjmp_target): Likewise. * machoread.c (macho_check_dsym): Likewise. * macroexp.c (resize_buffer): Likewise. (gather_arguments): Likewise. (maybe_expand): Likewise. * macrotab.c (new_macro_key): Likewise. (new_source_file): Likewise. (new_macro_definition): Likewise. * mdebugread.c (parse_symbol): Likewise. (parse_type): Likewise. (parse_partial_symbols): Likewise. (psymtab_to_symtab_1): Likewise. * mem-break.c (default_memory_insert_breakpoint): Likewise. * mi/mi-cmd-break.c (mi_argv_to_format): Likewise. * mi/mi-main.c (mi_cmd_data_read_memory): Likewise. (mi_cmd_data_read_memory_bytes): Likewise. (mi_cmd_data_write_memory_bytes): Likewise. (mi_cmd_trace_frame_collected): Likewise. * mi/mi-parse.c (mi_parse_argv): Likewise. (mi_parse): Likewise. * minidebug.c (lzma_open): Likewise. (lzma_pread): Likewise. * mips-tdep.c (mips_read_fp_register_single): Likewise. (mips_print_fp_register): Likewise. * mipsnbsd-tdep.c (mipsnbsd_get_longjmp_target): Likewise. * mipsread.c (read_alphacoff_dynamic_symtab): Likewise. * mt-tdep.c (mt_register_name): Likewise. (mt_registers_info): Likewise. (mt_push_dummy_call): Likewise. * namespace.c (add_using_directive): Likewise. * nat/linux-btrace.c (perf_event_read): Likewise. (linux_enable_bts): Likewise. * nat/linux-osdata.c (linux_common_core_of_thread): Likewise. * nat/linux-ptrace.c (linux_ptrace_test_ret_to_nx): Likewise. * nto-tdep.c (nto_find_and_open_solib): Likewise. (nto_parse_redirection): Likewise. * objc-lang.c (objc_demangle): Likewise. (find_methods): Likewise. * objfiles.c (get_objfile_bfd_data): Likewise. (set_objfile_main_name): Likewise. (allocate_objfile): Likewise. (objfile_relocate): Likewise. (update_section_map): Likewise. * osabi.c (generic_elf_osabi_sniff_abi_tag_sections): Likewise. * p-exp.y (exp): Likewise. (yylex): Likewise. * p-valprint.c (pascal_object_print_value): Likewise. * parse.c (initialize_expout): Likewise. (mark_completion_tag): Likewise. (copy_name): Likewise. (parse_float): Likewise. (type_stack_reserve): Likewise. * ppc-linux-tdep.c (ppc_stap_parse_special_token): Likewise. (ppu2spu_prev_register): Likewise. * ppc-ravenscar-thread.c (supply_register_at_address): Likewise. * printcmd.c (printf_wide_c_string): Likewise. (printf_pointer): Likewise. * probe.c (parse_probes): Likewise. * python/py-cmd.c (gdbpy_parse_command_name): Likewise. (cmdpy_init): Likewise. * python/py-gdb-readline.c (gdbpy_readline_wrapper): Likewise. * python/py-symtab.c (set_sal): Likewise. * python/py-unwind.c (pyuw_sniffer): Likewise. * python/python.c (python_interactive_command): Likewise. (compute_python_string): Likewise. * ravenscar-thread.c (get_running_thread_id): Likewise. * record-full.c (record_full_exec_insn): Likewise. (record_full_core_open_1): Likewise. * regcache.c (regcache_raw_read_signed): Likewise. (regcache_raw_read_unsigned): Likewise. (regcache_cooked_read_signed): Likewise. (regcache_cooked_read_unsigned): Likewise. * remote-fileio.c (remote_fileio_func_open): Likewise. (remote_fileio_func_rename): Likewise. (remote_fileio_func_unlink): Likewise. (remote_fileio_func_stat): Likewise. (remote_fileio_func_system): Likewise. * remote-mips.c (mips_xfer_memory): Likewise. (mips_load_srec): Likewise. (pmon_end_download): Likewise. * remote.c (new_remote_state): Likewise. (map_regcache_remote_table): Likewise. (remote_register_number_and_offset): Likewise. (init_remote_state): Likewise. (get_memory_packet_size): Likewise. (remote_pass_signals): Likewise. (remote_program_signals): Likewise. (remote_start_remote): Likewise. (remote_check_symbols): Likewise. (remote_query_supported): Likewise. (extended_remote_attach): Likewise. (process_g_packet): Likewise. (store_registers_using_G): Likewise. (putpkt_binary): Likewise. (read_frame): Likewise. (compare_sections_command): Likewise. (remote_hostio_pread): Likewise. (remote_hostio_readlink): Likewise. (remote_file_put): Likewise. (remote_file_get): Likewise. (remote_pid_to_exec_file): Likewise. (_initialize_remote): Likewise. * rs6000-aix-tdep.c (rs6000_aix_ld_info_to_xml): Likewise. (rs6000_aix_core_xfer_shared_libraries_aix): Likewise. * rs6000-tdep.c (ppc_displaced_step_copy_insn): Likewise. (bfd_uses_spe_extensions): Likewise. * s390-linux-tdep.c (s390_displaced_step_copy_insn): Likewise. * score-tdep.c (score7_malloc_and_get_memblock): Likewise. * solib-dsbt.c (decode_loadmap): Likewise. (fetch_loadmap): Likewise. (scan_dyntag): Likewise. (enable_break): Likewise. (dsbt_relocate_main_executable): Likewise. * solib-frv.c (fetch_loadmap): Likewise. (enable_break2): Likewise. (frv_relocate_main_executable): Likewise. * solib-spu.c (spu_relocate_main_executable): Likewise. (spu_bfd_open): Likewise. * solib-svr4.c (lm_info_read): Likewise. (read_program_header): Likewise. (find_program_interpreter): Likewise. (scan_dyntag): Likewise. (elf_locate_base): Likewise. (open_symbol_file_object): Likewise. (read_program_headers_from_bfd): Likewise. (svr4_relocate_main_executable): Likewise. * solib-target.c (solib_target_relocate_section_addresses): Likewise. * solib.c (solib_find_1): Likewise. (exec_file_find): Likewise. (solib_find): Likewise. * source.c (openp): Likewise. (print_source_lines_base): Likewise. (forward_search_command): Likewise. * sparc-ravenscar-thread.c (supply_register_at_address): Likewise. * spu-tdep.c (spu2ppu_prev_register): Likewise. (spu_get_overlay_table): Likewise. * stabsread.c (patch_block_stabs): Likewise. (define_symbol): Likewise. (again:): Likewise. (read_member_functions): Likewise. (read_one_struct_field): Likewise. (read_enum_type): Likewise. (common_block_start): Likewise. * stack.c (read_frame_arg): Likewise. (backtrace_command): Likewise. * stap-probe.c (stap_parse_register_operand): Likewise. * symfile.c (syms_from_objfile_1): Likewise. (find_separate_debug_file): Likewise. (load_command): Likewise. (load_progress): Likewise. (load_section_callback): Likewise. (reread_symbols): Likewise. (add_filename_language): Likewise. (allocate_compunit_symtab): Likewise. (read_target_long_array): Likewise. (simple_read_overlay_table): Likewise. * symtab.c (symbol_set_names): Likewise. (resize_symbol_cache): Likewise. (rbreak_command): Likewise. (completion_list_add_name): Likewise. (completion_list_objc_symbol): Likewise. (add_filename_to_list): Likewise. * target-descriptions.c (maint_print_c_tdesc_cmd): Likewise. * target-memory.c (target_write_memory_blocks): Likewise. * target.c (target_read_string): Likewise. (read_whatever_is_readable): Likewise. (target_read_alloc_1): Likewise. (simple_search_memory): Likewise. (target_fileio_read_alloc_1): Likewise. * tilegx-tdep.c (tilegx_push_dummy_call): Likewise. * top.c (command_line_input): Likewise. * tracefile-tfile.c (tfile_fetch_registers): Likewise. * tracefile.c (tracefile_fetch_registers): Likewise. * tracepoint.c (add_memrange): Likewise. (init_collection_list): Likewise. (add_aexpr): Likewise. (trace_dump_actions): Likewise. (parse_trace_status): Likewise. (parse_tracepoint_definition): Likewise. (parse_tsv_definition): Likewise. (parse_static_tracepoint_marker_definition): Likewise. * tui/tui-file.c (tui_sfileopen): Likewise. (tui_file_adjust_strbuf): Likewise. * tui/tui-io.c (tui_expand_tabs): Likewise. * tui/tui-source.c (tui_set_source_content): Likewise. * typeprint.c (find_global_typedef): Likewise. * ui-file.c (do_ui_file_xstrdup): Likewise. (ui_file_obsavestring): Likewise. (mem_file_write): Likewise. * utils.c (make_hex_string): Likewise. (get_regcomp_error): Likewise. (puts_filtered_tabular): Likewise. (gdb_realpath_keepfile): Likewise. (ldirname): Likewise. (gdb_bfd_errmsg): Likewise. (substitute_path_component): Likewise. * valops.c (search_struct_method): Likewise. (find_oload_champ_namespace_loop): Likewise. * valprint.c (print_decimal_chars): Likewise. (read_string): Likewise. (generic_emit_char): Likewise. * varobj.c (varobj_delete): Likewise. (varobj_value_get_print_value): Likewise. * vaxobsd-tdep.c (vaxobsd_sigtramp_sniffer): Likewise. * windows-tdep.c (display_one_tib): Likewise. * xcoffread.c (read_xcoff_symtab): Likewise. (process_xcoff_symbol): Likewise. (swap_sym): Likewise. (scan_xcoff_symtab): Likewise. (xcoff_initial_scan): Likewise. * xml-support.c (gdb_xml_end_element): Likewise. (xml_process_xincludes): Likewise. (xml_fetch_content_from_file): Likewise. * xml-syscall.c (xml_list_of_syscalls): Likewise. * xstormy16-tdep.c (xstormy16_push_dummy_call): Likewise. gdb/gdbserver/ChangeLog: * ax.c (gdb_parse_agent_expr): Add cast to allocation result assignment. (gdb_unparse_agent_expr): Likewise. * hostio.c (require_data): Likewise. (handle_pread): Likewise. * linux-low.c (disable_regset): Likewise. (fetch_register): Likewise. (store_register): Likewise. (get_dynamic): Likewise. (linux_qxfer_libraries_svr4): Likewise. * mem-break.c (delete_fast_tracepoint_jump): Likewise. (set_fast_tracepoint_jump): Likewise. (uninsert_fast_tracepoint_jumps_at): Likewise. (reinsert_fast_tracepoint_jumps_at): Likewise. (validate_inserted_breakpoint): Likewise. (clone_agent_expr): Likewise. * regcache.c (init_register_cache): Likewise. * remote-utils.c (putpkt_binary_1): Likewise. (decode_M_packet): Likewise. (decode_X_packet): Likewise. (look_up_one_symbol): Likewise. (relocate_instruction): Likewise. (monitor_output): Likewise. * server.c (handle_search_memory): Likewise. (handle_qxfer_exec_file): Likewise. (handle_qxfer_libraries): Likewise. (handle_qxfer): Likewise. (handle_query): Likewise. (handle_v_cont): Likewise. (handle_v_run): Likewise. (captured_main): Likewise. * target.c (write_inferior_memory): Likewise. * thread-db.c (try_thread_db_load_from_dir): Likewise. * tracepoint.c (init_trace_buffer): Likewise. (add_tracepoint_action): Likewise. (add_traceframe): Likewise. (add_traceframe_block): Likewise. (cmd_qtdpsrc): Likewise. (cmd_qtdv): Likewise. (cmd_qtstatus): Likewise. (response_source): Likewise. (response_tsv): Likewise. (cmd_qtnotes): Likewise. (gdb_collect): Likewise. (initialize_tracepoint): Likewise.
2015-09-25 20:08:06 +02:00
the_namespace = (char *) alloca (prefix_len + 1);
strncpy (the_namespace, type_name, prefix_len);
the_namespace[prefix_len] = '\0';
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
add_symbol_overload_list_namespace (func_name, the_namespace,
overload_list);
}
/* Check public base type */
if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
{
if (BASETYPE_VIA_PUBLIC (type, i))
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
add_symbol_overload_list_adl_namespace (TYPE_BASECLASS (type, i),
func_name,
overload_list);
}
}
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
/* Adds to OVERLOAD_LIST the overload list overload candidates for
FUNC_NAME found through argument dependent lookup. */
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
void
add_symbol_overload_list_adl (gdb::array_view<type *> arg_types,
const char *func_name,
std::vector<symbol *> *overload_list)
{
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
for (type *arg_type : arg_types)
add_symbol_overload_list_adl_namespace (arg_type, func_name,
overload_list);
}
/* This applies the using directives to add namespaces to search in,
and then searches for overloads in all of those namespaces. It
adds the symbols found to sym_return_val. Arguments are as in
make_symbol_overload_list. */
static void
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
add_symbol_overload_list_using (const char *func_name,
const char *the_namespace,
std::vector<symbol *> *overload_list)
{
struct using_direct *current;
const struct block *block;
/* First, go through the using directives. If any of them apply,
look in the appropriate namespaces for new functions to match
on. */
for (block = get_selected_block (0);
block != NULL;
block = BLOCK_SUPERBLOCK (block))
for (current = block_using (block);
current != NULL;
current = current->next)
{
/* Prevent recursive calls. */
if (current->searched)
continue;
/* If this is a namespace alias or imported declaration ignore
it. */
if (current->alias != NULL || current->declaration != NULL)
continue;
if (strcmp (the_namespace, current->import_dest) == 0)
{
/* Mark this import as searched so that the recursive call
does not search it again. */
scoped_restore reset_directive_searched
= make_scoped_restore (&current->searched, 1);
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
add_symbol_overload_list_using (func_name,
current->import_src,
overload_list);
}
}
/* Now, add names for this namespace. */
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
add_symbol_overload_list_namespace (func_name, the_namespace,
overload_list);
}
/* This does the bulk of the work of finding overloaded symbols.
FUNC_NAME is the name of the overloaded function we're looking for
(possibly including namespace info). */
static void
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
add_symbol_overload_list_qualified (const char *func_name,
std::vector<symbol *> *overload_list)
{
const struct block *b, *surrounding_static_block = 0;
/* Look through the partial symtabs for all symbols which begin by
matching FUNC_NAME. Make sure we read that symbol table in. */
Change all_objfiles adapter to be a method on program_space This changes the all_objfiles range adapter to be a method on the program space, and fixes up all the users. gdb/ChangeLog 2019-01-17 Tom Tromey <tom@tromey.com> * progspace.h (program_space) <objfiles_range>: New typedef. <objfiles>: New method. <objfiles_head>: Rename from objfiles. (object_files): Update. * guile/scm-progspace.c (gdbscm_progspace_objfiles): Update. * guile/scm-pretty-print.c (ppscm_find_pretty_printer_from_objfiles): Update. * guile/scm-objfile.c (gdbscm_objfiles): Update. * python/py-xmethods.c (gdbpy_get_matching_xmethod_workers): Update. * python/py-progspace.c (pspy_get_objfiles): Update. * python/py-prettyprint.c (find_pretty_printer_from_objfiles): Update. * python/py-objfile.c (objfpy_lookup_objfile_by_name) (objfpy_lookup_objfile_by_build_id): Update. * mi/mi-cmd-file.c (mi_cmd_file_list_exec_source_files): Update. * windows-tdep.c (windows_iterate_over_objfiles_in_search_order): Update. * symtab.c (iterate_over_symtabs, matching_obj_sections) (expand_symtab_containing_pc, lookup_objfile_from_block) (lookup_static_symbol, basic_lookup_transparent_type) (find_pc_sect_compunit_symtab, find_symbol_at_address) (find_line_symtab, info_sources_command) (default_collect_symbol_completion_matches_break_on) (make_source_files_completion_list, find_main_name): Update. * symmisc.c (print_symbol_bcache_statistics) (print_objfile_statistics, maintenance_print_symbols) (maintenance_print_msymbols, maintenance_print_objfiles) (maintenance_info_symtabs, maintenance_check_symtabs) (maintenance_expand_symtabs, maintenance_info_line_tables): Update. * symfile.c (remove_symbol_file_command, overlay_invalidate_all) (find_pc_overlay, find_pc_mapped_section, list_overlays_command) (map_overlay_command, unmap_overlay_command) (simple_overlay_update, expand_symtabs_matching) (map_symbol_filenames): Update. * symfile-debug.c (set_debug_symfile): Update. * spu-tdep.c (spu_overlay_update, spu_objfile_from_frame): Update. * source.c (select_source_symtab, forget_cached_source_info): Update. * solib.c (solib_read_symbols): Update. * solib-spu.c (append_ocl_sos): Update. * psymtab.c (maintenance_print_psymbols) (maintenance_info_psymtabs, maintenance_check_psymtabs): Update. * probe.c (parse_probes_in_pspace, find_probe_by_pc): Update. * printcmd.c (info_symbol_command): Update. * ppc-linux-tdep.c (ppc_linux_spe_context_inferior_created): Update. * objfiles.h (class all_objfiles): Remove. * objfiles.c (have_partial_symbols, have_full_symbols) (have_minimal_symbols, qsort_cmp, update_section_map) (shared_objfile_contains_address_p) (default_iterate_over_objfiles_in_search_order): Update. * objc-lang.c (info_selectors_command, info_classes_command) (find_methods): Update. * minsyms.c (find_solib_trampoline_target): Update. * maint.c (maintenance_info_sections) (maintenance_translate_address, count_symtabs_and_blocks): Update. * main.c (captured_main_1): Update. * linux-thread-db.c (try_thread_db_load_from_pdir) (has_libpthread): Update. * linespec.c (iterate_over_all_matching_symtabs) (search_minsyms_for_name): Update. * jit.c (jit_find_objf_with_entry_addr): Update. * hppa-tdep.c (find_unwind_entry) (hppa_lookup_stub_minimal_symbol): Update. * gcore.c (gcore_create_callback, objfile_find_memory_regions): Update. * elfread.c (elf_gnu_ifunc_resolve_by_cache) (elf_gnu_ifunc_resolve_by_got): Update. * dwarf2-frame.c (dwarf2_frame_find_fde): Update. * dwarf-index-write.c (save_gdb_index_command): Update. * cp-support.c (add_symbol_overload_list_qualified): Update. * breakpoint.c (create_overlay_event_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint): Update. * blockframe.c (find_pc_partial_function): Update. * ada-lang.c (ada_lookup_simple_minsym, add_nonlocal_symbols) (ada_collect_symbol_completion_matches) (ada_add_global_exceptions): Update.
2019-01-16 00:55:05 +01:00
for (objfile *objf : current_program_space->objfiles ())
Remove most uses of ALL_OBJFILES This removes most uses of ALL_OBJFILES, replacing them with ranged for loops. The remaining uses are all in macros, and will be removed in subsequent patches. gdb/ChangeLog 2019-01-09 Tom Tromey <tom@tromey.com> * symtab.c (iterate_over_symtabs, matching_obj_sections) (expand_symtab_containing_pc, lookup_static_symbol) (basic_lookup_transparent_type, find_pc_sect_compunit_symtab) (find_symbol_at_address, find_line_symtab, find_main_name): Use all_objfiles. * probe.c (find_probe_by_pc, collect_probes): Use all_objfiles. * breakpoint.c (create_overlay_event_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint): Use all_objfiles. * linux-thread-db.c (try_thread_db_load_from_pdir) (has_libpthread): Use all_objfiles. * ada-lang.c (add_nonlocal_symbols): Use all_objfiles. * linespec.c (iterate_over_all_matching_symtabs) (search_minsyms_for_name): Use all_objfiles. * maint.c (maintenance_info_sections): Use all_objfiles. * main.c (captured_main_1): Use all_objfiles. * spu-tdep.c (spu_objfile_from_frame): Use all_objfiles. * guile/scm-objfile.c (gdbscm_objfiles): Use all_objfiles. * guile/scm-pretty-print.c (ppscm_find_pretty_printer_from_objfiles): Use all_objfiles. * solib-spu.c (append_ocl_sos): Use all_objfiles. * symmisc.c (maintenance_print_symbols): Use all_objfiles. (maintenance_print_msymbols): Use all_objfiles. * source.c (select_source_symtab): Use all_objfiles. * jit.c (jit_find_objf_with_entry_addr): Use all_objfiles. * symfile.c (remove_symbol_file_command) (expand_symtabs_matching, map_symbol_filenames): Use all_objfiles. * ppc-linux-tdep.c (ppc_linux_spe_context_inferior_created): Use all_objfiles. * dwarf2-frame.c (dwarf2_frame_find_fde): Use all_objfiles. * objc-lang.c (find_methods): Use all_objfiles. * objfiles.c (have_partial_symbols, have_full_symbols) (have_minimal_symbols, qsort_cmp) (default_iterate_over_objfiles_in_search_order): Use all_objfiles. * hppa-tdep.c (find_unwind_entry): Use all_objfiles. * psymtab.c (maintenance_print_psymbols): Use all_objfiles. (maintenance_check_psymtabs): Use all_objfiles. (ALL_PSYMTABS): Remove. * compile/compile-object-run.c (do_module_cleanup): Use all_objfiles. * blockframe.c (find_pc_partial_function): Use all_objfiles. * cp-support.c (add_symbol_overload_list_qualified): Use all_objfiles. * windows-tdep.c (windows_iterate_over_objfiles_in_search_order): Use all_objfiles. * dwarf-index-write.c (save_gdb_index_command): Use all_objfiles. * python/py-xmethods.c (gdbpy_get_matching_xmethod_workers): Use all_objfiles. * python/py-objfile.c (objfpy_lookup_objfile_by_name) (objfpy_lookup_objfile_by_build_id): Use all_objfiles. * python/py-prettyprint.c (find_pretty_printer_from_objfiles): Uses all_objfiles. * solib.c (solib_read_symbols): Use all_objfiles
2018-11-23 20:20:05 +01:00
{
if (objf->sf)
objf->sf->qf->expand_symtabs_for_function (objf, func_name);
}
/* Search upwards from currently selected frame (so that we can
complete on local vars. */
for (b = get_selected_block (0); b != NULL; b = BLOCK_SUPERBLOCK (b))
Eliminate make_symbol_overload_list-related globals & cleanup This gets rid of a few globals and a cleanup. make_symbol_overload_list & friends currently maintain a global open-coded vector. Reimplement that with a std::vector, trickled down through the functions. Rename a few functions from "make_" to "add_" for clarity. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * cp-support.c (sym_return_val_size, sym_return_val_index) (sym_return_val): Delete. (overload_list_add_symbol): Add std::vector parameter. Adjust to add to the vector. (make_symbol_overload_list): Adjust to return a std::vector instead of maintaining a global open coded vector. (make_symbol_overload_list_block): Add std::vector parameter. (make_symbol_overload_list_block): Rename to ... (add_symbol_overload_list_block): ... this and add std::vector parameter. (make_symbol_overload_list_namespace): Rename to ... (add_symbol_overload_list_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl_namespace): Rename to ... (add_symbol_overload_list_adl_namespace): ... this and add std::vector parameter. (make_symbol_overload_list_adl): Delete. (add_symbol_overload_list_adl): New. (make_symbol_overload_list_using): Rename to ... (add_symbol_overload_list_using): ... this and add std::vector parameter. (make_symbol_overload_list_qualified): Rename to ... (add_symbol_overload_list_qualified): ... this and add std::vector parameter. * cp-support.h: Include "common/array-view.h" and <vector>. (make_symbol_overload_list): Change return type to std::vector. (make_symbol_overload_list_adl): Delete declaration. (add_symbol_overload_list_adl): New declaration. * valops.c (find_overload_match): Local 'oload_syms' now a std::vector. (find_oload_champ_namespace): 'oload_syms' parameter now a std::vector pointer. (find_oload_champ_namespace_loop): 'oload_syms' parameter now a std::vector pointer. Adjust to new make_symbol_overload_list interface.
2018-11-21 12:55:13 +01:00
add_symbol_overload_list_block (func_name, b, overload_list);
surrounding_static_block = block_static_block (get_selected_block (0));
/* Go through the symtabs and check the externs and statics for
symbols which match. */
Change all_objfiles adapter to be a method on program_space This changes the all_objfiles range adapter to be a method on the program space, and fixes up all the users. gdb/ChangeLog 2019-01-17 Tom Tromey <tom@tromey.com> * progspace.h (program_space) <objfiles_range>: New typedef. <objfiles>: New method. <objfiles_head>: Rename from objfiles. (object_files): Update. * guile/scm-progspace.c (gdbscm_progspace_objfiles): Update. * guile/scm-pretty-print.c (ppscm_find_pretty_printer_from_objfiles): Update. * guile/scm-objfile.c (gdbscm_objfiles): Update. * python/py-xmethods.c (gdbpy_get_matching_xmethod_workers): Update. * python/py-progspace.c (pspy_get_objfiles): Update. * python/py-prettyprint.c (find_pretty_printer_from_objfiles): Update. * python/py-objfile.c (objfpy_lookup_objfile_by_name) (objfpy_lookup_objfile_by_build_id): Update. * mi/mi-cmd-file.c (mi_cmd_file_list_exec_source_files): Update. * windows-tdep.c (windows_iterate_over_objfiles_in_search_order): Update. * symtab.c (iterate_over_symtabs, matching_obj_sections) (expand_symtab_containing_pc, lookup_objfile_from_block) (lookup_static_symbol, basic_lookup_transparent_type) (find_pc_sect_compunit_symtab, find_symbol_at_address) (find_line_symtab, info_sources_command) (default_collect_symbol_completion_matches_break_on) (make_source_files_completion_list, find_main_name): Update. * symmisc.c (print_symbol_bcache_statistics) (print_objfile_statistics, maintenance_print_symbols) (maintenance_print_msymbols, maintenance_print_objfiles) (maintenance_info_symtabs, maintenance_check_symtabs) (maintenance_expand_symtabs, maintenance_info_line_tables): Update. * symfile.c (remove_symbol_file_command, overlay_invalidate_all) (find_pc_overlay, find_pc_mapped_section, list_overlays_command) (map_overlay_command, unmap_overlay_command) (simple_overlay_update, expand_symtabs_matching) (map_symbol_filenames): Update. * symfile-debug.c (set_debug_symfile): Update. * spu-tdep.c (spu_overlay_update, spu_objfile_from_frame): Update. * source.c (select_source_symtab, forget_cached_source_info): Update. * solib.c (solib_read_symbols): Update. * solib-spu.c (append_ocl_sos): Update. * psymtab.c (maintenance_print_psymbols) (maintenance_info_psymtabs, maintenance_check_psymtabs): Update. * probe.c (parse_probes_in_pspace, find_probe_by_pc): Update. * printcmd.c (info_symbol_command): Update. * ppc-linux-tdep.c (ppc_linux_spe_context_inferior_created): Update. * objfiles.h (class all_objfiles): Remove. * objfiles.c (have_partial_symbols, have_full_symbols) (have_minimal_symbols, qsort_cmp, update_section_map) (shared_objfile_contains_address_p) (default_iterate_over_objfiles_in_search_order): Update. * objc-lang.c (info_selectors_command, info_classes_command) (find_methods): Update. * minsyms.c (find_solib_trampoline_target): Update. * maint.c (maintenance_info_sections) (maintenance_translate_address, count_symtabs_and_blocks): Update. * main.c (captured_main_1): Update. * linux-thread-db.c (try_thread_db_load_from_pdir) (has_libpthread): Update. * linespec.c (iterate_over_all_matching_symtabs) (search_minsyms_for_name): Update. * jit.c (jit_find_objf_with_entry_addr): Update. * hppa-tdep.c (find_unwind_entry) (hppa_lookup_stub_minimal_symbol): Update. * gcore.c (gcore_create_callback, objfile_find_memory_regions): Update. * elfread.c (elf_gnu_ifunc_resolve_by_cache) (elf_gnu_ifunc_resolve_by_got): Update. * dwarf2-frame.c (dwarf2_frame_find_fde): Update. * dwarf-index-write.c (save_gdb_index_command): Update. * cp-support.c (add_symbol_overload_list_qualified): Update. * breakpoint.c (create_overlay_event_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint): Update. * blockframe.c (find_pc_partial_function): Update. * ada-lang.c (ada_lookup_simple_minsym, add_nonlocal_symbols) (ada_collect_symbol_completion_matches) (ada_add_global_exceptions): Update.
2019-01-16 00:55:05 +01:00
for (objfile *objfile : current_program_space->objfiles ())
{
for (compunit_symtab *cust : objfile->compunits ())
{
QUIT;
b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), GLOBAL_BLOCK);
add_symbol_overload_list_block (func_name, b, overload_list);
}
}
Change all_objfiles adapter to be a method on program_space This changes the all_objfiles range adapter to be a method on the program space, and fixes up all the users. gdb/ChangeLog 2019-01-17 Tom Tromey <tom@tromey.com> * progspace.h (program_space) <objfiles_range>: New typedef. <objfiles>: New method. <objfiles_head>: Rename from objfiles. (object_files): Update. * guile/scm-progspace.c (gdbscm_progspace_objfiles): Update. * guile/scm-pretty-print.c (ppscm_find_pretty_printer_from_objfiles): Update. * guile/scm-objfile.c (gdbscm_objfiles): Update. * python/py-xmethods.c (gdbpy_get_matching_xmethod_workers): Update. * python/py-progspace.c (pspy_get_objfiles): Update. * python/py-prettyprint.c (find_pretty_printer_from_objfiles): Update. * python/py-objfile.c (objfpy_lookup_objfile_by_name) (objfpy_lookup_objfile_by_build_id): Update. * mi/mi-cmd-file.c (mi_cmd_file_list_exec_source_files): Update. * windows-tdep.c (windows_iterate_over_objfiles_in_search_order): Update. * symtab.c (iterate_over_symtabs, matching_obj_sections) (expand_symtab_containing_pc, lookup_objfile_from_block) (lookup_static_symbol, basic_lookup_transparent_type) (find_pc_sect_compunit_symtab, find_symbol_at_address) (find_line_symtab, info_sources_command) (default_collect_symbol_completion_matches_break_on) (make_source_files_completion_list, find_main_name): Update. * symmisc.c (print_symbol_bcache_statistics) (print_objfile_statistics, maintenance_print_symbols) (maintenance_print_msymbols, maintenance_print_objfiles) (maintenance_info_symtabs, maintenance_check_symtabs) (maintenance_expand_symtabs, maintenance_info_line_tables): Update. * symfile.c (remove_symbol_file_command, overlay_invalidate_all) (find_pc_overlay, find_pc_mapped_section, list_overlays_command) (map_overlay_command, unmap_overlay_command) (simple_overlay_update, expand_symtabs_matching) (map_symbol_filenames): Update. * symfile-debug.c (set_debug_symfile): Update. * spu-tdep.c (spu_overlay_update, spu_objfile_from_frame): Update. * source.c (select_source_symtab, forget_cached_source_info): Update. * solib.c (solib_read_symbols): Update. * solib-spu.c (append_ocl_sos): Update. * psymtab.c (maintenance_print_psymbols) (maintenance_info_psymtabs, maintenance_check_psymtabs): Update. * probe.c (parse_probes_in_pspace, find_probe_by_pc): Update. * printcmd.c (info_symbol_command): Update. * ppc-linux-tdep.c (ppc_linux_spe_context_inferior_created): Update. * objfiles.h (class all_objfiles): Remove. * objfiles.c (have_partial_symbols, have_full_symbols) (have_minimal_symbols, qsort_cmp, update_section_map) (shared_objfile_contains_address_p) (default_iterate_over_objfiles_in_search_order): Update. * objc-lang.c (info_selectors_command, info_classes_command) (find_methods): Update. * minsyms.c (find_solib_trampoline_target): Update. * maint.c (maintenance_info_sections) (maintenance_translate_address, count_symtabs_and_blocks): Update. * main.c (captured_main_1): Update. * linux-thread-db.c (try_thread_db_load_from_pdir) (has_libpthread): Update. * linespec.c (iterate_over_all_matching_symtabs) (search_minsyms_for_name): Update. * jit.c (jit_find_objf_with_entry_addr): Update. * hppa-tdep.c (find_unwind_entry) (hppa_lookup_stub_minimal_symbol): Update. * gcore.c (gcore_create_callback, objfile_find_memory_regions): Update. * elfread.c (elf_gnu_ifunc_resolve_by_cache) (elf_gnu_ifunc_resolve_by_got): Update. * dwarf2-frame.c (dwarf2_frame_find_fde): Update. * dwarf-index-write.c (save_gdb_index_command): Update. * cp-support.c (add_symbol_overload_list_qualified): Update. * breakpoint.c (create_overlay_event_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint): Update. * blockframe.c (find_pc_partial_function): Update. * ada-lang.c (ada_lookup_simple_minsym, add_nonlocal_symbols) (ada_collect_symbol_completion_matches) (ada_add_global_exceptions): Update.
2019-01-16 00:55:05 +01:00
for (objfile *objfile : current_program_space->objfiles ())
{
for (compunit_symtab *cust : objfile->compunits ())
{
QUIT;
b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), STATIC_BLOCK);
/* Don't do this block twice. */
if (b == surrounding_static_block)
continue;
add_symbol_overload_list_block (func_name, b, overload_list);
}
}
}
/* Lookup the rtti type for a class name. */
struct type *
More block constification I noticed that there are still many places referring to non-const blocks. This constifies all the remaining ones that I found that could be constified. In a few spots, this search found unused variables or fields. I removed these. I've also removed some unnecessary casts to "struct block *". gdb/ChangeLog 2019-03-24 Tom Tromey <tom@tromey.com> * c-exp.y (typebase): Remove casts. * gdbtypes.c (lookup_unsigned_typename, ) (lookup_signed_typename): Remove cast. * eval.c (parse_to_comma_and_eval): Remove cast. * parse.c (write_dollar_variable): Remove cast. * block.h (struct block) <superblock>: Now const. * symfile-debug.c (debug_qf_map_matching_symbols): Update. * psymtab.c (psym_map_matching_symbols): Make "block" const. (map_block): Make "block" const. * symfile.h (struct quick_symbol_functions) <map_matching_symbols>: Constify block argument to "callback". * symtab.c (basic_lookup_transparent_type_quick): Make "block" const. (find_pc_sect_compunit_symtab): Make "b" const. (find_symbol_at_address): Likewise. (search_symbols): Likewise. * dwarf2read.c (dw2_lookup_symbol): Make "block" const. (dw2_debug_names_lookup_symbol): Likewise. (dw2_map_matching_symbols): Update. * p-valprint.c (pascal_val_print): Remove "block". * ada-lang.c (ada_add_global_exceptions): Make "b" const. (aux_add_nonlocal_symbols): Make "block" const. (resolve_subexp): Remove cast. * linespec.c (iterate_over_all_matching_symtabs): Make "block" const. (iterate_over_file_blocks): Likewise. * f-exp.y (%union) <bval>: Remove. * coffread.c (patch_opaque_types): Make "b" const. * spu-tdep.c (spu_catch_start): Make "block" const. * c-valprint.c (print_unpacked_pointer): Remove "block". * symmisc.c (dump_symtab_1): Make "b" const. (block_depth): Make "block" const. * d-exp.y (%union) <bval>: Remove. * cp-support.h (cp_lookup_rtti_type): Update. * cp-support.c (cp_lookup_rtti_type): Make "block" const. * psymtab.c (psym_lookup_symbol): Make "block" const. (maintenance_check_psymtabs): Make "b" const. * python/py-framefilter.c (extract_sym): Make "sym_block" const. (enumerate_locals, enumerate_args): Update. * python/py-symtab.c (stpy_global_block): Make "block" const. (stpy_static_block): Likewise. * inline-frame.c (block_starting_point_at): Make "new_block" const. * block.c (find_block_in_blockvector): Make return type const. (blockvector_for_pc_sect): Make "b" const. (find_block_in_blockvector): Make "b" const.
2019-03-22 22:54:10 +01:00
cp_lookup_rtti_type (const char *name, const struct block *block)
{
struct symbol * rtti_sym;
struct type * rtti_type;
/* Use VAR_DOMAIN here as NAME may be a typedef. PR 18141, 18417.
Classes "live" in both STRUCT_DOMAIN and VAR_DOMAIN. */
Replace the block_found global with explicit data-flow As Pedro suggested on gdb-patches@ (see https://sourceware.org/ml/gdb-patches/2015-05/msg00714.html), this change makes symbol lookup functions return a structure that includes both the symbol found and the block in which it was found. This makes it possible to get rid of the block_found global variable and thus makes block hunting explicit. gdb/ * ada-exp.y (write_object_renaming): Replace struct ada_symbol_info with struct block_symbol. Update field references accordingly. (block_lookup, select_possible_type_sym): Likewise. (find_primitive_type): Likewise. Also update call to ada_lookup_symbol to extract the symbol itself. (write_var_or_type, write_name_assoc): Likewise. * ada-lang.h (struct ada_symbol_info): Remove. (ada_lookup_symbol_list): Replace struct ada_symbol_info with struct block_symbol. (ada_lookup_encoded_symbol, user_select_syms): Likewise. (ada_lookup_symbol): Return struct block_symbol instead of a mere symbol. * ada-lang.c (defns_collected): Replace struct ada_symbol_info with struct block_symbol. (resolve_subexp, ada_resolve_function, sort_choices, user_select_syms, is_nonfunction, add_defn_to_vec, num_defns_collected, defns_collected, symbols_are_identical_enums, remove_extra_symbols, remove_irrelevant_renamings, add_lookup_symbol_list_worker, ada_lookup_symbol_list, ada_iterate_over_symbols, ada_lookup_encoded_symbol, get_var_value): Likewise. (ada_lookup_symbol): Return a block_symbol instead of a mere symbol. Replace struct ada_symbol_info with struct block_symbol. (ada_lookup_symbol_nonlocal): Likewise. (standard_lookup): Make block passing explicit through lookup_symbol_in_language. * ada-tasks.c (get_tcb_types_info): Update the calls to lookup_symbol_in_language to extract the mere symbol out of the returned value. (ada_tasks_inferior_data_sniffer): Likewise. * ax-gdb.c (gen_static_field): Likewise for the call to lookup_symbol. (gen_maybe_namespace_elt): Deal with struct symbol_in_block from lookup functions. (gen_expr): Likewise. * c-exp.y: Likewise. Remove uses of block_found. (lex_one_token, classify_inner_name, c_print_token): Likewise. (classify_name): Likewise. Rename the "sym" local variable to "bsym". * c-valprint.c (print_unpacked_pointer): Likewise. * compile/compile-c-symbols.c (convert_symbol_sym): Promote the "sym" parameter from struct symbol * to struct block_symbol. Use it to remove uses of block_found. Deal with struct symbol_in_block from lookup functions. (gcc_convert_symbol): Likewise. Update the call to convert_symbol_sym. * compile/compile-object-load.c (compile_object_load): Deal with struct symbol_in_block from lookup functions. * cp-namespace.c (cp_lookup_nested_symbol_1, cp_lookup_nested_symbol, cp_lookup_bare_symbol, cp_search_static_and_baseclasses, cp_lookup_symbol_in_namespace, cp_lookup_symbol_via_imports, cp_lookup_symbol_imports_or_template, cp_lookup_symbol_via_all_imports, cp_lookup_symbol_namespace, lookup_namespace_scope, cp_lookup_nonlocal, find_symbol_in_baseclass): Return struct symbol_in_block instead of mere symbols and deal with struct symbol_in_block from lookup functions. * cp-support.c (inspect_type, replace_typedefs, cp_lookup_rtti_type): Deal with struct symbol_in_block from lookup functions. * cp-support.h (cp_lookup_symbol_nonlocal, cp_lookup_symbol_from_namespace, cp_lookup_symbol_imports_or_template, cp_lookup_nested_symbol): Return struct symbol_in_block instead of mere symbols. * d-exp.y (d_type_from_name, d_module_from_name, push_variable, push_module_name): Deal with struct symbol_in_block from lookup functions. Remove uses of block_found. * eval.c (evaluate_subexp_standard): Update call to cp_lookup_symbol_namespace. * f-exp.y: Deal with struct symbol_in_block from lookup functions. Remove uses of block_found. (yylex): Likewise. * gdbtypes.c (lookup_typename, lookup_struct, lookup_union, lookup_enum, lookup_template_type, check_typedef): Deal with struct symbol_in_block from lookup functions. * guile/scm-frame.c (gdbscm_frame_read_var): Likewise. * guile/scm-symbol.c (gdbscm_lookup_symbol): Likewise. (gdbscm_lookup_global_symbol): Likewise. * gnu-v3-abi.c (gnuv3_get_typeid_type): Likewise. * go-exp.y: Likewise. Remove uses of block_found. (package_name_p, classify_packaged_name, classify_name): Likewise. * infrun.c (insert_exception_resume_breakpoint): Likewise. * jv-exp.y (push_variable): Likewise. * jv-lang.c (java_lookup_class, get_java_object_type): Likewise. * language.c (language_bool_type): Likewise. * language.h (struct language_defn): Update la_lookup_symbol_nonlocal to return a struct symbol_in_block rather than a mere symbol. * linespec.c (find_label_symbols): Deal with struct symbol_in_block from lookup functions. * m2-exp.y: Likewise. Remove uses of block_found. (yylex): Likewise. * mi/mi-cmd-stack.c (list_args_or_locals): Likewise. * objc-lang.c (lookup_struct_typedef, find_imps): Likewise. * p-exp.y: Likewise. Remove uses of block_found. (yylex): Likewise. * p-valprint.c (pascal_val_print): Likewise. * parse.c (write_dollar_variable): Likewise. Remove uses of block_found. * parser-defs.h (struct symtoken): Turn the SYM field into a struct symbol_in_block. * printcmd.c (address_info): Deal with struct symbol_in_block from lookup functions. * python/py-frame.c (frapy_read_var): Likewise. * python/py-symbol.c (gdbpy_lookup_symbol, gdbpy_lookup_global_symbol): Likewise. * skip.c (skip_function_command): Likewise. * solib-darwin.c (darwin_lookup_lib_symbol): Return a struct symbol_in_block instead of a mere symbol. * solib-spu.c (spu_lookup_lib_symbol): Likewise. * solib-svr4.c (elf_lookup_lib_symbol): Likewise. * solib.c (solib_global_lookup): Likewise. * solist.h (solib_global_lookup): Likewise. (struct target_so_ops): Update lookup_lib_global_symbol to return a struct symbol_in_block rather than a mere symbol. * source.c (select_source_symtab): Deal with struct symbol_in_block from lookup functions. * stack.c (print_frame_args, iterate_over_block_arg_vars): Likewise. * symfile.c (set_initial_language): Likewise. * symtab.c (SYMBOL_LOOKUP_FAILED): Turn into a struct symbol_in_block. (SYMBOL_LOOKUP_FAILED_P): New predicate as a macro. (struct symbol_cache_slot): Turn the FOUND field into a struct symbol_in_block. (block_found): Remove. (eq_symbol_entry): Update to deal with struct symbol_in_block in cache slots. (symbol_cache_lookup): Return a struct symbol_in_block rather than a mere symbol. (symbol_cache_mark_found): Add a BLOCK parameter to fill appropriately the cache slots. Update callers. (symbol_cache_dump): Update cache slots handling to the type change. (lookup_symbol_in_language, lookup_symbol, lookup_language_this, lookup_symbol_aux, lookup_local_symbol, lookup_symbol_in_objfile, lookup_global_symbol_from_objfile, lookup_symbol_in_objfile_symtabs, lookup_symbol_in_objfile_from_linkage_name, lookup_symbol_via_quick_fns, basic_lookup_symbol_nonlocal, lookup_symbol_in_static_block, lookup_static_symbol, lookup_global_symbol): Return a struct symbol_in_block rather than a mere symbol. Deal with struct symbol_in_block from other lookup functions. Remove uses of block_found. (lookup_symbol_in_block): Remove uses of block_found. (struct global_sym_lookup_data): Turn the RESULT field into a struct symbol_in_block. (lookup_symbol_global_iterator_cb): Update references to the RESULT field. (search_symbols): Deal with struct symbol_in_block from lookup functions. * symtab.h (struct symbol_in_block): New structure. (block_found): Remove. (lookup_symbol_in_language, lookup_symbol, basic_lookup_symbol_nonlocal, lookup_symbol_in_static_block, looku_static_symbol, lookup_global_symbol, lookup_symbol_in_block, lookup_language_this, lookup_global_symbol_from_objfile): Return a struct symbol_in_block rather than just a mere symbol. Update comments to remove mentions of block_found. * valops.c (find_function_in_inferior, value_struct_elt_for_reference, value_maybe_namespace_elt, value_of_this): Deal with struct symbol_in_block from lookup functions. * value.c (value_static_field, value_fn_field): Likewise.
2015-07-21 17:02:15 +02:00
rtti_sym = lookup_symbol (name, block, VAR_DOMAIN, NULL).symbol;
if (rtti_sym == NULL)
{
2005-02-10 Andrew Cagney <cagney@gnu.org> Mark up all error and warning messages. * ada-lang.c, amd64-tdep.c, arch-utils.c, breakpoint.c: Update. * bsd-kvm.c, bsd-uthread.c, coff-solib.h, coffread.c: Update. * core-aout.c, core-regset.c, corefile.c, corelow.c: Update. * cp-abi.c, cp-support.c, cp-valprint.c, cris-tdep.c: Update. * dbxread.c, demangle.c, doublest.c, dsrec.c: Update. * dve3900-rom.c, dwarf2expr.c, dwarf2loc.c: Update. * dwarf2read.c, dwarfread.c, elfread.c, eval.c: Update. * event-top.c, exec.c, expprint.c, f-lang.c: Update. * f-typeprint.c, f-valprint.c, fbsd-nat.c, findvar.c: Update. * frame.c, frv-linux-tdep.c, gcore.c, gdbtypes.c: Update. * gnu-nat.c, gnu-v2-abi.c, gnu-v3-abi.c, go32-nat.c: Update. * hpacc-abi.c, hppa-hpux-nat.c, hppa-hpux-tdep.c: Update. * hppa-linux-nat.c, hppa-linux-tdep.c, hppa-tdep.c: Update. * hpread.c, hpux-thread.c, i386-linux-nat.c: Update. * i386-linux-tdep.c, i386-tdep.c, i386bsd-nat.c: Update. * i386gnu-nat.c, i387-tdep.c, ia64-linux-nat.c: Update. * ia64-tdep.c, inf-child.c, inf-ptrace.c, inf-ttrace.c: Update. * infcall.c, infcmd.c, inflow.c, infptrace.c, infrun.c: Update. * inftarg.c, interps.c, irix5-nat.c, jv-lang.c: Update. * kod-cisco.c, kod.c, language.c, libunwind-frame.c: Update. * linespec.c, linux-nat.c, linux-thread-db.c, m2-lang.c: Update. * m32r-rom.c, m68hc11-tdep.c, m68k-tdep.c: Update. * m68klinux-nat.c, macrocmd.c, macroexp.c, main.c: Update. * maint.c, mdebugread.c, mem-break.c, memattr.c: Update. * mips-linux-tdep.c, mips-tdep.c, mipsread.c, monitor.c: Update. * nlmread.c, nto-procfs.c, objc-lang.c, objfiles.c: Update. * observer.c, ocd.c, p-lang.c, p-typeprint.c: Update. * p-valprint.c, pa64solib.c, parse.c, ppc-linux-tdep.c: Update. * ppcnbsd-tdep.c, printcmd.c, procfs.c, remote-e7000.c: Update. * remote-fileio.c, remote-m32r-sdi.c, remote-rdi.c: Update. * remote-rdp.c, remote-sim.c, remote-st.c: Update. * remote-utils.c, remote-utils.h, remote.c: Update. * rom68k-rom.c, rs6000-nat.c, s390-tdep.c, scm-lang.c: Update. * ser-e7kpc.c, ser-tcp.c, ser-unix.c, sh-tdep.c: Update. * sh3-rom.c, shnbsd-tdep.c, sol-thread.c, solib-aix5.c: Update. * solib-frv.c, solib-irix.c, solib-osf.c, solib-pa64.c: Update. * solib-som.c, solib-sunos.c, solib-svr4.c, solib.c: Update. * somread.c, somsolib.c, source.c, stabsread.c: Update. * stack.c, std-regs.c, symfile-mem.c, symfile.c: Update. * symmisc.c, symtab.c, target.c, thread.c, top.c: Update. * tracepoint.c, trad-frame.c, typeprint.c, utils.c: Update. * uw-thread.c, valarith.c, valops.c, valprint.c: Update. * value.c, varobj.c, version.in, win32-nat.c, wince.c: Update. * xcoffread.c, xcoffsolib.c, cli/cli-cmds.c: Update. * cli/cli-decode.c, cli/cli-dump.c, cli/cli-logging.c: Update. * cli/cli-script.c, cli/cli-setshow.c, mi/mi-cmd-break.c: Update. * mi/mi-cmd-disas.c, mi/mi-cmd-env.c, mi/mi-cmd-file.c: Update. * mi/mi-cmd-stack.c, mi/mi-cmd-var.c, mi/mi-getopt.c: Update. * mi/mi-symbol-cmds.c, tui/tui-layout.c, tui/tui-stack.c: Update. * tui/tui-win.c: Update.
2005-02-11 05:06:14 +01:00
warning (_("RTTI symbol not found for class '%s'"), name);
return NULL;
}
if (SYMBOL_CLASS (rtti_sym) != LOC_TYPEDEF)
{
2005-02-10 Andrew Cagney <cagney@gnu.org> Mark up all error and warning messages. * ada-lang.c, amd64-tdep.c, arch-utils.c, breakpoint.c: Update. * bsd-kvm.c, bsd-uthread.c, coff-solib.h, coffread.c: Update. * core-aout.c, core-regset.c, corefile.c, corelow.c: Update. * cp-abi.c, cp-support.c, cp-valprint.c, cris-tdep.c: Update. * dbxread.c, demangle.c, doublest.c, dsrec.c: Update. * dve3900-rom.c, dwarf2expr.c, dwarf2loc.c: Update. * dwarf2read.c, dwarfread.c, elfread.c, eval.c: Update. * event-top.c, exec.c, expprint.c, f-lang.c: Update. * f-typeprint.c, f-valprint.c, fbsd-nat.c, findvar.c: Update. * frame.c, frv-linux-tdep.c, gcore.c, gdbtypes.c: Update. * gnu-nat.c, gnu-v2-abi.c, gnu-v3-abi.c, go32-nat.c: Update. * hpacc-abi.c, hppa-hpux-nat.c, hppa-hpux-tdep.c: Update. * hppa-linux-nat.c, hppa-linux-tdep.c, hppa-tdep.c: Update. * hpread.c, hpux-thread.c, i386-linux-nat.c: Update. * i386-linux-tdep.c, i386-tdep.c, i386bsd-nat.c: Update. * i386gnu-nat.c, i387-tdep.c, ia64-linux-nat.c: Update. * ia64-tdep.c, inf-child.c, inf-ptrace.c, inf-ttrace.c: Update. * infcall.c, infcmd.c, inflow.c, infptrace.c, infrun.c: Update. * inftarg.c, interps.c, irix5-nat.c, jv-lang.c: Update. * kod-cisco.c, kod.c, language.c, libunwind-frame.c: Update. * linespec.c, linux-nat.c, linux-thread-db.c, m2-lang.c: Update. * m32r-rom.c, m68hc11-tdep.c, m68k-tdep.c: Update. * m68klinux-nat.c, macrocmd.c, macroexp.c, main.c: Update. * maint.c, mdebugread.c, mem-break.c, memattr.c: Update. * mips-linux-tdep.c, mips-tdep.c, mipsread.c, monitor.c: Update. * nlmread.c, nto-procfs.c, objc-lang.c, objfiles.c: Update. * observer.c, ocd.c, p-lang.c, p-typeprint.c: Update. * p-valprint.c, pa64solib.c, parse.c, ppc-linux-tdep.c: Update. * ppcnbsd-tdep.c, printcmd.c, procfs.c, remote-e7000.c: Update. * remote-fileio.c, remote-m32r-sdi.c, remote-rdi.c: Update. * remote-rdp.c, remote-sim.c, remote-st.c: Update. * remote-utils.c, remote-utils.h, remote.c: Update. * rom68k-rom.c, rs6000-nat.c, s390-tdep.c, scm-lang.c: Update. * ser-e7kpc.c, ser-tcp.c, ser-unix.c, sh-tdep.c: Update. * sh3-rom.c, shnbsd-tdep.c, sol-thread.c, solib-aix5.c: Update. * solib-frv.c, solib-irix.c, solib-osf.c, solib-pa64.c: Update. * solib-som.c, solib-sunos.c, solib-svr4.c, solib.c: Update. * somread.c, somsolib.c, source.c, stabsread.c: Update. * stack.c, std-regs.c, symfile-mem.c, symfile.c: Update. * symmisc.c, symtab.c, target.c, thread.c, top.c: Update. * tracepoint.c, trad-frame.c, typeprint.c, utils.c: Update. * uw-thread.c, valarith.c, valops.c, valprint.c: Update. * value.c, varobj.c, version.in, win32-nat.c, wince.c: Update. * xcoffread.c, xcoffsolib.c, cli/cli-cmds.c: Update. * cli/cli-decode.c, cli/cli-dump.c, cli/cli-logging.c: Update. * cli/cli-script.c, cli/cli-setshow.c, mi/mi-cmd-break.c: Update. * mi/mi-cmd-disas.c, mi/mi-cmd-env.c, mi/mi-cmd-file.c: Update. * mi/mi-cmd-stack.c, mi/mi-cmd-var.c, mi/mi-getopt.c: Update. * mi/mi-symbol-cmds.c, tui/tui-layout.c, tui/tui-stack.c: Update. * tui/tui-win.c: Update.
2005-02-11 05:06:14 +01:00
warning (_("RTTI symbol for class '%s' is not a type"), name);
return NULL;
}
rtti_type = check_typedef (SYMBOL_TYPE (rtti_sym));
switch (TYPE_CODE (rtti_type))
{
case TYPE_CODE_STRUCT:
break;
case TYPE_CODE_NAMESPACE:
/* chastain/2003-11-26: the symbol tables often contain fake
symbols for namespaces with the same name as the struct.
This warning is an indication of a bug in the lookup order
or a bug in the way that the symbol tables are populated. */
2005-02-10 Andrew Cagney <cagney@gnu.org> Mark up all error and warning messages. * ada-lang.c, amd64-tdep.c, arch-utils.c, breakpoint.c: Update. * bsd-kvm.c, bsd-uthread.c, coff-solib.h, coffread.c: Update. * core-aout.c, core-regset.c, corefile.c, corelow.c: Update. * cp-abi.c, cp-support.c, cp-valprint.c, cris-tdep.c: Update. * dbxread.c, demangle.c, doublest.c, dsrec.c: Update. * dve3900-rom.c, dwarf2expr.c, dwarf2loc.c: Update. * dwarf2read.c, dwarfread.c, elfread.c, eval.c: Update. * event-top.c, exec.c, expprint.c, f-lang.c: Update. * f-typeprint.c, f-valprint.c, fbsd-nat.c, findvar.c: Update. * frame.c, frv-linux-tdep.c, gcore.c, gdbtypes.c: Update. * gnu-nat.c, gnu-v2-abi.c, gnu-v3-abi.c, go32-nat.c: Update. * hpacc-abi.c, hppa-hpux-nat.c, hppa-hpux-tdep.c: Update. * hppa-linux-nat.c, hppa-linux-tdep.c, hppa-tdep.c: Update. * hpread.c, hpux-thread.c, i386-linux-nat.c: Update. * i386-linux-tdep.c, i386-tdep.c, i386bsd-nat.c: Update. * i386gnu-nat.c, i387-tdep.c, ia64-linux-nat.c: Update. * ia64-tdep.c, inf-child.c, inf-ptrace.c, inf-ttrace.c: Update. * infcall.c, infcmd.c, inflow.c, infptrace.c, infrun.c: Update. * inftarg.c, interps.c, irix5-nat.c, jv-lang.c: Update. * kod-cisco.c, kod.c, language.c, libunwind-frame.c: Update. * linespec.c, linux-nat.c, linux-thread-db.c, m2-lang.c: Update. * m32r-rom.c, m68hc11-tdep.c, m68k-tdep.c: Update. * m68klinux-nat.c, macrocmd.c, macroexp.c, main.c: Update. * maint.c, mdebugread.c, mem-break.c, memattr.c: Update. * mips-linux-tdep.c, mips-tdep.c, mipsread.c, monitor.c: Update. * nlmread.c, nto-procfs.c, objc-lang.c, objfiles.c: Update. * observer.c, ocd.c, p-lang.c, p-typeprint.c: Update. * p-valprint.c, pa64solib.c, parse.c, ppc-linux-tdep.c: Update. * ppcnbsd-tdep.c, printcmd.c, procfs.c, remote-e7000.c: Update. * remote-fileio.c, remote-m32r-sdi.c, remote-rdi.c: Update. * remote-rdp.c, remote-sim.c, remote-st.c: Update. * remote-utils.c, remote-utils.h, remote.c: Update. * rom68k-rom.c, rs6000-nat.c, s390-tdep.c, scm-lang.c: Update. * ser-e7kpc.c, ser-tcp.c, ser-unix.c, sh-tdep.c: Update. * sh3-rom.c, shnbsd-tdep.c, sol-thread.c, solib-aix5.c: Update. * solib-frv.c, solib-irix.c, solib-osf.c, solib-pa64.c: Update. * solib-som.c, solib-sunos.c, solib-svr4.c, solib.c: Update. * somread.c, somsolib.c, source.c, stabsread.c: Update. * stack.c, std-regs.c, symfile-mem.c, symfile.c: Update. * symmisc.c, symtab.c, target.c, thread.c, top.c: Update. * tracepoint.c, trad-frame.c, typeprint.c, utils.c: Update. * uw-thread.c, valarith.c, valops.c, valprint.c: Update. * value.c, varobj.c, version.in, win32-nat.c, wince.c: Update. * xcoffread.c, xcoffsolib.c, cli/cli-cmds.c: Update. * cli/cli-decode.c, cli/cli-dump.c, cli/cli-logging.c: Update. * cli/cli-script.c, cli/cli-setshow.c, mi/mi-cmd-break.c: Update. * mi/mi-cmd-disas.c, mi/mi-cmd-env.c, mi/mi-cmd-file.c: Update. * mi/mi-cmd-stack.c, mi/mi-cmd-var.c, mi/mi-getopt.c: Update. * mi/mi-symbol-cmds.c, tui/tui-layout.c, tui/tui-stack.c: Update. * tui/tui-win.c: Update.
2005-02-11 05:06:14 +01:00
warning (_("RTTI symbol for class '%s' is a namespace"), name);
return NULL;
default:
2005-02-10 Andrew Cagney <cagney@gnu.org> Mark up all error and warning messages. * ada-lang.c, amd64-tdep.c, arch-utils.c, breakpoint.c: Update. * bsd-kvm.c, bsd-uthread.c, coff-solib.h, coffread.c: Update. * core-aout.c, core-regset.c, corefile.c, corelow.c: Update. * cp-abi.c, cp-support.c, cp-valprint.c, cris-tdep.c: Update. * dbxread.c, demangle.c, doublest.c, dsrec.c: Update. * dve3900-rom.c, dwarf2expr.c, dwarf2loc.c: Update. * dwarf2read.c, dwarfread.c, elfread.c, eval.c: Update. * event-top.c, exec.c, expprint.c, f-lang.c: Update. * f-typeprint.c, f-valprint.c, fbsd-nat.c, findvar.c: Update. * frame.c, frv-linux-tdep.c, gcore.c, gdbtypes.c: Update. * gnu-nat.c, gnu-v2-abi.c, gnu-v3-abi.c, go32-nat.c: Update. * hpacc-abi.c, hppa-hpux-nat.c, hppa-hpux-tdep.c: Update. * hppa-linux-nat.c, hppa-linux-tdep.c, hppa-tdep.c: Update. * hpread.c, hpux-thread.c, i386-linux-nat.c: Update. * i386-linux-tdep.c, i386-tdep.c, i386bsd-nat.c: Update. * i386gnu-nat.c, i387-tdep.c, ia64-linux-nat.c: Update. * ia64-tdep.c, inf-child.c, inf-ptrace.c, inf-ttrace.c: Update. * infcall.c, infcmd.c, inflow.c, infptrace.c, infrun.c: Update. * inftarg.c, interps.c, irix5-nat.c, jv-lang.c: Update. * kod-cisco.c, kod.c, language.c, libunwind-frame.c: Update. * linespec.c, linux-nat.c, linux-thread-db.c, m2-lang.c: Update. * m32r-rom.c, m68hc11-tdep.c, m68k-tdep.c: Update. * m68klinux-nat.c, macrocmd.c, macroexp.c, main.c: Update. * maint.c, mdebugread.c, mem-break.c, memattr.c: Update. * mips-linux-tdep.c, mips-tdep.c, mipsread.c, monitor.c: Update. * nlmread.c, nto-procfs.c, objc-lang.c, objfiles.c: Update. * observer.c, ocd.c, p-lang.c, p-typeprint.c: Update. * p-valprint.c, pa64solib.c, parse.c, ppc-linux-tdep.c: Update. * ppcnbsd-tdep.c, printcmd.c, procfs.c, remote-e7000.c: Update. * remote-fileio.c, remote-m32r-sdi.c, remote-rdi.c: Update. * remote-rdp.c, remote-sim.c, remote-st.c: Update. * remote-utils.c, remote-utils.h, remote.c: Update. * rom68k-rom.c, rs6000-nat.c, s390-tdep.c, scm-lang.c: Update. * ser-e7kpc.c, ser-tcp.c, ser-unix.c, sh-tdep.c: Update. * sh3-rom.c, shnbsd-tdep.c, sol-thread.c, solib-aix5.c: Update. * solib-frv.c, solib-irix.c, solib-osf.c, solib-pa64.c: Update. * solib-som.c, solib-sunos.c, solib-svr4.c, solib.c: Update. * somread.c, somsolib.c, source.c, stabsread.c: Update. * stack.c, std-regs.c, symfile-mem.c, symfile.c: Update. * symmisc.c, symtab.c, target.c, thread.c, top.c: Update. * tracepoint.c, trad-frame.c, typeprint.c, utils.c: Update. * uw-thread.c, valarith.c, valops.c, valprint.c: Update. * value.c, varobj.c, version.in, win32-nat.c, wince.c: Update. * xcoffread.c, xcoffsolib.c, cli/cli-cmds.c: Update. * cli/cli-decode.c, cli/cli-dump.c, cli/cli-logging.c: Update. * cli/cli-script.c, cli/cli-setshow.c, mi/mi-cmd-break.c: Update. * mi/mi-cmd-disas.c, mi/mi-cmd-env.c, mi/mi-cmd-file.c: Update. * mi/mi-cmd-stack.c, mi/mi-cmd-var.c, mi/mi-getopt.c: Update. * mi/mi-symbol-cmds.c, tui/tui-layout.c, tui/tui-stack.c: Update. * tui/tui-win.c: Update.
2005-02-11 05:06:14 +01:00
warning (_("RTTI symbol for class '%s' has bad type"), name);
return NULL;
}
return rtti_type;
}
#ifdef HAVE_WORKING_FORK
Change boolean options to bool instead of int This is for add_setshow_boolean_cmd as well as the gdb::option interface. gdb/ChangeLog: 2019-09-17 Christian Biesinger <cbiesinger@google.com> * ada-lang.c (ada_ignore_descriptive_types_p): Change to bool. (print_signatures): Likewise. (trust_pad_over_xvs): Likewise. * arch/aarch64-insn.c (aarch64_debug): Likewise. * arch/aarch64-insn.h (aarch64_debug): Likewise. * arm-linux-nat.c (arm_apcs_32): Likewise. * arm-linux-tdep.c (arm_apcs_32): Likewise. * arm-nbsd-nat.c (arm_apcs_32): Likewise. * arm-tdep.c (arm_debug): Likewise. (arm_apcs_32): Likewise. * auto-load.c (debug_auto_load): Likewise. (auto_load_gdb_scripts): Likewise. (global_auto_load): Likewise. (auto_load_local_gdbinit): Likewise. (auto_load_local_gdbinit_loaded): Likewise. * auto-load.h (global_auto_load): Likewise. (auto_load_local_gdbinit): Likewise. (auto_load_local_gdbinit_loaded): Likewise. * breakpoint.c (disconnected_dprintf): Likewise. (breakpoint_proceeded): Likewise. (automatic_hardware_breakpoints): Likewise. (always_inserted_mode): Likewise. (target_exact_watchpoints): Likewise. (_initialize_breakpoint): Update. * breakpoint.h (target_exact_watchpoints): Change to bool. * btrace.c (maint_btrace_pt_skip_pad): Likewise. * cli/cli-cmds.c (trace_commands): Likewise. * cli/cli-cmds.h (trace_commands): Likewise. * cli/cli-decode.c (add_setshow_boolean_cmd): Change int* argument to bool*. * cli/cli-logging.c (logging_overwrite): Change to bool. (logging_redirect): Likewise. (debug_redirect): Likewise. * cli/cli-option.h (option_def) <boolean>: Change return type to bool*. (struct boolean_option_def) <get_var_address_cb_>: Change return type to bool. <boolean_option_def>: Update. (struct flag_option_def): Change default type of Context to bool from int. <flag_option_def>: Change return type of var_address_cb_ to bool*. * cli/cli-setshow.c (do_set_command): Cast to bool* instead of int*. (get_setshow_command_value_string): Likewise. * cli/cli-style.c (cli_styling): Change to bool. (source_styling): Likewise. * cli/cli-style.h (source_styling): Likewise. (cli_styling): Likewise. * cli/cli-utils.h (struct qcs_flags) <quiet, cont, silent>: Change to bool. * command.h (var_types): Update comment. (add_setshow_boolean_cmd): Change int* var argument to bool*. * compile/compile-cplus-types.c (debug_compile_cplus_types): Change to bool. (debug_compile_cplus_scopes): Likewise. * compile/compile-internal.h (compile_debug): Likewise. * compile/compile.c (compile_debug): Likewise. (struct compile_options) <raw>: Likewise. * cp-support.c (catch_demangler_crashes): Likewise. * cris-tdep.c (usr_cmd_cris_version_valid): Likewise. (usr_cmd_cris_dwarf2_cfi): Likewise. * csky-tdep.c (csky_debug): Likewise. * darwin-nat.c (enable_mach_exceptions): Likewise. * dcache.c (dcache_enabled_p): Likewise. * defs.h (info_verbose): Likewise. * demangle.c (demangle): Likewise. (asm_demangle): Likewise. * dwarf-index-cache.c (debug_index_cache): Likewise. * dwarf2-frame.c (dwarf2_frame_unwinders_enabled_p): Likewise. * dwarf2-frame.h (dwarf2_frame_unwinders_enabled_p): Likewise. * dwarf2read.c (check_physname): Likewise. (use_deprecated_index_sections): Likewise. (dwarf_always_disassemble): Likewise. * eval.c (overload_resolution): Likewise. * event-top.c (set_editing_cmd_var): Likewise. (exec_done_display_p): Likewise. * event-top.h (set_editing_cmd_var): Likewise. (exec_done_display_p): Likewise. * exec.c (write_files): Likewise. * fbsd-nat.c (debug_fbsd_lwp): Likewise (debug_fbsd_nat): Likewise. * frame.h (struct frame_print_options) <print_raw_frame_arguments>: Likewise. (struct set_backtrace_options) <backtrace_past_main>: Likewise. <backtrace_past_entry> Likewise. * gdb-demangle.h (demangle): Likewise. (asm_demangle): Likewise. * gdb_bfd.c (bfd_sharing): Likewise. * gdbcore.h (write_files): Likewise. * gdbsupport/common-debug.c (show_debug_regs): Likewise. * gdbsupport/common-debug.h (show_debug_regs): Likewise. * gdbthread.h (print_thread_events): Likewise. * gdbtypes.c (opaque_type_resolution): Likewise. (strict_type_checking): Likewise. * gnu-nat.c (gnu_debug_flag): Likewise. * guile/scm-auto-load.c (auto_load_guile_scripts): Likewise. * guile/scm-param.c (pascm_variable): Add boolval. (add_setshow_generic): Update. (pascm_param_value): Update. (pascm_set_param_value_x): Update. * hppa-tdep.c (hppa_debug): Change to bool.. * infcall.c (may_call_functions_p): Likewise. (coerce_float_to_double_p): Likewise. (unwind_on_signal_p): Likewise. (unwind_on_terminating_exception_p): Likewise. * infcmd.c (startup_with_shell): Likewise. * inferior.c (print_inferior_events): Likewise. * inferior.h (startup_with_shell): Likewise. (print_inferior_events): Likewise. * infrun.c (step_stop_if_no_debug): Likewise. (detach_fork): Likewise. (debug_displaced): Likewise. (disable_randomization): Likewise. (non_stop): Likewise. (non_stop_1): Likewise. (observer_mode): Likewise. (observer_mode_1): Likewise. (set_observer_mode): Update. (sched_multi): Change to bool. * infrun.h (debug_displaced): Likewise. (sched_multi): Likewise. (step_stop_if_no_debug): Likewise. (non_stop): Likewise. (disable_randomization): Likewise. * linux-tdep.c (use_coredump_filter): Likewise. (dump_excluded_mappings): Likewise. * linux-thread-db.c (auto_load_thread_db): Likewise. (check_thread_db_on_load): Likewise. * main.c (captured_main_1): Update. * maint-test-options.c (struct test_options_opts) <flag_opt, xx1_opt, xx2_opt, boolean_opt>: Change to bool. * maint-test-settings.c (maintenance_test_settings_boolean): Likewise. * maint.c (maintenance_profile_p): Likewise. (per_command_time): Likewise. (per_command_space): Likewise. (per_command_symtab): Likewise. * memattr.c (inaccessible_by_default): Likewise. * mi/mi-main.c (mi_async): Likewise. (mi_async_1): Likewise. * mips-tdep.c (mips64_transfers_32bit_regs_p): Likewise. * nat/fork-inferior.h (startup_with_shell): Likewise. * nat/linux-namespaces.c (debug_linux_namespaces): Likewise. * nat/linux-namespaces.h (debug_linux_namespaces): Likewise. * nios2-tdep.c (nios2_debug): Likewise. * or1k-tdep.c (or1k_debug): Likewise. * parse.c (parser_debug): Likewise. * parser-defs.h (parser_debug): Likewise. * printcmd.c (print_symbol_filename): Likewise. * proc-api.c (procfs_trace): Likewise. * python/py-auto-load.c (auto_load_python_scripts): Likewise. * python/py-param.c (union parmpy_variable): Add "bool boolval" field. (set_parameter_value): Update. (add_setshow_generic): Update. * python/py-value.c (copy_py_bool_obj): Change argument from int* to bool*. * python/python.c (gdbpy_parameter_value): Cast to bool* instead of int*. * ravenscar-thread.c (ravenscar_task_support): Change to bool. * record-btrace.c (record_btrace_target::store_registers): Update. * record-full.c (record_full_memory_query): Change to bool. (record_full_stop_at_limit): Likewise. * record-full.h (record_full_memory_query): Likewise. * remote-notif.c (notif_debug): Likewise. * remote-notif.h (notif_debug): Likewise. * remote.c (use_range_stepping): Likewise. (interrupt_on_connect): Likewise. (remote_break): Likewise. * ser-tcp.c (tcp_auto_retry): Likewise. * ser-unix.c (serial_hwflow): Likewise. * skip.c (debug_skip): Likewise. * solib-aix.c (solib_aix_debug): Likewise. * spu-tdep.c (spu_stop_on_load_p): Likewise. (spu_auto_flush_cache_p): Likewise. * stack.c (struct backtrace_cmd_options) <full, no_filters, hide>: Likewise. (struct info_print_options) <quiet>: Likewise. * symfile-debug.c (debug_symfile): Likewise. * symfile.c (auto_solib_add): Likewise. (separate_debug_file_debug): Likewise. * symfile.h (auto_solib_add): Likewise. (separate_debug_file_debug): Likewise. * symtab.c (basenames_may_differ): Likewise. (struct filename_partial_match_opts) <dirname, basename>: Likewise. (struct info_print_options) <quiet, exclude_minsyms>: Likewise. (struct info_types_options) <quiet>: Likewise. * symtab.h (demangle): Likewise. (basenames_may_differ): Likewise. * target-dcache.c (stack_cache_enabled_1): Likewise. (code_cache_enabled_1): Likewise. * target.c (trust_readonly): Likewise. (may_write_registers): Likewise. (may_write_memory): Likewise. (may_insert_breakpoints): Likewise. (may_insert_tracepoints): Likewise. (may_insert_fast_tracepoints): Likewise. (may_stop): Likewise. (auto_connect_native_target): Likewise. (target_stop_and_wait): Update. (target_async_permitted): Change to bool. (target_async_permitted_1): Likewise. (may_write_registers_1): Likewise. (may_write_memory_1): Likewise. (may_insert_breakpoints_1): Likewise. (may_insert_tracepoints_1): Likewise. (may_insert_fast_tracepoints_1): Likewise. (may_stop_1): Likewise. * target.h (target_async_permitted): Likewise. (may_write_registers): Likewise. (may_write_memory): Likewise. (may_insert_breakpoints): Likewise. (may_insert_tracepoints): Likewise. (may_insert_fast_tracepoints): Likewise. (may_stop): Likewise. * thread.c (struct info_threads_opts) <show_global_ids>: Likewise. (make_thread_apply_all_options_def_group): Change argument from int* to bool*. (thread_apply_all_command): Update. (print_thread_events): Change to bool. * top.c (confirm): Likewise. (command_editing_p): Likewise. (history_expansion_p): Likewise. (write_history_p): Likewise. (info_verbose): Likewise. * top.h (confirm): Likewise. (history_expansion_p): Likewise. * tracepoint.c (disconnected_tracing): Likewise. (circular_trace_buffer): Likewise. * typeprint.c (print_methods): Likewise. (print_typedefs): Likewise. * utils.c (debug_timestamp): Likewise. (sevenbit_strings): Likewise. (pagination_enabled): Likewise. * utils.h (sevenbit_strings): Likewise. (pagination_enabled): Likewise. * valops.c (overload_resolution): Likewise. * valprint.h (struct value_print_options) <prettyformat_arrays, prettyformat_structs, vtblprint, unionprint, addressprint, objectprint, stop_print_at_null, print_array_indexes, deref_ref, static_field_print, pascal_static_field_print, raw, summary, symbol_print, finish_print>: Likewise. * windows-nat.c (new_console): Likewise. (cygwin_exceptions): Likewise. (new_group): Likewise. (debug_exec): Likewise. (debug_events): Likewise. (debug_memory): Likewise. (debug_exceptions): Likewise. (useshell): Likewise. * windows-tdep.c (maint_display_all_tib): Likewise. * xml-support.c (debug_xml): Likewise.
2019-09-14 21:36:58 +02:00
/* If true, attempt to catch crashes in the demangler and print
useful debugging information. */
Change boolean options to bool instead of int This is for add_setshow_boolean_cmd as well as the gdb::option interface. gdb/ChangeLog: 2019-09-17 Christian Biesinger <cbiesinger@google.com> * ada-lang.c (ada_ignore_descriptive_types_p): Change to bool. (print_signatures): Likewise. (trust_pad_over_xvs): Likewise. * arch/aarch64-insn.c (aarch64_debug): Likewise. * arch/aarch64-insn.h (aarch64_debug): Likewise. * arm-linux-nat.c (arm_apcs_32): Likewise. * arm-linux-tdep.c (arm_apcs_32): Likewise. * arm-nbsd-nat.c (arm_apcs_32): Likewise. * arm-tdep.c (arm_debug): Likewise. (arm_apcs_32): Likewise. * auto-load.c (debug_auto_load): Likewise. (auto_load_gdb_scripts): Likewise. (global_auto_load): Likewise. (auto_load_local_gdbinit): Likewise. (auto_load_local_gdbinit_loaded): Likewise. * auto-load.h (global_auto_load): Likewise. (auto_load_local_gdbinit): Likewise. (auto_load_local_gdbinit_loaded): Likewise. * breakpoint.c (disconnected_dprintf): Likewise. (breakpoint_proceeded): Likewise. (automatic_hardware_breakpoints): Likewise. (always_inserted_mode): Likewise. (target_exact_watchpoints): Likewise. (_initialize_breakpoint): Update. * breakpoint.h (target_exact_watchpoints): Change to bool. * btrace.c (maint_btrace_pt_skip_pad): Likewise. * cli/cli-cmds.c (trace_commands): Likewise. * cli/cli-cmds.h (trace_commands): Likewise. * cli/cli-decode.c (add_setshow_boolean_cmd): Change int* argument to bool*. * cli/cli-logging.c (logging_overwrite): Change to bool. (logging_redirect): Likewise. (debug_redirect): Likewise. * cli/cli-option.h (option_def) <boolean>: Change return type to bool*. (struct boolean_option_def) <get_var_address_cb_>: Change return type to bool. <boolean_option_def>: Update. (struct flag_option_def): Change default type of Context to bool from int. <flag_option_def>: Change return type of var_address_cb_ to bool*. * cli/cli-setshow.c (do_set_command): Cast to bool* instead of int*. (get_setshow_command_value_string): Likewise. * cli/cli-style.c (cli_styling): Change to bool. (source_styling): Likewise. * cli/cli-style.h (source_styling): Likewise. (cli_styling): Likewise. * cli/cli-utils.h (struct qcs_flags) <quiet, cont, silent>: Change to bool. * command.h (var_types): Update comment. (add_setshow_boolean_cmd): Change int* var argument to bool*. * compile/compile-cplus-types.c (debug_compile_cplus_types): Change to bool. (debug_compile_cplus_scopes): Likewise. * compile/compile-internal.h (compile_debug): Likewise. * compile/compile.c (compile_debug): Likewise. (struct compile_options) <raw>: Likewise. * cp-support.c (catch_demangler_crashes): Likewise. * cris-tdep.c (usr_cmd_cris_version_valid): Likewise. (usr_cmd_cris_dwarf2_cfi): Likewise. * csky-tdep.c (csky_debug): Likewise. * darwin-nat.c (enable_mach_exceptions): Likewise. * dcache.c (dcache_enabled_p): Likewise. * defs.h (info_verbose): Likewise. * demangle.c (demangle): Likewise. (asm_demangle): Likewise. * dwarf-index-cache.c (debug_index_cache): Likewise. * dwarf2-frame.c (dwarf2_frame_unwinders_enabled_p): Likewise. * dwarf2-frame.h (dwarf2_frame_unwinders_enabled_p): Likewise. * dwarf2read.c (check_physname): Likewise. (use_deprecated_index_sections): Likewise. (dwarf_always_disassemble): Likewise. * eval.c (overload_resolution): Likewise. * event-top.c (set_editing_cmd_var): Likewise. (exec_done_display_p): Likewise. * event-top.h (set_editing_cmd_var): Likewise. (exec_done_display_p): Likewise. * exec.c (write_files): Likewise. * fbsd-nat.c (debug_fbsd_lwp): Likewise (debug_fbsd_nat): Likewise. * frame.h (struct frame_print_options) <print_raw_frame_arguments>: Likewise. (struct set_backtrace_options) <backtrace_past_main>: Likewise. <backtrace_past_entry> Likewise. * gdb-demangle.h (demangle): Likewise. (asm_demangle): Likewise. * gdb_bfd.c (bfd_sharing): Likewise. * gdbcore.h (write_files): Likewise. * gdbsupport/common-debug.c (show_debug_regs): Likewise. * gdbsupport/common-debug.h (show_debug_regs): Likewise. * gdbthread.h (print_thread_events): Likewise. * gdbtypes.c (opaque_type_resolution): Likewise. (strict_type_checking): Likewise. * gnu-nat.c (gnu_debug_flag): Likewise. * guile/scm-auto-load.c (auto_load_guile_scripts): Likewise. * guile/scm-param.c (pascm_variable): Add boolval. (add_setshow_generic): Update. (pascm_param_value): Update. (pascm_set_param_value_x): Update. * hppa-tdep.c (hppa_debug): Change to bool.. * infcall.c (may_call_functions_p): Likewise. (coerce_float_to_double_p): Likewise. (unwind_on_signal_p): Likewise. (unwind_on_terminating_exception_p): Likewise. * infcmd.c (startup_with_shell): Likewise. * inferior.c (print_inferior_events): Likewise. * inferior.h (startup_with_shell): Likewise. (print_inferior_events): Likewise. * infrun.c (step_stop_if_no_debug): Likewise. (detach_fork): Likewise. (debug_displaced): Likewise. (disable_randomization): Likewise. (non_stop): Likewise. (non_stop_1): Likewise. (observer_mode): Likewise. (observer_mode_1): Likewise. (set_observer_mode): Update. (sched_multi): Change to bool. * infrun.h (debug_displaced): Likewise. (sched_multi): Likewise. (step_stop_if_no_debug): Likewise. (non_stop): Likewise. (disable_randomization): Likewise. * linux-tdep.c (use_coredump_filter): Likewise. (dump_excluded_mappings): Likewise. * linux-thread-db.c (auto_load_thread_db): Likewise. (check_thread_db_on_load): Likewise. * main.c (captured_main_1): Update. * maint-test-options.c (struct test_options_opts) <flag_opt, xx1_opt, xx2_opt, boolean_opt>: Change to bool. * maint-test-settings.c (maintenance_test_settings_boolean): Likewise. * maint.c (maintenance_profile_p): Likewise. (per_command_time): Likewise. (per_command_space): Likewise. (per_command_symtab): Likewise. * memattr.c (inaccessible_by_default): Likewise. * mi/mi-main.c (mi_async): Likewise. (mi_async_1): Likewise. * mips-tdep.c (mips64_transfers_32bit_regs_p): Likewise. * nat/fork-inferior.h (startup_with_shell): Likewise. * nat/linux-namespaces.c (debug_linux_namespaces): Likewise. * nat/linux-namespaces.h (debug_linux_namespaces): Likewise. * nios2-tdep.c (nios2_debug): Likewise. * or1k-tdep.c (or1k_debug): Likewise. * parse.c (parser_debug): Likewise. * parser-defs.h (parser_debug): Likewise. * printcmd.c (print_symbol_filename): Likewise. * proc-api.c (procfs_trace): Likewise. * python/py-auto-load.c (auto_load_python_scripts): Likewise. * python/py-param.c (union parmpy_variable): Add "bool boolval" field. (set_parameter_value): Update. (add_setshow_generic): Update. * python/py-value.c (copy_py_bool_obj): Change argument from int* to bool*. * python/python.c (gdbpy_parameter_value): Cast to bool* instead of int*. * ravenscar-thread.c (ravenscar_task_support): Change to bool. * record-btrace.c (record_btrace_target::store_registers): Update. * record-full.c (record_full_memory_query): Change to bool. (record_full_stop_at_limit): Likewise. * record-full.h (record_full_memory_query): Likewise. * remote-notif.c (notif_debug): Likewise. * remote-notif.h (notif_debug): Likewise. * remote.c (use_range_stepping): Likewise. (interrupt_on_connect): Likewise. (remote_break): Likewise. * ser-tcp.c (tcp_auto_retry): Likewise. * ser-unix.c (serial_hwflow): Likewise. * skip.c (debug_skip): Likewise. * solib-aix.c (solib_aix_debug): Likewise. * spu-tdep.c (spu_stop_on_load_p): Likewise. (spu_auto_flush_cache_p): Likewise. * stack.c (struct backtrace_cmd_options) <full, no_filters, hide>: Likewise. (struct info_print_options) <quiet>: Likewise. * symfile-debug.c (debug_symfile): Likewise. * symfile.c (auto_solib_add): Likewise. (separate_debug_file_debug): Likewise. * symfile.h (auto_solib_add): Likewise. (separate_debug_file_debug): Likewise. * symtab.c (basenames_may_differ): Likewise. (struct filename_partial_match_opts) <dirname, basename>: Likewise. (struct info_print_options) <quiet, exclude_minsyms>: Likewise. (struct info_types_options) <quiet>: Likewise. * symtab.h (demangle): Likewise. (basenames_may_differ): Likewise. * target-dcache.c (stack_cache_enabled_1): Likewise. (code_cache_enabled_1): Likewise. * target.c (trust_readonly): Likewise. (may_write_registers): Likewise. (may_write_memory): Likewise. (may_insert_breakpoints): Likewise. (may_insert_tracepoints): Likewise. (may_insert_fast_tracepoints): Likewise. (may_stop): Likewise. (auto_connect_native_target): Likewise. (target_stop_and_wait): Update. (target_async_permitted): Change to bool. (target_async_permitted_1): Likewise. (may_write_registers_1): Likewise. (may_write_memory_1): Likewise. (may_insert_breakpoints_1): Likewise. (may_insert_tracepoints_1): Likewise. (may_insert_fast_tracepoints_1): Likewise. (may_stop_1): Likewise. * target.h (target_async_permitted): Likewise. (may_write_registers): Likewise. (may_write_memory): Likewise. (may_insert_breakpoints): Likewise. (may_insert_tracepoints): Likewise. (may_insert_fast_tracepoints): Likewise. (may_stop): Likewise. * thread.c (struct info_threads_opts) <show_global_ids>: Likewise. (make_thread_apply_all_options_def_group): Change argument from int* to bool*. (thread_apply_all_command): Update. (print_thread_events): Change to bool. * top.c (confirm): Likewise. (command_editing_p): Likewise. (history_expansion_p): Likewise. (write_history_p): Likewise. (info_verbose): Likewise. * top.h (confirm): Likewise. (history_expansion_p): Likewise. * tracepoint.c (disconnected_tracing): Likewise. (circular_trace_buffer): Likewise. * typeprint.c (print_methods): Likewise. (print_typedefs): Likewise. * utils.c (debug_timestamp): Likewise. (sevenbit_strings): Likewise. (pagination_enabled): Likewise. * utils.h (sevenbit_strings): Likewise. (pagination_enabled): Likewise. * valops.c (overload_resolution): Likewise. * valprint.h (struct value_print_options) <prettyformat_arrays, prettyformat_structs, vtblprint, unionprint, addressprint, objectprint, stop_print_at_null, print_array_indexes, deref_ref, static_field_print, pascal_static_field_print, raw, summary, symbol_print, finish_print>: Likewise. * windows-nat.c (new_console): Likewise. (cygwin_exceptions): Likewise. (new_group): Likewise. (debug_exec): Likewise. (debug_events): Likewise. (debug_memory): Likewise. (debug_exceptions): Likewise. (useshell): Likewise. * windows-tdep.c (maint_display_all_tib): Likewise. * xml-support.c (debug_xml): Likewise.
2019-09-14 21:36:58 +02:00
static bool catch_demangler_crashes = true;
/* Stack context and environment for demangler crash recovery. */
static thread_local SIGJMP_BUF *gdb_demangle_jmp_buf;
/* If true, attempt to dump core from the signal handler. */
static std::atomic<bool> gdb_demangle_attempt_core_dump;
/* Signal handler for gdb_demangle. */
static void
gdb_demangle_signal_handler (int signo)
{
if (gdb_demangle_attempt_core_dump)
{
if (fork () == 0)
dump_core ();
gdb_demangle_attempt_core_dump = false;
}
SIGLONGJMP (*gdb_demangle_jmp_buf, signo);
}
/* A helper for gdb_demangle that reports a demangling failure. */
static void
report_failed_demangle (const char *name, bool core_dump_allowed,
int crash_signal)
{
static bool error_reported = false;
if (!error_reported)
{
std::string short_msg
= string_printf (_("unable to demangle '%s' "
"(demangler failed with signal %d)"),
name, crash_signal);
std::string long_msg
= string_printf ("%s:%d: %s: %s", __FILE__, __LINE__,
"demangler-warning", short_msg.c_str ());
target_terminal::scoped_restore_terminal_state term_state;
target_terminal::ours_for_output ();
begin_line ();
if (core_dump_allowed)
fprintf_unfiltered (gdb_stderr,
_("%s\nAttempting to dump core.\n"),
long_msg.c_str ());
else
warn_cant_dump_core (long_msg.c_str ());
demangler_warning (__FILE__, __LINE__, "%s", short_msg.c_str ());
error_reported = true;
}
}
#endif
/* A wrapper for bfd_demangle. */
char *
gdb_demangle (const char *name, int options)
{
char *result = NULL;
int crash_signal = 0;
#ifdef HAVE_WORKING_FORK
scoped_restore restore_segv
= make_scoped_restore (&thread_local_segv_handler,
catch_demangler_crashes
? gdb_demangle_signal_handler
: nullptr);
bool core_dump_allowed = gdb_demangle_attempt_core_dump;
SIGJMP_BUF jmp_buf;
scoped_restore restore_jmp_buf
= make_scoped_restore (&gdb_demangle_jmp_buf, &jmp_buf);
if (catch_demangler_crashes)
{
/* The signal handler may keep the signal blocked when we longjmp out
of it. If we have sigprocmask, we can use it to unblock the signal
afterwards and we can avoid the performance overhead of saving the
signal mask just in case the signal gets triggered. Otherwise, just
tell sigsetjmp to save the mask. */
#ifdef HAVE_SIGPROCMASK
crash_signal = SIGSETJMP (*gdb_demangle_jmp_buf, 0);
#else
crash_signal = SIGSETJMP (*gdb_demangle_jmp_buf, 1);
#endif
}
#endif
if (crash_signal == 0)
result = bfd_demangle (NULL, name, options);
#ifdef HAVE_WORKING_FORK
if (catch_demangler_crashes)
{
if (crash_signal != 0)
{
#ifdef HAVE_SIGPROCMASK
/* If we got the signal, SIGSEGV may still be blocked; restore it. */
sigset_t segv_sig_set;
sigemptyset (&segv_sig_set);
sigaddset (&segv_sig_set, SIGSEGV);
Add RAII class for blocking gdb signals This adds configury support and an RAII class that can be used to temporarily block signals that are used by gdb. (This class is not used in this patch, but it split out for easier review.) The idea of this patch is that these signals should only be delivered to the main thread. So, when creating a background thread, they are temporarily blocked; the blocked state is inherited by the new thread. The sigprocmask man page says: The use of sigprocmask() is unspecified in a multithreaded process; see pthread_sigmask(3). This patch changes gdb to use pthread_sigmask when appropriate, by introducing a convenience define. I've updated gdbserver as well, because I had to touch gdbsupport, and because the threading patches will make it link against the thread library. I chose not to touch the NTO code, because I don't know anything about that platform and because I cannot test it. Finally, this modifies an existing spot in the Guile layer to use the new facility. gdb/ChangeLog 2019-11-26 Tom Tromey <tom@tromey.com> * gdbsupport/signals-state-save-restore.c (original_signal_mask): Remove comment. (save_original_signals_state, restore_original_signals_state): Use gdb_sigmask. * linux-nat.c (block_child_signals, restore_child_signals_mask) (_initialize_linux_nat): Use gdb_sigmask. * guile/guile.c (_initialize_guile): Use block_signals. * Makefile.in (HFILES_NO_SRCDIR): Add gdb-sigmask.h. * gdbsupport/gdb-sigmask.h: New file. * event-top.c (async_sigtstp_handler): Use gdb_sigmask. * cp-support.c (gdb_demangle): Use gdb_sigmask. * gdbsupport/common.m4 (GDB_AC_COMMON): Check for pthread_sigmask. * configure, config.in: Rebuild. * gdbsupport/block-signals.h: New file. gdb/gdbserver/ChangeLog 2019-11-26 Tom Tromey <tom@tromey.com> * remote-utils.c (block_unblock_async_io): Use gdb_sigmask. * linux-low.c (linux_wait_for_event_filtered, linux_async): Use gdb_sigmask. * configure, config.in: Rebuild. Change-Id: If3f37dc57dd859c226e9e4d79458a0514746e8c6
2019-09-29 16:50:15 +02:00
gdb_sigmask (SIG_UNBLOCK, &segv_sig_set, NULL);
#endif
/* If there was a failure, we can't report it here, because
we might be in a background thread. Instead, arrange for
the reporting to happen on the main thread. */
std::string copy = name;
run_on_main_thread ([=] ()
{
report_failed_demangle (copy.c_str (), core_dump_allowed,
crash_signal);
});
result = NULL;
}
}
#endif
return result;
}
Move logic out of symbol_find_demangled_name This patch moves most of the demangling logic out of symbol_find_demangled_name into the various language_defn objects. The simplest way to do this seemed to be to add a new method to language_defn. This is shame given the existing la_demangle, but given Ada's unusual needs, and the differing demangling options between languages, la_demangle didn't seem to fit. In order to make this work, I made enum language order-sensitive. This helps preserve the current ordering of demangling operations. 2016-06-23 Tom Tromey <tom@tromey.com> * symtab.c (symbol_find_demangled_name): Loop over languages and use language_sniff_from_mangled_name. * rust-lang.c (rust_sniff_from_mangled_name): New function. (rust_language_defn): Update. * p-lang.c (pascal_language_defn): Update. * opencl-lang.c (opencl_language_defn): Update. * objc-lang.c (objc_sniff_from_mangled_name): New function. (objc_language_defn): Update. * m2-lang.c (m2_language_defn): Update. * language.h (struct language_defn) <la_sniff_from_mangled_name>: New field. (language_sniff_from_mangled_name): Declare. * language.c (language_sniff_from_mangled_name): New function. (unknown_language_defn, auto_language_defn, local_language_defn): Update. * jv-lang.c (java_sniff_from_mangled_name): New function. (java_language_defn): Use it. * go-lang.c (go_sniff_from_mangled_name): New function. (go_language_defn): Use it. * f-lang.c (f_language_defn): Update. * defs.h (enum language): Reorder. * d-lang.c (d_sniff_from_mangled_name): New function. (d_language_defn): Use it. * cp-support.h (gdb_sniff_from_mangled_name): Declare. * cp-support.c (gdb_sniff_from_mangled_name): New function. * c-lang.c (c_language_defn, cplus_language_defn) (asm_language_defn, minimal_language_defn): Update. * ada-lang.c (ada_sniff_from_mangled_name): New function. (ada_language_defn): Use it.
2016-05-26 23:04:07 +02:00
/* See cp-support.h. */
int
gdb_sniff_from_mangled_name (const char *mangled, char **demangled)
{
*demangled = gdb_demangle (mangled, DMGL_PARAMS | DMGL_ANSI);
return *demangled != NULL;
}
Make "break foo" find "A::foo", A::B::foo", etc. [C++ and wild matching] This patch teaches GDB about setting breakpoints in all scopes (namespaces and classes) by default. Here's a contrived example: (gdb) b func<tab> (anonymous namespace)::A::function() Bn::(anonymous namespace)::B::function() function(int, int) (anonymous namespace)::B::function() Bn::(anonymous namespace)::function() gdb::(anonymous namespace)::A::function() (anonymous namespace)::B::function() const Bn::(anonymous namespace)::function(int, int) gdb::(anonymous namespace)::function() (anonymous namespace)::function() Bn::B::func() gdb::(anonymous namespace)::function(int, int) (anonymous namespace)::function(int, int) Bn::B::function() gdb::A::func() A::func() Bn::func() gdb::A::function() A::function() Bn::function() gdb::func() B::func() Bn::function(int, int) gdb::function() B::function() Bn::function(long) gdb::function(int, int) B::function() const func() gdb::function(long) B::function_const() const function() (gdb) b function Breakpoint 1 at 0x4005ce: function. (26 locations) (gdb) b B::function<tab> (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() (gdb) b B::function Breakpoint 1 at 0x40072c: B::function. (6 locations) To get back the original behavior of interpreting the function name as a fully-qualified name, you can use the new "-qualified" (or "-q") option/flag (added by this commit). For example: (gdb) b B::function (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() vs: (gdb) b -qualified B::function B::function() B::function() const B::function_const() const I've chosen "-qualified" / "-q" because "-f" (for "full" or "fully-qualified") is already taken for "-function". Note: the "-qualified" option works with both linespecs and explicit locations. I.e., these are equivalent: (gdb) b -q func (gdb) b -q -f func and so are these: (gdb) b -q filename.cc:func (gdb) b -q -s filename.cc -f func (gdb) b -s filename.cc -q -f func (gdb) b -s filename.cc -f func -q To better understand why I consider wild matching the better default, consider what happens when we get to the point when _all_ of GDB is wrapped under "namespace gdb {}". I have a patch series that does that, and when I started debugging that GDB, I immediately became frustrated. You'd have to write "b gdb::internal_error", "b gdb::foo", "b gdb::bar", etc. etc., which gets annoying pretty quickly. OTOH, consider how this makes it very easy to set breakpoints in classes wrapped in anonymous namespaces. You just don't think of them, GDB finds the symbols for you automatically. (At the Cauldron a couple months ago, several people told me that they run into a similar issue when debugging other C++ projects. One example was when debugging LLVM, which puts all its code under the "llvm" namespace.) Implementation-wise, what the patch does is: - makes C++ symbol name hashing only consider the last component of a symbol name. (so that we can look up symbol names by last-component name only). - adds a C++ symbol name matcher for symbol_name_match_type::WILD, which ignores missing leading specifiers / components. - adjusts a few preexisting testsuite tests to use "-qualified" when they mean it. - adds new testsuite tests. - adds unit tests. Grows the gdb.linespec/ tests like this: -# of expected passes 7823 +# of expected passes 8977 gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * NEWS: Mention that breakpoints on C++ functions are now set on on all namespaces/classes by default, and mention "break -qualified". * ax-gdb.c (agent_command_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * breakpoint.c (parse_breakpoint_sals): Adjust to get_linespec_location's return type change. (strace_marker_create_sals_from_location): Adjust to pass a symbol_name_match_type to new_linespec_location. (strace_marker_decode_location): Adjust to get_linespec_location's return type change. (strace_command): Adjust to pass a symbol_name_match_type to new_linespec_location. (LOCATION_HELP_STRING): Add paragraph about wildmatching, and mention "-qualified". * c-lang.c (cplus_language_defn): Install cp_search_name_hash. * completer.c (explicit_location_match_type::MATCH_QUALIFIED): New enumerator. (complete_address_and_linespec_locations): New parameter 'match_type'. Pass it down. (explicit_options): Add "-qualified". (collect_explicit_location_matches): Pass the requested match type to the linespec completers. Handle MATCH_QUALIFIED. (location_completer): Handle "-qualified" combined with linespecs. * cp-support.c (cp_search_name_hash): New. (cp_symbol_name_matches_1): Implement wild matching for C++. (cp_fq_symbol_name_matches): Reimplement. (cp_get_symbol_name_matcher): Return different matchers depending on the lookup name's match type. (selftests::test_cp_symbol_name_matches): Add wild matching tests. * cp-support.h (cp_search_name_hash): New declaration. * dwarf2read.c (selftests::dw2_expand_symtabs_matching::test_symbols): Add symbols. (test_dw2_expand_symtabs_matching_symbol): Add wild matching tests. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Adjust to pass a symbol_name_match_type to new_linespec_location. * linespec.c (linespec_parse_basic): Lookup function symbols using the parser's symbol name match type. (convert_explicit_location_to_linespec): New symbol_name_match_type parameter. Pass it down to find_linespec_symbols. (convert_explicit_location_to_sals): Pass the location's name match type to convert_explicit_location_to_linespec. (parse_linespec): New match_type parameter. Save it in the parser. (linespec_parser_new): Default to symbol_name_match_type::WILD. (linespec_complete_function): New symbol_name_match_type parameter. Use it. (complete_linespec_component): Pass down the parser's recorded name match type. (linespec_complete_label): New symbol_name_match_type parameter. Use it. (linespec_complete): New symbol_name_match_type parameter. Save it in the parser and pass it down. Adjust to get_linespec_location's prototype change. (find_function_symbols, find_linespec_symbols): New symbol_name_match_type parameter. Pass it down instead of assuming symbol_name_match_type::WILD. * linespec.h (linespec_complete, linespec_complete_function) (linespec_complete_label): New symbol_name_match_type parameter. * location.c (event_location::linespec_location): Now a struct linespec_location. (EL_LINESPEC): Adjust. (initialize_explicit_location): Default to symbol_name_match_type::WILD. (new_linespec_location): New symbol_name_match_type parameter. Record it in the location. (get_linespec_location): Now returns a struct linespec_location. (new_explicit_location): Also copy func_name_match_type. (explicit_to_string_internal) (string_to_explicit_location): Handle "-qualified". (copy_event_location): Adjust to LINESPEC_LOCATION type change. Copy symbol_name_match_type fields. (event_location_deleter::operator()): Adjust to LINESPEC_LOCATION type change. (event_location_to_string): Adjust to LINESPEC_LOCATION type change. Handle "-qualfied". (string_to_explicit_location): Handle "-qualified". (string_to_event_location_basic): New symbol_name_match_type parameter. Pass it down. (string_to_event_location): Handle "-qualified". * location.h (struct linespec_location): New. (explicit_location::func_name_match_type): New field. (new_linespec_location): Now returns a const linespec_location *. (string_to_event_location_basic): New symbol_name_match_type parameter. (explicit_completion_info::saw_explicit_location_option): New field. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * python/py-breakpoint.c (bppy_init): Likewise. * python/python.c (gdbpy_decode_line): Likewise. gdb/testsuite/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.base/langs.exp: Use -qualified. * gdb.cp/meth-typedefs.exp: Use -qualified, and add tests without it. * gdb.cp/namespace.exp: Use -qualified. * gdb.linespec/cpcompletion.exp (overload-2, fqn, fqn-2) (overload-3, template-overload, template-ret-type, const-overload) (const-overload-quoted, anon-ns, ambiguous-prefix): New procedures. (test_driver): Call them. * gdb.cp/save-bp-qualified.cc: New. * gdb.cp/save-bp-qualified.exp: New. * gdb.linespec/explicit.exp: Test -qualified. * lib/completion-support.exp (completion::explicit_opts_list): Add "-qualified". * lib/gdb.exp (gdb_breakpoint): Handle "qualified". gdb/doc/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.texinfo (Linespec Locations): Document how "function" is interpreted in C++ and Ada. Document "-qualified". (Explicit Locations): Document how "-function" is interpreted in C++ and Ada. Document "-qualified".
2017-11-29 20:33:23 +01:00
/* See cp-support.h. */
unsigned int
cp_search_name_hash (const char *search_name)
{
/* cp_entire_prefix_len assumes a fully-qualified name with no
leading "::". */
if (startswith (search_name, "::"))
search_name += 2;
unsigned int prefix_len = cp_entire_prefix_len (search_name);
if (prefix_len != 0)
search_name += prefix_len + 2;
Breakpoints in symbols with ABI tags (PR c++/19436) Trying to set a breakpoint in a function with an ABI tag does not work currently. E.g., debugging gdb itself, we see this with the "string_printf" function: (top-gdb) b string_print [TAB] (top-gdb) b string_printf[abi:cxx11](char const*, ...) [RET] No source file named string_printf[abi. Make breakpoint pending on future shared library load? (y or [n]) Quoting doesn't help: (top-gdb) b 'string_printf[abi:cxx11]'(char const*, ...) malformed linespec error: unexpected string, "(char const*, ...)" (top-gdb) b 'string_printf[abi:cxx11](char const*, ...)' No source file named string_printf[abi. Make breakpoint pending on future shared library load? (y or [n]) n This patch fixes this, and takes it a bit further. The actual symbol name as demangled by libiberty's demangler is really string_printf[abi:cxx11](char const*, ...) however, this patch makes it possible to set the breakpoint with string_printf(char const*, ...) too. I.e., ignoring the ABI tag. And to match, it teaches the completer to complete the symbol name without the ABI tag, i.e., "string_pri<TAB>" -> "string_printf(char const*, ...)" If however, you really want to break on a symbol with the tag, then you simply start writing the tag, and GDB will preserve it, like: "string_printf[a<TAB>" -> "string_printf[abi:cxx11](char const*, ...)" Grows the gdb.linespec/ tests like this: -# of expected passes 8977 +# of expected passes 9176 gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> PR c++/19436 * NEWS: Mention setting breakpoints on functions with C++ ABI tags. * completer.h (completion_match_for_lcd) <match, mark_ignored_range>: New methods. <finish>: Consider ignored ranges. <clear>: Clear ignored ranges. <m_ignored_ranges, m_finished_storage>: New fields. * cp-support.c (cp_search_name_hash): Ignore ABI tags. (cp_symbol_name_matches_1, cp_fq_symbol_name_matches): Pass the completion_match_for_lcd pointer to strncmp_iw_with_mode. (test_cp_symbol_name_cmp): Add [abi:...] tags unit tests. * language.c (default_symbol_name_matcher): Pass the completion_match_for_lcd pointer to strncmp_iw_with_mode. * linespec.c (linespec_lexer_lex_string): Don't tokenize ABI tags. * utils.c (skip_abi_tag): New function. (strncmp_iw_with_mode): Add completion_match_for_lcd parameter. Handle ABI tags. * utils.h (strncmp_iw_with_mode): Add completion_match_for_lcd parameter. gdb/testsuite/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> PR c++/19436 * gdb.linespec/cpls-abi-tag.cc: New file. * gdb.linespec/cpls-abi-tag.exp: New file. gdb/doc/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> PR c++/19436 * gdb.texinfo (Debugging C Plus Plus): Document setting breakpoints in functions with ABI tags.
2017-11-29 20:33:24 +01:00
unsigned int hash = 0;
for (const char *string = search_name; *string != '\0'; ++string)
{
string = skip_spaces (string);
if (*string == '(')
break;
/* Ignore ABI tags such as "[abi:cxx11]. */
if (*string == '['
&& startswith (string + 1, "abi:")
&& string[5] != ':')
break;
hash = SYMBOL_HASH_NEXT (hash, *string);
}
return hash;
Make "break foo" find "A::foo", A::B::foo", etc. [C++ and wild matching] This patch teaches GDB about setting breakpoints in all scopes (namespaces and classes) by default. Here's a contrived example: (gdb) b func<tab> (anonymous namespace)::A::function() Bn::(anonymous namespace)::B::function() function(int, int) (anonymous namespace)::B::function() Bn::(anonymous namespace)::function() gdb::(anonymous namespace)::A::function() (anonymous namespace)::B::function() const Bn::(anonymous namespace)::function(int, int) gdb::(anonymous namespace)::function() (anonymous namespace)::function() Bn::B::func() gdb::(anonymous namespace)::function(int, int) (anonymous namespace)::function(int, int) Bn::B::function() gdb::A::func() A::func() Bn::func() gdb::A::function() A::function() Bn::function() gdb::func() B::func() Bn::function(int, int) gdb::function() B::function() Bn::function(long) gdb::function(int, int) B::function() const func() gdb::function(long) B::function_const() const function() (gdb) b function Breakpoint 1 at 0x4005ce: function. (26 locations) (gdb) b B::function<tab> (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() (gdb) b B::function Breakpoint 1 at 0x40072c: B::function. (6 locations) To get back the original behavior of interpreting the function name as a fully-qualified name, you can use the new "-qualified" (or "-q") option/flag (added by this commit). For example: (gdb) b B::function (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() vs: (gdb) b -qualified B::function B::function() B::function() const B::function_const() const I've chosen "-qualified" / "-q" because "-f" (for "full" or "fully-qualified") is already taken for "-function". Note: the "-qualified" option works with both linespecs and explicit locations. I.e., these are equivalent: (gdb) b -q func (gdb) b -q -f func and so are these: (gdb) b -q filename.cc:func (gdb) b -q -s filename.cc -f func (gdb) b -s filename.cc -q -f func (gdb) b -s filename.cc -f func -q To better understand why I consider wild matching the better default, consider what happens when we get to the point when _all_ of GDB is wrapped under "namespace gdb {}". I have a patch series that does that, and when I started debugging that GDB, I immediately became frustrated. You'd have to write "b gdb::internal_error", "b gdb::foo", "b gdb::bar", etc. etc., which gets annoying pretty quickly. OTOH, consider how this makes it very easy to set breakpoints in classes wrapped in anonymous namespaces. You just don't think of them, GDB finds the symbols for you automatically. (At the Cauldron a couple months ago, several people told me that they run into a similar issue when debugging other C++ projects. One example was when debugging LLVM, which puts all its code under the "llvm" namespace.) Implementation-wise, what the patch does is: - makes C++ symbol name hashing only consider the last component of a symbol name. (so that we can look up symbol names by last-component name only). - adds a C++ symbol name matcher for symbol_name_match_type::WILD, which ignores missing leading specifiers / components. - adjusts a few preexisting testsuite tests to use "-qualified" when they mean it. - adds new testsuite tests. - adds unit tests. Grows the gdb.linespec/ tests like this: -# of expected passes 7823 +# of expected passes 8977 gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * NEWS: Mention that breakpoints on C++ functions are now set on on all namespaces/classes by default, and mention "break -qualified". * ax-gdb.c (agent_command_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * breakpoint.c (parse_breakpoint_sals): Adjust to get_linespec_location's return type change. (strace_marker_create_sals_from_location): Adjust to pass a symbol_name_match_type to new_linespec_location. (strace_marker_decode_location): Adjust to get_linespec_location's return type change. (strace_command): Adjust to pass a symbol_name_match_type to new_linespec_location. (LOCATION_HELP_STRING): Add paragraph about wildmatching, and mention "-qualified". * c-lang.c (cplus_language_defn): Install cp_search_name_hash. * completer.c (explicit_location_match_type::MATCH_QUALIFIED): New enumerator. (complete_address_and_linespec_locations): New parameter 'match_type'. Pass it down. (explicit_options): Add "-qualified". (collect_explicit_location_matches): Pass the requested match type to the linespec completers. Handle MATCH_QUALIFIED. (location_completer): Handle "-qualified" combined with linespecs. * cp-support.c (cp_search_name_hash): New. (cp_symbol_name_matches_1): Implement wild matching for C++. (cp_fq_symbol_name_matches): Reimplement. (cp_get_symbol_name_matcher): Return different matchers depending on the lookup name's match type. (selftests::test_cp_symbol_name_matches): Add wild matching tests. * cp-support.h (cp_search_name_hash): New declaration. * dwarf2read.c (selftests::dw2_expand_symtabs_matching::test_symbols): Add symbols. (test_dw2_expand_symtabs_matching_symbol): Add wild matching tests. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Adjust to pass a symbol_name_match_type to new_linespec_location. * linespec.c (linespec_parse_basic): Lookup function symbols using the parser's symbol name match type. (convert_explicit_location_to_linespec): New symbol_name_match_type parameter. Pass it down to find_linespec_symbols. (convert_explicit_location_to_sals): Pass the location's name match type to convert_explicit_location_to_linespec. (parse_linespec): New match_type parameter. Save it in the parser. (linespec_parser_new): Default to symbol_name_match_type::WILD. (linespec_complete_function): New symbol_name_match_type parameter. Use it. (complete_linespec_component): Pass down the parser's recorded name match type. (linespec_complete_label): New symbol_name_match_type parameter. Use it. (linespec_complete): New symbol_name_match_type parameter. Save it in the parser and pass it down. Adjust to get_linespec_location's prototype change. (find_function_symbols, find_linespec_symbols): New symbol_name_match_type parameter. Pass it down instead of assuming symbol_name_match_type::WILD. * linespec.h (linespec_complete, linespec_complete_function) (linespec_complete_label): New symbol_name_match_type parameter. * location.c (event_location::linespec_location): Now a struct linespec_location. (EL_LINESPEC): Adjust. (initialize_explicit_location): Default to symbol_name_match_type::WILD. (new_linespec_location): New symbol_name_match_type parameter. Record it in the location. (get_linespec_location): Now returns a struct linespec_location. (new_explicit_location): Also copy func_name_match_type. (explicit_to_string_internal) (string_to_explicit_location): Handle "-qualified". (copy_event_location): Adjust to LINESPEC_LOCATION type change. Copy symbol_name_match_type fields. (event_location_deleter::operator()): Adjust to LINESPEC_LOCATION type change. (event_location_to_string): Adjust to LINESPEC_LOCATION type change. Handle "-qualfied". (string_to_explicit_location): Handle "-qualified". (string_to_event_location_basic): New symbol_name_match_type parameter. Pass it down. (string_to_event_location): Handle "-qualified". * location.h (struct linespec_location): New. (explicit_location::func_name_match_type): New field. (new_linespec_location): Now returns a const linespec_location *. (string_to_event_location_basic): New symbol_name_match_type parameter. (explicit_completion_info::saw_explicit_location_option): New field. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * python/py-breakpoint.c (bppy_init): Likewise. * python/python.c (gdbpy_decode_line): Likewise. gdb/testsuite/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.base/langs.exp: Use -qualified. * gdb.cp/meth-typedefs.exp: Use -qualified, and add tests without it. * gdb.cp/namespace.exp: Use -qualified. * gdb.linespec/cpcompletion.exp (overload-2, fqn, fqn-2) (overload-3, template-overload, template-ret-type, const-overload) (const-overload-quoted, anon-ns, ambiguous-prefix): New procedures. (test_driver): Call them. * gdb.cp/save-bp-qualified.cc: New. * gdb.cp/save-bp-qualified.exp: New. * gdb.linespec/explicit.exp: Test -qualified. * lib/completion-support.exp (completion::explicit_opts_list): Add "-qualified". * lib/gdb.exp (gdb_breakpoint): Handle "qualified". gdb/doc/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.texinfo (Linespec Locations): Document how "function" is interpreted in C++ and Ada. Document "-qualified". (Explicit Locations): Document how "-function" is interpreted in C++ and Ada. Document "-qualified".
2017-11-29 20:33:23 +01:00
}
/* Helper for cp_symbol_name_matches (i.e., symbol_name_matcher_ftype
implementation for symbol_name_match_type::WILD matching). Split
to a separate function for unit-testing convenience.
If SYMBOL_SEARCH_NAME has more scopes than LOOKUP_NAME, we try to
match ignoring the extra leading scopes of SYMBOL_SEARCH_NAME.
This allows conveniently setting breakpoints on functions/methods
inside any namespace/class without specifying the fully-qualified
name.
E.g., these match:
Introduce lookup_name_info and generalize Ada's FULL/WILD name matching Summary: - This is preparation for supporting wild name matching on C++ too. - This is also preparation for TAB-completion fixes. - Makes symbol name matching (think strcmp_iw) be based on a per-language method. - Merges completion and non-completion name comparison (think language_ops::la_get_symbol_name_cmp generalized). - Avoid re-hashing lookup name multiple times - Centralizes preparing a name for lookup (Ada name encoding / C++ Demangling), both completion and non-completion. - Fixes Ada latent bug with verbatim name matches in expressions - Makes ada-lang.c use common|symtab.c completion code a bit more. Ada's wild matching basically means that "(gdb) break foo" will find all methods named "foo" in all packages. Translating to C++, it's roughly the same as saying that "break klass::method" sets breakpoints on all "klass::method" methods of all classes, no matter the namespace. A following patch will teach GDB about fullname vs wild matching for C++ too. This patch is preparatory work to get there. Another idea here is to do symbol name matching based on the symbol language's algorithm. I.e., avoid dependency on current language set. This allows for example doing (gdb) b foo::bar< int > (<tab> and having gdb name match the C++ symbols correctly even if the current language is C or Assembly (or Rust, or Ada, or ...), which can easily happen if you step into an Assembly/C runtime library frame. By encapsulating all the information related to a lookup name in a class, we can also cache hash computation for a given language in the lookup name object, to avoid recomputing it over and over. Similarly, because we don't really know upfront which languages the lookup name will be matched against, for each language we store the lookup name transformed into a search name. E.g., for C++, that means demangling the name. But for Ada, it means encoding the name. This actually forces us to centralize all the different lookup name encoding in a central place, resulting in clearer code, IMO. See e.g., the new ada_lookup_name_info class. The lookup name -> symbol search name computation is also done only once per language. The old language->la_get_symbol_name_cmp / symbol_name_cmp_ftype are generalized to work with both completion, and normal symbol look up. At some point early on, I had separate completion vs non-completion language vector entry points, but a single method ends up being better IMO for simplifying things -- the more we merge the completion / non-completion name lookup code paths, the less changes for bugs causing completion vs normal lookup finding different symbols. The ada-lex.l change is necessary because when doing (gdb) p <UpperCase> then the name that is passed to write_ write_var_or_type -> ada_lookup_symbol_list misses the "<>", i.e., it's just "UpperCase", and we end up doing a wild match against "UpperCase" lowercased by ada_lookup_name_info's constructor. I.e., "uppercase" wouldn't ever match "UpperCase", and the symbol lookup fails. This wouldn't cause any regression in the testsuite, but I added a new test that would pass before the patch and fail after, if it weren't for that fix. This is latent bug that happens to go unnoticed because that particular path was inconsistent with the rest of Ada symbol lookup by not lowercasing the lookup name. Ada's symbol_completion_add is deleted, replaced by using common code's completion_list_add_name. To make the latter work for Ada, we needed to add a new output parameter, because Ada wants to return back a custom completion candidates that are not the symbol name. With this patch, minimal symbol demangled name hashing is made consistent with regular symbol hashing. I.e., it now goes via the language vector's search_name_hash method too, as I had suggested in a previous patch. dw2_expand_symtabs_matching / .gdb_index symbol names were a challenge. The problem is that we have no way to telling what is the language of each symbol name found in the index, until we expand the corresponding full symbol, which is off course what we're trying to avoid. Language information is simply not considered in the index format... Since the symbol name hashing and comparison routines are per-language, we now have a problem. The patch sorts this out by matching each name against all languages. This is inneficient, and indeed slows down completion several times. E.g., with: $ cat script.cmd set pagination off set $count = 0 while $count < 400 complete b string_prin printf "count = %d\n", $count set $count = $count + 1 end $ time gdb --batch -q ./gdb-with-index -ex "source script-string_printf.cmd" I get, before patch (-O2, x86-64): real 0m1.773s user 0m1.737s sys 0m0.040s While after patch (-O2, x86-64): real 0m9.843s user 0m9.482s sys 0m0.034s However, the following patch will optimize this, and will actually make this use case faster compared to the "before patch" above: real 0m1.321s user 0m1.285s sys 0m0.039s gdb/ChangeLog: 2017-11-08 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_encode): Rename to .. (ada_encode_1): ... this. Add throw_errors parameter and handle it. (ada_encode): Reimplement. (match_name): Delete, folded into full_name. (resolve_subexp): No longer pass the encoded name to ada_lookup_symbol_list. (should_use_wild_match): Delete. (name_match_type_from_name): New. (ada_lookup_simple_minsym): Use lookup_name_info and the language's symbol_name_matcher_ftype. (add_symbols_from_enclosing_procs, ada_add_local_symbols) (ada_add_block_renamings): Adjust to use lookup_name_info. (ada_lookup_name): New. (add_nonlocal_symbols, ada_add_all_symbols) (ada_lookup_symbol_list_worker, ada_lookup_symbol_list) (ada_iterate_over_symbols): Adjust to use lookup_name_info. (ada_name_for_lookup): Delete. (ada_lookup_encoded_symbol): Construct a verbatim name. (wild_match): Reverse sense of return type. Use bool. (full_match): Reverse sense of return type. Inline bits of old match_name here. (ada_add_block_symbols): Adjust to use lookup_name_info. (symbol_completion_match): Delete, folded into... (ada_lookup_name_info::matches): ... .this new method. (symbol_completion_add): Delete. (ada_collect_symbol_completion_matches): Add name_match_type parameter. Adjust to use lookup_name_info and completion_list_add_name. (get_var_value, ada_add_global_exceptions): Adjust to use lookup_name_info. (ada_get_symbol_name_cmp): Delete. (do_wild_match, do_full_match): New functions. (ada_lookup_name_info::ada_lookup_name_info): New method. (ada_symbol_name_matches, ada_get_symbol_name_matcher): New functions. (ada_language_defn): Install ada_get_symbol_name_matcher. * ada-lex.l (processId): If name starts with '<', copy it verbatim. * block.c (block_iter_match_step, block_iter_match_first) (block_iter_match_next, block_lookup_symbol) (block_lookup_symbol_primary, block_find_symbol): Adjust to use lookup_name_info. * block.h (block_iter_match_first, block_iter_match_next) (ALL_BLOCK_SYMBOLS_WITH_NAME): Adjust to use lookup_name_info. * c-lang.c (c_language_defn, cplus_language_defn) (asm_language_defn, minimal_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * completer.c (complete_files_symbols) (collect_explicit_location_matches, symbol_completer): Pass a symbol_name_match_type down. * completer.h (class completion_match, completion_match_result): New classes. (completion_tracker::reset_completion_match_result): New method. (completion_tracker::m_completion_match_result): New field. * cp-support.c (make_symbol_overload_list_block): Adjust to use lookup_name_info. (cp_fq_symbol_name_matches, cp_get_symbol_name_matcher): New functions. * cp-support.h (cp_get_symbol_name_matcher): New declaration. * d-lang.c: Adjust comments to refer to la_get_symbol_name_matcher. * dictionary.c (dict_vector) <iter_match_first, iter_match_next>: Adjust to use lookup_name_info. (dict_iter_match_first, dict_iter_match_next) (iter_match_first_hashed, iter_match_next_hashed) (iter_match_first_linear, iter_match_next_linear): Adjust to work with a lookup_name_info. * dictionary.h (dict_iter_match_first, dict_iter_match_next): Likewise. * dwarf2read.c (dw2_lookup_symbol): Adjust to use lookup_name_info. (dw2_map_matching_symbols): Adjust to use symbol_name_match_type. (gdb_index_symbol_name_matcher): New class. (dw2_expand_symtabs_matching) Adjust to use lookup_name_info and gdb_index_symbol_name_matcher. Accept a NULL symbol_matcher. * f-lang.c (f_collect_symbol_completion_matches): Adjust to work with a symbol_name_match_type. (f_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * go-lang.c (go_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * language.c (default_symbol_name_matcher) (language_get_symbol_name_matcher): New functions. (unknown_language_defn, auto_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * language.h (symbol_name_cmp_ftype): Delete. (language_defn) <la_collect_symbol_completion_matches>: Add match type parameter. <la_get_symbol_name_cmp>: Delete field. <la_get_symbol_name_matcher>: New field. <la_iterate_over_symbols>: Adjust to use lookup_name_info. (default_symbol_name_matcher, language_get_symbol_name_matcher): Declare. * linespec.c (iterate_over_all_matching_symtabs) (iterate_over_file_blocks): Adjust to use lookup_name_info. (find_methods): Add language parameter, and use lookup_name_info and the language's symbol_name_matcher_ftype. (linespec_complete_function): Adjust. (lookup_prefix_sym): Use lookup_name_info. (add_all_symbol_names_from_pspace): Adjust. (find_superclass_methods): Add language parameter and pass it down. (find_method): Pass symbol language down. (find_linespec_symbols): Don't demangle or Ada encode here. (search_minsyms_for_name): Add lookup_name_info parameter. (add_matching_symbols_to_info): Add name_match_type parameter. Use lookup_name_info. * m2-lang.c (m2_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * minsyms.c: Include <algorithm>. (add_minsym_to_demangled_hash_table): Remove table parameter and add objfile parameter. Use search_name_hash, and add language to demangled languages vector. (struct found_minimal_symbols): New struct. (lookup_minimal_symbol_mangled, lookup_minimal_symbol_demangled): New functions. (lookup_minimal_symbol): Adjust to use them. Don't canonicalize input names here. Use lookup_name_info instead. Lookup up demangled names once for each language in the demangled names vector. (iterate_over_minimal_symbols): Use lookup_name_info. Lookup up demangled names once for each language in the demangled names vector. (build_minimal_symbol_hash_tables): Adjust. * minsyms.h (iterate_over_minimal_symbols): Adjust to pass down a lookup_name_info. * objc-lang.c (objc_language_defn): Adjust comment to refer to la_get_symbol_name_matcher. * objfiles.h: Include <vector>. (objfile_per_bfd_storage) <demangled_hash_languages>: New field. * opencl-lang.c (opencl_language_defn): Adjust comment to refer to la_get_symbol_name_matcher. * p-lang.c (pascal_language_defn): Adjust comment to refer to la_get_symbol_name_matcher. * psymtab.c (psym_lookup_symbol): Use lookup_name_info. (match_partial_symbol): Use symbol_name_match_type, lookup_name_info and psymbol_name_matches. (lookup_partial_symbol): Use lookup_name_info. (map_block): Use symbol_name_match_type and lookup_name_info. (psym_map_matching_symbols): Use symbol_name_match_type. (psymbol_name_matches): New. (recursively_search_psymtabs): Use lookup_name_info and psymbol_name_matches. Rename 'kind' parameter to 'domain'. (psym_expand_symtabs_matching): Use lookup_name_info. Rename 'kind' parameter to 'domain'. * rust-lang.c (rust_language_defn): Adjust comment to refer to la_get_symbol_name_matcher. * symfile-debug.c (debug_qf_map_matching_symbols) (debug_qf_map_matching_symbols): Use symbol_name_match_type. (debug_qf_expand_symtabs_matching): Use lookup_name_info. * symfile.c (expand_symtabs_matching): Use lookup_name_info. * symfile.h (quick_symbol_functions) <map_matching_symbols>: Adjust to use symbol_name_match_type. <expand_symtabs_matching>: Adjust to use lookup_name_info. (expand_symtabs_matching): Adjust to use lookup_name_info. * symmisc.c (maintenance_expand_symtabs): Use lookup_name_info::match_any (). * symtab.c (symbol_matches_search_name): New. (eq_symbol_entry): Adjust to use lookup_name_info and the language's matcher. (demangle_for_lookup_info::demangle_for_lookup_info): New. (lookup_name_info::match_any): New. (iterate_over_symbols, search_symbols): Use lookup_name_info. (compare_symbol_name): Add language, lookup_name_info and completion_match_result parameters, and use them. (completion_list_add_name): Make extern. Add language and lookup_name_info parameters. Use them. (completion_list_add_symbol, completion_list_add_msymbol) (completion_list_objc_symbol): Add lookup_name_info parameters and adjust. Pass down language. (completion_list_add_fields): Add lookup_name_info parameters and adjust. Pass down language. (add_symtab_completions): Add lookup_name_info parameters and adjust. (default_collect_symbol_completion_matches_break_on): Add name_match_type parameter, and use it. Use lookup_name_info. (default_collect_symbol_completion_matches) (collect_symbol_completion_matches): Add name_match_type parameter, and pass it down. (collect_symbol_completion_matches_type): Adjust. (collect_file_symbol_completion_matches): Add name_match_type parameter, and use lookup_name_info. * symtab.h: Include <string> and "common/gdb_optional.h". (enum class symbol_name_match_type): New. (class ada_lookup_name_info): New. (struct demangle_for_lookup_info): New. (class lookup_name_info): New. (symbol_name_matcher_ftype): New. (SYMBOL_MATCHES_SEARCH_NAME): Use symbol_matches_search_name. (symbol_matches_search_name): Declare. (MSYMBOL_MATCHES_SEARCH_NAME): Delete. (default_collect_symbol_completion_matches) (collect_symbol_completion_matches) (collect_file_symbol_completion_matches): Add name_match_type parameter. (iterate_over_symbols): Use lookup_name_info. (completion_list_add_name): Declare. * utils.c (enum class strncmp_iw_mode): Moved to utils.h. (strncmp_iw_with_mode): Now extern. * utils.h (enum class strncmp_iw_mode): Moved from utils.c. (strncmp_iw_with_mode): Declare. gdb/testsuite/ChangeLog: 2017-11-08 Pedro Alves <palves@redhat.com> * gdb.ada/complete.exp (p <Exported_Capitalized>): New test. (p Exported_Capitalized): New test. (p exported_capitalized): New test.
2017-11-08 15:22:32 +01:00
Make "break foo" find "A::foo", A::B::foo", etc. [C++ and wild matching] This patch teaches GDB about setting breakpoints in all scopes (namespaces and classes) by default. Here's a contrived example: (gdb) b func<tab> (anonymous namespace)::A::function() Bn::(anonymous namespace)::B::function() function(int, int) (anonymous namespace)::B::function() Bn::(anonymous namespace)::function() gdb::(anonymous namespace)::A::function() (anonymous namespace)::B::function() const Bn::(anonymous namespace)::function(int, int) gdb::(anonymous namespace)::function() (anonymous namespace)::function() Bn::B::func() gdb::(anonymous namespace)::function(int, int) (anonymous namespace)::function(int, int) Bn::B::function() gdb::A::func() A::func() Bn::func() gdb::A::function() A::function() Bn::function() gdb::func() B::func() Bn::function(int, int) gdb::function() B::function() Bn::function(long) gdb::function(int, int) B::function() const func() gdb::function(long) B::function_const() const function() (gdb) b function Breakpoint 1 at 0x4005ce: function. (26 locations) (gdb) b B::function<tab> (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() (gdb) b B::function Breakpoint 1 at 0x40072c: B::function. (6 locations) To get back the original behavior of interpreting the function name as a fully-qualified name, you can use the new "-qualified" (or "-q") option/flag (added by this commit). For example: (gdb) b B::function (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() vs: (gdb) b -qualified B::function B::function() B::function() const B::function_const() const I've chosen "-qualified" / "-q" because "-f" (for "full" or "fully-qualified") is already taken for "-function". Note: the "-qualified" option works with both linespecs and explicit locations. I.e., these are equivalent: (gdb) b -q func (gdb) b -q -f func and so are these: (gdb) b -q filename.cc:func (gdb) b -q -s filename.cc -f func (gdb) b -s filename.cc -q -f func (gdb) b -s filename.cc -f func -q To better understand why I consider wild matching the better default, consider what happens when we get to the point when _all_ of GDB is wrapped under "namespace gdb {}". I have a patch series that does that, and when I started debugging that GDB, I immediately became frustrated. You'd have to write "b gdb::internal_error", "b gdb::foo", "b gdb::bar", etc. etc., which gets annoying pretty quickly. OTOH, consider how this makes it very easy to set breakpoints in classes wrapped in anonymous namespaces. You just don't think of them, GDB finds the symbols for you automatically. (At the Cauldron a couple months ago, several people told me that they run into a similar issue when debugging other C++ projects. One example was when debugging LLVM, which puts all its code under the "llvm" namespace.) Implementation-wise, what the patch does is: - makes C++ symbol name hashing only consider the last component of a symbol name. (so that we can look up symbol names by last-component name only). - adds a C++ symbol name matcher for symbol_name_match_type::WILD, which ignores missing leading specifiers / components. - adjusts a few preexisting testsuite tests to use "-qualified" when they mean it. - adds new testsuite tests. - adds unit tests. Grows the gdb.linespec/ tests like this: -# of expected passes 7823 +# of expected passes 8977 gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * NEWS: Mention that breakpoints on C++ functions are now set on on all namespaces/classes by default, and mention "break -qualified". * ax-gdb.c (agent_command_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * breakpoint.c (parse_breakpoint_sals): Adjust to get_linespec_location's return type change. (strace_marker_create_sals_from_location): Adjust to pass a symbol_name_match_type to new_linespec_location. (strace_marker_decode_location): Adjust to get_linespec_location's return type change. (strace_command): Adjust to pass a symbol_name_match_type to new_linespec_location. (LOCATION_HELP_STRING): Add paragraph about wildmatching, and mention "-qualified". * c-lang.c (cplus_language_defn): Install cp_search_name_hash. * completer.c (explicit_location_match_type::MATCH_QUALIFIED): New enumerator. (complete_address_and_linespec_locations): New parameter 'match_type'. Pass it down. (explicit_options): Add "-qualified". (collect_explicit_location_matches): Pass the requested match type to the linespec completers. Handle MATCH_QUALIFIED. (location_completer): Handle "-qualified" combined with linespecs. * cp-support.c (cp_search_name_hash): New. (cp_symbol_name_matches_1): Implement wild matching for C++. (cp_fq_symbol_name_matches): Reimplement. (cp_get_symbol_name_matcher): Return different matchers depending on the lookup name's match type. (selftests::test_cp_symbol_name_matches): Add wild matching tests. * cp-support.h (cp_search_name_hash): New declaration. * dwarf2read.c (selftests::dw2_expand_symtabs_matching::test_symbols): Add symbols. (test_dw2_expand_symtabs_matching_symbol): Add wild matching tests. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Adjust to pass a symbol_name_match_type to new_linespec_location. * linespec.c (linespec_parse_basic): Lookup function symbols using the parser's symbol name match type. (convert_explicit_location_to_linespec): New symbol_name_match_type parameter. Pass it down to find_linespec_symbols. (convert_explicit_location_to_sals): Pass the location's name match type to convert_explicit_location_to_linespec. (parse_linespec): New match_type parameter. Save it in the parser. (linespec_parser_new): Default to symbol_name_match_type::WILD. (linespec_complete_function): New symbol_name_match_type parameter. Use it. (complete_linespec_component): Pass down the parser's recorded name match type. (linespec_complete_label): New symbol_name_match_type parameter. Use it. (linespec_complete): New symbol_name_match_type parameter. Save it in the parser and pass it down. Adjust to get_linespec_location's prototype change. (find_function_symbols, find_linespec_symbols): New symbol_name_match_type parameter. Pass it down instead of assuming symbol_name_match_type::WILD. * linespec.h (linespec_complete, linespec_complete_function) (linespec_complete_label): New symbol_name_match_type parameter. * location.c (event_location::linespec_location): Now a struct linespec_location. (EL_LINESPEC): Adjust. (initialize_explicit_location): Default to symbol_name_match_type::WILD. (new_linespec_location): New symbol_name_match_type parameter. Record it in the location. (get_linespec_location): Now returns a struct linespec_location. (new_explicit_location): Also copy func_name_match_type. (explicit_to_string_internal) (string_to_explicit_location): Handle "-qualified". (copy_event_location): Adjust to LINESPEC_LOCATION type change. Copy symbol_name_match_type fields. (event_location_deleter::operator()): Adjust to LINESPEC_LOCATION type change. (event_location_to_string): Adjust to LINESPEC_LOCATION type change. Handle "-qualfied". (string_to_explicit_location): Handle "-qualified". (string_to_event_location_basic): New symbol_name_match_type parameter. Pass it down. (string_to_event_location): Handle "-qualified". * location.h (struct linespec_location): New. (explicit_location::func_name_match_type): New field. (new_linespec_location): Now returns a const linespec_location *. (string_to_event_location_basic): New symbol_name_match_type parameter. (explicit_completion_info::saw_explicit_location_option): New field. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * python/py-breakpoint.c (bppy_init): Likewise. * python/python.c (gdbpy_decode_line): Likewise. gdb/testsuite/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.base/langs.exp: Use -qualified. * gdb.cp/meth-typedefs.exp: Use -qualified, and add tests without it. * gdb.cp/namespace.exp: Use -qualified. * gdb.linespec/cpcompletion.exp (overload-2, fqn, fqn-2) (overload-3, template-overload, template-ret-type, const-overload) (const-overload-quoted, anon-ns, ambiguous-prefix): New procedures. (test_driver): Call them. * gdb.cp/save-bp-qualified.cc: New. * gdb.cp/save-bp-qualified.exp: New. * gdb.linespec/explicit.exp: Test -qualified. * lib/completion-support.exp (completion::explicit_opts_list): Add "-qualified". * lib/gdb.exp (gdb_breakpoint): Handle "qualified". gdb/doc/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.texinfo (Linespec Locations): Document how "function" is interpreted in C++ and Ada. Document "-qualified". (Explicit Locations): Document how "-function" is interpreted in C++ and Ada. Document "-qualified".
2017-11-29 20:33:23 +01:00
[symbol search name] [lookup name]
foo::bar::func foo::bar::func
foo::bar::func bar::func
foo::bar::func func
While these don't:
[symbol search name] [lookup name]
foo::zbar::func bar::func
foo::bar::func foo::func
See more examples in the test_cp_symbol_name_matches selftest
function below.
Make strcmp_iw NOT ignore whitespace in the middle of tokens currently "b func tion" manages to set a breakpoint at "function" ! All these years I had never noticed this, but now that the linespec completer actually works, this easily happens by accident, with: "b func t<tab>" expecting to get "thread", but getting instead: "b func tion" ... Also, this: "b rettypefunc<int>" manages to set a breakpoint on "rettype func<int>()". These things happen due to strcmp_iw "magic". Fix it by teaching strcmp_iw about when can it skip whitespace. This required handling user-defined operators, and scope operators, complicating the code a bit, unfortunately. I added unit tests for all the corner cases I stumbled on, as I was developing this, and then in the end wrote a testsuite testcase covering many of the same things and more (to be added later). gdb/ChangeLog: 2017-11-24 Pedro Alves <palves@redhat.com> * cp-support.c (cp_symbol_name_matches_1): New, factored out from cp_fq_symbol_name_matches. Pass language_cplus to strncmp_with_mode. (cp_fq_symbol_name_matches): Call cp_symbol_name_matches_1. (selftests::test_cp_symbol_name_cmp): New. (_initialize_cp_support): Register "cp_symbol_name_matches" selftests. * language.c (default_symbol_name_matcher): Pass language_minimal to strncmp_iw_with_mode. * utils.c: Include "cp-support.h" and <algorithm>. (valid_identifier_name_char, cp_skip_operator_token, skip_ws) (cp_is_operator): New functions. (strncmp_iw_with_mode): Use them. Add language parameter. Don't skip whitespace in the symbol name when the lookup name doesn't have spaces, and vice versa. (strncmp_iw, strcmp_iw): Pass language to strncmp_iw_with_mode. * utils.h (strncmp_iw_with_mode): Add language parameter.
2017-11-25 00:30:04 +01:00
See symbol_name_matcher_ftype for description of SYMBOL_SEARCH_NAME
and COMP_MATCH_RES.
LOOKUP_NAME/LOOKUP_NAME_LEN is the name we're looking up.
See strncmp_iw_with_mode for description of MODE.
*/
static bool
cp_symbol_name_matches_1 (const char *symbol_search_name,
const char *lookup_name,
size_t lookup_name_len,
strncmp_iw_mode mode,
Handle custom completion match prefix / LCD A following patch will add support for wild matching for C++ symbols, making completing on "b push_ba" on a C++ program complete to std::vector<...>::push_back, std::string::push_back etc., like: (gdb) b push_ba[TAB] std::vector<...>::push_back(....) std::string<...>::push_back(....) Currently, we compute the "lowest common denominator" between all completion candidates (what the input line is adjusted to) as the common prefix of all matches. That's problematic with wild matching as above, as then we'd end up with TAB changing the input line to "b std::", losing the original input, like: (gdb) b push_ba[TAB] std::vector<...>::push_back(....) std::string<...>::push_back(....) (gdb) b std:: while obviously we'd want it to adjust itself to "b push_back(" instead: (gdb) b push_ba[TAB] std::vector<...>::push_back(....) std::string<...>::push_back(....) (gdb) b push_back( This patch adds the core code necessary to support this, though nothing really makes use of it yet in this patch. gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_lookup_name_info::matches): Change type of parameter from completion_match to completion_match_result. Adjust. (do_wild_match, do_full_match, ada_symbol_name_matches): Likewise. * completer.c (completion_tracker::maybe_add_completion): Add match_for_lcd parameter and use it. (completion_tracker::add_completion): Likewise. * completer.h (class completion_match_for_lcd): New class. (completion_match_result::match_for_lcd): New field. (completion_match_result::set_match): New method. (completion_tracker): Add comments. (completion_tracker::add_completion): Add match_for_lcd parameter. (completion_tracker::reset_completion_match_result): Reset match_for_lcd too. (completion_tracker::maybe_add_completion): Add match_for_lcd parameter. (completion_tracker::m_lowest_common_denominator_unique): Extend comments. * cp-support.c (cp_symbol_name_matches_1) (cp_fq_symbol_name_matches): Change type of parameter from completion_match to completion_match_result. Adjust. * language.c (default_symbol_name_matcher): Change type of parameter from completion_match to completion_match_result. Adjust. * language.h (completion_match_for_lcd): Forward declare. (default_symbol_name_matcher): Change type of parameter from completion_match to completion_match_result. * symtab.c (compare_symbol_name): Adjust. (completion_list_add_name): Pass the match_for_lcd to the tracker. * symtab.h (ada_lookup_name_info::matches): Change type of parameter from completion_match to completion_match_result. (symbol_name_matcher_ftype): Likewise, and update comments.
2017-11-29 20:33:23 +01:00
completion_match_result *comp_match_res)
Make strcmp_iw NOT ignore whitespace in the middle of tokens currently "b func tion" manages to set a breakpoint at "function" ! All these years I had never noticed this, but now that the linespec completer actually works, this easily happens by accident, with: "b func t<tab>" expecting to get "thread", but getting instead: "b func tion" ... Also, this: "b rettypefunc<int>" manages to set a breakpoint on "rettype func<int>()". These things happen due to strcmp_iw "magic". Fix it by teaching strcmp_iw about when can it skip whitespace. This required handling user-defined operators, and scope operators, complicating the code a bit, unfortunately. I added unit tests for all the corner cases I stumbled on, as I was developing this, and then in the end wrote a testsuite testcase covering many of the same things and more (to be added later). gdb/ChangeLog: 2017-11-24 Pedro Alves <palves@redhat.com> * cp-support.c (cp_symbol_name_matches_1): New, factored out from cp_fq_symbol_name_matches. Pass language_cplus to strncmp_with_mode. (cp_fq_symbol_name_matches): Call cp_symbol_name_matches_1. (selftests::test_cp_symbol_name_cmp): New. (_initialize_cp_support): Register "cp_symbol_name_matches" selftests. * language.c (default_symbol_name_matcher): Pass language_minimal to strncmp_iw_with_mode. * utils.c: Include "cp-support.h" and <algorithm>. (valid_identifier_name_char, cp_skip_operator_token, skip_ws) (cp_is_operator): New functions. (strncmp_iw_with_mode): Use them. Add language parameter. Don't skip whitespace in the symbol name when the lookup name doesn't have spaces, and vice versa. (strncmp_iw, strcmp_iw): Pass language to strncmp_iw_with_mode. * utils.h (strncmp_iw_with_mode): Add language parameter.
2017-11-25 00:30:04 +01:00
{
Make "break foo" find "A::foo", A::B::foo", etc. [C++ and wild matching] This patch teaches GDB about setting breakpoints in all scopes (namespaces and classes) by default. Here's a contrived example: (gdb) b func<tab> (anonymous namespace)::A::function() Bn::(anonymous namespace)::B::function() function(int, int) (anonymous namespace)::B::function() Bn::(anonymous namespace)::function() gdb::(anonymous namespace)::A::function() (anonymous namespace)::B::function() const Bn::(anonymous namespace)::function(int, int) gdb::(anonymous namespace)::function() (anonymous namespace)::function() Bn::B::func() gdb::(anonymous namespace)::function(int, int) (anonymous namespace)::function(int, int) Bn::B::function() gdb::A::func() A::func() Bn::func() gdb::A::function() A::function() Bn::function() gdb::func() B::func() Bn::function(int, int) gdb::function() B::function() Bn::function(long) gdb::function(int, int) B::function() const func() gdb::function(long) B::function_const() const function() (gdb) b function Breakpoint 1 at 0x4005ce: function. (26 locations) (gdb) b B::function<tab> (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() (gdb) b B::function Breakpoint 1 at 0x40072c: B::function. (6 locations) To get back the original behavior of interpreting the function name as a fully-qualified name, you can use the new "-qualified" (or "-q") option/flag (added by this commit). For example: (gdb) b B::function (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() vs: (gdb) b -qualified B::function B::function() B::function() const B::function_const() const I've chosen "-qualified" / "-q" because "-f" (for "full" or "fully-qualified") is already taken for "-function". Note: the "-qualified" option works with both linespecs and explicit locations. I.e., these are equivalent: (gdb) b -q func (gdb) b -q -f func and so are these: (gdb) b -q filename.cc:func (gdb) b -q -s filename.cc -f func (gdb) b -s filename.cc -q -f func (gdb) b -s filename.cc -f func -q To better understand why I consider wild matching the better default, consider what happens when we get to the point when _all_ of GDB is wrapped under "namespace gdb {}". I have a patch series that does that, and when I started debugging that GDB, I immediately became frustrated. You'd have to write "b gdb::internal_error", "b gdb::foo", "b gdb::bar", etc. etc., which gets annoying pretty quickly. OTOH, consider how this makes it very easy to set breakpoints in classes wrapped in anonymous namespaces. You just don't think of them, GDB finds the symbols for you automatically. (At the Cauldron a couple months ago, several people told me that they run into a similar issue when debugging other C++ projects. One example was when debugging LLVM, which puts all its code under the "llvm" namespace.) Implementation-wise, what the patch does is: - makes C++ symbol name hashing only consider the last component of a symbol name. (so that we can look up symbol names by last-component name only). - adds a C++ symbol name matcher for symbol_name_match_type::WILD, which ignores missing leading specifiers / components. - adjusts a few preexisting testsuite tests to use "-qualified" when they mean it. - adds new testsuite tests. - adds unit tests. Grows the gdb.linespec/ tests like this: -# of expected passes 7823 +# of expected passes 8977 gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * NEWS: Mention that breakpoints on C++ functions are now set on on all namespaces/classes by default, and mention "break -qualified". * ax-gdb.c (agent_command_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * breakpoint.c (parse_breakpoint_sals): Adjust to get_linespec_location's return type change. (strace_marker_create_sals_from_location): Adjust to pass a symbol_name_match_type to new_linespec_location. (strace_marker_decode_location): Adjust to get_linespec_location's return type change. (strace_command): Adjust to pass a symbol_name_match_type to new_linespec_location. (LOCATION_HELP_STRING): Add paragraph about wildmatching, and mention "-qualified". * c-lang.c (cplus_language_defn): Install cp_search_name_hash. * completer.c (explicit_location_match_type::MATCH_QUALIFIED): New enumerator. (complete_address_and_linespec_locations): New parameter 'match_type'. Pass it down. (explicit_options): Add "-qualified". (collect_explicit_location_matches): Pass the requested match type to the linespec completers. Handle MATCH_QUALIFIED. (location_completer): Handle "-qualified" combined with linespecs. * cp-support.c (cp_search_name_hash): New. (cp_symbol_name_matches_1): Implement wild matching for C++. (cp_fq_symbol_name_matches): Reimplement. (cp_get_symbol_name_matcher): Return different matchers depending on the lookup name's match type. (selftests::test_cp_symbol_name_matches): Add wild matching tests. * cp-support.h (cp_search_name_hash): New declaration. * dwarf2read.c (selftests::dw2_expand_symtabs_matching::test_symbols): Add symbols. (test_dw2_expand_symtabs_matching_symbol): Add wild matching tests. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Adjust to pass a symbol_name_match_type to new_linespec_location. * linespec.c (linespec_parse_basic): Lookup function symbols using the parser's symbol name match type. (convert_explicit_location_to_linespec): New symbol_name_match_type parameter. Pass it down to find_linespec_symbols. (convert_explicit_location_to_sals): Pass the location's name match type to convert_explicit_location_to_linespec. (parse_linespec): New match_type parameter. Save it in the parser. (linespec_parser_new): Default to symbol_name_match_type::WILD. (linespec_complete_function): New symbol_name_match_type parameter. Use it. (complete_linespec_component): Pass down the parser's recorded name match type. (linespec_complete_label): New symbol_name_match_type parameter. Use it. (linespec_complete): New symbol_name_match_type parameter. Save it in the parser and pass it down. Adjust to get_linespec_location's prototype change. (find_function_symbols, find_linespec_symbols): New symbol_name_match_type parameter. Pass it down instead of assuming symbol_name_match_type::WILD. * linespec.h (linespec_complete, linespec_complete_function) (linespec_complete_label): New symbol_name_match_type parameter. * location.c (event_location::linespec_location): Now a struct linespec_location. (EL_LINESPEC): Adjust. (initialize_explicit_location): Default to symbol_name_match_type::WILD. (new_linespec_location): New symbol_name_match_type parameter. Record it in the location. (get_linespec_location): Now returns a struct linespec_location. (new_explicit_location): Also copy func_name_match_type. (explicit_to_string_internal) (string_to_explicit_location): Handle "-qualified". (copy_event_location): Adjust to LINESPEC_LOCATION type change. Copy symbol_name_match_type fields. (event_location_deleter::operator()): Adjust to LINESPEC_LOCATION type change. (event_location_to_string): Adjust to LINESPEC_LOCATION type change. Handle "-qualfied". (string_to_explicit_location): Handle "-qualified". (string_to_event_location_basic): New symbol_name_match_type parameter. Pass it down. (string_to_event_location): Handle "-qualified". * location.h (struct linespec_location): New. (explicit_location::func_name_match_type): New field. (new_linespec_location): Now returns a const linespec_location *. (string_to_event_location_basic): New symbol_name_match_type parameter. (explicit_completion_info::saw_explicit_location_option): New field. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * python/py-breakpoint.c (bppy_init): Likewise. * python/python.c (gdbpy_decode_line): Likewise. gdb/testsuite/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.base/langs.exp: Use -qualified. * gdb.cp/meth-typedefs.exp: Use -qualified, and add tests without it. * gdb.cp/namespace.exp: Use -qualified. * gdb.linespec/cpcompletion.exp (overload-2, fqn, fqn-2) (overload-3, template-overload, template-ret-type, const-overload) (const-overload-quoted, anon-ns, ambiguous-prefix): New procedures. (test_driver): Call them. * gdb.cp/save-bp-qualified.cc: New. * gdb.cp/save-bp-qualified.exp: New. * gdb.linespec/explicit.exp: Test -qualified. * lib/completion-support.exp (completion::explicit_opts_list): Add "-qualified". * lib/gdb.exp (gdb_breakpoint): Handle "qualified". gdb/doc/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.texinfo (Linespec Locations): Document how "function" is interpreted in C++ and Ada. Document "-qualified". (Explicit Locations): Document how "-function" is interpreted in C++ and Ada. Document "-qualified".
2017-11-29 20:33:23 +01:00
const char *sname = symbol_search_name;
Breakpoints in symbols with ABI tags (PR c++/19436) Trying to set a breakpoint in a function with an ABI tag does not work currently. E.g., debugging gdb itself, we see this with the "string_printf" function: (top-gdb) b string_print [TAB] (top-gdb) b string_printf[abi:cxx11](char const*, ...) [RET] No source file named string_printf[abi. Make breakpoint pending on future shared library load? (y or [n]) Quoting doesn't help: (top-gdb) b 'string_printf[abi:cxx11]'(char const*, ...) malformed linespec error: unexpected string, "(char const*, ...)" (top-gdb) b 'string_printf[abi:cxx11](char const*, ...)' No source file named string_printf[abi. Make breakpoint pending on future shared library load? (y or [n]) n This patch fixes this, and takes it a bit further. The actual symbol name as demangled by libiberty's demangler is really string_printf[abi:cxx11](char const*, ...) however, this patch makes it possible to set the breakpoint with string_printf(char const*, ...) too. I.e., ignoring the ABI tag. And to match, it teaches the completer to complete the symbol name without the ABI tag, i.e., "string_pri<TAB>" -> "string_printf(char const*, ...)" If however, you really want to break on a symbol with the tag, then you simply start writing the tag, and GDB will preserve it, like: "string_printf[a<TAB>" -> "string_printf[abi:cxx11](char const*, ...)" Grows the gdb.linespec/ tests like this: -# of expected passes 8977 +# of expected passes 9176 gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> PR c++/19436 * NEWS: Mention setting breakpoints on functions with C++ ABI tags. * completer.h (completion_match_for_lcd) <match, mark_ignored_range>: New methods. <finish>: Consider ignored ranges. <clear>: Clear ignored ranges. <m_ignored_ranges, m_finished_storage>: New fields. * cp-support.c (cp_search_name_hash): Ignore ABI tags. (cp_symbol_name_matches_1, cp_fq_symbol_name_matches): Pass the completion_match_for_lcd pointer to strncmp_iw_with_mode. (test_cp_symbol_name_cmp): Add [abi:...] tags unit tests. * language.c (default_symbol_name_matcher): Pass the completion_match_for_lcd pointer to strncmp_iw_with_mode. * linespec.c (linespec_lexer_lex_string): Don't tokenize ABI tags. * utils.c (skip_abi_tag): New function. (strncmp_iw_with_mode): Add completion_match_for_lcd parameter. Handle ABI tags. * utils.h (strncmp_iw_with_mode): Add completion_match_for_lcd parameter. gdb/testsuite/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> PR c++/19436 * gdb.linespec/cpls-abi-tag.cc: New file. * gdb.linespec/cpls-abi-tag.exp: New file. gdb/doc/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> PR c++/19436 * gdb.texinfo (Debugging C Plus Plus): Document setting breakpoints in functions with ABI tags.
2017-11-29 20:33:24 +01:00
completion_match_for_lcd *match_for_lcd
= (comp_match_res != NULL ? &comp_match_res->match_for_lcd : NULL);
Make "break foo" find "A::foo", A::B::foo", etc. [C++ and wild matching] This patch teaches GDB about setting breakpoints in all scopes (namespaces and classes) by default. Here's a contrived example: (gdb) b func<tab> (anonymous namespace)::A::function() Bn::(anonymous namespace)::B::function() function(int, int) (anonymous namespace)::B::function() Bn::(anonymous namespace)::function() gdb::(anonymous namespace)::A::function() (anonymous namespace)::B::function() const Bn::(anonymous namespace)::function(int, int) gdb::(anonymous namespace)::function() (anonymous namespace)::function() Bn::B::func() gdb::(anonymous namespace)::function(int, int) (anonymous namespace)::function(int, int) Bn::B::function() gdb::A::func() A::func() Bn::func() gdb::A::function() A::function() Bn::function() gdb::func() B::func() Bn::function(int, int) gdb::function() B::function() Bn::function(long) gdb::function(int, int) B::function() const func() gdb::function(long) B::function_const() const function() (gdb) b function Breakpoint 1 at 0x4005ce: function. (26 locations) (gdb) b B::function<tab> (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() (gdb) b B::function Breakpoint 1 at 0x40072c: B::function. (6 locations) To get back the original behavior of interpreting the function name as a fully-qualified name, you can use the new "-qualified" (or "-q") option/flag (added by this commit). For example: (gdb) b B::function (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() vs: (gdb) b -qualified B::function B::function() B::function() const B::function_const() const I've chosen "-qualified" / "-q" because "-f" (for "full" or "fully-qualified") is already taken for "-function". Note: the "-qualified" option works with both linespecs and explicit locations. I.e., these are equivalent: (gdb) b -q func (gdb) b -q -f func and so are these: (gdb) b -q filename.cc:func (gdb) b -q -s filename.cc -f func (gdb) b -s filename.cc -q -f func (gdb) b -s filename.cc -f func -q To better understand why I consider wild matching the better default, consider what happens when we get to the point when _all_ of GDB is wrapped under "namespace gdb {}". I have a patch series that does that, and when I started debugging that GDB, I immediately became frustrated. You'd have to write "b gdb::internal_error", "b gdb::foo", "b gdb::bar", etc. etc., which gets annoying pretty quickly. OTOH, consider how this makes it very easy to set breakpoints in classes wrapped in anonymous namespaces. You just don't think of them, GDB finds the symbols for you automatically. (At the Cauldron a couple months ago, several people told me that they run into a similar issue when debugging other C++ projects. One example was when debugging LLVM, which puts all its code under the "llvm" namespace.) Implementation-wise, what the patch does is: - makes C++ symbol name hashing only consider the last component of a symbol name. (so that we can look up symbol names by last-component name only). - adds a C++ symbol name matcher for symbol_name_match_type::WILD, which ignores missing leading specifiers / components. - adjusts a few preexisting testsuite tests to use "-qualified" when they mean it. - adds new testsuite tests. - adds unit tests. Grows the gdb.linespec/ tests like this: -# of expected passes 7823 +# of expected passes 8977 gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * NEWS: Mention that breakpoints on C++ functions are now set on on all namespaces/classes by default, and mention "break -qualified". * ax-gdb.c (agent_command_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * breakpoint.c (parse_breakpoint_sals): Adjust to get_linespec_location's return type change. (strace_marker_create_sals_from_location): Adjust to pass a symbol_name_match_type to new_linespec_location. (strace_marker_decode_location): Adjust to get_linespec_location's return type change. (strace_command): Adjust to pass a symbol_name_match_type to new_linespec_location. (LOCATION_HELP_STRING): Add paragraph about wildmatching, and mention "-qualified". * c-lang.c (cplus_language_defn): Install cp_search_name_hash. * completer.c (explicit_location_match_type::MATCH_QUALIFIED): New enumerator. (complete_address_and_linespec_locations): New parameter 'match_type'. Pass it down. (explicit_options): Add "-qualified". (collect_explicit_location_matches): Pass the requested match type to the linespec completers. Handle MATCH_QUALIFIED. (location_completer): Handle "-qualified" combined with linespecs. * cp-support.c (cp_search_name_hash): New. (cp_symbol_name_matches_1): Implement wild matching for C++. (cp_fq_symbol_name_matches): Reimplement. (cp_get_symbol_name_matcher): Return different matchers depending on the lookup name's match type. (selftests::test_cp_symbol_name_matches): Add wild matching tests. * cp-support.h (cp_search_name_hash): New declaration. * dwarf2read.c (selftests::dw2_expand_symtabs_matching::test_symbols): Add symbols. (test_dw2_expand_symtabs_matching_symbol): Add wild matching tests. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Adjust to pass a symbol_name_match_type to new_linespec_location. * linespec.c (linespec_parse_basic): Lookup function symbols using the parser's symbol name match type. (convert_explicit_location_to_linespec): New symbol_name_match_type parameter. Pass it down to find_linespec_symbols. (convert_explicit_location_to_sals): Pass the location's name match type to convert_explicit_location_to_linespec. (parse_linespec): New match_type parameter. Save it in the parser. (linespec_parser_new): Default to symbol_name_match_type::WILD. (linespec_complete_function): New symbol_name_match_type parameter. Use it. (complete_linespec_component): Pass down the parser's recorded name match type. (linespec_complete_label): New symbol_name_match_type parameter. Use it. (linespec_complete): New symbol_name_match_type parameter. Save it in the parser and pass it down. Adjust to get_linespec_location's prototype change. (find_function_symbols, find_linespec_symbols): New symbol_name_match_type parameter. Pass it down instead of assuming symbol_name_match_type::WILD. * linespec.h (linespec_complete, linespec_complete_function) (linespec_complete_label): New symbol_name_match_type parameter. * location.c (event_location::linespec_location): Now a struct linespec_location. (EL_LINESPEC): Adjust. (initialize_explicit_location): Default to symbol_name_match_type::WILD. (new_linespec_location): New symbol_name_match_type parameter. Record it in the location. (get_linespec_location): Now returns a struct linespec_location. (new_explicit_location): Also copy func_name_match_type. (explicit_to_string_internal) (string_to_explicit_location): Handle "-qualified". (copy_event_location): Adjust to LINESPEC_LOCATION type change. Copy symbol_name_match_type fields. (event_location_deleter::operator()): Adjust to LINESPEC_LOCATION type change. (event_location_to_string): Adjust to LINESPEC_LOCATION type change. Handle "-qualfied". (string_to_explicit_location): Handle "-qualified". (string_to_event_location_basic): New symbol_name_match_type parameter. Pass it down. (string_to_event_location): Handle "-qualified". * location.h (struct linespec_location): New. (explicit_location::func_name_match_type): New field. (new_linespec_location): Now returns a const linespec_location *. (string_to_event_location_basic): New symbol_name_match_type parameter. (explicit_completion_info::saw_explicit_location_option): New field. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * python/py-breakpoint.c (bppy_init): Likewise. * python/python.c (gdbpy_decode_line): Likewise. gdb/testsuite/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.base/langs.exp: Use -qualified. * gdb.cp/meth-typedefs.exp: Use -qualified, and add tests without it. * gdb.cp/namespace.exp: Use -qualified. * gdb.linespec/cpcompletion.exp (overload-2, fqn, fqn-2) (overload-3, template-overload, template-ret-type, const-overload) (const-overload-quoted, anon-ns, ambiguous-prefix): New procedures. (test_driver): Call them. * gdb.cp/save-bp-qualified.cc: New. * gdb.cp/save-bp-qualified.exp: New. * gdb.linespec/explicit.exp: Test -qualified. * lib/completion-support.exp (completion::explicit_opts_list): Add "-qualified". * lib/gdb.exp (gdb_breakpoint): Handle "qualified". gdb/doc/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.texinfo (Linespec Locations): Document how "function" is interpreted in C++ and Ada. Document "-qualified". (Explicit Locations): Document how "-function" is interpreted in C++ and Ada. Document "-qualified".
2017-11-29 20:33:23 +01:00
while (true)
{
if (strncmp_iw_with_mode (sname, lookup_name, lookup_name_len,
Breakpoints in symbols with ABI tags (PR c++/19436) Trying to set a breakpoint in a function with an ABI tag does not work currently. E.g., debugging gdb itself, we see this with the "string_printf" function: (top-gdb) b string_print [TAB] (top-gdb) b string_printf[abi:cxx11](char const*, ...) [RET] No source file named string_printf[abi. Make breakpoint pending on future shared library load? (y or [n]) Quoting doesn't help: (top-gdb) b 'string_printf[abi:cxx11]'(char const*, ...) malformed linespec error: unexpected string, "(char const*, ...)" (top-gdb) b 'string_printf[abi:cxx11](char const*, ...)' No source file named string_printf[abi. Make breakpoint pending on future shared library load? (y or [n]) n This patch fixes this, and takes it a bit further. The actual symbol name as demangled by libiberty's demangler is really string_printf[abi:cxx11](char const*, ...) however, this patch makes it possible to set the breakpoint with string_printf(char const*, ...) too. I.e., ignoring the ABI tag. And to match, it teaches the completer to complete the symbol name without the ABI tag, i.e., "string_pri<TAB>" -> "string_printf(char const*, ...)" If however, you really want to break on a symbol with the tag, then you simply start writing the tag, and GDB will preserve it, like: "string_printf[a<TAB>" -> "string_printf[abi:cxx11](char const*, ...)" Grows the gdb.linespec/ tests like this: -# of expected passes 8977 +# of expected passes 9176 gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> PR c++/19436 * NEWS: Mention setting breakpoints on functions with C++ ABI tags. * completer.h (completion_match_for_lcd) <match, mark_ignored_range>: New methods. <finish>: Consider ignored ranges. <clear>: Clear ignored ranges. <m_ignored_ranges, m_finished_storage>: New fields. * cp-support.c (cp_search_name_hash): Ignore ABI tags. (cp_symbol_name_matches_1, cp_fq_symbol_name_matches): Pass the completion_match_for_lcd pointer to strncmp_iw_with_mode. (test_cp_symbol_name_cmp): Add [abi:...] tags unit tests. * language.c (default_symbol_name_matcher): Pass the completion_match_for_lcd pointer to strncmp_iw_with_mode. * linespec.c (linespec_lexer_lex_string): Don't tokenize ABI tags. * utils.c (skip_abi_tag): New function. (strncmp_iw_with_mode): Add completion_match_for_lcd parameter. Handle ABI tags. * utils.h (strncmp_iw_with_mode): Add completion_match_for_lcd parameter. gdb/testsuite/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> PR c++/19436 * gdb.linespec/cpls-abi-tag.cc: New file. * gdb.linespec/cpls-abi-tag.exp: New file. gdb/doc/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> PR c++/19436 * gdb.texinfo (Debugging C Plus Plus): Document setting breakpoints in functions with ABI tags.
2017-11-29 20:33:24 +01:00
mode, language_cplus, match_for_lcd) == 0)
Make "break foo" find "A::foo", A::B::foo", etc. [C++ and wild matching] This patch teaches GDB about setting breakpoints in all scopes (namespaces and classes) by default. Here's a contrived example: (gdb) b func<tab> (anonymous namespace)::A::function() Bn::(anonymous namespace)::B::function() function(int, int) (anonymous namespace)::B::function() Bn::(anonymous namespace)::function() gdb::(anonymous namespace)::A::function() (anonymous namespace)::B::function() const Bn::(anonymous namespace)::function(int, int) gdb::(anonymous namespace)::function() (anonymous namespace)::function() Bn::B::func() gdb::(anonymous namespace)::function(int, int) (anonymous namespace)::function(int, int) Bn::B::function() gdb::A::func() A::func() Bn::func() gdb::A::function() A::function() Bn::function() gdb::func() B::func() Bn::function(int, int) gdb::function() B::function() Bn::function(long) gdb::function(int, int) B::function() const func() gdb::function(long) B::function_const() const function() (gdb) b function Breakpoint 1 at 0x4005ce: function. (26 locations) (gdb) b B::function<tab> (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() (gdb) b B::function Breakpoint 1 at 0x40072c: B::function. (6 locations) To get back the original behavior of interpreting the function name as a fully-qualified name, you can use the new "-qualified" (or "-q") option/flag (added by this commit). For example: (gdb) b B::function (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() vs: (gdb) b -qualified B::function B::function() B::function() const B::function_const() const I've chosen "-qualified" / "-q" because "-f" (for "full" or "fully-qualified") is already taken for "-function". Note: the "-qualified" option works with both linespecs and explicit locations. I.e., these are equivalent: (gdb) b -q func (gdb) b -q -f func and so are these: (gdb) b -q filename.cc:func (gdb) b -q -s filename.cc -f func (gdb) b -s filename.cc -q -f func (gdb) b -s filename.cc -f func -q To better understand why I consider wild matching the better default, consider what happens when we get to the point when _all_ of GDB is wrapped under "namespace gdb {}". I have a patch series that does that, and when I started debugging that GDB, I immediately became frustrated. You'd have to write "b gdb::internal_error", "b gdb::foo", "b gdb::bar", etc. etc., which gets annoying pretty quickly. OTOH, consider how this makes it very easy to set breakpoints in classes wrapped in anonymous namespaces. You just don't think of them, GDB finds the symbols for you automatically. (At the Cauldron a couple months ago, several people told me that they run into a similar issue when debugging other C++ projects. One example was when debugging LLVM, which puts all its code under the "llvm" namespace.) Implementation-wise, what the patch does is: - makes C++ symbol name hashing only consider the last component of a symbol name. (so that we can look up symbol names by last-component name only). - adds a C++ symbol name matcher for symbol_name_match_type::WILD, which ignores missing leading specifiers / components. - adjusts a few preexisting testsuite tests to use "-qualified" when they mean it. - adds new testsuite tests. - adds unit tests. Grows the gdb.linespec/ tests like this: -# of expected passes 7823 +# of expected passes 8977 gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * NEWS: Mention that breakpoints on C++ functions are now set on on all namespaces/classes by default, and mention "break -qualified". * ax-gdb.c (agent_command_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * breakpoint.c (parse_breakpoint_sals): Adjust to get_linespec_location's return type change. (strace_marker_create_sals_from_location): Adjust to pass a symbol_name_match_type to new_linespec_location. (strace_marker_decode_location): Adjust to get_linespec_location's return type change. (strace_command): Adjust to pass a symbol_name_match_type to new_linespec_location. (LOCATION_HELP_STRING): Add paragraph about wildmatching, and mention "-qualified". * c-lang.c (cplus_language_defn): Install cp_search_name_hash. * completer.c (explicit_location_match_type::MATCH_QUALIFIED): New enumerator. (complete_address_and_linespec_locations): New parameter 'match_type'. Pass it down. (explicit_options): Add "-qualified". (collect_explicit_location_matches): Pass the requested match type to the linespec completers. Handle MATCH_QUALIFIED. (location_completer): Handle "-qualified" combined with linespecs. * cp-support.c (cp_search_name_hash): New. (cp_symbol_name_matches_1): Implement wild matching for C++. (cp_fq_symbol_name_matches): Reimplement. (cp_get_symbol_name_matcher): Return different matchers depending on the lookup name's match type. (selftests::test_cp_symbol_name_matches): Add wild matching tests. * cp-support.h (cp_search_name_hash): New declaration. * dwarf2read.c (selftests::dw2_expand_symtabs_matching::test_symbols): Add symbols. (test_dw2_expand_symtabs_matching_symbol): Add wild matching tests. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Adjust to pass a symbol_name_match_type to new_linespec_location. * linespec.c (linespec_parse_basic): Lookup function symbols using the parser's symbol name match type. (convert_explicit_location_to_linespec): New symbol_name_match_type parameter. Pass it down to find_linespec_symbols. (convert_explicit_location_to_sals): Pass the location's name match type to convert_explicit_location_to_linespec. (parse_linespec): New match_type parameter. Save it in the parser. (linespec_parser_new): Default to symbol_name_match_type::WILD. (linespec_complete_function): New symbol_name_match_type parameter. Use it. (complete_linespec_component): Pass down the parser's recorded name match type. (linespec_complete_label): New symbol_name_match_type parameter. Use it. (linespec_complete): New symbol_name_match_type parameter. Save it in the parser and pass it down. Adjust to get_linespec_location's prototype change. (find_function_symbols, find_linespec_symbols): New symbol_name_match_type parameter. Pass it down instead of assuming symbol_name_match_type::WILD. * linespec.h (linespec_complete, linespec_complete_function) (linespec_complete_label): New symbol_name_match_type parameter. * location.c (event_location::linespec_location): Now a struct linespec_location. (EL_LINESPEC): Adjust. (initialize_explicit_location): Default to symbol_name_match_type::WILD. (new_linespec_location): New symbol_name_match_type parameter. Record it in the location. (get_linespec_location): Now returns a struct linespec_location. (new_explicit_location): Also copy func_name_match_type. (explicit_to_string_internal) (string_to_explicit_location): Handle "-qualified". (copy_event_location): Adjust to LINESPEC_LOCATION type change. Copy symbol_name_match_type fields. (event_location_deleter::operator()): Adjust to LINESPEC_LOCATION type change. (event_location_to_string): Adjust to LINESPEC_LOCATION type change. Handle "-qualfied". (string_to_explicit_location): Handle "-qualified". (string_to_event_location_basic): New symbol_name_match_type parameter. Pass it down. (string_to_event_location): Handle "-qualified". * location.h (struct linespec_location): New. (explicit_location::func_name_match_type): New field. (new_linespec_location): Now returns a const linespec_location *. (string_to_event_location_basic): New symbol_name_match_type parameter. (explicit_completion_info::saw_explicit_location_option): New field. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * python/py-breakpoint.c (bppy_init): Likewise. * python/python.c (gdbpy_decode_line): Likewise. gdb/testsuite/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.base/langs.exp: Use -qualified. * gdb.cp/meth-typedefs.exp: Use -qualified, and add tests without it. * gdb.cp/namespace.exp: Use -qualified. * gdb.linespec/cpcompletion.exp (overload-2, fqn, fqn-2) (overload-3, template-overload, template-ret-type, const-overload) (const-overload-quoted, anon-ns, ambiguous-prefix): New procedures. (test_driver): Call them. * gdb.cp/save-bp-qualified.cc: New. * gdb.cp/save-bp-qualified.exp: New. * gdb.linespec/explicit.exp: Test -qualified. * lib/completion-support.exp (completion::explicit_opts_list): Add "-qualified". * lib/gdb.exp (gdb_breakpoint): Handle "qualified". gdb/doc/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.texinfo (Linespec Locations): Document how "function" is interpreted in C++ and Ada. Document "-qualified". (Explicit Locations): Document how "-function" is interpreted in C++ and Ada. Document "-qualified".
2017-11-29 20:33:23 +01:00
{
if (comp_match_res != NULL)
{
/* Note here we set different MATCH and MATCH_FOR_LCD
strings. This is because with
(gdb) b push_bac[TAB]
we want the completion matches to list
std::vector<int>::push_back(...)
std::vector<char>::push_back(...)
etc., which are SYMBOL_SEARCH_NAMEs, while we want
the input line to auto-complete to
(gdb) push_back(...)
which is SNAME, not to
(gdb) std::vector<
which would be the regular common prefix between all
the matches otherwise. */
comp_match_res->set_match (symbol_search_name, sname);
}
return true;
}
unsigned int len = cp_find_first_component (sname);
if (sname[len] == '\0')
return false;
gdb_assert (sname[len] == ':');
/* Skip the '::'. */
sname += len + 2;
}
}
/* C++ symbol_name_matcher_ftype implementation. */
static bool
cp_fq_symbol_name_matches (const char *symbol_search_name,
const lookup_name_info &lookup_name,
completion_match_result *comp_match_res)
{
/* Get the demangled name. */
const std::string &name = lookup_name.cplus ().lookup_name ();
Breakpoints in symbols with ABI tags (PR c++/19436) Trying to set a breakpoint in a function with an ABI tag does not work currently. E.g., debugging gdb itself, we see this with the "string_printf" function: (top-gdb) b string_print [TAB] (top-gdb) b string_printf[abi:cxx11](char const*, ...) [RET] No source file named string_printf[abi. Make breakpoint pending on future shared library load? (y or [n]) Quoting doesn't help: (top-gdb) b 'string_printf[abi:cxx11]'(char const*, ...) malformed linespec error: unexpected string, "(char const*, ...)" (top-gdb) b 'string_printf[abi:cxx11](char const*, ...)' No source file named string_printf[abi. Make breakpoint pending on future shared library load? (y or [n]) n This patch fixes this, and takes it a bit further. The actual symbol name as demangled by libiberty's demangler is really string_printf[abi:cxx11](char const*, ...) however, this patch makes it possible to set the breakpoint with string_printf(char const*, ...) too. I.e., ignoring the ABI tag. And to match, it teaches the completer to complete the symbol name without the ABI tag, i.e., "string_pri<TAB>" -> "string_printf(char const*, ...)" If however, you really want to break on a symbol with the tag, then you simply start writing the tag, and GDB will preserve it, like: "string_printf[a<TAB>" -> "string_printf[abi:cxx11](char const*, ...)" Grows the gdb.linespec/ tests like this: -# of expected passes 8977 +# of expected passes 9176 gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> PR c++/19436 * NEWS: Mention setting breakpoints on functions with C++ ABI tags. * completer.h (completion_match_for_lcd) <match, mark_ignored_range>: New methods. <finish>: Consider ignored ranges. <clear>: Clear ignored ranges. <m_ignored_ranges, m_finished_storage>: New fields. * cp-support.c (cp_search_name_hash): Ignore ABI tags. (cp_symbol_name_matches_1, cp_fq_symbol_name_matches): Pass the completion_match_for_lcd pointer to strncmp_iw_with_mode. (test_cp_symbol_name_cmp): Add [abi:...] tags unit tests. * language.c (default_symbol_name_matcher): Pass the completion_match_for_lcd pointer to strncmp_iw_with_mode. * linespec.c (linespec_lexer_lex_string): Don't tokenize ABI tags. * utils.c (skip_abi_tag): New function. (strncmp_iw_with_mode): Add completion_match_for_lcd parameter. Handle ABI tags. * utils.h (strncmp_iw_with_mode): Add completion_match_for_lcd parameter. gdb/testsuite/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> PR c++/19436 * gdb.linespec/cpls-abi-tag.cc: New file. * gdb.linespec/cpls-abi-tag.exp: New file. gdb/doc/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> PR c++/19436 * gdb.texinfo (Debugging C Plus Plus): Document setting breakpoints in functions with ABI tags.
2017-11-29 20:33:24 +01:00
completion_match_for_lcd *match_for_lcd
= (comp_match_res != NULL ? &comp_match_res->match_for_lcd : NULL);
Make "break foo" find "A::foo", A::B::foo", etc. [C++ and wild matching] This patch teaches GDB about setting breakpoints in all scopes (namespaces and classes) by default. Here's a contrived example: (gdb) b func<tab> (anonymous namespace)::A::function() Bn::(anonymous namespace)::B::function() function(int, int) (anonymous namespace)::B::function() Bn::(anonymous namespace)::function() gdb::(anonymous namespace)::A::function() (anonymous namespace)::B::function() const Bn::(anonymous namespace)::function(int, int) gdb::(anonymous namespace)::function() (anonymous namespace)::function() Bn::B::func() gdb::(anonymous namespace)::function(int, int) (anonymous namespace)::function(int, int) Bn::B::function() gdb::A::func() A::func() Bn::func() gdb::A::function() A::function() Bn::function() gdb::func() B::func() Bn::function(int, int) gdb::function() B::function() Bn::function(long) gdb::function(int, int) B::function() const func() gdb::function(long) B::function_const() const function() (gdb) b function Breakpoint 1 at 0x4005ce: function. (26 locations) (gdb) b B::function<tab> (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() (gdb) b B::function Breakpoint 1 at 0x40072c: B::function. (6 locations) To get back the original behavior of interpreting the function name as a fully-qualified name, you can use the new "-qualified" (or "-q") option/flag (added by this commit). For example: (gdb) b B::function (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() vs: (gdb) b -qualified B::function B::function() B::function() const B::function_const() const I've chosen "-qualified" / "-q" because "-f" (for "full" or "fully-qualified") is already taken for "-function". Note: the "-qualified" option works with both linespecs and explicit locations. I.e., these are equivalent: (gdb) b -q func (gdb) b -q -f func and so are these: (gdb) b -q filename.cc:func (gdb) b -q -s filename.cc -f func (gdb) b -s filename.cc -q -f func (gdb) b -s filename.cc -f func -q To better understand why I consider wild matching the better default, consider what happens when we get to the point when _all_ of GDB is wrapped under "namespace gdb {}". I have a patch series that does that, and when I started debugging that GDB, I immediately became frustrated. You'd have to write "b gdb::internal_error", "b gdb::foo", "b gdb::bar", etc. etc., which gets annoying pretty quickly. OTOH, consider how this makes it very easy to set breakpoints in classes wrapped in anonymous namespaces. You just don't think of them, GDB finds the symbols for you automatically. (At the Cauldron a couple months ago, several people told me that they run into a similar issue when debugging other C++ projects. One example was when debugging LLVM, which puts all its code under the "llvm" namespace.) Implementation-wise, what the patch does is: - makes C++ symbol name hashing only consider the last component of a symbol name. (so that we can look up symbol names by last-component name only). - adds a C++ symbol name matcher for symbol_name_match_type::WILD, which ignores missing leading specifiers / components. - adjusts a few preexisting testsuite tests to use "-qualified" when they mean it. - adds new testsuite tests. - adds unit tests. Grows the gdb.linespec/ tests like this: -# of expected passes 7823 +# of expected passes 8977 gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * NEWS: Mention that breakpoints on C++ functions are now set on on all namespaces/classes by default, and mention "break -qualified". * ax-gdb.c (agent_command_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * breakpoint.c (parse_breakpoint_sals): Adjust to get_linespec_location's return type change. (strace_marker_create_sals_from_location): Adjust to pass a symbol_name_match_type to new_linespec_location. (strace_marker_decode_location): Adjust to get_linespec_location's return type change. (strace_command): Adjust to pass a symbol_name_match_type to new_linespec_location. (LOCATION_HELP_STRING): Add paragraph about wildmatching, and mention "-qualified". * c-lang.c (cplus_language_defn): Install cp_search_name_hash. * completer.c (explicit_location_match_type::MATCH_QUALIFIED): New enumerator. (complete_address_and_linespec_locations): New parameter 'match_type'. Pass it down. (explicit_options): Add "-qualified". (collect_explicit_location_matches): Pass the requested match type to the linespec completers. Handle MATCH_QUALIFIED. (location_completer): Handle "-qualified" combined with linespecs. * cp-support.c (cp_search_name_hash): New. (cp_symbol_name_matches_1): Implement wild matching for C++. (cp_fq_symbol_name_matches): Reimplement. (cp_get_symbol_name_matcher): Return different matchers depending on the lookup name's match type. (selftests::test_cp_symbol_name_matches): Add wild matching tests. * cp-support.h (cp_search_name_hash): New declaration. * dwarf2read.c (selftests::dw2_expand_symtabs_matching::test_symbols): Add symbols. (test_dw2_expand_symtabs_matching_symbol): Add wild matching tests. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Adjust to pass a symbol_name_match_type to new_linespec_location. * linespec.c (linespec_parse_basic): Lookup function symbols using the parser's symbol name match type. (convert_explicit_location_to_linespec): New symbol_name_match_type parameter. Pass it down to find_linespec_symbols. (convert_explicit_location_to_sals): Pass the location's name match type to convert_explicit_location_to_linespec. (parse_linespec): New match_type parameter. Save it in the parser. (linespec_parser_new): Default to symbol_name_match_type::WILD. (linespec_complete_function): New symbol_name_match_type parameter. Use it. (complete_linespec_component): Pass down the parser's recorded name match type. (linespec_complete_label): New symbol_name_match_type parameter. Use it. (linespec_complete): New symbol_name_match_type parameter. Save it in the parser and pass it down. Adjust to get_linespec_location's prototype change. (find_function_symbols, find_linespec_symbols): New symbol_name_match_type parameter. Pass it down instead of assuming symbol_name_match_type::WILD. * linespec.h (linespec_complete, linespec_complete_function) (linespec_complete_label): New symbol_name_match_type parameter. * location.c (event_location::linespec_location): Now a struct linespec_location. (EL_LINESPEC): Adjust. (initialize_explicit_location): Default to symbol_name_match_type::WILD. (new_linespec_location): New symbol_name_match_type parameter. Record it in the location. (get_linespec_location): Now returns a struct linespec_location. (new_explicit_location): Also copy func_name_match_type. (explicit_to_string_internal) (string_to_explicit_location): Handle "-qualified". (copy_event_location): Adjust to LINESPEC_LOCATION type change. Copy symbol_name_match_type fields. (event_location_deleter::operator()): Adjust to LINESPEC_LOCATION type change. (event_location_to_string): Adjust to LINESPEC_LOCATION type change. Handle "-qualfied". (string_to_explicit_location): Handle "-qualified". (string_to_event_location_basic): New symbol_name_match_type parameter. Pass it down. (string_to_event_location): Handle "-qualified". * location.h (struct linespec_location): New. (explicit_location::func_name_match_type): New field. (new_linespec_location): Now returns a const linespec_location *. (string_to_event_location_basic): New symbol_name_match_type parameter. (explicit_completion_info::saw_explicit_location_option): New field. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * python/py-breakpoint.c (bppy_init): Likewise. * python/python.c (gdbpy_decode_line): Likewise. gdb/testsuite/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.base/langs.exp: Use -qualified. * gdb.cp/meth-typedefs.exp: Use -qualified, and add tests without it. * gdb.cp/namespace.exp: Use -qualified. * gdb.linespec/cpcompletion.exp (overload-2, fqn, fqn-2) (overload-3, template-overload, template-ret-type, const-overload) (const-overload-quoted, anon-ns, ambiguous-prefix): New procedures. (test_driver): Call them. * gdb.cp/save-bp-qualified.cc: New. * gdb.cp/save-bp-qualified.exp: New. * gdb.linespec/explicit.exp: Test -qualified. * lib/completion-support.exp (completion::explicit_opts_list): Add "-qualified". * lib/gdb.exp (gdb_breakpoint): Handle "qualified". gdb/doc/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.texinfo (Linespec Locations): Document how "function" is interpreted in C++ and Ada. Document "-qualified". (Explicit Locations): Document how "-function" is interpreted in C++ and Ada. Document "-qualified".
2017-11-29 20:33:23 +01:00
strncmp_iw_mode mode = (lookup_name.completion_mode ()
? strncmp_iw_mode::NORMAL
: strncmp_iw_mode::MATCH_PARAMS);
Make strcmp_iw NOT ignore whitespace in the middle of tokens currently "b func tion" manages to set a breakpoint at "function" ! All these years I had never noticed this, but now that the linespec completer actually works, this easily happens by accident, with: "b func t<tab>" expecting to get "thread", but getting instead: "b func tion" ... Also, this: "b rettypefunc<int>" manages to set a breakpoint on "rettype func<int>()". These things happen due to strcmp_iw "magic". Fix it by teaching strcmp_iw about when can it skip whitespace. This required handling user-defined operators, and scope operators, complicating the code a bit, unfortunately. I added unit tests for all the corner cases I stumbled on, as I was developing this, and then in the end wrote a testsuite testcase covering many of the same things and more (to be added later). gdb/ChangeLog: 2017-11-24 Pedro Alves <palves@redhat.com> * cp-support.c (cp_symbol_name_matches_1): New, factored out from cp_fq_symbol_name_matches. Pass language_cplus to strncmp_with_mode. (cp_fq_symbol_name_matches): Call cp_symbol_name_matches_1. (selftests::test_cp_symbol_name_cmp): New. (_initialize_cp_support): Register "cp_symbol_name_matches" selftests. * language.c (default_symbol_name_matcher): Pass language_minimal to strncmp_iw_with_mode. * utils.c: Include "cp-support.h" and <algorithm>. (valid_identifier_name_char, cp_skip_operator_token, skip_ws) (cp_is_operator): New functions. (strncmp_iw_with_mode): Use them. Add language parameter. Don't skip whitespace in the symbol name when the lookup name doesn't have spaces, and vice versa. (strncmp_iw, strcmp_iw): Pass language to strncmp_iw_with_mode. * utils.h (strncmp_iw_with_mode): Add language parameter.
2017-11-25 00:30:04 +01:00
if (strncmp_iw_with_mode (symbol_search_name,
Make "break foo" find "A::foo", A::B::foo", etc. [C++ and wild matching] This patch teaches GDB about setting breakpoints in all scopes (namespaces and classes) by default. Here's a contrived example: (gdb) b func<tab> (anonymous namespace)::A::function() Bn::(anonymous namespace)::B::function() function(int, int) (anonymous namespace)::B::function() Bn::(anonymous namespace)::function() gdb::(anonymous namespace)::A::function() (anonymous namespace)::B::function() const Bn::(anonymous namespace)::function(int, int) gdb::(anonymous namespace)::function() (anonymous namespace)::function() Bn::B::func() gdb::(anonymous namespace)::function(int, int) (anonymous namespace)::function(int, int) Bn::B::function() gdb::A::func() A::func() Bn::func() gdb::A::function() A::function() Bn::function() gdb::func() B::func() Bn::function(int, int) gdb::function() B::function() Bn::function(long) gdb::function(int, int) B::function() const func() gdb::function(long) B::function_const() const function() (gdb) b function Breakpoint 1 at 0x4005ce: function. (26 locations) (gdb) b B::function<tab> (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() (gdb) b B::function Breakpoint 1 at 0x40072c: B::function. (6 locations) To get back the original behavior of interpreting the function name as a fully-qualified name, you can use the new "-qualified" (or "-q") option/flag (added by this commit). For example: (gdb) b B::function (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() vs: (gdb) b -qualified B::function B::function() B::function() const B::function_const() const I've chosen "-qualified" / "-q" because "-f" (for "full" or "fully-qualified") is already taken for "-function". Note: the "-qualified" option works with both linespecs and explicit locations. I.e., these are equivalent: (gdb) b -q func (gdb) b -q -f func and so are these: (gdb) b -q filename.cc:func (gdb) b -q -s filename.cc -f func (gdb) b -s filename.cc -q -f func (gdb) b -s filename.cc -f func -q To better understand why I consider wild matching the better default, consider what happens when we get to the point when _all_ of GDB is wrapped under "namespace gdb {}". I have a patch series that does that, and when I started debugging that GDB, I immediately became frustrated. You'd have to write "b gdb::internal_error", "b gdb::foo", "b gdb::bar", etc. etc., which gets annoying pretty quickly. OTOH, consider how this makes it very easy to set breakpoints in classes wrapped in anonymous namespaces. You just don't think of them, GDB finds the symbols for you automatically. (At the Cauldron a couple months ago, several people told me that they run into a similar issue when debugging other C++ projects. One example was when debugging LLVM, which puts all its code under the "llvm" namespace.) Implementation-wise, what the patch does is: - makes C++ symbol name hashing only consider the last component of a symbol name. (so that we can look up symbol names by last-component name only). - adds a C++ symbol name matcher for symbol_name_match_type::WILD, which ignores missing leading specifiers / components. - adjusts a few preexisting testsuite tests to use "-qualified" when they mean it. - adds new testsuite tests. - adds unit tests. Grows the gdb.linespec/ tests like this: -# of expected passes 7823 +# of expected passes 8977 gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * NEWS: Mention that breakpoints on C++ functions are now set on on all namespaces/classes by default, and mention "break -qualified". * ax-gdb.c (agent_command_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * breakpoint.c (parse_breakpoint_sals): Adjust to get_linespec_location's return type change. (strace_marker_create_sals_from_location): Adjust to pass a symbol_name_match_type to new_linespec_location. (strace_marker_decode_location): Adjust to get_linespec_location's return type change. (strace_command): Adjust to pass a symbol_name_match_type to new_linespec_location. (LOCATION_HELP_STRING): Add paragraph about wildmatching, and mention "-qualified". * c-lang.c (cplus_language_defn): Install cp_search_name_hash. * completer.c (explicit_location_match_type::MATCH_QUALIFIED): New enumerator. (complete_address_and_linespec_locations): New parameter 'match_type'. Pass it down. (explicit_options): Add "-qualified". (collect_explicit_location_matches): Pass the requested match type to the linespec completers. Handle MATCH_QUALIFIED. (location_completer): Handle "-qualified" combined with linespecs. * cp-support.c (cp_search_name_hash): New. (cp_symbol_name_matches_1): Implement wild matching for C++. (cp_fq_symbol_name_matches): Reimplement. (cp_get_symbol_name_matcher): Return different matchers depending on the lookup name's match type. (selftests::test_cp_symbol_name_matches): Add wild matching tests. * cp-support.h (cp_search_name_hash): New declaration. * dwarf2read.c (selftests::dw2_expand_symtabs_matching::test_symbols): Add symbols. (test_dw2_expand_symtabs_matching_symbol): Add wild matching tests. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Adjust to pass a symbol_name_match_type to new_linespec_location. * linespec.c (linespec_parse_basic): Lookup function symbols using the parser's symbol name match type. (convert_explicit_location_to_linespec): New symbol_name_match_type parameter. Pass it down to find_linespec_symbols. (convert_explicit_location_to_sals): Pass the location's name match type to convert_explicit_location_to_linespec. (parse_linespec): New match_type parameter. Save it in the parser. (linespec_parser_new): Default to symbol_name_match_type::WILD. (linespec_complete_function): New symbol_name_match_type parameter. Use it. (complete_linespec_component): Pass down the parser's recorded name match type. (linespec_complete_label): New symbol_name_match_type parameter. Use it. (linespec_complete): New symbol_name_match_type parameter. Save it in the parser and pass it down. Adjust to get_linespec_location's prototype change. (find_function_symbols, find_linespec_symbols): New symbol_name_match_type parameter. Pass it down instead of assuming symbol_name_match_type::WILD. * linespec.h (linespec_complete, linespec_complete_function) (linespec_complete_label): New symbol_name_match_type parameter. * location.c (event_location::linespec_location): Now a struct linespec_location. (EL_LINESPEC): Adjust. (initialize_explicit_location): Default to symbol_name_match_type::WILD. (new_linespec_location): New symbol_name_match_type parameter. Record it in the location. (get_linespec_location): Now returns a struct linespec_location. (new_explicit_location): Also copy func_name_match_type. (explicit_to_string_internal) (string_to_explicit_location): Handle "-qualified". (copy_event_location): Adjust to LINESPEC_LOCATION type change. Copy symbol_name_match_type fields. (event_location_deleter::operator()): Adjust to LINESPEC_LOCATION type change. (event_location_to_string): Adjust to LINESPEC_LOCATION type change. Handle "-qualfied". (string_to_explicit_location): Handle "-qualified". (string_to_event_location_basic): New symbol_name_match_type parameter. Pass it down. (string_to_event_location): Handle "-qualified". * location.h (struct linespec_location): New. (explicit_location::func_name_match_type): New field. (new_linespec_location): Now returns a const linespec_location *. (string_to_event_location_basic): New symbol_name_match_type parameter. (explicit_completion_info::saw_explicit_location_option): New field. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * python/py-breakpoint.c (bppy_init): Likewise. * python/python.c (gdbpy_decode_line): Likewise. gdb/testsuite/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.base/langs.exp: Use -qualified. * gdb.cp/meth-typedefs.exp: Use -qualified, and add tests without it. * gdb.cp/namespace.exp: Use -qualified. * gdb.linespec/cpcompletion.exp (overload-2, fqn, fqn-2) (overload-3, template-overload, template-ret-type, const-overload) (const-overload-quoted, anon-ns, ambiguous-prefix): New procedures. (test_driver): Call them. * gdb.cp/save-bp-qualified.cc: New. * gdb.cp/save-bp-qualified.exp: New. * gdb.linespec/explicit.exp: Test -qualified. * lib/completion-support.exp (completion::explicit_opts_list): Add "-qualified". * lib/gdb.exp (gdb_breakpoint): Handle "qualified". gdb/doc/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.texinfo (Linespec Locations): Document how "function" is interpreted in C++ and Ada. Document "-qualified". (Explicit Locations): Document how "-function" is interpreted in C++ and Ada. Document "-qualified".
2017-11-29 20:33:23 +01:00
name.c_str (), name.size (),
Breakpoints in symbols with ABI tags (PR c++/19436) Trying to set a breakpoint in a function with an ABI tag does not work currently. E.g., debugging gdb itself, we see this with the "string_printf" function: (top-gdb) b string_print [TAB] (top-gdb) b string_printf[abi:cxx11](char const*, ...) [RET] No source file named string_printf[abi. Make breakpoint pending on future shared library load? (y or [n]) Quoting doesn't help: (top-gdb) b 'string_printf[abi:cxx11]'(char const*, ...) malformed linespec error: unexpected string, "(char const*, ...)" (top-gdb) b 'string_printf[abi:cxx11](char const*, ...)' No source file named string_printf[abi. Make breakpoint pending on future shared library load? (y or [n]) n This patch fixes this, and takes it a bit further. The actual symbol name as demangled by libiberty's demangler is really string_printf[abi:cxx11](char const*, ...) however, this patch makes it possible to set the breakpoint with string_printf(char const*, ...) too. I.e., ignoring the ABI tag. And to match, it teaches the completer to complete the symbol name without the ABI tag, i.e., "string_pri<TAB>" -> "string_printf(char const*, ...)" If however, you really want to break on a symbol with the tag, then you simply start writing the tag, and GDB will preserve it, like: "string_printf[a<TAB>" -> "string_printf[abi:cxx11](char const*, ...)" Grows the gdb.linespec/ tests like this: -# of expected passes 8977 +# of expected passes 9176 gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> PR c++/19436 * NEWS: Mention setting breakpoints on functions with C++ ABI tags. * completer.h (completion_match_for_lcd) <match, mark_ignored_range>: New methods. <finish>: Consider ignored ranges. <clear>: Clear ignored ranges. <m_ignored_ranges, m_finished_storage>: New fields. * cp-support.c (cp_search_name_hash): Ignore ABI tags. (cp_symbol_name_matches_1, cp_fq_symbol_name_matches): Pass the completion_match_for_lcd pointer to strncmp_iw_with_mode. (test_cp_symbol_name_cmp): Add [abi:...] tags unit tests. * language.c (default_symbol_name_matcher): Pass the completion_match_for_lcd pointer to strncmp_iw_with_mode. * linespec.c (linespec_lexer_lex_string): Don't tokenize ABI tags. * utils.c (skip_abi_tag): New function. (strncmp_iw_with_mode): Add completion_match_for_lcd parameter. Handle ABI tags. * utils.h (strncmp_iw_with_mode): Add completion_match_for_lcd parameter. gdb/testsuite/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> PR c++/19436 * gdb.linespec/cpls-abi-tag.cc: New file. * gdb.linespec/cpls-abi-tag.exp: New file. gdb/doc/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> PR c++/19436 * gdb.texinfo (Debugging C Plus Plus): Document setting breakpoints in functions with ABI tags.
2017-11-29 20:33:24 +01:00
mode, language_cplus, match_for_lcd) == 0)
Make strcmp_iw NOT ignore whitespace in the middle of tokens currently "b func tion" manages to set a breakpoint at "function" ! All these years I had never noticed this, but now that the linespec completer actually works, this easily happens by accident, with: "b func t<tab>" expecting to get "thread", but getting instead: "b func tion" ... Also, this: "b rettypefunc<int>" manages to set a breakpoint on "rettype func<int>()". These things happen due to strcmp_iw "magic". Fix it by teaching strcmp_iw about when can it skip whitespace. This required handling user-defined operators, and scope operators, complicating the code a bit, unfortunately. I added unit tests for all the corner cases I stumbled on, as I was developing this, and then in the end wrote a testsuite testcase covering many of the same things and more (to be added later). gdb/ChangeLog: 2017-11-24 Pedro Alves <palves@redhat.com> * cp-support.c (cp_symbol_name_matches_1): New, factored out from cp_fq_symbol_name_matches. Pass language_cplus to strncmp_with_mode. (cp_fq_symbol_name_matches): Call cp_symbol_name_matches_1. (selftests::test_cp_symbol_name_cmp): New. (_initialize_cp_support): Register "cp_symbol_name_matches" selftests. * language.c (default_symbol_name_matcher): Pass language_minimal to strncmp_iw_with_mode. * utils.c: Include "cp-support.h" and <algorithm>. (valid_identifier_name_char, cp_skip_operator_token, skip_ws) (cp_is_operator): New functions. (strncmp_iw_with_mode): Use them. Add language parameter. Don't skip whitespace in the symbol name when the lookup name doesn't have spaces, and vice versa. (strncmp_iw, strcmp_iw): Pass language to strncmp_iw_with_mode. * utils.h (strncmp_iw_with_mode): Add language parameter.
2017-11-25 00:30:04 +01:00
{
Handle custom completion match prefix / LCD A following patch will add support for wild matching for C++ symbols, making completing on "b push_ba" on a C++ program complete to std::vector<...>::push_back, std::string::push_back etc., like: (gdb) b push_ba[TAB] std::vector<...>::push_back(....) std::string<...>::push_back(....) Currently, we compute the "lowest common denominator" between all completion candidates (what the input line is adjusted to) as the common prefix of all matches. That's problematic with wild matching as above, as then we'd end up with TAB changing the input line to "b std::", losing the original input, like: (gdb) b push_ba[TAB] std::vector<...>::push_back(....) std::string<...>::push_back(....) (gdb) b std:: while obviously we'd want it to adjust itself to "b push_back(" instead: (gdb) b push_ba[TAB] std::vector<...>::push_back(....) std::string<...>::push_back(....) (gdb) b push_back( This patch adds the core code necessary to support this, though nothing really makes use of it yet in this patch. gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_lookup_name_info::matches): Change type of parameter from completion_match to completion_match_result. Adjust. (do_wild_match, do_full_match, ada_symbol_name_matches): Likewise. * completer.c (completion_tracker::maybe_add_completion): Add match_for_lcd parameter and use it. (completion_tracker::add_completion): Likewise. * completer.h (class completion_match_for_lcd): New class. (completion_match_result::match_for_lcd): New field. (completion_match_result::set_match): New method. (completion_tracker): Add comments. (completion_tracker::add_completion): Add match_for_lcd parameter. (completion_tracker::reset_completion_match_result): Reset match_for_lcd too. (completion_tracker::maybe_add_completion): Add match_for_lcd parameter. (completion_tracker::m_lowest_common_denominator_unique): Extend comments. * cp-support.c (cp_symbol_name_matches_1) (cp_fq_symbol_name_matches): Change type of parameter from completion_match to completion_match_result. Adjust. * language.c (default_symbol_name_matcher): Change type of parameter from completion_match to completion_match_result. Adjust. * language.h (completion_match_for_lcd): Forward declare. (default_symbol_name_matcher): Change type of parameter from completion_match to completion_match_result. * symtab.c (compare_symbol_name): Adjust. (completion_list_add_name): Pass the match_for_lcd to the tracker. * symtab.h (ada_lookup_name_info::matches): Change type of parameter from completion_match to completion_match_result. (symbol_name_matcher_ftype): Likewise, and update comments.
2017-11-29 20:33:23 +01:00
if (comp_match_res != NULL)
comp_match_res->set_match (symbol_search_name);
Make strcmp_iw NOT ignore whitespace in the middle of tokens currently "b func tion" manages to set a breakpoint at "function" ! All these years I had never noticed this, but now that the linespec completer actually works, this easily happens by accident, with: "b func t<tab>" expecting to get "thread", but getting instead: "b func tion" ... Also, this: "b rettypefunc<int>" manages to set a breakpoint on "rettype func<int>()". These things happen due to strcmp_iw "magic". Fix it by teaching strcmp_iw about when can it skip whitespace. This required handling user-defined operators, and scope operators, complicating the code a bit, unfortunately. I added unit tests for all the corner cases I stumbled on, as I was developing this, and then in the end wrote a testsuite testcase covering many of the same things and more (to be added later). gdb/ChangeLog: 2017-11-24 Pedro Alves <palves@redhat.com> * cp-support.c (cp_symbol_name_matches_1): New, factored out from cp_fq_symbol_name_matches. Pass language_cplus to strncmp_with_mode. (cp_fq_symbol_name_matches): Call cp_symbol_name_matches_1. (selftests::test_cp_symbol_name_cmp): New. (_initialize_cp_support): Register "cp_symbol_name_matches" selftests. * language.c (default_symbol_name_matcher): Pass language_minimal to strncmp_iw_with_mode. * utils.c: Include "cp-support.h" and <algorithm>. (valid_identifier_name_char, cp_skip_operator_token, skip_ws) (cp_is_operator): New functions. (strncmp_iw_with_mode): Use them. Add language parameter. Don't skip whitespace in the symbol name when the lookup name doesn't have spaces, and vice versa. (strncmp_iw, strcmp_iw): Pass language to strncmp_iw_with_mode. * utils.h (strncmp_iw_with_mode): Add language parameter.
2017-11-25 00:30:04 +01:00
return true;
}
return false;
}
Make "break foo" find "A::foo", A::B::foo", etc. [C++ and wild matching] This patch teaches GDB about setting breakpoints in all scopes (namespaces and classes) by default. Here's a contrived example: (gdb) b func<tab> (anonymous namespace)::A::function() Bn::(anonymous namespace)::B::function() function(int, int) (anonymous namespace)::B::function() Bn::(anonymous namespace)::function() gdb::(anonymous namespace)::A::function() (anonymous namespace)::B::function() const Bn::(anonymous namespace)::function(int, int) gdb::(anonymous namespace)::function() (anonymous namespace)::function() Bn::B::func() gdb::(anonymous namespace)::function(int, int) (anonymous namespace)::function(int, int) Bn::B::function() gdb::A::func() A::func() Bn::func() gdb::A::function() A::function() Bn::function() gdb::func() B::func() Bn::function(int, int) gdb::function() B::function() Bn::function(long) gdb::function(int, int) B::function() const func() gdb::function(long) B::function_const() const function() (gdb) b function Breakpoint 1 at 0x4005ce: function. (26 locations) (gdb) b B::function<tab> (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() (gdb) b B::function Breakpoint 1 at 0x40072c: B::function. (6 locations) To get back the original behavior of interpreting the function name as a fully-qualified name, you can use the new "-qualified" (or "-q") option/flag (added by this commit). For example: (gdb) b B::function (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() vs: (gdb) b -qualified B::function B::function() B::function() const B::function_const() const I've chosen "-qualified" / "-q" because "-f" (for "full" or "fully-qualified") is already taken for "-function". Note: the "-qualified" option works with both linespecs and explicit locations. I.e., these are equivalent: (gdb) b -q func (gdb) b -q -f func and so are these: (gdb) b -q filename.cc:func (gdb) b -q -s filename.cc -f func (gdb) b -s filename.cc -q -f func (gdb) b -s filename.cc -f func -q To better understand why I consider wild matching the better default, consider what happens when we get to the point when _all_ of GDB is wrapped under "namespace gdb {}". I have a patch series that does that, and when I started debugging that GDB, I immediately became frustrated. You'd have to write "b gdb::internal_error", "b gdb::foo", "b gdb::bar", etc. etc., which gets annoying pretty quickly. OTOH, consider how this makes it very easy to set breakpoints in classes wrapped in anonymous namespaces. You just don't think of them, GDB finds the symbols for you automatically. (At the Cauldron a couple months ago, several people told me that they run into a similar issue when debugging other C++ projects. One example was when debugging LLVM, which puts all its code under the "llvm" namespace.) Implementation-wise, what the patch does is: - makes C++ symbol name hashing only consider the last component of a symbol name. (so that we can look up symbol names by last-component name only). - adds a C++ symbol name matcher for symbol_name_match_type::WILD, which ignores missing leading specifiers / components. - adjusts a few preexisting testsuite tests to use "-qualified" when they mean it. - adds new testsuite tests. - adds unit tests. Grows the gdb.linespec/ tests like this: -# of expected passes 7823 +# of expected passes 8977 gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * NEWS: Mention that breakpoints on C++ functions are now set on on all namespaces/classes by default, and mention "break -qualified". * ax-gdb.c (agent_command_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * breakpoint.c (parse_breakpoint_sals): Adjust to get_linespec_location's return type change. (strace_marker_create_sals_from_location): Adjust to pass a symbol_name_match_type to new_linespec_location. (strace_marker_decode_location): Adjust to get_linespec_location's return type change. (strace_command): Adjust to pass a symbol_name_match_type to new_linespec_location. (LOCATION_HELP_STRING): Add paragraph about wildmatching, and mention "-qualified". * c-lang.c (cplus_language_defn): Install cp_search_name_hash. * completer.c (explicit_location_match_type::MATCH_QUALIFIED): New enumerator. (complete_address_and_linespec_locations): New parameter 'match_type'. Pass it down. (explicit_options): Add "-qualified". (collect_explicit_location_matches): Pass the requested match type to the linespec completers. Handle MATCH_QUALIFIED. (location_completer): Handle "-qualified" combined with linespecs. * cp-support.c (cp_search_name_hash): New. (cp_symbol_name_matches_1): Implement wild matching for C++. (cp_fq_symbol_name_matches): Reimplement. (cp_get_symbol_name_matcher): Return different matchers depending on the lookup name's match type. (selftests::test_cp_symbol_name_matches): Add wild matching tests. * cp-support.h (cp_search_name_hash): New declaration. * dwarf2read.c (selftests::dw2_expand_symtabs_matching::test_symbols): Add symbols. (test_dw2_expand_symtabs_matching_symbol): Add wild matching tests. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Adjust to pass a symbol_name_match_type to new_linespec_location. * linespec.c (linespec_parse_basic): Lookup function symbols using the parser's symbol name match type. (convert_explicit_location_to_linespec): New symbol_name_match_type parameter. Pass it down to find_linespec_symbols. (convert_explicit_location_to_sals): Pass the location's name match type to convert_explicit_location_to_linespec. (parse_linespec): New match_type parameter. Save it in the parser. (linespec_parser_new): Default to symbol_name_match_type::WILD. (linespec_complete_function): New symbol_name_match_type parameter. Use it. (complete_linespec_component): Pass down the parser's recorded name match type. (linespec_complete_label): New symbol_name_match_type parameter. Use it. (linespec_complete): New symbol_name_match_type parameter. Save it in the parser and pass it down. Adjust to get_linespec_location's prototype change. (find_function_symbols, find_linespec_symbols): New symbol_name_match_type parameter. Pass it down instead of assuming symbol_name_match_type::WILD. * linespec.h (linespec_complete, linespec_complete_function) (linespec_complete_label): New symbol_name_match_type parameter. * location.c (event_location::linespec_location): Now a struct linespec_location. (EL_LINESPEC): Adjust. (initialize_explicit_location): Default to symbol_name_match_type::WILD. (new_linespec_location): New symbol_name_match_type parameter. Record it in the location. (get_linespec_location): Now returns a struct linespec_location. (new_explicit_location): Also copy func_name_match_type. (explicit_to_string_internal) (string_to_explicit_location): Handle "-qualified". (copy_event_location): Adjust to LINESPEC_LOCATION type change. Copy symbol_name_match_type fields. (event_location_deleter::operator()): Adjust to LINESPEC_LOCATION type change. (event_location_to_string): Adjust to LINESPEC_LOCATION type change. Handle "-qualfied". (string_to_explicit_location): Handle "-qualified". (string_to_event_location_basic): New symbol_name_match_type parameter. Pass it down. (string_to_event_location): Handle "-qualified". * location.h (struct linespec_location): New. (explicit_location::func_name_match_type): New field. (new_linespec_location): Now returns a const linespec_location *. (string_to_event_location_basic): New symbol_name_match_type parameter. (explicit_completion_info::saw_explicit_location_option): New field. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * python/py-breakpoint.c (bppy_init): Likewise. * python/python.c (gdbpy_decode_line): Likewise. gdb/testsuite/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.base/langs.exp: Use -qualified. * gdb.cp/meth-typedefs.exp: Use -qualified, and add tests without it. * gdb.cp/namespace.exp: Use -qualified. * gdb.linespec/cpcompletion.exp (overload-2, fqn, fqn-2) (overload-3, template-overload, template-ret-type, const-overload) (const-overload-quoted, anon-ns, ambiguous-prefix): New procedures. (test_driver): Call them. * gdb.cp/save-bp-qualified.cc: New. * gdb.cp/save-bp-qualified.exp: New. * gdb.linespec/explicit.exp: Test -qualified. * lib/completion-support.exp (completion::explicit_opts_list): Add "-qualified". * lib/gdb.exp (gdb_breakpoint): Handle "qualified". gdb/doc/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.texinfo (Linespec Locations): Document how "function" is interpreted in C++ and Ada. Document "-qualified". (Explicit Locations): Document how "-function" is interpreted in C++ and Ada. Document "-qualified".
2017-11-29 20:33:23 +01:00
/* C++ symbol_name_matcher_ftype implementation for wild matches.
Defers work to cp_symbol_name_matches_1. */
Make strcmp_iw NOT ignore whitespace in the middle of tokens currently "b func tion" manages to set a breakpoint at "function" ! All these years I had never noticed this, but now that the linespec completer actually works, this easily happens by accident, with: "b func t<tab>" expecting to get "thread", but getting instead: "b func tion" ... Also, this: "b rettypefunc<int>" manages to set a breakpoint on "rettype func<int>()". These things happen due to strcmp_iw "magic". Fix it by teaching strcmp_iw about when can it skip whitespace. This required handling user-defined operators, and scope operators, complicating the code a bit, unfortunately. I added unit tests for all the corner cases I stumbled on, as I was developing this, and then in the end wrote a testsuite testcase covering many of the same things and more (to be added later). gdb/ChangeLog: 2017-11-24 Pedro Alves <palves@redhat.com> * cp-support.c (cp_symbol_name_matches_1): New, factored out from cp_fq_symbol_name_matches. Pass language_cplus to strncmp_with_mode. (cp_fq_symbol_name_matches): Call cp_symbol_name_matches_1. (selftests::test_cp_symbol_name_cmp): New. (_initialize_cp_support): Register "cp_symbol_name_matches" selftests. * language.c (default_symbol_name_matcher): Pass language_minimal to strncmp_iw_with_mode. * utils.c: Include "cp-support.h" and <algorithm>. (valid_identifier_name_char, cp_skip_operator_token, skip_ws) (cp_is_operator): New functions. (strncmp_iw_with_mode): Use them. Add language parameter. Don't skip whitespace in the symbol name when the lookup name doesn't have spaces, and vice versa. (strncmp_iw, strcmp_iw): Pass language to strncmp_iw_with_mode. * utils.h (strncmp_iw_with_mode): Add language parameter.
2017-11-25 00:30:04 +01:00
Introduce lookup_name_info and generalize Ada's FULL/WILD name matching Summary: - This is preparation for supporting wild name matching on C++ too. - This is also preparation for TAB-completion fixes. - Makes symbol name matching (think strcmp_iw) be based on a per-language method. - Merges completion and non-completion name comparison (think language_ops::la_get_symbol_name_cmp generalized). - Avoid re-hashing lookup name multiple times - Centralizes preparing a name for lookup (Ada name encoding / C++ Demangling), both completion and non-completion. - Fixes Ada latent bug with verbatim name matches in expressions - Makes ada-lang.c use common|symtab.c completion code a bit more. Ada's wild matching basically means that "(gdb) break foo" will find all methods named "foo" in all packages. Translating to C++, it's roughly the same as saying that "break klass::method" sets breakpoints on all "klass::method" methods of all classes, no matter the namespace. A following patch will teach GDB about fullname vs wild matching for C++ too. This patch is preparatory work to get there. Another idea here is to do symbol name matching based on the symbol language's algorithm. I.e., avoid dependency on current language set. This allows for example doing (gdb) b foo::bar< int > (<tab> and having gdb name match the C++ symbols correctly even if the current language is C or Assembly (or Rust, or Ada, or ...), which can easily happen if you step into an Assembly/C runtime library frame. By encapsulating all the information related to a lookup name in a class, we can also cache hash computation for a given language in the lookup name object, to avoid recomputing it over and over. Similarly, because we don't really know upfront which languages the lookup name will be matched against, for each language we store the lookup name transformed into a search name. E.g., for C++, that means demangling the name. But for Ada, it means encoding the name. This actually forces us to centralize all the different lookup name encoding in a central place, resulting in clearer code, IMO. See e.g., the new ada_lookup_name_info class. The lookup name -> symbol search name computation is also done only once per language. The old language->la_get_symbol_name_cmp / symbol_name_cmp_ftype are generalized to work with both completion, and normal symbol look up. At some point early on, I had separate completion vs non-completion language vector entry points, but a single method ends up being better IMO for simplifying things -- the more we merge the completion / non-completion name lookup code paths, the less changes for bugs causing completion vs normal lookup finding different symbols. The ada-lex.l change is necessary because when doing (gdb) p <UpperCase> then the name that is passed to write_ write_var_or_type -> ada_lookup_symbol_list misses the "<>", i.e., it's just "UpperCase", and we end up doing a wild match against "UpperCase" lowercased by ada_lookup_name_info's constructor. I.e., "uppercase" wouldn't ever match "UpperCase", and the symbol lookup fails. This wouldn't cause any regression in the testsuite, but I added a new test that would pass before the patch and fail after, if it weren't for that fix. This is latent bug that happens to go unnoticed because that particular path was inconsistent with the rest of Ada symbol lookup by not lowercasing the lookup name. Ada's symbol_completion_add is deleted, replaced by using common code's completion_list_add_name. To make the latter work for Ada, we needed to add a new output parameter, because Ada wants to return back a custom completion candidates that are not the symbol name. With this patch, minimal symbol demangled name hashing is made consistent with regular symbol hashing. I.e., it now goes via the language vector's search_name_hash method too, as I had suggested in a previous patch. dw2_expand_symtabs_matching / .gdb_index symbol names were a challenge. The problem is that we have no way to telling what is the language of each symbol name found in the index, until we expand the corresponding full symbol, which is off course what we're trying to avoid. Language information is simply not considered in the index format... Since the symbol name hashing and comparison routines are per-language, we now have a problem. The patch sorts this out by matching each name against all languages. This is inneficient, and indeed slows down completion several times. E.g., with: $ cat script.cmd set pagination off set $count = 0 while $count < 400 complete b string_prin printf "count = %d\n", $count set $count = $count + 1 end $ time gdb --batch -q ./gdb-with-index -ex "source script-string_printf.cmd" I get, before patch (-O2, x86-64): real 0m1.773s user 0m1.737s sys 0m0.040s While after patch (-O2, x86-64): real 0m9.843s user 0m9.482s sys 0m0.034s However, the following patch will optimize this, and will actually make this use case faster compared to the "before patch" above: real 0m1.321s user 0m1.285s sys 0m0.039s gdb/ChangeLog: 2017-11-08 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_encode): Rename to .. (ada_encode_1): ... this. Add throw_errors parameter and handle it. (ada_encode): Reimplement. (match_name): Delete, folded into full_name. (resolve_subexp): No longer pass the encoded name to ada_lookup_symbol_list. (should_use_wild_match): Delete. (name_match_type_from_name): New. (ada_lookup_simple_minsym): Use lookup_name_info and the language's symbol_name_matcher_ftype. (add_symbols_from_enclosing_procs, ada_add_local_symbols) (ada_add_block_renamings): Adjust to use lookup_name_info. (ada_lookup_name): New. (add_nonlocal_symbols, ada_add_all_symbols) (ada_lookup_symbol_list_worker, ada_lookup_symbol_list) (ada_iterate_over_symbols): Adjust to use lookup_name_info. (ada_name_for_lookup): Delete. (ada_lookup_encoded_symbol): Construct a verbatim name. (wild_match): Reverse sense of return type. Use bool. (full_match): Reverse sense of return type. Inline bits of old match_name here. (ada_add_block_symbols): Adjust to use lookup_name_info. (symbol_completion_match): Delete, folded into... (ada_lookup_name_info::matches): ... .this new method. (symbol_completion_add): Delete. (ada_collect_symbol_completion_matches): Add name_match_type parameter. Adjust to use lookup_name_info and completion_list_add_name. (get_var_value, ada_add_global_exceptions): Adjust to use lookup_name_info. (ada_get_symbol_name_cmp): Delete. (do_wild_match, do_full_match): New functions. (ada_lookup_name_info::ada_lookup_name_info): New method. (ada_symbol_name_matches, ada_get_symbol_name_matcher): New functions. (ada_language_defn): Install ada_get_symbol_name_matcher. * ada-lex.l (processId): If name starts with '<', copy it verbatim. * block.c (block_iter_match_step, block_iter_match_first) (block_iter_match_next, block_lookup_symbol) (block_lookup_symbol_primary, block_find_symbol): Adjust to use lookup_name_info. * block.h (block_iter_match_first, block_iter_match_next) (ALL_BLOCK_SYMBOLS_WITH_NAME): Adjust to use lookup_name_info. * c-lang.c (c_language_defn, cplus_language_defn) (asm_language_defn, minimal_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * completer.c (complete_files_symbols) (collect_explicit_location_matches, symbol_completer): Pass a symbol_name_match_type down. * completer.h (class completion_match, completion_match_result): New classes. (completion_tracker::reset_completion_match_result): New method. (completion_tracker::m_completion_match_result): New field. * cp-support.c (make_symbol_overload_list_block): Adjust to use lookup_name_info. (cp_fq_symbol_name_matches, cp_get_symbol_name_matcher): New functions. * cp-support.h (cp_get_symbol_name_matcher): New declaration. * d-lang.c: Adjust comments to refer to la_get_symbol_name_matcher. * dictionary.c (dict_vector) <iter_match_first, iter_match_next>: Adjust to use lookup_name_info. (dict_iter_match_first, dict_iter_match_next) (iter_match_first_hashed, iter_match_next_hashed) (iter_match_first_linear, iter_match_next_linear): Adjust to work with a lookup_name_info. * dictionary.h (dict_iter_match_first, dict_iter_match_next): Likewise. * dwarf2read.c (dw2_lookup_symbol): Adjust to use lookup_name_info. (dw2_map_matching_symbols): Adjust to use symbol_name_match_type. (gdb_index_symbol_name_matcher): New class. (dw2_expand_symtabs_matching) Adjust to use lookup_name_info and gdb_index_symbol_name_matcher. Accept a NULL symbol_matcher. * f-lang.c (f_collect_symbol_completion_matches): Adjust to work with a symbol_name_match_type. (f_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * go-lang.c (go_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * language.c (default_symbol_name_matcher) (language_get_symbol_name_matcher): New functions. (unknown_language_defn, auto_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * language.h (symbol_name_cmp_ftype): Delete. (language_defn) <la_collect_symbol_completion_matches>: Add match type parameter. <la_get_symbol_name_cmp>: Delete field. <la_get_symbol_name_matcher>: New field. <la_iterate_over_symbols>: Adjust to use lookup_name_info. (default_symbol_name_matcher, language_get_symbol_name_matcher): Declare. * linespec.c (iterate_over_all_matching_symtabs) (iterate_over_file_blocks): Adjust to use lookup_name_info. (find_methods): Add language parameter, and use lookup_name_info and the language's symbol_name_matcher_ftype. (linespec_complete_function): Adjust. (lookup_prefix_sym): Use lookup_name_info. (add_all_symbol_names_from_pspace): Adjust. (find_superclass_methods): Add language parameter and pass it down. (find_method): Pass symbol language down. (find_linespec_symbols): Don't demangle or Ada encode here. (search_minsyms_for_name): Add lookup_name_info parameter. (add_matching_symbols_to_info): Add name_match_type parameter. Use lookup_name_info. * m2-lang.c (m2_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * minsyms.c: Include <algorithm>. (add_minsym_to_demangled_hash_table): Remove table parameter and add objfile parameter. Use search_name_hash, and add language to demangled languages vector. (struct found_minimal_symbols): New struct. (lookup_minimal_symbol_mangled, lookup_minimal_symbol_demangled): New functions. (lookup_minimal_symbol): Adjust to use them. Don't canonicalize input names here. Use lookup_name_info instead. Lookup up demangled names once for each language in the demangled names vector. (iterate_over_minimal_symbols): Use lookup_name_info. Lookup up demangled names once for each language in the demangled names vector. (build_minimal_symbol_hash_tables): Adjust. * minsyms.h (iterate_over_minimal_symbols): Adjust to pass down a lookup_name_info. * objc-lang.c (objc_language_defn): Adjust comment to refer to la_get_symbol_name_matcher. * objfiles.h: Include <vector>. (objfile_per_bfd_storage) <demangled_hash_languages>: New field. * opencl-lang.c (opencl_language_defn): Adjust comment to refer to la_get_symbol_name_matcher. * p-lang.c (pascal_language_defn): Adjust comment to refer to la_get_symbol_name_matcher. * psymtab.c (psym_lookup_symbol): Use lookup_name_info. (match_partial_symbol): Use symbol_name_match_type, lookup_name_info and psymbol_name_matches. (lookup_partial_symbol): Use lookup_name_info. (map_block): Use symbol_name_match_type and lookup_name_info. (psym_map_matching_symbols): Use symbol_name_match_type. (psymbol_name_matches): New. (recursively_search_psymtabs): Use lookup_name_info and psymbol_name_matches. Rename 'kind' parameter to 'domain'. (psym_expand_symtabs_matching): Use lookup_name_info. Rename 'kind' parameter to 'domain'. * rust-lang.c (rust_language_defn): Adjust comment to refer to la_get_symbol_name_matcher. * symfile-debug.c (debug_qf_map_matching_symbols) (debug_qf_map_matching_symbols): Use symbol_name_match_type. (debug_qf_expand_symtabs_matching): Use lookup_name_info. * symfile.c (expand_symtabs_matching): Use lookup_name_info. * symfile.h (quick_symbol_functions) <map_matching_symbols>: Adjust to use symbol_name_match_type. <expand_symtabs_matching>: Adjust to use lookup_name_info. (expand_symtabs_matching): Adjust to use lookup_name_info. * symmisc.c (maintenance_expand_symtabs): Use lookup_name_info::match_any (). * symtab.c (symbol_matches_search_name): New. (eq_symbol_entry): Adjust to use lookup_name_info and the language's matcher. (demangle_for_lookup_info::demangle_for_lookup_info): New. (lookup_name_info::match_any): New. (iterate_over_symbols, search_symbols): Use lookup_name_info. (compare_symbol_name): Add language, lookup_name_info and completion_match_result parameters, and use them. (completion_list_add_name): Make extern. Add language and lookup_name_info parameters. Use them. (completion_list_add_symbol, completion_list_add_msymbol) (completion_list_objc_symbol): Add lookup_name_info parameters and adjust. Pass down language. (completion_list_add_fields): Add lookup_name_info parameters and adjust. Pass down language. (add_symtab_completions): Add lookup_name_info parameters and adjust. (default_collect_symbol_completion_matches_break_on): Add name_match_type parameter, and use it. Use lookup_name_info. (default_collect_symbol_completion_matches) (collect_symbol_completion_matches): Add name_match_type parameter, and pass it down. (collect_symbol_completion_matches_type): Adjust. (collect_file_symbol_completion_matches): Add name_match_type parameter, and use lookup_name_info. * symtab.h: Include <string> and "common/gdb_optional.h". (enum class symbol_name_match_type): New. (class ada_lookup_name_info): New. (struct demangle_for_lookup_info): New. (class lookup_name_info): New. (symbol_name_matcher_ftype): New. (SYMBOL_MATCHES_SEARCH_NAME): Use symbol_matches_search_name. (symbol_matches_search_name): Declare. (MSYMBOL_MATCHES_SEARCH_NAME): Delete. (default_collect_symbol_completion_matches) (collect_symbol_completion_matches) (collect_file_symbol_completion_matches): Add name_match_type parameter. (iterate_over_symbols): Use lookup_name_info. (completion_list_add_name): Declare. * utils.c (enum class strncmp_iw_mode): Moved to utils.h. (strncmp_iw_with_mode): Now extern. * utils.h (enum class strncmp_iw_mode): Moved from utils.c. (strncmp_iw_with_mode): Declare. gdb/testsuite/ChangeLog: 2017-11-08 Pedro Alves <palves@redhat.com> * gdb.ada/complete.exp (p <Exported_Capitalized>): New test. (p Exported_Capitalized): New test. (p exported_capitalized): New test.
2017-11-08 15:22:32 +01:00
static bool
Make "break foo" find "A::foo", A::B::foo", etc. [C++ and wild matching] This patch teaches GDB about setting breakpoints in all scopes (namespaces and classes) by default. Here's a contrived example: (gdb) b func<tab> (anonymous namespace)::A::function() Bn::(anonymous namespace)::B::function() function(int, int) (anonymous namespace)::B::function() Bn::(anonymous namespace)::function() gdb::(anonymous namespace)::A::function() (anonymous namespace)::B::function() const Bn::(anonymous namespace)::function(int, int) gdb::(anonymous namespace)::function() (anonymous namespace)::function() Bn::B::func() gdb::(anonymous namespace)::function(int, int) (anonymous namespace)::function(int, int) Bn::B::function() gdb::A::func() A::func() Bn::func() gdb::A::function() A::function() Bn::function() gdb::func() B::func() Bn::function(int, int) gdb::function() B::function() Bn::function(long) gdb::function(int, int) B::function() const func() gdb::function(long) B::function_const() const function() (gdb) b function Breakpoint 1 at 0x4005ce: function. (26 locations) (gdb) b B::function<tab> (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() (gdb) b B::function Breakpoint 1 at 0x40072c: B::function. (6 locations) To get back the original behavior of interpreting the function name as a fully-qualified name, you can use the new "-qualified" (or "-q") option/flag (added by this commit). For example: (gdb) b B::function (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() vs: (gdb) b -qualified B::function B::function() B::function() const B::function_const() const I've chosen "-qualified" / "-q" because "-f" (for "full" or "fully-qualified") is already taken for "-function". Note: the "-qualified" option works with both linespecs and explicit locations. I.e., these are equivalent: (gdb) b -q func (gdb) b -q -f func and so are these: (gdb) b -q filename.cc:func (gdb) b -q -s filename.cc -f func (gdb) b -s filename.cc -q -f func (gdb) b -s filename.cc -f func -q To better understand why I consider wild matching the better default, consider what happens when we get to the point when _all_ of GDB is wrapped under "namespace gdb {}". I have a patch series that does that, and when I started debugging that GDB, I immediately became frustrated. You'd have to write "b gdb::internal_error", "b gdb::foo", "b gdb::bar", etc. etc., which gets annoying pretty quickly. OTOH, consider how this makes it very easy to set breakpoints in classes wrapped in anonymous namespaces. You just don't think of them, GDB finds the symbols for you automatically. (At the Cauldron a couple months ago, several people told me that they run into a similar issue when debugging other C++ projects. One example was when debugging LLVM, which puts all its code under the "llvm" namespace.) Implementation-wise, what the patch does is: - makes C++ symbol name hashing only consider the last component of a symbol name. (so that we can look up symbol names by last-component name only). - adds a C++ symbol name matcher for symbol_name_match_type::WILD, which ignores missing leading specifiers / components. - adjusts a few preexisting testsuite tests to use "-qualified" when they mean it. - adds new testsuite tests. - adds unit tests. Grows the gdb.linespec/ tests like this: -# of expected passes 7823 +# of expected passes 8977 gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * NEWS: Mention that breakpoints on C++ functions are now set on on all namespaces/classes by default, and mention "break -qualified". * ax-gdb.c (agent_command_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * breakpoint.c (parse_breakpoint_sals): Adjust to get_linespec_location's return type change. (strace_marker_create_sals_from_location): Adjust to pass a symbol_name_match_type to new_linespec_location. (strace_marker_decode_location): Adjust to get_linespec_location's return type change. (strace_command): Adjust to pass a symbol_name_match_type to new_linespec_location. (LOCATION_HELP_STRING): Add paragraph about wildmatching, and mention "-qualified". * c-lang.c (cplus_language_defn): Install cp_search_name_hash. * completer.c (explicit_location_match_type::MATCH_QUALIFIED): New enumerator. (complete_address_and_linespec_locations): New parameter 'match_type'. Pass it down. (explicit_options): Add "-qualified". (collect_explicit_location_matches): Pass the requested match type to the linespec completers. Handle MATCH_QUALIFIED. (location_completer): Handle "-qualified" combined with linespecs. * cp-support.c (cp_search_name_hash): New. (cp_symbol_name_matches_1): Implement wild matching for C++. (cp_fq_symbol_name_matches): Reimplement. (cp_get_symbol_name_matcher): Return different matchers depending on the lookup name's match type. (selftests::test_cp_symbol_name_matches): Add wild matching tests. * cp-support.h (cp_search_name_hash): New declaration. * dwarf2read.c (selftests::dw2_expand_symtabs_matching::test_symbols): Add symbols. (test_dw2_expand_symtabs_matching_symbol): Add wild matching tests. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Adjust to pass a symbol_name_match_type to new_linespec_location. * linespec.c (linespec_parse_basic): Lookup function symbols using the parser's symbol name match type. (convert_explicit_location_to_linespec): New symbol_name_match_type parameter. Pass it down to find_linespec_symbols. (convert_explicit_location_to_sals): Pass the location's name match type to convert_explicit_location_to_linespec. (parse_linespec): New match_type parameter. Save it in the parser. (linespec_parser_new): Default to symbol_name_match_type::WILD. (linespec_complete_function): New symbol_name_match_type parameter. Use it. (complete_linespec_component): Pass down the parser's recorded name match type. (linespec_complete_label): New symbol_name_match_type parameter. Use it. (linespec_complete): New symbol_name_match_type parameter. Save it in the parser and pass it down. Adjust to get_linespec_location's prototype change. (find_function_symbols, find_linespec_symbols): New symbol_name_match_type parameter. Pass it down instead of assuming symbol_name_match_type::WILD. * linespec.h (linespec_complete, linespec_complete_function) (linespec_complete_label): New symbol_name_match_type parameter. * location.c (event_location::linespec_location): Now a struct linespec_location. (EL_LINESPEC): Adjust. (initialize_explicit_location): Default to symbol_name_match_type::WILD. (new_linespec_location): New symbol_name_match_type parameter. Record it in the location. (get_linespec_location): Now returns a struct linespec_location. (new_explicit_location): Also copy func_name_match_type. (explicit_to_string_internal) (string_to_explicit_location): Handle "-qualified". (copy_event_location): Adjust to LINESPEC_LOCATION type change. Copy symbol_name_match_type fields. (event_location_deleter::operator()): Adjust to LINESPEC_LOCATION type change. (event_location_to_string): Adjust to LINESPEC_LOCATION type change. Handle "-qualfied". (string_to_explicit_location): Handle "-qualified". (string_to_event_location_basic): New symbol_name_match_type parameter. Pass it down. (string_to_event_location): Handle "-qualified". * location.h (struct linespec_location): New. (explicit_location::func_name_match_type): New field. (new_linespec_location): Now returns a const linespec_location *. (string_to_event_location_basic): New symbol_name_match_type parameter. (explicit_completion_info::saw_explicit_location_option): New field. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * python/py-breakpoint.c (bppy_init): Likewise. * python/python.c (gdbpy_decode_line): Likewise. gdb/testsuite/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.base/langs.exp: Use -qualified. * gdb.cp/meth-typedefs.exp: Use -qualified, and add tests without it. * gdb.cp/namespace.exp: Use -qualified. * gdb.linespec/cpcompletion.exp (overload-2, fqn, fqn-2) (overload-3, template-overload, template-ret-type, const-overload) (const-overload-quoted, anon-ns, ambiguous-prefix): New procedures. (test_driver): Call them. * gdb.cp/save-bp-qualified.cc: New. * gdb.cp/save-bp-qualified.exp: New. * gdb.linespec/explicit.exp: Test -qualified. * lib/completion-support.exp (completion::explicit_opts_list): Add "-qualified". * lib/gdb.exp (gdb_breakpoint): Handle "qualified". gdb/doc/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.texinfo (Linespec Locations): Document how "function" is interpreted in C++ and Ada. Document "-qualified". (Explicit Locations): Document how "-function" is interpreted in C++ and Ada. Document "-qualified".
2017-11-29 20:33:23 +01:00
cp_symbol_name_matches (const char *symbol_search_name,
const lookup_name_info &lookup_name,
completion_match_result *comp_match_res)
Introduce lookup_name_info and generalize Ada's FULL/WILD name matching Summary: - This is preparation for supporting wild name matching on C++ too. - This is also preparation for TAB-completion fixes. - Makes symbol name matching (think strcmp_iw) be based on a per-language method. - Merges completion and non-completion name comparison (think language_ops::la_get_symbol_name_cmp generalized). - Avoid re-hashing lookup name multiple times - Centralizes preparing a name for lookup (Ada name encoding / C++ Demangling), both completion and non-completion. - Fixes Ada latent bug with verbatim name matches in expressions - Makes ada-lang.c use common|symtab.c completion code a bit more. Ada's wild matching basically means that "(gdb) break foo" will find all methods named "foo" in all packages. Translating to C++, it's roughly the same as saying that "break klass::method" sets breakpoints on all "klass::method" methods of all classes, no matter the namespace. A following patch will teach GDB about fullname vs wild matching for C++ too. This patch is preparatory work to get there. Another idea here is to do symbol name matching based on the symbol language's algorithm. I.e., avoid dependency on current language set. This allows for example doing (gdb) b foo::bar< int > (<tab> and having gdb name match the C++ symbols correctly even if the current language is C or Assembly (or Rust, or Ada, or ...), which can easily happen if you step into an Assembly/C runtime library frame. By encapsulating all the information related to a lookup name in a class, we can also cache hash computation for a given language in the lookup name object, to avoid recomputing it over and over. Similarly, because we don't really know upfront which languages the lookup name will be matched against, for each language we store the lookup name transformed into a search name. E.g., for C++, that means demangling the name. But for Ada, it means encoding the name. This actually forces us to centralize all the different lookup name encoding in a central place, resulting in clearer code, IMO. See e.g., the new ada_lookup_name_info class. The lookup name -> symbol search name computation is also done only once per language. The old language->la_get_symbol_name_cmp / symbol_name_cmp_ftype are generalized to work with both completion, and normal symbol look up. At some point early on, I had separate completion vs non-completion language vector entry points, but a single method ends up being better IMO for simplifying things -- the more we merge the completion / non-completion name lookup code paths, the less changes for bugs causing completion vs normal lookup finding different symbols. The ada-lex.l change is necessary because when doing (gdb) p <UpperCase> then the name that is passed to write_ write_var_or_type -> ada_lookup_symbol_list misses the "<>", i.e., it's just "UpperCase", and we end up doing a wild match against "UpperCase" lowercased by ada_lookup_name_info's constructor. I.e., "uppercase" wouldn't ever match "UpperCase", and the symbol lookup fails. This wouldn't cause any regression in the testsuite, but I added a new test that would pass before the patch and fail after, if it weren't for that fix. This is latent bug that happens to go unnoticed because that particular path was inconsistent with the rest of Ada symbol lookup by not lowercasing the lookup name. Ada's symbol_completion_add is deleted, replaced by using common code's completion_list_add_name. To make the latter work for Ada, we needed to add a new output parameter, because Ada wants to return back a custom completion candidates that are not the symbol name. With this patch, minimal symbol demangled name hashing is made consistent with regular symbol hashing. I.e., it now goes via the language vector's search_name_hash method too, as I had suggested in a previous patch. dw2_expand_symtabs_matching / .gdb_index symbol names were a challenge. The problem is that we have no way to telling what is the language of each symbol name found in the index, until we expand the corresponding full symbol, which is off course what we're trying to avoid. Language information is simply not considered in the index format... Since the symbol name hashing and comparison routines are per-language, we now have a problem. The patch sorts this out by matching each name against all languages. This is inneficient, and indeed slows down completion several times. E.g., with: $ cat script.cmd set pagination off set $count = 0 while $count < 400 complete b string_prin printf "count = %d\n", $count set $count = $count + 1 end $ time gdb --batch -q ./gdb-with-index -ex "source script-string_printf.cmd" I get, before patch (-O2, x86-64): real 0m1.773s user 0m1.737s sys 0m0.040s While after patch (-O2, x86-64): real 0m9.843s user 0m9.482s sys 0m0.034s However, the following patch will optimize this, and will actually make this use case faster compared to the "before patch" above: real 0m1.321s user 0m1.285s sys 0m0.039s gdb/ChangeLog: 2017-11-08 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_encode): Rename to .. (ada_encode_1): ... this. Add throw_errors parameter and handle it. (ada_encode): Reimplement. (match_name): Delete, folded into full_name. (resolve_subexp): No longer pass the encoded name to ada_lookup_symbol_list. (should_use_wild_match): Delete. (name_match_type_from_name): New. (ada_lookup_simple_minsym): Use lookup_name_info and the language's symbol_name_matcher_ftype. (add_symbols_from_enclosing_procs, ada_add_local_symbols) (ada_add_block_renamings): Adjust to use lookup_name_info. (ada_lookup_name): New. (add_nonlocal_symbols, ada_add_all_symbols) (ada_lookup_symbol_list_worker, ada_lookup_symbol_list) (ada_iterate_over_symbols): Adjust to use lookup_name_info. (ada_name_for_lookup): Delete. (ada_lookup_encoded_symbol): Construct a verbatim name. (wild_match): Reverse sense of return type. Use bool. (full_match): Reverse sense of return type. Inline bits of old match_name here. (ada_add_block_symbols): Adjust to use lookup_name_info. (symbol_completion_match): Delete, folded into... (ada_lookup_name_info::matches): ... .this new method. (symbol_completion_add): Delete. (ada_collect_symbol_completion_matches): Add name_match_type parameter. Adjust to use lookup_name_info and completion_list_add_name. (get_var_value, ada_add_global_exceptions): Adjust to use lookup_name_info. (ada_get_symbol_name_cmp): Delete. (do_wild_match, do_full_match): New functions. (ada_lookup_name_info::ada_lookup_name_info): New method. (ada_symbol_name_matches, ada_get_symbol_name_matcher): New functions. (ada_language_defn): Install ada_get_symbol_name_matcher. * ada-lex.l (processId): If name starts with '<', copy it verbatim. * block.c (block_iter_match_step, block_iter_match_first) (block_iter_match_next, block_lookup_symbol) (block_lookup_symbol_primary, block_find_symbol): Adjust to use lookup_name_info. * block.h (block_iter_match_first, block_iter_match_next) (ALL_BLOCK_SYMBOLS_WITH_NAME): Adjust to use lookup_name_info. * c-lang.c (c_language_defn, cplus_language_defn) (asm_language_defn, minimal_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * completer.c (complete_files_symbols) (collect_explicit_location_matches, symbol_completer): Pass a symbol_name_match_type down. * completer.h (class completion_match, completion_match_result): New classes. (completion_tracker::reset_completion_match_result): New method. (completion_tracker::m_completion_match_result): New field. * cp-support.c (make_symbol_overload_list_block): Adjust to use lookup_name_info. (cp_fq_symbol_name_matches, cp_get_symbol_name_matcher): New functions. * cp-support.h (cp_get_symbol_name_matcher): New declaration. * d-lang.c: Adjust comments to refer to la_get_symbol_name_matcher. * dictionary.c (dict_vector) <iter_match_first, iter_match_next>: Adjust to use lookup_name_info. (dict_iter_match_first, dict_iter_match_next) (iter_match_first_hashed, iter_match_next_hashed) (iter_match_first_linear, iter_match_next_linear): Adjust to work with a lookup_name_info. * dictionary.h (dict_iter_match_first, dict_iter_match_next): Likewise. * dwarf2read.c (dw2_lookup_symbol): Adjust to use lookup_name_info. (dw2_map_matching_symbols): Adjust to use symbol_name_match_type. (gdb_index_symbol_name_matcher): New class. (dw2_expand_symtabs_matching) Adjust to use lookup_name_info and gdb_index_symbol_name_matcher. Accept a NULL symbol_matcher. * f-lang.c (f_collect_symbol_completion_matches): Adjust to work with a symbol_name_match_type. (f_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * go-lang.c (go_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * language.c (default_symbol_name_matcher) (language_get_symbol_name_matcher): New functions. (unknown_language_defn, auto_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * language.h (symbol_name_cmp_ftype): Delete. (language_defn) <la_collect_symbol_completion_matches>: Add match type parameter. <la_get_symbol_name_cmp>: Delete field. <la_get_symbol_name_matcher>: New field. <la_iterate_over_symbols>: Adjust to use lookup_name_info. (default_symbol_name_matcher, language_get_symbol_name_matcher): Declare. * linespec.c (iterate_over_all_matching_symtabs) (iterate_over_file_blocks): Adjust to use lookup_name_info. (find_methods): Add language parameter, and use lookup_name_info and the language's symbol_name_matcher_ftype. (linespec_complete_function): Adjust. (lookup_prefix_sym): Use lookup_name_info. (add_all_symbol_names_from_pspace): Adjust. (find_superclass_methods): Add language parameter and pass it down. (find_method): Pass symbol language down. (find_linespec_symbols): Don't demangle or Ada encode here. (search_minsyms_for_name): Add lookup_name_info parameter. (add_matching_symbols_to_info): Add name_match_type parameter. Use lookup_name_info. * m2-lang.c (m2_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * minsyms.c: Include <algorithm>. (add_minsym_to_demangled_hash_table): Remove table parameter and add objfile parameter. Use search_name_hash, and add language to demangled languages vector. (struct found_minimal_symbols): New struct. (lookup_minimal_symbol_mangled, lookup_minimal_symbol_demangled): New functions. (lookup_minimal_symbol): Adjust to use them. Don't canonicalize input names here. Use lookup_name_info instead. Lookup up demangled names once for each language in the demangled names vector. (iterate_over_minimal_symbols): Use lookup_name_info. Lookup up demangled names once for each language in the demangled names vector. (build_minimal_symbol_hash_tables): Adjust. * minsyms.h (iterate_over_minimal_symbols): Adjust to pass down a lookup_name_info. * objc-lang.c (objc_language_defn): Adjust comment to refer to la_get_symbol_name_matcher. * objfiles.h: Include <vector>. (objfile_per_bfd_storage) <demangled_hash_languages>: New field. * opencl-lang.c (opencl_language_defn): Adjust comment to refer to la_get_symbol_name_matcher. * p-lang.c (pascal_language_defn): Adjust comment to refer to la_get_symbol_name_matcher. * psymtab.c (psym_lookup_symbol): Use lookup_name_info. (match_partial_symbol): Use symbol_name_match_type, lookup_name_info and psymbol_name_matches. (lookup_partial_symbol): Use lookup_name_info. (map_block): Use symbol_name_match_type and lookup_name_info. (psym_map_matching_symbols): Use symbol_name_match_type. (psymbol_name_matches): New. (recursively_search_psymtabs): Use lookup_name_info and psymbol_name_matches. Rename 'kind' parameter to 'domain'. (psym_expand_symtabs_matching): Use lookup_name_info. Rename 'kind' parameter to 'domain'. * rust-lang.c (rust_language_defn): Adjust comment to refer to la_get_symbol_name_matcher. * symfile-debug.c (debug_qf_map_matching_symbols) (debug_qf_map_matching_symbols): Use symbol_name_match_type. (debug_qf_expand_symtabs_matching): Use lookup_name_info. * symfile.c (expand_symtabs_matching): Use lookup_name_info. * symfile.h (quick_symbol_functions) <map_matching_symbols>: Adjust to use symbol_name_match_type. <expand_symtabs_matching>: Adjust to use lookup_name_info. (expand_symtabs_matching): Adjust to use lookup_name_info. * symmisc.c (maintenance_expand_symtabs): Use lookup_name_info::match_any (). * symtab.c (symbol_matches_search_name): New. (eq_symbol_entry): Adjust to use lookup_name_info and the language's matcher. (demangle_for_lookup_info::demangle_for_lookup_info): New. (lookup_name_info::match_any): New. (iterate_over_symbols, search_symbols): Use lookup_name_info. (compare_symbol_name): Add language, lookup_name_info and completion_match_result parameters, and use them. (completion_list_add_name): Make extern. Add language and lookup_name_info parameters. Use them. (completion_list_add_symbol, completion_list_add_msymbol) (completion_list_objc_symbol): Add lookup_name_info parameters and adjust. Pass down language. (completion_list_add_fields): Add lookup_name_info parameters and adjust. Pass down language. (add_symtab_completions): Add lookup_name_info parameters and adjust. (default_collect_symbol_completion_matches_break_on): Add name_match_type parameter, and use it. Use lookup_name_info. (default_collect_symbol_completion_matches) (collect_symbol_completion_matches): Add name_match_type parameter, and pass it down. (collect_symbol_completion_matches_type): Adjust. (collect_file_symbol_completion_matches): Add name_match_type parameter, and use lookup_name_info. * symtab.h: Include <string> and "common/gdb_optional.h". (enum class symbol_name_match_type): New. (class ada_lookup_name_info): New. (struct demangle_for_lookup_info): New. (class lookup_name_info): New. (symbol_name_matcher_ftype): New. (SYMBOL_MATCHES_SEARCH_NAME): Use symbol_matches_search_name. (symbol_matches_search_name): Declare. (MSYMBOL_MATCHES_SEARCH_NAME): Delete. (default_collect_symbol_completion_matches) (collect_symbol_completion_matches) (collect_file_symbol_completion_matches): Add name_match_type parameter. (iterate_over_symbols): Use lookup_name_info. (completion_list_add_name): Declare. * utils.c (enum class strncmp_iw_mode): Moved to utils.h. (strncmp_iw_with_mode): Now extern. * utils.h (enum class strncmp_iw_mode): Moved from utils.c. (strncmp_iw_with_mode): Declare. gdb/testsuite/ChangeLog: 2017-11-08 Pedro Alves <palves@redhat.com> * gdb.ada/complete.exp (p <Exported_Capitalized>): New test. (p Exported_Capitalized): New test. (p exported_capitalized): New test.
2017-11-08 15:22:32 +01:00
{
/* Get the demangled name. */
const std::string &name = lookup_name.cplus ().lookup_name ();
strncmp_iw_mode mode = (lookup_name.completion_mode ()
? strncmp_iw_mode::NORMAL
: strncmp_iw_mode::MATCH_PARAMS);
Make strcmp_iw NOT ignore whitespace in the middle of tokens currently "b func tion" manages to set a breakpoint at "function" ! All these years I had never noticed this, but now that the linespec completer actually works, this easily happens by accident, with: "b func t<tab>" expecting to get "thread", but getting instead: "b func tion" ... Also, this: "b rettypefunc<int>" manages to set a breakpoint on "rettype func<int>()". These things happen due to strcmp_iw "magic". Fix it by teaching strcmp_iw about when can it skip whitespace. This required handling user-defined operators, and scope operators, complicating the code a bit, unfortunately. I added unit tests for all the corner cases I stumbled on, as I was developing this, and then in the end wrote a testsuite testcase covering many of the same things and more (to be added later). gdb/ChangeLog: 2017-11-24 Pedro Alves <palves@redhat.com> * cp-support.c (cp_symbol_name_matches_1): New, factored out from cp_fq_symbol_name_matches. Pass language_cplus to strncmp_with_mode. (cp_fq_symbol_name_matches): Call cp_symbol_name_matches_1. (selftests::test_cp_symbol_name_cmp): New. (_initialize_cp_support): Register "cp_symbol_name_matches" selftests. * language.c (default_symbol_name_matcher): Pass language_minimal to strncmp_iw_with_mode. * utils.c: Include "cp-support.h" and <algorithm>. (valid_identifier_name_char, cp_skip_operator_token, skip_ws) (cp_is_operator): New functions. (strncmp_iw_with_mode): Use them. Add language parameter. Don't skip whitespace in the symbol name when the lookup name doesn't have spaces, and vice versa. (strncmp_iw, strcmp_iw): Pass language to strncmp_iw_with_mode. * utils.h (strncmp_iw_with_mode): Add language parameter.
2017-11-25 00:30:04 +01:00
return cp_symbol_name_matches_1 (symbol_search_name,
name.c_str (), name.size (),
Handle custom completion match prefix / LCD A following patch will add support for wild matching for C++ symbols, making completing on "b push_ba" on a C++ program complete to std::vector<...>::push_back, std::string::push_back etc., like: (gdb) b push_ba[TAB] std::vector<...>::push_back(....) std::string<...>::push_back(....) Currently, we compute the "lowest common denominator" between all completion candidates (what the input line is adjusted to) as the common prefix of all matches. That's problematic with wild matching as above, as then we'd end up with TAB changing the input line to "b std::", losing the original input, like: (gdb) b push_ba[TAB] std::vector<...>::push_back(....) std::string<...>::push_back(....) (gdb) b std:: while obviously we'd want it to adjust itself to "b push_back(" instead: (gdb) b push_ba[TAB] std::vector<...>::push_back(....) std::string<...>::push_back(....) (gdb) b push_back( This patch adds the core code necessary to support this, though nothing really makes use of it yet in this patch. gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_lookup_name_info::matches): Change type of parameter from completion_match to completion_match_result. Adjust. (do_wild_match, do_full_match, ada_symbol_name_matches): Likewise. * completer.c (completion_tracker::maybe_add_completion): Add match_for_lcd parameter and use it. (completion_tracker::add_completion): Likewise. * completer.h (class completion_match_for_lcd): New class. (completion_match_result::match_for_lcd): New field. (completion_match_result::set_match): New method. (completion_tracker): Add comments. (completion_tracker::add_completion): Add match_for_lcd parameter. (completion_tracker::reset_completion_match_result): Reset match_for_lcd too. (completion_tracker::maybe_add_completion): Add match_for_lcd parameter. (completion_tracker::m_lowest_common_denominator_unique): Extend comments. * cp-support.c (cp_symbol_name_matches_1) (cp_fq_symbol_name_matches): Change type of parameter from completion_match to completion_match_result. Adjust. * language.c (default_symbol_name_matcher): Change type of parameter from completion_match to completion_match_result. Adjust. * language.h (completion_match_for_lcd): Forward declare. (default_symbol_name_matcher): Change type of parameter from completion_match to completion_match_result. * symtab.c (compare_symbol_name): Adjust. (completion_list_add_name): Pass the match_for_lcd to the tracker. * symtab.h (ada_lookup_name_info::matches): Change type of parameter from completion_match to completion_match_result. (symbol_name_matcher_ftype): Likewise, and update comments.
2017-11-29 20:33:23 +01:00
mode, comp_match_res);
Introduce lookup_name_info and generalize Ada's FULL/WILD name matching Summary: - This is preparation for supporting wild name matching on C++ too. - This is also preparation for TAB-completion fixes. - Makes symbol name matching (think strcmp_iw) be based on a per-language method. - Merges completion and non-completion name comparison (think language_ops::la_get_symbol_name_cmp generalized). - Avoid re-hashing lookup name multiple times - Centralizes preparing a name for lookup (Ada name encoding / C++ Demangling), both completion and non-completion. - Fixes Ada latent bug with verbatim name matches in expressions - Makes ada-lang.c use common|symtab.c completion code a bit more. Ada's wild matching basically means that "(gdb) break foo" will find all methods named "foo" in all packages. Translating to C++, it's roughly the same as saying that "break klass::method" sets breakpoints on all "klass::method" methods of all classes, no matter the namespace. A following patch will teach GDB about fullname vs wild matching for C++ too. This patch is preparatory work to get there. Another idea here is to do symbol name matching based on the symbol language's algorithm. I.e., avoid dependency on current language set. This allows for example doing (gdb) b foo::bar< int > (<tab> and having gdb name match the C++ symbols correctly even if the current language is C or Assembly (or Rust, or Ada, or ...), which can easily happen if you step into an Assembly/C runtime library frame. By encapsulating all the information related to a lookup name in a class, we can also cache hash computation for a given language in the lookup name object, to avoid recomputing it over and over. Similarly, because we don't really know upfront which languages the lookup name will be matched against, for each language we store the lookup name transformed into a search name. E.g., for C++, that means demangling the name. But for Ada, it means encoding the name. This actually forces us to centralize all the different lookup name encoding in a central place, resulting in clearer code, IMO. See e.g., the new ada_lookup_name_info class. The lookup name -> symbol search name computation is also done only once per language. The old language->la_get_symbol_name_cmp / symbol_name_cmp_ftype are generalized to work with both completion, and normal symbol look up. At some point early on, I had separate completion vs non-completion language vector entry points, but a single method ends up being better IMO for simplifying things -- the more we merge the completion / non-completion name lookup code paths, the less changes for bugs causing completion vs normal lookup finding different symbols. The ada-lex.l change is necessary because when doing (gdb) p <UpperCase> then the name that is passed to write_ write_var_or_type -> ada_lookup_symbol_list misses the "<>", i.e., it's just "UpperCase", and we end up doing a wild match against "UpperCase" lowercased by ada_lookup_name_info's constructor. I.e., "uppercase" wouldn't ever match "UpperCase", and the symbol lookup fails. This wouldn't cause any regression in the testsuite, but I added a new test that would pass before the patch and fail after, if it weren't for that fix. This is latent bug that happens to go unnoticed because that particular path was inconsistent with the rest of Ada symbol lookup by not lowercasing the lookup name. Ada's symbol_completion_add is deleted, replaced by using common code's completion_list_add_name. To make the latter work for Ada, we needed to add a new output parameter, because Ada wants to return back a custom completion candidates that are not the symbol name. With this patch, minimal symbol demangled name hashing is made consistent with regular symbol hashing. I.e., it now goes via the language vector's search_name_hash method too, as I had suggested in a previous patch. dw2_expand_symtabs_matching / .gdb_index symbol names were a challenge. The problem is that we have no way to telling what is the language of each symbol name found in the index, until we expand the corresponding full symbol, which is off course what we're trying to avoid. Language information is simply not considered in the index format... Since the symbol name hashing and comparison routines are per-language, we now have a problem. The patch sorts this out by matching each name against all languages. This is inneficient, and indeed slows down completion several times. E.g., with: $ cat script.cmd set pagination off set $count = 0 while $count < 400 complete b string_prin printf "count = %d\n", $count set $count = $count + 1 end $ time gdb --batch -q ./gdb-with-index -ex "source script-string_printf.cmd" I get, before patch (-O2, x86-64): real 0m1.773s user 0m1.737s sys 0m0.040s While after patch (-O2, x86-64): real 0m9.843s user 0m9.482s sys 0m0.034s However, the following patch will optimize this, and will actually make this use case faster compared to the "before patch" above: real 0m1.321s user 0m1.285s sys 0m0.039s gdb/ChangeLog: 2017-11-08 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_encode): Rename to .. (ada_encode_1): ... this. Add throw_errors parameter and handle it. (ada_encode): Reimplement. (match_name): Delete, folded into full_name. (resolve_subexp): No longer pass the encoded name to ada_lookup_symbol_list. (should_use_wild_match): Delete. (name_match_type_from_name): New. (ada_lookup_simple_minsym): Use lookup_name_info and the language's symbol_name_matcher_ftype. (add_symbols_from_enclosing_procs, ada_add_local_symbols) (ada_add_block_renamings): Adjust to use lookup_name_info. (ada_lookup_name): New. (add_nonlocal_symbols, ada_add_all_symbols) (ada_lookup_symbol_list_worker, ada_lookup_symbol_list) (ada_iterate_over_symbols): Adjust to use lookup_name_info. (ada_name_for_lookup): Delete. (ada_lookup_encoded_symbol): Construct a verbatim name. (wild_match): Reverse sense of return type. Use bool. (full_match): Reverse sense of return type. Inline bits of old match_name here. (ada_add_block_symbols): Adjust to use lookup_name_info. (symbol_completion_match): Delete, folded into... (ada_lookup_name_info::matches): ... .this new method. (symbol_completion_add): Delete. (ada_collect_symbol_completion_matches): Add name_match_type parameter. Adjust to use lookup_name_info and completion_list_add_name. (get_var_value, ada_add_global_exceptions): Adjust to use lookup_name_info. (ada_get_symbol_name_cmp): Delete. (do_wild_match, do_full_match): New functions. (ada_lookup_name_info::ada_lookup_name_info): New method. (ada_symbol_name_matches, ada_get_symbol_name_matcher): New functions. (ada_language_defn): Install ada_get_symbol_name_matcher. * ada-lex.l (processId): If name starts with '<', copy it verbatim. * block.c (block_iter_match_step, block_iter_match_first) (block_iter_match_next, block_lookup_symbol) (block_lookup_symbol_primary, block_find_symbol): Adjust to use lookup_name_info. * block.h (block_iter_match_first, block_iter_match_next) (ALL_BLOCK_SYMBOLS_WITH_NAME): Adjust to use lookup_name_info. * c-lang.c (c_language_defn, cplus_language_defn) (asm_language_defn, minimal_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * completer.c (complete_files_symbols) (collect_explicit_location_matches, symbol_completer): Pass a symbol_name_match_type down. * completer.h (class completion_match, completion_match_result): New classes. (completion_tracker::reset_completion_match_result): New method. (completion_tracker::m_completion_match_result): New field. * cp-support.c (make_symbol_overload_list_block): Adjust to use lookup_name_info. (cp_fq_symbol_name_matches, cp_get_symbol_name_matcher): New functions. * cp-support.h (cp_get_symbol_name_matcher): New declaration. * d-lang.c: Adjust comments to refer to la_get_symbol_name_matcher. * dictionary.c (dict_vector) <iter_match_first, iter_match_next>: Adjust to use lookup_name_info. (dict_iter_match_first, dict_iter_match_next) (iter_match_first_hashed, iter_match_next_hashed) (iter_match_first_linear, iter_match_next_linear): Adjust to work with a lookup_name_info. * dictionary.h (dict_iter_match_first, dict_iter_match_next): Likewise. * dwarf2read.c (dw2_lookup_symbol): Adjust to use lookup_name_info. (dw2_map_matching_symbols): Adjust to use symbol_name_match_type. (gdb_index_symbol_name_matcher): New class. (dw2_expand_symtabs_matching) Adjust to use lookup_name_info and gdb_index_symbol_name_matcher. Accept a NULL symbol_matcher. * f-lang.c (f_collect_symbol_completion_matches): Adjust to work with a symbol_name_match_type. (f_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * go-lang.c (go_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * language.c (default_symbol_name_matcher) (language_get_symbol_name_matcher): New functions. (unknown_language_defn, auto_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * language.h (symbol_name_cmp_ftype): Delete. (language_defn) <la_collect_symbol_completion_matches>: Add match type parameter. <la_get_symbol_name_cmp>: Delete field. <la_get_symbol_name_matcher>: New field. <la_iterate_over_symbols>: Adjust to use lookup_name_info. (default_symbol_name_matcher, language_get_symbol_name_matcher): Declare. * linespec.c (iterate_over_all_matching_symtabs) (iterate_over_file_blocks): Adjust to use lookup_name_info. (find_methods): Add language parameter, and use lookup_name_info and the language's symbol_name_matcher_ftype. (linespec_complete_function): Adjust. (lookup_prefix_sym): Use lookup_name_info. (add_all_symbol_names_from_pspace): Adjust. (find_superclass_methods): Add language parameter and pass it down. (find_method): Pass symbol language down. (find_linespec_symbols): Don't demangle or Ada encode here. (search_minsyms_for_name): Add lookup_name_info parameter. (add_matching_symbols_to_info): Add name_match_type parameter. Use lookup_name_info. * m2-lang.c (m2_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * minsyms.c: Include <algorithm>. (add_minsym_to_demangled_hash_table): Remove table parameter and add objfile parameter. Use search_name_hash, and add language to demangled languages vector. (struct found_minimal_symbols): New struct. (lookup_minimal_symbol_mangled, lookup_minimal_symbol_demangled): New functions. (lookup_minimal_symbol): Adjust to use them. Don't canonicalize input names here. Use lookup_name_info instead. Lookup up demangled names once for each language in the demangled names vector. (iterate_over_minimal_symbols): Use lookup_name_info. Lookup up demangled names once for each language in the demangled names vector. (build_minimal_symbol_hash_tables): Adjust. * minsyms.h (iterate_over_minimal_symbols): Adjust to pass down a lookup_name_info. * objc-lang.c (objc_language_defn): Adjust comment to refer to la_get_symbol_name_matcher. * objfiles.h: Include <vector>. (objfile_per_bfd_storage) <demangled_hash_languages>: New field. * opencl-lang.c (opencl_language_defn): Adjust comment to refer to la_get_symbol_name_matcher. * p-lang.c (pascal_language_defn): Adjust comment to refer to la_get_symbol_name_matcher. * psymtab.c (psym_lookup_symbol): Use lookup_name_info. (match_partial_symbol): Use symbol_name_match_type, lookup_name_info and psymbol_name_matches. (lookup_partial_symbol): Use lookup_name_info. (map_block): Use symbol_name_match_type and lookup_name_info. (psym_map_matching_symbols): Use symbol_name_match_type. (psymbol_name_matches): New. (recursively_search_psymtabs): Use lookup_name_info and psymbol_name_matches. Rename 'kind' parameter to 'domain'. (psym_expand_symtabs_matching): Use lookup_name_info. Rename 'kind' parameter to 'domain'. * rust-lang.c (rust_language_defn): Adjust comment to refer to la_get_symbol_name_matcher. * symfile-debug.c (debug_qf_map_matching_symbols) (debug_qf_map_matching_symbols): Use symbol_name_match_type. (debug_qf_expand_symtabs_matching): Use lookup_name_info. * symfile.c (expand_symtabs_matching): Use lookup_name_info. * symfile.h (quick_symbol_functions) <map_matching_symbols>: Adjust to use symbol_name_match_type. <expand_symtabs_matching>: Adjust to use lookup_name_info. (expand_symtabs_matching): Adjust to use lookup_name_info. * symmisc.c (maintenance_expand_symtabs): Use lookup_name_info::match_any (). * symtab.c (symbol_matches_search_name): New. (eq_symbol_entry): Adjust to use lookup_name_info and the language's matcher. (demangle_for_lookup_info::demangle_for_lookup_info): New. (lookup_name_info::match_any): New. (iterate_over_symbols, search_symbols): Use lookup_name_info. (compare_symbol_name): Add language, lookup_name_info and completion_match_result parameters, and use them. (completion_list_add_name): Make extern. Add language and lookup_name_info parameters. Use them. (completion_list_add_symbol, completion_list_add_msymbol) (completion_list_objc_symbol): Add lookup_name_info parameters and adjust. Pass down language. (completion_list_add_fields): Add lookup_name_info parameters and adjust. Pass down language. (add_symtab_completions): Add lookup_name_info parameters and adjust. (default_collect_symbol_completion_matches_break_on): Add name_match_type parameter, and use it. Use lookup_name_info. (default_collect_symbol_completion_matches) (collect_symbol_completion_matches): Add name_match_type parameter, and pass it down. (collect_symbol_completion_matches_type): Adjust. (collect_file_symbol_completion_matches): Add name_match_type parameter, and use lookup_name_info. * symtab.h: Include <string> and "common/gdb_optional.h". (enum class symbol_name_match_type): New. (class ada_lookup_name_info): New. (struct demangle_for_lookup_info): New. (class lookup_name_info): New. (symbol_name_matcher_ftype): New. (SYMBOL_MATCHES_SEARCH_NAME): Use symbol_matches_search_name. (symbol_matches_search_name): Declare. (MSYMBOL_MATCHES_SEARCH_NAME): Delete. (default_collect_symbol_completion_matches) (collect_symbol_completion_matches) (collect_file_symbol_completion_matches): Add name_match_type parameter. (iterate_over_symbols): Use lookup_name_info. (completion_list_add_name): Declare. * utils.c (enum class strncmp_iw_mode): Moved to utils.h. (strncmp_iw_with_mode): Now extern. * utils.h (enum class strncmp_iw_mode): Moved from utils.c. (strncmp_iw_with_mode): Declare. gdb/testsuite/ChangeLog: 2017-11-08 Pedro Alves <palves@redhat.com> * gdb.ada/complete.exp (p <Exported_Capitalized>): New test. (p Exported_Capitalized): New test. (p exported_capitalized): New test.
2017-11-08 15:22:32 +01:00
}
/* See cp-support.h. */
symbol_name_matcher_ftype *
cp_get_symbol_name_matcher (const lookup_name_info &lookup_name)
{
Make "break foo" find "A::foo", A::B::foo", etc. [C++ and wild matching] This patch teaches GDB about setting breakpoints in all scopes (namespaces and classes) by default. Here's a contrived example: (gdb) b func<tab> (anonymous namespace)::A::function() Bn::(anonymous namespace)::B::function() function(int, int) (anonymous namespace)::B::function() Bn::(anonymous namespace)::function() gdb::(anonymous namespace)::A::function() (anonymous namespace)::B::function() const Bn::(anonymous namespace)::function(int, int) gdb::(anonymous namespace)::function() (anonymous namespace)::function() Bn::B::func() gdb::(anonymous namespace)::function(int, int) (anonymous namespace)::function(int, int) Bn::B::function() gdb::A::func() A::func() Bn::func() gdb::A::function() A::function() Bn::function() gdb::func() B::func() Bn::function(int, int) gdb::function() B::function() Bn::function(long) gdb::function(int, int) B::function() const func() gdb::function(long) B::function_const() const function() (gdb) b function Breakpoint 1 at 0x4005ce: function. (26 locations) (gdb) b B::function<tab> (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() (gdb) b B::function Breakpoint 1 at 0x40072c: B::function. (6 locations) To get back the original behavior of interpreting the function name as a fully-qualified name, you can use the new "-qualified" (or "-q") option/flag (added by this commit). For example: (gdb) b B::function (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() vs: (gdb) b -qualified B::function B::function() B::function() const B::function_const() const I've chosen "-qualified" / "-q" because "-f" (for "full" or "fully-qualified") is already taken for "-function". Note: the "-qualified" option works with both linespecs and explicit locations. I.e., these are equivalent: (gdb) b -q func (gdb) b -q -f func and so are these: (gdb) b -q filename.cc:func (gdb) b -q -s filename.cc -f func (gdb) b -s filename.cc -q -f func (gdb) b -s filename.cc -f func -q To better understand why I consider wild matching the better default, consider what happens when we get to the point when _all_ of GDB is wrapped under "namespace gdb {}". I have a patch series that does that, and when I started debugging that GDB, I immediately became frustrated. You'd have to write "b gdb::internal_error", "b gdb::foo", "b gdb::bar", etc. etc., which gets annoying pretty quickly. OTOH, consider how this makes it very easy to set breakpoints in classes wrapped in anonymous namespaces. You just don't think of them, GDB finds the symbols for you automatically. (At the Cauldron a couple months ago, several people told me that they run into a similar issue when debugging other C++ projects. One example was when debugging LLVM, which puts all its code under the "llvm" namespace.) Implementation-wise, what the patch does is: - makes C++ symbol name hashing only consider the last component of a symbol name. (so that we can look up symbol names by last-component name only). - adds a C++ symbol name matcher for symbol_name_match_type::WILD, which ignores missing leading specifiers / components. - adjusts a few preexisting testsuite tests to use "-qualified" when they mean it. - adds new testsuite tests. - adds unit tests. Grows the gdb.linespec/ tests like this: -# of expected passes 7823 +# of expected passes 8977 gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * NEWS: Mention that breakpoints on C++ functions are now set on on all namespaces/classes by default, and mention "break -qualified". * ax-gdb.c (agent_command_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * breakpoint.c (parse_breakpoint_sals): Adjust to get_linespec_location's return type change. (strace_marker_create_sals_from_location): Adjust to pass a symbol_name_match_type to new_linespec_location. (strace_marker_decode_location): Adjust to get_linespec_location's return type change. (strace_command): Adjust to pass a symbol_name_match_type to new_linespec_location. (LOCATION_HELP_STRING): Add paragraph about wildmatching, and mention "-qualified". * c-lang.c (cplus_language_defn): Install cp_search_name_hash. * completer.c (explicit_location_match_type::MATCH_QUALIFIED): New enumerator. (complete_address_and_linespec_locations): New parameter 'match_type'. Pass it down. (explicit_options): Add "-qualified". (collect_explicit_location_matches): Pass the requested match type to the linespec completers. Handle MATCH_QUALIFIED. (location_completer): Handle "-qualified" combined with linespecs. * cp-support.c (cp_search_name_hash): New. (cp_symbol_name_matches_1): Implement wild matching for C++. (cp_fq_symbol_name_matches): Reimplement. (cp_get_symbol_name_matcher): Return different matchers depending on the lookup name's match type. (selftests::test_cp_symbol_name_matches): Add wild matching tests. * cp-support.h (cp_search_name_hash): New declaration. * dwarf2read.c (selftests::dw2_expand_symtabs_matching::test_symbols): Add symbols. (test_dw2_expand_symtabs_matching_symbol): Add wild matching tests. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Adjust to pass a symbol_name_match_type to new_linespec_location. * linespec.c (linespec_parse_basic): Lookup function symbols using the parser's symbol name match type. (convert_explicit_location_to_linespec): New symbol_name_match_type parameter. Pass it down to find_linespec_symbols. (convert_explicit_location_to_sals): Pass the location's name match type to convert_explicit_location_to_linespec. (parse_linespec): New match_type parameter. Save it in the parser. (linespec_parser_new): Default to symbol_name_match_type::WILD. (linespec_complete_function): New symbol_name_match_type parameter. Use it. (complete_linespec_component): Pass down the parser's recorded name match type. (linespec_complete_label): New symbol_name_match_type parameter. Use it. (linespec_complete): New symbol_name_match_type parameter. Save it in the parser and pass it down. Adjust to get_linespec_location's prototype change. (find_function_symbols, find_linespec_symbols): New symbol_name_match_type parameter. Pass it down instead of assuming symbol_name_match_type::WILD. * linespec.h (linespec_complete, linespec_complete_function) (linespec_complete_label): New symbol_name_match_type parameter. * location.c (event_location::linespec_location): Now a struct linespec_location. (EL_LINESPEC): Adjust. (initialize_explicit_location): Default to symbol_name_match_type::WILD. (new_linespec_location): New symbol_name_match_type parameter. Record it in the location. (get_linespec_location): Now returns a struct linespec_location. (new_explicit_location): Also copy func_name_match_type. (explicit_to_string_internal) (string_to_explicit_location): Handle "-qualified". (copy_event_location): Adjust to LINESPEC_LOCATION type change. Copy symbol_name_match_type fields. (event_location_deleter::operator()): Adjust to LINESPEC_LOCATION type change. (event_location_to_string): Adjust to LINESPEC_LOCATION type change. Handle "-qualfied". (string_to_explicit_location): Handle "-qualified". (string_to_event_location_basic): New symbol_name_match_type parameter. Pass it down. (string_to_event_location): Handle "-qualified". * location.h (struct linespec_location): New. (explicit_location::func_name_match_type): New field. (new_linespec_location): Now returns a const linespec_location *. (string_to_event_location_basic): New symbol_name_match_type parameter. (explicit_completion_info::saw_explicit_location_option): New field. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * python/py-breakpoint.c (bppy_init): Likewise. * python/python.c (gdbpy_decode_line): Likewise. gdb/testsuite/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.base/langs.exp: Use -qualified. * gdb.cp/meth-typedefs.exp: Use -qualified, and add tests without it. * gdb.cp/namespace.exp: Use -qualified. * gdb.linespec/cpcompletion.exp (overload-2, fqn, fqn-2) (overload-3, template-overload, template-ret-type, const-overload) (const-overload-quoted, anon-ns, ambiguous-prefix): New procedures. (test_driver): Call them. * gdb.cp/save-bp-qualified.cc: New. * gdb.cp/save-bp-qualified.exp: New. * gdb.linespec/explicit.exp: Test -qualified. * lib/completion-support.exp (completion::explicit_opts_list): Add "-qualified". * lib/gdb.exp (gdb_breakpoint): Handle "qualified". gdb/doc/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.texinfo (Linespec Locations): Document how "function" is interpreted in C++ and Ada. Document "-qualified". (Explicit Locations): Document how "-function" is interpreted in C++ and Ada. Document "-qualified".
2017-11-29 20:33:23 +01:00
switch (lookup_name.match_type ())
{
case symbol_name_match_type::FULL:
case symbol_name_match_type::EXPRESSION:
Fix regresssion(internal-error) printing subprogram argument (PR gdb/22670) At <https://sourceware.org/ml/gdb-patches/2017-12/msg00298.html>, Joel wrote: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Consider the following code which first declares a tagged type (the equivalent of a class in Ada), and then a procedure which takes a pointer (access) to this type's 'Class. package Pck is type Top_T is tagged record N : Integer := 1; end record; procedure Inspect (Obj: access Top_T'Class); end Pck; Putting a breakpoint in that procedure and then running to it triggers an internal error: (gdb) break inspect (gdb) continue Breakpoint 1, pck.inspect (obj=0x63e010 /[...]/gdb/stack.c:621: internal-error: void print_frame_args(symbol*, frame_info*, int, ui_file*): Assertion `nsym != NULL' failed. What's special about this subprogram is that it takes an access to what we call a 'Class type, and for implementation reasons, the compiler adds an extra argument named "objL". If you are curious why, it allows the compiler for perform dynamic accessibility checks that are mandated by the language. If we look at the location where we get the internal error (in stack.c), we find that we are looping over the symbol of each parameter, and for each parameter, we do: /* We have to look up the symbol because arguments can have two entries (one a parameter, one a local) and the one we want is the local, which lookup_symbol will find for us. [...] nsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym), b, VAR_DOMAIN, NULL).symbol; gdb_assert (nsym != NULL); The lookup_symbol goes through the lookup structure, which means the symbol's linkage name ("objL") gets transformed into a lookup_name_info object (in block_lookup_symbol), before it gets fed to the block symbol dictionary iterators. This, in turn, triggers the symbol matching by comparing the "lookup" name which, for Ada, means among other things, lowercasing the given name to "objl". It is this transformation that causes the lookup find no matches, and therefore trip this assertion. Going back to the "offending" call to lookup_symbol in stack.c, what we are trying to do, here, is do a lookup by linkage name. So, I think what we mean to be doing is a completely literal symbol lookup, so maybe not even strcmp_iw, but actually just plain strcmp??? In the past, in practice, you could get that effect by doing a lookup using the C language. But that doesn't work, because we still end up somehow using Ada's lookup_name routine which transforms "objL". So, ideally, as I hinted before, I think what we need is a way to perform a literal lookup so that searches by linkage names like the above can be performed. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This commit fixes the problem by implementing something similar to Joel's literal idea, but with some important differences. I considered adding a symbol_name_match_type::LINKAGE and supporting searching by linkage name for any language, but the problem with that is that the dictionaries only work with SYMBOL_SEARCH_NAME, because that's what is used for hashing. We'd need separate dictionaries for hashed linkage names. So with the current symbol tables infrastructure, it's not literal linkage names that we want to pass down, but instead literal _search_ names (SYMBOL_SEARCH_NAME, etc.). However, psymbols have no overload/function parameter info in C++, so a straight strcmp doesn't work properly for C++ name matching. So what we do is be a little less aggressive then and add a new symbol_name_match_type::SEARCH_SYMBOL instead that takes as input a non-user-input search symbol, and then we skip any decoding/demangling steps and make: - Ada treat that as a verbatim match, - other languages treat it as symbol_name_match_type::FULL. This also fixes the new '"maint check-psymtabs" for Ada' testcase for me (gdb.ada/maint_with_ada.exp). I've not removed the kfail yet because Joel still sees that testcase failing with this patch. That'll be fixed in follow up patches. gdb/ChangeLog: 2018-01-05 Pedro Alves <palves@redhat.com> PR gdb/22670 * ada-lang.c (literal_symbol_name_matcher): New function. (ada_get_symbol_name_matcher): Use it for symbol_name_match_type::SEARCH_NAME. * block.c (block_lookup_symbol): New parameter 'match_type'. Pass it down instead of assuming symbol_name_match_type::FULL. * block.h (block_lookup_symbol): New parameter 'match_type'. * c-valprint.c (print_unpacked_pointer): Use lookup_symbol_search_name instead of lookup_symbol. * compile/compile-object-load.c (get_out_value_type): Pass down symbol_name_match_type::SEARCH_NAME. * cp-namespace.c (cp_basic_lookup_symbol): Pass down symbol_name_match_type::FULL. * cp-support.c (cp_get_symbol_name_matcher): Handle symbol_name_match_type::SEARCH_NAME. * infrun.c (insert_exception_resume_breakpoint): Use lookup_symbol_search_name. * p-valprint.c (pascal_val_print): Use lookup_symbol_search_name. * psymtab.c (maintenance_check_psymtabs): Use symbol_name_match_type::SEARCH_NAME and SYMBOL_SEARCH_NAME. * stack.c (print_frame_args): Use lookup_symbol_search_name and SYMBOL_SEARCH_NAME. * symtab.c (lookup_local_symbol): Don't demangle the lookup name if symbol_name_match_type::SEARCH_NAME. (lookup_symbol_in_language): Pass down symbol_name_match_type::FULL. (lookup_symbol_search_name): New. (lookup_language_this): Pass down symbol_name_match_type::SEARCH_NAME. (lookup_symbol_aux, lookup_local_symbol): New parameter 'match_type'. Pass it down. * symtab.h (symbol_name_match_type::SEARCH_NAME): New enumerator. (lookup_symbol_search_name): New declaration. (lookup_symbol_in_block): New 'match_type' parameter. gdb/testsuite/ChangeLog: 2018-01-05 Joel Brobecker <brobecker@adacore.com> PR gdb/22670 * gdb.ada/access_tagged_param.exp: New file. * gdb.ada/access_tagged_param/foo.adb: New file.
2018-01-05 15:04:09 +01:00
case symbol_name_match_type::SEARCH_NAME:
Make "break foo" find "A::foo", A::B::foo", etc. [C++ and wild matching] This patch teaches GDB about setting breakpoints in all scopes (namespaces and classes) by default. Here's a contrived example: (gdb) b func<tab> (anonymous namespace)::A::function() Bn::(anonymous namespace)::B::function() function(int, int) (anonymous namespace)::B::function() Bn::(anonymous namespace)::function() gdb::(anonymous namespace)::A::function() (anonymous namespace)::B::function() const Bn::(anonymous namespace)::function(int, int) gdb::(anonymous namespace)::function() (anonymous namespace)::function() Bn::B::func() gdb::(anonymous namespace)::function(int, int) (anonymous namespace)::function(int, int) Bn::B::function() gdb::A::func() A::func() Bn::func() gdb::A::function() A::function() Bn::function() gdb::func() B::func() Bn::function(int, int) gdb::function() B::function() Bn::function(long) gdb::function(int, int) B::function() const func() gdb::function(long) B::function_const() const function() (gdb) b function Breakpoint 1 at 0x4005ce: function. (26 locations) (gdb) b B::function<tab> (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() (gdb) b B::function Breakpoint 1 at 0x40072c: B::function. (6 locations) To get back the original behavior of interpreting the function name as a fully-qualified name, you can use the new "-qualified" (or "-q") option/flag (added by this commit). For example: (gdb) b B::function (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() vs: (gdb) b -qualified B::function B::function() B::function() const B::function_const() const I've chosen "-qualified" / "-q" because "-f" (for "full" or "fully-qualified") is already taken for "-function". Note: the "-qualified" option works with both linespecs and explicit locations. I.e., these are equivalent: (gdb) b -q func (gdb) b -q -f func and so are these: (gdb) b -q filename.cc:func (gdb) b -q -s filename.cc -f func (gdb) b -s filename.cc -q -f func (gdb) b -s filename.cc -f func -q To better understand why I consider wild matching the better default, consider what happens when we get to the point when _all_ of GDB is wrapped under "namespace gdb {}". I have a patch series that does that, and when I started debugging that GDB, I immediately became frustrated. You'd have to write "b gdb::internal_error", "b gdb::foo", "b gdb::bar", etc. etc., which gets annoying pretty quickly. OTOH, consider how this makes it very easy to set breakpoints in classes wrapped in anonymous namespaces. You just don't think of them, GDB finds the symbols for you automatically. (At the Cauldron a couple months ago, several people told me that they run into a similar issue when debugging other C++ projects. One example was when debugging LLVM, which puts all its code under the "llvm" namespace.) Implementation-wise, what the patch does is: - makes C++ symbol name hashing only consider the last component of a symbol name. (so that we can look up symbol names by last-component name only). - adds a C++ symbol name matcher for symbol_name_match_type::WILD, which ignores missing leading specifiers / components. - adjusts a few preexisting testsuite tests to use "-qualified" when they mean it. - adds new testsuite tests. - adds unit tests. Grows the gdb.linespec/ tests like this: -# of expected passes 7823 +# of expected passes 8977 gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * NEWS: Mention that breakpoints on C++ functions are now set on on all namespaces/classes by default, and mention "break -qualified". * ax-gdb.c (agent_command_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * breakpoint.c (parse_breakpoint_sals): Adjust to get_linespec_location's return type change. (strace_marker_create_sals_from_location): Adjust to pass a symbol_name_match_type to new_linespec_location. (strace_marker_decode_location): Adjust to get_linespec_location's return type change. (strace_command): Adjust to pass a symbol_name_match_type to new_linespec_location. (LOCATION_HELP_STRING): Add paragraph about wildmatching, and mention "-qualified". * c-lang.c (cplus_language_defn): Install cp_search_name_hash. * completer.c (explicit_location_match_type::MATCH_QUALIFIED): New enumerator. (complete_address_and_linespec_locations): New parameter 'match_type'. Pass it down. (explicit_options): Add "-qualified". (collect_explicit_location_matches): Pass the requested match type to the linespec completers. Handle MATCH_QUALIFIED. (location_completer): Handle "-qualified" combined with linespecs. * cp-support.c (cp_search_name_hash): New. (cp_symbol_name_matches_1): Implement wild matching for C++. (cp_fq_symbol_name_matches): Reimplement. (cp_get_symbol_name_matcher): Return different matchers depending on the lookup name's match type. (selftests::test_cp_symbol_name_matches): Add wild matching tests. * cp-support.h (cp_search_name_hash): New declaration. * dwarf2read.c (selftests::dw2_expand_symtabs_matching::test_symbols): Add symbols. (test_dw2_expand_symtabs_matching_symbol): Add wild matching tests. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Adjust to pass a symbol_name_match_type to new_linespec_location. * linespec.c (linespec_parse_basic): Lookup function symbols using the parser's symbol name match type. (convert_explicit_location_to_linespec): New symbol_name_match_type parameter. Pass it down to find_linespec_symbols. (convert_explicit_location_to_sals): Pass the location's name match type to convert_explicit_location_to_linespec. (parse_linespec): New match_type parameter. Save it in the parser. (linespec_parser_new): Default to symbol_name_match_type::WILD. (linespec_complete_function): New symbol_name_match_type parameter. Use it. (complete_linespec_component): Pass down the parser's recorded name match type. (linespec_complete_label): New symbol_name_match_type parameter. Use it. (linespec_complete): New symbol_name_match_type parameter. Save it in the parser and pass it down. Adjust to get_linespec_location's prototype change. (find_function_symbols, find_linespec_symbols): New symbol_name_match_type parameter. Pass it down instead of assuming symbol_name_match_type::WILD. * linespec.h (linespec_complete, linespec_complete_function) (linespec_complete_label): New symbol_name_match_type parameter. * location.c (event_location::linespec_location): Now a struct linespec_location. (EL_LINESPEC): Adjust. (initialize_explicit_location): Default to symbol_name_match_type::WILD. (new_linespec_location): New symbol_name_match_type parameter. Record it in the location. (get_linespec_location): Now returns a struct linespec_location. (new_explicit_location): Also copy func_name_match_type. (explicit_to_string_internal) (string_to_explicit_location): Handle "-qualified". (copy_event_location): Adjust to LINESPEC_LOCATION type change. Copy symbol_name_match_type fields. (event_location_deleter::operator()): Adjust to LINESPEC_LOCATION type change. (event_location_to_string): Adjust to LINESPEC_LOCATION type change. Handle "-qualfied". (string_to_explicit_location): Handle "-qualified". (string_to_event_location_basic): New symbol_name_match_type parameter. Pass it down. (string_to_event_location): Handle "-qualified". * location.h (struct linespec_location): New. (explicit_location::func_name_match_type): New field. (new_linespec_location): Now returns a const linespec_location *. (string_to_event_location_basic): New symbol_name_match_type parameter. (explicit_completion_info::saw_explicit_location_option): New field. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * python/py-breakpoint.c (bppy_init): Likewise. * python/python.c (gdbpy_decode_line): Likewise. gdb/testsuite/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.base/langs.exp: Use -qualified. * gdb.cp/meth-typedefs.exp: Use -qualified, and add tests without it. * gdb.cp/namespace.exp: Use -qualified. * gdb.linespec/cpcompletion.exp (overload-2, fqn, fqn-2) (overload-3, template-overload, template-ret-type, const-overload) (const-overload-quoted, anon-ns, ambiguous-prefix): New procedures. (test_driver): Call them. * gdb.cp/save-bp-qualified.cc: New. * gdb.cp/save-bp-qualified.exp: New. * gdb.linespec/explicit.exp: Test -qualified. * lib/completion-support.exp (completion::explicit_opts_list): Add "-qualified". * lib/gdb.exp (gdb_breakpoint): Handle "qualified". gdb/doc/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.texinfo (Linespec Locations): Document how "function" is interpreted in C++ and Ada. Document "-qualified". (Explicit Locations): Document how "-function" is interpreted in C++ and Ada. Document "-qualified".
2017-11-29 20:33:23 +01:00
return cp_fq_symbol_name_matches;
case symbol_name_match_type::WILD:
return cp_symbol_name_matches;
}
gdb_assert_not_reached ("");
Introduce lookup_name_info and generalize Ada's FULL/WILD name matching Summary: - This is preparation for supporting wild name matching on C++ too. - This is also preparation for TAB-completion fixes. - Makes symbol name matching (think strcmp_iw) be based on a per-language method. - Merges completion and non-completion name comparison (think language_ops::la_get_symbol_name_cmp generalized). - Avoid re-hashing lookup name multiple times - Centralizes preparing a name for lookup (Ada name encoding / C++ Demangling), both completion and non-completion. - Fixes Ada latent bug with verbatim name matches in expressions - Makes ada-lang.c use common|symtab.c completion code a bit more. Ada's wild matching basically means that "(gdb) break foo" will find all methods named "foo" in all packages. Translating to C++, it's roughly the same as saying that "break klass::method" sets breakpoints on all "klass::method" methods of all classes, no matter the namespace. A following patch will teach GDB about fullname vs wild matching for C++ too. This patch is preparatory work to get there. Another idea here is to do symbol name matching based on the symbol language's algorithm. I.e., avoid dependency on current language set. This allows for example doing (gdb) b foo::bar< int > (<tab> and having gdb name match the C++ symbols correctly even if the current language is C or Assembly (or Rust, or Ada, or ...), which can easily happen if you step into an Assembly/C runtime library frame. By encapsulating all the information related to a lookup name in a class, we can also cache hash computation for a given language in the lookup name object, to avoid recomputing it over and over. Similarly, because we don't really know upfront which languages the lookup name will be matched against, for each language we store the lookup name transformed into a search name. E.g., for C++, that means demangling the name. But for Ada, it means encoding the name. This actually forces us to centralize all the different lookup name encoding in a central place, resulting in clearer code, IMO. See e.g., the new ada_lookup_name_info class. The lookup name -> symbol search name computation is also done only once per language. The old language->la_get_symbol_name_cmp / symbol_name_cmp_ftype are generalized to work with both completion, and normal symbol look up. At some point early on, I had separate completion vs non-completion language vector entry points, but a single method ends up being better IMO for simplifying things -- the more we merge the completion / non-completion name lookup code paths, the less changes for bugs causing completion vs normal lookup finding different symbols. The ada-lex.l change is necessary because when doing (gdb) p <UpperCase> then the name that is passed to write_ write_var_or_type -> ada_lookup_symbol_list misses the "<>", i.e., it's just "UpperCase", and we end up doing a wild match against "UpperCase" lowercased by ada_lookup_name_info's constructor. I.e., "uppercase" wouldn't ever match "UpperCase", and the symbol lookup fails. This wouldn't cause any regression in the testsuite, but I added a new test that would pass before the patch and fail after, if it weren't for that fix. This is latent bug that happens to go unnoticed because that particular path was inconsistent with the rest of Ada symbol lookup by not lowercasing the lookup name. Ada's symbol_completion_add is deleted, replaced by using common code's completion_list_add_name. To make the latter work for Ada, we needed to add a new output parameter, because Ada wants to return back a custom completion candidates that are not the symbol name. With this patch, minimal symbol demangled name hashing is made consistent with regular symbol hashing. I.e., it now goes via the language vector's search_name_hash method too, as I had suggested in a previous patch. dw2_expand_symtabs_matching / .gdb_index symbol names were a challenge. The problem is that we have no way to telling what is the language of each symbol name found in the index, until we expand the corresponding full symbol, which is off course what we're trying to avoid. Language information is simply not considered in the index format... Since the symbol name hashing and comparison routines are per-language, we now have a problem. The patch sorts this out by matching each name against all languages. This is inneficient, and indeed slows down completion several times. E.g., with: $ cat script.cmd set pagination off set $count = 0 while $count < 400 complete b string_prin printf "count = %d\n", $count set $count = $count + 1 end $ time gdb --batch -q ./gdb-with-index -ex "source script-string_printf.cmd" I get, before patch (-O2, x86-64): real 0m1.773s user 0m1.737s sys 0m0.040s While after patch (-O2, x86-64): real 0m9.843s user 0m9.482s sys 0m0.034s However, the following patch will optimize this, and will actually make this use case faster compared to the "before patch" above: real 0m1.321s user 0m1.285s sys 0m0.039s gdb/ChangeLog: 2017-11-08 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_encode): Rename to .. (ada_encode_1): ... this. Add throw_errors parameter and handle it. (ada_encode): Reimplement. (match_name): Delete, folded into full_name. (resolve_subexp): No longer pass the encoded name to ada_lookup_symbol_list. (should_use_wild_match): Delete. (name_match_type_from_name): New. (ada_lookup_simple_minsym): Use lookup_name_info and the language's symbol_name_matcher_ftype. (add_symbols_from_enclosing_procs, ada_add_local_symbols) (ada_add_block_renamings): Adjust to use lookup_name_info. (ada_lookup_name): New. (add_nonlocal_symbols, ada_add_all_symbols) (ada_lookup_symbol_list_worker, ada_lookup_symbol_list) (ada_iterate_over_symbols): Adjust to use lookup_name_info. (ada_name_for_lookup): Delete. (ada_lookup_encoded_symbol): Construct a verbatim name. (wild_match): Reverse sense of return type. Use bool. (full_match): Reverse sense of return type. Inline bits of old match_name here. (ada_add_block_symbols): Adjust to use lookup_name_info. (symbol_completion_match): Delete, folded into... (ada_lookup_name_info::matches): ... .this new method. (symbol_completion_add): Delete. (ada_collect_symbol_completion_matches): Add name_match_type parameter. Adjust to use lookup_name_info and completion_list_add_name. (get_var_value, ada_add_global_exceptions): Adjust to use lookup_name_info. (ada_get_symbol_name_cmp): Delete. (do_wild_match, do_full_match): New functions. (ada_lookup_name_info::ada_lookup_name_info): New method. (ada_symbol_name_matches, ada_get_symbol_name_matcher): New functions. (ada_language_defn): Install ada_get_symbol_name_matcher. * ada-lex.l (processId): If name starts with '<', copy it verbatim. * block.c (block_iter_match_step, block_iter_match_first) (block_iter_match_next, block_lookup_symbol) (block_lookup_symbol_primary, block_find_symbol): Adjust to use lookup_name_info. * block.h (block_iter_match_first, block_iter_match_next) (ALL_BLOCK_SYMBOLS_WITH_NAME): Adjust to use lookup_name_info. * c-lang.c (c_language_defn, cplus_language_defn) (asm_language_defn, minimal_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * completer.c (complete_files_symbols) (collect_explicit_location_matches, symbol_completer): Pass a symbol_name_match_type down. * completer.h (class completion_match, completion_match_result): New classes. (completion_tracker::reset_completion_match_result): New method. (completion_tracker::m_completion_match_result): New field. * cp-support.c (make_symbol_overload_list_block): Adjust to use lookup_name_info. (cp_fq_symbol_name_matches, cp_get_symbol_name_matcher): New functions. * cp-support.h (cp_get_symbol_name_matcher): New declaration. * d-lang.c: Adjust comments to refer to la_get_symbol_name_matcher. * dictionary.c (dict_vector) <iter_match_first, iter_match_next>: Adjust to use lookup_name_info. (dict_iter_match_first, dict_iter_match_next) (iter_match_first_hashed, iter_match_next_hashed) (iter_match_first_linear, iter_match_next_linear): Adjust to work with a lookup_name_info. * dictionary.h (dict_iter_match_first, dict_iter_match_next): Likewise. * dwarf2read.c (dw2_lookup_symbol): Adjust to use lookup_name_info. (dw2_map_matching_symbols): Adjust to use symbol_name_match_type. (gdb_index_symbol_name_matcher): New class. (dw2_expand_symtabs_matching) Adjust to use lookup_name_info and gdb_index_symbol_name_matcher. Accept a NULL symbol_matcher. * f-lang.c (f_collect_symbol_completion_matches): Adjust to work with a symbol_name_match_type. (f_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * go-lang.c (go_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * language.c (default_symbol_name_matcher) (language_get_symbol_name_matcher): New functions. (unknown_language_defn, auto_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * language.h (symbol_name_cmp_ftype): Delete. (language_defn) <la_collect_symbol_completion_matches>: Add match type parameter. <la_get_symbol_name_cmp>: Delete field. <la_get_symbol_name_matcher>: New field. <la_iterate_over_symbols>: Adjust to use lookup_name_info. (default_symbol_name_matcher, language_get_symbol_name_matcher): Declare. * linespec.c (iterate_over_all_matching_symtabs) (iterate_over_file_blocks): Adjust to use lookup_name_info. (find_methods): Add language parameter, and use lookup_name_info and the language's symbol_name_matcher_ftype. (linespec_complete_function): Adjust. (lookup_prefix_sym): Use lookup_name_info. (add_all_symbol_names_from_pspace): Adjust. (find_superclass_methods): Add language parameter and pass it down. (find_method): Pass symbol language down. (find_linespec_symbols): Don't demangle or Ada encode here. (search_minsyms_for_name): Add lookup_name_info parameter. (add_matching_symbols_to_info): Add name_match_type parameter. Use lookup_name_info. * m2-lang.c (m2_language_defn): Adjust comments to refer to la_get_symbol_name_matcher. * minsyms.c: Include <algorithm>. (add_minsym_to_demangled_hash_table): Remove table parameter and add objfile parameter. Use search_name_hash, and add language to demangled languages vector. (struct found_minimal_symbols): New struct. (lookup_minimal_symbol_mangled, lookup_minimal_symbol_demangled): New functions. (lookup_minimal_symbol): Adjust to use them. Don't canonicalize input names here. Use lookup_name_info instead. Lookup up demangled names once for each language in the demangled names vector. (iterate_over_minimal_symbols): Use lookup_name_info. Lookup up demangled names once for each language in the demangled names vector. (build_minimal_symbol_hash_tables): Adjust. * minsyms.h (iterate_over_minimal_symbols): Adjust to pass down a lookup_name_info. * objc-lang.c (objc_language_defn): Adjust comment to refer to la_get_symbol_name_matcher. * objfiles.h: Include <vector>. (objfile_per_bfd_storage) <demangled_hash_languages>: New field. * opencl-lang.c (opencl_language_defn): Adjust comment to refer to la_get_symbol_name_matcher. * p-lang.c (pascal_language_defn): Adjust comment to refer to la_get_symbol_name_matcher. * psymtab.c (psym_lookup_symbol): Use lookup_name_info. (match_partial_symbol): Use symbol_name_match_type, lookup_name_info and psymbol_name_matches. (lookup_partial_symbol): Use lookup_name_info. (map_block): Use symbol_name_match_type and lookup_name_info. (psym_map_matching_symbols): Use symbol_name_match_type. (psymbol_name_matches): New. (recursively_search_psymtabs): Use lookup_name_info and psymbol_name_matches. Rename 'kind' parameter to 'domain'. (psym_expand_symtabs_matching): Use lookup_name_info. Rename 'kind' parameter to 'domain'. * rust-lang.c (rust_language_defn): Adjust comment to refer to la_get_symbol_name_matcher. * symfile-debug.c (debug_qf_map_matching_symbols) (debug_qf_map_matching_symbols): Use symbol_name_match_type. (debug_qf_expand_symtabs_matching): Use lookup_name_info. * symfile.c (expand_symtabs_matching): Use lookup_name_info. * symfile.h (quick_symbol_functions) <map_matching_symbols>: Adjust to use symbol_name_match_type. <expand_symtabs_matching>: Adjust to use lookup_name_info. (expand_symtabs_matching): Adjust to use lookup_name_info. * symmisc.c (maintenance_expand_symtabs): Use lookup_name_info::match_any (). * symtab.c (symbol_matches_search_name): New. (eq_symbol_entry): Adjust to use lookup_name_info and the language's matcher. (demangle_for_lookup_info::demangle_for_lookup_info): New. (lookup_name_info::match_any): New. (iterate_over_symbols, search_symbols): Use lookup_name_info. (compare_symbol_name): Add language, lookup_name_info and completion_match_result parameters, and use them. (completion_list_add_name): Make extern. Add language and lookup_name_info parameters. Use them. (completion_list_add_symbol, completion_list_add_msymbol) (completion_list_objc_symbol): Add lookup_name_info parameters and adjust. Pass down language. (completion_list_add_fields): Add lookup_name_info parameters and adjust. Pass down language. (add_symtab_completions): Add lookup_name_info parameters and adjust. (default_collect_symbol_completion_matches_break_on): Add name_match_type parameter, and use it. Use lookup_name_info. (default_collect_symbol_completion_matches) (collect_symbol_completion_matches): Add name_match_type parameter, and pass it down. (collect_symbol_completion_matches_type): Adjust. (collect_file_symbol_completion_matches): Add name_match_type parameter, and use lookup_name_info. * symtab.h: Include <string> and "common/gdb_optional.h". (enum class symbol_name_match_type): New. (class ada_lookup_name_info): New. (struct demangle_for_lookup_info): New. (class lookup_name_info): New. (symbol_name_matcher_ftype): New. (SYMBOL_MATCHES_SEARCH_NAME): Use symbol_matches_search_name. (symbol_matches_search_name): Declare. (MSYMBOL_MATCHES_SEARCH_NAME): Delete. (default_collect_symbol_completion_matches) (collect_symbol_completion_matches) (collect_file_symbol_completion_matches): Add name_match_type parameter. (iterate_over_symbols): Use lookup_name_info. (completion_list_add_name): Declare. * utils.c (enum class strncmp_iw_mode): Moved to utils.h. (strncmp_iw_with_mode): Now extern. * utils.h (enum class strncmp_iw_mode): Moved from utils.c. (strncmp_iw_with_mode): Declare. gdb/testsuite/ChangeLog: 2017-11-08 Pedro Alves <palves@redhat.com> * gdb.ada/complete.exp (p <Exported_Capitalized>): New test. (p Exported_Capitalized): New test. (p exported_capitalized): New test.
2017-11-08 15:22:32 +01:00
}
lookup_name_info::make_ignore_params A few places in the completion code look for a "(" to find a function's parameter list, in order to strip it, because psymtabs (and gdb index) don't include parameter info in the symbol names. See compare_symbol_name and default_collect_symbol_completion_matches_break_on. This is too naive. Consider: ns_overload2_test::([TAB] We'd want to complete that to: ns_overload2_test::(anonymous namespace)::struct_overload2_test Or: b (anonymous namespace)::[TAB] That currently completes to: b (anonymous namespace) Which is obviously broken. This patch makes that work. Also, the current compare_symbol_name hack means that while this works: "b function([TAB]" -> "b function()" This does not: "b function ([TAB]" This patch fixes that. Whitespace "ignoring" now Just Works, i.e., assuming a symbol named "function(int, long)", this: b function ( int , lon[TAB] completes to: b function ( int , long) To address all of this, this patch builds on top of the rest of the series, and pushes the responsibility of stripping parameters from a lookup name to the new lookup_name_info object, where we can apply per-language rules. Also note that we now only make a version of the lookup name with parameters stripped out where it's actually required to do that, in the psymtab and GDB index code. For C++, the right way to strip parameters is with "cp_remove_params", which uses a real parser (cp-name-parser.y) to split the name into a component tree and then discards parameters. The trouble for completion is that in that case we have an incomplete name, like "foo::func(int" and thus cp_remove_params throws an error. This patch sorts that by adding a cp_remove_params_if_any variant of cp_remove_params that tries removing characters from the end of the string until cp_remove_params works. So cp_remove_params_if_any behaves like this: With a complete name: "foo::func(int)" => foo::func(int) # cp_remove_params_1 succeeds the first time. With an incomplete name: "foo::func(int" => NULL # cp_remove_params fails the first time. "foo::func(in" => NULL # and again... "foo::func(i" => NULL # and again... "foo::func(" => NULL # and again... "foo::func" => "foo::func" # success! Note that even if this approach removes significant rightmost characters, it's still OK, because this parameter stripping is only necessary for psymtabs and gdb index, where we're determining whether to expand a symbol table. Say cp_remove_params_if_any returned "foo::" above for "foo::func(int". That'd cause us to expand more symtabs than ideal (because we'd expand all symtabs with symbols that start with "foo::", not just "foo::func"), but then when we actually look for completion matches, we'd still use the original lookup name, with parameter information ["foo::func(int"], and thus we'll return no false positive to the user. Whether the stripping works as intended and doesn't strip too much is thus covered by a unit test instead of a testsuite test. The "if_any" part of the name refers to the fact that while cp_remove_params returns NULL if the input name has no parameters in the first place, like: "foo::func" => NULL # cp_remove_params cp_remove_params_if_any still returns the function name: "foo::func" => "foo::func" # cp_remove_params_if_any gdb/ChangeLog: 2017-11-08 Pedro Alves <palves@redhat.com> * Makefile.in (SUBDIR_UNITTESTS_SRCS): Add unittests/lookup_name_info-selftests.c. (SUBDIR_UNITTESTS_OBS): Add lookup_name_info-selftests.o. * cp-support.c: Include "selftest.h". (cp_remove_params_1): Rename from cp_remove_params. Add 'require_param' parameter, and handle it. (cp_remove_params): Reimplement. (cp_remove_params_if_any): New. (selftests::quote): New. (selftests::check_remove_params): New. (selftests::test_cp_remove_params): New. (_initialize_cp_support): Install selftests::test_cp_remove_params. * cp-support.h (cp_remove_params_if_any): Declare. * dwarf2read.c :Include "selftest.h". (dw2_expand_symtabs_matching_symbol): Use lookup_name_info::make_ignore_params. (selftests::dw2_expand_symtabs_matching::mock_mapped_index) (selftests::dw2_expand_symtabs_matching::string_or_null) (selftests::dw2_expand_symtabs_matching::check_match) (selftests::dw2_expand_symtabs_matching::test_symbols) (selftests::dw2_expand_symtabs_matching::run_test): New. (_initialize_dwarf2_read): Register selftests::dw2_expand_symtabs_matching::run_test. * psymtab.c (psym_expand_symtabs_matching): Use lookup_name_info::make_ignore_params. * symtab.c (demangle_for_lookup_info::demangle_for_lookup_info): If the lookup name wants to ignore parameters, strip them. (compare_symbol_name): Remove sym_text/sym_text_len parameters and code handling '('. (completion_list_add_name): Don't pass down sym_text/sym_text_len. (default_collect_symbol_completion_matches_break_on): Don't try to strip parameters. * symtab.h (lookup_name_info::lookup_name_info): Add 'ignore_parameters' parameter. (lookup_name_info::ignore_parameters) (lookup_name_info::make_ignore_params): New methods. (lookup_name_info::m_ignore_parameters): New field. * unittests/lookup_name_info-selftests.c: New file.
2017-11-08 15:49:10 +01:00
#if GDB_SELF_TEST
namespace selftests {
static void
Make strcmp_iw NOT ignore whitespace in the middle of tokens currently "b func tion" manages to set a breakpoint at "function" ! All these years I had never noticed this, but now that the linespec completer actually works, this easily happens by accident, with: "b func t<tab>" expecting to get "thread", but getting instead: "b func tion" ... Also, this: "b rettypefunc<int>" manages to set a breakpoint on "rettype func<int>()". These things happen due to strcmp_iw "magic". Fix it by teaching strcmp_iw about when can it skip whitespace. This required handling user-defined operators, and scope operators, complicating the code a bit, unfortunately. I added unit tests for all the corner cases I stumbled on, as I was developing this, and then in the end wrote a testsuite testcase covering many of the same things and more (to be added later). gdb/ChangeLog: 2017-11-24 Pedro Alves <palves@redhat.com> * cp-support.c (cp_symbol_name_matches_1): New, factored out from cp_fq_symbol_name_matches. Pass language_cplus to strncmp_with_mode. (cp_fq_symbol_name_matches): Call cp_symbol_name_matches_1. (selftests::test_cp_symbol_name_cmp): New. (_initialize_cp_support): Register "cp_symbol_name_matches" selftests. * language.c (default_symbol_name_matcher): Pass language_minimal to strncmp_iw_with_mode. * utils.c: Include "cp-support.h" and <algorithm>. (valid_identifier_name_char, cp_skip_operator_token, skip_ws) (cp_is_operator): New functions. (strncmp_iw_with_mode): Use them. Add language parameter. Don't skip whitespace in the symbol name when the lookup name doesn't have spaces, and vice versa. (strncmp_iw, strcmp_iw): Pass language to strncmp_iw_with_mode. * utils.h (strncmp_iw_with_mode): Add language parameter.
2017-11-25 00:30:04 +01:00
test_cp_symbol_name_matches ()
{
#define CHECK_MATCH(SYMBOL, INPUT) \
SELF_CHECK (cp_symbol_name_matches_1 (SYMBOL, \
INPUT, sizeof (INPUT) - 1, \
strncmp_iw_mode::MATCH_PARAMS, \
NULL))
#define CHECK_NOT_MATCH(SYMBOL, INPUT) \
SELF_CHECK (!cp_symbol_name_matches_1 (SYMBOL, \
INPUT, sizeof (INPUT) - 1, \
strncmp_iw_mode::MATCH_PARAMS, \
NULL))
/* Like CHECK_MATCH, and also check that INPUT (and all substrings
that start at index 0) completes to SYMBOL. */
#define CHECK_MATCH_C(SYMBOL, INPUT) \
do \
{ \
CHECK_MATCH (SYMBOL, INPUT); \
for (size_t i = 0; i < sizeof (INPUT) - 1; i++) \
SELF_CHECK (cp_symbol_name_matches_1 (SYMBOL, INPUT, i, \
strncmp_iw_mode::NORMAL, \
NULL)); \
} while (0)
/* Like CHECK_NOT_MATCH, and also check that INPUT does NOT complete
to SYMBOL. */
#define CHECK_NOT_MATCH_C(SYMBOL, INPUT) \
do \
{ \
CHECK_NOT_MATCH (SYMBOL, INPUT); \
SELF_CHECK (!cp_symbol_name_matches_1 (SYMBOL, INPUT, \
sizeof (INPUT) - 1, \
strncmp_iw_mode::NORMAL, \
NULL)); \
} while (0)
/* Lookup name without parens matches all overloads. */
CHECK_MATCH_C ("function()", "function");
CHECK_MATCH_C ("function(int)", "function");
/* Check whitespace around parameters is ignored. */
CHECK_MATCH_C ("function()", "function ()");
CHECK_MATCH_C ("function ( )", "function()");
CHECK_MATCH_C ("function ()", "function( )");
CHECK_MATCH_C ("func(int)", "func( int )");
CHECK_MATCH_C ("func(int)", "func ( int ) ");
CHECK_MATCH_C ("func ( int )", "func( int )");
CHECK_MATCH_C ("func ( int )", "func ( int ) ");
/* Check symbol name prefixes aren't incorrectly matched. */
CHECK_NOT_MATCH ("func", "function");
CHECK_NOT_MATCH ("function", "func");
CHECK_NOT_MATCH ("function()", "func");
/* Check that if the lookup name includes parameters, only the right
overload matches. */
CHECK_MATCH_C ("function(int)", "function(int)");
CHECK_NOT_MATCH_C ("function(int)", "function()");
/* Check that whitespace within symbol names is not ignored. */
CHECK_NOT_MATCH_C ("function", "func tion");
CHECK_NOT_MATCH_C ("func__tion", "func_ _tion");
CHECK_NOT_MATCH_C ("func11tion", "func1 1tion");
/* Check the converse, which can happen with template function,
where the return type is part of the demangled name. */
CHECK_NOT_MATCH_C ("func tion", "function");
CHECK_NOT_MATCH_C ("func1 1tion", "func11tion");
CHECK_NOT_MATCH_C ("func_ _tion", "func__tion");
/* Within parameters too. */
CHECK_NOT_MATCH_C ("func(param)", "func(par am)");
/* Check handling of whitespace around C++ operators. */
CHECK_NOT_MATCH_C ("operator<<", "opera tor<<");
CHECK_NOT_MATCH_C ("operator<<", "operator< <");
CHECK_NOT_MATCH_C ("operator<<", "operator < <");
CHECK_NOT_MATCH_C ("operator==", "operator= =");
CHECK_NOT_MATCH_C ("operator==", "operator = =");
CHECK_MATCH_C ("operator<<", "operator <<");
CHECK_MATCH_C ("operator<<()", "operator <<");
CHECK_NOT_MATCH_C ("operator<<()", "operator<<(int)");
CHECK_NOT_MATCH_C ("operator<<(int)", "operator<<()");
CHECK_MATCH_C ("operator==", "operator ==");
CHECK_MATCH_C ("operator==()", "operator ==");
CHECK_MATCH_C ("operator <<", "operator<<");
CHECK_MATCH_C ("operator ==", "operator==");
CHECK_MATCH_C ("operator bool", "operator bool");
CHECK_MATCH_C ("operator bool ()", "operator bool");
CHECK_MATCH_C ("operatorX<<", "operatorX < <");
CHECK_MATCH_C ("Xoperator<<", "Xoperator < <");
CHECK_MATCH_C ("operator()(int)", "operator()(int)");
CHECK_MATCH_C ("operator()(int)", "operator ( ) ( int )");
CHECK_MATCH_C ("operator()<long>(int)", "operator ( ) < long > ( int )");
/* The first "()" is not the parameter list. */
CHECK_NOT_MATCH ("operator()(int)", "operator");
/* Misc user-defined operator tests. */
CHECK_NOT_MATCH_C ("operator/=()", "operator ^=");
/* Same length at end of input. */
CHECK_NOT_MATCH_C ("operator>>", "operator[]");
/* Same length but not at end of input. */
CHECK_NOT_MATCH_C ("operator>>()", "operator[]()");
CHECK_MATCH_C ("base::operator char*()", "base::operator char*()");
CHECK_MATCH_C ("base::operator char*()", "base::operator char * ()");
CHECK_MATCH_C ("base::operator char**()", "base::operator char * * ()");
CHECK_MATCH ("base::operator char**()", "base::operator char * *");
CHECK_MATCH_C ("base::operator*()", "base::operator*()");
CHECK_NOT_MATCH_C ("base::operator char*()", "base::operatorc");
CHECK_NOT_MATCH ("base::operator char*()", "base::operator char");
CHECK_NOT_MATCH ("base::operator char*()", "base::operat");
/* Check handling of whitespace around C++ scope operators. */
CHECK_NOT_MATCH_C ("foo::bar", "foo: :bar");
CHECK_MATCH_C ("foo::bar", "foo :: bar");
CHECK_MATCH_C ("foo :: bar", "foo::bar");
CHECK_MATCH_C ("abc::def::ghi()", "abc::def::ghi()");
CHECK_MATCH_C ("abc::def::ghi ( )", "abc::def::ghi()");
CHECK_MATCH_C ("abc::def::ghi()", "abc::def::ghi ( )");
CHECK_MATCH_C ("function()", "function()");
CHECK_MATCH_C ("bar::function()", "bar::function()");
Make "break foo" find "A::foo", A::B::foo", etc. [C++ and wild matching] This patch teaches GDB about setting breakpoints in all scopes (namespaces and classes) by default. Here's a contrived example: (gdb) b func<tab> (anonymous namespace)::A::function() Bn::(anonymous namespace)::B::function() function(int, int) (anonymous namespace)::B::function() Bn::(anonymous namespace)::function() gdb::(anonymous namespace)::A::function() (anonymous namespace)::B::function() const Bn::(anonymous namespace)::function(int, int) gdb::(anonymous namespace)::function() (anonymous namespace)::function() Bn::B::func() gdb::(anonymous namespace)::function(int, int) (anonymous namespace)::function(int, int) Bn::B::function() gdb::A::func() A::func() Bn::func() gdb::A::function() A::function() Bn::function() gdb::func() B::func() Bn::function(int, int) gdb::function() B::function() Bn::function(long) gdb::function(int, int) B::function() const func() gdb::function(long) B::function_const() const function() (gdb) b function Breakpoint 1 at 0x4005ce: function. (26 locations) (gdb) b B::function<tab> (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() (gdb) b B::function Breakpoint 1 at 0x40072c: B::function. (6 locations) To get back the original behavior of interpreting the function name as a fully-qualified name, you can use the new "-qualified" (or "-q") option/flag (added by this commit). For example: (gdb) b B::function (anonymous namespace)::B::function() B::function() const Bn::B::function() (anonymous namespace)::B::function() const B::function_const() const B::function() Bn::(anonymous namespace)::B::function() vs: (gdb) b -qualified B::function B::function() B::function() const B::function_const() const I've chosen "-qualified" / "-q" because "-f" (for "full" or "fully-qualified") is already taken for "-function". Note: the "-qualified" option works with both linespecs and explicit locations. I.e., these are equivalent: (gdb) b -q func (gdb) b -q -f func and so are these: (gdb) b -q filename.cc:func (gdb) b -q -s filename.cc -f func (gdb) b -s filename.cc -q -f func (gdb) b -s filename.cc -f func -q To better understand why I consider wild matching the better default, consider what happens when we get to the point when _all_ of GDB is wrapped under "namespace gdb {}". I have a patch series that does that, and when I started debugging that GDB, I immediately became frustrated. You'd have to write "b gdb::internal_error", "b gdb::foo", "b gdb::bar", etc. etc., which gets annoying pretty quickly. OTOH, consider how this makes it very easy to set breakpoints in classes wrapped in anonymous namespaces. You just don't think of them, GDB finds the symbols for you automatically. (At the Cauldron a couple months ago, several people told me that they run into a similar issue when debugging other C++ projects. One example was when debugging LLVM, which puts all its code under the "llvm" namespace.) Implementation-wise, what the patch does is: - makes C++ symbol name hashing only consider the last component of a symbol name. (so that we can look up symbol names by last-component name only). - adds a C++ symbol name matcher for symbol_name_match_type::WILD, which ignores missing leading specifiers / components. - adjusts a few preexisting testsuite tests to use "-qualified" when they mean it. - adds new testsuite tests. - adds unit tests. Grows the gdb.linespec/ tests like this: -# of expected passes 7823 +# of expected passes 8977 gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * NEWS: Mention that breakpoints on C++ functions are now set on on all namespaces/classes by default, and mention "break -qualified". * ax-gdb.c (agent_command_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * breakpoint.c (parse_breakpoint_sals): Adjust to get_linespec_location's return type change. (strace_marker_create_sals_from_location): Adjust to pass a symbol_name_match_type to new_linespec_location. (strace_marker_decode_location): Adjust to get_linespec_location's return type change. (strace_command): Adjust to pass a symbol_name_match_type to new_linespec_location. (LOCATION_HELP_STRING): Add paragraph about wildmatching, and mention "-qualified". * c-lang.c (cplus_language_defn): Install cp_search_name_hash. * completer.c (explicit_location_match_type::MATCH_QUALIFIED): New enumerator. (complete_address_and_linespec_locations): New parameter 'match_type'. Pass it down. (explicit_options): Add "-qualified". (collect_explicit_location_matches): Pass the requested match type to the linespec completers. Handle MATCH_QUALIFIED. (location_completer): Handle "-qualified" combined with linespecs. * cp-support.c (cp_search_name_hash): New. (cp_symbol_name_matches_1): Implement wild matching for C++. (cp_fq_symbol_name_matches): Reimplement. (cp_get_symbol_name_matcher): Return different matchers depending on the lookup name's match type. (selftests::test_cp_symbol_name_matches): Add wild matching tests. * cp-support.h (cp_search_name_hash): New declaration. * dwarf2read.c (selftests::dw2_expand_symtabs_matching::test_symbols): Add symbols. (test_dw2_expand_symtabs_matching_symbol): Add wild matching tests. * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Adjust to pass a symbol_name_match_type to new_linespec_location. * linespec.c (linespec_parse_basic): Lookup function symbols using the parser's symbol name match type. (convert_explicit_location_to_linespec): New symbol_name_match_type parameter. Pass it down to find_linespec_symbols. (convert_explicit_location_to_sals): Pass the location's name match type to convert_explicit_location_to_linespec. (parse_linespec): New match_type parameter. Save it in the parser. (linespec_parser_new): Default to symbol_name_match_type::WILD. (linespec_complete_function): New symbol_name_match_type parameter. Use it. (complete_linespec_component): Pass down the parser's recorded name match type. (linespec_complete_label): New symbol_name_match_type parameter. Use it. (linespec_complete): New symbol_name_match_type parameter. Save it in the parser and pass it down. Adjust to get_linespec_location's prototype change. (find_function_symbols, find_linespec_symbols): New symbol_name_match_type parameter. Pass it down instead of assuming symbol_name_match_type::WILD. * linespec.h (linespec_complete, linespec_complete_function) (linespec_complete_label): New symbol_name_match_type parameter. * location.c (event_location::linespec_location): Now a struct linespec_location. (EL_LINESPEC): Adjust. (initialize_explicit_location): Default to symbol_name_match_type::WILD. (new_linespec_location): New symbol_name_match_type parameter. Record it in the location. (get_linespec_location): Now returns a struct linespec_location. (new_explicit_location): Also copy func_name_match_type. (explicit_to_string_internal) (string_to_explicit_location): Handle "-qualified". (copy_event_location): Adjust to LINESPEC_LOCATION type change. Copy symbol_name_match_type fields. (event_location_deleter::operator()): Adjust to LINESPEC_LOCATION type change. (event_location_to_string): Adjust to LINESPEC_LOCATION type change. Handle "-qualfied". (string_to_explicit_location): Handle "-qualified". (string_to_event_location_basic): New symbol_name_match_type parameter. Pass it down. (string_to_event_location): Handle "-qualified". * location.h (struct linespec_location): New. (explicit_location::func_name_match_type): New field. (new_linespec_location): Now returns a const linespec_location *. (string_to_event_location_basic): New symbol_name_match_type parameter. (explicit_completion_info::saw_explicit_location_option): New field. * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Adjust to pass a symbol_name_match_type to new_linespec_location. * python/py-breakpoint.c (bppy_init): Likewise. * python/python.c (gdbpy_decode_line): Likewise. gdb/testsuite/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.base/langs.exp: Use -qualified. * gdb.cp/meth-typedefs.exp: Use -qualified, and add tests without it. * gdb.cp/namespace.exp: Use -qualified. * gdb.linespec/cpcompletion.exp (overload-2, fqn, fqn-2) (overload-3, template-overload, template-ret-type, const-overload) (const-overload-quoted, anon-ns, ambiguous-prefix): New procedures. (test_driver): Call them. * gdb.cp/save-bp-qualified.cc: New. * gdb.cp/save-bp-qualified.exp: New. * gdb.linespec/explicit.exp: Test -qualified. * lib/completion-support.exp (completion::explicit_opts_list): Add "-qualified". * lib/gdb.exp (gdb_breakpoint): Handle "qualified". gdb/doc/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> * gdb.texinfo (Linespec Locations): Document how "function" is interpreted in C++ and Ada. Document "-qualified". (Explicit Locations): Document how "-function" is interpreted in C++ and Ada. Document "-qualified".
2017-11-29 20:33:23 +01:00
/* Wild matching tests follow. */
/* Tests matching symbols in some scope. */
CHECK_MATCH_C ("foo::function()", "function");
CHECK_MATCH_C ("foo::function(int)", "function");
CHECK_MATCH_C ("foo::bar::function()", "function");
CHECK_MATCH_C ("bar::function()", "bar::function");
CHECK_MATCH_C ("foo::bar::function()", "bar::function");
CHECK_MATCH_C ("foo::bar::function(int)", "bar::function");
/* Same, with parameters in the lookup name. */
CHECK_MATCH_C ("foo::function()", "function()");
CHECK_MATCH_C ("foo::bar::function()", "function()");
CHECK_MATCH_C ("foo::function(int)", "function(int)");
CHECK_MATCH_C ("foo::function()", "foo::function()");
CHECK_MATCH_C ("foo::bar::function()", "bar::function()");
CHECK_MATCH_C ("foo::bar::function(int)", "bar::function(int)");
CHECK_MATCH_C ("bar::function()", "bar::function()");
CHECK_NOT_MATCH_C ("foo::bar::function(int)", "bar::function()");
CHECK_MATCH_C ("(anonymous namespace)::bar::function(int)",
"bar::function(int)");
CHECK_MATCH_C ("foo::(anonymous namespace)::bar::function(int)",
"function(int)");
/* Lookup scope wider than symbol scope, should not match. */
CHECK_NOT_MATCH_C ("function()", "bar::function");
CHECK_NOT_MATCH_C ("function()", "bar::function()");
/* Explicit global scope doesn't match. */
CHECK_NOT_MATCH_C ("foo::function()", "::function");
CHECK_NOT_MATCH_C ("foo::function()", "::function()");
CHECK_NOT_MATCH_C ("foo::function(int)", "::function()");
CHECK_NOT_MATCH_C ("foo::function(int)", "::function(int)");
Breakpoints in symbols with ABI tags (PR c++/19436) Trying to set a breakpoint in a function with an ABI tag does not work currently. E.g., debugging gdb itself, we see this with the "string_printf" function: (top-gdb) b string_print [TAB] (top-gdb) b string_printf[abi:cxx11](char const*, ...) [RET] No source file named string_printf[abi. Make breakpoint pending on future shared library load? (y or [n]) Quoting doesn't help: (top-gdb) b 'string_printf[abi:cxx11]'(char const*, ...) malformed linespec error: unexpected string, "(char const*, ...)" (top-gdb) b 'string_printf[abi:cxx11](char const*, ...)' No source file named string_printf[abi. Make breakpoint pending on future shared library load? (y or [n]) n This patch fixes this, and takes it a bit further. The actual symbol name as demangled by libiberty's demangler is really string_printf[abi:cxx11](char const*, ...) however, this patch makes it possible to set the breakpoint with string_printf(char const*, ...) too. I.e., ignoring the ABI tag. And to match, it teaches the completer to complete the symbol name without the ABI tag, i.e., "string_pri<TAB>" -> "string_printf(char const*, ...)" If however, you really want to break on a symbol with the tag, then you simply start writing the tag, and GDB will preserve it, like: "string_printf[a<TAB>" -> "string_printf[abi:cxx11](char const*, ...)" Grows the gdb.linespec/ tests like this: -# of expected passes 8977 +# of expected passes 9176 gdb/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> PR c++/19436 * NEWS: Mention setting breakpoints on functions with C++ ABI tags. * completer.h (completion_match_for_lcd) <match, mark_ignored_range>: New methods. <finish>: Consider ignored ranges. <clear>: Clear ignored ranges. <m_ignored_ranges, m_finished_storage>: New fields. * cp-support.c (cp_search_name_hash): Ignore ABI tags. (cp_symbol_name_matches_1, cp_fq_symbol_name_matches): Pass the completion_match_for_lcd pointer to strncmp_iw_with_mode. (test_cp_symbol_name_cmp): Add [abi:...] tags unit tests. * language.c (default_symbol_name_matcher): Pass the completion_match_for_lcd pointer to strncmp_iw_with_mode. * linespec.c (linespec_lexer_lex_string): Don't tokenize ABI tags. * utils.c (skip_abi_tag): New function. (strncmp_iw_with_mode): Add completion_match_for_lcd parameter. Handle ABI tags. * utils.h (strncmp_iw_with_mode): Add completion_match_for_lcd parameter. gdb/testsuite/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> PR c++/19436 * gdb.linespec/cpls-abi-tag.cc: New file. * gdb.linespec/cpls-abi-tag.exp: New file. gdb/doc/ChangeLog: 2017-11-29 Pedro Alves <palves@redhat.com> PR c++/19436 * gdb.texinfo (Debugging C Plus Plus): Document setting breakpoints in functions with ABI tags.
2017-11-29 20:33:24 +01:00
/* Test ABI tag matching/ignoring. */
/* If the symbol name has an ABI tag, but the lookup name doesn't,
then the ABI tag in the symbol name is ignored. */
CHECK_MATCH_C ("function[abi:foo]()", "function");
CHECK_MATCH_C ("function[abi:foo](int)", "function");
CHECK_MATCH_C ("function[abi:foo]()", "function ()");
CHECK_NOT_MATCH_C ("function[abi:foo]()", "function (int)");
CHECK_MATCH_C ("function[abi:foo]()", "function[abi:foo]");
CHECK_MATCH_C ("function[abi:foo](int)", "function[abi:foo]");
CHECK_MATCH_C ("function[abi:foo]()", "function[abi:foo] ()");
CHECK_MATCH_C ("function[abi:foo][abi:bar]()", "function");
CHECK_MATCH_C ("function[abi:foo][abi:bar](int)", "function");
CHECK_MATCH_C ("function[abi:foo][abi:bar]()", "function[abi:foo]");
CHECK_MATCH_C ("function[abi:foo][abi:bar](int)", "function[abi:foo]");
CHECK_MATCH_C ("function[abi:foo][abi:bar]()", "function[abi:foo] ()");
CHECK_NOT_MATCH_C ("function[abi:foo][abi:bar]()", "function[abi:foo] (int)");
CHECK_MATCH_C ("function [abi:foo][abi:bar] ( )", "function [abi:foo]");
/* If the symbol name does not have an ABI tag, while the lookup
name has one, then there's no match. */
CHECK_NOT_MATCH_C ("function()", "function[abi:foo]()");
CHECK_NOT_MATCH_C ("function()", "function[abi:foo]");
Make strcmp_iw NOT ignore whitespace in the middle of tokens currently "b func tion" manages to set a breakpoint at "function" ! All these years I had never noticed this, but now that the linespec completer actually works, this easily happens by accident, with: "b func t<tab>" expecting to get "thread", but getting instead: "b func tion" ... Also, this: "b rettypefunc<int>" manages to set a breakpoint on "rettype func<int>()". These things happen due to strcmp_iw "magic". Fix it by teaching strcmp_iw about when can it skip whitespace. This required handling user-defined operators, and scope operators, complicating the code a bit, unfortunately. I added unit tests for all the corner cases I stumbled on, as I was developing this, and then in the end wrote a testsuite testcase covering many of the same things and more (to be added later). gdb/ChangeLog: 2017-11-24 Pedro Alves <palves@redhat.com> * cp-support.c (cp_symbol_name_matches_1): New, factored out from cp_fq_symbol_name_matches. Pass language_cplus to strncmp_with_mode. (cp_fq_symbol_name_matches): Call cp_symbol_name_matches_1. (selftests::test_cp_symbol_name_cmp): New. (_initialize_cp_support): Register "cp_symbol_name_matches" selftests. * language.c (default_symbol_name_matcher): Pass language_minimal to strncmp_iw_with_mode. * utils.c: Include "cp-support.h" and <algorithm>. (valid_identifier_name_char, cp_skip_operator_token, skip_ws) (cp_is_operator): New functions. (strncmp_iw_with_mode): Use them. Add language parameter. Don't skip whitespace in the symbol name when the lookup name doesn't have spaces, and vice versa. (strncmp_iw, strcmp_iw): Pass language to strncmp_iw_with_mode. * utils.h (strncmp_iw_with_mode): Add language parameter.
2017-11-25 00:30:04 +01:00
}
lookup_name_info::make_ignore_params A few places in the completion code look for a "(" to find a function's parameter list, in order to strip it, because psymtabs (and gdb index) don't include parameter info in the symbol names. See compare_symbol_name and default_collect_symbol_completion_matches_break_on. This is too naive. Consider: ns_overload2_test::([TAB] We'd want to complete that to: ns_overload2_test::(anonymous namespace)::struct_overload2_test Or: b (anonymous namespace)::[TAB] That currently completes to: b (anonymous namespace) Which is obviously broken. This patch makes that work. Also, the current compare_symbol_name hack means that while this works: "b function([TAB]" -> "b function()" This does not: "b function ([TAB]" This patch fixes that. Whitespace "ignoring" now Just Works, i.e., assuming a symbol named "function(int, long)", this: b function ( int , lon[TAB] completes to: b function ( int , long) To address all of this, this patch builds on top of the rest of the series, and pushes the responsibility of stripping parameters from a lookup name to the new lookup_name_info object, where we can apply per-language rules. Also note that we now only make a version of the lookup name with parameters stripped out where it's actually required to do that, in the psymtab and GDB index code. For C++, the right way to strip parameters is with "cp_remove_params", which uses a real parser (cp-name-parser.y) to split the name into a component tree and then discards parameters. The trouble for completion is that in that case we have an incomplete name, like "foo::func(int" and thus cp_remove_params throws an error. This patch sorts that by adding a cp_remove_params_if_any variant of cp_remove_params that tries removing characters from the end of the string until cp_remove_params works. So cp_remove_params_if_any behaves like this: With a complete name: "foo::func(int)" => foo::func(int) # cp_remove_params_1 succeeds the first time. With an incomplete name: "foo::func(int" => NULL # cp_remove_params fails the first time. "foo::func(in" => NULL # and again... "foo::func(i" => NULL # and again... "foo::func(" => NULL # and again... "foo::func" => "foo::func" # success! Note that even if this approach removes significant rightmost characters, it's still OK, because this parameter stripping is only necessary for psymtabs and gdb index, where we're determining whether to expand a symbol table. Say cp_remove_params_if_any returned "foo::" above for "foo::func(int". That'd cause us to expand more symtabs than ideal (because we'd expand all symtabs with symbols that start with "foo::", not just "foo::func"), but then when we actually look for completion matches, we'd still use the original lookup name, with parameter information ["foo::func(int"], and thus we'll return no false positive to the user. Whether the stripping works as intended and doesn't strip too much is thus covered by a unit test instead of a testsuite test. The "if_any" part of the name refers to the fact that while cp_remove_params returns NULL if the input name has no parameters in the first place, like: "foo::func" => NULL # cp_remove_params cp_remove_params_if_any still returns the function name: "foo::func" => "foo::func" # cp_remove_params_if_any gdb/ChangeLog: 2017-11-08 Pedro Alves <palves@redhat.com> * Makefile.in (SUBDIR_UNITTESTS_SRCS): Add unittests/lookup_name_info-selftests.c. (SUBDIR_UNITTESTS_OBS): Add lookup_name_info-selftests.o. * cp-support.c: Include "selftest.h". (cp_remove_params_1): Rename from cp_remove_params. Add 'require_param' parameter, and handle it. (cp_remove_params): Reimplement. (cp_remove_params_if_any): New. (selftests::quote): New. (selftests::check_remove_params): New. (selftests::test_cp_remove_params): New. (_initialize_cp_support): Install selftests::test_cp_remove_params. * cp-support.h (cp_remove_params_if_any): Declare. * dwarf2read.c :Include "selftest.h". (dw2_expand_symtabs_matching_symbol): Use lookup_name_info::make_ignore_params. (selftests::dw2_expand_symtabs_matching::mock_mapped_index) (selftests::dw2_expand_symtabs_matching::string_or_null) (selftests::dw2_expand_symtabs_matching::check_match) (selftests::dw2_expand_symtabs_matching::test_symbols) (selftests::dw2_expand_symtabs_matching::run_test): New. (_initialize_dwarf2_read): Register selftests::dw2_expand_symtabs_matching::run_test. * psymtab.c (psym_expand_symtabs_matching): Use lookup_name_info::make_ignore_params. * symtab.c (demangle_for_lookup_info::demangle_for_lookup_info): If the lookup name wants to ignore parameters, strip them. (compare_symbol_name): Remove sym_text/sym_text_len parameters and code handling '('. (completion_list_add_name): Don't pass down sym_text/sym_text_len. (default_collect_symbol_completion_matches_break_on): Don't try to strip parameters. * symtab.h (lookup_name_info::lookup_name_info): Add 'ignore_parameters' parameter. (lookup_name_info::ignore_parameters) (lookup_name_info::make_ignore_params): New methods. (lookup_name_info::m_ignore_parameters): New field. * unittests/lookup_name_info-selftests.c: New file.
2017-11-08 15:49:10 +01:00
/* If non-NULL, return STR wrapped in quotes. Otherwise, return a
"<null>" string (with no quotes). */
static std::string
quote (const char *str)
{
if (str != NULL)
return std::string (1, '"') + str + '"';
lookup_name_info::make_ignore_params A few places in the completion code look for a "(" to find a function's parameter list, in order to strip it, because psymtabs (and gdb index) don't include parameter info in the symbol names. See compare_symbol_name and default_collect_symbol_completion_matches_break_on. This is too naive. Consider: ns_overload2_test::([TAB] We'd want to complete that to: ns_overload2_test::(anonymous namespace)::struct_overload2_test Or: b (anonymous namespace)::[TAB] That currently completes to: b (anonymous namespace) Which is obviously broken. This patch makes that work. Also, the current compare_symbol_name hack means that while this works: "b function([TAB]" -> "b function()" This does not: "b function ([TAB]" This patch fixes that. Whitespace "ignoring" now Just Works, i.e., assuming a symbol named "function(int, long)", this: b function ( int , lon[TAB] completes to: b function ( int , long) To address all of this, this patch builds on top of the rest of the series, and pushes the responsibility of stripping parameters from a lookup name to the new lookup_name_info object, where we can apply per-language rules. Also note that we now only make a version of the lookup name with parameters stripped out where it's actually required to do that, in the psymtab and GDB index code. For C++, the right way to strip parameters is with "cp_remove_params", which uses a real parser (cp-name-parser.y) to split the name into a component tree and then discards parameters. The trouble for completion is that in that case we have an incomplete name, like "foo::func(int" and thus cp_remove_params throws an error. This patch sorts that by adding a cp_remove_params_if_any variant of cp_remove_params that tries removing characters from the end of the string until cp_remove_params works. So cp_remove_params_if_any behaves like this: With a complete name: "foo::func(int)" => foo::func(int) # cp_remove_params_1 succeeds the first time. With an incomplete name: "foo::func(int" => NULL # cp_remove_params fails the first time. "foo::func(in" => NULL # and again... "foo::func(i" => NULL # and again... "foo::func(" => NULL # and again... "foo::func" => "foo::func" # success! Note that even if this approach removes significant rightmost characters, it's still OK, because this parameter stripping is only necessary for psymtabs and gdb index, where we're determining whether to expand a symbol table. Say cp_remove_params_if_any returned "foo::" above for "foo::func(int". That'd cause us to expand more symtabs than ideal (because we'd expand all symtabs with symbols that start with "foo::", not just "foo::func"), but then when we actually look for completion matches, we'd still use the original lookup name, with parameter information ["foo::func(int"], and thus we'll return no false positive to the user. Whether the stripping works as intended and doesn't strip too much is thus covered by a unit test instead of a testsuite test. The "if_any" part of the name refers to the fact that while cp_remove_params returns NULL if the input name has no parameters in the first place, like: "foo::func" => NULL # cp_remove_params cp_remove_params_if_any still returns the function name: "foo::func" => "foo::func" # cp_remove_params_if_any gdb/ChangeLog: 2017-11-08 Pedro Alves <palves@redhat.com> * Makefile.in (SUBDIR_UNITTESTS_SRCS): Add unittests/lookup_name_info-selftests.c. (SUBDIR_UNITTESTS_OBS): Add lookup_name_info-selftests.o. * cp-support.c: Include "selftest.h". (cp_remove_params_1): Rename from cp_remove_params. Add 'require_param' parameter, and handle it. (cp_remove_params): Reimplement. (cp_remove_params_if_any): New. (selftests::quote): New. (selftests::check_remove_params): New. (selftests::test_cp_remove_params): New. (_initialize_cp_support): Install selftests::test_cp_remove_params. * cp-support.h (cp_remove_params_if_any): Declare. * dwarf2read.c :Include "selftest.h". (dw2_expand_symtabs_matching_symbol): Use lookup_name_info::make_ignore_params. (selftests::dw2_expand_symtabs_matching::mock_mapped_index) (selftests::dw2_expand_symtabs_matching::string_or_null) (selftests::dw2_expand_symtabs_matching::check_match) (selftests::dw2_expand_symtabs_matching::test_symbols) (selftests::dw2_expand_symtabs_matching::run_test): New. (_initialize_dwarf2_read): Register selftests::dw2_expand_symtabs_matching::run_test. * psymtab.c (psym_expand_symtabs_matching): Use lookup_name_info::make_ignore_params. * symtab.c (demangle_for_lookup_info::demangle_for_lookup_info): If the lookup name wants to ignore parameters, strip them. (compare_symbol_name): Remove sym_text/sym_text_len parameters and code handling '('. (completion_list_add_name): Don't pass down sym_text/sym_text_len. (default_collect_symbol_completion_matches_break_on): Don't try to strip parameters. * symtab.h (lookup_name_info::lookup_name_info): Add 'ignore_parameters' parameter. (lookup_name_info::ignore_parameters) (lookup_name_info::make_ignore_params): New methods. (lookup_name_info::m_ignore_parameters): New field. * unittests/lookup_name_info-selftests.c: New file.
2017-11-08 15:49:10 +01:00
else
return "<null>";
}
/* Check that removing parameter info out of NAME produces EXPECTED.
COMPLETION_MODE indicates whether we're testing normal and
completion mode. FILE and LINE are used to provide better test
location information in case ithe check fails. */
static void
check_remove_params (const char *file, int line,
const char *name, const char *expected,
bool completion_mode)
{
gdb::unique_xmalloc_ptr<char> result
= cp_remove_params_if_any (name, completion_mode);
if ((expected == NULL) != (result == NULL)
|| (expected != NULL
&& strcmp (result.get (), expected) != 0))
{
error (_("%s:%d: make-paramless self-test failed: (completion=%d) "
"\"%s\" -> %s, expected %s"),
file, line, completion_mode, name,
quote (result.get ()).c_str (), quote (expected).c_str ());
}
}
/* Entry point for cp_remove_params unit tests. */
static void
test_cp_remove_params ()
{
/* Check that removing parameter info out of NAME produces EXPECTED.
Checks both normal and completion modes. */
#define CHECK(NAME, EXPECTED) \
do \
{ \
check_remove_params (__FILE__, __LINE__, NAME, EXPECTED, false); \
check_remove_params (__FILE__, __LINE__, NAME, EXPECTED, true); \
} \
while (0)
/* Similar, but used when NAME is incomplete -- i.e., is has
unbalanced parentheses. In this case, looking for the exact name
should fail / return empty. */
#define CHECK_INCOMPL(NAME, EXPECTED) \
do \
{ \
check_remove_params (__FILE__, __LINE__, NAME, NULL, false); \
check_remove_params (__FILE__, __LINE__, NAME, EXPECTED, true); \
} \
while (0)
CHECK ("function()", "function");
CHECK_INCOMPL ("function(", "function");
CHECK ("function() const", "function");
CHECK ("(anonymous namespace)::A::B::C",
"(anonymous namespace)::A::B::C");
CHECK ("A::(anonymous namespace)",
"A::(anonymous namespace)");
CHECK_INCOMPL ("A::(anonymou", "A");
CHECK ("A::foo<int>()",
"A::foo<int>");
CHECK_INCOMPL ("A::foo<int>(",
"A::foo<int>");
CHECK ("A::foo<(anonymous namespace)::B>::func(int)",
"A::foo<(anonymous namespace)::B>::func");
CHECK_INCOMPL ("A::foo<(anonymous namespace)::B>::func(in",
"A::foo<(anonymous namespace)::B>::func");
CHECK_INCOMPL ("A::foo<(anonymous namespace)::B>::",
"A::foo<(anonymous namespace)::B>");
CHECK_INCOMPL ("A::foo<(anonymous namespace)::B>:",
"A::foo<(anonymous namespace)::B>");
CHECK ("A::foo<(anonymous namespace)::B>",
"A::foo<(anonymous namespace)::B>");
CHECK_INCOMPL ("A::foo<(anonymous namespace)::B",
"A::foo");
/* Shouldn't this parse? Looks like a bug in
cp_demangled_name_to_comp. See PR c++/22411. */
#if 0
CHECK ("A::foo<void(int)>::func(int)",
"A::foo<void(int)>::func");
#else
CHECK_INCOMPL ("A::foo<void(int)>::func(int)",
"A::foo");
#endif
CHECK_INCOMPL ("A::foo<void(int",
"A::foo");
#undef CHECK
#undef CHECK_INCOMPL
}
} // namespace selftests
#endif /* GDB_SELF_CHECK */
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
/* This is a front end for cp_find_first_component, for unit testing.
Be careful when using it: see the NOTE above
cp_find_first_component. */
static void
first_component_command (const char *arg, int from_tty)
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
{
int len;
char *prefix;
if (!arg)
return;
len = cp_find_first_component (arg);
Add casts to memory allocation related calls Most allocation functions (if not all) return a void* pointing to the allocated memory. In C++, we need to add an explicit cast when assigning the result to a pointer to another type (which is the case more often than not). The content of this patch is taken from Pedro's branch, from commit "(mostly) auto-generated patch to insert casts needed for C++". I validated that the changes make sense and manually reflowed the code to make it respect the coding style. I also found multiple places where I could use XNEW/XNEWVEC/XRESIZEVEC/etc. Thanks a lot to whoever did that automated script to insert casts, doing it completely by hand would have taken a ridiculous amount of time. Only files built on x86 with --enable-targets=all are modified. This means that all other -nat.c files are untouched and will have to be dealt with later by using appropiate compilers. Or maybe we can try to build them with a regular g++ just to know where to add casts, I don't know. I built-tested this with --enable-targets=all and reg-tested. Here's the changelog entry, which was not too bad to make despite the size, thanks to David Malcom's script. I fixed some bits by hand, but there might be some wrong parts left (hopefully not). gdb/ChangeLog: * aarch64-linux-tdep.c (aarch64_stap_parse_special_token): Add cast to allocation result assignment. * ada-exp.y (write_object_renaming): Likewise. (write_ambiguous_var): Likewise. (ada_nget_field_index): Likewise. (write_var_or_type): Likewise. * ada-lang.c (ada_decode_symbol): Likewise. (ada_value_assign): Likewise. (value_pointer): Likewise. (cache_symbol): Likewise. (add_nonlocal_symbols): Likewise. (ada_name_for_lookup): Likewise. (symbol_completion_add): Likewise. (ada_to_fixed_type_1): Likewise. (ada_get_next_arg): Likewise. (defns_collected): Likewise. * ada-lex.l (processId): Likewise. (processString): Likewise. * ada-tasks.c (read_known_tasks_array): Likewise. (read_known_tasks_list): Likewise. * ada-typeprint.c (decoded_type_name): Likewise. * addrmap.c (addrmap_mutable_create_fixed): Likewise. * amd64-tdep.c (amd64_push_arguments): Likewise. (amd64_displaced_step_copy_insn): Likewise. (amd64_classify_insn_at): Likewise. (amd64_relocate_instruction): Likewise. * amd64obsd-tdep.c (amd64obsd_sigtramp_p): Likewise. * arch-utils.c (simple_displaced_step_copy_insn): Likewise. (initialize_current_architecture): Likewise. * arm-linux-tdep.c (arm_stap_parse_special_token): Likewise. * arm-symbian-tdep.c (arm_symbian_osabi_sniffer): Likewise. * arm-tdep.c (arm_exidx_new_objfile): Likewise. (arm_push_dummy_call): Likewise. (extend_buffer_earlier): Likewise. (arm_adjust_breakpoint_address): Likewise. (arm_skip_stub): Likewise. * auto-load.c (filename_is_in_pattern): Likewise. (maybe_add_script_file): Likewise. (maybe_add_script_text): Likewise. (auto_load_objfile_script_1): Likewise. * auxv.c (ld_so_xfer_auxv): Likewise. * ax-general.c (new_agent_expr): Likewise. (grow_expr): Likewise. (ax_reg_mask): Likewise. * bcache.c (bcache_full): Likewise. * breakpoint.c (program_breakpoint_here_p): Likewise. * btrace.c (parse_xml_raw): Likewise. * build-id.c (build_id_to_debug_bfd): Likewise. * buildsym.c (end_symtab_with_blockvector): Likewise. * c-exp.y (string_exp): Likewise. (qualified_name): Likewise. (write_destructor_name): Likewise. (operator_stoken): Likewise. (parse_number): Likewise. (scan_macro_expansion): Likewise. (yylex): Likewise. (c_print_token): Likewise. * c-lang.c (c_get_string): Likewise. (emit_numeric_character): Likewise. * charset.c (wchar_iterate): Likewise. * cli/cli-cmds.c (complete_command): Likewise. (make_command): Likewise. * cli/cli-dump.c (restore_section_callback): Likewise. (restore_binary_file): Likewise. * cli/cli-interp.c (cli_interpreter_exec): Likewise. * cli/cli-script.c (execute_control_command): Likewise. * cli/cli-setshow.c (do_set_command): Likewise. * coff-pe-read.c (add_pe_forwarded_sym): Likewise. (read_pe_exported_syms): Likewise. * coffread.c (coff_read_struct_type): Likewise. (coff_read_enum_type): Likewise. * common/btrace-common.c (btrace_data_append): Likewise. * common/buffer.c (buffer_grow): Likewise. * common/filestuff.c (gdb_fopen_cloexec): Likewise. * common/format.c (parse_format_string): Likewise. * common/gdb_vecs.c (delim_string_to_char_ptr_vec_append): Likewise. * common/xml-utils.c (xml_escape_text): Likewise. * compile/compile-object-load.c (copy_sections): Likewise. (compile_object_load): Likewise. * compile/compile-object-run.c (compile_object_run): Likewise. * completer.c (filename_completer): Likewise. * corefile.c (read_memory_typed_address): Likewise. (write_memory_unsigned_integer): Likewise. (write_memory_signed_integer): Likewise. (complete_set_gnutarget): Likewise. * corelow.c (get_core_register_section): Likewise. * cp-name-parser.y (d_grab): Likewise. (allocate_info): Likewise. (cp_new_demangle_parse_info): Likewise. * cp-namespace.c (cp_scan_for_anonymous_namespaces): Likewise. (cp_lookup_symbol_in_namespace): Likewise. (lookup_namespace_scope): Likewise. (find_symbol_in_baseclass): Likewise. (cp_lookup_nested_symbol): Likewise. (cp_lookup_transparent_type_loop): Likewise. * cp-support.c (copy_string_to_obstack): Likewise. (make_symbol_overload_list): Likewise. (make_symbol_overload_list_namespace): Likewise. (make_symbol_overload_list_adl_namespace): Likewise. (first_component_command): Likewise. * cp-valprint.c (cp_print_value): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * d-exp.y (StringExp): Likewise. * d-namespace.c (d_lookup_symbol_in_module): Likewise. (lookup_module_scope): Likewise. (find_symbol_in_baseclass): Likewise. (d_lookup_nested_symbol): Likewise. * dbxread.c (find_stab_function_addr): Likewise. (read_dbx_symtab): Likewise. (dbx_end_psymtab): Likewise. (cp_set_block_scope): Likewise. * dcache.c (dcache_alloc): Likewise. * demangle.c (_initialize_demangler): Likewise. * dicos-tdep.c (dicos_load_module_p): Likewise. * dictionary.c (dict_create_hashed_expandable): Likewise. (dict_create_linear_expandable): Likewise. (expand_hashtable): Likewise. (add_symbol_linear_expandable): Likewise. * dwarf2-frame.c (add_cie): Likewise. (add_fde): Likewise. (dwarf2_build_frame_info): Likewise. * dwarf2expr.c (dwarf_expr_grow_stack): Likewise. (dwarf_expr_fetch_address): Likewise. (add_piece): Likewise. (execute_stack_op): Likewise. * dwarf2loc.c (chain_candidate): Likewise. (dwarf_entry_parameter_to_value): Likewise. (read_pieced_value): Likewise. (write_pieced_value): Likewise. * dwarf2read.c (dwarf2_read_section): Likewise. (add_type_unit): Likewise. (read_comp_units_from_section): Likewise. (fixup_go_packaging): Likewise. (dwarf2_compute_name): Likewise. (dwarf2_physname): Likewise. (create_dwo_unit_in_dwp_v1): Likewise. (create_dwo_unit_in_dwp_v2): Likewise. (read_func_scope): Likewise. (read_call_site_scope): Likewise. (dwarf2_attach_fields_to_type): Likewise. (process_structure_scope): Likewise. (mark_common_block_symbol_computed): Likewise. (read_common_block): Likewise. (abbrev_table_read_table): Likewise. (guess_partial_die_structure_name): Likewise. (fixup_partial_die): Likewise. (add_file_name): Likewise. (dwarf2_const_value_data): Likewise. (dwarf2_const_value_attr): Likewise. (build_error_marker_type): Likewise. (guess_full_die_structure_name): Likewise. (anonymous_struct_prefix): Likewise. (typename_concat): Likewise. (dwarf2_canonicalize_name): Likewise. (dwarf2_name): Likewise. (write_constant_as_bytes): Likewise. (dwarf2_fetch_constant_bytes): Likewise. (copy_string): Likewise. (parse_macro_definition): Likewise. * elfread.c (elf_symfile_segments): Likewise. (elf_rel_plt_read): Likewise. (elf_gnu_ifunc_resolve_by_cache): Likewise. (elf_gnu_ifunc_resolve_by_got): Likewise. (elf_read_minimal_symbols): Likewise. (elf_gnu_ifunc_record_cache): Likewise. * event-top.c (top_level_prompt): Likewise. (command_line_handler): Likewise. * exec.c (resize_section_table): Likewise. * expprint.c (print_subexp_standard): Likewise. * fbsd-tdep.c (fbsd_collect_regset_section_cb): Likewise. * findcmd.c (parse_find_args): Likewise. * findvar.c (address_from_register): Likewise. * frame.c (get_prev_frame_always): Likewise. * gdb_bfd.c (gdb_bfd_ref): Likewise. (get_section_descriptor): Likewise. * gdb_obstack.c (obconcat): Likewise. (obstack_strdup): Likewise. * gdbtypes.c (lookup_function_type_with_arguments): Likewise. (create_set_type): Likewise. (lookup_unsigned_typename): Likewise. (lookup_signed_typename): Likewise. (resolve_dynamic_union): Likewise. (resolve_dynamic_struct): Likewise. (add_dyn_prop): Likewise. (copy_dynamic_prop_list): Likewise. (arch_flags_type): Likewise. (append_composite_type_field_raw): Likewise. * gdbtypes.h (INIT_FUNC_SPECIFIC): Likewise. * gnu-v3-abi.c (gnuv3_rtti_type): Likewise. * go-exp.y (string_exp): Likewise. * go-lang.c (go_demangle): Likewise. * guile/guile.c (compute_scheme_string): Likewise. * guile/scm-cmd.c (gdbscm_parse_command_name): Likewise. (gdbscm_canonicalize_command_name): Likewise. * guile/scm-ports.c (ioscm_init_stdio_buffers): Likewise. (ioscm_init_memory_port): Likewise. (ioscm_reinit_memory_port): Likewise. * guile/scm-utils.c (gdbscm_gc_xstrdup): Likewise. (gdbscm_gc_dup_argv): Likewise. * h8300-tdep.c (h8300_push_dummy_call): Likewise. * hppa-tdep.c (internalize_unwinds): Likewise. (read_unwind_info): Likewise. * i386-cygwin-tdep.c (core_process_module_section): Likewise. (windows_core_xfer_shared_libraries): Likewise. * i386-tdep.c (i386_displaced_step_copy_insn): Likewise. (i386_stap_parse_special_token_triplet): Likewise. (i386_stap_parse_special_token_three_arg_disp): Likewise. * i386obsd-tdep.c (i386obsd_sigtramp_p): Likewise. * inf-child.c (inf_child_fileio_readlink): Likewise. * inf-ptrace.c (inf_ptrace_fetch_register): Likewise. (inf_ptrace_store_register): Likewise. * infrun.c (follow_exec): Likewise. (displaced_step_prepare_throw): Likewise. (save_stop_context): Likewise. (save_infcall_suspend_state): Likewise. * jit.c (jit_read_descriptor): Likewise. (jit_read_code_entry): Likewise. (jit_symtab_line_mapping_add_impl): Likewise. (finalize_symtab): Likewise. (jit_unwind_reg_get_impl): Likewise. * jv-exp.y (QualifiedName): Likewise. * jv-lang.c (get_java_utf8_name): Likewise. (type_from_class): Likewise. (java_demangle_type_signature): Likewise. (java_class_name_from_physname): Likewise. * jv-typeprint.c (java_type_print_base): Likewise. * jv-valprint.c (java_value_print): Likewise. * language.c (add_language): Likewise. * linespec.c (add_sal_to_sals_basic): Likewise. (add_sal_to_sals): Likewise. (decode_objc): Likewise. (find_linespec_symbols): Likewise. * linux-fork.c (fork_save_infrun_state): Likewise. * linux-nat.c (linux_nat_detach): Likewise. (linux_nat_fileio_readlink): Likewise. * linux-record.c (record_linux_sockaddr): Likewise. (record_linux_msghdr): Likewise. (Do): Likewise. * linux-tdep.c (linux_core_info_proc_mappings): Likewise. (linux_collect_regset_section_cb): Likewise. (linux_get_siginfo_data): Likewise. * linux-thread-db.c (try_thread_db_load_from_pdir_1): Likewise. (try_thread_db_load_from_dir): Likewise. (thread_db_load_search): Likewise. (info_auto_load_libthread_db): Likewise. * m32c-tdep.c (m32c_m16c_address_to_pointer): Likewise. (m32c_m16c_pointer_to_address): Likewise. * m68hc11-tdep.c (m68hc11_pseudo_register_write): Likewise. * m68k-tdep.c (m68k_get_longjmp_target): Likewise. * machoread.c (macho_check_dsym): Likewise. * macroexp.c (resize_buffer): Likewise. (gather_arguments): Likewise. (maybe_expand): Likewise. * macrotab.c (new_macro_key): Likewise. (new_source_file): Likewise. (new_macro_definition): Likewise. * mdebugread.c (parse_symbol): Likewise. (parse_type): Likewise. (parse_partial_symbols): Likewise. (psymtab_to_symtab_1): Likewise. * mem-break.c (default_memory_insert_breakpoint): Likewise. * mi/mi-cmd-break.c (mi_argv_to_format): Likewise. * mi/mi-main.c (mi_cmd_data_read_memory): Likewise. (mi_cmd_data_read_memory_bytes): Likewise. (mi_cmd_data_write_memory_bytes): Likewise. (mi_cmd_trace_frame_collected): Likewise. * mi/mi-parse.c (mi_parse_argv): Likewise. (mi_parse): Likewise. * minidebug.c (lzma_open): Likewise. (lzma_pread): Likewise. * mips-tdep.c (mips_read_fp_register_single): Likewise. (mips_print_fp_register): Likewise. * mipsnbsd-tdep.c (mipsnbsd_get_longjmp_target): Likewise. * mipsread.c (read_alphacoff_dynamic_symtab): Likewise. * mt-tdep.c (mt_register_name): Likewise. (mt_registers_info): Likewise. (mt_push_dummy_call): Likewise. * namespace.c (add_using_directive): Likewise. * nat/linux-btrace.c (perf_event_read): Likewise. (linux_enable_bts): Likewise. * nat/linux-osdata.c (linux_common_core_of_thread): Likewise. * nat/linux-ptrace.c (linux_ptrace_test_ret_to_nx): Likewise. * nto-tdep.c (nto_find_and_open_solib): Likewise. (nto_parse_redirection): Likewise. * objc-lang.c (objc_demangle): Likewise. (find_methods): Likewise. * objfiles.c (get_objfile_bfd_data): Likewise. (set_objfile_main_name): Likewise. (allocate_objfile): Likewise. (objfile_relocate): Likewise. (update_section_map): Likewise. * osabi.c (generic_elf_osabi_sniff_abi_tag_sections): Likewise. * p-exp.y (exp): Likewise. (yylex): Likewise. * p-valprint.c (pascal_object_print_value): Likewise. * parse.c (initialize_expout): Likewise. (mark_completion_tag): Likewise. (copy_name): Likewise. (parse_float): Likewise. (type_stack_reserve): Likewise. * ppc-linux-tdep.c (ppc_stap_parse_special_token): Likewise. (ppu2spu_prev_register): Likewise. * ppc-ravenscar-thread.c (supply_register_at_address): Likewise. * printcmd.c (printf_wide_c_string): Likewise. (printf_pointer): Likewise. * probe.c (parse_probes): Likewise. * python/py-cmd.c (gdbpy_parse_command_name): Likewise. (cmdpy_init): Likewise. * python/py-gdb-readline.c (gdbpy_readline_wrapper): Likewise. * python/py-symtab.c (set_sal): Likewise. * python/py-unwind.c (pyuw_sniffer): Likewise. * python/python.c (python_interactive_command): Likewise. (compute_python_string): Likewise. * ravenscar-thread.c (get_running_thread_id): Likewise. * record-full.c (record_full_exec_insn): Likewise. (record_full_core_open_1): Likewise. * regcache.c (regcache_raw_read_signed): Likewise. (regcache_raw_read_unsigned): Likewise. (regcache_cooked_read_signed): Likewise. (regcache_cooked_read_unsigned): Likewise. * remote-fileio.c (remote_fileio_func_open): Likewise. (remote_fileio_func_rename): Likewise. (remote_fileio_func_unlink): Likewise. (remote_fileio_func_stat): Likewise. (remote_fileio_func_system): Likewise. * remote-mips.c (mips_xfer_memory): Likewise. (mips_load_srec): Likewise. (pmon_end_download): Likewise. * remote.c (new_remote_state): Likewise. (map_regcache_remote_table): Likewise. (remote_register_number_and_offset): Likewise. (init_remote_state): Likewise. (get_memory_packet_size): Likewise. (remote_pass_signals): Likewise. (remote_program_signals): Likewise. (remote_start_remote): Likewise. (remote_check_symbols): Likewise. (remote_query_supported): Likewise. (extended_remote_attach): Likewise. (process_g_packet): Likewise. (store_registers_using_G): Likewise. (putpkt_binary): Likewise. (read_frame): Likewise. (compare_sections_command): Likewise. (remote_hostio_pread): Likewise. (remote_hostio_readlink): Likewise. (remote_file_put): Likewise. (remote_file_get): Likewise. (remote_pid_to_exec_file): Likewise. (_initialize_remote): Likewise. * rs6000-aix-tdep.c (rs6000_aix_ld_info_to_xml): Likewise. (rs6000_aix_core_xfer_shared_libraries_aix): Likewise. * rs6000-tdep.c (ppc_displaced_step_copy_insn): Likewise. (bfd_uses_spe_extensions): Likewise. * s390-linux-tdep.c (s390_displaced_step_copy_insn): Likewise. * score-tdep.c (score7_malloc_and_get_memblock): Likewise. * solib-dsbt.c (decode_loadmap): Likewise. (fetch_loadmap): Likewise. (scan_dyntag): Likewise. (enable_break): Likewise. (dsbt_relocate_main_executable): Likewise. * solib-frv.c (fetch_loadmap): Likewise. (enable_break2): Likewise. (frv_relocate_main_executable): Likewise. * solib-spu.c (spu_relocate_main_executable): Likewise. (spu_bfd_open): Likewise. * solib-svr4.c (lm_info_read): Likewise. (read_program_header): Likewise. (find_program_interpreter): Likewise. (scan_dyntag): Likewise. (elf_locate_base): Likewise. (open_symbol_file_object): Likewise. (read_program_headers_from_bfd): Likewise. (svr4_relocate_main_executable): Likewise. * solib-target.c (solib_target_relocate_section_addresses): Likewise. * solib.c (solib_find_1): Likewise. (exec_file_find): Likewise. (solib_find): Likewise. * source.c (openp): Likewise. (print_source_lines_base): Likewise. (forward_search_command): Likewise. * sparc-ravenscar-thread.c (supply_register_at_address): Likewise. * spu-tdep.c (spu2ppu_prev_register): Likewise. (spu_get_overlay_table): Likewise. * stabsread.c (patch_block_stabs): Likewise. (define_symbol): Likewise. (again:): Likewise. (read_member_functions): Likewise. (read_one_struct_field): Likewise. (read_enum_type): Likewise. (common_block_start): Likewise. * stack.c (read_frame_arg): Likewise. (backtrace_command): Likewise. * stap-probe.c (stap_parse_register_operand): Likewise. * symfile.c (syms_from_objfile_1): Likewise. (find_separate_debug_file): Likewise. (load_command): Likewise. (load_progress): Likewise. (load_section_callback): Likewise. (reread_symbols): Likewise. (add_filename_language): Likewise. (allocate_compunit_symtab): Likewise. (read_target_long_array): Likewise. (simple_read_overlay_table): Likewise. * symtab.c (symbol_set_names): Likewise. (resize_symbol_cache): Likewise. (rbreak_command): Likewise. (completion_list_add_name): Likewise. (completion_list_objc_symbol): Likewise. (add_filename_to_list): Likewise. * target-descriptions.c (maint_print_c_tdesc_cmd): Likewise. * target-memory.c (target_write_memory_blocks): Likewise. * target.c (target_read_string): Likewise. (read_whatever_is_readable): Likewise. (target_read_alloc_1): Likewise. (simple_search_memory): Likewise. (target_fileio_read_alloc_1): Likewise. * tilegx-tdep.c (tilegx_push_dummy_call): Likewise. * top.c (command_line_input): Likewise. * tracefile-tfile.c (tfile_fetch_registers): Likewise. * tracefile.c (tracefile_fetch_registers): Likewise. * tracepoint.c (add_memrange): Likewise. (init_collection_list): Likewise. (add_aexpr): Likewise. (trace_dump_actions): Likewise. (parse_trace_status): Likewise. (parse_tracepoint_definition): Likewise. (parse_tsv_definition): Likewise. (parse_static_tracepoint_marker_definition): Likewise. * tui/tui-file.c (tui_sfileopen): Likewise. (tui_file_adjust_strbuf): Likewise. * tui/tui-io.c (tui_expand_tabs): Likewise. * tui/tui-source.c (tui_set_source_content): Likewise. * typeprint.c (find_global_typedef): Likewise. * ui-file.c (do_ui_file_xstrdup): Likewise. (ui_file_obsavestring): Likewise. (mem_file_write): Likewise. * utils.c (make_hex_string): Likewise. (get_regcomp_error): Likewise. (puts_filtered_tabular): Likewise. (gdb_realpath_keepfile): Likewise. (ldirname): Likewise. (gdb_bfd_errmsg): Likewise. (substitute_path_component): Likewise. * valops.c (search_struct_method): Likewise. (find_oload_champ_namespace_loop): Likewise. * valprint.c (print_decimal_chars): Likewise. (read_string): Likewise. (generic_emit_char): Likewise. * varobj.c (varobj_delete): Likewise. (varobj_value_get_print_value): Likewise. * vaxobsd-tdep.c (vaxobsd_sigtramp_sniffer): Likewise. * windows-tdep.c (display_one_tib): Likewise. * xcoffread.c (read_xcoff_symtab): Likewise. (process_xcoff_symbol): Likewise. (swap_sym): Likewise. (scan_xcoff_symtab): Likewise. (xcoff_initial_scan): Likewise. * xml-support.c (gdb_xml_end_element): Likewise. (xml_process_xincludes): Likewise. (xml_fetch_content_from_file): Likewise. * xml-syscall.c (xml_list_of_syscalls): Likewise. * xstormy16-tdep.c (xstormy16_push_dummy_call): Likewise. gdb/gdbserver/ChangeLog: * ax.c (gdb_parse_agent_expr): Add cast to allocation result assignment. (gdb_unparse_agent_expr): Likewise. * hostio.c (require_data): Likewise. (handle_pread): Likewise. * linux-low.c (disable_regset): Likewise. (fetch_register): Likewise. (store_register): Likewise. (get_dynamic): Likewise. (linux_qxfer_libraries_svr4): Likewise. * mem-break.c (delete_fast_tracepoint_jump): Likewise. (set_fast_tracepoint_jump): Likewise. (uninsert_fast_tracepoint_jumps_at): Likewise. (reinsert_fast_tracepoint_jumps_at): Likewise. (validate_inserted_breakpoint): Likewise. (clone_agent_expr): Likewise. * regcache.c (init_register_cache): Likewise. * remote-utils.c (putpkt_binary_1): Likewise. (decode_M_packet): Likewise. (decode_X_packet): Likewise. (look_up_one_symbol): Likewise. (relocate_instruction): Likewise. (monitor_output): Likewise. * server.c (handle_search_memory): Likewise. (handle_qxfer_exec_file): Likewise. (handle_qxfer_libraries): Likewise. (handle_qxfer): Likewise. (handle_query): Likewise. (handle_v_cont): Likewise. (handle_v_run): Likewise. (captured_main): Likewise. * target.c (write_inferior_memory): Likewise. * thread-db.c (try_thread_db_load_from_dir): Likewise. * tracepoint.c (init_trace_buffer): Likewise. (add_tracepoint_action): Likewise. (add_traceframe): Likewise. (add_traceframe_block): Likewise. (cmd_qtdpsrc): Likewise. (cmd_qtdv): Likewise. (cmd_qtstatus): Likewise. (response_source): Likewise. (response_tsv): Likewise. (cmd_qtnotes): Likewise. (gdb_collect): Likewise. (initialize_tracepoint): Likewise.
2015-09-25 20:08:06 +02:00
prefix = (char *) alloca (len + 1);
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
memcpy (prefix, arg, len);
prefix[len] = '\0';
printf_unfiltered ("%s\n", prefix);
}
/* Implement "info vtbl". */
static void
Constify add_info This patch constifies add_info and updates all the info commands. The bulk of this patch was written using a script; and then I did a manual pass to fix up the remaining compilation errors. I could not compile every changed file; in particular nto-procfs.c, gnu-nat.c, and darwin-nat-info.c; but I at least tried to check the correctness by inspection. gdb/ChangeLog 2017-11-07 Tom Tromey <tom@tromey.com> * frame.h (info_locals_command, info_args_command): Constify. * auto-load.h (auto_load_info_scripts): Constify. * inferior.h (registers_info): Constify. * copying.c: Rebuild. * copying.awk: Constify generated commands. * auto-load.c (auto_load_info_scripts) (info_auto_load_gdb_scripts): Constify. * cli/cli-decode.c (struct cmd_list_element): Take a cmd_const_cfunc_ftype. * command.h (add_info): Take a cmd_const_cfunc_ftype. * tui/tui-win.c (tui_all_windows_info): Constify. * python/py-auto-load.c (info_auto_load_python_scripts): Constify. * cli/cli-cmds.c (show_command): Remove non-const overload. * tracepoint.c (info_tvariables_command, info_scope_command): Constify. (info_static_tracepoint_markers_command): Constify. * thread.c (info_threads_command): Constify. (print_thread_info_1): Constify. * target.c (info_target_command): Constify. * symtab.c (info_sources_command, info_functions_command) (info_types_command): Constify. (info_variables_command): Remove non-const overload. * symfile.c (info_ext_lang_command): Constify. * stack.c (info_frame_command, info_locals_command) (info_args_command): Constify. (backtrace_command): Remove non-const overload. * source.c (info_source_command, info_line_command): Constify. * solib.c (info_sharedlibrary_command): Constify. * skip.c (info_skip_command): Constify. * ser-go32.c (info_serial_command): Constify. * reverse.c (info_bookmarks_command): Constify. * printcmd.c (info_symbol_command, info_address_command) (info_display_command): Constify. * osdata.c (info_osdata_command): Constify. * objc-lang.c (info_selectors_command, info_classes_command): Constify. * nto-procfs.c (procfs_pidlist, procfs_meminfo): Constify. * memattr.c (info_mem_command): Constify. * macrocmd.c (info_macro_command, info_macros_command): Constify. * linux-fork.c (info_checkpoints_command): Constify. * infrun.c (info_signals_command): Constify. * inflow.c (info_terminal_command): Constify. * inferior.c (info_inferiors_command): Constify. (print_inferior): Constify. * infcmd.c (info_program_command, info_all_registers_command) (info_registers_command, info_vector_command) (info_float_command): Constify. (registers_info): Constify. * gnu-nat.c (info_send_rights_cmd, info_recv_rights_cmd) (info_port_sets_cmd, info_dead_names_cmd, info_port_rights_cmd): Constify. * f-valprint.c (info_common_command): Constify. * dcache.c (info_dcache_command): Constify. (dcache_info_1): Constify. * darwin-nat-info.c (info_mach_tasks_command) (info_mach_task_command, info_mach_ports_command) (info_mach_port_command, info_mach_threads_command) (info_mach_thread_command, info_mach_regions_command) (info_mach_regions_recurse_command, info_mach_region_command) (info_mach_exceptions_command): Constify. (get_task_from_args): Constify. * cp-support.c (info_vtbl_command): Constify. * breakpoint.c (info_watchpoints_command) (info_tracepoints_command): Constify. (info_breakpoints_command): Remove non-const overload. * avr-tdep.c (avr_io_reg_read_command): Constify. * auxv.c (info_auxv_command): Constify. * ada-tasks.c (info_tasks_command): Constify. (info_task): Constify. * ada-lang.c (info_exceptions_command): Constify.
2017-10-14 06:07:26 +02:00
info_vtbl_command (const char *arg, int from_tty)
{
struct value *value;
value = parse_and_eval (arg);
cplus_print_vtable (value);
}
gdb: add back declarations for _initialize functions I'd like to enable the -Wmissing-declarations warning. However, it warns for every _initialize function, for example: CXX dcache.o /home/smarchi/src/binutils-gdb/gdb/dcache.c: In function ‘void _initialize_dcache()’: /home/smarchi/src/binutils-gdb/gdb/dcache.c:688:1: error: no previous declaration for ‘void _initialize_dcache()’ [-Werror=missing-declarations] _initialize_dcache (void) ^~~~~~~~~~~~~~~~~~ The only practical way forward I found is to add back the declarations, which were removed by this commit: commit 481695ed5f6e0a8a9c9c50bfac1cdd2b3151e6c9 Author: John Baldwin <jhb@FreeBSD.org> Date: Sat Sep 9 11:02:37 2017 -0700 Remove unnecessary function prototypes. I don't think it's a big problem to have the declarations for these functions, but if anybody has a better solution for this, I'll be happy to use it. gdb/ChangeLog: * aarch64-fbsd-nat.c (_initialize_aarch64_fbsd_nat): Add declaration. * aarch64-fbsd-tdep.c (_initialize_aarch64_fbsd_tdep): Add declaration. * aarch64-linux-nat.c (_initialize_aarch64_linux_nat): Add declaration. * aarch64-linux-tdep.c (_initialize_aarch64_linux_tdep): Add declaration. * aarch64-newlib-tdep.c (_initialize_aarch64_newlib_tdep): Add declaration. * aarch64-tdep.c (_initialize_aarch64_tdep): Add declaration. * ada-exp.y (_initialize_ada_exp): Add declaration. * ada-lang.c (_initialize_ada_language): Add declaration. * ada-tasks.c (_initialize_tasks): Add declaration. * agent.c (_initialize_agent): Add declaration. * aix-thread.c (_initialize_aix_thread): Add declaration. * alpha-bsd-nat.c (_initialize_alphabsd_nat): Add declaration. * alpha-linux-nat.c (_initialize_alpha_linux_nat): Add declaration. * alpha-linux-tdep.c (_initialize_alpha_linux_tdep): Add declaration. * alpha-nbsd-tdep.c (_initialize_alphanbsd_tdep): Add declaration. * alpha-obsd-tdep.c (_initialize_alphaobsd_tdep): Add declaration. * alpha-tdep.c (_initialize_alpha_tdep): Add declaration. * amd64-darwin-tdep.c (_initialize_amd64_darwin_tdep): Add declaration. * amd64-dicos-tdep.c (_initialize_amd64_dicos_tdep): Add declaration. * amd64-fbsd-nat.c (_initialize_amd64fbsd_nat): Add declaration. * amd64-fbsd-tdep.c (_initialize_amd64fbsd_tdep): Add declaration. * amd64-linux-nat.c (_initialize_amd64_linux_nat): Add declaration. * amd64-linux-tdep.c (_initialize_amd64_linux_tdep): Add declaration. * amd64-nbsd-nat.c (_initialize_amd64nbsd_nat): Add declaration. * amd64-nbsd-tdep.c (_initialize_amd64nbsd_tdep): Add declaration. * amd64-obsd-nat.c (_initialize_amd64obsd_nat): Add declaration. * amd64-obsd-tdep.c (_initialize_amd64obsd_tdep): Add declaration. * amd64-sol2-tdep.c (_initialize_amd64_sol2_tdep): Add declaration. * amd64-tdep.c (_initialize_amd64_tdep): Add declaration. * amd64-windows-nat.c (_initialize_amd64_windows_nat): Add declaration. * amd64-windows-tdep.c (_initialize_amd64_windows_tdep): Add declaration. * annotate.c (_initialize_annotate): Add declaration. * arc-newlib-tdep.c (_initialize_arc_newlib_tdep): Add declaration. * arc-tdep.c (_initialize_arc_tdep): Add declaration. * arch-utils.c (_initialize_gdbarch_utils): Add declaration. * arm-fbsd-nat.c (_initialize_arm_fbsd_nat): Add declaration. * arm-fbsd-tdep.c (_initialize_arm_fbsd_tdep): Add declaration. * arm-linux-nat.c (_initialize_arm_linux_nat): Add declaration. * arm-linux-tdep.c (_initialize_arm_linux_tdep): Add declaration. * arm-nbsd-nat.c (_initialize_arm_netbsd_nat): Add declaration. * arm-nbsd-tdep.c (_initialize_arm_netbsd_tdep): Add declaration. * arm-obsd-tdep.c (_initialize_armobsd_tdep): Add declaration. * arm-pikeos-tdep.c (_initialize_arm_pikeos_tdep): Add declaration. * arm-symbian-tdep.c (_initialize_arm_symbian_tdep): Add declaration. * arm-tdep.c (_initialize_arm_tdep): Add declaration. * arm-wince-tdep.c (_initialize_arm_wince_tdep): Add declaration. * auto-load.c (_initialize_auto_load): Add declaration. * auxv.c (_initialize_auxv): Add declaration. * avr-tdep.c (_initialize_avr_tdep): Add declaration. * ax-gdb.c (_initialize_ax_gdb): Add declaration. * bfin-linux-tdep.c (_initialize_bfin_linux_tdep): Add declaration. * bfin-tdep.c (_initialize_bfin_tdep): Add declaration. * break-catch-sig.c (_initialize_break_catch_sig): Add declaration. * break-catch-syscall.c (_initialize_break_catch_syscall): Add declaration. * break-catch-throw.c (_initialize_break_catch_throw): Add declaration. * breakpoint.c (_initialize_breakpoint): Add declaration. * bsd-uthread.c (_initialize_bsd_uthread): Add declaration. * btrace.c (_initialize_btrace): Add declaration. * charset.c (_initialize_charset): Add declaration. * cli/cli-cmds.c (_initialize_cli_cmds): Add declaration. * cli/cli-dump.c (_initialize_cli_dump): Add declaration. * cli/cli-interp.c (_initialize_cli_interp): Add declaration. * cli/cli-logging.c (_initialize_cli_logging): Add declaration. * cli/cli-script.c (_initialize_cli_script): Add declaration. * cli/cli-style.c (_initialize_cli_style): Add declaration. * coff-pe-read.c (_initialize_coff_pe_read): Add declaration. * coffread.c (_initialize_coffread): Add declaration. * compile/compile-cplus-types.c (_initialize_compile_cplus_types): Add declaration. * compile/compile.c (_initialize_compile): Add declaration. * complaints.c (_initialize_complaints): Add declaration. * completer.c (_initialize_completer): Add declaration. * copying.c (_initialize_copying): Add declaration. * corefile.c (_initialize_core): Add declaration. * corelow.c (_initialize_corelow): Add declaration. * cp-abi.c (_initialize_cp_abi): Add declaration. * cp-namespace.c (_initialize_cp_namespace): Add declaration. * cp-support.c (_initialize_cp_support): Add declaration. * cp-valprint.c (_initialize_cp_valprint): Add declaration. * cris-linux-tdep.c (_initialize_cris_linux_tdep): Add declaration. * cris-tdep.c (_initialize_cris_tdep): Add declaration. * csky-linux-tdep.c (_initialize_csky_linux_tdep): Add declaration. * csky-tdep.c (_initialize_csky_tdep): Add declaration. * ctfread.c (_initialize_ctfread): Add declaration. * d-lang.c (_initialize_d_language): Add declaration. * darwin-nat-info.c (_initialize_darwin_info_commands): Add declaration. * darwin-nat.c (_initialize_darwin_nat): Add declaration. * dbxread.c (_initialize_dbxread): Add declaration. * dcache.c (_initialize_dcache): Add declaration. * disasm-selftests.c (_initialize_disasm_selftests): Add declaration. * disasm.c (_initialize_disasm): Add declaration. * dtrace-probe.c (_initialize_dtrace_probe): Add declaration. * dummy-frame.c (_initialize_dummy_frame): Add declaration. * dwarf-index-cache.c (_initialize_index_cache): Add declaration. * dwarf-index-write.c (_initialize_dwarf_index_write): Add declaration. * dwarf2-frame-tailcall.c (_initialize_tailcall_frame): Add declaration. * dwarf2-frame.c (_initialize_dwarf2_frame): Add declaration. * dwarf2expr.c (_initialize_dwarf2expr): Add declaration. * dwarf2loc.c (_initialize_dwarf2loc): Add declaration. * dwarf2read.c (_initialize_dwarf2_read): Add declaration. * elfread.c (_initialize_elfread): Add declaration. * exec.c (_initialize_exec): Add declaration. * extension.c (_initialize_extension): Add declaration. * f-lang.c (_initialize_f_language): Add declaration. * f-valprint.c (_initialize_f_valprint): Add declaration. * fbsd-nat.c (_initialize_fbsd_nat): Add declaration. * fbsd-tdep.c (_initialize_fbsd_tdep): Add declaration. * filesystem.c (_initialize_filesystem): Add declaration. * findcmd.c (_initialize_mem_search): Add declaration. * findvar.c (_initialize_findvar): Add declaration. * fork-child.c (_initialize_fork_child): Add declaration. * frame-base.c (_initialize_frame_base): Add declaration. * frame-unwind.c (_initialize_frame_unwind): Add declaration. * frame.c (_initialize_frame): Add declaration. * frv-linux-tdep.c (_initialize_frv_linux_tdep): Add declaration. * frv-tdep.c (_initialize_frv_tdep): Add declaration. * ft32-tdep.c (_initialize_ft32_tdep): Add declaration. * gcore.c (_initialize_gcore): Add declaration. * gdb-demangle.c (_initialize_gdb_demangle): Add declaration. * gdb_bfd.c (_initialize_gdb_bfd): Add declaration. * gdbarch-selftests.c (_initialize_gdbarch_selftests): Add declaration. * gdbarch.c (_initialize_gdbarch): Add declaration. * gdbtypes.c (_initialize_gdbtypes): Add declaration. * gnu-nat.c (_initialize_gnu_nat): Add declaration. * gnu-v2-abi.c (_initialize_gnu_v2_abi): Add declaration. * gnu-v3-abi.c (_initialize_gnu_v3_abi): Add declaration. * go-lang.c (_initialize_go_language): Add declaration. * go32-nat.c (_initialize_go32_nat): Add declaration. * guile/guile.c (_initialize_guile): Add declaration. * h8300-tdep.c (_initialize_h8300_tdep): Add declaration. * hppa-linux-nat.c (_initialize_hppa_linux_nat): Add declaration. * hppa-linux-tdep.c (_initialize_hppa_linux_tdep): Add declaration. * hppa-nbsd-nat.c (_initialize_hppanbsd_nat): Add declaration. * hppa-nbsd-tdep.c (_initialize_hppanbsd_tdep): Add declaration. * hppa-obsd-nat.c (_initialize_hppaobsd_nat): Add declaration. * hppa-obsd-tdep.c (_initialize_hppabsd_tdep): Add declaration. * hppa-tdep.c (_initialize_hppa_tdep): Add declaration. * i386-bsd-nat.c (_initialize_i386bsd_nat): Add declaration. * i386-cygwin-tdep.c (_initialize_i386_cygwin_tdep): Add declaration. * i386-darwin-nat.c (_initialize_i386_darwin_nat): Add declaration. * i386-darwin-tdep.c (_initialize_i386_darwin_tdep): Add declaration. * i386-dicos-tdep.c (_initialize_i386_dicos_tdep): Add declaration. * i386-fbsd-nat.c (_initialize_i386fbsd_nat): Add declaration. * i386-fbsd-tdep.c (_initialize_i386fbsd_tdep): Add declaration. * i386-gnu-nat.c (_initialize_i386gnu_nat): Add declaration. * i386-gnu-tdep.c (_initialize_i386gnu_tdep): Add declaration. * i386-go32-tdep.c (_initialize_i386_go32_tdep): Add declaration. * i386-linux-nat.c (_initialize_i386_linux_nat): Add declaration. * i386-linux-tdep.c (_initialize_i386_linux_tdep): Add declaration. * i386-nbsd-nat.c (_initialize_i386nbsd_nat): Add declaration. * i386-nbsd-tdep.c (_initialize_i386nbsd_tdep): Add declaration. * i386-nto-tdep.c (_initialize_i386nto_tdep): Add declaration. * i386-obsd-nat.c (_initialize_i386obsd_nat): Add declaration. * i386-obsd-tdep.c (_initialize_i386obsd_tdep): Add declaration. * i386-sol2-nat.c (_initialize_amd64_sol2_nat): Add declaration. * i386-sol2-tdep.c (_initialize_i386_sol2_tdep): Add declaration. * i386-tdep.c (_initialize_i386_tdep): Add declaration. * i386-windows-nat.c (_initialize_i386_windows_nat): Add declaration. * ia64-libunwind-tdep.c (_initialize_libunwind_frame): Add declaration. * ia64-linux-nat.c (_initialize_ia64_linux_nat): Add declaration. * ia64-linux-tdep.c (_initialize_ia64_linux_tdep): Add declaration. * ia64-tdep.c (_initialize_ia64_tdep): Add declaration. * ia64-vms-tdep.c (_initialize_ia64_vms_tdep): Add declaration. * infcall.c (_initialize_infcall): Add declaration. * infcmd.c (_initialize_infcmd): Add declaration. * inflow.c (_initialize_inflow): Add declaration. * infrun.c (_initialize_infrun): Add declaration. * interps.c (_initialize_interpreter): Add declaration. * iq2000-tdep.c (_initialize_iq2000_tdep): Add declaration. * jit.c (_initialize_jit): Add declaration. * language.c (_initialize_language): Add declaration. * linux-fork.c (_initialize_linux_fork): Add declaration. * linux-nat.c (_initialize_linux_nat): Add declaration. * linux-tdep.c (_initialize_linux_tdep): Add declaration. * linux-thread-db.c (_initialize_thread_db): Add declaration. * lm32-tdep.c (_initialize_lm32_tdep): Add declaration. * m2-lang.c (_initialize_m2_language): Add declaration. * m32c-tdep.c (_initialize_m32c_tdep): Add declaration. * m32r-linux-nat.c (_initialize_m32r_linux_nat): Add declaration. * m32r-linux-tdep.c (_initialize_m32r_linux_tdep): Add declaration. * m32r-tdep.c (_initialize_m32r_tdep): Add declaration. * m68hc11-tdep.c (_initialize_m68hc11_tdep): Add declaration. * m68k-bsd-nat.c (_initialize_m68kbsd_nat): Add declaration. * m68k-bsd-tdep.c (_initialize_m68kbsd_tdep): Add declaration. * m68k-linux-nat.c (_initialize_m68k_linux_nat): Add declaration. * m68k-linux-tdep.c (_initialize_m68k_linux_tdep): Add declaration. * m68k-tdep.c (_initialize_m68k_tdep): Add declaration. * machoread.c (_initialize_machoread): Add declaration. * macrocmd.c (_initialize_macrocmd): Add declaration. * macroscope.c (_initialize_macroscope): Add declaration. * maint-test-options.c (_initialize_maint_test_options): Add declaration. * maint-test-settings.c (_initialize_maint_test_settings): Add declaration. * maint.c (_initialize_maint_cmds): Add declaration. * mdebugread.c (_initialize_mdebugread): Add declaration. * memattr.c (_initialize_mem): Add declaration. * mep-tdep.c (_initialize_mep_tdep): Add declaration. * mi/mi-cmd-env.c (_initialize_mi_cmd_env): Add declaration. * mi/mi-cmds.c (_initialize_mi_cmds): Add declaration. * mi/mi-interp.c (_initialize_mi_interp): Add declaration. * mi/mi-main.c (_initialize_mi_main): Add declaration. * microblaze-linux-tdep.c (_initialize_microblaze_linux_tdep): Add declaration. * microblaze-tdep.c (_initialize_microblaze_tdep): Add declaration. * mips-fbsd-nat.c (_initialize_mips_fbsd_nat): Add declaration. * mips-fbsd-tdep.c (_initialize_mips_fbsd_tdep): Add declaration. * mips-linux-nat.c (_initialize_mips_linux_nat): Add declaration. * mips-linux-tdep.c (_initialize_mips_linux_tdep): Add declaration. * mips-nbsd-nat.c (_initialize_mipsnbsd_nat): Add declaration. * mips-nbsd-tdep.c (_initialize_mipsnbsd_tdep): Add declaration. * mips-sde-tdep.c (_initialize_mips_sde_tdep): Add declaration. * mips-tdep.c (_initialize_mips_tdep): Add declaration. * mips64-obsd-nat.c (_initialize_mips64obsd_nat): Add declaration. * mips64-obsd-tdep.c (_initialize_mips64obsd_tdep): Add declaration. * mipsread.c (_initialize_mipsread): Add declaration. * mn10300-linux-tdep.c (_initialize_mn10300_linux_tdep): Add declaration. * mn10300-tdep.c (_initialize_mn10300_tdep): Add declaration. * moxie-tdep.c (_initialize_moxie_tdep): Add declaration. * msp430-tdep.c (_initialize_msp430_tdep): Add declaration. * nds32-tdep.c (_initialize_nds32_tdep): Add declaration. * nios2-linux-tdep.c (_initialize_nios2_linux_tdep): Add declaration. * nios2-tdep.c (_initialize_nios2_tdep): Add declaration. * nto-procfs.c (_initialize_procfs): Add declaration. * objc-lang.c (_initialize_objc_language): Add declaration. * observable.c (_initialize_observer): Add declaration. * opencl-lang.c (_initialize_opencl_language): Add declaration. * or1k-linux-tdep.c (_initialize_or1k_linux_tdep): Add declaration. * or1k-tdep.c (_initialize_or1k_tdep): Add declaration. * osabi.c (_initialize_gdb_osabi): Add declaration. * osdata.c (_initialize_osdata): Add declaration. * p-valprint.c (_initialize_pascal_valprint): Add declaration. * parse.c (_initialize_parse): Add declaration. * ppc-fbsd-nat.c (_initialize_ppcfbsd_nat): Add declaration. * ppc-fbsd-tdep.c (_initialize_ppcfbsd_tdep): Add declaration. * ppc-linux-nat.c (_initialize_ppc_linux_nat): Add declaration. * ppc-linux-tdep.c (_initialize_ppc_linux_tdep): Add declaration. * ppc-nbsd-nat.c (_initialize_ppcnbsd_nat): Add declaration. * ppc-nbsd-tdep.c (_initialize_ppcnbsd_tdep): Add declaration. * ppc-obsd-nat.c (_initialize_ppcobsd_nat): Add declaration. * ppc-obsd-tdep.c (_initialize_ppcobsd_tdep): Add declaration. * printcmd.c (_initialize_printcmd): Add declaration. * probe.c (_initialize_probe): Add declaration. * proc-api.c (_initialize_proc_api): Add declaration. * proc-events.c (_initialize_proc_events): Add declaration. * proc-service.c (_initialize_proc_service): Add declaration. * procfs.c (_initialize_procfs): Add declaration. * producer.c (_initialize_producer): Add declaration. * psymtab.c (_initialize_psymtab): Add declaration. * python/python.c (_initialize_python): Add declaration. * ravenscar-thread.c (_initialize_ravenscar): Add declaration. * record-btrace.c (_initialize_record_btrace): Add declaration. * record-full.c (_initialize_record_full): Add declaration. * record.c (_initialize_record): Add declaration. * regcache-dump.c (_initialize_regcache_dump): Add declaration. * regcache.c (_initialize_regcache): Add declaration. * reggroups.c (_initialize_reggroup): Add declaration. * remote-notif.c (_initialize_notif): Add declaration. * remote-sim.c (_initialize_remote_sim): Add declaration. * remote.c (_initialize_remote): Add declaration. * reverse.c (_initialize_reverse): Add declaration. * riscv-fbsd-nat.c (_initialize_riscv_fbsd_nat): Add declaration. * riscv-fbsd-tdep.c (_initialize_riscv_fbsd_tdep): Add declaration. * riscv-linux-nat.c (_initialize_riscv_linux_nat): Add declaration. * riscv-linux-tdep.c (_initialize_riscv_linux_tdep): Add declaration. * riscv-tdep.c (_initialize_riscv_tdep): Add declaration. * rl78-tdep.c (_initialize_rl78_tdep): Add declaration. * rs6000-aix-tdep.c (_initialize_rs6000_aix_tdep): Add declaration. * rs6000-lynx178-tdep.c (_initialize_rs6000_lynx178_tdep): Add declaration. * rs6000-nat.c (_initialize_rs6000_nat): Add declaration. * rs6000-tdep.c (_initialize_rs6000_tdep): Add declaration. * run-on-main-thread.c (_initialize_run_on_main_thread): Add declaration. * rust-exp.y (_initialize_rust_exp): Add declaration. * rx-tdep.c (_initialize_rx_tdep): Add declaration. * s12z-tdep.c (_initialize_s12z_tdep): Add declaration. * s390-linux-nat.c (_initialize_s390_nat): Add declaration. * s390-linux-tdep.c (_initialize_s390_linux_tdep): Add declaration. * s390-tdep.c (_initialize_s390_tdep): Add declaration. * score-tdep.c (_initialize_score_tdep): Add declaration. * ser-go32.c (_initialize_ser_dos): Add declaration. * ser-mingw.c (_initialize_ser_windows): Add declaration. * ser-pipe.c (_initialize_ser_pipe): Add declaration. * ser-tcp.c (_initialize_ser_tcp): Add declaration. * ser-uds.c (_initialize_ser_socket): Add declaration. * ser-unix.c (_initialize_ser_hardwire): Add declaration. * serial.c (_initialize_serial): Add declaration. * sh-linux-tdep.c (_initialize_sh_linux_tdep): Add declaration. * sh-nbsd-nat.c (_initialize_shnbsd_nat): Add declaration. * sh-nbsd-tdep.c (_initialize_shnbsd_tdep): Add declaration. * sh-tdep.c (_initialize_sh_tdep): Add declaration. * skip.c (_initialize_step_skip): Add declaration. * sol-thread.c (_initialize_sol_thread): Add declaration. * solib-aix.c (_initialize_solib_aix): Add declaration. * solib-darwin.c (_initialize_darwin_solib): Add declaration. * solib-dsbt.c (_initialize_dsbt_solib): Add declaration. * solib-frv.c (_initialize_frv_solib): Add declaration. * solib-svr4.c (_initialize_svr4_solib): Add declaration. * solib-target.c (_initialize_solib_target): Add declaration. * solib.c (_initialize_solib): Add declaration. * source-cache.c (_initialize_source_cache): Add declaration. * source.c (_initialize_source): Add declaration. * sparc-linux-nat.c (_initialize_sparc_linux_nat): Add declaration. * sparc-linux-tdep.c (_initialize_sparc_linux_tdep): Add declaration. * sparc-nat.c (_initialize_sparc_nat): Add declaration. * sparc-nbsd-nat.c (_initialize_sparcnbsd_nat): Add declaration. * sparc-nbsd-tdep.c (_initialize_sparcnbsd_tdep): Add declaration. * sparc-obsd-tdep.c (_initialize_sparc32obsd_tdep): Add declaration. * sparc-sol2-tdep.c (_initialize_sparc_sol2_tdep): Add declaration. * sparc-tdep.c (_initialize_sparc_tdep): Add declaration. * sparc64-fbsd-nat.c (_initialize_sparc64fbsd_nat): Add declaration. * sparc64-fbsd-tdep.c (_initialize_sparc64fbsd_tdep): Add declaration. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Add declaration. * sparc64-linux-tdep.c (_initialize_sparc64_linux_tdep): Add declaration. * sparc64-nat.c (_initialize_sparc64_nat): Add declaration. * sparc64-nbsd-nat.c (_initialize_sparc64nbsd_nat): Add declaration. * sparc64-nbsd-tdep.c (_initialize_sparc64nbsd_tdep): Add declaration. * sparc64-obsd-nat.c (_initialize_sparc64obsd_nat): Add declaration. * sparc64-obsd-tdep.c (_initialize_sparc64obsd_tdep): Add declaration. * sparc64-sol2-tdep.c (_initialize_sparc64_sol2_tdep): Add declaration. * sparc64-tdep.c (_initialize_sparc64_adi_tdep): Add declaration. * stabsread.c (_initialize_stabsread): Add declaration. * stack.c (_initialize_stack): Add declaration. * stap-probe.c (_initialize_stap_probe): Add declaration. * std-regs.c (_initialize_frame_reg): Add declaration. * symfile-debug.c (_initialize_symfile_debug): Add declaration. * symfile-mem.c (_initialize_symfile_mem): Add declaration. * symfile.c (_initialize_symfile): Add declaration. * symmisc.c (_initialize_symmisc): Add declaration. * symtab.c (_initialize_symtab): Add declaration. * target.c (_initialize_target): Add declaration. * target-connection.c (_initialize_target_connection): Add declaration. * target-dcache.c (_initialize_target_dcache): Add declaration. * target-descriptions.c (_initialize_target_descriptions): Add declaration. * thread.c (_initialize_thread): Add declaration. * tic6x-linux-tdep.c (_initialize_tic6x_linux_tdep): Add declaration. * tic6x-tdep.c (_initialize_tic6x_tdep): Add declaration. * tilegx-linux-nat.c (_initialize_tile_linux_nat): Add declaration. * tilegx-linux-tdep.c (_initialize_tilegx_linux_tdep): Add declaration. * tilegx-tdep.c (_initialize_tilegx_tdep): Add declaration. * tracectf.c (_initialize_ctf): Add declaration. * tracefile-tfile.c (_initialize_tracefile_tfile): Add declaration. * tracefile.c (_initialize_tracefile): Add declaration. * tracepoint.c (_initialize_tracepoint): Add declaration. * tui/tui-hooks.c (_initialize_tui_hooks): Add declaration. * tui/tui-interp.c (_initialize_tui_interp): Add declaration. * tui/tui-layout.c (_initialize_tui_layout): Add declaration. * tui/tui-regs.c (_initialize_tui_regs): Add declaration. * tui/tui-stack.c (_initialize_tui_stack): Add declaration. * tui/tui-win.c (_initialize_tui_win): Add declaration. * tui/tui.c (_initialize_tui): Add declaration. * typeprint.c (_initialize_typeprint): Add declaration. * ui-style.c (_initialize_ui_style): Add declaration. * unittests/array-view-selftests.c (_initialize_array_view_selftests): Add declaration. * unittests/child-path-selftests.c (_initialize_child_path_selftests): Add declaration. * unittests/cli-utils-selftests.c (_initialize_cli_utils_selftests): Add declaration. * unittests/common-utils-selftests.c (_initialize_common_utils_selftests): Add declaration. * unittests/copy_bitwise-selftests.c (_initialize_copy_bitwise_utils_selftests): Add declaration. * unittests/environ-selftests.c (_initialize_environ_selftests): Add declaration. * unittests/filtered_iterator-selftests.c (_initialize_filtered_iterator_selftests): Add declaration. * unittests/format_pieces-selftests.c (_initialize_format_pieces_selftests): Add declaration. * unittests/function-view-selftests.c (_initialize_function_view_selftests): Add declaration. * unittests/help-doc-selftests.c (_initialize_help_doc_selftests): Add declaration. * unittests/lookup_name_info-selftests.c (_initialize_lookup_name_info_selftests): Add declaration. * unittests/main-thread-selftests.c (_initialize_main_thread_selftests): Add declaration. * unittests/memory-map-selftests.c (_initialize_memory_map_selftests): Add declaration. * unittests/memrange-selftests.c (_initialize_memrange_selftests): Add declaration. * unittests/mkdir-recursive-selftests.c (_initialize_mkdir_recursive_selftests): Add declaration. * unittests/observable-selftests.c (_initialize_observer_selftest): Add declaration. * unittests/offset-type-selftests.c (_initialize_offset_type_selftests): Add declaration. * unittests/optional-selftests.c (_initialize_optional_selftests): Add declaration. * unittests/parse-connection-spec-selftests.c (_initialize_parse_connection_spec_selftests): Add declaration. * unittests/rsp-low-selftests.c (_initialize_rsp_low_selftests): Add declaration. * unittests/scoped_fd-selftests.c (_initialize_scoped_fd_selftests): Add declaration. * unittests/scoped_mmap-selftests.c (_initialize_scoped_mmap_selftests): Add declaration. * unittests/scoped_restore-selftests.c (_initialize_scoped_restore_selftests): Add declaration. * unittests/string_view-selftests.c (_initialize_string_view_selftests): Add declaration. * unittests/style-selftests.c (_initialize_style_selftest): Add declaration. * unittests/tracepoint-selftests.c (_initialize_tracepoint_selftests): Add declaration. * unittests/tui-selftests.c (_initialize_tui_selftest): Add declaration. * unittests/unpack-selftests.c (_initialize_unpack_selftests): Add declaration. * unittests/utils-selftests.c (_initialize_utils_selftests): Add declaration. * unittests/vec-utils-selftests.c (_initialize_vec_utils_selftests): Add declaration. * unittests/xml-utils-selftests.c (_initialize_xml_utils): Add declaration. * user-regs.c (_initialize_user_regs): Add declaration. * utils.c (_initialize_utils): Add declaration. * v850-tdep.c (_initialize_v850_tdep): Add declaration. * valops.c (_initialize_valops): Add declaration. * valprint.c (_initialize_valprint): Add declaration. * value.c (_initialize_values): Add declaration. * varobj.c (_initialize_varobj): Add declaration. * vax-bsd-nat.c (_initialize_vaxbsd_nat): Add declaration. * vax-nbsd-tdep.c (_initialize_vaxnbsd_tdep): Add declaration. * vax-tdep.c (_initialize_vax_tdep): Add declaration. * windows-nat.c (_initialize_windows_nat): Add declaration. (_initialize_check_for_gdb_ini): Add declaration. (_initialize_loadable): Add declaration. * windows-tdep.c (_initialize_windows_tdep): Add declaration. * x86-bsd-nat.c (_initialize_x86_bsd_nat): Add declaration. * x86-linux-nat.c (_initialize_x86_linux_nat): Add declaration. * xcoffread.c (_initialize_xcoffread): Add declaration. * xml-support.c (_initialize_xml_support): Add declaration. * xstormy16-tdep.c (_initialize_xstormy16_tdep): Add declaration. * xtensa-linux-nat.c (_initialize_xtensa_linux_nat): Add declaration. * xtensa-linux-tdep.c (_initialize_xtensa_linux_tdep): Add declaration. * xtensa-tdep.c (_initialize_xtensa_tdep): Add declaration. Change-Id: I13eec7e0ed2b3c427377a7bdb055cf46da64def9
2020-01-13 20:01:38 +01:00
void _initialize_cp_support ();
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
void
gdb: add back declarations for _initialize functions I'd like to enable the -Wmissing-declarations warning. However, it warns for every _initialize function, for example: CXX dcache.o /home/smarchi/src/binutils-gdb/gdb/dcache.c: In function ‘void _initialize_dcache()’: /home/smarchi/src/binutils-gdb/gdb/dcache.c:688:1: error: no previous declaration for ‘void _initialize_dcache()’ [-Werror=missing-declarations] _initialize_dcache (void) ^~~~~~~~~~~~~~~~~~ The only practical way forward I found is to add back the declarations, which were removed by this commit: commit 481695ed5f6e0a8a9c9c50bfac1cdd2b3151e6c9 Author: John Baldwin <jhb@FreeBSD.org> Date: Sat Sep 9 11:02:37 2017 -0700 Remove unnecessary function prototypes. I don't think it's a big problem to have the declarations for these functions, but if anybody has a better solution for this, I'll be happy to use it. gdb/ChangeLog: * aarch64-fbsd-nat.c (_initialize_aarch64_fbsd_nat): Add declaration. * aarch64-fbsd-tdep.c (_initialize_aarch64_fbsd_tdep): Add declaration. * aarch64-linux-nat.c (_initialize_aarch64_linux_nat): Add declaration. * aarch64-linux-tdep.c (_initialize_aarch64_linux_tdep): Add declaration. * aarch64-newlib-tdep.c (_initialize_aarch64_newlib_tdep): Add declaration. * aarch64-tdep.c (_initialize_aarch64_tdep): Add declaration. * ada-exp.y (_initialize_ada_exp): Add declaration. * ada-lang.c (_initialize_ada_language): Add declaration. * ada-tasks.c (_initialize_tasks): Add declaration. * agent.c (_initialize_agent): Add declaration. * aix-thread.c (_initialize_aix_thread): Add declaration. * alpha-bsd-nat.c (_initialize_alphabsd_nat): Add declaration. * alpha-linux-nat.c (_initialize_alpha_linux_nat): Add declaration. * alpha-linux-tdep.c (_initialize_alpha_linux_tdep): Add declaration. * alpha-nbsd-tdep.c (_initialize_alphanbsd_tdep): Add declaration. * alpha-obsd-tdep.c (_initialize_alphaobsd_tdep): Add declaration. * alpha-tdep.c (_initialize_alpha_tdep): Add declaration. * amd64-darwin-tdep.c (_initialize_amd64_darwin_tdep): Add declaration. * amd64-dicos-tdep.c (_initialize_amd64_dicos_tdep): Add declaration. * amd64-fbsd-nat.c (_initialize_amd64fbsd_nat): Add declaration. * amd64-fbsd-tdep.c (_initialize_amd64fbsd_tdep): Add declaration. * amd64-linux-nat.c (_initialize_amd64_linux_nat): Add declaration. * amd64-linux-tdep.c (_initialize_amd64_linux_tdep): Add declaration. * amd64-nbsd-nat.c (_initialize_amd64nbsd_nat): Add declaration. * amd64-nbsd-tdep.c (_initialize_amd64nbsd_tdep): Add declaration. * amd64-obsd-nat.c (_initialize_amd64obsd_nat): Add declaration. * amd64-obsd-tdep.c (_initialize_amd64obsd_tdep): Add declaration. * amd64-sol2-tdep.c (_initialize_amd64_sol2_tdep): Add declaration. * amd64-tdep.c (_initialize_amd64_tdep): Add declaration. * amd64-windows-nat.c (_initialize_amd64_windows_nat): Add declaration. * amd64-windows-tdep.c (_initialize_amd64_windows_tdep): Add declaration. * annotate.c (_initialize_annotate): Add declaration. * arc-newlib-tdep.c (_initialize_arc_newlib_tdep): Add declaration. * arc-tdep.c (_initialize_arc_tdep): Add declaration. * arch-utils.c (_initialize_gdbarch_utils): Add declaration. * arm-fbsd-nat.c (_initialize_arm_fbsd_nat): Add declaration. * arm-fbsd-tdep.c (_initialize_arm_fbsd_tdep): Add declaration. * arm-linux-nat.c (_initialize_arm_linux_nat): Add declaration. * arm-linux-tdep.c (_initialize_arm_linux_tdep): Add declaration. * arm-nbsd-nat.c (_initialize_arm_netbsd_nat): Add declaration. * arm-nbsd-tdep.c (_initialize_arm_netbsd_tdep): Add declaration. * arm-obsd-tdep.c (_initialize_armobsd_tdep): Add declaration. * arm-pikeos-tdep.c (_initialize_arm_pikeos_tdep): Add declaration. * arm-symbian-tdep.c (_initialize_arm_symbian_tdep): Add declaration. * arm-tdep.c (_initialize_arm_tdep): Add declaration. * arm-wince-tdep.c (_initialize_arm_wince_tdep): Add declaration. * auto-load.c (_initialize_auto_load): Add declaration. * auxv.c (_initialize_auxv): Add declaration. * avr-tdep.c (_initialize_avr_tdep): Add declaration. * ax-gdb.c (_initialize_ax_gdb): Add declaration. * bfin-linux-tdep.c (_initialize_bfin_linux_tdep): Add declaration. * bfin-tdep.c (_initialize_bfin_tdep): Add declaration. * break-catch-sig.c (_initialize_break_catch_sig): Add declaration. * break-catch-syscall.c (_initialize_break_catch_syscall): Add declaration. * break-catch-throw.c (_initialize_break_catch_throw): Add declaration. * breakpoint.c (_initialize_breakpoint): Add declaration. * bsd-uthread.c (_initialize_bsd_uthread): Add declaration. * btrace.c (_initialize_btrace): Add declaration. * charset.c (_initialize_charset): Add declaration. * cli/cli-cmds.c (_initialize_cli_cmds): Add declaration. * cli/cli-dump.c (_initialize_cli_dump): Add declaration. * cli/cli-interp.c (_initialize_cli_interp): Add declaration. * cli/cli-logging.c (_initialize_cli_logging): Add declaration. * cli/cli-script.c (_initialize_cli_script): Add declaration. * cli/cli-style.c (_initialize_cli_style): Add declaration. * coff-pe-read.c (_initialize_coff_pe_read): Add declaration. * coffread.c (_initialize_coffread): Add declaration. * compile/compile-cplus-types.c (_initialize_compile_cplus_types): Add declaration. * compile/compile.c (_initialize_compile): Add declaration. * complaints.c (_initialize_complaints): Add declaration. * completer.c (_initialize_completer): Add declaration. * copying.c (_initialize_copying): Add declaration. * corefile.c (_initialize_core): Add declaration. * corelow.c (_initialize_corelow): Add declaration. * cp-abi.c (_initialize_cp_abi): Add declaration. * cp-namespace.c (_initialize_cp_namespace): Add declaration. * cp-support.c (_initialize_cp_support): Add declaration. * cp-valprint.c (_initialize_cp_valprint): Add declaration. * cris-linux-tdep.c (_initialize_cris_linux_tdep): Add declaration. * cris-tdep.c (_initialize_cris_tdep): Add declaration. * csky-linux-tdep.c (_initialize_csky_linux_tdep): Add declaration. * csky-tdep.c (_initialize_csky_tdep): Add declaration. * ctfread.c (_initialize_ctfread): Add declaration. * d-lang.c (_initialize_d_language): Add declaration. * darwin-nat-info.c (_initialize_darwin_info_commands): Add declaration. * darwin-nat.c (_initialize_darwin_nat): Add declaration. * dbxread.c (_initialize_dbxread): Add declaration. * dcache.c (_initialize_dcache): Add declaration. * disasm-selftests.c (_initialize_disasm_selftests): Add declaration. * disasm.c (_initialize_disasm): Add declaration. * dtrace-probe.c (_initialize_dtrace_probe): Add declaration. * dummy-frame.c (_initialize_dummy_frame): Add declaration. * dwarf-index-cache.c (_initialize_index_cache): Add declaration. * dwarf-index-write.c (_initialize_dwarf_index_write): Add declaration. * dwarf2-frame-tailcall.c (_initialize_tailcall_frame): Add declaration. * dwarf2-frame.c (_initialize_dwarf2_frame): Add declaration. * dwarf2expr.c (_initialize_dwarf2expr): Add declaration. * dwarf2loc.c (_initialize_dwarf2loc): Add declaration. * dwarf2read.c (_initialize_dwarf2_read): Add declaration. * elfread.c (_initialize_elfread): Add declaration. * exec.c (_initialize_exec): Add declaration. * extension.c (_initialize_extension): Add declaration. * f-lang.c (_initialize_f_language): Add declaration. * f-valprint.c (_initialize_f_valprint): Add declaration. * fbsd-nat.c (_initialize_fbsd_nat): Add declaration. * fbsd-tdep.c (_initialize_fbsd_tdep): Add declaration. * filesystem.c (_initialize_filesystem): Add declaration. * findcmd.c (_initialize_mem_search): Add declaration. * findvar.c (_initialize_findvar): Add declaration. * fork-child.c (_initialize_fork_child): Add declaration. * frame-base.c (_initialize_frame_base): Add declaration. * frame-unwind.c (_initialize_frame_unwind): Add declaration. * frame.c (_initialize_frame): Add declaration. * frv-linux-tdep.c (_initialize_frv_linux_tdep): Add declaration. * frv-tdep.c (_initialize_frv_tdep): Add declaration. * ft32-tdep.c (_initialize_ft32_tdep): Add declaration. * gcore.c (_initialize_gcore): Add declaration. * gdb-demangle.c (_initialize_gdb_demangle): Add declaration. * gdb_bfd.c (_initialize_gdb_bfd): Add declaration. * gdbarch-selftests.c (_initialize_gdbarch_selftests): Add declaration. * gdbarch.c (_initialize_gdbarch): Add declaration. * gdbtypes.c (_initialize_gdbtypes): Add declaration. * gnu-nat.c (_initialize_gnu_nat): Add declaration. * gnu-v2-abi.c (_initialize_gnu_v2_abi): Add declaration. * gnu-v3-abi.c (_initialize_gnu_v3_abi): Add declaration. * go-lang.c (_initialize_go_language): Add declaration. * go32-nat.c (_initialize_go32_nat): Add declaration. * guile/guile.c (_initialize_guile): Add declaration. * h8300-tdep.c (_initialize_h8300_tdep): Add declaration. * hppa-linux-nat.c (_initialize_hppa_linux_nat): Add declaration. * hppa-linux-tdep.c (_initialize_hppa_linux_tdep): Add declaration. * hppa-nbsd-nat.c (_initialize_hppanbsd_nat): Add declaration. * hppa-nbsd-tdep.c (_initialize_hppanbsd_tdep): Add declaration. * hppa-obsd-nat.c (_initialize_hppaobsd_nat): Add declaration. * hppa-obsd-tdep.c (_initialize_hppabsd_tdep): Add declaration. * hppa-tdep.c (_initialize_hppa_tdep): Add declaration. * i386-bsd-nat.c (_initialize_i386bsd_nat): Add declaration. * i386-cygwin-tdep.c (_initialize_i386_cygwin_tdep): Add declaration. * i386-darwin-nat.c (_initialize_i386_darwin_nat): Add declaration. * i386-darwin-tdep.c (_initialize_i386_darwin_tdep): Add declaration. * i386-dicos-tdep.c (_initialize_i386_dicos_tdep): Add declaration. * i386-fbsd-nat.c (_initialize_i386fbsd_nat): Add declaration. * i386-fbsd-tdep.c (_initialize_i386fbsd_tdep): Add declaration. * i386-gnu-nat.c (_initialize_i386gnu_nat): Add declaration. * i386-gnu-tdep.c (_initialize_i386gnu_tdep): Add declaration. * i386-go32-tdep.c (_initialize_i386_go32_tdep): Add declaration. * i386-linux-nat.c (_initialize_i386_linux_nat): Add declaration. * i386-linux-tdep.c (_initialize_i386_linux_tdep): Add declaration. * i386-nbsd-nat.c (_initialize_i386nbsd_nat): Add declaration. * i386-nbsd-tdep.c (_initialize_i386nbsd_tdep): Add declaration. * i386-nto-tdep.c (_initialize_i386nto_tdep): Add declaration. * i386-obsd-nat.c (_initialize_i386obsd_nat): Add declaration. * i386-obsd-tdep.c (_initialize_i386obsd_tdep): Add declaration. * i386-sol2-nat.c (_initialize_amd64_sol2_nat): Add declaration. * i386-sol2-tdep.c (_initialize_i386_sol2_tdep): Add declaration. * i386-tdep.c (_initialize_i386_tdep): Add declaration. * i386-windows-nat.c (_initialize_i386_windows_nat): Add declaration. * ia64-libunwind-tdep.c (_initialize_libunwind_frame): Add declaration. * ia64-linux-nat.c (_initialize_ia64_linux_nat): Add declaration. * ia64-linux-tdep.c (_initialize_ia64_linux_tdep): Add declaration. * ia64-tdep.c (_initialize_ia64_tdep): Add declaration. * ia64-vms-tdep.c (_initialize_ia64_vms_tdep): Add declaration. * infcall.c (_initialize_infcall): Add declaration. * infcmd.c (_initialize_infcmd): Add declaration. * inflow.c (_initialize_inflow): Add declaration. * infrun.c (_initialize_infrun): Add declaration. * interps.c (_initialize_interpreter): Add declaration. * iq2000-tdep.c (_initialize_iq2000_tdep): Add declaration. * jit.c (_initialize_jit): Add declaration. * language.c (_initialize_language): Add declaration. * linux-fork.c (_initialize_linux_fork): Add declaration. * linux-nat.c (_initialize_linux_nat): Add declaration. * linux-tdep.c (_initialize_linux_tdep): Add declaration. * linux-thread-db.c (_initialize_thread_db): Add declaration. * lm32-tdep.c (_initialize_lm32_tdep): Add declaration. * m2-lang.c (_initialize_m2_language): Add declaration. * m32c-tdep.c (_initialize_m32c_tdep): Add declaration. * m32r-linux-nat.c (_initialize_m32r_linux_nat): Add declaration. * m32r-linux-tdep.c (_initialize_m32r_linux_tdep): Add declaration. * m32r-tdep.c (_initialize_m32r_tdep): Add declaration. * m68hc11-tdep.c (_initialize_m68hc11_tdep): Add declaration. * m68k-bsd-nat.c (_initialize_m68kbsd_nat): Add declaration. * m68k-bsd-tdep.c (_initialize_m68kbsd_tdep): Add declaration. * m68k-linux-nat.c (_initialize_m68k_linux_nat): Add declaration. * m68k-linux-tdep.c (_initialize_m68k_linux_tdep): Add declaration. * m68k-tdep.c (_initialize_m68k_tdep): Add declaration. * machoread.c (_initialize_machoread): Add declaration. * macrocmd.c (_initialize_macrocmd): Add declaration. * macroscope.c (_initialize_macroscope): Add declaration. * maint-test-options.c (_initialize_maint_test_options): Add declaration. * maint-test-settings.c (_initialize_maint_test_settings): Add declaration. * maint.c (_initialize_maint_cmds): Add declaration. * mdebugread.c (_initialize_mdebugread): Add declaration. * memattr.c (_initialize_mem): Add declaration. * mep-tdep.c (_initialize_mep_tdep): Add declaration. * mi/mi-cmd-env.c (_initialize_mi_cmd_env): Add declaration. * mi/mi-cmds.c (_initialize_mi_cmds): Add declaration. * mi/mi-interp.c (_initialize_mi_interp): Add declaration. * mi/mi-main.c (_initialize_mi_main): Add declaration. * microblaze-linux-tdep.c (_initialize_microblaze_linux_tdep): Add declaration. * microblaze-tdep.c (_initialize_microblaze_tdep): Add declaration. * mips-fbsd-nat.c (_initialize_mips_fbsd_nat): Add declaration. * mips-fbsd-tdep.c (_initialize_mips_fbsd_tdep): Add declaration. * mips-linux-nat.c (_initialize_mips_linux_nat): Add declaration. * mips-linux-tdep.c (_initialize_mips_linux_tdep): Add declaration. * mips-nbsd-nat.c (_initialize_mipsnbsd_nat): Add declaration. * mips-nbsd-tdep.c (_initialize_mipsnbsd_tdep): Add declaration. * mips-sde-tdep.c (_initialize_mips_sde_tdep): Add declaration. * mips-tdep.c (_initialize_mips_tdep): Add declaration. * mips64-obsd-nat.c (_initialize_mips64obsd_nat): Add declaration. * mips64-obsd-tdep.c (_initialize_mips64obsd_tdep): Add declaration. * mipsread.c (_initialize_mipsread): Add declaration. * mn10300-linux-tdep.c (_initialize_mn10300_linux_tdep): Add declaration. * mn10300-tdep.c (_initialize_mn10300_tdep): Add declaration. * moxie-tdep.c (_initialize_moxie_tdep): Add declaration. * msp430-tdep.c (_initialize_msp430_tdep): Add declaration. * nds32-tdep.c (_initialize_nds32_tdep): Add declaration. * nios2-linux-tdep.c (_initialize_nios2_linux_tdep): Add declaration. * nios2-tdep.c (_initialize_nios2_tdep): Add declaration. * nto-procfs.c (_initialize_procfs): Add declaration. * objc-lang.c (_initialize_objc_language): Add declaration. * observable.c (_initialize_observer): Add declaration. * opencl-lang.c (_initialize_opencl_language): Add declaration. * or1k-linux-tdep.c (_initialize_or1k_linux_tdep): Add declaration. * or1k-tdep.c (_initialize_or1k_tdep): Add declaration. * osabi.c (_initialize_gdb_osabi): Add declaration. * osdata.c (_initialize_osdata): Add declaration. * p-valprint.c (_initialize_pascal_valprint): Add declaration. * parse.c (_initialize_parse): Add declaration. * ppc-fbsd-nat.c (_initialize_ppcfbsd_nat): Add declaration. * ppc-fbsd-tdep.c (_initialize_ppcfbsd_tdep): Add declaration. * ppc-linux-nat.c (_initialize_ppc_linux_nat): Add declaration. * ppc-linux-tdep.c (_initialize_ppc_linux_tdep): Add declaration. * ppc-nbsd-nat.c (_initialize_ppcnbsd_nat): Add declaration. * ppc-nbsd-tdep.c (_initialize_ppcnbsd_tdep): Add declaration. * ppc-obsd-nat.c (_initialize_ppcobsd_nat): Add declaration. * ppc-obsd-tdep.c (_initialize_ppcobsd_tdep): Add declaration. * printcmd.c (_initialize_printcmd): Add declaration. * probe.c (_initialize_probe): Add declaration. * proc-api.c (_initialize_proc_api): Add declaration. * proc-events.c (_initialize_proc_events): Add declaration. * proc-service.c (_initialize_proc_service): Add declaration. * procfs.c (_initialize_procfs): Add declaration. * producer.c (_initialize_producer): Add declaration. * psymtab.c (_initialize_psymtab): Add declaration. * python/python.c (_initialize_python): Add declaration. * ravenscar-thread.c (_initialize_ravenscar): Add declaration. * record-btrace.c (_initialize_record_btrace): Add declaration. * record-full.c (_initialize_record_full): Add declaration. * record.c (_initialize_record): Add declaration. * regcache-dump.c (_initialize_regcache_dump): Add declaration. * regcache.c (_initialize_regcache): Add declaration. * reggroups.c (_initialize_reggroup): Add declaration. * remote-notif.c (_initialize_notif): Add declaration. * remote-sim.c (_initialize_remote_sim): Add declaration. * remote.c (_initialize_remote): Add declaration. * reverse.c (_initialize_reverse): Add declaration. * riscv-fbsd-nat.c (_initialize_riscv_fbsd_nat): Add declaration. * riscv-fbsd-tdep.c (_initialize_riscv_fbsd_tdep): Add declaration. * riscv-linux-nat.c (_initialize_riscv_linux_nat): Add declaration. * riscv-linux-tdep.c (_initialize_riscv_linux_tdep): Add declaration. * riscv-tdep.c (_initialize_riscv_tdep): Add declaration. * rl78-tdep.c (_initialize_rl78_tdep): Add declaration. * rs6000-aix-tdep.c (_initialize_rs6000_aix_tdep): Add declaration. * rs6000-lynx178-tdep.c (_initialize_rs6000_lynx178_tdep): Add declaration. * rs6000-nat.c (_initialize_rs6000_nat): Add declaration. * rs6000-tdep.c (_initialize_rs6000_tdep): Add declaration. * run-on-main-thread.c (_initialize_run_on_main_thread): Add declaration. * rust-exp.y (_initialize_rust_exp): Add declaration. * rx-tdep.c (_initialize_rx_tdep): Add declaration. * s12z-tdep.c (_initialize_s12z_tdep): Add declaration. * s390-linux-nat.c (_initialize_s390_nat): Add declaration. * s390-linux-tdep.c (_initialize_s390_linux_tdep): Add declaration. * s390-tdep.c (_initialize_s390_tdep): Add declaration. * score-tdep.c (_initialize_score_tdep): Add declaration. * ser-go32.c (_initialize_ser_dos): Add declaration. * ser-mingw.c (_initialize_ser_windows): Add declaration. * ser-pipe.c (_initialize_ser_pipe): Add declaration. * ser-tcp.c (_initialize_ser_tcp): Add declaration. * ser-uds.c (_initialize_ser_socket): Add declaration. * ser-unix.c (_initialize_ser_hardwire): Add declaration. * serial.c (_initialize_serial): Add declaration. * sh-linux-tdep.c (_initialize_sh_linux_tdep): Add declaration. * sh-nbsd-nat.c (_initialize_shnbsd_nat): Add declaration. * sh-nbsd-tdep.c (_initialize_shnbsd_tdep): Add declaration. * sh-tdep.c (_initialize_sh_tdep): Add declaration. * skip.c (_initialize_step_skip): Add declaration. * sol-thread.c (_initialize_sol_thread): Add declaration. * solib-aix.c (_initialize_solib_aix): Add declaration. * solib-darwin.c (_initialize_darwin_solib): Add declaration. * solib-dsbt.c (_initialize_dsbt_solib): Add declaration. * solib-frv.c (_initialize_frv_solib): Add declaration. * solib-svr4.c (_initialize_svr4_solib): Add declaration. * solib-target.c (_initialize_solib_target): Add declaration. * solib.c (_initialize_solib): Add declaration. * source-cache.c (_initialize_source_cache): Add declaration. * source.c (_initialize_source): Add declaration. * sparc-linux-nat.c (_initialize_sparc_linux_nat): Add declaration. * sparc-linux-tdep.c (_initialize_sparc_linux_tdep): Add declaration. * sparc-nat.c (_initialize_sparc_nat): Add declaration. * sparc-nbsd-nat.c (_initialize_sparcnbsd_nat): Add declaration. * sparc-nbsd-tdep.c (_initialize_sparcnbsd_tdep): Add declaration. * sparc-obsd-tdep.c (_initialize_sparc32obsd_tdep): Add declaration. * sparc-sol2-tdep.c (_initialize_sparc_sol2_tdep): Add declaration. * sparc-tdep.c (_initialize_sparc_tdep): Add declaration. * sparc64-fbsd-nat.c (_initialize_sparc64fbsd_nat): Add declaration. * sparc64-fbsd-tdep.c (_initialize_sparc64fbsd_tdep): Add declaration. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Add declaration. * sparc64-linux-tdep.c (_initialize_sparc64_linux_tdep): Add declaration. * sparc64-nat.c (_initialize_sparc64_nat): Add declaration. * sparc64-nbsd-nat.c (_initialize_sparc64nbsd_nat): Add declaration. * sparc64-nbsd-tdep.c (_initialize_sparc64nbsd_tdep): Add declaration. * sparc64-obsd-nat.c (_initialize_sparc64obsd_nat): Add declaration. * sparc64-obsd-tdep.c (_initialize_sparc64obsd_tdep): Add declaration. * sparc64-sol2-tdep.c (_initialize_sparc64_sol2_tdep): Add declaration. * sparc64-tdep.c (_initialize_sparc64_adi_tdep): Add declaration. * stabsread.c (_initialize_stabsread): Add declaration. * stack.c (_initialize_stack): Add declaration. * stap-probe.c (_initialize_stap_probe): Add declaration. * std-regs.c (_initialize_frame_reg): Add declaration. * symfile-debug.c (_initialize_symfile_debug): Add declaration. * symfile-mem.c (_initialize_symfile_mem): Add declaration. * symfile.c (_initialize_symfile): Add declaration. * symmisc.c (_initialize_symmisc): Add declaration. * symtab.c (_initialize_symtab): Add declaration. * target.c (_initialize_target): Add declaration. * target-connection.c (_initialize_target_connection): Add declaration. * target-dcache.c (_initialize_target_dcache): Add declaration. * target-descriptions.c (_initialize_target_descriptions): Add declaration. * thread.c (_initialize_thread): Add declaration. * tic6x-linux-tdep.c (_initialize_tic6x_linux_tdep): Add declaration. * tic6x-tdep.c (_initialize_tic6x_tdep): Add declaration. * tilegx-linux-nat.c (_initialize_tile_linux_nat): Add declaration. * tilegx-linux-tdep.c (_initialize_tilegx_linux_tdep): Add declaration. * tilegx-tdep.c (_initialize_tilegx_tdep): Add declaration. * tracectf.c (_initialize_ctf): Add declaration. * tracefile-tfile.c (_initialize_tracefile_tfile): Add declaration. * tracefile.c (_initialize_tracefile): Add declaration. * tracepoint.c (_initialize_tracepoint): Add declaration. * tui/tui-hooks.c (_initialize_tui_hooks): Add declaration. * tui/tui-interp.c (_initialize_tui_interp): Add declaration. * tui/tui-layout.c (_initialize_tui_layout): Add declaration. * tui/tui-regs.c (_initialize_tui_regs): Add declaration. * tui/tui-stack.c (_initialize_tui_stack): Add declaration. * tui/tui-win.c (_initialize_tui_win): Add declaration. * tui/tui.c (_initialize_tui): Add declaration. * typeprint.c (_initialize_typeprint): Add declaration. * ui-style.c (_initialize_ui_style): Add declaration. * unittests/array-view-selftests.c (_initialize_array_view_selftests): Add declaration. * unittests/child-path-selftests.c (_initialize_child_path_selftests): Add declaration. * unittests/cli-utils-selftests.c (_initialize_cli_utils_selftests): Add declaration. * unittests/common-utils-selftests.c (_initialize_common_utils_selftests): Add declaration. * unittests/copy_bitwise-selftests.c (_initialize_copy_bitwise_utils_selftests): Add declaration. * unittests/environ-selftests.c (_initialize_environ_selftests): Add declaration. * unittests/filtered_iterator-selftests.c (_initialize_filtered_iterator_selftests): Add declaration. * unittests/format_pieces-selftests.c (_initialize_format_pieces_selftests): Add declaration. * unittests/function-view-selftests.c (_initialize_function_view_selftests): Add declaration. * unittests/help-doc-selftests.c (_initialize_help_doc_selftests): Add declaration. * unittests/lookup_name_info-selftests.c (_initialize_lookup_name_info_selftests): Add declaration. * unittests/main-thread-selftests.c (_initialize_main_thread_selftests): Add declaration. * unittests/memory-map-selftests.c (_initialize_memory_map_selftests): Add declaration. * unittests/memrange-selftests.c (_initialize_memrange_selftests): Add declaration. * unittests/mkdir-recursive-selftests.c (_initialize_mkdir_recursive_selftests): Add declaration. * unittests/observable-selftests.c (_initialize_observer_selftest): Add declaration. * unittests/offset-type-selftests.c (_initialize_offset_type_selftests): Add declaration. * unittests/optional-selftests.c (_initialize_optional_selftests): Add declaration. * unittests/parse-connection-spec-selftests.c (_initialize_parse_connection_spec_selftests): Add declaration. * unittests/rsp-low-selftests.c (_initialize_rsp_low_selftests): Add declaration. * unittests/scoped_fd-selftests.c (_initialize_scoped_fd_selftests): Add declaration. * unittests/scoped_mmap-selftests.c (_initialize_scoped_mmap_selftests): Add declaration. * unittests/scoped_restore-selftests.c (_initialize_scoped_restore_selftests): Add declaration. * unittests/string_view-selftests.c (_initialize_string_view_selftests): Add declaration. * unittests/style-selftests.c (_initialize_style_selftest): Add declaration. * unittests/tracepoint-selftests.c (_initialize_tracepoint_selftests): Add declaration. * unittests/tui-selftests.c (_initialize_tui_selftest): Add declaration. * unittests/unpack-selftests.c (_initialize_unpack_selftests): Add declaration. * unittests/utils-selftests.c (_initialize_utils_selftests): Add declaration. * unittests/vec-utils-selftests.c (_initialize_vec_utils_selftests): Add declaration. * unittests/xml-utils-selftests.c (_initialize_xml_utils): Add declaration. * user-regs.c (_initialize_user_regs): Add declaration. * utils.c (_initialize_utils): Add declaration. * v850-tdep.c (_initialize_v850_tdep): Add declaration. * valops.c (_initialize_valops): Add declaration. * valprint.c (_initialize_valprint): Add declaration. * value.c (_initialize_values): Add declaration. * varobj.c (_initialize_varobj): Add declaration. * vax-bsd-nat.c (_initialize_vaxbsd_nat): Add declaration. * vax-nbsd-tdep.c (_initialize_vaxnbsd_tdep): Add declaration. * vax-tdep.c (_initialize_vax_tdep): Add declaration. * windows-nat.c (_initialize_windows_nat): Add declaration. (_initialize_check_for_gdb_ini): Add declaration. (_initialize_loadable): Add declaration. * windows-tdep.c (_initialize_windows_tdep): Add declaration. * x86-bsd-nat.c (_initialize_x86_bsd_nat): Add declaration. * x86-linux-nat.c (_initialize_x86_linux_nat): Add declaration. * xcoffread.c (_initialize_xcoffread): Add declaration. * xml-support.c (_initialize_xml_support): Add declaration. * xstormy16-tdep.c (_initialize_xstormy16_tdep): Add declaration. * xtensa-linux-nat.c (_initialize_xtensa_linux_nat): Add declaration. * xtensa-linux-tdep.c (_initialize_xtensa_linux_tdep): Add declaration. * xtensa-tdep.c (_initialize_xtensa_tdep): Add declaration. Change-Id: I13eec7e0ed2b3c427377a7bdb055cf46da64def9
2020-01-13 20:01:38 +01:00
_initialize_cp_support ()
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
{
Replace most calls to help_list and cmd_show_list Currently there are many prefix commands that do nothing but call either help_list or cmd_show_list. I happened to notice that one such call, for "set print type", used the wrong command list parameter, causing incorrect output. Rather than fix this bug in isolation, I decided to eliminate this possibility by adding two new ways to add prefix commands, which simply route the call to help_list or cmd_show_list, as appropriate. This makes it impossible for a mismatch to occur. In some cases, a bit of output was removed; however, I don't think this output in general was very useful. It seemed redundant with what's already printed by help_list. A representative example is this hunk, removed from ada-lang.c: - printf_unfiltered (_(\ -"\"set ada\" must be followed by the name of a setting.\n")); This simplified the CLI style set/show commands quite a bit, and allowed the deletion of a macro. This also cleans up some unusual code in windows-tdep.c. Tested on x86-64 Fedora 30. Note that I have no way to build the go32-nat.c change. gdb/ChangeLog 2020-04-17 Tom Tromey <tromey@adacore.com> * auto-load.c (show_auto_load_cmd): Remove. (auto_load_show_cmdlist_get): Use add_show_prefix_cmd. * arc-tdep.c (_initialize_arc_tdep): Use add_show_prefix_cmd. (maintenance_print_arc_command): Remove. * tui/tui-win.c (tui_command): Remove. (tui_get_cmd_list): Use add_basic_prefix_cmd. * tui/tui-layout.c (tui_layout_command): Remove. (_initialize_tui_layout): Use add_basic_prefix_cmd. * python/python.c (user_set_python, user_show_python): Remove. (_initialize_python): Use add_basic_prefix_cmd, add_show_prefix_cmd. * guile/guile.c (set_guile_command, show_guile_command): Remove. (install_gdb_commands): Use add_basic_prefix_cmd, add_show_prefix_cmd. (info_guile_command): Remove. * dwarf2/read.c (set_dwarf_cmd, show_dwarf_cmd): Remove. (_initialize_dwarf2_read): Use add_basic_prefix_cmd, add_show_prefix_cmd. * cli/cli-style.h (class cli_style_option) <add_setshow_commands>: Remove do_set and do_show parameters. * cli/cli-style.c (set_style, show_style): Remove. (_initialize_cli_style): Use add_basic_prefix_cmd, add_show_prefix_cmd. (cli_style_option::add_setshow_commands): Remove do_set and do_show parameters. (cli_style_option::add_setshow_commands): Use add_basic_prefix_cmd, add_show_prefix_cmd. (STYLE_ADD_SETSHOW_COMMANDS): Remove macro. (set_style_name): Remove. * cli/cli-dump.c (dump_command, append_command): Remove. (srec_dump_command, ihex_dump_command, verilog_dump_command) (tekhex_dump_command, binary_dump_command) (binary_append_command): Remove. (_initialize_cli_dump): Use add_basic_prefix_cmd. * windows-tdep.c (w32_prefix_command_valid): Remove global. (init_w32_command_list): Remove; move into ... (_initialize_windows_tdep): ... here. Use add_basic_prefix_cmd. * valprint.c (set_print, show_print, set_print_raw) (show_print_raw): Remove. (_initialize_valprint): Use add_basic_prefix_cmd, add_show_prefix_cmd. * typeprint.c (set_print_type, show_print_type): Remove. (_initialize_typeprint): Use add_basic_prefix_cmd, add_show_prefix_cmd. * record.c (set_record_command, show_record_command): Remove. (_initialize_record): Use add_basic_prefix_cmd, add_show_prefix_cmd. * cli/cli-cmds.c (_initialize_cli_cmds): Use add_basic_prefix_cmd, add_show_prefix_cmd. (info_command, show_command, set_debug, show_debug): Remove. * top.h (set_history, show_history): Don't declare. * top.c (set_history, show_history): Remove. * target-descriptions.c (set_tdesc_cmd, show_tdesc_cmd) (unset_tdesc_cmd): Remove. (_initialize_target_descriptions): Use add_basic_prefix_cmd, add_show_prefix_cmd. * symtab.c (info_module_command): Remove. (_initialize_symtab): Use add_basic_prefix_cmd. * symfile.c (overlay_command): Remove. (_initialize_symfile): Use add_basic_prefix_cmd. * sparc64-tdep.c (info_adi_command): Remove. (_initialize_sparc64_adi_tdep): Use add_basic_prefix_cmd. * sh-tdep.c (show_sh_command, set_sh_command): Remove. (_initialize_sh_tdep): Use add_basic_prefix_cmd, add_show_prefix_cmd. * serial.c (serial_set_cmd, serial_show_cmd): Remove. (_initialize_serial): Use add_basic_prefix_cmd, add_show_prefix_cmd. * ser-tcp.c (set_tcp_cmd, show_tcp_cmd): Remove. (_initialize_ser_tcp): Use add_basic_prefix_cmd, add_show_prefix_cmd. * rs6000-tdep.c (set_powerpc_command, show_powerpc_command) (_initialize_rs6000_tdep): Use add_basic_prefix_cmd, add_show_prefix_cmd. * riscv-tdep.c (show_riscv_command, set_riscv_command) (show_debug_riscv_command, set_debug_riscv_command): Remove. (_initialize_riscv_tdep): Use add_basic_prefix_cmd, add_show_prefix_cmd. * remote.c (remote_command, set_remote_cmd): Remove. (_initialize_remote): Use add_basic_prefix_cmd. * record-full.c (set_record_full_command) (show_record_full_command): Remove. (_initialize_record_full): Use add_basic_prefix_cmd, add_show_prefix_cmd. * record-btrace.c (cmd_set_record_btrace) (cmd_show_record_btrace, cmd_set_record_btrace_bts) (cmd_show_record_btrace_bts, cmd_set_record_btrace_pt) (cmd_show_record_btrace_pt): Remove. (_initialize_record_btrace): Use add_basic_prefix_cmd, add_show_prefix_cmd. * ravenscar-thread.c (set_ravenscar_command) (show_ravenscar_command): Remove. (_initialize_ravenscar): Use add_basic_prefix_cmd, add_show_prefix_cmd. * mips-tdep.c (show_mips_command, set_mips_command) (_initialize_mips_tdep): Use add_basic_prefix_cmd, add_show_prefix_cmd. * maint.c (maintenance_command, maintenance_info_command) (maintenance_check_command, maintenance_print_command) (maintenance_set_cmd, maintenance_show_cmd): Remove. (_initialize_maint_cmds): Use add_basic_prefix_cmd, add_show_prefix_cmd. (show_per_command_cmd): Remove. * maint-test-settings.c (maintenance_set_test_settings_cmd): Remove. (maintenance_show_test_settings_cmd): Remove. (_initialize_maint_test_settings): Use add_basic_prefix_cmd, add_show_prefix_cmd. * maint-test-options.c (maintenance_test_options_command): Remove. (_initialize_maint_test_options): Use add_basic_prefix_cmd. * macrocmd.c (macro_command): Remove (_initialize_macrocmd): Use add_basic_prefix_cmd. * language.c (set_check, show_check): Remove. (_initialize_language): Use add_basic_prefix_cmd, add_show_prefix_cmd. * infcmd.c (unset_command): Remove. (_initialize_infcmd): Use add_basic_prefix_cmd. * i386-tdep.c (set_mpx_cmd, show_mpx_cmd): Remove. (_initialize_i386_tdep): Use add_basic_prefix_cmd, add_show_prefix_cmd. * go32-nat.c (go32_info_dos_command): Remove. (_initialize_go32_nat): Use add_basic_prefix_cmd. * cli/cli-decode.c (do_prefix_cmd, add_basic_prefix_cmd) (do_show_prefix_cmd, add_show_prefix_cmd): New functions. * frame.c (set_backtrace_cmd, show_backtrace_cmd): Remove. (_initialize_frame): Use add_basic_prefix_cmd, add_show_prefix_cmd. * dcache.c (set_dcache_command, show_dcache_command): Remove. (_initialize_dcache): Use add_basic_prefix_cmd, add_show_prefix_cmd. * cp-support.c (maint_cplus_command): Remove. (_initialize_cp_support): Use add_basic_prefix_cmd. * btrace.c (maint_btrace_cmd, maint_btrace_set_cmd) (maint_btrace_show_cmd, maint_btrace_pt_set_cmd) (maint_btrace_pt_show_cmd, _initialize_btrace): Use add_basic_prefix_cmd, add_show_prefix_cmd. * breakpoint.c (save_command): Remove. (_initialize_breakpoint): Use add_basic_prefix_cmd. * arm-tdep.c (set_arm_command, show_arm_command): Remove. (_initialize_arm_tdep): Use add_basic_prefix_cmd, add_show_prefix_cmd. * ada-lang.c (maint_set_ada_cmd, maint_show_ada_cmd) (set_ada_command, show_ada_command): Remove. (_initialize_ada_language): Use add_basic_prefix_cmd, add_show_prefix_cmd. * command.h (add_basic_prefix_cmd, add_show_prefix_cmd): Declare. gdb/testsuite/ChangeLog 2020-04-17 Tom Tromey <tromey@adacore.com> * gdb.cp/maint.exp (test_help): Simplify multiple_help_body. Update tests. * gdb.btrace/cpu.exp: Update tests. * gdb.base/maint.exp: Update tests. * gdb.base/default.exp: Update tests. * gdb.base/completion.exp: Update tests.
2020-04-17 15:27:14 +02:00
add_basic_prefix_cmd ("cplus", class_maintenance,
_("C++ maintenance commands."),
&maint_cplus_cmd_list,
"maintenance cplus ",
0, &maintenancelist);
add_alias_cmd ("cp", "cplus",
class_maintenance, 1,
&maintenancelist);
add_cmd ("first_component",
class_maintenance,
first_component_command,
_("Print the first class/namespace component of NAME."),
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
&maint_cplus_cmd_list);
add_info ("vtbl", info_vtbl_command,
_("Show the virtual function table for a C++ object.\n\
Usage: info vtbl EXPRESSION\n\
Evaluate EXPRESSION and display the virtual function table for the\n\
resulting object."));
#ifdef HAVE_WORKING_FORK
add_setshow_boolean_cmd ("catch-demangler-crashes", class_maintenance,
&catch_demangler_crashes, _("\
Set whether to attempt to catch demangler crashes."), _("\
Show whether to attempt to catch demangler crashes."), _("\
If enabled GDB will attempt to catch demangler crashes and\n\
display the offending symbol."),
NULL,
NULL,
&maintenance_set_cmdlist,
&maintenance_show_cmdlist);
gdb_demangle_attempt_core_dump = can_dump_core (LIMIT_CUR);
#endif
lookup_name_info::make_ignore_params A few places in the completion code look for a "(" to find a function's parameter list, in order to strip it, because psymtabs (and gdb index) don't include parameter info in the symbol names. See compare_symbol_name and default_collect_symbol_completion_matches_break_on. This is too naive. Consider: ns_overload2_test::([TAB] We'd want to complete that to: ns_overload2_test::(anonymous namespace)::struct_overload2_test Or: b (anonymous namespace)::[TAB] That currently completes to: b (anonymous namespace) Which is obviously broken. This patch makes that work. Also, the current compare_symbol_name hack means that while this works: "b function([TAB]" -> "b function()" This does not: "b function ([TAB]" This patch fixes that. Whitespace "ignoring" now Just Works, i.e., assuming a symbol named "function(int, long)", this: b function ( int , lon[TAB] completes to: b function ( int , long) To address all of this, this patch builds on top of the rest of the series, and pushes the responsibility of stripping parameters from a lookup name to the new lookup_name_info object, where we can apply per-language rules. Also note that we now only make a version of the lookup name with parameters stripped out where it's actually required to do that, in the psymtab and GDB index code. For C++, the right way to strip parameters is with "cp_remove_params", which uses a real parser (cp-name-parser.y) to split the name into a component tree and then discards parameters. The trouble for completion is that in that case we have an incomplete name, like "foo::func(int" and thus cp_remove_params throws an error. This patch sorts that by adding a cp_remove_params_if_any variant of cp_remove_params that tries removing characters from the end of the string until cp_remove_params works. So cp_remove_params_if_any behaves like this: With a complete name: "foo::func(int)" => foo::func(int) # cp_remove_params_1 succeeds the first time. With an incomplete name: "foo::func(int" => NULL # cp_remove_params fails the first time. "foo::func(in" => NULL # and again... "foo::func(i" => NULL # and again... "foo::func(" => NULL # and again... "foo::func" => "foo::func" # success! Note that even if this approach removes significant rightmost characters, it's still OK, because this parameter stripping is only necessary for psymtabs and gdb index, where we're determining whether to expand a symbol table. Say cp_remove_params_if_any returned "foo::" above for "foo::func(int". That'd cause us to expand more symtabs than ideal (because we'd expand all symtabs with symbols that start with "foo::", not just "foo::func"), but then when we actually look for completion matches, we'd still use the original lookup name, with parameter information ["foo::func(int"], and thus we'll return no false positive to the user. Whether the stripping works as intended and doesn't strip too much is thus covered by a unit test instead of a testsuite test. The "if_any" part of the name refers to the fact that while cp_remove_params returns NULL if the input name has no parameters in the first place, like: "foo::func" => NULL # cp_remove_params cp_remove_params_if_any still returns the function name: "foo::func" => "foo::func" # cp_remove_params_if_any gdb/ChangeLog: 2017-11-08 Pedro Alves <palves@redhat.com> * Makefile.in (SUBDIR_UNITTESTS_SRCS): Add unittests/lookup_name_info-selftests.c. (SUBDIR_UNITTESTS_OBS): Add lookup_name_info-selftests.o. * cp-support.c: Include "selftest.h". (cp_remove_params_1): Rename from cp_remove_params. Add 'require_param' parameter, and handle it. (cp_remove_params): Reimplement. (cp_remove_params_if_any): New. (selftests::quote): New. (selftests::check_remove_params): New. (selftests::test_cp_remove_params): New. (_initialize_cp_support): Install selftests::test_cp_remove_params. * cp-support.h (cp_remove_params_if_any): Declare. * dwarf2read.c :Include "selftest.h". (dw2_expand_symtabs_matching_symbol): Use lookup_name_info::make_ignore_params. (selftests::dw2_expand_symtabs_matching::mock_mapped_index) (selftests::dw2_expand_symtabs_matching::string_or_null) (selftests::dw2_expand_symtabs_matching::check_match) (selftests::dw2_expand_symtabs_matching::test_symbols) (selftests::dw2_expand_symtabs_matching::run_test): New. (_initialize_dwarf2_read): Register selftests::dw2_expand_symtabs_matching::run_test. * psymtab.c (psym_expand_symtabs_matching): Use lookup_name_info::make_ignore_params. * symtab.c (demangle_for_lookup_info::demangle_for_lookup_info): If the lookup name wants to ignore parameters, strip them. (compare_symbol_name): Remove sym_text/sym_text_len parameters and code handling '('. (completion_list_add_name): Don't pass down sym_text/sym_text_len. (default_collect_symbol_completion_matches_break_on): Don't try to strip parameters. * symtab.h (lookup_name_info::lookup_name_info): Add 'ignore_parameters' parameter. (lookup_name_info::ignore_parameters) (lookup_name_info::make_ignore_params): New methods. (lookup_name_info::m_ignore_parameters): New field. * unittests/lookup_name_info-selftests.c: New file.
2017-11-08 15:49:10 +01:00
#if GDB_SELF_TEST
Make strcmp_iw NOT ignore whitespace in the middle of tokens currently "b func tion" manages to set a breakpoint at "function" ! All these years I had never noticed this, but now that the linespec completer actually works, this easily happens by accident, with: "b func t<tab>" expecting to get "thread", but getting instead: "b func tion" ... Also, this: "b rettypefunc<int>" manages to set a breakpoint on "rettype func<int>()". These things happen due to strcmp_iw "magic". Fix it by teaching strcmp_iw about when can it skip whitespace. This required handling user-defined operators, and scope operators, complicating the code a bit, unfortunately. I added unit tests for all the corner cases I stumbled on, as I was developing this, and then in the end wrote a testsuite testcase covering many of the same things and more (to be added later). gdb/ChangeLog: 2017-11-24 Pedro Alves <palves@redhat.com> * cp-support.c (cp_symbol_name_matches_1): New, factored out from cp_fq_symbol_name_matches. Pass language_cplus to strncmp_with_mode. (cp_fq_symbol_name_matches): Call cp_symbol_name_matches_1. (selftests::test_cp_symbol_name_cmp): New. (_initialize_cp_support): Register "cp_symbol_name_matches" selftests. * language.c (default_symbol_name_matcher): Pass language_minimal to strncmp_iw_with_mode. * utils.c: Include "cp-support.h" and <algorithm>. (valid_identifier_name_char, cp_skip_operator_token, skip_ws) (cp_is_operator): New functions. (strncmp_iw_with_mode): Use them. Add language parameter. Don't skip whitespace in the symbol name when the lookup name doesn't have spaces, and vice versa. (strncmp_iw, strcmp_iw): Pass language to strncmp_iw_with_mode. * utils.h (strncmp_iw_with_mode): Add language parameter.
2017-11-25 00:30:04 +01:00
selftests::register_test ("cp_symbol_name_matches",
selftests::test_cp_symbol_name_matches);
lookup_name_info::make_ignore_params A few places in the completion code look for a "(" to find a function's parameter list, in order to strip it, because psymtabs (and gdb index) don't include parameter info in the symbol names. See compare_symbol_name and default_collect_symbol_completion_matches_break_on. This is too naive. Consider: ns_overload2_test::([TAB] We'd want to complete that to: ns_overload2_test::(anonymous namespace)::struct_overload2_test Or: b (anonymous namespace)::[TAB] That currently completes to: b (anonymous namespace) Which is obviously broken. This patch makes that work. Also, the current compare_symbol_name hack means that while this works: "b function([TAB]" -> "b function()" This does not: "b function ([TAB]" This patch fixes that. Whitespace "ignoring" now Just Works, i.e., assuming a symbol named "function(int, long)", this: b function ( int , lon[TAB] completes to: b function ( int , long) To address all of this, this patch builds on top of the rest of the series, and pushes the responsibility of stripping parameters from a lookup name to the new lookup_name_info object, where we can apply per-language rules. Also note that we now only make a version of the lookup name with parameters stripped out where it's actually required to do that, in the psymtab and GDB index code. For C++, the right way to strip parameters is with "cp_remove_params", which uses a real parser (cp-name-parser.y) to split the name into a component tree and then discards parameters. The trouble for completion is that in that case we have an incomplete name, like "foo::func(int" and thus cp_remove_params throws an error. This patch sorts that by adding a cp_remove_params_if_any variant of cp_remove_params that tries removing characters from the end of the string until cp_remove_params works. So cp_remove_params_if_any behaves like this: With a complete name: "foo::func(int)" => foo::func(int) # cp_remove_params_1 succeeds the first time. With an incomplete name: "foo::func(int" => NULL # cp_remove_params fails the first time. "foo::func(in" => NULL # and again... "foo::func(i" => NULL # and again... "foo::func(" => NULL # and again... "foo::func" => "foo::func" # success! Note that even if this approach removes significant rightmost characters, it's still OK, because this parameter stripping is only necessary for psymtabs and gdb index, where we're determining whether to expand a symbol table. Say cp_remove_params_if_any returned "foo::" above for "foo::func(int". That'd cause us to expand more symtabs than ideal (because we'd expand all symtabs with symbols that start with "foo::", not just "foo::func"), but then when we actually look for completion matches, we'd still use the original lookup name, with parameter information ["foo::func(int"], and thus we'll return no false positive to the user. Whether the stripping works as intended and doesn't strip too much is thus covered by a unit test instead of a testsuite test. The "if_any" part of the name refers to the fact that while cp_remove_params returns NULL if the input name has no parameters in the first place, like: "foo::func" => NULL # cp_remove_params cp_remove_params_if_any still returns the function name: "foo::func" => "foo::func" # cp_remove_params_if_any gdb/ChangeLog: 2017-11-08 Pedro Alves <palves@redhat.com> * Makefile.in (SUBDIR_UNITTESTS_SRCS): Add unittests/lookup_name_info-selftests.c. (SUBDIR_UNITTESTS_OBS): Add lookup_name_info-selftests.o. * cp-support.c: Include "selftest.h". (cp_remove_params_1): Rename from cp_remove_params. Add 'require_param' parameter, and handle it. (cp_remove_params): Reimplement. (cp_remove_params_if_any): New. (selftests::quote): New. (selftests::check_remove_params): New. (selftests::test_cp_remove_params): New. (_initialize_cp_support): Install selftests::test_cp_remove_params. * cp-support.h (cp_remove_params_if_any): Declare. * dwarf2read.c :Include "selftest.h". (dw2_expand_symtabs_matching_symbol): Use lookup_name_info::make_ignore_params. (selftests::dw2_expand_symtabs_matching::mock_mapped_index) (selftests::dw2_expand_symtabs_matching::string_or_null) (selftests::dw2_expand_symtabs_matching::check_match) (selftests::dw2_expand_symtabs_matching::test_symbols) (selftests::dw2_expand_symtabs_matching::run_test): New. (_initialize_dwarf2_read): Register selftests::dw2_expand_symtabs_matching::run_test. * psymtab.c (psym_expand_symtabs_matching): Use lookup_name_info::make_ignore_params. * symtab.c (demangle_for_lookup_info::demangle_for_lookup_info): If the lookup name wants to ignore parameters, strip them. (compare_symbol_name): Remove sym_text/sym_text_len parameters and code handling '('. (completion_list_add_name): Don't pass down sym_text/sym_text_len. (default_collect_symbol_completion_matches_break_on): Don't try to strip parameters. * symtab.h (lookup_name_info::lookup_name_info): Add 'ignore_parameters' parameter. (lookup_name_info::ignore_parameters) (lookup_name_info::make_ignore_params): New methods. (lookup_name_info::m_ignore_parameters): New field. * unittests/lookup_name_info-selftests.c: New file.
2017-11-08 15:49:10 +01:00
selftests::register_test ("cp_remove_params",
selftests::test_cp_remove_params);
#endif
2003-04-15 David Carlton <carlton@math.stanford.edu> * Makefile.in (SFILES): Add cp-namespace.c. (COMMON_OBS): Add cp-namespace.o. (block.o): Depend on gdb_obstack_h and cp_support_h. (buildsym.o): Depend on cp_support_h. (cp-namespace.o): New. (cp-support.o): Depend on gdb_string_h, demangle_h, gdb_assert_h, gdb_obstack_h, symtab_h, symfile_h, and gdbcmd_h. (dwarf2read.o): Depend on cp_support_h. * jv-lang.c (get_java_class_symtab): Set BLOCK_NAMESPACE. * dwarf2read.c (process_die): Set processing_has_namespace_info, processing_current_namespace. (read_namespace): Update processing_current_namespace; check for anonymous namespaces. (dwarf2_name): New function. (dwarf2_extension): Ditto. * cp-support.h: Update copyright, contributors. Add inclusion guards. Add opaque declaration for structs obstack, block, symbol. (struct using_direct): New struct. Add declarations for cp_find_first_component, cp_entire_prefix_len, processing_has_namespace_info, processing_current_namespace, cp_is_anonymous, cp_add_using_directive, cp_initialize_namespace, cp_finalize_namespace, cp_set_block_scope, cp_scan_for_anonymous_namespaces. * cp-namespace.c: New file. * cp-support.c: Update copyright. Include ctype.h, gdb_assert.h, gdbcmd.h. New variable maint_cplus_cmd_list. (cp_find_first_component): New function. (cp_entire_prefix_len, maint_cplus_command) (first_component_command, _initialize_cp_support): Ditto. * buildsym.c: Include cp-support.h. New variable using_list. (add_symbol_to_list): Check for anonymous namespaces. (finish_block): Set block's scope. (start_symtab): Initialize C++ namespace support. (end_symtab): Finalize C++ namespace support. * block.h: Add opaque declarations for structs block_namespace_info, using_direct, and obstack. Add declarations for block_set_scope and block_set_using. (struct block): Add 'language_specific' member. (BLOCK_NAMESPACE): New macro. * block.c: Include gdb_obstack.h and cp-support.h. (struct block_namespace_info): New struct. (block_set_scope): New function. (block_set_using, block_initialize_namespace): Ditto. 2003-04-15 David Carlton <carlton@math.stanford.edu> * gdb.c++/maint.exp: New file.
2003-04-16 01:07:11 +02:00
}