diff --git a/llvm/tools/llvm-dwarfdump/SectionSizes.cpp b/llvm/tools/llvm-dwarfdump/SectionSizes.cpp --- a/llvm/tools/llvm-dwarfdump/SectionSizes.cpp +++ b/llvm/tools/llvm-dwarfdump/SectionSizes.cpp @@ -6,12 +6,13 @@ // //===----------------------------------------------------------------------===// -#include "SectionSizes.h" +#include "llvm-dwarfdump.h" #define DEBUG_TYPE "dwarfdump" using namespace llvm; -using namespace object; +using namespace llvm::dwarfdump; +using namespace llvm::object; static size_t getNameColumnWidth(const SectionSizes &Sizes, const StringRef SectionNameTitle) { @@ -77,8 +78,9 @@ OS << "----------------------------------------------------" << '\n'; } -void llvm::calculateSectionSizes(const ObjectFile &Obj, SectionSizes &Sizes, - const Twine &Filename) { +void dwarfdump::calculateSectionSizes(const ObjectFile &Obj, + SectionSizes &Sizes, + const Twine &Filename) { // Get total size. Sizes.TotalObjectSize = Obj.getData().size(); @@ -101,8 +103,10 @@ } } -bool collectObjectSectionSizes(ObjectFile &Obj, DWARFContext & /*DICtx*/, - const Twine &Filename, raw_ostream &OS) { +bool dwarfdump::collectObjectSectionSizes(ObjectFile &Obj, + DWARFContext & /*DICtx*/, + const Twine &Filename, + raw_ostream &OS) { SectionSizes Sizes; // Get the section sizes. diff --git a/llvm/tools/llvm-dwarfdump/Statistics.cpp b/llvm/tools/llvm-dwarfdump/Statistics.cpp --- a/llvm/tools/llvm-dwarfdump/Statistics.cpp +++ b/llvm/tools/llvm-dwarfdump/Statistics.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm-dwarfdump.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringSet.h" @@ -15,11 +16,10 @@ #include "llvm/Object/ObjectFile.h" #include "llvm/Support/JSON.h" -#include "SectionSizes.h" - #define DEBUG_TYPE "dwarfdump" using namespace llvm; -using namespace object; +using namespace llvm::dwarfdump; +using namespace llvm::object; /// This represents the number of categories of debug location coverage being /// calculated. The first category is the number of variables with 0% location @@ -27,6 +27,7 @@ /// location coverage. constexpr int NumOfCoverageCategories = 12; +namespace { /// Holds statistics for one function (or other entity that has a PC range and /// contains variables, such as a compile unit). struct PerFunctionStats { @@ -141,6 +142,7 @@ /// Total number of local variables processed. unsigned NumVar = 0; }; +} // namespace /// Collect debug location statistics for one DIE. static void collectLocStats(uint64_t BytesCovered, uint64_t BytesInScope, @@ -510,8 +512,9 @@ /// of particular optimizations. The raw numbers themselves are not particularly /// useful, only the delta between compiling the same program with different /// compilers is. -bool collectStatsForObjectFile(ObjectFile &Obj, DWARFContext &DICtx, - const Twine &Filename, raw_ostream &OS) { +bool dwarfdump::collectStatsForObjectFile(ObjectFile &Obj, DWARFContext &DICtx, + const Twine &Filename, + raw_ostream &OS) { StringRef FormatName = Obj.getFileFormatName(); GlobalStats GlobalStats; LocationStats LocStats; diff --git a/llvm/tools/llvm-dwarfdump/SectionSizes.h b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.h rename from llvm/tools/llvm-dwarfdump/SectionSizes.h rename to llvm/tools/llvm-dwarfdump/llvm-dwarfdump.h --- a/llvm/tools/llvm-dwarfdump/SectionSizes.h +++ b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.h @@ -1,28 +1,28 @@ -//===- SectionSizes.h - Debug section sizes ---------------------*- C++ -*-===// +//===-- llvm-dwarfdump - Debug info dumping utility -------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // -//===-----------------------------------------------------------------------===/ +//===----------------------------------------------------------------------===// -#ifndef LLVM_TOOLS_SECTION_SIZES_H -#define LLVM_TOOLS_SECTION_SIZES_H +#ifndef LLVM_TOOLS_LLVM_DWARFDUMP_LLVM_DWARFDUMP_H +#define LLVM_TOOLS_LLVM_DWARFDUMP_LLVM_DWARFDUMP_H -#include "llvm/DebugInfo/DIContext.h" +#include "llvm/ADT/Twine.h" #include "llvm/DebugInfo/DWARF/DWARFContext.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Support/WithColor.h" +#include "llvm/Support/raw_ostream.h" namespace llvm { - -using SectionSizeMap = StringMap; +namespace dwarfdump { /// Holds cumulative section sizes for an object file. struct SectionSizes { /// Map of .debug section names and their sizes across all such-named /// sections. - SectionSizeMap DebugSectionSizes; + StringMap DebugSectionSizes; /// Total number of bytes of all sections. uint64_t TotalObjectSize = 0; /// Total number of bytes of all debug sections. @@ -33,6 +33,12 @@ void calculateSectionSizes(const object::ObjectFile &Obj, SectionSizes &Sizes, const Twine &Filename); -} // end namespace llvm +bool collectStatsForObjectFile(object::ObjectFile &Obj, DWARFContext &DICtx, + const Twine &Filename, raw_ostream &OS); +bool collectObjectSectionSizes(object::ObjectFile &Obj, DWARFContext &DICtx, + const Twine &Filename, raw_ostream &OS); + +} // namespace dwarfdump +} // namespace llvm -#endif // LLVM_TOOLS_SECTION_SIZES_H +#endif diff --git a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp --- a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp +++ b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp @@ -10,6 +10,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm-dwarfdump.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringSet.h" #include "llvm/ADT/Triple.h" @@ -32,8 +33,10 @@ #include using namespace llvm; -using namespace object; +using namespace llvm::dwarfdump; +using namespace llvm::object; +namespace { /// Parser for options that take an optional offest argument. /// @{ struct OffsetOption { @@ -41,6 +44,7 @@ bool HasValue = false; bool IsRequested = false; }; +} // namespace namespace llvm { namespace cl { @@ -82,8 +86,8 @@ // An out-of-line virtual method to provide a 'home' for this class. void anchor() override {}; }; -} // cl -} // llvm +} // namespace cl +} // namespace llvm /// @} /// Command line options. @@ -416,12 +420,6 @@ return true; } -bool collectStatsForObjectFile(ObjectFile &Obj, DWARFContext &DICtx, - const Twine &Filename, raw_ostream &OS); - -bool collectObjectSectionSizes(ObjectFile &Obj, DWARFContext & /*DICtx*/, - const Twine &Filename, raw_ostream &OS); - static bool dumpObjectFile(ObjectFile &Obj, DWARFContext &DICtx, const Twine &Filename, raw_ostream &OS) { logAllUnhandledErrors(DICtx.loadRegisterInfo(Obj), errs(),