1 | /* |
---|
2 | ********************************************************************** |
---|
3 | * |
---|
4 | * Component: RDB |
---|
5 | * Module: servutil.c |
---|
6 | * |
---|
7 | * Synopsis: Various utility routines |
---|
8 | * |
---|
9 | ********************************************************************** |
---|
10 | */ |
---|
11 | |
---|
12 | #include <string.h> |
---|
13 | #include <rdbg/rdbg.h> |
---|
14 | #include <rdbg/servrpc.h> |
---|
15 | |
---|
16 | /*----- Management of per-process list ----*/ |
---|
17 | |
---|
18 | /* |
---|
19 | * ListAlloc - build up list entry. |
---|
20 | * |
---|
21 | * Notes: |
---|
22 | * - this is a generic routine to build up entries in the per-connection |
---|
23 | * list. The fields list, list_sz and list_alloc are affected. |
---|
24 | */ |
---|
25 | |
---|
26 | Boolean |
---|
27 | ListAlloc(buff, clst) |
---|
28 | char *buff; |
---|
29 | CONN_LIST *clst; /* place to copy it */ |
---|
30 | { |
---|
31 | int tmp; |
---|
32 | char* name; |
---|
33 | int new_len; |
---|
34 | int len; |
---|
35 | |
---|
36 | tmp = strlen(buff); |
---|
37 | new_len = (int)clst->list_sz + 1 + tmp; |
---|
38 | if (clst->list_alloc < (unsigned)new_len) { |
---|
39 | /* need more space */ |
---|
40 | name = (char *)Realloc(clst->list, len = new_len + MAX_FILENAME); |
---|
41 | if (name == NULL) { |
---|
42 | return(False); /* failed, no space */ |
---|
43 | } |
---|
44 | clst->list_alloc = len; |
---|
45 | clst->list = name; |
---|
46 | } |
---|
47 | strcpy(clst->list + clst->list_sz, buff); |
---|
48 | clst->list_sz += tmp; |
---|
49 | return(True); |
---|
50 | } |
---|
51 | |
---|
52 | /*----- Management of processes -----*/ |
---|
53 | |
---|
54 | /* |
---|
55 | * FindPidEntry - locate pid_list entry from pid |
---|
56 | */ |
---|
57 | |
---|
58 | int |
---|
59 | FindPidEntry (pid) |
---|
60 | int pid; /* process identifier */ |
---|
61 | { |
---|
62 | int idx; |
---|
63 | |
---|
64 | /* pid 0 is invalid, and signals a free slot */ |
---|
65 | if (pid_list == NULL || pid == 0) { |
---|
66 | return -1; |
---|
67 | } |
---|
68 | for (idx = 0; idx < pid_list_cnt; idx++) { |
---|
69 | if (pid_list [idx].pid == pid ) |
---|
70 | return idx; |
---|
71 | } |
---|
72 | return -1; |
---|
73 | } |
---|
74 | |
---|
75 | /*----- Debug suport -----*/ |
---|
76 | |
---|
77 | #ifdef DDEBUG |
---|
78 | |
---|
79 | /* |
---|
80 | * Names of debug primitives |
---|
81 | */ |
---|
82 | |
---|
83 | const char* PtraceNames [] = { |
---|
84 | |
---|
85 | "RPT_TRACEME", "RPT_PEEKTEXT", "RPT_PEEKDATA", "RPT_PEEKUSER", |
---|
86 | "RPT_POKETEXT", "RPT_POKEDATA", "RPT_POKEUSER", "RPT_CONT", |
---|
87 | "RPT_KILL", "RPT_SINGLESTEP", "RPT_ATTACH", "RPT_DETACH", |
---|
88 | "RPT_GETREGS", "RPT_SETREGS", "RPT_GETFPREGS", "RPT_SETFPREGS", |
---|
89 | "RPT_READDATA", "RPT_WRITEDATA", "RPT_READTEXT", "RPT_WRITETEXT", |
---|
90 | "RPT_GETFPAREGS", "RPT_SETFPAREGS", "RPT_22", "RPT_23", |
---|
91 | "RPT_SYSCALL", "RPT_DUMPCORE", "RPT_26", "RPT_27", |
---|
92 | "RPT_28", "RPT_GETUCODE", "RPT_30", "RPT_31", |
---|
93 | "RPT_32", "RPT_33", "RPT_34", "RPT_35", |
---|
94 | "RPT_36", "RPT_37", "RPT_38", "RPT_39", |
---|
95 | "RPT_40", "RPT_41", "RPT_42", "RPT_43", |
---|
96 | "RPT_44", "RPT_45", "RPT_46", "RPT_47", |
---|
97 | "RPT_48", "RPT_49", "RPT_GETTARGETTHREAD", "RPT_SETTARGETTHREAD", |
---|
98 | "RPT_THREADSUSPEND", "RPT_THREADRESUME", "RPT_THREADLIST", "RPT_GETTHREADNAME", |
---|
99 | "RPT_SETTHREADNAME", "RPT_SETTHREADREGS", "RPT_GETTHREADREGS", |
---|
100 | "RPT_59", |
---|
101 | "RPT_60", "RPT_61", "RPT_62", "RPT_63", |
---|
102 | "RPT_64", "RPT_65", "RPT_66", "RPT_67", |
---|
103 | "RPT_68", "RPT_69", "RPT_70", "RPT_71", |
---|
104 | "RPT_72", "RPT_73", "RPT_74", "RPT_STEPRANGE", |
---|
105 | "RPT_CONTTO", "RPT_SETBREAK", "RPT_CLRBREAK", "RPT_GETBREAK", |
---|
106 | "RPT_GETNAME", "RPT_STOP", |
---|
107 | "RPT_PGETREGS", "RPT_PSETREGS", |
---|
108 | "RPT_PSETTHREADREGS", "RPT_PGETTHREADREGS" |
---|
109 | }; |
---|
110 | |
---|
111 | const char* |
---|
112 | PtraceName(req) |
---|
113 | int req; |
---|
114 | { |
---|
115 | static char bufret[40]; |
---|
116 | |
---|
117 | if ((req < 0) || (req >= sizeof(PtraceNames)/sizeof(char*))) { |
---|
118 | sprintf(bufret, "BAD_REQ_%d", req); |
---|
119 | return bufret; |
---|
120 | } |
---|
121 | return PtraceNames[req]; |
---|
122 | } |
---|
123 | |
---|
124 | const char* BmsgNames [] = { |
---|
125 | "?", "WARM", "WAIT", "BREAK", |
---|
126 | "EXEC_FAIL", "DETACH", "KILLED", "NOT_PRIM", |
---|
127 | "NEW_PID" |
---|
128 | }; |
---|
129 | |
---|
130 | #endif /* DDEBUG */ |
---|