Blame dwarfdump/print_types.c

Packit cdaae3
/*
Packit cdaae3
  Copyright (C) 2000-2006 Silicon Graphics, Inc.  All Rights Reserved.
Packit cdaae3
  Portions Copyright 2007-2010 Sun Microsystems, Inc. All rights reserved.
Packit cdaae3
  Portions Copyright 2009-2010 SN Systems Ltd. All rights reserved.
Packit cdaae3
  Portions Copyright 2008-2011 David Anderson. All rights reserved.
Packit cdaae3
Packit cdaae3
  This program is free software; you can redistribute it and/or modify it
Packit cdaae3
  under the terms of version 2 of the GNU General Public License as
Packit cdaae3
  published by the Free Software Foundation.
Packit cdaae3
Packit cdaae3
  This program is distributed in the hope that it would be useful, but
Packit cdaae3
  WITHOUT ANY WARRANTY; without even the implied warranty of
Packit cdaae3
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Packit cdaae3
Packit cdaae3
  Further, this software is distributed without any warranty that it is
Packit cdaae3
  free of the rightful claim of any third person regarding infringement
Packit cdaae3
  or the like.  Any license provided herein, whether implied or
Packit cdaae3
  otherwise, applies only to this software file.  Patent licenses, if
Packit cdaae3
  any, provided herein do not apply to combinations of this program with
Packit cdaae3
  other software, or any other product whatsoever.
Packit cdaae3
Packit cdaae3
  You should have received a copy of the GNU General Public License along
Packit cdaae3
  with this program; if not, write the Free Software Foundation, Inc., 51
Packit cdaae3
  Franklin Street - Fifth Floor, Boston MA 02110-1301, USA.
Packit cdaae3
Packit cdaae3
*/
Packit cdaae3
Packit cdaae3
#include "globals.h"
Packit cdaae3
#include "naming.h"
Packit cdaae3
#include "dwconf.h"
Packit cdaae3
#include "esb.h"
Packit cdaae3
Packit cdaae3
#include "print_sections.h"
Packit cdaae3
#include "print_frames.h"
Packit cdaae3
Packit cdaae3
/* Get all the data in .debug_typenames or debug_pubtypes. */
Packit cdaae3
extern void
Packit cdaae3
print_types(Dwarf_Debug dbg, enum type_type_e type_type)
Packit cdaae3
{
Packit cdaae3
    Dwarf_Type *typebuf = NULL;
Packit cdaae3
    Dwarf_Signed count = 0;
Packit cdaae3
    Dwarf_Signed i = 0;
Packit cdaae3
    char *name = NULL;
Packit cdaae3
    int gtres = 0;
Packit cdaae3
    Dwarf_Error err = 0;
Packit cdaae3
Packit cdaae3
    char *section_name = NULL;
Packit cdaae3
    char *offset_err_name = NULL;
Packit cdaae3
    char *section_open_name = NULL;
Packit cdaae3
    char *print_name_prefix = NULL;
Packit cdaae3
    int (*get_types) (Dwarf_Debug, Dwarf_Type **, Dwarf_Signed *,
Packit cdaae3
        Dwarf_Error *) = 0;
Packit cdaae3
    int (*get_offset) (Dwarf_Type, char **, Dwarf_Off *, Dwarf_Off *,
Packit cdaae3
        Dwarf_Error *) = NULL;
Packit cdaae3
    int (*get_cu_offset) (Dwarf_Type, Dwarf_Off *, Dwarf_Error *) =
Packit cdaae3
        NULL;
Packit cdaae3
    void (*dealloctype) (Dwarf_Debug, Dwarf_Type *, Dwarf_Signed) =
Packit cdaae3
        NULL;
Packit cdaae3
Packit cdaae3
    /* Do nothing if in check mode */
Packit cdaae3
    if (!glflags.gf_do_print_dwarf) {
Packit cdaae3
        return;
Packit cdaae3
    }
Packit cdaae3
Packit cdaae3
    if (type_type == DWARF_PUBTYPES) {
Packit cdaae3
        /*  No need to get the real section name, this
Packit cdaae3
            section not used in modern compilers. */
Packit cdaae3
        section_name = ".debug_pubtypes";
Packit cdaae3
        offset_err_name = "dwarf_pubtype_name_offsets";
Packit cdaae3
        section_open_name = "dwarf_get_pubtypes";
Packit cdaae3
        print_name_prefix = "pubtype";
Packit cdaae3
        get_types = dwarf_get_pubtypes;
Packit cdaae3
        get_offset = dwarf_pubtype_name_offsets;
Packit cdaae3
        get_cu_offset = dwarf_pubtype_cu_offset;
Packit cdaae3
        dealloctype = dwarf_pubtypes_dealloc;
Packit cdaae3
    } else {
Packit cdaae3
        /* SGI_TYPENAME */
Packit cdaae3
        /*  No need to get the real section name, this
Packit cdaae3
            section not used in modern compilers. */
Packit cdaae3
        section_name = ".debug_typenames";
Packit cdaae3
        offset_err_name = "dwarf_type_name_offsets";
Packit cdaae3
        section_open_name = "dwarf_get_types";
Packit cdaae3
        print_name_prefix = "type";
Packit cdaae3
        get_types = dwarf_get_types;
Packit cdaae3
        get_offset = dwarf_type_name_offsets;
Packit cdaae3
        get_cu_offset = dwarf_type_cu_offset;
Packit cdaae3
        dealloctype = dwarf_types_dealloc;
Packit cdaae3
    }
Packit cdaae3
Packit cdaae3
Packit cdaae3
    gtres = get_types(dbg, &typebuf, &count, &err;;
Packit cdaae3
    if (gtres == DW_DLV_ERROR) {
Packit cdaae3
        print_error(dbg, section_open_name, gtres, err);
Packit cdaae3
    } else if (gtres == DW_DLV_NO_ENTRY) {
Packit cdaae3
        /* no types */
Packit cdaae3
    } else {
Packit cdaae3
        Dwarf_Unsigned maxoff = get_info_max_offset(dbg);
Packit cdaae3
Packit cdaae3
        /*  Before July 2005, the section name was printed
Packit cdaae3
            unconditionally, now only prints if non-empty section really
Packit cdaae3
            exists. */
Packit cdaae3
        printf("\n%s\n", section_name);
Packit cdaae3
Packit cdaae3
        for (i = 0; i < count; i++) {
Packit cdaae3
            int tnres = 0;
Packit cdaae3
            int cures3 = 0;
Packit cdaae3
            Dwarf_Off die_off = 0;
Packit cdaae3
            Dwarf_Off cu_off = 0;
Packit cdaae3
            Dwarf_Off global_cu_off = 0;
Packit cdaae3
Packit cdaae3
            tnres =
Packit cdaae3
                get_offset(typebuf[i], &name, &die_off, &cu_off, &err;;
Packit cdaae3
            deal_with_name_offset_err(dbg, offset_err_name, name,
Packit cdaae3
                die_off, tnres, err);
Packit cdaae3
            cures3 = get_cu_offset(typebuf[i], &global_cu_off, &err;;
Packit cdaae3
            if (cures3 != DW_DLV_OK) {
Packit cdaae3
                print_error(dbg, "dwarf_var_cu_offset", cures3, err);
Packit cdaae3
            }
Packit cdaae3
            print_pubname_style_entry(dbg,
Packit cdaae3
                print_name_prefix,
Packit cdaae3
                name, die_off, cu_off,
Packit cdaae3
                global_cu_off, maxoff);
Packit cdaae3
Packit cdaae3
            /* print associated die too? */
Packit cdaae3
        }
Packit cdaae3
        dealloctype(dbg, typebuf, count);
Packit cdaae3
    }
Packit cdaae3
}   /* print_types() */