GNU Binutils with patches for OS216
Revision | 98d9f24ed15c5ca33bff06647d87b85e22e586d2 (tree) |
---|---|
Time | 2016-06-21 09:11:53 |
Author | Pedro Alves <palves@redh...> |
Commiter | Pedro Alves |
Make main_ui be heap allocated
This is preparation for being able to create more than one UI object.
The change to gdb_main to stop using catch_errors is necessary because
catch_errors references current_uiout, which expands to
current_ui->m_current_ui, which would crash because current_ui is not
initialized yet at that point. It didn't trigger earlier in the
series because before this patch, main_ui/current_ui always start out
non-NULL.
gdb/ChangeLog:
2016-06-21 Pedro Alves <palves@redhat.com>
* event-top.c (main_ui_): Delete.
(main_ui, current_ui, ui_list): No longer initialize here.
* main.c (captured_main): UI initialization code factored out to
new new_ui function.
(gdb_main): Wrap captured_main with TRY/CATCH instead of
catch_errors.
* top.c (highest_ui_num): New global.
(new_ui): New function.
* top.h (struct ui) <num>: New field.
(new_ui): New declaration.
@@ -1,5 +1,18 @@ | ||
1 | 1 | 2016-06-21 Pedro Alves <palves@redhat.com> |
2 | 2 | |
3 | + * event-top.c (main_ui_): Delete. | |
4 | + (main_ui, current_ui, ui_list): No longer initialize here. | |
5 | + * main.c (captured_main): UI initialization code factored out to | |
6 | + new new_ui function. | |
7 | + (gdb_main): Wrap captured_main with TRY/CATCH instead of | |
8 | + catch_errors. | |
9 | + * top.c (highest_ui_num): New global. | |
10 | + (new_ui): New function. | |
11 | + * top.h (struct ui) <num>: New field. | |
12 | + (new_ui): New declaration. | |
13 | + | |
14 | +2016-06-21 Pedro Alves <palves@redhat.com> | |
15 | + | |
3 | 16 | * cli/cli-interp.c (cli_on_normal_stop): Bail out early if there's |
4 | 17 | nothing to print. Use should_print_stop_to_console. |
5 | 18 | * tui/tui-interp.c (tui_on_normal_stop): Likewise. |
@@ -441,12 +441,11 @@ top_level_prompt (void) | ||
441 | 441 | return xstrdup (prompt); |
442 | 442 | } |
443 | 443 | |
444 | -/* The main UI. */ | |
445 | -static struct ui main_ui_; | |
444 | +/* See top.h. */ | |
446 | 445 | |
447 | -struct ui *main_ui = &main_ui_; | |
448 | -struct ui *current_ui = &main_ui_; | |
449 | -struct ui *ui_list = &main_ui_; | |
446 | +struct ui *main_ui; | |
447 | +struct ui *current_ui; | |
448 | +struct ui *ui_list; | |
450 | 449 | |
451 | 450 | /* See top.h. */ |
452 | 451 |
@@ -443,7 +443,6 @@ DEF_VEC_O (cmdarg_s); | ||
443 | 443 | static int |
444 | 444 | captured_main (void *data) |
445 | 445 | { |
446 | - struct ui *ui = current_ui; | |
447 | 446 | struct captured_main_args *context = (struct captured_main_args *) data; |
448 | 447 | int argc = context->argc; |
449 | 448 | char **argv = context->argv; |
@@ -514,26 +513,15 @@ captured_main (void *data) | ||
514 | 513 | |
515 | 514 | saved_command_line = (char *) xstrdup (""); |
516 | 515 | |
517 | - ui->instream = stdin; | |
518 | - ui->outstream = stdout; | |
519 | - ui->errstream = stderr; | |
520 | - | |
521 | - ui->input_fd = fileno (stdin); | |
522 | - | |
523 | - ui->prompt_state = PROMPT_NEEDED; | |
524 | - | |
525 | 516 | #ifdef __MINGW32__ |
526 | 517 | /* Ensure stderr is unbuffered. A Cygwin pty or pipe is implemented |
527 | 518 | as a Windows pipe, and Windows buffers on pipes. */ |
528 | 519 | setvbuf (stderr, NULL, _IONBF, BUFSIZ); |
529 | 520 | #endif |
530 | 521 | |
531 | - gdb_stdout = stdio_fileopen (stdout); | |
532 | - gdb_stderr = stderr_fileopen (stderr); | |
522 | + main_ui = new_ui (stdin, stdout, stderr); | |
523 | + current_ui = main_ui; | |
533 | 524 | |
534 | - gdb_stdlog = gdb_stderr; /* for moment */ | |
535 | - gdb_stdtarg = gdb_stderr; /* for moment */ | |
536 | - gdb_stdin = stdio_fileopen (stdin); | |
537 | 525 | gdb_stdtargerr = gdb_stderr; /* for moment */ |
538 | 526 | gdb_stdtargin = gdb_stdin; /* for moment */ |
539 | 527 |
@@ -1174,7 +1162,16 @@ captured_main (void *data) | ||
1174 | 1162 | int |
1175 | 1163 | gdb_main (struct captured_main_args *args) |
1176 | 1164 | { |
1177 | - catch_errors (captured_main, args, "", RETURN_MASK_ALL); | |
1165 | + TRY | |
1166 | + { | |
1167 | + captured_main (args); | |
1168 | + } | |
1169 | + CATCH (ex, RETURN_MASK_ALL) | |
1170 | + { | |
1171 | + exception_print (gdb_stderr, ex); | |
1172 | + } | |
1173 | + END_CATCH | |
1174 | + | |
1178 | 1175 | /* The only way to end up here is by an error (normal exit is |
1179 | 1176 | handled by quit_force()), hence always return an error status. */ |
1180 | 1177 | return 1; |
@@ -246,6 +246,46 @@ void (*deprecated_call_command_hook) (struct cmd_list_element * c, | ||
246 | 246 | |
247 | 247 | void (*deprecated_context_hook) (int id); |
248 | 248 | |
249 | +/* The highest UI number ever assigned. */ | |
250 | +static int highest_ui_num; | |
251 | + | |
252 | +/* See top.h. */ | |
253 | + | |
254 | +struct ui * | |
255 | +new_ui (FILE *instream, FILE *outstream, FILE *errstream) | |
256 | +{ | |
257 | + struct ui *ui; | |
258 | + | |
259 | + ui = XCNEW (struct ui); | |
260 | + | |
261 | + ui->num = ++highest_ui_num; | |
262 | + ui->instream = instream; | |
263 | + ui->outstream = outstream; | |
264 | + ui->errstream = errstream; | |
265 | + | |
266 | + ui->input_fd = fileno (ui->instream); | |
267 | + | |
268 | + ui->m_gdb_stdin = stdio_fileopen (ui->instream); | |
269 | + ui->m_gdb_stdout = stdio_fileopen (ui->outstream); | |
270 | + ui->m_gdb_stderr = stderr_fileopen (ui->errstream); | |
271 | + ui->m_gdb_stdlog = ui->m_gdb_stderr; | |
272 | + | |
273 | + ui->prompt_state = PROMPT_NEEDED; | |
274 | + | |
275 | + if (ui_list == NULL) | |
276 | + ui_list = ui; | |
277 | + else | |
278 | + { | |
279 | + struct ui *last; | |
280 | + | |
281 | + for (last = ui_list; last->next != NULL; last = last->next) | |
282 | + ; | |
283 | + last->next = ui; | |
284 | + } | |
285 | + | |
286 | + return ui; | |
287 | +} | |
288 | + | |
249 | 289 | /* Handler for SIGHUP. */ |
250 | 290 | |
251 | 291 | #ifdef SIGHUP |
@@ -57,6 +57,9 @@ struct ui | ||
57 | 57 | /* Pointer to next in singly-linked list. */ |
58 | 58 | struct ui *next; |
59 | 59 | |
60 | + /* Convenient handle (UI number). Unique across all UIs. */ | |
61 | + int num; | |
62 | + | |
60 | 63 | /* The UI's command line buffer. This is to used to accumulate |
61 | 64 | input until we have a whole command line. */ |
62 | 65 | struct buffer line_buffer; |
@@ -170,6 +173,9 @@ extern void switch_thru_all_uis_next (struct switch_thru_all_uis *state); | ||
170 | 173 | #define ALL_UIS(UI) \ |
171 | 174 | for (UI = ui_list; UI; UI = UI->next) \ |
172 | 175 | |
176 | +/* Create a new UI. */ | |
177 | +extern struct ui *new_ui (FILE *instream, FILE *outstream, FILE *errstream); | |
178 | + | |
173 | 179 | /* Cleanup that restores the current UI. */ |
174 | 180 | extern void restore_ui_cleanup (void *data); |
175 | 181 |