xref: /titanic_41/usr/src/tools/ctf/dwarf/common/dwarf_funcs.c (revision 3e2514dc0f3dfbffad7bfb4744cf26707a910f26)
1 /*
2 
3   Copyright (C) 2000-2005 Silicon Graphics, Inc.  All Rights Reserved.
4   Portions Copyright (C) 2009-2010 David Anderson. All Rights Reserved.
5 
6   This program is free software; you can redistribute it and/or modify it
7   under the terms of version 2.1 of the GNU Lesser General Public License
8   as published by the Free Software Foundation.
9 
10   This program is distributed in the hope that it would be useful, but
11   WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 
14   Further, this software is distributed without any warranty that it is
15   free of the rightful claim of any third person regarding infringement
16   or the like.  Any license provided herein, whether implied or
17   otherwise, applies only to this software file.  Patent licenses, if
18   any, provided herein do not apply to combinations of this program with
19   other software, or any other product whatsoever.
20 
21   You should have received a copy of the GNU Lesser General Public
22   License along with this program; if not, write the Free Software
23   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
24   USA.
25 
26   Contact information:  Silicon Graphics, Inc., 1500 Crittenden Lane,
27   Mountain View, CA 94043, or:
28 
29   http://www.sgi.com
30 
31   For further information regarding this notice, see:
32 
33   http://oss.sgi.com/projects/GenInfo/NoticeExplan
34 
35 */
36 
37 
38 
39 #include "config.h"
40 #include "dwarf_incl.h"
41 #include <stdio.h>
42 #include "dwarf_funcs.h"
43 #include "dwarf_global.h"
44 
45 int
46 dwarf_get_funcs(Dwarf_Debug dbg,
47     Dwarf_Func ** funcs,
48     Dwarf_Signed * ret_func_count, Dwarf_Error * error)
49 {
50     int res = _dwarf_load_section(dbg, &dbg->de_debug_funcnames,error);
51     if (res != DW_DLV_OK) {
52         return res;
53     }
54 
55     return _dwarf_internal_get_pubnames_like_data(dbg,
56         dbg->de_debug_funcnames.dss_data,
57         dbg->de_debug_funcnames.dss_size,
58         (Dwarf_Global **) funcs, /* Type punning for sections with identical format. */
59         ret_func_count,
60         error,
61         DW_DLA_FUNC_CONTEXT,
62         DW_DLA_FUNC,
63         DW_DLE_DEBUG_FUNCNAMES_LENGTH_BAD,
64         DW_DLE_DEBUG_FUNCNAMES_VERSION_ERROR);
65 }
66 
67 /* Deallocating fully requires deallocating the list
68    and all entries.  But some internal data is
69    not exposed, so we need a function with internal knowledge.
70 */
71 
72 void
73 dwarf_funcs_dealloc(Dwarf_Debug dbg, Dwarf_Func * dwgl,
74     Dwarf_Signed count)
75 {
76     _dwarf_internal_globals_dealloc(dbg, (Dwarf_Global *) dwgl,
77         count,
78         DW_DLA_FUNC_CONTEXT,
79         DW_DLA_FUNC, DW_DLA_LIST);
80     return;
81 }
82 
83 
84 
85 int
86 dwarf_funcname(Dwarf_Func func_in, char **ret_name, Dwarf_Error * error)
87 {
88     Dwarf_Global func = (Dwarf_Global) func_in;
89 
90     if (func == NULL) {
91         _dwarf_error(NULL, error, DW_DLE_FUNC_NULL);
92         return (DW_DLV_ERROR);
93     }
94 
95     *ret_name = (char *) (func->gl_name);
96     return DW_DLV_OK;
97 }
98 
99 int
100 dwarf_func_die_offset(Dwarf_Func func_in,
101     Dwarf_Off * return_offset, Dwarf_Error * error)
102 {
103     Dwarf_Global func = (Dwarf_Global) func_in;
104 
105     return dwarf_global_die_offset(func, return_offset, error);
106 }
107 
108 
109 int
110 dwarf_func_cu_offset(Dwarf_Func func_in,
111     Dwarf_Off * return_offset, Dwarf_Error * error)
112 {
113     Dwarf_Global func = (Dwarf_Global) func_in;
114 
115     return dwarf_global_cu_offset(func, return_offset, error);
116 }
117 
118 
119 int
120 dwarf_func_name_offsets(Dwarf_Func func_in,
121     char **ret_func_name,
122     Dwarf_Off * die_offset,
123     Dwarf_Off * cu_die_offset, Dwarf_Error * error)
124 {
125     Dwarf_Global func = (Dwarf_Global) func_in;
126 
127     return dwarf_global_name_offsets(func,
128         ret_func_name,
129         die_offset, cu_die_offset, error);
130 }
131