xref: /onnv-gate/usr/src/cmd/sgs/libconv/common/dwarf_ehe.c (revision 5152:fa5ab16f3606)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51618Srie  * Common Development and Distribution License (the "License").
61618Srie  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211618Srie 
220Sstevel@tonic-gate /*
234734Sab196087  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include	<strings.h>
290Sstevel@tonic-gate #include	<dwarf.h>
304734Sab196087 #include	"_conv.h"
310Sstevel@tonic-gate #include	<dwarf_ehe_msg.h>
320Sstevel@tonic-gate 
331618Srie #define	FLAGSZ	MSG_GBL_OSQBRKT_SIZE + \
341618Srie 		MSG_DWEHE_SLEB128_SIZE + \
351618Srie 		MSG_DWEHE_INDIRECT_SIZE + \
364734Sab196087 		CONV_INV_BUFSIZE + MSG_GBL_CSQBRKT_SIZE
374734Sab196087 
384734Sab196087 /*
394734Sab196087  * Ensure that Conv_dwarf_ehe_buf_t is large enough:
404734Sab196087  *
414734Sab196087  * FLAGSZ is the real minimum size of the buffer required by conv_dwarf_ehe().
424734Sab196087  * However, Conv_dwarf_ehe_buf_t uses CONV_EHDR_FLAG_BUFSIZE to set the
434734Sab196087  * buffer size. We do things this way because the definition of FLAGSZ uses
444734Sab196087  * information that is not available in the environment of other programs
454734Sab196087  * that include the conv.h header file.
464734Sab196087  */
47*5152Sab196087 #if (CONV_DWARF_EHE_BUFSIZE != FLAGSZ) && !defined(__lint)
48*5152Sab196087 #define	REPORT_BUFSIZE FLAGSZ
49*5152Sab196087 #include "report_bufsize.h"
50*5152Sab196087 #error "CONV_DWARF_EHE_BUFSIZE does not match FLAGSZ"
514734Sab196087 #endif
521618Srie 
530Sstevel@tonic-gate const char *
conv_dwarf_ehe(uint_t flags,Conv_dwarf_ehe_buf_t * dwarf_ehe_buf)544734Sab196087 conv_dwarf_ehe(uint_t flags, Conv_dwarf_ehe_buf_t *dwarf_ehe_buf)
550Sstevel@tonic-gate {
564734Sab196087 	char	*buf = dwarf_ehe_buf->buf;
574734Sab196087 	size_t	ret = 0;
580Sstevel@tonic-gate 
594734Sab196087 	(void) strncpy(buf, MSG_ORIG(MSG_GBL_OSQBRKT), FLAGSZ);
601618Srie 
611618Srie 	if (flags == DW_EH_PE_omit)
624734Sab196087 		ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_OMIT), FLAGSZ);
631618Srie 	else if (flags == DW_EH_PE_absptr)
644734Sab196087 		ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_ABSPTR), FLAGSZ);
651618Srie 
661618Srie 	if (ret >= FLAGSZ)
674734Sab196087 		return (conv_invalid_val(&dwarf_ehe_buf->inv_buf, flags, 0));
681618Srie 
691618Srie 	if ((flags == DW_EH_PE_omit) || (flags == DW_EH_PE_absptr)) {
704734Sab196087 		(void) strlcat(buf, MSG_ORIG(MSG_GBL_CSQBRKT), FLAGSZ);
714734Sab196087 		return (buf);
720Sstevel@tonic-gate 	}
730Sstevel@tonic-gate 
740Sstevel@tonic-gate 	switch (flags & 0x0f) {
750Sstevel@tonic-gate 	case DW_EH_PE_uleb128:
764734Sab196087 		ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_ULEB128), FLAGSZ);
770Sstevel@tonic-gate 		break;
780Sstevel@tonic-gate 	case DW_EH_PE_udata2:
794734Sab196087 		ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_UDATA2), FLAGSZ);
800Sstevel@tonic-gate 		break;
810Sstevel@tonic-gate 	case DW_EH_PE_udata4:
824734Sab196087 		ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_UDATA4), FLAGSZ);
830Sstevel@tonic-gate 		break;
840Sstevel@tonic-gate 	case DW_EH_PE_udata8:
854734Sab196087 		ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_UDATA8), FLAGSZ);
860Sstevel@tonic-gate 		break;
870Sstevel@tonic-gate 	case DW_EH_PE_sleb128:
884734Sab196087 		ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_SLEB128), FLAGSZ);
890Sstevel@tonic-gate 		break;
900Sstevel@tonic-gate 	case DW_EH_PE_sdata2:
914734Sab196087 		ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_SDATA2), FLAGSZ);
920Sstevel@tonic-gate 		break;
930Sstevel@tonic-gate 	case DW_EH_PE_sdata4:
944734Sab196087 		ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_SDATA4), FLAGSZ);
950Sstevel@tonic-gate 		break;
960Sstevel@tonic-gate 	case DW_EH_PE_sdata8:
974734Sab196087 		ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_SDATA8), FLAGSZ);
980Sstevel@tonic-gate 		break;
990Sstevel@tonic-gate 	}
1001618Srie 	if (ret >= FLAGSZ)
1014734Sab196087 		return (conv_invalid_val(&dwarf_ehe_buf->inv_buf, flags, 0));
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate 	switch (flags & 0xf0) {
1040Sstevel@tonic-gate 	case DW_EH_PE_pcrel:
1054734Sab196087 		ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_PCREL), FLAGSZ);
1060Sstevel@tonic-gate 		break;
1070Sstevel@tonic-gate 	case DW_EH_PE_textrel:
1084734Sab196087 		ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_TEXTREL), FLAGSZ);
1090Sstevel@tonic-gate 		break;
1100Sstevel@tonic-gate 	case DW_EH_PE_datarel:
1114734Sab196087 		ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_DATAREL), FLAGSZ);
1120Sstevel@tonic-gate 		break;
1130Sstevel@tonic-gate 	case DW_EH_PE_funcrel:
1144734Sab196087 		ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_FUNCREL), FLAGSZ);
1150Sstevel@tonic-gate 		break;
1160Sstevel@tonic-gate 	case DW_EH_PE_aligned:
1174734Sab196087 		ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_ALIGNED), FLAGSZ);
1180Sstevel@tonic-gate 		break;
1190Sstevel@tonic-gate 	case DW_EH_PE_indirect:
1204734Sab196087 		ret = strlcat(buf, MSG_ORIG(MSG_DWEHE_INDIRECT), FLAGSZ);
1210Sstevel@tonic-gate 		break;
1220Sstevel@tonic-gate 	}
1231618Srie 	if (ret >= FLAGSZ)
1244734Sab196087 		return (conv_invalid_val(&dwarf_ehe_buf->inv_buf, flags, 0));
1250Sstevel@tonic-gate 
1264734Sab196087 	(void) strlcat(buf, MSG_ORIG(MSG_GBL_CSQBRKT), FLAGSZ);
1274734Sab196087 	return (buf);
1280Sstevel@tonic-gate }
129