Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: gdb/mi/mi-console.c

Issue 11969036: Merge GDB 7.5.1 (Closed) Base URL: http://git.chromium.org/native_client/nacl-gdb.git@master
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gdb/mi/mi-console.h ('k') | gdb/mi/mi-getopt.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* MI Console code. 1 /* MI Console code.
2 2
3 Copyright (C) 2000-2002, 2007-2012 Free Software Foundation, Inc. 3 Copyright (C) 2000-2002, 2007-2012 Free Software Foundation, Inc.
4 4
5 Contributed by Cygnus Solutions (a Red Hat company). 5 Contributed by Cygnus Solutions (a Red Hat company).
6 6
7 This file is part of GDB. 7 This file is part of GDB.
8 8
9 This program is free software; you can redistribute it and/or modify 9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by 10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or 11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version. 12 (at your option) any later version.
13 13
14 This program is distributed in the hope that it will be useful, 14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details. 17 GNU General Public License for more details.
18 18
19 You should have received a copy of the GNU General Public License 19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 21
22 /* An MI console is a kind of ui_file stream that sends output to
23 stdout, but encapsulated and prefixed with a distinctive string;
24 for instance, error output is normally identified by a leading
25 "&". */
26
22 #include "defs.h" 27 #include "defs.h"
23 #include "mi-console.h" 28 #include "mi-console.h"
24 #include "gdb_string.h" 29 #include "gdb_string.h"
25 30
26 /* MI-console: send output to std-out but correcty encapsulated */
27
28 static ui_file_fputs_ftype mi_console_file_fputs; 31 static ui_file_fputs_ftype mi_console_file_fputs;
29 static ui_file_flush_ftype mi_console_file_flush; 32 static ui_file_flush_ftype mi_console_file_flush;
30 static ui_file_delete_ftype mi_console_file_delete; 33 static ui_file_delete_ftype mi_console_file_delete;
31 34
32 struct mi_console_file 35 struct mi_console_file
33 { 36 {
34 int *magic; 37 int *magic;
35 struct ui_file *raw; 38 struct ui_file *raw;
36 struct ui_file *buffer; 39 struct ui_file *buffer;
37 const char *prefix; 40 const char *prefix;
38 char quote; 41 char quote;
39 }; 42 };
40 43
41 int mi_console_file_magic; 44 /* Use the address of this otherwise-unused global as a magic number
45 identifying this class of ui_file objects. */
46 static int mi_console_file_magic;
47
48 /* Create a console that wraps the given output stream RAW with the
49 string PREFIX and quoting it with QUOTE. */
42 50
43 struct ui_file * 51 struct ui_file *
44 mi_console_file_new (struct ui_file *raw, 52 mi_console_file_new (struct ui_file *raw, const char *prefix, char quote)
45 » » const char *prefix, char quote)
46 { 53 {
47 struct ui_file *ui_file = ui_file_new (); 54 struct ui_file *ui_file = ui_file_new ();
48 struct mi_console_file *mi_console = XMALLOC (struct mi_console_file); 55 struct mi_console_file *mi_console = XMALLOC (struct mi_console_file);
49 56
50 mi_console->magic = &mi_console_file_magic; 57 mi_console->magic = &mi_console_file_magic;
51 mi_console->raw = raw; 58 mi_console->raw = raw;
52 mi_console->buffer = mem_fileopen (); 59 mi_console->buffer = mem_fileopen ();
53 mi_console->prefix = prefix; 60 mi_console->prefix = prefix;
54 mi_console->quote = quote; 61 mi_console->quote = quote;
55 set_ui_file_fputs (ui_file, mi_console_file_fputs); 62 set_ui_file_fputs (ui_file, mi_console_file_fputs);
56 set_ui_file_flush (ui_file, mi_console_file_flush); 63 set_ui_file_flush (ui_file, mi_console_file_flush);
57 set_ui_file_data (ui_file, mi_console, mi_console_file_delete); 64 set_ui_file_data (ui_file, mi_console, mi_console_file_delete);
65
58 return ui_file; 66 return ui_file;
59 } 67 }
60 68
61 static void 69 static void
62 mi_console_file_delete (struct ui_file *file) 70 mi_console_file_delete (struct ui_file *file)
63 { 71 {
64 struct mi_console_file *mi_console = ui_file_data (file); 72 struct mi_console_file *mi_console = ui_file_data (file);
65 73
66 if (mi_console->magic != &mi_console_file_magic) 74 if (mi_console->magic != &mi_console_file_magic)
67 internal_error (__FILE__, __LINE__, 75 internal_error (__FILE__, __LINE__,
68 _("mi_console_file_delete: bad magic number")); 76 _("mi_console_file_delete: bad magic number"));
77
69 xfree (mi_console); 78 xfree (mi_console);
70 } 79 }
71 80
72 static void 81 static void
73 mi_console_file_fputs (const char *buf, 82 mi_console_file_fputs (const char *buf, struct ui_file *file)
74 » » struct ui_file *file)
75 { 83 {
76 struct mi_console_file *mi_console = ui_file_data (file); 84 struct mi_console_file *mi_console = ui_file_data (file);
77 85
78 if (mi_console->magic != &mi_console_file_magic) 86 if (mi_console->magic != &mi_console_file_magic)
79 internal_error (__FILE__, __LINE__, 87 internal_error (__FILE__, __LINE__,
80 "mi_console_file_fputs: bad magic number"); 88 "mi_console_file_fputs: bad magic number");
81 /* Append the text to our internal buffer */ 89
90 /* Append the text to our internal buffer. */
82 fputs_unfiltered (buf, mi_console->buffer); 91 fputs_unfiltered (buf, mi_console->buffer);
83 /* Flush when an embedded \n */ 92 /* Flush when an embedded newline is present anywhere in the buffer. */
84 if (strchr (buf, '\n') != NULL) 93 if (strchr (buf, '\n') != NULL)
85 gdb_flush (file); 94 gdb_flush (file);
86 } 95 }
87 96
88 /* Transform a byte sequence into a console output packet. */ 97 /* Transform a byte sequence into a console output packet. */
98
89 static void 99 static void
90 mi_console_raw_packet (void *data, 100 mi_console_raw_packet (void *data, const char *buf, long length_buf)
91 » » const char *buf,
92 » » long length_buf)
93 { 101 {
94 struct mi_console_file *mi_console = data; 102 struct mi_console_file *mi_console = data;
95 103
96 if (mi_console->magic != &mi_console_file_magic) 104 if (mi_console->magic != &mi_console_file_magic)
97 internal_error (__FILE__, __LINE__, 105 internal_error (__FILE__, __LINE__,
98 » » _("mi_console_file_transform: bad magic number")); 106 » » _("mi_console_raw_packet: bad magic number"));
99 107
100 if (length_buf > 0) 108 if (length_buf > 0)
101 { 109 {
102 fputs_unfiltered (mi_console->prefix, mi_console->raw); 110 fputs_unfiltered (mi_console->prefix, mi_console->raw);
103 if (mi_console->quote) 111 if (mi_console->quote)
104 { 112 {
105 fputs_unfiltered ("\"", mi_console->raw); 113 fputs_unfiltered ("\"", mi_console->raw);
106 fputstrn_unfiltered (buf, length_buf, 114 fputstrn_unfiltered (buf, length_buf,
107 mi_console->quote, mi_console->raw); 115 mi_console->quote, mi_console->raw);
108 fputs_unfiltered ("\"\n", mi_console->raw); 116 fputs_unfiltered ("\"\n", mi_console->raw);
109 } 117 }
110 else 118 else
111 { 119 {
112 fputstrn_unfiltered (buf, length_buf, 0, mi_console->raw); 120 fputstrn_unfiltered (buf, length_buf, 0, mi_console->raw);
113 fputs_unfiltered ("\n", mi_console->raw); 121 fputs_unfiltered ("\n", mi_console->raw);
114 } 122 }
115 gdb_flush (mi_console->raw); 123 gdb_flush (mi_console->raw);
116 } 124 }
117 } 125 }
118 126
119 static void 127 static void
120 mi_console_file_flush (struct ui_file *file) 128 mi_console_file_flush (struct ui_file *file)
121 { 129 {
122 struct mi_console_file *mi_console = ui_file_data (file); 130 struct mi_console_file *mi_console = ui_file_data (file);
123 131
124 if (mi_console->magic != &mi_console_file_magic) 132 if (mi_console->magic != &mi_console_file_magic)
125 internal_error (__FILE__, __LINE__, 133 internal_error (__FILE__, __LINE__,
126 _("mi_console_file_flush: bad magic number")); 134 _("mi_console_file_flush: bad magic number"));
135
127 ui_file_put (mi_console->buffer, mi_console_raw_packet, mi_console); 136 ui_file_put (mi_console->buffer, mi_console_raw_packet, mi_console);
128 ui_file_rewind (mi_console->buffer); 137 ui_file_rewind (mi_console->buffer);
138
129 } 139 }
140
141 /* Change the underlying stream of the console directly; this is
142 useful as a minimum-impact way to reflect external changes like
143 logging enable/disable. */
144
145 void
146 mi_console_set_raw (struct ui_file *file, struct ui_file *raw)
147 {
148 struct mi_console_file *mi_console = ui_file_data (file);
149
150 if (mi_console->magic != &mi_console_file_magic)
151 internal_error (__FILE__, __LINE__,
152 _("mi_console_file_set_raw: bad magic number"));
153
154 mi_console->raw = raw;
155 }
OLDNEW
« no previous file with comments | « gdb/mi/mi-console.h ('k') | gdb/mi/mi-getopt.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698