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