aboutsummaryrefslogtreecommitdiff
path: root/libsframe
diff options
context:
space:
mode:
authorIndu Bhagat <indu.bhagat@oracle.com>2022-12-25 00:06:22 -0800
committerIndu Bhagat <indu.bhagat@oracle.com>2022-12-25 00:08:27 -0800
commit68bb0d2765abfdcd9f2b29311c60b5472f0b1a24 (patch)
tree7a0cac150dc25e7571970b85ffb9586e7b8c15c8 /libsframe
parent111b1cf97e7e5a8db35b48c4a9d93692dec799ce (diff)
downloadgdb-68bb0d2765abfdcd9f2b29311c60b5472f0b1a24.zip
gdb-68bb0d2765abfdcd9f2b29311c60b5472f0b1a24.tar.gz
gdb-68bb0d2765abfdcd9f2b29311c60b5472f0b1a24.tar.bz2
libsframe: write out SFrame FRE start address correctly
The following test was failing on ppc64 and s390x: "FAIL: encode-1: Encode buffer match" The offending stub was how we memcpy the FRE start address to the buffer (on-disk format). When the host is big-endian, the address of the source buffer for the memcpy needs to point to the uint8_t/uint16_t sized value of the FRE start addr, not uint32_t sized value; we intend to copy out only the fre_start_addr_sz number of bytes. ChangeLog: * libsframe/sframe.c (sframe_encoder_write_fre_start_addr): New function. (sframe_encoder_write_fre): Use it instead of memcpy.
Diffstat (limited to 'libsframe')
-rw-r--r--libsframe/sframe.c38
1 files changed, 35 insertions, 3 deletions
diff --git a/libsframe/sframe.c b/libsframe/sframe.c
index e41c95b..c912340 100644
--- a/libsframe/sframe.c
+++ b/libsframe/sframe.c
@@ -1502,6 +1502,39 @@ sframe_sort_funcdesc (sframe_encoder_ctx *encoder)
return 0;
}
+/* Write the SFrame FRE start address from the in-memory FRE_START_ADDR
+ to the buffer CONTENTS (on-disk format), given the FRE_TYPE and
+ FRE_START_ADDR_SZ. */
+
+static int
+sframe_encoder_write_fre_start_addr (char *contents,
+ uint32_t fre_start_addr,
+ unsigned int fre_type,
+ size_t fre_start_addr_sz)
+{
+ int err = 0;
+
+ if (fre_type == SFRAME_FRE_TYPE_ADDR1)
+ {
+ uint8_t uc = fre_start_addr;
+ memcpy (contents, &uc, fre_start_addr_sz);
+ }
+ else if (fre_type == SFRAME_FRE_TYPE_ADDR2)
+ {
+ uint16_t ust = fre_start_addr;
+ memcpy (contents, &ust, fre_start_addr_sz);
+ }
+ else if (fre_type == SFRAME_FRE_TYPE_ADDR4)
+ {
+ uint32_t uit = fre_start_addr;
+ memcpy (contents, &uit, fre_start_addr_sz);
+ }
+ else
+ return sframe_set_errno (&err, SFRAME_ERR_INVAL);
+
+ return 0;
+}
+
/* Write a frame row entry pointed to by FREP into the buffer CONTENTS. The
size in bytes written out are updated in ESZ.
@@ -1529,9 +1562,8 @@ sframe_encoder_write_fre (char *contents, sframe_frame_row_entry *frep,
uint64_t bitmask = SFRAME_BITMASK_OF_SIZE (fre_start_addr_sz);
sframe_assert ((uint64_t)frep->fre_start_addr <= bitmask);
- memcpy (contents,
- &frep->fre_start_addr,
- fre_start_addr_sz);
+ sframe_encoder_write_fre_start_addr (contents, frep->fre_start_addr,
+ fre_type, fre_start_addr_sz);
contents += fre_start_addr_sz;
memcpy (contents,