source: rtems/cpukit/libmisc/monitor/mon-object.c @ 63977bb4

4.104.114.84.95
Last change on this file since 63977bb4 was 63977bb4, checked in by Joel Sherrill <joel.sherrill@…>, on Jul 1, 2002 at 10:19:33 PM

2002-07-01 Joel Sherrill <joel@…>

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