OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [librdbg/] [src/] [_servtgt.c] - Blame information for rev 389

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.