static int
print_types_culist_array(Dwarf_Debug dbg,
                         Dwarf_Gdbindex  gdbindex,
                         Dwarf_Error * err)
{
    Dwarf_Unsigned list_len = 0;
    Dwarf_Unsigned i;
    int res = dwarf_gdbindex_types_culist_array(gdbindex,
              &list_len,err);
    if (res != DW_DLV_OK) {
        print_error_and_continue(dbg,
                                 "dwarf_gdbindex_types_culist_array failed",res,*err);
        return res;
    }
    printf("  TU list. array length: %" DW_PR_DUu
           " format: [entry#] cuoffset culength signature\n",
           list_len);

    for( i  = 0; i < list_len; i++) {
        Dwarf_Unsigned cuoffset = 0;
        Dwarf_Unsigned culength = 0;
        Dwarf_Unsigned signature,
                       res = dwarf_gdbindex_types_culist_entry(gdbindex,i,
                               &cuoffset,&culength,
                               &signature,
                               err);
        if (res != DW_DLV_OK) {
            print_error_and_continue(dbg,
                                     "dwarf_gdbindex_culist_entry failed",res,*err);
            return res;
        }
        printf("    [%4" DW_PR_DUu "] 0x%"
               DW_PR_XZEROS DW_PR_DUx
               " 0x%" DW_PR_XZEROS DW_PR_DUx
               " 0x%" DW_PR_XZEROS DW_PR_DUx "\n",
               i,
               cuoffset,
               culength,
               signature);
    }
    printf("\n");
    return DW_DLV_OK;
}
static int
print_addressarea(Dwarf_Debug dbg,
                  Dwarf_Gdbindex  gdbindex,
                  Dwarf_Error * err)
{
    Dwarf_Unsigned list_len = 0;
    Dwarf_Unsigned i;
    int res = dwarf_gdbindex_addressarea(gdbindex,
                                         &list_len,err);
    if (res != DW_DLV_OK) {
        print_error_and_continue(dbg,
                                 "dwarf_gdbindex_addressarea failed",res,*err);
        return res;
    }
    printf("  Address table array length: %" DW_PR_DUu
           " format: [entry#] lowpc highpc cu-index\n",
           list_len);

    for( i  = 0; i < list_len; i++) {
        Dwarf_Unsigned lowpc = 0;
        Dwarf_Unsigned highpc = 0;
        Dwarf_Unsigned cu_index,
                       res = dwarf_gdbindex_addressarea_entry(gdbindex,i,
                               &lowpc,&highpc,
                               &cu_index,
                               err);
        if (res != DW_DLV_OK) {
            print_error_and_continue(dbg,
                                     "dwarf_gdbindex_addressarea_entry failed",res,*err);
            return res;
        }
        printf("    [%4" DW_PR_DUu "] 0x%"
               DW_PR_XZEROS DW_PR_DUx
               " 0x%" DW_PR_XZEROS DW_PR_DUx
               " %4" DW_PR_DUu "\n",
               i,
               lowpc,
               highpc,
               cu_index);
    }
    printf("\n");
    return DW_DLV_OK;
}
static int
print_symboltable(Dwarf_Debug dbg,
                  Dwarf_Gdbindex  gdbindex,
                  Dwarf_Unsigned culist_len,
                  Dwarf_Error * err)
{
    Dwarf_Unsigned list_len = 0;
    Dwarf_Unsigned i;
    int res = dwarf_gdbindex_symboltable_array(gdbindex,
              &list_len,err);
    if (res != DW_DLV_OK) {
        print_error_and_continue(dbg,
                                 "dwarf_gdbindex_symboltable failed",res,*err);
        return res;
    }
    printf("\n  Symbol table: length %" DW_PR_DUu
           " format: [entry#] symindex cuindex [type] \"name\" or \n",
           list_len);
    printf("                          "
           " format: [entry#]  \"name\" , list of  cuindex [type]\n");

    for( i  = 0; i < list_len; i++) {
        Dwarf_Unsigned symnameoffset = 0;
        Dwarf_Unsigned cuvecoffset = 0;
        res = dwarf_gdbindex_symboltable_entry(gdbindex,i,
                                               &symnameoffset,&cuvecoffset,
                                               err);
        if (res != DW_DLV_OK) {
            print_error_and_continue(dbg,
                                     "dwarf_gdbindex_symboltable_entry failed",res,*err);
            return res;
        }
        res = print_symtab_entry(dbg,gdbindex,i,symnameoffset,cuvecoffset,
                                 culist_len,err);
        if (res != DW_DLV_OK) {
            return res;
        }
    }
    printf("\n");
    return DW_DLV_OK;
}
static int
print_symtab_entry(Dwarf_Debug dbg,
                   Dwarf_Gdbindex gdbindex,
                   Dwarf_Unsigned index,
                   Dwarf_Unsigned symnameoffset,
                   Dwarf_Unsigned cuvecoffset,
                   Dwarf_Unsigned culist_len,
                   Dwarf_Error *err)
{
    int res = 0;
    const char *name = 0;
    Dwarf_Unsigned cuvec_len = 0;
    Dwarf_Unsigned ii = 0;

    if (symnameoffset == 0 && cuvecoffset == 0) {
        if (verbose > 1) {
            printf("        [%4" DW_PR_DUu "] \"empty-hash-entry\"\n", index);
        }
        return DW_DLV_OK;
    }
    res = dwarf_gdbindex_string_by_offset(gdbindex,
                                          symnameoffset,&name,err);
    if(res != DW_DLV_OK) {
        print_error_and_continue(dbg,
                                 "dwarf_gdbindex_string_by_offset failed",res,*err);
        return res;
    }
    res = dwarf_gdbindex_cuvector_length(gdbindex,
                                         cuvecoffset,&cuvec_len,err);
    if( res != DW_DLV_OK) {
        print_error_and_continue(dbg,
                                 "dwarf_gdbindex_cuvector_length failed",res,*err);
        return res;
    }
    if (verbose > 1) {
        printf("     [%4" DW_PR_DUu "]"
               "stroff 0x%"    DW_PR_XZEROS DW_PR_DUx
               " cuvecoff 0x%"    DW_PR_XZEROS DW_PR_DUx
               " cuveclen 0x%"    DW_PR_XZEROS DW_PR_DUx "\n",
               index,symnameoffset,cuvecoffset,cuvec_len);
    }
    for(ii = 0; ii < cuvec_len; ++ii ) {
        Dwarf_Unsigned attributes = 0;
        Dwarf_Unsigned cu_index = 0;
        Dwarf_Unsigned reserved1 = 0;
        Dwarf_Unsigned symbol_kind = 0;
        Dwarf_Unsigned is_static = 0;

        res = dwarf_gdbindex_cuvector_inner_attributes(
                  gdbindex,cuvecoffset,ii,
                  &attributes,err);
        if( res != DW_DLV_OK) {
            print_error_and_continue(dbg,
                                     "dwarf_gdbindex_cuvector_inner_attributes failed",res,*err);
            return res;
        }
        res = dwarf_gdbindex_cuvector_instance_expand_value(gdbindex,
                attributes, &cu_index,&reserved1,&symbol_kind, &is_static,
                err);
        if( res != DW_DLV_OK) {
            print_error_and_continue(dbg,
                                     "dwarf_gdbindex_cuvector_instance_expand_value failed",res,*err);
            return res;
        }
        /*  if cu_index is > the cu-count, then it  refers
            to a tu_index of  'cu_index - cu-count' */
        if (cuvec_len == 1) {
            printf("  [%4" DW_PR_DUu "]"
                   "%s"
                   " [%s %s] \"%s\"\n",
                   index,
                   cu_index_string(cu_index,culist_len),
                   is_static?
                   "static ":
                   "global ",
                   get_kind(symbol_kind),
                   name);
        } else if (ii == 0) {
            printf("  [%4" DW_PR_DUu "] \"%s\"\n" ,
                   index,
                   name);
            printf("         %s [%s %s]\n",
                   cu_index_string(cu_index,culist_len),
                   is_static?
                   "static ":
                   "global ",
                   get_kind(symbol_kind));
        } else {
            printf("         %s [%s %s]\n",
                   cu_index_string(cu_index,culist_len),
                   is_static?
                   "static ":
                   "global ",
                   get_kind(symbol_kind));
        }
        if (verbose > 1) {
            printf("        [%4" DW_PR_DUu "]"
                   "attr 0x%"    DW_PR_XZEROS DW_PR_DUx
                   " cuindx 0x%"    DW_PR_XZEROS DW_PR_DUx
                   " kind 0x%"    DW_PR_XZEROS DW_PR_DUx
                   " static 0x%"    DW_PR_XZEROS DW_PR_DUx "\n",
                   ii,attributes,cu_index,symbol_kind,is_static);
        }

    }
    return DW_DLV_OK;
}
Beispiel #5
0
/* print data in .debug_str_offsets.
   There is no guarantee this will work because
   the DWARF5 standard is silent about
   whether arbitrary non-zero bytes, or odd
   alignments, or unused data spaces  are allowed
   in the section
*/
void
print_str_offsets_section(Dwarf_Debug dbg)
{
    int res = 0;
    Dwarf_Str_Offsets_Table sot = 0;
    Dwarf_Unsigned wasted_byte_count = 0;
    Dwarf_Unsigned table_count = 0;
    Dwarf_Error error = 0;
    Dwarf_Unsigned tabnum = 0;

    res = dwarf_open_str_offsets_table_access(dbg, &sot,&error);
    if(res == DW_DLV_NO_ENTRY) {
        /* No such table */
        return;
    }
    if(res == DW_DLV_ERROR) {
        print_error_and_continue(dbg,
            "dwarf_open_str_offsets_table_access",
            res, error);
        return;
    }
    for(;; ++tabnum) {
        Dwarf_Unsigned unit_length =0;
        Dwarf_Unsigned unit_length_offset =0;
        Dwarf_Unsigned table_start_offset =0;
        Dwarf_Half     entry_size = 0;
        Dwarf_Half     version =0;
        Dwarf_Half     padding =0;
        Dwarf_Unsigned table_value_count =0;
        Dwarf_Unsigned i = 0;
        Dwarf_Unsigned table_entry_value = 0;
        unsigned rowlim = 4;
        unsigned count_in_row = 0;

        res = dwarf_next_str_offsets_table(sot,
            &unit_length, &unit_length_offset,
            &table_start_offset,
            &entry_size,&version,&padding,
            &table_value_count,&error);
        if (res == DW_DLV_NO_ENTRY) {
            /* We have dealt with all tables */
            break;
        }
        if (res == DW_DLV_ERROR) {
            print_error_and_continue(dbg,
                "dwarf_next_str_offsets_table", res,error);
            return;
        }
        if (tabnum == 0) {
            struct esb_s truename;
            char buf[DWARF_SECNAME_BUFFER_SIZE];

            esb_constructor_fixed(&truename,buf,sizeof(buf));
            get_true_section_name(dbg,".debug_str_offsets",
                &truename,TRUE);
            printf("\n%s\n",sanitized(esb_get_string(&truename)));
            esb_destructor(&truename);
        } else {
            printf("\n");
        }
        printf(" table %" DW_PR_DUu "\n",tabnum);
        printf(" tableheader 0x%" DW_PR_XZEROS DW_PR_DUx "\n",
            unit_length_offset);
        printf(" arrayoffset 0x%" DW_PR_XZEROS DW_PR_DUx "\n",
            table_start_offset);
        printf(" unit length 0x%" DW_PR_XZEROS DW_PR_DUx "\n",
            unit_length);
        printf(" entry size  %u\n",entry_size);
        printf(" version     %u\n",version);
        if (padding) {
            printf("Error: padding is non-zero. Something is wrong.\n");
        }
        printf(" padding     0x%x\n",padding);
        printf(" arraysize   %" DW_PR_DUu "\n",table_value_count);

        /*  Lets print 4 per row. */
        count_in_row = 0;
        for (i=0; i < table_value_count; ++i) {

            res = dwarf_str_offsets_value_by_index(sot,i,
                &table_entry_value,&error);
            if (res != DW_DLV_OK) {
                print_error_and_continue(dbg,
                    "dwarf_next_str_offsets_table", res,error);
                return;
            }
            if (!count_in_row) {
                printf(" Entry [%4" DW_PR_DUu "]: ",i);
            }
            printf(" 0x%" DW_PR_XZEROS DW_PR_DUx ,
                table_entry_value);
            ++count_in_row;
            if( count_in_row < rowlim) {
                continue;
            }
            printf("\n");
            count_in_row = 0;
        }
        if (count_in_row) {
            printf("\n");
            count_in_row = 0;
        }
        res = dwarf_str_offsets_statistics(sot,&wasted_byte_count,
            &table_count,&error);
        if (res == DW_DLV_OK) {
            printf(" wasted      %" DW_PR_DUu " bytes\n",
                wasted_byte_count);
        }
    }
    if (wasted_byte_count) {
        res = dwarf_str_offsets_statistics(sot,&wasted_byte_count,
            &table_count,&error);
        if (res == DW_DLV_OK) {
            printf(" finalwasted %" DW_PR_DUu " bytes\n",
                wasted_byte_count);
        } else {
            print_error_and_continue(dbg,
                "dwarf_open_str_offsets_statistics",
                res, error);
            return;
        }
    }
    res = dwarf_close_str_offsets_table_access(sot,&error);
    if (res != DW_DLV_OK) {
        print_error_and_continue(dbg,
            "dwarf_close_str_offsets_table_access",
            res, error);
        return;
    }
    sot = 0;
}