mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-12-25 16:57:52 +00:00
Avoid crash with "NSString" literals
Evaluating an Objective-C "NSString" literal will cause gdb to crash.
This patch fixes the crash.
I think the result here still isn't correct -- I see a warning from
the runtime ("autorelease called without pool for object") with the
new code.
However, not crashing is an improvement on its own.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=20501
This commit is contained in:
10
gdb/c-exp.y
10
gdb/c-exp.y
@@ -223,7 +223,7 @@ static void c_print_token (FILE *file, int type, YYSTYPE value);
|
||||
nonterminal "name", which matches either NAME or TYPENAME. */
|
||||
|
||||
%token <tsval> STRING
|
||||
%token <sval> NSSTRING /* ObjC Foundation "NSString" literal */
|
||||
%token <tsval> NSSTRING /* ObjC Foundation "NSString" literal */
|
||||
%token SELECTOR /* ObjC "@selector" pseudo-operator */
|
||||
%token <tsval> CHAR
|
||||
%token <ssym> NAME /* BLOCKNAME defined below to give it higher precedence. */
|
||||
@@ -1030,12 +1030,12 @@ exp : string_exp
|
||||
}
|
||||
;
|
||||
|
||||
exp : NSSTRING /* ObjC NextStep NSString constant
|
||||
* of the form '@' '"' string '"'.
|
||||
*/
|
||||
exp : NSSTRING
|
||||
{
|
||||
/* ObjC NextStep NSString constant of the
|
||||
form '@' '"' string '"'. */
|
||||
pstate->push_new<objc_nsstring_operation>
|
||||
(copy_name ($1));
|
||||
(std::string ($1.ptr, $1.length));
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
@@ -169,7 +169,8 @@ objc_nsstring_operation::evaluate (struct type *expect_type,
|
||||
struct type *type;
|
||||
|
||||
if (!target_has_execution ())
|
||||
return 0; /* Can't call into inferior to create NSString. */
|
||||
error (_("evaluation of this expression "
|
||||
"requires the target program to be active"));
|
||||
|
||||
stringValue[2] = value_string (str.c_str (), str.size () + 1, char_type);
|
||||
stringValue[2] = value_coerce_array (stringValue[2]);
|
||||
|
||||
@@ -62,6 +62,10 @@ clean_restart
|
||||
if { [set_lang_objc] } {
|
||||
test_float_accepted
|
||||
test_float_rejected
|
||||
|
||||
gdb_test {print @"hi"} \
|
||||
"evaluation of this expression requires the target program to be active" \
|
||||
"simple nsstring"
|
||||
} else {
|
||||
warning "Objective-c print tests suppressed"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user