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  <palves@redhat.com>

	* 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  <palves@redhat.com>

	* 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.
This commit is contained in:
Pedro Alves 2013-07-01 11:28:30 +00:00
parent 38ec22075a
commit d8d2a3ee47
26 changed files with 72 additions and 59 deletions

View File

@ -1,3 +1,36 @@
2013-07-01 Pedro Alves <palves@redhat.com>
* 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 <palves@redhat.com>
* gnulib/update-gnulib.sh (IMPORTED_GNULIB_MODULES): Add pathmax.

View File

@ -35,7 +35,6 @@
#endif
#include <paths.h>
#include "readline/readline.h"
#include <sys/param.h>
#include <sys/proc.h>
#include <sys/user.h>

View File

@ -20,8 +20,4 @@
#ifndef NM_FBSD_H
#define NM_FBSD_H
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#endif /* nm-fbsd.h */

View File

@ -35,7 +35,6 @@
#include "gdbcmd.h"
#include "inferior.h"
#include <sys/param.h>
#include <sys/sysctl.h>
#include "darwin-nat.h"

View File

@ -48,7 +48,6 @@
#include <signal.h>
#include <string.h>
#include <ctype.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/proc.h>
#include <libproc.h>
@ -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

View File

@ -53,6 +53,10 @@
#endif
#include <unistd.h>
/* For gnulib's PATH_MAX. */
#include "pathmax.h"
#include <fcntl.h>
/* First include ansidecl.h so we can use the various macro definitions

View File

@ -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;

View File

@ -1,3 +1,12 @@
2013-07-01 Pedro Alves <palves@redhat.com>
* 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 <palves@redhat.com>
* event-loop.c: Don't check HAVE_UNISTD_H before including

View File

@ -23,7 +23,6 @@
#include "gdb_wait.h"
#include <stdio.h>
#include <sys/param.h>
#include <sys/ptrace.h>
#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);

View File

@ -38,6 +38,9 @@
#endif
#include <setjmp.h>
/* For gnulib's PATH_MAX. */
#include "pathmax.h"
#ifdef HAVE_STRING_H
#include <string.h>
#endif

View File

@ -32,7 +32,6 @@
#include <imagehlp.h>
#include <tlhelp32.h>
#include <psapi.h>
#include <sys/param.h>
#include <process.h>
#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

View File

@ -22,7 +22,6 @@
#include "regcache.h"
#include "target.h"
#include <sys/param.h>
#include <sys/sysctl.h>
#include <machine/frame.h>
#include <machine/pcb.h>

View File

@ -32,9 +32,6 @@
#include "gdb_wait.h"
#include "filestuff.h"
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h> /* for MAXPATHLEN */
#endif
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
@ -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;

View File

@ -33,7 +33,6 @@
#include <sys/ptrace.h>
#include "gdb_wait.h"
#include <sys/param.h>
#include "gdb_dirent.h"
#include <ctype.h>
@ -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;

View File

@ -39,7 +39,6 @@
#include "inf-child.h"
#include "inf-ptrace.h"
#include "auxv.h"
#include <sys/param.h> /* for MAXPATHLEN */
#include <sys/procfs.h> /* 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

View File

@ -29,7 +29,6 @@
#include "m68k-tdep.h"
#include <sys/param.h>
#include <sys/dir.h>
#include <signal.h>
#include <sys/ptrace.h>

View File

@ -19,8 +19,6 @@
#include "defs.h"
#include <sys/param.h>
#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;

View File

@ -31,7 +31,6 @@
#include <stdint.h>
#include <sys/types.h>
#include <sys/param.h>
#include <signal.h>
#include <sys/user.h>
#include <sys/ioctl.h>

View File

@ -41,7 +41,6 @@
#include <sys/ptrace.h>
#include <sys/reg.h>
#include <sys/param.h>
#include <sys/dir.h>
#include <sys/user.h>
#include <signal.h>

View File

@ -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));

View File

@ -22,7 +22,6 @@
#include <sys/types.h>
#include <signal.h>
#include "gdb_string.h"
#include <sys/param.h>
#include <fcntl.h>
/* SunOS shared libs need the nlist structure. */

View File

@ -34,7 +34,6 @@
#include <sys/ptrace.h>
#include <asm/ptrace.h>
#include <sys/types.h>
#include <sys/param.h>
#include "spu-tdep.h"

View File

@ -66,8 +66,6 @@
#include "inferior.h" /* for signed_pointer_to_address */
#include <sys/param.h> /* 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 */

View File

@ -54,7 +54,6 @@
#include "gdb_string.h"
#include "gdbthread.h"
#include "gdbcmd.h"
#include <sys/param.h>
#include <unistd.h>
#include "exec.h"
#include "solist.h"

View File

@ -26,7 +26,6 @@
#include <ctype.h>
#include "gdb_string.h"
#include <sys/param.h>
#ifdef HAVE_SYS_FILE_H
#include <sys/file.h>
#endif

View File

@ -29,7 +29,6 @@
#include <stdint.h>
#include <sys/types.h>
#include <sys/param.h>
#include <signal.h>
#include <sys/user.h>
#include <sys/ioctl.h>