source: rtems/c/src/lib/librdbg/remdeb.x @ c0438add

4.104.114.84.95
Last change on this file since c0438add was 4721cf1, checked in by Joel Sherrill <joel.sherrill@…>, on 12/03/98 at 23:54:14

Patch from Emmanuel Raguet <raguet@…> to add remote debug server
and RPC support to RTEMS. Thanks. :) Email follows:

Hello,

For Xmas, here is the Remote Debugger on RTEMS !

Here are 2 patches for the Remote Debugger on RTEMS for pc386 from Linux
host :

  • one for RTEMS it self,
  • one for GDB-4.17.

1/ RTEMS patch
--------------

This patch adds 2 libraries :

  • a simplified SUN RPC library
  • the Remote Debugger library

The configuration command is the following :
../rtems4/configure --target=i386-rtemself --enable-rtemsbsp=pc386
--enable-rdbg

The SUN RPC library is built only if networking is set.
The RDBG library is built if networking and enable-rdbg are set.

The function used to initialize the debugger is :

rtems_rdbg_initialize ();

A special function has been created to force a task to be
in a "debug" state : enterRdbg().
The use of this function is not mandatory.

2/ GDB-4.17 patch
-----------------

This patch create a new RTEMS target for GDB-4.17.

The configuration command is the following :
./configure --enable-shared --target=i386RTEMS

To connect to a target, use :

target rtems [your_site_address]

Then, attach the target using : attach 1

And... Debug ;)

You can obtain the original GDB-4.17 on
ftp://ftp.debian.org/debian/dists/stable/main/source/devel/gdb_4.17.orig.tar.gz

This has been tested from a Debian 2.0.1 linux host.

  • Property mode set to 100644
