From patchwork Thu Apr 5 21:15:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 26625 Received: (qmail 40836 invoked by alias); 5 Apr 2018 21:16:07 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 40261 invoked by uid 89); 5 Apr 2018 21:15:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=watching, watchpoints X-HELO: gateway34.websitewelcome.com Received: from gateway34.websitewelcome.com (HELO gateway34.websitewelcome.com) (192.185.149.77) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 05 Apr 2018 21:15:28 +0000 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway34.websitewelcome.com (Postfix) with ESMTP id BBDED321A85A for ; Thu, 5 Apr 2018 16:15:18 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 4CE2fAtg7cGlp4CE2fwCDG; Thu, 05 Apr 2018 16:15:18 -0500 Received: from 75-166-37-45.hlrn.qwest.net ([75.166.37.45]:47524 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1f4CE2-003niR-FF; Thu, 05 Apr 2018 16:15:18 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 07/12] Remove free_value_chain Date: Thu, 5 Apr 2018 15:15:02 -0600 Message-Id: <20180405211507.6103-8-tom@tromey.com> In-Reply-To: <20180405211507.6103-1-tom@tromey.com> References: <20180405211507.6103-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1f4CE2-003niR-FF X-Source-Sender: 75-166-37-45.hlrn.qwest.net (bapiya.Home) [75.166.37.45]:47524 X-Source-Auth: tom+tromey.com X-Email-Count: 8 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This patch changes value_release_to_mark and fetch_subexp_value to return a std::vector of value references, rather than relying on the "next" field that is contained in a struct value. This makes it simpler to reason about the returned values, and also allows for the removal of free_value_chain. ChangeLog 2018-04-05 Tom Tromey * value.h (fetch_subexp_value, value_release_to_mark): Update. (free_value_chain): Remove. * value.c (free_value_chain): Remove. (value_release_to_mark): Return a std::vector. * ppc-linux-nat.c (num_memory_accesses): Change "chain" to a std::vector. (check_condition): Update. * eval.c (fetch_subexp_value): Change "val_chain" to a std::vector. * breakpoint.c (update_watchpoint): Update. (can_use_hardware_watchpoint): Change "vals" to a std::vector. --- gdb/ChangeLog | 14 ++++++++++++++ gdb/breakpoint.c | 30 ++++++++++++++++-------------- gdb/eval.c | 15 +++++++-------- gdb/ppc-linux-nat.c | 33 +++++++++------------------------ gdb/value.c | 34 ++++++++++++---------------------- gdb/value.h | 7 +++---- 6 files changed, 61 insertions(+), 72 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 67ba5a6b31..c2b9f55461 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -117,7 +117,8 @@ static std::vector decode_location_default (struct breakpoint *b, const struct event_location *location, struct program_space *search_pspace); -static int can_use_hardware_watchpoint (struct value *); +static int can_use_hardware_watchpoint + (const std::vector &vals); static void mention (struct breakpoint *); @@ -1777,7 +1778,8 @@ update_watchpoint (struct watchpoint *b, int reparse) else if (within_current_scope && b->exp) { int pc = 0; - struct value *val_chain, *v, *result, *next; + std::vector val_chain; + struct value *v, *result, *next; struct program_space *frame_pspace; fetch_subexp_value (b->exp.get (), &pc, &v, &result, &val_chain, 0); @@ -1799,15 +1801,18 @@ update_watchpoint (struct watchpoint *b, int reparse) frame_pspace = get_frame_program_space (get_selected_frame (NULL)); /* Look at each value on the value chain. */ - for (v = val_chain; v; v = value_next (v)) + gdb_assert (!val_chain.empty ()); + for (const value_ref_ptr &iter : val_chain) { + v = iter.get (); + /* If it's a memory location, and GDB actually needed its contents to evaluate the expression, then we must watch it. If the first value returned is still lazy, that means an error occurred reading it; watch it anyway in case it becomes readable. */ if (VALUE_LVAL (v) == lval_memory - && (v == val_chain || ! value_lazy (v))) + && (v == val_chain[0] || ! value_lazy (v))) { struct type *vtype = check_typedef (value_type (v)); @@ -1962,13 +1967,6 @@ update_watchpoint (struct watchpoint *b, int reparse) bl->loc_type = loc_type; } - for (v = val_chain; v; v = next) - { - next = value_next (v); - if (v != b->val) - value_decref (v); - } - /* If a software watchpoint is not watching any memory, then the above left it without any location set up. But, bpstat_stop_status requires a location to be able to report @@ -10875,15 +10873,17 @@ watch_command_1 (const char *arg, int accessflag, int from_tty, If the watchpoint cannot be handled in hardware return zero. */ static int -can_use_hardware_watchpoint (struct value *v) +can_use_hardware_watchpoint (const std::vector &vals) { int found_memory_cnt = 0; - struct value *head = v; /* Did the user specifically forbid us to use hardware watchpoints? */ if (!can_use_hw_watchpoints) return 0; + gdb_assert (!vals.empty ()); + struct value *head = vals[0].get (); + /* Make sure that the value of the expression depends only upon memory contents, and values computed from them within GDB. If we find any register references or function calls, we can't use a @@ -10903,8 +10903,10 @@ can_use_hardware_watchpoint (struct value *v) function calls are special in any way. So this function may not notice that an expression involving an inferior function call can't be watched with hardware watchpoints. FIXME. */ - for (; v; v = value_next (v)) + for (const value_ref_ptr &iter : vals) { + struct value *v = iter.get (); + if (VALUE_LVAL (v) == lval_memory) { if (v != head && value_lazy (v)) diff --git a/gdb/eval.c b/gdb/eval.c index 021503e9dd..b6fbfcf6c9 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -179,14 +179,14 @@ evaluate_subexpression_type (struct expression *exp, int subexp) set to any referenced values. *VALP will never be a lazy value. This is the value which we store in struct breakpoint. - If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the - value chain. The caller must free the values individually. If - VAL_CHAIN is NULL, all generated values will be left on the value - chain. */ + If VAL_CHAIN is non-NULL, the values put into *VAL_CHAIN will be + released from the value chain. If VAL_CHAIN is NULL, all generated + values will be left on the value chain. */ void fetch_subexp_value (struct expression *exp, int *pc, struct value **valp, - struct value **resultp, struct value **val_chain, + struct value **resultp, + std::vector *val_chain, int preserve_errors) { struct value *mark, *new_mark, *result; @@ -195,7 +195,7 @@ fetch_subexp_value (struct expression *exp, int *pc, struct value **valp, if (resultp) *resultp = NULL; if (val_chain) - *val_chain = NULL; + val_chain->clear (); /* Evaluate the expression. */ mark = value_mark (); @@ -253,8 +253,7 @@ fetch_subexp_value (struct expression *exp, int *pc, struct value **valp, { /* Return the chain of intermediate values. We use this to decide which addresses to watch. */ - *val_chain = new_mark; - value_release_to_mark (mark); + *val_chain = value_release_to_mark (mark); } } diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c index 1d2769a983..2cd8792d30 100644 --- a/gdb/ppc-linux-nat.c +++ b/gdb/ppc-linux-nat.c @@ -1840,10 +1840,9 @@ calculate_dvc (CORE_ADDR addr, int len, CORE_ADDR data_value, other kinds of values which are not acceptable in a condition expression (e.g., lval_computed or lval_internalvar). */ static int -num_memory_accesses (struct value *v) +num_memory_accesses (const std::vector &chain) { int found_memory_cnt = 0; - struct value *head = v; /* The idea here is that evaluating an expression generates a series of values, one holding the value of every subexpression. (The @@ -1860,8 +1859,10 @@ num_memory_accesses (struct value *v) notice that an expression contains an inferior function call. FIXME. */ - for (; v; v = value_next (v)) + for (const value_ref_ptr &iter : chain) { + struct value *v = iter.get (); + /* Constants and values from the history are fine. */ if (VALUE_LVAL (v) == not_lval || deprecated_value_modifiable (v) == 0) continue; @@ -1892,7 +1893,8 @@ check_condition (CORE_ADDR watch_addr, struct expression *cond, CORE_ADDR *data_value, int *len) { int pc = 1, num_accesses_left, num_accesses_right; - struct value *left_val, *right_val, *left_chain, *right_chain; + struct value *left_val, *right_val; + std::vector left_chain, right_chain; if (cond->elts[0].opcode != BINOP_EQUAL) return 0; @@ -1901,22 +1903,13 @@ check_condition (CORE_ADDR watch_addr, struct expression *cond, num_accesses_left = num_memory_accesses (left_chain); if (left_val == NULL || num_accesses_left < 0) - { - free_value_chain (left_chain); - - return 0; - } + return 0; fetch_subexp_value (cond, &pc, &right_val, NULL, &right_chain, 0); num_accesses_right = num_memory_accesses (right_chain); if (right_val == NULL || num_accesses_right < 0) - { - free_value_chain (left_chain); - free_value_chain (right_chain); - - return 0; - } + return 0; if (num_accesses_left == 1 && num_accesses_right == 0 && VALUE_LVAL (left_val) == lval_memory @@ -1939,15 +1932,7 @@ check_condition (CORE_ADDR watch_addr, struct expression *cond, *len = TYPE_LENGTH (check_typedef (value_type (right_val))); } else - { - free_value_chain (left_chain); - free_value_chain (right_chain); - - return 0; - } - - free_value_chain (left_chain); - free_value_chain (right_chain); + return 0; return 1; } diff --git a/gdb/value.c b/gdb/value.c index a84c196aaa..fed722da51 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -1638,20 +1638,6 @@ value_free_to_mark (const struct value *mark) all_values = val; } -/* Frees all the elements in a chain of values. */ - -void -free_value_chain (struct value *v) -{ - struct value *next; - - for (; v; v = next) - { - next = value_next (v); - value_decref (v); - } -} - /* Remove VAL from the chain all_values so it will not be freed automatically. */ @@ -1696,24 +1682,28 @@ release_value (struct value *val) } /* Release all values up to mark */ -struct value * +std::vector value_release_to_mark (const struct value *mark) { - struct value *val; + std::vector result; struct value *next; - for (val = next = all_values; next; next = next->next) + for (next = all_values; next; next = next->next) { + next->released = 1; + result.emplace_back (next); + if (next->next == mark) { - all_values = next->next; + struct value *save = next->next; next->next = NULL; - return val; + next = save; + break; } - next->released = 1; } - all_values = 0; - return val; + + all_values = next; + return result; } /* Return a copy of the value ARG. diff --git a/gdb/value.h b/gdb/value.h index 2016937406..9c6a1b8859 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -915,7 +915,7 @@ extern value *eval_skip_value (expression *exp); extern void fetch_subexp_value (struct expression *exp, int *pc, struct value **valp, struct value **resultp, - struct value **val_chain, + std::vector *val_chain, int preserve_errors); extern const char *extract_field_op (struct expression *exp, int *subexp); @@ -1053,8 +1053,6 @@ extern int unop_user_defined_p (enum exp_opcode op, struct value *arg1); extern int destructor_name_p (const char *name, struct type *type); -extern void free_value_chain (struct value *v); - extern value_ref_ptr release_value (struct value *val); extern int record_latest_value (struct value *val); @@ -1084,7 +1082,8 @@ extern void value_print_array_elements (struct value *val, struct ui_file *stream, int format, enum val_prettyformat pretty); -extern struct value *value_release_to_mark (const struct value *mark); +extern std::vector value_release_to_mark + (const struct value *mark); extern void val_print (struct type *type, LONGEST embedded_offset, CORE_ADDR address,