* objfiles.h: Delete comments refering to inside_entry_func and
[deliverable/binutils-gdb.git] / gdb / linux-proc.c
index e4ea747008b80d9329f79aad501329b55cf18f31..0a774593edaf73ecaff97ab1fc2c2bf9fd04877f 100644 (file)
@@ -35,6 +35,8 @@
 #include "cli/cli-decode.h"    /* for add_info */
 #include "gdb_string.h"
 
+#include <signal.h>
+
 #include "linux-nat.h"
 
 #ifndef O_LARGEFILE
@@ -206,7 +208,7 @@ struct linux_corefile_thread_data
 };
 
 /* Function: linux_corefile_thread_callback
- * 
+ *
  * Called by gdbthread.c once per thread.
  * Records the thread's register state for the corefile note section.
  */
@@ -219,7 +221,7 @@ linux_corefile_thread_callback (struct lwp_info *ti, void *data)
 
   inferior_ptid = ti->ptid;
   registers_changed ();
-  target_fetch_registers (-1); /* FIXME should not be necessary; 
+  target_fetch_registers (-1); /* FIXME should not be necessary;
                                   fill_gregset should do it automatically. */
   args->note_data = linux_do_thread_registers (args->obfd,
                                               ti->ptid,
@@ -228,16 +230,36 @@ linux_corefile_thread_callback (struct lwp_info *ti, void *data)
   args->num_notes++;
   inferior_ptid = saved_ptid;
   registers_changed ();
-  target_fetch_registers (-1); /* FIXME should not be necessary; 
+  target_fetch_registers (-1); /* FIXME should not be necessary;
                                   fill_gregset should do it automatically. */
   return 0;
 }
 
+/* Function: linux_do_registers
+ *
+ * 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 ();
+  target_fetch_registers (-1); /* FIXME should not be necessary;
+                                  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;
+}
+
 /* Function: linux_make_note_section
  *
  * Fills the "to_make_corefile_note" target vector.
- * Builds the note section for a corefile, and returns it 
- * in a malloc buffer. 
+ * Builds the note section for a corefile, and returns it
+ * in a malloc buffer.
  */
 
 static char *
@@ -249,6 +271,8 @@ linux_make_note_section (bfd *obfd, int *note_size)
   char psargs[80] = { '\0' };
   char *note_data = NULL;
   ptid_t current_ptid = inferior_ptid;
+  char *auxv;
+  int auxv_len;
 
   if (get_exec_file (0))
     {
@@ -275,14 +299,22 @@ linux_make_note_section (bfd *obfd, int *note_size)
     {
       /* iterate_over_threads didn't come up with any threads;
          just use inferior_ptid.  */
-      note_data = linux_do_thread_registers (obfd, inferior_ptid,
-                                            note_data, note_size);
+      note_data = linux_do_registers (obfd, inferior_ptid,
+                                     note_data, note_size);
     }
   else
     {
       note_data = thread_args.note_data;
     }
 
+  auxv_len = target_auxv_read (&current_target, &auxv);
+  if (auxv_len > 0)
+    {
+      note_data = elfcore_write_note (obfd, note_data, note_size,
+                                     "CORE", NT_AUXV, auxv, auxv_len);
+      xfree (auxv);
+    }
+
   make_cleanup (xfree, note_data);
   return note_data;
 }
@@ -404,35 +436,52 @@ linux_info_proc_cmd (char *args, int from_tty)
        {
          long long addr, endaddr, size, offset, inode;
          char permissions[8], device[8], filename[MAXPATHLEN];
-         char *header_fmt_string, *data_fmt_string;
 
+         printf_filtered ("Mapped address spaces:\n\n");
          if (TARGET_ADDR_BIT == 32)
            {
-             header_fmt_string = "\t%10s %10s %10s %10s %7s\n";
-             data_fmt_string = "\t%#10lx %#10lx %#10x %#10x %7s\n";
-           }
+             printf_filtered ("\t%10s %10s %10s %10s %7s\n",
+                          "Start Addr",
+                          "  End Addr",
+                          "      Size", "    Offset", "objfile");
+            }
          else
-           {
-             header_fmt_string = "  %18s %18s %10s %10s %7s\n";
-             data_fmt_string = "  %#18lx %#18lx %#10x %#10x %7s\n";
-           }
-
-         printf_filtered ("Mapped address spaces:\n\n");
-         printf_filtered (header_fmt_string,
+            {
+             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;
-             printf_filtered (data_fmt_string, (unsigned long) addr,   /* FIXME: pr_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 (TARGET_ADDR_BIT == 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 : "");
+               }
            }
 
          fclose (procfile);
@@ -446,7 +495,7 @@ linux_info_proc_cmd (char *args, int from_tty)
       if ((procfile = fopen (fname1, "r")) > 0)
        {
          while (fgets (buffer, sizeof (buffer), procfile) != NULL)
-           printf_filtered (buffer);
+           puts_filtered (buffer);
          fclose (procfile);
        }
       else
@@ -525,7 +574,7 @@ linux_info_proc_cmd (char *args, int from_tty)
            printf_filtered ("End of text: 0x%x\n", itmp);
          if (fscanf (procfile, "%u ", &itmp) > 0)
            printf_filtered ("Start of stack: 0x%x\n", itmp);
-#if 0                          /* Don't know how architecture-dependent the rest is... 
+#if 0                          /* Don't know how architecture-dependent the rest is...
                                   Anyway the signal bitmap info is available from "status".  */
          if (fscanf (procfile, "%u ", &itmp) > 0)      /* FIXME arch? */
            printf_filtered ("Kernel stack pointer: 0x%x\n", itmp);
@@ -592,11 +641,7 @@ linux_proc_xfer_memory (CORE_ADDR addr, char *myaddr, int len, int write,
   /* 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
-     application).
-
-     We play some autoconf and CFLAGS games to get this declaration
-     exposed: -D_XOPEN_SOURCE=500 -D_LARGEFILE64_SOURCE.  And then
-     a -D_BSD_SOURCE to counteract the defaults for _XOPEN_SOURCE.  */
+     application).  */
 #ifdef HAVE_PREAD64
   if (pread64 (fd, myaddr, len, addr) != len)
 #else
@@ -609,3 +654,84 @@ linux_proc_xfer_memory (CORE_ADDR addr, char *myaddr, int len, int write,
   close (fd);
   return ret;
 }
+
+/* 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);
+}
This page took 0.026686 seconds and 4 git commands to generate.