File size: 15.2 KB
Line 
1/*
2 **********************************************************************
3 *
4 *  Component:  RDBG servers
5 *  Module:     remdeb.x
6 *
7 *  Synopsis:   XDR definitions for remote debug server RPC calls.
8 *              XDR definitions for RPCGEN to build remote debug server.
9 *
10 **********************************************************************
11 */
12
13#ifdef RPC_SVC
14%/*HEADER_START*/
15#endif
16
17%#define RTEMS_PORT 2071
18%#define RTEMS_BACK_PORT 2073
19
20#ifdef   RPC_HDR
21%#ifndef REMDEB_H
22%#define RPCGENSRVNAME(a)     a
23#endif
24
25enum rpc_type {
26        SUNRPC          = 0,
27        BADRPCTYPE      = 25
28};
29
30
31const NET_SAFE = 1400;  /* this is safe for UDP messages */
32
33struct UDP_MSG
34{                               /* format of UDP messages (should be in .h) */
35  unsigned char  type;          /* type of message (BMSG_xx) */
36  unsigned char  msg_num;       /* ringed number for resend detect */
37  unsigned short spec;          /* specific information for type */
38  long           pid;           /* process this affects */
39  unsigned long  context;       /* specific information to request */
40};
41
42  /* First we support the overhead structures and types needed for RPC
43        requests. Then, we have all RPC routines input/output args.     */
44
45%/*
46% * Sun request values for the remote ptrace system call
47% */
48%
49enum ptracereq
50{                               /* these match PTRACE_xxx numbers */
51  RPT_TRACEME = 0,              /* 0, by tracee to begin tracing */
52  RPT_CHILDDONE = 0,            /* 0, tracee is done with his half */
53  RPT_PEEKTEXT,                 /* 1, read word from text segment */
54  RPT_PEEKDATA,                 /* 2, read word from data segment */
55  RPT_PEEKUSER,                 /* 3, read word from user struct */
56  RPT_POKETEXT,                 /* 4, write word into text segment */
57  RPT_POKEDATA,                 /* 5, write word into data segment */
58  RPT_POKEUSER,                 /* 6, write word into user struct */
59  RPT_CONT,                     /* 7, continue process */
60  RPT_KILL,                     /* 8, terminate process */
61  RPT_SINGLESTEP,               /* 9, single step process */
62  RPT_ATTACH,                   /* 10, attach to an existing process (returns 2 if not primary)*/
63  RPT_DETACH,                   /* 11, detach from a process */
64  RPT_GETREGS,                  /* 12, get all registers */
65  RPT_SETREGS,                  /* 13, set all registers */
66  RPT_GETFPREGS,                /* 14, get all floating point regs */
67  RPT_SETFPREGS,                /* 15, set all floating point regs */
68  RPT_READDATA,                 /* 16, read data segment */
69  RPT_WRITEDATA,                /* 17, write data segment */
70  RPT_READTEXT,                 /* 18, read text segment */
71  RPT_WRITETEXT,                /* 19, write text segment */
72  RPT_GETFPAREGS,               /* 20, get all fpa regs */
73  RPT_SETFPAREGS,               /* 21, set all fpa regs */
74  RPT_22,                       /* 22, filler */
75  RPT_23,                       /* 23, filler */
76  RPT_SYSCALL,                  /* 24, trap next sys call */
77  RPT_DUMPCORE,                 /* 25, dump process core */
78  RPT_26,                       /* 26, filler */
79  RPT_27,                       /* 27, filler */
80  RPT_28,                       /* 28, filler */
81  RPT_GETUCODE,                 /* 29, get u.u_code */
82  /* Begin  specific ptrace options */
83  RPT_GETTARGETTHREAD = 50,     /* get PM target thread identifier */
84  RPT_SETTARGETTHREAD = 51,     /* set PM target thread identifier */
85  RPT_THREADSUSPEND   = 52,     /* suspend a thread */
86  RPT_THREADRESUME    = 53,     /* resume a thread */
87  RPT_THREADLIST      = 54,     /* get list of process's threads */
88  RPT_GETTHREADNAME   = 55,     /* get the name of the thread */
89  RPT_SETTHREADNAME   = 56,     /* set the name of the thread */
90  RPT_SETTHREADREGS   = 57,     /* set all registers for a specific thread*/
91  RPT_GETTHREADREGS   = 58,     /* get all registers for a specific thread*/
92  /* Begin extended ptrace options for remote debug server */
93  RPT_STEPRANGE       = 75,     /* step while in range (addr=start, data=len) */
94  RPT_CONTTO          = 76,     /* cont from PC to temp break in addr */
95  RPT_SETBREAK        = 77,     /* set a breakpoint (addr=break) */
96  RPT_CLRBREAK        = 78,     /* clear a breakpoint (data=handle or 0 for all) */
97  RPT_GETBREAK        = 79,     /* get breakpoint (data=handle, addr=buffer to
98                                   fill). Returns next break. If data=0,
99                                   returns number of breaks. */                 
100  RPT_GETNAME         = 80,     /* get name of process (data 0=name, 1=path
101                                   as started, 2=fullpath). Return in addr
102                                   as mem) */
103  RPT_STOP            = 81,     /* (C-actors) Stop the C-actor */
104  RPT_PGETREGS        = 82,     /* portable version */
105  RPT_PSETREGS        = 83,     /* portable version */
106  RPT_PSETTHREADREGS  = 84,     /* portable version */
107  RPT_PGETTHREADREGS  = 85      /* portable version */
108};
109
110#include "remdeb_f.x"
111
112const MAXDEBUGGEE= 150;
113const NAMEMAX = 17;   
114
115%  /*
116%   * Memory data for read/write text or data. The size is in data. The target
117%   * addr is in the addr field.
118%   * Be careful before modifying because this value goes into internal
119%   * pipes and is allocated on stack too. Pipes and/or the stack could
120%   * become too small if this value gets incremented.
121%   */
122
123const MEM_DATA_MAX      = 256;
124
125#ifndef RPC_XDR
126
127struct xdr_mem {
128        u_long          addr;
129        u_int           dataNb;
130        unsigned char   data[MEM_DATA_MAX];
131};
132
133#else
134/* manually define best XDR function for this */
135%bool_t xdr_xdr_mem(xdrs, objp)
136%       XDR *xdrs;
137%       struct xdr_mem *objp;
138%{
139%       if (!xdr_u_long(xdrs, &objp->addr)) {
140%               return (FALSE);
141%       }
142%       if (!xdr_u_int(xdrs, &objp->dataNb)) {
143%               return(FALSE);
144%       }
145%       return (xdr_opaque(xdrs, objp->data, objp->dataNb));
146%}
147
148#endif
149
150/* Breakpoint structure maps to same structure on host. Do not change one
151   without changing the other. */
152
153enum break_type
154{                               /* types of breakpoints */
155  BRKT_NONE,                    /* unused entry */
156  BRKT_INSTR,                   /* general instruction break */
157  BRKT_READ,                    /* read break */
158  BRKT_WRITE,                   /* write breakpoint */
159  BRKT_ACCESS,                  /* read-or-write break */
160  BRKT_EXEC,                    /* execution HW breakpoint */
161  BRKT_OS_CALL,                 /* break on OS call, addr is call number */
162  BRKT_OS_SWITCH,               /* dispatch breakpoint */
163  BRKT_STEPEMUL                 /* emulate hardware single-step */
164};
165const MAX_THRD_BRK = 4;         /* enough for 128 threads per process */
166struct xdr_break
167{                               /* one per process local breakpoint */
168  u_char        type;           /* BRKT_xxx type of break */
169  u_char        thread_spec;    /* 0=all, else count of threads it affects */
170  u_short       handle;         /* handle of breakpoint returned */
171  u_long        ee_loc;         /* address of start */
172  u_long        ee_type;        /* type/method of address */
173  u_short       length;         /* length of break if range, else 0 */
174  u_char        pass_count;     /* pass count to initialize to (0=none) */
175  u_char        curr_pass;      /* pass count current value */
176  u_long        thread_list[MAX_THRD_BRK]; /* bit map for thread list */
177};                              /* 20 bytes+4 per thread_list (4x4=16) = 36 */
178
179const UTHREAD_MAX     = 64;
180
181const THREADNAMEMAX =   16;
182typedef string thread_name <THREADNAMEMAX>;
183
184struct KernThread {
185        unsigned int threadLi;
186};
187
188#ifndef RPC_XDR
189
190#ifdef RPC_HDR
191%typedef KernThread *ptThreadList;
192#endif
193
194struct thread_list {
195        unsigned int nbThread;
196        ptThreadList threads;   
197};
198
199#else /* RPC_XDR */
200
201/* must write this function by hand */
202
203%bool_t xdr_thread_list(xdrs, objp)
204%       XDR *xdrs;
205%       struct thread_list *objp;
206%{
207%       return (xdr_array(xdrs, (char**)&objp->threads, &objp->nbThread,
208%                       UTHREAD_MAX, sizeof(KernThread), xdr_KernThread));
209%}
210
211#endif /* not RPC_XDR */
212
213
214union ptrace_addr_data_in switch (ptracereq req) {
215    /*
216     * due to rpcgen poor features, we cannot put RPC_SETREGS
217     * AND RPC_SETTHREADREGS in the case list. So we use a hack (FIX rpcgen).
218     */
219#ifndef RPC_HDR
220        case RPT_SETTHREADREGS :
221                                xdr_regs regs;
222#endif
223        case RPT_SETREGS:
224
225                                xdr_regs regs;
226
227#ifndef RPC_HDR
228        case RPT_PSETTHREADREGS:
229                                u_int pregs<>;
230#endif
231        case RPT_PSETREGS:
232                                u_int pregs<>;
233
234#ifdef LATER
235        case RPT_SETFPREGS:
236                                xdr_fp_status fpregs;
237#endif
238        case RPT_SETTHREADNAME:
239                                thread_name name;
240#ifndef RPC_HDR
241        case RPT_WRITETEXT:
242                                xdr_mem mem;
243#endif
244        case RPT_WRITEDATA:
245                                xdr_mem mem;
246        case RPT_SETBREAK:
247                                xdr_break breakp;
248        default:
249                                u_int address;
250};
251
252union ptrace_addr_data_out switch (ptracereq req) {
253        case RPT_GETREGS:
254                                xdr_regs regs;
255#ifndef RPC_HDR
256        case RPT_GETTHREADREGS:
257                                xdr_regs regs;
258#endif
259
260        case RPT_PGETREGS:
261                                u_int pregs<>;
262
263#ifndef RPC_HDR
264        case RPT_PGETTHREADREGS:
265                                u_int pregs<>;
266#endif
267
268#ifdef LATER
269        case RPT_GETFPREGS:
270                                xdr_fp_status fpregs;
271#endif
272        case RPT_THREADLIST:
273                                thread_list threads;
274        case RPT_GETTHREADNAME:
275                                thread_name name;                               
276#ifndef RPC_HDR
277        case RPT_READTEXT:
278                                xdr_mem mem;
279        case RPT_GETNAME:
280                                xdr_mem mem;
281#endif
282        case RPT_READDATA:
283                                xdr_mem mem;
284        case RPT_GETBREAK:
285                                xdr_break breakp;
286        default:
287                                u_int addr;
288};
289
290typedef opaque CHAR_DATA <NET_SAFE>;    /* variable sized data */
291
292const XRY_MAX_INST_BUFF = 128;
293const XRY_MAX_INSTANCES = 16;
294%#ifndef XRY_MAX_CMD_STR
295const XRY_MAX_CMD_STR = 320; /* XRY_MAX_INST_BUFF+(XRY_MAX_INSTANCES*12) */
296%#endif /* REMDEB_H */
297
298
299struct xry_inst
300{
301  unsigned char flags;          /* value2 interp, etc. INFL_xxx */
302  unsigned char type;           /* base type of data (str, val, etc) INST_xxx */
303  unsigned char sub_type;       /* specific type (task, res, etc). This is
304                                   set and defined by the user defined instance
305                                   processor and not the auto-processor */
306  unsigned char res_type;
307  u_long        value;          /* pointer to value or value itself */
308  u_long        value2;         /* second value (optional - based on flags) */ 
309};
310
311struct instance
312{
313  struct xry_inst instances[XRY_MAX_INSTANCES];
314  unsigned char buffer[XRY_MAX_INST_BUFF];
315};
316
317union instance_union switch (bool instances)
318{
319  case TRUE:
320        instance        inst;
321  case FALSE:
322        string          buffer <XRY_MAX_CMD_STR>;
323};
324
325typedef string  one_arg <NET_SAFE>;     
326
327const XRY_MAX_OBJ_NAME = 32;    /* objname in some commands */
328
329%  /* now open_connex() routine which establishes a connection to server */
330
331enum debug_type
332{                               /* type of connection requested */
333  DEBTYP_PROCESS = 0,           /* process connection */
334  DEBTYP_C_ACTOR = 1,           /* C-Actor connection */
335  DEBTYP_KERNEL = 2,            /* kernel debug connection */
336  DEBTYP_OTHER = 3              /* other subsystem */
337};
338
339%#define DEBUGGER_IS_GDB 0x2    /* */
340
341struct open_in
342{                               /* input args to open a connection */
343  u_char        back_port[16];  /* opaque NET address format */
344  u_short       debug_type;     /* type of process DEBTYP_xxx */
345  u_short       flags;          /* connection information OPNFLG_xxx */
346  u_char        destination[16];/* opaque address if to router */
347  one_arg       user_name;      /* name of user on host */
348};
349
350struct open_out
351{                               /* return from open_connex */
352  u_long        port;           /* connection number to server or -1 if error */
353  u_int         pad[4];         /* Planned to be KnIpcDest. Never used */
354  u_int         fp;             /* True if floating point processor. If error,
355                                   set to errno for open error.         */
356  u_char        cmd_table_num;  /* command table used */
357  u_char        cmd_table_vers; /* version of command table */
358  u_short       server_vers;    /* version number of server itself */
359};
360
361%  /* now close_connex() routine which detaches from server */
362
363enum close_control
364{                               /* choice of how to handle owned processes */
365  CLOSE_IGNORE = 0,             /* ignore all controlled pids on close */
366  CLOSE_KILL = 1,               /* kill all controlled pids on close */
367  CLOSE_DETACH = 2              /* detach free running all controlled pids */
368};
369
370struct close_in
371{                               /* arg to close connection */
372  close_control control;        /* shutdown of owned processes control */
373};
374
375%  /* now send_signal() routine which sends signals to processes like kill(2) */
376
377struct signal_in
378{                               /* input to send_signal */
379  int           pid;            /* process/actor to send signal to */
380  int           sig;            /* signal to send (from /usr/include/signal.h) */
381};
382
383struct signal_out
384{                               /* return from send_signal */
385  int           kill_return;    /* return code from kill(2) call */
386  int           errNo;          /* error code if failed */
387};
388
389
390%  /* now wait_info() routine which returns results of polling the wait status
391%       of a process/actor. It may return 0 if running, else pid or -1 */
392
393enum stop_code
394{                               /* stop code information */
395  STOP_ERROR = 0,               /* error, errno set */
396  STOP_NONE = 1,                /* not stopped */
397  STOP_UNKNOWN = 2,             /* unknown stop reason */
398  STOP_BREAK = 3,               /* stopped on breakpoint */
399  STOP_STEP = 4,                /* stopped on step */
400  STOP_SIGNAL = 5,              /* stopped on signal receieve */
401  STOP_TERM_EXIT = 6,           /* terminated normally */
402  STOP_TERM_SIG = 7,            /* terminated by signal */
403  STOP_DETACHED = 8,            /* detached from server */
404  STOP_KILLED = 9,              /* killed by ptrace KILL */
405  STOP_SPAWN_FAILED = 10        /* spawn failed in exec part, handle=errno */
406};
407
408struct wait_in
409{                               /* input arg to wait is process */
410  int           pid;            /* process/actor id */
411};
412
413struct wait_out
414{                               /* result of wait_info call */
415  int           wait_return;    /* -1=error,0=running,pid=stopped */
416  int           errNo;          /* error code if error */
417  int           status;         /* wait(2) status if stopped */
418  stop_code     reason;         /* reason in more abstracted terms */
419  int           handle;         /* handle of break if stopped on break,
420                                   or signal number or exit code  */
421  u_long        PC;             /* program counter if stopped */
422  u_long        SP;             /* stack pointer if stopped */
423  u_long        FP;             /* frame pointer if stopped */
424  u_long        thread;         /* thread that stopped if applies (else -1) */
425};
426
427%  /* now ptrace() routine. This matches the Sun UNIX ptrace as well as
428%       some additions */
429
430const PTRFLG_FORCE = 1;         /* when set and process running, forces process
431                                   to stop, make the request, then start again.
432                                   This is used for breakpoints and the like */
433const PTRFLG_NON_OWNER = 2;     /* do request even if not primary owner (will
434                                   notify all owners including caller if owns) */
435const PTRFLG_FREE = 4;          /* free pid_list after KILL/DETACH */
436
437const PTRDET_UNOWN = 0x100;     /* data value in RPT_DETACH just disconnects
438                                   caller as an owner of process.       */
439
440struct ptrace_in
441{                               /* input args matches ptrace but for XDR */
442  int           pid;            /* process to act on */
443  ptrace_addr_data_in addr;     /* mappings for addr and addr2 */
444  u_int         data;           /* simple data arg of ptrace */
445  u_int         flags;          /* mask of PTRFLG_xxx flags. */
446};
447
448struct ptrace_out
449{                               /* return information from ptrace */
450  ptrace_addr_data_out  addr;   /* return through addr/addr2 */
451  int                   result; /* result of ptrace call (return value) */
452  int                   errNo;  /* error code if error */
453};
454
455    /* Data for GET_GLOBAL_SYMBOLS */
456struct one_symbol {             /* Must match common/src/lib/ctx/ctx.h */
457    string symbolName<>;
458    long symbolValue;
459};
460
461typedef one_symbol all_symbols<>;
462
463struct get_global_symbols_out {
464    all_symbols symbols;
465};
466
467    /* Data for GET_TEXT_DATA */
468struct get_text_data_in {
469  int           pid;            /* process/actor id if non-zero */
470  string        actorName<16>;  /* actor name for system mode */
471};
472
473struct get_text_data_out {
474    int         result;
475    int         errNo;
476    u_long      textStart;
477    u_long      textSize;
478    u_long      dataStart;
479    u_long      dataSize;
480};
481
482    /* Data for GET_SIGNAL_NAMES */
483struct one_signal {
484    u_int       number;
485    string      name<>;
486};
487
488typedef one_signal all_signals<>;
489
490struct get_signal_names_out {
491    all_signals signals;
492};
493
494%  /* now define the actual calls we support */
495
496program REMOTEDEB {
497        version REMOTEVERS {
498
499                /* open a connection to server or router */
500                open_out
501                OPEN_CONNEX(open_in)            = 1;
502
503                /* send a signal to a process */
504                signal_out
505                SEND_SIGNAL(signal_in)          = 2;
506
507        /* all routines below require a connection first */
508
509                /* close the connection to the server */
510                void
511                CLOSE_CONNEX(close_in)          = 10;
512
513                /* process ptrace request */
514                ptrace_out
515                PTRACE(ptrace_in)               = 11;
516               
517                /* poll for status of process */
518                wait_out
519                WAIT_INFO(wait_in)              = 13;
520
521                get_signal_names_out
522                GET_SIGNAL_NAMES(void)          = 17;
523
524        } = 2;                  /* now version 2 */
525} = 0x20000fff;
526
527#ifdef RPC_HDR
528%#define REMDEB_H
529%#endif
530#endif
531
532#ifdef RPC_SVC
533
534%const char* names [] = {
535%    "NULLPROC", "OPEN_CONNEX", "SEND_SIGNAL", "name3",
536%    "name4", "name5", "name6", "name7",
537%    "name8", "name9", "CLOSE_CONNEX", "PTRACE",
538%    "name12", "WAIT_INFO", "name14", "name15",
539%    "name16", "GET_SIGNAL_NAMES", "name18"
540%};
541%
542
543%/*HEADER_END*/
544#endif
Note: See TracBrowser for help on using the repository browser.