<commit_before>//===-- DWARFTypeUnit.cpp -------------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "llvm/DebugInfo/DWARF/DWARFTypeUnit.h"
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
#include "llvm/Support/Dwarf.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"

using namespace llvm;

bool DWARFTypeUnit::extractImpl(DataExtractor debug_info,
                                uint32_t *offset_ptr) {
  if (!DWARFUnit::extractImpl(debug_info, offset_ptr))
    return false;
  TypeHash = debug_info.getU64(offset_ptr);
  TypeOffset = debug_info.getU32(offset_ptr);
  return TypeOffset < getLength();
}

void DWARFTypeUnit::dump(raw_ostream &OS, bool SummarizeTypes) {
  const DWARFDebugInfoEntryMinimal *TD =
      getDIEForOffset(TypeOffset + getOffset());
  DWARFFormValue NameVal;
  const char *Name = "";
  if (TD->getAttributeValue(this, llvm::dwarf::DW_AT_name, NameVal))
    if (auto ON = NameVal.getAsCString(this))
      Name = *ON;

  if (SummarizeTypes) {
    OS << "name = '" << Name << "'"
       << " type_signature = " << format("0x%16" PRIx64, TypeHash)
       << " length = " << format("0x%08x", getLength()) << '\n';
    return;
  }

  OS << format("0x%08x", getOffset()) << ": Type Unit:"
     << " length = " << format("0x%08x", getLength())
     << " version = " << format("0x%04x", getVersion())
     << " abbr_offset = " << format("0x%04x", getAbbreviations()->getOffset())
     << " addr_size = " << format("0x%02x", getAddressByteSize())
     << " type_signature = " << format("0x%16" PRIx64, TypeHash)
     << " type_offset = " << format("0x%04x", TypeOffset)
     << " (next unit at " << format("0x%08x", getNextUnitOffset()) << ")\n";

  if (const DWARFDebugInfoEntryMinimal *TU = getUnitDIE(false))
    TU->dump(OS, this, -1U);
  else<commit_msg>dwarfdump: Include the name in the unit description, even in non-summarized mode<commit_after>//===-- DWARFTypeUnit.cpp -------------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "llvm/DebugInfo/DWARF/DWARFTypeUnit.h"
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
#include "llvm/Support/Dwarf.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"

using namespace llvm;

bool DWARFTypeUnit::extractImpl(DataExtractor debug_info,
                                uint32_t *offset_ptr) {
  if (!DWARFUnit::extractImpl(debug_info, offset_ptr))
    return false;
  TypeHash = debug_info.getU64(offset_ptr);
  TypeOffset = debug_info.getU32(offset_ptr);
  return TypeOffset < getLength();
}

void DWARFTypeUnit::dump(raw_ostream &OS, bool SummarizeTypes) {
  const DWARFDebugInfoEntryMinimal *TD =
      getDIEForOffset(TypeOffset + getOffset());
  DWARFFormValue NameVal;
  const char *Name = "";
  if (TD->getAttributeValue(this, llvm::dwarf::DW_AT_name, NameVal))
    if (auto ON = NameVal.getAsCString(this))
      Name = *ON;

  if (SummarizeTypes) {
    OS << "name = '" << Name << "'"
       << " type_signature = " << format("0x%16" PRIx64, TypeHash)
       << " length = " << format("0x%08x", getLength()) << '\n';
    return;
  }

  OS << format("0x%08x", getOffset()) << ": Type Unit:"
     << " length = " << format("0x%08x", getLength())
     << " version = " << format("0x%04x", getVersion())
     << " abbr_offset = " << format("0x%04x", getAbbreviations()->getOffset())
     << " addr_size = " << format("0x%02x", getAddressByteSize())
     << "name = '" << Name << "'"
     << " type_signature = " << format("0x%16" PRIx64, TypeHash)
     << " type_offset = " << format("0x%04x", TypeOffset)
     << " (next unit at " << format("0x%08x", getNextUnitOffset()) << ")\n";

  if (const DWARFDebugInfoEntryMinimal *TU = getUnitDIE(false))
    TU->dump(OS, this, -1U);
  else
{'fraction_non_alphanumeric': 0.22091102194949255, 'fraction_numerical': 0.019353316025489734, 'mean_word_length': 2.8043087971274687, 'pattern_counts': {'":': 2, '<': 111, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4610091', 'n_tokens_mistral': 1438, 'n_tokens_neox': 1390, 'n_words': 272}