OLD | NEW |
1 /* Handle Native Client manifest files. | 1 /* Handle Native Client manifest files. |
2 | 2 |
3 Copyright (C) 2011 Free Software Foundation, Inc. | 3 Copyright (C) 2011 Free Software Foundation, Inc. |
4 | 4 |
5 This file is part of GDB. | 5 This file is part of GDB. |
6 | 6 |
7 This program is free software; you can redistribute it and/or modify | 7 This program is free software; you can redistribute it and/or modify |
8 it under the terms of the GNU General Public License as published by | 8 it under the terms of the GNU General Public License as published by |
9 the Free Software Foundation; either version 3 of the License, or | 9 the Free Software Foundation; either version 3 of the License, or |
10 (at your option) any later version. | 10 (at your option) any later version. |
11 | 11 |
12 This program is distributed in the hope that it will be useful, | 12 This program is distributed in the hope that it will be useful, |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 GNU General Public License for more details. | 15 GNU General Public License for more details. |
16 | 16 |
17 You should have received a copy of the GNU General Public License | 17 You should have received a copy of the GNU General Public License |
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ | 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
19 | 19 |
20 #include "defs.h" | 20 #include "defs.h" |
21 | 21 |
22 #include "command.h" | 22 #include "command.h" |
23 #include "completer.h" | 23 #include "completer.h" |
| 24 #include "exec.h" |
| 25 #include "observer.h" |
24 #include "readline/readline.h" | 26 #include "readline/readline.h" |
25 #include "solib.h" | 27 #include "solib.h" |
| 28 #include "symfile.h" |
26 | 29 |
27 #include <ctype.h> | 30 #include <ctype.h> |
28 #include <stdio.h> | 31 #include <stdio.h> |
29 #include <string.h> | 32 #include <string.h> |
30 | 33 |
31 #define MANIFEST_MAX_NESTING 4 | 34 #define MANIFEST_MAX_NESTING 4 |
32 | 35 |
33 #define MANIFEST_MAX_STRING_SIZE 256 | 36 #define MANIFEST_MAX_STRING_SIZE 256 |
34 | 37 |
35 struct file_list | 38 struct file_list |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 r->members[r->nesting] = member; | 153 r->members[r->nesting] = member; |
151 ++r->nesting; | 154 ++r->nesting; |
152 } | 155 } |
153 | 156 |
154 static void | 157 static void |
155 json_on_end_member (struct json_manifest_reader *r, const char *member) | 158 json_on_end_member (struct json_manifest_reader *r, const char *member) |
156 { | 159 { |
157 --r->nesting; | 160 --r->nesting; |
158 } | 161 } |
159 | 162 |
| 163 static void |
| 164 append_dir_name (struct json_manifest_reader *r, |
| 165 char *full_path, |
| 166 int max_path_size, |
| 167 char *name) |
| 168 { |
| 169 full_path[0] = '\0'; |
| 170 if (r->dirname) |
| 171 { |
| 172 if (strlen (r->dirname) + strlen (SLASH_STRING) >= max_path_size) |
| 173 error (_("Mapped file name in manifest is too long.")); |
| 174 strcpy (full_path, r->dirname); |
| 175 strcat (full_path, SLASH_STRING); |
| 176 } |
| 177 if (strlen (full_path) + strlen (name) >= max_path_size) |
| 178 error (_("Mapped file name in manifest is too long.")); |
| 179 strcat (full_path, name); |
| 180 } |
| 181 |
160 static struct file_list * | 182 static struct file_list * |
161 json_append_file_list (struct json_manifest_reader *r, | 183 json_append_file_list (struct json_manifest_reader *r, |
162 struct file_list **nacl_file_list, | 184 struct file_list **nacl_file_list, |
163 const char *original_name, | 185 const char *original_name, |
164 const char *name) | 186 const char *name) |
165 { | 187 { |
166 struct file_list *curr = XZALLOC (struct file_list); | 188 struct file_list *curr = XZALLOC (struct file_list); |
167 | 189 |
168 if (strlen(original_name) >= MANIFEST_MAX_STRING_SIZE) | 190 if (strlen(original_name) >= MANIFEST_MAX_STRING_SIZE) |
169 error (_("Original file name in manifest is too long.")); | 191 error (_("Original file name in manifest is too long.")); |
170 strcpy (curr->original_name, original_name); | 192 strcpy (curr->original_name, original_name); |
171 | 193 append_dir_name (r, curr->name, MANIFEST_MAX_STRING_SIZE, name); |
172 if (r->dirname) | |
173 { | |
174 strcpy (curr->name, r->dirname); | |
175 if (strlen(curr->name) + strlen(SLASH_STRING) >= MANIFEST_MAX_STRING_SIZE) | |
176 » error (_("Mapped file name in manifest is too long.")); | |
177 strcat (curr->name, SLASH_STRING); | |
178 } | |
179 if (strlen(curr->name) + strlen(name) >= MANIFEST_MAX_STRING_SIZE) | |
180 error (_("Mapped file name in manifest is too long.")); | |
181 strcat (curr->name, name); | |
182 | 194 |
183 curr->next = *nacl_file_list; | 195 curr->next = *nacl_file_list; |
184 *nacl_file_list = curr; | 196 *nacl_file_list = curr; |
185 return curr; | 197 return curr; |
186 } | 198 } |
187 | 199 |
188 static void | 200 static void |
189 json_on_string_value (struct json_manifest_reader *r, const char *value) | 201 json_on_string_value (struct json_manifest_reader *r, const char *value) |
190 { | 202 { |
191 if (r->nesting == 3 && | 203 if (r->nesting == 3 && |
192 strcmp(r->members[0], "program") == 0 && | 204 strcmp(r->members[0], "program") == 0 && |
193 strcmp(r->members[2], "url") == 0) | 205 strcmp(r->members[2], "url") == 0) |
194 { | 206 { |
195 /* We'll xfree nacl_program_filename_* in nacl_manifest_free. */ | 207 /* We'll xfree nacl_program_filename_* in nacl_manifest_free. */ |
196 if (strcmp (r->members[1], "x86-32") == 0) | 208 if (strcmp (r->members[1], "x86-32") == 0) |
197 » nacl_program_filename_32 = xstrdup (value); | 209 » { |
| 210 » nacl_program_filename_32 = malloc (MANIFEST_MAX_STRING_SIZE); |
| 211 » append_dir_name (r, nacl_program_filename_32, |
| 212 » » » MANIFEST_MAX_STRING_SIZE, value); |
| 213 » } |
198 else if (strcmp (r->members[1], "x86-64") == 0) | 214 else if (strcmp (r->members[1], "x86-64") == 0) |
199 » nacl_program_filename_64 = xstrdup (value); | 215 » { |
| 216 » nacl_program_filename_64 = malloc (MANIFEST_MAX_STRING_SIZE); |
| 217 » append_dir_name (r, nacl_program_filename_64, |
| 218 » » » MANIFEST_MAX_STRING_SIZE, value); |
| 219 » } |
200 } | 220 } |
201 else if (r->nesting == 4 && | 221 else if (r->nesting == 4 && |
202 strcmp (r->members[0], "files") == 0 && | 222 strcmp (r->members[0], "files") == 0 && |
203 strcmp (r->members[3], "url") == 0) | 223 strcmp (r->members[3], "url") == 0) |
204 { | 224 { |
205 if (strcmp(r->members[2], "x86-32") == 0) | 225 if (strcmp(r->members[2], "x86-32") == 0) |
206 json_append_file_list(r, &nacl_file_list_32, r->members[1], value); | 226 json_append_file_list(r, &nacl_file_list_32, r->members[1], value); |
207 else if (strcmp(r->members[2], "x86-64") == 0) | 227 else if (strcmp(r->members[2], "x86-64") == 0) |
208 json_append_file_list(r, &nacl_file_list_64, r->members[1], value); | 228 json_append_file_list(r, &nacl_file_list_64, r->members[1], value); |
209 } | 229 } |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 { | 342 { |
323 if (args) | 343 if (args) |
324 { | 344 { |
325 xfree (nacl_irt_filename); | 345 xfree (nacl_irt_filename); |
326 nacl_irt_filename = tilde_expand (args); | 346 nacl_irt_filename = tilde_expand (args); |
327 | 347 |
328 solib_add (NULL, from_tty, NULL, 1); | 348 solib_add (NULL, from_tty, NULL, 1); |
329 } | 349 } |
330 } | 350 } |
331 | 351 |
| 352 static struct observer *about_to_proceed_observer = NULL; |
| 353 |
| 354 static void |
| 355 about_to_proceed_hook () |
| 356 { |
| 357 if (exec_bfd == NULL) |
| 358 { |
| 359 const char *filename = nacl_manifest_find ("NaClMain"); |
| 360 exec_file_attach (filename, 0); |
| 361 symbol_file_add (filename, SYMFILE_MAINLINE, NULL, 0); |
| 362 } |
| 363 } |
| 364 |
332 static void | 365 static void |
333 nacl_manifest_command (char *args, int from_tty) | 366 nacl_manifest_command (char *args, int from_tty) |
334 { | 367 { |
335 if (args) | 368 if (args) |
336 { | 369 { |
337 char *manifest_filename; | 370 char *manifest_filename; |
338 struct cleanup *old_chain; | 371 struct cleanup *old_chain; |
339 struct json_manifest_reader r = { 0 }; | 372 struct json_manifest_reader r = { 0 }; |
340 | 373 |
341 manifest_filename = tilde_expand (args); | 374 manifest_filename = tilde_expand (args); |
342 old_chain = make_cleanup (xfree, manifest_filename); | 375 old_chain = make_cleanup (xfree, manifest_filename); |
343 | 376 |
344 r.file = fopen (manifest_filename, "r"); | 377 r.file = fopen (manifest_filename, "r"); |
345 if (!r.file) | 378 if (!r.file) |
346 perror_with_name (manifest_filename); | 379 perror_with_name (manifest_filename); |
347 make_cleanup_fclose (r.file); | 380 make_cleanup_fclose (r.file); |
348 | 381 |
349 r.dirname = ldirname (manifest_filename); | 382 r.dirname = ldirname (manifest_filename); |
350 make_cleanup (xfree, r.dirname); | 383 make_cleanup (xfree, r.dirname); |
351 | 384 |
352 /* TODO: Kill existing manifest only if new one parsed OK! */ | 385 /* TODO: Kill existing manifest only if new one parsed OK! */ |
353 nacl_manifest_free (); | 386 nacl_manifest_free (); |
354 json_parse_value (&r); | 387 json_parse_value (&r); |
355 | 388 |
356 solib_add (NULL, from_tty, NULL, 1); | 389 solib_add (NULL, from_tty, NULL, 1); |
357 | 390 |
| 391 if (about_to_proceed_observer == NULL) |
| 392 { |
| 393 about_to_proceed_observer |
| 394 = observer_attach_about_to_proceed (about_to_proceed_hook); |
| 395 } |
| 396 |
358 do_cleanups(old_chain); | 397 do_cleanups(old_chain); |
359 } | 398 } |
360 } | 399 } |
361 | 400 |
362 void | 401 void |
363 _initialize_nacl_manifest (void) | 402 _initialize_nacl_manifest (void) |
364 { | 403 { |
365 struct cmd_list_element *c; | 404 struct cmd_list_element *c; |
366 | 405 |
367 c = add_com ("nacl-irt", class_files, nacl_irt_command, | 406 c = add_com ("nacl-irt", class_files, nacl_irt_command, |
368 _("Use FILE as Native Client IRT to be debugged.")); | 407 _("Use FILE as Native Client IRT to be debugged.")); |
369 set_cmd_completer (c, filename_completer); | 408 set_cmd_completer (c, filename_completer); |
370 | 409 |
371 c = add_com ("nacl-manifest", class_files, nacl_manifest_command, | 410 c = add_com ("nacl-manifest", class_files, nacl_manifest_command, |
372 _("Use FILE as Native Client manifest for the program" | 411 _("Use FILE as Native Client manifest for the program" |
373 " to be debugged.")); | 412 " to be debugged.")); |
374 set_cmd_completer (c, filename_completer); | 413 set_cmd_completer (c, filename_completer); |
375 } | 414 } |
OLD | NEW |