From 00158a68d1c382f9afe16630ac327695a4904556 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sun, 6 Dec 2020 21:34:25 -0700 Subject: [PATCH] Fix struct expression regression The patch to change struct expression to use new introduced a regression -- there is a spot that reallocates expressions that I failed to update. This patch rewrites this code to follow the new approach. Now the rewriting is done in place. gdb/ChangeLog 2020-12-06 Tom Tromey PR ada/26999 * ada-lang.c (replace_operator_with_call): Rewrite. --- gdb/ChangeLog | 5 +++++ gdb/ada-lang.c | 31 +++++++++++++------------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 21115067e58..3c21cff271f 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2020-12-06 Tom Tromey + + PR ada/26999 + * ada-lang.c (replace_operator_with_call): Rewrite. + 2020-12-06 Giancarlo Frix (tiny change) PR breakpoints/27009 diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 906671155d0..7d062294aa5 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -4000,28 +4000,23 @@ replace_operator_with_call (expression_up *expp, int pc, int nargs, int oplen, struct symbol *sym, const struct block *block) { - /* A new expression, with 6 more elements (3 for funcall, 4 for function - symbol, -oplen for operator being replaced). */ - struct expression *newexp = (struct expression *) - xzalloc (sizeof (struct expression) - + EXP_ELEM_TO_BYTES ((*expp)->nelts + 7 - oplen)); + /* We want to add 6 more elements (3 for funcall, 4 for function + symbol, -OPLEN for operator being replaced) to the + expression. */ struct expression *exp = expp->get (); + int save_nelts = exp->nelts; + exp->nelts = exp->nelts + 7 - oplen; + exp->resize (exp->nelts); - newexp->nelts = exp->nelts + 7 - oplen; - newexp->language_defn = exp->language_defn; - newexp->gdbarch = exp->gdbarch; - memcpy (newexp->elts, exp->elts, EXP_ELEM_TO_BYTES (pc)); - memcpy (newexp->elts + pc + 7, exp->elts + pc + oplen, - EXP_ELEM_TO_BYTES (exp->nelts - pc - oplen)); + memmove (exp->elts + pc + 7, exp->elts + pc + oplen, + EXP_ELEM_TO_BYTES (save_nelts - pc - oplen)); - newexp->elts[pc].opcode = newexp->elts[pc + 2].opcode = OP_FUNCALL; - newexp->elts[pc + 1].longconst = (LONGEST) nargs; + exp->elts[pc].opcode = exp->elts[pc + 2].opcode = OP_FUNCALL; + exp->elts[pc + 1].longconst = (LONGEST) nargs; - newexp->elts[pc + 3].opcode = newexp->elts[pc + 6].opcode = OP_VAR_VALUE; - newexp->elts[pc + 4].block = block; - newexp->elts[pc + 5].symbol = sym; - - expp->reset (newexp); + exp->elts[pc + 3].opcode = exp->elts[pc + 6].opcode = OP_VAR_VALUE; + exp->elts[pc + 4].block = block; + exp->elts[pc + 5].symbol = sym; } /* Type-class predicates */ -- 2.30.2