source: rtems-libbsd/rtemsbsd/rtems/rtems-bsd-shell.c @ ab415f9

4.115-freebsd-12freebsd-9.3
Last change on this file since ab415f9 was ab415f9, checked in by Sebastian Huber <sebastian.huber@…>, on Oct 9, 2013 at 6:56:49 AM

Use extension to attach a struct thread to threads

Add test thread01.

  • Property mode set to 100644
File size: 4.2 KB
Line 
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-config.h>
41#include <machine/rtems-bsd-thread.h>
42
43#include <rtems/bsd/sys/param.h>
44#include <rtems/bsd/sys/types.h>
45#include <sys/systm.h>
46#include <rtems/bsd/sys/lock.h>
47#include <sys/mutex.h>
48#include <sys/callout.h>
49#include <sys/condvar.h>
50#include <sys/proc.h>
51
52#include <rtems/bsd/bsd.h>
53#include <rtems/shell.h>
54
55static void
56rtems_bsd_dump_mtx(void)
57{
58        rtems_chain_control *chain = &rtems_bsd_mtx_chain;
59        rtems_chain_node *node = rtems_chain_first(chain);
60
61        printf("mtx dump:\n");
62
63        while (!rtems_chain_is_tail(chain, node)) {
64                struct lock_object *lo = (struct lock_object *) node;
65
66                printf("\t%s: 0x%08x\n", lo->lo_name, lo->lo_id);
67
68                node = rtems_chain_next(node);
69        }
70}
71
72static void
73rtems_bsd_dump_sx(void)
74{
75        rtems_chain_control *chain = &rtems_bsd_sx_chain;
76        rtems_chain_node *node = rtems_chain_first(chain);
77
78        printf("sx dump:\n");
79
80        while (!rtems_chain_is_tail(chain, node)) {
81                struct lock_object *lo = (struct lock_object *) node;
82
83                printf("\t%s: 0x%08x\n", lo->lo_name, lo->lo_id);
84
85                node = rtems_chain_next(node);
86        }
87}
88
89static void
90rtems_bsd_dump_condvar(void)
91{
92        rtems_chain_control *chain = &rtems_bsd_condvar_chain;
93        rtems_chain_node *node = rtems_chain_first(chain);
94
95        printf("condvar dump:\n");
96
97        while (!rtems_chain_is_tail(chain, node)) {
98                struct cv *cv = (struct cv *) node;
99
100                printf("\t%s: 0x%08x\n", cv->cv_description, cv->cv_id);
101
102                node = rtems_chain_next(node);
103        }
104}
105
106static void
107rtems_bsd_dump_thread(void)
108{
109        const rtems_chain_control *chain = &rtems_bsd_thread_chain;
110        const rtems_chain_node *node = rtems_chain_immutable_first(chain);
111
112        printf("thread dump:\n");
113
114        while (!rtems_chain_is_tail(chain, node)) {
115                const struct thread *td = (const struct thread *) node;
116
117                printf("\t%s: 0x%08x\n", td->td_name, rtems_bsd_get_task_id(td));
118
119                node = rtems_chain_immutable_next(node);
120        }
121}
122
123static const char rtems_bsd_usage [] =
124        "bsd {all|mtx|sx|condvar|thread|callout}";
125
126#define CMP(s) all || strcasecmp(argv [1], s) == 0
127
128static int
129rtems_bsd_info(int argc, char **argv)
130{
131        bool usage = true;
132
133        if (argc == 2) {
134                bool all = false;
135
136                if (CMP("all")) {
137                        all = true;
138                }
139
140                if (CMP("mtx")) {
141                        rtems_bsd_dump_mtx();
142                        usage = false;
143                }
144                if (CMP("sx")) {
145                        rtems_bsd_dump_sx();
146                        usage = false;
147                }
148                if (CMP("condvar")) {
149                        rtems_bsd_dump_condvar();
150                        usage = false;
151                }
152                if (CMP("thread")) {
153                        rtems_bsd_dump_thread();
154                        usage = false;
155                }
156        }
157
158        if (usage) {
159                puts(rtems_bsd_usage);
160        }
161
162        return 0;
163}
164
165static rtems_shell_cmd_t rtems_bsd_info_command = {
166        .name = "bsd",
167        .usage = rtems_bsd_usage,
168        .topic = "bsp",
169        .command = rtems_bsd_info,
170        .alias = NULL,
171        .next = NULL
172};
173
174void
175rtems_bsd_shell_initialize(void)
176{
177        rtems_shell_add_cmd_struct(&rtems_bsd_info_command);
178}
Note: See TracBrowser for help on using the repository browser.