xref: /titanic_44/usr/src/tools/ctf/dwarf/common/dwarf_string.c (revision 6a3e8e8695d5c7d1d18c6800d676990d7f61a2a4)
1 /*
2 
3   Copyright (C) 2000-2004 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 
42 int
43 dwarf_get_str(Dwarf_Debug dbg,
44               Dwarf_Off offset,
45               char **string,
46               Dwarf_Signed * returned_str_len, Dwarf_Error * error)
47 {
48     int res = DW_DLV_ERROR;
49 
50     if (dbg == NULL) {
51         _dwarf_error(NULL, error, DW_DLE_DBG_NULL);
52         return (DW_DLV_ERROR);
53     }
54 
55     if (offset == dbg->de_debug_str.dss_size) {
56         /* Normal (if we've iterated thru the set of strings using
57            dwarf_get_str and are at the end). */
58         return DW_DLV_NO_ENTRY;
59     }
60     if (offset > dbg->de_debug_str.dss_size) {
61         _dwarf_error(dbg, error, DW_DLE_DEBUG_STR_OFFSET_BAD);
62         return (DW_DLV_ERROR);
63     }
64 
65     if (string == NULL) {
66         _dwarf_error(dbg, error, DW_DLE_STRING_PTR_NULL);
67         return (DW_DLV_ERROR);
68     }
69 
70     res = _dwarf_load_section(dbg, &dbg->de_debug_str,error);
71     if (res != DW_DLV_OK) {
72         return res;
73     }
74 
75     *string = (char *) dbg->de_debug_str.dss_data + offset;
76 
77     *returned_str_len = (strlen(*string));
78     return DW_DLV_OK;
79 }
80