diff mbox series

[2/9] libpdbg: Avoid direct access of class in pdbg_target

Message ID 20200622004501.12889-3-amitay@ozlabs.org
State Superseded
Headers show
Series Make register access into thread procedures | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success Successfully applied on branch master (b0a62fc11260400ad7518e36cbab9e56dd1bbf5b)
snowpatch_ozlabs/build-multiarch success Test build-multiarch on branch master

Commit Message

Amitay Isaacs June 22, 2020, 12:44 a.m. UTC
Signed-off-by: Amitay Isaacs <amitay@ozlabs.org>
---
 libpdbg/chip.c | 114 ++++++++++++++++++++++++-------------------------
 1 file changed, 57 insertions(+), 57 deletions(-)
diff mbox series

Patch

diff --git a/libpdbg/chip.c b/libpdbg/chip.c
index f9f184b..f0dd6bf 100644
--- a/libpdbg/chip.c
+++ b/libpdbg/chip.c
@@ -110,7 +110,7 @@  struct thread_state thread_status(struct pdbg_target *target)
 {
 	struct thread *thread;
 
-	assert(!strcmp(target->class, "thread"));
+	assert(pdbg_target_is_class(target, "thread"));
 	thread = target_to_thread(target);
 	return thread->status;
 }
@@ -118,39 +118,39 @@  struct thread_state thread_status(struct pdbg_target *target)
 /*
  * Single step the thread count instructions.
  */
-int thread_step(struct pdbg_target *thread_target, int count)
+int thread_step(struct pdbg_target *target, int count)
 {
 	struct thread *thread;
 
-	assert(!strcmp(thread_target->class, "thread"));
-	thread = target_to_thread(thread_target);
+	assert(pdbg_target_is_class(target, "thread"));
+	thread = target_to_thread(target);
 	return thread->step(thread, count);
 }
 
-int thread_start(struct pdbg_target *thread_target)
+int thread_start(struct pdbg_target *target)
 {
 	struct thread *thread;
 
-	assert(!strcmp(thread_target->class, "thread"));
-	thread = target_to_thread(thread_target);
+	assert(pdbg_target_is_class(target, "thread"));
+	thread = target_to_thread(target);
 	return thread->start(thread);
 }
 
-int thread_stop(struct pdbg_target *thread_target)
+int thread_stop(struct pdbg_target *target)
 {
 	struct thread *thread;
 
-	assert(!strcmp(thread_target->class, "thread"));
-	thread = target_to_thread(thread_target);
+	assert(pdbg_target_is_class(target, "thread"));
+	thread = target_to_thread(target);
 	return thread->stop(thread);
 }
 
-int thread_sreset(struct pdbg_target *thread_target)
+int thread_sreset(struct pdbg_target *target)
 {
 	struct thread *thread;
 
-	assert(!strcmp(thread_target->class, "thread"));
-	thread = target_to_thread(thread_target);
+	assert(pdbg_target_is_class(target, "thread"));
+	thread = target_to_thread(target);
 	return thread->sreset(thread);
 }
 
@@ -526,29 +526,29 @@  int thread_putxer(struct pdbg_target *target, uint64_t value)
 /*
  * Read the given ring from the given chiplet. Result must be large enough to hold ring_len bits.
  */
-int getring(struct pdbg_target *chiplet_target, uint64_t ring_addr, uint64_t ring_len, uint32_t result[])
+int getring(struct pdbg_target *target, uint64_t ring_addr, uint64_t ring_len, uint32_t result[])
 {
 	struct chiplet *chiplet;
 
-	assert(!strcmp(chiplet_target->class, "chiplet"));
-	chiplet = target_to_chiplet(chiplet_target);
+	assert(pdbg_target_is_class(target, "chiplet"));
+	chiplet = target_to_chiplet(target);
 	return chiplet->getring(chiplet, ring_addr, ring_len, result);
 }
 
