summaryrefslogtreecommitdiff
path: root/usr/src/lib/libctf/common/libctf.h
blob: 8f6a23205753b52955a3a03da3aaf3f0cbc7c02c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2001-2003 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */
/*
 * Copyright (c) 2019, Joyent, Inc.
 * Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
 */

/*
 * This header file defines the interfaces available from the CTF debugger
 * library, libctf.  This library provides functions that a debugger can
 * use to operate on data in the Compact ANSI-C Type Format (CTF).  This
 * is NOT a public interface, although it may eventually become one in
 * the fullness of time after we gain more experience with the interfaces.
 *
 * In the meantime, be aware that any program linked with libctf in this
 * release of illumos is almost guaranteed to break in the next release.
 *
 * In short, do not use this header file or libctf for any purpose.
 */

#ifndef	_LIBCTF_H
#define	_LIBCTF_H

#include <sys/ctf_api.h>
#include <libelf.h>

#ifdef	__cplusplus
extern "C" {
#endif

/*
 * This flag can be used to enable debug messages.
 */
extern int _libctf_debug;

typedef enum ctf_diff_flag {
	CTF_DIFF_F_IGNORE_INTNAMES = 0x01
} ctf_diff_flag_t;

typedef struct ctf_diff ctf_diff_t;
typedef void (*ctf_diff_type_f)(ctf_file_t *, ctf_id_t, boolean_t, ctf_file_t *,
    ctf_id_t, void *);
typedef void (*ctf_diff_func_f)(ctf_file_t *, ulong_t, boolean_t, ctf_file_t *,
    ulong_t, void *);
typedef void (*ctf_diff_obj_f)(ctf_file_t *, ulong_t, ctf_id_t, boolean_t,
    ctf_file_t *, ulong_t, ctf_id_t, void *);

extern int ctf_diff_init(ctf_file_t *, ctf_file_t *, ctf_diff_t **);
extern uint_t ctf_diff_getflags(ctf_diff_t *);
extern int ctf_diff_setflags(ctf_diff_t *, uint_t);
extern int ctf_diff_types(ctf_diff_t *, ctf_diff_type_f, void *);
extern int ctf_diff_functions(ctf_diff_t *, ctf_diff_func_f, void *);
extern int ctf_diff_objects(ctf_diff_t *, ctf_diff_obj_f, void *);
extern void ctf_diff_fini(ctf_diff_t *);

#define	CTF_CONVERT_DEFAULT_BATCHSIZE	256
#define	CTF_CONVERT_DEFAULT_NTHREADS	4

typedef enum ctf_convert_flag {
	/*
	 * Normally, we return a failure if we find a C-derived compilation
	 * unit that lacks DWARF or CTF (as required).  This flag over-rides
	 * this check.
	 */
	CTF_ALLOW_MISSING_DEBUG	 = 0x01,
	/*
	 * Normally, we return a failure if we can't fully convert a structure
	 * to CTF format, such as an enum with too many values. This flag
	 * allows us to continue and convert what we can.
	 */
	CTF_ALLOW_TRUNCATION = 0x02,
	/*
	 * Conversion is not usually attempted for objects that don't appear
	 * to be built from C sources. This flag overrides this and attempts
	 * conversion anyway.
	 */
	CTF_FORCE_CONVERSION = 0x04
} ctf_convert_flag_t;

#define	CTF_CONVERT_ALL_FLAGS	(CTF_ALLOW_MISSING_DEBUG | \
				    CTF_ALLOW_TRUNCATION | \
				    CTF_FORCE_CONVERSION)

/* opaque handle for ctfconvert functions */
struct ctf_convert_handle;
typedef struct ctf_convert_handle ctf_convert_t;

extern ctf_convert_t *ctf_convert_init(int *);
extern void ctf_convert_fini(ctf_convert_t *);

typedef void (*ctf_convert_warn_f)(void *, const char *, ...);
/* Any warning callback must be MT-Safe if multiple threads are used */
extern int ctf_convert_set_warncb(ctf_convert_t *, ctf_convert_warn_f, void *);
extern int ctf_convert_set_batchsize(ctf_convert_t *, uint_t);
extern int ctf_convert_set_flags(ctf_convert_t *, ctf_convert_flag_t);
extern int ctf_convert_set_label(ctf_convert_t *, const char *);
extern int ctf_convert_set_nthreads(ctf_convert_t *, uint_t);

extern ctf_file_t *ctf_fdconvert(ctf_convert_t *, int, int *, char *, size_t);


typedef enum ctf_hsc_ret {
	CHR_ERROR = -1,
	CHR_NO_C_SOURCE = 0,
	CHR_HAS_C_SOURCE = 1
} ctf_hsc_ret_t;

extern ctf_hsc_ret_t ctf_has_c_source(Elf *, char *, size_t);

typedef struct ctf_merge_handle ctf_merge_t;
extern ctf_merge_t *ctf_merge_init(int, int *);
extern int ctf_merge_add(ctf_merge_t *, ctf_file_t *);
extern int ctf_merge_set_nthreads(ctf_merge_t *, const uint_t);
extern int ctf_merge_label(ctf_merge_t *, const char *);
extern int ctf_merge_uniquify(ctf_merge_t *, ctf_file_t *, const char *);
extern int ctf_merge_merge(ctf_merge_t *, ctf_file_t **);
extern int ctf_merge_dedup(ctf_merge_t *, ctf_file_t **);
extern void ctf_merge_fini(ctf_merge_t *);

#define	CTF_ELFWRITE_F_COMPRESS		0x1
extern int ctf_elffdwrite(ctf_file_t *, int, int, int);
extern int ctf_elfwrite(ctf_file_t *, const char *, const char *, int);

#ifdef	__cplusplus
}
#endif

#endif	/* _LIBCTF_H */