mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-11-21 01:12:32 +08:00
06b3c5bdb0
This patch renames the .c source files in gdbsupport to .cc. In the gdb directory, there is an argument against renaming the source files, which is that it makes using some git commands more difficult to do archeology. Some commands have some kind of "follow" option that makes git try to follow renames, but it doesn't work in all situations. Given that we have just moved the gdbsupport directory, that argument doesn't hold for source files in that directory. I therefore suggest renaming them to .cc, so that they are automatically recognized as C++ by various tools and editors. The original motivation behind this is that when building gdbsupport with clang, I get: CC agent.o clang: error: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Werror,-Wdeprecated] In the gdb/ directory, we make clang happy by passing "-x c++". We could do this in gdbsupport too, but I think that renaming the files is a better long-term solution. gdbserver still does its own build of gdbsupport, so a few changes in its Makefile are necessary. gdbsupport/ChangeLog: * Makefile.am: Rename source files from .c to .cc. (CC, CFLAGS): Don't override. (AM_CFLAGS): Rename to ... (AM_CXXFLAGS): ... this. * Makefile.in: Re-generate. * %.c: Rename to %.cc. gdbserver/ChangeLog: * Makefile.in: Rename gdbsupport source files from .c to .cc.
179 lines
3.8 KiB
C++
179 lines
3.8 KiB
C++
/* A simple growing buffer for GDB.
|
|
|
|
Copyright (C) 2009-2020 Free Software Foundation, Inc.
|
|
|
|
This file is part of GDB.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
#include "common-defs.h"
|
|
#include "xml-utils.h"
|
|
#include "buffer.h"
|
|
#include "inttypes.h"
|
|
void
|
|
buffer_grow (struct buffer *buffer, const char *data, size_t size)
|
|
{
|
|
char *new_buffer;
|
|
size_t new_buffer_size;
|
|
|
|
if (size == 0)
|
|
return;
|
|
|
|
new_buffer_size = buffer->buffer_size;
|
|
|
|
if (new_buffer_size == 0)
|
|
new_buffer_size = 1;
|
|
|
|
while (buffer->used_size + size > new_buffer_size)
|
|
new_buffer_size *= 2;
|
|
new_buffer = (char *) xrealloc (buffer->buffer, new_buffer_size);
|
|
memcpy (new_buffer + buffer->used_size, data, size);
|
|
buffer->buffer = new_buffer;
|
|
buffer->buffer_size = new_buffer_size;
|
|
buffer->used_size += size;
|
|
}
|
|
|
|
void
|
|
buffer_free (struct buffer *buffer)
|
|
{
|
|
if (!buffer)
|
|
return;
|
|
|
|
xfree (buffer->buffer);
|
|
buffer->buffer = NULL;
|
|
buffer->buffer_size = 0;
|
|
buffer->used_size = 0;
|
|
}
|
|
|
|
void
|
|
buffer_init (struct buffer *buffer)
|
|
{
|
|
memset (buffer, 0, sizeof (*buffer));
|
|
}
|
|
|
|
char*
|
|
buffer_finish (struct buffer *buffer)
|
|
{
|
|
char *ret = buffer->buffer;
|
|
buffer->buffer = NULL;
|
|
buffer->buffer_size = 0;
|
|
buffer->used_size = 0;
|
|
return ret;
|
|
}
|
|
|
|
void
|
|
buffer_xml_printf (struct buffer *buffer, const char *format, ...)
|
|
{
|
|
va_list ap;
|
|
const char *f;
|
|
const char *prev;
|
|
int percent = 0;
|
|
|
|
va_start (ap, format);
|
|
|
|
prev = format;
|
|
for (f = format; *f; f++)
|
|
{
|
|
if (percent)
|
|
{
|
|
char buf[32];
|
|
char *str = buf;
|
|
const char *f_old = f;
|
|
|
|
switch (*f)
|
|
{
|
|
case 's':
|
|
str = va_arg (ap, char *);
|
|
break;
|
|
case 'd':
|
|
sprintf (str, "%d", va_arg (ap, int));
|
|
break;
|
|
case 'u':
|
|
sprintf (str, "%u", va_arg (ap, unsigned int));
|
|
break;
|
|
case 'x':
|
|
sprintf (str, "%x", va_arg (ap, unsigned int));
|
|
break;
|
|
case 'o':
|
|
sprintf (str, "%o", va_arg (ap, unsigned int));
|
|
break;
|
|
case 'l':
|
|
f++;
|
|
switch (*f)
|
|
{
|
|
case 'd':
|
|
sprintf (str, "%ld", va_arg (ap, long));
|
|
break;
|
|
case 'u':
|
|
sprintf (str, "%lu", va_arg (ap, unsigned long));
|
|
break;
|
|
case 'x':
|
|
sprintf (str, "%lx", va_arg (ap, unsigned long));
|
|
break;
|
|
case 'o':
|
|
sprintf (str, "%lo", va_arg (ap, unsigned long));
|
|
break;
|
|
case 'l':
|
|
f++;
|
|
switch (*f)
|
|
{
|
|
case 'd':
|
|
sprintf (str, "%" PRId64,
|
|
(int64_t) va_arg (ap, long long));
|
|
break;
|
|
case 'u':
|
|
sprintf (str, "%" PRIu64,
|
|
(uint64_t) va_arg (ap, unsigned long long));
|
|
break;
|
|
case 'x':
|
|
sprintf (str, "%" PRIx64,
|
|
(uint64_t) va_arg (ap, unsigned long long));
|
|
break;
|
|
case 'o':
|
|
sprintf (str, "%" PRIo64,
|
|
(uint64_t) va_arg (ap, unsigned long long));
|
|
break;
|
|
default:
|
|
str = 0;
|
|
break;
|
|
}
|
|
break;
|
|
default:
|
|
str = 0;
|
|
break;
|
|
}
|
|
break;
|
|
default:
|
|
str = 0;
|
|
break;
|
|
}
|
|
|
|
if (str)
|
|
{
|
|
buffer_grow (buffer, prev, f_old - prev - 1);
|
|
std::string p = xml_escape_text (str);
|
|
buffer_grow_str (buffer, p.c_str ());
|
|
prev = f + 1;
|
|
}
|
|
percent = 0;
|
|
}
|
|
else if (*f == '%')
|
|
percent = 1;
|
|
}
|
|
|
|
buffer_grow_str (buffer, prev);
|
|
va_end (ap);
|
|
}
|
|
|