source: rtems/cpukit/libmisc/monitor/mon-monitor.c @ ef30eb1

Last change on this file since ef30eb1 was ef30eb1, checked in by Sebastian Huber <sebastian.huber@…>, on Nov 8, 2018 at 6:52:28 AM

monitor: Remove dead code

Update #3587.
Update #3589.

  • Property mode set to 100644
File size: 13.0 KB
Line 
1/*
2 * RTEMS monitor main body
3 *
4 *  TODO:
5 *      add stuff to RTEMS api
6 *            rtems_get_name(id)
7 *            rtems_get_type(id)
8 *            rtems_build_id(node, type, num)
9 *      Add a command to dump out info about an arbitrary id when
10 *         types are added to id's
11 *         rtems> id idnum
12 *                idnum: node n, object: whatever, id: whatever
13 *      allow id's to be specified as n:t:id, where 'n:t' is optional
14 *      should have a separate monitor FILE stream (ala the debugger)
15 *      remote request/response stuff should be cleaned up
16 *         maybe we can use real rpc??
17 *      'info' command to print out:
18 *           interrupt stack location, direction and size
19 *           floating point config stuff
20 *           interrupt config stuff
21 */
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#include <rtems.h>
28
29#include <stdio.h>
30#include <string.h>
31#include <stdlib.h>
32
33#include <rtems/monitor.h>
34
35/*
36 * Various id's for the monitor
37 * They need to be public variables for access by other agencies
38 * such as debugger and remote servers'
39 */
40
41rtems_id  rtems_monitor_task_id;
42
43uint32_t   rtems_monitor_node;          /* our node number */
44uint32_t   rtems_monitor_default_node;  /* current default for commands */
45
46/*
47 * The rtems symbol table
48 */
49
50rtems_symbol_table_t *rtems_monitor_symbols;
51
52/*
53 * The top-level commands
54 */
55
56static const rtems_monitor_command_entry_t rtems_monitor_commands[] = {
57    { "config",
58      "Show the system configuration.",
59      0,
60      rtems_monitor_object_cmd,
61      { RTEMS_MONITOR_OBJECT_CONFIG },
62      &rtems_monitor_commands[1],
63    },
64    { "itask",
65      "List init tasks for the system",
66      0,
67      rtems_monitor_object_cmd,
68      { RTEMS_MONITOR_OBJECT_INIT_TASK },
69      &rtems_monitor_commands[2],
70    },
71   { "mpci",
72      "Show the MPCI system configuration, if configured.",
73      0,
74      rtems_monitor_object_cmd,
75      { RTEMS_MONITOR_OBJECT_MPCI },
76      &rtems_monitor_commands[3],
77    },
78    { "pause",
79      "Monitor goes to \"sleep\" for specified ticks (default is 1). "
80      "Monitor will resume at end of period or if explicitly awakened\n"
81      "  pause [ticks]",
82      0,
83      rtems_monitor_pause_cmd,
84      { 0 },
85      &rtems_monitor_commands[4],
86    },
87    { "continue",
88      "Put the monitor to sleep waiting for an explicit wakeup from the "
89      "program running.\n",
90      0,
91      rtems_monitor_continue_cmd,
92      { 0 },
93      &rtems_monitor_commands[5],
94    },
95    { "go",
96      "Alias for 'continue'",
97      0,
98      rtems_monitor_continue_cmd,
99      { 0 },
100      &rtems_monitor_commands[6],
101    },
102    { "symbol",
103      "Display value associated with specified symbol. "
104      "Defaults to displaying all known symbols.\n"
105      "  symbol [ symbolname [symbolname ... ] ]",
106      0,
107      rtems_monitor_symbol_cmd,
108      { .symbol_table = &rtems_monitor_symbols },
109      &rtems_monitor_commands[7],
110    },
111    { "extension",
112      "Display information about specified extensions. "
113      "Default is to display information about all extensions on this node.\n"
114      "  extension [id [id ...] ]",
115      0,
116      rtems_monitor_object_cmd,
117      { RTEMS_MONITOR_OBJECT_EXTENSION },
118      &rtems_monitor_commands[8],
119    },
120    { "task",
121      "Display information about the specified tasks. "
122      "Default is to display information about all tasks on this node.\n"
123      "  task [id [id ...] ]",
124      0,
125      rtems_monitor_object_cmd,
126      { RTEMS_MONITOR_OBJECT_TASK },
127      &rtems_monitor_commands[9],
128    },
129    { "queue",
130      "Display information about the specified message queues. "
131      "Default is to display information about all queues on this node.\n"
132      "  queue [id [id ... ] ]",
133      0,
134      rtems_monitor_object_cmd,
135      { RTEMS_MONITOR_OBJECT_QUEUE },
136      &rtems_monitor_commands[10],
137    },
138    { "sema",
139      "sema [id [id ... ] ]\n"
140      "  display information about the specified semaphores\n"
141      "  Default is to display information about all semaphores on this node\n"
142      ,
143      0,
144      rtems_monitor_object_cmd,
145      { RTEMS_MONITOR_OBJECT_SEMAPHORE },
146      &rtems_monitor_commands[11],
147    },
148    { "region",
149      "region [id [id ... ] ]\n"
150      "  display information about the specified regions\n"
151      "  Default is to display information about all regions on this node\n"
152      ,
153      0,
154      rtems_monitor_object_cmd,
155      { RTEMS_MONITOR_OBJECT_REGION },
156      &rtems_monitor_commands[12],
157    },
158    { "part",
159      "part [id [id ... ] ]\n"
160      "  display information about the specified partitions\n"
161      "  Default is to display information about all partitions on this node\n"
162      ,
163      0,
164      rtems_monitor_object_cmd,
165      { RTEMS_MONITOR_OBJECT_PARTITION },
166      &rtems_monitor_commands[13],
167    },
168    { "object",
169      "Display information about specified RTEMS objects. "
170      "Object id's must include 'type' information. "
171      "(which may normally be defaulted)\n"
172      "  object [id [id ...] ]",
173      0,
174      rtems_monitor_object_cmd,
175      { RTEMS_MONITOR_OBJECT_INVALID },
176      &rtems_monitor_commands[14],
177    },
178    { "driver",
179      "Display the RTEMS device driver table.\n"
180      "  driver [ major [ major ... ] ]",
181      0,
182      rtems_monitor_object_cmd,
183      { RTEMS_MONITOR_OBJECT_DRIVER },
184      &rtems_monitor_commands[15],
185    },
186    { "dname",
187      "Displays information about named drivers.\n",
188      0,
189      rtems_monitor_object_cmd,
190      { RTEMS_MONITOR_OBJECT_DNAME },
191      &rtems_monitor_commands[16],
192    },
193    { "fatal",
194      "'exit' with fatal error; default error is RTEMS_TASK_EXITTED\n"
195      "  fatal [status]",
196      0,
197      rtems_monitor_fatal_cmd,
198      { .status_code = RTEMS_TASK_EXITTED },            /* exit value */
199      &rtems_monitor_commands[17],
200    },
201    { "reset",
202      "(SW)Resets the System.",
203      0,
204      rtems_monitor_reset_cmd,
205      { 0 },
206      &rtems_monitor_commands[18],
207    },
208#if defined(RTEMS_MULTIPROCESSING)
209    { "node",
210      "Specify default node number for commands that take id's.\n"
211      "  node [ node number ]",
212      0,
213      rtems_monitor_node_cmd,
214      { 0 },
215      &rtems_monitor_commands[19],
216    },
217  #define RTEMS_MONITOR_POSIX_NEXT 20
218#else
219  #define RTEMS_MONITOR_POSIX_NEXT 19
220#endif
221    { "pthread",
222      "Display information about the specified pthreads. "
223      "Default is to display information about all pthreads on this node.\n"
224      "  pthread [id [id ...] ]",
225      0,
226      rtems_monitor_object_cmd,
227      { RTEMS_MONITOR_OBJECT_PTHREAD },
228      &rtems_monitor_commands[RTEMS_MONITOR_POSIX_NEXT],
229    },
230  #define RTEMS_MONITOR_DEBUGGER_NEXT (RTEMS_MONITOR_POSIX_NEXT + 1)
231#ifdef CPU_INVOKE_DEBUGGER
232    { "debugger",
233      "Enter the debugger, if possible. "
234      "A continue from the debugger will return to the monitor.\n",
235      0,
236      rtems_monitor_debugger_cmd,
237      { 0 },
238      &rtems_monitor_commands[RTEMS_MONITOR_DEBUGGER_NEXT],
239    },
240#endif
241    { "help",
242      "Provide information about commands. "
243      "Default is show basic command summary.\n"
244      "help [ command [ command ] ]",
245      0,
246      rtems_monitor_help_cmd,
247      { .monitor_command_entry = rtems_monitor_commands },
248      NULL
249    }
250};
251
252/*
253 * All registered commands.
254 */
255
256static const rtems_monitor_command_entry_t *rtems_monitor_registered_commands =
257  &rtems_monitor_commands [0];
258
259
260rtems_status_code
261rtems_monitor_suspend(rtems_interval timeout)
262{
263    rtems_event_set event_set;
264    rtems_status_code status;
265
266    status = rtems_event_receive(MONITOR_WAKEUP_EVENT,
267                                 RTEMS_DEFAULT_OPTIONS,
268                                 timeout,
269                                 &event_set);
270    return status;
271}
272
273void __attribute__((weak))
274rtems_monitor_reset_cmd(
275  int argc,
276  char **argv,
277  const rtems_monitor_command_arg_t* command_arg,
278  bool verbose
279)
280{
281
282}
283
284void
285rtems_monitor_wakeup(void)
286{
287    rtems_event_send(rtems_monitor_task_id, MONITOR_WAKEUP_EVENT);
288}
289
290void rtems_monitor_debugger_cmd(
291  int                                argc RTEMS_UNUSED,
292  char                             **argv RTEMS_UNUSED,
293  const rtems_monitor_command_arg_t *command_arg RTEMS_UNUSED,
294  bool                               verbose RTEMS_UNUSED
295)
296{
297#ifdef CPU_INVOKE_DEBUGGER
298    CPU_INVOKE_DEBUGGER;
299#endif
300}
301
302void rtems_monitor_pause_cmd(
303  int                                argc,
304  char                             **argv,
305  const rtems_monitor_command_arg_t *command_arg RTEMS_UNUSED,
306  bool                               verbose RTEMS_UNUSED
307)
308{
309    if (argc == 1)
310        rtems_monitor_suspend(1);
311    else
312        rtems_monitor_suspend(strtoul(argv[1], 0, 0));
313}
314
315void rtems_monitor_fatal_cmd(
316  int                                argc,
317  char                             **argv,
318  const rtems_monitor_command_arg_t *command_arg,
319  bool                               verbose RTEMS_UNUSED
320)
321{
322    if (argc == 1)
323        rtems_fatal_error_occurred(command_arg->status_code);
324    else
325        rtems_fatal_error_occurred(strtoul(argv[1], 0, 0));
326}
327
328void rtems_monitor_continue_cmd(
329  int                                argc RTEMS_UNUSED,
330  char                             **argv RTEMS_UNUSED,
331  const rtems_monitor_command_arg_t *command_arg RTEMS_UNUSED,
332  bool                               verbose RTEMS_UNUSED
333)
334{
335    rtems_monitor_suspend(RTEMS_NO_TIMEOUT);
336}
337
338#if defined(RTEMS_MULTIPROCESSING)
339void rtems_monitor_node_cmd(
340  int                                argc,
341  char                             **argv,
342  const rtems_monitor_command_arg_t *command_arg RTEMS_UNUSED,
343  bool                               verbose RTEMS_UNUSED
344)
345{
346  uint32_t   new_node = rtems_monitor_default_node;
347
348  switch (argc) {
349    case 1:             /* no node, just set back to ours */
350      new_node = rtems_monitor_node;
351      break;
352
353    case 2:
354      new_node = strtoul(argv[1], 0, 0);
355      break;
356
357    default:
358      fprintf(stdout,"invalid syntax, try 'help node'\n");
359      break;
360  }
361
362  if ((new_node >= 1) &&
363    _Configuration_MP_table &&
364    (new_node <= _Configuration_MP_table->maximum_nodes))
365        rtems_monitor_default_node = new_node;
366}
367#endif
368
369
370/*
371 *  Function:   rtems_monitor_symbols_loadup
372 *
373 *  Description:
374 *      Create and load the monitor's symbol table.
375 *      We are reading the output format of 'gnm' which looks like this:
376 *
377 *              400a7068 ? _Rate_monotonic_Information
378 *              400a708c ? _Thread_Dispatch_disable_level
379 *              400a7090 ? _Configuration_Table
380 *
381 *      We ignore the type field.
382 *
383 *  Side Effects:
384 *      Creates and fills in 'rtems_monitor_symbols' table
385 *
386 *  TODO
387 *      there should be a BSP #define or something like that
388 *         to do this;  Assuming stdio is crazy.
389 *      Someday this should know BFD
390 *              Maybe we could get objcopy to just copy the symbol areas
391 *              and copy that down.
392 *
393 */
394
395void
396rtems_monitor_symbols_loadup(void)
397{
398    FILE *fp;
399    char buffer[128];
400
401    if (rtems_monitor_symbols)
402        rtems_symbol_table_destroy(rtems_monitor_symbols);
403
404    rtems_monitor_symbols = rtems_symbol_table_create();
405    if (rtems_monitor_symbols == 0)
406        return;
407
408    fp = fopen("symbols", "r");
409
410    if (fp == 0)
411        return;
412
413    while (fgets(buffer, sizeof(buffer) - 1, fp))
414    {
415        char *symbol;
416        char *value;
417        char *ignored_type;
418
419        value = strtok(buffer, " \t\n");
420        ignored_type = strtok(0, " \t\n");
421        symbol = strtok(0, " \t\n");
422
423        if (symbol && ignored_type && value)
424        {
425            rtems_symbol_t *sp;
426            sp = rtems_symbol_create(rtems_monitor_symbols,
427                                     symbol,
428                                     (uint32_t) strtoul(value, 0, 16));
429            if (sp == 0)
430            {
431                fprintf(stdout,"could not define symbol '%s'\n", symbol);
432                goto done;
433            }
434        }
435        else
436        {
437            fprintf(stdout,"parsing error on '%s'\n", buffer);
438            goto done;
439        }
440    }
441
442done:
443    fclose(fp);
444    return;
445}
446
447/*
448 * User registered commands.
449 */
450
451int
452rtems_monitor_insert_cmd (
453  rtems_monitor_command_entry_t *command
454)
455{
456  const rtems_monitor_command_entry_t *e = rtems_monitor_registered_commands;
457
458  /* Reject empty commands */
459  if (command->command == NULL) {
460    return 0;
461  }
462
463  /* Reject command if already present */
464  while (e->next != NULL) {
465      if (e->command != NULL && strcmp(command->command, e->command) == 0) {
466        return 0;
467      }
468      e = e->next;
469  }
470
471  /* Prepend new command */
472  command->next = rtems_monitor_registered_commands;
473  rtems_monitor_registered_commands = command;
474
475  return 1;
476}
477
478/**
479 * @brief Iterates through all registerd commands.
480 *
481 * For each command the interation routine @a routine is called with the
482 * command entry and the user provided argument @a arg.  It is guaranteed that
483 * the command name and function are not NULL.
484 */
485void rtems_monitor_command_iterate(
486  rtems_monitor_per_command_routine routine,
487  void *arg
488)
489{
490  const rtems_monitor_command_entry_t *e = rtems_monitor_registered_commands;
491
492  while (e != NULL) {
493    if (e->command != NULL && e->command_function != NULL) {
494      if (!routine(e, arg)) {
495        break;
496      }
497    }
498    e = e->next;
499  }
500}
Note: See TracBrowser for help on using the repository browser.