From patchwork Mon Oct 3 19:59:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 58304 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DBA04385E013 for ; Mon, 3 Oct 2022 20:00:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DBA04385E013 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1664827214; bh=+txB0au53skg4o2iUu22td5EiY1t4d5fUbrRT60umFA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=ubW4zbWgFKivEOD1gKVnb6q33aVES1a+olIUjLoYQnG59DtWWjzhnpw4bmpW+gV4w VE9eNHwHOX961wJ2xsfFJsZMQGy7jvRDV5McOBOyFO3WxKp1WeN4ZImUZuwWxr70ri ybYAP692K0Sfo1ZEORDFzrx/2sQZZaDHp+NXpeoE= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) by sourceware.org (Postfix) with ESMTPS id 8D0C2385AC36 for ; Mon, 3 Oct 2022 19:59:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8D0C2385AC36 Received: by mail-il1-x135.google.com with SMTP id o13so1156855ilc.7 for ; Mon, 03 Oct 2022 12:59:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=+txB0au53skg4o2iUu22td5EiY1t4d5fUbrRT60umFA=; b=dPqL+RVKmUZUE59dRe8kjvMmj5jcx8CZwAIYQG4gGsruWKPrgzOgfVNFHlTI/Yj2aW paU2ubVVe5wWXV3XvBAEBZxTn7DfzhPG1M9xbCKNo7QdIEsVbIsGqE+aUWYSKNxvnMJi Zt7rzOSyLQ8f9uRvbQD6HaFx8SxHWTHCqGMnd8TSoeKuThrAcYJNiI15o+S3mAEub4zg E2Dt9PAfwFXEJDVCRepPC/3/zkS5VsxJDMbNzJiYWey4EyzChso1fw0et8Oh5w2uhAoT OX3PDaSxZNpb8cM3DlGt0vPt8HjUHLTutZ9fMvz1cjftBeNHilBzDspmANxEgr1cafFt eUPQ== X-Gm-Message-State: ACrzQf2FvvARUDJpoZorr8nJJd/N4XFzw4GO4V/BZX7xsXPDAupH3mp1 0K2X42AtmO1mjQMFkkhqIEE/lntjvgVBtg== X-Google-Smtp-Source: AMsMyM6erV6asGs7CusY8GbmBYtsb3IQD6tyy47IU3QdJMG3kWRixls2jgdoQwSeIzNU1wTzI+ds4w== X-Received: by 2002:a92:4a12:0:b0:2f9:dfe1:659c with SMTP id m18-20020a924a12000000b002f9dfe1659cmr2486931ilf.265.1664827181789; Mon, 03 Oct 2022 12:59:41 -0700 (PDT) Received: from localhost.localdomain (71-211-160-49.hlrn.qwest.net. [71.211.160.49]) by smtp.gmail.com with ESMTPSA id l63-20020a6b3e42000000b006a13b263315sm4875710ioa.43.2022.10.03.12.59.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 12:59:41 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCH] Use scoped_value_mark in more places Date: Mon, 3 Oct 2022 13:59:34 -0600 Message-Id: <20221003195934.540352-1-tromey@adacore.com> X-Mailer: git-send-email 2.34.3 MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Cc: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" I looked at all the spots using value_mark, and converted all the straightforward ones to use scoped_value_mark instead. Regression tested on x86-64 Fedora 34. --- gdb/ada-lang.c | 12 ++++-------- gdb/ada-valprint.c | 5 ++--- gdb/breakpoint.c | 24 +++++++++--------------- gdb/cli/cli-script.c | 32 ++++++++++++++++---------------- gdb/gnu-nat.c | 4 +--- gdb/opencl-lang.c | 5 ++--- gdb/regcache.c | 6 ++---- gdb/valarith.c | 3 +-- 8 files changed, 37 insertions(+), 54 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index ac23eb5938c..26d2012ef6b 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -7858,7 +7858,6 @@ ada_template_to_fixed_record_type_1 (struct type *type, CORE_ADDR address, struct value *dval0, int keep_dynamic_fields) { - struct value *mark = value_mark (); struct value *dval; struct type *rtype; int nfields, bit_len; @@ -7867,6 +7866,8 @@ ada_template_to_fixed_record_type_1 (struct type *type, int fld_bit_len; int f; + scoped_value_mark mark; + /* Compute the number of fields in this record type that are going to be processed: unless keep_dynamic_fields, this includes only fields whose position and length are static will be processed. */ @@ -8068,7 +8069,6 @@ ada_template_to_fixed_record_type_1 (struct type *type, else rtype->set_length (align_up (rtype->length (), type->length ())); - value_free_to_mark (mark); return rtype; } @@ -8169,7 +8169,6 @@ static struct type * to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr, CORE_ADDR address, struct value *dval0) { - struct value *mark = value_mark (); struct value *dval; struct type *rtype; struct type *branch_type; @@ -8179,6 +8178,7 @@ to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr, if (variant_field == -1) return type; + scoped_value_mark mark; if (dval0 == NULL) { dval = value_from_contents_and_address (type, valaddr, address); @@ -8228,7 +8228,6 @@ to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr, rtype->set_length (rtype->length () - type->field (variant_field).type ()->length ()); - value_free_to_mark (mark); return rtype; } @@ -12311,11 +12310,8 @@ should_stop_exception (const struct bp_location *bl) stop = true; try { - struct value *mark; - - mark = value_mark (); + scoped_value_mark mark; stop = value_true (evaluate_expression (ada_loc->excep_cond_expr.get ())); - value_free_to_mark (mark); } catch (const gdb_exception &ex) { diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c index 59f0be480d4..40c26145224 100644 --- a/gdb/ada-valprint.c +++ b/gdb/ada-valprint.c @@ -127,9 +127,10 @@ val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr, unsigned len; struct type *elttype, *index_type; unsigned long bitsize = TYPE_FIELD_BITSIZE (type, 0); - struct value *mark = value_mark (); LONGEST low = 0; + scoped_value_mark mark; + elttype = type->target_type (); index_type = type->index_type (); @@ -251,8 +252,6 @@ val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr, { gdb_printf (stream, "..."); } - - value_free_to_mark (mark); } /* Print the character C on STREAM as part of the contents of a literal diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 002f4a935b1..b65043edc42 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -4839,11 +4839,8 @@ bpstat_print (bpstat *bs, target_waitkind kind) static bool breakpoint_cond_eval (expression *exp) { - struct value *mark = value_mark (); - bool res = value_true (evaluate_expression (exp)); - - value_free_to_mark (mark); - return res; + scoped_value_mark mark; + return value_true (evaluate_expression (exp)); } /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ @@ -5355,12 +5352,11 @@ bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread) int within_current_scope = 1; struct watchpoint * w; - /* We use value_mark and value_free_to_mark because it could - be a long time before we return to the command level and - call free_all_values. We can't call free_all_values - because we might be in the middle of evaluating a - function call. */ - struct value *mark = value_mark (); + /* We use scoped_value_mark because it could be a long time + before we return to the command level and call + free_all_values. We can't call free_all_values because we + might be in the middle of evaluating a function call. */ + scoped_value_mark mark; if (is_watchpoint (b)) w = (struct watchpoint *) b; @@ -5419,7 +5415,6 @@ bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread) watchpoint, unconditionally report it. */ } /* FIXME-someday, should give breakpoint #. */ - value_free_to_mark (mark); } if (cond && !condition_result) @@ -9961,17 +9956,16 @@ watch_command_1 (const char *arg, int accessflag, int from_tty, /* We've found a "mask" token, which means the user wants to create a hardware watchpoint that is going to have the mask facility. */ - struct value *mask_value, *mark; + struct value *mask_value; if (use_mask) error(_("You can specify only one mask.")); use_mask = just_location = true; - mark = value_mark (); + scoped_value_mark mark; mask_value = parse_to_comma_and_eval (&value_start); mask = value_as_address (mask_value); - value_free_to_mark (mark); } else /* We didn't recognize what we found. We should stop here. */ diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c index 6c67b60e721..22e3efa5643 100644 --- a/gdb/cli/cli-script.c +++ b/gdb/cli/cli-script.c @@ -512,8 +512,6 @@ static enum command_control_type execute_control_command_1 (struct command_line *cmd, int from_tty) { struct command_line *current; - struct value *val; - struct value *val_mark; int loop; enum command_control_type ret; @@ -567,10 +565,11 @@ execute_control_command_1 (struct command_line *cmd, int from_tty) QUIT; /* Evaluate the expression. */ - val_mark = value_mark (); - val = evaluate_expression (expr.get ()); - cond_result = value_true (val); - value_free_to_mark (val_mark); + { + scoped_value_mark mark; + value *val = evaluate_expression (expr.get ()); + cond_result = value_true (val); + } /* If the value is false, then break out of the loop. */ if (!cond_result) @@ -621,16 +620,17 @@ execute_control_command_1 (struct command_line *cmd, int from_tty) ret = simple_control; /* Evaluate the conditional. */ - val_mark = value_mark (); - val = evaluate_expression (expr.get ()); - - /* Choose which arm to take commands from based on the value - of the conditional expression. */ - if (value_true (val)) - current = cmd->body_list_0.get (); - else if (cmd->body_list_1 != nullptr) - current = cmd->body_list_1.get (); - value_free_to_mark (val_mark); + { + scoped_value_mark mark; + value *val = evaluate_expression (expr.get ()); + + /* Choose which arm to take commands from based on the value + of the conditional expression. */ + if (value_true (val)) + current = cmd->body_list_0.get (); + else if (cmd->body_list_1 != nullptr) + current = cmd->body_list_1.get (); + } /* Execute commands in the given arm. */ while (current) diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c index 5dd4d148c76..ae049cab3de 100644 --- a/gdb/gnu-nat.c +++ b/gdb/gnu-nat.c @@ -3062,7 +3062,7 @@ static void info_port_rights (const char *args, mach_port_type_t only) { struct inf *inf = active_inf (); - struct value *vmark = value_mark (); + scoped_value_mark vmark; if (args) /* Explicit list of port rights. */ @@ -3088,8 +3088,6 @@ info_port_rights (const char *args, mach_port_type_t only) if (err) error (_("%s."), safe_strerror (err)); } - - value_free_to_mark (vmark); } static void diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c index c88b3fe6bbd..e41db3dcbba 100644 --- a/gdb/opencl-lang.c +++ b/gdb/opencl-lang.c @@ -147,7 +147,8 @@ lval_func_read (struct value *v) static void lval_func_write (struct value *v, struct value *fromval) { - struct value *mark = value_mark (); + scoped_value_mark mark; + struct lval_closure *c = (struct lval_closure *) value_computed_closure (v); struct type *type = check_typedef (value_type (v)); struct type *eltype = check_typedef (value_type (c->val))->target_type (); @@ -184,8 +185,6 @@ lval_func_write (struct value *v, struct value *fromval) elsize); value_assign (to_elm_val, from_elm_val); } - - value_free_to_mark (mark); } /* Return nonzero if bits in V from OFFSET and LENGTH represent a diff --git a/gdb/regcache.c b/gdb/regcache.c index 279bf2258a9..11565909d7d 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -708,10 +708,10 @@ readable_regcache::cooked_read (int regnum, gdb_byte *buf) } else if (gdbarch_pseudo_register_read_value_p (m_descr->gdbarch)) { - struct value *mark, *computed; + struct value *computed; enum register_status result = REG_VALID; - mark = value_mark (); + scoped_value_mark mark; computed = gdbarch_pseudo_register_read_value (m_descr->gdbarch, this, regnum); @@ -724,8 +724,6 @@ readable_regcache::cooked_read (int regnum, gdb_byte *buf) result = REG_UNAVAILABLE; } - value_free_to_mark (mark); - return result; } else diff --git a/gdb/valarith.c b/gdb/valarith.c index c0e937d6c25..7a9e130a576 100644 --- a/gdb/valarith.c +++ b/gdb/valarith.c @@ -1615,7 +1615,7 @@ vector_binop (struct value *val1, struct value *val2, enum exp_opcode op) value *val = allocate_value (type1); gdb::array_view val_contents = value_contents_writeable (val); - value *mark = value_mark (); + scoped_value_mark mark; for (i = 0; i < high_bound1 - low_bound1 + 1; i++) { value *tmp = value_binop (value_subscript (val1, i), @@ -1623,7 +1623,6 @@ vector_binop (struct value *val1, struct value *val2, enum exp_opcode op) copy (value_contents_all (tmp), val_contents.slice (i * elsize, elsize)); } - value_free_to_mark (mark); return val; }