1 | #include <rpc/types.h> |
---|
2 | #include <rpc/rpc.h> |
---|
3 | #include <stdio.h> |
---|
4 | #include <stdlib.h> |
---|
5 | #include <string.h> |
---|
6 | #include <bsp.h> |
---|
7 | #include <rdbg/servrpc.h> |
---|
8 | #include <rdbg/remdeb.h> |
---|
9 | #define fprintf(a,b) printf(b) |
---|
10 | /*HEADER_START*/ |
---|
11 | #define RTEMS_PORT 2071 |
---|
12 | #define RTEMS_BACK_PORT 2073 |
---|
13 | /* |
---|
14 | * Sun request values for the remote ptrace system call |
---|
15 | */ |
---|
16 | |
---|
17 | /* |
---|
18 | * Memory data for read/write text or data. The size is in data. The target |
---|
19 | * addr is in the addr field. |
---|
20 | * Be careful before modifying because this value goes into internal |
---|
21 | * pipes and is allocated on stack too. Pipes and/or the stack could |
---|
22 | * become too small if this value gets incremented. |
---|
23 | */ |
---|
24 | #ifndef XRY_MAX_CMD_STR |
---|
25 | #endif /* REMDEB_H */ |
---|
26 | /* |
---|
27 | * now open_connex() routine which establishes a connection to server |
---|
28 | */ |
---|
29 | #define DEBUGGER_IS_GDB 0x2 /* */ |
---|
30 | /* |
---|
31 | * now close_connex() routine which detaches from server |
---|
32 | */ |
---|
33 | /* |
---|
34 | * now send_signal() routine which sends signals to processes like kill(2) |
---|
35 | */ |
---|
36 | /* |
---|
37 | * now wait_info() routine which returns results of polling the wait status |
---|
38 | * of a process/actor. It may return 0 if running, else pid or -1 |
---|
39 | */ |
---|
40 | /* |
---|
41 | * now ptrace() routine. This matches the Sun UNIX ptrace as well as |
---|
42 | * some additions |
---|
43 | */ |
---|
44 | /* |
---|
45 | * now define the actual calls we support |
---|
46 | */ |
---|
47 | const char *names[] = { |
---|
48 | "NULLPROC", "OPEN_CONNEX", "SEND_SIGNAL", "name3", |
---|
49 | "name4", "name5", "name6", "name7", |
---|
50 | "name8", "name9", "CLOSE_CONNEX", "PTRACE", |
---|
51 | "name12", "WAIT_INFO", "name14", "name15", |
---|
52 | "name16", "GET_SIGNAL_NAMES", "name18" |
---|
53 | }; |
---|
54 | |
---|
55 | void |
---|
56 | remotedeb_2 (struct svc_req *rqstp, register SVCXPRT * transp) |
---|
57 | { |
---|
58 | union { |
---|
59 | open_in open_connex_2_arg; |
---|
60 | signal_in send_signal_2_arg; |
---|
61 | close_in close_connex_2_arg; |
---|
62 | ptrace_in ptrace_2_arg; |
---|
63 | wait_in wait_info_2_arg; |
---|
64 | } argument; |
---|
65 | char *result; |
---|
66 | xdrproc_t _xdr_argument, _xdr_result; |
---|
67 | char *(*local) (char *, struct svc_req *); |
---|
68 | |
---|
69 | DPRINTF (("remotedeb_2: %s (%d)\n", |
---|
70 | (unsigned) rqstp->rq_proc < |
---|
71 | (unsigned) (sizeof names / sizeof names[0]) ? |
---|
72 | names[rqstp->rq_proc] : "???", (int) rqstp->rq_proc)); |
---|
73 | |
---|
74 | switch (rqstp->rq_proc) { |
---|
75 | case NULLPROC: |
---|
76 | (void) svc_sendreply (transp, (xdrproc_t) xdr_void, (char *) NULL); |
---|
77 | return; |
---|
78 | |
---|
79 | case OPEN_CONNEX: |
---|
80 | _xdr_argument = (xdrproc_t) xdr_open_in; |
---|
81 | _xdr_result = (xdrproc_t) xdr_open_out; |
---|
82 | local = (char *(*)(char *, struct svc_req *)) open_connex_2_svc; |
---|
83 | break; |
---|
84 | |
---|
85 | case SEND_SIGNAL: |
---|
86 | _xdr_argument = (xdrproc_t) xdr_signal_in; |
---|
87 | _xdr_result = (xdrproc_t) xdr_signal_out; |
---|
88 | local = (char *(*)(char *, struct svc_req *)) send_signal_2_svc; |
---|
89 | break; |
---|
90 | |
---|
91 | case CLOSE_CONNEX: |
---|
92 | _xdr_argument = (xdrproc_t) xdr_close_in; |
---|
93 | _xdr_result = (xdrproc_t) xdr_void; |
---|
94 | local = (char *(*)(char *, struct svc_req *)) close_connex_2_svc; |
---|
95 | break; |
---|
96 | |
---|
97 | case PTRACE: |
---|
98 | _xdr_argument = (xdrproc_t) xdr_ptrace_in; |
---|
99 | _xdr_result = (xdrproc_t) xdr_ptrace_out; |
---|
100 | local = (char *(*)(char *, struct svc_req *)) ptrace_2_svc; |
---|
101 | break; |
---|
102 | |
---|
103 | case WAIT_INFO: |
---|
104 | _xdr_argument = (xdrproc_t) xdr_wait_in; |
---|
105 | _xdr_result = (xdrproc_t) xdr_wait_out; |
---|
106 | local = (char *(*)(char *, struct svc_req *)) wait_info_2_svc; |
---|
107 | break; |
---|
108 | |
---|
109 | case GET_SIGNAL_NAMES: |
---|
110 | _xdr_argument = (xdrproc_t) xdr_void; |
---|
111 | _xdr_result = (xdrproc_t) xdr_get_signal_names_out; |
---|
112 | local = (char *(*)(char *, struct svc_req *)) get_signal_names_2_svc; |
---|
113 | break; |
---|
114 | |
---|
115 | default: |
---|
116 | svcerr_noproc (transp); |
---|
117 | return; |
---|
118 | } |
---|
119 | memset ((char *) &argument, 0, sizeof (argument)); |
---|
120 | if (!svc_getargs (transp, _xdr_argument, (caddr_t) & argument)) { |
---|
121 | svcerr_decode (transp); |
---|
122 | return; |
---|
123 | } |
---|
124 | result = (*local) ((char *) &argument, rqstp); |
---|
125 | if (result != NULL && !svc_sendreply (transp, _xdr_result, result)) { |
---|
126 | svcerr_systemerr (transp); |
---|
127 | } |
---|
128 | if (!svc_freeargs (transp, _xdr_argument, (caddr_t) & argument)) { |
---|
129 | fprintf (stderr, "unable to free arguments"); |
---|
130 | exit (1); |
---|
131 | } |
---|
132 | return; |
---|
133 | } |
---|