gdb/common/common-utils.h - gdb

Macros defined

Source code

  1. /* Shared general utility routines for GDB, the GNU debugger.

  2.    Copyright (C) 1986-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #ifndef COMMON_UTILS_H
  15. #define COMMON_UTILS_H

  16. /* If possible, define FUNCTION_NAME, a macro containing the name of
  17.    the function being defined.  Since this macro may not always be
  18.    defined, all uses must be protected by appropriate macro definition
  19.    checks (Eg: "#ifdef FUNCTION_NAME").

  20.    Version 2.4 and later of GCC define a magical variable `__PRETTY_FUNCTION__'
  21.    which contains the name of the function currently being defined.
  22.    This is broken in G++ before version 2.6.
  23.    C9x has a similar variable called __func__, but prefer the GCC one since
  24.    it demangles C++ function names.  */
  25. #if (GCC_VERSION >= 2004)
  26. #define FUNCTION_NAME                __PRETTY_FUNCTION__
  27. #else
  28. #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
  29. #define FUNCTION_NAME                __func__  /* ARI: func */
  30. #endif
  31. #endif

  32. /* xmalloc(), xrealloc() and xcalloc() have already been declared in
  33.    "libiberty.h". */

  34. /* Like xmalloc, but zero the memory.  */
  35. void *xzalloc (size_t);

  36. void xfree (void *);

  37. /* Like asprintf and vasprintf, but return the string, throw an error
  38.    if no memory.  */
  39. char *xstrprintf (const char *format, ...) ATTRIBUTE_PRINTF (1, 2);
  40. char *xstrvprintf (const char *format, va_list ap)
  41.      ATTRIBUTE_PRINTF (1, 0);

  42. /* Like snprintf, but throw an error if the output buffer is too small.  */
  43. int xsnprintf (char *str, size_t size, const char *format, ...)
  44.      ATTRIBUTE_PRINTF (3, 4);

  45. /* Make a copy of the string at PTR with LEN characters
  46.    (and add a null character at the end in the copy).
  47.    Uses malloc to get the space.  Returns the address of the copy.  */

  48. char *savestring (const char *ptr, size_t len);

  49. #endif