107dc1947SRichard Lowe /*
207dc1947SRichard Lowe
307dc1947SRichard Lowe Copyright (C) 2000,2002,2004,2005 Silicon Graphics, Inc. All Rights Reserved.
407dc1947SRichard Lowe Portions Copyright (C) 2009-2010 David Anderson. All Rights Reserved.
507dc1947SRichard Lowe
607dc1947SRichard Lowe This program is free software; you can redistribute it and/or modify it
7*4d9fdb46SRobert Mustacchi under the terms of version 2.1 of the GNU Lesser General Public License
807dc1947SRichard Lowe as published by the Free Software Foundation.
907dc1947SRichard Lowe
1007dc1947SRichard Lowe This program is distributed in the hope that it would be useful, but
1107dc1947SRichard Lowe WITHOUT ANY WARRANTY; without even the implied warranty of
12*4d9fdb46SRobert Mustacchi MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1307dc1947SRichard Lowe
1407dc1947SRichard Lowe Further, this software is distributed without any warranty that it is
15*4d9fdb46SRobert Mustacchi free of the rightful claim of any third person regarding infringement
16*4d9fdb46SRobert Mustacchi or the like. Any license provided herein, whether implied or
1707dc1947SRichard Lowe otherwise, applies only to this software file. Patent licenses, if
18*4d9fdb46SRobert Mustacchi any, provided herein do not apply to combinations of this program with
19*4d9fdb46SRobert Mustacchi other software, or any other product whatsoever.
2007dc1947SRichard Lowe
21*4d9fdb46SRobert Mustacchi You should have received a copy of the GNU Lesser General Public
22*4d9fdb46SRobert Mustacchi License along with this program; if not, write the Free Software
2307dc1947SRichard Lowe Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
2407dc1947SRichard Lowe USA.
2507dc1947SRichard Lowe
2607dc1947SRichard Lowe */
2707dc1947SRichard Lowe
2807dc1947SRichard Lowe /* Reads DWARF3 .debug_pubtypes section. */
2907dc1947SRichard Lowe
3007dc1947SRichard Lowe #include "config.h"
3107dc1947SRichard Lowe #include <stdio.h>
32*4d9fdb46SRobert Mustacchi #include "dwarf_incl.h"
33*4d9fdb46SRobert Mustacchi #include "dwarf_error.h"
3407dc1947SRichard Lowe #include "dwarf_types.h"
3507dc1947SRichard Lowe #include "dwarf_global.h"
3607dc1947SRichard Lowe
3707dc1947SRichard Lowe int
dwarf_get_pubtypes(Dwarf_Debug dbg,Dwarf_Type ** types,Dwarf_Signed * ret_type_count,Dwarf_Error * error)3807dc1947SRichard Lowe dwarf_get_pubtypes(Dwarf_Debug dbg,
3907dc1947SRichard Lowe Dwarf_Type ** types,
4007dc1947SRichard Lowe Dwarf_Signed * ret_type_count, Dwarf_Error * error)
4107dc1947SRichard Lowe {
4207dc1947SRichard Lowe int res = _dwarf_load_section(dbg, &dbg->de_debug_pubtypes,error);
4307dc1947SRichard Lowe if (res != DW_DLV_OK) {
4407dc1947SRichard Lowe return res;
4507dc1947SRichard Lowe }
46*4d9fdb46SRobert Mustacchi if (!dbg->de_debug_pubtypes.dss_size) {
47*4d9fdb46SRobert Mustacchi return DW_DLV_NO_ENTRY;
48*4d9fdb46SRobert Mustacchi }
4907dc1947SRichard Lowe
50*4d9fdb46SRobert Mustacchi res = _dwarf_internal_get_pubnames_like_data(dbg,
51*4d9fdb46SRobert Mustacchi dbg->de_debug_pubtypes.dss_data,
52*4d9fdb46SRobert Mustacchi dbg->de_debug_pubtypes.dss_size,
53*4d9fdb46SRobert Mustacchi (Dwarf_Global **) types, /* Type punning for sections
5407dc1947SRichard Lowe with identical format. */
55*4d9fdb46SRobert Mustacchi ret_type_count, error,
56*4d9fdb46SRobert Mustacchi DW_DLA_PUBTYPES_CONTEXT,
57*4d9fdb46SRobert Mustacchi DW_DLA_GLOBAL, /* We don't have DW_DLA_PUBTYPES,
5807dc1947SRichard Lowe so use DW_DLA_GLOBAL. */
5907dc1947SRichard Lowe DW_DLE_DEBUG_PUBTYPES_LENGTH_BAD,
6007dc1947SRichard Lowe DW_DLE_DEBUG_PUBTYPES_VERSION_ERROR);
61*4d9fdb46SRobert Mustacchi return res;
6207dc1947SRichard Lowe }
6307dc1947SRichard Lowe
6407dc1947SRichard Lowe /* Deallocating fully requires deallocating the list
6507dc1947SRichard Lowe and all entries. But some internal data is
6607dc1947SRichard Lowe not exposed, so we need a function with internal knowledge.
6707dc1947SRichard Lowe */
6807dc1947SRichard Lowe
6907dc1947SRichard Lowe void
dwarf_pubtypes_dealloc(Dwarf_Debug dbg,Dwarf_Type * dwgl,Dwarf_Signed count)7007dc1947SRichard Lowe dwarf_pubtypes_dealloc(Dwarf_Debug dbg, Dwarf_Type * dwgl,
7107dc1947SRichard Lowe Dwarf_Signed count)
7207dc1947SRichard Lowe {
73*4d9fdb46SRobert Mustacchi _dwarf_internal_globals_dealloc(dbg,
74*4d9fdb46SRobert Mustacchi (Dwarf_Global *) dwgl,
75*4d9fdb46SRobert Mustacchi count,
76*4d9fdb46SRobert Mustacchi DW_DLA_PUBTYPES_CONTEXT,
77*4d9fdb46SRobert Mustacchi DW_DLA_GLOBAL, /* We don't have DW_DLA_PUBTYPES,
7807dc1947SRichard Lowe so use DW_DLA_GLOBAL. */
7907dc1947SRichard Lowe DW_DLA_LIST);
8007dc1947SRichard Lowe return;
8107dc1947SRichard Lowe }
8207dc1947SRichard Lowe
8307dc1947SRichard Lowe
8407dc1947SRichard Lowe
8507dc1947SRichard Lowe int
dwarf_pubtypename(Dwarf_Type type_in,char ** ret_name,Dwarf_Error * error)8607dc1947SRichard Lowe dwarf_pubtypename(Dwarf_Type type_in, char **ret_name,
8707dc1947SRichard Lowe Dwarf_Error * error)
8807dc1947SRichard Lowe {
8907dc1947SRichard Lowe Dwarf_Global type = (Dwarf_Global) type_in;
9007dc1947SRichard Lowe if (type == NULL) {
9107dc1947SRichard Lowe _dwarf_error(NULL, error, DW_DLE_TYPE_NULL);
9207dc1947SRichard Lowe return (DW_DLV_ERROR);
9307dc1947SRichard Lowe }
9407dc1947SRichard Lowe *ret_name = (char *) (type->gl_name);
9507dc1947SRichard Lowe return DW_DLV_OK;
9607dc1947SRichard Lowe }
9707dc1947SRichard Lowe
9807dc1947SRichard Lowe
9907dc1947SRichard Lowe int
dwarf_pubtype_type_die_offset(Dwarf_Type type_in,Dwarf_Off * ret_offset,Dwarf_Error * error)10007dc1947SRichard Lowe dwarf_pubtype_type_die_offset(Dwarf_Type type_in,
10107dc1947SRichard Lowe Dwarf_Off * ret_offset,
10207dc1947SRichard Lowe Dwarf_Error * error)
10307dc1947SRichard Lowe {
10407dc1947SRichard Lowe Dwarf_Global type = (Dwarf_Global) type_in;
10507dc1947SRichard Lowe
10607dc1947SRichard Lowe return dwarf_global_die_offset(type, ret_offset, error);
10707dc1947SRichard Lowe }
10807dc1947SRichard Lowe
10907dc1947SRichard Lowe
11007dc1947SRichard Lowe int
dwarf_pubtype_cu_offset(Dwarf_Type type_in,Dwarf_Off * ret_offset,Dwarf_Error * error)11107dc1947SRichard Lowe dwarf_pubtype_cu_offset(Dwarf_Type type_in,
11207dc1947SRichard Lowe Dwarf_Off * ret_offset, Dwarf_Error * error)
11307dc1947SRichard Lowe {
11407dc1947SRichard Lowe Dwarf_Global type = (Dwarf_Global) type_in;
11507dc1947SRichard Lowe
11607dc1947SRichard Lowe return dwarf_global_cu_offset(type, ret_offset, error);
11707dc1947SRichard Lowe
11807dc1947SRichard Lowe }
11907dc1947SRichard Lowe
12007dc1947SRichard Lowe
12107dc1947SRichard Lowe int
dwarf_pubtype_name_offsets(Dwarf_Type type_in,char ** returned_name,Dwarf_Off * die_offset,Dwarf_Off * cu_die_offset,Dwarf_Error * error)12207dc1947SRichard Lowe dwarf_pubtype_name_offsets(Dwarf_Type type_in,
12307dc1947SRichard Lowe char **returned_name,
12407dc1947SRichard Lowe Dwarf_Off * die_offset,
12507dc1947SRichard Lowe Dwarf_Off * cu_die_offset,
12607dc1947SRichard Lowe Dwarf_Error * error)
12707dc1947SRichard Lowe {
12807dc1947SRichard Lowe Dwarf_Global type = (Dwarf_Global) type_in;
12907dc1947SRichard Lowe
13007dc1947SRichard Lowe return dwarf_global_name_offsets(type,
13107dc1947SRichard Lowe returned_name,
13207dc1947SRichard Lowe die_offset, cu_die_offset, error);
13307dc1947SRichard Lowe }
134