diff mbox series

src/thread.c: Don't print uninitialised thread status

Message ID 20180813083943.29068-1-alistair@popple.id.au
State Accepted
Headers show
Series src/thread.c: Don't print uninitialised thread status | expand

Checks

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

Commit Message

Alistair Popple Aug. 13, 2018, 8:39 a.m. UTC
Depending on the selection flags passed to pdbg not all threads will be
selected. This was leading to random uninitialised values being used to print
thread status for unselected threads. Instead nothing should be printed for
those threads.

Signed-off-by: Alistair Popple <alistair@popple.id.au>
---
 src/thread.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Nicholas Piggin Aug. 13, 2018, 2:43 p.m. UTC | #1
On Mon, 13 Aug 2018 18:39:43 +1000
Alistair Popple <alistair@popple.id.au> wrote:

> Depending on the selection flags passed to pdbg not all threads will be
> selected. This was leading to random uninitialised values being used to print
> thread status for unselected threads. Instead nothing should be printed for
> those threads.
> 
> Signed-off-by: Alistair Popple <alistair@popple.id.au>

Acked-by: Nicholas Piggin <npiggin@gmail.com>

> ---
>  src/thread.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/src/thread.c b/src/thread.c
> index 4b95636..d282307 100644
> --- a/src/thread.c
> +++ b/src/thread.c
> @@ -23,24 +23,30 @@
>  #include "main.h"
>  #include "optcmd.h"
>  
> -static int print_thread_status(struct pdbg_target *target, uint32_t index, uint64_t *arg, uint64_t *unused1)
> +static int print_thread_status(struct pdbg_target *target, uint32_t index, uint64_t *arg, uint64_t *valid)
>  {
>  	struct thread_state *status = (struct thread_state *) arg;
>  
>  	status[index] = thread_status(target);
> +	valid[index] = true;
>  	return 1;
>  }
>  
>  static int print_core_thread_status(struct pdbg_target *core_target, uint32_t index, uint64_t *maxindex, uint64_t *unused1)
>  {
>  	struct thread_state status[8];
> +	uint64_t valid[8] = {0};
>  	int i, rc;
>  
>  	printf("c%02d:  ", index);
>  
>  	/* TODO: This cast is gross. Need to rewrite for_each_child_target as an iterator. */
> -	rc = for_each_child_target("thread", core_target, print_thread_status, (uint64_t *) &status[0], NULL);
> +	rc = for_each_child_target("thread", core_target, print_thread_status, (uint64_t *) &status[0], &valid[0]);
>  	for (i = 0; i <= *maxindex; i++) {
> +		if (!valid[i]) {
> +			printf("    ");
> +			continue;
> +		}
>  
>  		if (status[i].active)
>  			printf("A");
diff mbox series

Patch

diff --git a/src/thread.c b/src/thread.c
index 4b95636..d282307 100644
--- a/src/thread.c
+++ b/src/thread.c
@@ -23,24 +23,30 @@ 
 #include "main.h"
 #include "optcmd.h"
 
-static int print_thread_status(struct pdbg_target *target, uint32_t index, uint64_t *arg, uint64_t *unused1)
+static int print_thread_status(struct pdbg_target *target, uint32_t index, uint64_t *arg, uint64_t *valid)
 {
 	struct thread_state *status = (struct thread_state *) arg;
 
 	status[index] = thread_status(target);
+	valid[index] = true;
 	return 1;
 }
 
 static int print_core_thread_status(struct pdbg_target *core_target, uint32_t index, uint64_t *maxindex, uint64_t *unused1)
 {
 	struct thread_state status[8];
+	uint64_t valid[8] = {0};
 	int i, rc;
 
 	printf("c%02d:  ", index);
 
 	/* TODO: This cast is gross. Need to rewrite for_each_child_target as an iterator. */
-	rc = for_each_child_target("thread", core_target, print_thread_status, (uint64_t *) &status[0], NULL);
+	rc = for_each_child_target("thread", core_target, print_thread_status, (uint64_t *) &status[0], &valid[0]);
 	for (i = 0; i <= *maxindex; i++) {
+		if (!valid[i]) {
+			printf("    ");
+			continue;
+		}
 
 		if (status[i].active)
 			printf("A");