Put GDB's terminal settings into effect when paginating
[deliverable/binutils-gdb.git] / gdb / linux-tdep.c
index fbdca463510dc4d47d0657755da7b5117058c88c..d0f1106ce85daef51bd00175155a0c5b46f7dfdf 100644 (file)
@@ -1,6 +1,6 @@
 /* Target-dependent code for GNU/Linux, architecture independent.
 
-   Copyright (C) 2009-2013 Free Software Foundation, Inc.
+   Copyright (C) 2009-2014 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -32,7 +32,6 @@
 #include "cli/cli-utils.h"
 #include "arch-utils.h"
 #include "gdb_obstack.h"
-#include "cli/cli-utils.h"
 
 #include <ctype.h>
 
@@ -241,19 +240,22 @@ linux_get_siginfo_type (struct gdbarch *gdbarch)
   return siginfo_type;
 }
 
-static int
-linux_has_shared_address_space (struct gdbarch *gdbarch)
+/* Return true if the target is running on uClinux instead of normal
+   Linux kernel.  */
+
+int
+linux_is_uclinux (void)
 {
-  /* Determine whether we are running on uClinux or normal Linux
-     kernel.  */
   CORE_ADDR dummy;
-  int target_is_uclinux;
 
-  target_is_uclinux
-    = (target_auxv_search (&current_target, AT_NULL, &dummy) > 0
-       && target_auxv_search (&current_target, AT_PAGESZ, &dummy) == 0);
+  return (target_auxv_search (&current_target, AT_NULL, &dummy) > 0
+         && target_auxv_search (&current_target, AT_PAGESZ, &dummy) == 0);
+}
 
-  return target_is_uclinux;
+static int
+linux_has_shared_address_space (struct gdbarch *gdbarch)
+{
+  return linux_is_uclinux ();
 }
 
 /* This is how we want PTIDs from core files to be printed.  */
@@ -313,7 +315,7 @@ read_mapping (const char *line,
 /* Implement the "info proc" command.  */
 
 static void
-linux_info_proc (struct gdbarch *gdbarch, char *args,
+linux_info_proc (struct gdbarch *gdbarch, const char *args,
                 enum info_proc_what what)
 {
   /* A long is used for pid instead of an int to avoid a loss of precision
@@ -330,7 +332,12 @@ linux_info_proc (struct gdbarch *gdbarch, char *args,
   int target_errno;
 
   if (args && isdigit (args[0]))
-    pid = strtoul (args, &args, 10);
+    {
+      char *tem;
+
+      pid = strtoul (args, &tem, 10);
+      args = tem;
+    }
   else
     {
       if (!target_has_execution)
@@ -341,7 +348,7 @@ linux_info_proc (struct gdbarch *gdbarch, char *args,
       pid = current_inferior ()->pid;
     }
 
-  args = skip_spaces (args);
+  args = skip_spaces_const (args);
   if (args && args[0])
     error (_("Too many parameters: %s"), args);
 
@@ -474,7 +481,9 @@ linux_info_proc (struct gdbarch *gdbarch, char *args,
          p = skip_spaces_const (p);
          if (*p == '(')
            {
-             const char *ep = strchr (p, ')');
+             /* ps command also relies on no trailing fields
+                ever contain ')'.  */
+             const char *ep = strrchr (p, ')');
              if (ep != NULL)
                {
                  printf_filtered ("Exec file: %.*s\n",
@@ -599,7 +608,7 @@ linux_info_proc (struct gdbarch *gdbarch, char *args,
 /* Implement "info proc mappings" for a corefile.  */
 
 static void
-linux_core_info_proc_mappings (struct gdbarch *gdbarch, char *args)
+linux_core_info_proc_mappings (struct gdbarch *gdbarch, const char *args)
 {
   asection *section;
   ULONGEST count, page_size;
@@ -702,7 +711,7 @@ linux_core_info_proc_mappings (struct gdbarch *gdbarch, char *args)
 /* Implement "info proc" for a corefile.  */
 
 static void
-linux_core_info_proc (struct gdbarch *gdbarch, char *args,
+linux_core_info_proc (struct gdbarch *gdbarch, const char *args,
                      enum info_proc_what what)
 {
   int exe_f = (what == IP_MINIMAL || what == IP_EXE || what == IP_ALL);
@@ -1173,7 +1182,6 @@ struct linux_corefile_thread_data
   bfd *obfd;
   char *note_data;
   int *note_size;
-  int num_notes;
   enum gdb_signal stop_signal;
   linux_collect_thread_registers_ftype collect;
 };
@@ -1191,7 +1199,7 @@ linux_corefile_thread_callback (struct thread_info *info, void *data)
       struct cleanup *old_chain;
       struct regcache *regcache;
       gdb_byte *siginfo_data;
-      LONGEST siginfo_size;
+      LONGEST siginfo_size = 0;
 
       regcache = get_thread_arch_regcache (info->ptid, args->gdbarch);
 
@@ -1206,17 +1214,16 @@ linux_corefile_thread_callback (struct thread_info *info, void *data)
       args->note_data = args->collect (regcache, info->ptid, args->obfd,
                                       args->note_data, args->note_size,
                                       args->stop_signal);
-      args->num_notes++;
 
-      if (siginfo_data != NULL)
-       {
+      /* Don't return anything if we got no register information above,
+         such a core file is useless.  */
+      if (args->note_data != NULL)
+       if (siginfo_data != NULL)
          args->note_data = elfcore_write_note (args->obfd,
                                                args->note_data,
                                                args->note_size,
                                                "CORE", NT_SIGINFO,
                                                siginfo_data, siginfo_size);
-         args->num_notes++;
-       }
 
       do_cleanups (old_chain);
     }
@@ -1331,12 +1338,14 @@ linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo *p)
 
   proc_stat = skip_spaces (proc_stat);
 
-  /* Getting rid of the executable name, since we already have it.  We
-     know that this name will be in parentheses, so we can safely look
-     for the close-paren.  */
-  while (*proc_stat != ')')
-    ++proc_stat;
-  ++proc_stat;
+  /* ps command also relies on no trailing fields ever contain ')'.  */
+  proc_stat = strrchr (proc_stat, ')');
+  if (proc_stat == NULL)
+    {
+      do_cleanups (c);
+      return 1;
+    }
+  proc_stat++;
 
   proc_stat = skip_spaces (proc_stat);
 
@@ -1464,7 +1473,6 @@ linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size,
   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 ();
   thread_args.collect = collect;
   iterate_over_threads (linux_corefile_thread_callback, &thread_args);
@@ -1494,7 +1502,6 @@ linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size,
   note_data = linux_make_mappings_corefile_notes (gdbarch, obfd,
                                                  note_data, note_size);
 
-  make_cleanup (xfree, note_data);
   return note_data;
 }
 
This page took 0.026954 seconds and 4 git commands to generate.