From 1110808a9d39d4b808aef724c861a2e1a38d2a69 Mon Sep 17 00:00:00 2001
From: Devtools Arcadia <arcadia-devtools@yandex-team.ru>
Date: Mon, 7 Feb 2022 18:08:42 +0300
Subject: intermediate changes ref:cde9a383711a11544ce7e107a78147fb96cc4029

---
 .../include/llvm/DebugInfo/Symbolize/DIPrinter.h   |  70 ++++++++++
 .../llvm/DebugInfo/Symbolize/SymbolizableModule.h  |  61 +++++++++
 .../include/llvm/DebugInfo/Symbolize/Symbolize.h   | 152 +++++++++++++++++++++
 3 files changed, 283 insertions(+)
 create mode 100644 contrib/libs/llvm12/include/llvm/DebugInfo/Symbolize/DIPrinter.h
 create mode 100644 contrib/libs/llvm12/include/llvm/DebugInfo/Symbolize/SymbolizableModule.h
 create mode 100644 contrib/libs/llvm12/include/llvm/DebugInfo/Symbolize/Symbolize.h

(limited to 'contrib/libs/llvm12/include/llvm/DebugInfo/Symbolize')

diff --git a/contrib/libs/llvm12/include/llvm/DebugInfo/Symbolize/DIPrinter.h b/contrib/libs/llvm12/include/llvm/DebugInfo/Symbolize/DIPrinter.h
new file mode 100644
index 0000000000..d5c9cb8be5
--- /dev/null
+++ b/contrib/libs/llvm12/include/llvm/DebugInfo/Symbolize/DIPrinter.h
@@ -0,0 +1,70 @@
+#pragma once
+
+#ifdef __GNUC__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-parameter"
+#endif
+
+//===- llvm/DebugInfo/Symbolize/DIPrinter.h ---------------------*- 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
+//
+//===----------------------------------------------------------------------===//
+//
+// This file declares the DIPrinter class, which is responsible for printing
+// structures defined in DebugInfo/DIContext.h
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_SYMBOLIZE_DIPRINTER_H
+#define LLVM_DEBUGINFO_SYMBOLIZE_DIPRINTER_H
+
+#include <string>
+
+namespace llvm {
+struct DILineInfo;
+class DIInliningInfo;
+struct DIGlobal;
+struct DILocal;
+class raw_ostream;
+
+namespace symbolize {
+
+class DIPrinter {
+public:
+  enum class OutputStyle { LLVM, GNU };
+
+private:
+  raw_ostream &OS;
+  bool PrintFunctionNames;
+  bool PrintPretty;
+  int PrintSourceContext;
+  bool Verbose;
+  OutputStyle Style;
+
+  void print(const DILineInfo &Info, bool Inlined);
+  void printContext(const std::string &FileName, int64_t Line);
+
+public:
+  DIPrinter(raw_ostream &OS, bool PrintFunctionNames = true,
+            bool PrintPretty = false, int PrintSourceContext = 0,
+            bool Verbose = false, OutputStyle Style = OutputStyle::LLVM)
+      : OS(OS), PrintFunctionNames(PrintFunctionNames),
+        PrintPretty(PrintPretty), PrintSourceContext(PrintSourceContext),
+        Verbose(Verbose), Style(Style) {}
+
+  DIPrinter &operator<<(const DILineInfo &Info);
+  DIPrinter &operator<<(const DIInliningInfo &Info);
+  DIPrinter &operator<<(const DIGlobal &Global);
+  DIPrinter &operator<<(const DILocal &Local);
+};
+}
+}
+
+#endif
+
+#ifdef __GNUC__
+#pragma GCC diagnostic pop
+#endif
diff --git a/contrib/libs/llvm12/include/llvm/DebugInfo/Symbolize/SymbolizableModule.h b/contrib/libs/llvm12/include/llvm/DebugInfo/Symbolize/SymbolizableModule.h
new file mode 100644
index 0000000000..9273fde00e
--- /dev/null
+++ b/contrib/libs/llvm12/include/llvm/DebugInfo/Symbolize/SymbolizableModule.h
@@ -0,0 +1,61 @@
+#pragma once
+
+#ifdef __GNUC__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-parameter"
+#endif
+
+//===- SymbolizableModule.h -------------------------------------*- 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
+//
+//===----------------------------------------------------------------------===//
+//
+// This file declares the SymbolizableModule interface.
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEMODULE_H
+#define LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEMODULE_H
+
+#include "llvm/DebugInfo/DIContext.h"
+#include <cstdint>
+
+namespace llvm {
+namespace symbolize {
+
+using FunctionNameKind = DILineInfoSpecifier::FunctionNameKind;
+
+class SymbolizableModule {
+public:
+  virtual ~SymbolizableModule() = default;
+
+  virtual DILineInfo symbolizeCode(object::SectionedAddress ModuleOffset,
+                                   DILineInfoSpecifier LineInfoSpecifier,
+                                   bool UseSymbolTable) const = 0;
+  virtual DIInliningInfo
+  symbolizeInlinedCode(object::SectionedAddress ModuleOffset,
+                       DILineInfoSpecifier LineInfoSpecifier,
+                       bool UseSymbolTable) const = 0;
+  virtual DIGlobal
+  symbolizeData(object::SectionedAddress ModuleOffset) const = 0;
+  virtual std::vector<DILocal>
+  symbolizeFrame(object::SectionedAddress ModuleOffset) const = 0;
+
+  // Return true if this is a 32-bit x86 PE COFF module.
+  virtual bool isWin32Module() const = 0;
+
+  // Returns the preferred base of the module, i.e. where the loader would place
+  // it in memory assuming there were no conflicts.
+  virtual uint64_t getModulePreferredBase() const = 0;
+};
+
+} // end namespace symbolize
+} // end namespace llvm
+
+#endif  // LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEMODULE_H
+
+#ifdef __GNUC__
+#pragma GCC diagnostic pop
+#endif
diff --git a/contrib/libs/llvm12/include/llvm/DebugInfo/Symbolize/Symbolize.h b/contrib/libs/llvm12/include/llvm/DebugInfo/Symbolize/Symbolize.h
new file mode 100644
index 0000000000..d141990421
--- /dev/null
+++ b/contrib/libs/llvm12/include/llvm/DebugInfo/Symbolize/Symbolize.h
@@ -0,0 +1,152 @@
+#pragma once
+
+#ifdef __GNUC__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-parameter"
+#endif
+
+//===- Symbolize.h ----------------------------------------------*- 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
+//
+//===----------------------------------------------------------------------===//
+//
+// Header for LLVM symbolization library.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZE_H
+#define LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZE_H
+
+#include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
+#include "llvm/Object/Binary.h"
+#include "llvm/Object/ObjectFile.h"
+#include "llvm/Object/ELFObjectFile.h"
+#include "llvm/Support/Error.h"
+#include <algorithm>
+#include <cstdint>
+#include <map>
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
+namespace llvm {
+namespace symbolize {
+
+using namespace object;
+
+using FunctionNameKind = DILineInfoSpecifier::FunctionNameKind;
+using FileLineInfoKind = DILineInfoSpecifier::FileLineInfoKind;
+
+class LLVMSymbolizer {
+public:
+  struct Options {
+    FunctionNameKind PrintFunctions = FunctionNameKind::LinkageName;
+    FileLineInfoKind PathStyle = FileLineInfoKind::AbsoluteFilePath;
+    bool UseSymbolTable = true;
+    bool Demangle = true;
+    bool RelativeAddresses = false;
+    bool UntagAddresses = false;
+    bool UseDIA = false;
+    std::string DefaultArch;
+    std::vector<std::string> DsymHints;
+    std::string FallbackDebugPath;
+    std::string DWPName;
+    std::vector<std::string> DebugFileDirectory;
+  };
+
+  LLVMSymbolizer() = default;
+  LLVMSymbolizer(const Options &Opts) : Opts(Opts) {}
+
+  ~LLVMSymbolizer() {
+    flush();
+  }
+
+  Expected<DILineInfo> symbolizeCode(const ObjectFile &Obj,
+                                     object::SectionedAddress ModuleOffset);
+  Expected<DILineInfo> symbolizeCode(const std::string &ModuleName,
+                                     object::SectionedAddress ModuleOffset);
+  Expected<DIInliningInfo>
+  symbolizeInlinedCode(const std::string &ModuleName,
+                       object::SectionedAddress ModuleOffset);
+  Expected<DIGlobal> symbolizeData(const std::string &ModuleName,
+                                   object::SectionedAddress ModuleOffset);
+  Expected<std::vector<DILocal>>
+  symbolizeFrame(const std::string &ModuleName,
+                 object::SectionedAddress ModuleOffset);
+  void flush();
+
+  static std::string
+  DemangleName(const std::string &Name,
+               const SymbolizableModule *DbiModuleDescriptor);
+
+private:
+  // Bundles together object file with code/data and object file with
+  // corresponding debug info. These objects can be the same.
+  using ObjectPair = std::pair<const ObjectFile *, const ObjectFile *>;
+
+  Expected<DILineInfo>
+  symbolizeCodeCommon(SymbolizableModule *Info,
+                      object::SectionedAddress ModuleOffset);
+
+  /// Returns a SymbolizableModule or an error if loading debug info failed.
+  /// Only one attempt is made to load a module, and errors during loading are
+  /// only reported once. Subsequent calls to get module info for a module that
+  /// failed to load will return nullptr.
+  Expected<SymbolizableModule *>
+  getOrCreateModuleInfo(const std::string &ModuleName);
+
+  Expected<SymbolizableModule *>
+  createModuleInfo(const ObjectFile *Obj,
+                   std::unique_ptr<DIContext> Context,
+                   StringRef ModuleName);
+
+  ObjectFile *lookUpDsymFile(const std::string &Path,
+                             const MachOObjectFile *ExeObj,
+                             const std::string &ArchName);
+  ObjectFile *lookUpDebuglinkObject(const std::string &Path,
+                                    const ObjectFile *Obj,
+                                    const std::string &ArchName);
+  ObjectFile *lookUpBuildIDObject(const std::string &Path,
+                                  const ELFObjectFileBase *Obj,
+                                  const std::string &ArchName);
+
+  /// Returns pair of pointers to object and debug object.
+  Expected<ObjectPair> getOrCreateObjectPair(const std::string &Path,
+                                            const std::string &ArchName);
+
+  /// Return a pointer to object file at specified path, for a specified
+  /// architecture (e.g. if path refers to a Mach-O universal binary, only one
+  /// object file from it will be returned).
+  Expected<ObjectFile *> getOrCreateObject(const std::string &Path,
+                                          const std::string &ArchName);
+
+  std::map<std::string, std::unique_ptr<SymbolizableModule>, std::less<>>
+      Modules;
+
+  /// Contains cached results of getOrCreateObjectPair().
+  std::map<std::pair<std::string, std::string>, ObjectPair>
+      ObjectPairForPathArch;
+
+  /// Contains parsed binary for each path, or parsing error.
+  std::map<std::string, OwningBinary<Binary>> BinaryForPath;
+
+  /// Parsed object file for path/architecture pair, where "path" refers
+  /// to Mach-O universal binary.
+  std::map<std::pair<std::string, std::string>, std::unique_ptr<ObjectFile>>
+      ObjectForUBPathAndArch;
+
+  Options Opts;
+};
+
+} // end namespace symbolize
+} // end namespace llvm
+
+#endif // LLVM_DEBUGINFO_SYMBOLIZE_SYMBOLIZE_H
+
+#ifdef __GNUC__
+#pragma GCC diagnostic pop
+#endif
-- 
cgit v1.2.3