DIERef.cpp revision 314564
118316Swollman//===-- DIERef.cpp ----------------------------------------------*- C++ -*-===//
218316Swollman//
318316Swollman//                     The LLVM Compiler Infrastructure
418316Swollman//
518316Swollman// This file is distributed under the University of Illinois Open Source
618316Swollman// License. See LICENSE.TXT for details.
718316Swollman//
818316Swollman//===----------------------------------------------------------------------===//
918316Swollman
1018316Swollman#include "DIERef.h"
1118316Swollman#include "DWARFCompileUnit.h"
1218316Swollman#include "DWARFDebugInfo.h"
1318316Swollman#include "DWARFFormValue.h"
1418316Swollman#include "SymbolFileDWARF.h"
1518316Swollman#include "SymbolFileDWARFDebugMap.h"
1618316Swollman
1718316SwollmanDIERef::DIERef()
1818316Swollman    : cu_offset(DW_INVALID_OFFSET), die_offset(DW_INVALID_OFFSET) {}
1918316Swollman
2018316SwollmanDIERef::DIERef(dw_offset_t c, dw_offset_t d) : cu_offset(c), die_offset(d) {}
2118316Swollman
2218316SwollmanDIERef::DIERef(lldb::user_id_t uid, SymbolFileDWARF *dwarf)
2318316Swollman    : cu_offset(DW_INVALID_OFFSET), die_offset(uid & 0xffffffff) {
2418316Swollman  SymbolFileDWARFDebugMap *debug_map = dwarf->GetDebugMapSymfile();
2518316Swollman  if (debug_map) {
2618316Swollman    const uint32_t oso_idx = debug_map->GetOSOIndexFromUserID(uid);
2718316Swollman    SymbolFileDWARF *actual_dwarf = debug_map->GetSymbolFileByOSOIndex(oso_idx);
2846303Smarkm    if (actual_dwarf) {
2950476Speter      DWARFDebugInfo *debug_info = actual_dwarf->DebugInfo();
3018316Swollman      if (debug_info) {
3118316Swollman        DWARFCompileUnit *dwarf_cu =
3218316Swollman            debug_info->GetCompileUnitContainingDIEOffset(die_offset);
3346303Smarkm        if (dwarf_cu) {
3418316Swollman          cu_offset = dwarf_cu->GetOffset();
3518316Swollman          return;
3618316Swollman        }
3746303Smarkm      }
3818316Swollman    }
3946303Smarkm    die_offset = DW_INVALID_OFFSET;
4018316Swollman  } else {
41190710Sphk    cu_offset = uid >> 32;
42126250Sbms  }
43190710Sphk}
44126250Sbms
4546303SmarkmDIERef::DIERef(const DWARFFormValue &form_value)
46126250Sbms    : cu_offset(DW_INVALID_OFFSET), die_offset(DW_INVALID_OFFSET) {
47126250Sbms  if (form_value.IsValid()) {
48126250Sbms    const DWARFCompileUnit *dwarf_cu = form_value.GetCompileUnit();
49126250Sbms    if (dwarf_cu) {
50163999Strhodes      if (dwarf_cu->GetBaseObjOffset() != DW_INVALID_OFFSET)
51163999Strhodes        cu_offset = dwarf_cu->GetBaseObjOffset();
5246303Smarkm      else
5346303Smarkm        cu_offset = dwarf_cu->GetOffset();
5418316Swollman    }
5518316Swollman    die_offset = form_value.Reference();
5618316Swollman  }
57190715Sphk}
5818316Swollman
59190715Sphklldb::user_id_t DIERef::GetUID(SymbolFileDWARF *dwarf) const {
6046303Smarkm  //----------------------------------------------------------------------
6118316Swollman  // Each SymbolFileDWARF will set its ID to what is expected.
6218316Swollman  //
63190715Sphk  // SymbolFileDWARF, when used for DWARF with .o files on MacOSX, has the
6418316Swollman  // ID set to the compile unit index.
65190715Sphk  //
66190715Sphk  // SymbolFileDWARFDwo sets the ID to the compile unit offset.
6718316Swollman  //----------------------------------------------------------------------
6818316Swollman  if (dwarf)
6937908Scharnier    return dwarf->GetID() | die_offset;
7018316Swollman  else
71272872Shrs    return LLDB_INVALID_UID;
7218316Swollman}
7318316Swollman