X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fc-lang.c;h=4b44b950ee695e1eb0ced44aaf981c7b13c7d65e;hb=2608dbf8a3ee666ac0a7d5d7c45611d489edcda5;hp=48a1fb02be990a7d171ec1adcec5d88d4f2aaf14;hpb=51a5cd9059b96a2ac33cf149d369db12b891fd96;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/c-lang.c b/gdb/c-lang.c index 48a1fb02be..4b44b950ee 100644 --- a/gdb/c-lang.c +++ b/gdb/c-lang.c @@ -1,6 +1,6 @@ /* C language support routines for GDB, the GNU debugger. - Copyright (C) 1992-2013 Free Software Foundation, Inc. + Copyright (C) 1992-2015 Free Software Foundation, Inc. This file is part of GDB. @@ -23,18 +23,17 @@ #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" #include "gdb_obstack.h" #include -#include "exceptions.h" +#include "gdbcore.h" extern void _initialize_c_language (void); @@ -225,9 +224,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. */ @@ -307,17 +310,27 @@ 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) { xfree (*buffer); - if (err == EIO) - throw_error (MEMORY_ERROR, "Address %s out of bounds", - paddress (get_type_arch (type), addr)); - else - error (_("Error reading string from inferior: %s"), - safe_strerror (err)); + memory_error (err, addr); } } @@ -815,6 +828,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, @@ -850,6 +864,9 @@ const struct language_defn c_language_defn = c_get_string, NULL, /* la_get_symbol_name_cmp */ iterate_over_symbols, + &c_varobj_ops, + c_get_compile_context, + c_compute_program, LANG_MAGIC }; @@ -938,6 +955,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, @@ -973,12 +991,16 @@ const struct language_defn cplus_language_defn = c_get_string, NULL, /* la_get_symbol_name_cmp */ iterate_over_symbols, + &cplus_varobj_ops, + NULL, + NULL, LANG_MAGIC }; const struct language_defn asm_language_defn = { "asm", /* Language name */ + "assembly", language_asm, range_check_off, case_sensitive_on, @@ -1014,6 +1036,9 @@ const struct language_defn asm_language_defn = c_get_string, NULL, /* la_get_symbol_name_cmp */ iterate_over_symbols, + &default_varobj_ops, + NULL, + NULL, LANG_MAGIC }; @@ -1025,6 +1050,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, @@ -1060,6 +1086,9 @@ const struct language_defn minimal_language_defn = c_get_string, NULL, /* la_get_symbol_name_cmp */ iterate_over_symbols, + &default_varobj_ops, + NULL, + NULL, LANG_MAGIC };