1*7fd79137SRobert Mustacchi /*
2*7fd79137SRobert Mustacchi
3*7fd79137SRobert Mustacchi Copyright (C) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
4*7fd79137SRobert Mustacchi Portions Copyright (C) 2009-2010 David Anderson. All Rights Reserved.
5*7fd79137SRobert Mustacchi
6*7fd79137SRobert Mustacchi This program is free software; you can redistribute it and/or modify it
7*7fd79137SRobert Mustacchi under the terms of version 2.1 of the GNU Lesser General Public License
8*7fd79137SRobert Mustacchi as published by the Free Software Foundation.
9*7fd79137SRobert Mustacchi
10*7fd79137SRobert Mustacchi This program is distributed in the hope that it would be useful, but
11*7fd79137SRobert Mustacchi WITHOUT ANY WARRANTY; without even the implied warranty of
12*7fd79137SRobert Mustacchi MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13*7fd79137SRobert Mustacchi
14*7fd79137SRobert Mustacchi Further, this software is distributed without any warranty that it is
15*7fd79137SRobert Mustacchi free of the rightful claim of any third person regarding infringement
16*7fd79137SRobert Mustacchi or the like. Any license provided herein, whether implied or
17*7fd79137SRobert Mustacchi otherwise, applies only to this software file. Patent licenses, if
18*7fd79137SRobert Mustacchi any, provided herein do not apply to combinations of this program with
19*7fd79137SRobert Mustacchi other software, or any other product whatsoever.
20*7fd79137SRobert Mustacchi
21*7fd79137SRobert Mustacchi You should have received a copy of the GNU Lesser General Public
22*7fd79137SRobert Mustacchi License along with this program; if not, write the Free Software
23*7fd79137SRobert Mustacchi Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
24*7fd79137SRobert Mustacchi USA.
25*7fd79137SRobert Mustacchi
26*7fd79137SRobert Mustacchi Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane,
27*7fd79137SRobert Mustacchi Mountain View, CA 94043, or:
28*7fd79137SRobert Mustacchi
29*7fd79137SRobert Mustacchi http://www.sgi.com
30*7fd79137SRobert Mustacchi
31*7fd79137SRobert Mustacchi For further information regarding this notice, see:
32*7fd79137SRobert Mustacchi
33*7fd79137SRobert Mustacchi http://oss.sgi.com/projects/GenInfo/NoticeExplan
34*7fd79137SRobert Mustacchi
35*7fd79137SRobert Mustacchi */
36*7fd79137SRobert Mustacchi
37*7fd79137SRobert Mustacchi
38*7fd79137SRobert Mustacchi
39*7fd79137SRobert Mustacchi #include "config.h"
40*7fd79137SRobert Mustacchi #include "dwarf_incl.h"
41*7fd79137SRobert Mustacchi
42*7fd79137SRobert Mustacchi int
dwarf_get_str(Dwarf_Debug dbg,Dwarf_Off offset,char ** string,Dwarf_Signed * returned_str_len,Dwarf_Error * error)43*7fd79137SRobert Mustacchi dwarf_get_str(Dwarf_Debug dbg,
44*7fd79137SRobert Mustacchi Dwarf_Off offset,
45*7fd79137SRobert Mustacchi char **string,
46*7fd79137SRobert Mustacchi Dwarf_Signed * returned_str_len, Dwarf_Error * error)
47*7fd79137SRobert Mustacchi {
48*7fd79137SRobert Mustacchi int res = DW_DLV_ERROR;
49*7fd79137SRobert Mustacchi
50*7fd79137SRobert Mustacchi if (dbg == NULL) {
51*7fd79137SRobert Mustacchi _dwarf_error(NULL, error, DW_DLE_DBG_NULL);
52*7fd79137SRobert Mustacchi return (DW_DLV_ERROR);
53*7fd79137SRobert Mustacchi }
54*7fd79137SRobert Mustacchi
55*7fd79137SRobert Mustacchi if (offset == dbg->de_debug_str.dss_size) {
56*7fd79137SRobert Mustacchi /* Normal (if we've iterated thru the set of strings using
57*7fd79137SRobert Mustacchi dwarf_get_str and are at the end). */
58*7fd79137SRobert Mustacchi return DW_DLV_NO_ENTRY;
59*7fd79137SRobert Mustacchi }
60*7fd79137SRobert Mustacchi if (offset > dbg->de_debug_str.dss_size) {
61*7fd79137SRobert Mustacchi _dwarf_error(dbg, error, DW_DLE_DEBUG_STR_OFFSET_BAD);
62*7fd79137SRobert Mustacchi return (DW_DLV_ERROR);
63*7fd79137SRobert Mustacchi }
64*7fd79137SRobert Mustacchi
65*7fd79137SRobert Mustacchi if (string == NULL) {
66*7fd79137SRobert Mustacchi _dwarf_error(dbg, error, DW_DLE_STRING_PTR_NULL);
67*7fd79137SRobert Mustacchi return (DW_DLV_ERROR);
68*7fd79137SRobert Mustacchi }
69*7fd79137SRobert Mustacchi
70*7fd79137SRobert Mustacchi res = _dwarf_load_section(dbg, &dbg->de_debug_str,error);
71*7fd79137SRobert Mustacchi if (res != DW_DLV_OK) {
72*7fd79137SRobert Mustacchi return res;
73*7fd79137SRobert Mustacchi }
74*7fd79137SRobert Mustacchi
75*7fd79137SRobert Mustacchi *string = (char *) dbg->de_debug_str.dss_data + offset;
76*7fd79137SRobert Mustacchi
77*7fd79137SRobert Mustacchi *returned_str_len = (strlen(*string));
78*7fd79137SRobert Mustacchi return DW_DLV_OK;
79*7fd79137SRobert Mustacchi }
80