public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
From: Indu Bhagat <ibhagat@sourceware.org>
To: bfd-cvs@sourceware.org, gdb-cvs@sourceware.org
Subject: [binutils-gdb] libsframe: reuse static function sframe_decoder_get_funcdesc_at_index
Date: Wed,  7 Jun 2023 22:19:21 +0000 (GMT)	[thread overview]
Message-ID: <20230607221921.502E63857019@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=676cb9d2e019685a357a02b7a15999e7c3414de2

commit 676cb9d2e019685a357a02b7a15999e7c3414de2
Author: Indu Bhagat <indu.bhagat@oracle.com>
Date:   Wed Jun 7 15:13:35 2023 -0700

    libsframe: reuse static function sframe_decoder_get_funcdesc_at_index
    
    sframe_decoder_get_funcdesc_at_index () is the function to access SFrame
    FDEs in the SFrame decoder context.  Use it consistently.
    
    Avoid unnecessary type cast and include minor enhancements as the code
    is moved around.
    
    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, unsigned int fre_type)
 	  + sframe_fre_offset_bytes_size (fre_info));
 }
 
+/* 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 = sframe_decoder_get_num_fidx (ctx);
+  if (num_fdes == 0
+      || func_idx >= num_fdes
+      || ctx->sfd_funcdesc == NULL)
+    return sframe_ret_set_errno (&err, SFRAME_ERR_DCTX_INVAL);
+
+  fdep = &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 *ctx,
 			     unsigned char *func_info)
 {
   sframe_func_desc_entry *fdp;
-  unsigned int num_fdes;
   int err = 0;
 
   if (ctx == NULL || func_start_address == NULL || num_fres == NULL
       || func_size == NULL)
     return sframe_set_errno (&err, SFRAME_ERR_INVAL);
 
-  num_fdes = sframe_decoder_get_num_fidx (ctx);
-  if (num_fdes == 0
-      || i >= num_fdes
-      || ctx->sfd_funcdesc == NULL)
-    return sframe_set_errno (&err, SFRAME_ERR_DCTX_INVAL);
+  fdp = sframe_decoder_get_funcdesc_at_index (ctx, i);
+
+  if (fdp == NULL)
+    return sframe_set_errno (&err, SFRAME_ERR_FDE_NOTFOUND);
 
-  fdp = (sframe_func_desc_entry *) ctx->sfd_funcdesc + i;
   *num_fres = fdp->sfde_func_num_fres;
   *func_start_address = fdp->sfde_func_start_address;
   *func_size = fdp->sfde_func_size;
@@ -1125,22 +1143,6 @@ sframe_decoder_get_funcdesc (sframe_decoder_ctx *ctx,
   return 0;
 }
 
-/* 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 >= sframe_decoder_get_num_fidx (ctx))
-    return NULL;
-
-  sframe_func_desc_entry *fdep;
-  fdep = (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.  */

                 reply	other threads:[~2023-06-07 22:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230607221921.502E63857019@sourceware.org \
    --to=ibhagat@sourceware.org \
    --cc=bfd-cvs@sourceware.org \
    --cc=gdb-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).