]> git.pld-linux.org Git - packages/gdb.git/blame - gdb-check-type.patch
- typo
[packages/gdb.git] / gdb-check-type.patch
CommitLineData
a7de96f0
PS
1http://sourceware.org/ml/gdb-cvs/2012-08/msg00133.html
2
3### src/gdb/ChangeLog 2012/08/17 03:06:10 1.14599
4### src/gdb/ChangeLog 2012/08/17 17:36:56 1.14600
5## -1,3 +1,48 @@
6+2012-08-17 Keith Seitz <keiths@redhat.com>
7+
8+ PR c++/13356
9+ * gdbtypes.c (strict_type_checking): New variable.
10+ (show_strict_type_checking): New function.
11+ (rank_one_type): Return NS_POINTER_INTEGER_CONVERSION_BADNESS
12+ if strict type checking is disabled.
13+ (_initialize_gdbtypes): Add "check type" subcommand.
14+ * gdbtypes.h (NS_INTEGER_POINTER_CONVERSION_BADNESS): New struct.
15+
16+2012-08-17 Keith Seitz <keiths@redhat.com>
17+
18+ * language.h (type_mode): Remove.
19+ (type_check): Remove.
20+ (struct language_defn): Remove la_type_check.
21+ (STRICT_TYPE): Remove unused macro.
22+ (type_error): Remove.
23+ * language.c (set_type_range_case): Renamed to ...
24+ (set_range_case): ... this. Update all callers.
25+ Remove type_mode/type_check.
26+ (type_mode): Remove.
27+ (type_check): Remove.
28+ (show_type_command): Remove.
29+ (set_type_command): Remove.
30+ (language_info): Remove type checking output.
31+ (type_error): Remove unused function.
32+ (range_error): Update comment.
33+ (unknown_language_defn): Remove la_type_check.
34+ (auto_language_defn): Likewise.
35+ (local_language_defn): Likewise.
36+ (_initialize_language): Remove "check type" subcommand.
37+ * ada-lang.c (ada_language_defn): Remove la_type_check.
38+ * c-lang.c (c_language_defn): Likewise.
39+ (cplus_language_defn): Likewise.
40+ (asm_language_defn): Likewise.
41+ (minimal_language_defn): Likewise.
42+ * d-lang.c (d_language_defn): Likewise.
43+ * f-lang.c (f_language_defn): Likewise.
44+ * go-lang.c (go_language_defn): Likewise.
45+ * jv-lang.c (java_language_defn): Likewise.
46+ * m2-lang.c (m2_language_defn): Likewise.
47+ * objc-lang.c (objc_language_defn): Likewise.
48+ * opencl-lang.c (opencl_language_defn): Likewise.
49+ * p-lang.c (pascal_language_defn): Likewise.
50+
51 2012-08-16 Mike Frysinger <vapier@gentoo.org>
52
53 * infcmd.c (_initialize_infcmd): Remove trailing ) in next help text.
54Index: gdb-7.5.0.20120926/gdb/gdbtypes.c
55===================================================================
56--- gdb-7.5.0.20120926.orig/gdb/gdbtypes.c 2012-09-27 22:14:21.000000000 +0200
57+++ gdb-7.5.0.20120926/gdb/gdbtypes.c 2012-09-27 22:15:05.807706105 +0200
58@@ -62,6 +62,7 @@ const struct rank BASE_CONVERSION_BADNES
59 const struct rank REFERENCE_CONVERSION_BADNESS = {2,0};
60 const struct rank NULL_POINTER_CONVERSION_BADNESS = {2,0};
61 const struct rank NS_POINTER_CONVERSION_BADNESS = {10,0};
62+const struct rank NS_INTEGER_POINTER_CONVERSION_BADNESS = {3,0};
63
64 /* Floatformat pairs. */
65 const struct floatformat *floatformats_ieee_half[BFD_ENDIAN_UNKNOWN] = {
66@@ -134,6 +135,19 @@ show_overload_debug (struct ui_file *fil
67 value);
68 }
69
70+/* A flag to enable strict type checking. */
71+
72+static int strict_type_checking = 1;
73+
74+/* A function to show the status of strict type checking. */
75+
76+static void
77+show_strict_type_checking (struct ui_file *file, int from_tty,
78+ struct cmd_list_element *c, const char *value)
79+{
80+ fprintf_filtered (file, _("Strict type checking is %s.\n"), value);
81+}
82+
83 struct extra
84 {
85 char str[128];
86@@ -2649,12 +2663,20 @@ rank_one_type (struct type *parm, struct
87 case TYPE_CODE_FUNC:
88 return rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL);
89 case TYPE_CODE_INT:
90- if (value != NULL && TYPE_CODE (value_type (value)) == TYPE_CODE_INT
91- && value_as_long (value) == 0)
92+ if (value != NULL && TYPE_CODE (value_type (value)) == TYPE_CODE_INT)
93 {
94- /* Null pointer conversion: allow it to be cast to a pointer.
95- [4.10.1 of C++ standard draft n3290] */
96- return NULL_POINTER_CONVERSION_BADNESS;
97+ if (value_as_long (value) == 0)
98+ {
99+ /* Null pointer conversion: allow it to be cast to a pointer.
100+ [4.10.1 of C++ standard draft n3290] */
101+ return NULL_POINTER_CONVERSION_BADNESS;
102+ }
103+ else
104+ {
105+ /* If type checking is disabled, allow the conversion. */
106+ if (!strict_type_checking)
107+ return NS_INTEGER_POINTER_CONVERSION_BADNESS;
108+ }
109 }
110 /* fall through */
111 case TYPE_CODE_ENUM:
112@@ -4637,4 +4659,13 @@ _initialize_gdbtypes (void)
113 NULL, NULL,
114 show_opaque_type_resolution,
115 &setlist, &showlist);
116+
117+ /* Add an option to permit non-strict type checking. */
118+ add_setshow_boolean_cmd ("type", class_support,
119+ &strict_type_checking,
120+ _("Set strict type checking."),
121+ _("Show strict type checking."),
122+ NULL, NULL,
123+ show_strict_type_checking,
124+ &setchecklist, &showchecklist);
125 }
126Index: gdb-7.5.0.20120926/gdb/gdbtypes.h
127===================================================================
128--- gdb-7.5.0.20120926.orig/gdb/gdbtypes.h 2012-09-27 22:14:23.000000000 +0200
129+++ gdb-7.5.0.20120926/gdb/gdbtypes.h 2012-09-27 22:14:40.690695059 +0200
130@@ -1745,6 +1745,9 @@ extern const struct rank NULL_POINTER_CO
131 /* Converting a pointer to an int is usually OK. */
132 extern const struct rank NS_POINTER_CONVERSION_BADNESS;
133
134+/* Badness of converting a (non-zero) integer constant
135+ to a pointer. */
136+extern const struct rank NS_INTEGER_POINTER_CONVERSION_BADNESS;
137
138 extern struct rank sum_ranks (struct rank a, struct rank b);
139 extern int compare_ranks (struct rank a, struct rank b);
140Index: gdb-7.5.0.20120926/gdb/language.h
141===================================================================
142--- gdb-7.5.0.20120926.orig/gdb/language.h 2012-06-13 17:47:14.000000000 +0200
143+++ gdb-7.5.0.20120926/gdb/language.h 2012-09-27 22:14:40.834695121 +0200
144@@ -55,27 +55,6 @@ extern enum range_check
145 }
146 range_check;
147
148-/* type_mode ==
149- type_mode_auto: type_check set automatically to default of language.
150- type_mode_manual: type_check set manually by user. */
151-
152-extern enum type_mode
153- {
154- type_mode_auto, type_mode_manual
155- }
156-type_mode;
157-
158-/* type_check ==
159- type_check_on: Types are checked in GDB expressions, producing errors.
160- type_check_warn: Types are checked, producing warnings.
161- type_check_off: Types are not checked in GDB expressions. */
162-
163-extern enum type_check
164- {
165- type_check_off, type_check_warn, type_check_on
166- }
167-type_check;
168-
169 /* case_mode ==
170 case_mode_auto: case_sensitivity set upon selection of scope.
171 case_mode_manual: case_sensitivity set only by user. */
172@@ -162,10 +141,6 @@ struct language_defn
173
174 enum range_check la_range_check;
175
176- /* Default type checking. */
177-
178- enum type_check la_type_check;
179-
180 /* Default case sensitivity. */
181 enum case_sensitivity la_case_sensitivity;
182
183@@ -422,9 +397,6 @@ struct type *language_lookup_primitive_t
184 /* These macros define the behaviour of the expression
185 evaluator. */
186
187-/* Should we strictly type check expressions? */
188-#define STRICT_TYPE (type_check != type_check_off)
189-
190 /* Should we range check values against the domain of their type? */
191 #define RANGE_CHECK (range_check != range_check_off)
192
193@@ -496,8 +468,6 @@ extern void binop_type_check (struct val
194
195 /* Error messages */
196
197-extern void type_error (const char *, ...) ATTRIBUTE_PRINTF (1, 2);
198-
199 extern void range_error (const char *, ...) ATTRIBUTE_PRINTF (1, 2);
200
201 /* Data: Does this value represent "truth" to the current language? */
202Index: gdb-7.5.0.20120926/gdb/language.c
203===================================================================
204--- gdb-7.5.0.20120926.orig/gdb/language.c 2012-03-02 20:29:01.000000000 +0100
205+++ gdb-7.5.0.20120926/gdb/language.c 2012-09-27 22:14:40.922695162 +0200
206@@ -55,7 +55,7 @@ static void show_check (char *, int);
207
208 static void set_check (char *, int);
209
210-static void set_type_range_case (void);
211+static void set_range_case (void);
212
213 static void unk_lang_emit_char (int c, struct type *type,
214 struct ui_file *stream, int quoter);
215@@ -81,8 +81,6 @@ extern const struct language_defn unknow
216
217 enum range_mode range_mode = range_mode_auto;
218 enum range_check range_check = range_check_off;
219-enum type_mode type_mode = type_mode_auto;
220-enum type_check type_check = type_check_off;
221 enum case_mode case_mode = case_mode_auto;
222 enum case_sensitivity case_sensitivity = case_sensitive_on;
223
224@@ -174,7 +172,7 @@ set_language_command (char *ignore, int
225 /* Enter manual mode. Set the specified language. */
226 language_mode = language_mode_manual;
227 current_language = languages[i];
228- set_type_range_case ();
229+ set_range_case ();
230 expected_language = current_language;
231 return;
232 }
233@@ -186,79 +184,6 @@ set_language_command (char *ignore, int
234 language);
235 }
236
237-/* Show command. Display a warning if the type setting does
238- not match the current language. */
239-static void
240-show_type_command (struct ui_file *file, int from_tty,
241- struct cmd_list_element *c, const char *value)
242-{
243- if (type_mode == type_mode_auto)
244- {
245- char *tmp = NULL;
246-
247- switch (type_check)
248- {
249- case type_check_on:
250- tmp = "on";
251- break;
252- case type_check_off:
253- tmp = "off";
254- break;
255- case type_check_warn:
256- tmp = "warn";
257- break;
258- default:
259- internal_error (__FILE__, __LINE__,
260- "Unrecognized type check setting.");
261- }
262-
263- fprintf_filtered (gdb_stdout,
264- _("Type checking is \"auto; currently %s\".\n"),
265- tmp);
266- }
267- else
268- fprintf_filtered (gdb_stdout, _("Type checking is \"%s\".\n"),
269- value);
270-
271- if (type_check != current_language->la_type_check)
272- warning (_("the current type check setting"
273- " does not match the language.\n"));
274-}
275-
276-/* Set command. Change the setting for type checking. */
277-static void
278-set_type_command (char *ignore, int from_tty, struct cmd_list_element *c)
279-{
280- if (strcmp (type, "on") == 0)
281- {
282- type_check = type_check_on;
283- type_mode = type_mode_manual;
284- }
285- else if (strcmp (type, "warn") == 0)
286- {
287- type_check = type_check_warn;
288- type_mode = type_mode_manual;
289- }
290- else if (strcmp (type, "off") == 0)
291- {
292- type_check = type_check_off;
293- type_mode = type_mode_manual;
294- }
295- else if (strcmp (type, "auto") == 0)
296- {
297- type_mode = type_mode_auto;
298- set_type_range_case ();
299- return;
300- }
301- else
302- internal_error (__FILE__, __LINE__,
303- _("Unrecognized type check setting: \"%s\""), type);
304-
305- if (type_check != current_language->la_type_check)
306- warning (_("the current type check setting"
307- " does not match the language.\n"));
308-}
309-
310 /* Show command. Display a warning if the range setting does
311 not match the current language. */
312 static void
313@@ -320,7 +245,7 @@ set_range_command (char *ignore, int fro
314 else if (strcmp (range, "auto") == 0)
315 {
316 range_mode = range_mode_auto;
317- set_type_range_case ();
318+ set_range_case ();
319 return;
320 }
321 else
322@@ -389,7 +314,7 @@ set_case_command (char *ignore, int from
323 else if (strcmp (case_sensitive, "auto") == 0)
324 {
325 case_mode = case_mode_auto;
326- set_type_range_case ();
327+ set_range_case ();
328 return;
329 }
330 else
331@@ -409,14 +334,11 @@ set_case_command (char *ignore, int from
332 If SHOW is non-zero, then print out the current language,
333 type and range checking status. */
334 static void
335-set_type_range_case (void)
336+set_range_case (void)
337 {
338 if (range_mode == range_mode_auto)
339 range_check = current_language->la_range_check;
340
341- if (type_mode == type_mode_auto)
342- type_check = current_language->la_type_check;
343-
344 if (case_mode == case_mode_auto)
345 case_sensitivity = current_language->la_case_sensitivity;
346 }
347@@ -437,7 +359,7 @@ set_language (enum language lang)
348 if (languages[i]->la_language == lang)
349 {
350 current_language = languages[i];
351- set_type_range_case ();
352+ set_range_case ();
353 break;
354 }
355 }
356@@ -461,8 +383,6 @@ language_info (int quietly)
357
358 if (!quietly)
359 {
360- printf_unfiltered (_("Type checking: %s\n"), type);
361- show_type_command (NULL, 1, NULL, NULL);
362 printf_unfiltered (_("Range checking: %s\n"), range);
363 show_range_command (NULL, 1, NULL, NULL);
364 printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive);
365@@ -500,38 +420,11 @@ value_true (struct value *val)
366 error messages that occur during type- and range-
367 checking. */
368
369-/* These are called when a language fails a type- or range-check. The
370+/* This is called when a language fails a range-check. The
371 first argument should be a printf()-style format string, and the
372- rest of the arguments should be its arguments. If
373- [type|range]_check is [type|range]_check_on, an error is printed;
374- if [type|range]_check_warn, a warning; otherwise just the
375- message. */
376-
377-void
378-type_error (const char *string,...)
379-{
380- va_list args;
381-
382- va_start (args, string);
383- switch (type_check)
384- {
385- case type_check_warn:
386- vwarning (string, args);
387- break;
388- case type_check_on:
389- verror (string, args);
390- break;
391- case type_check_off:
392- /* FIXME: cagney/2002-01-30: Should this function print anything
393- when type error is off? */
394- vfprintf_filtered (gdb_stderr, string, args);
395- fprintf_filtered (gdb_stderr, "\n");
396- break;
397- default:
398- internal_error (__FILE__, __LINE__, _("bad switch"));
399- }
400- va_end (args);
401-}
402+ rest of the arguments should be its arguments. If range_check is
403+ range_check_on, an error is printed; if range_check_warn, a warning;
404+ otherwise just the message. */
405
406 void
407 range_error (const char *string,...)
408@@ -902,7 +795,6 @@ const struct language_defn unknown_langu
409 "unknown",
410 language_unknown,
411 range_check_off,
412- type_check_off,
413 case_sensitive_on,
414 array_row_major,
415 macro_expansion_no,
416@@ -946,7 +838,6 @@ const struct language_defn auto_language
417 "auto",
418 language_auto,
419 range_check_off,
420- type_check_off,
421 case_sensitive_on,
422 array_row_major,
423 macro_expansion_no,
424@@ -988,7 +879,6 @@ const struct language_defn local_languag
425 "local",
426 language_auto,
427 range_check_off,
428- type_check_off,
429 case_sensitive_on,
430 array_row_major,
431 macro_expansion_no,
432@@ -1135,13 +1025,6 @@ _initialize_language (void)
433 add_alias_cmd ("c", "check", no_class, 1, &showlist);
434 add_alias_cmd ("ch", "check", no_class, 1, &showlist);
435
436- add_setshow_enum_cmd ("type", class_support, type_or_range_names, &type,
437- _("Set type checking. (on/warn/off/auto)"),
438- _("Show type checking. (on/warn/off/auto)"),
439- NULL, set_type_command,
440- show_type_command,
441- &setchecklist, &showchecklist);
442-
443 add_setshow_enum_cmd ("range", class_support, type_or_range_names,
444 &range,
445 _("Set range checking. (on/warn/off/auto)"),
446Index: gdb-7.5.0.20120926/gdb/ada-lang.c
447===================================================================
448--- gdb-7.5.0.20120926.orig/gdb/ada-lang.c 2012-09-27 22:14:17.000000000 +0200
449+++ gdb-7.5.0.20120926/gdb/ada-lang.c 2012-09-27 22:14:41.112695245 +0200
450@@ -12503,7 +12503,6 @@ const struct language_defn ada_language_
451 "ada", /* Language name */
452 language_ada,
453 range_check_off,
454- type_check_off,
455 case_sensitive_on, /* Yes, Ada is case-insensitive, but
456 that's not quite what this means. */
457 array_row_major,
458Index: gdb-7.5.0.20120926/gdb/c-lang.c
459===================================================================
460--- gdb-7.5.0.20120926.orig/gdb/c-lang.c 2012-07-06 07:46:04.000000000 +0200
461+++ gdb-7.5.0.20120926/gdb/c-lang.c 2012-09-27 22:14:41.141695257 +0200
462@@ -831,7 +831,6 @@ const struct language_defn c_language_de
463 "c", /* Language name */
464 language_c,
465 range_check_off,
466- type_check_off,
467 case_sensitive_on,
468 array_row_major,
469 macro_expansion_c,
470@@ -955,7 +954,6 @@ const struct language_defn cplus_languag
471 "c++", /* Language name */
472 language_cplus,
473 range_check_off,
474- type_check_off,
475 case_sensitive_on,
476 array_row_major,
477 macro_expansion_c,
478@@ -997,7 +995,6 @@ const struct language_defn asm_language_
479 "asm", /* Language name */
480 language_asm,
481 range_check_off,
482- type_check_off,
483 case_sensitive_on,
484 array_row_major,
485 macro_expansion_c,
486@@ -1044,7 +1041,6 @@ const struct language_defn minimal_langu
487 "minimal", /* Language name */
488 language_minimal,
489 range_check_off,
490- type_check_off,
491 case_sensitive_on,
492 array_row_major,
493 macro_expansion_c,
494Index: gdb-7.5.0.20120926/gdb/d-lang.c
495===================================================================
496--- gdb-7.5.0.20120926.orig/gdb/d-lang.c 2012-03-15 15:06:20.000000000 +0100
497+++ gdb-7.5.0.20120926/gdb/d-lang.c 2012-09-27 22:14:41.143695257 +0200
498@@ -240,7 +240,6 @@ static const struct language_defn d_lang
499 "d",
500 language_d,
501 range_check_off,
502- type_check_off,
503 case_sensitive_on,
504 array_row_major,
505 macro_expansion_c,
506Index: gdb-7.5.0.20120926/gdb/f-lang.c
507===================================================================
508--- gdb-7.5.0.20120926.orig/gdb/f-lang.c 2012-09-27 22:14:23.000000000 +0200
509+++ gdb-7.5.0.20120926/gdb/f-lang.c 2012-09-27 22:14:41.151695260 +0200
510@@ -260,7 +260,6 @@ const struct language_defn f_language_de
511 "fortran",
512 language_fortran,
513 range_check_on,
514- type_check_on,
515 case_sensitive_off,
516 array_column_major,
517 macro_expansion_no,
518Index: gdb-7.5.0.20120926/gdb/go-lang.c
519===================================================================
520--- gdb-7.5.0.20120926.orig/gdb/go-lang.c 2012-04-25 16:07:20.000000000 +0200
521+++ gdb-7.5.0.20120926/gdb/go-lang.c 2012-09-27 22:14:41.152695261 +0200
522@@ -562,7 +562,6 @@ static const struct language_defn go_lan
523 "go",
524 language_go,
525 range_check_off,
526- type_check_off,
527 case_sensitive_on,
528 array_row_major,
529 macro_expansion_no,
530Index: gdb-7.5.0.20120926/gdb/jv-lang.c
531===================================================================
532--- gdb-7.5.0.20120926.orig/gdb/jv-lang.c 2012-09-27 22:14:23.000000000 +0200
533+++ gdb-7.5.0.20120926/gdb/jv-lang.c 2012-09-27 22:14:41.154695263 +0200
534@@ -1169,7 +1169,6 @@ const struct language_defn java_language
535 "java", /* Language name */
536 language_java,
537 range_check_off,
538- type_check_off,
539 case_sensitive_on,
540 array_row_major,
541 macro_expansion_no,
542Index: gdb-7.5.0.20120926/gdb/m2-lang.c
543===================================================================
544--- gdb-7.5.0.20120926.orig/gdb/m2-lang.c 2012-03-02 20:29:01.000000000 +0100
545+++ gdb-7.5.0.20120926/gdb/m2-lang.c 2012-09-27 22:14:41.161695266 +0200
546@@ -370,7 +370,6 @@ const struct language_defn m2_language_d
547 "modula-2",
548 language_m2,
549 range_check_on,
550- type_check_on,
551 case_sensitive_on,
552 array_row_major,
553 macro_expansion_no,
554Index: gdb-7.5.0.20120926/gdb/objc-lang.c
555===================================================================
556--- gdb-7.5.0.20120926.orig/gdb/objc-lang.c 2012-03-02 20:29:01.000000000 +0100
557+++ gdb-7.5.0.20120926/gdb/objc-lang.c 2012-09-27 22:14:41.163695268 +0200
558@@ -509,7 +509,6 @@ const struct language_defn objc_language
559 "objective-c", /* Language name */
560 language_objc,
561 range_check_off,
562- type_check_off,
563 case_sensitive_on,
564 array_row_major,
565 macro_expansion_c,
566Index: gdb-7.5.0.20120926/gdb/opencl-lang.c
567===================================================================
568--- gdb-7.5.0.20120926.orig/gdb/opencl-lang.c 2012-03-02 20:29:01.000000000 +0100
569+++ gdb-7.5.0.20120926/gdb/opencl-lang.c 2012-09-27 22:14:41.165695268 +0200
570@@ -993,7 +993,6 @@ const struct language_defn opencl_langua
571 "opencl", /* Language name */
572 language_opencl,
573 range_check_off,
574- type_check_off,
575 case_sensitive_on,
576 array_row_major,
577 macro_expansion_c,
578Index: gdb-7.5.0.20120926/gdb/p-lang.c
579===================================================================
580--- gdb-7.5.0.20120926.orig/gdb/p-lang.c 2012-03-02 20:29:01.000000000 +0100
581+++ gdb-7.5.0.20120926/gdb/p-lang.c 2012-09-27 22:14:41.170695270 +0200
582@@ -429,7 +429,6 @@ const struct language_defn pascal_langua
583 "pascal", /* Language name */
584 language_pascal,
585 range_check_on,
586- type_check_on,
587 case_sensitive_on,
588 array_row_major,
589 macro_expansion_no,
590Index: gdb-7.5.0.20120926/gdb/doc/gdb.texinfo
591===================================================================
592--- gdb-7.5.0.20120926.orig/gdb/doc/gdb.texinfo 2012-09-27 22:14:23.000000000 +0200
593+++ gdb-7.5.0.20120926/gdb/doc/gdb.texinfo 2012-09-27 22:14:41.188695279 +0200
594@@ -12648,29 +12648,18 @@ List all the filename extensions and the
595 @node Checks
596 @section Type and Range Checking
597
598-@quotation
599-@emph{Warning:} In this release, the @value{GDBN} commands for type and range
600-checking are included, but they do not yet have any effect. This
601-section documents the intended facilities.
602-@end quotation
603-@c FIXME remove warning when type/range code added
604-
605 Some languages are designed to guard you against making seemingly common
606 errors through a series of compile- and run-time checks. These include
607-checking the type of arguments to functions and operators, and making
608+checking the type of arguments to functions and operators and making
609 sure mathematical overflows are caught at run time. Checks such as
610 these help to ensure a program's correctness once it has been compiled
611-by eliminating type mismatches, and providing active checks for range
612+by eliminating type mismatches and providing active checks for range
613 errors when your program is running.
614
615-@value{GDBN} can check for conditions like the above if you wish.
616-Although @value{GDBN} does not check the statements in your program,
617-it can check expressions entered directly into @value{GDBN} for
618-evaluation via the @code{print} command, for example. As with the
619-working language, @value{GDBN} can also decide whether or not to check
620-automatically based on your program's source language.
621-@xref{Supported Languages, ,Supported Languages}, for the default
622-settings of supported languages.
623+By default @value{GDBN} checks for these errors according to the
624+rules of the current source language. Although @value{GDBN} does not check
625+the statements in your program, it can check expressions entered directly
626+into @value{GDBN} for evaluation via the @code{print} command, for example.
627
628 @menu
629 * Type Checking:: An overview of type checking
630@@ -12682,69 +12671,51 @@ settings of supported languages.
631 @node Type Checking
632 @subsection An Overview of Type Checking
633
634-Some languages, such as Modula-2, are strongly typed, meaning that the
635+Some languages, such as C and C@t{++}, are strongly typed, meaning that the
636 arguments to operators and functions have to be of the correct type,
637 otherwise an error occurs. These checks prevent type mismatch
638 errors from ever causing any run-time problems. For example,
639
640 @smallexample
641-1 + 2 @result{} 3
642+int klass::my_method(char *b) @{ return b ? 1 : 2; @}
643+
644+(@value{GDBP}) print obj.my_method (0)
645+$1 = 2
646 @exdent but
647-@error{} 1 + 2.3
648+(@value{GDBP}) print obj.my_method (0x1234)
649+Cannot resolve method klass::my_method to any overloaded instance
650 @end smallexample
651
652-The second example fails because the @code{CARDINAL} 1 is not
653-type-compatible with the @code{REAL} 2.3.
654+The second example fails because in C@t{++} the integer constant
655+@samp{0x1234} is not type-compatible with the pointer parameter type.
656
657-For the expressions you use in @value{GDBN} commands, you can tell the
658-@value{GDBN} type checker to skip checking;
659+For the expressions you use in @value{GDBN} commands, you can tell
660+@value{GDBN} to not enforce strict type checking or
661 to treat any mismatches as errors and abandon the expression;
662-or to only issue warnings when type mismatches occur,
663-but evaluate the expression anyway. When you choose the last of
664-these, @value{GDBN} evaluates expressions like the second example above, but
665-also issues a warning.
666+When type checking is disabled, @value{GDBN} successfully evaluates
667+expressions like the second example above.
668
669-Even if you turn type checking off, there may be other reasons
670+Even if type checking is off, there may be other reasons
671 related to type that prevent @value{GDBN} from evaluating an expression.
672 For instance, @value{GDBN} does not know how to add an @code{int} and
673 a @code{struct foo}. These particular type errors have nothing to do
674-with the language in use, and usually arise from expressions, such as
675-the one described above, which make little sense to evaluate anyway.
676-
677-Each language defines to what degree it is strict about type. For
678-instance, both Modula-2 and C require the arguments to arithmetical
679-operators to be numbers. In C, enumerated types and pointers can be
680-represented as numbers, so that they are valid arguments to mathematical
681-operators. @xref{Supported Languages, ,Supported Languages}, for further
682-details on specific languages.
683+with the language in use and usually arise from expressions which make
684+little sense to evaluate anyway.
685
686-@value{GDBN} provides some additional commands for controlling the type checker:
687+@value{GDBN} provides some additional commands for controlling type checking:
688
689 @kindex set check type
690 @kindex show check type
691 @table @code
692-@item set check type auto
693-Set type checking on or off based on the current working language.
694-@xref{Supported Languages, ,Supported Languages}, for the default settings for
695-each language.
696-
697 @item set check type on
698 @itemx set check type off
699-Set type checking on or off, overriding the default setting for the
700-current working language. Issue a warning if the setting does not
701-match the language default. If any type mismatches occur in
702+Set strict type checking on or off. If any type mismatches occur in
703 evaluating an expression while type checking is on, @value{GDBN} prints a
704 message and aborts evaluation of the expression.
705
706-@item set check type warn
707-Cause the type checker to issue warnings, but to always attempt to
708-evaluate the expression. Evaluating the expression may still
709-be impossible for other reasons. For example, @value{GDBN} cannot add
710-numbers and structures.
711-
712-@item show type
713-Show the current setting of the type checker, and whether or not @value{GDBN}
714-is setting it automatically.
715+@item show check type
716+Show the current setting of type checking and whether @value{GDBN}
717+is enforcing strict type checking rules.
718 @end table
719
720 @cindex range checking
721@@ -13195,8 +13166,8 @@ specification.
722
723 @cindex C and C@t{++} defaults
724
725-If you allow @value{GDBN} to set type and range checking automatically, they
726-both default to @code{off} whenever the working language changes to
727+If you allow @value{GDBN} to set range checking automatically, it
728+defaults to @code{off} whenever the working language changes to
729 C or C@t{++}. This happens regardless of whether you or @value{GDBN}
730 selects the working language.
731
732@@ -13207,37 +13178,15 @@ these files, it sets the working languag
733 @xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
734 for further details.
735
736-@c Type checking is (a) primarily motivated by Modula-2, and (b)
737-@c unimplemented. If (b) changes, it might make sense to let this node
738-@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
739-
740 @node C Checks
741 @subsubsection C and C@t{++} Type and Range Checks
742
743 @cindex C and C@t{++} checks
744
745-By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
746-is not used. However, if you turn type checking on, @value{GDBN}
747-considers two variables type equivalent if:
748-
749-@itemize @bullet
750-@item
751-The two variables are structured and have the same structure, union, or
752-enumerated tag.
753-
754-@item
755-The two variables have the same type name, or types that have been
756-declared equivalent through @code{typedef}.
757-
758-@ignore
759-@c leaving this out because neither J Gilmore nor R Pesch understand it.
760-@c FIXME--beers?
761-@item
762-The two @code{struct}, @code{union}, or @code{enum} variables are
763-declared in the same declaration. (Note: this may not be true for all C
764-compilers.)
765-@end ignore
766-@end itemize
767+By default, when @value{GDBN} parses C or C@t{++} expressions, strict type
768+checking is used. However, if you turn type checking off, @value{GDBN}
769+will allow certain non-standard conversions, such as promoting integer
770+constants to pointers.
771
772 Range checking, if turned on, is done on mathematical operations. Array
773 indices are not checked, since they are often used to index a pointer
774Index: gdb-7.5.0.20120926/gdb/testsuite/gdb.base/default.exp
775===================================================================
776--- gdb-7.5.0.20120926.orig/gdb/testsuite/gdb.base/default.exp 2012-04-27 22:52:06.000000000 +0200
777+++ gdb-7.5.0.20120926/gdb/testsuite/gdb.base/default.exp 2012-09-27 22:14:41.312695333 +0200
778@@ -495,12 +495,13 @@ gdb_test "section" "Must specify section
779 gdb_test "set annotate" "Argument required .integer to set it to.*" "set annotate"
780 #test set args
781 gdb_test_no_output "set args" "set args"
782-#test set check "c" abbreviation
783-gdb_test "set c" "\"set check\" must be followed by the name of a check subcommand.(\[^\r\n\]*\[\r\n\])+List of set check subcommands:(\[^\r\n\]*\[\r\n\])+set check range -- Set range checking(\[^\r\n\]*\[\r\n\])+set check type -- Set type checking(\[^\r\n\]*\[\r\n\])+Type \"help set check\" followed by set check subcommand name for full documentation.(\[^\r\n\]*\[\r\n\])+Command name abbreviations are allowed if unambiguous." "set check \"c\" abbreviation"
784-#test set check "ch" abbreviation
785-gdb_test "set ch" "\"set check\" must be followed by the name of a check subcommand.(\[^\r\n\]*\[\r\n\])+List of set check subcommands:(\[^\r\n\]*\[\r\n\])+set check range -- Set range checking(\[^\r\n\]*\[\r\n\])+set check type -- Set type checking(\[^\r\n\]*\[\r\n\])+Type \"help set check\" followed by set check subcommand name for full documentation.(\[^\r\n\]*\[\r\n\])+Command name abbreviations are allowed if unambiguous." "set check \"ch\" abbreviation"
786-#test set check
787-gdb_test "set check" "\"set check\" must be followed by the name of a check subcommand.(\[^\r\n\]*\[\r\n\])+List of set check subcommands:(\[^\r\n\]*\[\r\n\])+set check range -- Set range checking(\[^\r\n\]*\[\r\n\])+set check type -- Set type checking(\[^\r\n\]*\[\r\n\])+Type \"help set check\" followed by set check subcommand name for full documentation.(\[^\r\n\]*\[\r\n\])+Command name abbreviations are allowed if unambiguous." "set check"
788+
789+# Test set check abbreviations
790+foreach x {"c" "ch" "check"} {
791+ gdb_test "set $x" "\"set check\" must be followed by the name of a check subcommand.(\[^\r\n\]*\[\r\n\])+List of set check subcommands:(\[^\r\n\]*\[\r\n\])+set check range -- Set range checking(\[^\r\n\]*\[\r\n\])+set check type -- Set strict type checking(\[^\r\n\]*\[\r\n\])+Type \"help set check\" followed by set check subcommand name for full documentation.(\[^\r\n\]*\[\r\n\])+Command name abbreviations are allowed if unambiguous." \
792+ "set check \"$x\" abbreviation"
793+}
794+
795 #test set check range
796 gdb_test "set check range" ".*" "set check range"
797 #test set check type
798@@ -577,16 +578,17 @@ gdb_test "shell echo Hi dad!" "Hi dad!"
799 gdb_test "show annotate" "Annotation_level is 0." "show annotate"
800 #test show args
801 gdb_test "show args" "Argument list to give program being debugged when it is started is \"\"." "show args"
802-#test show check "c" abbreviation
803-gdb_test "show c" "range: *Range checking is \"auto; currently off\".(\[^\r\n\]*\[\r\n\])+type: *Type checking is \"auto; currently off\".*" "show check \"c\" abbreviation"
804-#test show check "ch" abbreviation
805-gdb_test "show ch" "range: *Range checking is \"auto; currently off\".(\[^\r\n\]*\[\r\n\])+type: *Type checking is \"auto; currently off\"." "show check \"ch\" abbreviation"
806-#test show check
807-gdb_test "show check" "range: *Range checking is \"auto; currently off\".(\[^\r\n\]*\[\r\n\])+type: *Type checking is \"auto; currently off\"." "show check"
808+
809+# test show check abbreviations
810+foreach x {"c" "ch" "check"} {
811+ gdb_test "show $x" "range: *Range checking is \"auto; currently off\".(\[^\r\n\]*\[\r\n\])+type: *Strict type checking is on\..*" \
812+ "show check \"$x\" abbreviation"
813+}
814+
815 #test show check range
816 gdb_test "show check range" "Range checking is \"auto; currently off\"." "show check range"
817 #test show check type
818-gdb_test "show check type" "Type checking is \"auto; currently off\"." "show check type"
819+gdb_test "show check type" "Strict type checking is on\." "show check type"
820 #test show commands
821 gdb_test "show commands" ".*" "show commands"
822 #test show complaints
823Index: gdb-7.5.0.20120926/gdb/testsuite/gdb.base/help.exp
824===================================================================
825--- gdb-7.5.0.20120926.orig/gdb/testsuite/gdb.base/help.exp 2012-07-02 19:53:19.000000000 +0200
826+++ gdb-7.5.0.20120926/gdb/testsuite/gdb.base/help.exp 2012-09-27 22:14:41.315695333 +0200
827@@ -376,22 +376,26 @@ gdb_test "help section" "Change the base
828 gdb_test "help set annotate" "Set annotation_level\.\[\r\n\]+0 == normal; 1 == fullname \\(for use when running under emacs\\)\[\r\n\]+2 == output annotated suitably for use by programs that control GDB\." "help set annotate"
829 # test help set args
830 gdb_test "help set args" "Set argument list to give program being debugged when it is started\.\[\r\n\]+Follow this command with any number of args, to be passed to the program\."
831-# test help set check "c" abbreviation
832-test_prefix_command_help {"set c" "set check"} {
833- "Set the status of the type/range checker\.\[\r\n\]+"
834-} "help set check \"c\" abbreviation"
835-# test help set check "ch" abbreviation
836-test_prefix_command_help {"set ch" "set check"} {
837- "Set the status of the type/range checker\.\[\r\n\]+"
838-} "help set check \"ch\" abbreviation"
839-# test help set check
840+
841+# Test help set check abbreviations
842+foreach x {"c" "ch"} {
843+ test_prefix_command_help [list "set $x" "set check"] {
844+ "Set the status of the type/range checker\.\[\r\n\]+"
845+ } "help set check \"$x\" abbreviation"
846+}
847+
848+# Test help set check
849 test_prefix_command_help {"set check"} {
850 "Set the status of the type/range checker\.\[\r\n\]+"
851 }
852+
853 # test help set check range
854 gdb_test "help set check range" "Set range checking\. \\(on/warn/off/auto\\)" "help set check range"
855-# test help set check type
856-gdb_test "help set check type" "Set type checking\. \\(on/warn/off/auto\\)." "help set check type"
857+
858+# Test help set check type
859+gdb_test "help set check type" "Set strict type checking\." \
860+ "help set check type"
861+
862 # test help set complaints
863 gdb_test "help set complaints" "Set max number of complaints about incorrect symbols\." "help set complaints"
864 # test help set confirm
865@@ -487,18 +491,25 @@ gdb_test "help shell" "Execute the rest
866 gdb_test "help show annotate" "Show annotation_level\.\[\r\n\]+0 == normal; 1 == fullname \\(for use when running under emacs\\)\[\r\n\]+2 == output annotated suitably for use by programs that control GDB\." "help show annotate"
867 # test help show args
868 gdb_test "help show args" "Show argument list to give program being debugged when it is started\.\[\r\n\]+Follow this command with any number of args, to be passed to the program\."
869-# test help show check "c" abbreviation
870-test_prefix_command_help {"show c" "show check"} {
871- "Show the status of the type/range checker\.\[\r\n\]+"
872-} "help show check \"c\" abbreviation"
873+
874+# Test help show check abbreviations
875+foreach x {"c" "check"} {
876+ test_prefix_command_help [list "show $x" "show check"] {
877+ "Show the status of the type/range checker\.\[\r\n\]+"
878+ } "help show check \"$x\" abbreviation"
879+}
880+
881 # test help show check
882 test_prefix_command_help {"show check"} {
883 "Show the status of the type/range checker\.\[\r\n\]+"
884 }
885 # test help show check range
886 gdb_test "help show check range" "Show range checking\. \\(on/warn/off/auto\\)" "help show check range"
887+
888 # test help show check type
889-gdb_test "help show check type" "Show type checking\. \\(on/warn/off/auto\\)" "help show check type"
890+gdb_test "help show check type" "Show strict type checking\." \
891+ "help show check type"
892+
893 # test help show commands
894 gdb_test "help show commands" "Show the history of commands you typed\.\[\r\n\]+You can supply a command number to start with, or a `\[+\]' to start after\[\r\n\]+the previous command number shown\." "help show commands"
895 # test help show complaints
896Index: gdb-7.5.0.20120926/gdb/testsuite/gdb.base/setshow.exp
897===================================================================
898--- gdb-7.5.0.20120926.orig/gdb/testsuite/gdb.base/setshow.exp 2012-03-13 22:02:40.000000000 +0100
899+++ gdb-7.5.0.20120926/gdb/testsuite/gdb.base/setshow.exp 2012-09-27 22:14:41.320695336 +0200
900@@ -110,19 +110,22 @@ gdb_test "show check range" "Range check
901 #test set check range auto
902 gdb_test_no_output "set check range auto" "set check range auto"
903 #test show check range auto
904-gdb_test "show check range" "Range checking is \"auto; currently .*" "show check range (auto)"
905-#test set check type on
906-gdb_test "set check type on" ".*" "set check type on"
907-#test show check type on
908-gdb_test "show check type" "Type checking is \"on\"..*" "show check type (on)"
909-#test set check type off with trailing space
910-gdb_test_no_output "set check type off " "set check type off"
911-#test show check type off
912-gdb_test "show check type" "Type checking is \"off\"..*" "show check type (off)"
913-#test set check type auto
914-gdb_test_no_output "set check type auto" "set check type auto"
915-#test show check type
916-gdb_test "show check type" "Type checking is \"auto; currently .*" "show check type (auto)"
917+gdb_test "show check range" "Range checking is \"auto; currently .*" "show check range (auto)"
918+
919+# Test set check type on
920+gdb_test "set check type on" ".*" "set check type on"
921+
922+# Test show check type on
923+gdb_test "show check type" "Strict type checking is on\..*" \
924+ "show check type (on)"
925+
926+# Test set check type off with trailing space
927+gdb_test_no_output "set check type off " "set check type off"
928+
929+# Test show check type off
930+gdb_test "show check type" "Strict type checking is off\..*" \
931+ "show check type (off)"
932+
933 #test set complaints 100
934 gdb_test_no_output "set complaints 100" "set complaints 100"
935 #test show complaints 100
936Index: gdb-7.5.0.20120926/gdb/testsuite/gdb.cp/converts.exp
937===================================================================
938--- gdb-7.5.0.20120926.orig/gdb/testsuite/gdb.cp/converts.exp 2012-07-10 17:18:18.000000000 +0200
939+++ gdb-7.5.0.20120926/gdb/testsuite/gdb.cp/converts.exp 2012-09-27 22:14:41.321695337 +0200
940@@ -70,9 +70,37 @@ gdb_test_multiple "p foo3_1 (0, 0)" $t {
941 pass $t
942 }
943 }
944+
945 gdb_test "p foo3_1 (0, 1)" \
946 "Cannot resolve function foo3_1 to any overloaded instance"
947 gdb_test "p foo3_1 (0, (const char**) 1)" " = 31"
948 gdb_test "p foo3_2 (0, 0)" "= 32"
949 gdb_test "p foo3_2 (0, (char const**) 0)" " = 320"
950
951+# Test for strict type checking
952+set error_str "Cannot resolve function %s to any overloaded instance"
953+gdb_test "show check type" "Strict type checking is on\."
954+gdb_test "p foo1_type_check (123)" [format $error_str "foo1_type_check"]
955+gdb_test "p foo2_type_check (0, 1)" [format $error_str "foo2_type_check"]
956+gdb_test "p foo2_type_check (1, 0)" [format $error_str "foo2_type_check"]
957+gdb_test "p foo2_type_check (1, 1)" [format $error_str "foo2_type_check"]
958+gdb_test "p foo3_type_check (0, 0, 1)" [format $error_str "foo3_type_check"]
959+gdb_test "p foo3_type_check (0, 1, 0)" [format $error_str "foo3_type_check"]
960+gdb_test "p foo3_type_check (1, 0, 0)" [format $error_str "foo3_type_check"]
961+gdb_test "p foo3_type_check (0, 1, 1)" [format $error_str "foo3_type_check"]
962+gdb_test "p foo3_type_check (1, 1, 0)" [format $error_str "foo3_type_check"]
963+gdb_test "p foo3_type_check (1, 1, 1)" [format $error_str "foo3_type_check"]
964+
965+gdb_test_no_output "set check type off"
966+gdb_test "show check type" "Strict type checking is off\."
967+gdb_test "p foo1_type_check (123)" " = 1000"
968+gdb_test "p foo2_type_check (0, 1)" " = 1001"
969+gdb_test "p foo2_type_check (1, 0)" " = 1001"
970+gdb_test "p foo2_type_check (1, 1)" " = 1001"
971+gdb_test "p foo3_type_check (0, 0, 1)" " = 1002"
972+gdb_test "p foo3_type_check (0, 1, 0)" " = 1002"
973+gdb_test "p foo3_type_check (1, 0, 0)" " = 1002"
974+gdb_test "p foo3_type_check (0, 1, 1)" " = 1002"
975+gdb_test "p foo3_type_check (1, 1, 0)" " = 1002"
976+gdb_test "p foo3_type_check (1, 1, 1)" " = 1002"
977+gdb_test "p foo3_2 (1,1)" " = 32"
978Index: gdb-7.5.0.20120926/gdb/testsuite/gdb.cp/converts.cc
979===================================================================
980--- gdb-7.5.0.20120926.orig/gdb/testsuite/gdb.cp/converts.cc 2011-10-14 22:22:50.000000000 +0200
981+++ gdb-7.5.0.20120926/gdb/testsuite/gdb.cp/converts.cc 2012-09-27 22:14:41.322695337 +0200
982@@ -27,6 +27,10 @@ int foo3_1 (int a, const char **b) { ret
983 int foo3_2 (int a, int b) { return 32; }
984 int foo3_2 (int a, const char **b) { return 320; }
985
986+int foo1_type_check (char *a) { return 1000; }
987+int foo2_type_check (char *a, char *b) { return 1001; }
988+int foo3_type_check (char *a, char *b, char *c) { return 1002; }
989+
990 int main()
991 {
992
993@@ -62,5 +66,9 @@ int main()
994 foo3_2 (0, static_cast<char const**> (0));
995 foo3_2 (0, 0);
996
997+ foo1_type_check (a);
998+ foo2_type_check (a, a);
999+ foo3_type_check (a, a, a);
1000+
1001 return 0; // end of main
1002 }
This page took 0.267246 seconds and 4 git commands to generate.