8354 sync regcomp(3C) with upstream (fix make catalog)
[unleashed/tickless.git] / usr / src / cmd / sgs / librtld_db / demo / common / gram.y
blobd8366eba9db0728f6aa53cde2755e3383f6088a1
1 %{
2 /*
3 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
24 * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
27 #include <stdio.h>
28 #include <sys/types.h>
29 #include <libelf.h>
30 #include "rdb.h"
32 extern void rdb_prompt();
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
40 %union {
41 char *str;
42 ulong_t addr;
43 int num;
46 %type <addr> NUMBER address
47 %type <str> SYMBOL QSTRING VARSTRING
49 %left PLUS
52 start: commands
55 commands: /* empty */
56 | commands command
58 command: BREAK NEWLINE
60 list_breakpoints(&proch);
61 rdb_prompt();
63 | BREAK address NEWLINE
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();
72 | CONT NEWLINE
74 (void) continue_to_break(&proch);
75 rdb_prompt();
77 | DELETE address NEWLINE
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);
86 rdb_prompt();
88 | DIS NEWLINE
90 disasm(&proch, 10);
91 rdb_prompt();
93 | DIS address NEWLINE
95 (void) disasm_addr(&proch, (ulong_t)$2, 10);
96 rdb_prompt();
98 | DIS address NUMBER NEWLINE
100 (void) disasm_addr(&proch, (ulong_t)$2, (int)$3);
101 rdb_prompt();
103 | ECHO_OUT QSTRING NEWLINE
105 (void) puts($2);
106 free($2);
107 rdb_prompt();
109 | EVENT SYMBOL NEWLINE
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);
120 free($2);
121 rdb_prompt();
123 | GETMAPS NEWLINE
125 if (get_linkmaps(&proch) != RET_OK)
126 (void) printf("get_linkmaps failed\n");
128 rdb_prompt();
130 | LINKMAPS NEWLINE
132 if (display_linkmaps(&proch) != RET_OK)
133 (void) printf("display_linkmaps failed\n");
134 rdb_prompt();
136 | MAPS NEWLINE
138 if (display_maps(&proch) != RET_OK)
139 (void) printf("display_maps failed\n");
140 rdb_prompt();
142 | STEP NEWLINE
144 sn_flags_e sf;
146 (void) printf("single step\n");
147 sf = FLG_SN_VERBOSE;
148 if (proch.pp_flags & FLG_PP_PLTSKIP)
149 sf |= FLG_SN_PLTSKIP;
151 (void) step_n(&proch, 1, sf);
152 rdb_prompt();
154 | STEP NUMBER NEWLINE
156 sn_flags_e sf;
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;
163 (void) step_n(&proch, $2, sf);
164 rdb_prompt();
166 | STEP NUMBER SYMBOL NEWLINE
168 sn_flags_e sf;
170 sf = FLG_SN_VERBOSE;
171 if (proch.pp_flags & FLG_PP_PLTSKIP)
172 sf |= FLG_SN_PLTSKIP;
174 if (strcmp("silent", $3) == 0)
175 (void) step_n(&proch, $2, sf);
176 else
177 (void) printf("error: step <count> [silent]\n");
179 free($3);
180 rdb_prompt();
182 | HELP NEWLINE
184 rdb_help(0);
185 rdb_prompt();
187 | HELP SYMBOL NEWLINE
189 rdb_help($2);
190 free($2);
191 rdb_prompt();
193 | OBJPAD NUMBER NEWLINE
195 (void) printf("setting object padding to: %#lx\n", $2);
196 (void) set_objpad(&proch, $2);
197 rdb_prompt();
199 | PLTSKIP NEWLINE
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");
209 rdb_prompt();
211 | PRINT VARSTRING NEWLINE
213 print_varstring(&proch, $2);
214 free($2);
215 rdb_prompt();
217 | PRINT address NEWLINE
219 print_mem(&proch, $2, 4, "X");
220 rdb_prompt();
222 | PRINT address NUMBER NEWLINE
224 print_mem(&proch, $2, (int)$3, "X");
225 rdb_prompt();
227 | PRINT address NUMBER SYMBOL NEWLINE
229 print_mem(&proch, $2, (int)$3, $4);
230 rdb_prompt();
232 | VALUE address NEWLINE
234 (void) printf("value: %#lx\n", (unsigned long)$2);
235 rdb_prompt();
237 | WHERE NEWLINE
239 (void) printf("printing stack trace\n");
240 CallStack(&proch);
241 rdb_prompt();
243 | error NEWLINE
245 yyerrok;
246 rdb_prompt();
248 | NEWLINE
250 disasm(&proch, 1);
251 rdb_prompt();
255 address: address PLUS address
257 $$ = $1 + $3;
259 | SYMBOL
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;
268 free($1);
270 | NUMBER
272 $$ = $1;
277 void
278 rdb_prompt()
280 if (proch.pp_flags & FLG_PP_PROMPT) {
281 (void) fputs("<rdb> ", stdout);
282 (void) fflush(stdout);