• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

修訂98d9f24ed15c5ca33bff06647d87b85e22e586d2 (tree)
時間2016-06-21 09:11:53
作者Pedro Alves <palves@redh...>
CommiterPedro Alves

Log Message

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.

Change Summary

差異

--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,18 @@
11 2016-06-21 Pedro Alves <palves@redhat.com>
22
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+
316 * cli/cli-interp.c (cli_on_normal_stop): Bail out early if there's
417 nothing to print. Use should_print_stop_to_console.
518 * tui/tui-interp.c (tui_on_normal_stop): Likewise.
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -441,12 +441,11 @@ top_level_prompt (void)
441441 return xstrdup (prompt);
442442 }
443443
444-/* The main UI. */
445-static struct ui main_ui_;
444+/* See top.h. */
446445
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;
450449
451450 /* See top.h. */
452451
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -443,7 +443,6 @@ DEF_VEC_O (cmdarg_s);
443443 static int
444444 captured_main (void *data)
445445 {
446- struct ui *ui = current_ui;
447446 struct captured_main_args *context = (struct captured_main_args *) data;
448447 int argc = context->argc;
449448 char **argv = context->argv;
@@ -514,26 +513,15 @@ captured_main (void *data)
514513
515514 saved_command_line = (char *) xstrdup ("");
516515
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-
525516 #ifdef __MINGW32__
526517 /* Ensure stderr is unbuffered. A Cygwin pty or pipe is implemented
527518 as a Windows pipe, and Windows buffers on pipes. */
528519 setvbuf (stderr, NULL, _IONBF, BUFSIZ);
529520 #endif
530521
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;
533524
534- gdb_stdlog = gdb_stderr; /* for moment */
535- gdb_stdtarg = gdb_stderr; /* for moment */
536- gdb_stdin = stdio_fileopen (stdin);
537525 gdb_stdtargerr = gdb_stderr; /* for moment */
538526 gdb_stdtargin = gdb_stdin; /* for moment */
539527
@@ -1174,7 +1162,16 @@ captured_main (void *data)
11741162 int
11751163 gdb_main (struct captured_main_args *args)
11761164 {
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+
11781175 /* The only way to end up here is by an error (normal exit is
11791176 handled by quit_force()), hence always return an error status. */
11801177 return 1;
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -246,6 +246,46 @@ void (*deprecated_call_command_hook) (struct cmd_list_element * c,
246246
247247 void (*deprecated_context_hook) (int id);
248248
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+
249289 /* Handler for SIGHUP. */
250290
251291 #ifdef SIGHUP
--- a/gdb/top.h
+++ b/gdb/top.h
@@ -57,6 +57,9 @@ struct ui
5757 /* Pointer to next in singly-linked list. */
5858 struct ui *next;
5959
60+ /* Convenient handle (UI number). Unique across all UIs. */
61+ int num;
62+
6063 /* The UI's command line buffer. This is to used to accumulate
6164 input until we have a whole command line. */
6265 struct buffer line_buffer;
@@ -170,6 +173,9 @@ extern void switch_thru_all_uis_next (struct switch_thru_all_uis *state);
170173 #define ALL_UIS(UI) \
171174 for (UI = ui_list; UI; UI = UI->next) \
172175
176+/* Create a new UI. */
177+extern struct ui *new_ui (FILE *instream, FILE *outstream, FILE *errstream);
178+
173179 /* Cleanup that restores the current UI. */
174180 extern void restore_ui_cleanup (void *data);
175181