[Pdbg] [PATCH 05/19] libpdbg: Always allocate ffdc data and return to caller
Amitay Isaacs
amitay at ozlabs.org
Thu Jul 2 13:39:04 AEST 2020
Instead of returning the pointer to internally cached ffdc data, copy
the ffdc data.
Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
---
libpdbg/libpdbg.h | 5 +++--
libpdbg/target.c | 17 +++++++++++++++--
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h
index e850108..28380cd 100644
--- a/libpdbg/libpdbg.h
+++ b/libpdbg/libpdbg.h
@@ -1259,9 +1259,10 @@ int sbe_istep(struct pdbg_target *target, uint32_t major, uint32_t minor);
*
* @return SBE error code, 0 if there is no ffdc data
*
- * The ffdc data must be freed by caller.
+ * The ffdc data must be freed by caller. It is allocated using malloc and
+ * must be freed using free().
*/
-uint32_t sbe_ffdc_get(struct pdbg_target *target, const uint8_t **ffdc, uint32_t *ffdc_len);
+uint32_t sbe_ffdc_get(struct pdbg_target *target, uint8_t **ffdc, uint32_t *ffdc_len);
/**
* @brief Execute enter mpipl on the pib
diff --git a/libpdbg/target.c b/libpdbg/target.c
index dff446c..69f8b24 100644
--- a/libpdbg/target.c
+++ b/libpdbg/target.c
@@ -463,9 +463,11 @@ int sbe_mpipl_get_ti_info(struct pdbg_target *target, uint8_t **data, uint32_t *
return chipop->mpipl_get_ti_info(chipop, data, data_len);
}
-uint32_t sbe_ffdc_get(struct pdbg_target *target, const uint8_t **ffdc, uint32_t *ffdc_len)
+uint32_t sbe_ffdc_get(struct pdbg_target *target, uint8_t **ffdc, uint32_t *ffdc_len)
{
struct chipop *chipop;
+ const uint8_t *data = NULL;
+ uint32_t status, len = 0;
chipop = pib_to_chipop(target);
if (!chipop)
@@ -476,7 +478,18 @@ uint32_t sbe_ffdc_get(struct pdbg_target *target, const uint8_t **ffdc, uint32_t
return -1;
}
- return chipop->ffdc_get(chipop, ffdc, ffdc_len);
+ status = chipop->ffdc_get(chipop, &data, &len);
+ if (data && len > 0) {
+ *ffdc = malloc(len);
+ assert(*ffdc);
+ memcpy(*ffdc, data, len);
+ *ffdc_len = len;
+ } else {
+ *ffdc = NULL;
+ *ffdc_len = 0;
+ }
+
+ return status;
}
/* Finds the given class. Returns NULL if not found. */
--
2.26.2
More information about the Pdbg
mailing list