Include common-defs.h instead of defs.h/server.h in shared code
[deliverable/binutils-gdb.git] / gdb / c-lang.c
index 33bb4443f088215244d743014832bf3ddf202c5f..185b38ed0c99fc71408084b9cba5bd3fa304a3e5 100644 (file)
@@ -1,6 +1,6 @@
 /* C language support routines for GDB, the GNU debugger.
 
-   Copyright (C) 1992-2013 Free Software Foundation, Inc.
+   Copyright (C) 1992-2014 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 #include "expression.h"
 #include "parser-defs.h"
 #include "language.h"
+#include "varobj.h"
 #include "c-lang.h"
 #include "valprint.h"
 #include "macroscope.h"
-#include "gdb_assert.h"
 #include "charset.h"
-#include "gdb_string.h"
 #include "demangle.h"
 #include "cp-abi.h"
 #include "cp-support.h"
@@ -226,9 +225,13 @@ c_printstr (struct ui_file *stream, struct type *type,
    until a null character of the appropriate width is found, otherwise
    the string is read to the length of characters specified.  The size
    of a character is determined by the length of the target type of
-   the pointer or array.  If VALUE is an array with a known length,
-   the function will not read past the end of the array.  On
-   completion, *LENGTH will be set to the size of the string read in
+   the pointer or array.
+
+   If VALUE is an array with a known length, and *LENGTH is -1,
+   the function will not read past the end of the array.  However, any
+   declared size of the array is ignored if *LENGTH > 0.
+
+   On completion, *LENGTH will be set to the size of the string read in
    characters.  (If a length of -1 is specified, the length returned
    will not include the null character).  CHARSET is always set to the
    target charset.  */
@@ -308,6 +311,21 @@ c_get_string (struct value *value, gdb_byte **buffer,
     {
       CORE_ADDR addr = value_as_address (value);
 
+      /* Prior to the fix for PR 16196 read_string would ignore fetchlimit
+        if length > 0.  The old "broken" behaviour is the behaviour we want:
+        The caller may want to fetch 100 bytes from a variable length array
+        implemented using the common idiom of having an array of length 1 at
+        the end of a struct.  In this case we want to ignore the declared
+        size of the array.  However, it's counterintuitive to implement that
+        behaviour in read_string: what does fetchlimit otherwise mean if
+        length > 0.  Therefore we implement the behaviour we want here:
+        If *length > 0, don't specify a fetchlimit.  This preserves the
+        previous behaviour.  We could move this check above where we know
+        whether the array is declared with a fixed size, but we only want
+        to apply this behaviour when calling read_string.  PR 16286.  */
+      if (*length > 0)
+       fetchlimit = UINT_MAX;
+
       err = read_string (addr, *length, width, fetchlimit,
                         byte_order, buffer, length);
       if (err)
@@ -811,6 +829,7 @@ const struct exp_descriptor exp_descriptor_c =
 const struct language_defn c_language_defn =
 {
   "c",                         /* Language name */
+  "C",
   language_c,
   range_check_off,
   case_sensitive_on,
@@ -846,6 +865,7 @@ const struct language_defn c_language_defn =
   c_get_string,
   NULL,                                /* la_get_symbol_name_cmp */
   iterate_over_symbols,
+  &c_varobj_ops,
   LANG_MAGIC
 };
 
@@ -934,6 +954,7 @@ cplus_language_arch_info (struct gdbarch *gdbarch,
 const struct language_defn cplus_language_defn =
 {
   "c++",                       /* Language name */
+  "C++",
   language_cplus,
   range_check_off,
   case_sensitive_on,
@@ -969,12 +990,14 @@ const struct language_defn cplus_language_defn =
   c_get_string,
   NULL,                                /* la_get_symbol_name_cmp */
   iterate_over_symbols,
+  &cplus_varobj_ops,
   LANG_MAGIC
 };
 
 const struct language_defn asm_language_defn =
 {
   "asm",                       /* Language name */
+  "assembly",
   language_asm,
   range_check_off,
   case_sensitive_on,
@@ -1010,6 +1033,7 @@ const struct language_defn asm_language_defn =
   c_get_string,
   NULL,                                /* la_get_symbol_name_cmp */
   iterate_over_symbols,
+  &default_varobj_ops,
   LANG_MAGIC
 };
 
@@ -1021,6 +1045,7 @@ const struct language_defn asm_language_defn =
 const struct language_defn minimal_language_defn =
 {
   "minimal",                   /* Language name */
+  "Minimal",
   language_minimal,
   range_check_off,
   case_sensitive_on,
@@ -1056,6 +1081,7 @@ const struct language_defn minimal_language_defn =
   c_get_string,
   NULL,                                /* la_get_symbol_name_cmp */
   iterate_over_symbols,
+  &default_varobj_ops,
   LANG_MAGIC
 };
 
This page took 0.025225 seconds and 4 git commands to generate.