Fix a typo in bunzip2..
[deliverable/binutils-gdb.git] / gdb / utils.c
index c66496f0157d373af88b0af10a2047a6c29f216f..d151174ea3ff4f59fd70cae7a05ebfab8987cf50 100644 (file)
@@ -133,18 +133,42 @@ int immediate_quit;
    C++/ObjC form rather than raw.  */
 
 int demangle = 1;
+static void
+show_demangle (struct ui_file *file, int from_tty,
+              struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("\
+Demangling of encoded C++/ObjC names when displaying symbols is %s.\n"),
+                   value);
+}
 
 /* Nonzero means that encoded C++/ObjC names should be printed out in their
    C++/ObjC form even in assembler language displays.  If this is set, but
    DEMANGLE is zero, names are printed raw, i.e. DEMANGLE controls.  */
 
 int asm_demangle = 0;
+static void
+show_asm_demangle (struct ui_file *file, int from_tty,
+                  struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("\
+Demangling of C++/ObjC names in disassembly listings is %s.\n"),
+                   value);
+}
 
 /* Nonzero means that strings with character values >0x7F should be printed
    as octal escapes.  Zero means just print the value (e.g. it's an
    international character, and the terminal or window can cope.)  */
 
 int sevenbit_strings = 0;
+static void
+show_sevenbit_strings (struct ui_file *file, int from_tty,
+                      struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("\
+Printing of 8-bit characters in strings as \\nnn is %s.\n"),
+                   value);
+}
 
 /* String to be printed before error messages, if any.  */
 
@@ -159,6 +183,13 @@ char *quit_pre_print;
 char *warning_pre_print = "\nwarning: ";
 
 int pagination_enabled = 1;
+static void
+show_pagination_enabled (struct ui_file *file, int from_tty,
+                        struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("State of pagination is %s.\n"), value);
+}
+
 \f
 
 /* Add a new cleanup to the cleanup_chain,
@@ -758,8 +789,10 @@ further debugging may prove unreliable.", file, line, problem->name, msg);
     {
       if (dump_core_p)
        {
+#ifdef HAVE_WORKING_FORK
          if (fork () == 0)
            abort ();           /* NOTE: GDB has only three calls to abort().  */
+#endif
        }
     }
 
@@ -813,12 +846,12 @@ char *
 safe_strerror (int errnum)
 {
   char *msg;
-  static char buf[32];
 
   msg = strerror (errnum);
   if (msg == NULL)
     {
-      sprintf (buf, "(undocumented errno %d)", errnum);
+      static char buf[32];
+      xsnprintf (buf, sizeof buf, "(undocumented errno %d)", errnum);
       msg = buf;
     }
   return (msg);
@@ -1046,6 +1079,20 @@ xstrvprintf (const char *format, va_list ap)
   return ret;
 }
 
+int
+xsnprintf (char *str, size_t size, const char *format, ...)
+{
+  va_list args;
+  int ret;
+
+  va_start (args, format);
+  ret = vsnprintf (str, size, format, args);
+  gdb_assert (ret < size);
+  va_end (args);
+
+  return ret;
+}
+
 /* My replacement for the read system call.
    Used like `read' but keeps going if `read' returns too soon.  */
 
@@ -1525,9 +1572,25 @@ fputstrn_unfiltered (const char *str, int n, int quoter,
 
 /* Number of lines per page or UINT_MAX if paging is disabled.  */
 static unsigned int lines_per_page;
+static void
+show_lines_per_page (struct ui_file *file, int from_tty,
+                    struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("\
+Number of lines gdb thinks are in a page is %s.\n"),
+                   value);
+}
 
 /* Number of chars per line or UINT_MAX if line folding is disabled.  */
 static unsigned int chars_per_line;
+static void
+show_chars_per_line (struct ui_file *file, int from_tty,
+                    struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("\
+Number of characters gdb thinks are in a line is %s.\n"),
+                   value);
+}
 
 /* Current count of lines printed on this page, chars on this line.  */
 static unsigned int lines_printed, chars_printed;
