mirror of
https://github.com/JakeHillion/drgn.git
synced 2024-12-23 01:33:06 +00:00
libdrgn: add drgn_object_read_integer()
There are some cases where we want to read an integer regardless of its signedness, so drgn_object_read_signed() and drgn_object_read_unsigned() are cumbersome to use, and drgn_object_read_value() is too permissive.
This commit is contained in:
parent
97b5967c37
commit
b5735de8dc
@ -1945,6 +1945,20 @@ struct drgn_error *drgn_object_read_signed(const struct drgn_object *obj,
|
||||
struct drgn_error *drgn_object_read_unsigned(const struct drgn_object *obj,
|
||||
uint64_t *ret);
|
||||
|
||||
/**
|
||||
* Get the value of an object with kind @ref
|
||||
* drgn_object_kind::DRGN_OBJECT_SIGNED or @ref
|
||||
* drgn_object_kind::DRGN_OBJECT_UNSIGNED.
|
||||
*
|
||||
* If the object is not an integer, an error is returned.
|
||||
*
|
||||
* @param[in] obj Object to read.
|
||||
* @param[out] ret Returned value.
|
||||
* @return @c NULL on success, non-@c NULL on error.
|
||||
*/
|
||||
struct drgn_error *drgn_object_read_integer(const struct drgn_object *obj,
|
||||
union drgn_value *ret);
|
||||
|
||||
/**
|
||||
* Get the value of an object with kind @ref
|
||||
* drgn_object_kind::DRGN_OBJECT_FLOAT.
|
||||
|
@ -737,6 +737,26 @@ drgn_object_read_unsigned(const struct drgn_object *obj, uint64_t *ret)
|
||||
return drgn_object_value_unsigned(obj, ret);
|
||||
}
|
||||
|
||||
LIBDRGN_PUBLIC struct drgn_error *
|
||||
drgn_object_read_integer(const struct drgn_object *obj, union drgn_value *ret)
|
||||
{
|
||||
struct drgn_error *err;
|
||||
union drgn_value value_mem;
|
||||
const union drgn_value *value;
|
||||
|
||||
if (obj->kind != DRGN_OBJECT_SIGNED &&
|
||||
obj->kind != DRGN_OBJECT_UNSIGNED) {
|
||||
return drgn_error_create(DRGN_ERROR_TYPE,
|
||||
"not an integer");
|
||||
}
|
||||
err = drgn_object_read_value(obj, &value_mem, &value);
|
||||
if (err)
|
||||
return err;
|
||||
*ret = *value;
|
||||
drgn_object_deinit_value(obj, value);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LIBDRGN_PUBLIC struct drgn_error *
|
||||
drgn_object_read_float(const struct drgn_object *obj, double *ret)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user