public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
* [binutils-gdb] libsframe: reuse static function sframe_decoder_get_funcdesc_at_index
@ 2023-06-07 22:19 Indu Bhagat
  0 siblings, 0 replies; only message in thread
From: Indu Bhagat @ 2023-06-07 22:19 UTC (permalink / raw)
  To: bfd-cvs, gdb-cvs

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.  */

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-06-07 22:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-07 22:19 [binutils-gdb] libsframe: reuse static function sframe_decoder_get_funcdesc_at_index Indu Bhagat

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).