SymbolFileDWARF.cpp revision fb7c51c07c249bd611051c76e4ff491f1a17cf2d
1//===-- SymbolFileDWARF.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 "SymbolFileDWARF.h"
11
12// Other libraries and framework includes
13#include "clang/AST/ASTConsumer.h"
14#include "clang/AST/ASTContext.h"
15#include "clang/AST/Decl.h"
16#include "clang/AST/DeclGroup.h"
17#include "clang/Basic/Builtins.h"
18#include "clang/Basic/IdentifierTable.h"
19#include "clang/Basic/LangOptions.h"
20#include "clang/Basic/SourceManager.h"
21#include "clang/Basic/TargetInfo.h"
22#include "clang/Basic/Specifiers.h"
23
24#include "lldb/Core/Module.h"
25#include "lldb/Core/PluginManager.h"
26#include "lldb/Core/RegularExpression.h"
27#include "lldb/Core/Scalar.h"
28#include "lldb/Core/Section.h"
29#include "lldb/Core/StreamFile.h"
30#include "lldb/Core/Timer.h"
31#include "lldb/Core/Value.h"
32
33#include "lldb/Symbol/Block.h"
34#include "lldb/Symbol/CompileUnit.h"
35#include "lldb/Symbol/LineTable.h"
36#include "lldb/Symbol/ObjectFile.h"
37#include "lldb/Symbol/SymbolVendor.h"
38#include "lldb/Symbol/VariableList.h"
39
40#include "DWARFCompileUnit.h"
41#include "DWARFDebugAbbrev.h"
42#include "DWARFDebugAranges.h"
43#include "DWARFDebugInfo.h"
44#include "DWARFDebugInfoEntry.h"
45#include "DWARFDebugLine.h"
46#include "DWARFDebugPubnames.h"
47#include "DWARFDebugRanges.h"
48#include "DWARFDIECollection.h"
49#include "DWARFFormValue.h"
50#include "DWARFLocationList.h"
51#include "LogChannelDWARF.h"
52#include "SymbolFileDWARFDebugMap.h"
53
54#include <map>
55
56//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
57
58#ifdef ENABLE_DEBUG_PRINTF
59#include <stdio.h>
60#define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
61#else
62#define DEBUG_PRINTF(fmt, ...)
63#endif
64
65#define DIE_IS_BEING_PARSED ((lldb_private::Type*)1)
66
67using namespace lldb;
68using namespace lldb_private;
69
70
71static AccessType
72DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility)
73{
74    switch (dwarf_accessibility)
75    {
76        case DW_ACCESS_public:      return eAccessPublic;
77        case DW_ACCESS_private:     return eAccessPrivate;
78        case DW_ACCESS_protected:   return eAccessProtected;
79        default:                    break;
80    }
81    return eAccessNone;
82}
83
84void
85SymbolFileDWARF::Initialize()
86{
87    LogChannelDWARF::Initialize();
88    PluginManager::RegisterPlugin (GetPluginNameStatic(),
89                                   GetPluginDescriptionStatic(),
90                                   CreateInstance);
91}
92
93void
94SymbolFileDWARF::Terminate()
95{
96    PluginManager::UnregisterPlugin (CreateInstance);
97    LogChannelDWARF::Initialize();
98}
99
100
101const char *
102SymbolFileDWARF::GetPluginNameStatic()
103{
104    return "symbol-file.dwarf2";
105}
106
107const char *
108SymbolFileDWARF::GetPluginDescriptionStatic()
109{
110    return "DWARF and DWARF3 debug symbol file reader.";
111}
112
113
114SymbolFile*
115SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
116{
117    return new SymbolFileDWARF(obj_file);
118}
119
120//----------------------------------------------------------------------
121// Gets the first parent that is a lexical block, function or inlined
122// subroutine, or compile unit.
123//----------------------------------------------------------------------
124static const DWARFDebugInfoEntry *
125GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die)
126{
127    const DWARFDebugInfoEntry *die;
128    for (die = child_die->GetParent(); die != NULL; die = die->GetParent())
129    {
130        dw_tag_t tag = die->Tag();
131
132        switch (tag)
133        {
134        case DW_TAG_compile_unit:
135        case DW_TAG_subprogram:
136        case DW_TAG_inlined_subroutine:
137        case DW_TAG_lexical_block:
138            return die;
139        }
140    }
141    return NULL;
142}
143
144
145SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
146    SymbolFile (objfile),
147    m_debug_map_symfile (NULL),
148    m_flags(),
149    m_data_debug_abbrev(),
150    m_data_debug_frame(),
151    m_data_debug_info(),
152    m_data_debug_line(),
153    m_data_debug_loc(),
154    m_data_debug_ranges(),
155    m_data_debug_str(),
156    m_abbr(),
157    m_aranges(),
158    m_info(),
159    m_line(),
160    m_function_basename_index(),
161    m_function_fullname_index(),
162    m_function_method_index(),
163    m_function_selector_index(),
164    m_objc_class_selectors_index(),
165    m_global_index(),
166    m_types_index(),
167    m_indexed(false),
168    m_ranges()
169{
170}
171
172SymbolFileDWARF::~SymbolFileDWARF()
173{
174}
175
176bool
177SymbolFileDWARF::SupportedVersion(uint16_t version)
178{
179    return version == 2 || version == 3;
180}
181
182uint32_t
183SymbolFileDWARF::GetAbilities ()
184{
185    uint32_t abilities = 0;
186    if (m_obj_file != NULL)
187    {
188        const Section* section = NULL;
189        const SectionList *section_list = m_obj_file->GetSectionList();
190        if (section_list == NULL)
191            return 0;
192
193        uint64_t debug_abbrev_file_size = 0;
194        uint64_t debug_aranges_file_size = 0;
195        uint64_t debug_frame_file_size = 0;
196        uint64_t debug_info_file_size = 0;
197        uint64_t debug_line_file_size = 0;
198        uint64_t debug_loc_file_size = 0;
199        uint64_t debug_macinfo_file_size = 0;
200        uint64_t debug_pubnames_file_size = 0;
201        uint64_t debug_pubtypes_file_size = 0;
202        uint64_t debug_ranges_file_size = 0;
203        uint64_t debug_str_file_size = 0;
204
205        static ConstString g_dwarf_section_name ("__DWARF");
206
207        section = section_list->FindSectionByName(g_dwarf_section_name).get();
208
209        if (section)
210        {
211            section->MemoryMapSectionDataFromObjectFile(m_obj_file, m_dwarf_data);
212            section_list = &section->GetChildren ();
213        }
214
215        section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
216        if (section != NULL)
217        {
218            debug_info_file_size = section->GetByteSize();
219
220            section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
221            if (section)
222                debug_abbrev_file_size = section->GetByteSize();
223            else
224                m_flags.Set (flagsGotDebugAbbrevData);
225
226            section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
227            if (section)
228                debug_aranges_file_size = section->GetByteSize();
229            else
230                m_flags.Set (flagsGotDebugArangesData);
231
232            section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
233            if (section)
234                debug_frame_file_size = section->GetByteSize();
235            else
236                m_flags.Set (flagsGotDebugFrameData);
237
238            section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
239            if (section)
240                debug_line_file_size = section->GetByteSize();
241            else
242                m_flags.Set (flagsGotDebugLineData);
243
244            section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
245            if (section)
246                debug_loc_file_size = section->GetByteSize();
247            else
248                m_flags.Set (flagsGotDebugLocData);
249
250            section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
251            if (section)
252                debug_macinfo_file_size = section->GetByteSize();
253            else
254                m_flags.Set (flagsGotDebugMacInfoData);
255
256            section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
257            if (section)
258                debug_pubnames_file_size = section->GetByteSize();
259            else
260                m_flags.Set (flagsGotDebugPubNamesData);
261
262            section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
263            if (section)
264                debug_pubtypes_file_size = section->GetByteSize();
265            else
266                m_flags.Set (flagsGotDebugPubTypesData);
267
268            section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
269            if (section)
270                debug_ranges_file_size = section->GetByteSize();
271            else
272                m_flags.Set (flagsGotDebugRangesData);
273
274            section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
275            if (section)
276                debug_str_file_size = section->GetByteSize();
277            else
278                m_flags.Set (flagsGotDebugStrData);
279        }
280
281        if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
282            abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
283
284        if (debug_line_file_size > 0)
285            abilities |= LineTables;
286
287        if (debug_aranges_file_size > 0)
288            abilities |= AddressAcceleratorTable;
289
290        if (debug_pubnames_file_size > 0)
291            abilities |= FunctionAcceleratorTable;
292
293        if (debug_pubtypes_file_size > 0)
294            abilities |= TypeAcceleratorTable;
295
296        if (debug_macinfo_file_size > 0)
297            abilities |= MacroInformation;
298
299        if (debug_frame_file_size > 0)
300            abilities |= CallFrameInformation;
301    }
302    return abilities;
303}
304
305const DataExtractor&
306SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data)
307{
308    if (m_flags.IsClear (got_flag))
309    {
310        m_flags.Set (got_flag);
311        const SectionList *section_list = m_obj_file->GetSectionList();
312        if (section_list)
313        {
314            Section *section = section_list->FindSectionByType(sect_type, true).get();
315            if (section)
316            {
317                // See if we memory mapped the DWARF segment?
318                if (m_dwarf_data.GetByteSize())
319                {
320                    data.SetData(m_dwarf_data, section->GetOffset (), section->GetByteSize());
321                }
322                else
323                {
324                    if (section->ReadSectionDataFromObjectFile(m_obj_file, data) == 0)
325                        data.Clear();
326                }
327            }
328        }
329    }
330    return data;
331}
332
333const DataExtractor&
334SymbolFileDWARF::get_debug_abbrev_data()
335{
336    return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
337}
338
339const DataExtractor&
340SymbolFileDWARF::get_debug_frame_data()
341{
342    return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
343}
344
345const DataExtractor&
346SymbolFileDWARF::get_debug_info_data()
347{
348    return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
349}
350
351const DataExtractor&
352SymbolFileDWARF::get_debug_line_data()
353{
354    return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
355}
356
357const DataExtractor&
358SymbolFileDWARF::get_debug_loc_data()
359{
360    return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
361}
362
363const DataExtractor&
364SymbolFileDWARF::get_debug_ranges_data()
365{
366    return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
367}
368
369const DataExtractor&
370SymbolFileDWARF::get_debug_str_data()
371{
372    return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
373}
374
375
376DWARFDebugAbbrev*
377SymbolFileDWARF::DebugAbbrev()
378{
379    if (m_abbr.get() == NULL)
380    {
381        const DataExtractor &debug_abbrev_data = get_debug_abbrev_data();
382        if (debug_abbrev_data.GetByteSize() > 0)
383        {
384            m_abbr.reset(new DWARFDebugAbbrev());
385            if (m_abbr.get())
386                m_abbr->Parse(debug_abbrev_data);
387        }
388    }
389    return m_abbr.get();
390}
391
392const DWARFDebugAbbrev*
393SymbolFileDWARF::DebugAbbrev() const
394{
395    return m_abbr.get();
396}
397
398DWARFDebugAranges*
399SymbolFileDWARF::DebugAranges()
400{
401    // It turns out that llvm-gcc doesn't generate .debug_aranges in .o files
402    // and we are already parsing all of the DWARF because the .debug_pubnames
403    // is useless (it only mentions symbols that are externally visible), so
404    // don't use the .debug_aranges section, we should be using a debug aranges
405    // we got from SymbolFileDWARF::Index().
406
407    if (!m_indexed)
408        Index();
409
410
411//    if (m_aranges.get() == NULL)
412//    {
413//        Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
414//        m_aranges.reset(new DWARFDebugAranges());
415//        if (m_aranges.get())
416//        {
417//            const DataExtractor &debug_aranges_data = get_debug_aranges_data();
418//            if (debug_aranges_data.GetByteSize() > 0)
419//                m_aranges->Extract(debug_aranges_data);
420//            else
421//                m_aranges->Generate(this);
422//        }
423//    }
424    return m_aranges.get();
425}
426
427const DWARFDebugAranges*
428SymbolFileDWARF::DebugAranges() const
429{
430    return m_aranges.get();
431}
432
433
434DWARFDebugInfo*
435SymbolFileDWARF::DebugInfo()
436{
437    if (m_info.get() == NULL)
438    {
439        Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
440        if (get_debug_info_data().GetByteSize() > 0)
441        {
442            m_info.reset(new DWARFDebugInfo());
443            if (m_info.get())
444            {
445                m_info->SetDwarfData(this);
446            }
447        }
448    }
449    return m_info.get();
450}
451
452const DWARFDebugInfo*
453SymbolFileDWARF::DebugInfo() const
454{
455    return m_info.get();
456}
457
458DWARFCompileUnit*
459SymbolFileDWARF::GetDWARFCompileUnitForUID(lldb::user_id_t cu_uid)
460{
461    DWARFDebugInfo* info = DebugInfo();
462    if (info)
463        return info->GetCompileUnit(cu_uid).get();
464    return NULL;
465}
466
467
468DWARFDebugRanges*
469SymbolFileDWARF::DebugRanges()
470{
471    if (m_ranges.get() == NULL)
472    {
473        Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
474        if (get_debug_ranges_data().GetByteSize() > 0)
475        {
476            m_ranges.reset(new DWARFDebugRanges());
477            if (m_ranges.get())
478                m_ranges->Extract(this);
479        }
480    }
481    return m_ranges.get();
482}
483
484const DWARFDebugRanges*
485SymbolFileDWARF::DebugRanges() const
486{
487    return m_ranges.get();
488}
489
490bool
491SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* cu, CompUnitSP& compile_unit_sp)
492{
493    if (cu != NULL)
494    {
495        const DWARFDebugInfoEntry * cu_die = cu->GetCompileUnitDIEOnly ();
496        if (cu_die)
497        {
498            const char * cu_die_name = cu_die->GetName(this, cu);
499            const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, cu, DW_AT_comp_dir, NULL);
500            LanguageType class_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, cu, DW_AT_language, 0);
501            if (cu_die_name)
502            {
503                FileSpec cu_file_spec;
504
505                if (cu_die_name[0] == '/' || cu_comp_dir == NULL && cu_comp_dir[0])
506                {
507                    // If we have a full path to the compile unit, we don't need to resolve
508                    // the file.  This can be expensive e.g. when the source files are NFS mounted.
509                    cu_file_spec.SetFile (cu_die_name, false);
510                }
511                else
512                {
513                    std::string fullpath(cu_comp_dir);
514                    if (*fullpath.rbegin() != '/')
515                        fullpath += '/';
516                    fullpath += cu_die_name;
517                    cu_file_spec.SetFile (fullpath.c_str(), false);
518                }
519
520                compile_unit_sp.reset(new CompileUnit(m_obj_file->GetModule(), cu, cu_file_spec, cu->GetOffset(), class_language));
521                if (compile_unit_sp.get())
522                {
523                    cu->SetUserData(compile_unit_sp.get());
524                    return true;
525                }
526            }
527        }
528    }
529    return false;
530}
531
532uint32_t
533SymbolFileDWARF::GetNumCompileUnits()
534{
535    DWARFDebugInfo* info = DebugInfo();
536    if (info)
537        return info->GetNumCompileUnits();
538    return 0;
539}
540
541CompUnitSP
542SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
543{
544    CompUnitSP comp_unit;
545    DWARFDebugInfo* info = DebugInfo();
546    if (info)
547    {
548        DWARFCompileUnit* cu = info->GetCompileUnitAtIndex(cu_idx);
549        if (cu != NULL)
550        {
551            // Our symbol vendor shouldn't be asking us to add a compile unit that
552            // has already been added to it, which this DWARF plug-in knows as it
553            // stores the lldb compile unit (CompileUnit) pointer in each
554            // DWARFCompileUnit object when it gets added.
555            assert(cu->GetUserData() == NULL);
556            ParseCompileUnit(cu, comp_unit);
557        }
558    }
559    return comp_unit;
560}
561
562static void
563AddRangesToBlock
564(
565    Block& block,
566    DWARFDebugRanges::RangeList& ranges,
567    addr_t block_base_addr
568)
569{
570    ranges.SubtractOffset (block_base_addr);
571    size_t range_idx = 0;
572    const DWARFDebugRanges::Range *debug_range;
573    for (range_idx = 0; (debug_range = ranges.RangeAtIndex(range_idx)) != NULL; range_idx++)
574    {
575        block.AddRange(debug_range->begin_offset, debug_range->end_offset);
576    }
577}
578
579
580Function *
581SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
582{
583    DWARFDebugRanges::RangeList func_ranges;
584    const char *name = NULL;
585    const char *mangled = NULL;
586    int decl_file = 0;
587    int decl_line = 0;
588    int decl_column = 0;
589    int call_file = 0;
590    int call_line = 0;
591    int call_column = 0;
592    DWARFExpression frame_base;
593
594    assert (die->Tag() == DW_TAG_subprogram);
595
596    if (die->Tag() != DW_TAG_subprogram)
597        return NULL;
598
599    const DWARFDebugInfoEntry *parent_die = die->GetParent();
600    switch (parent_die->Tag())
601    {
602    case DW_TAG_structure_type:
603    case DW_TAG_class_type:
604        // We have methods of a class or struct
605        {
606            Type *class_type = ResolveType (dwarf_cu, parent_die);
607            if (class_type)
608                class_type->GetClangType();
609        }
610        break;
611
612    default:
613        // Parse the function prototype as a type that can then be added to concrete function instance
614        ParseTypes (sc, dwarf_cu, die, false, false);
615        break;
616    }
617
618    //FixupTypes();
619
620    if (die->GetDIENamesAndRanges(this, dwarf_cu, name, mangled, func_ranges, decl_file, decl_line, decl_column, call_file, call_line, call_column, &frame_base))
621    {
622        // Union of all ranges in the function DIE (if the function is discontiguous)
623        AddressRange func_range;
624        lldb::addr_t lowest_func_addr = func_ranges.LowestAddress(0);
625        lldb::addr_t highest_func_addr = func_ranges.HighestAddress(0);
626        if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
627        {
628            func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList());
629            if (func_range.GetBaseAddress().IsValid())
630                func_range.SetByteSize(highest_func_addr - lowest_func_addr);
631        }
632
633        if (func_range.GetBaseAddress().IsValid())
634        {
635            Mangled func_name;
636            if (mangled)
637                func_name.SetValue(mangled, true);
638            else if (name)
639                func_name.SetValue(name, false);
640
641            FunctionSP func_sp;
642            std::auto_ptr<Declaration> decl_ap;
643            if (decl_file != 0 || decl_line != 0 || decl_column != 0)
644                decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), decl_line, decl_column));
645
646            Type *func_type = m_die_to_type.lookup (die);
647
648            assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
649
650            func_range.GetBaseAddress().ResolveLinkedAddress();
651
652            func_sp.reset(new Function (sc.comp_unit,
653                                        die->GetOffset(),       // UserID is the DIE offset
654                                        die->GetOffset(),
655                                        func_name,
656                                        func_type,
657                                        func_range));           // first address range
658
659            if (func_sp.get() != NULL)
660            {
661                func_sp->GetFrameBaseExpression() = frame_base;
662                sc.comp_unit->AddFunction(func_sp);
663                return func_sp.get();
664            }
665        }
666    }
667    return NULL;
668}
669
670size_t
671SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
672{
673    assert (sc.comp_unit);
674    size_t functions_added = 0;
675    DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
676    if (dwarf_cu)
677    {
678        DWARFDIECollection function_dies;
679        const size_t num_funtions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
680        size_t func_idx;
681        for (func_idx = 0; func_idx < num_funtions; ++func_idx)
682        {
683            const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
684            if (sc.comp_unit->FindFunctionByUID (die->GetOffset()).get() == NULL)
685            {
686                if (ParseCompileUnitFunction(sc, dwarf_cu, die))
687                    ++functions_added;
688            }
689        }
690        //FixupTypes();
691    }
692    return functions_added;
693}
694
695bool
696SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
697{
698    assert (sc.comp_unit);
699    DWARFCompileUnit* cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
700    assert (cu);
701    const DWARFDebugInfoEntry * cu_die = cu->GetCompileUnitDIEOnly();
702
703    if (cu_die)
704    {
705        const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, cu, DW_AT_comp_dir, NULL);
706        dw_offset_t stmt_list = cu_die->GetAttributeValueAsUnsigned(this, cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
707
708        // All file indexes in DWARF are one based and a file of index zero is
709        // supposed to be the compile unit itself.
710        support_files.Append (*sc.comp_unit);
711
712        return DWARFDebugLine::ParseSupportFiles(get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
713    }
714    return false;
715}
716
717struct ParseDWARFLineTableCallbackInfo
718{
719    LineTable* line_table;
720    const SectionList *section_list;
721    lldb::addr_t prev_sect_file_base_addr;
722    lldb::addr_t curr_sect_file_base_addr;
723    bool is_oso_for_debug_map;
724    bool prev_in_final_executable;
725    DWARFDebugLine::Row prev_row;
726    SectionSP prev_section_sp;
727    SectionSP curr_section_sp;
728};
729
730//----------------------------------------------------------------------
731// ParseStatementTableCallback
732//----------------------------------------------------------------------
733static void
734ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
735{
736    LineTable* line_table = ((ParseDWARFLineTableCallbackInfo*)userData)->line_table;
737    if (state.row == DWARFDebugLine::State::StartParsingLineTable)
738    {
739        // Just started parsing the line table
740    }
741    else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
742    {
743        // Done parsing line table, nothing to do for the cleanup
744    }
745    else
746    {
747        ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
748        // We have a new row, lets append it
749
750        if (info->curr_section_sp.get() == NULL || info->curr_section_sp->ContainsFileAddress(state.address) == false)
751        {
752            info->prev_section_sp = info->curr_section_sp;
753            info->prev_sect_file_base_addr = info->curr_sect_file_base_addr;
754            // If this is an end sequence entry, then we subtract one from the
755            // address to make sure we get an address that is not the end of
756            // a section.
757            if (state.end_sequence && state.address != 0)
758                info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address - 1);
759            else
760                info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address);
761
762            if (info->curr_section_sp.get())
763                info->curr_sect_file_base_addr = info->curr_section_sp->GetFileAddress ();
764            else
765                info->curr_sect_file_base_addr = 0;
766        }
767        if (info->curr_section_sp.get())
768        {
769            lldb::addr_t curr_line_section_offset = state.address - info->curr_sect_file_base_addr;
770            // Check for the fancy section magic to determine if we
771
772            if (info->is_oso_for_debug_map)
773            {
774                // When this is a debug map object file that contains DWARF
775                // (referenced from an N_OSO debug map nlist entry) we will have
776                // a file address in the file range for our section from the
777                // original .o file, and a load address in the executable that
778                // contains the debug map.
779                //
780                // If the sections for the file range and load range are
781                // different, we have a remapped section for the function and
782                // this address is resolved. If they are the same, then the
783                // function for this address didn't make it into the final
784                // executable.
785                bool curr_in_final_executable = info->curr_section_sp->GetLinkedSection () != NULL;
786
787                // If we are doing DWARF with debug map, then we need to carefully
788                // add each line table entry as there may be gaps as functions
789                // get moved around or removed.
790                if (!info->prev_row.end_sequence && info->prev_section_sp.get())
791                {
792                    if (info->prev_in_final_executable)
793                    {
794                        bool terminate_previous_entry = false;
795                        if (!curr_in_final_executable)
796                        {
797                            // Check for the case where the previous line entry
798                            // in a function made it into the final executable,
799                            // yet the current line entry falls in a function
800                            // that didn't. The line table used to be contiguous
801                            // through this address range but now it isn't. We
802                            // need to terminate the previous line entry so
803                            // that we can reconstruct the line range correctly
804                            // for it and to keep the line table correct.
805                            terminate_previous_entry = true;
806                        }
807                        else if (info->curr_section_sp.get() != info->prev_section_sp.get())
808                        {
809                            // Check for cases where the line entries used to be
810                            // contiguous address ranges, but now they aren't.
811                            // This can happen when order files specify the
812                            // ordering of the functions.
813                            lldb::addr_t prev_line_section_offset = info->prev_row.address - info->prev_sect_file_base_addr;
814                            Section *curr_sect = info->curr_section_sp.get();
815                            Section *prev_sect = info->prev_section_sp.get();
816                            assert (curr_sect->GetLinkedSection());
817                            assert (prev_sect->GetLinkedSection());
818                            lldb::addr_t object_file_addr_delta = state.address - info->prev_row.address;
819                            lldb::addr_t curr_linked_file_addr = curr_sect->GetLinkedFileAddress() + curr_line_section_offset;
820                            lldb::addr_t prev_linked_file_addr = prev_sect->GetLinkedFileAddress() + prev_line_section_offset;
821                            lldb::addr_t linked_file_addr_delta = curr_linked_file_addr - prev_linked_file_addr;
822                            if (object_file_addr_delta != linked_file_addr_delta)
823                                terminate_previous_entry = true;
824                        }
825
826                        if (terminate_previous_entry)
827                        {
828                            line_table->InsertLineEntry (info->prev_section_sp,
829                                                         state.address - info->prev_sect_file_base_addr,
830                                                         info->prev_row.line,
831                                                         info->prev_row.column,
832                                                         info->prev_row.file,
833                                                         false,                 // is_stmt
834                                                         false,                 // basic_block
835                                                         false,                 // state.prologue_end
836                                                         false,                 // state.epilogue_begin
837                                                         true);                 // end_sequence);
838                        }
839                    }
840                }
841
842                if (curr_in_final_executable)
843                {
844                    line_table->InsertLineEntry (info->curr_section_sp,
845                                                 curr_line_section_offset,
846                                                 state.line,
847                                                 state.column,
848                                                 state.file,
849                                                 state.is_stmt,
850                                                 state.basic_block,
851                                                 state.prologue_end,
852                                                 state.epilogue_begin,
853                                                 state.end_sequence);
854                    info->prev_section_sp = info->curr_section_sp;
855                }
856                else
857                {
858                    // If the current address didn't make it into the final
859                    // executable, the current section will be the __text
860                    // segment in the .o file, so we need to clear this so
861                    // we can catch the next function that did make it into
862                    // the final executable.
863                    info->prev_section_sp.reset();
864                    info->curr_section_sp.reset();
865                }
866
867                info->prev_in_final_executable = curr_in_final_executable;
868            }
869            else
870            {
871                // We are not in an object file that contains DWARF for an
872                // N_OSO, this is just a normal DWARF file. The DWARF spec
873                // guarantees that the addresses will be in increasing order
874                // so, since we store line tables in file address order, we
875                // can always just append the line entry without needing to
876                // search for the correct insertion point (we don't need to
877                // use LineEntry::InsertLineEntry()).
878                line_table->AppendLineEntry (info->curr_section_sp,
879                                             curr_line_section_offset,
880                                             state.line,
881                                             state.column,
882                                             state.file,
883                                             state.is_stmt,
884                                             state.basic_block,
885                                             state.prologue_end,
886                                             state.epilogue_begin,
887                                             state.end_sequence);
888            }
889        }
890
891        info->prev_row = state;
892    }
893}
894
895bool
896SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
897{
898    assert (sc.comp_unit);
899    if (sc.comp_unit->GetLineTable() != NULL)
900        return true;
901
902    DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
903    if (dwarf_cu)
904    {
905        const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
906        const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
907        if (cu_line_offset != DW_INVALID_OFFSET)
908        {
909            std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
910            if (line_table_ap.get())
911            {
912                ParseDWARFLineTableCallbackInfo info = { line_table_ap.get(), m_obj_file->GetSectionList(), 0, 0, m_debug_map_symfile != NULL, false};
913                uint32_t offset = cu_line_offset;
914                DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
915                sc.comp_unit->SetLineTable(line_table_ap.release());
916                return true;
917            }
918        }
919    }
920    return false;
921}
922
923size_t
924SymbolFileDWARF::ParseFunctionBlocks
925(
926    const SymbolContext& sc,
927    Block *parent_block,
928    DWARFCompileUnit* dwarf_cu,
929    const DWARFDebugInfoEntry *die,
930    addr_t subprogram_low_pc,
931    bool parse_siblings,
932    bool parse_children
933)
934{
935    size_t blocks_added = 0;
936    while (die != NULL)
937    {
938        dw_tag_t tag = die->Tag();
939
940        switch (tag)
941        {
942        case DW_TAG_inlined_subroutine:
943        case DW_TAG_subprogram:
944        case DW_TAG_lexical_block:
945            {
946                DWARFDebugRanges::RangeList ranges;
947                const char *name = NULL;
948                const char *mangled_name = NULL;
949                Block *block = NULL;
950                if (tag != DW_TAG_subprogram)
951                {
952                    BlockSP block_sp(new Block (die->GetOffset()));
953                    parent_block->AddChild(block_sp);
954                    block = block_sp.get();
955                }
956                else
957                {
958                    block = parent_block;
959                }
960
961                int decl_file = 0;
962                int decl_line = 0;
963                int decl_column = 0;
964                int call_file = 0;
965                int call_line = 0;
966                int call_column = 0;
967                if (die->GetDIENamesAndRanges (this,
968                                               dwarf_cu,
969                                               name,
970                                               mangled_name,
971                                               ranges,
972                                               decl_file, decl_line, decl_column,
973                                               call_file, call_line, call_column))
974                {
975                    if (tag == DW_TAG_subprogram)
976                    {
977                        assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
978                        subprogram_low_pc = ranges.LowestAddress(0);
979                    }
980                    else if (tag == DW_TAG_inlined_subroutine)
981                    {
982                        // We get called here for inlined subroutines in two ways.
983                        // The first time is when we are making the Function object
984                        // for this inlined concrete instance.  Since we're creating a top level block at
985                        // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS.  So we need to
986                        // adjust the containing address.
987                        // The second time is when we are parsing the blocks inside the function that contains
988                        // the inlined concrete instance.  Since these will be blocks inside the containing "real"
989                        // function the offset will be for that function.
990                        if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
991                        {
992                            subprogram_low_pc = ranges.LowestAddress(0);
993                        }
994                    }
995
996                    AddRangesToBlock (*block, ranges, subprogram_low_pc);
997
998                    if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
999                    {
1000                        std::auto_ptr<Declaration> decl_ap;
1001                        if (decl_file != 0 || decl_line != 0 || decl_column != 0)
1002                            decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1003                                                          decl_line, decl_column));
1004
1005                        std::auto_ptr<Declaration> call_ap;
1006                        if (call_file != 0 || call_line != 0 || call_column != 0)
1007                            call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1008                                                          call_line, call_column));
1009
1010                        block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
1011                    }
1012
1013                    ++blocks_added;
1014
1015                    if (parse_children && die->HasChildren())
1016                    {
1017                        blocks_added += ParseFunctionBlocks (sc,
1018                                                             block,
1019                                                             dwarf_cu,
1020                                                             die->GetFirstChild(),
1021                                                             subprogram_low_pc,
1022                                                             true,
1023                                                             true);
1024                    }
1025                }
1026            }
1027            break;
1028        default:
1029            break;
1030        }
1031
1032        if (parse_siblings)
1033            die = die->GetSibling();
1034        else
1035            die = NULL;
1036    }
1037    return blocks_added;
1038}
1039
1040size_t
1041SymbolFileDWARF::ParseChildMembers
1042(
1043    const SymbolContext& sc,
1044    DWARFCompileUnit* dwarf_cu,
1045    const DWARFDebugInfoEntry *parent_die,
1046    clang_type_t class_clang_type,
1047    const LanguageType class_language,
1048    std::vector<clang::CXXBaseSpecifier *>& base_classes,
1049    std::vector<int>& member_accessibilities,
1050    DWARFDIECollection& member_function_dies,
1051    AccessType& default_accessibility,
1052    bool &is_a_class
1053)
1054{
1055    if (parent_die == NULL)
1056        return 0;
1057
1058    TypeList* type_list = m_obj_file->GetModule()->GetTypeList();
1059
1060    size_t count = 0;
1061    const DWARFDebugInfoEntry *die;
1062    const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
1063
1064    for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1065    {
1066        dw_tag_t tag = die->Tag();
1067
1068        switch (tag)
1069        {
1070        case DW_TAG_member:
1071            {
1072                DWARFDebugInfoEntry::Attributes attributes;
1073                const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
1074                if (num_attributes > 0)
1075                {
1076                    Declaration decl;
1077                    DWARFExpression location;
1078                    const char *name = NULL;
1079                    bool is_artificial = false;
1080                    lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
1081                    AccessType accessibility = eAccessNone;
1082                    off_t member_offset = 0;
1083                    size_t byte_size = 0;
1084                    size_t bit_offset = 0;
1085                    size_t bit_size = 0;
1086                    uint32_t i;
1087                    for (i=0; i<num_attributes && !is_artificial; ++i)
1088                    {
1089                        const dw_attr_t attr = attributes.AttributeAtIndex(i);
1090                        DWARFFormValue form_value;
1091                        if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1092                        {
1093                            switch (attr)
1094                            {
1095                            case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1096                            case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break;
1097                            case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1098                            case DW_AT_name:        name = form_value.AsCString(&get_debug_str_data()); break;
1099                            case DW_AT_type:        encoding_uid = form_value.Reference(dwarf_cu); break;
1100                            case DW_AT_bit_offset:  bit_offset = form_value.Unsigned(); break;
1101                            case DW_AT_bit_size:    bit_size = form_value.Unsigned(); break;
1102                            case DW_AT_byte_size:   byte_size = form_value.Unsigned(); break;
1103                            case DW_AT_data_member_location:
1104                                if (form_value.BlockData())
1105                                {
1106                                    Value initialValue(0);
1107                                    Value memberOffset(0);
1108                                    const DataExtractor& debug_info_data = get_debug_info_data();
1109                                    uint32_t block_length = form_value.Unsigned();
1110                                    uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1111                                    if (DWARFExpression::Evaluate(NULL, NULL, debug_info_data, NULL, NULL, block_offset, block_length, eRegisterKindDWARF, &initialValue, memberOffset, NULL))
1112                                    {
1113                                        member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1114                                    }
1115                                }
1116                                break;
1117
1118                            case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
1119                            case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
1120                            case DW_AT_declaration:
1121                            case DW_AT_description:
1122                            case DW_AT_mutable:
1123                            case DW_AT_visibility:
1124                            default:
1125                            case DW_AT_sibling:
1126                                break;
1127                            }
1128                        }
1129                    }
1130
1131                    if (is_artificial == false)
1132                    {
1133                        Type *member_type = ResolveTypeUID(encoding_uid);
1134                        assert(member_type);
1135                        if (accessibility == eAccessNone)
1136                            accessibility = default_accessibility;
1137                        member_accessibilities.push_back(accessibility);
1138
1139                        type_list->GetClangASTContext().AddFieldToRecordType (class_clang_type, name, member_type->GetClangType(), accessibility, bit_size);
1140                    }
1141                }
1142            }
1143            break;
1144
1145        case DW_TAG_subprogram:
1146            // Let the type parsing code handle this one for us.
1147            member_function_dies.Append (die);
1148            break;
1149
1150        case DW_TAG_inheritance:
1151            {
1152                is_a_class = true;
1153                if (default_accessibility == eAccessNone)
1154                    default_accessibility = eAccessPrivate;
1155                // TODO: implement DW_TAG_inheritance type parsing
1156                DWARFDebugInfoEntry::Attributes attributes;
1157                const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
1158                if (num_attributes > 0)
1159                {
1160                    Declaration decl;
1161                    DWARFExpression location;
1162                    lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
1163                    AccessType accessibility = default_accessibility;
1164                    bool is_virtual = false;
1165                    bool is_base_of_class = true;
1166                    off_t member_offset = 0;
1167                    uint32_t i;
1168                    for (i=0; i<num_attributes; ++i)
1169                    {
1170                        const dw_attr_t attr = attributes.AttributeAtIndex(i);
1171                        DWARFFormValue form_value;
1172                        if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1173                        {
1174                            switch (attr)
1175                            {
1176                            case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1177                            case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break;
1178                            case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1179                            case DW_AT_type:        encoding_uid = form_value.Reference(dwarf_cu); break;
1180                            case DW_AT_data_member_location:
1181                                if (form_value.BlockData())
1182                                {
1183                                    Value initialValue(0);
1184                                    Value memberOffset(0);
1185                                    const DataExtractor& debug_info_data = get_debug_info_data();
1186                                    uint32_t block_length = form_value.Unsigned();
1187                                    uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1188                                    if (DWARFExpression::Evaluate(NULL, NULL, debug_info_data, NULL, NULL, block_offset, block_length, eRegisterKindDWARF, &initialValue, memberOffset, NULL))
1189                                    {
1190                                        member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1191                                    }
1192                                }
1193                                break;
1194
1195                            case DW_AT_accessibility:
1196                                accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
1197                                break;
1198
1199                            case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
1200                            default:
1201                            case DW_AT_sibling:
1202                                break;
1203                            }
1204                        }
1205                    }
1206
1207                    Type *base_class_dctype = ResolveTypeUID(encoding_uid);
1208                    assert(base_class_dctype);
1209
1210                    if (class_language == eLanguageTypeObjC)
1211                    {
1212                        type_list->GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_dctype->GetClangType());
1213                    }
1214                    else
1215                    {
1216                        base_classes.push_back (type_list->GetClangASTContext().CreateBaseClassSpecifier (base_class_dctype->GetClangType(), accessibility, is_virtual, is_base_of_class));
1217                        assert(base_classes.back());
1218                    }
1219                }
1220            }
1221            break;
1222
1223        default:
1224            break;
1225        }
1226    }
1227    return count;
1228}
1229
1230
1231clang::DeclContext*
1232SymbolFileDWARF::GetClangDeclContextForTypeUID (lldb::user_id_t type_uid)
1233{
1234    DWARFDebugInfo* debug_info = DebugInfo();
1235    if (debug_info)
1236    {
1237        DWARFCompileUnitSP cu_sp;
1238        const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1239        if (die)
1240            return GetClangDeclContextForDIE (cu_sp.get(), die);
1241    }
1242    return NULL;
1243}
1244
1245Type*
1246SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
1247{
1248    DWARFDebugInfo* debug_info = DebugInfo();
1249    if (debug_info)
1250    {
1251        DWARFCompileUnitSP cu_sp;
1252        const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1253        if (type_die != NULL)
1254            return ResolveType (cu_sp.get(), type_die);
1255    }
1256    return NULL;
1257}
1258
1259lldb::clang_type_t
1260SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
1261{
1262    // We have a struct/union/class/enum that needs to be fully resolved.
1263    const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (ClangASTType::RemoveFastQualifiers(clang_type));
1264    assert (die);
1265    if (die == NULL)
1266        return NULL;
1267
1268    DWARFDebugInfo* debug_info = DebugInfo();
1269
1270    DWARFCompileUnit *cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
1271    Type *type = m_die_to_type.lookup (die);
1272
1273    const dw_tag_t tag = die->Tag();
1274
1275    DEBUG_PRINTF ("0x%8.8x: %s (\"%s\") - resolve forward declaration...\n", die->GetOffset(), DW_TAG_value_to_name(tag), type->GetName().AsCString());
1276    assert (clang_type);
1277    DWARFDebugInfoEntry::Attributes attributes;
1278
1279    TypeList* type_list = m_obj_file->GetModule()->GetTypeList();
1280
1281    switch (tag)
1282    {
1283    case DW_TAG_structure_type:
1284    case DW_TAG_union_type:
1285    case DW_TAG_class_type:
1286        type_list->GetClangASTContext().StartTagDeclarationDefinition (clang_type);
1287        if (die->HasChildren())
1288        {
1289            LanguageType class_language = eLanguageTypeUnknown;
1290            bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type);
1291            if (is_objc_class)
1292                class_language = eLanguageTypeObjC;
1293
1294            int tag_decl_kind = -1;
1295            AccessType default_accessibility = eAccessNone;
1296            if (tag == DW_TAG_structure_type)
1297            {
1298                tag_decl_kind = clang::TTK_Struct;
1299                default_accessibility = eAccessPublic;
1300            }
1301            else if (tag == DW_TAG_union_type)
1302            {
1303                tag_decl_kind = clang::TTK_Union;
1304                default_accessibility = eAccessPublic;
1305            }
1306            else if (tag == DW_TAG_class_type)
1307            {
1308                tag_decl_kind = clang::TTK_Class;
1309                default_accessibility = eAccessPrivate;
1310            }
1311
1312            SymbolContext sc(GetCompUnitForDWARFCompUnit(cu));
1313            std::vector<clang::CXXBaseSpecifier *> base_classes;
1314            std::vector<int> member_accessibilities;
1315            bool is_a_class = false;
1316            // Parse members and base classes first
1317            DWARFDIECollection member_function_dies;
1318
1319            ParseChildMembers (sc,
1320                               cu,
1321                               die,
1322                               clang_type,
1323                               class_language,
1324                               base_classes,
1325                               member_accessibilities,
1326                               member_function_dies,
1327                               default_accessibility,
1328                               is_a_class);
1329
1330            // Now parse any methods if there were any...
1331            size_t num_functions = member_function_dies.Size();
1332            if (num_functions > 0)
1333            {
1334                for (size_t i=0; i<num_functions; ++i)
1335                {
1336                    ResolveType(cu, member_function_dies.GetDIEPtrAtIndex(i));
1337                }
1338            }
1339
1340            if (class_language == eLanguageTypeObjC)
1341            {
1342                std::string class_str (ClangASTContext::GetTypeName (clang_type));
1343                if (!class_str.empty())
1344                {
1345
1346                    ConstString class_name (class_str.c_str());
1347                    std::vector<NameToDIE::Info> method_die_infos;
1348                    if (m_objc_class_selectors_index.Find (class_name, method_die_infos))
1349                    {
1350                        DWARFCompileUnit* method_cu = NULL;
1351                        DWARFCompileUnit* prev_method_cu = NULL;
1352                        const size_t num_objc_methods = method_die_infos.size();
1353                        for (size_t i=0;i<num_objc_methods; ++i, prev_method_cu = method_cu)
1354                        {
1355                            method_cu = debug_info->GetCompileUnitAtIndex(method_die_infos[i].cu_idx);
1356
1357                            if (method_cu != prev_method_cu)
1358                                method_cu->ExtractDIEsIfNeeded (false);
1359
1360                            DWARFDebugInfoEntry *method_die = method_cu->GetDIEAtIndexUnchecked(method_die_infos[i].die_idx);
1361
1362                            ResolveType (method_cu, method_die);
1363                        }
1364                    }
1365                }
1366            }
1367
1368            // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
1369            // need to tell the clang type it is actually a class.
1370            if (class_language != eLanguageTypeObjC)
1371            {
1372                if (is_a_class && tag_decl_kind != clang::TTK_Class)
1373                    type_list->GetClangASTContext().SetTagTypeKind (clang_type, clang::TTK_Class);
1374            }
1375
1376            // Since DW_TAG_structure_type gets used for both classes
1377            // and structures, we may need to set any DW_TAG_member
1378            // fields to have a "private" access if none was specified.
1379            // When we parsed the child members we tracked that actual
1380            // accessibility value for each DW_TAG_member in the
1381            // "member_accessibilities" array. If the value for the
1382            // member is zero, then it was set to the "default_accessibility"
1383            // which for structs was "public". Below we correct this
1384            // by setting any fields to "private" that weren't correctly
1385            // set.
1386            if (is_a_class && !member_accessibilities.empty())
1387            {
1388                // This is a class and all members that didn't have
1389                // their access specified are private.
1390                type_list->GetClangASTContext().SetDefaultAccessForRecordFields (clang_type, eAccessPrivate, &member_accessibilities.front(), member_accessibilities.size());
1391            }
1392
1393            if (!base_classes.empty())
1394            {
1395                type_list->GetClangASTContext().SetBaseClassesForClassType (clang_type, &base_classes.front(), base_classes.size());
1396
1397                // Clang will copy each CXXBaseSpecifier in "base_classes"
1398                // so we have to free them all.
1399                ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(), base_classes.size());
1400            }
1401
1402        }
1403        type_list->GetClangASTContext().CompleteTagDeclarationDefinition (clang_type);
1404        return clang_type;
1405
1406    case DW_TAG_enumeration_type:
1407        type_list->GetClangASTContext().StartTagDeclarationDefinition (clang_type);
1408        if (die->HasChildren())
1409        {
1410            SymbolContext sc(GetCompUnitForDWARFCompUnit(cu));
1411            ParseChildEnumerators(sc, clang_type, type->GetByteSize(), cu, die);
1412        }
1413        type_list->GetClangASTContext().CompleteTagDeclarationDefinition (clang_type);
1414        return clang_type;
1415
1416    default:
1417        assert(false && "not a forward clang type decl!");
1418        break;
1419    }
1420    return NULL;
1421}
1422
1423Type*
1424SymbolFileDWARF::ResolveType (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
1425{
1426    if (type_die != NULL)
1427    {
1428        Type *type = m_die_to_type.lookup (type_die);
1429        if (type == NULL)
1430            type = GetTypeForDIE (cu, type_die).get();
1431        if (assert_not_being_parsed)
1432            assert (type != DIE_IS_BEING_PARSED);
1433        return type;
1434    }
1435    return NULL;
1436}
1437
1438CompileUnit*
1439SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* cu, uint32_t cu_idx)
1440{
1441    // Check if the symbol vendor already knows about this compile unit?
1442    if (cu->GetUserData() == NULL)
1443    {
1444        // The symbol vendor doesn't know about this compile unit, we
1445        // need to parse and add it to the symbol vendor object.
1446        CompUnitSP dc_cu;
1447        ParseCompileUnit(cu, dc_cu);
1448        if (dc_cu.get())
1449        {
1450            // Figure out the compile unit index if we weren't given one
1451            if (cu_idx == UINT32_MAX)
1452                DebugInfo()->GetCompileUnit(cu->GetOffset(), &cu_idx);
1453
1454            m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(dc_cu, cu_idx);
1455
1456            if (m_debug_map_symfile)
1457                m_debug_map_symfile->SetCompileUnit(this, dc_cu);
1458        }
1459    }
1460    return (CompileUnit*)cu->GetUserData();
1461}
1462
1463bool
1464SymbolFileDWARF::GetFunction (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
1465{
1466    sc.Clear();
1467    // Check if the symbol vendor already knows about this compile unit?
1468    sc.module_sp = m_obj_file->GetModule()->GetSP();
1469    sc.comp_unit = GetCompUnitForDWARFCompUnit(cu, UINT32_MAX);
1470
1471    sc.function = sc.comp_unit->FindFunctionByUID (func_die->GetOffset()).get();
1472    if (sc.function == NULL)
1473        sc.function = ParseCompileUnitFunction(sc, cu, func_die);
1474
1475    return sc.function != NULL;
1476}
1477
1478uint32_t
1479SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
1480{
1481    Timer scoped_timer(__PRETTY_FUNCTION__,
1482                       "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%llx }, resolve_scope = 0x%8.8x)",
1483                       so_addr.GetSection(),
1484                       so_addr.GetOffset(),
1485                       resolve_scope);
1486    uint32_t resolved = 0;
1487    if (resolve_scope & (   eSymbolContextCompUnit |
1488                            eSymbolContextFunction |
1489                            eSymbolContextBlock |
1490                            eSymbolContextLineEntry))
1491    {
1492        lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
1493
1494        DWARFDebugAranges* debug_aranges = DebugAranges();
1495        DWARFDebugInfo* debug_info = DebugInfo();
1496        if (debug_aranges)
1497        {
1498            dw_offset_t cu_offset = debug_aranges->FindAddress(file_vm_addr);
1499            if (cu_offset != DW_INVALID_OFFSET)
1500            {
1501                uint32_t cu_idx;
1502                DWARFCompileUnit* cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
1503                if (cu)
1504                {
1505                    sc.comp_unit = GetCompUnitForDWARFCompUnit(cu, cu_idx);
1506                    assert(sc.comp_unit != NULL);
1507                    resolved |= eSymbolContextCompUnit;
1508
1509                    if (resolve_scope & eSymbolContextLineEntry)
1510                    {
1511                        LineTable *line_table = sc.comp_unit->GetLineTable();
1512                        if (line_table == NULL)
1513                        {
1514                            if (ParseCompileUnitLineTable(sc))
1515                                line_table = sc.comp_unit->GetLineTable();
1516                        }
1517                        if (line_table != NULL)
1518                        {
1519                            if (so_addr.IsLinkedAddress())
1520                            {
1521                                Address linked_addr (so_addr);
1522                                linked_addr.ResolveLinkedAddress();
1523                                if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry))
1524                                {
1525                                    resolved |= eSymbolContextLineEntry;
1526                                }
1527                            }
1528                            else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry))
1529                            {
1530                                resolved |= eSymbolContextLineEntry;
1531                            }
1532                        }
1533                    }
1534
1535                    if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
1536                    {
1537                        DWARFDebugInfoEntry *function_die = NULL;
1538                        DWARFDebugInfoEntry *block_die = NULL;
1539                        if (resolve_scope & eSymbolContextBlock)
1540                        {
1541                            cu->LookupAddress(file_vm_addr, &function_die, &block_die);
1542                        }
1543                        else
1544                        {
1545                            cu->LookupAddress(file_vm_addr, &function_die, NULL);
1546                        }
1547
1548                        if (function_die != NULL)
1549                        {
1550                            sc.function = sc.comp_unit->FindFunctionByUID (function_die->GetOffset()).get();
1551                            if (sc.function == NULL)
1552                                sc.function = ParseCompileUnitFunction(sc, cu, function_die);
1553                        }
1554
1555                        if (sc.function != NULL)
1556                        {
1557                            resolved |= eSymbolContextFunction;
1558
1559                            if (resolve_scope & eSymbolContextBlock)
1560                            {
1561                                Block& block = sc.function->GetBlock (true);
1562
1563                                if (block_die != NULL)
1564                                    sc.block = block.FindBlockByID (block_die->GetOffset());
1565                                else
1566                                    sc.block = block.FindBlockByID (function_die->GetOffset());
1567                                if (sc.block)
1568                                    resolved |= eSymbolContextBlock;
1569                            }
1570                        }
1571                    }
1572                }
1573            }
1574        }
1575    }
1576    return resolved;
1577}
1578
1579
1580
1581uint32_t
1582SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
1583{
1584    const uint32_t prev_size = sc_list.GetSize();
1585    if (resolve_scope & eSymbolContextCompUnit)
1586    {
1587        DWARFDebugInfo* debug_info = DebugInfo();
1588        if (debug_info)
1589        {
1590            uint32_t cu_idx;
1591            DWARFCompileUnit* cu = NULL;
1592
1593            for (cu_idx = 0; (cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
1594            {
1595                CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(cu, cu_idx);
1596                bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Compare(file_spec, *dc_cu, false) == 0;
1597                if (check_inlines || file_spec_matches_cu_file_spec)
1598                {
1599                    SymbolContext sc (m_obj_file->GetModule());
1600                    sc.comp_unit = GetCompUnitForDWARFCompUnit(cu, cu_idx);
1601                    assert(sc.comp_unit != NULL);
1602
1603                    uint32_t file_idx = UINT32_MAX;
1604
1605                    // If we are looking for inline functions only and we don't
1606                    // find it in the support files, we are done.
1607                    if (check_inlines)
1608                    {
1609                        file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec);
1610                        if (file_idx == UINT32_MAX)
1611                            continue;
1612                    }
1613
1614                    if (line != 0)
1615                    {
1616                        LineTable *line_table = sc.comp_unit->GetLineTable();
1617
1618                        if (line_table != NULL && line != 0)
1619                        {
1620                            // We will have already looked up the file index if
1621                            // we are searching for inline entries.
1622                            if (!check_inlines)
1623                                file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec);
1624
1625                            if (file_idx != UINT32_MAX)
1626                            {
1627                                uint32_t found_line;
1628                                uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
1629                                found_line = sc.line_entry.line;
1630
1631                                while (line_idx != UINT32_MAX)
1632                                {
1633                                    sc.function = NULL;
1634                                    sc.block = NULL;
1635                                    if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
1636                                    {
1637                                        const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
1638                                        if (file_vm_addr != LLDB_INVALID_ADDRESS)
1639                                        {
1640                                            DWARFDebugInfoEntry *function_die = NULL;
1641                                            DWARFDebugInfoEntry *block_die = NULL;
1642                                            cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
1643
1644                                            if (function_die != NULL)
1645                                            {
1646                                                sc.function = sc.comp_unit->FindFunctionByUID (function_die->GetOffset()).get();
1647                                                if (sc.function == NULL)
1648                                                    sc.function = ParseCompileUnitFunction(sc, cu, function_die);
1649                                            }
1650
1651                                            if (sc.function != NULL)
1652                                            {
1653                                                Block& block = sc.function->GetBlock (true);
1654
1655                                                if (block_die != NULL)
1656                                                    sc.block = block.FindBlockByID (block_die->GetOffset());
1657                                                else
1658                                                    sc.block = block.FindBlockByID (function_die->GetOffset());
1659                                            }
1660                                        }
1661                                    }
1662
1663                                    sc_list.Append(sc);
1664                                    line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
1665                                }
1666                            }
1667                        }
1668                        else if (file_spec_matches_cu_file_spec && !check_inlines)
1669                        {
1670                            // only append the context if we aren't looking for inline call sites
1671                            // by file and line and if the file spec matches that of the compile unit
1672                            sc_list.Append(sc);
1673                        }
1674                    }
1675                    else if (file_spec_matches_cu_file_spec && !check_inlines)
1676                    {
1677                        // only append the context if we aren't looking for inline call sites
1678                        // by file and line and if the file spec matches that of the compile unit
1679                        sc_list.Append(sc);
1680                    }
1681
1682                    if (!check_inlines)
1683                        break;
1684                }
1685            }
1686        }
1687    }
1688    return sc_list.GetSize() - prev_size;
1689}
1690
1691void
1692SymbolFileDWARF::Index ()
1693{
1694    if (m_indexed)
1695        return;
1696    m_indexed = true;
1697    Timer scoped_timer (__PRETTY_FUNCTION__,
1698                        "SymbolFileDWARF::Index (%s)",
1699                        GetObjectFile()->GetFileSpec().GetFilename().AsCString());
1700
1701    DWARFDebugInfo* debug_info = DebugInfo();
1702    if (debug_info)
1703    {
1704        m_aranges.reset(new DWARFDebugAranges());
1705
1706        uint32_t cu_idx = 0;
1707        const uint32_t num_compile_units = GetNumCompileUnits();
1708        for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
1709        {
1710            DWARFCompileUnit* cu = debug_info->GetCompileUnitAtIndex(cu_idx);
1711
1712            bool clear_dies = cu->ExtractDIEsIfNeeded (false) > 1;
1713
1714            cu->Index (cu_idx,
1715                       m_function_basename_index,
1716                       m_function_fullname_index,
1717                       m_function_method_index,
1718                       m_function_selector_index,
1719                       m_objc_class_selectors_index,
1720                       m_global_index,
1721                       m_types_index,
1722                       DebugRanges(),
1723                       m_aranges.get());
1724
1725            // Keep memory down by clearing DIEs if this generate function
1726            // caused them to be parsed
1727            if (clear_dies)
1728                cu->ClearDIEs (true);
1729        }
1730
1731        m_aranges->Sort();
1732
1733#if defined (ENABLE_DEBUG_PRINTF)
1734        StreamFile s(stdout);
1735        s.Printf ("DWARF index for (%s) '%s/%s':",
1736                  GetObjectFile()->GetModule()->GetArchitecture().AsCString(),
1737                  GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
1738                  GetObjectFile()->GetFileSpec().GetFilename().AsCString());
1739        s.Printf("\nFunction basenames:\n");    m_function_basename_index.Dump (&s);
1740        s.Printf("\nFunction fullnames:\n");    m_function_fullname_index.Dump (&s);
1741        s.Printf("\nFunction methods:\n");      m_function_method_index.Dump (&s);
1742        s.Printf("\nFunction selectors:\n");    m_function_selector_index.Dump (&s);
1743        s.Printf("\nObjective C class selectors:\n");    m_objc_class_selectors_index.Dump (&s);
1744        s.Printf("\nGlobals and statics:\n");   m_global_index.Dump (&s);
1745        s.Printf("\nTypes:\n");                 m_types_index.Dump (&s);
1746#endif
1747    }
1748}
1749
1750uint32_t
1751SymbolFileDWARF::FindGlobalVariables (const ConstString &name, bool append, uint32_t max_matches, VariableList& variables)
1752{
1753    DWARFDebugInfo* info = DebugInfo();
1754    if (info == NULL)
1755        return 0;
1756
1757    // If we aren't appending the results to this list, then clear the list
1758    if (!append)
1759        variables.Clear();
1760
1761    // Remember how many variables are in the list before we search in case
1762    // we are appending the results to a variable list.
1763    const uint32_t original_size = variables.GetSize();
1764
1765    // Index the DWARF if we haven't already
1766    if (!m_indexed)
1767        Index ();
1768
1769    SymbolContext sc;
1770    sc.module_sp = m_obj_file->GetModule()->GetSP();
1771    assert (sc.module_sp);
1772
1773    DWARFCompileUnit* cu = NULL;
1774    DWARFCompileUnit* prev_cu = NULL;
1775    const DWARFDebugInfoEntry* die = NULL;
1776    std::vector<NameToDIE::Info> die_info_array;
1777    const size_t num_matches = m_global_index.Find(name, die_info_array);
1778    for (size_t i=0; i<num_matches; ++i, prev_cu = cu)
1779    {
1780        cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
1781
1782        if (cu != prev_cu)
1783            cu->ExtractDIEsIfNeeded (false);
1784
1785        die = cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
1786
1787        sc.comp_unit = GetCompUnitForDWARFCompUnit(cu, UINT32_MAX);
1788        assert(sc.comp_unit != NULL);
1789
1790        ParseVariables(sc, cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
1791
1792        if (variables.GetSize() - original_size >= max_matches)
1793            break;
1794    }
1795
1796    // Return the number of variable that were appended to the list
1797    return variables.GetSize() - original_size;
1798}
1799
1800uint32_t
1801SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
1802{
1803    DWARFDebugInfo* info = DebugInfo();
1804    if (info == NULL)
1805        return 0;
1806
1807    // If we aren't appending the results to this list, then clear the list
1808    if (!append)
1809        variables.Clear();
1810
1811    // Remember how many variables are in the list before we search in case
1812    // we are appending the results to a variable list.
1813    const uint32_t original_size = variables.GetSize();
1814
1815    // Index the DWARF if we haven't already
1816    if (!m_indexed)
1817        Index ();
1818
1819    SymbolContext sc;
1820    sc.module_sp = m_obj_file->GetModule()->GetSP();
1821    assert (sc.module_sp);
1822
1823    DWARFCompileUnit* cu = NULL;
1824    DWARFCompileUnit* prev_cu = NULL;
1825    const DWARFDebugInfoEntry* die = NULL;
1826    std::vector<NameToDIE::Info> die_info_array;
1827    const size_t num_matches = m_global_index.Find(regex, die_info_array);
1828    for (size_t i=0; i<num_matches; ++i, prev_cu = cu)
1829    {
1830        cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
1831
1832        if (cu != prev_cu)
1833            cu->ExtractDIEsIfNeeded (false);
1834
1835        die = cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
1836
1837        sc.comp_unit = GetCompUnitForDWARFCompUnit(cu, UINT32_MAX);
1838        assert(sc.comp_unit != NULL);
1839
1840        ParseVariables(sc, cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
1841
1842        if (variables.GetSize() - original_size >= max_matches)
1843            break;
1844    }
1845
1846    // Return the number of variable that were appended to the list
1847    return variables.GetSize() - original_size;
1848}
1849
1850
1851void
1852SymbolFileDWARF::FindFunctions
1853(
1854    const ConstString &name,
1855    const NameToDIE &name_to_die,
1856    SymbolContextList& sc_list
1857)
1858{
1859    DWARFDebugInfo* info = DebugInfo();
1860    if (info == NULL)
1861        return;
1862
1863    SymbolContext sc;
1864    sc.module_sp = m_obj_file->GetModule()->GetSP();
1865    assert (sc.module_sp);
1866
1867    DWARFCompileUnit* cu = NULL;
1868    DWARFCompileUnit* prev_cu = NULL;
1869    const DWARFDebugInfoEntry* die = NULL;
1870    std::vector<NameToDIE::Info> die_info_array;
1871    const size_t num_matches = name_to_die.Find(name, die_info_array);
1872    for (size_t i=0; i<num_matches; ++i, prev_cu = cu)
1873    {
1874        cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
1875
1876        if (cu != prev_cu)
1877            cu->ExtractDIEsIfNeeded (false);
1878
1879        die = cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
1880        if (GetFunction (cu, die, sc))
1881        {
1882            // We found the function, so we should find the line table
1883            // and line table entry as well
1884            LineTable *line_table = sc.comp_unit->GetLineTable();
1885            if (line_table == NULL)
1886            {
1887                if (ParseCompileUnitLineTable(sc))
1888                    line_table = sc.comp_unit->GetLineTable();
1889            }
1890            if (line_table != NULL)
1891                line_table->FindLineEntryByAddress (sc.function->GetAddressRange().GetBaseAddress(), sc.line_entry);
1892
1893            sc_list.Append(sc);
1894        }
1895    }
1896}
1897
1898
1899void
1900SymbolFileDWARF::FindFunctions
1901(
1902    const RegularExpression &regex,
1903    const NameToDIE &name_to_die,
1904    SymbolContextList& sc_list
1905)
1906{
1907    DWARFDebugInfo* info = DebugInfo();
1908    if (info == NULL)
1909        return;
1910
1911    SymbolContext sc;
1912    sc.module_sp = m_obj_file->GetModule()->GetSP();
1913    assert (sc.module_sp);
1914
1915    DWARFCompileUnit* cu = NULL;
1916    DWARFCompileUnit* prev_cu = NULL;
1917    const DWARFDebugInfoEntry* die = NULL;
1918    std::vector<NameToDIE::Info> die_info_array;
1919    const size_t num_matches = name_to_die.Find(regex, die_info_array);
1920    for (size_t i=0; i<num_matches; ++i, prev_cu = cu)
1921    {
1922        cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
1923
1924        if (cu != prev_cu)
1925            cu->ExtractDIEsIfNeeded (false);
1926
1927        die = cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
1928        if (GetFunction (cu, die, sc))
1929        {
1930            // We found the function, so we should find the line table
1931            // and line table entry as well
1932            LineTable *line_table = sc.comp_unit->GetLineTable();
1933            if (line_table == NULL)
1934            {
1935                if (ParseCompileUnitLineTable(sc))
1936                    line_table = sc.comp_unit->GetLineTable();
1937            }
1938            if (line_table != NULL)
1939                line_table->FindLineEntryByAddress (sc.function->GetAddressRange().GetBaseAddress(), sc.line_entry);
1940
1941            sc_list.Append(sc);
1942        }
1943    }
1944}
1945
1946uint32_t
1947SymbolFileDWARF::FindFunctions
1948(
1949    const ConstString &name,
1950    uint32_t name_type_mask,
1951    bool append,
1952    SymbolContextList& sc_list
1953)
1954{
1955    Timer scoped_timer (__PRETTY_FUNCTION__,
1956                        "SymbolFileDWARF::FindFunctions (name = '%s')",
1957                        name.AsCString());
1958
1959    // If we aren't appending the results to this list, then clear the list
1960    if (!append)
1961        sc_list.Clear();
1962
1963    // Remember how many sc_list are in the list before we search in case
1964    // we are appending the results to a variable list.
1965    uint32_t original_size = sc_list.GetSize();
1966
1967    // Index the DWARF if we haven't already
1968    if (!m_indexed)
1969        Index ();
1970
1971    if (name_type_mask & eFunctionNameTypeBase)
1972        FindFunctions (name, m_function_basename_index, sc_list);
1973
1974    if (name_type_mask & eFunctionNameTypeFull)
1975        FindFunctions (name, m_function_fullname_index, sc_list);
1976
1977    if (name_type_mask & eFunctionNameTypeMethod)
1978        FindFunctions (name, m_function_method_index, sc_list);
1979
1980    if (name_type_mask & eFunctionNameTypeSelector)
1981        FindFunctions (name, m_function_selector_index, sc_list);
1982
1983    // Return the number of variable that were appended to the list
1984    return sc_list.GetSize() - original_size;
1985}
1986
1987
1988uint32_t
1989SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool append, SymbolContextList& sc_list)
1990{
1991    Timer scoped_timer (__PRETTY_FUNCTION__,
1992                        "SymbolFileDWARF::FindFunctions (regex = '%s')",
1993                        regex.GetText());
1994
1995    // If we aren't appending the results to this list, then clear the list
1996    if (!append)
1997        sc_list.Clear();
1998
1999    // Remember how many sc_list are in the list before we search in case
2000    // we are appending the results to a variable list.
2001    uint32_t original_size = sc_list.GetSize();
2002
2003    // Index the DWARF if we haven't already
2004    if (!m_indexed)
2005        Index ();
2006
2007    FindFunctions (regex, m_function_basename_index, sc_list);
2008
2009    FindFunctions (regex, m_function_fullname_index, sc_list);
2010
2011    // Return the number of variable that were appended to the list
2012    return sc_list.GetSize() - original_size;
2013}
2014
2015uint32_t
2016SymbolFileDWARF::FindTypes(const SymbolContext& sc, const ConstString &name, bool append, uint32_t max_matches, TypeList& types)
2017{
2018    DWARFDebugInfo* info = DebugInfo();
2019    if (info == NULL)
2020        return 0;
2021
2022    // If we aren't appending the results to this list, then clear the list
2023    if (!append)
2024        types.Clear();
2025
2026    // Index if we already haven't to make sure the compile units
2027    // get indexed and make their global DIE index list
2028    if (!m_indexed)
2029        Index ();
2030
2031    const uint32_t initial_types_size = types.GetSize();
2032    DWARFCompileUnit* cu = NULL;
2033    DWARFCompileUnit* prev_cu = NULL;
2034    const DWARFDebugInfoEntry* die = NULL;
2035    std::vector<NameToDIE::Info> die_info_array;
2036    const size_t num_matches = m_types_index.Find (name, die_info_array);
2037    for (size_t i=0; i<num_matches; ++i, prev_cu = cu)
2038    {
2039        cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
2040
2041        if (cu != prev_cu)
2042            cu->ExtractDIEsIfNeeded (false);
2043
2044        die = cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
2045
2046        Type *matching_type = ResolveType (cu, die);
2047        if (matching_type)
2048        {
2049            // We found a type pointer, now find the shared pointer form our type list
2050            TypeSP type_sp (m_obj_file->GetModule()->GetTypeList()->FindType(matching_type->GetID()));
2051            assert (type_sp.get() != NULL);
2052            types.InsertUnique (type_sp);
2053            if (types.GetSize() >= max_matches)
2054                break;
2055        }
2056    }
2057    return types.GetSize() - initial_types_size;
2058}
2059
2060
2061uint32_t
2062SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
2063{
2064    // Remember how many sc_list are in the list before we search in case
2065    // we are appending the results to a variable list.
2066    uint32_t original_size = types.GetSize();
2067
2068    const uint32_t num_die_offsets = die_offsets.size();
2069    // Parse all of the types we found from the pubtypes matches
2070    uint32_t i;
2071    uint32_t num_matches = 0;
2072    for (i = 0; i < num_die_offsets; ++i)
2073    {
2074        Type *matching_type = ResolveTypeUID (die_offsets[i]);
2075        if (matching_type)
2076        {
2077            // We found a type pointer, now find the shared pointer form our type list
2078            TypeSP type_sp (m_obj_file->GetModule()->GetTypeList()->FindType(matching_type->GetID()));
2079            assert (type_sp.get() != NULL);
2080            types.InsertUnique (type_sp);
2081            ++num_matches;
2082            if (num_matches >= max_matches)
2083                break;
2084        }
2085    }
2086
2087    // Return the number of variable that were appended to the list
2088    return types.GetSize() - original_size;
2089}
2090
2091
2092size_t
2093SymbolFileDWARF::ParseChildParameters
2094(
2095    const SymbolContext& sc,
2096    TypeSP& type_sp,
2097    DWARFCompileUnit* dwarf_cu,
2098    const DWARFDebugInfoEntry *parent_die,
2099    bool skip_artificial,
2100    TypeList* type_list,
2101    std::vector<clang_type_t>& function_param_types,
2102    std::vector<clang::ParmVarDecl*>& function_param_decls
2103)
2104{
2105    if (parent_die == NULL)
2106        return 0;
2107
2108    const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
2109
2110    size_t count = 0;
2111    const DWARFDebugInfoEntry *die;
2112    for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
2113    {
2114        dw_tag_t tag = die->Tag();
2115        switch (tag)
2116        {
2117        case DW_TAG_formal_parameter:
2118            {
2119                DWARFDebugInfoEntry::Attributes attributes;
2120                const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
2121                if (num_attributes > 0)
2122                {
2123                    const char *name = NULL;
2124                    Declaration decl;
2125                    dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
2126                    bool is_artificial = false;
2127                    // one of None, Auto, Register, Extern, Static, PrivateExtern
2128
2129                    clang::StorageClass storage = clang::SC_None;
2130                    uint32_t i;
2131                    for (i=0; i<num_attributes; ++i)
2132                    {
2133                        const dw_attr_t attr = attributes.AttributeAtIndex(i);
2134                        DWARFFormValue form_value;
2135                        if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2136                        {
2137                            switch (attr)
2138                            {
2139                            case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2140                            case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break;
2141                            case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2142                            case DW_AT_name:        name = form_value.AsCString(&get_debug_str_data()); break;
2143                            case DW_AT_type:        param_type_die_offset = form_value.Reference(dwarf_cu); break;
2144                            case DW_AT_artificial:  is_artificial = form_value.Unsigned() != 0; break;
2145                            case DW_AT_location:
2146    //                          if (form_value.BlockData())
2147    //                          {
2148    //                              const DataExtractor& debug_info_data = debug_info();
2149    //                              uint32_t block_length = form_value.Unsigned();
2150    //                              DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
2151    //                          }
2152    //                          else
2153    //                          {
2154    //                          }
2155    //                          break;
2156                            case DW_AT_const_value:
2157                            case DW_AT_default_value:
2158                            case DW_AT_description:
2159                            case DW_AT_endianity:
2160                            case DW_AT_is_optional:
2161                            case DW_AT_segment:
2162                            case DW_AT_variable_parameter:
2163                            default:
2164                            case DW_AT_abstract_origin:
2165                            case DW_AT_sibling:
2166                                break;
2167                            }
2168                        }
2169                    }
2170
2171                    bool skip = false;
2172                    if (skip_artificial)
2173                    {
2174                        if (is_artificial)
2175                            skip = true;
2176                        else
2177                        {
2178
2179                            // HACK: Objective C formal parameters "self" and "_cmd"
2180                            // are not marked as artificial in the DWARF...
2181                            CompileUnit *cu = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
2182                            if (cu && (cu->GetLanguage() == eLanguageTypeObjC || cu->GetLanguage() == eLanguageTypeObjC_plus_plus))
2183                            {
2184                                if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
2185                                    skip = true;
2186                            }
2187                        }
2188                    }
2189
2190                    if (!skip)
2191                    {
2192                        Type *type = ResolveTypeUID(param_type_die_offset);
2193                        if (type)
2194                        {
2195                            function_param_types.push_back (type->GetClangForwardType());
2196
2197                            clang::ParmVarDecl *param_var_decl = type_list->GetClangASTContext().CreateParameterDeclaration (name, type->GetClangForwardType(), storage);
2198                            assert(param_var_decl);
2199                            function_param_decls.push_back(param_var_decl);
2200                        }
2201                    }
2202                }
2203            }
2204            break;
2205
2206        default:
2207            break;
2208        }
2209    }
2210    return count;
2211}
2212
2213size_t
2214SymbolFileDWARF::ParseChildEnumerators
2215(
2216    const SymbolContext& sc,
2217    clang_type_t  enumerator_clang_type,
2218    uint32_t enumerator_byte_size,
2219    DWARFCompileUnit* dwarf_cu,
2220    const DWARFDebugInfoEntry *parent_die
2221)
2222{
2223    if (parent_die == NULL)
2224        return 0;
2225
2226    size_t enumerators_added = 0;
2227    const DWARFDebugInfoEntry *die;
2228    const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
2229
2230    for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
2231    {
2232        const dw_tag_t tag = die->Tag();
2233        if (tag == DW_TAG_enumerator)
2234        {
2235            DWARFDebugInfoEntry::Attributes attributes;
2236            const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
2237            if (num_child_attributes > 0)
2238            {
2239                const char *name = NULL;
2240                bool got_value = false;
2241                int64_t enum_value = 0;
2242                Declaration decl;
2243
2244                uint32_t i;
2245                for (i=0; i<num_child_attributes; ++i)
2246                {
2247                    const dw_attr_t attr = attributes.AttributeAtIndex(i);
2248                    DWARFFormValue form_value;
2249                    if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2250                    {
2251                        switch (attr)
2252                        {
2253                        case DW_AT_const_value:
2254                            got_value = true;
2255                            enum_value = form_value.Unsigned();
2256                            break;
2257
2258                        case DW_AT_name:
2259                            name = form_value.AsCString(&get_debug_str_data());
2260                            break;
2261
2262                        case DW_AT_description:
2263                        default:
2264                        case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2265                        case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break;
2266                        case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2267                        case DW_AT_sibling:
2268                            break;
2269                        }
2270                    }
2271                }
2272
2273                if (name && name[0] && got_value)
2274                {
2275                    TypeList* type_list = m_obj_file->GetModule()->GetTypeList();
2276                    type_list->GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type,
2277                                                                                          enumerator_clang_type,
2278                                                                                          decl,
2279                                                                                          name,
2280                                                                                          enum_value,
2281                                                                                          enumerator_byte_size * 8);
2282                    ++enumerators_added;
2283                }
2284            }
2285        }
2286    }
2287    return enumerators_added;
2288}
2289
2290void
2291SymbolFileDWARF::ParseChildArrayInfo
2292(
2293    const SymbolContext& sc,
2294    DWARFCompileUnit* dwarf_cu,
2295    const DWARFDebugInfoEntry *parent_die,
2296    int64_t& first_index,
2297    std::vector<uint64_t>& element_orders,
2298    uint32_t& byte_stride,
2299    uint32_t& bit_stride
2300)
2301{
2302    if (parent_die == NULL)
2303        return;
2304
2305    const DWARFDebugInfoEntry *die;
2306    const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
2307    for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
2308    {
2309        const dw_tag_t tag = die->Tag();
2310        switch (tag)
2311        {
2312        case DW_TAG_enumerator:
2313            {
2314                DWARFDebugInfoEntry::Attributes attributes;
2315                const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
2316                if (num_child_attributes > 0)
2317                {
2318                    const char *name = NULL;
2319                    bool got_value = false;
2320                    int64_t enum_value = 0;
2321
2322                    uint32_t i;
2323                    for (i=0; i<num_child_attributes; ++i)
2324                    {
2325                        const dw_attr_t attr = attributes.AttributeAtIndex(i);
2326                        DWARFFormValue form_value;
2327                        if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2328                        {
2329                            switch (attr)
2330                            {
2331                            case DW_AT_const_value:
2332                                got_value = true;
2333                                enum_value = form_value.Unsigned();
2334                                break;
2335
2336                            case DW_AT_name:
2337                                name = form_value.AsCString(&get_debug_str_data());
2338                                break;
2339
2340                            case DW_AT_description:
2341                            default:
2342                            case DW_AT_decl_file:
2343                            case DW_AT_decl_line:
2344                            case DW_AT_decl_column:
2345                            case DW_AT_sibling:
2346                                break;
2347                            }
2348                        }
2349                    }
2350                }
2351            }
2352            break;
2353
2354        case DW_TAG_subrange_type:
2355            {
2356                DWARFDebugInfoEntry::Attributes attributes;
2357                const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
2358                if (num_child_attributes > 0)
2359                {
2360                    const char *name = NULL;
2361                    bool got_value = false;
2362                    uint64_t byte_size = 0;
2363                    int64_t enum_value = 0;
2364                    uint64_t num_elements = 0;
2365                    uint64_t lower_bound = 0;
2366                    uint64_t upper_bound = 0;
2367                    uint32_t i;
2368                    for (i=0; i<num_child_attributes; ++i)
2369                    {
2370                        const dw_attr_t attr = attributes.AttributeAtIndex(i);
2371                        DWARFFormValue form_value;
2372                        if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2373                        {
2374                            switch (attr)
2375                            {
2376                            case DW_AT_const_value:
2377                                got_value = true;
2378                                enum_value = form_value.Unsigned();
2379                                break;
2380
2381                            case DW_AT_name:
2382                                name = form_value.AsCString(&get_debug_str_data());
2383                                break;
2384
2385                            case DW_AT_count:
2386                                num_elements = form_value.Unsigned();
2387                                break;
2388
2389                            case DW_AT_bit_stride:
2390                                bit_stride = form_value.Unsigned();
2391                                break;
2392
2393                            case DW_AT_byte_stride:
2394                                byte_stride = form_value.Unsigned();
2395                                break;
2396
2397                            case DW_AT_byte_size:
2398                                byte_size = form_value.Unsigned();
2399                                break;
2400
2401                            case DW_AT_lower_bound:
2402                                lower_bound = form_value.Unsigned();
2403                                break;
2404
2405                            case DW_AT_upper_bound:
2406                                upper_bound = form_value.Unsigned();
2407                                break;
2408
2409                            default:
2410                            case DW_AT_abstract_origin:
2411                            case DW_AT_accessibility:
2412                            case DW_AT_allocated:
2413                            case DW_AT_associated:
2414                            case DW_AT_data_location:
2415                            case DW_AT_declaration:
2416                            case DW_AT_description:
2417                            case DW_AT_sibling:
2418                            case DW_AT_threads_scaled:
2419                            case DW_AT_type:
2420                            case DW_AT_visibility:
2421                                break;
2422                            }
2423                        }
2424                    }
2425
2426                    if (upper_bound > lower_bound)
2427                        num_elements = upper_bound - lower_bound + 1;
2428
2429                    if (num_elements > 0)
2430                        element_orders.push_back (num_elements);
2431                }
2432            }
2433            break;
2434        }
2435    }
2436}
2437
2438TypeSP
2439SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry* die)
2440{
2441    TypeSP type_sp;
2442    if (die != NULL)
2443    {
2444        assert(cu != NULL);
2445        Type *type_ptr = m_die_to_type.lookup (die);
2446        if (type_ptr == NULL)
2447        {
2448            SymbolContext sc(GetCompUnitForDWARFCompUnit(cu));
2449            type_sp = ParseType(sc, cu, die, NULL);
2450        }
2451        else if (type_ptr != DIE_IS_BEING_PARSED)
2452        {
2453            // Grab the existing type from the master types lists
2454            type_sp = m_obj_file->GetModule()->GetTypeList()->FindType(type_ptr->GetID());
2455        }
2456
2457    }
2458    return type_sp;
2459}
2460
2461clang::DeclContext *
2462SymbolFileDWARF::GetClangDeclContextForDIEOffset (dw_offset_t die_offset)
2463{
2464    if (die_offset != DW_INVALID_OFFSET)
2465    {
2466        DWARFCompileUnitSP cu_sp;
2467        const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
2468        return GetClangDeclContextForDIE (cu_sp.get(), die);
2469    }
2470    return NULL;
2471}
2472
2473
2474
2475clang::DeclContext *
2476SymbolFileDWARF::GetClangDeclContextForDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
2477{
2478    DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find(die);
2479    if (pos != m_die_to_decl_ctx.end())
2480        return pos->second;
2481
2482    while (die != NULL)
2483    {
2484        switch (die->Tag())
2485        {
2486        case DW_TAG_namespace:
2487            {
2488                const char *namespace_name = die->GetAttributeValueAsString(this, cu, DW_AT_name, NULL);
2489                if (namespace_name)
2490                {
2491                    TypeList* type_list = m_obj_file->GetModule()->GetTypeList();
2492                    assert(type_list);
2493                    Declaration decl;   // TODO: fill in the decl object
2494                    clang::NamespaceDecl *namespace_decl = type_list->GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, decl, GetClangDeclContextForDIE (cu, die->GetParent()));
2495                    if (namespace_decl)
2496                        m_die_to_decl_ctx[die] = (clang::DeclContext*)namespace_decl;
2497                    return namespace_decl;
2498                }
2499            }
2500            break;
2501
2502        default:
2503            break;
2504        }
2505        clang::DeclContext *decl_ctx;
2506        decl_ctx = GetClangDeclContextForDIEOffset (die->GetAttributeValueAsUnsigned(this, cu, DW_AT_specification, DW_INVALID_OFFSET));
2507        if (decl_ctx)
2508            return decl_ctx;
2509
2510        decl_ctx = GetClangDeclContextForDIEOffset (die->GetAttributeValueAsUnsigned(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET));
2511        if (decl_ctx)
2512            return decl_ctx;
2513
2514        die = die->GetParent();
2515    }
2516    return NULL;
2517}
2518
2519TypeSP
2520SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
2521{
2522    TypeSP type_sp;
2523
2524    if (type_is_new_ptr)
2525        *type_is_new_ptr = false;
2526
2527    AccessType accessibility = eAccessNone;
2528    if (die != NULL)
2529    {
2530        Type *type_ptr = m_die_to_type.lookup (die);
2531        if (type_ptr == NULL)
2532        {
2533            if (type_is_new_ptr)
2534                *type_is_new_ptr = true;
2535
2536            const dw_tag_t tag = die->Tag();
2537
2538            bool is_forward_declaration = false;
2539            DWARFDebugInfoEntry::Attributes attributes;
2540            const char *type_name_cstr = NULL;
2541            ConstString type_name_const_str;
2542            Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
2543            clang_type_t clang_type = NULL;
2544
2545            TypeList* type_list = m_obj_file->GetModule()->GetTypeList();
2546            dw_attr_t attr;
2547
2548            switch (tag)
2549            {
2550            case DW_TAG_base_type:
2551            case DW_TAG_pointer_type:
2552            case DW_TAG_reference_type:
2553            case DW_TAG_typedef:
2554            case DW_TAG_const_type:
2555            case DW_TAG_restrict_type:
2556            case DW_TAG_volatile_type:
2557                {
2558                    // Set a bit that lets us know that we are currently parsing this
2559                    m_die_to_type[die] = DIE_IS_BEING_PARSED;
2560
2561                    const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
2562                    Declaration decl;
2563                    uint32_t encoding = 0;
2564                    size_t byte_size = 0;
2565                    lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
2566
2567                    if (num_attributes > 0)
2568                    {
2569                        uint32_t i;
2570                        for (i=0; i<num_attributes; ++i)
2571                        {
2572                            attr = attributes.AttributeAtIndex(i);
2573                            DWARFFormValue form_value;
2574                            if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2575                            {
2576                                switch (attr)
2577                                {
2578                                case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2579                                case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break;
2580                                case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2581                                case DW_AT_name:
2582                                    type_name_cstr = form_value.AsCString(&get_debug_str_data());
2583                                    type_name_const_str.SetCString(type_name_cstr);
2584                                    break;
2585                                case DW_AT_byte_size:   byte_size = form_value.Unsigned();  break;
2586                                case DW_AT_encoding:    encoding = form_value.Unsigned(); break;
2587                                case DW_AT_type:        encoding_uid = form_value.Reference(dwarf_cu); break;
2588                                default:
2589                                case DW_AT_sibling:
2590                                    break;
2591                                }
2592                            }
2593                        }
2594                    }
2595
2596                    DEBUG_PRINTF ("0x%8.8x: %s (\"%s\") type => 0x%8.8x\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr, encoding_uid);
2597
2598                    switch (tag)
2599                    {
2600                    default:
2601                    case DW_TAG_base_type:
2602                        clang_type = type_list->GetClangASTContext().GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr, encoding, byte_size * 8);
2603                        break;
2604
2605                    case DW_TAG_pointer_type:
2606                        // The encoding_uid will be embedded into the
2607                        // Type object and will be looked up when the Type::GetClangType()
2608                        encoding_data_type = Type::eEncodingIsPointerUID;
2609                        break;
2610
2611                    case DW_TAG_reference_type:
2612                        // The encoding_uid will be embedded into the
2613                        // Type object and will be looked up when the Type::GetClangType()
2614                        encoding_data_type = Type::eEncodingIsLValueReferenceUID;
2615                        break;
2616
2617                    case DW_TAG_typedef:
2618                        // The encoding_uid will be embedded into the
2619                        // Type object and will be looked up when the Type::GetClangType()
2620                        encoding_data_type = Type::eEncodingIsTypedefUID;
2621                        break;
2622
2623                    case DW_TAG_const_type:
2624                        // The encoding_uid will be embedded into the
2625                        // Type object and will be looked up when the Type::GetClangType()
2626                        encoding_data_type = Type::eEncodingIsConstUID; //ClangASTContext::AddConstModifier (clang_type);
2627                        break;
2628
2629                    case DW_TAG_restrict_type:
2630                        // The encoding_uid will be embedded into the
2631                        // Type object and will be looked up when the Type::GetClangType()
2632                        encoding_data_type = Type::eEncodingIsRestrictUID; //ClangASTContext::AddRestrictModifier (clang_type);
2633                        break;
2634
2635                    case DW_TAG_volatile_type:
2636                        // The encoding_uid will be embedded into the
2637                        // Type object and will be looked up when the Type::GetClangType()
2638                        encoding_data_type = Type::eEncodingIsVolatileUID; //ClangASTContext::AddVolatileModifier (clang_type);
2639                        break;
2640                    }
2641
2642                    if (type_name_cstr != NULL && sc.comp_unit != NULL &&
2643                        (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus))
2644                    {
2645                        static ConstString g_objc_type_name_id("id");
2646                        static ConstString g_objc_type_name_Class("Class");
2647                        static ConstString g_objc_type_name_selector("SEL");
2648
2649                        if (type_name_const_str == g_objc_type_name_id)
2650                        {
2651                            clang_type = type_list->GetClangASTContext().GetBuiltInType_objc_id();
2652                        }
2653                        else if (type_name_const_str == g_objc_type_name_Class)
2654                        {
2655                            clang_type = type_list->GetClangASTContext().GetBuiltInType_objc_Class();
2656                        }
2657                        else if (type_name_const_str == g_objc_type_name_selector)
2658                        {
2659                            clang_type = type_list->GetClangASTContext().GetBuiltInType_objc_selector();
2660                        }
2661                    }
2662
2663                    type_sp.reset( new Type(die->GetOffset(), this, type_name_const_str, byte_size, NULL, encoding_uid, encoding_data_type, &decl, clang_type, clang_type == NULL));
2664
2665                    m_die_to_type[die] = type_sp.get();
2666
2667//                  Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
2668//                  if (encoding_type != NULL)
2669//                  {
2670//                      if (encoding_type != DIE_IS_BEING_PARSED)
2671//                          type_sp->SetEncodingType(encoding_type);
2672//                      else
2673//                          m_indirect_fixups.push_back(type_sp.get());
2674//                  }
2675                }
2676                break;
2677
2678            case DW_TAG_structure_type:
2679            case DW_TAG_union_type:
2680            case DW_TAG_class_type:
2681                {
2682                    // Set a bit that lets us know that we are currently parsing this
2683                    m_die_to_type[die] = DIE_IS_BEING_PARSED;
2684
2685                    size_t byte_size = 0;
2686                    LanguageType class_language = eLanguageTypeUnknown;
2687                    //bool struct_is_class = false;
2688                    Declaration decl;
2689                    const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
2690                    if (num_attributes > 0)
2691                    {
2692                        uint32_t i;
2693                        for (i=0; i<num_attributes; ++i)
2694                        {
2695                            attr = attributes.AttributeAtIndex(i);
2696                            DWARFFormValue form_value;
2697                            if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2698                            {
2699                                switch (attr)
2700                                {
2701                                case DW_AT_decl_file:
2702                                    decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
2703                                    break;
2704
2705                                case DW_AT_decl_line:
2706                                    decl.SetLine(form_value.Unsigned());
2707                                    break;
2708
2709                                case DW_AT_decl_column:
2710                                    decl.SetColumn(form_value.Unsigned());
2711                                    break;
2712
2713                                case DW_AT_name:
2714                                    type_name_cstr = form_value.AsCString(&get_debug_str_data());
2715                                    type_name_const_str.SetCString(type_name_cstr);
2716                                    break;
2717
2718                                case DW_AT_byte_size:
2719                                    byte_size = form_value.Unsigned();
2720                                    break;
2721
2722                                case DW_AT_accessibility:
2723                                    accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
2724                                    break;
2725
2726                                case DW_AT_declaration:
2727                                    is_forward_declaration = form_value.Unsigned() != 0;
2728                                    break;
2729
2730                                case DW_AT_APPLE_runtime_class:
2731                                    class_language = (LanguageType)form_value.Signed();
2732                                    break;
2733
2734                                case DW_AT_allocated:
2735                                case DW_AT_associated:
2736                                case DW_AT_data_location:
2737                                case DW_AT_description:
2738                                case DW_AT_start_scope:
2739                                case DW_AT_visibility:
2740                                default:
2741                                case DW_AT_sibling:
2742                                    break;
2743                                }
2744                            }
2745                        }
2746                    }
2747
2748                    DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr);
2749
2750                    int tag_decl_kind = -1;
2751                    AccessType default_accessibility = eAccessNone;
2752                    if (tag == DW_TAG_structure_type)
2753                    {
2754                        tag_decl_kind = clang::TTK_Struct;
2755                        default_accessibility = eAccessPublic;
2756                    }
2757                    else if (tag == DW_TAG_union_type)
2758                    {
2759                        tag_decl_kind = clang::TTK_Union;
2760                        default_accessibility = eAccessPublic;
2761                    }
2762                    else if (tag == DW_TAG_class_type)
2763                    {
2764                        tag_decl_kind = clang::TTK_Class;
2765                        default_accessibility = eAccessPrivate;
2766                    }
2767
2768
2769                    if (is_forward_declaration)
2770                    {
2771                        // We have a forward declaration
2772                        std::vector<NameToDIE::Info> die_info_array;
2773                        const size_t num_matches = m_types_index.Find (type_name_const_str, die_info_array);
2774                        DWARFCompileUnit* type_cu = NULL;
2775                        DWARFCompileUnit* curr_cu = dwarf_cu;
2776                        DWARFDebugInfo *info = DebugInfo();
2777                        for (size_t i=0; i<num_matches; ++i)
2778                        {
2779                            type_cu = info->GetCompileUnitAtIndex (die_info_array[i].cu_idx);
2780
2781                            if (type_cu != curr_cu)
2782                            {
2783                                type_cu->ExtractDIEsIfNeeded (false);
2784                                curr_cu = type_cu;
2785                            }
2786
2787                            DWARFDebugInfoEntry *type_die = type_cu->GetDIEAtIndexUnchecked (die_info_array[i].die_idx);
2788
2789                            if (type_die != die && type_die->Tag() == tag)
2790                            {
2791                                // Hold off on comparing parent DIE tags until
2792                                // we know what happens with stuff in namespaces
2793                                // for gcc and clang...
2794//                                DWARFDebugInfoEntry *parent_die = die->GetParent();
2795//                                DWARFDebugInfoEntry *parent_type_die = type_die->GetParent();
2796//                                if (parent_die->Tag() == parent_type_die->Tag())
2797                                {
2798                                    Type *resolved_type = ResolveType (type_cu, type_die, false);
2799                                    if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
2800                                    {
2801                                        DEBUG_PRINTF ("resolved 0x%8.8x (cu 0x%8.8x) from %s to 0x%8.8x (cu 0x%8.8x)\n",
2802                                                      die->GetOffset(),
2803                                                      dwarf_cu->GetOffset(),
2804                                                      m_obj_file->GetFileSpec().GetFilename().AsCString(),
2805                                                      type_die->GetOffset(),
2806                                                      type_cu->GetOffset());
2807
2808                                        m_die_to_type[die] = resolved_type;
2809                                        type_sp = m_obj_file->GetModule()->GetTypeList()->FindType(resolved_type->GetID());
2810                                        return type_sp;
2811                                    }
2812                                }
2813                            }
2814                        }
2815                    }
2816                    assert (tag_decl_kind != -1);
2817                    bool clang_type_was_created = false;
2818                    clang_type = m_forward_decl_die_to_clang_type.lookup (die);
2819                    if (clang_type == NULL)
2820                    {
2821                        clang_type_was_created = true;
2822                        clang_type = type_list->GetClangASTContext().CreateRecordType (type_name_cstr, tag_decl_kind, GetClangDeclContextForDIE (dwarf_cu, die), class_language);
2823                    }
2824
2825                    // Store a forward declaration to this class type in case any
2826                    // parameters in any class methods need it for the clang
2827                    // types for function prototypes.
2828                    m_die_to_decl_ctx[die] = ClangASTContext::GetDeclContextForType (clang_type);
2829                    const bool is_forward_decl = die->HasChildren();
2830                    type_sp.reset (new Type(die->GetOffset(), this, type_name_const_str, byte_size, NULL, LLDB_INVALID_UID, Type::eEncodingIsUID, &decl, clang_type, is_forward_decl));
2831
2832                    m_die_to_type[die] = type_sp.get();
2833
2834                    if (die->HasChildren() == false)
2835                    {
2836                        // No children for this struct/union/class, lets finish it
2837                        type_list->GetClangASTContext().StartTagDeclarationDefinition (clang_type);
2838                        type_list->GetClangASTContext().CompleteTagDeclarationDefinition (clang_type);
2839                    }
2840                    else if (clang_type_was_created)
2841                    {
2842                        // Leave this as a forward declaration until we need
2843                        // to know the details of the type. lldb_private::Type
2844                        // will automatically call the SymbolFile virtual function
2845                        // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
2846                        // When the definition needs to be defined.
2847                        m_forward_decl_die_to_clang_type[die] = clang_type;
2848                        m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
2849                    }
2850
2851                }
2852                break;
2853
2854            case DW_TAG_enumeration_type:
2855                {
2856                    // Set a bit that lets us know that we are currently parsing this
2857                    m_die_to_type[die] = DIE_IS_BEING_PARSED;
2858
2859                    size_t byte_size = 0;
2860                    lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
2861                    Declaration decl;
2862
2863                    const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
2864                    if (num_attributes > 0)
2865                    {
2866                        uint32_t i;
2867
2868                        for (i=0; i<num_attributes; ++i)
2869                        {
2870                            attr = attributes.AttributeAtIndex(i);
2871                            DWARFFormValue form_value;
2872                            if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2873                            {
2874                                switch (attr)
2875                                {
2876                                case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2877                                case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break;
2878                                case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2879                                case DW_AT_name:
2880                                    type_name_cstr = form_value.AsCString(&get_debug_str_data());
2881                                    type_name_const_str.SetCString(type_name_cstr);
2882                                    break;
2883                                case DW_AT_type:        encoding_uid = form_value.Reference(dwarf_cu); break;
2884                                case DW_AT_byte_size:   byte_size = form_value.Unsigned(); break;
2885                                case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
2886                                case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break;
2887                                case DW_AT_allocated:
2888                                case DW_AT_associated:
2889                                case DW_AT_bit_stride:
2890                                case DW_AT_byte_stride:
2891                                case DW_AT_data_location:
2892                                case DW_AT_description:
2893                                case DW_AT_start_scope:
2894                                case DW_AT_visibility:
2895                                case DW_AT_specification:
2896                                case DW_AT_abstract_origin:
2897                                case DW_AT_sibling:
2898                                    break;
2899                                }
2900                            }
2901                        }
2902
2903                        DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr);
2904
2905                        clang_type_t enumerator_clang_type = NULL;
2906                        clang_type = m_forward_decl_die_to_clang_type.lookup (die);
2907                        if (clang_type == NULL)
2908                        {
2909                            enumerator_clang_type = type_list->GetClangASTContext().GetBuiltinTypeForDWARFEncodingAndBitSize (NULL, DW_ATE_signed, byte_size * 8);
2910                            clang_type = type_list->GetClangASTContext().CreateEnumerationType(decl, type_name_cstr, enumerator_clang_type);
2911                        }
2912                        else
2913                        {
2914                            enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type);
2915                            assert (enumerator_clang_type != NULL);
2916                        }
2917
2918                        m_die_to_decl_ctx[die] = ClangASTContext::GetDeclContextForType (clang_type);
2919                        type_sp.reset( new Type(die->GetOffset(), this, type_name_const_str, byte_size, NULL, encoding_uid, Type::eEncodingIsUID, &decl, clang_type, true));
2920
2921                        m_die_to_type[die] = type_sp.get();
2922
2923                        // Leave this as a forward declaration until we need
2924                        // to know the details of the type. lldb_private::Type
2925                        // will automatically call the SymbolFile virtual function
2926                        // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
2927                        // When the definition needs to be defined.
2928                        m_forward_decl_die_to_clang_type[die] = clang_type;
2929                        m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
2930
2931                    }
2932                }
2933                break;
2934
2935            case DW_TAG_inlined_subroutine:
2936            case DW_TAG_subprogram:
2937            case DW_TAG_subroutine_type:
2938                {
2939                    // Set a bit that lets us know that we are currently parsing this
2940                    m_die_to_type[die] = DIE_IS_BEING_PARSED;
2941
2942                    const char *mangled = NULL;
2943                    dw_offset_t type_die_offset = DW_INVALID_OFFSET;
2944                    Declaration decl;
2945                    bool is_variadic = false;
2946                    bool is_inline = false;
2947                    bool is_static = false;
2948                    bool is_virtual = false;
2949                    bool is_explicit = false;
2950
2951                    unsigned type_quals = 0;
2952                    clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
2953
2954
2955                    const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
2956                    if (num_attributes > 0)
2957                    {
2958                        uint32_t i;
2959                        for (i=0; i<num_attributes; ++i)
2960                        {
2961                            const dw_attr_t attr = attributes.AttributeAtIndex(i);
2962                            DWARFFormValue form_value;
2963                            if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2964                            {
2965                                switch (attr)
2966                                {
2967                                case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2968                                case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break;
2969                                case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2970                                case DW_AT_name:
2971                                    type_name_cstr = form_value.AsCString(&get_debug_str_data());
2972                                    type_name_const_str.SetCString(type_name_cstr);
2973                                    break;
2974
2975                                case DW_AT_MIPS_linkage_name:   mangled = form_value.AsCString(&get_debug_str_data()); break;
2976                                case DW_AT_type:                type_die_offset = form_value.Reference(dwarf_cu); break;
2977                                case DW_AT_accessibility:       accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
2978                                case DW_AT_declaration:         is_forward_declaration = form_value.Unsigned() != 0; break;
2979                                case DW_AT_inline:              is_inline = form_value.Unsigned() != 0; break;
2980                                case DW_AT_virtuality:          is_virtual = form_value.Unsigned() != 0;  break;
2981                                case DW_AT_explicit:            is_explicit = form_value.Unsigned() != 0;  break;
2982
2983                                case DW_AT_external:
2984                                    if (form_value.Unsigned())
2985                                    {
2986                                        if (storage == clang::SC_None)
2987                                            storage = clang::SC_Extern;
2988                                        else
2989                                            storage = clang::SC_PrivateExtern;
2990                                    }
2991                                    break;
2992
2993                                case DW_AT_allocated:
2994                                case DW_AT_associated:
2995                                case DW_AT_address_class:
2996                                case DW_AT_artificial:
2997                                case DW_AT_calling_convention:
2998                                case DW_AT_data_location:
2999                                case DW_AT_elemental:
3000                                case DW_AT_entry_pc:
3001                                case DW_AT_frame_base:
3002                                case DW_AT_high_pc:
3003                                case DW_AT_low_pc:
3004                                case DW_AT_object_pointer:
3005                                case DW_AT_prototyped:
3006                                case DW_AT_pure:
3007                                case DW_AT_ranges:
3008                                case DW_AT_recursive:
3009                                case DW_AT_return_addr:
3010                                case DW_AT_segment:
3011                                case DW_AT_specification:
3012                                case DW_AT_start_scope:
3013                                case DW_AT_static_link:
3014                                case DW_AT_trampoline:
3015                                case DW_AT_visibility:
3016                                case DW_AT_vtable_elem_location:
3017                                case DW_AT_abstract_origin:
3018                                case DW_AT_description:
3019                                case DW_AT_sibling:
3020                                    break;
3021                                }
3022                            }
3023                        }
3024                    }
3025
3026                    DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr);
3027
3028                    clang_type_t return_clang_type = NULL;
3029                    Type *func_type = NULL;
3030
3031                    if (type_die_offset != DW_INVALID_OFFSET)
3032                        func_type = ResolveTypeUID(type_die_offset);
3033
3034                    if (func_type)
3035                        return_clang_type = func_type->GetClangForwardType();
3036                    else
3037                        return_clang_type = type_list->GetClangASTContext().GetBuiltInType_void();
3038
3039
3040                    std::vector<clang_type_t> function_param_types;
3041                    std::vector<clang::ParmVarDecl*> function_param_decls;
3042
3043                    // Parse the function children for the parameters
3044                    if (die->HasChildren())
3045                    {
3046                        bool skip_artificial = true;
3047                        ParseChildParameters (sc, type_sp, dwarf_cu, die, skip_artificial, type_list, function_param_types, function_param_decls);
3048                    }
3049
3050                    // clang_type will get the function prototype clang type after this call
3051                    clang_type = type_list->GetClangASTContext().CreateFunctionType (return_clang_type, &function_param_types[0], function_param_types.size(), is_variadic, type_quals);
3052
3053                    if (type_name_cstr)
3054                    {
3055                        bool type_handled = false;
3056                        const DWARFDebugInfoEntry *parent_die = die->GetParent();
3057                        if (tag == DW_TAG_subprogram)
3058                        {
3059                            if (type_name_cstr[1] == '[' && (type_name_cstr[0] == '-' || type_name_cstr[0] == '+'))
3060                            {
3061                                // We need to find the DW_TAG_class_type or
3062                                // DW_TAG_struct_type by name so we can add this
3063                                // as a member function of the class.
3064                                const char *class_name_start = type_name_cstr + 2;
3065                                const char *class_name_end = ::strchr (class_name_start, ' ');
3066                                SymbolContext empty_sc;
3067                                clang_type_t class_opaque_type = NULL;
3068                                if (class_name_start < class_name_end)
3069                                {
3070                                    ConstString class_name (class_name_start, class_name_end - class_name_start);
3071                                    TypeList types;
3072                                    const uint32_t match_count = FindTypes (empty_sc, class_name, true, UINT32_MAX, types);
3073                                    if (match_count > 0)
3074                                    {
3075                                        for (uint32_t i=0; i<match_count; ++i)
3076                                        {
3077                                            Type *type = types.GetTypeAtIndex (i).get();
3078                                            clang_type_t type_clang_forward_type = type->GetClangForwardType();
3079                                            if (ClangASTContext::IsObjCClassType (type_clang_forward_type))
3080                                            {
3081                                                class_opaque_type = type_clang_forward_type;
3082                                                break;
3083                                            }
3084                                        }
3085                                    }
3086                                }
3087
3088                                if (class_opaque_type)
3089                                {
3090                                    // If accessibility isn't set to anything valid, assume public for
3091                                    // now...
3092                                    if (accessibility == eAccessNone)
3093                                        accessibility = eAccessPublic;
3094
3095                                    clang::ObjCMethodDecl *objc_method_decl;
3096                                    objc_method_decl = type_list->GetClangASTContext().AddMethodToObjCObjectType (class_opaque_type,
3097                                                                                                                  type_name_cstr,
3098                                                                                                                  clang_type,
3099                                                                                                                  accessibility);
3100                                    type_handled = objc_method_decl != NULL;
3101                                }
3102                            }
3103                            else if (parent_die->Tag() == DW_TAG_class_type ||
3104                                     parent_die->Tag() == DW_TAG_structure_type)
3105                            {
3106                                // Look at the parent of this DIE and see if is is
3107                                // a class or struct and see if this is actually a
3108                                // C++ method
3109                                Type *class_type = ResolveType (dwarf_cu, parent_die);
3110                                if (class_type)
3111                                {
3112                                    clang_type_t class_opaque_type = class_type->GetClangForwardType();
3113                                    if (ClangASTContext::IsCXXClassType (class_opaque_type))
3114                                    {
3115                                        // Neither GCC 4.2 nor clang++ currently set a valid accessibility
3116                                        // in the DWARF for C++ methods... Default to public for now...
3117                                        if (accessibility == eAccessNone)
3118                                            accessibility = eAccessPublic;
3119
3120                                        clang::CXXMethodDecl *cxx_method_decl;
3121                                        cxx_method_decl = type_list->GetClangASTContext().AddMethodToCXXRecordType (class_opaque_type,
3122                                                                                                                    type_name_cstr,
3123                                                                                                                    clang_type,
3124                                                                                                                    accessibility,
3125                                                                                                                    is_virtual,
3126                                                                                                                    is_static,
3127                                                                                                                    is_inline,
3128                                                                                                                    is_explicit);
3129                                        type_handled = cxx_method_decl != NULL;
3130                                    }
3131                                }
3132                            }
3133                        }
3134
3135                        if (!type_handled)
3136                        {
3137                            // We just have a function that isn't part of a class
3138                            clang::FunctionDecl *function_decl = type_list->GetClangASTContext().CreateFunctionDeclaration (type_name_cstr, clang_type, storage, is_inline);
3139
3140                            // Add the decl to our DIE to decl context map
3141                            assert (function_decl);
3142                            m_die_to_decl_ctx[die] = function_decl;
3143                            if (!function_param_decls.empty())
3144                                type_list->GetClangASTContext().SetFunctionParameters (function_decl, &function_param_decls.front(), function_param_decls.size());
3145                        }
3146                    }
3147                    type_sp.reset( new Type(die->GetOffset(), this, type_name_const_str, 0, NULL, LLDB_INVALID_UID, Type::eEncodingIsUID, &decl, clang_type, false));
3148
3149                    m_die_to_type[die] = type_sp.get();
3150                    assert(type_sp.get());
3151                }
3152                break;
3153
3154            case DW_TAG_array_type:
3155                {
3156                    // Set a bit that lets us know that we are currently parsing this
3157                    m_die_to_type[die] = DIE_IS_BEING_PARSED;
3158
3159                    size_t byte_size = 0;
3160                    lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
3161                    Declaration decl;
3162                    int64_t first_index = 0;
3163                    uint32_t byte_stride = 0;
3164                    uint32_t bit_stride = 0;
3165                    const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
3166
3167                    if (num_attributes > 0)
3168                    {
3169                        uint32_t i;
3170                        for (i=0; i<num_attributes; ++i)
3171                        {
3172                            attr = attributes.AttributeAtIndex(i);
3173                            DWARFFormValue form_value;
3174                            if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3175                            {
3176                                switch (attr)
3177                                {
3178                                case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3179                                case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break;
3180                                case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3181                                case DW_AT_name:
3182                                    type_name_cstr = form_value.AsCString(&get_debug_str_data());
3183                                    type_name_const_str.SetCString(type_name_cstr);
3184                                    break;
3185
3186                                case DW_AT_type:            type_die_offset = form_value.Reference(dwarf_cu); break;
3187                                case DW_AT_byte_size:       byte_size = form_value.Unsigned(); break;
3188                                case DW_AT_byte_stride:     byte_stride = form_value.Unsigned(); break;
3189                                case DW_AT_bit_stride:      bit_stride = form_value.Unsigned(); break;
3190                                case DW_AT_accessibility:   accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
3191                                case DW_AT_declaration:     is_forward_declaration = form_value.Unsigned() != 0; break;
3192                                case DW_AT_allocated:
3193                                case DW_AT_associated:
3194                                case DW_AT_data_location:
3195                                case DW_AT_description:
3196                                case DW_AT_ordering:
3197                                case DW_AT_start_scope:
3198                                case DW_AT_visibility:
3199                                case DW_AT_specification:
3200                                case DW_AT_abstract_origin:
3201                                case DW_AT_sibling:
3202                                    break;
3203                                }
3204                            }
3205                        }
3206
3207                        DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr);
3208
3209                        Type *element_type = ResolveTypeUID(type_die_offset);
3210
3211                        if (element_type)
3212                        {
3213                            std::vector<uint64_t> element_orders;
3214                            ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
3215                            // We have an array that claims to have no members, lets give it at least one member...
3216                            if (element_orders.empty())
3217                                element_orders.push_back (1);
3218                            if (byte_stride == 0 && bit_stride == 0)
3219                                byte_stride = element_type->GetByteSize();
3220                            clang_type_t array_element_type = element_type->GetClangType();
3221                            uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
3222                            uint64_t num_elements = 0;
3223                            std::vector<uint64_t>::const_reverse_iterator pos;
3224                            std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
3225                            for (pos = element_orders.rbegin(); pos != end; ++pos)
3226                            {
3227                                num_elements = *pos;
3228                                clang_type = type_list->GetClangASTContext().CreateArrayType (array_element_type, num_elements, num_elements * array_element_bit_stride);
3229                                array_element_type = clang_type;
3230                                array_element_bit_stride = array_element_bit_stride * num_elements;
3231                            }
3232                            ConstString empty_name;
3233                            type_sp.reset( new Type(die->GetOffset(), this, empty_name, array_element_bit_stride / 8, NULL, LLDB_INVALID_UID, Type::eEncodingIsUID, &decl, clang_type, false));
3234                            m_die_to_type[die] = type_sp.get();
3235                        }
3236                    }
3237                }
3238                break;
3239
3240            case DW_TAG_ptr_to_member_type:
3241                {
3242                    dw_offset_t type_die_offset = DW_INVALID_OFFSET;
3243                    dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
3244
3245                    const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
3246
3247                    if (num_attributes > 0) {
3248                        uint32_t i;
3249                        for (i=0; i<num_attributes; ++i)
3250                        {
3251                            attr = attributes.AttributeAtIndex(i);
3252                            DWARFFormValue form_value;
3253                            if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3254                            {
3255                                switch (attr)
3256                                {
3257                                    case DW_AT_type:
3258                                        type_die_offset = form_value.Reference(dwarf_cu); break;
3259                                    case DW_AT_containing_type:
3260                                        containing_type_die_offset = form_value.Reference(dwarf_cu); break;
3261                                }
3262                            }
3263                        }
3264
3265                        Type *pointee_type = ResolveTypeUID(type_die_offset);
3266                        Type *class_type = ResolveTypeUID(containing_type_die_offset);
3267
3268                        clang_type_t pointee_clang_type = pointee_type->GetClangType();
3269                        clang_type_t class_clang_type = class_type->GetClangType();
3270
3271                        clang_type = type_list->GetClangASTContext().CreateMemberPointerType(pointee_clang_type, class_clang_type);
3272
3273                        size_t byte_size = ClangASTType::GetClangTypeBitWidth (type_list->GetClangASTContext().getASTContext(), clang_type) / 8;
3274
3275                        type_sp.reset( new Type(die->GetOffset(), this, type_name_const_str, byte_size, NULL, LLDB_INVALID_UID, Type::eEncodingIsUID, NULL, clang_type, false));
3276                        m_die_to_type[die] = type_sp.get();
3277                    }
3278
3279                    break;
3280                }
3281            default:
3282                assert(false && "Unhandled type tag!");
3283                break;
3284            }
3285
3286            if (type_sp.get())
3287            {
3288                const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
3289                dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
3290
3291                SymbolContextScope * symbol_context_scope = NULL;
3292                if (sc_parent_tag == DW_TAG_compile_unit)
3293                {
3294                    symbol_context_scope = sc.comp_unit;
3295                }
3296                else if (sc.function != NULL)
3297                {
3298                    symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(sc_parent_die->GetOffset());
3299                    if (symbol_context_scope == NULL)
3300                        symbol_context_scope = sc.function;
3301                }
3302
3303                if (symbol_context_scope != NULL)
3304                {
3305                    type_sp->SetSymbolContextScope(symbol_context_scope);
3306                }
3307
3308//              if (udt_sp.get())
3309//              {
3310//                  if (is_forward_declaration)
3311//                      udt_sp->GetFlags().Set(UserDefType::flagIsForwardDefinition);
3312//                  type_sp->SetUserDefinedType(udt_sp);
3313//              }
3314
3315                if (type_sp.unique())
3316                {
3317                    // We are ready to put this type into the uniqued list up at the module level
3318                    TypeSP uniqued_type_sp(m_obj_file->GetModule()->GetTypeList()->InsertUnique(type_sp));
3319
3320                    if (m_debug_map_symfile)
3321                        m_debug_map_symfile->GetObjectFile()->GetModule()->GetTypeList()->InsertUnique (uniqued_type_sp);
3322
3323                    type_sp = uniqued_type_sp;
3324                    m_die_to_type[die] = type_sp.get();
3325                }
3326            }
3327        }
3328        else if (type_ptr != DIE_IS_BEING_PARSED)
3329        {
3330            type_sp = m_obj_file->GetModule()->GetTypeList()->FindType(type_ptr->GetID());
3331        }
3332    }
3333    return type_sp;
3334}
3335
3336size_t
3337SymbolFileDWARF::ParseTypes
3338(
3339    const SymbolContext& sc,
3340    DWARFCompileUnit* dwarf_cu,
3341    const DWARFDebugInfoEntry *die,
3342    bool parse_siblings,
3343    bool parse_children
3344)
3345{
3346    size_t types_added = 0;
3347    while (die != NULL)
3348    {
3349        bool type_is_new = false;
3350        if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
3351        {
3352            if (type_is_new)
3353                ++types_added;
3354        }
3355
3356        if (parse_children && die->HasChildren())
3357        {
3358            if (die->Tag() == DW_TAG_subprogram)
3359            {
3360                SymbolContext child_sc(sc);
3361                child_sc.function = sc.comp_unit->FindFunctionByUID(die->GetOffset()).get();
3362                types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
3363            }
3364            else
3365                types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
3366        }
3367
3368        if (parse_siblings)
3369            die = die->GetSibling();
3370        else
3371            die = NULL;
3372    }
3373    return types_added;
3374}
3375
3376
3377size_t
3378SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
3379{
3380    assert(sc.comp_unit && sc.function);
3381    size_t functions_added = 0;
3382    DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
3383    if (dwarf_cu)
3384    {
3385        dw_offset_t function_die_offset = sc.function->GetID();
3386        const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
3387        if (function_die)
3388        {
3389            ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, false, true);
3390        }
3391    }
3392
3393    return functions_added;
3394}
3395
3396
3397size_t
3398SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
3399{
3400    // At least a compile unit must be valid
3401    assert(sc.comp_unit);
3402    size_t types_added = 0;
3403    DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
3404    if (dwarf_cu)
3405    {
3406        if (sc.function)
3407        {
3408            dw_offset_t function_die_offset = sc.function->GetID();
3409            const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
3410            if (func_die && func_die->HasChildren())
3411            {
3412                types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
3413            }
3414        }
3415        else
3416        {
3417            const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
3418            if (dwarf_cu_die && dwarf_cu_die->HasChildren())
3419            {
3420                types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
3421            }
3422        }
3423    }
3424
3425    return types_added;
3426}
3427
3428size_t
3429SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
3430{
3431    if (sc.comp_unit != NULL)
3432    {
3433        DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
3434
3435        if (dwarf_cu == NULL)
3436            return 0;
3437
3438        if (sc.function)
3439        {
3440            const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
3441
3442            dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, DW_INVALID_ADDRESS);
3443            assert (func_lo_pc != DW_INVALID_ADDRESS);
3444
3445            return ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
3446        }
3447        else if (sc.comp_unit)
3448        {
3449            uint32_t vars_added = 0;
3450            VariableListSP variables (sc.comp_unit->GetVariableList(false));
3451
3452            if (variables.get() == NULL)
3453            {
3454                variables.reset(new VariableList());
3455                sc.comp_unit->SetVariableList(variables);
3456
3457                // Index if we already haven't to make sure the compile units
3458                // get indexed and make their global DIE index list
3459                if (!m_indexed)
3460                    Index ();
3461
3462
3463                std::vector<NameToDIE::Info> global_die_info_array;
3464                const size_t num_globals = m_global_index.FindAllEntriesForCompileUnitWithIndex (sc.comp_unit->GetID(), global_die_info_array);
3465                for (size_t idx=0; idx<num_globals; ++idx)
3466                {
3467                    VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, dwarf_cu->GetDIEAtIndexUnchecked(global_die_info_array[idx].die_idx), LLDB_INVALID_ADDRESS));
3468                    if (var_sp)
3469                    {
3470                        variables->AddVariable(var_sp);
3471                        ++vars_added;
3472                    }
3473                }
3474            }
3475            return vars_added;
3476        }
3477    }
3478    return 0;
3479}
3480
3481
3482VariableSP
3483SymbolFileDWARF::ParseVariableDIE
3484(
3485    const SymbolContext& sc,
3486    DWARFCompileUnit* dwarf_cu,
3487    const DWARFDebugInfoEntry *die,
3488    const lldb::addr_t func_low_pc
3489)
3490{
3491
3492    VariableSP var_sp;
3493
3494    const dw_tag_t tag = die->Tag();
3495    DWARFDebugInfoEntry::Attributes attributes;
3496    const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
3497    if (num_attributes > 0)
3498    {
3499        const char *name = NULL;
3500        const char *mangled = NULL;
3501        Declaration decl;
3502        uint32_t i;
3503        Type *var_type = NULL;
3504        DWARFExpression location;
3505        bool is_external = false;
3506        bool is_artificial = false;
3507        AccessType accessibility = eAccessNone;
3508
3509        for (i=0; i<num_attributes; ++i)
3510        {
3511            dw_attr_t attr = attributes.AttributeAtIndex(i);
3512            DWARFFormValue form_value;
3513            if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3514            {
3515                switch (attr)
3516                {
3517                case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3518                case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break;
3519                case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3520                case DW_AT_name:        name = form_value.AsCString(&get_debug_str_data()); break;
3521                case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
3522                case DW_AT_type:        var_type = ResolveTypeUID(form_value.Reference(dwarf_cu)); break;
3523                case DW_AT_external:    is_external = form_value.Unsigned() != 0; break;
3524                case DW_AT_location:
3525                    {
3526                        if (form_value.BlockData())
3527                        {
3528                            const DataExtractor& debug_info_data = get_debug_info_data();
3529
3530                            uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
3531                            uint32_t block_length = form_value.Unsigned();
3532                            location.SetOpcodeData(get_debug_info_data(), block_offset, block_length);
3533                        }
3534                        else
3535                        {
3536                            const DataExtractor&    debug_loc_data = get_debug_loc_data();
3537                            const dw_offset_t debug_loc_offset = form_value.Unsigned();
3538
3539                            size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
3540                            if (loc_list_length > 0)
3541                            {
3542                                location.SetOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
3543                                assert (func_low_pc != LLDB_INVALID_ADDRESS);
3544                                location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
3545                            }
3546                        }
3547                    }
3548                    break;
3549
3550                case DW_AT_artificial:      is_artificial = form_value.Unsigned() != 0; break;
3551                case DW_AT_accessibility:   accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
3552                case DW_AT_const_value:
3553                case DW_AT_declaration:
3554                case DW_AT_description:
3555                case DW_AT_endianity:
3556                case DW_AT_segment:
3557                case DW_AT_start_scope:
3558                case DW_AT_visibility:
3559                default:
3560                case DW_AT_abstract_origin:
3561                case DW_AT_sibling:
3562                case DW_AT_specification:
3563                    break;
3564                }
3565            }
3566        }
3567
3568        if (location.IsValid())
3569        {
3570            assert(var_type != DIE_IS_BEING_PARSED);
3571
3572            ConstString var_name;
3573            if (mangled)
3574            {
3575                Mangled mangled_var_name (mangled, true);
3576                var_name = mangled_var_name.GetDemangledName();
3577            }
3578
3579            if (!var_name && name)
3580            {
3581                var_name.SetCString(name);
3582            }
3583
3584            ValueType scope = eValueTypeInvalid;
3585
3586            const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
3587            dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
3588
3589            if (tag == DW_TAG_formal_parameter)
3590                scope = eValueTypeVariableArgument;
3591            else if (is_external || parent_tag == DW_TAG_compile_unit)
3592                scope = eValueTypeVariableGlobal;
3593            else
3594                scope = eValueTypeVariableLocal;
3595
3596            SymbolContextScope * symbol_context_scope = NULL;
3597            if (parent_tag == DW_TAG_compile_unit)
3598            {
3599                symbol_context_scope = sc.comp_unit;
3600            }
3601            else if (sc.function != NULL)
3602            {
3603                symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(sc_parent_die->GetOffset());
3604                if (symbol_context_scope == NULL)
3605                    symbol_context_scope = sc.function;
3606            }
3607
3608            assert(symbol_context_scope != NULL);
3609            var_sp.reset (new Variable(die->GetOffset(),
3610                                       var_name,
3611                                       var_type,
3612                                       scope,
3613                                       symbol_context_scope,
3614                                       &decl,
3615                                       location,
3616                                       is_external,
3617                                       is_artificial));
3618
3619            m_die_to_variable_sp[die] = var_sp;
3620        }
3621    }
3622    return var_sp;
3623}
3624
3625size_t
3626SymbolFileDWARF::ParseVariables
3627(
3628    const SymbolContext& sc,
3629    DWARFCompileUnit* dwarf_cu,
3630    const lldb::addr_t func_low_pc,
3631    const DWARFDebugInfoEntry *orig_die,
3632    bool parse_siblings,
3633    bool parse_children,
3634    VariableList* cc_variable_list
3635)
3636{
3637    if (orig_die == NULL)
3638        return 0;
3639
3640    size_t vars_added = 0;
3641    const DWARFDebugInfoEntry *die = orig_die;
3642    const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
3643    dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
3644    VariableListSP variables;
3645    switch (parent_tag)
3646    {
3647    case DW_TAG_compile_unit:
3648        if (sc.comp_unit != NULL)
3649        {
3650            variables = sc.comp_unit->GetVariableList(false);
3651            if (variables.get() == NULL)
3652            {
3653                variables.reset(new VariableList());
3654                sc.comp_unit->SetVariableList(variables);
3655            }
3656        }
3657        else
3658        {
3659            assert(!"Parent DIE was a compile unit, yet we don't have a valid compile unit in the symbol context...");
3660            vars_added = 0;
3661        }
3662        break;
3663
3664    case DW_TAG_subprogram:
3665    case DW_TAG_inlined_subroutine:
3666    case DW_TAG_lexical_block:
3667        if (sc.function != NULL)
3668        {
3669            // Check to see if we already have parsed the variables for the given scope
3670
3671            Block *block = sc.function->GetBlock(true).FindBlockByID(sc_parent_die->GetOffset());
3672            assert (block != NULL);
3673            variables = block->GetVariableList(false, false);
3674            if (variables.get() == NULL)
3675            {
3676                variables.reset(new VariableList());
3677                block->SetVariableList(variables);
3678            }
3679        }
3680        else
3681        {
3682            assert(!"Parent DIE was a function or block, yet we don't have a function in the symbol context...");
3683            vars_added = 0;
3684        }
3685        break;
3686
3687    default:
3688        assert(!"Didn't find appropriate parent DIE for variable list...");
3689        break;
3690    }
3691
3692    // We need to have a variable list at this point that we can add variables to
3693    assert(variables.get());
3694
3695    while (die != NULL)
3696    {
3697        dw_tag_t tag = die->Tag();
3698
3699        // Check to see if we have already parsed this variable or constant?
3700        if (m_die_to_variable_sp[die].get() == NULL)
3701        {
3702            // We haven't already parsed it, lets do that now.
3703            if ((tag == DW_TAG_variable) ||
3704                (tag == DW_TAG_constant) ||
3705                (tag == DW_TAG_formal_parameter && sc.function))
3706            {
3707                VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
3708                if (var_sp)
3709                {
3710                    variables->AddVariable(var_sp);
3711                    ++vars_added;
3712                }
3713            }
3714        }
3715
3716        bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
3717
3718        if (!skip_children && parse_children && die->HasChildren())
3719        {
3720            vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true);
3721            //vars_added += ParseVariables(sc, dwarf_cu, die->GetFirstChild(), parse_siblings, parse_children);
3722        }
3723
3724        if (parse_siblings)
3725            die = die->GetSibling();
3726        else
3727            die = NULL;
3728    }
3729
3730    if (cc_variable_list)
3731    {
3732        cc_variable_list->AddVariables(variables.get());
3733    }
3734
3735    return vars_added;
3736}
3737
3738//------------------------------------------------------------------
3739// PluginInterface protocol
3740//------------------------------------------------------------------
3741const char *
3742SymbolFileDWARF::GetPluginName()
3743{
3744    return "SymbolFileDWARF";
3745}
3746
3747const char *
3748SymbolFileDWARF::GetShortPluginName()
3749{
3750    return GetPluginNameStatic();
3751}
3752
3753uint32_t
3754SymbolFileDWARF::GetPluginVersion()
3755{
3756    return 1;
3757}
3758
3759void
3760SymbolFileDWARF::GetPluginCommandHelp (const char *command, Stream *strm)
3761{
3762}
3763
3764Error
3765SymbolFileDWARF::ExecutePluginCommand (Args &command, Stream *strm)
3766{
3767    Error error;
3768    error.SetErrorString("No plug-in command are currently supported.");
3769    return error;
3770}
3771
3772Log *
3773SymbolFileDWARF::EnablePluginLogging (Stream *strm, Args &command)
3774{
3775    return NULL;
3776}
3777
3778