Commit | Line | Data |
---|---|---|
7a9eb4c4 PB |
1 | /* Support for printing Java values for GDB, the GNU debugger. |
2 | Copyright 1997 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GDB. | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
19 | ||
20 | #include "defs.h" | |
21 | #include "symtab.h" | |
22 | #include "gdbtypes.h" | |
23 | #include "expression.h" | |
24 | #include "value.h" | |
25 | #include "demangle.h" | |
26 | #include "valprint.h" | |
27 | #include "language.h" | |
166606b7 | 28 | #include "jv-lang.h" |
40b647e9 | 29 | #include "c-lang.h" |
7a9eb4c4 PB |
30 | |
31 | int | |
32 | java_value_print (val, stream, format, pretty) | |
33 | value_ptr val; | |
34 | GDB_FILE *stream; | |
35 | int format; | |
36 | enum val_prettyprint pretty; | |
37 | { | |
38 | struct type *type = VALUE_TYPE (val); | |
fc655dc2 PB |
39 | CORE_ADDR address = VALUE_ADDRESS (val) + VALUE_OFFSET (val); |
40 | if (is_object_type (type)) | |
41 | { | |
42 | CORE_ADDR obj_addr = unpack_pointer (type, VALUE_CONTENTS (val)); | |
43 | if (obj_addr != 0) | |
44 | { | |
45 | value_ptr obj_val | |
46 | = value_at (TYPE_TARGET_TYPE (type), obj_addr, NULL); | |
47 | type = type_from_class (java_class_from_object (obj_val)); | |
48 | type = lookup_pointer_type (type); | |
49 | } | |
50 | } | |
51 | if (TYPE_CODE (type) == TYPE_CODE_PTR && ! value_logical_not (val)) | |
7a9eb4c4 | 52 | { |
7a9eb4c4 | 53 | type_print (TYPE_TARGET_TYPE (type), "", stream, -1); |
7a9eb4c4 | 54 | } |
fc655dc2 PB |
55 | |
56 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT && TYPE_TAG_NAME (type) != NULL | |
57 | && TYPE_TAG_NAME (type)[0] == '[') | |
58 | { | |
59 | value_ptr len = value_at (java_int_type, address + JAVA_OBJECT_SIZE, 0); | |
60 | long length = value_as_long (len); | |
61 | fprintf_filtered (stream, "{"); | |
62 | fprintf_filtered (stream, "length = %ld", length); | |
63 | fprintf_filtered (stream, "}"); | |
64 | return 0; | |
65 | } | |
66 | ||
67 | return (val_print (type, VALUE_CONTENTS (val), address, | |
7a9eb4c4 PB |
68 | stream, format, 1, 0, pretty)); |
69 | } | |
70 | ||
71 | int | |
72 | java_val_print (type, valaddr, address, stream, format, deref_ref, recurse, | |
73 | pretty) | |
74 | struct type *type; | |
75 | char *valaddr; | |
76 | CORE_ADDR address; | |
77 | GDB_FILE *stream; | |
78 | int format; | |
79 | int deref_ref; | |
80 | int recurse; | |
81 | enum val_prettyprint pretty; | |
82 | { | |
fc655dc2 PB |
83 | register unsigned int i = 0; /* Number of characters printed */ |
84 | struct type *elttype; | |
85 | CORE_ADDR addr; | |
86 | ||
d2e131a1 | 87 | CHECK_TYPEDEF (type); |
fc655dc2 | 88 | switch (TYPE_CODE (type)) |
7a9eb4c4 | 89 | { |
fc655dc2 PB |
90 | case TYPE_CODE_PTR: |
91 | if (format && format != 's') | |
7a9eb4c4 | 92 | { |
fc655dc2 PB |
93 | print_scalar_formatted (valaddr, type, format, 0, stream); |
94 | break; | |
7a9eb4c4 | 95 | } |
fc655dc2 PB |
96 | #if 0 |
97 | if (vtblprint && cp_is_vtbl_ptr_type(type)) | |
98 | { | |
99 | /* Print the unmangled name if desired. */ | |
100 | /* Print vtable entry - we only get here if we ARE using | |
101 | -fvtable_thunks. (Otherwise, look under TYPE_CODE_STRUCT.) */ | |
102 | print_address_demangle(extract_address (valaddr, TYPE_LENGTH (type)), | |
103 | stream, demangle); | |
104 | break; | |
105 | } | |
106 | #endif | |
107 | addr = unpack_pointer (type, valaddr); | |
108 | if (addr == 0) | |
109 | { | |
110 | fputs_filtered ("null", stream); | |
111 | return i; | |
112 | } | |
113 | elttype = check_typedef (TYPE_TARGET_TYPE (type)); | |
114 | { | |
115 | print_unpacked_pointer: | |
116 | elttype = check_typedef (TYPE_TARGET_TYPE (type)); | |
117 | ||
118 | if (TYPE_CODE (elttype) == TYPE_CODE_FUNC) | |
119 | { | |
120 | /* Try to print what function it points to. */ | |
121 | print_address_demangle (addr, stream, demangle); | |
122 | /* Return value is irrelevant except for string pointers. */ | |
123 | return (0); | |
124 | } | |
125 | ||
126 | if (addressprint && format != 's') | |
127 | { | |
128 | fputs_filtered ("@", stream); | |
129 | print_longest (stream, 'x', 0, (ULONGEST) addr); | |
130 | } | |
131 | return i; | |
132 | } | |
133 | break; | |
d2e131a1 PB |
134 | default: |
135 | return c_val_print (type, valaddr, address, stream, format, | |
136 | deref_ref, recurse, pretty); | |
137 | } | |
7a9eb4c4 | 138 | } |