-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCLICommand.c
260 lines (192 loc) · 4.86 KB
/
CLICommand.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/******************************************************************************
* Copyright (c) 2005 The Regents of the University of California.
* This material was produced under U.S. Government contract W-7405-ENG-36
* for Los Alamos National Laboratory, which is operated by the University
* of California for the U.S. Department of Energy. The U.S. Government has
* rights to use, reproduce, and distribute this software. NEITHER THE
* GOVERNMENT NOR THE UNIVERSITY MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR
* ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified
* to produce derivative works, such modified software should be clearly
* marked, so as not to confuse it with the version available from LANL.
*
* Additionally, this program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* LA-CC 04-115
*
* Copyright 2012-2014 Cray Inc. All Rights Reserved.
*
******************************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /* HAVE_CONFIG_H */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "MICommand.h"
MICommand *
CLIHandle(char *arg) {
MICommand * cmd;
char * cmd_argv[2];
cmd_argv[0] = "handle";
cmd_argv[1] = arg;
cmd = CLIBypass(2, cmd_argv);
return cmd;
}
MICommand *
CLIInfoThreads(void) {
MICommand * cmd;
char * cmd_argv[2];
cmd_argv[0] = "info";
cmd_argv[1] = "threads";
cmd = CLIBypass(2, cmd_argv);
return cmd;
}
MICommand *
CLIPtype(char *name) {
MICommand * cmd;
char * cmd_argv[2];
cmd_argv[0] = "ptype";
cmd_argv[1] = name;
cmd = CLIBypass(2, cmd_argv);
return cmd;
}
MICommand *
CLIWhatis(char *var) {
MICommand * cmd;
char * cmd_argv[2];
cmd_argv[0] = "whatis";
cmd_argv[1] = var;
cmd = CLIBypass(2, cmd_argv);
return cmd;
}
MICommand *
CLIListSignals(char *name) {
MICommand * cmd;
char * cmd_argv[3];
cmd_argv[0] = "info";
cmd_argv[1] = "signals";
cmd_argv[2] = name;
if (name != NULL)
cmd = CLIBypass(3, cmd_argv);
else
cmd = CLIBypass(2, cmd_argv);
return cmd;
}
MICommand *
CLISignalInfo(char *arg) {
MICommand * cmd;
char * cmd_argv[2];
cmd_argv[0] = "signal";
cmd_argv[1] = arg;
cmd = CLIBypass(2, cmd_argv);
return cmd;
}
MICommand *
CLIFrame(void) {
MICommand * cmd;
char * cmd_argv[1];
cmd_argv[0] = "frame";
cmd = CLIBypass(1, cmd_argv);
return cmd;
}
MICommand *
CLIList(char *arg) {
MICommand * cmd;
char * cmd_argv[2];
cmd_argv[0] = "list";
cmd_argv[1] = arg;
cmd = CLIBypass(2, cmd_argv);
return cmd;
}
MICommand *
CLIListSingleLine(int lineno) {
MICommand * cmd;
char * cmd_argv[2];
char arg[BUFSIZ];
snprintf(arg, BUFSIZ, "%d,%d", lineno, lineno);
cmd_argv[0] = "list";
cmd_argv[1] = arg;
cmd = CLIBypass(2, cmd_argv);
return cmd;
}
MICommand *
CLIPrint(char *arg) {
MICommand * cmd;
char * cmd_argv[2];
cmd_argv[0] = "print";
cmd_argv[1] = arg;
cmd = CLIBypass(2, cmd_argv);
return cmd;
}
MICommand *
CLIPrintHex(char *arg) {
MICommand * cmd;
char * cmd_argv[2];
cmd_argv[0] = "print/a";
cmd_argv[1] = arg;
cmd = CLIBypass(2, cmd_argv);
return cmd;
}
MICommand *
CLIInfoProc(void) {
MICommand * cmd;
char * cmd_argv[2];
cmd_argv[0] = "info";
cmd_argv[1] = "proc";
cmd = CLIBypass(2, cmd_argv);
return cmd;
}
MICommand *
CLIInfoScope(char *location) {
MICommand * cmd;
char * cmd_argv[3];
cmd_argv[0] = "info";
cmd_argv[1] = "scope";
cmd_argv[2] = location;
cmd = CLIBypass(3, cmd_argv);
return cmd;
}
// This implements the "approved" method of passing CLI commands directly to
// the gdb interpreter. Support for passing commands directly can go away at
// any time.
MICommand *
CLIBypass(int cmd_argc, char *cmd_argv[]) {
int i;
int cmd_len = 3;
char * cmd_str;
char * tmp_str;
MICommand * mi_cmd;
if (cmd_argc == 0 || (cmd_argv == NULL ? 1:(*cmd_argv == NULL))) {
// there were no arguments...
return NULL;
}
mi_cmd = MICommandNew("-interpreter-exec", MIResultRecordDONE);
MICommandAddOption(mi_cmd, "console", NULL);
// first figure out the string length
for ( i=0; i < cmd_argc; i++) {
cmd_len += strlen(cmd_argv[i])+1;
}
// allocate the string
if ((cmd_str = malloc(sizeof(char)*cmd_len)) == (void *)0) {
MICommandFree(mi_cmd);
return NULL;
}
// write the first arg
snprintf(cmd_str, cmd_len, "\"%s", cmd_argv[0]);
// now write the rest of the string
for ( i=1; i < cmd_argc; i++) {
tmp_str = strdup(cmd_str);
snprintf(cmd_str, cmd_len, "%s %s", tmp_str, cmd_argv[i]);
free(tmp_str);
}
// write the final "
tmp_str = strdup(cmd_str);
snprintf(cmd_str, cmd_len, "%s\"", tmp_str);
free(tmp_str);
MICommandAddOption(mi_cmd, cmd_str, NULL);
free(cmd_str);
return mi_cmd;
}