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

Side by Side Diff: gdb/common/buffer.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/common/ax.def ('k') | gdb/common/format.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 /* A simple growing buffer for GDB. 1 /* A simple growing buffer for GDB.
2 2
3 Copyright (C) 2009-2012 Free Software Foundation, Inc. 3 Copyright (C) 2009-2012 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 #ifdef GDBSERVER 20 #ifdef GDBSERVER
21 #include "server.h" 21 #include "server.h"
22 #else 22 #else
23 #include "defs.h" 23 #include "defs.h"
24 #endif 24 #endif
25 25
26 #include "xml-utils.h" 26 #include "xml-utils.h"
27 #include "buffer.h" 27 #include "buffer.h"
28 #include "inttypes.h"
28 29
29 #include <stdlib.h> 30 #include <stdlib.h>
30 #include <string.h> 31 #include <string.h>
31 #include <stdio.h> 32 #include <stdio.h>
33 #include <stdint.h>
32 34
33 void 35 void
34 buffer_grow (struct buffer *buffer, const char *data, size_t size) 36 buffer_grow (struct buffer *buffer, const char *data, size_t size)
35 { 37 {
36 char *new_buffer; 38 char *new_buffer;
37 size_t new_buffer_size; 39 size_t new_buffer_size;
38 40
39 if (size == 0) 41 if (size == 0)
40 return; 42 return;
41 43
42 new_buffer_size = buffer->buffer_size; 44 new_buffer_size = buffer->buffer_size;
43 45
44 if (new_buffer_size == 0) 46 if (new_buffer_size == 0)
45 new_buffer_size = 1; 47 new_buffer_size = 1;
46 48
47 while (buffer->used_size + size > new_buffer_size) 49 while (buffer->used_size + size > new_buffer_size)
48 new_buffer_size *= 2; 50 new_buffer_size *= 2;
49 new_buffer = xrealloc (buffer->buffer, new_buffer_size); 51 new_buffer = xrealloc (buffer->buffer, new_buffer_size);
50 if (!new_buffer)
51 abort ();
52 memcpy (new_buffer + buffer->used_size, data, size); 52 memcpy (new_buffer + buffer->used_size, data, size);
53 buffer->buffer = new_buffer; 53 buffer->buffer = new_buffer;
54 buffer->buffer_size = new_buffer_size; 54 buffer->buffer_size = new_buffer_size;
55 buffer->used_size += size; 55 buffer->used_size += size;
56 } 56 }
57 57
58 void 58 void
59 buffer_free (struct buffer *buffer) 59 buffer_free (struct buffer *buffer)
60 { 60 {
61 if (!buffer) 61 if (!buffer)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 va_start (ap, format); 94 va_start (ap, format);
95 95
96 prev = format; 96 prev = format;
97 for (f = format; *f; f++) 97 for (f = format; *f; f++)
98 { 98 {
99 if (percent) 99 if (percent)
100 { 100 {
101 char buf[32]; 101 char buf[32];
102 char *p; 102 char *p;
103 char *str = buf; 103 char *str = buf;
104 const char *f_old = f;
104 105
105 switch (*f) 106 switch (*f)
106 { 107 {
107 case 's': 108 case 's':
108 str = va_arg (ap, char *); 109 str = va_arg (ap, char *);
109 break; 110 break;
110 case 'd': 111 case 'd':
111 sprintf (str, "%d", va_arg (ap, int)); 112 sprintf (str, "%d", va_arg (ap, int));
112 break; 113 break;
113 case 'u': 114 case 'u':
114 sprintf (str, "%u", va_arg (ap, unsigned int)); 115 sprintf (str, "%u", va_arg (ap, unsigned int));
115 break; 116 break;
116 case 'x': 117 case 'x':
117 sprintf (str, "%x", va_arg (ap, unsigned int)); 118 sprintf (str, "%x", va_arg (ap, unsigned int));
118 break; 119 break;
119 case 'o': 120 case 'o':
120 sprintf (str, "%o", va_arg (ap, unsigned int)); 121 sprintf (str, "%o", va_arg (ap, unsigned int));
121 break; 122 break;
123 case 'l':
124 f++;
125 switch (*f)
126 {
127 case 'd':
128 sprintf (str, "%ld", va_arg (ap, long));
129 break;
130 case 'u':
131 sprintf (str, "%lu", va_arg (ap, unsigned long));
132 break;
133 case 'x':
134 sprintf (str, "%lx", va_arg (ap, unsigned long));
135 break;
136 case 'o':
137 sprintf (str, "%lo", va_arg (ap, unsigned long));
138 break;
139 case 'l':
140 f++;
141 switch (*f)
142 {
143 case 'd':
144 sprintf (str, "%" PRId64,
145 (int64_t) va_arg (ap, long long));
146 break;
147 case 'u':
148 sprintf (str, "%" PRIu64,
149 (uint64_t) va_arg (ap, unsigned long long));
150 break;
151 case 'x':
152 sprintf (str, "%" PRIx64,
153 (uint64_t) va_arg (ap, unsigned long long));
154 break;
155 case 'o':
156 sprintf (str, "%" PRIo64,
157 (uint64_t) va_arg (ap, unsigned long long));
158 break;
159 default:
160 str = 0;
161 break;
162 }
163 break;
164 default:
165 str = 0;
166 break;
167 }
168 break;
122 default: 169 default:
123 str = 0; 170 str = 0;
124 break; 171 break;
125 } 172 }
126 » 173
127 if (str) 174 if (str)
128 { 175 {
129 » buffer_grow (buffer, prev, f - prev - 1); 176 » buffer_grow (buffer, prev, f_old - prev - 1);
130 p = xml_escape_text (str); 177 p = xml_escape_text (str);
131 buffer_grow_str (buffer, p); 178 buffer_grow_str (buffer, p);
132 xfree (p); 179 xfree (p);
133 prev = f + 1; 180 prev = f + 1;
134 } 181 }
135 percent = 0; 182 percent = 0;
136 } 183 }
137 else if (*f == '%') 184 else if (*f == '%')
138 percent = 1; 185 percent = 1;
139 } 186 }
140 187
141 buffer_grow_str (buffer, prev); 188 buffer_grow_str (buffer, prev);
142 va_end (ap); 189 va_end (ap);
143 } 190 }
144 191
OLDNEW
« no previous file with comments | « gdb/common/ax.def ('k') | gdb/common/format.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698