Ignore:
Timestamp:
Aug 17, 1995, 7:51:51 PM (25 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
95fbca1
Parents:
3b438fa
Message:

Numerous miscellaneous features incorporated from Tony Bennett
(tbennett@…) including the following major additions:

+ variable length messages
+ named devices
+ debug monitor
+ association tables/variables

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libmisc/monitor/mon-symbols.c

    r3b438fa rb06e68ef  
    11/*
    2  *      @(#)symbols.c   1.3 - 95/04/24
     2 *      @(#)symbols.c   1.10 - 95/08/02
    33 *     
     4 *  $Id$
    45 */
    56
     
    2223#include <string.h>
    2324
     25#include "monitor.h"
    2426#include "symbols.h"
    2527
    26 extern rtems_symbol_table_t *rtems_monitor_symbols;
    27 
    28 #ifdef RTEMS_DEBUG
    29 #define CHK_ADR_PTR(p)  \
    30 do { \
    31     if (((p) < rtems_monitor_symbols->addresses) || \
    32         ((p) >= (rtems_monitor_symbols->addresses + rtems_monitor_symbols->next))) \
    33     { \
    34         printf("bad address pointer %p\n", (p)); \
    35         rtems_fatal_error_occurred(RTEMS_INVALID_ADDRESS); \
    36     } \
    37 } while (0)
    38 
    39 #define CHK_NAME_PTR(p) \
    40 do { \
    41     if (((p) < rtems_monitor_symbols->symbols) || \
    42         ((p) >= (rtems_monitor_symbols->symbols + rtems_monitor_symbols->next))) \
    43     { \
    44         printf("bad symbol pointer %p\n", (p)); \
    45         rtems_fatal_error_occurred(RTEMS_INVALID_ADDRESS); \
    46     } \
    47 } while (0)
    48 #else
    49 #define CHK_ADR_PTR(p)
    50 #define CHK_NAME_PTR(p)
    51 #endif
    5228
    5329rtems_symbol_table_t *
     
    179155    s2 = (rtems_symbol_t *) e2;
    180156
    181     CHK_ADR_PTR(s1);
    182     CHK_ADR_PTR(s2);
    183 
    184157    if (s1->value < s2->value)
    185158        return -1;
     
    200173    s1 = (rtems_symbol_t *) e1;
    201174    s2 = (rtems_symbol_t *) e2;
    202 
    203     CHK_NAME_PTR(s1);
    204     CHK_NAME_PTR(s2);
    205175
    206176    return strcasecmp(s1->name, s2->name);
     
    252222    rtems_unsigned32 best_distance = ~0;
    253223    rtems_unsigned32 elements;
     224
     225    if (table == 0)
     226        table = rtems_monitor_symbols;
    254227
    255228    if ((table == 0) || (table->size == 0))
     
    301274    rtems_symbol_t  key;
    302275
     276    if (table == 0)
     277        table = rtems_monitor_symbols;
     278
    303279    if ((table == 0) || (name == 0))
    304280        goto done;
    305281
    306282    if (table->sorted == 0)
    307     {
    308283        rtems_symbol_sort(table);
    309     }
    310284
    311285    /*
     
    326300}
    327301
     302void *
     303rtems_monitor_symbol_next(
     304    void                   *object_info,
     305    rtems_monitor_symbol_t *canonical,
     306    rtems_id               *next_id
     307)
     308{
     309    rtems_symbol_table_t *table;
     310    int n = rtems_get_index(*next_id);
     311
     312    table = *(rtems_symbol_table_t **) object_info;
     313    if (table == 0)
     314        goto failed;
     315
     316    if (n >= table->next)
     317        goto failed;
     318
     319    /* NOTE: symbols do not have id and name fields */
     320     
     321    if (table->sorted == 0)
     322        rtems_symbol_sort(table);
     323
     324    _Thread_Disable_dispatch();
     325
     326    *next_id += 1;
     327    return (void *) (table->symbols + n);
     328
     329failed:
     330    *next_id = RTEMS_OBJECT_ID_FINAL;
     331    return 0;
     332}
     333
     334void
     335rtems_monitor_symbol_canonical(
     336    rtems_monitor_symbol_t *canonical_symbol,
     337    rtems_symbol_t *sp
     338)
     339{
     340    canonical_symbol->value = sp->value;
     341    canonical_symbol->offset = 0;
     342    strncpy(canonical_symbol->name, sp->name, sizeof(canonical_symbol->name));
     343}
     344
     345
     346void
     347rtems_monitor_symbol_canonical_by_name(
     348    rtems_monitor_symbol_t *canonical_symbol,
     349    char                   *name
     350)
     351{
     352    rtems_symbol_t *sp;
     353
     354    sp = rtems_symbol_name_lookup(0, name);
     355
     356    canonical_symbol->value = sp ? sp->value : 0;
     357
     358    strncpy(canonical_symbol->name, name, sizeof(canonical_symbol->name));
     359    canonical_symbol->offset = 0;
     360}
     361
     362void
     363rtems_monitor_symbol_canonical_by_value(
     364    rtems_monitor_symbol_t *canonical_symbol,
     365    void                   *value_void_p
     366)
     367{
     368    unsigned32 value = (unsigned32) value_void_p;
     369    rtems_symbol_t *sp;
     370
     371    sp = rtems_symbol_value_lookup(0, value);
     372    if (sp)
     373    {
     374        canonical_symbol->value = sp->value;
     375        canonical_symbol->offset = value - sp->value;
     376        strncpy(canonical_symbol->name, sp->name, sizeof(canonical_symbol->name));
     377    }
     378    else
     379    {
     380        canonical_symbol->value = value;
     381        canonical_symbol->offset = 0;
     382        canonical_symbol->name[0] = '\0';
     383    }
     384}
     385
     386
     387unsigned32
     388rtems_monitor_symbol_dump(
     389    rtems_monitor_symbol_t *canonical_symbol,
     390    boolean                 verbose
     391)
     392{
     393    unsigned32 length = 0;
     394
     395    /*
     396     * print the name if it exists AND if value is non-zero
     397     * Ie: don't print some garbage symbol for address 0
     398     */
     399
     400    if (canonical_symbol->name[0] && (canonical_symbol->value != 0))
     401    {
     402        if (canonical_symbol->offset == 0)
     403            length += printf("%.*s",
     404                             sizeof(canonical_symbol->name),
     405                             canonical_symbol->name);
     406        else
     407            length += printf("<%.*s+0x%x>",
     408                             sizeof(canonical_symbol->name),
     409                             canonical_symbol->name,
     410                             canonical_symbol->offset);
     411        if (verbose)
     412            length += printf(" [0x%x]", canonical_symbol->value);
     413    }
     414    else
     415        length += printf("[0x%x]", canonical_symbol->value);
     416
     417    return length;
     418}
     419
     420
     421void
     422rtems_monitor_symbol_dump_all(
     423    rtems_symbol_table_t *table,
     424    boolean               verbose
     425)
     426{
     427    int s;
     428    rtems_symbol_t *sp;
     429
     430    if (table == 0)
     431    {
     432        table = rtems_monitor_symbols;
     433        if (table == 0)
     434            return;
     435    }
     436
     437    if (table->sorted == 0)
     438        rtems_symbol_sort(table);
     439
     440    for (s = 0, sp = table->symbols; s < table->next; s++, sp++)
     441    {
     442        rtems_monitor_symbol_t canonical_symbol;
     443
     444        rtems_monitor_symbol_canonical(&canonical_symbol, sp);
     445        rtems_monitor_symbol_dump(&canonical_symbol, TRUE);
     446        printf("\n");
     447    }
     448}
     449
     450
     451/*
     452 * 'symbol' command
     453 */
     454
     455void
     456rtems_monitor_symbol_cmd(
     457    int        argc,
     458    char     **argv,
     459    unsigned32 command_arg,
     460    boolean    verbose
     461)
     462{
     463    int arg;
     464    rtems_symbol_table_t *table;
     465
     466    table = *(rtems_symbol_table_t **) command_arg;
     467    if (table == 0)
     468    {
     469        table = rtems_monitor_symbols;
     470        if (table == 0)
     471            return;
     472    }
     473
     474    /*
     475     * Use object command to dump out whole symbol table
     476     */
     477    if (argc == 1)
     478        rtems_monitor_symbol_dump_all(table, verbose);
     479    else
     480    {
     481        rtems_monitor_symbol_t canonical_symbol;
     482
     483        for (arg=1; argv[arg]; arg++)
     484        {
     485            rtems_monitor_symbol_canonical_by_name(&canonical_symbol, argv[arg]);
     486            rtems_monitor_symbol_dump(&canonical_symbol, verbose);
     487            printf("\n");
     488        }
     489    }
     490}
Note: See TracChangeset for help on using the changeset viewer.