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

Alistair Popple alistair at popple.id.au
Fri Jan 10 14:40:43 AEDT 2020


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



More information about the Pdbg mailing list