Revert broken changes.
[mono.git] / mcs / class / Mono.CSharp.Debugger / csharp-lang.c
1 /* -*- mode: C; c-basic-offset: 2 -*-
2
3    C# language support for Mono.
4    Copyright 2002 Ximian, Inc.
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,
19    Boston, MA 02111-1307, USA.  */
20
21 #include "defs.h"
22 #include "symtab.h"
23 #include "gdbtypes.h"
24 #include "expression.h"
25 #include "parser-defs.h"
26 #include "language.h"
27 #include "gdbtypes.h"
28 #include "symtab.h"
29 #include "symfile.h"
30 #include "objfiles.h"
31 #include "gdb_string.h"
32 #include "value.h"
33 #include "csharp-lang.h"
34 #include "c-lang.h"
35 #include "gdbcore.h"
36 #include <ctype.h>
37
38 /* Print the character C on STREAM as part of the contents of a literal
39    string whose delimiter is QUOTER.  Note that that format for printing
40    characters and strings is language specific. */
41
42 void
43 csharp_emit_char (int c, struct ui_file *stream, int quoter)
44 {
45   switch (c)
46     {
47     case '\\':
48     case '\'':
49       fprintf_filtered (stream, "\\%c", c);
50       break;
51     case '\b':
52       fputs_filtered ("\\b", stream);
53       break;
54     case '\t':
55       fputs_filtered ("\\t", stream);
56       break;
57     case '\n':
58       fputs_filtered ("\\n", stream);
59       break;
60     case '\f':
61       fputs_filtered ("\\f", stream);
62       break;
63     case '\r':
64       fputs_filtered ("\\r", stream);
65       break;
66     default:
67       if (isprint (c))
68         fputc_filtered (c, stream);
69       else
70         fprintf_filtered (stream, "\\u%.4x", (unsigned int) c);
71       break;
72     }
73 }
74
75 int
76 csharp_value_print (struct value *val, struct ui_file *stream, int format,
77                     enum val_prettyprint pretty)
78 {
79   struct type *type;
80   CORE_ADDR address;
81   int i;
82   char *name;
83
84   type = VALUE_TYPE (val);
85   address = VALUE_ADDRESS (val) + VALUE_OFFSET (val);
86
87   /* If it's type String, print it */
88
89   if (TYPE_CODE (type) == TYPE_CODE_PTR
90       && TYPE_TARGET_TYPE (type)
91       && TYPE_TAG_NAME (TYPE_TARGET_TYPE (type))
92       && strcmp (TYPE_TAG_NAME (TYPE_TARGET_TYPE (type)), "MonoString") == 0
93       && (format == 0 || format == 's')
94       && address != 0
95       && value_as_address (val) != 0)
96     {
97       struct value *data_val;
98       CORE_ADDR data;
99       struct value *count_val;
100       unsigned long count;
101       struct value *mark;
102
103       mark = value_mark ();     /* Remember start of new values */
104
105       data_val = value_struct_elt (&val, NULL, "Chars", NULL, NULL);
106       data = VALUE_ADDRESS (data_val) + VALUE_OFFSET (data_val);
107
108       count_val = value_struct_elt (&val, NULL, "Length", NULL, NULL);
109       count = value_as_address (count_val);
110
111       value_free_to_mark (mark);        /* Release unnecessary values */
112
113       val_print_string (data, count, 2, stream);
114
115       return 0;
116     }
117
118   return (val_print (type, VALUE_CONTENTS (val), 0, address,
119                      stream, format, 1, 0, pretty));
120 }
121
122
123 /* Print data of type TYPE located at VALADDR (within GDB), which came from
124    the inferior at address ADDRESS, onto stdio stream STREAM according to
125    FORMAT (a letter or 0 for natural format).  The data at VALADDR is in
126    target byte order.
127
128    If the data are a string pointer, returns the number of string characters
129    printed.
130
131    If DEREF_REF is nonzero, then dereference references, otherwise just print
132    them like pointers.
133
134    The PRETTY parameter controls prettyprinting.  */
135
136 int
137 csharp_val_print (struct type *type, char *valaddr, int embedded_offset,
138                   CORE_ADDR address, struct ui_file *stream, int format,
139                   int deref_ref, int recurse, enum val_prettyprint pretty)
140 {
141   register unsigned int i = 0;  /* Number of characters printed */
142   struct type *target_type;
143   LONGEST length;
144   CORE_ADDR addr;
145
146   CHECK_TYPEDEF (type);
147   switch (TYPE_CODE (type))
148     {
149 #if 0
150     case TYPE_CODE_CSHARP_STRING:
151       addr = address + TYPE_CSHARP_STRING_LENGTH_OFFSET (type);
152       length = read_memory_integer (addr, TYPE_CSHARP_STRING_LENGTH_BYTESIZE (type));
153
154       addr = address + TYPE_CSHARP_STRING_DATA_OFFSET (type);
155
156       return val_print_string (addr, length, 2, stream);
157
158     case TYPE_CODE_PTR:
159       addr = unpack_pointer (type, valaddr);
160       target_type = check_typedef (TYPE_TARGET_TYPE (type));
161
162       if (deref_ref && addr != 0)
163         {
164           if (TYPE_CODE (target_type) == TYPE_CODE_CSHARP_STRING)
165             return csharp_val_print (target_type, NULL, 0, addr, stream,
166                                      format, deref_ref, recurse, pretty);
167           else
168             return 0;
169         }
170
171       return c_val_print (type, valaddr, embedded_offset, address, stream,
172                           format, deref_ref, recurse, pretty);
173 #endif
174
175     default:
176       return c_val_print (type, valaddr, embedded_offset, address, stream,
177                           format, deref_ref, recurse, pretty);
178     }
179
180   return 0;
181 }
182
183 /* Table mapping opcodes into strings for printing operators
184    and precedences of the operators.  */
185
186 const struct op_print csharp_op_print_tab[] =
187 {
188   {NULL, 0, 0, 0}
189 };