private void LoadDebug()

in src/BinaryParsers/ElfBinary/ElfBinary.cs [367:485]


        private void LoadDebug(string localSymbolDirectories = null)
        {
            DebugFileType = DebugFileType.Unknown;
            DebugFileLoaded = false;

            if (SectionExistsAndHasBits(SectionName.DebugInfoDwo))
            {
                DebugFileType = DebugFileType.DebugOnlyFileDwo;
                return;
            }

            string debugFileName = null;

            if (CompilationUnits.Count > 0)
            {
                // Load from Dwo
                DwarfSymbol skeletonOrCompileSymbol = CompilationUnits
                .SelectMany(c => c.Symbols)
                .FirstOrDefault(s => s.Tag == DwarfTag.SkeletonUnit || s.Tag == DwarfTag.CompileUnit);
                KeyValuePair<DwarfAttribute, DwarfAttributeValue>? dwo = skeletonOrCompileSymbol?.Attributes?
                    .FirstOrDefault(a => a.Key == DwarfAttribute.DwoName || a.Key == DwarfAttribute.GnuDwoName);
                debugFileName = (dwo == null || !dwo.HasValue) ? string.Empty : dwo.Value.Value?.String;
                if (!string.IsNullOrWhiteSpace(debugFileName))
                {
                    DebugFileType = DebugFileType.FromDwo;
                }
            }

            if (string.IsNullOrWhiteSpace(debugFileName))
            {
                // Load from gnu_debuglink
                if (SectionExistsAndHasBits(SectionName.GnuDebugLink, out Section<ulong> debugLinkSection))
                {
                    byte[] debugLinkSectionContents = debugLinkSection.GetContents();

                    if (debugLinkSectionContents != null && debugLinkSectionContents.Length > 0)
                    {
                        string debuglinkFileName = Encoding.ASCII.GetString(debugLinkSectionContents.TakeWhile(x => x != 0).ToArray());

                        if (!string.IsNullOrWhiteSpace(debuglinkFileName))
                        {
                            debugFileName = debuglinkFileName;
                            DebugFileType = DebugFileType.FromDebuglink;
                        }
                    }
                }
            }

            if (!string.IsNullOrWhiteSpace(debugFileName))
            {
                var directory = new Uri(TargetUri, ".");
                Uri debugFileUri = GetFirstExistFile(debugFileName, directory.AbsolutePath, localSymbolDirectories);
                if (debugFileUri != null)
                {
                    if (debugFileUri == this.TargetUri)
                    {
                        DebugFileType = DebugFileType.FromDebuglinkPointingToItself;
                    }
                    else
                    {
                        var dwoBinary = new ElfBinary(debugFileUri);

                        if (dwoBinary != null && dwoBinary.CompilationUnits.Count > 0)
                        {
                            this.CompilationUnits.AddRange(dwoBinary.CompilationUnits);

                            if (dwoBinary.CommandLineInfos.Count > 0)
                            {
                                this.CommandLineInfos.AddRange(dwoBinary.CommandLineInfos);
                            }

                            DebugFileLoaded = true;
                            return;
                        }
                    }
                }
            }

            if (DebugFileType == DebugFileType.Unknown)
            {
                if (SectionExistsAndHasNoBits(SectionName.Interp) &&
                    SectionExistsAndHasNoBits(SectionName.Dynsym) &&
                    SectionExistsAndHasNoBits(SectionName.Init) &&
                    SectionExistsAndHasNoBits(SectionName.Data) &&
                    SectionExistsAndHasBits(SectionName.DebugInfo)
                    )
                {
                    DebugFileType = DebugFileType.DebugOnlyFileDebuglink;
                }
                else if (SectionExistsAndHasNoBits(SectionName.Interp) &&
                    SectionExistsAndHasNoBits(SectionName.Dynsym) &&
                    SectionExistsAndHasNoBits(SectionName.Init) &&
                    SectionExistsAndHasNoBits(SectionName.Data) &&
                    SectionDoesNotExistOrHasNoBits(SectionName.DebugInfo)
                    )
                {
                    DebugFileType = DebugFileType.DebugOnlyFileWithDebugStripped;
                }
                else if (SectionExistsAndHasBits(SectionName.Interp) &&
                    SectionExistsAndHasBits(SectionName.Dynsym) &&
                    SectionExistsAndHasBits(SectionName.Init) &&
                    SectionExistsAndHasBits(SectionName.Data) &&
                    SectionExistsAndHasBits(SectionName.DebugInfo)
                    )
                {
                    DebugFileType = DebugFileType.DebugIncluded;
                    DebugFileLoaded = true;
                }
                else if (SectionExistsAndHasBits(SectionName.Interp) &&
                   SectionExistsAndHasBits(SectionName.Dynsym) &&
                   SectionExistsAndHasBits(SectionName.Init) &&
                   SectionExistsAndHasBits(SectionName.Data) &&
                   !SectionExistsAndHasBits(SectionName.DebugInfo)
                   )
                {
                    DebugFileType = DebugFileType.NoDebug;
                }
            }
        }