source: rtems/cpukit/libmisc/monitor/mon-object.c @ 6c06288

4.104.114.95
Last change on this file since 6c06288 was 6c06288, checked in by Joel Sherrill <joel.sherrill@…>, on 01/29/08 at 21:52:21

2008-01-29 Joel Sherrill <joel.sherrill@…>

  • itron/src/exd_tsk.c, itron/src/task.c, libmisc/capture/capture.c, libmisc/monitor/mon-config.c, libmisc/monitor/mon-driver.c, libmisc/monitor/mon-itask.c, libmisc/monitor/mon-monitor.c, libmisc/monitor/mon-mpci.c, libmisc/monitor/mon-object.c, libmisc/monitor/mon-symbols.c, posix/src/cancelrun.c, posix/src/pthreadexit.c, rtems/Makefile.am, rtems/preinstall.am, rtems/include/rtems.h, rtems/include/rtems/rtems/support.h, rtems/inline/rtems/rtems/tasks.inl, rtems/src/eventmp.c, rtems/src/msgmp.c, rtems/src/partmp.c, rtems/src/regionmp.c, rtems/src/rtemsobjectgetname.c, rtems/src/semmp.c, rtems/src/signalmp.c, rtems/src/taskdelete.c, rtems/src/taskmp.c, rtems/src/timerserver.c, score/Makefile.am, score/include/rtems/score/object.h, score/inline/rtems/score/object.inl, score/src/Unlimited.txt, score/src/objectgetnameasstring.c, score/src/threadqextractwithproxy.c: Add new Object Services collection. This changed the name of a few previously public but undocumented services and added a some new services.
  • rtems/include/rtems/rtems/object.h, rtems/src/rtemsbuildid.c, rtems/src/rtemsbuildname.c, rtems/src/rtemsobjectapimaximumclass.c, rtems/src/rtemsobjectapiminimumclass.c, rtems/src/rtemsobjectgetapiclassname.c, rtems/src/rtemsobjectgetapiname.c, rtems/src/rtemsobjectgetclassicname.c, rtems/src/rtemsobjectgetclassinfo.c, rtems/src/rtemsobjectidapimaximum.c, rtems/src/rtemsobjectidapiminimum.c, rtems/src/rtemsobjectidgetapi.c, rtems/src/rtemsobjectidgetclass.c, rtems/src/rtemsobjectidgetindex.c, rtems/src/rtemsobjectidgetnode.c, rtems/src/rtemsobjectsetname.c, score/src/objectapimaximumclass.c, score/src/objectgetinfo.c, score/src/objectgetinfoid.c, score/src/objectsetname.c: New files.
  • rtems/src/rtemsidtoname.c: Removed.
  • Property mode set to 100644
