aboutsummaryrefslogtreecommitdiff
path: root/libctf/ctf-impl.h
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2019-04-23 18:55:27 +0100
committerNick Alcock <nick.alcock@oracle.com>2019-05-28 17:07:15 +0100
commit60da9d955964759b1f52690bff587ad32a198507 (patch)
treee3d9dd8f6667916ef29c557e62c2d0f3fba6f6c0 /libctf/ctf-impl.h
parent2e94b05630514109994abb77ee2dae730f17c263 (diff)
downloadgdb-60da9d955964759b1f52690bff587ad32a198507.zip
gdb-60da9d955964759b1f52690bff587ad32a198507.tar.gz
gdb-60da9d955964759b1f52690bff587ad32a198507.tar.bz2
libctf: lowest-level memory allocation and debug-dumping wrappers
The memory-allocation wrappers are simple things to allow malloc interposition: they are only used inconsistently at present, usually where malloc debugging was required in the past. These provide a default implementation that is environment-variable triggered (initialized on the first call to the libctf creation and file-opening functions, the first functions people will use), and a ctf_setdebug()/ctf_getdebug() pair that allows the caller to explicitly turn debugging off and on. If ctf_setdebug() is called, the automatic setting from an environment variable is skipped. libctf/ * ctf-impl.h: New file. * ctf-subr.c: New file. include/ * ctf-api.h (ctf_setdebug): New. (ctf_getdebug): Likewise.
Diffstat (limited to 'libctf/ctf-impl.h')
-rw-r--r--libctf/ctf-impl.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/libctf/ctf-impl.h b/libctf/ctf-impl.h
new file mode 100644
index 0000000..4356a2a
--- /dev/null
+++ b/libctf/ctf-impl.h
@@ -0,0 +1,78 @@
+/* Implementation header.
+ Copyright (C) 2019 Free Software Foundation, Inc.
+
+ This file is part of libctf.
+
+ libctf 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, 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; see the file COPYING. If not see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _CTF_IMPL_H
+#define _CTF_IMPL_H
+
+#include "config.h"
+#include <sys/errno.h>
+#include <ctf-api.h>
+#include <sys/types.h>
+
+#ifdef __cplusplus
+extern "C"
+ {
+#endif
+
+/* Compiler attributes. */
+
+#if defined (__GNUC__)
+
+/* GCC. We assume that all compilers claiming to be GCC support sufficiently
+ many GCC attributes that the code below works. If some non-GCC compilers
+ masquerading as GCC in fact do not implement these attributes, version checks
+ may be required. */
+
+/* We use the _libctf_*_ pattern to avoid clashes with any future attribute
+ macros glibc may introduce, which have names of the pattern
+ __attribute_blah__. */
+
+#define _libctf_printflike_(string_index,first_to_check) \
+ __attribute__ ((__format__ (__printf__, (string_index), (first_to_check))))
+#define _libctf_unlikely_(x) __builtin_expect ((x), 0)
+#define _libctf_unused_ __attribute__ ((__unused__))
+#define _libctf_malloc_ __attribute__((__malloc__))
+
+#endif
+
+_libctf_malloc_
+extern void *ctf_data_alloc (size_t);
+extern void ctf_data_free (void *, size_t);
+extern void ctf_data_protect (void *, size_t);
+
+_libctf_malloc_
+extern void *ctf_mmap (size_t length, size_t offset, int fd);
+extern void ctf_munmap (void *, size_t);
+extern ssize_t ctf_pread (int fd, void *buf, ssize_t count, off_t offset);
+
+_libctf_malloc_
+extern void *ctf_alloc (size_t);
+extern void ctf_free (void *);
+
+_libctf_printflike_ (1, 2)
+extern void ctf_dprintf (const char *, ...);
+extern void libctf_init_debug (void);
+
+extern int _libctf_debug; /* debugging messages enabled */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _CTF_IMPL_H */