149d3bc91SRichard Lowe /*
249d3bc91SRichard Lowe 
307dc1947SRichard Lowe   Copyright (C) 2000-2005 Silicon Graphics, Inc.  All Rights Reserved.
407dc1947SRichard Lowe   Portions Copyright (C) 2009-2010 David Anderson. All Rights Reserved.
549d3bc91SRichard Lowe 
649d3bc91SRichard 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
849d3bc91SRichard Lowe   as published by the Free Software Foundation.
949d3bc91SRichard Lowe 
1049d3bc91SRichard Lowe   This program is distributed in the hope that it would be useful, but
1149d3bc91SRichard Lowe   WITHOUT ANY WARRANTY; without even the implied warranty of
1349d3bc91SRichard Lowe 
1449d3bc91SRichard 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
1749d3bc91SRichard 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.
2049d3bc91SRichard 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,
2449d3bc91SRichard Lowe   USA.
2549d3bc91SRichard Lowe 
2649d3bc91SRichard Lowe */
2749d3bc91SRichard Lowe 
2849d3bc91SRichard Lowe #include "config.h"
2949d3bc91SRichard Lowe #include <stdio.h>
30*4d9fdb46SRobert Mustacchi #include "dwarf_incl.h"
31*4d9fdb46SRobert Mustacchi #include "dwarf_error.h"
3249d3bc91SRichard Lowe #include "dwarf_weaks.h"
3349d3bc91SRichard Lowe #include "dwarf_global.h"
3449d3bc91SRichard Lowe 
3549d3bc91SRichard Lowe int
dwarf_get_weaks(Dwarf_Debug dbg,Dwarf_Weak ** weaks,Dwarf_Signed * ret_weak_count,Dwarf_Error * error)3649d3bc91SRichard Lowe dwarf_get_weaks(Dwarf_Debug dbg,
3707dc1947SRichard Lowe     Dwarf_Weak ** weaks,
3807dc1947SRichard Lowe     Dwarf_Signed * ret_weak_count, Dwarf_Error * error)
3949d3bc91SRichard Lowe {
4007dc1947SRichard Lowe     int res = _dwarf_load_section(dbg, &dbg->de_debug_weaknames,error);
4149d3bc91SRichard Lowe     if (res != DW_DLV_OK) {
4207dc1947SRichard Lowe         return res;
4349d3bc91SRichard Lowe     }
44*4d9fdb46SRobert Mustacchi     if (!dbg->de_debug_weaknames.dss_size) {
45*4d9fdb46SRobert Mustacchi         return (DW_DLV_NO_ENTRY);
46*4d9fdb46SRobert Mustacchi     }
47*4d9fdb46SRobert Mustacchi 
4849d3bc91SRichard Lowe 
49*4d9fdb46SRobert Mustacchi     return _dwarf_internal_get_pubnames_like_data(dbg,
50*4d9fdb46SRobert Mustacchi         dbg->de_debug_weaknames.dss_data,
51*4d9fdb46SRobert Mustacchi         dbg->de_debug_weaknames.dss_size,
52*4d9fdb46SRobert Mustacchi         (Dwarf_Global **) weaks, /* Type punning for sections
5307dc1947SRichard Lowe             with identical format. */
5407dc1947SRichard Lowe         ret_weak_count,
5507dc1947SRichard Lowe         error,
5607dc1947SRichard Lowe         DW_DLA_WEAK_CONTEXT,
5707dc1947SRichard Lowe         DW_DLA_WEAK,
5807dc1947SRichard Lowe         DW_DLE_DEBUG_WEAKNAMES_LENGTH_BAD,
5907dc1947SRichard Lowe         DW_DLE_DEBUG_WEAKNAMES_VERSION_ERROR);
6007dc1947SRichard Lowe }
6149d3bc91SRichard Lowe 
6207dc1947SRichard Lowe /* Deallocating fully requires deallocating the list
6307dc1947SRichard Lowe    and all entries.  But some internal data is
6407dc1947SRichard Lowe    not exposed, so we need a function with internal knowledge.
6507dc1947SRichard Lowe */
6607dc1947SRichard Lowe 
6707dc1947SRichard Lowe void
dwarf_weaks_dealloc(Dwarf_Debug dbg,Dwarf_Weak * dwgl,Dwarf_Signed count)6807dc1947SRichard Lowe dwarf_weaks_dealloc(Dwarf_Debug dbg, Dwarf_Weak * dwgl,
6907dc1947SRichard Lowe     Dwarf_Signed count)
7007dc1947SRichard Lowe {
7107dc1947SRichard Lowe     _dwarf_internal_globals_dealloc(dbg, (Dwarf_Global *) dwgl,
7207dc1947SRichard Lowe         count,
7307dc1947SRichard Lowe         DW_DLA_WEAK_CONTEXT,
7407dc1947SRichard Lowe         DW_DLA_WEAK, DW_DLA_LIST);
7507dc1947SRichard Lowe     return;
7649d3bc91SRichard Lowe }
7749d3bc91SRichard Lowe 
7849d3bc91SRichard Lowe 
7949d3bc91SRichard Lowe 
8049d3bc91SRichard Lowe int
dwarf_weakname(Dwarf_Weak weak_in,char ** ret_name,Dwarf_Error * error)8149d3bc91SRichard Lowe dwarf_weakname(Dwarf_Weak weak_in, char **ret_name, Dwarf_Error * error)
8249d3bc91SRichard Lowe {
8349d3bc91SRichard Lowe     Dwarf_Global weak = (Dwarf_Global) weak_in;
8449d3bc91SRichard Lowe 
8549d3bc91SRichard Lowe     if (weak == NULL) {
8607dc1947SRichard Lowe         _dwarf_error(NULL, error, DW_DLE_WEAK_NULL);
8707dc1947SRichard Lowe         return (DW_DLV_ERROR);
8849d3bc91SRichard Lowe     }
8949d3bc91SRichard Lowe     *ret_name = (char *) (weak->gl_name);
9049d3bc91SRichard Lowe     return DW_DLV_OK;
9149d3bc91SRichard Lowe }
9249d3bc91SRichard Lowe 
9349d3bc91SRichard Lowe 
9449d3bc91SRichard Lowe int
dwarf_weak_die_offset(Dwarf_Weak weak_in,Dwarf_Off * weak_off,Dwarf_Error * error)9549d3bc91SRichard Lowe dwarf_weak_die_offset(Dwarf_Weak weak_in,
9607dc1947SRichard Lowe     Dwarf_Off * weak_off, Dwarf_Error * error)
9749d3bc91SRichard Lowe {
9849d3bc91SRichard Lowe     Dwarf_Global weak = (Dwarf_Global) weak_in;
9949d3bc91SRichard Lowe 
10049d3bc91SRichard Lowe     return dwarf_global_die_offset(weak, weak_off, error);
10149d3bc91SRichard Lowe }
10249d3bc91SRichard Lowe 
10349d3bc91SRichard Lowe 
10449d3bc91SRichard Lowe int
dwarf_weak_cu_offset(Dwarf_Weak weak_in,Dwarf_Off * weak_off,Dwarf_Error * error)10549d3bc91SRichard Lowe dwarf_weak_cu_offset(Dwarf_Weak weak_in,
10607dc1947SRichard Lowe     Dwarf_Off * weak_off, Dwarf_Error * error)
10749d3bc91SRichard Lowe {
10849d3bc91SRichard Lowe     Dwarf_Global weak = (Dwarf_Global) weak_in;
10949d3bc91SRichard Lowe 
11049d3bc91SRichard Lowe     return dwarf_global_cu_offset(weak, weak_off, error);
11149d3bc91SRichard Lowe }
11249d3bc91SRichard Lowe 
11349d3bc91SRichard Lowe 
11449d3bc91SRichard Lowe int
dwarf_weak_name_offsets(Dwarf_Weak weak_in,char ** weak_name,Dwarf_Off * die_offset,Dwarf_Off * cu_offset,Dwarf_Error * error)11549d3bc91SRichard Lowe dwarf_weak_name_offsets(Dwarf_Weak weak_in,
11607dc1947SRichard Lowe     char **weak_name,
11707dc1947SRichard Lowe     Dwarf_Off * die_offset,
11807dc1947SRichard Lowe     Dwarf_Off * cu_offset, Dwarf_Error * error)
11949d3bc91SRichard Lowe {
12049d3bc91SRichard Lowe     Dwarf_Global weak = (Dwarf_Global) weak_in;
12149d3bc91SRichard Lowe 
12249d3bc91SRichard Lowe     return dwarf_global_name_offsets(weak,
12307dc1947SRichard Lowe         weak_name, die_offset, cu_offset, error);
12449d3bc91SRichard Lowe }