File indexing completed on 2024-05-12 05:43:27

0001 /*
0002     Copyright (C) 2014-2015 Volker Krause <vkrause@kde.org>
0003 
0004     This program is free software; you can redistribute it and/or modify it
0005     under the terms of the GNU Library General Public License as published by
0006     the Free Software Foundation; either version 2 of the License, or (at your
0007     option) any later version.
0008 
0009     This program is distributed in the hope that it will be useful, but WITHOUT
0010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
0012     License for more details.
0013 
0014     You should have received a copy of the GNU General Public License
0015     along with this program.  If not, see <https://www.gnu.org/licenses/>.
0016 */
0017 
0018 #ifndef DWARFINFO_H
0019 #define DWARFINFO_H
0020 
0021 #include <elf/elffile.h>
0022 
0023 #include <libdwarf.h>
0024 
0025 #include <memory>
0026 
0027 class DwarfCuDie;
0028 class DwarfDie;
0029 class DwarfInfoPrivate;
0030 class DwarfAddressRanges;
0031 
0032 /** Represents the .debug_info section. */
0033 class DwarfInfo
0034 {
0035 public:
0036     explicit DwarfInfo(ElfFile* elfFile);
0037     DwarfInfo(const DwarfInfo&) = delete;
0038     ~DwarfInfo();
0039 
0040     DwarfInfo& operator=(const DwarfInfo&) = delete;
0041 
0042     /** The ELF file this DWARF information belong to. */
0043     ElfFile* elfFile() const;
0044 
0045     /** The corresponding .debug_arange section. Use for address-based lookups. */
0046     DwarfAddressRanges* addressRanges() const;
0047 
0048     DwarfDie* dieForMangledSymbol(const QByteArray &symbol) const;
0049 
0050     Dwarf_Debug dwarfHandle() const; // TODO this shouldn't be public API
0051 
0052     QVector<DwarfCuDie*> compilationUnits() const;
0053     /** Returns the CU DIE for the given address.
0054      *  Prefer this over direct .debug_arange lookup, as that is not always
0055      *  available.
0056      */
0057     DwarfCuDie* compilationUnitForAddress(uint64_t address) const;
0058 
0059     DwarfDie* dieAtOffset(Dwarf_Off offset) const;
0060 
0061     bool isValid() const;
0062 private:
0063     std::unique_ptr<DwarfInfoPrivate> d;
0064 };
0065 
0066 #endif // DWARFINFO_H