xref: /titanic_51/usr/src/cmd/sgs/libconv/common/dwarf_ehe.c (revision 49f0e51890161901ae4f49c7a47602d97b52b934)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 #include	<strings.h>
29 #include	<dwarf.h>
30 #include	<dwarf_ehe_msg.h>
31 #include	"_conv.h"
32 
33 #define	FLAGSZ	MSG_GBL_OSQBRKT_SIZE + \
34 		MSG_DWEHE_SLEB128_SIZE + \
35 		MSG_DWEHE_INDIRECT_SIZE + \
36 		CONV_INV_STRSIZE + MSG_GBL_CSQBRKT_SIZE
37 
38 const char *
39 conv_dwarf_ehe(uint_t flags)
40 {
41 	static char	string[FLAGSZ];
42 	size_t		ret = 0;
43 
44 	(void) strncpy(string, MSG_ORIG(MSG_GBL_OSQBRKT), FLAGSZ);
45 
46 	if (flags == DW_EH_PE_omit)
47 		ret = strlcat(string, MSG_ORIG(MSG_DWEHE_OMIT), FLAGSZ);
48 	else if (flags == DW_EH_PE_absptr)
49 		ret = strlcat(string, MSG_ORIG(MSG_DWEHE_ABSPTR), FLAGSZ);
50 
51 	if (ret >= FLAGSZ)
52 		return (conv_invalid_val(string, FLAGSZ, flags, 0));
53 
54 	if ((flags == DW_EH_PE_omit) || (flags == DW_EH_PE_absptr)) {
55 		(void) strlcat(string, MSG_ORIG(MSG_GBL_CSQBRKT), FLAGSZ);
56 		return (string);
57 	}
58 
59 	switch (flags & 0x0f) {
60 	case DW_EH_PE_uleb128:
61 		ret = strlcat(string, MSG_ORIG(MSG_DWEHE_ULEB128), FLAGSZ);
62 		break;
63 	case DW_EH_PE_udata2:
64 		ret = strlcat(string, MSG_ORIG(MSG_DWEHE_UDATA2), FLAGSZ);
65 		break;
66 	case DW_EH_PE_udata4:
67 		ret = strlcat(string, MSG_ORIG(MSG_DWEHE_UDATA4), FLAGSZ);
68 		break;
69 	case DW_EH_PE_udata8:
70 		ret = strlcat(string, MSG_ORIG(MSG_DWEHE_UDATA8), FLAGSZ);
71 		break;
72 	case DW_EH_PE_sleb128:
73 		ret = strlcat(string, MSG_ORIG(MSG_DWEHE_SLEB128), FLAGSZ);
74 		break;
75 	case DW_EH_PE_sdata2:
76 		ret = strlcat(string, MSG_ORIG(MSG_DWEHE_SDATA2), FLAGSZ);
77 		break;
78 	case DW_EH_PE_sdata4:
79 		ret = strlcat(string, MSG_ORIG(MSG_DWEHE_SDATA4), FLAGSZ);
80 		break;
81 	case DW_EH_PE_sdata8:
82 		ret = strlcat(string, MSG_ORIG(MSG_DWEHE_SDATA8), FLAGSZ);
83 		break;
84 	}
85 	if (ret >= FLAGSZ)
86 		return (conv_invalid_val(string, FLAGSZ, flags, 0));
87 
88 	switch (flags & 0xf0) {
89 	case DW_EH_PE_pcrel:
90 		ret = strlcat(string, MSG_ORIG(MSG_DWEHE_PCREL), FLAGSZ);
91 		break;
92 	case DW_EH_PE_textrel:
93 		ret = strlcat(string, MSG_ORIG(MSG_DWEHE_TEXTREL), FLAGSZ);
94 		break;
95 	case DW_EH_PE_datarel:
96 		ret = strlcat(string, MSG_ORIG(MSG_DWEHE_DATAREL), FLAGSZ);
97 		break;
98 	case DW_EH_PE_funcrel:
99 		ret = strlcat(string, MSG_ORIG(MSG_DWEHE_FUNCREL), FLAGSZ);
100 		break;
101 	case DW_EH_PE_aligned:
102 		ret = strlcat(string, MSG_ORIG(MSG_DWEHE_ALIGNED), FLAGSZ);
103 		break;
104 	case DW_EH_PE_indirect:
105 		ret = strlcat(string, MSG_ORIG(MSG_DWEHE_INDIRECT), FLAGSZ);
106 		break;
107 	}
108 	if (ret >= FLAGSZ)
109 		return (conv_invalid_val(string, FLAGSZ, flags, 0));
110 
111 	(void) strlcat(string, MSG_ORIG(MSG_GBL_CSQBRKT), FLAGSZ);
112 	return (string);
113 }
114