File size: 11.8 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_SEMAPHORE,
88      (void *) &_Semaphore_Information,
89      sizeof(rtems_monitor_sema_t),
90      (rtems_monitor_object_next_fn)        rtems_monitor_manager_next,
91      (rtems_monitor_object_canonical_fn)   rtems_monitor_sema_canonical,
92      (rtems_monitor_object_dump_header_fn) rtems_monitor_sema_dump_header,
93      (rtems_monitor_object_dump_fn)        rtems_monitor_sema_dump,
94    },
95    { RTEMS_MONITOR_OBJECT_REGION,
96      (void *) &_Region_Information,
97      sizeof(rtems_monitor_region_t),
98      (rtems_monitor_object_next_fn)        rtems_monitor_manager_next,
99      (rtems_monitor_object_canonical_fn)   rtems_monitor_region_canonical,
100      (rtems_monitor_object_dump_header_fn) rtems_monitor_region_dump_header,
101      (rtems_monitor_object_dump_fn)        rtems_monitor_region_dump,
102    },
103    { RTEMS_MONITOR_OBJECT_PARTITION,
104      (void *) &_Partition_Information,
105      sizeof(rtems_monitor_part_t),
106      (rtems_monitor_object_next_fn)        rtems_monitor_manager_next,
107      (rtems_monitor_object_canonical_fn)   rtems_monitor_part_canonical,
108      (rtems_monitor_object_dump_header_fn) rtems_monitor_part_dump_header,
109      (rtems_monitor_object_dump_fn)        rtems_monitor_part_dump,
110    },
111    { RTEMS_MONITOR_OBJECT_EXTENSION,
112      (void *) &_Extension_Information,
113      sizeof(rtems_monitor_extension_t),
114      (rtems_monitor_object_next_fn)        rtems_monitor_manager_next,
115      (rtems_monitor_object_canonical_fn)   rtems_monitor_extension_canonical,
116      (rtems_monitor_object_dump_header_fn) rtems_monitor_extension_dump_header,
117      (rtems_monitor_object_dump_fn)        rtems_monitor_extension_dump,
118    },
119    { RTEMS_MONITOR_OBJECT_DRIVER,
120      (void *) 0,
121      sizeof(rtems_monitor_driver_t),
122      (rtems_monitor_object_next_fn)        rtems_monitor_driver_next,
123      (rtems_monitor_object_canonical_fn)   rtems_monitor_driver_canonical,
124      (rtems_monitor_object_dump_header_fn) rtems_monitor_driver_dump_header,
125      (rtems_monitor_object_dump_fn)        rtems_monitor_driver_dump,
126    },
127};
128
129/*
130 * Allow id's to be specified without the node number or
131 * type for convenience.
132 */
133
134rtems_id
135rtems_monitor_id_fixup(
136    rtems_id            id,
137    uint32_t            default_node,
138    rtems_monitor_object_type_t type
139)
140{
141    uint32_t    node;
142
143    node = rtems_object_id_get_node(id);
144    if (node == 0)
145    {
146        if (rtems_object_id_get_class(id) != OBJECTS_CLASSIC_NO_CLASS)
147            type = rtems_object_id_get_class(id);
148
149        id = rtems_build_id(
150          OBJECTS_CLASSIC_API,
151          type,
152          default_node,
153          rtems_object_id_get_index(id)
154        );
155    }
156    return id;
157}
158
159
160rtems_monitor_object_info_t *
161rtems_monitor_object_lookup(
162    rtems_monitor_object_type_t type
163)
164{
165    rtems_monitor_object_info_t *p;
166    for (p = &rtems_monitor_object_info[0];
167         p < &rtems_monitor_object_info[NUMELEMS(rtems_monitor_object_info)];
168         p++)
169    {
170        if (p->type == type)
171            return p;
172    }
173    return 0;
174}
175
176rtems_id
177rtems_monitor_object_canonical_next_remote(
178    rtems_monitor_object_type_t type,
179    rtems_id            id,
180    void               *canonical
181)
182{
183    rtems_id                        next_id;
184    rtems_status_code               status;
185    rtems_monitor_server_request_t  request;
186    rtems_monitor_server_response_t response;
187
188    /*
189     * Send request
190     */
191
192    request.command = RTEMS_MONITOR_SERVER_CANONICAL;
193    request.argument0 = (uint32_t  ) type;
194    request.argument1 = (uint32_t  ) id;
195
196    status = rtems_monitor_server_request(
197      rtems_object_id_get_node(id), &request, &response);
198    if (status != RTEMS_SUCCESSFUL)
199        goto failed;
200
201    /*
202     * process response
203     */
204
205    next_id = (rtems_id) response.result0;
206    if (next_id != RTEMS_OBJECT_ID_FINAL)
207        (void) memcpy(canonical, &response.payload, response.result1);
208
209    return next_id;
210
211failed:
212    return RTEMS_OBJECT_ID_FINAL;
213
214}
215
216
217rtems_id
218rtems_monitor_object_canonical_next(
219    rtems_monitor_object_info_t *info,
220    rtems_id                     id,
221    void                        *canonical
222)
223{
224  rtems_id  next_id;
225  void     *raw_item;
226
227#if defined(RTEMS_MULTIPROCESSING)
228    if ( ! _Objects_Is_local_id(id) ) {
229       next_id = rtems_monitor_object_canonical_next_remote(
230         info->type,
231         id,
232         canonical
233      );
234    } else
235#endif
236    {
237      next_id = id;
238
239      raw_item = (void *) info->next(
240        info->object_information,
241        canonical,
242        &next_id
243      );
244
245     if (raw_item) {
246       info->canonical(canonical, raw_item);
247       _Thread_Enable_dispatch();
248     }
249  }
250  return next_id;
251}
252
253
254/*
255 * this is routine server invokes locally to get the type
256 */
257
258rtems_id
259rtems_monitor_object_canonical_get(
260    rtems_monitor_object_type_t  type,
261    rtems_id             id,
262    void                *canonical,
263    size_t              *size_p
264)
265{
266    rtems_monitor_object_info_t *info;
267    rtems_id                     next_id;
268
269    *size_p = 0;
270
271    info = rtems_monitor_object_lookup(type);
272
273    if (info == 0)
274        return RTEMS_OBJECT_ID_FINAL;
275
276    next_id = rtems_monitor_object_canonical_next(info, id, canonical);
277    *size_p = info->size;
278
279    return next_id;
280}
281
282
283void
284rtems_monitor_object_dump_1(
285    rtems_monitor_object_info_t *info,
286    rtems_id                     id,
287    boolean                      verbose
288)
289{
290    rtems_id next_id;
291    rtems_monitor_union_t canonical;
292
293    if ((next_id = rtems_monitor_object_canonical_next(
294                                     info,
295                                     id,
296                                     &canonical)) != RTEMS_OBJECT_ID_FINAL)
297    {
298        /*
299         * If the one we actually got is the one we wanted, then
300         * print it out.
301         * For ones that have an id field, this works fine,
302         * for all others, always dump it out.
303         *
304         * HACK: the way we determine whether there is an id is a hack.
305         *
306         * by the way: the reason we try to not have an id, is that some
307         *   of the canonical structures are almost too big for shared
308         *   memory driver (eg: mpci)
309         */
310
311        if ((info->next != rtems_monitor_manager_next) ||
312            (id == canonical.generic.id))
313            info->dump(&canonical, verbose);
314    }
315}
316
317void
318rtems_monitor_object_dump_all(
319    rtems_monitor_object_info_t *info,
320    boolean                      verbose
321)
322{
323    rtems_id next_id;
324    rtems_monitor_union_t canonical;
325
326    next_id = RTEMS_OBJECT_ID_INITIAL(OBJECTS_CLASSIC_API, info->type, rtems_monitor_default_node);
327
328    while ((next_id = rtems_monitor_object_canonical_next(
329                                         info,
330                                         next_id,
331                                         &canonical)) != RTEMS_OBJECT_ID_FINAL)
332    {
333        info->dump(&canonical, verbose);
334    }
335}
336
337void
338rtems_monitor_object_cmd(
339    int        argc,
340    char     **argv,
341    rtems_monitor_command_arg_t *command_arg,
342    boolean    verbose
343)
344{
345    int arg;
346    rtems_monitor_object_info_t *info = 0;
347    rtems_monitor_object_type_t  type;
348
349    /* what is the default type? */
350    type = command_arg->monitor_object;
351
352    if (argc == 1)
353    {
354        if (type == RTEMS_MONITOR_OBJECT_INVALID)
355        {
356            fprintf(stdout,"A type must be specified to \"dump all\"\n");
357            goto done;
358        }
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        rtems_monitor_object_dump_all(info, verbose);
367    }
368    else
369    {
370        uint32_t            default_node = rtems_monitor_default_node;
371        rtems_monitor_object_type_t last_type = RTEMS_MONITOR_OBJECT_INVALID;
372        rtems_id            id;
373
374        for (arg=1; argv[arg]; arg++)
375        {
376            id = (rtems_id) strtoul(argv[arg], 0, 16);
377            id = rtems_monitor_id_fixup(id, default_node, type);
378            type = (rtems_monitor_object_type_t) rtems_object_id_get_class(id);
379
380            /*
381             * Allow the item type to change in the middle
382             * of the command.  If the type changes, then
383             * just dump out a new header and keep on going.
384             */
385            if (type != last_type)
386            {
387                info = rtems_monitor_object_lookup(type);
388                if (info == 0)
389                    goto not_found;
390
391                if (info->dump_header)
392                    info->dump_header(verbose);
393            }
394
395            if (info == 0)
396            {
397not_found:      fprintf(stdout,"Invalid or unsupported type %d\n", type);
398                goto done;
399            }
400
401            rtems_monitor_object_dump_1(info, id, verbose);
402
403            default_node = rtems_object_id_get_node(id);
404
405            last_type = type;
406        }
407    }
408done:
409    return;
410}
Note: See TracBrowser for help on using the repository browser.