This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: Kernel API for PS application?
- From: Andrew Lunn <andrew dot lunn at ascom dot ch>
- To: jyl087 at netscape dot net
- Cc: eCos Discussion <ecos-discuss at sources dot redhat dot com>
- Date: Thu, 5 Sep 2002 09:20:26 +0200
- Subject: Re: [ECOS] Kernel API for PS application?
- References: <2D5E5EF0.2D81761A.00067016@netscape.net>
> I'd like to write a simple "ps" (process status) type
> application which will allow me to dump thread info
> to the console at will, without firing up GDB. This
> info would include thread status (e.g. SLEEPING, RUNNING...)
> stack address, etc...
We only use this under fatal conditions, but i think its safe to use
at other times.
Andrew
#include <cyg/kernel/kapi.h>
#include <pkgconf/kernel.h>
#include <pkgconf/hal.h>
#include <cyg/hal/dbg-threads-api.h>
#include "dbgprint.h"
#include "dump_threads.h"
#include "dump_threads_hw_api.h"
#include "cygwatchdog.h"
/* Walk the list of threads and print the info for each.
We call into the HW dependant code to print the info about
each thread.*/
#ifndef linux
void dump_threads(void) {
threadref lastthreadid;
threadref next_thread;
cyg_scheduler_lock();
if (!dbg_threadlist(1,NULL,&next_thread)) {
printf("No Threads!\n");
return;
}
print_thread(&next_thread);
memcpy(lastthreadid,next_thread,sizeof(lastthreadid));
while (dbg_threadlist(0,&lastthreadid,&next_thread)) {
print_thread(&next_thread);
memcpy(lastthreadid,next_thread,sizeof(lastthreadid));
cygwatchdog_reset();
}
dump_stack();
cyg_scheduler_unlock();
}
#else
void dump_threads(void) {
}
#endif
The next bit is processor dependent. Each have different numbers of
registers and names etc. This is for the ARM.
#include <cyg/kernel/kapi.h>
#include <pkgconf/kernel.h>
#include <pkgconf/hal.h>
#include <cyg/hal/dbg-threads-api.h>
#include "dbgprint.h"
#include "dump_threads.h"
#include "dump_threads_hw_api.h"
#define NUMREGS 25
#define NUM_REG_PC 15
extern int _etext;
/* Print the info for one thread */
void print_thread(threadref * thread) {
struct cygmon_thread_debug_info info;
CYG_ADDRWORD regs[NUMREGS];
if (!dbg_threadinfo(thread,&info)) {
printf("Thread disappeared!\n");
}
printf("%25s %25s ",
(info.unique_thread_name ? info.unique_thread_name : "Anonymous"),
info.thread_display);
if (dbg_getthreadreg(thread,NUMREGS,®s)) {
printf("PC: %8x ",regs[NUM_REG_PC]);
}
/* Yes, this is ugly, but we have to peek around in threadref's
* internal data to get the thread's address. If USE_ID is not
* defined in <ecos>/packages/kernel/current/src/debug/dbg_gdb.cxx,
* [0] has to be changed to [1] below. */
printf(" th: %8lx\n", ((unsigned long *)thread)[0]);
}
/* Dump the last 80 words on the stack. It can be hard to interpret,
but useful*/
void dump_stack(void) {
unsigned int * address;
int c,d;
address = (unsigned int *)((char *)&address - (char *)(80*4));
for (c=0 ; c < 16 ; c++ ) {
printf("%8p: ",(void *)address);
for (d=0; d < 5; d++) {
printf("0x%08x",*address);
printf("%c ",((*address < (int)&_etext) && ((*address % 4) == 0))
? '*' : ' ');
address++;
}
printf("\n");
}
}
On Wed, Sep 04, 2002 at 12:28:04PM -0400, jyl087@netscape.net wrote:
> I'd like to write a simple "ps" (process status) type
> application which will allow me to dump thread info
> to the console at will, without firing up GDB. This
> info would include thread status (e.g. SLEEPING, RUNNING...)
> stack address, etc...
>
> Has anyone done this before (and be willing to share the
> source?) If not, what's the best place to go looking for
> the proper hooks into the kernel for this info? Eventually,
> I'd like to do a "top" kind of routine also, which will
> show CPU utilization... but that'll be for another day...
>
> /Jim
>
>
>
>
> __________________________________________________________________
> The NEW Netscape 7.0 browser is now available. Upgrade now! http://channels.netscape.com/ns/browsers/download.jsp
>
> Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/
>
> --
> Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
> and search the list archive: http://sources.redhat.com/ml/ecos-discuss
>
--
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss