source: rtems/cpukit/libmisc/monitor/mon-object.c @ 3e08d4e

4.104.114.84.95
Last change on this file since 3e08d4e was 3e08d4e, checked in by Ralf Corsepius <ralf.corsepius@…>, on 03/26/04 at 06:59:18

2004-03-26 Ralf Corsepius <ralf_corsepius@…>

  • libmisc/capture/capture-cli.c, libmisc/capture/capture.c, libmisc/capture/capture.h, libmisc/cpuuse/cpuuse.c, libmisc/devnull/devnull.c, libmisc/fsmount/fsmount.h, libmisc/monitor/mon-config.c, libmisc/monitor/mon-dname.c, libmisc/monitor/mon-driver.c, libmisc/monitor/mon-extension.c, libmisc/monitor/mon-itask.c, libmisc/monitor/mon-monitor.c, libmisc/monitor/mon-mpci.c, libmisc/monitor/mon-object.c, libmisc/monitor/mon-prmisc.c, libmisc/monitor/mon-queue.c, libmisc/monitor/mon-server.c, libmisc/monitor/mon-symbols.c, libmisc/monitor/monitor.h, libmisc/monitor/symbols.h, libmisc/mw-fb/mw_uid.c, libmisc/rtmonuse/rtmonuse.c, libmisc/serdbg/serdbg.h, libmisc/serdbg/serdbgio.c, libmisc/serdbg/termios_printk.c, libmisc/serdbg/termios_printk.h, libmisc/shell/shell.c, libmisc/shell/shell.h, libmisc/stackchk/check.c, libmisc/stackchk/internal.h: Convert to using c99 fixed size types.
  • Property mode set to 100644
