blob: a9b149c02682561d1afdd57e61c19081d0afdf0c [file] [log] [blame]
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00001/* Return name, DIE offset, and offset of the compile unit for global
2 definition.
3 Copyright (C) 2000, 2002 Red Hat, Inc.
4 Written by Ulrich Drepper <drepper@redhat.com>, 2000.
5
6 This program is Open Source software; you can redistribute it and/or
7 modify it under the terms of the Open Software License version 1.0 as
8 published by the Open Source Initiative.
9
10 You should have received a copy of the Open Software License along
11 with this program; if not, you may obtain a copy of the Open Software
12 License version 1.0 from http://www.opensource.org/licenses/osl.php or
13 by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
14 3001 King Ranch Road, Ukiah, CA 95482. */
15
16#ifdef HAVE_CONFIG_H
17# include <config.h>
18#endif
19
20#include <string.h>
21
22#include <libdwarfP.h>
23
24
25int
26dwarf_global_name_offsets (global, return_name, die_offset, cu_offset, error)
27 Dwarf_Global global;
28 char **return_name;
29 Dwarf_Off *die_offset;
30 Dwarf_Off *cu_offset;
31 Dwarf_Error *error;
32{
33 if (return_name != NULL)
34 {
35 *return_name = strdup (global->name);
36 if (*return_name == NULL)
37 {
38 __libdwarf_error (global->info->dbg, error, DW_E_NOMEM);
39 return DW_DLV_ERROR;
40 }
41 }
42
43 if (die_offset != NULL)
44 *die_offset = global->offset + global->info->offset;
45
46 /* Determine the size of the CU header. */
47 if (cu_offset != NULL)
48 {
49 Dwarf_Small *cu_header;
50 unsigned int offset_size;
51
52 cu_header =
53 ((Dwarf_Small *) global->info->dbg->sections[IDX_debug_info].addr
54 + global->info->offset);
55 if (read_4ubyte_unaligned_noncvt (cu_header) == 0xffffffff)
56 offset_size = 8;
57 else
58 offset_size = 4;
59
60 *cu_offset = global->info->offset + 3 * offset_size - 4 + 3;
61 }
62
63 return DW_DLV_OK;
64}