binutils-gdb/gdbsupport/pathstuff.h

99 lines
3.4 KiB
C
Raw Normal View History

Create new common/pathstuff.[ch] This commit moves the path manipulation routines found on utils.c to a new common/pathstuff.c, and updates the Makefile.in's accordingly. The routines moved are "gdb_realpath", "gdb_realpath_keepfile" and "gdb_abspath". This will be needed because gdbserver will have to call "gdb_abspath" on my next patch, which implements a way to expand the path of the inferior provided by the user in order to allow specifying just the binary name when starting gdbserver, like: $ gdbserver :1234 a.out With the recent addition of the startup-with-shell feature on gdbserver, this scenario doesn't work anymore if the user doesn't have the current directory listed in the PATH variable. I had to do a minor adjustment on "gdb_abspath" because we don't have access to "tilde_expand" on gdbserver, so now the function is using "gdb_tilde_expand" instead. Otherwise, the code is the same. Regression tested on the BuildBot, without regressions. gdb/ChangeLog: 2018-02-28 Sergio Durigan Junior <sergiodj@redhat.com> * Makefile.in (COMMON_SFILES): Add "common/pathstuff.c". (HFILES_NO_SRCDIR): Add "common/pathstuff.h". * auto-load.c: Include "common/pathstuff.h". * common/common-def.h (current_directory): Move here. * common/gdb_tilde_expand.c (gdb_tilde_expand_up): New function. * common/gdb_tilde_expand.h (gdb_tilde_expand_up): New prototype. * common/pathstuff.c: New file. * common/pathstuff.h: New file. * compile/compile.c: Include "common/pathstuff.h". * defs.h (current_directory): Move to "common/common-defs.h". * dwarf2read.c: Include "common/pathstuff.h". * exec.c: Likewise. * guile/scm-safe-call.c: Likewise. * linux-thread-db.c: Likewise. * main.c: Likewise. * nto-tdep.c: Likewise. * objfiles.c: Likewise. * source.c: Likewise. * symtab.c: Likewise. * utils.c: Include "common/pathstuff.h". (gdb_realpath): Move to "common/pathstuff.c". (gdb_realpath_keepfile): Likewise. (gdb_abspath): Likewise. * utils.h (gdb_realpath): Move to "common/pathstuff.h". (gdb_realpath_keepfile): Likewise. (gdb_abspath): Likewise. gdb/gdbserver/ChangeLog: 2018-02-28 Sergio Durigan Junior <sergiodj@redhat.com> * Makefile.in (SFILES): Add "$(srcdir)/common/pathstuff.c". (OBJS): Add "pathstuff.o". * server.c (current_directory): New global variable. (captured_main): Initialize "current_directory".
2018-02-10 00:44:59 +01:00
/* Path manipulation routines for GDB and gdbserver.
Copyright (C) 1986-2020 Free Software Foundation, Inc.
Create new common/pathstuff.[ch] This commit moves the path manipulation routines found on utils.c to a new common/pathstuff.c, and updates the Makefile.in's accordingly. The routines moved are "gdb_realpath", "gdb_realpath_keepfile" and "gdb_abspath". This will be needed because gdbserver will have to call "gdb_abspath" on my next patch, which implements a way to expand the path of the inferior provided by the user in order to allow specifying just the binary name when starting gdbserver, like: $ gdbserver :1234 a.out With the recent addition of the startup-with-shell feature on gdbserver, this scenario doesn't work anymore if the user doesn't have the current directory listed in the PATH variable. I had to do a minor adjustment on "gdb_abspath" because we don't have access to "tilde_expand" on gdbserver, so now the function is using "gdb_tilde_expand" instead. Otherwise, the code is the same. Regression tested on the BuildBot, without regressions. gdb/ChangeLog: 2018-02-28 Sergio Durigan Junior <sergiodj@redhat.com> * Makefile.in (COMMON_SFILES): Add "common/pathstuff.c". (HFILES_NO_SRCDIR): Add "common/pathstuff.h". * auto-load.c: Include "common/pathstuff.h". * common/common-def.h (current_directory): Move here. * common/gdb_tilde_expand.c (gdb_tilde_expand_up): New function. * common/gdb_tilde_expand.h (gdb_tilde_expand_up): New prototype. * common/pathstuff.c: New file. * common/pathstuff.h: New file. * compile/compile.c: Include "common/pathstuff.h". * defs.h (current_directory): Move to "common/common-defs.h". * dwarf2read.c: Include "common/pathstuff.h". * exec.c: Likewise. * guile/scm-safe-call.c: Likewise. * linux-thread-db.c: Likewise. * main.c: Likewise. * nto-tdep.c: Likewise. * objfiles.c: Likewise. * source.c: Likewise. * symtab.c: Likewise. * utils.c: Include "common/pathstuff.h". (gdb_realpath): Move to "common/pathstuff.c". (gdb_realpath_keepfile): Likewise. (gdb_abspath): Likewise. * utils.h (gdb_realpath): Move to "common/pathstuff.h". (gdb_realpath_keepfile): Likewise. (gdb_abspath): Likewise. gdb/gdbserver/ChangeLog: 2018-02-28 Sergio Durigan Junior <sergiodj@redhat.com> * Makefile.in (SFILES): Add "$(srcdir)/common/pathstuff.c". (OBJS): Add "pathstuff.o". * server.c (current_directory): New global variable. (captured_main): Initialize "current_directory".
2018-02-10 00:44:59 +01:00
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/>. */
Normalize include guards in gdb While working on my other scripts to deal with gdb headers, I noticed that some files were missing include guards. I wrote a script to add the missing ones, but found that using the obvious names for the guards ran into clashes -- for example, gdb/nat/linux-nat.h used "LINUX_NAT_H", but this was also the script's choice for gdb/linux-nat.h. So, I changed the script to normalize all include guards in gdb. This patch is the result. As usual the script is available here: https://github.com/tromey/gdb-refactoring-scripts Tested by rebuilding; I also ran it through "Fedora-x86_64-m64" on the buildbot. gdb/ChangeLog 2019-02-07 Tom Tromey <tom@tromey.com> * yy-remap.h: Add include guard. * xtensa-tdep.h: Add include guard. * xcoffread.h: Rename include guard. * varobj-iter.h: Add include guard. * tui/tui.h: Rename include guard. * tui/tui-winsource.h: Rename include guard. * tui/tui-wingeneral.h: Rename include guard. * tui/tui-windata.h: Rename include guard. * tui/tui-win.h: Rename include guard. * tui/tui-stack.h: Rename include guard. * tui/tui-source.h: Rename include guard. * tui/tui-regs.h: Rename include guard. * tui/tui-out.h: Rename include guard. * tui/tui-layout.h: Rename include guard. * tui/tui-io.h: Rename include guard. * tui/tui-hooks.h: Rename include guard. * tui/tui-file.h: Rename include guard. * tui/tui-disasm.h: Rename include guard. * tui/tui-data.h: Rename include guard. * tui/tui-command.h: Rename include guard. * tic6x-tdep.h: Add include guard. * target/waitstatus.h: Rename include guard. * target/wait.h: Rename include guard. * target/target.h: Rename include guard. * target/resume.h: Rename include guard. * target-float.h: Rename include guard. * stabsread.h: Add include guard. * rs6000-tdep.h: Add include guard. * riscv-fbsd-tdep.h: Add include guard. * regformats/regdef.h: Rename include guard. * record.h: Rename include guard. * python/python.h: Rename include guard. * python/python-internal.h: Rename include guard. * python/py-stopevent.h: Rename include guard. * python/py-ref.h: Rename include guard. * python/py-record.h: Rename include guard. * python/py-record-full.h: Rename include guard. * python/py-record-btrace.h: Rename include guard. * python/py-instruction.h: Rename include guard. * python/py-events.h: Rename include guard. * python/py-event.h: Rename include guard. * procfs.h: Add include guard. * proc-utils.h: Add include guard. * p-lang.h: Add include guard. * or1k-tdep.h: Rename include guard. * observable.h: Rename include guard. * nto-tdep.h: Rename include guard. * nat/x86-linux.h: Rename include guard. * nat/x86-linux-dregs.h: Rename include guard. * nat/x86-gcc-cpuid.h: Add include guard. * nat/x86-dregs.h: Rename include guard. * nat/x86-cpuid.h: Rename include guard. * nat/ppc-linux.h: Rename include guard. * nat/mips-linux-watch.h: Rename include guard. * nat/linux-waitpid.h: Rename include guard. * nat/linux-ptrace.h: Rename include guard. * nat/linux-procfs.h: Rename include guard. * nat/linux-osdata.h: Rename include guard. * nat/linux-nat.h: Rename include guard. * nat/linux-namespaces.h: Rename include guard. * nat/linux-btrace.h: Rename include guard. * nat/glibc_thread_db.h: Rename include guard. * nat/gdb_thread_db.h: Rename include guard. * nat/gdb_ptrace.h: Rename include guard. * nat/fork-inferior.h: Rename include guard. * nat/amd64-linux-siginfo.h: Rename include guard. * nat/aarch64-sve-linux-sigcontext.h: Rename include guard. * nat/aarch64-sve-linux-ptrace.h: Rename include guard. * nat/aarch64-linux.h: Rename include guard. * nat/aarch64-linux-hw-point.h: Rename include guard. * mn10300-tdep.h: Add include guard. * mips-linux-tdep.h: Add include guard. * mi/mi-parse.h: Rename include guard. * mi/mi-out.h: Rename include guard. * mi/mi-main.h: Rename include guard. * mi/mi-interp.h: Rename include guard. * mi/mi-getopt.h: Rename include guard. * mi/mi-console.h: Rename include guard. * mi/mi-common.h: Rename include guard. * mi/mi-cmds.h: Rename include guard. * mi/mi-cmd-break.h: Rename include guard. * m2-lang.h: Add include guard. * location.h: Rename include guard. * linux-record.h: Rename include guard. * linux-nat.h: Add include guard. * linux-fork.h: Add include guard. * i386-darwin-tdep.h: Rename include guard. * hppa-linux-offsets.h: Add include guard. * guile/guile.h: Rename include guard. * guile/guile-internal.h: Rename include guard. * gnu-nat.h: Rename include guard. * gdb-stabs.h: Rename include guard. * frv-tdep.h: Add include guard. * f-lang.h: Add include guard. * event-loop.h: Add include guard. * darwin-nat.h: Rename include guard. * cp-abi.h: Rename include guard. * config/sparc/nm-sol2.h: Rename include guard. * config/nm-nto.h: Rename include guard. * config/nm-linux.h: Add include guard. * config/i386/nm-i386gnu.h: Rename include guard. * config/djgpp/nl_types.h: Rename include guard. * config/djgpp/langinfo.h: Rename include guard. * compile/gcc-cp-plugin.h: Add include guard. * compile/gcc-c-plugin.h: Add include guard. * compile/compile.h: Rename include guard. * compile/compile-object-run.h: Rename include guard. * compile/compile-object-load.h: Rename include guard. * compile/compile-internal.h: Rename include guard. * compile/compile-cplus.h: Rename include guard. * compile/compile-c.h: Rename include guard. * common/xml-utils.h: Rename include guard. * common/x86-xstate.h: Rename include guard. * common/version.h: Rename include guard. * common/vec.h: Rename include guard. * common/tdesc.h: Rename include guard. * common/selftest.h: Rename include guard. * common/scoped_restore.h: Rename include guard. * common/scoped_mmap.h: Rename include guard. * common/scoped_fd.h: Rename include guard. * common/safe-iterator.h: Rename include guard. * common/run-time-clock.h: Rename include guard. * common/refcounted-object.h: Rename include guard. * common/queue.h: Rename include guard. * common/ptid.h: Rename include guard. * common/print-utils.h: Rename include guard. * common/preprocessor.h: Rename include guard. * common/pathstuff.h: Rename include guard. * common/observable.h: Rename include guard. * common/netstuff.h: Rename include guard. * common/job-control.h: Rename include guard. * common/host-defs.h: Rename include guard. * common/gdb_wait.h: Rename include guard. * common/gdb_vecs.h: Rename include guard. * common/gdb_unlinker.h: Rename include guard. * common/gdb_unique_ptr.h: Rename include guard. * common/gdb_tilde_expand.h: Rename include guard. * common/gdb_sys_time.h: Rename include guard. * common/gdb_string_view.h: Rename include guard. * common/gdb_splay_tree.h: Rename include guard. * common/gdb_setjmp.h: Rename include guard. * common/gdb_ref_ptr.h: Rename include guard. * common/gdb_optional.h: Rename include guard. * common/gdb_locale.h: Rename include guard. * common/gdb_assert.h: Rename include guard. * common/filtered-iterator.h: Rename include guard. * common/filestuff.h: Rename include guard. * common/fileio.h: Rename include guard. * common/environ.h: Rename include guard. * common/common-utils.h: Rename include guard. * common/common-types.h: Rename include guard. * common/common-regcache.h: Rename include guard. * common/common-inferior.h: Rename include guard. * common/common-gdbthread.h: Rename include guard. * common/common-exceptions.h: Rename include guard. * common/common-defs.h: Rename include guard. * common/common-debug.h: Rename include guard. * common/cleanups.h: Rename include guard. * common/buffer.h: Rename include guard. * common/btrace-common.h: Rename include guard. * common/break-common.h: Rename include guard. * cli/cli-utils.h: Rename include guard. * cli/cli-style.h: Rename include guard. * cli/cli-setshow.h: Rename include guard. * cli/cli-script.h: Rename include guard. * cli/cli-interp.h: Rename include guard. * cli/cli-decode.h: Rename include guard. * cli/cli-cmds.h: Rename include guard. * charset-list.h: Add include guard. * buildsym-legacy.h: Rename include guard. * bfin-tdep.h: Add include guard. * ax.h: Rename include guard. * arm-linux-tdep.h: Add include guard. * arm-fbsd-tdep.h: Add include guard. * arch/xtensa.h: Rename include guard. * arch/tic6x.h: Add include guard. * arch/i386.h: Add include guard. * arch/arm.h: Rename include guard. * arch/arm-linux.h: Rename include guard. * arch/arm-get-next-pcs.h: Rename include guard. * arch/amd64.h: Add include guard. * arch/aarch64-insn.h: Rename include guard. * arch-utils.h: Rename include guard. * annotate.h: Add include guard. * amd64-darwin-tdep.h: Rename include guard. * aarch64-linux-tdep.h: Add include guard. * aarch64-fbsd-tdep.h: Add include guard. * aarch32-linux-nat.h: Add include guard. gdb/gdbserver/ChangeLog 2019-02-07 Tom Tromey <tom@tromey.com> * x86-tdesc.h: Rename include guard. * x86-low.h: Add include guard. * wincecompat.h: Rename include guard. * win32-low.h: Add include guard. * utils.h: Rename include guard. * tracepoint.h: Rename include guard. * tdesc.h: Rename include guard. * target.h: Rename include guard. * server.h: Rename include guard. * remote-utils.h: Rename include guard. * regcache.h: Rename include guard. * nto-low.h: Rename include guard. * notif.h: Add include guard. * mem-break.h: Rename include guard. * lynx-low.h: Add include guard. * linux-x86-tdesc.h: Add include guard. * linux-s390-tdesc.h: Add include guard. * linux-ppc-tdesc-init.h: Add include guard. * linux-low.h: Add include guard. * linux-aarch64-tdesc.h: Add include guard. * linux-aarch32-low.h: Add include guard. * inferiors.h: Rename include guard. * i387-fp.h: Rename include guard. * hostio.h: Rename include guard. * gdbthread.h: Rename include guard. * gdb_proc_service.h: Rename include guard. * event-loop.h: Rename include guard. * dll.h: Rename include guard. * debug.h: Rename include guard. * ax.h: Rename include guard.
2019-01-27 20:51:36 +01:00
#ifndef COMMON_PATHSTUFF_H
#define COMMON_PATHSTUFF_H
Create new common/pathstuff.[ch] This commit moves the path manipulation routines found on utils.c to a new common/pathstuff.c, and updates the Makefile.in's accordingly. The routines moved are "gdb_realpath", "gdb_realpath_keepfile" and "gdb_abspath". This will be needed because gdbserver will have to call "gdb_abspath" on my next patch, which implements a way to expand the path of the inferior provided by the user in order to allow specifying just the binary name when starting gdbserver, like: $ gdbserver :1234 a.out With the recent addition of the startup-with-shell feature on gdbserver, this scenario doesn't work anymore if the user doesn't have the current directory listed in the PATH variable. I had to do a minor adjustment on "gdb_abspath" because we don't have access to "tilde_expand" on gdbserver, so now the function is using "gdb_tilde_expand" instead. Otherwise, the code is the same. Regression tested on the BuildBot, without regressions. gdb/ChangeLog: 2018-02-28 Sergio Durigan Junior <sergiodj@redhat.com> * Makefile.in (COMMON_SFILES): Add "common/pathstuff.c". (HFILES_NO_SRCDIR): Add "common/pathstuff.h". * auto-load.c: Include "common/pathstuff.h". * common/common-def.h (current_directory): Move here. * common/gdb_tilde_expand.c (gdb_tilde_expand_up): New function. * common/gdb_tilde_expand.h (gdb_tilde_expand_up): New prototype. * common/pathstuff.c: New file. * common/pathstuff.h: New file. * compile/compile.c: Include "common/pathstuff.h". * defs.h (current_directory): Move to "common/common-defs.h". * dwarf2read.c: Include "common/pathstuff.h". * exec.c: Likewise. * guile/scm-safe-call.c: Likewise. * linux-thread-db.c: Likewise. * main.c: Likewise. * nto-tdep.c: Likewise. * objfiles.c: Likewise. * source.c: Likewise. * symtab.c: Likewise. * utils.c: Include "common/pathstuff.h". (gdb_realpath): Move to "common/pathstuff.c". (gdb_realpath_keepfile): Likewise. (gdb_abspath): Likewise. * utils.h (gdb_realpath): Move to "common/pathstuff.h". (gdb_realpath_keepfile): Likewise. (gdb_abspath): Likewise. gdb/gdbserver/ChangeLog: 2018-02-28 Sergio Durigan Junior <sergiodj@redhat.com> * Makefile.in (SFILES): Add "$(srcdir)/common/pathstuff.c". (OBJS): Add "pathstuff.o". * server.c (current_directory): New global variable. (captured_main): Initialize "current_directory".
2018-02-10 00:44:59 +01:00
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/byte-vector.h"
Create new common/pathstuff.[ch] This commit moves the path manipulation routines found on utils.c to a new common/pathstuff.c, and updates the Makefile.in's accordingly. The routines moved are "gdb_realpath", "gdb_realpath_keepfile" and "gdb_abspath". This will be needed because gdbserver will have to call "gdb_abspath" on my next patch, which implements a way to expand the path of the inferior provided by the user in order to allow specifying just the binary name when starting gdbserver, like: $ gdbserver :1234 a.out With the recent addition of the startup-with-shell feature on gdbserver, this scenario doesn't work anymore if the user doesn't have the current directory listed in the PATH variable. I had to do a minor adjustment on "gdb_abspath" because we don't have access to "tilde_expand" on gdbserver, so now the function is using "gdb_tilde_expand" instead. Otherwise, the code is the same. Regression tested on the BuildBot, without regressions. gdb/ChangeLog: 2018-02-28 Sergio Durigan Junior <sergiodj@redhat.com> * Makefile.in (COMMON_SFILES): Add "common/pathstuff.c". (HFILES_NO_SRCDIR): Add "common/pathstuff.h". * auto-load.c: Include "common/pathstuff.h". * common/common-def.h (current_directory): Move here. * common/gdb_tilde_expand.c (gdb_tilde_expand_up): New function. * common/gdb_tilde_expand.h (gdb_tilde_expand_up): New prototype. * common/pathstuff.c: New file. * common/pathstuff.h: New file. * compile/compile.c: Include "common/pathstuff.h". * defs.h (current_directory): Move to "common/common-defs.h". * dwarf2read.c: Include "common/pathstuff.h". * exec.c: Likewise. * guile/scm-safe-call.c: Likewise. * linux-thread-db.c: Likewise. * main.c: Likewise. * nto-tdep.c: Likewise. * objfiles.c: Likewise. * source.c: Likewise. * symtab.c: Likewise. * utils.c: Include "common/pathstuff.h". (gdb_realpath): Move to "common/pathstuff.c". (gdb_realpath_keepfile): Likewise. (gdb_abspath): Likewise. * utils.h (gdb_realpath): Move to "common/pathstuff.h". (gdb_realpath_keepfile): Likewise. (gdb_abspath): Likewise. gdb/gdbserver/ChangeLog: 2018-02-28 Sergio Durigan Junior <sergiodj@redhat.com> * Makefile.in (SFILES): Add "$(srcdir)/common/pathstuff.c". (OBJS): Add "pathstuff.o". * server.c (current_directory): New global variable. (captured_main): Initialize "current_directory".
2018-02-10 00:44:59 +01:00
/* Path utilities. */
/* Return the real path of FILENAME, expanding all the symbolic links.
Contrary to "gdb_abspath", this function does not use
CURRENT_DIRECTORY for path expansion. Instead, it relies on the
current working directory (CWD) of GDB or gdbserver. */
extern gdb::unique_xmalloc_ptr<char> gdb_realpath (const char *filename);
/* Return a copy of FILENAME, with its directory prefix canonicalized
by gdb_realpath. */
extern gdb::unique_xmalloc_ptr<char>
gdb_realpath_keepfile (const char *filename);
/* Return PATH in absolute form, performing tilde-expansion if necessary.
PATH cannot be NULL or the empty string.
This does not resolve symlinks however, use gdb_realpath for that.
Contrary to "gdb_realpath", this function uses CURRENT_DIRECTORY
for the path expansion. This may lead to scenarios the current
Guard against 'current_directory == NULL' on gdb_abspath (PR gdb/23613) Ref.: https://bugzilla.redhat.com/show_bug.cgi?id=1728147 Ref.: https://sourceware.org/bugzilla/show_bug.cgi?id=23613 Hi, This bug has been reported against Fedora GDB, but there's also an upstream bug. The problem reported is that GDB segfaults when the working directory is deleted. It's pretty use to reproduce it: mkdir bla cd bla rmdir ../bla gdb echo Debugging the problem is a bit tricky, because, since the current directory doesn't exist anymore, a corefile cannot be saved there. After a few attempts, I came up with the following: gdb -ex 'shell mkdir bla' -ex 'cd bla' -ex 'shell rmdir ../bla' -ex 'r echo' ./gdb/gdb This assumes that you're inside a build directory which contains ./gdb/gdb, of course. After investigating it, I found that the problem happens at gdb_abspath, where we're dereferencing 'current_directory' without checking if it's NULL: ... (concat (current_directory, IS_DIR_SEPARATOR (current_directory[strlen (current_directory) - 1]) ? "" : SLASH_STRING, ... So I fixed the problem with the patch below. The idea is that, if 'current_directory' is NULL, then the final string returned should be just the "path". After fixing the bug, I found a similar one reported against our bugzilla: PR gdb/23613. The problem is the same, but the reproducer is a bit different. I really tried writing a testcase for this, but unfortunately it's apparently not possible to start GDB inside a non-existent directory with DejaGNU. I regression tested this patch on the BuildBot, and no regressions were found. gdb/ChangeLog: 2019-12-14 Sergio Durigan Junior <sergiodj@redhat.com> https://bugzilla.redhat.com/show_bug.cgi?id=1728147 PR gdb/23613 * bsd-kvm.c (bsd_kvm_target_open): Use 'gdb_abspath'. * corelow.c: Include 'gdbsupport/pathstuff.h'. (core_target_open): Use 'gdb_abspath'. * gdbsupport/pathstuff.c (gdb_abspath): Guard against 'current_directory == NULL' case. * gdbsupport/pathstuff.h (gdb_abspath): Expand comment and explain what happens when 'current_directory' is NULL. * go32-nat.c (go32_nat_target::wait): Check if 'current_directory' is NULL before call to 'chdir'. * source.c (add_path): Use 'gdb_abspath'. * top.c: Include 'gdbsupport/pathstuff.h'. (init_history): Use 'gdb_abspath'. (set_history_filename): Likewise. * tracefile-tfile.c: Include 'gdbsupport/pathstuff.h'. (tfile_target_open): Use 'gdb_abspath'. Change-Id: Ibb0932fa25bc5c2d3ae4a7f64bd7f32885ca403b
2019-07-10 22:18:27 +02:00
working directory (CWD) is different than CURRENT_DIRECTORY.
If CURRENT_DIRECTORY is NULL, this function returns a copy of
PATH. */
Create new common/pathstuff.[ch] This commit moves the path manipulation routines found on utils.c to a new common/pathstuff.c, and updates the Makefile.in's accordingly. The routines moved are "gdb_realpath", "gdb_realpath_keepfile" and "gdb_abspath". This will be needed because gdbserver will have to call "gdb_abspath" on my next patch, which implements a way to expand the path of the inferior provided by the user in order to allow specifying just the binary name when starting gdbserver, like: $ gdbserver :1234 a.out With the recent addition of the startup-with-shell feature on gdbserver, this scenario doesn't work anymore if the user doesn't have the current directory listed in the PATH variable. I had to do a minor adjustment on "gdb_abspath" because we don't have access to "tilde_expand" on gdbserver, so now the function is using "gdb_tilde_expand" instead. Otherwise, the code is the same. Regression tested on the BuildBot, without regressions. gdb/ChangeLog: 2018-02-28 Sergio Durigan Junior <sergiodj@redhat.com> * Makefile.in (COMMON_SFILES): Add "common/pathstuff.c". (HFILES_NO_SRCDIR): Add "common/pathstuff.h". * auto-load.c: Include "common/pathstuff.h". * common/common-def.h (current_directory): Move here. * common/gdb_tilde_expand.c (gdb_tilde_expand_up): New function. * common/gdb_tilde_expand.h (gdb_tilde_expand_up): New prototype. * common/pathstuff.c: New file. * common/pathstuff.h: New file. * compile/compile.c: Include "common/pathstuff.h". * defs.h (current_directory): Move to "common/common-defs.h". * dwarf2read.c: Include "common/pathstuff.h". * exec.c: Likewise. * guile/scm-safe-call.c: Likewise. * linux-thread-db.c: Likewise. * main.c: Likewise. * nto-tdep.c: Likewise. * objfiles.c: Likewise. * source.c: Likewise. * symtab.c: Likewise. * utils.c: Include "common/pathstuff.h". (gdb_realpath): Move to "common/pathstuff.c". (gdb_realpath_keepfile): Likewise. (gdb_abspath): Likewise. * utils.h (gdb_realpath): Move to "common/pathstuff.h". (gdb_realpath_keepfile): Likewise. (gdb_abspath): Likewise. gdb/gdbserver/ChangeLog: 2018-02-28 Sergio Durigan Junior <sergiodj@redhat.com> * Makefile.in (SFILES): Add "$(srcdir)/common/pathstuff.c". (OBJS): Add "pathstuff.o". * server.c (current_directory): New global variable. (captured_main): Initialize "current_directory".
2018-02-10 00:44:59 +01:00
extern gdb::unique_xmalloc_ptr<char> gdb_abspath (const char *path);
/* If the path in CHILD is a child of the path in PARENT, return a
pointer to the first component in the CHILD's pathname below the
PARENT. Otherwise, return NULL. */
extern const char *child_path (const char *parent, const char *child);
Make gdbserver work with filename-only binaries Simon mentioned on IRC that, after the startup-with-shell feature has been implemented on gdbserver, it is not possible to specify a filename-only binary, like: $ gdbserver :1234 a.out /bin/bash: line 0: exec: a.out: not found During startup program exited with code 127. Exiting This happens on systems where the current directory "." is not listed in the PATH environment variable. Although including "." in the PATH variable is a possible workaround, this can be considered a regression because before startup-with-shell it was possible to use only the filename (due to reason that gdbserver used "exec*" directly). The idea of the patch is to verify if the program path provided by the user (or by the remote protocol) contains a directory separator character. If it doesn't, it means we're dealing with a filename-only binary, so we call "gdb_abspath" to properly expand it and transform it into a full path. Otherwise, we leave the program path untouched. This mimicks the behaviour seen on GDB (look at "openp" and "attach_inferior", for example). I am also submitting a testcase which exercises the scenario described above. This test requires gdbserver to be executed in a different CWD than the original, so I also created a helper function, "with_cwd" (on testsuite/lib/gdb.exp), which takes care of cd'ing into and out of the specified dir. Built and regtested on BuildBot, without regressions. gdb/ChangeLog: 2018-02-28 Sergio Durigan Junior <sergiodj@redhat.com> Simon Marchi <simon.marchi@polymtl.ca> * common/common-utils.c: Include "sys/stat.h". (is_regular_file): Move here from "source.c"; change return type to "bool". * common/common-utils.h (is_regular_file): New prototype. * common/pathstuff.c (contains_dir_separator): New function. * common/pathstuff.h (contains_dir_separator): New prototype. * source.c: Don't include "sys/stat.h". (is_regular_file): Move to "common/common-utils.c". gdb/gdbserver/ChangeLog: 2018-02-28 Sergio Durigan Junior <sergiodj@redhat.com> * server.c: Include "filenames.h" and "pathstuff.h". (program_name): Delete variable. (program_path): New anonymous class. (get_exec_wrapper): Use "program_path" instead of "program_name". (handle_v_run): Likewise. (captured_main): Likewise. (process_serial_event): Likewise. gdb/testsuite/ChangeLog: 2018-02-28 Sergio Durigan Junior <sergiodj@redhat.com> * gdb.server/abspath.exp: New file. * lib/gdb.exp (with_cwd): New procedure.
2018-02-10 00:54:41 +01:00
/* Return whether PATH contains a directory separator character. */
extern bool contains_dir_separator (const char *path);
Add DWARF index cache New in v3: - Remove things related to the dwarf-5 format. - Fix compilation on mingw (scoped_mmap.c). GDB can generate indexes for DWARF debug information, which, when integrated in the original binary, can speed up loading object files. This can be done using the gdb-add-index script or directly by the linker itself. However, not many people know about this. And even among those who do, because it requires additional steps, I don't know a lot of people who actually go through that trouble. To help make using the DWARF index more transparent, this patch introduces a DWARF index cache. When enabled, loading an index-less binary in GDB will automatically save an index file in ~/.cache/gdb. When loading that same object file again, the index file will be looked up and used to load the DWARF index. You therefore get the benefit of the DWARF index without having to do additional manual steps or modifying your build system. When an index section is already present in the file, GDB will prefer that one over looking up the cache. When doing my edit-compile-debug cycle, I often debug multiple times the same build, so the cache helps reducing the load time of the debug sessions after the first one. - The saved index file is exactly the same as the output of the "save gdb-index" command. It is therefore the exact same content that would be found in the .gdb_index or .debug_names section. We just leave it as a standalone file instead of merging it in the binary. - The cache is just a directory with files named after the object file's build-id. It is not possible to save/load the index for an object file without build-id in the cache. - The cache uses the gdb index format. The problem with the dwarf-5 format is that we can generate an addendum to the .debug_str section that you're supposed to integrate to the original binary. This complicates a little bit loading the data from the cached index files, so I would leave this for later. - The size taken up by ~/.cache/gdb is not limited. I was thinking we could add configurable limit (like ccache does), but that would come after. Also, maybe a command to flush the cache. - The cache is disabled by default. I think once it's been out there and tested for a while, it could be turned on by default, so that everybody can enjoy it. - The code was made to follow the XDG specification: if the XDG_CACHE_HOME environment variable, it is used, otherwise it falls back to ~/.cache/gdb. It is possible to change it using "set index-cache directory". On other OSes than GNU/Linux, ~/.cache may not be the best place to put such data. On macOS it should probably default to ~/Library/Caches/... On Windows, %LocalAppData%/... I don't intend to do this part, but further patches are welcome. - I think that we need to be careful that multiple instances of GDB don't interfere with each other (not far fetched at all if you run GDB in some automated script) and the cache is always coherent (either the file is not found, or it is found and entirely valid). Writing the file directly to its final location seems like a recipe for failure. One GDB could read a file in the index while it is being written by another GDB. To mitigate this, I made write_psymtabs_to_index write to temporary files and rename them once it's done. Two GDB instances writing the index for the same file should not step on each other's toes (the last file to be renamed will stay). A GDB looking up a file will only see a complete file or no file. Also, if GDB crashes while generating the index file, it will leave a work-in-progress file, but it won't be picked up by other instances looking up in the cache. gdb/ChangeLog: * common/pathstuff.h (get_standard_cache_dir): New. * common/pathstuff.c (get_standard_cache_dir): New. * build-id.h (build_id_to_string): New. * dwarf-index-common.h (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move to here. * dwarf-index-write.c (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move from there. (write_psymtabs_to_index): Make non-static, add basename parameter. Write to temporary files, rename when done. (save_gdb_index_command): Adjust call to write_psymtabs_to_index. * dwarf2read.h (dwarf2_per_objfile) <index_cache_res>: New field. * dwarf2read.c (dwz_file) <index_cache_res>: New field. (get_gdb_index_contents_from_cache): New. (get_gdb_index_contents_from_cache_dwz): New. (dwarf2_initialize_objfile): Read index from cache. (dwarf2_build_psymtabs): Save to index. * dwarf-index-cache.h: New file. * dwarf-index-cache.c: New file. * dwarf-index-write.h: New file. gdb/testsuite/ChangeLog: * boards/index-cache-gdb.exp: New file. * gdb.dwarf2/index-cache.exp: New file. * gdb.dwarf2/index-cache.c: New file. * gdb.base/maint.exp: Check if we are using the index cache.
2018-08-08 00:14:20 +02:00
/* Get the usual user cache directory for the current platform.
On Linux, it follows the XDG Base Directory specification: use
$XDG_CACHE_HOME/gdb if the XDG_CACHE_HOME environment variable is
defined, otherwise $HOME/.cache.
Add DWARF index cache New in v3: - Remove things related to the dwarf-5 format. - Fix compilation on mingw (scoped_mmap.c). GDB can generate indexes for DWARF debug information, which, when integrated in the original binary, can speed up loading object files. This can be done using the gdb-add-index script or directly by the linker itself. However, not many people know about this. And even among those who do, because it requires additional steps, I don't know a lot of people who actually go through that trouble. To help make using the DWARF index more transparent, this patch introduces a DWARF index cache. When enabled, loading an index-less binary in GDB will automatically save an index file in ~/.cache/gdb. When loading that same object file again, the index file will be looked up and used to load the DWARF index. You therefore get the benefit of the DWARF index without having to do additional manual steps or modifying your build system. When an index section is already present in the file, GDB will prefer that one over looking up the cache. When doing my edit-compile-debug cycle, I often debug multiple times the same build, so the cache helps reducing the load time of the debug sessions after the first one. - The saved index file is exactly the same as the output of the "save gdb-index" command. It is therefore the exact same content that would be found in the .gdb_index or .debug_names section. We just leave it as a standalone file instead of merging it in the binary. - The cache is just a directory with files named after the object file's build-id. It is not possible to save/load the index for an object file without build-id in the cache. - The cache uses the gdb index format. The problem with the dwarf-5 format is that we can generate an addendum to the .debug_str section that you're supposed to integrate to the original binary. This complicates a little bit loading the data from the cached index files, so I would leave this for later. - The size taken up by ~/.cache/gdb is not limited. I was thinking we could add configurable limit (like ccache does), but that would come after. Also, maybe a command to flush the cache. - The cache is disabled by default. I think once it's been out there and tested for a while, it could be turned on by default, so that everybody can enjoy it. - The code was made to follow the XDG specification: if the XDG_CACHE_HOME environment variable, it is used, otherwise it falls back to ~/.cache/gdb. It is possible to change it using "set index-cache directory". On other OSes than GNU/Linux, ~/.cache may not be the best place to put such data. On macOS it should probably default to ~/Library/Caches/... On Windows, %LocalAppData%/... I don't intend to do this part, but further patches are welcome. - I think that we need to be careful that multiple instances of GDB don't interfere with each other (not far fetched at all if you run GDB in some automated script) and the cache is always coherent (either the file is not found, or it is found and entirely valid). Writing the file directly to its final location seems like a recipe for failure. One GDB could read a file in the index while it is being written by another GDB. To mitigate this, I made write_psymtabs_to_index write to temporary files and rename them once it's done. Two GDB instances writing the index for the same file should not step on each other's toes (the last file to be renamed will stay). A GDB looking up a file will only see a complete file or no file. Also, if GDB crashes while generating the index file, it will leave a work-in-progress file, but it won't be picked up by other instances looking up in the cache. gdb/ChangeLog: * common/pathstuff.h (get_standard_cache_dir): New. * common/pathstuff.c (get_standard_cache_dir): New. * build-id.h (build_id_to_string): New. * dwarf-index-common.h (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move to here. * dwarf-index-write.c (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move from there. (write_psymtabs_to_index): Make non-static, add basename parameter. Write to temporary files, rename when done. (save_gdb_index_command): Adjust call to write_psymtabs_to_index. * dwarf2read.h (dwarf2_per_objfile) <index_cache_res>: New field. * dwarf2read.c (dwz_file) <index_cache_res>: New field. (get_gdb_index_contents_from_cache): New. (get_gdb_index_contents_from_cache_dwz): New. (dwarf2_initialize_objfile): Read index from cache. (dwarf2_build_psymtabs): Save to index. * dwarf-index-cache.h: New file. * dwarf-index-cache.c: New file. * dwarf-index-write.h: New file. gdb/testsuite/ChangeLog: * boards/index-cache-gdb.exp: New file. * gdb.dwarf2/index-cache.exp: New file. * gdb.dwarf2/index-cache.c: New file. * gdb.base/maint.exp: Check if we are using the index cache.
2018-08-08 00:14:20 +02:00
On macOS, it follows the local convention and uses
~/Library/Caches/gdb.
The return value is absolute and tilde-expanded. Return an empty
string if neither XDG_CACHE_HOME (on Linux) or HOME are defined. */
Add DWARF index cache New in v3: - Remove things related to the dwarf-5 format. - Fix compilation on mingw (scoped_mmap.c). GDB can generate indexes for DWARF debug information, which, when integrated in the original binary, can speed up loading object files. This can be done using the gdb-add-index script or directly by the linker itself. However, not many people know about this. And even among those who do, because it requires additional steps, I don't know a lot of people who actually go through that trouble. To help make using the DWARF index more transparent, this patch introduces a DWARF index cache. When enabled, loading an index-less binary in GDB will automatically save an index file in ~/.cache/gdb. When loading that same object file again, the index file will be looked up and used to load the DWARF index. You therefore get the benefit of the DWARF index without having to do additional manual steps or modifying your build system. When an index section is already present in the file, GDB will prefer that one over looking up the cache. When doing my edit-compile-debug cycle, I often debug multiple times the same build, so the cache helps reducing the load time of the debug sessions after the first one. - The saved index file is exactly the same as the output of the "save gdb-index" command. It is therefore the exact same content that would be found in the .gdb_index or .debug_names section. We just leave it as a standalone file instead of merging it in the binary. - The cache is just a directory with files named after the object file's build-id. It is not possible to save/load the index for an object file without build-id in the cache. - The cache uses the gdb index format. The problem with the dwarf-5 format is that we can generate an addendum to the .debug_str section that you're supposed to integrate to the original binary. This complicates a little bit loading the data from the cached index files, so I would leave this for later. - The size taken up by ~/.cache/gdb is not limited. I was thinking we could add configurable limit (like ccache does), but that would come after. Also, maybe a command to flush the cache. - The cache is disabled by default. I think once it's been out there and tested for a while, it could be turned on by default, so that everybody can enjoy it. - The code was made to follow the XDG specification: if the XDG_CACHE_HOME environment variable, it is used, otherwise it falls back to ~/.cache/gdb. It is possible to change it using "set index-cache directory". On other OSes than GNU/Linux, ~/.cache may not be the best place to put such data. On macOS it should probably default to ~/Library/Caches/... On Windows, %LocalAppData%/... I don't intend to do this part, but further patches are welcome. - I think that we need to be careful that multiple instances of GDB don't interfere with each other (not far fetched at all if you run GDB in some automated script) and the cache is always coherent (either the file is not found, or it is found and entirely valid). Writing the file directly to its final location seems like a recipe for failure. One GDB could read a file in the index while it is being written by another GDB. To mitigate this, I made write_psymtabs_to_index write to temporary files and rename them once it's done. Two GDB instances writing the index for the same file should not step on each other's toes (the last file to be renamed will stay). A GDB looking up a file will only see a complete file or no file. Also, if GDB crashes while generating the index file, it will leave a work-in-progress file, but it won't be picked up by other instances looking up in the cache. gdb/ChangeLog: * common/pathstuff.h (get_standard_cache_dir): New. * common/pathstuff.c (get_standard_cache_dir): New. * build-id.h (build_id_to_string): New. * dwarf-index-common.h (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move to here. * dwarf-index-write.c (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move from there. (write_psymtabs_to_index): Make non-static, add basename parameter. Write to temporary files, rename when done. (save_gdb_index_command): Adjust call to write_psymtabs_to_index. * dwarf2read.h (dwarf2_per_objfile) <index_cache_res>: New field. * dwarf2read.c (dwz_file) <index_cache_res>: New field. (get_gdb_index_contents_from_cache): New. (get_gdb_index_contents_from_cache_dwz): New. (dwarf2_initialize_objfile): Read index from cache. (dwarf2_build_psymtabs): Save to index. * dwarf-index-cache.h: New file. * dwarf-index-cache.c: New file. * dwarf-index-write.h: New file. gdb/testsuite/ChangeLog: * boards/index-cache-gdb.exp: New file. * gdb.dwarf2/index-cache.exp: New file. * gdb.dwarf2/index-cache.c: New file. * gdb.base/maint.exp: Check if we are using the index cache.
2018-08-08 00:14:20 +02:00
extern std::string get_standard_cache_dir ();
Import mkdtemp gnulib module, fix mingw build Building with mingw currently fails: CXX unittests/mkdir-recursive-selftests.o /home/emaisin/src/binutils-gdb/gdb/unittests/mkdir-recursive-selftests.c: In function ‘void selftests::mkdir_recursive::test()’: /home/emaisin/src/binutils-gdb/gdb/unittests/mkdir-recursive-selftests.c:49:20: error: ‘mkdtemp’ was not declared in this scope if (mkdtemp (base) == NULL) ^ Commit e418a61a67a ("Move mkdir_recursive to common/filestuff.c") moved this code, but also removed the HAVE_MKDTEMP guard which prevented the mkdtemp call to be compiled on mingw. We can either put back the HAVE_MKDTEMP ifdef, or import the gnulib mkdtemp module, which provides the function for mingw. Since the mkdir_recursive is susceptible to be used on mingw at some point, I think it would be nice to have it tested on mingw, so I did the latter. Once built, I tested it on Windows (copied the resulting gdb.exe on a Windows machine, ran it, and ran "maint selftest mkdir_recursive"). It failed, because the temporary directory is hardcoded to "/tmp/...". I therefore added and used a new get_standard_temp_dir function, which returns an appropriate temporary directory for the host platform. gdb/ChangeLog: * common/pathstuff.c (get_standard_temp_dir): New. * common/pathstuff.h (get_standard_temp_dir): New. * config.in: Re-generate. * configure: Re-generate. * configure.ac: Don't check for mkdtemp. * gnulib/aclocal-m4-deps.mk: Re-generate. * gnulib/aclocal.m4: Re-generate. * gnulib/config.in: Re-generate. * gnulib/configure: Re-generate. * gnulib/import/Makefile.am: Re-generate. * gnulib/import/Makefile.in: Re-generate. * gnulib/import/m4/gnulib-cache.m4: Re-generate. * gnulib/import/m4/gnulib-comp.m4: Re-generate. * gnulib/import/m4/mkdtemp.m4: New file. * gnulib/import/mkdtemp.c: New file. * gnulib/update-gnulib.sh (IMPORTED_GNULIB_MODULES): Add mkdtemp module. * unittests/mkdir-recursive-selftests.c (test): Use get_standard_temp_dir. (_initialize_mkdir_recursive_selftests): Remove HAVE_MKDTEMP ifdef. * compile/compile.c (get_compile_file_tempdir): Likewise.
2018-11-01 20:40:43 +01:00
/* Get the usual temporary directory for the current platform.
On Windows, this is the TMP or TEMP environment variable.
On the rest, this is the TMPDIR environment variable, if defined, else /tmp.
Throw an exception on error. */
extern std::string get_standard_temp_dir ();
/* Return the file name of the user's shell. Normally this comes from
the SHELL environment variable. */
extern const char *get_shell ();
/* Make a filename suitable to pass to mkstemp based on F (e.g.
/tmp/foo -> /tmp/foo-XXXXXX). */
extern gdb::char_vector make_temp_filename (const std::string &f);
Normalize include guards in gdb While working on my other scripts to deal with gdb headers, I noticed that some files were missing include guards. I wrote a script to add the missing ones, but found that using the obvious names for the guards ran into clashes -- for example, gdb/nat/linux-nat.h used "LINUX_NAT_H", but this was also the script's choice for gdb/linux-nat.h. So, I changed the script to normalize all include guards in gdb. This patch is the result. As usual the script is available here: https://github.com/tromey/gdb-refactoring-scripts Tested by rebuilding; I also ran it through "Fedora-x86_64-m64" on the buildbot. gdb/ChangeLog 2019-02-07 Tom Tromey <tom@tromey.com> * yy-remap.h: Add include guard. * xtensa-tdep.h: Add include guard. * xcoffread.h: Rename include guard. * varobj-iter.h: Add include guard. * tui/tui.h: Rename include guard. * tui/tui-winsource.h: Rename include guard. * tui/tui-wingeneral.h: Rename include guard. * tui/tui-windata.h: Rename include guard. * tui/tui-win.h: Rename include guard. * tui/tui-stack.h: Rename include guard. * tui/tui-source.h: Rename include guard. * tui/tui-regs.h: Rename include guard. * tui/tui-out.h: Rename include guard. * tui/tui-layout.h: Rename include guard. * tui/tui-io.h: Rename include guard. * tui/tui-hooks.h: Rename include guard. * tui/tui-file.h: Rename include guard. * tui/tui-disasm.h: Rename include guard. * tui/tui-data.h: Rename include guard. * tui/tui-command.h: Rename include guard. * tic6x-tdep.h: Add include guard. * target/waitstatus.h: Rename include guard. * target/wait.h: Rename include guard. * target/target.h: Rename include guard. * target/resume.h: Rename include guard. * target-float.h: Rename include guard. * stabsread.h: Add include guard. * rs6000-tdep.h: Add include guard. * riscv-fbsd-tdep.h: Add include guard. * regformats/regdef.h: Rename include guard. * record.h: Rename include guard. * python/python.h: Rename include guard. * python/python-internal.h: Rename include guard. * python/py-stopevent.h: Rename include guard. * python/py-ref.h: Rename include guard. * python/py-record.h: Rename include guard. * python/py-record-full.h: Rename include guard. * python/py-record-btrace.h: Rename include guard. * python/py-instruction.h: Rename include guard. * python/py-events.h: Rename include guard. * python/py-event.h: Rename include guard. * procfs.h: Add include guard. * proc-utils.h: Add include guard. * p-lang.h: Add include guard. * or1k-tdep.h: Rename include guard. * observable.h: Rename include guard. * nto-tdep.h: Rename include guard. * nat/x86-linux.h: Rename include guard. * nat/x86-linux-dregs.h: Rename include guard. * nat/x86-gcc-cpuid.h: Add include guard. * nat/x86-dregs.h: Rename include guard. * nat/x86-cpuid.h: Rename include guard. * nat/ppc-linux.h: Rename include guard. * nat/mips-linux-watch.h: Rename include guard. * nat/linux-waitpid.h: Rename include guard. * nat/linux-ptrace.h: Rename include guard. * nat/linux-procfs.h: Rename include guard. * nat/linux-osdata.h: Rename include guard. * nat/linux-nat.h: Rename include guard. * nat/linux-namespaces.h: Rename include guard. * nat/linux-btrace.h: Rename include guard. * nat/glibc_thread_db.h: Rename include guard. * nat/gdb_thread_db.h: Rename include guard. * nat/gdb_ptrace.h: Rename include guard. * nat/fork-inferior.h: Rename include guard. * nat/amd64-linux-siginfo.h: Rename include guard. * nat/aarch64-sve-linux-sigcontext.h: Rename include guard. * nat/aarch64-sve-linux-ptrace.h: Rename include guard. * nat/aarch64-linux.h: Rename include guard. * nat/aarch64-linux-hw-point.h: Rename include guard. * mn10300-tdep.h: Add include guard. * mips-linux-tdep.h: Add include guard. * mi/mi-parse.h: Rename include guard. * mi/mi-out.h: Rename include guard. * mi/mi-main.h: Rename include guard. * mi/mi-interp.h: Rename include guard. * mi/mi-getopt.h: Rename include guard. * mi/mi-console.h: Rename include guard. * mi/mi-common.h: Rename include guard. * mi/mi-cmds.h: Rename include guard. * mi/mi-cmd-break.h: Rename include guard. * m2-lang.h: Add include guard. * location.h: Rename include guard. * linux-record.h: Rename include guard. * linux-nat.h: Add include guard. * linux-fork.h: Add include guard. * i386-darwin-tdep.h: Rename include guard. * hppa-linux-offsets.h: Add include guard. * guile/guile.h: Rename include guard. * guile/guile-internal.h: Rename include guard. * gnu-nat.h: Rename include guard. * gdb-stabs.h: Rename include guard. * frv-tdep.h: Add include guard. * f-lang.h: Add include guard. * event-loop.h: Add include guard. * darwin-nat.h: Rename include guard. * cp-abi.h: Rename include guard. * config/sparc/nm-sol2.h: Rename include guard. * config/nm-nto.h: Rename include guard. * config/nm-linux.h: Add include guard. * config/i386/nm-i386gnu.h: Rename include guard. * config/djgpp/nl_types.h: Rename include guard. * config/djgpp/langinfo.h: Rename include guard. * compile/gcc-cp-plugin.h: Add include guard. * compile/gcc-c-plugin.h: Add include guard. * compile/compile.h: Rename include guard. * compile/compile-object-run.h: Rename include guard. * compile/compile-object-load.h: Rename include guard. * compile/compile-internal.h: Rename include guard. * compile/compile-cplus.h: Rename include guard. * compile/compile-c.h: Rename include guard. * common/xml-utils.h: Rename include guard. * common/x86-xstate.h: Rename include guard. * common/version.h: Rename include guard. * common/vec.h: Rename include guard. * common/tdesc.h: Rename include guard. * common/selftest.h: Rename include guard. * common/scoped_restore.h: Rename include guard. * common/scoped_mmap.h: Rename include guard. * common/scoped_fd.h: Rename include guard. * common/safe-iterator.h: Rename include guard. * common/run-time-clock.h: Rename include guard. * common/refcounted-object.h: Rename include guard. * common/queue.h: Rename include guard. * common/ptid.h: Rename include guard. * common/print-utils.h: Rename include guard. * common/preprocessor.h: Rename include guard. * common/pathstuff.h: Rename include guard. * common/observable.h: Rename include guard. * common/netstuff.h: Rename include guard. * common/job-control.h: Rename include guard. * common/host-defs.h: Rename include guard. * common/gdb_wait.h: Rename include guard. * common/gdb_vecs.h: Rename include guard. * common/gdb_unlinker.h: Rename include guard. * common/gdb_unique_ptr.h: Rename include guard. * common/gdb_tilde_expand.h: Rename include guard. * common/gdb_sys_time.h: Rename include guard. * common/gdb_string_view.h: Rename include guard. * common/gdb_splay_tree.h: Rename include guard. * common/gdb_setjmp.h: Rename include guard. * common/gdb_ref_ptr.h: Rename include guard. * common/gdb_optional.h: Rename include guard. * common/gdb_locale.h: Rename include guard. * common/gdb_assert.h: Rename include guard. * common/filtered-iterator.h: Rename include guard. * common/filestuff.h: Rename include guard. * common/fileio.h: Rename include guard. * common/environ.h: Rename include guard. * common/common-utils.h: Rename include guard. * common/common-types.h: Rename include guard. * common/common-regcache.h: Rename include guard. * common/common-inferior.h: Rename include guard. * common/common-gdbthread.h: Rename include guard. * common/common-exceptions.h: Rename include guard. * common/common-defs.h: Rename include guard. * common/common-debug.h: Rename include guard. * common/cleanups.h: Rename include guard. * common/buffer.h: Rename include guard. * common/btrace-common.h: Rename include guard. * common/break-common.h: Rename include guard. * cli/cli-utils.h: Rename include guard. * cli/cli-style.h: Rename include guard. * cli/cli-setshow.h: Rename include guard. * cli/cli-script.h: Rename include guard. * cli/cli-interp.h: Rename include guard. * cli/cli-decode.h: Rename include guard. * cli/cli-cmds.h: Rename include guard. * charset-list.h: Add include guard. * buildsym-legacy.h: Rename include guard. * bfin-tdep.h: Add include guard. * ax.h: Rename include guard. * arm-linux-tdep.h: Add include guard. * arm-fbsd-tdep.h: Add include guard. * arch/xtensa.h: Rename include guard. * arch/tic6x.h: Add include guard. * arch/i386.h: Add include guard. * arch/arm.h: Rename include guard. * arch/arm-linux.h: Rename include guard. * arch/arm-get-next-pcs.h: Rename include guard. * arch/amd64.h: Add include guard. * arch/aarch64-insn.h: Rename include guard. * arch-utils.h: Rename include guard. * annotate.h: Add include guard. * amd64-darwin-tdep.h: Rename include guard. * aarch64-linux-tdep.h: Add include guard. * aarch64-fbsd-tdep.h: Add include guard. * aarch32-linux-nat.h: Add include guard. gdb/gdbserver/ChangeLog 2019-02-07 Tom Tromey <tom@tromey.com> * x86-tdesc.h: Rename include guard. * x86-low.h: Add include guard. * wincecompat.h: Rename include guard. * win32-low.h: Add include guard. * utils.h: Rename include guard. * tracepoint.h: Rename include guard. * tdesc.h: Rename include guard. * target.h: Rename include guard. * server.h: Rename include guard. * remote-utils.h: Rename include guard. * regcache.h: Rename include guard. * nto-low.h: Rename include guard. * notif.h: Add include guard. * mem-break.h: Rename include guard. * lynx-low.h: Add include guard. * linux-x86-tdesc.h: Add include guard. * linux-s390-tdesc.h: Add include guard. * linux-ppc-tdesc-init.h: Add include guard. * linux-low.h: Add include guard. * linux-aarch64-tdesc.h: Add include guard. * linux-aarch32-low.h: Add include guard. * inferiors.h: Rename include guard. * i387-fp.h: Rename include guard. * hostio.h: Rename include guard. * gdbthread.h: Rename include guard. * gdb_proc_service.h: Rename include guard. * event-loop.h: Rename include guard. * dll.h: Rename include guard. * debug.h: Rename include guard. * ax.h: Rename include guard.
2019-01-27 20:51:36 +01:00
#endif /* COMMON_PATHSTUFF_H */