예제 #1
0
retc_t
addr_to_sym(struct ps_prochandle *ph, ulong_t addr,
	GElf_Sym *symp, char **str)
{
	map_info_t	*mip;

	if ((mip = addr_to_map(ph, addr)) == NULL)
		return (RET_FAILED);

	return (addr_map_sym(mip, addr, symp, str));
}
예제 #2
0
파일: dis.c 프로젝트: andreiw/polaris
/*
 * This routine converts 'address' into it's closest symbol
 * representation.
 *
 * The following flags are used to effect the output:
 *
 *	FLG_PAP_SONAME
 *		embed the SONAME in the symbol name
 *	FLG_PAP_NOHEXNAME
 *		if no symbol found return a null string
 *		If this flag is not set return a string displaying
 *		the 'hex' value of address.
 *	FLG_PAP_PLTDECOM
 *		decompose the PLT symbol if possible
 */
char *
print_address_ps(struct ps_prochandle * ph, ulong_t address, unsigned flags)
{
	static char	buf[256];
	GElf_Sym	sym;
	char *		str;
	ulong_t		val;

	if (addr_to_sym(ph, address, &sym, &str) == RET_OK) {
		map_info_t *	mip;
		ulong_t		pltbase;

		if (flags & FLG_PAP_SONAME) {
			/*
			 * Embed SOName in symbol name
			 */
			if (mip = addr_to_map(ph, address)) {
				strcpy(buf, mip->mi_name);
				strcat(buf, ":");
			} else
				sprintf(buf, "0x%08lx:", address);
		} else
			buf[0] = '\0';

		if ((flags & FLG_PAP_PLTDECOM) &&
		    (pltbase = is_plt(ph, address)) != 0) {
			rd_plt_info_t	rp;
			pstatus_t	pstatus;

			if (pread(ph->pp_statusfd, &pstatus,
			    sizeof (pstatus), 0) == -1)
				perr("pap: reading pstatus");

			if (rd_plt_resolution(ph->pp_rap, address,
			    pstatus.pr_lwp.pr_lwpid, pltbase,
			    &rp) == RD_OK) {
				if (rp.pi_flags & RD_FLG_PI_PLTBOUND) {
					GElf_Sym	_sym;
					char *		_str;
					if (addr_to_sym(ph, rp.pi_baddr,
					    &_sym, &_str) == RET_OK) {
						sprintf(buf,
						    "%s0x%lx:plt(%s)",
						    buf, address, _str);
						return (buf);
					}
				}
			}
			val = sym.st_value;
			sprintf(buf, "%s0x%lx:plt(unbound)+0x%lx", buf,
			    address, address - val);
			return (buf);
		} else {

			val = sym.st_value;

			if (val < address)
				sprintf(buf, "%s%s+0x%lx", buf, str,
					address - val);
			else
				sprintf(buf, "%s%s", buf, str);
			return (buf);
		}
	} else {
		if (flags & FLG_PAP_NOHEXNAME)
			buf[0] = '\0';
		else
			sprintf(buf, "0x%lx", address);
		return (buf);
	}
}