-int thread_getregs(struct pdbg_target *thread, struct thread_regs *regs)
+int thread_getregs(struct pdbg_target *target, struct thread_regs *regs)
 {
+	struct thread *thread;
 	struct thread_regs _regs;
-	struct thread *t;
 	uint64_t value = 0;
 	int i;
 
 	if (!regs)
 		regs = &_regs;
 
-	assert(!strcmp(thread->class, "thread"));
-	t = target_to_thread(thread);
+	assert(pdbg_target_is_class(target, "thread"));
+	thread = target_to_thread(target);
 
-	CHECK_ERR(t->ram_setup(t));
+	CHECK_ERR(thread->ram_setup(thread));
 
 	/*
 	 * It would be neat to do all the ramming up front, then go through
@@ -556,120 +556,120 @@  int thread_getregs(struct pdbg_target *thread, struct thread_regs *regs)
 	 * can help to diagnose checkstop issues with ramming to print as
 	 * we go. Once it's more robust and tested, maybe.
 	 */
-	thread_getnia(thread, &regs->nia);
+	thread_getnia(target, &regs->nia);
 	printf("NIA   : 0x%016" PRIx64 "\n", regs->nia);
 
-	thread_getspr(thread, 28, &regs->cfar);
+	thread_getspr(target, 28, &regs->cfar);
 	printf("CFAR  : 0x%016" PRIx64 "\n", regs->cfar);
 
-	thread_getmsr(thread, &regs->msr);
+	thread_getmsr(target, &regs->msr);
 	printf("MSR   : 0x%016" PRIx64 "\n", regs->msr);
 
-	thread_getspr(thread, 8, &regs->lr);
+	thread_getspr(target, 8, &regs->lr);
 	printf("LR    : 0x%016" PRIx64 "\n", regs->lr);
 
-	thread_getspr(thread, 9, &regs->ctr);
+	thread_getspr(target, 9, &regs->ctr);
 	printf("CTR   : 0x%016" PRIx64 "\n", regs->ctr);
 
-	thread_getspr(thread, 815, &regs->tar);
+	thread_getspr(target, 815, &regs->tar);
 	printf("TAR   : 0x%016" PRIx64 "\n", regs->tar);
 
-	thread_getcr(thread, &regs->cr);
+	thread_getcr(target, &regs->cr);
 	printf("CR    : 0x%08" PRIx32 "\n", regs->cr);
 
-	thread_getxer(thread, &regs->xer);
+	thread_getxer(target, &regs->xer);
 	printf("XER   : 0x%08" PRIx64 "\n", regs->xer);
 
 	printf("GPRS  :\n");
 	for (i = 0; i < 32; i++) {
-		thread_getgpr(thread, i, &regs->gprs[i]);
+		thread_getgpr(target, i, &regs->gprs[i]);
 		printf(" 0x%016" PRIx64 "", regs->gprs[i]);
 		if (i % 4 == 3)
 			printf("\n");
 	}
 
-	thread_getspr(thread, 318, &regs->lpcr);
+	thread_getspr(target, 318, &regs->lpcr);
 	printf("LPCR  : 0x%016" PRIx64 "\n", regs->lpcr);
 
-	thread_getspr(thread, 464, &regs->ptcr);
+	thread_getspr(target, 464, &regs->ptcr);
 	printf("PTCR  : 0x%016" PRIx64 "\n", regs->ptcr);
 
-	thread_getspr(thread, 319, &regs->lpidr);
+	thread_getspr(target, 319, &regs->lpidr);
 	printf("LPIDR : 0x%016" PRIx64 "\n", regs->lpidr);
 
-	thread_getspr(thread, 48, &regs->pidr);
+	thread_getspr(target, 48, &regs->pidr);
 	printf("PIDR  : 0x%016" PRIx64 "\n", regs->pidr);
 
-	thread_getspr(thread, 190, &regs->hfscr);
+	thread_getspr(target, 190, &regs->hfscr);
 	printf("HFSCR : 0x%016" PRIx64 "\n", regs->hfscr);
 
-	thread_getspr(thread, 306, &value);
+	thread_getspr(target, 306, &value);
 	regs->hdsisr = value;
 	printf("HDSISR: 0x%08" PRIx32 "\n", regs->hdsisr);
 
-	thread_getspr(thread, 307, &regs->hdar);
+	thread_getspr(target, 307, &regs->hdar);
 	printf("HDAR  : 0x%016" PRIx64 "\n", regs->hdar);
 
-	thread_getspr(thread, 339, &value);
+	thread_getspr(target, 339, &value);
 	regs->heir = value;
 	printf("HEIR : 0x%016" PRIx32 "\n", regs->heir);
 
-	thread_getspr(thread, 1008, &regs->hid);
+	thread_getspr(target, 1008, &regs->hid);
 	printf("HID0 : 0x%016" PRIx64 "\n", regs->hid);
 
-	thread_getspr(thread, 314, &regs->hsrr0);
+	thread_getspr(target, 314, &regs->hsrr0);
 	printf("HSRR0 : 0x%016" PRIx64 "\n", regs->hsrr0);
 
-	thread_getspr(thread, 315, &regs->hsrr1);
+	thread_getspr(target, 315, &regs->hsrr1);
 	printf("HSRR1 : 0x%016" PRIx64 "\n", regs->hsrr1);
 
-	thread_getspr(thread, 310, &regs->hdec);
+	thread_getspr(target, 310, &regs->hdec);
 	printf("HDEC  : 0x%016" PRIx64 "\n", regs->hdec);
 
-	thread_getspr(thread, 304, &regs->hsprg0);
+	thread_getspr(target, 304, &regs->hsprg0);
 	printf("HSPRG0: 0x%016" PRIx64 "\n", regs->hsprg0);
 
-	thread_getspr(thread, 305, &regs->hsprg1);
+	thread_getspr(target, 305, &regs->hsprg1);
 	printf("HSPRG1: 0x%016" PRIx64 "\n", regs->hsprg1);
 
-	thread_getspr(thread, 153, &regs->fscr);
+	thread_getspr(target, 153, &regs->fscr);
 	printf("FSCR  : 0x%016" PRIx64 "\n", regs->fscr);
 
-	thread_getspr(thread, 18, &value);
+	thread_getspr(target, 18, &value);
 	regs->dsisr = value;
 	printf("DSISR : 0x%08" PRIx32 "\n", regs->dsisr);
 
-	thread_getspr(thread, 19, &regs->dar);
+	thread_getspr(target, 19, &regs->dar);
 	printf("DAR   : 0x%016" PRIx64 "\n", regs->dar);
 
-	thread_getspr(thread, 26, &regs->srr0);
+	thread_getspr(target, 26, &regs->srr0);
 	printf("SRR0  : 0x%016" PRIx64 "\n", regs->srr0);
 
-	thread_getspr(thread, 27, &regs->srr1);
+	thread_getspr(target, 27, &regs->srr1);
 	printf("SRR1  : 0x%016" PRIx64 "\n", regs->srr1);
 
-	thread_getspr(thread, 22, &regs->dec);
+	thread_getspr(target, 22, &regs->dec);
 	printf("DEC   : 0x%016" PRIx64 "\n", regs->dec);
 
-	thread_getspr(thread, 268, &regs->tb);
+	thread_getspr(target, 268, &regs->tb);
 	printf("TB    : 0x%016" PRIx64 "\n", regs->tb);
 
-	thread_getspr(thread, 272, &regs->sprg0);
+	thread_getspr(target, 272, &regs->sprg0);
 	printf("SPRG0 : 0x%016" PRIx64 "\n", regs->sprg0);
 
-	thread_getspr(thread, 273, &regs->sprg1);
+	thread_getspr(target, 273, &regs->sprg1);
 	printf("SPRG1 : 0x%016" PRIx64 "\n", regs->sprg1);
 
-	thread_getspr(thread, 274, &regs->sprg2);
+	thread_getspr(target, 274, &regs->sprg2);
 	printf("SPRG2 : 0x%016" PRIx64 "\n", regs->sprg2);
 
-	thread_getspr(thread, 275, &regs->sprg3);
+	thread_getspr(target, 275, &regs->sprg3);
 	printf("SPRG3 : 0x%016" PRIx64 "\n", regs->sprg3);
 
-	thread_getspr(thread, 896, &regs->ppr);
+	thread_getspr(target, 896, &regs->ppr);
 	printf("PPR   : 0x%016" PRIx64 "\n", regs->ppr);
 
-	CHECK_ERR(t->ram_destroy(t));
+	CHECK_ERR(thread->ram_destroy(thread));
 
 	return 0;
 }