aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIndu Bhagat <indu.bhagat@oracle.com>2024-04-26 16:15:57 -0700
committerIndu Bhagat <indu.bhagat@oracle.com>2024-04-30 15:09:37 -0700
commitb201fff7e0de790ee9eacdccc6100979dc6caa3f (patch)
tree02676e1a092b0f8a649a2e7decdc2e181638dcf2
parentfc316c05349d54805e0f1a76ce3a0cf6c572c6a2 (diff)
downloadbinutils-b201fff7e0de790ee9eacdccc6100979dc6caa3f.zip
binutils-b201fff7e0de790ee9eacdccc6100979dc6caa3f.tar.gz
binutils-b201fff7e0de790ee9eacdccc6100979dc6caa3f.tar.bz2
testsuite: libsframest: rename for readability
Some struct names and member names were long and unintuitive. Reduce the technical debt and make the code hopefully easier to maintain. libsframe/testsuite/ * libsframe.stacktrace/libsframest/sframe-stacktrace.c * libsframe.stacktrace/libsframest/sframe-state.c * libsframe.stacktrace/libsframest/sframe-state.h
-rw-r--r--libsframe/testsuite/libsframe.stacktrace/libsframest/sframe-stacktrace.c50
-rw-r--r--libsframe/testsuite/libsframe.stacktrace/libsframest/sframe-state.c133
-rw-r--r--libsframe/testsuite/libsframe.stacktrace/libsframest/sframe-state.h62
3 files changed, 129 insertions, 116 deletions
diff --git a/libsframe/testsuite/libsframe.stacktrace/libsframest/sframe-stacktrace.c b/libsframe/testsuite/libsframe.stacktrace/libsframest/sframe-stacktrace.c
index 0687b99..cd6071a 100644
--- a/libsframe/testsuite/libsframe.stacktrace/libsframest/sframe-stacktrace.c
+++ b/libsframe/testsuite/libsframe.stacktrace/libsframest/sframe-stacktrace.c
@@ -67,15 +67,15 @@ get_contents_8b (int fd, uint64_t addr, uint64_t *data)
Return 1 if valid, 0 otherwise. */
static bool
-sframe_valid_addr_p (struct sframe_state *sf, uint64_t addr)
+sframe_valid_addr_p (struct sframest_ctx *sf, uint64_t addr)
{
- struct sframe_stinfo *cdp;
+ struct sframest_info *sfinfo;
if (!sf)
return 0;
- cdp = sframe_find_context (sf, addr);
- return cdp ? 1 : 0;
+ sfinfo = sframe_find_context (sf, addr);
+ return sfinfo ? 1 : 0;
}
/* Unwind the stack and collect the stacktrace given SFrame unwind info SF.
@@ -84,13 +84,13 @@ sframe_valid_addr_p (struct sframe_state *sf, uint64_t addr)
RA_LST and contains the number of the addresses collected. */
static int
-sframe_unwind (struct sframe_state *sf, void **ra_lst, int *ra_size)
+sframe_unwind (struct sframest_ctx *sf, void **ra_lst, int *ra_size)
{
uint64_t cfa, return_addr, ra_stack_loc, rfp_stack_loc;
- sframe_decoder_ctx *ctx;
+ sframe_decoder_ctx *dctx;
int cfa_offset, rfp_offset, ra_offset, errnum, i, count;
sframe_frame_row_entry fred, *frep = &fred;
- uint64_t pc, rfp, rsp, ra, cfi_vma;
+ uint64_t pc, rfp, rsp, ra, sframe_vma;
ucontext_t context, *cp = &context;
int err = 0;
@@ -109,31 +109,31 @@ sframe_unwind (struct sframe_state *sf, void **ra_lst, int *ra_size)
return_addr = ra;
/* Load and set up the decoder. */
- ctx = sframe_load_ctx (sf, pc);
- if (!ctx)
+ dctx = sframe_load_ctx (sf, pc);
+ if (!dctx)
return sframe_bt_ret_set_errno (&err, SFRAME_BT_ERR_DECODE);
- cfi_vma = sf->sui_ctx.sfdd_sframe_vma;
+ sframe_vma = sf->prog_sfinfo.sframe_vma;
count = *ra_size;
for (i = 0; i < count; ++i)
{
- pc -= cfi_vma;
- errnum = sframe_find_fre (ctx, pc, frep);
+ pc -= sframe_vma;
+ errnum = sframe_find_fre (dctx, pc, frep);
if (!errnum)
{
- cfa_offset = sframe_fre_get_cfa_offset (ctx, frep, &errnum);
+ cfa_offset = sframe_fre_get_cfa_offset (dctx, frep, &errnum);
if (errnum == SFRAME_ERR_FREOFFSET_NOPRESENT)
return sframe_bt_ret_set_errno (&err, SFRAME_BT_ERR_CFA_OFFSET);
cfa = ((sframe_fre_get_base_reg_id (frep, &errnum)
== SFRAME_BASE_REG_SP) ? rsp : rfp) + cfa_offset;
- ra_offset = sframe_fre_get_ra_offset (ctx, frep, &errnum);
+ ra_offset = sframe_fre_get_ra_offset (dctx, frep, &errnum);
if (!errnum)
{
ra_stack_loc = cfa + ra_offset;
- errnum = get_contents_8b (sf->sui_fd, ra_stack_loc, &return_addr);
+ errnum = get_contents_8b (sf->fd, ra_stack_loc, &return_addr);
if (sframe_bt_errno (&errnum))
return sframe_bt_ret_set_errno (&err, SFRAME_BT_ERR_FRE_INVAL);
}
@@ -148,11 +148,11 @@ sframe_unwind (struct sframe_state *sf, void **ra_lst, int *ra_size)
ra_lst[i-1] = (void *)return_addr;
/* Set up for the next frame. */
- rfp_offset = sframe_fre_get_fp_offset (ctx, frep, &errnum);
+ rfp_offset = sframe_fre_get_fp_offset (dctx, frep, &errnum);
if (!errnum)
{
rfp_stack_loc = cfa + rfp_offset;
- errnum = get_contents_8b (sf->sui_fd, rfp_stack_loc, &rfp);
+ errnum = get_contents_8b (sf->fd, rfp_stack_loc, &rfp);
if (sframe_bt_errno (&errnum))
return sframe_bt_ret_set_errno (&err, SFRAME_BT_ERR_FRE_INVAL);
}
@@ -160,8 +160,8 @@ sframe_unwind (struct sframe_state *sf, void **ra_lst, int *ra_size)
pc = return_addr;
/* Check if need to update the decoder context and vma. */
- sframe_update_ctx (sf, return_addr, &ctx, &cfi_vma);
- if (!ctx)
+ sframe_update_ctx (sf, return_addr, &dctx, &sframe_vma);
+ if (!dctx)
return sframe_bt_ret_set_errno (&err, SFRAME_BT_ERR_DECODE);
}
else
@@ -189,27 +189,27 @@ find_fre_ra_err:
int
sframe_stacktrace (void **buffer, int size, int *errp)
{
- struct sframe_state sframeinfo;
+ struct sframest_ctx sf_ctx;
sframe_unwind_init_debug ();
- memset (&sframeinfo, 0, sizeof (struct sframe_state));
+ memset (&sf_ctx, 0, sizeof (struct sframest_ctx));
/* Find the .sframe sections and setup the SFrame state for generating stack
traces. */
- (void) dl_iterate_phdr (sframe_callback, (void *)&sframeinfo);
- if (!sframeinfo.sui_fd)
+ (void) dl_iterate_phdr (sframe_callback, (void *)&sf_ctx);
+ if (!sf_ctx.fd)
{
sframe_bt_ret_set_errno (errp, SFRAME_BT_ERR_BAD_SFSTATE);
return -1;
}
/* Do the stack unwinding. */
- *errp = sframe_unwind (&sframeinfo, buffer, &size);
+ *errp = sframe_unwind (&sf_ctx, buffer, &size);
if (sframe_bt_errno (errp))
size = -1;
- sframe_free_cfi (&sframeinfo);
+ sframe_free_cfi (&sf_ctx);
return size;
}
diff --git a/libsframe/testsuite/libsframe.stacktrace/libsframest/sframe-state.c b/libsframe/testsuite/libsframe.stacktrace/libsframest/sframe-state.c
index 424bfd7..efbf38f 100644
--- a/libsframe/testsuite/libsframe.stacktrace/libsframest/sframe-state.c
+++ b/libsframe/testsuite/libsframe.stacktrace/libsframest/sframe-state.c
@@ -84,31 +84,31 @@ sframe_bt_set_errno (int *errp, int error)
a dynamic shared object, to D_LIST. */
static int
-sframe_add_dso (struct sframe_stinfo_list *d_list,
- struct sframe_stinfo d_data)
+sframe_add_dso (struct sframest_info_list *d_list,
+ struct sframest_info d_data)
{
int err = 0;
if (!d_list->alloced)
{
- d_list->entry = malloc (no_of_entries * sizeof (struct sframe_stinfo));
+ d_list->entry = malloc (no_of_entries * sizeof (struct sframest_info));
if (!d_list->entry)
return sframe_bt_ret_set_errno (&err, SFRAME_BT_ERR_MALLOC);
memset (d_list->entry, 0,
- no_of_entries * sizeof (struct sframe_stinfo));
+ no_of_entries * sizeof (struct sframest_info));
d_list->alloced = no_of_entries;
}
else if (d_list->used == d_list->alloced)
{
d_list->entry = realloc (d_list->entry,
((d_list->alloced + no_of_entries)
- * sizeof (struct sframe_stinfo)));
+ * sizeof (struct sframest_info)));
if (!d_list->entry)
return sframe_bt_ret_set_errno (&err, SFRAME_BT_ERR_REALLOC);
memset (&d_list->entry[d_list->alloced], 0,
- no_of_entries * sizeof (struct sframe_stinfo));
+ no_of_entries * sizeof (struct sframest_info));
d_list->alloced += no_of_entries;
}
@@ -121,26 +121,26 @@ sframe_add_dso (struct sframe_stinfo_list *d_list,
/* Free up space allocated for .sframe info for CF. */
void
-sframe_free_cfi (struct sframe_state *sf)
+sframe_free_cfi (struct sframest_ctx *sf)
{
- struct sframe_stinfo_list *d_list;
+ struct sframest_info_list *d_list;
int i;
if (!sf)
return;
// free (sf->sui_ctx.sfdd_data);
- sframe_decoder_free (&sf->sui_ctx.sfdd_sframe_ctx);
- close (sf->sui_fd);
+ sframe_decoder_free (&sf->prog_sfinfo.dctx);
+ close (sf->fd);
- d_list = &sf-> sui_dsos;
- if (!d_list)
+ d_list = &sf->dsos_sfinfo;
+ if (!d_list->alloced)
return;
for (i = 0; i < d_list->used; ++i)
{
// free (d_list->entry[i].sfdd_data);
- sframe_decoder_free (&d_list->entry[i].sfdd_sframe_ctx);
+ sframe_decoder_free (&d_list->entry[i].dctx);
}
free (d_list->entry);
@@ -149,26 +149,26 @@ sframe_free_cfi (struct sframe_state *sf)
/* Find the decode data that contains ADDR from CF.
Return the pointer to the decode data or NULL. */
-struct sframe_stinfo *
-sframe_find_context (struct sframe_state *sf, uint64_t addr)
+struct sframest_info *
+sframe_find_context (struct sframest_ctx *sf, uint64_t addr)
{
- struct sframe_stinfo_list *d_list;
- struct sframe_stinfo sdec_data;
+ struct sframest_info_list *d_list;
+ struct sframest_info sfinfo;
int i;
if (!sf)
return NULL;
- if (sf->sui_ctx.sfdd_text_vma < addr
- && sf->sui_ctx.sfdd_text_vma + sf->sui_ctx.sfdd_text_size > addr)
- return &sf->sui_ctx;
+ if (sf->prog_sfinfo.text_vma < addr
+ && sf->prog_sfinfo.text_vma + sf->prog_sfinfo.text_size > addr)
+ return &sf->prog_sfinfo;
- d_list = &sf->sui_dsos;
- for (i = 0; i < sf->sui_dsos.used; ++i)
+ d_list = &sf->dsos_sfinfo;
+ for (i = 0; i < sf->dsos_sfinfo.used; ++i)
{
- sdec_data = d_list->entry[i];
- if ((sdec_data.sfdd_text_vma <= addr)
- && (sdec_data.sfdd_text_vma + sdec_data.sfdd_text_size >= addr))
+ sfinfo = d_list->entry[i];
+ if ((sfinfo.text_vma <= addr)
+ && (sfinfo.text_vma + sfinfo.text_size >= addr))
return &d_list->entry[i];
}
@@ -180,26 +180,26 @@ sframe_find_context (struct sframe_state *sf, uint64_t addr)
newly created decode context or NULL. */
sframe_decoder_ctx *
-sframe_load_ctx (struct sframe_state *sf, uint64_t raddr)
+sframe_load_ctx (struct sframest_ctx *sf, uint64_t raddr)
{
- sframe_decoder_ctx *nctx;
- struct sframe_stinfo *cdp;
+ sframe_decoder_ctx *dctx;
+ struct sframest_info *sfinfo;
if (!sf)
return NULL;
- cdp = sframe_find_context (sf, raddr);
- if (!cdp)
+ sfinfo = sframe_find_context (sf, raddr);
+ if (!sfinfo)
return NULL;
- if (!cdp->sfdd_sframe_ctx)
+ if (!sfinfo->dctx)
{
int err;
- nctx = sframe_decode (cdp->sfdd_data, cdp->sfdd_data_size, &err);
- if (!nctx)
+ dctx = sframe_decode (sfinfo->buf, sfinfo->buflen, &err);
+ if (!dctx)
return NULL;
- cdp->sfdd_sframe_ctx = nctx;
- return nctx;
+ sfinfo->dctx = dctx;
+ return dctx;
}
return NULL;
@@ -211,28 +211,26 @@ sframe_load_ctx (struct sframe_state *sf, uint64_t raddr)
CFI_VMA. */
void
-sframe_update_ctx (struct sframe_state *sf, uint64_t raddr,
- sframe_decoder_ctx **ctx, uint64_t *cfi_vma)
+sframe_update_ctx (struct sframest_ctx *sf, uint64_t raddr,
+ sframe_decoder_ctx **ctx, uint64_t *sframe_vma)
{
- sframe_decoder_ctx *nctx;
- struct sframe_stinfo *cdp;
+ sframe_decoder_ctx *dctx = NULL;
+ struct sframest_info *sfinfo;
- cdp = sframe_find_context (sf, raddr);
- if (cdp)
+ sfinfo = sframe_find_context (sf, raddr);
+ if (sfinfo)
{
- if (!cdp->sfdd_sframe_ctx)
+ if (!sfinfo->dctx)
{
int err;
- nctx = sframe_decode (cdp->sfdd_data, cdp->sfdd_data_size, &err);
- if (!nctx)
- {
- *ctx = NULL;
- return;
- }
- cdp->sfdd_sframe_ctx = nctx;
+ dctx = sframe_decode (sfinfo->buf, sfinfo->buflen, &err);
+ if (!dctx)
+ return;
+
+ sfinfo->dctx = dctx;
}
- *ctx = cdp->sfdd_sframe_ctx;
- *cfi_vma = cdp->sfdd_sframe_vma;
+ *ctx = sfinfo->dctx;
+ *sframe_vma = sfinfo->sframe_vma;
}
}
@@ -261,7 +259,7 @@ sframe_callback (struct dl_phdr_info *info,
size_t size ATTRIBUTE_UNUSED,
void *data)
{
- struct sframe_state *sf = (struct sframe_state *) data;
+ struct sframest_ctx *sf = (struct sframest_ctx *) data;
int p_type, i, fd, sframe_err;
ssize_t len;
uint64_t text_vma = 0;
@@ -304,7 +302,7 @@ sframe_callback (struct dl_phdr_info *info,
#endif
// sf->sui_ctx.sfdd_data = malloc (info->dlpi_phdr[i].p_memsz);
- sf->sui_ctx.sfdd_data = (char *)(info->dlpi_addr + info->dlpi_phdr[i].p_vaddr);
+ sf->prog_sfinfo.buf = (char *)(info->dlpi_addr + info->dlpi_phdr[i].p_vaddr);
#if 0
if (sf->sui_ctx.sfdd_data == NULL)
{
@@ -322,19 +320,19 @@ sframe_callback (struct dl_phdr_info *info,
len = info->dlpi_phdr[i].p_memsz;
assert (text_vma);
- sf->sui_ctx.sfdd_data_size = len;
- sf->sui_ctx.sfdd_sframe_vma = info->dlpi_addr + info->dlpi_phdr[i].p_vaddr;
- sf->sui_fd = fd;
- sf->sui_ctx.sfdd_text_vma = text_vma;
- sf->sui_ctx.sfdd_text_size = text_size;
+ sf->prog_sfinfo.buflen = len;
+ sf->prog_sfinfo.sframe_vma = info->dlpi_addr + info->dlpi_phdr[i].p_vaddr;
+ sf->fd = fd;
+ sf->prog_sfinfo.text_vma = text_vma;
+ sf->prog_sfinfo.text_size = text_size;
text_vma = 0;
return 0;
}
else
{ /* a dynamic shared object. */
- struct sframe_stinfo dt;
- memset (&dt, 0, sizeof (struct sframe_stinfo));
- assert (sf->sui_fd);
+ struct sframest_info sfinfo;
+ memset (&sfinfo, 0, sizeof (struct sframest_info));
+ assert (sf->fd);
#if 0
if (lseek (sf->sui_fd, info->dlpi_addr + info->dlpi_phdr[i].p_vaddr,
SEEK_SET) == -1)
@@ -344,8 +342,7 @@ sframe_callback (struct dl_phdr_info *info,
}
#endif
- // dt.sfdd_data = malloc (info->dlpi_phdr[i].p_memsz);
- dt.sfdd_data = (char *)(info->dlpi_addr + info->dlpi_phdr[i].p_vaddr);
+ sfinfo.buf = (char *)(info->dlpi_addr + info->dlpi_phdr[i].p_vaddr);
#if 0
if (dt.sfdd_data == NULL)
{
@@ -362,13 +359,13 @@ sframe_callback (struct dl_phdr_info *info,
#endif
len = info->dlpi_phdr[i].p_memsz;
assert (text_vma);
- dt.sfdd_data_size = len;
- dt.sfdd_sframe_vma = info->dlpi_addr + info->dlpi_phdr[i].p_vaddr;
- dt.sfdd_text_vma = text_vma;
- dt.sfdd_text_size = text_size;
+ sfinfo.buflen = len;
+ sfinfo.sframe_vma = info->dlpi_addr + info->dlpi_phdr[i].p_vaddr;
+ sfinfo.text_vma = text_vma;
+ sfinfo.text_size = text_size;
text_vma = 0;
- sframe_err = sframe_add_dso (&sf->sui_dsos, dt);
+ sframe_err = sframe_add_dso (&sf->dsos_sfinfo, sfinfo);
// FIXME TODO
if (sframe_err != SFRAME_BT_OK)
return 1;
diff --git a/libsframe/testsuite/libsframe.stacktrace/libsframest/sframe-state.h b/libsframe/testsuite/libsframe.stacktrace/libsframest/sframe-state.h
index 98c91f6..57d8564 100644
--- a/libsframe/testsuite/libsframe.stacktrace/libsframest/sframe-state.h
+++ b/libsframe/testsuite/libsframe.stacktrace/libsframest/sframe-state.h
@@ -43,48 +43,64 @@
#define PT_SFRAME 0x6474e554
#endif
-/* SFrame decode data for the main module or a DSO. */
-struct sframe_stinfo
+/* SFrame stacktrace data. */
+
+struct sframest_info
{
- char *sfdd_data; /* SFrame decode data. */
- int sfdd_data_size; /* SFrame decode data size. */
- uint64_t sfdd_text_vma; /* Text segment's virtual address. */
- int sfdd_text_size; /* Text segment's size. */
- uint64_t sfdd_sframe_vma; /* SFrame segment's virtual address. */
- sframe_decoder_ctx *sfdd_sframe_ctx; /* SFrame decoder context. */
+ /* Reference to the SFrame section in process memory. */
+ char *buf;
+ /* Length in bytes of the SFrame section in memory. */
+ int buflen;
+ /* Text segment's virtual address. */
+ uint64_t text_vma;
+ /* Text segment's length in bytes. */
+ int text_size;
+ /* SFrame segment's virtual address. */
+ uint64_t sframe_vma;
+ /* SFrame decoder context. For access to decoded SFrame information. */
+ sframe_decoder_ctx *dctx;
};
-/* List that holds SFrame info for the shared libraries. */
-struct sframe_stinfo_list
+/* List of SFrame stacktrace info objects.
+ Typically used to represent SFrame stacktrace info for set of shared
+ libraries of a program. */
+
+struct sframest_info_list
{
- int alloced; /* Entries allocated. */
- int used; /* Entries used. */
- struct sframe_stinfo *entry; /* DSO's decode data. */
+ /* Number of entries allocated. */
+ int alloced;
+ /* Number of entries used. */
+ int used;
+ /* (Array) List of SFrame stacktrace info objects. */
+ struct sframest_info *entry;
};
-/* Data that's passed through sframe_callback. */
-struct sframe_state
+/* SFrame stacktracing context. */
+
+struct sframest_ctx
{
- int sui_fd; /* File descriptor. */
- struct sframe_stinfo sui_ctx; /* The decode data. */
- struct sframe_stinfo_list sui_dsos; /* The DSO list. */
+ /* File descriptor for the process memory. */
+ int fd;
+ /* SFrame stacktrace info for program. */
+ struct sframest_info prog_sfinfo;
+ /* SFrame stacktrace info for its DSOs. */
+ struct sframest_info_list dsos_sfinfo;
};
-
void sframe_unwind_init_debug (void);
int sframe_callback (struct dl_phdr_info *info,
size_t size ATTRIBUTE_UNUSED,
void *data);
-void sframe_update_ctx (struct sframe_state *sf, uint64_t raddr,
+void sframe_update_ctx (struct sframest_ctx *sf, uint64_t raddr,
sframe_decoder_ctx **ctx, uint64_t *cfi_vma);
-sframe_decoder_ctx *sframe_load_ctx (struct sframe_state *sf, uint64_t raddr);
+sframe_decoder_ctx *sframe_load_ctx (struct sframest_ctx *sf, uint64_t raddr);
-struct sframe_stinfo *sframe_find_context (struct sframe_state *sf,
+struct sframest_info *sframe_find_context (struct sframest_ctx *sf,
uint64_t addr);
-void sframe_free_cfi (struct sframe_state *sf);
+void sframe_free_cfi (struct sframest_ctx *sf);
#endif /* SFRAME_STATE_H. */