1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup rtems_bsd_rtems |
---|
5 | * |
---|
6 | * @brief TODO. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (c) 2009-2013 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 <rtems/bsd/sys/types.h> |
---|
46 | #include <sys/systm.h> |
---|
47 | #include <sys/proc.h> |
---|
48 | |
---|
49 | #include <rtems/bsd/bsd.h> |
---|
50 | #include <rtems/shell.h> |
---|
51 | |
---|
52 | static void |
---|
53 | rtems_bsd_dump_thread(void) |
---|
54 | { |
---|
55 | const rtems_chain_control *chain = &rtems_bsd_thread_chain; |
---|
56 | const rtems_chain_node *node = rtems_chain_immutable_first(chain); |
---|
57 | |
---|
58 | printf("thread dump:\n"); |
---|
59 | |
---|
60 | while (!rtems_chain_is_tail(chain, node)) { |
---|
61 | const struct thread *td = (const struct thread *) node; |
---|
62 | |
---|
63 | printf("\t%s: 0x%08x\n", td->td_name, rtems_bsd_get_task_id(td)); |
---|
64 | |
---|
65 | node = rtems_chain_immutable_next(node); |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | static const char rtems_bsd_usage [] = |
---|
70 | "bsd {all|condvar|thread|callout}"; |
---|
71 | |
---|
72 | #define CMP(s) all || strcasecmp(argv [1], s) == 0 |
---|
73 | |
---|
74 | static int |
---|
75 | rtems_bsd_info(int argc, char **argv) |
---|
76 | { |
---|
77 | bool usage = true; |
---|
78 | |
---|
79 | if (argc == 2) { |
---|
80 | bool all = false; |
---|
81 | |
---|
82 | if (CMP("all")) { |
---|
83 | all = true; |
---|
84 | } |
---|
85 | |
---|
86 | if (CMP("thread")) { |
---|
87 | rtems_bsd_dump_thread(); |
---|
88 | usage = false; |
---|
89 | } |
---|
90 | } |
---|
91 | |
---|
92 | if (usage) { |
---|
93 | puts(rtems_bsd_usage); |
---|
94 | } |
---|
95 | |
---|
96 | return 0; |
---|
97 | } |
---|
98 | |
---|
99 | static rtems_shell_cmd_t rtems_bsd_info_command = { |
---|
100 | .name = "bsd", |
---|
101 | .usage = rtems_bsd_usage, |
---|
102 | .topic = "bsp", |
---|
103 | .command = rtems_bsd_info, |
---|
104 | .alias = NULL, |
---|
105 | .next = NULL |
---|
106 | }; |
---|
107 | |
---|
108 | void |
---|
109 | rtems_bsd_shell_initialize(void) |
---|
110 | { |
---|
111 | rtems_shell_add_cmd_struct(&rtems_bsd_info_command); |
---|
112 | } |
---|