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