15426539cSMatt Macy /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 35426539cSMatt Macy * 45426539cSMatt Macy * Copyright (c) 2019, Matthew Macy <mmacy@freebsd.org> 55426539cSMatt Macy * 65426539cSMatt Macy * Redistribution and use in source and binary forms, with or without 75426539cSMatt Macy * modification, are permitted provided that the following conditions 85426539cSMatt Macy * are met: 95426539cSMatt Macy * 1. Redistributions of source code must retain the above copyright 105426539cSMatt Macy * notice, this list of conditions and the following disclaimer. 115426539cSMatt Macy * 2. Redistributions in binary form must reproduce the above copyright 125426539cSMatt Macy * notice, this list of conditions and the following disclaimer in the 135426539cSMatt Macy * documentation and/or other materials provided with the distribution. 145426539cSMatt Macy * 155426539cSMatt Macy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 165426539cSMatt Macy * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 175426539cSMatt Macy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 185426539cSMatt Macy * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 195426539cSMatt Macy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 205426539cSMatt Macy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 215426539cSMatt Macy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 225426539cSMatt Macy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 235426539cSMatt Macy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 245426539cSMatt Macy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 255426539cSMatt Macy * SUCH DAMAGE. 265426539cSMatt Macy * 275426539cSMatt Macy */ 285426539cSMatt Macy 295426539cSMatt Macy #ifndef _SYS_GCOV_H_ 305426539cSMatt Macy #define _SYS_GCOV_H_ 315426539cSMatt Macy 325426539cSMatt Macy MALLOC_DECLARE(M_GCOV); 335426539cSMatt Macy 345426539cSMatt Macy /* 355426539cSMatt Macy * Profiling data types used for gcc 3.4 and above - these are defined by 365426539cSMatt Macy * gcc and need to be kept as close to the original definition as possible to 375426539cSMatt Macy * remain compatible. 385426539cSMatt Macy */ 395426539cSMatt Macy #define GCOV_DATA_MAGIC ((unsigned int) 0x67636461) 405426539cSMatt Macy #define GCOV_TAG_FUNCTION ((unsigned int) 0x01000000) 415426539cSMatt Macy #define GCOV_TAG_COUNTER_BASE ((unsigned int) 0x01a10000) 425426539cSMatt Macy #define GCOV_TAG_FOR_COUNTER(count) \ 435426539cSMatt Macy (GCOV_TAG_COUNTER_BASE + ((unsigned int) (count) << 17)) 445426539cSMatt Macy 455426539cSMatt Macy typedef uint64_t gcov_type; 465426539cSMatt Macy 475426539cSMatt Macy /* Opaque gcov_info. The gcov structures can change as for example in gcc 4.7 so 485426539cSMatt Macy * we cannot use full definition here and they need to be placed in gcc specific 495426539cSMatt Macy * implementation of gcov. This also means no direct access to the members in 505426539cSMatt Macy * generic code and usage of the interface below.*/ 515426539cSMatt Macy struct gcov_info; 525426539cSMatt Macy 535426539cSMatt Macy /* Interface to access gcov_info data */ 545426539cSMatt Macy const char *gcov_info_filename(struct gcov_info *info); 555426539cSMatt Macy unsigned int gcov_info_version(struct gcov_info *info); 565426539cSMatt Macy struct gcov_info *gcov_info_next(struct gcov_info *info); 575426539cSMatt Macy void gcov_info_link(struct gcov_info *info); 585426539cSMatt Macy void gcov_info_unlink(struct gcov_info *prev, struct gcov_info *info); 595426539cSMatt Macy 605426539cSMatt Macy /* Base interface. */ 615426539cSMatt Macy enum gcov_action { 625426539cSMatt Macy GCOV_ADD, 635426539cSMatt Macy GCOV_REMOVE, 645426539cSMatt Macy }; 655426539cSMatt Macy 665426539cSMatt Macy /* Iterator control. */ 675426539cSMatt Macy struct gcov_iterator; 685426539cSMatt Macy 695426539cSMatt Macy struct gcov_iterator *gcov_iter_new(struct gcov_info *info); 705426539cSMatt Macy void gcov_iter_free(struct gcov_iterator *iter); 715426539cSMatt Macy void gcov_iter_start(struct gcov_iterator *iter); 725426539cSMatt Macy int gcov_iter_next(struct gcov_iterator *iter); 735426539cSMatt Macy int gcov_iter_write(struct gcov_iterator *iter, struct sbuf *sbuf); 745426539cSMatt Macy struct gcov_info *gcov_iter_get_info(struct gcov_iterator *iter); 755426539cSMatt Macy 765426539cSMatt Macy /* gcov_info control. */ 775426539cSMatt Macy void gcov_info_reset(struct gcov_info *info); 785426539cSMatt Macy int gcov_info_is_compatible(struct gcov_info *info1, struct gcov_info *info2); 795426539cSMatt Macy void gcov_info_add(struct gcov_info *dest, struct gcov_info *source); 805426539cSMatt Macy struct gcov_info *gcov_info_dup(struct gcov_info *info); 815426539cSMatt Macy void gcov_info_free(struct gcov_info *info); 825426539cSMatt Macy void gcov_stats_reset(void); 835426539cSMatt Macy void gcov_enable_events(void); 845426539cSMatt Macy void gcov_module_unload(void *, module_t); 855426539cSMatt Macy void gcov_fs_init(void); 865426539cSMatt Macy 875426539cSMatt Macy int within_module(vm_offset_t addr, module_t mod); 885426539cSMatt Macy 895426539cSMatt Macy struct gcov_link { 905426539cSMatt Macy enum { 915426539cSMatt Macy OBJ_TREE, 925426539cSMatt Macy SRC_TREE, 935426539cSMatt Macy } dir; 945426539cSMatt Macy const char *ext; 955426539cSMatt Macy }; 965426539cSMatt Macy extern const struct gcov_link gcov_link[]; 975426539cSMatt Macy #endif 98