GDB (API)
|
00001 /* Support for printing D values for GDB, the GNU debugger. 00002 00003 Copyright (C) 2008-2013 Free Software Foundation, Inc. 00004 00005 This file is part of GDB. 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00019 00020 #include "defs.h" 00021 #include "gdbtypes.h" 00022 #include "gdbcore.h" 00023 #include "d-lang.h" 00024 #include "c-lang.h" 00025 00026 /* Assuming that TYPE is a TYPE_CODE_STRUCT, verify that TYPE is a 00027 dynamic array, and then print its value to STREAM. Return zero if 00028 TYPE is a dynamic array, non-zero otherwise. */ 00029 00030 static int 00031 dynamic_array_type (struct type *type, const gdb_byte *valaddr, 00032 int embedded_offset, CORE_ADDR address, 00033 struct ui_file *stream, int recurse, 00034 const struct value *val, 00035 const struct value_print_options *options) 00036 { 00037 if (TYPE_NFIELDS (type) == 2 00038 && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_INT 00039 && strcmp (TYPE_FIELD_NAME (type, 0), "length") == 0 00040 && strcmp (TYPE_FIELD_NAME (type, 1), "ptr") == 0 00041 && value_bits_valid (val, TARGET_CHAR_BIT * embedded_offset, 00042 TARGET_CHAR_BIT * TYPE_LENGTH (type))) 00043 { 00044 CORE_ADDR addr; 00045 struct type *elttype; 00046 struct type *true_type; 00047 struct type *ptr_type; 00048 struct value *ival; 00049 int length; 00050 00051 length = unpack_field_as_long (type, valaddr + embedded_offset, 0); 00052 00053 ptr_type = TYPE_FIELD_TYPE (type, 1); 00054 elttype = check_typedef (TYPE_TARGET_TYPE (ptr_type)); 00055 addr = unpack_pointer (ptr_type, 00056 valaddr + TYPE_FIELD_BITPOS (type, 1) / 8 00057 + embedded_offset); 00058 true_type = check_typedef (elttype); 00059 00060 true_type = lookup_array_range_type (true_type, 0, length - 1); 00061 ival = value_at (true_type, addr); 00062 00063 d_val_print (true_type, 00064 value_contents_for_printing (ival), 00065 value_embedded_offset (ival), addr, 00066 stream, recurse + 1, ival, options); 00067 return 0; 00068 } 00069 return 1; 00070 } 00071 00072 /* Implements the la_val_print routine for language D. */ 00073 void 00074 d_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, 00075 CORE_ADDR address, struct ui_file *stream, int recurse, 00076 const struct value *val, 00077 const struct value_print_options *options) 00078 { 00079 int ret; 00080 00081 CHECK_TYPEDEF (type); 00082 switch (TYPE_CODE (type)) 00083 { 00084 case TYPE_CODE_STRUCT: 00085 ret = dynamic_array_type (type, valaddr, embedded_offset, address, 00086 stream, recurse, val, options); 00087 if (ret == 0) 00088 break; 00089 default: 00090 c_val_print (type, valaddr, embedded_offset, address, stream, 00091 recurse, val, options); 00092 } 00093 }