Replace ../include/wait.h with gdb_wait.h.
[deliverable/binutils-gdb.git] / gdb / printcmd.c
index 9fac1f39b4b9b44d30804341cdcda8e54df73f0e..710f2d2c47825f129d9637763afa71a0d1645c2e 100644 (file)
@@ -35,6 +35,9 @@
 #include "annotate.h"
 #include "symfile.h"           /* for overlay functions */
 #include "objfiles.h"          /* ditto */
+#ifdef UI_OUT
+#include "ui-out.h"
+#endif
 
 extern int asm_demangle;       /* Whether to demangle syms in asm printouts */
 extern int addressprint;       /* Whether to print hex addresses in HLL " */
@@ -542,22 +545,79 @@ print_address_symbolic (addr, stream, do_demangle, leadin)
      struct ui_file *stream;
      int do_demangle;
      char *leadin;
+{
+  char *name = NULL;
+  char *filename = NULL;
+  int unmapped = 0;
+  int offset = 0;
+  int line = 0;
+
+  struct cleanup *cleanup_chain = make_cleanup (free, name);
+  if (print_symbol_filename)
+    make_cleanup (free, filename);
+
+  if (build_address_symbolic (addr, do_demangle, &name, &offset, &filename, &line, &unmapped))
+    return;
+
+  fputs_filtered (leadin, stream);
+  if (unmapped)
+    fputs_filtered ("<*", stream);
+  else
+    fputs_filtered ("<", stream);
+  fputs_filtered (name, stream);
+  if (offset != 0)
+    fprintf_filtered (stream, "+%u", (unsigned int) offset);
+
+  /* Append source filename and line number if desired.  Give specific
+     line # of this addr, if we have it; else line # of the nearest symbol.  */
+  if (print_symbol_filename && filename != NULL)
+    {
+      if (line != -1)
+       fprintf_filtered (stream, " at %s:%d", filename, line);
+      else
+       fprintf_filtered (stream, " in %s", filename);
+    }
+  if (unmapped)
+    fputs_filtered ("*>", stream);
+  else
+    fputs_filtered (">", stream);
+
+  do_cleanups (cleanup_chain);
+}
+
+/* Given an address ADDR return all the elements needed to print the
+   address in a symbolic form. NAME can be mangled or not depending
+   on DO_DEMANGLE (and also on the asm_demangle global variable,
+   manipulated via ''set print asm-demangle''). Return 0 in case of
+   success, when all the info in the OUT paramters is valid. Return 1
+   otherwise. */
+int
+build_address_symbolic (CORE_ADDR addr,  /* IN */
+                       int do_demangle, /* IN */
+                       char **name,     /* OUT */
+                       int *offset,     /* OUT */
+                       char **filename, /* OUT */
+                       int *line,       /* OUT */
+                       int *unmapped)   /* OUT */
 {
   struct minimal_symbol *msymbol;
   struct symbol *symbol;
   struct symtab *symtab = 0;
   CORE_ADDR name_location = 0;
-  char *name = "";
   asection *section = 0;
-  int unmapped = 0;
+  char *name_temp = "";
+  
+  /* Let's say it is unmapped. */
+  *unmapped = 0;
 
-  /* Determine if the address is in an overlay, and whether it is mapped. */
+  /* Determine if the address is in an overlay, and whether it is
+     mapped. */
   if (overlay_debugging)
     {
       section = find_pc_overlay (addr);
       if (pc_in_unmapped_range (addr, section))
        {
-         unmapped = 1;
+         *unmapped = 1;
          addr = overlay_mapped_address (addr, section);
        }
     }
@@ -587,9 +647,9 @@ print_address_symbolic (addr, stream, do_demangle, leadin)
     {
       name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol));
       if (do_demangle)
-       name = SYMBOL_SOURCE_NAME (symbol);
+       name_temp = SYMBOL_SOURCE_NAME (symbol);
       else
-       name = SYMBOL_LINKAGE_NAME (symbol);
+       name_temp = SYMBOL_LINKAGE_NAME (symbol);
     }
 
   if (msymbol != NULL)
@@ -602,13 +662,13 @@ print_address_symbolic (addr, stream, do_demangle, leadin)
          symtab = 0;
          name_location = SYMBOL_VALUE_ADDRESS (msymbol);
          if (do_demangle)
-           name = SYMBOL_SOURCE_NAME (msymbol);
+           name_temp = SYMBOL_SOURCE_NAME (msymbol);
          else
-           name = SYMBOL_LINKAGE_NAME (msymbol);
+           name_temp = SYMBOL_LINKAGE_NAME (msymbol);
        }
     }
   if (symbol == NULL && msymbol == NULL)
-    return;
+    return 1;
 
   /* On some targets, mask out extra "flag" bits from PC for handsome
      disassembly. */
@@ -627,19 +687,12 @@ print_address_symbolic (addr, stream, do_demangle, leadin)
      of the address space back to the beginning, giving bogus comparison.  */
   if (addr > name_location + max_symbolic_offset
       && name_location + max_symbolic_offset > name_location)
