17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright 2001-2003 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 26bc1f688bSRobert Mustacchi /* 273eca6103SJohn Levon * Copyright (c) 2019, Joyent, Inc. 28dd442252SAndy Fiddaman * Copyright 2020 OmniOS Community Edition (OmniOSce) Association. 29bc1f688bSRobert Mustacchi */ 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate /* 327c478bd9Sstevel@tonic-gate * This header file defines the interfaces available from the CTF debugger 337c478bd9Sstevel@tonic-gate * library, libctf. This library provides functions that a debugger can 347c478bd9Sstevel@tonic-gate * use to operate on data in the Compact ANSI-C Type Format (CTF). This 357c478bd9Sstevel@tonic-gate * is NOT a public interface, although it may eventually become one in 367c478bd9Sstevel@tonic-gate * the fullness of time after we gain more experience with the interfaces. 377c478bd9Sstevel@tonic-gate * 387c478bd9Sstevel@tonic-gate * In the meantime, be aware that any program linked with libctf in this 39bc1f688bSRobert Mustacchi * release of illumos is almost guaranteed to break in the next release. 407c478bd9Sstevel@tonic-gate * 41dd442252SAndy Fiddaman * In short, do not use this header file or libctf for any purpose. 427c478bd9Sstevel@tonic-gate */ 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate #ifndef _LIBCTF_H 457c478bd9Sstevel@tonic-gate #define _LIBCTF_H 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate #include <sys/ctf_api.h> 483eca6103SJohn Levon #include <libelf.h> 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate #ifdef __cplusplus 517c478bd9Sstevel@tonic-gate extern "C" { 527c478bd9Sstevel@tonic-gate #endif 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate /* 557c478bd9Sstevel@tonic-gate * This flag can be used to enable debug messages. 567c478bd9Sstevel@tonic-gate */ 577c478bd9Sstevel@tonic-gate extern int _libctf_debug; 587c478bd9Sstevel@tonic-gate 59bc1f688bSRobert Mustacchi typedef enum ctf_diff_flag { 60bc1f688bSRobert Mustacchi CTF_DIFF_F_IGNORE_INTNAMES = 0x01 61bc1f688bSRobert Mustacchi } ctf_diff_flag_t; 62bc1f688bSRobert Mustacchi 63bc1f688bSRobert Mustacchi typedef struct ctf_diff ctf_diff_t; 64bc1f688bSRobert Mustacchi typedef void (*ctf_diff_type_f)(ctf_file_t *, ctf_id_t, boolean_t, ctf_file_t *, 65bc1f688bSRobert Mustacchi ctf_id_t, void *); 66bc1f688bSRobert Mustacchi typedef void (*ctf_diff_func_f)(ctf_file_t *, ulong_t, boolean_t, ctf_file_t *, 67bc1f688bSRobert Mustacchi ulong_t, void *); 68bc1f688bSRobert Mustacchi typedef void (*ctf_diff_obj_f)(ctf_file_t *, ulong_t, ctf_id_t, boolean_t, 69bc1f688bSRobert Mustacchi ctf_file_t *, ulong_t, ctf_id_t, void *); 70bc1f688bSRobert Mustacchi 71bc1f688bSRobert Mustacchi extern int ctf_diff_init(ctf_file_t *, ctf_file_t *, ctf_diff_t **); 72bc1f688bSRobert Mustacchi extern uint_t ctf_diff_getflags(ctf_diff_t *); 73bc1f688bSRobert Mustacchi extern int ctf_diff_setflags(ctf_diff_t *, uint_t); 74bc1f688bSRobert Mustacchi extern int ctf_diff_types(ctf_diff_t *, ctf_diff_type_f, void *); 75bc1f688bSRobert Mustacchi extern int ctf_diff_functions(ctf_diff_t *, ctf_diff_func_f, void *); 76bc1f688bSRobert Mustacchi extern int ctf_diff_objects(ctf_diff_t *, ctf_diff_obj_f, void *); 77bc1f688bSRobert Mustacchi extern void ctf_diff_fini(ctf_diff_t *); 78bc1f688bSRobert Mustacchi 79dd442252SAndy Fiddaman #define CTF_CONVERT_DEFAULT_BATCHSIZE 256 80dd442252SAndy Fiddaman #define CTF_CONVERT_DEFAULT_NTHREADS 4 813eca6103SJohn Levon 82dd442252SAndy Fiddaman typedef enum ctf_convert_flag { 83dd442252SAndy Fiddaman /* 84dd442252SAndy Fiddaman * Normally, we return a failure if we find a C-derived compilation 85dd442252SAndy Fiddaman * unit that lacks DWARF or CTF (as required). This flag over-rides 86dd442252SAndy Fiddaman * this check. 87dd442252SAndy Fiddaman */ 88dd442252SAndy Fiddaman CTF_ALLOW_MISSING_DEBUG = 0x01, 89dd442252SAndy Fiddaman /* 90dd442252SAndy Fiddaman * Normally, we return a failure if we can't fully convert a structure 91dd442252SAndy Fiddaman * to CTF format, such as an enum with too many values. This flag 92dd442252SAndy Fiddaman * allows us to continue and convert what we can. 93dd442252SAndy Fiddaman */ 9473197b54SAndy Fiddaman CTF_ALLOW_TRUNCATION = 0x02, 9573197b54SAndy Fiddaman /* 9673197b54SAndy Fiddaman * Conversion is not usually attempted for objects that don't appear 9773197b54SAndy Fiddaman * to be built from C sources. This flag overrides this and attempts 9873197b54SAndy Fiddaman * conversion anyway. 9973197b54SAndy Fiddaman */ 10073197b54SAndy Fiddaman CTF_FORCE_CONVERSION = 0x04 101dd442252SAndy Fiddaman } ctf_convert_flag_t; 102dd442252SAndy Fiddaman 103dd442252SAndy Fiddaman #define CTF_CONVERT_ALL_FLAGS (CTF_ALLOW_MISSING_DEBUG | \ 10473197b54SAndy Fiddaman CTF_ALLOW_TRUNCATION | \ 10573197b54SAndy Fiddaman CTF_FORCE_CONVERSION) 106dd442252SAndy Fiddaman 107dd442252SAndy Fiddaman /* opaque handle for ctfconvert functions */ 108dd442252SAndy Fiddaman struct ctf_convert_handle; 109dd442252SAndy Fiddaman typedef struct ctf_convert_handle ctf_convert_t; 110dd442252SAndy Fiddaman 111dd442252SAndy Fiddaman extern ctf_convert_t *ctf_convert_init(int *); 112dd442252SAndy Fiddaman extern void ctf_convert_fini(ctf_convert_t *); 113dd442252SAndy Fiddaman 114dd442252SAndy Fiddaman typedef void (*ctf_convert_warn_f)(void *, const char *, ...); 115dd442252SAndy Fiddaman /* Any warning callback must be MT-Safe if multiple threads are used */ 116dd442252SAndy Fiddaman extern int ctf_convert_set_warncb(ctf_convert_t *, ctf_convert_warn_f, void *); 117dd442252SAndy Fiddaman extern int ctf_convert_set_batchsize(ctf_convert_t *, uint_t); 118dd442252SAndy Fiddaman extern int ctf_convert_set_flags(ctf_convert_t *, ctf_convert_flag_t); 119dd442252SAndy Fiddaman extern int ctf_convert_set_label(ctf_convert_t *, const char *); 120dd442252SAndy Fiddaman extern int ctf_convert_set_nthreads(ctf_convert_t *, uint_t); 121*88a08813SAndy Fiddaman extern int ctf_convert_add_ignore(ctf_convert_t *, const char *); 122dd442252SAndy Fiddaman 123dd442252SAndy Fiddaman extern ctf_file_t *ctf_fdconvert(ctf_convert_t *, int, int *, char *, size_t); 124dd442252SAndy Fiddaman 125bc1f688bSRobert Mustacchi 1263eca6103SJohn Levon typedef enum ctf_hsc_ret { 1273eca6103SJohn Levon CHR_ERROR = -1, 1283eca6103SJohn Levon CHR_NO_C_SOURCE = 0, 1293eca6103SJohn Levon CHR_HAS_C_SOURCE = 1 1303eca6103SJohn Levon } ctf_hsc_ret_t; 1313eca6103SJohn Levon 1323eca6103SJohn Levon extern ctf_hsc_ret_t ctf_has_c_source(Elf *, char *, size_t); 1333eca6103SJohn Levon 134bc1f688bSRobert Mustacchi typedef struct ctf_merge_handle ctf_merge_t; 135bc1f688bSRobert Mustacchi extern ctf_merge_t *ctf_merge_init(int, int *); 136bc1f688bSRobert Mustacchi extern int ctf_merge_add(ctf_merge_t *, ctf_file_t *); 137bc1f688bSRobert Mustacchi extern int ctf_merge_set_nthreads(ctf_merge_t *, const uint_t); 138bc1f688bSRobert Mustacchi extern int ctf_merge_label(ctf_merge_t *, const char *); 139bc1f688bSRobert Mustacchi extern int ctf_merge_uniquify(ctf_merge_t *, ctf_file_t *, const char *); 140bc1f688bSRobert Mustacchi extern int ctf_merge_merge(ctf_merge_t *, ctf_file_t **); 141bc1f688bSRobert Mustacchi extern int ctf_merge_dedup(ctf_merge_t *, ctf_file_t **); 142bc1f688bSRobert Mustacchi extern void ctf_merge_fini(ctf_merge_t *); 143bc1f688bSRobert Mustacchi 144bc1f688bSRobert Mustacchi #define CTF_ELFWRITE_F_COMPRESS 0x1 145bc1f688bSRobert Mustacchi extern int ctf_elffdwrite(ctf_file_t *, int, int, int); 146bc1f688bSRobert Mustacchi extern int ctf_elfwrite(ctf_file_t *, const char *, const char *, int); 147bc1f688bSRobert Mustacchi 1487c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1497c478bd9Sstevel@tonic-gate } 1507c478bd9Sstevel@tonic-gate #endif 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate #endif /* _LIBCTF_H */ 153