DWARFDebugInfo.cpp revision 276479
1//===-- DWARFDebugInfo.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#include <algorithm>
13#include <set>
14
15#include "lldb/Core/RegularExpression.h"
16#include "lldb/Core/Stream.h"
17#include "lldb/Symbol/ObjectFile.h"
18
19#include "DWARFDebugAranges.h"
20#include "DWARFDebugInfo.h"
21#include "DWARFCompileUnit.h"
22#include "DWARFDebugAranges.h"
23#include "DWARFDebugInfoEntry.h"
24#include "DWARFFormValue.h"
25#include "LogChannelDWARF.h"
26
27using namespace lldb;
28using namespace lldb_private;
29using namespace std;
30
31//----------------------------------------------------------------------
32// Constructor
33//----------------------------------------------------------------------
34DWARFDebugInfo::DWARFDebugInfo() :
35    m_dwarf2Data(NULL),
36    m_compile_units(),
37    m_cu_aranges_ap ()
38{
39}
40
41//----------------------------------------------------------------------
42// SetDwarfData
43//----------------------------------------------------------------------
44void
45DWARFDebugInfo::SetDwarfData(SymbolFileDWARF* dwarf2Data)
46{
47    m_dwarf2Data = dwarf2Data;
48    m_compile_units.clear();
49}
50
51
52DWARFDebugAranges &
53DWARFDebugInfo::GetCompileUnitAranges ()
54{
55    if (m_cu_aranges_ap.get() == NULL && m_dwarf2Data)
56    {
57        Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_ARANGES));
58
59        m_cu_aranges_ap.reset (new DWARFDebugAranges());
60        const DWARFDataExtractor &debug_aranges_data = m_dwarf2Data->get_debug_aranges_data();
61        if (debug_aranges_data.GetByteSize() > 0)
62        {
63            if (log)
64                log->Printf ("DWARFDebugInfo::GetCompileUnitAranges() for \"%s\" from .debug_aranges",
65                             m_dwarf2Data->GetObjectFile()->GetFileSpec().GetPath().c_str());
66            m_cu_aranges_ap->Extract (debug_aranges_data);
67
68        }
69
70        // Make a list of all CUs represented by the arange data in the file.
71        std::set<dw_offset_t> cus_with_data;
72        for (size_t n=0;n<m_cu_aranges_ap.get()->GetNumRanges();n++)
73        {
74            dw_offset_t offset = m_cu_aranges_ap.get()->OffsetAtIndex(n);
75            if (offset != DW_INVALID_OFFSET)
76                cus_with_data.insert (offset);
77        }
78
79        // Manually build arange data for everything that wasn't in the .debug_aranges table.
80        bool printed = false;
81        const size_t num_compile_units = GetNumCompileUnits();
82        for (size_t idx = 0; idx < num_compile_units; ++idx)
83        {
84            DWARFCompileUnit* cu = GetCompileUnitAtIndex(idx);
85
86            dw_offset_t offset = cu->GetOffset();
87            if (cus_with_data.find(offset) == cus_with_data.end())
88            {
89                if (log)
90                {
91                    if (!printed)
92                        log->Printf ("DWARFDebugInfo::GetCompileUnitAranges() for \"%s\" by parsing",
93                                     m_dwarf2Data->GetObjectFile()->GetFileSpec().GetPath().c_str());
94                    printed = true;
95                }
96                cu->BuildAddressRangeTable (m_dwarf2Data, m_cu_aranges_ap.get());
97            }
98        }
99
100        const bool minimize = true;
101        m_cu_aranges_ap->Sort (minimize);
102    }
103    return *m_cu_aranges_ap.get();
104}
105
106
107//----------------------------------------------------------------------
108// LookupAddress
109//----------------------------------------------------------------------
110bool
111DWARFDebugInfo::LookupAddress
112(
113    const dw_addr_t address,
114    const dw_offset_t hint_die_offset,
115    DWARFCompileUnitSP& cu_sp,
116    DWARFDebugInfoEntry** function_die,
117    DWARFDebugInfoEntry** block_die
118)
119{
120
121    if (hint_die_offset != DW_INVALID_OFFSET)
122        cu_sp = GetCompileUnit(hint_die_offset);
123    else
124    {
125        DWARFDebugAranges &cu_aranges = GetCompileUnitAranges ();
126        const dw_offset_t cu_offset = cu_aranges.FindAddress (address);
127        cu_sp = GetCompileUnit(cu_offset);
128    }
129
130    if (cu_sp.get())
131    {
132        if (cu_sp->LookupAddress(address, function_die, block_die))
133            return true;
134        cu_sp.reset();
135    }
136    else
137    {
138        // The hint_die_offset may have been a pointer to the actual item that
139        // we are looking for
140        DWARFDebugInfoEntry* die_ptr = GetDIEPtr(hint_die_offset, &cu_sp);
141        if (die_ptr)
142        {
143            if (cu_sp.get())
144            {
145                if (function_die || block_die)
146                    return die_ptr->LookupAddress(address, m_dwarf2Data, cu_sp.get(), function_die, block_die);
147
148                // We only wanted the compile unit that contained this address
149                return true;
150            }
151        }
152    }
153    return false;
154}
155
156
157void
158DWARFDebugInfo::ParseCompileUnitHeadersIfNeeded()
159{
160    if (m_compile_units.empty())
161    {
162        if (m_dwarf2Data != NULL)
163        {
164            lldb::offset_t offset = 0;
165            const DWARFDataExtractor &debug_info_data = m_dwarf2Data->get_debug_info_data();
166            while (debug_info_data.ValidOffset(offset))
167            {
168                DWARFCompileUnitSP cu_sp(new DWARFCompileUnit(m_dwarf2Data));
169                // Out of memory?
170                if (cu_sp.get() == NULL)
171                    break;
172
173                if (cu_sp->Extract(debug_info_data, &offset) == false)
174                    break;
175
176                m_compile_units.push_back(cu_sp);
177
178                offset = cu_sp->GetNextCompileUnitOffset();
179            }
180        }
181    }
182}
183
184size_t
185DWARFDebugInfo::GetNumCompileUnits()
186{
187    ParseCompileUnitHeadersIfNeeded();
188    return m_compile_units.size();
189}
190
191DWARFCompileUnit*
192DWARFDebugInfo::GetCompileUnitAtIndex(uint32_t idx)
193{
194    DWARFCompileUnit* cu = NULL;
195    if (idx < GetNumCompileUnits())
196        cu = m_compile_units[idx].get();
197    return cu;
198}
199
200bool
201DWARFDebugInfo::ContainsCompileUnit (const DWARFCompileUnit *cu) const
202{
203    // Not a verify efficient function, but it is handy for use in assertions
204    // to make sure that a compile unit comes from a debug information file.
205    CompileUnitColl::const_iterator end_pos = m_compile_units.end();
206    CompileUnitColl::const_iterator pos;
207
208    for (pos = m_compile_units.begin(); pos != end_pos; ++pos)
209    {
210        if (pos->get() == cu)
211            return true;
212    }
213    return false;
214}
215
216static int
217CompareDWARFCompileUnitSPOffset (const void *key, const void *arrmem)
218{
219    const dw_offset_t key_cu_offset = *(dw_offset_t*) key;
220    const dw_offset_t cu_offset = ((DWARFCompileUnitSP *)arrmem)->get()->GetOffset();
221    if (key_cu_offset < cu_offset)
222        return -1;
223    if (key_cu_offset > cu_offset)
224        return 1;
225    return 0;
226}
227
228DWARFCompileUnitSP
229DWARFDebugInfo::GetCompileUnit(dw_offset_t cu_offset, uint32_t* idx_ptr)
230{
231    DWARFCompileUnitSP cu_sp;
232    uint32_t cu_idx = DW_INVALID_INDEX;
233    if (cu_offset != DW_INVALID_OFFSET)
234    {
235        ParseCompileUnitHeadersIfNeeded();
236
237        DWARFCompileUnitSP* match = (DWARFCompileUnitSP*)bsearch(&cu_offset, &m_compile_units[0], m_compile_units.size(), sizeof(DWARFCompileUnitSP), CompareDWARFCompileUnitSPOffset);
238        if (match)
239        {
240            cu_sp = *match;
241            cu_idx = match - &m_compile_units[0];
242        }
243    }
244    if (idx_ptr)
245        *idx_ptr = cu_idx;
246    return cu_sp;
247}
248
249DWARFCompileUnitSP
250DWARFDebugInfo::GetCompileUnitContainingDIE(dw_offset_t die_offset)
251{
252    DWARFCompileUnitSP cu_sp;
253    if (die_offset != DW_INVALID_OFFSET)
254    {
255        ParseCompileUnitHeadersIfNeeded();
256
257        CompileUnitColl::const_iterator end_pos = m_compile_units.end();
258        CompileUnitColl::const_iterator pos;
259
260        for (pos = m_compile_units.begin(); pos != end_pos; ++pos)
261        {
262            dw_offset_t cu_start_offset = (*pos)->GetOffset();
263            dw_offset_t cu_end_offset = (*pos)->GetNextCompileUnitOffset();
264            if (cu_start_offset <= die_offset && die_offset < cu_end_offset)
265            {
266                cu_sp = *pos;
267                break;
268            }
269        }
270    }
271    return cu_sp;
272}
273
274//----------------------------------------------------------------------
275// GetDIE()
276//
277// Get the DIE (Debug Information Entry) with the specified offset.
278//----------------------------------------------------------------------
279DWARFDebugInfoEntry*
280DWARFDebugInfo::GetDIEPtr(dw_offset_t die_offset, DWARFCompileUnitSP* cu_sp_ptr)
281{
282    DWARFCompileUnitSP cu_sp(GetCompileUnitContainingDIE(die_offset));
283    if (cu_sp_ptr)
284        *cu_sp_ptr = cu_sp;
285    if (cu_sp.get())
286        return cu_sp->GetDIEPtr(die_offset);
287    return NULL;    // Not found in any compile units
288}
289
290DWARFDebugInfoEntry*
291DWARFDebugInfo::GetDIEPtrWithCompileUnitHint (dw_offset_t die_offset, DWARFCompileUnit**cu_handle)
292{
293    assert (cu_handle);
294    DWARFDebugInfoEntry* die = NULL;
295    if (*cu_handle)
296        die = (*cu_handle)->GetDIEPtr(die_offset);
297
298    if (die == NULL)
299    {
300        DWARFCompileUnitSP cu_sp (GetCompileUnitContainingDIE(die_offset));
301        if (cu_sp.get())
302        {
303            *cu_handle = cu_sp.get();
304            die = cu_sp->GetDIEPtr(die_offset);
305        }
306    }
307    if (die == NULL)
308        *cu_handle = NULL;
309    return die;
310}
311
312
313const DWARFDebugInfoEntry*
314DWARFDebugInfo::GetDIEPtrContainingOffset(dw_offset_t die_offset, DWARFCompileUnitSP* cu_sp_ptr)
315{
316    DWARFCompileUnitSP cu_sp(GetCompileUnitContainingDIE(die_offset));
317    if (cu_sp_ptr)
318        *cu_sp_ptr = cu_sp;
319    if (cu_sp.get())
320        return cu_sp->GetDIEPtrContainingOffset(die_offset);
321
322    return NULL;    // Not found in any compile units
323
324}
325
326//----------------------------------------------------------------------
327// AddCompileUnit
328//----------------------------------------------------------------------
329void
330DWARFDebugInfo::AddCompileUnit(DWARFCompileUnitSP& cu)
331{
332    m_compile_units.push_back(cu);
333}
334
335/*
336void
337DWARFDebugInfo::AddDIE(DWARFDebugInfoEntry& die)
338{
339    m_die_array.push_back(die);
340}
341*/
342
343
344
345
346//----------------------------------------------------------------------
347// Parse
348//
349// Parses the .debug_info section and uses the .debug_abbrev section
350// and various other sections in the SymbolFileDWARF class and calls the
351// supplied callback function each time a compile unit header, or debug
352// information entry is successfully parsed. This function can be used
353// for different tasks such as parsing the file contents into a
354// structured data, dumping, verifying and much more.
355//----------------------------------------------------------------------
356void
357DWARFDebugInfo::Parse(SymbolFileDWARF* dwarf2Data, Callback callback, void* userData)
358{
359    if (dwarf2Data)
360    {
361        lldb::offset_t offset = 0;
362        uint32_t depth = 0;
363        DWARFCompileUnitSP cu(new DWARFCompileUnit(dwarf2Data));
364        if (cu.get() == NULL)
365            return;
366        DWARFDebugInfoEntry die;
367
368        while (cu->Extract(dwarf2Data->get_debug_info_data(), &offset))
369        {
370            const dw_offset_t next_cu_offset = cu->GetNextCompileUnitOffset();
371
372            depth = 0;
373            // Call the callback function with no DIE pointer for the compile unit
374            // and get the offset that we are to continue to parse from
375            offset = callback(dwarf2Data, cu, NULL, offset, depth, userData);
376
377            // Make sure we are within our compile unit
378            if (offset < next_cu_offset)
379            {
380                // We are in our compile unit, parse starting at the offset
381                // we were told to parse
382                bool done = false;
383                while (!done && die.Extract(dwarf2Data, cu.get(), &offset))
384                {
385                    // Call the callback function with DIE pointer that falls within the compile unit
386                    offset = callback(dwarf2Data, cu, &die, offset, depth, userData);
387
388                    if (die.IsNULL())
389                    {
390                        if (depth)
391                            --depth;
392                        else
393                            done = true;    // We are done with this compile unit!
394                    }
395                    else if (die.HasChildren())
396                        ++depth;
397                }
398            }
399
400            // Make sure the offset returned is valid, and if not stop parsing.
401            // Returning DW_INVALID_OFFSET from this callback is a good way to end
402            // all parsing
403            if (!dwarf2Data->get_debug_info_data().ValidOffset(offset))
404                break;
405
406            // See if during the callback anyone retained a copy of the compile
407            // unit other than ourselves and if so, let whomever did own the object
408            // and create a new one for our own use!
409            if (!cu.unique())
410                cu.reset(new DWARFCompileUnit(dwarf2Data));
411
412
413            // Make sure we start on a proper
414            offset = next_cu_offset;
415        }
416    }
417}
418
419typedef struct DumpInfo
420{
421    DumpInfo(Stream* init_strm, uint32_t off, uint32_t depth) :
422        strm(init_strm),
423        die_offset(off),
424        recurse_depth(depth),
425        found_depth(UINT32_MAX),
426        found_die(false),
427        ancestors()
428    {
429    }
430    Stream* strm;
431    const uint32_t die_offset;
432    const uint32_t recurse_depth;
433    uint32_t found_depth;
434    bool found_die;
435    std::vector<DWARFDebugInfoEntry> ancestors;
436
437    DISALLOW_COPY_AND_ASSIGN(DumpInfo);
438} DumpInfo;
439
440//----------------------------------------------------------------------
441// DumpCallback
442//
443// A callback function for the static DWARFDebugInfo::Parse() function
444// that gets called each time a compile unit header or debug information
445// entry is successfully parsed.
446//
447// This function dump DWARF information and obey recurse depth and
448// whether a single DIE is to be dumped (or all of the data).
449//----------------------------------------------------------------------
450static dw_offset_t DumpCallback
451(
452    SymbolFileDWARF* dwarf2Data,
453    DWARFCompileUnitSP& cu_sp,
454    DWARFDebugInfoEntry* die,
455    const dw_offset_t next_offset,
456    const uint32_t curr_depth,
457    void* userData
458)
459{
460    DumpInfo* dumpInfo = (DumpInfo*)userData;
461
462    const DWARFCompileUnit* cu = cu_sp.get();
463
464    Stream *s = dumpInfo->strm;
465    bool show_parents = s->GetFlags().Test(DWARFDebugInfo::eDumpFlag_ShowAncestors);
466
467    if (die)
468    {
469        // Are we dumping everything?
470        if (dumpInfo->die_offset == DW_INVALID_OFFSET)
471        {
472            // Yes we are dumping everything. Obey our recurse level though
473            if (curr_depth < dumpInfo->recurse_depth)
474                die->Dump(dwarf2Data, cu, *s, 0);
475        }
476        else
477        {
478            // We are dumping a specific DIE entry by offset
479            if (dumpInfo->die_offset == die->GetOffset())
480            {
481                // We found the DIE we were looking for, dump it!
482                if (show_parents)
483                {
484                    s->SetIndentLevel(0);
485                    const uint32_t num_ancestors = dumpInfo->ancestors.size();
486                    if (num_ancestors > 0)
487                    {
488                        for (uint32_t i=0; i<num_ancestors-1; ++i)
489                        {
490                            dumpInfo->ancestors[i].Dump(dwarf2Data, cu, *s, 0);
491                            s->IndentMore();
492                        }
493                    }
494                }
495
496                dumpInfo->found_depth = curr_depth;
497
498                die->Dump(dwarf2Data, cu, *s, 0);
499
500                // Note that we found the DIE we were looking for
501                dumpInfo->found_die = true;
502
503                // Since we are dumping a single DIE, if there are no children we are done!
504                if (!die->HasChildren() || dumpInfo->recurse_depth == 0)
505                    return DW_INVALID_OFFSET;   // Return an invalid address to end parsing
506            }
507            else if (dumpInfo->found_die)
508            {
509                // Are we done with all the children?
510                if (curr_depth <= dumpInfo->found_depth)
511                    return DW_INVALID_OFFSET;
512
513                // We have already found our DIE and are printing it's children. Obey
514                // our recurse depth and return an invalid offset if we get done
515                // dumping all of the children
516                if (dumpInfo->recurse_depth == UINT32_MAX || curr_depth <= dumpInfo->found_depth + dumpInfo->recurse_depth)
517                    die->Dump(dwarf2Data, cu, *s, 0);
518            }
519            else if (dumpInfo->die_offset > die->GetOffset())
520            {
521                if (show_parents)
522                    dumpInfo->ancestors.back() = *die;
523            }
524        }
525
526        // Keep up with our indent level
527        if (die->IsNULL())
528        {
529            if (show_parents)
530                dumpInfo->ancestors.pop_back();
531
532            if (curr_depth <= 1)
533                return cu->GetNextCompileUnitOffset();
534            else
535                s->IndentLess();
536        }
537        else if (die->HasChildren())
538        {
539            if (show_parents)
540            {
541                DWARFDebugInfoEntry null_die;
542                dumpInfo->ancestors.push_back(null_die);
543            }
544            s->IndentMore();
545        }
546    }
547    else
548    {
549        if (cu == NULL)
550            s->PutCString("NULL - cu");
551        // We have a compile unit, reset our indent level to zero just in case
552        s->SetIndentLevel(0);
553
554        // See if we are dumping everything?
555        if (dumpInfo->die_offset == DW_INVALID_OFFSET)
556        {
557            // We are dumping everything
558            cu->Dump(s);
559            return cu->GetFirstDIEOffset(); // Return true to parse all DIEs in this Compile Unit
560        }
561        else
562        {
563            if (show_parents)
564            {
565                dumpInfo->ancestors.clear();
566                dumpInfo->ancestors.resize(1);
567            }
568
569            // We are dumping only a single DIE possibly with it's children and
570            // we must find it's compile unit before we can dump it properly
571            if (dumpInfo->die_offset < cu->GetFirstDIEOffset())
572            {
573                // Not found, maybe the DIE offset provided wasn't correct?
574            //  *ostrm_ptr << "DIE at offset " << HEX32 << dumpInfo->die_offset << " was not found." << endl;
575                return DW_INVALID_OFFSET;
576            }
577            else
578            {
579                // See if the DIE is in this compile unit?
580                if (dumpInfo->die_offset < cu->GetNextCompileUnitOffset())
581                {
582                    // This DIE is in this compile unit!
583                    if (s->GetVerbose())
584                        cu->Dump(s); // Dump the compile unit for the DIE in verbose mode
585
586                    return next_offset;
587                //  // We found our compile unit that contains our DIE, just skip to dumping the requested DIE...
588                //  return dumpInfo->die_offset;
589                }
590                else
591                {
592                    // Skip to the next compile unit as the DIE isn't in the current one!
593                    return cu->GetNextCompileUnitOffset();
594                }
595            }
596        }
597    }
598
599    // Just return the current offset to parse the next CU or DIE entry
600    return next_offset;
601}
602
603//----------------------------------------------------------------------
604// Dump
605//
606// Dump the information in the .debug_info section to the specified
607// ostream. If die_offset is valid, a single DIE will be dumped. If the
608// die_offset is invalid, all the DWARF information will be dumped. Both
609// cases will obey a "recurse_depth" or how deep to traverse into the
610// children of each DIE entry. A recurse_depth of zero will dump all
611// compile unit headers. A recurse_depth of 1 will dump all compile unit
612// headers and the DW_TAG_compile unit tags. A depth of 2 will also
613// dump all types and functions.
614//----------------------------------------------------------------------
615void
616DWARFDebugInfo::Dump
617(
618    Stream *s,
619    SymbolFileDWARF* dwarf2Data,
620    const uint32_t die_offset,
621    const uint32_t recurse_depth
622)
623{
624    DumpInfo dumpInfo(s, die_offset, recurse_depth);
625    s->PutCString(".debug_info contents");
626    if (dwarf2Data->get_debug_info_data().GetByteSize() > 0)
627    {
628        if (die_offset == DW_INVALID_OFFSET)
629            s->PutCString(":\n");
630        else
631        {
632            s->Printf(" for DIE entry at .debug_info[0x%8.8x]", die_offset);
633            if (recurse_depth != UINT32_MAX)
634                s->Printf(" recursing %u levels deep.", recurse_depth);
635            s->EOL();
636        }
637    }
638    else
639    {
640        s->PutCString(": < EMPTY >\n");
641        return;
642    }
643    DWARFDebugInfo::Parse(dwarf2Data, DumpCallback, &dumpInfo);
644}
645
646
647//----------------------------------------------------------------------
648// Dump
649//
650// Dump the contents of this DWARFDebugInfo object as has been parsed
651// and/or modified after it has been parsed.
652//----------------------------------------------------------------------
653void
654DWARFDebugInfo::Dump (Stream *s, const uint32_t die_offset, const uint32_t recurse_depth)
655{
656    DumpInfo dumpInfo(s, die_offset, recurse_depth);
657
658    s->PutCString("Dumping .debug_info section from internal representation\n");
659
660    CompileUnitColl::const_iterator pos;
661    uint32_t curr_depth = 0;
662    ParseCompileUnitHeadersIfNeeded();
663    for (pos = m_compile_units.begin(); pos != m_compile_units.end(); ++pos)
664    {
665        const DWARFCompileUnitSP& cu_sp = *pos;
666        DumpCallback(m_dwarf2Data, (DWARFCompileUnitSP&)cu_sp, NULL, 0, curr_depth, &dumpInfo);
667
668        const DWARFDebugInfoEntry* die = cu_sp->DIE();
669        if (die)
670            die->Dump(m_dwarf2Data, cu_sp.get(), *s, recurse_depth);
671    }
672}
673
674
675//----------------------------------------------------------------------
676// FindCallbackString
677//
678// A callback function for the static DWARFDebugInfo::Parse() function
679// that gets called each time a compile unit header or debug information
680// entry is successfully parsed.
681//
682// This function will find the die_offset of any items whose DW_AT_name
683// matches the given string
684//----------------------------------------------------------------------
685typedef struct FindCallbackStringInfoTag
686{
687    const char* name;
688    bool ignore_case;
689    RegularExpression* regex;
690    vector<dw_offset_t>& die_offsets;
691} FindCallbackStringInfo;
692
693static dw_offset_t FindCallbackString
694(
695    SymbolFileDWARF* dwarf2Data,
696    DWARFCompileUnitSP& cu_sp,
697    DWARFDebugInfoEntry* die,
698    const dw_offset_t next_offset,
699    const uint32_t curr_depth,
700    void* userData
701)
702{
703    FindCallbackStringInfo* info = (FindCallbackStringInfo*)userData;
704    const DWARFCompileUnit* cu = cu_sp.get();
705
706    if (die)
707    {
708        const char* die_name = die->GetName(dwarf2Data, cu);
709        if (die_name)
710        {
711            if (info->regex)
712            {
713                if (info->regex->Execute(die_name))
714                    info->die_offsets.push_back(die->GetOffset());
715            }
716            else
717            {
718                if ((info->ignore_case ? strcasecmp(die_name, info->name) : strcmp(die_name, info->name)) == 0)
719                    info->die_offsets.push_back(die->GetOffset());
720            }
721        }
722    }
723
724    // Just return the current offset to parse the next CU or DIE entry
725    return next_offset;
726}
727
728//----------------------------------------------------------------------
729// Find
730//
731// Finds all DIE that have a specific DW_AT_name attribute by manually
732// searching through the debug information (not using the
733// .debug_pubnames section). The string must match the entire name
734// and case sensitive searches are an option.
735//----------------------------------------------------------------------
736bool
737DWARFDebugInfo::Find(const char* name, bool ignore_case, vector<dw_offset_t>& die_offsets) const
738{
739    die_offsets.clear();
740    if (name && name[0])
741    {
742        FindCallbackStringInfo info = { name, ignore_case, NULL, die_offsets };
743        DWARFDebugInfo::Parse(m_dwarf2Data, FindCallbackString, &info);
744    }
745    return !die_offsets.empty();
746}
747
748//----------------------------------------------------------------------
749// Find
750//
751// Finds all DIE that have a specific DW_AT_name attribute by manually
752// searching through the debug information (not using the
753// .debug_pubnames section). The string must match the supplied regular
754// expression.
755//----------------------------------------------------------------------
756bool
757DWARFDebugInfo::Find(RegularExpression& re, vector<dw_offset_t>& die_offsets) const
758{
759    die_offsets.clear();
760    FindCallbackStringInfo info = { NULL, false, &re, die_offsets };
761    DWARFDebugInfo::Parse(m_dwarf2Data, FindCallbackString, &info);
762    return !die_offsets.empty();
763}
764