X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=elfcpp%2Felfcpp_file.h;h=92898c376469e29c6ba573f58f24029715d7d875;hb=087e161b3cd9a8626dc05ce1bdb8dfaf353a71b1;hp=12f09250510e1eaa54b19c2089dfa7cb736d5434;hpb=c4aa1e2d740d76a37730514749c6ff2ef9f748f1;p=deliverable%2Fbinutils-gdb.git diff --git a/elfcpp/elfcpp_file.h b/elfcpp/elfcpp_file.h index 12f0925051..92898c3764 100644 --- a/elfcpp/elfcpp_file.h +++ b/elfcpp/elfcpp_file.h @@ -1,6 +1,6 @@ // elfcpp_file.h -- file access for elfcpp -*- C++ -*- -// Copyright 2006, 2007, Free Software Foundation, Inc. +// Copyright (C) 2006-2020 Free Software Foundation, Inc. // Written by Ian Lance Taylor . // This file is part of elfcpp. @@ -60,6 +60,8 @@ #include #include +#include "elfcpp.h" + namespace elfcpp { @@ -142,6 +144,15 @@ class Elf_file return this->shnum_; } + unsigned int + shnum() const + { + if (this->shnum_ == 0 && this->shoff_ != 0) + this->file_->error(_("ELF file has not been initialized yet" + " (internal error)")); + return this->shnum_; + } + // Return the section index of the section name string table. unsigned int shstrndx() @@ -150,6 +161,18 @@ class Elf_file return this->shstrndx_; } + unsigned int + shstrndx() const + { + if (this->shstrndx_ == SHN_XINDEX && this->shoff_ != 0) + { + this->file_->error(_("ELF file has not been initialized yet" + " (internal error)")); + return 0; + } + return this->shstrndx_; + } + // Return the value to subtract from section indexes >= // SHN_LORESERVE. See the comment in initialize_shnum. int @@ -159,6 +182,15 @@ class Elf_file return this->large_shndx_offset_; } + int + large_shndx_offset() const + { + if (this->shstrndx_ == SHN_XINDEX && this->shoff_ != 0) + this->file_->error(_("ELF file has not been initialized yet" + " (internal error)")); + return this->large_shndx_offset_; + } + // Return the location of the header of section SHNDX. typename File::Location section_header(unsigned int shndx) @@ -169,7 +201,7 @@ class Elf_file // Return the name of section SHNDX. std::string - section_name(unsigned int shndx); + section_name(unsigned int shndx) const; // Return the location of the contents of section SHNDX. typename File::Location @@ -214,7 +246,7 @@ class Elf_file // Return the file offset of the header of section SHNDX. off_t - section_header_offset(unsigned int shndx); + section_header_offset(unsigned int shndx) const; // The file we are reading. File* file_; @@ -463,7 +495,7 @@ Elf_file::find_section_by_type(unsigned int type) template off_t -Elf_file::section_header_offset(unsigned int shndx) +Elf_file::section_header_offset(unsigned int shndx) const { if (shndx >= this->shnum()) this->file_->error(_("section_header_offset: bad shndx %u >= %u"), @@ -475,7 +507,7 @@ Elf_file::section_header_offset(unsigned int shndx) template std::string -Elf_file::section_name(unsigned int shndx) +Elf_file::section_name(unsigned int shndx) const { File* const file = this->file_; @@ -490,7 +522,7 @@ Elf_file::section_name(unsigned int shndx) // Get the file offset for the section name string table data. off_t shstr_off; - off_t shstr_size; + typename Elf_types::Elf_WXword shstr_size; { const unsigned int shstrndx = this->shstrndx_; typename File::View v(file->view(this->section_header_offset(shstrndx),