149d3bc9Richard Lowe/*
249d3bc9Richard Lowe
307dc194Richard Lowe  Copyright (C) 2000,2004 Silicon Graphics, Inc.  All Rights Reserved.
407dc194Richard Lowe  Portions Copyright 2002-2010 Sun Microsystems, Inc. All rights reserved.
549d3bc9Richard Lowe
649d3bc9Richard Lowe  This program is free software; you can redistribute it and/or modify it
749d3bc9Richard Lowe  under the terms of version 2.1 of the GNU Lesser General Public License
849d3bc9Richard Lowe  as published by the Free Software Foundation.
949d3bc9Richard Lowe
1049d3bc9Richard Lowe  This program is distributed in the hope that it would be useful, but
1149d3bc9Richard Lowe  WITHOUT ANY WARRANTY; without even the implied warranty of
1349d3bc9Richard Lowe
1449d3bc9Richard Lowe  Further, this software is distributed without any warranty that it is
1549d3bc9Richard Lowe  free of the rightful claim of any third person regarding infringement
1649d3bc9Richard Lowe  or the like.  Any license provided herein, whether implied or
1749d3bc9Richard Lowe  otherwise, applies only to this software file.  Patent licenses, if
1849d3bc9Richard Lowe  any, provided herein do not apply to combinations of this program with
1949d3bc9Richard Lowe  other software, or any other product whatsoever.
2049d3bc9Richard Lowe
2149d3bc9Richard Lowe  You should have received a copy of the GNU Lesser General Public
2249d3bc9Richard Lowe  License along with this program; if not, write the Free Software
2307dc194Richard Lowe  Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
2449d3bc9Richard Lowe  USA.
2549d3bc9Richard Lowe
2607dc194Richard Lowe  Contact information:  Silicon Graphics, Inc., 1500 Crittenden Lane,
2749d3bc9Richard Lowe  Mountain View, CA 94043, or:
2849d3bc9Richard Lowe
2949d3bc9Richard Lowe  http://www.sgi.com
3049d3bc9Richard Lowe
3149d3bc9Richard Lowe  For further information regarding this notice, see:
3249d3bc9Richard Lowe
3349d3bc9Richard Lowe  http://oss.sgi.com/projects/GenInfo/NoticeExplan
3449d3bc9Richard Lowe
3549d3bc9Richard Lowe*/
3649d3bc9Richard Lowe
3749d3bc9Richard Lowe
3849d3bc9Richard Lowe
3949d3bc9Richard Lowe#include "config.h"
4049d3bc9Richard Lowe#include "libdwarfdefs.h"
4149d3bc9Richard Lowe#include <stdio.h>
4249d3bc9Richard Lowe#include <string.h>
4349d3bc9Richard Lowe#include "pro_incl.h"
4449d3bc9Richard Lowe#include "pro_die.h"
4549d3bc9Richard Lowe
4649d3bc9Richard Lowe#ifndef R_MIPS_NONE
4749d3bc9Richard Lowe#define R_MIPS_NONE 0
4849d3bc9Richard Lowe#endif
4949d3bc9Richard Lowe
5049d3bc9Richard Lowe/* adds an attribute to a die */
5149d3bc9Richard Lowevoid _dwarf_pro_add_at_to_die(Dwarf_P_Die die, Dwarf_P_Attribute attr);
5249d3bc9Richard Lowe
5349d3bc9Richard Lowe/*----------------------------------------------------------------------------
5407dc194Richard Lowe    This function creates a new die.
5507dc194Richard Lowe    tag: tag of the new die to be created
5607dc194Richard Lowe    parent,child,left,right: specify neighbors of the new die. Only
5707dc194Richard Lowe    one of these may be non-null
5849d3bc9Richard Lowe-----------------------------------------------------------------------------*/
5949d3bc9Richard LoweDwarf_P_Die
6049d3bc9Richard Lowedwarf_new_die(Dwarf_P_Debug dbg,
6107dc194Richard Lowe      Dwarf_Tag tag,
6207dc194Richard Lowe      Dwarf_P_Die parent,
6307dc194Richard Lowe      Dwarf_P_Die child,
6407dc194Richard Lowe      Dwarf_P_Die left, Dwarf_P_Die right, Dwarf_Error * error)
6549d3bc9Richard Lowe{
6607dc194Richard Lowe    Dwarf_P_Die ret_die = 0;
6749d3bc9Richard Lowe
6807dc194Richard Lowe    Dwarf_P_Die new_die = (Dwarf_P_Die)
6907dc194Richard Lowe        _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Die_s));
7049d3bc9Richard Lowe    if (new_die == NULL) {
7107dc194Richard Lowe        DWARF_P_DBG_ERROR(dbg, DW_DLE_DIE_ALLOC,
7207dc194Richard Lowe            (Dwarf_P_Die) DW_DLV_BADADDR);
7349d3bc9Richard Lowe    }
7449d3bc9Richard Lowe    new_die->di_parent = NULL;
7549d3bc9Richard Lowe    new_die->di_left = NULL;
7649d3bc9Richard Lowe    new_die->di_right = NULL;
7749d3bc9Richard Lowe    new_die->di_child = NULL;
7807dc194Richard Lowe    new_die->di_last_child = NULL;
7949d3bc9Richard Lowe    new_die->di_tag = tag;
8007dc194Richard Lowe    new_die->di_dbg = dbg;
8107dc194Richard Lowe    new_die->di_marker = 0;
8207dc194Richard Lowe    ret_die =
8307dc194Richard Lowe        dwarf_die_link(new_die, parent, child, left, right, error);
8449d3bc9Richard Lowe    return ret_die;
8549d3bc9Richard Lowe}
8649d3bc9Richard Lowe
8749d3bc9Richard Lowe/*----------------------------------------------------------------------------
8807dc194Richard Lowe    This function links up a die to specified neighbors
8907dc194Richard Lowe    parent,child,left,right: specify neighbors of the new die. Only
9007dc194Richard Lowe    one of these may be non-null
9149d3bc9Richard Lowe-----------------------------------------------------------------------------*/
9249d3bc9Richard LoweDwarf_P_Die
9349d3bc9Richard Lowedwarf_die_link(Dwarf_P_Die new_die,
9407dc194Richard Lowe       Dwarf_P_Die parent,
9507dc194Richard Lowe       Dwarf_P_Die child,
9607dc194Richard Lowe       Dwarf_P_Die left, Dwarf_P_Die right, Dwarf_Error * error)
9749d3bc9Richard Lowe{
9807dc194Richard Lowe    /* Count the # of non null neighbors. */
9907dc194Richard Lowe    int n_nulls = 0;
10049d3bc9Richard Lowe
10149d3bc9Richard Lowe    if (parent != NULL) {
10207dc194Richard Lowe        n_nulls++;
10307dc194Richard Lowe        if (new_die->di_parent != NULL) {
10407dc194Richard Lowe              DWARF_P_DBG_ERROR(NULL, DW_DLE_LINK_LOOP,
10507dc194Richard Lowe                    (Dwarf_P_Die) DW_DLV_BADADDR);
10607dc194Richard Lowe        }
10707dc194Richard Lowe        new_die->di_parent = parent;
10807dc194Richard Lowe        if (parent->di_child) {
10907dc194Richard Lowe
11007dc194Richard Lowe            /* di_last_child identifies the last sibling, the
11107dc194Richard Lowe               die we want to attach new_die to. */
11207dc194Richard Lowe            /* ASSERT: if di_child is set so is di_last_child. */
11307dc194Richard Lowe            Dwarf_P_Die former_lastchild = parent->di_last_child;
11407dc194Richard Lowe            parent->di_last_child = new_die;
11507dc194Richard Lowe            /* Attach to  the new die to end of the sibling list. */
11607dc194Richard Lowe            former_lastchild->di_right = new_die;
11707dc194Richard Lowe            new_die->di_left = former_lastchild;
11807dc194Richard Lowe        } else {
11907dc194Richard Lowe            parent->di_child = new_die;
12007dc194Richard Lowe            parent->di_last_child = new_die;
12107dc194Richard Lowe        }
12249d3bc9Richard Lowe    }
12349d3bc9Richard Lowe    if (child != NULL) {
12407dc194Richard Lowe        n_nulls++;
12507dc194Richard Lowe        new_die->di_child = child;
12607dc194Richard Lowe        new_die->di_last_child = child;
12707dc194Richard Lowe        if (child->di_parent) {
12807dc194Richard Lowe            DWARF_P_DBG_ERROR(NULL, DW_DLE_PARENT_EXISTS,
12907dc194Richard Lowe                              (Dwarf_P_Die) DW_DLV_BADADDR);
13007dc194Richard Lowe        } else {
13107dc194Richard Lowe            child->di_parent = new_die;
13207dc194Richard Lowe        }
13349d3bc9Richard Lowe    }
13449d3bc9Richard Lowe    if (left != NULL) {
13507dc194Richard Lowe        n_nulls++;
13607dc194Richard Lowe        new_die->di_left = left;
13707dc194Richard Lowe        if (left->di_right) {
13807dc194Richard Lowe            /* There's already a right sibling of left,
13907dc194Richard Lowe               insert the new die in the list. */
14007dc194Richard Lowe            new_die->di_right = left->di_right;
14107dc194Richard Lowe            left->di_right->di_left = new_die;
14207dc194Richard Lowe        }
14307dc194Richard Lowe        left->di_right = new_die;
14407dc194Richard Lowe        if (new_die->di_parent) {
14507dc194Richard Lowe            DWARF_P_DBG_ERROR(NULL, DW_DLE_PARENT_EXISTS,
14607dc194Richard Lowe                              (Dwarf_P_Die) DW_DLV_BADADDR);
14707dc194Richard Lowe        } else {
14807dc194Richard Lowe            new_die->di_parent = left->di_parent;
14907dc194Richard Lowe        }
15049d3bc9Richard Lowe    }
15149d3bc9Richard Lowe    if (right != NULL) {
15207dc194Richard Lowe        n_nulls++;
15307dc194Richard Lowe        new_die->di_right = right;
15407dc194Richard Lowe        if (right->di_left) {
15507dc194Richard Lowe            /* There is already a left sibling of the right die,
15607dc194Richard Lowe               insert the new die in the list.  */
15707dc194Richard Lowe            new_die->di_left = right->di_left;
15807dc194Richard Lowe            right->di_left->di_right = new_die;
15907dc194Richard Lowe        }
16007dc194Richard Lowe        right->di_left = new_die;
16107dc194Richard Lowe        if (new_die->di_parent) {
16207dc194Richard Lowe             DWARF_P_DBG_ERROR(NULL, DW_DLE_PARENT_EXISTS,
16307dc194Richard Lowe                              (Dwarf_P_Die) DW_DLV_BADADDR);
16407dc194Richard Lowe         } else {
16507dc194Richard Lowe             new_die->di_parent = right->di_parent;
16607dc194Richard Lowe        }
16749d3bc9Richard Lowe    }
16807dc194Richard Lowe    if (n_nulls > 1) {
16907dc194Richard Lowe         /* Multiple neighbors! error! */
17007dc194Richard Lowe         DWARF_P_DBG_ERROR(NULL, DW_DLE_EXTRA_NEIGHBORS,
17107dc194Richard Lowe             (Dwarf_P_Die) DW_DLV_BADADDR);
17249d3bc9Richard Lowe    }
17349d3bc9Richard Lowe    return new_die;
17449d3bc9Richard Lowe
17549d3bc9Richard Lowe}
17649d3bc9Richard Lowe
17707dc194Richard LoweDwarf_Unsigned
17807dc194Richard Lowedwarf_add_die_marker(Dwarf_P_Debug dbg,
17907dc194Richard Lowe    Dwarf_P_Die die,
18007dc194Richard Lowe    Dwarf_Unsigned marker,
18107dc194Richard Lowe    Dwarf_Error * error)
18207dc194Richard Lowe{
18307dc194Richard Lowe    if (die == NULL) {
18407dc194Richard Lowe        DWARF_P_DBG_ERROR(dbg, DW_DLE_DIE_NULL, DW_DLV_NOCOUNT);
18507dc194Richard Lowe    }
18607dc194Richard Lowe    die->di_marker = marker;
18707dc194Richard Lowe    return 0;
18807dc194Richard Lowe}
18907dc194Richard Lowe
19007dc194Richard Lowe
19107dc194Richard LoweDwarf_Unsigned
19207dc194Richard Lowedwarf_get_die_marker(Dwarf_P_Debug dbg,
19307dc194Richard Lowe     Dwarf_P_Die die,
19407dc194Richard Lowe     Dwarf_Unsigned * marker,
19507dc194Richard Lowe     Dwarf_Error * error)
19607dc194Richard Lowe{
19707dc194Richard Lowe    if (die == NULL) {
19807dc194Richard Lowe        DWARF_P_DBG_ERROR(dbg, DW_DLE_DIE_NULL, DW_DLV_NOCOUNT);
19907dc194Richard Lowe    }
20007dc194Richard Lowe    *marker = die->di_marker;
20107dc194Richard Lowe    return 0;
20207dc194Richard Lowe}
20307dc194Richard Lowe
20407dc194Richard Lowe
20549d3bc9Richard Lowe/*----------------------------------------------------------------------------
20607dc194Richard Lowe    This function adds a die to dbg struct. It should be called using
20707dc194Richard Lowe    the root of all the dies.
20849d3bc9Richard Lowe-----------------------------------------------------------------------------*/
20949d3bc9Richard LoweDwarf_Unsigned
21049d3bc9Richard Lowedwarf_add_die_to_debug(Dwarf_P_Debug dbg,
21107dc194Richard Lowe     Dwarf_P_Die first_die, Dwarf_Error * error)
21249d3bc9Richard Lowe{
21349d3bc9Richard Lowe    if (first_die == NULL) {
21407dc194Richard Lowe        DWARF_P_DBG_ERROR(dbg, DW_DLE_DIE_NULL, DW_DLV_NOCOUNT);
21549d3bc9Richard Lowe    }
21649d3bc9Richard Lowe    if (first_die->di_tag != DW_TAG_compile_unit) {
21707dc194Richard Lowe        DWARF_P_DBG_ERROR(dbg, DW_DLE_WRONG_TAG, DW_DLV_NOCOUNT);
21849d3bc9Richard Lowe    }
21949d3bc9Richard Lowe    dbg->de_dies = first_die;
22049d3bc9Richard Lowe    return 0;
22149d3bc9Richard Lowe}
22249d3bc9Richard Lowe
22349d3bc9Richard Loweint
22449d3bc9Richard Lowe_dwarf_pro_add_AT_stmt_list(Dwarf_P_Debug dbg,
22507dc194Richard Lowe    Dwarf_P_Die first_die, Dwarf_Error * error)
22649d3bc9Richard Lowe{
22749d3bc9Richard Lowe    Dwarf_P_Attribute new_attr;
22849d3bc9Richard Lowe    int uwordb_size = dbg->de_offset_size;
22949d3bc9Richard Lowe
23049d3bc9Richard Lowe    /* Add AT_stmt_list attribute */
23149d3bc9Richard Lowe    new_attr = (Dwarf_P_Attribute)
23207dc194Richard Lowe        _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s));
23349d3bc9Richard Lowe    if (new_attr == NULL) {
23549d3bc9Richard Lowe    }
23649d3bc9Richard Lowe
23749d3bc9Richard Lowe    new_attr->ar_attribute = DW_AT_stmt_list;
23849d3bc9Richard Lowe    new_attr->ar_attribute_form = dbg->de_ar_data_attribute_form;
23949d3bc9Richard Lowe    new_attr->ar_rel_type = dbg->de_offset_reloc;
24049d3bc9Richard Lowe
24149d3bc9Richard Lowe    new_attr->ar_nbytes = uwordb_size;
24249d3bc9Richard Lowe    new_attr->ar_next = NULL;
24349d3bc9Richard Lowe    new_attr->ar_reloc_len = uwordb_size;
24449d3bc9Richard Lowe    new_attr->ar_data = (char *)
24507dc194Richard Lowe        _dwarf_p_get_alloc(dbg, uwordb_size);
24649d3bc9Richard Lowe    if (new_attr->ar_data == NULL) {
24849d3bc9Richard Lowe    }
24949d3bc9Richard Lowe    {
25007dc194Richard Lowe       Dwarf_Unsigned du = 0;
25149d3bc9Richard Lowe
25207dc194Richard Lowe       WRITE_UNALIGNED(dbg, (void *) new_attr->ar_data,
25307dc194Richard Lowe           (const void *) &du, sizeof(du), uwordb_size);
25449d3bc9Richard Lowe    }
25549d3bc9Richard Lowe
25649d3bc9Richard Lowe    _dwarf_pro_add_at_to_die(first_die, new_attr);
25749d3bc9Richard Lowe    return 0;
25849d3bc9Richard Lowe}
25949d3bc9Richard Lowe
26049d3bc9Richard Lowe/*-----------------------------------------------------------------------------
26107dc194Richard Lowe    Add AT_name attribute to die
26249d3bc9Richard Lowe------------------------------------------------------------------------------*/
26349d3bc9Richard LoweDwarf_P_Attribute
26449d3bc9Richard Lowedwarf_add_AT_name(Dwarf_P_Die die, char *name, Dwarf_Error * error)
26549d3bc9Richard Lowe{
26649d3bc9Richard Lowe    Dwarf_P_Attribute new_attr;
26749d3bc9Richard Lowe
26849d3bc9Richard Lowe    if (die == NULL) {
26907dc194Richard Lowe        DWARF_P_DBG_ERROR(NULL, DW_DLE_DIE_NULL,
27007dc194Richard Lowe           (Dwarf_P_Attribute) DW_DLV_BADADDR);
27149d3bc9Richard Lowe    }
27249d3bc9Richard Lowe    new_attr = (Dwarf_P_Attribute)
27307dc194Richard Lowe        _dwarf_p_get_alloc(die->di_dbg,sizeof(struct Dwarf_P_Attribute_s));
27449d3bc9Richard Lowe    if (new_attr == NULL) {
27507dc194Richard Lowe        DWARF_P_DBG_ERROR(NULL, DW_DLE_ATTR_ALLOC,
27607dc194Richard Lowe            (Dwarf_P_Attribute) DW_DLV_BADADDR);
27749d3bc9Richard Lowe    }
27849d3bc9Richard Lowe
27949d3bc9Richard Lowe    /* fill in the information */
28049d3bc9Richard Lowe    new_attr->ar_attribute = DW_AT_name;
28149d3bc9Richard Lowe    /* assume that form is string, no debug_str yet */
28249d3bc9Richard Lowe    new_attr->ar_attribute_form = DW_FORM_string;
28349d3bc9Richard Lowe    new_attr->ar_nbytes = strlen(name) + 1;
28449d3bc9Richard Lowe    new_attr->ar_next = NULL;
28549d3bc9Richard Lowe    new_attr->ar_reloc_len = 0;
28649d3bc9Richard Lowe    new_attr->ar_data = (char *)
28707dc194Richard Lowe        _dwarf_p_get_alloc(die->di_dbg, strlen(name)+1);
28849d3bc9Richard Lowe    if (new_attr->ar_data == NULL) {
28907dc194Richard Lowe        DWARF_P_DBG_ERROR(NULL, DW_DLE_STRING_ALLOC,
29007dc194Richard Lowe            (Dwarf_P_Attribute) DW_DLV_BADADDR);
29149d3bc9Richard Lowe    }
29249d3bc9Richard Lowe    strcpy(new_attr->ar_data, name);
29349d3bc9Richard Lowe
29449d3bc9Richard Lowe    new_attr->ar_rel_type = R_MIPS_NONE;
29549d3bc9Richard Lowe
29649d3bc9Richard Lowe    /* add attribute to the die */
29749d3bc9Richard Lowe    _dwarf_pro_add_at_to_die(die, new_attr);
29849d3bc9Richard Lowe    return new_attr;
29949d3bc9Richard Lowe}
30049d3bc9Richard Lowe
30149d3bc9Richard Lowe
30249d3bc9Richard Lowe/*-----------------------------------------------------------------------------
30307dc194Richard Lowe    Add AT_comp_dir attribute to die
30449d3bc9Richard Lowe------------------------------------------------------------------------------*/
30549d3bc9Richard LoweDwarf_P_Attribute
30649d3bc9Richard Lowedwarf_add_AT_comp_dir(Dwarf_P_Die ownerdie,
30707dc194Richard Lowe    char *current_working_directory,
30807dc194Richard Lowe    Dwarf_Error * error)
30949d3bc9Richard Lowe{
31049d3bc9Richard Lowe    Dwarf_P_Attribute new_attr;
31149d3bc9Richard Lowe
31249d3bc9Richard Lowe    if (ownerdie == NULL) {
31307dc194Richard Lowe        DWARF_P_DBG_ERROR(NULL, DW_DLE_DIE_NULL,
31407dc194Richard Lowe            (Dwarf_P_Attribute) DW_DLV_BADADDR);
31549d3bc9Richard Lowe    }
31649d3bc9Richard Lowe    new_attr = (Dwarf_P_Attribute)
31707dc194Richard Lowe        _dwarf_p_get_alloc(ownerdie->di_dbg,
31807dc194Richard Lowe        sizeof(struct Dwarf_P_Attribute_s));
31949d3bc9Richard Lowe    if (new_attr == NULL) {
32007dc194Richard Lowe        DWARF_P_DBG_ERROR(NULL, DW_DLE_ATTR_ALLOC,
32107dc194Richard Lowe            (Dwarf_P_Attribute) DW_DLV_BADADDR);
32249d3bc9Richard Lowe    }
32349d3bc9Richard Lowe
32449d3bc9Richard Lowe    /* fill in the information */
32549d3bc9Richard Lowe    new_attr->ar_attribute = DW_AT_comp_dir;
32649d3bc9Richard Lowe    /* assume that form is string, no debug_str yet */
32749d3bc9Richard Lowe    new_attr->ar_attribute_form = DW_FORM_string;
32849d3bc9Richard Lowe    new_attr->ar_nbytes = strlen(current_working_directory) + 1;
32949d3bc9Richard Lowe    new_attr->ar_next = NULL;
33049d3bc9Richard Lowe    new_attr->ar_reloc_len = 0;
33149d3bc9Richard Lowe    new_attr->ar_data = (char *)
33207dc194Richard Lowe        _dwarf_p_get_alloc(ownerdie->di_dbg,
33307dc194Richard Lowe        strlen(current_working_directory)+1);
33449d3bc9Richard Lowe    if (new_attr->ar_data == NULL) {
33507dc194Richard Lowe        DWARF_P_DBG_ERROR(NULL, DW_DLE_STRING_ALLOC,
33607dc194Richard Lowe            (Dwarf_P_Attribute) DW_DLV_BADADDR);
33749d3bc9Richard Lowe    }
33849d3bc9Richard Lowe    strcpy(new_attr->ar_data, current_working_directory);
33949d3bc9Richard Lowe
34049d3bc9Richard Lowe    new_attr->ar_rel_type = R_MIPS_NONE;
34149d3bc9Richard Lowe
34249d3bc9Richard Lowe    /* add attribute to the die */
34349d3bc9Richard Lowe    _dwarf_pro_add_at_to_die(ownerdie, new_attr);
34449d3bc9Richard Lowe    return new_attr;
34549d3bc9Richard Lowe}
34649d3bc9Richard Lowe
34749d3bc9Richard Loweint
34849d3bc9Richard Lowe_dwarf_pro_add_AT_fde(Dwarf_P_Debug dbg,
34907dc194Richard Lowe    Dwarf_P_Die die,
35007dc194Richard Lowe    Dwarf_Unsigned offset, Dwarf_Error * error)
35149d3bc9Richard Lowe{
35249d3bc9Richard Lowe    Dwarf_P_Attribute new_attr;
35349d3bc9Richard Lowe    int uwordb_size = dbg->de_offset_size;
35449d3bc9Richard Lowe
35549d3bc9Richard Lowe    if (die == NULL) {
35607dc194Richard Lowe        DWARF_P_DBG_ERROR(NULL, DW_DLE_DIE_NULL, -1);
35749d3bc9Richard Lowe    }
35849d3bc9Richard Lowe    new_attr = (Dwarf_P_Attribute)
35907dc194Richard Lowe        _dwarf_p_get_alloc(dbg,sizeof(struct Dwarf_P_Attribute_s));
36049d3bc9Richard Lowe    if (new_attr == NULL) {
36107dc194Richard Lowe        DWARF_P_DBG_ERROR(NULL, DW_DLE_ATTR_ALLOC, -1);
36249d3bc9Richard Lowe    }
36349d3bc9Richard Lowe
36449d3bc9Richard Lowe    /* fill in the information */
36549d3bc9Richard Lowe    new_attr->ar_attribute = DW_AT_MIPS_fde;
36649d3bc9Richard Lowe    new_attr->ar_attribute_form = dbg->de_ar_data_attribute_form;;
36749d3bc9Richard Lowe    new_attr->ar_rel_type = dbg->de_offset_reloc;
36849d3bc9Richard Lowe    new_attr->ar_nbytes = uwordb_size;
36949d3bc9Richard Lowe    new_attr->ar_next = NULL;
37049d3bc9Richard Lowe    new_attr->ar_reloc_len = uwordb_size;
37149d3bc9Richard Lowe    new_attr->ar_data = (char *)
37207dc194Richard Lowe        _dwarf_p_get_alloc(dbg, uwordb_size);
37349d3bc9Richard Lowe    if (new_attr->ar_data == NULL) {
37549d3bc9Richard Lowe    }
37649d3bc9Richard Lowe    {
37707dc194Richard Lowe        Dwarf_Unsigned du = offset;
37849d3bc9Richard Lowe
37907dc194Richard Lowe        WRITE_UNALIGNED(dbg, (void *) new_attr->ar_data,
38007dc194Richard Lowe            (const void *) &du, sizeof(du), uwordb_size);
38149d3bc9Richard Lowe    }
38249d3bc9Richard Lowe
38349d3bc9Richard Lowe    _dwarf_pro_add_at_to_die(die, new_attr);
38449d3bc9Richard Lowe
38549d3bc9Richard Lowe    return 0;
38649d3bc9Richard Lowe}
38749d3bc9Richard Lowe
38849d3bc9Richard Loweint
38949d3bc9Richard Lowe_dwarf_pro_add_AT_macro_info(Dwarf_P_Debug dbg,
39007dc194Richard Lowe    Dwarf_P_Die die,
39107dc194Richard Lowe    Dwarf_Unsigned offset, Dwarf_Error * error)
39249d3bc9Richard Lowe{
39349d3bc9Richard Lowe    Dwarf_P_Attribute new_attr;
39449d3bc9Richard Lowe    int uwordb_size = dbg->de_offset_size;
39549d3bc9Richard Lowe
39649d3bc9Richard Lowe    if (die == NULL) {
39707dc194Richard Lowe        DWARF_P_DBG_ERROR(NULL, DW_DLE_DIE_NULL, -1);
39849d3bc9Richard Lowe    }
39949d3bc9Richard Lowe    new_attr = (Dwarf_P_Attribute)
40007dc194Richard Lowe        _dwarf_p_get_alloc(dbg,sizeof(struct Dwarf_P_Attribute_s));
40149d3bc9Richard Lowe    if (new_attr == NULL) {
40207dc194Richard Lowe        DWARF_P_DBG_ERROR(NULL, DW_DLE_ATTR_ALLOC, -1);
40349d3bc9Richard Lowe    }
40449d3bc9Richard Lowe
40549d3bc9Richard Lowe    /* fill in the information */
40649d3bc9Richard Lowe    new_attr->ar_attribute = DW_AT_macro_info;
40749d3bc9Richard Lowe    new_attr->ar_attribute_form = dbg->de_ar_data_attribute_form;
40849d3bc9Richard Lowe    new_attr->ar_rel_type = dbg->de_offset_reloc;
40949d3bc9Richard Lowe
41049d3bc9Richard Lowe    new_attr->ar_nbytes = uwordb_size;
41149d3bc9Richard Lowe    new_attr->ar_next = NULL;
41249d3bc9Richard Lowe    new_attr->ar_reloc_len = uwordb_size;
41349d3bc9Richard Lowe    new_attr->ar_data = (char *)
41407dc194Richard Lowe        _dwarf_p_get_alloc(dbg, uwordb_size);
41549d3bc9Richard Lowe    if (new_attr->ar_data == NULL) {
41749d3bc9Richard Lowe    }
41849d3bc9Richard Lowe    {
41907dc194Richard Lowe        Dwarf_Unsigned du = offset;
42049d3bc9Richard Lowe
42107dc194Richard Lowe        WRITE_UNALIGNED(dbg, (void *) new_attr->ar_data,
42207dc194Richard Lowe            (const void *) &du, sizeof(du), uwordb_size);
42349d3bc9Richard Lowe    }
42449d3bc9Richard Lowe
42549d3bc9Richard Lowe    _dwarf_pro_add_at_to_die(die, new_attr);
42649d3bc9Richard Lowe
42749d3bc9Richard Lowe    return 0;
42849d3bc9Richard Lowe}
42949d3bc9Richard Lowe
43049d3bc9Richard Lowe
43149d3bc9Richard Lowevoid
43249d3bc9Richard Lowe_dwarf_pro_add_at_to_die(Dwarf_P_Die die, Dwarf_P_Attribute attr)
43349d3bc9Richard Lowe{
43449d3bc9Richard Lowe    if (die->di_last_attr) {
43507dc194Richard Lowe        die->di_last_attr->ar_next = attr;
43607dc194Richard Lowe        die->di_last_attr = attr;
43707dc194Richard Lowe        die->di_n_attr++;
43849d3bc9Richard Lowe    } else {
43907dc194Richard Lowe        die->di_n_attr = 1;
44007dc194Richard Lowe        die->di_attrs = die->di_last_attr = attr;
44149d3bc9Richard Lowe    }
44249d3bc9Richard Lowe}