From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7850) id 502E63857019; Wed, 7 Jun 2023 22:19:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 502E63857019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Indu Bhagat To: bfd-cvs@sourceware.org, gdb-cvs@sourceware.org Subject: [binutils-gdb] libsframe: reuse static function sframe_decoder_get_funcdesc_at_index X-Act-Checkin: binutils-gdb X-Git-Author: Indu Bhagat X-Git-Refname: refs/heads/master X-Git-Oldrev: f0874f419209510d2a55e994f6ca10eb9f7905bc X-Git-Newrev: 676cb9d2e019685a357a02b7a15999e7c3414de2 Message-Id: <20230607221921.502E63857019@sourceware.org> Date: Wed, 7 Jun 2023 22:19:21 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Jun 2023 22:19:21 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D676cb9d2e019= 685a357a02b7a15999e7c3414de2 commit 676cb9d2e019685a357a02b7a15999e7c3414de2 Author: Indu Bhagat Date: Wed Jun 7 15:13:35 2023 -0700 libsframe: reuse static function sframe_decoder_get_funcdesc_at_index =20 sframe_decoder_get_funcdesc_at_index () is the function to access SFrame FDEs in the SFrame decoder context. Use it consistently. =20 Avoid unnecessary type cast and include minor enhancements as the code is moved around. =20 libsframe/ * sframe.c (sframe_decoder_get_funcdesc_at_index): Move some checks here. Move the static function definition before the new use. (sframe_decoder_get_funcdesc): Use sframe_decoder_get_funcdesc_at_index instead. Diff: --- libsframe/sframe.c | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/libsframe/sframe.c b/libsframe/sframe.c index a7615329767..a5f4a7f6519 100644 --- a/libsframe/sframe.c +++ b/libsframe/sframe.c @@ -341,6 +341,27 @@ sframe_fre_entry_size (sframe_frame_row_entry *frep, u= nsigned int fre_type) + sframe_fre_offset_bytes_size (fre_info)); } =20 +/* Get the function descriptor entry at index FUNC_IDX in the decoder + context CTX. */ + +static sframe_func_desc_entry * +sframe_decoder_get_funcdesc_at_index (sframe_decoder_ctx *ctx, + uint32_t func_idx) +{ + sframe_func_desc_entry *fdep; + unsigned int num_fdes; + int err; + + num_fdes =3D sframe_decoder_get_num_fidx (ctx); + if (num_fdes =3D=3D 0 + || func_idx >=3D num_fdes + || ctx->sfd_funcdesc =3D=3D NULL) + return sframe_ret_set_errno (&err, SFRAME_ERR_DCTX_INVAL); + + fdep =3D &ctx->sfd_funcdesc[func_idx]; + return fdep; +} + static int flip_fre (char *fp, unsigned int fre_type, size_t *fre_size) { @@ -1103,20 +1124,17 @@ sframe_decoder_get_funcdesc (sframe_decoder_ctx *ct= x, unsigned char *func_info) { sframe_func_desc_entry *fdp; - unsigned int num_fdes; int err =3D 0; =20 if (ctx =3D=3D NULL || func_start_address =3D=3D NULL || num_fres =3D=3D= NULL || func_size =3D=3D NULL) return sframe_set_errno (&err, SFRAME_ERR_INVAL); =20 - num_fdes =3D sframe_decoder_get_num_fidx (ctx); - if (num_fdes =3D=3D 0 - || i >=3D num_fdes - || ctx->sfd_funcdesc =3D=3D NULL) - return sframe_set_errno (&err, SFRAME_ERR_DCTX_INVAL); + fdp =3D sframe_decoder_get_funcdesc_at_index (ctx, i); + + if (fdp =3D=3D NULL) + return sframe_set_errno (&err, SFRAME_ERR_FDE_NOTFOUND); =20 - fdp =3D (sframe_func_desc_entry *) ctx->sfd_funcdesc + i; *num_fres =3D fdp->sfde_func_num_fres; *func_start_address =3D fdp->sfde_func_start_address; *func_size =3D fdp->sfde_func_size; @@ -1125,22 +1143,6 @@ sframe_decoder_get_funcdesc (sframe_decoder_ctx *ctx, return 0; } =20 -/* Get the function descriptor entry at index FUNC_IDX in the decoder - context CTX. */ - -static sframe_func_desc_entry * -sframe_decoder_get_funcdesc_at_index (sframe_decoder_ctx *ctx, - uint32_t func_idx) -{ - /* Invalid argument. No FDE will be found. */ - if (func_idx >=3D sframe_decoder_get_num_fidx (ctx)) - return NULL; - - sframe_func_desc_entry *fdep; - fdep =3D (sframe_func_desc_entry *) ctx->sfd_funcdesc; - return fdep + func_idx; -} - /* Get the FRE_IDX'th FRE of the function at FUNC_IDX'th function descriptor entry in the SFrame decoder CTX. Returns error code as applicable. */