public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Indu Bhagat <indu.bhagat@oracle.com>
To: binutils@sourceware.org
Cc: Indu Bhagat <indu.bhagat@oracle.com>
Subject: [COMMITTED] libsframe: update the semantics of sframe_fre_get_ra_offset
Date: Tue, 27 Jun 2023 12:51:18 -0700	[thread overview]
Message-ID: <20230627195126.1955051-4-indu.bhagat@oracle.com> (raw)
In-Reply-To: <20230627195126.1955051-1-indu.bhagat@oracle.com>

Until now, sframe_fre_get_ra_offset () would return
SFRAME_ERR_FREOFFSET_NOPRESENT if the ABI uses fixed RA offset (e.g.,
AMD64).  A stack tracer, then, will call an explicit
sframe_decoder_get_fixed_ra_offset () to get the RA offset.

On second look, it appears to make sense to hide these details of
whether the RA offset is fixed or not from the consumer.  Now, with the
changed semantics, the call to sframe_fre_get_ra_offset () will fetch
the fixed RA offset if applicable, or get the RA offset from FRE when
there is no fixed RA offset.

Adjustments need to be made to ensure the textual dump remains the same
as preivous.  Currently, e.g., if RA is not being tracked per FRE,
following is seen with objdump --sframe:

    STARTPC         CFA       FP        RA
    000000000000NNNN  sp+X      u         u

This patch changes the behavior of sframe_fre_get_ra_offset: it turns an
error into non-error.  This change will be included with the next
release of libsframe, where all exposed symbols will be versioned for
the first time.

libsframe/
	* sframe.c (sframe_fre_get_ra_offset): Return the fixed offset,
	if applicable.  Else return the RA offset from the FRE.
	* sframe-dump.c (dump_sframe_func_with_fres): Make adjustments
	to keep the textual dump same as previous.
---
 libsframe/sframe-dump.c | 12 ++++++++----
 libsframe/sframe.c      | 14 +++++++++-----
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/libsframe/sframe-dump.c b/libsframe/sframe-dump.c
index 6d266392cd7..2491b4391f3 100644
--- a/libsframe/sframe-dump.c
+++ b/libsframe/sframe-dump.c
@@ -164,11 +164,15 @@ dump_sframe_func_with_fres (sframe_decoder_ctx *sfd_ctx,
 	strcpy (temp, "u");
       printf ("%-10s", temp);
 
-      /* Dump RA info.  */
-      if (err[2] == 0)
-	sprintf (temp, "c%+d", ra_offset);
-      else
+      /* Dump RA info.
+	 If an ABI does not track RA offset, e.g., AMD64, display a 'u',
+	 else display the offset d as 'c+-d'.  */
+      if (sframe_decoder_get_fixed_ra_offset(sfd_ctx)
+	  != SFRAME_CFA_FIXED_RA_INVALID)
 	strcpy (temp, "u");
+      else if (err[2] == 0)
+	sprintf (temp, "c%+d", ra_offset);
+
       /* Mark SFrame FRE's RA information with "[s]" if the RA is mangled
 	 with signature bits.  */
       const char *ra_mangled_p_str
diff --git a/libsframe/sframe.c b/libsframe/sframe.c
index 8837f878fb0..3d1b5575f0b 100644
--- a/libsframe/sframe.c
+++ b/libsframe/sframe.c
@@ -665,11 +665,15 @@ int32_t
 sframe_fre_get_ra_offset (sframe_decoder_ctx *dctx,
 			  sframe_frame_row_entry *fre, int *errp)
 {
-  sframe_header *dhp = sframe_decoder_get_header (dctx);
-  /* If the RA offset was not being tracked, return an error code so the caller
-     can gather the fixed RA offset from the SFrame header.  */
-  if (dhp->sfh_cfa_fixed_ra_offset != SFRAME_CFA_FIXED_RA_INVALID)
-    return sframe_set_errno (errp, SFRAME_ERR_FREOFFSET_NOPRESENT);
+  int8_t ra_offset = sframe_decoder_get_fixed_ra_offset (dctx);
+  /* If the RA offset was not being tracked, return the fixed RA offset
+     from the SFrame header.  */
+  if (ra_offset != SFRAME_CFA_FIXED_RA_INVALID)
+    {
+      if (errp)
+	*errp = 0;
+      return ra_offset;
+    }
 
   /* Otherwise, get the RA offset from the FRE.  */
   return sframe_get_fre_offset (fre, SFRAME_FRE_RA_OFFSET_IDX, errp);
-- 
2.39.2


  parent reply	other threads:[~2023-06-27 19:52 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-27 19:51 [COMMITTED] libsframe: add library versioning Indu Bhagat
2023-06-27 19:51 ` [COMMITTED] libsframe: remove sframe_get_funcdesc_with_addr API Indu Bhagat
2023-06-27 19:51 ` [COMMITTED] libsframe: add symbol versioning Indu Bhagat
2023-06-27 19:51 ` Indu Bhagat [this message]
2023-06-27 19:51 ` [COMMITTED] libsframe: update the semantics of sframe_fre_get_fp_offset Indu Bhagat
2023-06-27 19:51 ` [COMMITTED] libsframe: use uint32_t for fre_type and fde_type function args Indu Bhagat
2023-06-27 19:51 ` [COMMITTED] libsframe: bfd: use uint32_t for return type of sframe_calc_fre_type Indu Bhagat
2023-06-27 19:51 ` [COMMITTED] libsframe: use uint8_t instead of unsigned char for abi_arch Indu Bhagat
2023-06-27 19:51 ` [COMMITTED] libsframe: use uint8_t for return type of sframe_fre_get_base_reg_id Indu Bhagat
2023-06-27 19:51 ` [COMMITTED] libsframe: use appropriate data types for args of sframe_encode Indu Bhagat
2023-06-27 19:51 ` [COMMITTED] libsframe: bfd: use uint32_t for return type of get_num_fidx APIs Indu Bhagat
2023-06-27 19:51 ` [COMMITTED] binutils/NEWS: add note about upcoming libsframe changes Indu Bhagat

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=20230627195126.1955051-4-indu.bhagat@oracle.com \
    --to=indu.bhagat@oracle.com \
    --cc=binutils@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).