Home | History | Annotate | Line # | Download | only in gdb
expprint.c revision 1.11
      1 /* Print in infix form a struct expression.
      2 
      3    Copyright (C) 1986-2024 Free Software Foundation, Inc.
      4 
      5    This file is part of GDB.
      6 
      7    This program is free software; you can redistribute it and/or modify
      8    it under the terms of the GNU General Public License as published by
      9    the Free Software Foundation; either version 3 of the License, or
     10    (at your option) any later version.
     11 
     12    This program is distributed in the hope that it will be useful,
     13    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15    GNU General Public License for more details.
     16 
     17    You should have received a copy of the GNU General Public License
     18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     19 
     20 #include "symtab.h"
     21 #include "gdbtypes.h"
     22 #include "expression.h"
     23 #include "value.h"
     24 #include "language.h"
     25 #include "parser-defs.h"
     26 #include "user-regs.h"
     27 #include "target.h"
     28 #include "block.h"
     29 #include "objfiles.h"
     30 #include "valprint.h"
     31 #include "cli/cli-style.h"
     32 #include "c-lang.h"
     33 #include "expop.h"
     34 #include "ada-exp.h"
     35 
     36 #include <ctype.h>
     37 
     38 /* Meant to be used in debug sessions, so don't export it in a header file.  */
     39 extern void ATTRIBUTE_USED debug_exp (struct expression *exp);
     40 
     41 /* Print EXP.  */
     42 
     43 void
     44 ATTRIBUTE_USED
     45 debug_exp (struct expression *exp)
     46 {
     47   exp->dump (gdb_stdlog);
     48   gdb_flush (gdb_stdlog);
     49 }
     50 
     51 namespace expr
     52 {
     53 
     54 bool
     55 check_objfile (const struct block *block, struct objfile *objfile)
     56 {
     57   return check_objfile (block->objfile (), objfile);
     58 }
     59 
     60 void
     61 dump_for_expression (struct ui_file *stream, int depth, enum exp_opcode op)
     62 {
     63   gdb_printf (stream, _("%*sOperation: "), depth, "");
     64 
     65   switch (op)
     66     {
     67     default:
     68       gdb_printf (stream, "<unknown %d>", op);
     69       break;
     70 
     71 #define OP(name)	\
     72     case name:		\
     73       gdb_puts (#name, stream); \
     74       break;
     75 #include "std-operator.def"
     76 #undef OP
     77     }
     78 
     79   gdb_puts ("\n", stream);
     80 }
     81 
     82 void
     83 dump_for_expression (struct ui_file *stream, int depth, const std::string &str)
     84 {
     85   gdb_printf (stream, _("%*sString: %s\n"), depth, "", str.c_str ());
     86 }
     87 
     88 void
     89 dump_for_expression (struct ui_file *stream, int depth, struct type *type)
     90 {
     91   gdb_printf (stream, _("%*sType: "), depth, "");
     92   type_print (type, nullptr, stream, 0);
     93   gdb_printf (stream, "\n");
     94 }
     95 
     96 void
     97 dump_for_expression (struct ui_file *stream, int depth, CORE_ADDR addr)
     98 {
     99   gdb_printf (stream, _("%*sConstant: %s\n"), depth, "",
    100 	      core_addr_to_string (addr));
    101 }
    102 
    103 void
    104 dump_for_expression (struct ui_file *stream, int depth, const gdb_mpz &val)
    105 {
    106   gdb_printf (stream, _("%*sConstant: %s\n"), depth, "", val.str ().c_str ());
    107 }
    108 
    109 void
    110 dump_for_expression (struct ui_file *stream, int depth, internalvar *ivar)
    111 {
    112   gdb_printf (stream, _("%*sInternalvar: $%s\n"), depth, "",
    113 	      internalvar_name (ivar));
    114 }
    115 
    116 void
    117 dump_for_expression (struct ui_file *stream, int depth, symbol *sym)
    118 {
    119   gdb_printf (stream, _("%*sSymbol: %s\n"), depth, "",
    120 	      sym->print_name ());
    121   dump_for_expression (stream, depth + 1, sym->type ());
    122 }
    123 
    124 void
    125 dump_for_expression (struct ui_file *stream, int depth,
    126 		     bound_minimal_symbol msym)
    127 {
    128   gdb_printf (stream, _("%*sMinsym %s in objfile %s\n"), depth, "",
    129 	      msym.minsym->print_name (), objfile_name (msym.objfile));
    130 }
    131 
    132 void
    133 dump_for_expression (struct ui_file *stream, int depth, const block *bl)
    134 {
    135   gdb_printf (stream, _("%*sBlock: %p\n"), depth, "", bl);
    136 }
    137 
    138 void
    139 dump_for_expression (struct ui_file *stream, int depth,
    140 		     const block_symbol &sym)
    141 {
    142   gdb_printf (stream, _("%*sBlock symbol:\n"), depth, "");
    143   dump_for_expression (stream, depth + 1, sym.symbol);
    144   dump_for_expression (stream, depth + 1, sym.block);
    145 }
    146 
    147 void
    148 dump_for_expression (struct ui_file *stream, int depth,
    149 		     type_instance_flags flags)
    150 {
    151   gdb_printf (stream, _("%*sType flags: "), depth, "");
    152   if (flags & TYPE_INSTANCE_FLAG_CONST)
    153     gdb_puts ("const ", stream);
    154   if (flags & TYPE_INSTANCE_FLAG_VOLATILE)
    155     gdb_puts ("volatile", stream);
    156   gdb_printf (stream, "\n");
    157 }
    158 
    159 void
    160 dump_for_expression (struct ui_file *stream, int depth,
    161 		     enum c_string_type_values flags)
    162 {
    163   gdb_printf (stream, _("%*sC string flags: "), depth, "");
    164   switch (flags & ~C_CHAR)
    165     {
    166     case C_WIDE_STRING:
    167       gdb_puts (_("wide "), stream);
    168       break;
    169     case C_STRING_16:
    170       gdb_puts (_("u16 "), stream);
    171       break;
    172     case C_STRING_32:
    173       gdb_puts (_("u32 "), stream);
    174       break;
    175     default:
    176       gdb_puts (_("ordinary "), stream);
    177       break;
    178     }
    179 
    180   if ((flags & C_CHAR) != 0)
    181     gdb_puts (_("char"), stream);
    182   else
    183     gdb_puts (_("string"), stream);
    184   gdb_puts ("\n", stream);
    185 }
    186 
    187 void
    188 dump_for_expression (struct ui_file *stream, int depth,
    189 		     enum range_flag flags)
    190 {
    191   gdb_printf (stream, _("%*sRange:"), depth, "");
    192   if ((flags & RANGE_LOW_BOUND_DEFAULT) != 0)
    193     gdb_puts (_("low-default "), stream);
    194   if ((flags & RANGE_HIGH_BOUND_DEFAULT) != 0)
    195     gdb_puts (_("high-default "), stream);
    196   if ((flags & RANGE_HIGH_BOUND_EXCLUSIVE) != 0)
    197     gdb_puts (_("high-exclusive "), stream);
    198   if ((flags & RANGE_HAS_STRIDE) != 0)
    199     gdb_puts (_("has-stride"), stream);
    200   gdb_printf (stream, "\n");
    201 }
    202 
    203 void
    204 dump_for_expression (struct ui_file *stream, int depth,
    205 		     const std::unique_ptr<ada_component> &comp)
    206 {
    207   comp->dump (stream, depth);
    208 }
    209 
    210 void
    211 float_const_operation::dump (struct ui_file *stream, int depth) const
    212 {
    213   gdb_printf (stream, _("%*sFloat: "), depth, "");
    214   print_floating (m_data.data (), m_type, stream);
    215   gdb_printf (stream, "\n");
    216 }
    217 
    218 } /* namespace expr */
    219