1210688Srpaulo/* 2210688Srpaulo * Copyright (c) 2010 The FreeBSD Foundation 3210688Srpaulo * All rights reserved. 4210688Srpaulo * 5210688Srpaulo * This software was developed by Rui Paulo under sponsorship from the 6210688Srpaulo * FreeBSD Foundation. 7210688Srpaulo * 8210688Srpaulo * Redistribution and use in source and binary forms, with or without 9210688Srpaulo * modification, are permitted provided that the following conditions 10210688Srpaulo * are met: 11210688Srpaulo * 1. Redistributions of source code must retain the above copyright 12210688Srpaulo * notice, this list of conditions and the following disclaimer. 13210688Srpaulo * 2. Redistributions in binary form must reproduce the above copyright 14210688Srpaulo * notice, this list of conditions and the following disclaimer in the 15210688Srpaulo * documentation and/or other materials provided with the distribution. 16210688Srpaulo * 17210688Srpaulo * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18210688Srpaulo * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19210688Srpaulo * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20210688Srpaulo * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21210688Srpaulo * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22210688Srpaulo * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23210688Srpaulo * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24210688Srpaulo * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25210688Srpaulo * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26210688Srpaulo * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27210688Srpaulo * SUCH DAMAGE. 28210688Srpaulo * 29210688Srpaulo * $FreeBSD: releng/10.3/lib/libproc/test/t3-name2sym/t3-name2sym.c 240154 2012-09-06 01:24:18Z rpaulo $ 30210688Srpaulo */ 31210688Srpaulo#include <sys/types.h> 32210688Srpaulo#include <assert.h> 33210688Srpaulo#include <stdio.h> 34210688Srpaulo#include <libproc.h> 35210688Srpaulo#include <gelf.h> 36240154Srpaulo#include <string.h> 37210688Srpaulo 38210688Srpauloint 39210688Srpaulomain(int argc, char *argv[]) 40210688Srpaulo{ 41210688Srpaulo prmap_t *map = NULL; 42210688Srpaulo struct proc_handle *phdl; 43210688Srpaulo GElf_Sym sym; 44210688Srpaulo 45210688Srpaulo proc_create("./t3-name2sym", argv, NULL, NULL, &phdl); 46210688Srpaulo memset(&sym, 0, sizeof(sym)); 47210688Srpaulo assert(proc_name2sym(phdl, "ld-elf.so.1", "r_debug_state", &sym) == 0); 48210688Srpaulo printf("0x%lx\n", sym.st_value); 49210688Srpaulo assert(proc_name2sym(phdl, "t3-name2sym", "main", &sym) == 0); 50210688Srpaulo printf("0x%lx\n", sym.st_value); 51210688Srpaulo} 52