[PATCH] D43313: [DebugInfo] Support parsing DWARF expressions

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 1 15:55:13 PST 2018


Rafael Auler via Phabricator via llvm-commits
<llvm-commits at lists.llvm.org> writes:

> +template <class ELFO>
> +static const typename ELFO::Elf_Shdr *findSectionByAddress(const ELFO *Obj,
> +                                                           uint64_t Addr) {
> +  auto Sections = Obj->sections();
> +  if (Error E = Sections.takeError()) {
> +    reportError(toString(std::move(E)));
> +  }

Drop the {}.

> +template <typename ELFT>
> +void PrinterContext<ELFT>::printUnwindInformation() const {
> +  const typename ELFT::Phdr *EHFramePhdr = nullptr;
> +
> +  auto PHs = Obj->program_headers();
> +  if (Error E = PHs.takeError()) {
> +    reportError(toString(std::move(E)));
> +  }

Drop the {}.

> +  for (const auto &Phdr : *PHs) {
> +    if (Phdr.p_type == ELF::PT_GNU_EH_FRAME) {
> +      EHFramePhdr = &Phdr;
> +      if (Phdr.p_paddr != Phdr.p_vaddr) {
> +        reportError("p_addr does not match p_vaddr for GNU_EH_FRAME");
> +      }

Why is this an error?

> +      if (Phdr.p_memsz != Phdr.p_filesz) {
> +        reportError("p_memsz does not match p_filesz for GNU_EH_FRAME");
> +      }

Drop the {}

> +      break;
> +    }
> +  }
> +
> +  if (EHFramePhdr) {
> +    printEHFrameHdr(EHFramePhdr->p_offset, EHFramePhdr->p_vaddr,
> +                    EHFramePhdr->p_memsz);
> +  }

Drop the {}

> +
> +  auto Sections = Obj->sections();
> +  if (!Sections)
> +    return;

Handle the error.

> +  for (const auto &Shdr : *Sections) {
> +    auto SectionName = Obj->getSectionName(&Shdr);
> +    if (SectionName && SectionName.get() == ".eh_frame")

Handle the error.

> +template <typename ELFT>
> +void PrinterContext<ELFT>::printEHFrameHdr(uint64_t EHFrameHdrOffset,
> +                                           uint64_t EHFrameHdrAddress,
> +                                           uint64_t EHFrameHdrSize) const {
> +  ListScope L(W, "EH_FRAME Header");
> +  W.startLine() << format("Address: 0x%" PRIx64 "\n", EHFrameHdrAddress);
> +  W.startLine() << format("Offset: 0x%" PRIx64 "\n", EHFrameHdrOffset);
> +  W.startLine() << format("Size: 0x%" PRIx64 "\n", EHFrameHdrSize);
> +
> +  const auto *EHFrameHdrShdr = findSectionByAddress(Obj, EHFrameHdrAddress);
> +  if (EHFrameHdrShdr) {
> +    auto SectionName = Obj->getSectionName(EHFrameHdrShdr);

Handle the error.

> +  auto Result = Obj->getSectionContents(EHFrameShdr);
> +  if (!Result)
> +    reportError("cannot get contents of .eh_frame");

Use takeError so that we don't assert when there is an error.

Cheers,
Rafael


More information about the llvm-commits mailing list