2002-02-25 06:31:19 +08:00
|
|
|
/* GNU/Linux specific methods for using the /proc file system.
|
|
|
|
|
2002-01-09 08:37:02 +08:00
|
|
|
Copyright 2001, 2002 Free Software Foundation, Inc.
|
2002-01-09 06:09:50 +08: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 2 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, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
Boston, MA 02111-1307, USA. */
|
|
|
|
|
|
|
|
#include "defs.h"
|
2002-01-09 08:37:02 +08:00
|
|
|
#include "inferior.h"
|
2003-03-29 05:42:41 +08:00
|
|
|
#include <sys/param.h> /* for MAXPATHLEN */
|
|
|
|
#include <sys/procfs.h> /* for elf_gregset etc. */
|
|
|
|
#include "gdb_stat.h" /* for struct stat */
|
|
|
|
#include <ctype.h> /* for isdigit */
|
|
|
|
#include <unistd.h> /* for open, pread64 */
|
|
|
|
#include <fcntl.h> /* for O_RDONLY */
|
|
|
|
#include "regcache.h" /* for registers_changed */
|
|
|
|
#include "gregset.h" /* for gregset */
|
|
|
|
#include "gdbcore.h" /* for get_exec_file */
|
|
|
|
#include "gdbthread.h" /* for struct thread_info etc. */
|
|
|
|
#include "elf-bfd.h" /* for elfcore_write_* */
|
2002-01-16 04:10:55 +08:00
|
|
|
#include "cli/cli-decode.h" /* for add_info */
|
2002-08-02 06:55:36 +08:00
|
|
|
#include "gdb_string.h"
|
2002-01-09 08:37:02 +08:00
|
|
|
|
2003-09-08 02:49:44 +08:00
|
|
|
#include <signal.h>
|
|
|
|
|
2003-06-20 06:52:04 +08:00
|
|
|
#include "linux-nat.h"
|
|
|
|
|
2002-11-26 09:23:46 +08:00
|
|
|
#ifndef O_LARGEFILE
|
|
|
|
#define O_LARGEFILE 0
|
|
|
|
#endif
|
|
|
|
|
2002-01-09 08:37:02 +08:00
|
|
|
/* Function: child_pid_to_exec_file
|
|
|
|
*
|
|
|
|
* Accepts an integer pid
|
|
|
|
* Returns a string representing a file that can be opened
|
|
|
|
* to get the symbols for the child process.
|
|
|
|
*/
|
2002-01-09 06:09:50 +08:00
|
|
|
|
|
|
|
char *
|
|
|
|
child_pid_to_exec_file (int pid)
|
|
|
|
{
|
2002-01-09 10:21:25 +08:00
|
|
|
char *name1, *name2;
|
2002-01-09 06:09:50 +08:00
|
|
|
|
2002-01-09 10:21:25 +08:00
|
|
|
name1 = xmalloc (MAXPATHLEN);
|
|
|
|
name2 = xmalloc (MAXPATHLEN);
|
|
|
|
make_cleanup (xfree, name1);
|
|
|
|
make_cleanup (xfree, name2);
|
|
|
|
memset (name2, 0, MAXPATHLEN);
|
|
|
|
|
|
|
|
sprintf (name1, "/proc/%d/exe", pid);
|
|
|
|
if (readlink (name1, name2, MAXPATHLEN) > 0)
|
|
|
|
return name2;
|
|
|
|
else
|
|
|
|
return name1;
|
2002-01-09 06:09:50 +08:00
|
|
|
}
|
2002-01-09 08:37:02 +08:00
|
|
|
|
2002-01-16 04:10:55 +08:00
|
|
|
/* Function: read_mappings
|
|
|
|
*
|
|
|
|
* Service function for corefiles and info proc.
|
|
|
|
*/
|
|
|
|
|
2003-03-29 05:42:41 +08:00
|
|
|
static int
|
|
|
|
read_mapping (FILE *mapfile,
|
|
|
|
long long *addr,
|
|
|
|
long long *endaddr,
|
|
|
|
char *permissions,
|
|
|
|
long long *offset,
|
|
|
|
char *device, long long *inode, char *filename)
|
2002-01-16 04:10:55 +08:00
|
|
|
{
|
2003-03-29 05:42:41 +08:00
|
|
|
int ret = fscanf (mapfile, "%llx-%llx %s %llx %s %llx",
|
2002-01-16 04:10:55 +08:00
|
|
|
addr, endaddr, permissions, offset, device, inode);
|
|
|
|
|
|
|
|
if (ret > 0 && ret != EOF && *inode != 0)
|
|
|
|
{
|
2002-03-26 03:47:41 +08:00
|
|
|
/* Eat everything up to EOL for the filename. This will prevent
|
2003-03-29 05:42:41 +08:00
|
|
|
weird filenames (such as one with embedded whitespace) from
|
|
|
|
confusing this code. It also makes this code more robust
|
|
|
|
in respect to annotations the kernel may add after the
|
|
|
|
filename.
|
2002-03-26 03:47:41 +08:00
|
|
|
|
2003-03-29 05:42:41 +08:00
|
|
|
Note the filename is used for informational purposes only. */
|
2002-03-26 03:47:41 +08:00
|
|
|
ret += fscanf (mapfile, "%[^\n]\n", filename);
|
2002-01-16 04:10:55 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
filename[0] = '\0'; /* no filename */
|
|
|
|
fscanf (mapfile, "\n");
|
|
|
|
}
|
|
|
|
return (ret != 0 && ret != EOF);
|
|
|
|
}
|
|
|
|
|
2002-01-09 08:37:02 +08:00
|
|
|
/* Function: linux_find_memory_regions
|
|
|
|
*
|
|
|
|
* Fills the "to_find_memory_regions" target vector.
|
|
|
|
* Lists the memory regions in the inferior for a corefile.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
2003-03-29 05:42:41 +08:00
|
|
|
linux_find_memory_regions (int (*func) (CORE_ADDR,
|
2002-01-09 08:37:02 +08:00
|
|
|
unsigned long,
|
2003-03-29 05:42:41 +08:00
|
|
|
int, int, int, void *), void *obfd)
|
2002-01-09 08:37:02 +08:00
|
|
|
{
|
|
|
|
long long pid = PIDGET (inferior_ptid);
|
2002-01-16 04:10:55 +08:00
|
|
|
char mapsfilename[MAXPATHLEN];
|
|
|
|
FILE *mapsfile;
|
2002-01-09 08:37:02 +08:00
|
|
|
long long addr, endaddr, size, offset, inode;
|
2002-01-16 04:10:55 +08:00
|
|
|
char permissions[8], device[8], filename[MAXPATHLEN];
|
2002-01-09 08:37:02 +08:00
|
|
|
int read, write, exec;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Compose the filename for the /proc memory map, and open it. */
|
2002-01-16 04:10:55 +08:00
|
|
|
sprintf (mapsfilename, "/proc/%lld/maps", pid);
|
|
|
|
if ((mapsfile = fopen (mapsfilename, "r")) == NULL)
|
|
|
|
error ("Could not open %s\n", mapsfilename);
|
2002-01-09 08:37:02 +08:00
|
|
|
|
|
|
|
if (info_verbose)
|
2003-03-29 05:42:41 +08:00
|
|
|
fprintf_filtered (gdb_stdout,
|
2002-01-16 04:10:55 +08:00
|
|
|
"Reading memory regions from %s\n", mapsfilename);
|
2002-01-09 08:37:02 +08:00
|
|
|
|
|
|
|
/* Now iterate until end-of-file. */
|
2003-03-29 05:42:41 +08:00
|
|
|
while (read_mapping (mapsfile, &addr, &endaddr, &permissions[0],
|
2002-01-16 04:10:55 +08:00
|
|
|
&offset, &device[0], &inode, &filename[0]))
|
2002-01-09 08:37:02 +08:00
|
|
|
{
|
|
|
|
size = endaddr - addr;
|
|
|
|
|
|
|
|
/* Get the segment's permissions. */
|
2003-03-29 05:42:41 +08:00
|
|
|
read = (strchr (permissions, 'r') != 0);
|
2002-01-16 04:10:55 +08:00
|
|
|
write = (strchr (permissions, 'w') != 0);
|
2003-03-29 05:42:41 +08:00
|
|
|
exec = (strchr (permissions, 'x') != 0);
|
2002-01-09 08:37:02 +08:00
|
|
|
|
|
|
|
if (info_verbose)
|
|
|
|
{
|
2003-03-29 05:42:41 +08:00
|
|
|
fprintf_filtered (gdb_stdout,
|
|
|
|
"Save segment, %lld bytes at 0x%s (%c%c%c)",
|
|
|
|
size, paddr_nz (addr),
|
|
|
|
read ? 'r' : ' ',
|
|
|
|
write ? 'w' : ' ', exec ? 'x' : ' ');
|
2002-01-09 08:37:02 +08:00
|
|
|
if (filename && filename[0])
|
2003-03-29 05:42:41 +08:00
|
|
|
fprintf_filtered (gdb_stdout, " for %s", filename);
|
2002-01-09 08:37:02 +08:00
|
|
|
fprintf_filtered (gdb_stdout, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Invoke the callback function to create the corefile segment. */
|
|
|
|
func (addr, size, read, write, exec, obfd);
|
|
|
|
}
|
2002-01-16 04:10:55 +08:00
|
|
|
fclose (mapsfile);
|
2002-01-09 08:37:02 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Function: linux_do_thread_registers
|
|
|
|
*
|
|
|
|
* Records the thread's register state for the corefile note section.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static char *
|
2003-03-29 05:42:41 +08:00
|
|
|
linux_do_thread_registers (bfd *obfd, ptid_t ptid,
|
2002-01-09 08:37:02 +08:00
|
|
|
char *note_data, int *note_size)
|
|
|
|
{
|
|
|
|
gdb_gregset_t gregs;
|
|
|
|
gdb_fpregset_t fpregs;
|
2002-04-25 06:09:58 +08:00
|
|
|
#ifdef FILL_FPXREGSET
|
|
|
|
gdb_fpxregset_t fpxregs;
|
|
|
|
#endif
|
2003-06-20 06:52:04 +08:00
|
|
|
unsigned long lwp = ptid_get_lwp (ptid);
|
2002-01-09 08:37:02 +08:00
|
|
|
|
|
|
|
fill_gregset (&gregs, -1);
|
2003-03-29 05:42:41 +08:00
|
|
|
note_data = (char *) elfcore_write_prstatus (obfd,
|
|
|
|
note_data,
|
|
|
|
note_size,
|
2003-06-20 06:52:04 +08:00
|
|
|
lwp,
|
2003-03-29 05:42:41 +08:00
|
|
|
stop_signal, &gregs);
|
2002-01-09 08:37:02 +08:00
|
|
|
|
|
|
|
fill_fpregset (&fpregs, -1);
|
2003-03-29 05:42:41 +08:00
|
|
|
note_data = (char *) elfcore_write_prfpreg (obfd,
|
|
|
|
note_data,
|
|
|
|
note_size,
|
|
|
|
&fpregs, sizeof (fpregs));
|
2002-04-25 06:09:58 +08:00
|
|
|
#ifdef FILL_FPXREGSET
|
|
|
|
fill_fpxregset (&fpxregs, -1);
|
2003-03-29 05:42:41 +08:00
|
|
|
note_data = (char *) elfcore_write_prxfpreg (obfd,
|
|
|
|
note_data,
|
|
|
|
note_size,
|
|
|
|
&fpxregs, sizeof (fpxregs));
|
2002-04-25 06:09:58 +08:00
|
|
|
#endif
|
2002-01-09 08:37:02 +08:00
|
|
|
return note_data;
|
|
|
|
}
|
|
|
|
|
2002-08-24 03:06:05 +08:00
|
|
|
struct linux_corefile_thread_data
|
|
|
|
{
|
|
|
|
bfd *obfd;
|
2002-01-09 08:37:02 +08:00
|
|
|
char *note_data;
|
2002-08-24 03:06:05 +08:00
|
|
|
int *note_size;
|
|
|
|
int num_notes;
|
2002-01-09 08:37:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Function: linux_corefile_thread_callback
|
2004-02-02 06:35:15 +08:00
|
|
|
*
|
2002-01-09 08:37:02 +08:00
|
|
|
* Called by gdbthread.c once per thread.
|
|
|
|
* Records the thread's register state for the corefile note section.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
2003-06-20 06:52:04 +08:00
|
|
|
linux_corefile_thread_callback (struct lwp_info *ti, void *data)
|
2002-01-09 08:37:02 +08:00
|
|
|
{
|
|
|
|
struct linux_corefile_thread_data *args = data;
|
|
|
|
ptid_t saved_ptid = inferior_ptid;
|
|
|
|
|
|
|
|
inferior_ptid = ti->ptid;
|
|
|
|
registers_changed ();
|
2004-02-02 06:35:15 +08:00
|
|
|
target_fetch_registers (-1); /* FIXME should not be necessary;
|
2002-01-09 08:37:02 +08:00
|
|
|
fill_gregset should do it automatically. */
|
2003-03-29 05:42:41 +08:00
|
|
|
args->note_data = linux_do_thread_registers (args->obfd,
|
|
|
|
ti->ptid,
|
|
|
|
args->note_data,
|
2002-01-09 08:37:02 +08:00
|
|
|
args->note_size);
|
2002-08-24 03:06:05 +08:00
|
|
|
args->num_notes++;
|
2002-01-09 08:37:02 +08:00
|
|
|
inferior_ptid = saved_ptid;
|
|
|
|
registers_changed ();
|
2004-02-02 06:35:15 +08:00
|
|
|
target_fetch_registers (-1); /* FIXME should not be necessary;
|
2002-01-09 08:37:02 +08:00
|
|
|
fill_gregset should do it automatically. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-10-02 04:36:56 +08:00
|
|
|
/* Function: linux_do_registers
|
2004-02-02 06:35:15 +08:00
|
|
|
*
|
2003-10-02 04:36:56 +08:00
|
|
|
* Records the register state for the corefile note section.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static char *
|
|
|
|
linux_do_registers (bfd *obfd, ptid_t ptid,
|
|
|
|
char *note_data, int *note_size)
|
|
|
|
{
|
|
|
|
registers_changed ();
|
2004-02-02 06:35:15 +08:00
|
|
|
target_fetch_registers (-1); /* FIXME should not be necessary;
|
2003-10-02 04:36:56 +08:00
|
|
|
fill_gregset should do it automatically. */
|
|
|
|
return linux_do_thread_registers (obfd,
|
|
|
|
ptid_build (ptid_get_pid (inferior_ptid),
|
|
|
|
ptid_get_pid (inferior_ptid),
|
|
|
|
0),
|
|
|
|
note_data, note_size);
|
|
|
|
return note_data;
|
|
|
|
}
|
|
|
|
|
2002-01-09 08:37:02 +08:00
|
|
|
/* Function: linux_make_note_section
|
|
|
|
*
|
|
|
|
* Fills the "to_make_corefile_note" target vector.
|
2004-02-02 06:35:15 +08:00
|
|
|
* Builds the note section for a corefile, and returns it
|
|
|
|
* in a malloc buffer.
|
2002-01-09 08:37:02 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
static char *
|
|
|
|
linux_make_note_section (bfd *obfd, int *note_size)
|
|
|
|
{
|
|
|
|
struct linux_corefile_thread_data thread_args;
|
|
|
|
struct cleanup *old_chain;
|
2003-03-29 05:42:41 +08:00
|
|
|
char fname[16] = { '\0' };
|
|
|
|
char psargs[80] = { '\0' };
|
2002-01-09 08:37:02 +08:00
|
|
|
char *note_data = NULL;
|
|
|
|
ptid_t current_ptid = inferior_ptid;
|
2004-02-02 06:35:15 +08:00
|
|
|
char *auxv;
|
|
|
|
int auxv_len;
|
2002-01-09 08:37:02 +08:00
|
|
|
|
|
|
|
if (get_exec_file (0))
|
|
|
|
{
|
|
|
|
strncpy (fname, strrchr (get_exec_file (0), '/') + 1, sizeof (fname));
|
2003-03-29 05:42:41 +08:00
|
|
|
strncpy (psargs, get_exec_file (0), sizeof (psargs));
|
2002-01-09 08:37:02 +08:00
|
|
|
if (get_inferior_args ())
|
|
|
|
{
|
2003-03-29 05:42:41 +08:00
|
|
|
strncat (psargs, " ", sizeof (psargs) - strlen (psargs));
|
|
|
|
strncat (psargs, get_inferior_args (),
|
2002-01-09 08:37:02 +08:00
|
|
|
sizeof (psargs) - strlen (psargs));
|
|
|
|
}
|
2003-03-29 05:42:41 +08:00
|
|
|
note_data = (char *) elfcore_write_prpsinfo (obfd,
|
|
|
|
note_data,
|
|
|
|
note_size, fname, psargs);
|
2002-01-09 08:37:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Dump information for threads. */
|
|
|
|
thread_args.obfd = obfd;
|
|
|
|
thread_args.note_data = note_data;
|
|
|
|
thread_args.note_size = note_size;
|
2002-08-24 03:06:05 +08:00
|
|
|
thread_args.num_notes = 0;
|
2003-06-20 06:52:04 +08:00
|
|
|
iterate_over_lwps (linux_corefile_thread_callback, &thread_args);
|
2002-08-24 03:06:05 +08:00
|
|
|
if (thread_args.num_notes == 0)
|
2002-01-09 08:37:02 +08:00
|
|
|
{
|
|
|
|
/* iterate_over_threads didn't come up with any threads;
|
2003-03-29 05:42:41 +08:00
|
|
|
just use inferior_ptid. */
|
2003-10-02 04:36:56 +08:00
|
|
|
note_data = linux_do_registers (obfd, inferior_ptid,
|
|
|
|
note_data, note_size);
|
2002-01-09 08:37:02 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
note_data = thread_args.note_data;
|
|
|
|
}
|
|
|
|
|
2004-02-02 06:35:15 +08:00
|
|
|
auxv_len = target_auxv_read (¤t_target, &auxv);
|
|
|
|
if (auxv_len > 0)
|
|
|
|
{
|
|
|
|
note_data = elfcore_write_note (obfd, note_data, note_size,
|
|
|
|
"CORE", NT_AUXV, auxv, auxv_len);
|
|
|
|
xfree (auxv);
|
|
|
|
}
|
|
|
|
|
2002-01-09 08:37:02 +08:00
|
|
|
make_cleanup (xfree, note_data);
|
|
|
|
return note_data;
|
|
|
|
}
|
|
|
|
|
2002-01-16 04:10:55 +08:00
|
|
|
/*
|
|
|
|
* Function: linux_info_proc_cmd
|
|
|
|
*
|
|
|
|
* Implement the "info proc" command.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
linux_info_proc_cmd (char *args, int from_tty)
|
|
|
|
{
|
|
|
|
long long pid = PIDGET (inferior_ptid);
|
|
|
|
FILE *procfile;
|
|
|
|
char **argv = NULL;
|
|
|
|
char buffer[MAXPATHLEN];
|
|
|
|
char fname1[MAXPATHLEN], fname2[MAXPATHLEN];
|
|
|
|
int cmdline_f = 1;
|
|
|
|
int cwd_f = 1;
|
|
|
|
int exe_f = 1;
|
|
|
|
int mappings_f = 0;
|
|
|
|
int environ_f = 0;
|
|
|
|
int status_f = 0;
|
|
|
|
int stat_f = 0;
|
|
|
|
int all = 0;
|
|
|
|
struct stat dummy;
|
|
|
|
|
|
|
|
if (args)
|
|
|
|
{
|
|
|
|
/* Break up 'args' into an argv array. */
|
|
|
|
if ((argv = buildargv (args)) == NULL)
|
|
|
|
nomem (0);
|
|
|
|
else
|
|
|
|
make_cleanup_freeargv (argv);
|
|
|
|
}
|
|
|
|
while (argv != NULL && *argv != NULL)
|
|
|
|
{
|
|
|
|
if (isdigit (argv[0][0]))
|
|
|
|
{
|
|
|
|
pid = strtoul (argv[0], NULL, 10);
|
|
|
|
}
|
|
|
|
else if (strncmp (argv[0], "mappings", strlen (argv[0])) == 0)
|
|
|
|
{
|
|
|
|
mappings_f = 1;
|
|
|
|
}
|
|
|
|
else if (strcmp (argv[0], "status") == 0)
|
|
|
|
{
|
|
|
|
status_f = 1;
|
|
|
|
}
|
|
|
|
else if (strcmp (argv[0], "stat") == 0)
|
|
|
|
{
|
|
|
|
stat_f = 1;
|
|
|
|
}
|
|
|
|
else if (strcmp (argv[0], "cmd") == 0)
|
|
|
|
{
|
|
|
|
cmdline_f = 1;
|
|
|
|
}
|
|
|
|
else if (strncmp (argv[0], "exe", strlen (argv[0])) == 0)
|
|
|
|
{
|
|
|
|
exe_f = 1;
|
|
|
|
}
|
|
|
|
else if (strcmp (argv[0], "cwd") == 0)
|
|
|
|
{
|
|
|
|
cwd_f = 1;
|
|
|
|
}
|
|
|
|
else if (strncmp (argv[0], "all", strlen (argv[0])) == 0)
|
|
|
|
{
|
|
|
|
all = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* [...] (future options here) */
|
|
|
|
}
|
|
|
|
argv++;
|
|
|
|
}
|
|
|
|
if (pid == 0)
|
|
|
|
error ("No current process: you must name one.");
|
|
|
|
|
|
|
|
sprintf (fname1, "/proc/%lld", pid);
|
|
|
|
if (stat (fname1, &dummy) != 0)
|
|
|
|
error ("No /proc directory: '%s'", fname1);
|
|
|
|
|
|
|
|
printf_filtered ("process %lld\n", pid);
|
|
|
|
if (cmdline_f || all)
|
|
|
|
{
|
|
|
|
sprintf (fname1, "/proc/%lld/cmdline", pid);
|
|
|
|
if ((procfile = fopen (fname1, "r")) > 0)
|
|
|
|
{
|
|
|
|
fgets (buffer, sizeof (buffer), procfile);
|
|
|
|
printf_filtered ("cmdline = '%s'\n", buffer);
|
|
|
|
fclose (procfile);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
warning ("unable to open /proc file '%s'", fname1);
|
|
|
|
}
|
|
|
|
if (cwd_f || all)
|
|
|
|
{
|
|
|
|
sprintf (fname1, "/proc/%lld/cwd", pid);
|
|
|
|
memset (fname2, 0, sizeof (fname2));
|
|
|
|
if (readlink (fname1, fname2, sizeof (fname2)) > 0)
|
|
|
|
printf_filtered ("cwd = '%s'\n", fname2);
|
|
|
|
else
|
|
|
|
warning ("unable to read link '%s'", fname1);
|
|
|
|
}
|
|
|
|
if (exe_f || all)
|
|
|
|
{
|
|
|
|
sprintf (fname1, "/proc/%lld/exe", pid);
|
|
|
|
memset (fname2, 0, sizeof (fname2));
|
|
|
|
if (readlink (fname1, fname2, sizeof (fname2)) > 0)
|
|
|
|
printf_filtered ("exe = '%s'\n", fname2);
|
|
|
|
else
|
|
|
|
warning ("unable to read link '%s'", fname1);
|
|
|
|
}
|
|
|
|
if (mappings_f || all)
|
|
|
|
{
|
|
|
|
sprintf (fname1, "/proc/%lld/maps", pid);
|
|
|
|
if ((procfile = fopen (fname1, "r")) > 0)
|
|
|
|
{
|
|
|
|
long long addr, endaddr, size, offset, inode;
|
|
|
|
char permissions[8], device[8], filename[MAXPATHLEN];
|
|
|
|
|
2003-08-27 23:41:41 +08:00
|
|
|
printf_filtered ("Mapped address spaces:\n\n");
|
2002-01-16 04:10:55 +08:00
|
|
|
if (TARGET_ADDR_BIT == 32)
|
|
|
|
{
|
2003-08-27 23:41:41 +08:00
|
|
|
printf_filtered ("\t%10s %10s %10s %10s %7s\n",
|
|
|
|
"Start Addr",
|
|
|
|
" End Addr",
|
|
|
|
" Size", " Offset", "objfile");
|
|
|
|
}
|
2002-01-16 04:10:55 +08:00
|
|
|
else
|
2003-08-27 23:41:41 +08:00
|
|
|
{
|
|
|
|
printf_filtered (" %18s %18s %10s %10s %7s\n",
|
2002-01-16 04:10:55 +08:00
|
|
|
"Start Addr",
|
|
|
|
" End Addr",
|
2003-03-29 05:42:41 +08:00
|
|
|
" Size", " Offset", "objfile");
|
2003-08-27 23:41:41 +08:00
|
|
|
}
|
2003-03-29 05:42:41 +08:00
|
|
|
|
|
|
|
while (read_mapping (procfile, &addr, &endaddr, &permissions[0],
|
2002-01-16 04:10:55 +08:00
|
|
|
&offset, &device[0], &inode, &filename[0]))
|
|
|
|
{
|
|
|
|
size = endaddr - addr;
|
2003-08-27 23:41:41 +08:00
|
|
|
|
|
|
|
/* FIXME: carlton/2003-08-27: Maybe the printf_filtered
|
|
|
|
calls here (and possibly above) should be abstracted
|
|
|
|
out into their own functions? Andrew suggests using
|
|
|
|
a generic local_address_string instead to print out
|
|
|
|
the addresses; that makes sense to me, too. */
|
|
|
|
|
|
|
|
if (TARGET_ADDR_BIT == 32)
|
|
|
|
{
|
|
|
|
printf_filtered ("\t%#10lx %#10lx %#10x %#10x %7s\n",
|
|
|
|
(unsigned long) addr, /* FIXME: pr_addr */
|
2003-03-29 05:42:41 +08:00
|
|
|
(unsigned long) endaddr,
|
|
|
|
(int) size,
|
|
|
|
(unsigned int) offset,
|
2002-01-16 04:10:55 +08:00
|
|
|
filename[0] ? filename : "");
|
2003-08-27 23:41:41 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf_filtered (" %#18lx %#18lx %#10x %#10x %7s\n",
|
|
|
|
(unsigned long) addr, /* FIXME: pr_addr */
|
|
|
|
(unsigned long) endaddr,
|
|
|
|
(int) size,
|
|
|
|
(unsigned int) offset,
|
|
|
|
filename[0] ? filename : "");
|
|
|
|
}
|
2002-01-16 04:10:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose (procfile);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
warning ("unable to open /proc file '%s'", fname1);
|
|
|
|
}
|
|
|
|
if (status_f || all)
|
|
|
|
{
|
|
|
|
sprintf (fname1, "/proc/%lld/status", pid);
|
|
|
|
if ((procfile = fopen (fname1, "r")) > 0)
|
|
|
|
{
|
|
|
|
while (fgets (buffer, sizeof (buffer), procfile) != NULL)
|
2003-08-04 David Carlton <carlton@kealia.com>
* charset.c (cached_iconv_convert): Add __FILE__ and __LINE__ args
to internal_error call.
* source.c (forward_search_command): Add "%s" format argument.
(reverse_search_command): Ditto.
* top.c (quit_confirm): Ditto.
* cli/cli-setshow.c (do_setshow_command): Ditto.
* cp-valprint.c (cp_print_class_method): Replace
{f,}printf_{un,}filtered by {f,}puts_{un,}filtered.
(cp_print_class_member): Ditto.
* event-top.c (command_line_handler): Ditto.
* linux-proc.c (linux_info_proc_cmd): Ditto.
* p-typeprint.c (pascal_type_print_base): Ditto.
* p-valprint.c (pascal_object_print_class_method): Ditto.
(pascal_object_print_class_member): Ditto.
* printcmd.c (print_scalar_formatted,printf_command): Ditto.
* remote.c (remote_cisco_section_offsets): Ditto.
* top.c (command_line_input): Ditto.
* utils.c (vwarning,error_stream,quit): Ditto.
* valprint.c (print_floating,print_binary_chars)
(print_octal_chars,print_decimal_chars,print_hex_chars): Ditto.
2003-08-04 David Carlton <carlton@kealia.com>
* mi-main.c (mi_error_last_message): Add "%s" second argument to
xasprintf call.
2003-08-04 David Carlton <carlton@kealia.com>
* generic/gdbtk.c (gdbtk_source_start_file): Add "%s" first
argument to error call.
(tk_command): Ditto.
(view_command): Ditto.
2003-08-05 01:08:24 +08:00
|
|
|
puts_filtered (buffer);
|
2002-01-16 04:10:55 +08:00
|
|
|
fclose (procfile);
|
|
|
|
}
|
2003-03-29 05:42:41 +08:00
|
|
|
else
|
2002-01-16 04:10:55 +08:00
|
|
|
warning ("unable to open /proc file '%s'", fname1);
|
|
|
|
}
|
|
|
|
if (stat_f || all)
|
|
|
|
{
|
|
|
|
sprintf (fname1, "/proc/%lld/stat", pid);
|
|
|
|
if ((procfile = fopen (fname1, "r")) > 0)
|
|
|
|
{
|
|
|
|
int itmp;
|
|
|
|
char ctmp;
|
|
|
|
|
|
|
|
if (fscanf (procfile, "%d ", &itmp) > 0)
|
|
|
|
printf_filtered ("Process: %d\n", itmp);
|
|
|
|
if (fscanf (procfile, "%s ", &buffer[0]) > 0)
|
|
|
|
printf_filtered ("Exec file: %s\n", buffer);
|
|
|
|
if (fscanf (procfile, "%c ", &ctmp) > 0)
|
|
|
|
printf_filtered ("State: %c\n", ctmp);
|
|
|
|
if (fscanf (procfile, "%d ", &itmp) > 0)
|
|
|
|
printf_filtered ("Parent process: %d\n", itmp);
|
|
|
|
if (fscanf (procfile, "%d ", &itmp) > 0)
|
|
|
|
printf_filtered ("Process group: %d\n", itmp);
|
|
|
|
if (fscanf (procfile, "%d ", &itmp) > 0)
|
|
|
|
printf_filtered ("Session id: %d\n", itmp);
|
|
|
|
if (fscanf (procfile, "%d ", &itmp) > 0)
|
|
|
|
printf_filtered ("TTY: %d\n", itmp);
|
|
|
|
if (fscanf (procfile, "%d ", &itmp) > 0)
|
|
|
|
printf_filtered ("TTY owner process group: %d\n", itmp);
|
|
|
|
if (fscanf (procfile, "%u ", &itmp) > 0)
|
|
|
|
printf_filtered ("Flags: 0x%x\n", itmp);
|
|
|
|
if (fscanf (procfile, "%u ", &itmp) > 0)
|
2003-03-29 05:42:41 +08:00
|
|
|
printf_filtered ("Minor faults (no memory page): %u\n",
|
2002-01-16 04:10:55 +08:00
|
|
|
(unsigned int) itmp);
|
|
|
|
if (fscanf (procfile, "%u ", &itmp) > 0)
|
2003-03-29 05:42:41 +08:00
|
|
|
printf_filtered ("Minor faults, children: %u\n",
|
2002-01-16 04:10:55 +08:00
|
|
|
(unsigned int) itmp);
|
|
|
|
if (fscanf (procfile, "%u ", &itmp) > 0)
|
2003-03-29 05:42:41 +08:00
|
|
|
printf_filtered ("Major faults (memory page faults): %u\n",
|
2002-01-16 04:10:55 +08:00
|
|
|
(unsigned int) itmp);
|
|
|
|
if (fscanf (procfile, "%u ", &itmp) > 0)
|
2003-03-29 05:42:41 +08:00
|
|
|
printf_filtered ("Major faults, children: %u\n",
|
2002-01-16 04:10:55 +08:00
|
|
|
(unsigned int) itmp);
|
|
|
|
if (fscanf (procfile, "%d ", &itmp) > 0)
|
|
|
|
printf_filtered ("utime: %d\n", itmp);
|
|
|
|
if (fscanf (procfile, "%d ", &itmp) > 0)
|
|
|
|
printf_filtered ("stime: %d\n", itmp);
|
|
|
|
if (fscanf (procfile, "%d ", &itmp) > 0)
|
|
|
|
printf_filtered ("utime, children: %d\n", itmp);
|
|
|
|
if (fscanf (procfile, "%d ", &itmp) > 0)
|
|
|
|
printf_filtered ("stime, children: %d\n", itmp);
|
|
|
|
if (fscanf (procfile, "%d ", &itmp) > 0)
|
2003-03-29 05:42:41 +08:00
|
|
|
printf_filtered ("jiffies remaining in current time slice: %d\n",
|
2002-01-16 04:10:55 +08:00
|
|
|
itmp);
|
|
|
|
if (fscanf (procfile, "%d ", &itmp) > 0)
|
|
|
|
printf_filtered ("'nice' value: %d\n", itmp);
|
|
|
|
if (fscanf (procfile, "%u ", &itmp) > 0)
|
2003-03-29 05:42:41 +08:00
|
|
|
printf_filtered ("jiffies until next timeout: %u\n",
|
2002-01-16 04:10:55 +08:00
|
|
|
(unsigned int) itmp);
|
|
|
|
if (fscanf (procfile, "%u ", &itmp) > 0)
|
2003-03-29 05:42:41 +08:00
|
|
|
printf_filtered ("jiffies until next SIGALRM: %u\n",
|
2002-01-16 04:10:55 +08:00
|
|
|
(unsigned int) itmp);
|
|
|
|
if (fscanf (procfile, "%d ", &itmp) > 0)
|
2003-03-29 05:42:41 +08:00
|
|
|
printf_filtered ("start time (jiffies since system boot): %d\n",
|
2002-01-16 04:10:55 +08:00
|
|
|
itmp);
|
|
|
|
if (fscanf (procfile, "%u ", &itmp) > 0)
|
2003-03-29 05:42:41 +08:00
|
|
|
printf_filtered ("Virtual memory size: %u\n",
|
2002-01-16 04:10:55 +08:00
|
|
|
(unsigned int) itmp);
|
|
|
|
if (fscanf (procfile, "%u ", &itmp) > 0)
|
2003-03-29 05:42:41 +08:00
|
|
|
printf_filtered ("Resident set size: %u\n", (unsigned int) itmp);
|
2002-01-16 04:10:55 +08:00
|
|
|
if (fscanf (procfile, "%u ", &itmp) > 0)
|
2003-03-29 05:42:41 +08:00
|
|
|
printf_filtered ("rlim: %u\n", (unsigned int) itmp);
|
2002-01-16 04:10:55 +08:00
|
|
|
if (fscanf (procfile, "%u ", &itmp) > 0)
|
|
|
|
printf_filtered ("Start of text: 0x%x\n", itmp);
|
|
|
|
if (fscanf (procfile, "%u ", &itmp) > 0)
|
|
|
|
printf_filtered ("End of text: 0x%x\n", itmp);
|
|
|
|
if (fscanf (procfile, "%u ", &itmp) > 0)
|
|
|
|
printf_filtered ("Start of stack: 0x%x\n", itmp);
|
2004-02-02 06:35:15 +08:00
|
|
|
#if 0 /* Don't know how architecture-dependent the rest is...
|
2003-03-29 05:42:41 +08:00
|
|
|
Anyway the signal bitmap info is available from "status". */
|
2002-01-16 04:10:55 +08:00
|
|
|
if (fscanf (procfile, "%u ", &itmp) > 0) /* FIXME arch? */
|
|
|
|
printf_filtered ("Kernel stack pointer: 0x%x\n", itmp);
|
|
|
|
if (fscanf (procfile, "%u ", &itmp) > 0) /* FIXME arch? */
|
|
|
|
printf_filtered ("Kernel instr pointer: 0x%x\n", itmp);
|
|
|
|
if (fscanf (procfile, "%d ", &itmp) > 0)
|
|
|
|
printf_filtered ("Pending signals bitmap: 0x%x\n", itmp);
|
|
|
|
if (fscanf (procfile, "%d ", &itmp) > 0)
|
|
|
|
printf_filtered ("Blocked signals bitmap: 0x%x\n", itmp);
|
|
|
|
if (fscanf (procfile, "%d ", &itmp) > 0)
|
|
|
|
printf_filtered ("Ignored signals bitmap: 0x%x\n", itmp);
|
|
|
|
if (fscanf (procfile, "%d ", &itmp) > 0)
|
|
|
|
printf_filtered ("Catched signals bitmap: 0x%x\n", itmp);
|
|
|
|
if (fscanf (procfile, "%u ", &itmp) > 0) /* FIXME arch? */
|
|
|
|
printf_filtered ("wchan (system call): 0x%x\n", itmp);
|
|
|
|
#endif
|
|
|
|
fclose (procfile);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
warning ("unable to open /proc file '%s'", fname1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-09 08:37:02 +08:00
|
|
|
void
|
|
|
|
_initialize_linux_proc (void)
|
|
|
|
{
|
|
|
|
extern void inftarg_set_find_memory_regions ();
|
|
|
|
extern void inftarg_set_make_corefile_notes ();
|
|
|
|
|
|
|
|
inftarg_set_find_memory_regions (linux_find_memory_regions);
|
|
|
|
inftarg_set_make_corefile_notes (linux_make_note_section);
|
2002-01-16 04:10:55 +08:00
|
|
|
|
2003-03-29 05:42:41 +08:00
|
|
|
add_info ("proc", linux_info_proc_cmd,
|
2002-01-16 04:10:55 +08:00
|
|
|
"Show /proc process information about any running process.\n\
|
|
|
|
Specify any process id, or use the program being debugged by default.\n\
|
|
|
|
Specify any of the following keywords for detailed info:\n\
|
|
|
|
mappings -- list of mapped memory regions.\n\
|
|
|
|
stat -- list a bunch of random process info.\n\
|
|
|
|
status -- list a different bunch of random process info.\n\
|
|
|
|
all -- list all available /proc info.");
|
2002-01-09 08:37:02 +08:00
|
|
|
}
|
2002-11-26 09:23:46 +08:00
|
|
|
|
2003-03-29 05:42:41 +08:00
|
|
|
int
|
|
|
|
linux_proc_xfer_memory (CORE_ADDR addr, char *myaddr, int len, int write,
|
|
|
|
struct mem_attrib *attrib, struct target_ops *target)
|
2002-11-26 09:23:46 +08:00
|
|
|
{
|
|
|
|
int fd, ret;
|
|
|
|
char filename[64];
|
|
|
|
|
|
|
|
if (write)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Don't bother for one word. */
|
|
|
|
if (len < 3 * sizeof (long))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* We could keep this file open and cache it - possibly one
|
|
|
|
per thread. That requires some juggling, but is even faster. */
|
|
|
|
sprintf (filename, "/proc/%d/mem", PIDGET (inferior_ptid));
|
|
|
|
fd = open (filename, O_RDONLY | O_LARGEFILE);
|
|
|
|
if (fd == -1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* If pread64 is available, use it. It's faster if the kernel
|
|
|
|
supports it (only one syscall), and it's 64-bit safe even
|
|
|
|
on 32-bit platforms (for instance, SPARC debugging a SPARC64
|
2003-08-24 21:34:01 +08:00
|
|
|
application). */
|
2002-11-26 09:23:46 +08:00
|
|
|
#ifdef HAVE_PREAD64
|
|
|
|
if (pread64 (fd, myaddr, len, addr) != len)
|
|
|
|
#else
|
2003-03-29 05:42:41 +08:00
|
|
|
if (lseek (fd, addr, SEEK_SET) == -1 || read (fd, myaddr, len) != len)
|
2002-11-26 09:23:46 +08:00
|
|
|
#endif
|
|
|
|
ret = 0;
|
|
|
|
else
|
|
|
|
ret = len;
|
|
|
|
|
|
|
|
close (fd);
|
|
|
|
return ret;
|
|
|
|
}
|
2003-09-08 02:49:44 +08:00
|
|
|
|
|
|
|
/* Parse LINE as a signal set and add its set bits to SIGS. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
linux_proc_add_line_to_sigset (const char *line, sigset_t *sigs)
|
|
|
|
{
|
|
|
|
int len = strlen (line) - 1;
|
|
|
|
const char *p;
|
|
|
|
int signum;
|
|
|
|
|
|
|
|
if (line[len] != '\n')
|
|
|
|
error ("Could not parse signal set: %s", line);
|
|
|
|
|
|
|
|
p = line;
|
|
|
|
signum = len * 4;
|
|
|
|
while (len-- > 0)
|
|
|
|
{
|
|
|
|
int digit;
|
|
|
|
|
|
|
|
if (*p >= '0' && *p <= '9')
|
|
|
|
digit = *p - '0';
|
|
|
|
else if (*p >= 'a' && *p <= 'f')
|
|
|
|
digit = *p - 'a' + 10;
|
|
|
|
else
|
|
|
|
error ("Could not parse signal set: %s", line);
|
|
|
|
|
|
|
|
signum -= 4;
|
|
|
|
|
|
|
|
if (digit & 1)
|
|
|
|
sigaddset (sigs, signum + 1);
|
|
|
|
if (digit & 2)
|
|
|
|
sigaddset (sigs, signum + 2);
|
|
|
|
if (digit & 4)
|
|
|
|
sigaddset (sigs, signum + 3);
|
|
|
|
if (digit & 8)
|
|
|
|
sigaddset (sigs, signum + 4);
|
|
|
|
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find process PID's pending signals from /proc/pid/status and set SIGS
|
|
|
|
to match. */
|
|
|
|
|
|
|
|
void
|
|
|
|
linux_proc_pending_signals (int pid, sigset_t *pending, sigset_t *blocked, sigset_t *ignored)
|
|
|
|
{
|
|
|
|
FILE *procfile;
|
|
|
|
char buffer[MAXPATHLEN], fname[MAXPATHLEN];
|
|
|
|
int signum;
|
|
|
|
|
|
|
|
sigemptyset (pending);
|
|
|
|
sigemptyset (blocked);
|
|
|
|
sigemptyset (ignored);
|
|
|
|
sprintf (fname, "/proc/%d/status", pid);
|
|
|
|
procfile = fopen (fname, "r");
|
|
|
|
if (procfile == NULL)
|
|
|
|
error ("Could not open %s", fname);
|
|
|
|
|
|
|
|
while (fgets (buffer, MAXPATHLEN, procfile) != NULL)
|
|
|
|
{
|
|
|
|
/* Normal queued signals are on the SigPnd line in the status
|
|
|
|
file. However, 2.6 kernels also have a "shared" pending queue
|
|
|
|
for delivering signals to a thread group, so check for a ShdPnd
|
|
|
|
line also.
|
|
|
|
|
|
|
|
Unfortunately some Red Hat kernels include the shared pending queue
|
|
|
|
but not the ShdPnd status field. */
|
|
|
|
|
|
|
|
if (strncmp (buffer, "SigPnd:\t", 8) == 0)
|
|
|
|
linux_proc_add_line_to_sigset (buffer + 8, pending);
|
|
|
|
else if (strncmp (buffer, "ShdPnd:\t", 8) == 0)
|
|
|
|
linux_proc_add_line_to_sigset (buffer + 8, pending);
|
|
|
|
else if (strncmp (buffer, "SigBlk:\t", 8) == 0)
|
|
|
|
linux_proc_add_line_to_sigset (buffer + 8, blocked);
|
|
|
|
else if (strncmp (buffer, "SigIgn:\t", 8) == 0)
|
|
|
|
linux_proc_add_line_to_sigset (buffer + 8, ignored);
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose (procfile);
|
|
|
|
}
|