From 40198f59053d7131ef0f7b4deb8725ab5fc19e29 Mon Sep 17 00:00:00 2001 From: Aaron Smith Date: Thu, 15 Mar 2018 06:04:51 +0000 Subject: [PATCH] [DebugInfo] Add a new method IPDBSession::findLineNumbersBySectOffset Summary: Some PDB symbols do not have a valid VA or RVA but have Addr by Section and Offset. For example, a variable in thread-local storage has the following properties: get_addressOffset: 0 get_addressSection: 5 get_lexicalParentId: 2 get_name: g_tls get_symIndexId: 12 get_typeId: 4 get_dataKind: 6 get_symTag: 7 get_locationType: 2 This change provides a new method to locate line numbers by Section and Offset from those symbols. Reviewers: zturner, rnk, llvm-commits Subscribers: asmith, JDevlieghere Differential Revision: https://reviews.llvm.org/D44407 llvm-svn: 327601 --- llvm/include/llvm/DebugInfo/PDB/DIA/DIASession.h | 3 +++ llvm/include/llvm/DebugInfo/PDB/IPDBSession.h | 3 +++ llvm/include/llvm/DebugInfo/PDB/Native/NativeSession.h | 3 +++ llvm/lib/DebugInfo/PDB/DIA/DIASession.cpp | 17 ++++++++++++++++- llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp | 6 ++++++ llvm/unittests/DebugInfo/PDB/PDBApiTest.cpp | 5 +++++ 6 files changed, 36 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/DebugInfo/PDB/DIA/DIASession.h b/llvm/include/llvm/DebugInfo/PDB/DIA/DIASession.h index 3a380d6..8c9ec9f 100644 --- a/llvm/include/llvm/DebugInfo/PDB/DIA/DIASession.h +++ b/llvm/include/llvm/DebugInfo/PDB/DIA/DIASession.h @@ -42,6 +42,9 @@ public: const IPDBSourceFile &File) const override; std::unique_ptr findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override; + std::unique_ptr + findLineNumbersBySectOffset(uint32_t Section, uint32_t Offset, + uint32_t Length) const override; std::unique_ptr findSourceFiles(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern, diff --git a/llvm/include/llvm/DebugInfo/PDB/IPDBSession.h b/llvm/include/llvm/DebugInfo/PDB/IPDBSession.h index 3e9f2df..9af16da 100644 --- a/llvm/include/llvm/DebugInfo/PDB/IPDBSession.h +++ b/llvm/include/llvm/DebugInfo/PDB/IPDBSession.h @@ -45,6 +45,9 @@ public: const IPDBSourceFile &File) const = 0; virtual std::unique_ptr findLineNumbersByAddress(uint64_t Address, uint32_t Length) const = 0; + virtual std::unique_ptr + findLineNumbersBySectOffset(uint32_t Section, uint32_t Offset, + uint32_t Length) const = 0; virtual std::unique_ptr findSourceFiles(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern, diff --git a/llvm/include/llvm/DebugInfo/PDB/Native/NativeSession.h b/llvm/include/llvm/DebugInfo/PDB/Native/NativeSession.h index bb85d13..a825969 100644 --- a/llvm/include/llvm/DebugInfo/PDB/Native/NativeSession.h +++ b/llvm/include/llvm/DebugInfo/PDB/Native/NativeSession.h @@ -61,6 +61,9 @@ public: const IPDBSourceFile &File) const override; std::unique_ptr findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override; + std::unique_ptr + findLineNumbersBySectOffset(uint32_t Section, uint32_t Offset, + uint32_t Length) const override; std::unique_ptr findSourceFiles(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern, diff --git a/llvm/lib/DebugInfo/PDB/DIA/DIASession.cpp b/llvm/lib/DebugInfo/PDB/DIA/DIASession.cpp index a6bbf6f..3a4ecdb 100644 --- a/llvm/lib/DebugInfo/PDB/DIA/DIASession.cpp +++ b/llvm/lib/DebugInfo/PDB/DIA/DIASession.cpp @@ -210,7 +210,22 @@ DIASession::findLineNumbers(const PDBSymbolCompiland &Compiland, std::unique_ptr DIASession::findLineNumbersByAddress(uint64_t Address, uint32_t Length) const { CComPtr LineNumbers; - if (S_OK != Session->findLinesByVA(Address, Length, &LineNumbers)) + if (S_OK != Session->findLinesByVA(Address, Length, &LineNumbers)) { + ULONGLONG LoadAddr = 0; + if (S_OK != Session->get_loadAddress(&LoadAddr)) + return nullptr; + DWORD RVA = static_cast(Address - LoadAddr); + if (S_OK != Session->findLinesByRVA(RVA, Length, &LineNumbers)) + return nullptr; + } + return llvm::make_unique(LineNumbers); +} + +std::unique_ptr +DIASession::findLineNumbersBySectOffset(uint32_t Section, uint32_t Offset, + uint32_t Length) const { + CComPtr LineNumbers; + if (S_OK != Session->findLinesByAddr(Section, Offset, Length, &LineNumbers)) return nullptr; return llvm::make_unique(LineNumbers); diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp index 481eb77..c4d188ee 100644 --- a/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp @@ -202,6 +202,12 @@ NativeSession::findLineNumbersByAddress(uint64_t Address, return nullptr; } +std::unique_ptr +NativeSession::findLineNumbersBySectOffset(uint32_t Section, uint32_t Offset, + uint32_t Length) const { + return nullptr; +} + std::unique_ptr NativeSession::findSourceFiles(const PDBSymbolCompiland *Compiland, StringRef Pattern, diff --git a/llvm/unittests/DebugInfo/PDB/PDBApiTest.cpp b/llvm/unittests/DebugInfo/PDB/PDBApiTest.cpp index 4cc47aa..2b8050a 100644 --- a/llvm/unittests/DebugInfo/PDB/PDBApiTest.cpp +++ b/llvm/unittests/DebugInfo/PDB/PDBApiTest.cpp @@ -88,6 +88,11 @@ class MockSession : public IPDBSession { findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override { return nullptr; } + std::unique_ptr + findLineNumbersBySectOffset(uint32_t Section, uint32_t Offset, + uint32_t Length) const override { + return nullptr; + } std::unique_ptr findSourceFiles(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern, PDB_NameSearchFlags Flags) const override { -- 2.7.4