blob: 205a94665238e1475255eb12b910e8b1e02f3940 [file] [log] [blame]
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00001/* Return string represented by attribute.
2 Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
3 Written by Ulrich Drepper <drepper@redhat.com>, 2000.
4
5 This program is Open Source software; you can redistribute it and/or
6 modify it under the terms of the Open Software License version 1.0 as
7 published by the Open Source Initiative.
8
9 You should have received a copy of the Open Software License along
10 with this program; if not, you may obtain a copy of the Open Software
11 License version 1.0 from http://www.opensource.org/licenses/osl.php or
12 by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
13 3001 King Ranch Road, Ukiah, CA 95482. */
14
15#ifdef HAVE_CONFIG_H
16# include <config.h>
17#endif
18
19#include <dwarf.h>
20#include <string.h>
21
22#include <libdwarfP.h>
23
24
25int
26dwarf_formstring (attr, return_string, error)
27 Dwarf_Attribute attr;
28 char **return_string;
29 Dwarf_Error *error;
30{
31 char *result;
32
33 if (attr->form == DW_FORM_string)
34 result = (char *) attr->valp;
35 else if (likely (attr->form == DW_FORM_strp))
36 {
37 Dwarf_Unsigned offset;
38
39 offset = read_4ubyte_unaligned (attr->cu->dbg, attr->valp);
40
41 result = (char *) attr->cu->dbg->sections[IDX_debug_str].addr + offset;
42 }
43 else
44 {
45 __libdwarf_error (attr->cu->dbg, error, DW_E_NO_STRING);
46 return DW_DLV_ERROR;
47 }
48
49 *return_string = result;
50 return DW_DLV_OK;
51}