Changeset 17e09f8 in rtems


Ignore:
Timestamp:
May 27, 2013, 3:29:47 PM (6 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
e3be691
Parents:
5b391f85
git-author:
Sebastian Huber <sebastian.huber@…> (05/27/13 15:29:47)
git-committer:
Sebastian Huber <sebastian.huber@…> (05/31/13 13:20:31)
Message:

bsps: Use _Objects_Information_table

Eliminate copy and paste. Use the _Objects_Information_table since this
will take into account that more than one internal thread may exist,
e.g. MPCI thread or idle threads of secondary processors.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/shared/gdbstub/rtems-stub-glue.c

    r5b391f85 r17e09f8  
    6565 */
    6666
    67 int rtems_gdb_stub_id_to_index(
     67static int rtems_gdb_stub_id_to_index(
    6868  Objects_Id thread_obj_id
    6969)
    7070{
    71   Objects_Id min_id, max_id;
    72   int first_posix_id, first_rtems_id;
    73   Objects_Information *obj_info;
     71  int gdb_index = 0;
     72  int first = 1;
     73  size_t api_index;
    7474
    7575  if (_System_state_Get() != SYSTEM_STATE_UP) {
    7676    /* We have one thread let us use value reserved for idle thread */
    77     return 1;
     77    gdb_index = 1;
    7878  }
    7979
    80   if (_Thread_Executing == _Thread_Idle) {
    81     return 1;
     80  for (
     81    api_index = 1;
     82    gdb_index == 0 && api_index <= OBJECTS_APIS_LAST;
     83    ++api_index
     84  ) {
     85    if (_Objects_Information_table[api_index] != NULL) {
     86      const Objects_Information *info =
     87        _Objects_Information_table[api_index][1];
     88      Objects_Id min_id = info->minimum_id;
     89      Objects_Id max_id = info->maximum_id;
     90      int last = first + (int) (max_id - min_id);
     91
     92      if (thread_obj_id >= min_id && thread_obj_id < max_id) {
     93        gdb_index = first + (int) (thread_obj_id - min_id);
     94      }
     95
     96      first = last + 1;
     97    }
    8298  }
    8399
    84   /* Let us figure out thread_id for gdb */
    85   first_rtems_id = 2;
    86 
    87   obj_info = _Objects_Information_table[OBJECTS_CLASSIC_API][1];
    88 
    89   min_id = obj_info->minimum_id;
    90   max_id = obj_info->maximum_id;
    91 
    92   if (thread_obj_id >= min_id && thread_obj_id < max_id) {
    93     return first_rtems_id + (thread_obj_id - min_id);
    94   }
    95 
    96   first_posix_id = first_rtems_id + (max_id - min_id) + 1;
    97 
    98   min_id = _Objects_Information_table[OBJECTS_POSIX_API][1]->minimum_id;
    99 
    100   return first_posix_id + (thread_obj_id - min_id);
     100  return gdb_index;
    101101}
    102102
    103103/* Return the RTEMS thread id from a gdb thread id */
    104104Thread_Control *rtems_gdb_index_to_stub_id(
    105   int thread
     105  int gdb_index
    106106)
    107107{
    108    Objects_Id thread_obj_id;
    109    Objects_Id min_id, max_id;
    110    int first_posix_id, first_rtems_id;
    111    Objects_Information *obj_info;
    112    Thread_Control *th;
    113 
    114    ASSERT(registers != NULL);
    115 
    116    if (_System_state_Get() != SYSTEM_STATE_UP || thread <= 0) {
    117       /* Should not happen */
    118       return NULL;
    119    }
    120 
    121    if (thread == 1) {
    122       th = _Thread_Idle;
    123       goto found;
    124    }
    125 
    126    /* Let us get object associtated with current thread */
    127    first_rtems_id = 2;
    128 
    129    thread_obj_id = _Thread_Executing->Object.id;
    130 
    131    /* Let us figure out thread_id for gdb */
    132    obj_info = _Objects_Information_table[OBJECTS_CLASSIC_API][1];
    133 
    134    min_id = obj_info->minimum_id;
    135    max_id = obj_info->maximum_id;
    136 
    137    if (thread <= (first_rtems_id + (max_id - min_id))) {
    138       th = (Thread_Control *)(obj_info->local_table[thread - first_rtems_id + 1]);
    139 
    140       if (th != NULL) {
    141          goto found;
     108  Thread_Control *th = NULL;
     109  int first = 1;
     110  size_t api_index;
     111
     112  ASSERT(registers != NULL);
     113
     114  if (_System_state_Get() != SYSTEM_STATE_UP || gdb_index <= 0) {
     115     /* Should not happen */
     116     return NULL;
     117  }
     118
     119  for (
     120    api_index = 1;
     121    th == NULL && api_index <= OBJECTS_APIS_LAST;
     122    ++api_index
     123  ) {
     124    if (_Objects_Information_table[api_index] != NULL) {
     125      const Objects_Information *info =
     126        _Objects_Information_table[api_index][1];
     127      Objects_Id min_id = info->minimum_id;
     128      Objects_Id max_id = info->maximum_id;
     129      int last = first + (int) (max_id - min_id);
     130
     131      if (gdb_index <= first + (int) (max_id - min_id)) {
     132        th = (Thread_Control *)
     133          info->local_table[gdb_index - first + 1];
    142134      }
    143135
    144       /* Thread does not exist */
    145       return NULL;
    146    }
    147 
    148    first_posix_id = first_rtems_id + (max_id - min_id) + 1;
    149 
    150    obj_info = _Objects_Information_table[OBJECTS_POSIX_API][1];
    151 
    152    min_id = obj_info->minimum_id;
    153    max_id = obj_info->maximum_id;
    154 
    155    th = (Thread_Control *)(obj_info->local_table[thread - first_posix_id + 1]);
    156    if (th == NULL) {
    157       /* Thread does not exist */
    158       return NULL;
    159    }
    160 
    161   found:
    162    return th;
     136      first = last + 1;
     137    }
     138  }
     139
     140  return th;
    163141}
    164142
     
    171149/* Get id of the next thread after athread, if argument <= 0 find the
    172150   first available thread, return thread if found or 0 if not */
    173 int rtems_gdb_stub_get_next_thread(int athread)
    174 {
    175   Objects_Id id, min_id, max_id;
    176   int lim, first_posix_id, first_rtems_id;
    177   Objects_Information *obj_info;
    178   int start;
     151int rtems_gdb_stub_get_next_thread(int gdb_index)
     152{
     153  int next_gdb_index = 0;
     154  int first = 1;
     155  size_t api_index;
    179156
    180157  if (_System_state_Get() != SYSTEM_STATE_UP) {
    181158    /* We have one thread let us use value of idle thread */
    182     return (athread < 1) ? 1 : 0;
     159    return (gdb_index < 1) ? 1 : 0;
    183160  }
    184161
    185   if (athread < 1) {
    186     return 1;
     162  for (
     163    api_index = 1;
     164    next_gdb_index == 0 && api_index <= OBJECTS_APIS_LAST;
     165    ++api_index
     166  ) {
     167    if (_Objects_Information_table[api_index] != NULL) {
     168      const Objects_Information *info =
     169        _Objects_Information_table[api_index][1];
     170      Objects_Id min_id = info->minimum_id;
     171      Objects_Id max_id = info->maximum_id;
     172      int last = first + (int) (max_id - min_id);
     173
     174      if (gdb_index <= last) {
     175        int start = gdb_index < first ? first : gdb_index + 1;
     176        int potential_next;
     177
     178        for (
     179          potential_next = start;
     180          next_gdb_index == 0 && potential_next <= last;
     181          ++potential_next
     182        ) {
     183          if (info->local_table[potential_next - first + 1] != NULL) {
     184            next_gdb_index = potential_next;
     185          }
     186        }
     187      }
     188
     189      first = last + 1;
     190    }
    187191  }
    188192
    189   first_rtems_id = 2;
    190 
    191   obj_info = _Objects_Information_table[OBJECTS_CLASSIC_API][1];
    192 
    193   min_id = obj_info->minimum_id;
    194   max_id = obj_info->maximum_id;
    195 
    196   lim = first_rtems_id + max_id - min_id;
    197 
    198   if (athread < lim) {
    199     if (athread < first_rtems_id) {
    200       start = first_rtems_id;
    201     } else {
    202       start = 1 + athread;
    203     }
    204 
    205     for (id=start; id<=lim; id++) {
    206       if (obj_info->local_table[id - first_rtems_id + 1] != NULL) {
    207         return id;
    208       }
    209     }
    210   }
    211 
    212   first_posix_id = first_rtems_id + (max_id - min_id) + 1;
    213 
    214   obj_info = _Objects_Information_table[OBJECTS_POSIX_API][1];
    215 
    216   min_id = obj_info->minimum_id;
    217   max_id = obj_info->maximum_id;
    218 
    219   lim = first_posix_id + (max_id - min_id);
    220 
    221   if (athread < lim) {
    222     if (athread < first_posix_id) {
    223       start = first_posix_id;
    224     } else {
    225       start = 1 + athread;
    226     }
    227 
    228     for (id=start; id<=lim; id++) {
    229       if (obj_info->local_table[id - first_posix_id + 1] != NULL) {
    230         return id;
    231       }
    232     }
    233   }
    234 
    235   /* Not found */
    236   return 0;
     193  return next_gdb_index;
    237194}
    238195
     
    274231/* Get thread information, return 0 if thread does not
    275232   exist and 1 otherwise */
    276 int rtems_gdb_stub_get_thread_info(
    277   int thread,
     233static int rtems_gdb_stub_get_thread_info(
     234  int gdb_index,
    278235  struct rtems_gdb_stub_thread_info *info
    279236)
    280237{
    281    Objects_Id thread_obj_id;
    282    Objects_Id min_id, max_id;
    283    int first_posix_id, first_rtems_id;
    284    Objects_Information *obj_info;
    285    Thread_Control *th;
    286    char tmp_buf[20];
     238   int first = 1;
     239   size_t api_index;
    287240
    288241   ASSERT(info != NULL);
    289242
    290    if (thread <= 0) {
     243   if (gdb_index <= 0) {
    291244      return 0;
    292245   }
    293246
    294    if (_System_state_Get() != SYSTEM_STATE_UP || thread == 1) {
     247   if (_System_state_Get() != SYSTEM_STATE_UP || gdb_index == 1) {
    295248      /* We have one thread let us use value
    296249         which will never happen for real thread */
     
    302255   }
    303256
    304    /* Let us get object associtated with current thread */
    305    thread_obj_id = _Thread_Executing->Object.id;
    306 
    307    /* Let us figure out thread_id for gdb */
    308    first_rtems_id = 2;
    309 
    310    obj_info = _Objects_Information_table[OBJECTS_CLASSIC_API][1];
    311 
    312    min_id = obj_info->minimum_id;
    313    max_id = obj_info->maximum_id;
    314 
    315    if (thread <= (first_rtems_id + (max_id - min_id))) {
    316       th = (Thread_Control *)(obj_info->local_table[thread -
    317                                                     first_rtems_id + 1]);
    318 
    319       if (th == NULL) {
    320          /* Thread does not exist */
    321          return 0;
    322       }
    323 
    324       strcpy(info->display, "rtems task:   control at 0x");
    325 
    326       tmp_buf[0] = gdb_hexchars[(((int)th) >> 28) & 0xf];
    327       tmp_buf[1] = gdb_hexchars[(((int)th) >> 24) & 0xf];
    328       tmp_buf[2] = gdb_hexchars[(((int)th) >> 20) & 0xf];
    329       tmp_buf[3] = gdb_hexchars[(((int)th) >> 16) & 0xf];
    330       tmp_buf[4] = gdb_hexchars[(((int)th) >> 12) & 0xf];
    331       tmp_buf[5] = gdb_hexchars[(((int)th) >> 8) & 0xf];
    332       tmp_buf[6] = gdb_hexchars[(((int)th) >> 4) & 0xf];
    333       tmp_buf[7] = gdb_hexchars[((int)th) & 0xf];
    334       tmp_buf[8] = 0;
    335 
    336       strcat(info->display, tmp_buf);
    337       rtems_object_get_name( ((Objects_Control*)th)->id, 5, info->name );
    338       info->more_display[0] = 0; /* Nothing */
    339 
    340       return 1;
     257   for (
     258     api_index = 1;
     259     api_index <= OBJECTS_APIS_LAST;
     260     ++api_index
     261   ) {
     262     if (_Objects_Information_table[api_index] != NULL) {
     263       const Objects_Information *obj_info =
     264         _Objects_Information_table[api_index][1];
     265       Objects_Id min_id = obj_info->minimum_id;
     266       Objects_Id max_id = obj_info->maximum_id;
     267       int last = first + (int) (max_id - min_id);
     268
     269       if (gdb_index <= last) {
     270         Thread_Control *th = (Thread_Control *)
     271           obj_info->local_table[gdb_index - first + 1];
     272
     273         if (th != NULL) {
     274           char tmp_buf[9];
     275
     276           strcpy(info->display, "task: control at 0x");
     277
     278           tmp_buf[0] = gdb_hexchars[(((int)th) >> 28) & 0xf];
     279           tmp_buf[1] = gdb_hexchars[(((int)th) >> 24) & 0xf];
     280           tmp_buf[2] = gdb_hexchars[(((int)th) >> 20) & 0xf];
     281           tmp_buf[3] = gdb_hexchars[(((int)th) >> 16) & 0xf];
     282           tmp_buf[4] = gdb_hexchars[(((int)th) >> 12) & 0xf];
     283           tmp_buf[5] = gdb_hexchars[(((int)th) >> 8) & 0xf];
     284           tmp_buf[6] = gdb_hexchars[(((int)th) >> 4) & 0xf];
     285           tmp_buf[7] = gdb_hexchars[((int)th) & 0xf];
     286           tmp_buf[8] = 0;
     287
     288           strcat(info->display, tmp_buf);
     289           rtems_object_get_name( th->Object.id, 5, info->name );
     290           info->more_display[0] = 0; /* Nothing */
     291
     292           return 1;
     293         } else {
     294           /* Thread does not exist */
     295           return 0;
     296         }
     297       }
     298
     299       first = last + 1;
     300     }
    341301   }
    342302
    343    first_posix_id = first_rtems_id + (max_id - min_id) + 1;
    344 
    345    obj_info = _Objects_Information_table[OBJECTS_POSIX_API][1];
    346 
    347    min_id = obj_info->minimum_id;
    348    max_id = obj_info->maximum_id;
    349 
    350    th = (Thread_Control *)(obj_info->local_table[thread - first_posix_id + 1]);
    351    if (th == NULL) {
    352       /* Thread does not exist */
    353       return 0;
    354    }
    355 
    356    strcpy(info->display, "posix thread: control at 0x");
    357 
    358    tmp_buf[0] = gdb_hexchars[(((int)th) >> 28) & 0xf];
    359    tmp_buf[1] = gdb_hexchars[(((int)th) >> 24) & 0xf];
    360    tmp_buf[2] = gdb_hexchars[(((int)th) >> 20) & 0xf];
    361    tmp_buf[3] = gdb_hexchars[(((int)th) >> 16) & 0xf];
    362    tmp_buf[4] = gdb_hexchars[(((int)th) >> 12) & 0xf];
    363    tmp_buf[5] = gdb_hexchars[(((int)th) >> 8) & 0xf];
    364    tmp_buf[6] = gdb_hexchars[(((int)th) >> 4) & 0xf];
    365    tmp_buf[7] = gdb_hexchars[((int)th) & 0xf];
    366    tmp_buf[8] = 0;
    367 
    368    strcat(info->display, tmp_buf);
    369    rtems_object_get_name( ((Objects_Control*)th)->id, 5, info->name );
    370    info->more_display[0] = 0; /* Nothing */
    371 
    372    return 1;
     303   return 0;
    373304}
    374305
Note: See TracChangeset for help on using the changeset viewer.