linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Add xmon command to dump process/task similar to ps(1)
  2015-11-18 18:55 Douglas Miller
@ 2015-11-18 18:55 ` Douglas Miller
  0 siblings, 0 replies; 4+ messages in thread
From: Douglas Miller @ 2015-11-18 18:55 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Douglas Miller

---
 arch/powerpc/xmon/xmon.c |   58 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 58 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index 13c6e20..5c24f55 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -149,6 +149,7 @@ static int  cpu_cmd(void);
 static void csum(void);
 static void bootcmds(void);
 static void proccall(void);
+static void proclist(void);
 void dump_segments(void);
 static void symbol_lookup(void);
 static void xmon_show_stack(unsigned long sp, unsigned long lr,
@@ -191,6 +192,24 @@ extern void xmon_leave(void);
 			 || ('A' <= (c) && (c) <= 'Z'))
 #define isspace(c)	(c == ' ' || c == '\t' || c == 10 || c == 13 || c == 0)
 
+/*
+ * Wrap a statement (typically function call) in setjmp to
+ * protect it from memory access errors. msg... are printf
+ * fmt+args used if error is trapped.
+ */
+#define XMON_PROTECT(stmt, msg...) 		\
+	if (setjmp(bus_error_jmp) != 0) {	\
+		catch_memory_errors = 0;	\
+		printf(msg);			\
+	} else {				\
+		catch_memory_errors = 1;	\
+		sync();				\
+		stmt;				\
+		sync();				\
+		__delay(200);			\
+		catch_memory_errors = 0;	\
+	}
+
 static char *help_string = "\
 Commands:\n\
   b	show breakpoints\n\
@@ -228,6 +247,7 @@ Commands:\n\
   mz	zero a block of memory\n\
   mi	show information about memory allocation\n\
   p 	call a procedure\n\
+  P 	list processes/tasks\n\
   r	print registers\n\
   s	single step\n"
 #ifdef CONFIG_SPU_BASE
@@ -947,6 +967,9 @@ cmds(struct pt_regs *excp)
 		case 'p':
 			proccall();
 			break;
+		case 'P':
+			proclist();
+			break;
 #ifdef CONFIG_PPC_STD_MMU
 		case 'u':
 			dump_segments();
@@ -2450,6 +2473,41 @@ memzcan(void)
 		printf("%.8x\n", a - mskip);
 }
 
+static void procshow(struct task_struct *tsk)
+{
+	char state;
+
+	state = (tsk->state == 0) ? 'R' :
+		(tsk->state < 0) ? 'U' :
+		(tsk->state & TASK_UNINTERRUPTIBLE) ? 'D' :
+		(tsk->state & TASK_STOPPED) ? 'T' :
+		(tsk->state & TASK_TRACED) ? 'C' :
+		(tsk->exit_state & EXIT_ZOMBIE) ? 'Z' :
+		(tsk->exit_state & EXIT_DEAD) ? 'E' :
+		(tsk->state & TASK_INTERRUPTIBLE) ? 'S' : '?';
+
+	printf("%p %016lx %6d %6d %c %2d %s\n", tsk,
+		tsk->thread.ksp,
+		tsk->pid, tsk->parent->pid,
+		state, task_thread_info(tsk)->cpu,
+		tsk->comm);
+}
+
+static void proclist(void)
+{
+	unsigned long tskv;
+	struct task_struct *tsk;
+
+	if (scanhex(&tskv)) {
+		tsk = (struct task_struct *)tskv;
+		XMON_PROTECT(procshow(tsk), "*** Error dumping task %p\n", tsk);
+	} else {
+		for_each_process(tsk) {
+			XMON_PROTECT(procshow(tsk), "*** Error dumping task %p\n", tsk);
+		}
+	}
+}
+
 static void proccall(void)
 {
 	unsigned long args[8];
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* RESEND: Add xmon command to dump process/task similar to ps(1)
@ 2015-11-19 12:31 Douglas Miller
  2015-11-19 12:31 ` [PATCH] " Douglas Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Douglas Miller @ 2015-11-19 12:31 UTC (permalink / raw)
  To: linuxppc-dev

Resending with Signed-Off line.

Request for comments

Add a command to xmon that prints basic task information like
ps(1) but includes the kernel stack pointer for use with 't'
(traceback) command.

Adds a macro to be used to wrap memory access with setjmp code
to protect against memory faults.

Is additional locking required? Any other concerns?

Thanks,
Doug

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] Add xmon command to dump process/task similar to ps(1)
  2015-11-19 12:31 RESEND: Add xmon command to dump process/task similar to ps(1) Douglas Miller
@ 2015-11-19 12:31 ` Douglas Miller
  2015-11-23  0:28   ` Michael Ellerman
  0 siblings, 1 reply; 4+ messages in thread
From: Douglas Miller @ 2015-11-19 12:31 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Douglas Miller

Signed-off-by: Douglas Miller <dougmill@linux.vnet.ibm.com>
---
 arch/powerpc/xmon/xmon.c |   58 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 58 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index 13c6e20..5c24f55 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -149,6 +149,7 @@ static int  cpu_cmd(void);
 static void csum(void);
 static void bootcmds(void);
 static void proccall(void);
+static void proclist(void);
 void dump_segments(void);
 static void symbol_lookup(void);
 static void xmon_show_stack(unsigned long sp, unsigned long lr,
@@ -191,6 +192,24 @@ extern void xmon_leave(void);
 			 || ('A' <= (c) && (c) <= 'Z'))
 #define isspace(c)	(c == ' ' || c == '\t' || c == 10 || c == 13 || c == 0)
 
