*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / utils.c
index 3be084e804e51c1559fa8f97cc10f063fb74f84d..76ea6b12b8f12a86aa8af456dfc8ad5720e9096d 100644 (file)
@@ -1,7 +1,7 @@
 /* General utility routines for GDB, the GNU debugger.
 
    Copyright (C) 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
-   1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+   1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
    Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -52,6 +52,7 @@
 #include "filenames.h"
 #include "symfile.h"
 #include "gdb_obstack.h"
+#include "gdbcore.h"
 #include "top.h"
 
 #include "inferior.h"          /* for signed_pointer_to_address */
@@ -62,6 +63,9 @@
 
 #include "readline/readline.h"
 
+#include <sys/time.h>
+#include <time.h>
+
 #if !HAVE_DECL_MALLOC
 extern PTR malloc ();          /* OK: PTR */
 #endif
@@ -91,14 +95,15 @@ static void prompt_for_continue (void);
 static void set_screen_size (void);
 static void set_width (void);
 
+/* A flag indicating whether to timestamp debugging messages.  */
+
+static int debug_timestamp = 0;
+
 /* Chain of cleanup actions established with make_cleanup,
    to be executed if an error happens.  */
 
 static struct cleanup *cleanup_chain;  /* cleaned up after a failed command */
 static struct cleanup *final_cleanup_chain;    /* cleaned up when gdb exits */
-static struct cleanup *exec_cleanup_chain;     /* cleaned up on each execution command */
-/* cleaned up on each error from within an execution command */
-static struct cleanup *exec_error_cleanup_chain;
 
 /* Pointer to what is left to do for an execution command after the
    target stops. Used only in asynchronous mode, by targets that
@@ -208,18 +213,6 @@ make_final_cleanup (make_cleanup_ftype *function, void *arg)
   return make_my_cleanup (&final_cleanup_chain, function, arg);
 }
 
-struct cleanup *
-make_exec_cleanup (make_cleanup_ftype *function, void *arg)
-{
-  return make_my_cleanup (&exec_cleanup_chain, function, arg);
-}
-
-struct cleanup *
-make_exec_error_cleanup (make_cleanup_ftype *function, void *arg)
-{
-  return make_my_cleanup (&exec_error_cleanup_chain, function, arg);
-}
-
 static void
 do_freeargv (void *arg)
 {
@@ -316,18 +309,6 @@ do_final_cleanups (struct cleanup *old_chain)
   do_my_cleanups (&final_cleanup_chain, old_chain);
 }
 
-void
-do_exec_cleanups (struct cleanup *old_chain)
-{
-  do_my_cleanups (&exec_cleanup_chain, old_chain);
-}
-
-void
-do_exec_error_cleanups (struct cleanup *old_chain)
-{
-  do_my_cleanups (&exec_error_cleanup_chain, old_chain);
-}
-
 static void
 do_my_cleanups (struct cleanup **pmy_chain,
                struct cleanup *old_chain)
@@ -356,12 +337,6 @@ discard_final_cleanups (struct cleanup *old_chain)
   discard_my_cleanups (&final_cleanup_chain, old_chain);
 }
 
-void
-discard_exec_error_cleanups (struct cleanup *old_chain)
-{
-  discard_my_cleanups (&exec_error_cleanup_chain, old_chain);
-}
-
 void
 discard_my_cleanups (struct cleanup **pmy_chain,
                     struct cleanup *old_chain)
@@ -452,7 +427,7 @@ null_cleanup (void *arg)
 /* Add a continuation to the continuation list, the global list
    cmd_continuation. The new continuation will be added at the front.*/
 void
