]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/SymbolFile/DWARF/DIERef.cpp
Import DTS from Linux 4.20
[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 "DWARFUnit.h"
12 #include "DWARFDebugInfo.h"
13 #include "DWARFFormValue.h"
14 #include "SymbolFileDWARF.h"
15 #include "SymbolFileDWARFDebugMap.h"
16
17 DIERef::DIERef(lldb::user_id_t uid, SymbolFileDWARF *dwarf)
18     : cu_offset(DW_INVALID_OFFSET), die_offset(uid & 0xffffffff) {
19   SymbolFileDWARFDebugMap *debug_map = dwarf->GetDebugMapSymfile();
20   if (debug_map) {
21     const uint32_t oso_idx = debug_map->GetOSOIndexFromUserID(uid);
22     SymbolFileDWARF *actual_dwarf = debug_map->GetSymbolFileByOSOIndex(oso_idx);
23     if (actual_dwarf) {
24       DWARFDebugInfo *debug_info = actual_dwarf->DebugInfo();
25       if (debug_info) {
26         DWARFUnit *dwarf_cu =
27             debug_info->GetCompileUnitContainingDIEOffset(die_offset);
28         if (dwarf_cu) {
29           cu_offset = dwarf_cu->GetOffset();
30           return;
31         }
32       }
33     }
34     die_offset = DW_INVALID_OFFSET;
35   } else {
36     cu_offset = uid >> 32;
37   }
38 }
39
40 DIERef::DIERef(const DWARFFormValue &form_value)
41     : cu_offset(DW_INVALID_OFFSET), die_offset(DW_INVALID_OFFSET) {
42   if (form_value.IsValid()) {
43     const DWARFUnit *dwarf_cu = form_value.GetCompileUnit();
44     if (dwarf_cu) {
45       if (dwarf_cu->GetBaseObjOffset() != DW_INVALID_OFFSET)
46         cu_offset = dwarf_cu->GetBaseObjOffset();
47       else
48         cu_offset = dwarf_cu->GetOffset();
49     }
50     die_offset = form_value.Reference();
51   }
52 }
53
54 lldb::user_id_t DIERef::GetUID(SymbolFileDWARF *dwarf) const {
55   //----------------------------------------------------------------------
56   // Each SymbolFileDWARF will set its ID to what is expected.
57   //
58   // SymbolFileDWARF, when used for DWARF with .o files on MacOSX, has the
59   // ID set to the compile unit index.
60   //
61   // SymbolFileDWARFDwo sets the ID to the compile unit offset.
62   //----------------------------------------------------------------------
63   if (dwarf && die_offset != DW_INVALID_OFFSET)
64     return dwarf->GetID() | die_offset;
65   else
66     return LLDB_INVALID_UID;
67 }