@@ -2446,29 +2509,36 @@ initialize_utils (void)
 {
   struct cmd_list_element *c;
 
-  c = add_set_cmd ("width", class_support, var_uinteger, &chars_per_line,
-                  "Set number of characters gdb thinks are in a line.",
-                  &setlist);
-  deprecated_add_show_from_set (c, &showlist);
-  set_cmd_sfunc (c, set_width_command);
+  add_setshow_uinteger_cmd ("width", class_support, &chars_per_line, _("\
+Set number of characters gdb thinks are in a line."), _("\
+Show number of characters gdb thinks are in a line."), NULL,
+                           set_width_command,
+                           show_chars_per_line,
+                           &setlist, &showlist);
 
-  c = add_set_cmd ("height", class_support, var_uinteger, &lines_per_page,
-                  "Set number of lines gdb thinks are in a page.", &setlist);
-  deprecated_add_show_from_set (c, &showlist);
-  set_cmd_sfunc (c, set_height_command);
+  add_setshow_uinteger_cmd ("height", class_support, &lines_per_page, _("\
+Set number of lines gdb thinks are in a page."), _("\
+Show number of lines gdb thinks are in a page."), NULL,
+                           set_height_command,
+                           show_lines_per_page,
+                           &setlist, &showlist);
 
   init_page_info ();
 
-  deprecated_add_show_from_set
-    (add_set_cmd ("demangle", class_support, var_boolean,
-                 (char *) &demangle,
-                 "Set demangling of encoded C++/ObjC names when displaying symbols.",
-                 &setprintlist), &showprintlist);
-
-  deprecated_add_show_from_set
-    (add_set_cmd ("pagination", class_support,
-                 var_boolean, (char *) &pagination_enabled,
-                 "Set state of pagination.", &setlist), &showlist);
+  add_setshow_boolean_cmd ("demangle", class_support, &demangle, _("\
+Set demangling of encoded C++/ObjC names when displaying symbols."), _("\
+Show demangling of encoded C++/ObjC names when displaying symbols."), NULL,
+                          NULL,
+                          show_demangle,
+                          &setprintlist, &showprintlist);
+
+  add_setshow_boolean_cmd ("pagination", class_support,
+                          &pagination_enabled, _("\
+Set state of pagination."), _("\
+Show state of pagination."), NULL,
+                          NULL,
+                          show_pagination_enabled,
+                          &setlist, &showlist);
 
   if (xdb_commands)
     {
@@ -2478,17 +2548,20 @@ initialize_utils (void)
               _("Disable pagination"));
     }
 
-  deprecated_add_show_from_set
-    (add_set_cmd ("sevenbit-strings", class_support, var_boolean,
-                 (char *) &sevenbit_strings,
-                 "Set printing of 8-bit characters in strings as \\nnn.",
-                 &setprintlist), &showprintlist);
+  add_setshow_boolean_cmd ("sevenbit-strings", class_support,
+                          &sevenbit_strings, _("\
+Set printing of 8-bit characters in strings as \\nnn."), _("\
+Show printing of 8-bit characters in strings as \\nnn."), NULL,
+                          NULL,
+                          show_sevenbit_strings,
+                          &setprintlist, &showprintlist);
 
-  deprecated_add_show_from_set
-    (add_set_cmd ("asm-demangle", class_support, var_boolean,
-                 (char *) &asm_demangle,
-                 "Set demangling of C++/ObjC names in disassembly listings.",
-                 &setprintlist), &showprintlist);
+  add_setshow_boolean_cmd ("asm-demangle", class_support, &asm_demangle, _("\
+Set demangling of C++/ObjC names in disassembly listings."), _("\
+Show demangling of C++/ObjC names in disassembly listings."), NULL,
+                          NULL,
+                          show_asm_demangle,
+                          &setprintlist, &showprintlist);
 }
 
 /* Machine specific function to handle SIGWINCH signal. */
