1 //===-- DWARFDebugInfo.h ----------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef SymbolFileDWARF_DWARFDebugInfo_h_
11 #define SymbolFileDWARF_DWARFDebugInfo_h_
12 
13 #include <vector>
14 #include <map>
15 
16 #include "lldb/lldb-private.h"
17 #include "lldb/lldb-private.h"
18 #include "SymbolFileDWARF.h"
19 
20 typedef std::multimap<const char*, dw_offset_t, CStringCompareFunctionObject> CStringToDIEMap;
21 typedef CStringToDIEMap::iterator CStringToDIEMapIter;
22 typedef CStringToDIEMap::const_iterator CStringToDIEMapConstIter;
23 
24 typedef lldb::SharedPtr<DWARFCompileUnit>::Type DWARFCompileUnitSP;
25 
26 class DWARFDebugInfo
27 {
28 public:
29     typedef dw_offset_t (*Callback)(
30         SymbolFileDWARF* dwarf2Data,
31         DWARFCompileUnitSP& cu_shared_ptr,
32         DWARFDebugInfoEntry* die,
33         const dw_offset_t next_offset,
34         const uint32_t depth,
35         void* userData);
36 
37     DWARFDebugInfo();
38     void SetDwarfData(SymbolFileDWARF* dwarf2Data);
39 
40     bool LookupAddress(
41             const dw_addr_t address,
42             const dw_offset_t cu_offset,    // Can be valid (find in .debug_aranges), or DW_INVALID_OFFSET if we need to search manually
43             DWARFCompileUnitSP& cu_shared_ptr,
44             DWARFDebugInfoEntry** function_die,
45             DWARFDebugInfoEntry** block_die);
46 
47     void AddCompileUnit(DWARFCompileUnitSP& cu);
48     uint32_t GetNumCompileUnits();
49     DWARFCompileUnit* GetCompileUnitAtIndex(uint32_t idx);
50     DWARFCompileUnitSP GetCompileUnit(dw_offset_t cu_offset, uint32_t* idx_ptr = NULL);
51     DWARFCompileUnitSP GetCompileUnitContainingDIE(dw_offset_t die_offset);
52 
53     DWARFDebugInfoEntry* GetDIEPtr(dw_offset_t die_offset, DWARFCompileUnitSP* cu_sp_ptr);
54     DWARFDebugInfoEntry* GetDIEPtrWithCompileUnitHint (dw_offset_t die_offset, DWARFCompileUnit**cu_handle);
55 
56     const DWARFDebugInfoEntry* GetDIEPtrContainingOffset(dw_offset_t die_offset, DWARFCompileUnitSP* cu_sp_ptr);
57 
58     void Dump(lldb_private::Stream *s, const uint32_t die_offset, const uint32_t recurse_depth);
59     static void Parse(SymbolFileDWARF* parser, Callback callback, void* userData);
60     static void Verify(lldb_private::Stream *s, SymbolFileDWARF* dwarf2Data);
61     static void Dump(lldb_private::Stream *s, SymbolFileDWARF* dwarf2Data, const uint32_t die_offset, const uint32_t recurse_depth);
62     bool Find(const char* name, bool ignore_case, std::vector<dw_offset_t>& die_offsets) const;
63     bool Find(lldb_private::RegularExpression& re, std::vector<dw_offset_t>& die_offsets) const;
64 
65     enum
66     {
67         eDumpFlag_Verbose               = (1<<0),   // Verbose dumping
68         eDumpFlag_ShowForm              = (1<<1),   // Show the DW_form type
69         eDumpFlag_ShowAncestors         = (1<<2)    // Show all parent DIEs when dumping single DIEs
70     };
71 
72     DWARFDebugAranges &
73     GetCompileUnitAranges ();
74 
75 protected:
76     SymbolFileDWARF* m_dwarf2Data;
77     typedef std::vector<DWARFCompileUnitSP>     CompileUnitColl;
78     CompileUnitColl m_compile_units;
79     std::auto_ptr<DWARFDebugAranges> m_cu_aranges_ap; // A quick address to compile unit table
80 
81 private:
82     // All parsing needs to be done partially any managed by this class as accessors are called.
83     void ParseCompileUnitHeadersIfNeeded();
84 
85     DISALLOW_COPY_AND_ASSIGN (DWARFDebugInfo);
86 };
87 
88 #endif  // SymbolFileDWARF_DWARFDebugInfo_h_
89