source: rtems/c/src/librdbg/src/_servtgt.c @ 35290c9

4.104.114.84.95
Last change on this file since 35290c9 was 40cf43ea, checked in by Joel Sherrill <joel.sherrill@…>, on 02/01/02 at 17:00:01
  • So many patches have been posted recently on the mailing list and because we were unable to find correct solution to compile on various linux distros (due to rpcgen incompatibilities), and because the coding style of rdbg was rather inconsistant among various pieces of code, I decided to:

1) make some cleaning regarding global coding style (using

indent + manual edits),

2) incorporate/review the paches send by various people

(S. Holford, T. Strauman),

3) Fix the bug due to varying rpcgen code generation

in remdeb_svc.c,

4) Remove some dead code,
5) Apply a patches enabling to call enterRdbg imediately

after rdbg initialization is done,

NB : the paches is huge but it is mainly due to coding styke chnages.
Only few lines of codes have been really changed and they do not impact
rdbg functionnality (AFAIKT).

  • include/rdbg/servrpc.h, include/rdbg/i386/rdbg_f.h, include/rdbg/m68k/rdbg_f.h, include/rdbg/powerpc/rdbg_f.h, src/_servtgt.c, src/awk.svc, src/excep.c, src/ptrace.c, src/rdbg.c, src/remdeb.x, src/servbkpt.c, src/servcon.c, src/servrpc.c, src/servtgt.c, src/servtsp.c, src/servutil.c, src/i386/excep_f.c, src/i386/rdbg_f.c, src/i386/any/Makefile.am, src/i386/any/remdeb.h, src/i386/any/remdeb_svc.c, src/i386/any/remdeb_xdr.c, src/m68k/excep_f.c, src/m68k/rdbg_f.c, src/m68k/any/Makefile.am, src/m68k/any/remdeb.h, src/m68k/any/remdeb_svc.c, src/m68k/any/remdeb_xdr.c, src/powerpc/excep_f.c, src/powerpc/rdbg_f.c, src/powerpc/new_exception_processing/Makefile.am, src/powerpc/new_exception_processing/remdeb.h, src/powerpc/new_exception_processing/remdeb_svc.c, src/powerpc/new_exception_processing/remdeb_xdr.c: Modified.
  • Property mode set to 100644
