xref: /dflybsd-src/contrib/gdb-7/gdb/d-valprint.c (revision de8e141f24382815c10a4012d209bbbf7abf1112)
1cf7f2e2dSJohn Marino /* Support for printing D values for GDB, the GNU debugger.
2cf7f2e2dSJohn Marino 
3*ef5ccd6cSJohn Marino    Copyright (C) 2008-2013 Free Software Foundation, Inc.
4cf7f2e2dSJohn Marino 
5cf7f2e2dSJohn Marino    This file is part of GDB.
6cf7f2e2dSJohn Marino 
7cf7f2e2dSJohn Marino    This program is free software; you can redistribute it and/or modify
8cf7f2e2dSJohn Marino    it under the terms of the GNU General Public License as published by
9cf7f2e2dSJohn Marino    the Free Software Foundation; either version 3 of the License, or
10cf7f2e2dSJohn Marino    (at your option) any later version.
11cf7f2e2dSJohn Marino 
12cf7f2e2dSJohn Marino    This program is distributed in the hope that it will be useful,
13cf7f2e2dSJohn Marino    but WITHOUT ANY WARRANTY; without even the implied warranty of
14cf7f2e2dSJohn Marino    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15cf7f2e2dSJohn Marino    GNU General Public License for more details.
16cf7f2e2dSJohn Marino 
17cf7f2e2dSJohn Marino    You should have received a copy of the GNU General Public License
18cf7f2e2dSJohn Marino    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19cf7f2e2dSJohn Marino 
20cf7f2e2dSJohn Marino #include "defs.h"
21cf7f2e2dSJohn Marino #include "gdbtypes.h"
22cf7f2e2dSJohn Marino #include "gdbcore.h"
23cf7f2e2dSJohn Marino #include "d-lang.h"
24cf7f2e2dSJohn Marino #include "c-lang.h"
25cf7f2e2dSJohn Marino 
26*ef5ccd6cSJohn Marino /* Assuming that TYPE is a TYPE_CODE_STRUCT, verify that TYPE is a
27*ef5ccd6cSJohn Marino    dynamic array, and then print its value to STREAM.  Return zero if
28*ef5ccd6cSJohn Marino    TYPE is a dynamic array, non-zero otherwise.  */
29*ef5ccd6cSJohn Marino 
30cf7f2e2dSJohn Marino static int
dynamic_array_type(struct type * type,const gdb_byte * valaddr,int embedded_offset,CORE_ADDR address,struct ui_file * stream,int recurse,const struct value * val,const struct value_print_options * options)31cf7f2e2dSJohn Marino dynamic_array_type (struct type *type, const gdb_byte *valaddr,
32cf7f2e2dSJohn Marino 		    int embedded_offset, CORE_ADDR address,
33cf7f2e2dSJohn Marino 		    struct ui_file *stream, int recurse,
34cf7f2e2dSJohn Marino 		    const struct value *val,
35cf7f2e2dSJohn Marino 		    const struct value_print_options *options)
36cf7f2e2dSJohn Marino {
37cf7f2e2dSJohn Marino   if (TYPE_NFIELDS (type) == 2
38cf7f2e2dSJohn Marino       && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_INT
39cf7f2e2dSJohn Marino       && strcmp (TYPE_FIELD_NAME (type, 0), "length") == 0
40cf7f2e2dSJohn Marino       && strcmp (TYPE_FIELD_NAME (type, 1), "ptr") == 0
41cf7f2e2dSJohn Marino       && value_bits_valid (val, TARGET_CHAR_BIT * embedded_offset,
42cf7f2e2dSJohn Marino 			   TARGET_CHAR_BIT * TYPE_LENGTH (type)))
43cf7f2e2dSJohn Marino     {
44cf7f2e2dSJohn Marino       CORE_ADDR addr;
45cf7f2e2dSJohn Marino       struct type *elttype;
46cf7f2e2dSJohn Marino       struct type *true_type;
47cf7f2e2dSJohn Marino       struct type *ptr_type;
48c50c785cSJohn Marino       struct value *ival;
49cf7f2e2dSJohn Marino       int length;
50cf7f2e2dSJohn Marino 
51cf7f2e2dSJohn Marino       length = unpack_field_as_long (type, valaddr + embedded_offset, 0);
52cf7f2e2dSJohn Marino 
53cf7f2e2dSJohn Marino       ptr_type = TYPE_FIELD_TYPE (type, 1);
54cf7f2e2dSJohn Marino       elttype = check_typedef (TYPE_TARGET_TYPE (ptr_type));
55cf7f2e2dSJohn Marino       addr = unpack_pointer (ptr_type,
56cf7f2e2dSJohn Marino 			     valaddr + TYPE_FIELD_BITPOS (type, 1) / 8
57cf7f2e2dSJohn Marino 			     + embedded_offset);
58cf7f2e2dSJohn Marino       true_type = check_typedef (elttype);
59cf7f2e2dSJohn Marino 
60cf7f2e2dSJohn Marino       true_type = lookup_array_range_type (true_type, 0, length - 1);
61c50c785cSJohn Marino       ival = value_at (true_type, addr);
62cf7f2e2dSJohn Marino 
63*ef5ccd6cSJohn Marino       d_val_print (true_type,
64c50c785cSJohn Marino 		   value_contents_for_printing (ival),
65c50c785cSJohn Marino 		   value_embedded_offset (ival), addr,
66c50c785cSJohn Marino 		   stream, recurse + 1, ival, options);
67*ef5ccd6cSJohn Marino       return 0;
68cf7f2e2dSJohn Marino     }
69*ef5ccd6cSJohn Marino   return 1;
70cf7f2e2dSJohn Marino }
71cf7f2e2dSJohn Marino 
72cf7f2e2dSJohn Marino /* Implements the la_val_print routine for language D.  */
73*ef5ccd6cSJohn Marino void
d_val_print(struct type * type,const gdb_byte * valaddr,int embedded_offset,CORE_ADDR address,struct ui_file * stream,int recurse,const struct value * val,const struct value_print_options * options)74cf7f2e2dSJohn Marino d_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
75cf7f2e2dSJohn Marino              CORE_ADDR address, struct ui_file *stream, int recurse,
76cf7f2e2dSJohn Marino 	     const struct value *val,
77cf7f2e2dSJohn Marino              const struct value_print_options *options)
78cf7f2e2dSJohn Marino {
79cf7f2e2dSJohn Marino   int ret;
80cf7f2e2dSJohn Marino 
81cf7f2e2dSJohn Marino   CHECK_TYPEDEF (type);
82cf7f2e2dSJohn Marino   switch (TYPE_CODE (type))
83cf7f2e2dSJohn Marino     {
84cf7f2e2dSJohn Marino       case TYPE_CODE_STRUCT:
85cf7f2e2dSJohn Marino         ret = dynamic_array_type (type, valaddr, embedded_offset, address,
86cf7f2e2dSJohn Marino 				  stream, recurse, val, options);
87*ef5ccd6cSJohn Marino 	if (ret == 0)
88cf7f2e2dSJohn Marino 	  break;
89cf7f2e2dSJohn Marino       default:
90*ef5ccd6cSJohn Marino 	c_val_print (type, valaddr, embedded_offset, address, stream,
91cf7f2e2dSJohn Marino 		     recurse, val, options);
92cf7f2e2dSJohn Marino     }
93cf7f2e2dSJohn Marino }
94