2 * Copyright (c) 2003-2008 Joseph Koshy
3 * Copyright (c) 2017 Ruslan Bukin <br@bsdpad.com>
6 * This software was developed by BAE Systems, the University of Cambridge
7 * Computer Laboratory, and Memorial University under DARPA/AFRL contract
8 * FA8650-15-C-7558 ("CADETS"), as part of the DARPA Transparent Computing
9 * (TC) research program.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <sys/types.h>
37 #include <sys/cpuset.h>
38 #include <sys/event.h>
39 #include <sys/param.h>
40 #include <sys/socket.h>
42 #include <sys/module.h>
54 #include "libpmcstat.h"
56 struct pmcstat_symbol *
57 pmcstat_symbol_search_by_name(struct pmcstat_process *pp,
58 const char *pi_name, const char *name, uintptr_t *addr_start,
61 struct pmcstat_symbol *sym;
62 struct pmcstat_image *image;
63 struct pmcstat_pcmap *pcm;
74 TAILQ_FOREACH(pcm, &pp->pp_map, ppm_next) {
75 image = pcm->ppm_image;
76 if (image->pi_name == NULL)
78 name1 = pmcstat_string_unintern(image->pi_name);
79 if (strcmp(name1, pi_name) == 0) {
85 if (!found || image->pi_symbols == NULL)
90 for (i = 0; i < image->pi_symcount; i++) {
91 sym = &image->pi_symbols[i];
92 name2 = pmcstat_string_unintern(sym->ps_name);
93 if (strcmp(name2, name) == 0) {
102 *addr_start = (image->pi_vaddr - image->pi_start +
103 pcm->ppm_lowpc + sym->ps_start);
104 *addr_end = (image->pi_vaddr - image->pi_start +
105 pcm->ppm_lowpc + sym->ps_end);
115 pmcstat_symbol_compare(const void *a, const void *b)
117 const struct pmcstat_symbol *sym1, *sym2;
119 sym1 = (const struct pmcstat_symbol *) a;
120 sym2 = (const struct pmcstat_symbol *) b;
122 if (sym1->ps_end <= sym2->ps_start)
124 if (sym1->ps_start >= sym2->ps_end)
130 * Map an address to a symbol in an image.
133 struct pmcstat_symbol *
134 pmcstat_symbol_search(struct pmcstat_image *image, uintfptr_t addr)
136 struct pmcstat_symbol sym;
138 if (image->pi_symbols == NULL)
143 sym.ps_end = addr + 1;
145 return (bsearch((void *) &sym, image->pi_symbols,
146 image->pi_symcount, sizeof(struct pmcstat_symbol),
147 pmcstat_symbol_compare));