[Pdbg] [PATCH 5/5] libpdbg: Return immediate parent if class is NULL

Alistair Popple alistair at popple.id.au
Fri Sep 7 13:23:31 AEST 2018


Hi Amitay,

What is this needed for? In the targetting model we have we are trying to avoid
relying on overly specific parent/child relationships as they can be brittle,
hence why callers need to specify which specific type/class of parent they are
looking for. There's not much that could be done with an arbitrary parent
anyway.

Although I agree an `assert(class)` would probably assist debug.

- Alistair

On Thursday, 16 August 2018 3:57:56 PM AEST Amitay Isaacs wrote:
> This avoids the segfault if class is NULL.  Also, this api can be used
> to traverse the tree by explicitly setting class=NULL.
> 
> Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
> ---
>  libpdbg/libpdbg.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/libpdbg/libpdbg.c b/libpdbg/libpdbg.c
> index 522bec9..810e045 100644
> --- a/libpdbg/libpdbg.c
> +++ b/libpdbg/libpdbg.c
> @@ -89,6 +89,9 @@ struct pdbg_target *pdbg_target_parent(const char *class, struct pdbg_target *ta
>  {
>  	struct pdbg_target *parent;
>  
> +	if (!class)
> +		return target->parent;
> +
>  	for (parent = target->parent; parent && parent->parent; parent = parent->parent) {
>  		if (!strcmp(class, pdbg_target_class_name(parent)))
>  			return parent;
> 




More information about the Pdbg mailing list