[b06e68ef] | 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 | |
---|
[e6424462] | 18 | #define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ |
---|
[b06e68ef] | 19 | #include <rtems.h> |
---|
[5beb562] | 20 | #include <rtems/monitor.h> |
---|
[b06e68ef] | 21 | |
---|
| 22 | #include <stdio.h> |
---|
| 23 | #include <stdlib.h> /* strtoul() */ |
---|
[be95da0] | 24 | #include <string.h> /* memcpy() */ |
---|
[b06e68ef] | 25 | |
---|
| 26 | #define NUMELEMS(arr) (sizeof(arr) / sizeof(arr[0])) |
---|
| 27 | |
---|
| 28 | /* |
---|
| 29 | * add: |
---|
| 30 | * next |
---|
| 31 | */ |
---|
| 32 | |
---|
| 33 | rtems_monitor_object_info_t rtems_monitor_object_info[] = |
---|
| 34 | { |
---|
[72c440e] | 35 | { RTEMS_MONITOR_OBJECT_CONFIG, |
---|
[b06e68ef] | 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 | }, |
---|
[72c440e] | 43 | { RTEMS_MONITOR_OBJECT_MPCI, |
---|
[b06e68ef] | 44 | (void *) 0, |
---|
[97e2729d] | 45 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[b06e68ef] | 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, |
---|
[97e2729d] | 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 |
---|
[b06e68ef] | 58 | }, |
---|
[72c440e] | 59 | { RTEMS_MONITOR_OBJECT_INIT_TASK, |
---|
[b06e68ef] | 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 | }, |
---|
[72c440e] | 67 | { RTEMS_MONITOR_OBJECT_TASK, |
---|
[5250ff39] | 68 | (void *) &_RTEMS_tasks_Information, |
---|
[b06e68ef] | 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 | }, |
---|
[72c440e] | 75 | { RTEMS_MONITOR_OBJECT_QUEUE, |
---|
[b06e68ef] | 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 | }, |
---|
[72c440e] | 83 | { RTEMS_MONITOR_OBJECT_EXTENSION, |
---|
[b06e68ef] | 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 | }, |
---|
[72c440e] | 91 | { RTEMS_MONITOR_OBJECT_DRIVER, |
---|
[b06e68ef] | 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 | }, |
---|
[72c440e] | 99 | { RTEMS_MONITOR_OBJECT_DNAME, |
---|
[3a4ae6c] | 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, */ |
---|
[b06e68ef] | 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 | |
---|
| 117 | rtems_id |
---|
| 118 | rtems_monitor_id_fixup( |
---|
| 119 | rtems_id id, |
---|
| 120 | unsigned32 default_node, |
---|
[72c440e] | 121 | rtems_monitor_object_type_t type |
---|
[b06e68ef] | 122 | ) |
---|
| 123 | { |
---|
| 124 | unsigned32 node; |
---|
| 125 | |
---|
| 126 | node = rtems_get_node(id); |
---|
| 127 | if (node == 0) |
---|
| 128 | { |
---|
[9863dbf] | 129 | if (rtems_get_class(id) != OBJECTS_NO_CLASS) |
---|
| 130 | type = rtems_get_class(id); |
---|
[b06e68ef] | 131 | |
---|
[63977bb4] | 132 | id = _Objects_Build_id( |
---|
| 133 | OBJECTS_CLASSIC_API, type, default_node, rtems_get_index(id)); |
---|
[b06e68ef] | 134 | } |
---|
| 135 | return id; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | |
---|
| 139 | rtems_monitor_object_info_t * |
---|
| 140 | rtems_monitor_object_lookup( |
---|
[72c440e] | 141 | rtems_monitor_object_type_t type |
---|
[b06e68ef] | 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 | |
---|
| 155 | rtems_id |
---|
| 156 | rtems_monitor_object_canonical_next_remote( |
---|
[72c440e] | 157 | rtems_monitor_object_type_t type, |
---|
[b06e68ef] | 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 | |
---|
| 189 | failed: |
---|
| 190 | return RTEMS_OBJECT_ID_FINAL; |
---|
| 191 | |
---|
| 192 | } |
---|
| 193 | |
---|
| 194 | |
---|
| 195 | rtems_id |
---|
| 196 | rtems_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 | |
---|
| 231 | rtems_id |
---|
| 232 | rtems_monitor_object_canonical_get( |
---|
[72c440e] | 233 | rtems_monitor_object_type_t type, |
---|
[b06e68ef] | 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 | |
---|
| 256 | void |
---|
| 257 | rtems_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 | |
---|
| 290 | void |
---|
| 291 | rtems_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 | |
---|
[63977bb4] | 299 | next_id = RTEMS_OBJECT_ID_INITIAL(OBJECTS_CLASSIC_API, info->type, rtems_monitor_default_node); |
---|
[b06e68ef] | 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 | |
---|
| 310 | void |
---|
| 311 | rtems_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; |
---|
[72c440e] | 320 | rtems_monitor_object_type_t type = (rtems_monitor_object_type_t) command_arg; |
---|
[b06e68ef] | 321 | |
---|
| 322 | /* what is the default type? */ |
---|
[72c440e] | 323 | type = (rtems_monitor_object_type_t) command_arg; |
---|
[b06e68ef] | 324 | |
---|
| 325 | if (argc == 1) |
---|
| 326 | { |
---|
[72c440e] | 327 | if (type == RTEMS_MONITOR_OBJECT_INVALID) |
---|
[b06e68ef] | 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; |
---|
[72c440e] | 344 | rtems_monitor_object_type_t last_type = RTEMS_MONITOR_OBJECT_INVALID; |
---|
[b06e68ef] | 345 | rtems_id id; |
---|
| 346 | |
---|
| 347 | for (arg=1; argv[arg]; arg++) |
---|
| 348 | { |
---|
[8389628] | 349 | id = (rtems_id) strtoul(argv[arg], 0, 16); |
---|
[b06e68ef] | 350 | id = rtems_monitor_id_fixup(id, default_node, type); |
---|
[72c440e] | 351 | type = (rtems_monitor_object_type_t) rtems_get_class(id); |
---|
| 352 | |
---|
[b06e68ef] | 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) |
---|
[72c440e] | 362 | goto not_found; |
---|
[b06e68ef] | 363 | |
---|
| 364 | if (info->dump_header) |
---|
| 365 | info->dump_header(verbose); |
---|
| 366 | } |
---|
| 367 | |
---|
[72c440e] | 368 | if (info == 0) |
---|
| 369 | { |
---|
| 370 | not_found: printf("Invalid or unsupported type %d\n", type); |
---|
| 371 | goto done; |
---|
| 372 | } |
---|
| 373 | |
---|
[b06e68ef] | 374 | rtems_monitor_object_dump_1(info, id, verbose); |
---|
| 375 | |
---|
| 376 | default_node = rtems_get_node(id); |
---|
| 377 | |
---|
| 378 | last_type = type; |
---|
| 379 | } |
---|
| 380 | } |
---|
| 381 | done: |
---|
[be95da0] | 382 | return; |
---|
[b06e68ef] | 383 | } |
---|