From d8d2a3ee4770ba7eab50829dd1126f95ac33e5a6 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Mon, 1 Jul 2013 11:28:30 +0000 Subject: [PATCH] Normalize on PATH_MAX instead of MAXPATHLEN throughout. With the pathmax gnulib module in place, we can use PATH_MAX consistently throughout, instead of the current mixbag of PATH_MAX and MAXPATHLEN uses. It's no longer necessary to include sys/param.h (supposedly, I can't check all ports touched here) for MAXPATHLEN. Don't remove sys/param.h from GDB's configure.ac, as later tests in the file use HAVE_SYS_PARAM_H checks. Tested on x86_64 Fedora 17. Also cross-built for --host=i686-w64-mingw32, and --host=i586-pc-msdosdjgpp. gdb/ 2013-07-01 Pedro Alves * defs.h: Include "pathmax.h". * utils.c: Don't include sys/param.h. (gdb_realpath): Remove code that checks for MAXPATHLEN. * solib-ia64-hpux.c (ia64_hpux_handle_load_event): Use PATH_MAX instead of MAXPATHLEN. * solib-sunos.c: Don't include sys/param.h. * xcoffread.c: Don't include sys/param.h. * bsd-kvm.c: Don't include sys/param.h. * darwin-nat.c: Don't include sys/param.h. (darwin_pid_to_exec_file): Use PATH_MAX instead of MAXPATHLEN. * darwin-nat-info.c: Don't include sys/param.h. * fbsd-nat.c (fbsd_pid_to_exec_file): Use PATH_MAX instead of MAXPATHLEN. * i386obsd-nat.c: Don't include sys/param.h. * inf-child.c: Don't include sys/param.h. (inf_child_fileio_readlink): Use PATH_MAX instead of MAXPATHLEN. * linux-fork.c: Don't include sys/param.h. (fork_save_infrun_state): Use PATH_MAX instead of MAXPATHLEN. * linux-nat.c: Don't include sys/param.h. (linux_child_pid_to_exec_file, linux_proc_pending_signals) (linux_proc_pending_signals): Use PATH_MAX instead of MAXPATHLEN. * m68klinux-nat.c: Don't include sys/param.h. * nbsd-nat.c: Don't include sys/param.h. (nbsd_pid_to_exec_file): Use PATH_MAX instead of MAXPATHLEN. * ppc-linux-nat.c: Don't include sys/param.h. * rs6000-nat.c: Don't include sys/param.h. * spu-linux-nat.c. Don't include sys/param.h. * windows-nat.c: Don't include sys/param.h. * xtensa-linux-nat.c: Don't include sys/param.h. * config/i386/nm-fbsd.h: Don't include sys/param.h. gdb/gdbserver/ 2013-07-01 Pedro Alves * server.h: Include "pathmax.h". * linux-low.c: Don't include sys/param.h. (linux_pid_exe_is_elf_64_file): Use PATH_MAX instead of MAXPATHLEN. * win32-low.c: Don't include sys/param.h. (win32_create_inferior): Use PATH_MAX instead of MAXPATHLEN. --- gdb/ChangeLog | 33 +++++++++++++++++++++++++++++++++ gdb/bsd-kvm.c | 1 - gdb/config/i386/nm-fbsd.h | 4 ---- gdb/darwin-nat-info.c | 1 - gdb/darwin-nat.c | 5 ++--- gdb/defs.h | 4 ++++ gdb/fbsd-nat.c | 4 ++-- gdb/gdbserver/ChangeLog | 9 +++++++++ gdb/gdbserver/linux-low.c | 3 +-- gdb/gdbserver/server.h | 3 +++ gdb/gdbserver/win32-low.c | 6 ++---- gdb/i386obsd-nat.c | 1 - gdb/inf-child.c | 9 +++------ gdb/linux-fork.c | 5 ++--- gdb/linux-nat.c | 13 ++++++------- gdb/m68klinux-nat.c | 1 - gdb/nbsd-nat.c | 6 ++---- gdb/ppc-linux-nat.c | 1 - gdb/rs6000-nat.c | 1 - gdb/solib-ia64-hpux.c | 4 ++-- gdb/solib-sunos.c | 1 - gdb/spu-linux-nat.c | 1 - gdb/utils.c | 12 +----------- gdb/windows-nat.c | 1 - gdb/xcoffread.c | 1 - gdb/xtensa-linux-nat.c | 1 - 26 files changed, 72 insertions(+), 59 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 2c71fdd..0ecad53 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,38 @@ 2013-07-01 Pedro Alves + * defs.h: Include "pathmax.h". + * utils.c: Don't include sys/param.h. + (gdb_realpath): Remove code that checks for MAXPATHLEN. + * solib-ia64-hpux.c (ia64_hpux_handle_load_event): Use PATH_MAX + instead of MAXPATHLEN. + * solib-sunos.c: Don't include sys/param.h. + * xcoffread.c: Don't include sys/param.h. + * bsd-kvm.c: Don't include sys/param.h. + * darwin-nat.c: Don't include sys/param.h. + (darwin_pid_to_exec_file): Use PATH_MAX instead of MAXPATHLEN. + * darwin-nat-info.c: Don't include sys/param.h. + * fbsd-nat.c (fbsd_pid_to_exec_file): Use PATH_MAX instead of + MAXPATHLEN. + * i386obsd-nat.c: Don't include sys/param.h. + * inf-child.c: Don't include sys/param.h. + (inf_child_fileio_readlink): Use PATH_MAX instead of MAXPATHLEN. + * linux-fork.c: Don't include sys/param.h. + (fork_save_infrun_state): Use PATH_MAX instead of MAXPATHLEN. + * linux-nat.c: Don't include sys/param.h. + (linux_child_pid_to_exec_file, linux_proc_pending_signals) + (linux_proc_pending_signals): Use PATH_MAX instead of MAXPATHLEN. + * m68klinux-nat.c: Don't include sys/param.h. + * nbsd-nat.c: Don't include sys/param.h. + (nbsd_pid_to_exec_file): Use PATH_MAX instead of MAXPATHLEN. + * ppc-linux-nat.c: Don't include sys/param.h. + * rs6000-nat.c: Don't include sys/param.h. + * spu-linux-nat.c. Don't include sys/param.h. + * windows-nat.c: Don't include sys/param.h. + * xtensa-linux-nat.c: Don't include sys/param.h. + * config/i386/nm-fbsd.h: Don't include sys/param.h. + +2013-07-01 Pedro Alves + * gnulib/update-gnulib.sh (IMPORTED_GNULIB_MODULES): Add pathmax. * gnulib/Makefile.in (aclocal_m4_deps): Add import/m4/pathmax.m4. * gnulib/aclocal.m4: Regenerate. diff --git a/gdb/bsd-kvm.c b/gdb/bsd-kvm.c index 1e43ccc..dd0ef06 100644 --- a/gdb/bsd-kvm.c +++ b/gdb/bsd-kvm.c @@ -35,7 +35,6 @@ #endif #include #include "readline/readline.h" -#include #include #include diff --git a/gdb/config/i386/nm-fbsd.h b/gdb/config/i386/nm-fbsd.h index 8da0bac..b25dadc 100644 --- a/gdb/config/i386/nm-fbsd.h +++ b/gdb/config/i386/nm-fbsd.h @@ -20,8 +20,4 @@ #ifndef NM_FBSD_H #define NM_FBSD_H -#ifdef HAVE_SYS_PARAM_H -#include -#endif - #endif /* nm-fbsd.h */ diff --git a/gdb/darwin-nat-info.c b/gdb/darwin-nat-info.c index e480cd7..bdc2889 100644 --- a/gdb/darwin-nat-info.c +++ b/gdb/darwin-nat-info.c @@ -35,7 +35,6 @@ #include "gdbcmd.h" #include "inferior.h" -#include #include #include "darwin-nat.h" diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c index cbf1f78..4f851ce 100644 --- a/gdb/darwin-nat.c +++ b/gdb/darwin-nat.c @@ -48,7 +48,6 @@ #include #include #include -#include #include #include #include @@ -2002,10 +2001,10 @@ darwin_pid_to_exec_file (int pid) char *path; int res; - path = xmalloc (MAXPATHLEN); + path = xmalloc (PATH_MAX); make_cleanup (xfree, path); - res = proc_pidinfo (pid, PROC_PIDPATHINFO, 0, path, MAXPATHLEN); + res = proc_pidinfo (pid, PROC_PIDPATHINFO, 0, path, PATH_MAX); if (res >= 0) return path; else diff --git a/gdb/defs.h b/gdb/defs.h index f90ca9d..f014976 100644 --- a/gdb/defs.h +++ b/gdb/defs.h @@ -53,6 +53,10 @@ #endif #include + +/* For gnulib's PATH_MAX. */ +#include "pathmax.h" + #include /* First include ansidecl.h so we can use the various macro definitions diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c index be7db1d..6a362da 100644 --- a/gdb/fbsd-nat.c +++ b/gdb/fbsd-nat.c @@ -39,7 +39,7 @@ char * fbsd_pid_to_exec_file (int pid) { - size_t len = MAXPATHLEN; + size_t len = PATH_MAX; char *buf = xcalloc (len, sizeof (char)); char *path; @@ -55,7 +55,7 @@ fbsd_pid_to_exec_file (int pid) #endif path = xstrprintf ("/proc/%d/file", pid); - if (readlink (path, buf, MAXPATHLEN - 1) == -1) + if (readlink (path, buf, PATH_MAX - 1) == -1) { xfree (buf); buf = NULL; diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index 11ae9f3..4e7fe00 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,5 +1,14 @@ 2013-07-01 Pedro Alves + * server.h: Include "pathmax.h". + * linux-low.c: Don't include sys/param.h. + (linux_pid_exe_is_elf_64_file): Use PATH_MAX instead of + MAXPATHLEN. + * win32-low.c: Don't include sys/param.h. + (win32_create_inferior): Use PATH_MAX instead of MAXPATHLEN. + +2013-07-01 Pedro Alves + * event-loop.c: Don't check HAVE_UNISTD_H before including . * gdbreplay.c: Likewise. diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index bb7298a..47ea76d 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -23,7 +23,6 @@ #include "gdb_wait.h" #include -#include #include #include "linux-ptrace.h" #include "linux-procfs.h" @@ -342,7 +341,7 @@ elf_64_file_p (const char *file, unsigned int *machine) int linux_pid_exe_is_elf_64_file (int pid, unsigned int *machine) { - char file[MAXPATHLEN]; + char file[PATH_MAX]; sprintf (file, "/proc/%d/exe", pid); return elf_64_file_p (file, machine); diff --git a/gdb/gdbserver/server.h b/gdb/gdbserver/server.h index c68c651..1a1d9b2 100644 --- a/gdb/gdbserver/server.h +++ b/gdb/gdbserver/server.h @@ -38,6 +38,9 @@ #endif #include +/* For gnulib's PATH_MAX. */ +#include "pathmax.h" + #ifdef HAVE_STRING_H #include #endif diff --git a/gdb/gdbserver/win32-low.c b/gdb/gdbserver/win32-low.c index d1caa73..30fd1e7 100644 --- a/gdb/gdbserver/win32-low.c +++ b/gdb/gdbserver/win32-low.c @@ -32,7 +32,6 @@ #include #include #include -#include #include #ifndef USE_WIN32API @@ -515,7 +514,7 @@ static int win32_create_inferior (char *program, char **program_args) { #ifndef USE_WIN32API - char real_path[MAXPATHLEN]; + char real_path[PATH_MAX]; char *orig_path, *new_path, *path_ptr; #endif BOOL ret; @@ -546,8 +545,7 @@ win32_create_inferior (char *program, char **program_args) cygwin_conv_path_list (CCP_POSIX_TO_WIN_A, path_ptr, new_path, size); setenv ("PATH", new_path, 1); } - cygwin_conv_path (CCP_POSIX_TO_WIN_A, program, real_path, - MAXPATHLEN); + cygwin_conv_path (CCP_POSIX_TO_WIN_A, program, real_path, PATH_MAX); program = real_path; #endif diff --git a/gdb/i386obsd-nat.c b/gdb/i386obsd-nat.c index aef79da..f214b64 100644 --- a/gdb/i386obsd-nat.c +++ b/gdb/i386obsd-nat.c @@ -22,7 +22,6 @@ #include "regcache.h" #include "target.h" -#include #include #include #include diff --git a/gdb/inf-child.c b/gdb/inf-child.c index 15d8613..f5992bb 100644 --- a/gdb/inf-child.c +++ b/gdb/inf-child.c @@ -32,9 +32,6 @@ #include "gdb_wait.h" #include "filestuff.h" -#ifdef HAVE_SYS_PARAM_H -#include /* for MAXPATHLEN */ -#endif #include #include #include @@ -344,9 +341,9 @@ static char * inf_child_fileio_readlink (const char *filename, int *target_errno) { /* We support readlink only on systems that also provide a compile-time - maximum path length (MAXPATHLEN), at least for now. */ -#if defined (HAVE_READLINK) && defined (MAXPATHLEN) - char buf[MAXPATHLEN - 1]; + maximum path length (PATH_MAX), at least for now. */ +#if defined (HAVE_READLINK) && defined (PATH_MAX) + char buf[PATH_MAX]; int len; char *ret; diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c index cb57050..4100cb1 100644 --- a/gdb/linux-fork.c +++ b/gdb/linux-fork.c @@ -33,7 +33,6 @@ #include #include "gdb_wait.h" -#include #include "gdb_dirent.h" #include @@ -269,7 +268,7 @@ fork_load_infrun_state (struct fork_info *fp) static void fork_save_infrun_state (struct fork_info *fp, int clobber_regs) { - char path[MAXPATHLEN]; + char path[PATH_MAX]; struct dirent *de; DIR *d; @@ -283,7 +282,7 @@ fork_save_infrun_state (struct fork_info *fp, int clobber_regs) { /* Now save the 'state' (file position) of all open file descriptors. Unfortunately fork does not take care of that for us... */ - snprintf (path, MAXPATHLEN, "/proc/%ld/fd", (long) PIDGET (fp->ptid)); + snprintf (path, PATH_MAX, "/proc/%ld/fd", (long) PIDGET (fp->ptid)); if ((d = opendir (path)) != NULL) { long tmp; diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 6ba71ba..45a6e5f 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -39,7 +39,6 @@ #include "inf-child.h" #include "inf-ptrace.h" #include "auxv.h" -#include /* for MAXPATHLEN */ #include /* for elf_gregset etc. */ #include "elf-bfd.h" /* for elfcore_write_* */ #include "gregset.h" /* for gregset */ @@ -4306,14 +4305,14 @@ linux_child_pid_to_exec_file (int pid) { char *name1, *name2; - name1 = xmalloc (MAXPATHLEN); - name2 = xmalloc (MAXPATHLEN); + name1 = xmalloc (PATH_MAX); + name2 = xmalloc (PATH_MAX); make_cleanup (xfree, name1); make_cleanup (xfree, name2); - memset (name2, 0, MAXPATHLEN); + memset (name2, 0, PATH_MAX); sprintf (name1, "/proc/%d/exe", pid); - if (readlink (name1, name2, MAXPATHLEN - 1) > 0) + if (readlink (name1, name2, PATH_MAX - 1) > 0) return name2; else return name1; @@ -4562,7 +4561,7 @@ linux_proc_pending_signals (int pid, sigset_t *pending, sigset_t *blocked, sigset_t *ignored) { FILE *procfile; - char buffer[MAXPATHLEN], fname[MAXPATHLEN]; + char buffer[PATH_MAX], fname[PATH_MAX]; struct cleanup *cleanup; sigemptyset (pending); @@ -4574,7 +4573,7 @@ linux_proc_pending_signals (int pid, sigset_t *pending, error (_("Could not open %s"), fname); cleanup = make_cleanup_fclose (procfile); - while (fgets (buffer, MAXPATHLEN, procfile) != NULL) + while (fgets (buffer, PATH_MAX, procfile) != NULL) { /* Normal queued signals are on the SigPnd line in the status file. However, 2.6 kernels also have a "shared" pending diff --git a/gdb/m68klinux-nat.c b/gdb/m68klinux-nat.c index 11e8f25..5e30ad2 100644 --- a/gdb/m68klinux-nat.c +++ b/gdb/m68klinux-nat.c @@ -29,7 +29,6 @@ #include "m68k-tdep.h" -#include #include #include #include diff --git a/gdb/nbsd-nat.c b/gdb/nbsd-nat.c index 274ef43..324efd8 100644 --- a/gdb/nbsd-nat.c +++ b/gdb/nbsd-nat.c @@ -19,8 +19,6 @@ #include "defs.h" -#include - #include "nbsd-nat.h" /* Return the name of a file that can be opened to get the symbols for @@ -29,12 +27,12 @@ char * nbsd_pid_to_exec_file (int pid) { - size_t len = MAXPATHLEN; + size_t len = PATH_MAX; char *buf = xcalloc (len, sizeof (char)); char *path; path = xstrprintf ("/proc/%d/exe", pid); - if (readlink (path, buf, MAXPATHLEN - 1) == -1) + if (readlink (path, buf, PATH_MAX - 1) == -1) { xfree (buf); buf = NULL; diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c index 1ff00a6..65d4f4a 100644 --- a/gdb/ppc-linux-nat.c +++ b/gdb/ppc-linux-nat.c @@ -31,7 +31,6 @@ #include #include -#include #include #include #include diff --git a/gdb/rs6000-nat.c b/gdb/rs6000-nat.c index 1b600f0..6769618 100644 --- a/gdb/rs6000-nat.c +++ b/gdb/rs6000-nat.c @@ -41,7 +41,6 @@ #include #include -#include #include #include #include diff --git a/gdb/solib-ia64-hpux.c b/gdb/solib-ia64-hpux.c index 0a92904..98fad07 100644 --- a/gdb/solib-ia64-hpux.c +++ b/gdb/solib-ia64-hpux.c @@ -189,7 +189,7 @@ ia64_hpux_handle_load_event (struct regcache *regcache) CORE_ADDR module_desc_addr; ULONGEST module_desc_size; CORE_ADDR so_path_addr; - char so_path[MAXPATHLEN]; + char so_path[PATH_MAX]; struct load_module_desc module_desc; struct so_list *new_so; @@ -210,7 +210,7 @@ ia64_hpux_handle_load_event (struct regcache *regcache) sizeof (struct load_module_desc), pulongest (module_desc_size)); - read_memory_string (so_path_addr, so_path, MAXPATHLEN); + read_memory_string (so_path_addr, so_path, PATH_MAX); read_memory (module_desc_addr, (gdb_byte *) &module_desc, sizeof (module_desc)); diff --git a/gdb/solib-sunos.c b/gdb/solib-sunos.c index 5863fc2..3259f8b 100644 --- a/gdb/solib-sunos.c +++ b/gdb/solib-sunos.c @@ -22,7 +22,6 @@ #include #include #include "gdb_string.h" -#include #include /* SunOS shared libs need the nlist structure. */ diff --git a/gdb/spu-linux-nat.c b/gdb/spu-linux-nat.c index 1fab9da..9855bac 100644 --- a/gdb/spu-linux-nat.c +++ b/gdb/spu-linux-nat.c @@ -34,7 +34,6 @@ #include #include #include -#include #include "spu-tdep.h" diff --git a/gdb/utils.c b/gdb/utils.c index a2015a8..01212ab 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -66,8 +66,6 @@ #include "inferior.h" /* for signed_pointer_to_address */ -#include /* For MAXPATHLEN */ - #include "gdb_curses.h" #include "readline/readline.h" @@ -3130,22 +3128,14 @@ gdb_realpath (const char *filename) path. Use that and realpath() to canonicalize the name. This is the most common case. Note that, if there isn't a compile time upper bound, you want to avoid realpath() at all costs. */ -#if defined(HAVE_REALPATH) +#if defined (HAVE_REALPATH) && defined (PATH_MAX) { -# if defined (PATH_MAX) char buf[PATH_MAX]; -# define USE_REALPATH -# elif defined (MAXPATHLEN) - char buf[MAXPATHLEN]; -# define USE_REALPATH -# endif -# if defined (USE_REALPATH) const char *rp = realpath (filename, buf); if (rp == NULL) rp = filename; return xstrdup (rp); -# endif } #endif /* HAVE_REALPATH */ diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index ed35801..9a0241b 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -54,7 +54,6 @@ #include "gdb_string.h" #include "gdbthread.h" #include "gdbcmd.h" -#include #include #include "exec.h" #include "solist.h" diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c index a9ce667..afe1554 100644 --- a/gdb/xcoffread.c +++ b/gdb/xcoffread.c @@ -26,7 +26,6 @@ #include #include "gdb_string.h" -#include #ifdef HAVE_SYS_FILE_H #include #endif diff --git a/gdb/xtensa-linux-nat.c b/gdb/xtensa-linux-nat.c index 2ca7144..3fdaa37 100644 --- a/gdb/xtensa-linux-nat.c +++ b/gdb/xtensa-linux-nat.c @@ -29,7 +29,6 @@ #include #include -#include #include #include #include -- 2.7.4