DWARFDebugInfoEntry.cpp revision 309124
1//===-- DWARFDebugInfoEntry.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 "DWARFDebugInfoEntry.h"
11
12#include <assert.h>
13
14#include <algorithm>
15
16#include "lldb/Core/Module.h"
17#include "lldb/Core/Stream.h"
18#include "lldb/Expression/DWARFExpression.h"
19#include "lldb/Symbol/ObjectFile.h"
20
21#include "DWARFCompileUnit.h"
22#include "DWARFDebugAbbrev.h"
23#include "DWARFDebugAranges.h"
24#include "DWARFDebugInfo.h"
25#include "DWARFDeclContext.h"
26#include "DWARFDIECollection.h"
27#include "DWARFFormValue.h"
28#include "DWARFDebugRanges.h"
29#include "SymbolFileDWARF.h"
30#include "SymbolFileDWARFDwo.h"
31
32using namespace lldb_private;
33using namespace std;
34extern int g_verbose;
35
36bool
37DWARFDebugInfoEntry::FastExtract
38(
39    const DWARFDataExtractor& debug_info_data,
40    const DWARFCompileUnit* cu,
41    const DWARFFormValue::FixedFormSizes& fixed_form_sizes,
42    lldb::offset_t *offset_ptr
43)
44{
45    m_offset = *offset_ptr;
46    m_parent_idx = 0;
47    m_sibling_idx = 0;
48    m_empty_children = false;
49    const uint64_t abbr_idx = debug_info_data.GetULEB128 (offset_ptr);
50    assert (abbr_idx < (1 << DIE_ABBR_IDX_BITSIZE));
51    m_abbr_idx = abbr_idx;
52
53    //assert (fixed_form_sizes);  // For best performance this should be specified!
54
55    if (m_abbr_idx)
56    {
57        lldb::offset_t offset = *offset_ptr;
58
59        const DWARFAbbreviationDeclaration *abbrevDecl = cu->GetAbbreviations()->GetAbbreviationDeclaration(m_abbr_idx);
60
61        if (abbrevDecl == NULL)
62        {
63            cu->GetSymbolFileDWARF()->GetObjectFile()->GetModule()->ReportError ("{0x%8.8x}: invalid abbreviation code %u, please file a bug and attach the file at the start of this error message",
64                                                                                 m_offset,
65                                                                                 (unsigned)abbr_idx);
66            // WE can't parse anymore if the DWARF is borked...
67            *offset_ptr = UINT32_MAX;
68            return false;
69        }
70        m_tag = abbrevDecl->Tag();
71        m_has_children = abbrevDecl->HasChildren();
72        // Skip all data in the .debug_info for the attributes
73        const uint32_t numAttributes = abbrevDecl->NumAttributes();
74        uint32_t i;
75        dw_form_t form;
76        for (i=0; i<numAttributes; ++i)
77        {
78            form = abbrevDecl->GetFormByIndexUnchecked(i);
79
80            const uint8_t fixed_skip_size = fixed_form_sizes.GetSize(form);
81            if (fixed_skip_size)
82                offset += fixed_skip_size;
83            else
84            {
85                bool form_is_indirect = false;
86                do
87                {
88                    form_is_indirect = false;
89                    uint32_t form_size = 0;
90                    switch (form)
91                    {
92                    // Blocks if inlined data that have a length field and the data bytes
93                    // inlined in the .debug_info
94                    case DW_FORM_exprloc     :
95                    case DW_FORM_block       : form_size = debug_info_data.GetULEB128 (&offset);      break;
96                    case DW_FORM_block1      : form_size = debug_info_data.GetU8_unchecked (&offset); break;
97                    case DW_FORM_block2      : form_size = debug_info_data.GetU16_unchecked (&offset);break;
98                    case DW_FORM_block4      : form_size = debug_info_data.GetU32_unchecked (&offset);break;
99
100                    // Inlined NULL terminated C-strings
101                    case DW_FORM_string      :
102                        debug_info_data.GetCStr (&offset);
103                        break;
104
105                    // Compile unit address sized values
106                    case DW_FORM_addr        :
107                        form_size = cu->GetAddressByteSize();
108                        break;
109                    case DW_FORM_ref_addr    :
110                        if (cu->GetVersion() <= 2)
111                            form_size = cu->GetAddressByteSize();
112                        else
113                            form_size = cu->IsDWARF64() ? 8 : 4;
114                        break;
115
116                    // 0 sized form
117                    case DW_FORM_flag_present:
118                        form_size = 0;
119                        break;
120
121                    // 1 byte values
122                    case DW_FORM_data1       :
123                    case DW_FORM_flag        :
124                    case DW_FORM_ref1        :
125                        form_size = 1;
126                        break;
127
128                    // 2 byte values
129                    case DW_FORM_data2       :
130                    case DW_FORM_ref2        :
131                        form_size = 2;
132                        break;
133
134                    // 4 byte values
135                    case DW_FORM_data4       :
136                    case DW_FORM_ref4        :
137                        form_size = 4;
138                        break;
139
140                    // 8 byte values
141                    case DW_FORM_data8       :
142                    case DW_FORM_ref8        :
143                    case DW_FORM_ref_sig8    :
144                        form_size = 8;
145                        break;
146
147                    // signed or unsigned LEB 128 values
148                    case DW_FORM_sdata         :
149                    case DW_FORM_udata         :
150                    case DW_FORM_ref_udata     :
151                    case DW_FORM_GNU_addr_index:
152                    case DW_FORM_GNU_str_index :
153                        debug_info_data.Skip_LEB128 (&offset);
154                        break;
155
156                    case DW_FORM_indirect    :
157                        form_is_indirect = true;
158                        form = debug_info_data.GetULEB128 (&offset);
159                        break;
160
161                    case DW_FORM_strp        :
162                    case DW_FORM_sec_offset  :
163                        if (cu->IsDWARF64 ())
164                            debug_info_data.GetU64 (offset_ptr);
165                        else
166                            debug_info_data.GetU32 (offset_ptr);
167                        break;
168
169                    default:
170                        *offset_ptr = m_offset;
171                        return false;
172                    }
173                    offset += form_size;
174
175                } while (form_is_indirect);
176            }
177        }
178        *offset_ptr = offset;
179        return true;
180    }
181    else
182    {
183        m_tag = 0;
184        m_has_children = false;
185        return true;    // NULL debug tag entry
186    }
187
188    return false;
189}
190
191//----------------------------------------------------------------------
192// Extract
193//
194// Extract a debug info entry for a given compile unit from the
195// .debug_info and .debug_abbrev data within the SymbolFileDWARF class
196// starting at the given offset
197//----------------------------------------------------------------------
198bool
199DWARFDebugInfoEntry::Extract
200(
201    SymbolFileDWARF* dwarf2Data,
202    const DWARFCompileUnit* cu,
203    lldb::offset_t *offset_ptr
204)
205{
206    const DWARFDataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
207//    const DWARFDataExtractor& debug_str_data = dwarf2Data->get_debug_str_data();
208    const uint32_t cu_end_offset = cu->GetNextCompileUnitOffset();
209    lldb::offset_t offset = *offset_ptr;
210//  if (offset >= cu_end_offset)
211//      Log::Error("DIE at offset 0x%8.8x is beyond the end of the current compile unit (0x%8.8x)", m_offset, cu_end_offset);
212    if ((offset < cu_end_offset) && debug_info_data.ValidOffset(offset))
213    {
214        m_offset = offset;
215
216        const uint64_t abbr_idx = debug_info_data.GetULEB128(&offset);
217        assert (abbr_idx < (1 << DIE_ABBR_IDX_BITSIZE));
218        m_abbr_idx = abbr_idx;
219        if (abbr_idx)
220        {
221            const DWARFAbbreviationDeclaration *abbrevDecl = cu->GetAbbreviations()->GetAbbreviationDeclaration(abbr_idx);
222
223            if (abbrevDecl)
224            {
225                m_tag = abbrevDecl->Tag();
226                m_has_children = abbrevDecl->HasChildren();
227
228                bool isCompileUnitTag = m_tag == DW_TAG_compile_unit;
229                if (cu && isCompileUnitTag)
230                    const_cast<DWARFCompileUnit *>(cu)->SetBaseAddress(0);
231
232                // Skip all data in the .debug_info for the attributes
233                const uint32_t numAttributes = abbrevDecl->NumAttributes();
234                uint32_t i;
235                dw_attr_t attr;
236                dw_form_t form;
237                for (i=0; i<numAttributes; ++i)
238                {
239                    abbrevDecl->GetAttrAndFormByIndexUnchecked(i, attr, form);
240
241                    if (isCompileUnitTag && ((attr == DW_AT_entry_pc) || (attr == DW_AT_low_pc)))
242                    {
243                        DWARFFormValue form_value(cu, form);
244                        if (form_value.ExtractValue(debug_info_data, &offset))
245                        {
246                            if (attr == DW_AT_low_pc || attr == DW_AT_entry_pc)
247                                const_cast<DWARFCompileUnit*>(cu)->SetBaseAddress(form_value.Address());
248                        }
249                    }
250                    else
251                    {
252                        bool form_is_indirect = false;
253                        do
254                        {
255                            form_is_indirect = false;
256                            uint32_t form_size = 0;
257                            switch (form)
258                            {
259                            // Blocks if inlined data that have a length field and the data bytes
260                            // inlined in the .debug_info
261                            case DW_FORM_exprloc     :
262                            case DW_FORM_block       : form_size = debug_info_data.GetULEB128(&offset);  break;
263                            case DW_FORM_block1      : form_size = debug_info_data.GetU8(&offset);       break;
264                            case DW_FORM_block2      : form_size = debug_info_data.GetU16(&offset);      break;
265                            case DW_FORM_block4      : form_size = debug_info_data.GetU32(&offset);      break;
266
267                            // Inlined NULL terminated C-strings
268                            case DW_FORM_string      : debug_info_data.GetCStr(&offset);                 break;
269
270                            // Compile unit address sized values
271                            case DW_FORM_addr        :
272                                form_size = cu->GetAddressByteSize();
273                                break;
274                            case DW_FORM_ref_addr    :
275                                if (cu->GetVersion() <= 2)
276                                    form_size = cu->GetAddressByteSize();
277                                else
278                                    form_size = cu->IsDWARF64() ? 8 : 4;
279                                break;
280
281                            // 0 sized form
282                            case DW_FORM_flag_present:
283                                form_size = 0;
284                                break;
285
286                            // 1 byte values
287                            case DW_FORM_data1       :
288                            case DW_FORM_flag        :
289                            case DW_FORM_ref1        :
290                                form_size = 1;
291                                break;
292
293                            // 2 byte values
294                            case DW_FORM_data2       :
295                            case DW_FORM_ref2        :
296                                form_size = 2;
297                                break;
298
299                            // 4 byte values
300                            case DW_FORM_data4       :
301                            case DW_FORM_ref4        :
302                                form_size = 4;
303                                break;
304
305                            // 8 byte values
306                            case DW_FORM_data8       :
307                            case DW_FORM_ref8        :
308                            case DW_FORM_ref_sig8    :
309                                form_size = 8;
310                                break;
311
312                            // signed or unsigned LEB 128 values
313                            case DW_FORM_sdata         :
314                            case DW_FORM_udata         :
315                            case DW_FORM_ref_udata     :
316                            case DW_FORM_GNU_addr_index:
317                            case DW_FORM_GNU_str_index :
318                                debug_info_data.Skip_LEB128(&offset);
319                                break;
320
321                            case DW_FORM_indirect    :
322                                form = debug_info_data.GetULEB128(&offset);
323                                form_is_indirect = true;
324                                break;
325
326                            case DW_FORM_strp        :
327                            case DW_FORM_sec_offset  :
328                                if (cu->IsDWARF64 ())
329                                    debug_info_data.GetU64 (offset_ptr);
330                                else
331                                    debug_info_data.GetU32 (offset_ptr);
332                                break;
333
334                            default:
335                                *offset_ptr = offset;
336                                return false;
337                            }
338
339                            offset += form_size;
340                        } while (form_is_indirect);
341                    }
342                }
343                *offset_ptr = offset;
344                return true;
345            }
346        }
347        else
348        {
349            m_tag = 0;
350            m_has_children = false;
351            *offset_ptr = offset;
352            return true;    // NULL debug tag entry
353        }
354    }
355
356    return false;
357}
358
359//----------------------------------------------------------------------
360// DumpAncestry
361//
362// Dumps all of a debug information entries parents up until oldest and
363// all of it's attributes to the specified stream.
364//----------------------------------------------------------------------
365void
366DWARFDebugInfoEntry::DumpAncestry
367(
368    SymbolFileDWARF* dwarf2Data,
369    const DWARFCompileUnit* cu,
370    const DWARFDebugInfoEntry* oldest,
371    Stream &s,
372    uint32_t recurse_depth
373) const
374{
375    const DWARFDebugInfoEntry* parent = GetParent();
376    if (parent && parent != oldest)
377        parent->DumpAncestry(dwarf2Data, cu, oldest, s, 0);
378    Dump(dwarf2Data, cu, s, recurse_depth);
379}
380
381//----------------------------------------------------------------------
382// GetDIENamesAndRanges
383//
384// Gets the valid address ranges for a given DIE by looking for a
385// DW_AT_low_pc/DW_AT_high_pc pair, DW_AT_entry_pc, or DW_AT_ranges
386// attributes.
387//----------------------------------------------------------------------
388bool
389DWARFDebugInfoEntry::GetDIENamesAndRanges
390(
391    SymbolFileDWARF* dwarf2Data,
392    const DWARFCompileUnit* cu,
393    const char * &name,
394    const char * &mangled,
395    DWARFRangeList& ranges,
396    int& decl_file,
397    int& decl_line,
398    int& decl_column,
399    int& call_file,
400    int& call_line,
401    int& call_column,
402    DWARFExpression *frame_base
403) const
404{
405    if (dwarf2Data == nullptr)
406        return false;
407
408    SymbolFileDWARFDwo* dwo_symbol_file = cu->GetDwoSymbolFile();
409    if (dwo_symbol_file)
410        return GetDIENamesAndRanges(dwo_symbol_file,
411                                    dwo_symbol_file->GetCompileUnit(),
412                                    name,
413                                    mangled,
414                                    ranges,
415                                    decl_file,
416                                    decl_line,
417                                    decl_column,
418                                    call_file,
419                                    call_line,
420                                    call_column,
421                                    frame_base);
422
423    dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
424    dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
425    std::vector<DIERef> die_refs;
426    bool set_frame_base_loclist_addr = false;
427
428    lldb::offset_t offset;
429    const DWARFAbbreviationDeclaration* abbrevDecl = GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
430
431    lldb::ModuleSP module = dwarf2Data->GetObjectFile()->GetModule();
432
433    if (abbrevDecl)
434    {
435        const DWARFDataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
436
437        if (!debug_info_data.ValidOffset(offset))
438            return false;
439
440        const uint32_t numAttributes = abbrevDecl->NumAttributes();
441        uint32_t i;
442        dw_attr_t attr;
443        dw_form_t form;
444        bool do_offset = false;
445
446        for (i=0; i<numAttributes; ++i)
447        {
448            abbrevDecl->GetAttrAndFormByIndexUnchecked(i, attr, form);
449            DWARFFormValue form_value(cu, form);
450            if (form_value.ExtractValue(debug_info_data, &offset))
451            {
452                switch (attr)
453                {
454                case DW_AT_low_pc:
455                    lo_pc = form_value.Address();
456
457                    if (do_offset)
458                        hi_pc += lo_pc;
459                    do_offset = false;
460                    break;
461
462                case DW_AT_entry_pc:
463                    lo_pc = form_value.Address();
464                    break;
465
466                case DW_AT_high_pc:
467                    if (form_value.Form() == DW_FORM_addr ||
468                        form_value.Form() == DW_FORM_GNU_addr_index)
469                    {
470                        hi_pc = form_value.Address();
471                    }
472                    else
473                    {
474                        hi_pc = form_value.Unsigned();
475                        if (lo_pc == LLDB_INVALID_ADDRESS)
476                            do_offset = hi_pc != LLDB_INVALID_ADDRESS;
477                        else
478                            hi_pc += lo_pc; // DWARF 4 introduces <offset-from-lo-pc> to save on relocations
479                    }
480                    break;
481
482                case DW_AT_ranges:
483                    {
484                        const DWARFDebugRanges* debug_ranges = dwarf2Data->DebugRanges();
485                        if (debug_ranges)
486                        {
487                            debug_ranges->FindRanges(form_value.Unsigned(), ranges);
488                            // All DW_AT_ranges are relative to the base address of the
489                            // compile unit. We add the compile unit base address to make
490                            // sure all the addresses are properly fixed up.
491                            ranges.Slide(cu->GetBaseAddress());
492                        }
493                        else
494                        {
495                            cu->GetSymbolFileDWARF()->GetObjectFile()->GetModule()->ReportError ("{0x%8.8x}: DIE has DW_AT_ranges(0x%" PRIx64 ") attribute yet DWARF has no .debug_ranges, please file a bug and attach the file at the start of this error message",
496                                                                                                 m_offset, form_value.Unsigned());
497                        }
498                    }
499                    break;
500
501                case DW_AT_name:
502                    if (name == NULL)
503                        name = form_value.AsCString();
504                    break;
505
506                case DW_AT_MIPS_linkage_name:
507                case DW_AT_linkage_name:
508                    if (mangled == NULL)
509                        mangled = form_value.AsCString();
510                    break;
511
512                case DW_AT_abstract_origin:
513                    die_refs.emplace_back(form_value);
514                    break;
515
516                case DW_AT_specification:
517                    die_refs.emplace_back(form_value);
518                    break;
519
520                case DW_AT_decl_file:
521                    if (decl_file == 0)
522                        decl_file = form_value.Unsigned();
523                    break;
524
525                case DW_AT_decl_line:
526                    if (decl_line == 0)
527                        decl_line = form_value.Unsigned();
528                    break;
529
530                case DW_AT_decl_column:
531                    if (decl_column == 0)
532                        decl_column = form_value.Unsigned();
533                    break;
534
535                case DW_AT_call_file:
536                    if (call_file == 0)
537                        call_file = form_value.Unsigned();
538                    break;
539
540                case DW_AT_call_line:
541                    if (call_line == 0)
542                        call_line = form_value.Unsigned();
543                    break;
544
545                case DW_AT_call_column:
546                    if (call_column == 0)
547                        call_column = form_value.Unsigned();
548                    break;
549
550                case DW_AT_frame_base:
551                    if (frame_base)
552                    {
553                        if (form_value.BlockData())
554                        {
555                            uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
556                            uint32_t block_length = form_value.Unsigned();
557                            frame_base->SetOpcodeData(module, debug_info_data, block_offset, block_length);
558                        }
559                        else
560                        {
561                            const DWARFDataExtractor &debug_loc_data = dwarf2Data->get_debug_loc_data();
562                            const dw_offset_t debug_loc_offset = form_value.Unsigned();
563
564                            size_t loc_list_length = DWARFExpression::LocationListSize(cu, debug_loc_data, debug_loc_offset);
565                            if (loc_list_length > 0)
566                            {
567                                frame_base->SetOpcodeData(module, debug_loc_data, debug_loc_offset, loc_list_length);
568                                if (lo_pc != LLDB_INVALID_ADDRESS)
569                                {
570                                    assert (lo_pc >= cu->GetBaseAddress());
571                                    frame_base->SetLocationListSlide(lo_pc - cu->GetBaseAddress());
572                                }
573                                else
574                                {
575                                    set_frame_base_loclist_addr = true;
576                                }
577                            }
578                        }
579                    }
580                    break;
581
582                default:
583                    break;
584                }
585            }
586        }
587    }
588
589    if (ranges.IsEmpty())
590    {
591        if (lo_pc != LLDB_INVALID_ADDRESS)
592        {
593            if (hi_pc != LLDB_INVALID_ADDRESS && hi_pc > lo_pc)
594                ranges.Append(DWARFRangeList::Entry (lo_pc, hi_pc - lo_pc));
595            else
596                ranges.Append(DWARFRangeList::Entry (lo_pc, 0));
597        }
598    }
599
600    if (set_frame_base_loclist_addr)
601    {
602        dw_addr_t lowest_range_pc = ranges.GetMinRangeBase(0);
603        assert (lowest_range_pc >= cu->GetBaseAddress());
604        frame_base->SetLocationListSlide (lowest_range_pc - cu->GetBaseAddress());
605    }
606
607    if (ranges.IsEmpty() || name == NULL || mangled == NULL)
608    {
609        for (const DIERef& die_ref : die_refs)
610        {
611            if (die_ref.die_offset != DW_INVALID_OFFSET)
612            {
613                DWARFDIE die = dwarf2Data->GetDIE(die_ref);
614                if (die)
615                    die.GetDIE()->GetDIENamesAndRanges(die.GetDWARF(), die.GetCU(), name, mangled, ranges, decl_file, decl_line, decl_column, call_file, call_line, call_column);
616            }
617        }
618    }
619    return !ranges.IsEmpty();
620}
621
622//----------------------------------------------------------------------
623// Dump
624//
625// Dumps a debug information entry and all of it's attributes to the
626// specified stream.
627//----------------------------------------------------------------------
628void
629DWARFDebugInfoEntry::Dump
630(
631    SymbolFileDWARF* dwarf2Data,
632    const DWARFCompileUnit* cu,
633    Stream &s,
634    uint32_t recurse_depth
635) const
636{
637    const DWARFDataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
638    lldb::offset_t offset = m_offset;
639
640    if (debug_info_data.ValidOffset(offset))
641    {
642        dw_uleb128_t abbrCode = debug_info_data.GetULEB128(&offset);
643
644        s.Printf("\n0x%8.8x: ", m_offset);
645        s.Indent();
646        if (abbrCode != m_abbr_idx)
647        {
648            s.Printf( "error: DWARF has been modified\n");
649        }
650        else if (abbrCode)
651        {
652            const DWARFAbbreviationDeclaration* abbrevDecl = cu->GetAbbreviations()->GetAbbreviationDeclaration (abbrCode);
653
654            if (abbrevDecl)
655            {
656                s.PutCString(DW_TAG_value_to_name(abbrevDecl->Tag()));
657                s.Printf( " [%u] %c\n", abbrCode, abbrevDecl->HasChildren() ? '*':' ');
658
659                // Dump all data in the .debug_info for the attributes
660                const uint32_t numAttributes = abbrevDecl->NumAttributes();
661                uint32_t i;
662                dw_attr_t attr;
663                dw_form_t form;
664                for (i=0; i<numAttributes; ++i)
665                {
666                    abbrevDecl->GetAttrAndFormByIndexUnchecked(i, attr, form);
667
668                    DumpAttribute(dwarf2Data, cu, debug_info_data, &offset, s, attr, form);
669                }
670
671                const DWARFDebugInfoEntry* child = GetFirstChild();
672                if (recurse_depth > 0 && child)
673                {
674                    s.IndentMore();
675
676                    while (child)
677                    {
678                        child->Dump(dwarf2Data, cu, s, recurse_depth-1);
679                        child = child->GetSibling();
680                    }
681                    s.IndentLess();
682                }
683            }
684            else
685                s.Printf( "Abbreviation code note found in 'debug_abbrev' class for code: %u\n", abbrCode);
686        }
687        else
688        {
689            s.Printf( "NULL\n");
690        }
691    }
692}
693
694void
695DWARFDebugInfoEntry::DumpLocation
696(
697    SymbolFileDWARF* dwarf2Data,
698    DWARFCompileUnit* cu,
699    Stream &s
700) const
701{
702    const DWARFDIE cu_die = cu->GetCompileUnitDIEOnly();
703    const char *cu_name = NULL;
704    if (cu_die)
705        cu_name = cu_die.GetName ();
706    const char *obj_file_name = NULL;
707    ObjectFile *obj_file = dwarf2Data->GetObjectFile();
708    if (obj_file)
709        obj_file_name = obj_file->GetFileSpec().GetFilename().AsCString("<Unknown>");
710    const char *die_name = GetName (dwarf2Data, cu);
711    s.Printf ("0x%8.8x/0x%8.8x: %-30s (from %s in %s)",
712              cu->GetOffset(),
713              GetOffset(),
714              die_name ? die_name : "",
715              cu_name ? cu_name : "<NULL>",
716              obj_file_name ? obj_file_name : "<NULL>");
717}
718
719//----------------------------------------------------------------------
720// DumpAttribute
721//
722// Dumps a debug information entry attribute along with it's form. Any
723// special display of attributes is done (disassemble location lists,
724// show enumeration values for attributes, etc).
725//----------------------------------------------------------------------
726void
727DWARFDebugInfoEntry::DumpAttribute
728(
729    SymbolFileDWARF* dwarf2Data,
730    const DWARFCompileUnit* cu,
731    const DWARFDataExtractor& debug_info_data,
732    lldb::offset_t *offset_ptr,
733    Stream &s,
734    dw_attr_t attr,
735    dw_form_t form
736)
737{
738    bool verbose    = s.GetVerbose();
739    bool show_form  = s.GetFlags().Test(DWARFDebugInfo::eDumpFlag_ShowForm);
740
741    if (verbose)
742        s.Offset (*offset_ptr);
743    else
744        s.Printf ("            ");
745    s.Indent(DW_AT_value_to_name(attr));
746
747    if (show_form)
748    {
749        s.Printf( "[%s", DW_FORM_value_to_name(form));
750    }
751
752    DWARFFormValue form_value(cu, form);
753
754    if (!form_value.ExtractValue(debug_info_data, offset_ptr))
755        return;
756
757    if (show_form)
758    {
759        if (form == DW_FORM_indirect)
760        {
761            s.Printf( " [%s]", DW_FORM_value_to_name(form_value.Form()));
762        }
763
764        s.PutCString("] ");
765    }
766
767    s.PutCString("( ");
768
769    // Always dump form value if verbose is enabled
770    if (verbose)
771    {
772        form_value.Dump(s);
773    }
774
775
776    // Check to see if we have any special attribute formatters
777    switch (attr)
778    {
779    case DW_AT_stmt_list:
780        if ( verbose ) s.PutCString(" ( ");
781        s.Printf( "0x%8.8" PRIx64, form_value.Unsigned());
782        if ( verbose ) s.PutCString(" )");
783        break;
784
785    case DW_AT_language:
786        if ( verbose ) s.PutCString(" ( ");
787        s.PutCString(DW_LANG_value_to_name(form_value.Unsigned()));
788        if ( verbose ) s.PutCString(" )");
789        break;
790
791    case DW_AT_encoding:
792        if ( verbose ) s.PutCString(" ( ");
793        s.PutCString(DW_ATE_value_to_name(form_value.Unsigned()));
794        if ( verbose ) s.PutCString(" )");
795        break;
796
797    case DW_AT_frame_base:
798    case DW_AT_location:
799    case DW_AT_data_member_location:
800        {
801            const uint8_t* blockData = form_value.BlockData();
802            if (blockData)
803            {
804                if (!verbose)
805                    form_value.Dump(s);
806
807                // Location description is inlined in data in the form value
808                DWARFDataExtractor locationData(debug_info_data, (*offset_ptr) - form_value.Unsigned(), form_value.Unsigned());
809                if ( verbose ) s.PutCString(" ( ");
810                DWARFExpression::PrintDWARFExpression(s,
811                                                      locationData,
812                                                      DWARFCompileUnit::GetAddressByteSize(cu),
813                                                      4,
814                                                      false);
815                if ( verbose ) s.PutCString(" )");
816            }
817            else
818            {
819                // We have a location list offset as the value that is
820                // the offset into the .debug_loc section that describes
821                // the value over it's lifetime
822                uint64_t debug_loc_offset = form_value.Unsigned();
823                if (dwarf2Data)
824                {
825                    if ( !verbose )
826                        form_value.Dump(s);
827                    DWARFExpression::PrintDWARFLocationList(s,
828                                                            cu,
829                                                            dwarf2Data->get_debug_loc_data(),
830                                                            debug_loc_offset);
831                }
832                else
833                {
834                    if ( !verbose )
835                        form_value.Dump(s);
836                }
837            }
838        }
839        break;
840
841    case DW_AT_abstract_origin:
842    case DW_AT_specification:
843        {
844            uint64_t abstract_die_offset = form_value.Reference();
845            form_value.Dump(s);
846        //  *ostrm_ptr << HEX32 << abstract_die_offset << " ( ";
847            if ( verbose ) s.PutCString(" ( ");
848            GetName(dwarf2Data, cu, abstract_die_offset, s);
849            if ( verbose ) s.PutCString(" )");
850        }
851        break;
852
853    case DW_AT_type:
854        {
855            uint64_t type_die_offset = form_value.Reference();
856            if (!verbose)
857                form_value.Dump(s);
858            s.PutCString(" ( ");
859            AppendTypeName(dwarf2Data, cu, type_die_offset, s);
860            s.PutCString(" )");
861        }
862        break;
863
864    case DW_AT_ranges:
865        {
866            if ( !verbose )
867                form_value.Dump(s);
868            lldb::offset_t ranges_offset = form_value.Unsigned();
869            dw_addr_t base_addr = cu ? cu->GetBaseAddress() : 0;
870            if (dwarf2Data)
871                DWARFDebugRanges::Dump(s, dwarf2Data->get_debug_ranges_data(), &ranges_offset, base_addr);
872        }
873        break;
874
875    default:
876        if ( !verbose )
877            form_value.Dump(s);
878        break;
879    }
880
881    s.PutCString(" )\n");
882}
883
884//----------------------------------------------------------------------
885// Get all attribute values for a given DIE, including following any
886// specification or abstract origin attributes and including those in
887// the results. Any duplicate attributes will have the first instance
888// take precedence (this can happen for declaration attributes).
889//----------------------------------------------------------------------
890size_t
891DWARFDebugInfoEntry::GetAttributes (const DWARFCompileUnit* cu,
892                                    DWARFFormValue::FixedFormSizes fixed_form_sizes,
893                                    DWARFAttributes& attributes,
894                                    uint32_t curr_depth) const
895{
896    SymbolFileDWARF* dwarf2Data = nullptr;
897    const DWARFAbbreviationDeclaration* abbrevDecl = nullptr;
898    lldb::offset_t offset = 0;
899    if (cu)
900    {
901        if (m_tag != DW_TAG_compile_unit)
902        {
903            SymbolFileDWARFDwo* dwo_symbol_file = cu->GetDwoSymbolFile();
904            if (dwo_symbol_file)
905                return GetAttributes(dwo_symbol_file->GetCompileUnit(),
906                                     fixed_form_sizes,
907                                     attributes,
908                                     curr_depth);
909        }
910
911        dwarf2Data = cu->GetSymbolFileDWARF();
912        abbrevDecl = GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
913    }
914
915    if (abbrevDecl)
916    {
917        const DWARFDataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
918
919        if (fixed_form_sizes.Empty())
920            fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize(
921                    cu->GetAddressByteSize(), cu->IsDWARF64());
922
923        const uint32_t num_attributes = abbrevDecl->NumAttributes();
924        uint32_t i;
925        dw_attr_t attr;
926        dw_form_t form;
927        for (i=0; i<num_attributes; ++i)
928        {
929            abbrevDecl->GetAttrAndFormByIndexUnchecked (i, attr, form);
930
931            // If we are tracking down DW_AT_specification or DW_AT_abstract_origin
932            // attributes, the depth will be non-zero. We need to omit certain
933            // attributes that don't make sense.
934            switch (attr)
935            {
936            case DW_AT_sibling:
937            case DW_AT_declaration:
938                if (curr_depth > 0)
939                {
940                    // This attribute doesn't make sense when combined with
941                    // the DIE that references this DIE. We know a DIE is
942                    // referencing this DIE because curr_depth is not zero
943                    break;
944                }
945                LLVM_FALLTHROUGH;
946            default:
947                attributes.Append(cu, offset, attr, form);
948                break;
949            }
950
951            if ((attr == DW_AT_specification) || (attr == DW_AT_abstract_origin))
952            {
953                DWARFFormValue form_value (cu, form);
954                if (form_value.ExtractValue(debug_info_data, &offset))
955                {
956                    dw_offset_t die_offset = form_value.Reference();
957                    DWARFDIE spec_die = const_cast<DWARFCompileUnit*>(cu)->GetDIE(die_offset);
958                    if (spec_die)
959                        spec_die.GetAttributes(attributes, curr_depth + 1);
960                }
961            }
962            else
963            {
964                const uint8_t fixed_skip_size = fixed_form_sizes.GetSize(form);
965                if (fixed_skip_size)
966                    offset += fixed_skip_size;
967                else
968                    DWARFFormValue::SkipValue(form, debug_info_data, &offset, cu);
969            }
970        }
971    }
972    else
973    {
974        attributes.Clear();
975    }
976    return attributes.Size();
977
978}
979
980//----------------------------------------------------------------------
981// GetAttributeValue
982//
983// Get the value of an attribute and return the .debug_info offset of the
984// attribute if it was properly extracted into form_value, or zero
985// if we fail since an offset of zero is invalid for an attribute (it
986// would be a compile unit header).
987//----------------------------------------------------------------------
988dw_offset_t
989DWARFDebugInfoEntry::GetAttributeValue
990(
991    SymbolFileDWARF* dwarf2Data,
992    const DWARFCompileUnit* cu,
993    const dw_attr_t attr,
994    DWARFFormValue& form_value,
995    dw_offset_t* end_attr_offset_ptr,
996    bool check_specification_or_abstract_origin
997) const
998{
999    SymbolFileDWARFDwo* dwo_symbol_file = cu->GetDwoSymbolFile();
1000    if (dwo_symbol_file && m_tag != DW_TAG_compile_unit)
1001        return GetAttributeValue(dwo_symbol_file,
1002                                 dwo_symbol_file->GetCompileUnit(),
1003                                 attr,
1004                                 form_value,
1005                                 end_attr_offset_ptr,
1006                                 check_specification_or_abstract_origin);
1007
1008    lldb::offset_t offset;
1009    const DWARFAbbreviationDeclaration* abbrevDecl = GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
1010
1011    if (abbrevDecl)
1012    {
1013        uint32_t attr_idx = abbrevDecl->FindAttributeIndex(attr);
1014
1015        if (attr_idx != DW_INVALID_INDEX)
1016        {
1017            const DWARFDataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
1018
1019            uint32_t idx=0;
1020            while (idx<attr_idx)
1021                DWARFFormValue::SkipValue(abbrevDecl->GetFormByIndex(idx++), debug_info_data, &offset, cu);
1022
1023            const dw_offset_t attr_offset = offset;
1024            form_value.SetCompileUnit(cu);
1025            form_value.SetForm(abbrevDecl->GetFormByIndex(idx));
1026            if (form_value.ExtractValue(debug_info_data, &offset))
1027            {
1028                if (end_attr_offset_ptr)
1029                    *end_attr_offset_ptr = offset;
1030                return attr_offset;
1031            }
1032        }
1033    }
1034
1035    if (check_specification_or_abstract_origin)
1036    {
1037        if (GetAttributeValue(dwarf2Data, cu, DW_AT_specification, form_value))
1038        {
1039            DWARFDIE die = const_cast<DWARFCompileUnit*>(cu)->GetDIE(form_value.Reference());
1040            if (die)
1041            {
1042                dw_offset_t die_offset = die.GetDIE()->GetAttributeValue(die.GetDWARF(),
1043                                                                         die.GetCU(),
1044                                                                         attr,
1045                                                                         form_value,
1046                                                                         end_attr_offset_ptr,
1047                                                                         false);
1048                if (die_offset)
1049                    return die_offset;
1050            }
1051        }
1052
1053        if (GetAttributeValue(dwarf2Data, cu, DW_AT_abstract_origin, form_value))
1054        {
1055            DWARFDIE die = const_cast<DWARFCompileUnit*>(cu)->GetDIE(form_value.Reference());
1056            if (die)
1057            {
1058                dw_offset_t die_offset = die.GetDIE()->GetAttributeValue(die.GetDWARF(),
1059                                                                         die.GetCU(),
1060                                                                         attr,
1061                                                                         form_value,
1062                                                                         end_attr_offset_ptr,
1063                                                                         false);
1064                if (die_offset)
1065                    return die_offset;
1066            }
1067        }
1068    }
1069
1070    if (!dwo_symbol_file)
1071        return 0;
1072
1073    DWARFCompileUnit* dwo_cu = dwo_symbol_file->GetCompileUnit();
1074    if (!dwo_cu)
1075        return 0;
1076
1077    DWARFDIE dwo_cu_die = dwo_cu->GetCompileUnitDIEOnly();
1078    if (!dwo_cu_die.IsValid())
1079        return 0;
1080
1081    return dwo_cu_die.GetDIE()->GetAttributeValue(dwo_symbol_file,
1082                                                  dwo_cu,
1083                                                  attr,
1084                                                  form_value,
1085                                                  end_attr_offset_ptr,
1086                                                  check_specification_or_abstract_origin);
1087}
1088
1089//----------------------------------------------------------------------
1090// GetAttributeValueAsString
1091//
1092// Get the value of an attribute as a string return it. The resulting
1093// pointer to the string data exists within the supplied SymbolFileDWARF
1094// and will only be available as long as the SymbolFileDWARF is still around
1095// and it's content doesn't change.
1096//----------------------------------------------------------------------
1097const char*
1098DWARFDebugInfoEntry::GetAttributeValueAsString
1099(
1100    SymbolFileDWARF* dwarf2Data,
1101    const DWARFCompileUnit* cu,
1102    const dw_attr_t attr,
1103    const char* fail_value,
1104    bool check_specification_or_abstract_origin) const
1105{
1106    DWARFFormValue form_value;
1107    if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr, check_specification_or_abstract_origin))
1108        return form_value.AsCString();
1109    return fail_value;
1110}
1111
1112//----------------------------------------------------------------------
1113// GetAttributeValueAsUnsigned
1114//
1115// Get the value of an attribute as unsigned and return it.
1116//----------------------------------------------------------------------
1117uint64_t
1118DWARFDebugInfoEntry::GetAttributeValueAsUnsigned
1119(
1120    SymbolFileDWARF* dwarf2Data,
1121    const DWARFCompileUnit* cu,
1122    const dw_attr_t attr,
1123    uint64_t fail_value,
1124    bool check_specification_or_abstract_origin
1125) const
1126{
1127    DWARFFormValue form_value;
1128    if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr, check_specification_or_abstract_origin))
1129        return form_value.Unsigned();
1130    return fail_value;
1131}
1132
1133//----------------------------------------------------------------------
1134// GetAttributeValueAsSigned
1135//
1136// Get the value of an attribute a signed value and return it.
1137//----------------------------------------------------------------------
1138int64_t
1139DWARFDebugInfoEntry::GetAttributeValueAsSigned
1140(
1141    SymbolFileDWARF* dwarf2Data,
1142    const DWARFCompileUnit* cu,
1143    const dw_attr_t attr,
1144    int64_t fail_value,
1145    bool check_specification_or_abstract_origin
1146) const
1147{
1148    DWARFFormValue form_value;
1149    if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr, check_specification_or_abstract_origin))
1150        return form_value.Signed();
1151    return fail_value;
1152}
1153
1154//----------------------------------------------------------------------
1155// GetAttributeValueAsReference
1156//
1157// Get the value of an attribute as reference and fix up and compile
1158// unit relative offsets as needed.
1159//----------------------------------------------------------------------
1160uint64_t
1161DWARFDebugInfoEntry::GetAttributeValueAsReference
1162(
1163    SymbolFileDWARF* dwarf2Data,
1164    const DWARFCompileUnit* cu,
1165    const dw_attr_t attr,
1166    uint64_t fail_value,
1167    bool check_specification_or_abstract_origin
1168) const
1169{
1170    DWARFFormValue form_value;
1171    if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr, check_specification_or_abstract_origin))
1172        return form_value.Reference();
1173    return fail_value;
1174}
1175
1176uint64_t
1177DWARFDebugInfoEntry::GetAttributeValueAsAddress
1178(
1179    SymbolFileDWARF* dwarf2Data,
1180    const DWARFCompileUnit* cu,
1181    const dw_attr_t attr,
1182    uint64_t fail_value,
1183    bool check_specification_or_abstract_origin
1184) const
1185{
1186    DWARFFormValue form_value;
1187    if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr, check_specification_or_abstract_origin))
1188        return form_value.Address();
1189    return fail_value;
1190}
1191
1192//----------------------------------------------------------------------
1193// GetAttributeHighPC
1194//
1195// Get the hi_pc, adding hi_pc to lo_pc when specified
1196// as an <offset-from-low-pc>.
1197//
1198// Returns the hi_pc or fail_value.
1199//----------------------------------------------------------------------
1200dw_addr_t
1201DWARFDebugInfoEntry::GetAttributeHighPC
1202(
1203    SymbolFileDWARF* dwarf2Data,
1204    const DWARFCompileUnit* cu,
1205    dw_addr_t lo_pc,
1206    uint64_t fail_value,
1207    bool check_specification_or_abstract_origin
1208) const
1209{
1210    DWARFFormValue form_value;
1211    if (GetAttributeValue(dwarf2Data, cu, DW_AT_high_pc, form_value, nullptr, check_specification_or_abstract_origin))
1212    {
1213        dw_form_t form = form_value.Form();
1214        if (form == DW_FORM_addr || form == DW_FORM_GNU_addr_index)
1215            return form_value.Address();
1216
1217        // DWARF4 can specify the hi_pc as an <offset-from-lowpc>
1218        return lo_pc + form_value.Unsigned();
1219    }
1220    return fail_value;
1221}
1222
1223//----------------------------------------------------------------------
1224// GetAttributeAddressRange
1225//
1226// Get the lo_pc and hi_pc, adding hi_pc to lo_pc when specified
1227// as an <offset-from-low-pc>.
1228//
1229// Returns true or sets lo_pc and hi_pc to fail_value.
1230//----------------------------------------------------------------------
1231bool
1232DWARFDebugInfoEntry::GetAttributeAddressRange
1233(
1234    SymbolFileDWARF* dwarf2Data,
1235    const DWARFCompileUnit* cu,
1236    dw_addr_t& lo_pc,
1237    dw_addr_t& hi_pc,
1238    uint64_t fail_value,
1239    bool check_specification_or_abstract_origin
1240) const
1241{
1242    lo_pc = GetAttributeValueAsAddress(dwarf2Data, cu, DW_AT_low_pc, fail_value, check_specification_or_abstract_origin);
1243    if (lo_pc != fail_value)
1244    {
1245        hi_pc = GetAttributeHighPC(dwarf2Data, cu, lo_pc, fail_value, check_specification_or_abstract_origin);
1246        if (hi_pc != fail_value)
1247          return true;
1248    }
1249    lo_pc = fail_value;
1250    hi_pc = fail_value;
1251    return false;
1252}
1253
1254size_t
1255DWARFDebugInfoEntry::GetAttributeAddressRanges (SymbolFileDWARF* dwarf2Data,
1256                                                const DWARFCompileUnit* cu,
1257                                                DWARFRangeList &ranges,
1258                                                bool check_hi_lo_pc,
1259                                                bool check_specification_or_abstract_origin) const
1260{
1261    ranges.Clear();
1262
1263    dw_offset_t debug_ranges_offset = GetAttributeValueAsUnsigned(dwarf2Data,
1264                                                                  cu,
1265                                                                  DW_AT_ranges,
1266                                                                  DW_INVALID_OFFSET,
1267                                                                  check_specification_or_abstract_origin);
1268    if (debug_ranges_offset != DW_INVALID_OFFSET)
1269    {
1270        DWARFDebugRanges* debug_ranges = dwarf2Data->DebugRanges();
1271
1272        debug_ranges->FindRanges(debug_ranges_offset, ranges);
1273        ranges.Slide (cu->GetBaseAddress());
1274    }
1275    else if (check_hi_lo_pc)
1276    {
1277        dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
1278        dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
1279        if (GetAttributeAddressRange (dwarf2Data, cu, lo_pc, hi_pc, LLDB_INVALID_ADDRESS, check_specification_or_abstract_origin))
1280        {
1281            if (lo_pc < hi_pc)
1282                ranges.Append(DWARFRangeList::Entry(lo_pc, hi_pc - lo_pc));
1283        }
1284    }
1285    return ranges.GetSize();
1286}
1287
1288//----------------------------------------------------------------------
1289// GetName
1290//
1291// Get value of the DW_AT_name attribute and return it if one exists,
1292// else return NULL.
1293//----------------------------------------------------------------------
1294const char*
1295DWARFDebugInfoEntry::GetName
1296(
1297    SymbolFileDWARF* dwarf2Data,
1298    const DWARFCompileUnit* cu
1299) const
1300{
1301    return GetAttributeValueAsString(dwarf2Data, cu, DW_AT_name, nullptr, true);
1302}
1303
1304//----------------------------------------------------------------------
1305// GetMangledName
1306//
1307// Get value of the DW_AT_MIPS_linkage_name attribute and return it if
1308// one exists, else return the value of the DW_AT_name attribute
1309//----------------------------------------------------------------------
1310const char*
1311DWARFDebugInfoEntry::GetMangledName
1312(
1313    SymbolFileDWARF* dwarf2Data,
1314    const DWARFCompileUnit* cu,
1315    bool substitute_name_allowed
1316) const
1317{
1318    const char* name = nullptr;
1319
1320    name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_MIPS_linkage_name, nullptr, true);
1321    if (name)
1322        return name;
1323
1324    name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_linkage_name, nullptr, true);
1325    if (name)
1326        return name;
1327
1328    if (!substitute_name_allowed)
1329        return nullptr;
1330
1331    name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_name, nullptr, true);
1332    return name;
1333}
1334
1335
1336//----------------------------------------------------------------------
1337// GetPubname
1338//
1339// Get value the name for a DIE as it should appear for a
1340// .debug_pubnames or .debug_pubtypes section.
1341//----------------------------------------------------------------------
1342const char*
1343DWARFDebugInfoEntry::GetPubname
1344(
1345    SymbolFileDWARF* dwarf2Data,
1346    const DWARFCompileUnit* cu
1347) const
1348{
1349    const char* name = nullptr;
1350    if (!dwarf2Data)
1351        return name;
1352
1353    name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_MIPS_linkage_name, nullptr, true);
1354    if (name)
1355        return name;
1356
1357    name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_linkage_name, nullptr, true);
1358    if (name)
1359        return name;
1360
1361    name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_name, nullptr, true);
1362    return name;
1363}
1364
1365
1366//----------------------------------------------------------------------
1367// GetName
1368//
1369// Get value of the DW_AT_name attribute for a debug information entry
1370// that exists at offset "die_offset" and place that value into the
1371// supplied stream object. If the DIE is a NULL object "NULL" is placed
1372// into the stream, and if no DW_AT_name attribute exists for the DIE
1373// then nothing is printed.
1374//----------------------------------------------------------------------
1375bool
1376DWARFDebugInfoEntry::GetName
1377(
1378    SymbolFileDWARF* dwarf2Data,
1379    const DWARFCompileUnit* cu,
1380    const dw_offset_t die_offset,
1381    Stream &s
1382)
1383{
1384    if (dwarf2Data == NULL)
1385    {
1386        s.PutCString("NULL");
1387        return false;
1388    }
1389
1390    DWARFDebugInfoEntry die;
1391    lldb::offset_t offset = die_offset;
1392    if (die.Extract(dwarf2Data, cu, &offset))
1393    {
1394        if (die.IsNULL())
1395        {
1396            s.PutCString("NULL");
1397            return true;
1398        }
1399        else
1400        {
1401            const char* name = die.GetAttributeValueAsString(dwarf2Data, cu, DW_AT_name, nullptr, true);
1402            if (name)
1403            {
1404                s.PutCString(name);
1405                return true;
1406            }
1407        }
1408    }
1409    return false;
1410}
1411
1412//----------------------------------------------------------------------
1413// AppendTypeName
1414//
1415// Follows the type name definition down through all needed tags to
1416// end up with a fully qualified type name and dump the results to
1417// the supplied stream. This is used to show the name of types given
1418// a type identifier.
1419//----------------------------------------------------------------------
1420bool
1421DWARFDebugInfoEntry::AppendTypeName
1422(
1423    SymbolFileDWARF* dwarf2Data,
1424    const DWARFCompileUnit* cu,
1425    const dw_offset_t die_offset,
1426    Stream &s
1427)
1428{
1429    if (dwarf2Data == NULL)
1430    {
1431        s.PutCString("NULL");
1432        return false;
1433    }
1434
1435    DWARFDebugInfoEntry die;
1436    lldb::offset_t offset = die_offset;
1437    if (die.Extract(dwarf2Data, cu, &offset))
1438    {
1439        if (die.IsNULL())
1440        {
1441            s.PutCString("NULL");
1442            return true;
1443        }
1444        else
1445        {
1446            const char* name = die.GetPubname(dwarf2Data, cu);
1447            if (name)
1448                s.PutCString(name);
1449            else
1450            {
1451                bool result = true;
1452                const DWARFAbbreviationDeclaration* abbrevDecl = die.GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
1453
1454                if (abbrevDecl == NULL)
1455                    return false;
1456
1457                switch (abbrevDecl->Tag())
1458                {
1459                case DW_TAG_array_type:         break;  // print out a "[]" after printing the full type of the element below
1460                case DW_TAG_base_type:          s.PutCString("base ");         break;
1461                case DW_TAG_class_type:         s.PutCString("class ");            break;
1462                case DW_TAG_const_type:         s.PutCString("const ");            break;
1463                case DW_TAG_enumeration_type:   s.PutCString("enum ");         break;
1464                case DW_TAG_file_type:          s.PutCString("file ");         break;
1465                case DW_TAG_interface_type:     s.PutCString("interface ");        break;
1466                case DW_TAG_packed_type:        s.PutCString("packed ");       break;
1467                case DW_TAG_pointer_type:       break;  // print out a '*' after printing the full type below
1468                case DW_TAG_ptr_to_member_type: break;  // print out a '*' after printing the full type below
1469                case DW_TAG_reference_type:     break;  // print out a '&' after printing the full type below
1470                case DW_TAG_restrict_type:      s.PutCString("restrict ");     break;
1471                case DW_TAG_set_type:           s.PutCString("set ");          break;
1472                case DW_TAG_shared_type:        s.PutCString("shared ");       break;
1473                case DW_TAG_string_type:        s.PutCString("string ");       break;
1474                case DW_TAG_structure_type:     s.PutCString("struct ");       break;
1475                case DW_TAG_subrange_type:      s.PutCString("subrange ");     break;
1476                case DW_TAG_subroutine_type:    s.PutCString("function ");     break;
1477                case DW_TAG_thrown_type:        s.PutCString("thrown ");       break;
1478                case DW_TAG_union_type:         s.PutCString("union ");            break;
1479                case DW_TAG_unspecified_type:   s.PutCString("unspecified ");  break;
1480                case DW_TAG_volatile_type:      s.PutCString("volatile ");     break;
1481                default:
1482                    return false;
1483                }
1484
1485                // Follow the DW_AT_type if possible
1486                DWARFFormValue form_value;
1487                if (die.GetAttributeValue(dwarf2Data, cu, DW_AT_type, form_value))
1488                {
1489                    uint64_t next_die_offset = form_value.Reference();
1490                    result = AppendTypeName(dwarf2Data, cu, next_die_offset, s);
1491                }
1492
1493                switch (abbrevDecl->Tag())
1494                {
1495                case DW_TAG_array_type:         s.PutCString("[]");    break;
1496                case DW_TAG_pointer_type:       s.PutChar('*');    break;
1497                case DW_TAG_ptr_to_member_type: s.PutChar('*');    break;
1498                case DW_TAG_reference_type:     s.PutChar('&');    break;
1499                default:
1500                    break;
1501                }
1502                return result;
1503            }
1504        }
1505    }
1506    return false;
1507}
1508
1509bool
1510DWARFDebugInfoEntry::Contains (const DWARFDebugInfoEntry *die) const
1511{
1512    if (die)
1513    {
1514        const dw_offset_t die_offset = die->GetOffset();
1515        if (die_offset > GetOffset())
1516        {
1517            const DWARFDebugInfoEntry *sibling = GetSibling();
1518            assert (sibling); // TODO: take this out
1519            if (sibling)
1520                return die_offset < sibling->GetOffset();
1521        }
1522    }
1523    return false;
1524}
1525
1526//----------------------------------------------------------------------
1527// BuildAddressRangeTable
1528//----------------------------------------------------------------------
1529void
1530DWARFDebugInfoEntry::BuildAddressRangeTable
1531(
1532    SymbolFileDWARF* dwarf2Data,
1533    const DWARFCompileUnit* cu,
1534    DWARFDebugAranges* debug_aranges
1535) const
1536{
1537    if (m_tag)
1538    {
1539        if (m_tag == DW_TAG_subprogram)
1540        {
1541            dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
1542            dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
1543            if (GetAttributeAddressRange(dwarf2Data, cu, lo_pc, hi_pc, LLDB_INVALID_ADDRESS))
1544            {
1545                /// printf("BuildAddressRangeTable() 0x%8.8x: %30s: [0x%8.8x - 0x%8.8x)\n", m_offset, DW_TAG_value_to_name(tag), lo_pc, hi_pc);
1546                debug_aranges->AppendRange (cu->GetOffset(), lo_pc, hi_pc);
1547            }
1548        }
1549
1550
1551        const DWARFDebugInfoEntry* child = GetFirstChild();
1552        while (child)
1553        {
1554            child->BuildAddressRangeTable(dwarf2Data, cu, debug_aranges);
1555            child = child->GetSibling();
1556        }
1557    }
1558}
1559
1560//----------------------------------------------------------------------
1561// BuildFunctionAddressRangeTable
1562//
1563// This function is very similar to the BuildAddressRangeTable function
1564// except that the actual DIE offset for the function is placed in the
1565// table instead of the compile unit offset (which is the way the
1566// standard .debug_aranges section does it).
1567//----------------------------------------------------------------------
1568void
1569DWARFDebugInfoEntry::BuildFunctionAddressRangeTable
1570(
1571    SymbolFileDWARF* dwarf2Data,
1572    const DWARFCompileUnit* cu,
1573    DWARFDebugAranges* debug_aranges
1574) const
1575{
1576    if (m_tag)
1577    {
1578        if (m_tag == DW_TAG_subprogram)
1579        {
1580            dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
1581            dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
1582            if (GetAttributeAddressRange(dwarf2Data, cu, lo_pc, hi_pc, LLDB_INVALID_ADDRESS))
1583            {
1584            //  printf("BuildAddressRangeTable() 0x%8.8x: [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ")\n", m_offset, lo_pc, hi_pc); // DEBUG ONLY
1585                debug_aranges->AppendRange (GetOffset(), lo_pc, hi_pc);
1586            }
1587        }
1588
1589        const DWARFDebugInfoEntry* child = GetFirstChild();
1590        while (child)
1591        {
1592            child->BuildFunctionAddressRangeTable(dwarf2Data, cu, debug_aranges);
1593            child = child->GetSibling();
1594        }
1595    }
1596}
1597
1598void
1599DWARFDebugInfoEntry::GetDeclContextDIEs (DWARFCompileUnit* cu,
1600                                         DWARFDIECollection &decl_context_dies) const
1601{
1602
1603    DWARFDIE die (cu, const_cast<DWARFDebugInfoEntry *>(this));
1604    die.GetDeclContextDIEs(decl_context_dies);
1605}
1606
1607void
1608DWARFDebugInfoEntry::GetDWARFDeclContext (SymbolFileDWARF* dwarf2Data,
1609                                          DWARFCompileUnit* cu,
1610                                          DWARFDeclContext &dwarf_decl_ctx) const
1611{
1612    const dw_tag_t tag = Tag();
1613    if (tag != DW_TAG_compile_unit)
1614    {
1615        dwarf_decl_ctx.AppendDeclContext(tag, GetName(dwarf2Data, cu));
1616        DWARFDIE parent_decl_ctx_die = GetParentDeclContextDIE (dwarf2Data, cu);
1617        if (parent_decl_ctx_die && parent_decl_ctx_die.GetDIE() != this)
1618        {
1619            if (parent_decl_ctx_die.Tag() != DW_TAG_compile_unit)
1620                parent_decl_ctx_die.GetDIE()->GetDWARFDeclContext (parent_decl_ctx_die.GetDWARF(), parent_decl_ctx_die.GetCU(), dwarf_decl_ctx);
1621        }
1622    }
1623}
1624
1625
1626bool
1627DWARFDebugInfoEntry::MatchesDWARFDeclContext (SymbolFileDWARF* dwarf2Data,
1628                                              DWARFCompileUnit* cu,
1629                                              const DWARFDeclContext &dwarf_decl_ctx) const
1630{
1631
1632    DWARFDeclContext this_dwarf_decl_ctx;
1633    GetDWARFDeclContext (dwarf2Data, cu, this_dwarf_decl_ctx);
1634    return this_dwarf_decl_ctx == dwarf_decl_ctx;
1635}
1636
1637DWARFDIE
1638DWARFDebugInfoEntry::GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data,
1639											  DWARFCompileUnit* cu) const
1640{
1641	DWARFAttributes attributes;
1642	GetAttributes(cu, DWARFFormValue::FixedFormSizes(), attributes);
1643	return GetParentDeclContextDIE (dwarf2Data, cu, attributes);
1644}
1645
1646DWARFDIE
1647DWARFDebugInfoEntry::GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data,
1648											  DWARFCompileUnit* cu,
1649											  const DWARFAttributes& attributes) const
1650{
1651    DWARFDIE die (cu, const_cast<DWARFDebugInfoEntry *>(this));
1652
1653	while (die)
1654	{
1655		// If this is the original DIE that we are searching for a declaration
1656		// for, then don't look in the cache as we don't want our own decl
1657		// context to be our decl context...
1658		if (die.GetDIE() != this)
1659		{
1660			switch (die.Tag())
1661			{
1662				case DW_TAG_compile_unit:
1663				case DW_TAG_namespace:
1664				case DW_TAG_structure_type:
1665				case DW_TAG_union_type:
1666				case DW_TAG_class_type:
1667					return die;
1668
1669				default:
1670					break;
1671			}
1672		}
1673
1674		dw_offset_t die_offset;
1675
1676		die_offset = attributes.FormValueAsUnsigned(DW_AT_specification, DW_INVALID_OFFSET);
1677		if (die_offset != DW_INVALID_OFFSET)
1678		{
1679			DWARFDIE spec_die = cu->GetDIE (die_offset);
1680			if (spec_die)
1681            {
1682                DWARFDIE decl_ctx_die = spec_die.GetParentDeclContextDIE();
1683                if (decl_ctx_die)
1684                    return decl_ctx_die;
1685            }
1686		}
1687
1688        die_offset = attributes.FormValueAsUnsigned(DW_AT_abstract_origin, DW_INVALID_OFFSET);
1689		if (die_offset != DW_INVALID_OFFSET)
1690		{
1691            DWARFDIE abs_die = cu->GetDIE (die_offset);
1692			if (abs_die)
1693			{
1694                DWARFDIE decl_ctx_die = abs_die.GetParentDeclContextDIE();
1695                if (decl_ctx_die)
1696                    return decl_ctx_die;
1697			}
1698		}
1699
1700		die = die.GetParent();
1701	}
1702    return DWARFDIE();
1703}
1704
1705
1706const char *
1707DWARFDebugInfoEntry::GetQualifiedName (SymbolFileDWARF* dwarf2Data,
1708									   DWARFCompileUnit* cu,
1709									   std::string &storage) const
1710{
1711	DWARFAttributes attributes;
1712	GetAttributes(cu, DWARFFormValue::FixedFormSizes(), attributes);
1713	return GetQualifiedName (dwarf2Data, cu, attributes, storage);
1714}
1715
1716const char*
1717DWARFDebugInfoEntry::GetQualifiedName (SymbolFileDWARF* dwarf2Data,
1718									   DWARFCompileUnit* cu,
1719									   const DWARFAttributes& attributes,
1720									   std::string &storage) const
1721{
1722
1723	const char *name = GetName (dwarf2Data, cu);
1724
1725	if (name)
1726	{
1727		DWARFDIE parent_decl_ctx_die = GetParentDeclContextDIE (dwarf2Data, cu);
1728		storage.clear();
1729		// TODO: change this to get the correct decl context parent....
1730		while (parent_decl_ctx_die)
1731		{
1732			const dw_tag_t parent_tag = parent_decl_ctx_die.Tag();
1733			switch (parent_tag)
1734			{
1735                case DW_TAG_namespace:
1736                    {
1737                        const char *namespace_name = parent_decl_ctx_die.GetName ();
1738                        if (namespace_name)
1739                        {
1740                            storage.insert (0, "::");
1741                            storage.insert (0, namespace_name);
1742                        }
1743                        else
1744                        {
1745                            storage.insert (0, "(anonymous namespace)::");
1746                        }
1747                        parent_decl_ctx_die = parent_decl_ctx_die.GetParentDeclContextDIE();
1748                    }
1749                    break;
1750
1751                case DW_TAG_class_type:
1752                case DW_TAG_structure_type:
1753                case DW_TAG_union_type:
1754                    {
1755                        const char *class_union_struct_name = parent_decl_ctx_die.GetName ();
1756
1757                        if (class_union_struct_name)
1758                        {
1759                            storage.insert (0, "::");
1760                            storage.insert (0, class_union_struct_name);
1761                        }
1762                        parent_decl_ctx_die = parent_decl_ctx_die.GetParentDeclContextDIE();
1763                    }
1764                    break;
1765
1766                default:
1767                    parent_decl_ctx_die.Clear();
1768                    break;
1769			}
1770		}
1771
1772		if (storage.empty())
1773			storage.append ("::");
1774
1775		storage.append (name);
1776	}
1777	if (storage.empty())
1778		return NULL;
1779	return storage.c_str();
1780}
1781
1782
1783//----------------------------------------------------------------------
1784// LookupAddress
1785//----------------------------------------------------------------------
1786bool
1787DWARFDebugInfoEntry::LookupAddress
1788(
1789    const dw_addr_t address,
1790    SymbolFileDWARF* dwarf2Data,
1791    const DWARFCompileUnit* cu,
1792    DWARFDebugInfoEntry** function_die,
1793    DWARFDebugInfoEntry** block_die
1794)
1795{
1796    bool found_address = false;
1797    if (m_tag)
1798    {
1799        bool check_children = false;
1800        bool match_addr_range = false;
1801    //  printf("0x%8.8x: %30s: address = 0x%8.8x - ", m_offset, DW_TAG_value_to_name(tag), address);
1802        switch (m_tag)
1803        {
1804        case DW_TAG_array_type                 : break;
1805        case DW_TAG_class_type                 : check_children = true; break;
1806        case DW_TAG_entry_point                : break;
1807        case DW_TAG_enumeration_type           : break;
1808        case DW_TAG_formal_parameter           : break;
1809        case DW_TAG_imported_declaration       : break;
1810        case DW_TAG_label                      : break;
1811        case DW_TAG_lexical_block              : check_children = true; match_addr_range = true; break;
1812        case DW_TAG_member                     : break;
1813        case DW_TAG_pointer_type               : break;
1814        case DW_TAG_reference_type             : break;
1815        case DW_TAG_compile_unit               : match_addr_range = true; break;
1816        case DW_TAG_string_type                : break;
1817        case DW_TAG_structure_type             : check_children = true; break;
1818        case DW_TAG_subroutine_type            : break;
1819        case DW_TAG_typedef                    : break;
1820        case DW_TAG_union_type                 : break;
1821        case DW_TAG_unspecified_parameters     : break;
1822        case DW_TAG_variant                    : break;
1823        case DW_TAG_common_block               : check_children = true; break;
1824        case DW_TAG_common_inclusion           : break;
1825        case DW_TAG_inheritance                : break;
1826        case DW_TAG_inlined_subroutine         : check_children = true; match_addr_range = true; break;
1827        case DW_TAG_module                     : match_addr_range = true; break;
1828        case DW_TAG_ptr_to_member_type         : break;
1829        case DW_TAG_set_type                   : break;
1830        case DW_TAG_subrange_type              : break;
1831        case DW_TAG_with_stmt                  : break;
1832        case DW_TAG_access_declaration         : break;
1833        case DW_TAG_base_type                  : break;
1834        case DW_TAG_catch_block                : match_addr_range = true; break;
1835        case DW_TAG_const_type                 : break;
1836        case DW_TAG_constant                   : break;
1837        case DW_TAG_enumerator                 : break;
1838        case DW_TAG_file_type                  : break;
1839        case DW_TAG_friend                     : break;
1840        case DW_TAG_namelist                   : break;
1841        case DW_TAG_namelist_item              : break;
1842        case DW_TAG_packed_type                : break;
1843        case DW_TAG_subprogram                 : match_addr_range = true; break;
1844        case DW_TAG_template_type_parameter    : break;
1845        case DW_TAG_template_value_parameter   : break;
1846        case DW_TAG_thrown_type                : break;
1847        case DW_TAG_try_block                  : match_addr_range = true; break;
1848        case DW_TAG_variant_part               : break;
1849        case DW_TAG_variable                   : break;
1850        case DW_TAG_volatile_type              : break;
1851        case DW_TAG_dwarf_procedure            : break;
1852        case DW_TAG_restrict_type              : break;
1853        case DW_TAG_interface_type             : break;
1854        case DW_TAG_namespace                  : check_children = true; break;
1855        case DW_TAG_imported_module            : break;
1856        case DW_TAG_unspecified_type           : break;
1857        case DW_TAG_partial_unit               : break;
1858        case DW_TAG_imported_unit              : break;
1859        case DW_TAG_shared_type                : break;
1860        default: break;
1861        }
1862
1863        if (match_addr_range)
1864        {
1865            dw_addr_t lo_pc = GetAttributeValueAsAddress(dwarf2Data, cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
1866            if (lo_pc != LLDB_INVALID_ADDRESS)
1867            {
1868                dw_addr_t hi_pc = GetAttributeHighPC(dwarf2Data, cu, lo_pc, LLDB_INVALID_ADDRESS);
1869                if (hi_pc != LLDB_INVALID_ADDRESS)
1870                {
1871                    //  printf("\n0x%8.8x: %30s: address = 0x%8.8x  [0x%8.8x - 0x%8.8x) ", m_offset, DW_TAG_value_to_name(tag), address, lo_pc, hi_pc);
1872                    if ((lo_pc <= address) && (address < hi_pc))
1873                    {
1874                        found_address = true;
1875                    //  puts("***MATCH***");
1876                        switch (m_tag)
1877                        {
1878                        case DW_TAG_compile_unit:       // File
1879                            check_children = ((function_die != NULL) || (block_die != NULL));
1880                            break;
1881
1882                        case DW_TAG_subprogram:         // Function
1883                            if (function_die)
1884                                *function_die = this;
1885                            check_children = (block_die != NULL);
1886                            break;
1887
1888                        case DW_TAG_inlined_subroutine: // Inlined Function
1889                        case DW_TAG_lexical_block:      // Block { } in code
1890                            if (block_die)
1891                            {
1892                                *block_die = this;
1893                                check_children = true;
1894                            }
1895                            break;
1896
1897                        default:
1898                            check_children = true;
1899                            break;
1900                        }
1901                    }
1902                }
1903                else
1904                {   // compile units may not have a valid high/low pc when there
1905                    // are address gaps in subroutines so we must always search
1906                    // if there is no valid high and low PC
1907                    check_children = (m_tag == DW_TAG_compile_unit) && ((function_die != NULL) || (block_die != NULL));
1908                }
1909            }
1910            else
1911            {
1912                dw_offset_t debug_ranges_offset = GetAttributeValueAsUnsigned(dwarf2Data, cu, DW_AT_ranges, DW_INVALID_OFFSET);
1913                if (debug_ranges_offset != DW_INVALID_OFFSET)
1914                {
1915                    DWARFRangeList ranges;
1916                    DWARFDebugRanges* debug_ranges = dwarf2Data->DebugRanges();
1917                    debug_ranges->FindRanges(debug_ranges_offset, ranges);
1918                    // All DW_AT_ranges are relative to the base address of the
1919                    // compile unit. We add the compile unit base address to make
1920                    // sure all the addresses are properly fixed up.
1921                    ranges.Slide (cu->GetBaseAddress());
1922                    if (ranges.FindEntryThatContains(address))
1923                    {
1924                        found_address = true;
1925                    //  puts("***MATCH***");
1926                        switch (m_tag)
1927                        {
1928                        case DW_TAG_compile_unit:       // File
1929                            check_children = ((function_die != NULL) || (block_die != NULL));
1930                            break;
1931
1932                        case DW_TAG_subprogram:         // Function
1933                            if (function_die)
1934                                *function_die = this;
1935                            check_children = (block_die != NULL);
1936                            break;
1937
1938                        case DW_TAG_inlined_subroutine: // Inlined Function
1939                        case DW_TAG_lexical_block:      // Block { } in code
1940                            if (block_die)
1941                            {
1942                                *block_die = this;
1943                                check_children = true;
1944                            }
1945                            break;
1946
1947                        default:
1948                            check_children = true;
1949                            break;
1950                        }
1951                    }
1952                    else
1953                    {
1954                        check_children = false;
1955                    }
1956                }
1957            }
1958        }
1959
1960
1961        if (check_children)
1962        {
1963        //  printf("checking children\n");
1964            DWARFDebugInfoEntry* child = GetFirstChild();
1965            while (child)
1966            {
1967                if (child->LookupAddress(address, dwarf2Data, cu, function_die, block_die))
1968                    return true;
1969                child = child->GetSibling();
1970            }
1971        }
1972    }
1973    return found_address;
1974}
1975
1976const DWARFAbbreviationDeclaration*
1977DWARFDebugInfoEntry::GetAbbreviationDeclarationPtr (SymbolFileDWARF* dwarf2Data,
1978                                                    const DWARFCompileUnit *cu,
1979                                                    lldb::offset_t &offset) const
1980{
1981    if (dwarf2Data)
1982    {
1983        offset = GetOffset();
1984
1985        const DWARFAbbreviationDeclarationSet *abbrev_set = cu->GetAbbreviations();
1986        if (abbrev_set)
1987        {
1988            const DWARFAbbreviationDeclaration* abbrev_decl = abbrev_set->GetAbbreviationDeclaration (m_abbr_idx);
1989            if (abbrev_decl)
1990            {
1991                // Make sure the abbreviation code still matches. If it doesn't and
1992                // the DWARF data was mmap'ed, the backing file might have been modified
1993                // which is bad news.
1994                const uint64_t abbrev_code = dwarf2Data->get_debug_info_data().GetULEB128 (&offset);
1995
1996                if (abbrev_decl->Code() == abbrev_code)
1997                    return abbrev_decl;
1998
1999                dwarf2Data->GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("0x%8.8x: the DWARF debug information has been modified (abbrev code was %u, and is now %u)",
2000                                                                                       GetOffset(),
2001                                                                                       (uint32_t)abbrev_decl->Code(),
2002                                                                                       (uint32_t)abbrev_code);
2003            }
2004        }
2005    }
2006    offset = DW_INVALID_OFFSET;
2007    return NULL;
2008}
2009
2010
2011bool
2012DWARFDebugInfoEntry::OffsetLessThan (const DWARFDebugInfoEntry& a, const DWARFDebugInfoEntry& b)
2013{
2014    return a.GetOffset() < b.GetOffset();
2015}
2016
2017void
2018DWARFDebugInfoEntry::DumpDIECollection (Stream &strm, DWARFDebugInfoEntry::collection &die_collection)
2019{
2020    DWARFDebugInfoEntry::const_iterator pos;
2021    DWARFDebugInfoEntry::const_iterator end = die_collection.end();
2022    strm.PutCString("\noffset    parent   sibling  child\n");
2023    strm.PutCString("--------  -------- -------- --------\n");
2024    for (pos = die_collection.begin(); pos != end; ++pos)
2025    {
2026        const DWARFDebugInfoEntry& die_ref = *pos;
2027        const DWARFDebugInfoEntry* p = die_ref.GetParent();
2028        const DWARFDebugInfoEntry* s = die_ref.GetSibling();
2029        const DWARFDebugInfoEntry* c = die_ref.GetFirstChild();
2030        strm.Printf("%.8x: %.8x %.8x %.8x 0x%4.4x %s%s\n",
2031                    die_ref.GetOffset(),
2032                    p ? p->GetOffset() : 0,
2033                    s ? s->GetOffset() : 0,
2034                    c ? c->GetOffset() : 0,
2035                    die_ref.Tag(),
2036                    DW_TAG_value_to_name(die_ref.Tag()),
2037                    die_ref.HasChildren() ? " *" : "");
2038    }
2039}
2040
2041
2042