149d3bc91SRichard Lowe /*
249d3bc91SRichard Lowe
3*07dc1947SRichard Lowe Copyright (C) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
4*07dc1947SRichard 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
749d3bc91SRichard Lowe 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
1249d3bc91SRichard Lowe MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1349d3bc91SRichard Lowe
1449d3bc91SRichard Lowe Further, this software is distributed without any warranty that it is
1549d3bc91SRichard Lowe free of the rightful claim of any third person regarding infringement
1649d3bc91SRichard Lowe or the like. Any license provided herein, whether implied or
1749d3bc91SRichard Lowe otherwise, applies only to this software file. Patent licenses, if
1849d3bc91SRichard Lowe any, provided herein do not apply to combinations of this program with
1949d3bc91SRichard Lowe other software, or any other product whatsoever.
2049d3bc91SRichard Lowe
2149d3bc91SRichard Lowe You should have received a copy of the GNU Lesser General Public
2249d3bc91SRichard Lowe License along with this program; if not, write the Free Software
23*07dc1947SRichard Lowe Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
2449d3bc91SRichard Lowe USA.
2549d3bc91SRichard Lowe
26*07dc1947SRichard Lowe Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane,
2749d3bc91SRichard Lowe Mountain View, CA 94043, or:
2849d3bc91SRichard Lowe
2949d3bc91SRichard Lowe http://www.sgi.com
3049d3bc91SRichard Lowe
3149d3bc91SRichard Lowe For further information regarding this notice, see:
3249d3bc91SRichard Lowe
3349d3bc91SRichard Lowe http://oss.sgi.com/projects/GenInfo/NoticeExplan
3449d3bc91SRichard Lowe
3549d3bc91SRichard Lowe */
3649d3bc91SRichard Lowe
3749d3bc91SRichard Lowe
3849d3bc91SRichard Lowe
3949d3bc91SRichard Lowe #include "config.h"
4049d3bc91SRichard Lowe #include "dwarf_incl.h"
4149d3bc91SRichard Lowe
4249d3bc91SRichard Lowe int
dwarf_get_str(Dwarf_Debug dbg,Dwarf_Off offset,char ** string,Dwarf_Signed * returned_str_len,Dwarf_Error * error)4349d3bc91SRichard Lowe dwarf_get_str(Dwarf_Debug dbg,
4449d3bc91SRichard Lowe Dwarf_Off offset,
4549d3bc91SRichard Lowe char **string,
4649d3bc91SRichard Lowe Dwarf_Signed * returned_str_len, Dwarf_Error * error)
4749d3bc91SRichard Lowe {
48*07dc1947SRichard Lowe int res = DW_DLV_ERROR;
4949d3bc91SRichard Lowe
5049d3bc91SRichard Lowe if (dbg == NULL) {
5149d3bc91SRichard Lowe _dwarf_error(NULL, error, DW_DLE_DBG_NULL);
5249d3bc91SRichard Lowe return (DW_DLV_ERROR);
5349d3bc91SRichard Lowe }
5449d3bc91SRichard Lowe
55*07dc1947SRichard Lowe if (offset == dbg->de_debug_str.dss_size) {
56*07dc1947SRichard Lowe /* Normal (if we've iterated thru the set of strings using
57*07dc1947SRichard Lowe dwarf_get_str and are at the end). */
5849d3bc91SRichard Lowe return DW_DLV_NO_ENTRY;
5949d3bc91SRichard Lowe }
60*07dc1947SRichard Lowe if (offset > dbg->de_debug_str.dss_size) {
6149d3bc91SRichard Lowe _dwarf_error(dbg, error, DW_DLE_DEBUG_STR_OFFSET_BAD);
6249d3bc91SRichard Lowe return (DW_DLV_ERROR);
6349d3bc91SRichard Lowe }
6449d3bc91SRichard Lowe
6549d3bc91SRichard Lowe if (string == NULL) {
6649d3bc91SRichard Lowe _dwarf_error(dbg, error, DW_DLE_STRING_PTR_NULL);
6749d3bc91SRichard Lowe return (DW_DLV_ERROR);
6849d3bc91SRichard Lowe }
6949d3bc91SRichard Lowe
70*07dc1947SRichard Lowe res = _dwarf_load_section(dbg, &dbg->de_debug_str,error);
7149d3bc91SRichard Lowe if (res != DW_DLV_OK) {
7249d3bc91SRichard Lowe return res;
7349d3bc91SRichard Lowe }
7449d3bc91SRichard Lowe
75*07dc1947SRichard Lowe *string = (char *) dbg->de_debug_str.dss_data + offset;
7649d3bc91SRichard Lowe
7749d3bc91SRichard Lowe *returned_str_len = (strlen(*string));
7849d3bc91SRichard Lowe return DW_DLV_OK;
7949d3bc91SRichard Lowe }
80