-add_continuation (void (*continuation_hook) (struct continuation_arg *),
+add_continuation (void (*continuation_hook) (struct continuation_arg *, int),
                  struct continuation_arg *arg_list)
 {
   struct continuation *continuation_ptr;
@@ -474,7 +449,7 @@ add_continuation (void (*continuation_hook) (struct continuation_arg *),
    and do the continuations from there on, instead of using the
    global beginning of list as our iteration pointer.  */
 void
-do_all_continuations (void)
+do_all_continuations (int error)
 {
   struct continuation *continuation_ptr;
   struct continuation *saved_continuation;
@@ -489,7 +464,7 @@ do_all_continuations (void)
   /* Work now on the list we have set aside.  */
   while (continuation_ptr)
     {
-      (continuation_ptr->continuation_hook) (continuation_ptr->arg_list);
+      (continuation_ptr->continuation_hook) (continuation_ptr->arg_list, error);
       saved_continuation = continuation_ptr;
       continuation_ptr = continuation_ptr->next;
       xfree (saved_continuation);
@@ -516,7 +491,7 @@ discard_all_continuations (void)
    the front.  */
 void
 add_intermediate_continuation (void (*continuation_hook)
-                              (struct continuation_arg *),
+                              (struct continuation_arg *, int),
                               struct continuation_arg *arg_list)
 {
   struct continuation *continuation_ptr;
@@ -538,7 +513,7 @@ add_intermediate_continuation (void (*continuation_hook)
    and do the continuations from there on, instead of using the
    global beginning of list as our iteration pointer.*/
 void
-do_all_intermediate_continuations (void)
+do_all_intermediate_continuations (int error)
 {
   struct continuation *continuation_ptr;
   struct continuation *saved_continuation;
@@ -553,7 +528,7 @@ do_all_intermediate_continuations (void)
   /* Work now on the list we have set aside.  */
   while (continuation_ptr)
     {
-      (continuation_ptr->continuation_hook) (continuation_ptr->arg_list);
+      (continuation_ptr->continuation_hook) (continuation_ptr->arg_list, error);
       saved_continuation = continuation_ptr;
       continuation_ptr = continuation_ptr->next;
       xfree (saved_continuation);
@@ -2120,6 +2095,16 @@ vfprintf_unfiltered (struct ui_file *stream, const char *format, va_list args)
 
   linebuffer = xstrvprintf (format, args);
   old_cleanups = make_cleanup (xfree, linebuffer);
+  if (debug_timestamp && stream == gdb_stdlog)
+    {
+      struct timeval tm;
+      char *timestamp;
+
+      gettimeofday (&tm, NULL);
+      timestamp = xstrprintf ("%ld:%ld ", (long) tm.tv_sec, (long) tm.tv_usec);
+      make_cleanup (xfree, timestamp);
+      fputs_unfiltered (timestamp, stream);
+    }
   fputs_unfiltered (linebuffer, stream);
   do_cleanups (old_cleanups);
 }
@@ -2436,6 +2421,13 @@ pagination_off_command (char *arg, int from_tty)
 {
   pagination_enabled = 0;
 }
+
+static void
+show_debug_timestamp (struct ui_file *file, int from_tty,
+                     struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("Timestamping debugging messages is %s.\n"), value);
+}
 \f
 
 void
@@ -2496,6 +2488,15 @@ Show demangling of C++/ObjC names in disassembly listings."), NULL,
                           NULL,
                           show_asm_demangle,
                           &setprintlist, &showprintlist);
+
+  add_setshow_boolean_cmd ("timestamp", class_maintenance,
+                           &debug_timestamp, _("\
+Set timestamping of debugging messages."), _("\
+Show timestamping of debugging messages."), _("\
+When set, debugging messages will be marked with seconds and microseconds."),
+                          NULL,
+                          show_debug_timestamp,
+                          &setdebuglist, &showdebuglist);
 }
 
 /* Machine specific function to handle SIGWINCH signal. */
@@ -2824,7 +2825,9 @@ core_addr_to_string_nz (const CORE_ADDR addr)
 CORE_ADDR
 string_to_core_addr (const char *my_string)
 {
+  int addr_bit = gdbarch_addr_bit (current_gdbarch);
   CORE_ADDR addr = 0;
+
   if (my_string[0] == '0' && tolower (my_string[1]) == 'x')
     {
       /* Assume that it is in hex.  */
@@ -2838,6 +2841,17 @@ string_to_core_addr (const char *my_string)
          else
            error (_("invalid hex \"%s\""), my_string);
        }
+
+      /* Not very modular, but if the executable format expects
+         addresses to be sign-extended, then do so if the address was
+         specified with only 32 significant bits.  Really this should
+         be determined by the target architecture, not by the object
+         file.  */
+      if (i - 2 == addr_bit / 4
+         && exec_bfd
+         && bfd_get_sign_extend_vma (exec_bfd))
+       addr = (addr ^ ((CORE_ADDR) 1 << (addr_bit - 1)))
+              - ((CORE_ADDR) 1 << (addr_bit - 1));
     }
   else
     {
@@ -2851,9 +2865,18 @@ string_to_core_addr (const char *my_string)
            error (_("invalid decimal \"%s\""), my_string);
        }
     }
+
   return addr;
 }
 
+const char *
+host_address_to_string (const void *addr)
+{
+  char *str = get_cell ();
+  sprintf (str, "0x%lx", (unsigned long) addr);
+  return str;
+}
+
 char *
 gdb_realpath (const char *filename)
 {
This page took 0.03424 seconds and 4 git commands to generate.