]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/SymbolFile/DWARF/DIERef.cpp
Merge ^/head r304236 through r304536.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / SymbolFile / DWARF / DIERef.cpp
1 //===-- DIERef.cpp ----------------------------------------------*- 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 #include "DIERef.h"
11 #include "DWARFCompileUnit.h"
12 #include "DWARFFormValue.h"
13 #include "DWARFDebugInfo.h"
14 #include "SymbolFileDWARF.h"
15 #include "SymbolFileDWARFDebugMap.h"
16
17 DIERef::DIERef() :
18     cu_offset(DW_INVALID_OFFSET),
19     die_offset(DW_INVALID_OFFSET)
20 {}
21
22 DIERef::DIERef(dw_offset_t c, dw_offset_t d) :
23     cu_offset(c),
24     die_offset(d)
25 {}
26
27 DIERef::DIERef(lldb::user_id_t uid, SymbolFileDWARF *dwarf) :
28     cu_offset(DW_INVALID_OFFSET),
29     die_offset(uid&0xffffffff)
30 {
31     SymbolFileDWARFDebugMap *debug_map = dwarf->GetDebugMapSymfile();
32     if (debug_map)
33     {
34         const uint32_t oso_idx = debug_map->GetOSOIndexFromUserID(uid);
35         SymbolFileDWARF *actual_dwarf = debug_map->GetSymbolFileByOSOIndex(oso_idx);
36         if (actual_dwarf)
37         {
38             DWARFDebugInfo *debug_info = actual_dwarf->DebugInfo();
39             if (debug_info)
40             {
41                 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIEOffset(die_offset);
42                 if (dwarf_cu)
43                 {
44                     cu_offset = dwarf_cu->GetOffset();
45                     return;
46                 }
47             }
48         }
49         die_offset = DW_INVALID_OFFSET;
50     }
51     else
52     {
53         cu_offset = uid>>32;
54     }
55 }
56
57 DIERef::DIERef(const DWARFFormValue& form_value) :
58     cu_offset(DW_INVALID_OFFSET),
59     die_offset(DW_INVALID_OFFSET)
60 {
61     if (form_value.IsValid())
62     {
63         const DWARFCompileUnit* dwarf_cu = form_value.GetCompileUnit();
64         if (dwarf_cu)
65         {
66             if (dwarf_cu->GetBaseObjOffset() != DW_INVALID_OFFSET)
67                 cu_offset = dwarf_cu->GetBaseObjOffset();
68             else
69                 cu_offset = dwarf_cu->GetOffset();
70         }
71         die_offset = form_value.Reference();
72     }
73 }
74
75 lldb::user_id_t
76 DIERef::GetUID(SymbolFileDWARF *dwarf) const
77 {
78     //----------------------------------------------------------------------
79     // Each SymbolFileDWARF will set its ID to what is expected.
80     //
81     // SymbolFileDWARF, when used for DWARF with .o files on MacOSX, has the
82     // ID set to the compile unit index.
83     //
84     // SymbolFileDWARFDwo sets the ID to the compile unit offset.
85     //----------------------------------------------------------------------
86     if (dwarf)
87         return dwarf->GetID() | die_offset;
88     else
89         return LLDB_INVALID_UID;
90 }
91