-    return;
+    return 1;
 
-  fputs_filtered (leadin, stream);
-  if (unmapped)
-    fputs_filtered ("<*", stream);
-  else
-    fputs_filtered ("<", stream);
-  fputs_filtered (name, stream);
-  if (addr != name_location)
-    fprintf_filtered (stream, "+%u", (unsigned int) (addr - name_location));
+  *offset = addr - name_location;
+
+  *name = xstrdup (name_temp);
 
-  /* Append source filename and line number if desired.  Give specific
-     line # of this addr, if we have it; else line # of the nearest symbol.  */
   if (print_symbol_filename)
     {
       struct symtab_and_line sal;
@@ -647,19 +700,24 @@ print_address_symbolic (addr, stream, do_demangle, leadin)
       sal = find_pc_sect_line (addr, section, 0);
 
       if (sal.symtab)
-       fprintf_filtered (stream, " at %s:%d", sal.symtab->filename, sal.line);
+       {
+         *filename = xstrdup (sal.symtab->filename);
+         *line = sal.line;
+       }
       else if (symtab && symbol && symbol->line)
-       fprintf_filtered (stream, " at %s:%d", symtab->filename, symbol->line);
+       {
+         *filename = xstrdup (symtab->filename);
+         *line = symbol->line;
+       }
       else if (symtab)
-       fprintf_filtered (stream, " in %s", symtab->filename);
+       {
+         *filename = xstrdup (symtab->filename);
+         *line = -1;
+       }
     }
-  if (unmapped)
-    fputs_filtered ("*>", stream);
-  else
-    fputs_filtered (">", stream);
+  return 0;
 }
 
-
 /* Print address ADDR on STREAM.  USE_LOCAL means the same thing as for
    print_longest.  */
 void
@@ -1777,6 +1835,13 @@ print_frame_args (func, fi, num, stream)
   int arg_size;
   /* Number of ints of arguments that we have printed so far.  */
   int args_printed = 0;
+#ifdef UI_OUT
+  struct cleanup *old_chain;
+  struct ui_stream *stb;
+
+  stb = ui_out_stream_new (uiout);
+  old_chain = make_cleanup ((make_cleanup_func) ui_out_stream_delete, stb);
+#endif /* UI_OUT */
 
   if (func)
     {
@@ -1881,6 +1946,21 @@ print_frame_args (func, fi, num, stream)
            sym = nsym;
        }
 
+#ifdef UI_OUT
+      /* Print the current arg.  */
+      if (!first)
+       ui_out_text (uiout, ", ");
+      ui_out_wrap_hint (uiout, "    ");
+
+      annotate_arg_begin ();
+
+      ui_out_list_begin (uiout, NULL);
+      fprintf_symbol_filtered (stb->stream, SYMBOL_SOURCE_NAME (sym),
+                           SYMBOL_LANGUAGE (sym), DMGL_PARAMS | DMGL_ANSI);
+      ui_out_field_stream (uiout, "name", stb);
+      annotate_arg_name_end ();
+      ui_out_text (uiout, "=");
+#else
       /* Print the current arg.  */
       if (!first)
        fprintf_filtered (stream, ", ");
@@ -1892,6 +1972,7 @@ print_frame_args (func, fi, num, stream)
                            SYMBOL_LANGUAGE (sym), DMGL_PARAMS | DMGL_ANSI);
       annotate_arg_name_end ();
       fputs_filtered ("=", stream);
+#endif
 
       /* Avoid value_print because it will deref ref parameters.  We just
          want to print their addresses.  Print ??? for args whose address
@@ -1907,12 +1988,24 @@ print_frame_args (func, fi, num, stream)
          if (GDB_TARGET_IS_D10V
              && SYMBOL_CLASS (sym) == LOC_REGPARM && TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_PTR)
            TYPE_LENGTH (VALUE_TYPE (val)) = 2;
+#ifdef UI_OUT
+         val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), 0,
+                    VALUE_ADDRESS (val),
+                    stb->stream, 0, 0, 2, Val_no_prettyprint);
+         ui_out_field_stream (uiout, "value", stb);
+       }
+      else
+       ui_out_text (uiout, "???");
+
+      ui_out_list_end (uiout);
+#else
          val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), 0,
                     VALUE_ADDRESS (val),
                     stream, 0, 0, 2, Val_no_prettyprint);
        }
       else
        fputs_filtered ("???", stream);
+#endif
 
       annotate_arg_end ();
 
@@ -1933,6 +2026,9 @@ print_frame_args (func, fi, num, stream)
       print_frame_nameless_args (fi, start, num - args_printed,
                                 first, stream);
     }
+#ifdef UI_OUT
+  do_cleanups (old_chain);
+#endif /* no UI_OUT */
 }
 
 /* Print nameless args on STREAM.
This page took 0.026357 seconds and 4 git commands to generate.