@@ -2547,12 +2620,14 @@ paddress (CORE_ADDR addr)
   return hex_string (addr);
 }
 
-static void
-decimal2str (char *paddr_str, char *sign, ULONGEST addr, int width)
+static char *
+decimal2str (char *sign, ULONGEST addr, int width)
 {
-  /* steal code from valprint.c:print_decimal().  Should this worry
+  /* Steal code from valprint.c:print_decimal().  Should this worry
      about the real size of addr as the above does? */
   unsigned long temp[3];
+  char *str = get_cell ();
+
   int i = 0;
   do
     {
@@ -2562,31 +2637,38 @@ decimal2str (char *paddr_str, char *sign, ULONGEST addr, int width)
       width -= 9;
     }
   while (addr != 0 && i < (sizeof (temp) / sizeof (temp[0])));
+
   width += 9;
   if (width < 0)
     width = 0;
+
   switch (i)
     {
     case 1:
-      sprintf (paddr_str, "%s%0*lu", sign, width, temp[0]);
+      xsnprintf (str, CELLSIZE, "%s%0*lu", sign, width, temp[0]);
       break;
     case 2:
-      sprintf (paddr_str, "%s%0*lu%09lu", sign, width, temp[1], temp[0]);
+      xsnprintf (str, CELLSIZE, "%s%0*lu%09lu", sign, width,
+                temp[1], temp[0]);
       break;
     case 3:
-      sprintf (paddr_str, "%s%0*lu%09lu%09lu", sign, width,
-              temp[2], temp[1], temp[0]);
+      xsnprintf (str, CELLSIZE, "%s%0*lu%09lu%09lu", sign, width,
+                temp[2], temp[1], temp[0]);
       break;
     default:
       internal_error (__FILE__, __LINE__,
                      _("failed internal consistency check"));
     }
+
+  return str;
 }
 
-static void
-octal2str (char *paddr_str, ULONGEST addr, int width)
+static char *
+octal2str (ULONGEST addr, int width)
 {
   unsigned long temp[3];
+  char *str = get_cell ();
+
   int i = 0;
   do
     {
@@ -2596,76 +2678,78 @@ octal2str (char *paddr_str, ULONGEST addr, int width)
       width -= 10;
     }
   while (addr != 0 && i < (sizeof (temp) / sizeof (temp[0])));
+
   width += 10;
   if (width < 0)
     width = 0;
+
   switch (i)
     {
     case 1:
       if (temp[0] == 0)
-       sprintf (paddr_str, "%*o", width, 0);
+       xsnprintf (str, CELLSIZE, "%*o", width, 0);
       else
-       sprintf (paddr_str, "0%0*lo", width, temp[0]);
+       xsnprintf (str, CELLSIZE, "0%0*lo", width, temp[0]);
       break;
     case 2:
-      sprintf (paddr_str, "0%0*lo%010lo", width, temp[1], temp[0]);
+      xsnprintf (str, CELLSIZE, "0%0*lo%010lo", width, temp[1], temp[0]);
       break;
     case 3:
-      sprintf (paddr_str, "0%0*lo%010lo%010lo", width,
-              temp[2], temp[1], temp[0]);
+      xsnprintf (str, CELLSIZE, "0%0*lo%010lo%010lo", width,
+                temp[2], temp[1], temp[0]);
       break;
     default:
       internal_error (__FILE__, __LINE__,
                      _("failed internal consistency check"));
     }
+
+  return str;
 }
 
 char *
 paddr_u (CORE_ADDR addr)
 {
-  char *paddr_str = get_cell ();
-  decimal2str (paddr_str, "", addr, 0);
-  return paddr_str;
+  return decimal2str ("", addr, 0);
 }
 
 char *
 paddr_d (LONGEST addr)
 {
-  char *paddr_str = get_cell ();
   if (addr < 0)
-    decimal2str (paddr_str, "-", -addr, 0);
+    return decimal2str ("-", -addr, 0);
   else
-    decimal2str (paddr_str, "", addr, 0);
-  return paddr_str;
+    return decimal2str ("", addr, 0);
 }
 
