diff options
author | Indu Bhagat <indu.bhagat@oracle.com> | 2024-04-26 11:58:41 -0700 |
---|---|---|
committer | Indu Bhagat <indu.bhagat@oracle.com> | 2024-04-30 15:09:37 -0700 |
commit | fc316c05349d54805e0f1a76ce3a0cf6c572c6a2 (patch) | |
tree | 1c87285bee152b4a914b47aed9ccda443facb7c0 | |
parent | 72ca5c892d4a52734036b0148bc21b6c0401cfae (diff) | |
download | gdb-fc316c05349d54805e0f1a76ce3a0cf6c572c6a2.zip gdb-fc316c05349d54805e0f1a76ce3a0cf6c572c6a2.tar.gz gdb-fc316c05349d54805e0f1a76ce3a0cf6c572c6a2.tar.bz2 |
testsuite: libsframest: use shorter version in conditionals
libsframe/testsuite/
* libsframe.stacktrace/libsframest/sframe-stacktrace.c
* libsframe.stacktrace/libsframest/sframe-state.c
-rw-r--r-- | libsframe/testsuite/libsframe.stacktrace/libsframest/sframe-stacktrace.c | 36 | ||||
-rw-r--r-- | libsframe/testsuite/libsframe.stacktrace/libsframest/sframe-state.c | 28 |
2 files changed, 33 insertions, 31 deletions
diff --git a/libsframe/testsuite/libsframe.stacktrace/libsframest/sframe-stacktrace.c b/libsframe/testsuite/libsframe.stacktrace/libsframest/sframe-stacktrace.c index 5034f86..0687b99 100644 --- a/libsframe/testsuite/libsframe.stacktrace/libsframest/sframe-stacktrace.c +++ b/libsframe/testsuite/libsframe.stacktrace/libsframest/sframe-stacktrace.c @@ -46,7 +46,7 @@ get_contents_8b (int fd, uint64_t addr, uint64_t *data) size_t sz = 0; int err = 0; - if (data == NULL) + if (!data) return sframe_bt_ret_set_errno (&err, SFRAME_BT_ERR_ARG); if (lseek (fd, addr, SEEK_SET) == -1) @@ -59,16 +59,19 @@ get_contents_8b (int fd, uint64_t addr, uint64_t *data) return SFRAME_BT_OK; } -/* sframe_valid_addr_p - Check if ADDR is valid in CF. The address is considered - invalid, with regards to SFrame, if it's not in any address range of the - main module or any of its DSO's. Return 1 if valid, 0 otherwise. */ +/* Check if ADDR is valid in SF. -static int + The address is considered invalid, with regards to SFrame, if it's not in + any address range of the main module or any of its DSO's. + + Return 1 if valid, 0 otherwise. */ + +static bool sframe_valid_addr_p (struct sframe_state *sf, uint64_t addr) { struct sframe_stinfo *cdp; - if (sf == NULL) + if (!sf) return 0; cdp = sframe_find_context (sf, addr); @@ -81,8 +84,7 @@ 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 sframe_state *sf, void **ra_lst, int *ra_size) { uint64_t cfa, return_addr, ra_stack_loc, rfp_stack_loc; sframe_decoder_ctx *ctx; @@ -92,11 +94,11 @@ sframe_unwind (struct sframe_state *sf, void **ra_lst, ucontext_t context, *cp = &context; int err = 0; - if (sf == NULL || ra_lst == NULL || ra_size == NULL) + if (!sf || !ra_lst || !ra_size) return sframe_bt_ret_set_errno (&err, SFRAME_BT_ERR_ARG); /* Get the user context for its registers. */ - if (getcontext (cp) != 0) + if (getcontext (cp)) return sframe_bt_ret_set_errno (&err, SFRAME_BT_ERR_GETCONTEXT); pc = get_context_pc (cp); @@ -108,7 +110,7 @@ sframe_unwind (struct sframe_state *sf, void **ra_lst, /* Load and set up the decoder. */ ctx = sframe_load_ctx (sf, pc); - if (ctx == NULL) + if (!ctx) return sframe_bt_ret_set_errno (&err, SFRAME_BT_ERR_DECODE); cfi_vma = sf->sui_ctx.sfdd_sframe_vma; @@ -118,7 +120,7 @@ sframe_unwind (struct sframe_state *sf, void **ra_lst, { pc -= cfi_vma; errnum = sframe_find_fre (ctx, pc, frep); - if (errnum == 0) + if (!errnum) { cfa_offset = sframe_fre_get_cfa_offset (ctx, frep, &errnum); if (errnum == SFRAME_ERR_FREOFFSET_NOPRESENT) @@ -128,7 +130,7 @@ sframe_unwind (struct sframe_state *sf, void **ra_lst, == SFRAME_BASE_REG_SP) ? rsp : rfp) + cfa_offset; ra_offset = sframe_fre_get_ra_offset (ctx, frep, &errnum); - if (errnum == 0) + if (!errnum) { ra_stack_loc = cfa + ra_offset; errnum = get_contents_8b (sf->sui_fd, ra_stack_loc, &return_addr); @@ -137,7 +139,7 @@ sframe_unwind (struct sframe_state *sf, void **ra_lst, } /* Validate and add return address to the list. */ - if (sframe_valid_addr_p (sf, return_addr) == 0) + if (!sframe_valid_addr_p (sf, return_addr)) { i -= 1; goto find_fre_ra_err; @@ -147,7 +149,7 @@ sframe_unwind (struct sframe_state *sf, void **ra_lst, /* Set up for the next frame. */ rfp_offset = sframe_fre_get_fp_offset (ctx, frep, &errnum); - if (errnum == 0) + if (!errnum) { rfp_stack_loc = cfa + rfp_offset; errnum = get_contents_8b (sf->sui_fd, rfp_stack_loc, &rfp); @@ -159,7 +161,7 @@ sframe_unwind (struct sframe_state *sf, void **ra_lst, /* Check if need to update the decoder context and vma. */ sframe_update_ctx (sf, return_addr, &ctx, &cfi_vma); - if (ctx == NULL) + if (!ctx) return sframe_bt_ret_set_errno (&err, SFRAME_BT_ERR_DECODE); } else @@ -196,7 +198,7 @@ sframe_stacktrace (void **buffer, int size, int *errp) /* 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 == 0) + if (!sframeinfo.sui_fd) { sframe_bt_ret_set_errno (errp, SFRAME_BT_ERR_BAD_SFSTATE); return -1; diff --git a/libsframe/testsuite/libsframe.stacktrace/libsframest/sframe-state.c b/libsframe/testsuite/libsframe.stacktrace/libsframest/sframe-state.c index 1d0ae08..424bfd7 100644 --- a/libsframe/testsuite/libsframe.stacktrace/libsframest/sframe-state.c +++ b/libsframe/testsuite/libsframe.stacktrace/libsframest/sframe-state.c @@ -89,10 +89,10 @@ sframe_add_dso (struct sframe_stinfo_list *d_list, { int err = 0; - if (d_list->alloced == 0) + if (!d_list->alloced) { d_list->entry = malloc (no_of_entries * sizeof (struct sframe_stinfo)); - if (d_list->entry == NULL) + if (!d_list->entry) return sframe_bt_ret_set_errno (&err, SFRAME_BT_ERR_MALLOC); memset (d_list->entry, 0, @@ -104,7 +104,7 @@ sframe_add_dso (struct sframe_stinfo_list *d_list, d_list->entry = realloc (d_list->entry, ((d_list->alloced + no_of_entries) * sizeof (struct sframe_stinfo))); - if (d_list->entry == NULL) + if (!d_list->entry) return sframe_bt_ret_set_errno (&err, SFRAME_BT_ERR_REALLOC); memset (&d_list->entry[d_list->alloced], 0, @@ -126,7 +126,7 @@ sframe_free_cfi (struct sframe_state *sf) struct sframe_stinfo_list *d_list; int i; - if (sf == NULL) + if (!sf) return; // free (sf->sui_ctx.sfdd_data); @@ -134,7 +134,7 @@ sframe_free_cfi (struct sframe_state *sf) close (sf->sui_fd); d_list = &sf-> sui_dsos; - if (d_list == NULL) + if (!d_list) return; for (i = 0; i < d_list->used; ++i) @@ -156,7 +156,7 @@ sframe_find_context (struct sframe_state *sf, uint64_t addr) struct sframe_stinfo sdec_data; int i; - if (sf == NULL) + if (!sf) return NULL; if (sf->sui_ctx.sfdd_text_vma < addr @@ -185,18 +185,18 @@ sframe_load_ctx (struct sframe_state *sf, uint64_t raddr) sframe_decoder_ctx *nctx; struct sframe_stinfo *cdp; - if (sf == NULL) + if (!sf) return NULL; cdp = sframe_find_context (sf, raddr); - if (cdp == NULL) + if (!cdp) return NULL; - if (cdp->sfdd_sframe_ctx == NULL) + if (!cdp->sfdd_sframe_ctx) { int err; nctx = sframe_decode (cdp->sfdd_data, cdp->sfdd_data_size, &err); - if (nctx == NULL) + if (!nctx) return NULL; cdp->sfdd_sframe_ctx = nctx; return nctx; @@ -218,13 +218,13 @@ sframe_update_ctx (struct sframe_state *sf, uint64_t raddr, struct sframe_stinfo *cdp; cdp = sframe_find_context (sf, raddr); - if (cdp != NULL) + if (cdp) { - if (cdp->sfdd_sframe_ctx == NULL) + if (!cdp->sfdd_sframe_ctx) { int err; nctx = sframe_decode (cdp->sfdd_data, cdp->sfdd_data_size, &err); - if (nctx == NULL) + if (!nctx) { *ctx = NULL; return; @@ -267,7 +267,7 @@ sframe_callback (struct dl_phdr_info *info, uint64_t text_vma = 0; int text_size = 0; - if (data == NULL || info == NULL) + if (!data || !info) return 1; debug_printf ("-- name: %s %14p\n", info->dlpi_name, (void *)info->dlpi_addr); |