gdb/go-typeprint.c - gdb

Functions defined

Source code

  1. /* Support for printing Go types for GDB, the GNU debugger.

  2.    Copyright (C) 2012-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. /* TODO:
  15.    - lots
  16.    - if the more complex types get Python pretty-printers, we'll
  17.      want a Python API for type printing
  18. */

  19. #include "defs.h"
  20. #include "gdbtypes.h"
  21. #include "c-lang.h"
  22. #include "go-lang.h"

  23. /* Print a description of a type TYPE.
  24.    Output goes to STREAM (via stdio).
  25.    If VARSTRING is a non-empty string, print as an Ada variable/field
  26.        declaration.
  27.    SHOW+1 is the maximum number of levels of internal type structure
  28.       to show (this applies to record types, enumerated types, and
  29.       array types).
  30.    SHOW is the number of levels of internal type structure to show
  31.       when there is a type name for the SHOWth deepest level (0th is
  32.       outer level).
  33.    When SHOW<0, no inner structure is shown.
  34.    LEVEL indicates level of recursion (for nested definitions).  */

  35. void
  36. go_print_type (struct type *type, const char *varstring,
  37.                struct ui_file *stream, int show, int level,
  38.                const struct type_print_options *flags)
  39. {
  40.   /* Borrowed from c-typeprint.c.  */
  41.   if (show > 0)
  42.     CHECK_TYPEDEF (type);

  43.   /* Print the type of "abc" as "string", not char[4].  */
  44.   if (TYPE_CODE (type) == TYPE_CODE_ARRAY
  45.       && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CHAR)
  46.     {
  47.       fputs_filtered ("string", stream);
  48.       return;
  49.     }

  50.   /* Punt the rest to C for now.  */
  51.   c_print_type (type, varstring, stream, show, level, flags);
  52. }