From patchwork Thu Nov 2 22:36:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 24058 Received: (qmail 8086 invoked by alias); 2 Nov 2017 22:36:25 -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 7201 invoked by uid 89); 2 Nov 2017 22:36:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.1 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=rfa X-HELO: gateway24.websitewelcome.com Received: from gateway24.websitewelcome.com (HELO gateway24.websitewelcome.com) (192.185.51.110) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 02 Nov 2017 22:36:17 +0000 Received: from cm15.websitewelcome.com (cm15.websitewelcome.com [100.42.49.9]) by gateway24.websitewelcome.com (Postfix) with ESMTP id B4D002EF88 for ; Thu, 2 Nov 2017 17:36:15 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id AO5veibH85b6TAO5vexSrz; Thu, 02 Nov 2017 17:36:15 -0500 Received: from 71-218-90-63.hlrn.qwest.net ([71.218.90.63]:58978 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1eAO5v-003CfJ-Hm; Thu, 02 Nov 2017 17:36:15 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 03/13] Use std::vector in compile-loc2c.c Date: Thu, 2 Nov 2017 16:36:02 -0600 Message-Id: <20171102223612.3642-4-tom@tromey.com> In-Reply-To: <20171102223612.3642-1-tom@tromey.com> References: <20171102223612.3642-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1eAO5v-003CfJ-Hm X-Source-Sender: 71-218-90-63.hlrn.qwest.net (bapiya.Home) [71.218.90.63]:58978 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This changes compile-loc2c.c to use std::vector, removing some cleanups. gdb/ChangeLog 2017-11-02 Tom Tromey * compile/compile-loc2c.c (compute_stack_depth_worker): Change type of "info". (compute_stack_depth): Likewise. (do_compile_dwarf_expr_to_c): Use std::vector. --- gdb/ChangeLog | 7 +++++++ gdb/compile/compile-loc2c.c | 42 +++++++++++++++++------------------------- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/gdb/compile/compile-loc2c.c b/gdb/compile/compile-loc2c.c index 7ec6f67cdf..ca26f13eda 100644 --- a/gdb/compile/compile-loc2c.c +++ b/gdb/compile/compile-loc2c.c @@ -62,7 +62,7 @@ struct insn_info NEED_TEMPVAR is an out parameter which is set if this expression needs a special temporary variable to be emitted (see the code generator). - INFO is an array of insn_info objects, indexed by offset from the + INFO is a vector of insn_info objects, indexed by offset from the start of the DWARF expression. TO_DO is a list of bytecodes which must be examined; it may be added to by this function. @@ -71,7 +71,7 @@ struct insn_info static void compute_stack_depth_worker (int start, int *need_tempvar, - struct insn_info *info, + std::vector *info, std::vector *to_do, enum bfd_endian byte_order, unsigned int addr_size, const gdb_byte *op_ptr, const gdb_byte *op_end) @@ -80,8 +80,8 @@ compute_stack_depth_worker (int start, int *need_tempvar, int stack_depth; op_ptr += start; - gdb_assert (info[start].visited); - stack_depth = info[start].depth; + gdb_assert ((*info)[start].visited); + stack_depth = (*info)[start].depth; while (op_ptr < op_end) { @@ -91,16 +91,16 @@ compute_stack_depth_worker (int start, int *need_tempvar, int ndx = op_ptr - base; #define SET_CHECK_DEPTH(WHERE) \ - if (info[WHERE].visited) \ + if ((*info)[WHERE].visited) \ { \ - if (info[WHERE].depth != stack_depth) \ + if ((*info)[WHERE].depth != stack_depth) \ error (_("inconsistent stack depths")); \ } \ else \ { \ /* Stack depth not set, so set it. */ \ - info[WHERE].visited = 1; \ - info[WHERE].depth = stack_depth; \ + (*info)[WHERE].visited = 1; \ + (*info)[WHERE].depth = stack_depth; \ } SET_CHECK_DEPTH (ndx); @@ -324,7 +324,7 @@ compute_stack_depth_worker (int start, int *need_tempvar, case DW_OP_GNU_push_tls_address: case DW_OP_form_tls_address: - info[ndx].is_tls = 1; + (*info)[ndx].is_tls = 1; break; case DW_OP_skip: @@ -333,10 +333,10 @@ compute_stack_depth_worker (int start, int *need_tempvar, offset = op_ptr + offset - base; /* If the destination has not been seen yet, add it to the to-do list. */ - if (!info[offset].visited) + if (!(*info)[offset].visited) to_do->push_back (offset); SET_CHECK_DEPTH (offset); - info[offset].label = 1; + (*info)[offset].label = 1; /* We're done with this line of code. */ return; @@ -347,10 +347,10 @@ compute_stack_depth_worker (int start, int *need_tempvar, --stack_depth; /* If the destination has not been seen yet, add it to the to-do list. */ - if (!info[offset].visited) + if (!(*info)[offset].visited) to_do->push_back (offset); SET_CHECK_DEPTH (offset); - info[offset].label = 1; + (*info)[offset].label = 1; break; case DW_OP_nop: @@ -387,15 +387,13 @@ compute_stack_depth (enum bfd_endian byte_order, unsigned int addr_size, int *need_tempvar, int *is_tls, const gdb_byte *op_ptr, const gdb_byte *op_end, int initial_depth, - struct insn_info **info) + std::vector *info) { unsigned char *set; - struct cleanup *outer_cleanup; std::vector to_do; int stack_depth, i; - *info = XCNEWVEC (struct insn_info, op_end - op_ptr); - outer_cleanup = make_cleanup (xfree, *info); + info->resize (op_end - op_ptr); to_do.push_back (0); (*info)[0].depth = initial_depth; @@ -406,7 +404,7 @@ compute_stack_depth (enum bfd_endian byte_order, unsigned int addr_size, int ndx = to_do.back (); to_do.pop_back (); - compute_stack_depth_worker (ndx, need_tempvar, *info, &to_do, + compute_stack_depth_worker (ndx, need_tempvar, info, &to_do, byte_order, addr_size, op_ptr, op_end); } @@ -421,7 +419,6 @@ compute_stack_depth (enum bfd_endian byte_order, unsigned int addr_size, *is_tls = 1; } - discard_cleanups (outer_cleanup); return stack_depth + 1; } @@ -594,8 +591,7 @@ do_compile_dwarf_expr_to_c (int indent, string_file &stream, const gdb_byte * const base = op_ptr; int need_tempvar = 0; int is_tls = 0; - struct cleanup *cleanup; - struct insn_info *info; + std::vector info; int stack_depth; ++scope; @@ -609,7 +605,6 @@ do_compile_dwarf_expr_to_c (int indent, string_file &stream, &need_tempvar, &is_tls, op_ptr, op_end, initial != NULL, &info); - cleanup = make_cleanup (xfree, info); /* This is a hack until we can add a feature to glibc to let us properly generate code for TLS. You might think we could emit @@ -643,7 +638,6 @@ do_compile_dwarf_expr_to_c (int indent, string_file &stream, result_name, core_addr_to_string (value_address (val))); fprintfi_filtered (indent - 2, &stream, "}\n"); - do_cleanups (cleanup); return; } @@ -1117,8 +1111,6 @@ do_compile_dwarf_expr_to_c (int indent, string_file &stream, fprintfi_filtered (indent, &stream, "%s = __gdb_stack[__gdb_tos];\n", result_name); fprintfi_filtered (indent - 2, &stream, "}\n"); - - do_cleanups (cleanup); } /* See compile.h. */