-/* eliminate warning from compiler on 32-bit systems */
+/* Eliminate warning from compiler on 32-bit systems.  */
 static int thirty_two = 32;
 
 char *
 phex (ULONGEST l, int sizeof_l)
 {
   char *str;
+
   switch (sizeof_l)
     {
     case 8:
       str = get_cell ();
-      sprintf (str, "%08lx%08lx",
-              (unsigned long) (l >> thirty_two),
-              (unsigned long) (l & 0xffffffff));
+      xsnprintf (str, CELLSIZE, "%08lx%08lx",
+                (unsigned long) (l >> thirty_two),
+                (unsigned long) (l & 0xffffffff));
       break;
     case 4:
       str = get_cell ();
-      sprintf (str, "%08lx", (unsigned long) l);
+      xsnprintf (str, CELLSIZE, "%08lx", (unsigned long) l);
       break;
     case 2:
       str = get_cell ();
-      sprintf (str, "%04x", (unsigned short) (l & 0xffff));
+      xsnprintf (str, CELLSIZE, "%04x", (unsigned short) (l & 0xffff));
       break;
     default:
       str = phex (l, sizeof (l));
       break;
     }
+
   return str;
 }
 
@@ -2673,6 +2757,7 @@ char *
 phex_nz (ULONGEST l, int sizeof_l)
 {
   char *str;
+
   switch (sizeof_l)
     {
     case 8:
@@ -2680,23 +2765,26 @@ phex_nz (ULONGEST l, int sizeof_l)
        unsigned long high = (unsigned long) (l >> thirty_two);
        str = get_cell ();
        if (high == 0)
-         sprintf (str, "%lx", (unsigned long) (l & 0xffffffff));
+         xsnprintf (str, CELLSIZE, "%lx",
+                    (unsigned long) (l & 0xffffffff));
        else
-         sprintf (str, "%lx%08lx", high, (unsigned long) (l & 0xffffffff));
+         xsnprintf (str, CELLSIZE, "%lx%08lx", high,
+                    (unsigned long) (l & 0xffffffff));
        break;
       }
     case 4:
       str = get_cell ();
-      sprintf (str, "%lx", (unsigned long) l);
+      xsnprintf (str, CELLSIZE, "%lx", (unsigned long) l);
       break;
     case 2:
       str = get_cell ();
-      sprintf (str, "%x", (unsigned short) (l & 0xffff));
+      xsnprintf (str, CELLSIZE, "%x", (unsigned short) (l & 0xffff));
       break;
     default:
       str = phex_nz (l, sizeof (l));
       break;
     }
+
   return str;
 }
 
@@ -2706,7 +2794,7 @@ char *
 hex_string (LONGEST num)
 {
   char *result = get_cell ();
-  snprintf (result, CELLSIZE, "0x%s", phex_nz (num, sizeof (num)));
+  xsnprintf (result, CELLSIZE, "0x%s", phex_nz (num, sizeof (num)));
   return result;
 }
 
@@ -2760,17 +2848,14 @@ int_string (LONGEST val, int radix, int is_signed, int width,
       }
     case 10:
       {
-       char *result = get_cell ();
        if (is_signed && val < 0)
-         decimal2str (result, "-", -val, width);
+         return decimal2str ("-", -val, width);
        else
-         decimal2str (result, "", val, width);
-       return result;
+         return decimal2str ("", val, width);
       }
     case 8:
       {
-       char *result = get_cell ();
-       octal2str (result, val, width);
+       char *result = octal2str (val, width);
        if (use_c_format || val == 0)
          return result;
        else
This page took 0.029676 seconds and 4 git commands to generate.