- struct linux_nat_corefile_thread_data *args = data;
-
- args->note_data = linux_nat_do_thread_registers (args->obfd,
- ti->ptid,
- args->note_data,
- args->note_size,
- args->stop_signal);
- args->num_notes++;
-
- return 0;
-}
-
-/* Enumerate spufs IDs for process PID. */
-
-static void
-iterate_over_spus (int pid, void (*callback) (void *, int), void *data)
-{
- char path[128];
- DIR *dir;
- struct dirent *entry;
-
- xsnprintf (path, sizeof path, "/proc/%d/fd", pid);
- dir = opendir (path);
- if (!dir)
- return;
-
- rewinddir (dir);
- while ((entry = readdir (dir)) != NULL)
- {
- struct stat st;
- struct statfs stfs;
- int fd;
-
- fd = atoi (entry->d_name);
- if (!fd)
- continue;
-
- xsnprintf (path, sizeof path, "/proc/%d/fd/%d", pid, fd);
- if (stat (path, &st) != 0)
- continue;
- if (!S_ISDIR (st.st_mode))
- continue;
-
- if (statfs (path, &stfs) != 0)
- continue;
- if (stfs.f_type != SPUFS_MAGIC)
- continue;
-
- callback (data, fd);
- }
-
- closedir (dir);
-}
-
-/* Generate corefile notes for SPU contexts. */
-
-struct linux_spu_corefile_data
-{
- bfd *obfd;
- char *note_data;
- int *note_size;
-};
-
-static void
-linux_spu_corefile_callback (void *data, int fd)
-{
- struct linux_spu_corefile_data *args = data;
- int i;
-
- static const char *spu_files[] =
- {
- "object-id",
- "mem",
- "regs",
- "fpcr",
- "lslr",
- "decr",
- "decr_status",
- "signal1",
- "signal1_type",
- "signal2",
- "signal2_type",
- "event_mask",
- "event_status",
- "mbox_info",
- "ibox_info",
- "wbox_info",
- "dma_info",
- "proxydma_info",
- };
-
- for (i = 0; i < sizeof (spu_files) / sizeof (spu_files[0]); i++)
- {
- char annex[32], note_name[32];
- gdb_byte *spu_data;
- LONGEST spu_len;
-
- xsnprintf (annex, sizeof annex, "%d/%s", fd, spu_files[i]);
- spu_len = target_read_alloc (¤t_target, TARGET_OBJECT_SPU,
- annex, &spu_data);
- if (spu_len > 0)
- {
- xsnprintf (note_name, sizeof note_name, "SPU/%s", annex);
- args->note_data = elfcore_write_note (args->obfd, args->note_data,
- args->note_size, note_name,
- NT_SPU, spu_data, spu_len);
- xfree (spu_data);
- }
- }
-}
-
-static char *
-linux_spu_make_corefile_notes (bfd *obfd, char *note_data, int *note_size)
-{
- struct linux_spu_corefile_data args;
-
- args.obfd = obfd;
- args.note_data = note_data;
- args.note_size = note_size;
-
- iterate_over_spus (PIDGET (inferior_ptid),
- linux_spu_corefile_callback, &args);
-
- return args.note_data;
-}
-
-/* Fills the "to_make_corefile_note" target vector. Builds the note
- section for a corefile, and returns it in a malloc buffer. */
-
-static char *
-linux_nat_make_corefile_notes (bfd *obfd, int *note_size)
-{
- struct linux_nat_corefile_thread_data thread_args;
- /* The variable size must be >= sizeof (prpsinfo_t.pr_fname). */
- char fname[16] = { '\0' };
- /* The variable size must be >= sizeof (prpsinfo_t.pr_psargs). */
- char psargs[80] = { '\0' };
- char *note_data = NULL;
- ptid_t filter = pid_to_ptid (ptid_get_pid (inferior_ptid));
- gdb_byte *auxv;
- int auxv_len;
-
- if (get_exec_file (0))
- {
- strncpy (fname, lbasename (get_exec_file (0)), sizeof (fname));
- strncpy (psargs, get_exec_file (0), sizeof (psargs));
- if (get_inferior_args ())
- {
- char *string_end;
- char *psargs_end = psargs + sizeof (psargs);
-
- /* linux_elfcore_write_prpsinfo () handles zero unterminated
- strings fine. */
- string_end = memchr (psargs, 0, sizeof (psargs));
- if (string_end != NULL)
- {
- *string_end++ = ' ';
- strncpy (string_end, get_inferior_args (),
- psargs_end - string_end);
- }
- }
- note_data = (char *) elfcore_write_prpsinfo (obfd,
- note_data,
- note_size, fname, psargs);
- }
-
- /* Dump information for threads. */
- thread_args.obfd = obfd;
- thread_args.note_data = note_data;
- thread_args.note_size = note_size;
- thread_args.num_notes = 0;
- thread_args.stop_signal = find_stop_signal ();
- iterate_over_lwps (filter, linux_nat_corefile_thread_callback, &thread_args);
- gdb_assert (thread_args.num_notes != 0);
- note_data = thread_args.note_data;
-
- auxv_len = target_read_alloc (¤t_target, TARGET_OBJECT_AUXV,
- NULL, &auxv);
- if (auxv_len > 0)
- {
- note_data = elfcore_write_note (obfd, note_data, note_size,
- "CORE", NT_AUXV, auxv, auxv_len);
- xfree (auxv);
- }
-
- note_data = linux_spu_make_corefile_notes (obfd, note_data, note_size);
-
- make_cleanup (xfree, note_data);
- return note_data;
-}
-
-/* Implement the "info proc" command. */
-
-static void
-linux_nat_info_proc_cmd (char *args, int from_tty)
-{
- /* A long is used for pid instead of an int to avoid a loss of precision
- compiler warning from the output of strtoul. */
- 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 status_f = 0;
- int stat_f = 0;
- int all = 0;
- struct stat dummy;
-
- if (args)
- {
- /* Break up 'args' into an argv array. */
- argv = gdb_buildargv (args);
- 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/%ld", pid);
- if (stat (fname1, &dummy) != 0)
- error (_("No /proc directory: '%s'"), fname1);
-
- printf_filtered (_("process %ld\n"), pid);
- if (cmdline_f || all)
- {
- sprintf (fname1, "/proc/%ld/cmdline", pid);
- if ((procfile = fopen (fname1, "r")) != NULL)
- {
- struct cleanup *cleanup = make_cleanup_fclose (procfile);
-
- if (fgets (buffer, sizeof (buffer), procfile))
- printf_filtered ("cmdline = '%s'\n", buffer);
- else
- warning (_("unable to read '%s'"), fname1);
- do_cleanups (cleanup);
- }
- else
- warning (_("unable to open /proc file '%s'"), fname1);
- }
- if (cwd_f || all)
- {
- sprintf (fname1, "/proc/%ld/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/%ld/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/%ld/maps", pid);
- if ((procfile = fopen (fname1, "r")) != NULL)
- {
- long long addr, endaddr, size, offset, inode;
- char permissions[8], device[8], filename[MAXPATHLEN];
- struct cleanup *cleanup;
-
- cleanup = make_cleanup_fclose (procfile);
- printf_filtered (_("Mapped address spaces:\n\n"));
- if (gdbarch_addr_bit (target_gdbarch) == 32)
- {
- printf_filtered ("\t%10s %10s %10s %10s %7s\n",
- "Start Addr",
- " End Addr",
- " Size", " Offset", "objfile");
- }
- else
- {
- printf_filtered (" %18s %18s %10s %10s %7s\n",
- "Start Addr",
- " End Addr",
- " Size", " Offset", "objfile");
- }
-
- while (read_mapping (procfile, &addr, &endaddr, &permissions[0],
- &offset, &device[0], &inode, &filename[0]))
- {
- size = endaddr - addr;
-
- /* 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 (gdbarch_addr_bit (target_gdbarch) == 32)
- {
- printf_filtered ("\t%#10lx %#10lx %#10x %#10x %7s\n",
- (unsigned long) addr, /* FIXME: pr_addr */
- (unsigned long) endaddr,
- (int) size,
- (unsigned int) offset,
- filename[0] ? filename : "");
- }
- 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 : "");
- }
- }
-
- do_cleanups (cleanup);
- }
- else
- warning (_("unable to open /proc file '%s'"), fname1);
- }
- if (status_f || all)
- {
- sprintf (fname1, "/proc/%ld/status", pid);
- if ((procfile = fopen (fname1, "r")) != NULL)
- {
- struct cleanup *cleanup = make_cleanup_fclose (procfile);
-
- while (fgets (buffer, sizeof (buffer), procfile) != NULL)
- puts_filtered (buffer);
- do_cleanups (cleanup);
- }
- else
- warning (_("unable to open /proc file '%s'"), fname1);
- }
- if (stat_f || all)
- {
- sprintf (fname1, "/proc/%ld/stat", pid);
- if ((procfile = fopen (fname1, "r")) != NULL)
- {
- int itmp;
- char ctmp;
- long ltmp;
- struct cleanup *cleanup = make_cleanup_fclose (procfile);
-
- if (fscanf (procfile, "%d ", &itmp) > 0)
- printf_filtered (_("Process: %d\n"), itmp);
- if (fscanf (procfile, "(%[^)]) ", &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, "%lu ", <mp) > 0)
- printf_filtered (_("Flags: 0x%lx\n"), ltmp);
- if (fscanf (procfile, "%lu ", <mp) > 0)
- printf_filtered (_("Minor faults (no memory page): %lu\n"),
- (unsigned long) ltmp);
- if (fscanf (procfile, "%lu ", <mp) > 0)
- printf_filtered (_("Minor faults, children: %lu\n"),
- (unsigned long) ltmp);
- if (fscanf (procfile, "%lu ", <mp) > 0)
- printf_filtered (_("Major faults (memory page faults): %lu\n"),
- (unsigned long) ltmp);
- if (fscanf (procfile, "%lu ", <mp) > 0)
- printf_filtered (_("Major faults, children: %lu\n"),
- (unsigned long) ltmp);
- if (fscanf (procfile, "%ld ", <mp) > 0)
- printf_filtered (_("utime: %ld\n"), ltmp);
- if (fscanf (procfile, "%ld ", <mp) > 0)
- printf_filtered (_("stime: %ld\n"), ltmp);
- if (fscanf (procfile, "%ld ", <mp) > 0)
- printf_filtered (_("utime, children: %ld\n"), ltmp);
- if (fscanf (procfile, "%ld ", <mp) > 0)
- printf_filtered (_("stime, children: %ld\n"), ltmp);
- if (fscanf (procfile, "%ld ", <mp) > 0)
- printf_filtered (_("jiffies remaining in current "
- "time slice: %ld\n"), ltmp);
- if (fscanf (procfile, "%ld ", <mp) > 0)
- printf_filtered (_("'nice' value: %ld\n"), ltmp);
- if (fscanf (procfile, "%lu ", <mp) > 0)
- printf_filtered (_("jiffies until next timeout: %lu\n"),
- (unsigned long) ltmp);
- if (fscanf (procfile, "%lu ", <mp) > 0)
- printf_filtered (_("jiffies until next SIGALRM: %lu\n"),
- (unsigned long) ltmp);
- if (fscanf (procfile, "%ld ", <mp) > 0)
- printf_filtered (_("start time (jiffies since "
- "system boot): %ld\n"), ltmp);
- if (fscanf (procfile, "%lu ", <mp) > 0)
- printf_filtered (_("Virtual memory size: %lu\n"),
- (unsigned long) ltmp);
- if (fscanf (procfile, "%lu ", <mp) > 0)
- printf_filtered (_("Resident set size: %lu\n"),
- (unsigned long) ltmp);
- if (fscanf (procfile, "%lu ", <mp) > 0)
- printf_filtered (_("rlim: %lu\n"), (unsigned long) ltmp);
- if (fscanf (procfile, "%lu ", <mp) > 0)
- printf_filtered (_("Start of text: 0x%lx\n"), ltmp);
- if (fscanf (procfile, "%lu ", <mp) > 0)
- printf_filtered (_("End of text: 0x%lx\n"), ltmp);
- if (fscanf (procfile, "%lu ", <mp) > 0)
- printf_filtered (_("Start of stack: 0x%lx\n"), ltmp);
-#if 0 /* Don't know how architecture-dependent the rest is...
- Anyway the signal bitmap info is available from "status". */
- if (fscanf (procfile, "%lu ", <mp) > 0) /* FIXME arch? */
- printf_filtered (_("Kernel stack pointer: 0x%lx\n"), ltmp);
- if (fscanf (procfile, "%lu ", <mp) > 0) /* FIXME arch? */
- printf_filtered (_("Kernel instr pointer: 0x%lx\n"), ltmp);
- if (fscanf (procfile, "%ld ", <mp) > 0)
- printf_filtered (_("Pending signals bitmap: 0x%lx\n"), ltmp);
- if (fscanf (procfile, "%ld ", <mp) > 0)
- printf_filtered (_("Blocked signals bitmap: 0x%lx\n"), ltmp);
- if (fscanf (procfile, "%ld ", <mp) > 0)
- printf_filtered (_("Ignored signals bitmap: 0x%lx\n"), ltmp);
- if (fscanf (procfile, "%ld ", <mp) > 0)
- printf_filtered (_("Catched signals bitmap: 0x%lx\n"), ltmp);
- if (fscanf (procfile, "%lu ", <mp) > 0) /* FIXME arch? */
- printf_filtered (_("wchan (system call): 0x%lx\n"), ltmp);
-#endif
- do_cleanups (cleanup);
- }
- else
- warning (_("unable to open /proc file '%s'"), fname1);
- }