File size: 9.9 KB
Line 
1/*
2 ============================================================================
3 _SERVTGT
4 $Id$
5 ============================================================================
6*/
7
8#include <string.h>
9#include <rtems.h>
10#include <rtems/error.h>
11
12#include <rdbg/rdbg.h>
13#include <rdbg/rdbg_f.h>
14#include <rdbg/servrpc.h>
15#include <errno.h>
16#include <sys/socket.h>
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;
31rtems_id debugId;
32
33CPU_Exception_frame Idle_frame;
34
35/* -----------------------------------------------------------------
36   TgtRealPtrace - lowest level ptrace() wrapper
37   ----------------------------------------------------------------- */
38
39  int
40TgtRealPtrace (int req, PID aid, char *addr, int d, void *addr2)
41{
42  return ptrace (req, aid, addr, d, addr2);
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
51  static int
52TgtChange (PID pid, CPU_Exception_frame * ctx, int status)
53{
54
55  if (TgtHandleChildChange (pid, &status, NULL, ctx)) {
56    TgtNotifyWaitChange (pid, status, -1);
57  }
58
59  return 0;
60}
61
62/* -----------------------------------------------------------------------
63   eventTask
64   ----------------------------------------------------------------------- */
65
66  rtems_task
67eventTask (rtems_task_argument pid)
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   */
77
78  for (;;) {
79    DPRINTF (("Event Task: wait event\n"));
80    rtems_semaphore_obtain (wakeupEventSemId, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
81    DPRINTF (("Event Task: wake up !!!!!!!!!!!!!\n"));
82
83    errno = 0;
84    ctx = GetExceptCtx (currentTargetThread);
85
86    CheckForSingleStep (ctx->ctx);
87
88    TgtChange (pid, ctx->ctx, STS_MAKESIG (ExcepToSig (ctx)));
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
100  rtems_task
101MyThreadIdle (rtems_task_argument argument)
102{
103  enterRdbg ();
104  rtems_task_delete (RTEMS_SELF);
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
115  Boolean
116TgtAttach (int conn_idx,        /* client that is requesting */
117           PID pid)
118{                               /* process to attach to */
119  rtems_name task_name;
120  rtems_status_code status;
121
122  errno = 0;
123
124  DPRINTF (("TgtAttach pid=%d\n", pid));
125
126  Ptrace (RPT_ATTACH, pid, NULL, 0, NULL);
127  if (errno)
128    return (False);             /* failed */
129
130  TgtCreateNew (pid, conn_idx, 0, NULL, False);
131
132  connect_rdbg_exception ();
133
134  /*
135   * Search for and remove debugging tasks / semaphores left over from
136   * a previous attach without a detach.
137   */
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);
164    rtems_panic ("Can't create task.\n");
165  }
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);
176  if (status != RTEMS_SUCCESSFUL)
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);
187  if (status != RTEMS_SUCCESSFUL)
188    rtems_panic ("Can't create wakeup semaphore: `%s'\n",
189                 rtems_status_text (status));
190
191  /*
192   * Create the MyThreadIdle task to init Exception mechanism
193   */
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));
200    rtems_panic ("Can't create task.\n");
201  }
202
203  status = rtems_task_start (debugId, MyThreadIdle, pid);
204
205  return (True);
206}
207
208/* -----------------------------------------------------------------------
209   TgtPtrace - handle ptrace requests for server.
210   ----------------------------------------------------------------------- */
211
212int
213TgtPtrace (int req, PID pid, char *addr, int data, void *addr2)
214{
215  if ((req == RPT_SINGLESTEP || req == RPT_CONT)
216      && addr2) {               /* clear then step *//* addr2 is the old value */
217
218    int ret;
219
220    errno = 0;
221    TgtBreakRestoreOrig (pid, addr, addr2);
222    ret = Ptrace (RPT_SINGLESTEP, pid, addr, data, NULL);   /* step over */
223    if (ret) {                  /* error, cannot single-step */
224      int pid_idx = FindPidEntry (pid);
225      TgtBreakCancelStep (&pid_list[pid_idx]);
226    }
227    return (ret);               /* failed or done */
228  } else
229      return (Ptrace (req, pid, addr, data, addr2));  /* normal call */
230}
231
232/* -----------------------------------------------------------------
233   TgtGetThreadName - get thread name
234   --------------------------------------------------------------- */
235
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
244  if (Id < _Objects_Information_table[OBJECTS_RTEMS_TASKS]->maximum_id &&
245      Id > _Objects_Information_table[OBJECTS_RTEMS_TASKS]->minimum_id) {
246
247    index = Id - _Objects_Information_table[OBJECTS_RTEMS_TASKS]->minimum_id;
248    name =
249      *(unsigned *) (_Objects_Information_table[OBJECTS_RTEMS_TASKS]->
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
259  if (Id < _Objects_Information_table[OBJECTS_POSIX_THREADS]->maximum_id &&
260      Id > _Objects_Information_table[OBJECTS_POSIX_THREADS]->minimum_id) {
261
262    index =
263      Id - _Objects_Information_table[OBJECTS_POSIX_THREADS]->minimum_id;
264    name =
265      *(unsigned *) (_Objects_Information_table[OBJECTS_POSIX_THREADS]->
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  }
274
275  return -1;
276}
277
278/* -----------------------------------------------------------------
279   TgtThreadList - return all the threads in the system
280   ----------------------------------------------------------------- */
281
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
291  id = _Objects_Information_table[OBJECTS_RTEMS_TASKS]->minimum_id;
292
293  while (id < _Objects_Information_table[OBJECTS_RTEMS_TASKS]->maximum_id) {
294    index = id - _Objects_Information_table[OBJECTS_RTEMS_TASKS]->minimum_id;
295    if (_Objects_Information_table[OBJECTS_RTEMS_TASKS]->
296        local_table[1 + index] != NULL) {
297      threads[curr] = (unsigned) id;
298      curr++;
299    }
300    id++;
301  }
302
303  id = _Objects_Information_table[OBJECTS_POSIX_THREADS]->minimum_id;
304
305  while (id < _Objects_Information_table[OBJECTS_POSIX_THREADS]->maximum_id) {
306    index =
307      id - _Objects_Information_table[OBJECTS_POSIX_THREADS]->minimum_id;
308    if (_Objects_Information_table[OBJECTS_POSIX_THREADS]->
309        local_table[1 + index] != NULL) {
310      threads[curr] = (unsigned) id;
311      curr++;
312    }
313    id++;
314  }
315
316  return curr;
317}
Note: See TracBrowser for help on using the repository browser.