xref: /illumos-gate/usr/src/cmd/sgs/demo_rdb/common/gram.y (revision ed093b41a93e8563e6e1e5dae0768dda2a7bcc27)
1 %{
2 /*
3  * CDDL HEADER START
4  *
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License (the "License").
7  * You may not use this file except in compliance with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 
23 /*
24  * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
25  */
26 
27 #include <stdio.h>
28 #include <sys/types.h>
29 #include <libelf.h>
30 #include "rdb.h"
31 
32 extern	void	rdb_prompt();
33 
34 %}
35 
36 %token	VALUE STEP HELP NUMBER NEWLINE SYMBOL PLUS BREAK CONT DIS GETMAPS
37 %token	DELETE MAPS PLTSKIP WHERE PRINT OBJPAD QSTRING VARSTRING ECHO_OUT
38 %token	EVENT LINKMAPS
39 
40 %union {
41 	char	*str;
42 	ulong_t	addr;
43 	int	num;
44 }
45 
46 %type <addr> NUMBER address
47 %type <str> SYMBOL QSTRING VARSTRING
48 
49 %left PLUS
50 
51 %%
52 start: commands
53 	;
54 
55 commands: /* empty */
56 	| commands command
57 	;
58 command: BREAK NEWLINE
59 	{
60 		list_breakpoints(&proch);
61 		rdb_prompt();
62 	}
63 	| BREAK address NEWLINE
64 	{
65 		if (set_breakpoint(&proch, $2, FLG_BP_USERDEF) == RET_OK)
66 			(void) printf("break point set at: 0x%lx\n",
67 			    (unsigned long)$2);
68 		else
69 			(void) printf("unable to set breakpoint.\n");
70 		rdb_prompt();
71 	}
72 	| CONT NEWLINE
73 	{
74 		(void) continue_to_break(&proch);
75 		rdb_prompt();
76 	}
77 	| DELETE address NEWLINE
78 	{
79 		if (delete_breakpoint(&proch, $2, FLG_BP_USERDEF) != RET_OK)
80 			(void) printf("unable to delete breakpoint at %#lx\n",
81 			    (unsigned long)$2);
82 		else
83 			(void) printf("breakpoint deleted at 0x%lx\n",
84 			    (unsigned long)$2);
85 
86 		rdb_prompt();
87 	}
88 	| DIS NEWLINE
89 	{
90 		disasm(&proch, 10);
91 		rdb_prompt();
92 	}
93 	| DIS address NEWLINE
94 	{
95 		(void) disasm_addr(&proch, (ulong_t)$2, 10);
96 		rdb_prompt();
97 	}
98 	| DIS address NUMBER NEWLINE
99 	{
100 		(void) disasm_addr(&proch, (ulong_t)$2, (int)$3);
101 		rdb_prompt();
102 	}
103 	| ECHO_OUT QSTRING NEWLINE
104 	{
105 		(void) puts($2);
106 		free($2);
107 		rdb_prompt();
108 	}
109 	| EVENT SYMBOL NEWLINE
110 	{
111 		if (strcmp($2, "on") == 0) {
112 			(void) printf("rdb: event information enabled.\n");
113 			rdb_flags |= RDB_FL_EVENTS;
114 		} else if (strcmp($2, "off") == 0) {
115 			(void) printf("rdb: event information disabled.\n");
116 			rdb_flags &= ~RDB_FL_EVENTS;
117 		} else {
118 			(void) printf("rdb: unknown event command: %s\n", $2);
119 		}
120 		free($2);
121 		rdb_prompt();
122 	}
123 	| GETMAPS NEWLINE
124 	{
125 		if (get_linkmaps(&proch) != RET_OK)
126 			(void) printf("get_linkmaps failed\n");
127 
128 		rdb_prompt();
129 	}
130 	| LINKMAPS NEWLINE
131 	{
132 		if (display_linkmaps(&proch) != RET_OK)
133 			(void) printf("display_linkmaps failed\n");
134 		rdb_prompt();
135 	}
136 	| MAPS NEWLINE
137 	{
138 		if (display_maps(&proch) != RET_OK)
139 			(void) printf("display_maps failed\n");
140 		rdb_prompt();
141 	}
142 	| STEP NEWLINE
143 	{
144 		sn_flags_e	sf;
145 
146 		(void) printf("single step\n");
147 		sf = FLG_SN_VERBOSE;
148 		if (proch.pp_flags & FLG_PP_PLTSKIP)
149 			sf |= FLG_SN_PLTSKIP;
150 
151 		(void) step_n(&proch, 1, sf);
152 		rdb_prompt();
153 	}
154 	| STEP NUMBER NEWLINE
155 	{
156 		sn_flags_e	sf;
157 
158 		(void) printf("stepping %d\n", (int)$2);
159 		sf = FLG_SN_VERBOSE;
160 		if (proch.pp_flags & FLG_PP_PLTSKIP)
161 			sf |= FLG_SN_PLTSKIP;
162 
163 		(void) step_n(&proch, $2, sf);
164 		rdb_prompt();
165 	}
166 	| STEP NUMBER SYMBOL NEWLINE
167 	{
168 		sn_flags_e	sf;
169 
170 		sf = FLG_SN_VERBOSE;
171 		if (proch.pp_flags & FLG_PP_PLTSKIP)
172 			sf |= FLG_SN_PLTSKIP;
173 
174 		if (strcmp("silent", $3) == 0)
175 			(void) step_n(&proch, $2, sf);
176 		else
177 			(void) printf("error: step <count> [silent]\n");
178 
179 		free($3);
180 		rdb_prompt();
181 	}
182 	| HELP NEWLINE
183 	{
184 		rdb_help(0);
185 		rdb_prompt();
186 	}
187 	| HELP SYMBOL NEWLINE
188 	{
189 		rdb_help($2);
190 		free($2);
191 		rdb_prompt();
192 	}
193 	| OBJPAD NUMBER NEWLINE
194 	{
195 		(void) printf("setting object padding to: %#lx\n", $2);
196 		(void) set_objpad(&proch, $2);
197 		rdb_prompt();
198 	}
199 	| PLTSKIP NEWLINE
200 	{
201 		if (proch.pp_flags & FLG_PP_PLTSKIP) {
202 			proch.pp_flags &= ~ FLG_PP_PLTSKIP;
203 			(void) printf("plt skipping disabled\n");
204 		} else {
205 			proch.pp_flags |= FLG_PP_PLTSKIP;
206 			(void) printf("plt skipping enabled\n");
207 		}
208 
209 		rdb_prompt();
210 	}
211 	| PRINT VARSTRING NEWLINE
212 	{
213 		print_varstring(&proch, $2);
214 		free($2);
215 		rdb_prompt();
216 	}
217 	| PRINT address NEWLINE
218 	{
219 		print_mem(&proch, $2, 4, "X");
220 		rdb_prompt();
221 	}
222 	| PRINT address NUMBER NEWLINE
223 	{
224 		print_mem(&proch, $2, (int)$3, "X");
225 		rdb_prompt();
226 	}
227 	| PRINT address NUMBER SYMBOL NEWLINE
228 	{
229 		print_mem(&proch, $2, (int)$3, $4);
230 		rdb_prompt();
231 	}
232 	| VALUE address NEWLINE
233 	{
234 		(void) printf("value: %#lx\n", (unsigned long)$2);
235 		rdb_prompt();
236 	}
237 	| WHERE NEWLINE
238 	{
239 		(void) printf("printing stack trace\n");
240 		CallStack(&proch);
241 		rdb_prompt();
242 	}
243 	| error NEWLINE
244 	{
245 		yyerrok;
246 		rdb_prompt();
247 	}
248 	| NEWLINE
249 	{
250 		disasm(&proch, 1);
251 		rdb_prompt();
252 	}
253 	;
254 
255 address: address PLUS address
256 	{
257 		$$ = $1 + $3;
258 	}
259 	| SYMBOL
260 	{
261 		GElf_Sym	sym;
262 		if (str_to_sym(&proch, $1, &sym) == RET_OK)
263 			$$ = (ulong_t)sym.st_value;
264 		else {
265 			(void) printf("unknown symbol: %s\n", $1);
266 			$$ = 0;
267 		}
268 		free($1);
269 	}
270 	| NUMBER
271 	{
272 		$$ = $1;
273 	}
274 	;
275 %%
276 
277 void
278 rdb_prompt()
279 {
280 	if (proch.pp_flags & FLG_PP_PROMPT) {
281 		(void) fputs("<rdb> ", stdout);
282 		(void) fflush(stdout);
283 	}
284 }
285