File size: 11.2 KB
Line 
1/*
2 * RTEMS Monitor "object" support.
3 *
4 * Used to traverse object lists and print them out.
5 * An object can be an RTEMS object (chain based stuff) or
6 * a "misc" object such as a device driver.
7 *
8 * Each object has its own file in this directory (eg: extension.c)
9 * That file provides routines to convert a "native" structure
10 * to its canonical form, print a canonical structure, etc.
11 *
12 * TODO:
13 *     should allow for non-numeric id's???
14 *
15 *  $Id$
16 */
17
18#ifdef HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
23#include <rtems.h>
24#include <rtems/monitor.h>
25
26#include <stdio.h>
27#include <stdlib.h>             /* strtoul() */
28#include <string.h>             /* memcpy() */
29
30#define NUMELEMS(arr)   (sizeof(arr) / sizeof(arr[0]))
31
32/*
33 * add:
34 *     next
35 */
36
37rtems_monitor_object_info_t rtems_monitor_object_info[] =
38{
39    { RTEMS_MONITOR_OBJECT_CONFIG,
40      (void *) 0,
41      sizeof(rtems_monitor_config_t),
42      (rtems_monitor_object_next_fn)        rtems_monitor_config_next,
43      (rtems_monitor_object_canonical_fn)   rtems_monitor_config_canonical,
44      (rtems_monitor_object_dump_header_fn) rtems_monitor_config_dump_header,
45      (rtems_monitor_object_dump_fn)        rtems_monitor_config_dump,
46    },
47    { RTEMS_MONITOR_OBJECT_MPCI,
48      (void *) 0,
49#if defined(RTEMS_MULTIPROCESSING)
50      sizeof(rtems_monitor_mpci_t),
51      (rtems_monitor_object_next_fn)        rtems_monitor_mpci_next,
52      (rtems_monitor_object_canonical_fn)   rtems_monitor_mpci_canonical,
53      (rtems_monitor_object_dump_header_fn) rtems_monitor_mpci_dump_header,
54      (rtems_monitor_object_dump_fn)        rtems_monitor_mpci_dump,
55#else
56      0,
57      (rtems_monitor_object_next_fn)        0,
58      (rtems_monitor_object_canonical_fn)   0,
59      (rtems_monitor_object_dump_header_fn) 0,
60      (rtems_monitor_object_dump_fn)        0,
61#endif
62    },
63    { RTEMS_MONITOR_OBJECT_INIT_TASK,
64      (void *) 0,
65      sizeof(rtems_monitor_init_task_t),
66      (rtems_monitor_object_next_fn)        rtems_monitor_init_task_next,
67      (rtems_monitor_object_canonical_fn)   rtems_monitor_init_task_canonical,
68      (rtems_monitor_object_dump_header_fn) rtems_monitor_init_task_dump_header,
69      (rtems_monitor_object_dump_fn)        rtems_monitor_init_task_dump,
70    },
71    { RTEMS_MONITOR_OBJECT_TASK,
72      (void *) &_RTEMS_tasks_Information,
73      sizeof(rtems_monitor_task_t),
74      (rtems_monitor_object_next_fn)        rtems_monitor_manager_next,
75      (rtems_monitor_object_canonical_fn)   rtems_monitor_task_canonical,
76      (rtems_monitor_object_dump_header_fn) rtems_monitor_task_dump_header,
77      (rtems_monitor_object_dump_fn)        rtems_monitor_task_dump,
78    },
79    { RTEMS_MONITOR_OBJECT_QUEUE,
80      (void *) &_Message_queue_Information,
81      sizeof(rtems_monitor_queue_t),
82      (rtems_monitor_object_next_fn)        rtems_monitor_manager_next,
83      (rtems_monitor_object_canonical_fn)   rtems_monitor_queue_canonical,
84      (rtems_monitor_object_dump_header_fn) rtems_monitor_queue_dump_header,
85      (rtems_monitor_object_dump_fn)        rtems_monitor_queue_dump,
86    },
87    { RTEMS_MONITOR_OBJECT_EXTENSION,
88      (void *) &_Extension_Information,
89      sizeof(rtems_monitor_extension_t),
90      (rtems_monitor_object_next_fn)        rtems_monitor_manager_next,
91      (rtems_monitor_object_canonical_fn)   rtems_monitor_extension_canonical,
92      (rtems_monitor_object_dump_header_fn) rtems_monitor_extension_dump_header,
93      (rtems_monitor_object_dump_fn)        rtems_monitor_extension_dump,
94    },
95    { RTEMS_MONITOR_OBJECT_DRIVER,
96      (void *) 0,
97      sizeof(rtems_monitor_driver_t),
98      (rtems_monitor_object_next_fn)        rtems_monitor_driver_next,
99      (rtems_monitor_object_canonical_fn)   rtems_monitor_driver_canonical,
100      (rtems_monitor_object_dump_header_fn) rtems_monitor_driver_dump_header,
101      (rtems_monitor_object_dump_fn)        rtems_monitor_driver_dump,
102    },
103    { RTEMS_MONITOR_OBJECT_DNAME,
104      /* XXX now that the driver name table is allocated from the */
105      /* XXX Workspace, this does not work */
106      (void *) 0,
107      /* (void *) _IO_Driver_name_table, */
108      sizeof(rtems_monitor_dname_t),
109      (rtems_monitor_object_next_fn)        rtems_monitor_dname_next,
110      (rtems_monitor_object_canonical_fn)   rtems_monitor_dname_canonical,
111      (rtems_monitor_object_dump_header_fn) rtems_monitor_dname_dump_header,
112      (rtems_monitor_object_dump_fn)        rtems_monitor_dname_dump,
113    },
114};
115
116/*
117 * Allow id's to be specified without the node number or
118 * type for convenience.
119 */
120
121rtems_id
122rtems_monitor_id_fixup(
123    rtems_id            id,
124    uint32_t            default_node,
125    rtems_monitor_object_type_t type
126)
127{
128    uint32_t    node;
129   
130    node = rtems_get_node(id);
131    if (node == 0)
132    {
133        if (rtems_get_class(id) != OBJECTS_NO_CLASS)
134            type = rtems_get_class(id);
135
136        id = _Objects_Build_id(
137          OBJECTS_CLASSIC_API, type, default_node, rtems_get_index(id));
138    }
139    return id;
140}
141
142
143rtems_monitor_object_info_t *
144rtems_monitor_object_lookup(
145    rtems_monitor_object_type_t type
146)
147{
148    rtems_monitor_object_info_t *p;
149    for (p = &rtems_monitor_object_info[0];
150         p < &rtems_monitor_object_info[NUMELEMS(rtems_monitor_object_info)];
151         p++)
152    {
153        if (p->type == type)
154            return p;
155    }
156    return 0;
157}
158
159rtems_id
160rtems_monitor_object_canonical_next_remote(
161    rtems_monitor_object_type_t type,
162    rtems_id            id,
163    void               *canonical
164)
165{
166    rtems_id                        next_id;
167    rtems_status_code               status;
168    rtems_monitor_server_request_t  request;
169    rtems_monitor_server_response_t response;
170
171    /*
172     * Send request
173     */
174   
175    request.command = RTEMS_MONITOR_SERVER_CANONICAL;
176    request.argument0 = (uint32_t  ) type;
177    request.argument1 = (uint32_t  ) id;
178
179    status = rtems_monitor_server_request(rtems_get_node(id), &request, &response);
180    if (status != RTEMS_SUCCESSFUL)
181        goto failed;
182
183    /*
184     * process response
185     */
186   
187    next_id = (rtems_id) response.result0;
188    if (next_id != RTEMS_OBJECT_ID_FINAL)
189        (void) memcpy(canonical, &response.payload, response.result1);
190
191    return next_id;
192
193failed:
194    return RTEMS_OBJECT_ID_FINAL;
195
196}
197
198
199rtems_id
200rtems_monitor_object_canonical_next(
201    rtems_monitor_object_info_t *info,
202    rtems_id                     id,
203    void                        *canonical
204)
205{
206    rtems_id                     next_id;
207    void                        *raw_item;
208
209    if ( ! _Objects_Is_local_id(id))
210        next_id = rtems_monitor_object_canonical_next_remote(info->type,
211                                                             id,
212                                                             canonical);
213    else
214    {
215        next_id = id;
216       
217        raw_item = (void *) info->next(info->object_information,
218                                       canonical,
219                                       &next_id);
220
221        if (raw_item)
222        {
223            info->canonical(canonical, raw_item);
224            _Thread_Enable_dispatch();
225        }   
226    }   
227    return next_id;
228}
229
230
231/*
232 * this is routine server invokes locally to get the type
233 */
234
235rtems_id
236rtems_monitor_object_canonical_get(
237    rtems_monitor_object_type_t  type,
238    rtems_id             id,
239    void                *canonical,
240    uint32_t            *size_p
241)
242{
243    rtems_monitor_object_info_t *info;
244    rtems_id                     next_id;
245
246    *size_p = 0;
247
248    info = rtems_monitor_object_lookup(type);
249
250    if (info == 0)
251        return RTEMS_OBJECT_ID_FINAL;
252
253    next_id = rtems_monitor_object_canonical_next(info, id, canonical);
254    *size_p = info->size;
255
256    return next_id;
257}
258
259
260void
261rtems_monitor_object_dump_1(
262    rtems_monitor_object_info_t *info,
263    rtems_id                     id,
264    boolean                      verbose
265)
266{
267    rtems_id next_id;
268    rtems_monitor_union_t canonical;
269
270    if ((next_id = rtems_monitor_object_canonical_next(
271                                     info,
272                                     id,
273                                     &canonical)) != RTEMS_OBJECT_ID_FINAL)
274    {
275        /*
276         * If the one we actually got is the one we wanted, then
277         * print it out.
278         * For ones that have an id field, this works fine,
279         * for all others, always dump it out.
280         *
281         * HACK: the way we determine whether there is an id is a hack.
282         *
283         * by the way: the reason we try to not have an id, is that some
284         *   of the canonical structures are almost too big for shared
285         *   memory driver (eg: mpci)
286         */
287       
288        if ((info->next != rtems_monitor_manager_next) ||
289            (id == canonical.generic.id))
290            info->dump(&canonical, verbose);
291    }
292}
293
294void
295rtems_monitor_object_dump_all(
296    rtems_monitor_object_info_t *info,
297    boolean                      verbose
298)
299{
300    rtems_id next_id;
301    rtems_monitor_union_t canonical;
302
303    next_id = RTEMS_OBJECT_ID_INITIAL(OBJECTS_CLASSIC_API, info->type, rtems_monitor_default_node);
304
305    while ((next_id = rtems_monitor_object_canonical_next(
306                                         info,
307                                         next_id,
308                                         &canonical)) != RTEMS_OBJECT_ID_FINAL)
309    {
310        info->dump(&canonical, verbose);
311    }
312}
313
314void
315rtems_monitor_object_cmd(
316    int        argc,
317    char     **argv,
318    rtems_monitor_command_arg_t *command_arg,
319    boolean    verbose
320)
321{
322    int arg;
323    rtems_monitor_object_info_t *info = 0;
324    rtems_monitor_object_type_t  type ;
325   
326    /* what is the default type? */
327    type = command_arg->monitor_object;
328
329    if (argc == 1)
330    {
331        if (type == RTEMS_MONITOR_OBJECT_INVALID)
332        {
333            printf("A type must be specified to \"dump all\"\n");
334            goto done;
335        }
336       
337        info = rtems_monitor_object_lookup(type);
338        if (info == 0)
339            goto not_found;
340
341        if (info->dump_header)
342            info->dump_header(verbose);
343        rtems_monitor_object_dump_all(info, verbose);
344    }
345    else
346    {
347        uint32_t            default_node = rtems_monitor_default_node;
348        rtems_monitor_object_type_t last_type = RTEMS_MONITOR_OBJECT_INVALID;
349        rtems_id            id;
350
351        for (arg=1; argv[arg]; arg++)
352        {
353            id = (rtems_id) strtoul(argv[arg], 0, 16);
354            id = rtems_monitor_id_fixup(id, default_node, type);
355            type = (rtems_monitor_object_type_t) rtems_get_class(id);
356
357            /*
358             * Allow the item type to change in the middle
359             * of the command.  If the type changes, then
360             * just dump out a new header and keep on going.
361             */
362            if (type != last_type)
363            {
364                info = rtems_monitor_object_lookup(type);
365                if (info == 0)
366                    goto not_found;
367           
368                if (info->dump_header)
369                    info->dump_header(verbose);
370            }
371
372            if (info == 0)
373            {
374not_found:      printf("Invalid or unsupported type %d\n", type);
375                goto done;
376            }
377
378            rtems_monitor_object_dump_1(info, id, verbose);
379
380            default_node = rtems_get_node(id);
381           
382            last_type = type;
383        }
384    }
385done:
386    return;
387}
Note: See TracBrowser for help on using the repository browser.