#include <sys/param.h>
#include <sys/types.h>
#include <ctf.h>
+#include <zlib.h>
#ifdef __cplusplus
extern "C"
typedef struct ctf_archive_internal ctf_archive_t;
typedef long ctf_id_t;
+/* This opaque definition allows libctf to accept BFD data structures without
+ importing all the BFD noise into users' namespaces. */
+
+struct bfd;
+
+/* If the debugger needs to provide the CTF library with a set of raw buffers
+ for use as the CTF data, symbol table, and string table, it can do so by
+ filling in ctf_sect_t structures and passing them to ctf_bufopen().
+
+ The contents of this structure must always be in native endianness (no
+ byteswapping is performed). */
+
+typedef struct ctf_sect
+{
+ const char *cts_name; /* Section name (if any). */
+ unsigned long cts_type; /* Section type (ELF SHT_... value). */
+ unsigned long cts_flags; /* Section flags (ELF SHF_... value). */
+ const void *cts_data; /* Pointer to section data. */
+ size_t cts_size; /* Size of data in bytes. */
+ size_t cts_entsize; /* Size of each section entry (symtab only). */
+ off64_t cts_offset; /* File offset of this section (if any). */
+} ctf_sect_t;
+
+/* Symbolic names for CTF sections. */
+
+typedef enum ctf_sect_names
+ {
+ CTF_SECT_HEADER,
+ CTF_SECT_LABEL,
+ CTF_SECT_OBJT,
+ CTF_SECT_FUNC,
+ CTF_SECT_VAR,
+ CTF_SECT_TYPE,
+ CTF_SECT_STR
+ } ctf_sect_names_t;
+
+/* Encoding information for integers, floating-point values, and certain other
+ intrinsics can be obtained by calling ctf_type_encoding(), below. The flags
+ field will contain values appropriate for the type defined in <ctf.h>. */
+
+typedef struct ctf_encoding
+{
+ uint32_t cte_format; /* Data format (CTF_INT_* or CTF_FP_* flags). */
+ uint32_t cte_offset; /* Offset of value in bits. */
+ uint32_t cte_bits; /* Size of storage in bits. */
+} ctf_encoding_t;
+
+typedef struct ctf_membinfo
+{
+ ctf_id_t ctm_type; /* Type of struct or union member. */
+ unsigned long ctm_offset; /* Offset of member in bits. */
+} ctf_membinfo_t;
+
+typedef struct ctf_arinfo
+{
+ ctf_id_t ctr_contents; /* Type of array contents. */
+ ctf_id_t ctr_index; /* Type of array index. */
+ uint32_t ctr_nelems; /* Number of elements. */
+} ctf_arinfo_t;
+
+typedef struct ctf_funcinfo
+{
+ ctf_id_t ctc_return; /* Function return type. */
+ uint32_t ctc_argc; /* Number of typed arguments to function. */
+ uint32_t ctc_flags; /* Function attributes (see below). */
+} ctf_funcinfo_t;
+
+typedef struct ctf_lblinfo
+{
+ ctf_id_t ctb_type; /* Last type associated with the label. */
+} ctf_lblinfo_t;
+
+typedef struct ctf_snapshot_id
+{
+ unsigned long dtd_id; /* Highest DTD ID at time of snapshot. */
+ unsigned long snapshot_id; /* Snapshot id at time of snapshot. */
+} ctf_snapshot_id_t;
+
+#define CTF_FUNC_VARARG 0x1 /* Function arguments end with varargs. */
+
/* Functions that return integer status or a ctf_id_t use the following value
to indicate failure. ctf_errno() can be used to obtain an error code. */
#define CTF_ERR (-1L)
#define CTF_ADD_NONROOT 0 /* Type only visible in nested scope. */
#define CTF_ADD_ROOT 1 /* Type visible at top-level scope. */
+/* These typedefs are used to define the signature for callback functions
+ that can be used with the iteration and visit functions below. */
+
+typedef int ctf_archive_member_f (ctf_file_t *fp, const char *name, void *arg);
+typedef int ctf_archive_raw_member_f (const char *name, const void *content,
+ size_t len, void *arg);
+
+/* Opening. These mostly return an abstraction over both CTF files and CTF
+ archives: so they can be used to open both. CTF files will appear to be an
+ archive with one member named '.ctf'. The low-level functions
+ ctf_simple_open() and ctf_bufopen() return ctf_file_t's directly, and cannot
+ be used on CTF archives. */
+
+extern ctf_archive_t *ctf_bfdopen (struct bfd *, int *);
+extern ctf_archive_t *ctf_bfdopen_ctfsect (struct bfd *, const ctf_sect_t *,
+ int *);
+extern ctf_archive_t *ctf_fdopen (int fd, const char *filename,
+ const char *target, int *errp);
+extern ctf_archive_t *ctf_open (const char *filename,
+ const char *target, int *errp);
+extern void ctf_close (ctf_archive_t *);
+extern ctf_sect_t ctf_getdatasect (const ctf_file_t *);
+extern ctf_archive_t *ctf_get_arc (const ctf_file_t *);
+extern ctf_archive_t *ctf_arc_open (const char *, int *);
+extern void ctf_arc_close (ctf_archive_t *);
+extern ctf_file_t *ctf_arc_open_by_name (const ctf_archive_t *,
+ const char *, int *);
+extern ctf_file_t *ctf_arc_open_by_name_sections (const ctf_archive_t *,
+ const ctf_sect_t *,
+ const ctf_sect_t *,
+ const char *, int *);
+
+/* The next functions return or close real CTF files, or write out CTF archives,
+ not opaque containers around either. */
+
+extern ctf_file_t *ctf_simple_open (const char *, size_t, const char *, size_t,
+ size_t, const char *, size_t, int *);
+extern ctf_file_t *ctf_bufopen (const ctf_sect_t *, const ctf_sect_t *,
+ const ctf_sect_t *, int *);
+extern void ctf_file_close (ctf_file_t *);
+
+extern int ctf_arc_write (const char *, ctf_file_t **, size_t,
+ const char **, size_t);
+
+extern ctf_file_t *ctf_parent_file (ctf_file_t *);
+extern const char *ctf_parent_name (ctf_file_t *);
+extern void ctf_parent_name_set (ctf_file_t *, const char *);
+
+extern int ctf_import (ctf_file_t *, ctf_file_t *);
+extern int ctf_setmodel (ctf_file_t *, int);
+extern int ctf_getmodel (ctf_file_t *);
+
+extern void ctf_setspecific (ctf_file_t *, void *);
+extern void *ctf_getspecific (ctf_file_t *);
+
+extern int ctf_errno (ctf_file_t *);
+extern const char *ctf_errmsg (int);
+extern int ctf_archive_iter (const ctf_archive_t *, ctf_archive_member_f *,
+ void *);
+/* This function alone does not currently operate on CTF files masquerading
+ as archives, and returns -EINVAL: the raw data is no longer available. It is
+ expected to be used only by archiving tools, in any case, which have no need
+ to deal with non-archives at all. */
+extern int ctf_archive_raw_iter (const ctf_archive_t *,
+ ctf_archive_raw_member_f *, void *);
+extern ctf_id_t ctf_add_array (ctf_file_t *, uint32_t,
+ const ctf_arinfo_t *);
+extern ctf_id_t ctf_add_const (ctf_file_t *, uint32_t, ctf_id_t);
+extern ctf_id_t ctf_add_enum_encoded (ctf_file_t *, uint32_t, const char *,
+ const ctf_encoding_t *);
+extern ctf_id_t ctf_add_enum (ctf_file_t *, uint32_t, const char *);
+extern ctf_id_t ctf_add_float (ctf_file_t *, uint32_t,
+ const char *, const ctf_encoding_t *);
+extern ctf_id_t ctf_add_forward (ctf_file_t *, uint32_t, const char *,
+ uint32_t);
+extern ctf_id_t ctf_add_function (ctf_file_t *, uint32_t,
+ const ctf_funcinfo_t *, const ctf_id_t *);
+extern ctf_id_t ctf_add_integer (ctf_file_t *, uint32_t, const char *,
+ const ctf_encoding_t *);
+extern ctf_id_t ctf_add_slice (ctf_file_t *, uint32_t, ctf_id_t, const ctf_encoding_t *);
+extern ctf_id_t ctf_add_pointer (ctf_file_t *, uint32_t, ctf_id_t);
+extern ctf_id_t ctf_add_type (ctf_file_t *, ctf_file_t *, ctf_id_t);
+extern ctf_id_t ctf_add_typedef (ctf_file_t *, uint32_t, const char *,
+ ctf_id_t);
+extern ctf_id_t ctf_add_restrict (ctf_file_t *, uint32_t, ctf_id_t);
+extern ctf_id_t ctf_add_struct (ctf_file_t *, uint32_t, const char *);
+extern ctf_id_t ctf_add_union (ctf_file_t *, uint32_t, const char *);
+extern ctf_id_t ctf_add_struct_sized (ctf_file_t *, uint32_t, const char *,
+ size_t);
+extern ctf_id_t ctf_add_union_sized (ctf_file_t *, uint32_t, const char *,
+ size_t);
+extern ctf_id_t ctf_add_volatile (ctf_file_t *, uint32_t, ctf_id_t);
+
+extern int ctf_add_enumerator (ctf_file_t *, ctf_id_t, const char *, int);
+extern int ctf_add_member (ctf_file_t *, ctf_id_t, const char *, ctf_id_t);
+extern int ctf_add_member_offset (ctf_file_t *, ctf_id_t, const char *,
+ ctf_id_t, unsigned long);
+extern int ctf_add_member_encoded (ctf_file_t *, ctf_id_t, const char *,
+ ctf_id_t, unsigned long,
+ const ctf_encoding_t);
+
+extern int ctf_add_variable (ctf_file_t *, const char *, ctf_id_t);
+
+extern int ctf_set_array (ctf_file_t *, ctf_id_t, const ctf_arinfo_t *);
+
+extern ctf_file_t *ctf_create (int *);
+extern int ctf_update (ctf_file_t *);
+extern ctf_snapshot_id_t ctf_snapshot (ctf_file_t *);
+extern int ctf_rollback (ctf_file_t *, ctf_snapshot_id_t);
+extern int ctf_discard (ctf_file_t *);
+extern int ctf_write (ctf_file_t *, int);
+extern int ctf_gzwrite (ctf_file_t * fp, gzFile fd);
+extern int ctf_compress_write (ctf_file_t * fp, int fd);
extern void ctf_setdebug (int debug);
extern int ctf_getdebug (void);