1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup rtems_bsd_rtems |
---|
5 | * |
---|
6 | * @brief TODO. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (c) 2009-2014 embedded brains GmbH. All rights reserved. |
---|
11 | * |
---|
12 | * embedded brains GmbH |
---|
13 | * Dornierstr. 4 |
---|
14 | * 82178 Puchheim |
---|
15 | * Germany |
---|
16 | * <rtems@embedded-brains.de> |
---|
17 | * |
---|
18 | * Redistribution and use in source and binary forms, with or without |
---|
19 | * modification, are permitted provided that the following conditions |
---|
20 | * are met: |
---|
21 | * 1. Redistributions of source code must retain the above copyright |
---|
22 | * notice, this list of conditions and the following disclaimer. |
---|
23 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
24 | * notice, this list of conditions and the following disclaimer in the |
---|
25 | * documentation and/or other materials provided with the distribution. |
---|
26 | * |
---|
27 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
---|
28 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
30 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
---|
31 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
33 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
34 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
35 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
36 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
37 | * SUCH DAMAGE. |
---|
38 | */ |
---|
39 | |
---|
40 | #include <machine/rtems-bsd-kernel-space.h> |
---|
41 | #include <machine/rtems-bsd-thread.h> |
---|
42 | #include <machine/rtems-bsd-support.h> |
---|
43 | |
---|
44 | #include <rtems/bsd/sys/param.h> |
---|
45 | #include <sys/types.h> |
---|
46 | #include <sys/systm.h> |
---|
47 | #include <sys/proc.h> |
---|
48 | |
---|
49 | #include <inttypes.h> |
---|
50 | |
---|
51 | #include <rtems/netcmds-config.h> |
---|
52 | |
---|
53 | static void |
---|
54 | rtems_bsd_dump_thread(Thread_Control *thread) |
---|
55 | { |
---|
56 | const struct thread *td = rtems_bsd_get_thread(thread); |
---|
57 | |
---|
58 | if (td != NULL) { |
---|
59 | char buf[5]; |
---|
60 | const char *name = td->td_name; |
---|
61 | |
---|
62 | if (name == NULL || name[0] == '\0') { |
---|
63 | rtems_object_get_name(thread->Object.id, sizeof(buf), &buf[0]); |
---|
64 | name = &buf[0]; |
---|
65 | } |
---|
66 | |
---|
67 | fprintf( |
---|
68 | stdout, |
---|
69 | " 0x%08" PRIx32 " | %8" PRIu32 " | %s\n", |
---|
70 | thread->Object.id, |
---|
71 | thread->current_priority, |
---|
72 | name |
---|
73 | ); |
---|
74 | } |
---|
75 | } |
---|
76 | |
---|
77 | static void |
---|
78 | rtems_bsd_dump_threads(void) |
---|
79 | { |
---|
80 | fprintf( |
---|
81 | stdout, |
---|
82 | "-------------------------------------------------------------------------------\n" |
---|
83 | " BSD THREADS\n" |
---|
84 | "------------+----------+-------------------------------------------------------\n" |
---|
85 | " ID | PRIORITY | NAME\n" |
---|
86 | "------------+----------+-------------------------------------------------------\n" |
---|
87 | ); |
---|
88 | |
---|
89 | rtems_iterate_over_all_threads(rtems_bsd_dump_thread); |
---|
90 | |
---|
91 | fprintf( |
---|
92 | stdout, |
---|
93 | "------------+----------+-------------------------------------------------------\n" |
---|
94 | ); |
---|
95 | } |
---|
96 | |
---|
97 | static const char rtems_bsd_usage[] = "bsd"; |
---|
98 | |
---|
99 | #define CMP(s) all || strcasecmp(argv [1], s) == 0 |
---|
100 | |
---|
101 | static int |
---|
102 | rtems_bsd_info(int argc, char **argv) |
---|
103 | { |
---|
104 | rtems_bsd_dump_threads(); |
---|
105 | |
---|
106 | return 0; |
---|
107 | } |
---|
108 | |
---|
109 | rtems_shell_cmd_t rtems_shell_BSD_Command = { |
---|
110 | .name = "bsd", |
---|
111 | .usage = &rtems_bsd_usage[0], |
---|
112 | .topic = "bsp", |
---|
113 | .command = rtems_bsd_info, |
---|
114 | .alias = NULL, |
---|
115 | .next = NULL |
---|
116 | }; |
---|