[Pdbg] [PATCH] libpdbg.c: Fix address translation

Amitay Isaacs amitay at ozlabs.org
Tue Jan 14 16:28:24 AEDT 2020


Minor nit-pick.  Avoid splitting log messages.  May be just cache the
old address and log it in the end.

Reviewed-by: Amitay Isaacs <amitay at ozlabs.org>

On Fri, 2020-01-10 at 14:40 +1100, Alistair Popple wrote:
> If a target provides a translation callback it's expected that the
> callback will return the absolute bus address to be used for the
> access. However the caller of this callback was continuing to apply
> translations to this absoulte address resulting in incorrect
> translations in some cases. Instead short-circuit the translation
> process.
> 
> Signed-off-by: Alistair Popple <alistair at popple.id.au>
> ---
>  libpdbg/target.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/libpdbg/target.c b/libpdbg/target.c
> index dcbee2f..46004ef 100644
> --- a/libpdbg/target.c
> +++ b/libpdbg/target.c
> @@ -19,12 +19,16 @@ struct list_head target_classes =
> LIST_HEAD_INIT(target_classes);
>  static struct pdbg_target *get_class_target_addr(struct pdbg_target
> *target, const char *name, uint64_t *addr)
>  {
>  	/* Check class */
> +	pdbg_log(PDBG_DEBUG, "Target addr 0x%" PRIx64, *addr);
>  	while (strcmp(target->class, name)) {
> -
> -		if (target->translate)
> +		if (target->translate) {
>  			*addr = target->translate(target, *addr);
> -		else
> +			target = target_parent(name, target, false);
> +			assert(target);
> +			break;
> +		} else {
>  			*addr += pdbg_target_address(target, NULL);
> +		}
>  
>  		/* Keep walking the tree translating addresses */
>  		target = get_parent(target, false);
> @@ -34,6 +38,7 @@ static struct pdbg_target
> *get_class_target_addr(struct pdbg_target *target, con
>  		assert(target != pdbg_target_root());
>  	}
>  
> +	pdbg_log(PDBG_DEBUG, " -> 0x%" PRIx64 "\n", *addr);
>  	return target;
>  }
>  
> -- 
> 2.20.1
> 

Amitay.
-- 

I am only one; but still I am one. I cannot do everything, but still I can do
something; I will not refuse to do the something I can do. - Helen Keller



More information about the Pdbg mailing list