source: rtems/c/src/librdbg/src/_servtgt.c @ ce8e6a8

4.104.114.84.95
Last change on this file since ce8e6a8 was ce8e6a8, checked in by Joel Sherrill <joel.sherrill@…>, on 07/01/02 at 22:14:25

2002-07-01 Joel Sherrill <joel@…>

  • src/_servtgt.c, src/ptrace.c: Corrected use of _Objects_Information_table now that it is a two dimensional array based upon API and class.
  • Property mode set to 100644
File size: 9.9 KB
RevLine 
[4721cf1]1/*
2 ============================================================================
[981b99f]3 _SERVTGT
4 $Id$
[4721cf1]5 ============================================================================
6*/
7
[40cf43ea]8#include <string.h>
[4721cf1]9#include <rtems.h>
10#include <rtems/error.h>
11
12#include <rdbg/rdbg.h>
13#include <rdbg/rdbg_f.h>
[40cf43ea]14#include <rdbg/servrpc.h>
[4721cf1]15#include <errno.h>
[40cf43ea]16#include <sys/socket.h>
[4721cf1]17#include <assert.h>
18#include <rtems/score/cpu.h>
19
20#ifdef DDEBUG
21#define Ptrace  TgtDbgPtrace
22#else
23#define Ptrace  TgtRealPtrace
24#endif
25
26extern int errno;
27
28rtems_id eventTaskId;
29rtems_id serializeSemId;
30rtems_id wakeupEventSemId;
[40cf43ea]31rtems_id debugId;
[4721cf1]32
33CPU_Exception_frame Idle_frame;
34
35/* -----------------------------------------------------------------
36   TgtRealPtrace - lowest level ptrace() wrapper
37   ----------------------------------------------------------------- */
38
[40cf43ea]39  int
40TgtRealPtrace (int req, PID aid, char *addr, int d, void *addr2)
[4721cf1]41{
[40cf43ea]42  return ptrace (req, aid, addr, d, addr2);
[4721cf1]43}
44
45/* -----------------------------------------------------------------------
46   TgtChange() is called when the system stops.
47   It informs the generic layers must be informed of
48   that fact.
49   ----------------------------------------------------------------------- */
50
[40cf43ea]51  static int
52TgtChange (PID pid, CPU_Exception_frame * ctx, int status)
[4721cf1]53{
54
[40cf43ea]55  if (TgtHandleChildChange (pid, &status, NULL, ctx)) {
56    TgtNotifyWaitChange (pid, status, -1);
57  }
[4721cf1]58
[40cf43ea]59  return 0;
[4721cf1]60}
61
62/* -----------------------------------------------------------------------
63   eventTask
64   ----------------------------------------------------------------------- */
65
[40cf43ea]66  rtems_task
67eventTask (rtems_task_argument pid)
[4721cf1]68{
69  Exception_context *ctx;
70
71  DPRINTF (("event task: pid %d\n", pid));
72
73  /*
74   * we spend all our time waiting for a semaphore.
75   * If wait change, we send info
76   */
[40cf43ea]77
78  for (;;) {
[4721cf1]79    DPRINTF (("Event Task: wait event\n"));
[40cf43ea]80    rtems_semaphore_obtain (wakeupEventSemId, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
[4721cf1]81    DPRINTF (("Event Task: wake up !!!!!!!!!!!!!\n"));
[40cf43ea]82
[4721cf1]83    errno = 0;
[40cf43ea]84    ctx = GetExceptCtx (currentTargetThread);
[4721cf1]85
[40cf43ea]86    CheckForSingleStep (ctx->ctx);
[4721cf1]87
[40cf43ea]88    TgtChange (pid, ctx->ctx, STS_MAKESIG (ExcepToSig (ctx)));
[4721cf1]89  }
90}
91
92/* -------------------------------------------------------------------
93   MyThreadIdle -
94
95   This task is used to initiate the exception mechanism:
96   It calls the enterDebug function with justSaveContext=1
97   only to push a first valid context in the list
98   ---------------------------------------------------------------------*/
99
[40cf43ea]100  rtems_task
101MyThreadIdle (rtems_task_argument argument)
[4721cf1]102{
[40cf43ea]103  enterRdbg ();
104  rtems_task_delete (RTEMS_SELF);
[4721cf1]105}
106
107/* -----------------------------------------------------------------------
108   TgtAttach - attach to a process that is running without control.
109
110   Notes:
111      - this function performs a ptrace ATTACH equivalent (attaching to a
112        process that we do not control now).
113   ----------------------------------------------------------------------- */
114
[40cf43ea]115  Boolean
116TgtAttach (int conn_idx,        /* client that is requesting */
117           PID pid)
118{                               /* process to attach to */
[4721cf1]119  rtems_name task_name;
120  rtems_status_code status;
[40cf43ea]121
[4721cf1]122  errno = 0;
123
[40cf43ea]124  DPRINTF (("TgtAttach pid=%d\n", pid));
125
126  Ptrace (RPT_ATTACH, pid, NULL, 0, NULL);
[4721cf1]127  if (errno)
[40cf43ea]128    return (False);             /* failed */
[4721cf1]129
[40cf43ea]130  TgtCreateNew (pid, conn_idx, 0, NULL, False);
[4721cf1]131
[40cf43ea]132  connect_rdbg_exception ();
[4721cf1]133
134  /*
[40cf43ea]135   * Search for and remove debugging tasks / semaphores left over from
136   * a previous attach without a detach.
[4721cf1]137   */
[40cf43ea]138
139  if (rtems_task_ident (rtems_build_name ('E', 'v', 'n', 't'),
140                        RTEMS_SEARCH_ALL_NODES,
141                        &eventTaskId) == RTEMS_SUCCESSFUL)
142    rtems_task_delete (eventTaskId);
143
144  if (rtems_semaphore_ident (rtems_build_name ('D', 'B', 'G', 's'),
145                             RTEMS_SEARCH_ALL_NODES,
146                             &serializeSemId) == RTEMS_SUCCESSFUL)
147    rtems_semaphore_delete (serializeSemId);
148
149  if (rtems_semaphore_ident (rtems_build_name ('D', 'B', 'G', 'w'),
150                             RTEMS_SEARCH_ALL_NODES,
151                             &wakeupEventSemId) == RTEMS_SUCCESSFUL)
152    rtems_semaphore_delete (wakeupEventSemId);
153
154  /*
155   * Create the attach debugger task
156   */
157  task_name = rtems_build_name ('E', 'v', 'n', 't');
158  if ((status = rtems_task_create (task_name, 10, 24576,
159                                   RTEMS_INTERRUPT_LEVEL (0),
160                                   RTEMS_DEFAULT_ATTRIBUTES |
161                                   RTEMS_SYSTEM_TASK, &eventTaskId))
162      != RTEMS_SUCCESSFUL) {
163    printf ("status = %d\n", status);
[4721cf1]164    rtems_panic ("Can't create task.\n");
165  }
[40cf43ea]166
167  status = rtems_task_start (eventTaskId, eventTask, pid);
168
169  status = rtems_semaphore_create (rtems_build_name ('D', 'B', 'G', 's'),
170                                   1,
171                                   RTEMS_FIFO |
172                                   RTEMS_COUNTING_SEMAPHORE |
173                                   RTEMS_NO_INHERIT_PRIORITY |
174                                   RTEMS_NO_PRIORITY_CEILING |
175                                   RTEMS_LOCAL, 0, &serializeSemId);
[4721cf1]176  if (status != RTEMS_SUCCESSFUL)
[40cf43ea]177    rtems_panic ("Can't create serialize semaphore: `%s'\n",
178                 rtems_status_text (status));
179
180  status = rtems_semaphore_create (rtems_build_name ('D', 'B', 'G', 'w'),
181                                   0,
182                                   RTEMS_FIFO |
183                                   RTEMS_COUNTING_SEMAPHORE |
184                                   RTEMS_NO_INHERIT_PRIORITY |
185                                   RTEMS_NO_PRIORITY_CEILING |
186                                   RTEMS_LOCAL, 0, &wakeupEventSemId);
[4721cf1]187  if (status != RTEMS_SUCCESSFUL)
[40cf43ea]188    rtems_panic ("Can't create wakeup semaphore: `%s'\n",
189                 rtems_status_text (status));
[4721cf1]190
191  /*
192   * Create the MyThreadIdle task to init Exception mechanism
193   */
[40cf43ea]194  task_name = rtems_build_name ('R', 'i', 'n', 'i');
195  if ((status = rtems_task_create (task_name, 10, 24576,
196                                   RTEMS_INTERRUPT_LEVEL (0),
197                                   RTEMS_DEFAULT_ATTRIBUTES, &debugId))
198      != RTEMS_SUCCESSFUL) {
199    printf ("status = %d (%s)\n", status, rtems_status_text (status));
[4721cf1]200    rtems_panic ("Can't create task.\n");
201  }
202
[40cf43ea]203  status = rtems_task_start (debugId, MyThreadIdle, pid);
[4721cf1]204
[40cf43ea]205  return (True);
[4721cf1]206}
207
208/* -----------------------------------------------------------------------
209   TgtPtrace - handle ptrace requests for server.
210   ----------------------------------------------------------------------- */
211
[40cf43ea]212int
213TgtPtrace (int req, PID pid, char *addr, int data, void *addr2)
[4721cf1]214{
215  if ((req == RPT_SINGLESTEP || req == RPT_CONT)
[40cf43ea]216      && addr2) {               /* clear then step *//* addr2 is the old value */
217
218    int ret;
[4721cf1]219
220    errno = 0;
221    TgtBreakRestoreOrig (pid, addr, addr2);
[40cf43ea]222    ret = Ptrace (RPT_SINGLESTEP, pid, addr, data, NULL);   /* step over */
223    if (ret) {                  /* error, cannot single-step */
[4721cf1]224      int pid_idx = FindPidEntry (pid);
[40cf43ea]225      TgtBreakCancelStep (&pid_list[pid_idx]);
[4721cf1]226    }
[40cf43ea]227    return (ret);               /* failed or done */
228  } else
229      return (Ptrace (req, pid, addr, data, addr2));  /* normal call */
[4721cf1]230}
231
232/* -----------------------------------------------------------------
233   TgtGetThreadName - get thread name
234   --------------------------------------------------------------- */
235
[40cf43ea]236  int
237TgtGetThreadName (PID_LIST * plst,  /* Process entry */
238                  unsigned Id,  /* Thread ID */
239                  char *ThrName)
240{                               /* Thread name */
241  int index;
242  unsigned name;
243
[ce8e6a8]244  if (Id < _Objects_Information_table[OBJECTS_CLASSIC_API][1]->maximum_id &&
245      Id > _Objects_Information_table[OBJECTS_CLASSIC_API][1]->minimum_id) {
[40cf43ea]246
[ce8e6a8]247    index = Id - _Objects_Information_table[OBJECTS_CLASSIC_API][1]->minimum_id;
[40cf43ea]248    name =
[ce8e6a8]249      *(unsigned *) (_Objects_Information_table[OBJECTS_CLASSIC_API][1]->
[40cf43ea]250                     local_table[1 + index]->name);
251    ThrName[0] = (char) ((name >> 24) & 0xFF);
252    ThrName[1] = (char) ((name >> 16) & 0xFF);
253    ThrName[2] = (char) ((name >> 8) & 0xFF);
254    ThrName[3] = (char) (name & 0xFF);
255    ThrName[4] = 0x0;
256    return 0;
257  }
258
[ce8e6a8]259  if (Id < _Objects_Information_table[OBJECTS_POSIX_API][1]->maximum_id &&
260      Id > _Objects_Information_table[OBJECTS_POSIX_API][1]->minimum_id) {
[40cf43ea]261
262    index =
[ce8e6a8]263      Id - _Objects_Information_table[OBJECTS_POSIX_API][1]->minimum_id;
[40cf43ea]264    name =
[ce8e6a8]265      *(unsigned *) (_Objects_Information_table[OBJECTS_POSIX_API][1]->
[40cf43ea]266                     local_table[1 + index]->name);
267    ThrName[0] = (char) ((name >> 24) & 0xFF);
268    ThrName[1] = (char) ((name >> 16) & 0xFF);
269    ThrName[2] = (char) ((name >> 8) & 0xFF);
270    ThrName[3] = (char) (name & 0xFF);
271    ThrName[4] = 0x0;
272    return 0;
273  }
[4721cf1]274
[40cf43ea]275  return -1;
[4721cf1]276}
277
278/* -----------------------------------------------------------------
279   TgtThreadList - return all the threads in the system
280   ----------------------------------------------------------------- */
281
[40cf43ea]282  int
283TgtThreadList (PID_LIST * plst, /* Process entry */
284               unsigned *threads,   /* Output buffer */
285               unsigned size)
286{                               /* Output buffer size */
287  int curr = 0;
288  Objects_Id id;
289  unsigned index;
290
[ce8e6a8]291  id = _Objects_Information_table[OBJECTS_CLASSIC_API][1]->minimum_id;
[40cf43ea]292
[ce8e6a8]293  while (id < _Objects_Information_table[OBJECTS_CLASSIC_API][1]->maximum_id) {
294    index = id - _Objects_Information_table[OBJECTS_CLASSIC_API][1]->minimum_id;
295    if (_Objects_Information_table[OBJECTS_CLASSIC_API][1]->
[40cf43ea]296        local_table[1 + index] != NULL) {
[4721cf1]297      threads[curr] = (unsigned) id;
298      curr++;
299    }
[40cf43ea]300    id++;
301  }
302
[ce8e6a8]303  id = _Objects_Information_table[OBJECTS_POSIX_API][1]->minimum_id;
[4721cf1]304
[ce8e6a8]305  while (id < _Objects_Information_table[OBJECTS_POSIX_API][1]->maximum_id) {
[40cf43ea]306    index =
[ce8e6a8]307      id - _Objects_Information_table[OBJECTS_POSIX_API][1]->minimum_id;
308    if (_Objects_Information_table[OBJECTS_POSIX_API][1]->
[40cf43ea]309        local_table[1 + index] != NULL) {
[4721cf1]310      threads[curr] = (unsigned) id;
311      curr++;
312    }
[40cf43ea]313    id++;
314  }
315
[ce8e6a8]316#warning "ignores ITRON tasks and could be a single loop"
317
[40cf43ea]318  return curr;
[4721cf1]319}
Note: See TracBrowser for help on using the repository browser.