+/*
+ * Wrap a statement (typically function call) in setjmp to
+ * protect it from memory access errors. msg... are printf
+ * fmt+args used if error is trapped.
+ */
+#define XMON_PROTECT(stmt, msg...) 		\
+	if (setjmp(bus_error_jmp) != 0) {	\
+		catch_memory_errors = 0;	\
+		printf(msg);			\
+	} else {				\
+		catch_memory_errors = 1;	\
+		sync();				\
+		stmt;				\
+		sync();				\
+		__delay(200);			\
+		catch_memory_errors = 0;	\
+	}
+
 static char *help_string = "\
 Commands:\n\
   b	show breakpoints\n\
@@ -228,6 +247,7 @@ Commands:\n\
   mz	zero a block of memory\n\
   mi	show information about memory allocation\n\
   p 	call a procedure\n\
+  P 	list processes/tasks\n\
   r	print registers\n\
   s	single step\n"
 #ifdef CONFIG_SPU_BASE
@@ -947,6 +967,9 @@ cmds(struct pt_regs *excp)
 		case 'p':
 			proccall();
 			break;
+		case 'P':
+			proclist();
+			break;
 #ifdef CONFIG_PPC_STD_MMU
 		case 'u':
 			dump_segments();
@@ -2450,6 +2473,41 @@ memzcan(void)
 		printf("%.8x\n", a - mskip);
 }
 
+static void procshow(struct task_struct *tsk)
+{
+	char state;
+
+	state = (tsk->state == 0) ? 'R' :
+		(tsk->state < 0) ? 'U' :
+		(tsk->state & TASK_UNINTERRUPTIBLE) ? 'D' :
+		(tsk->state & TASK_STOPPED) ? 'T' :
+		(tsk->state & TASK_TRACED) ? 'C' :
+		(tsk->exit_state & EXIT_ZOMBIE) ? 'Z' :
+		(tsk->exit_state & EXIT_DEAD) ? 'E' :
+		(tsk->state & TASK_INTERRUPTIBLE) ? 'S' : '?';
+
+	printf("%p %016lx %6d %6d %c %2d %s\n", tsk,
+		tsk->thread.ksp,
+		tsk->pid, tsk->parent->pid,
+		state, task_thread_info(tsk)->cpu,
+		tsk->comm);
+}
+
+static void proclist(void)
+{
+	unsigned long tskv;
+	struct task_struct *tsk;
+
+	if (scanhex(&tskv)) {
+		tsk = (struct task_struct *)tskv;
+		XMON_PROTECT(procshow(tsk), "*** Error dumping task %p\n", tsk);
+	} else {
+		for_each_process(tsk) {
+			XMON_PROTECT(procshow(tsk), "*** Error dumping task %p\n", tsk);
+		}
+	}
+}
+
 static void proccall(void)
 {
 	unsigned long args[8];
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Add xmon command to dump process/task similar to ps(1)
  2015-11-19 12:31 ` [PATCH] " Douglas Miller
@ 2015-11-23  0:28   ` Michael Ellerman
  0 siblings, 0 replies; 4+ messages in thread
From: Michael Ellerman @ 2015-11-23  0:28 UTC (permalink / raw)
  To: Douglas Miller, linuxppc-dev

Hi Doug,

Your subject should be something more like:

"powerpc/xmon: Add command to dump process/task similar to ps(1)"

On Thu, 2015-11-19 at 06:31 -0600, Douglas Miller wrote:
>

And you need to write a change log. It doesn't have to be an opus, but there
should be something here.

eg. Where did you get the mapping of the state to the letters, and does it
match the generic code?

> diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
> index 13c6e20..5c24f55 100644
> --- a/arch/powerpc/xmon/xmon.c
> +++ b/arch/powerpc/xmon/xmon.c
> @@ -2450,6 +2473,41 @@ memzcan(void)
>  		printf("%.8x\n", a - mskip);
>  }
>  
> +static void procshow(struct task_struct *tsk)
> +{
> +	char state;
> +
> +	state = (tsk->state == 0) ? 'R' :
> +		(tsk->state < 0) ? 'U' :
> +		(tsk->state & TASK_UNINTERRUPTIBLE) ? 'D' :
> +		(tsk->state & TASK_STOPPED) ? 'T' :
> +		(tsk->state & TASK_TRACED) ? 'C' :
> +		(tsk->exit_state & EXIT_ZOMBIE) ? 'Z' :
> +		(tsk->exit_state & EXIT_DEAD) ? 'E' :
> +		(tsk->state & TASK_INTERRUPTIBLE) ? 'S' : '?';
> +
> +	printf("%p %016lx %6d %6d %c %2d %s\n", tsk,
> +		tsk->thread.ksp,
> +		tsk->pid, tsk->parent->pid,
> +		state, task_thread_info(tsk)->cpu,
> +		tsk->comm);
> +}
> +
> +static void proclist(void)
> +{
> +	unsigned long tskv;
> +	struct task_struct *tsk;
> +
> +	if (scanhex(&tskv)) {
> +		tsk = (struct task_struct *)tskv;
> +		XMON_PROTECT(procshow(tsk), "*** Error dumping task %p\n", tsk);
> +	} else {
> +		for_each_process(tsk) {
> +			XMON_PROTECT(procshow(tsk), "*** Error dumping task %p\n", tsk);
> +		}

You should be wrapping the for_each_process() loop in the PROTECT macro as well
as the call to procshow(). There are pointer dereferences in the for each macro
that could fault if you have a corrupted task list.

cheers

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-11-23  0:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-19 12:31 RESEND: Add xmon command to dump process/task similar to ps(1) Douglas Miller
2015-11-19 12:31 ` [PATCH] " Douglas Miller
2015-11-23  0:28   ` Michael Ellerman
  -- strict thread matches above, loose matches on Subject: below --
2015-11-18 18:55 Douglas Miller
2015-11-18 18:55 ` [PATCH] " Douglas Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).