Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DwarfCompilationUnit only collect one or two DwarfSymbols in ReadData method call #1010

Open
hyzhappy opened this issue Sep 12, 2024 · 0 comments

Comments

@hyzhappy
Copy link

It seens a break there at line 432 in DwarfCompilationUnit.cs that break the loop to collect all the symbols

                foreach (DataDescriptionAttribute descriptionAttribute in description.Attributes)
                {
                    DwarfAttributeValue attributeValue = new DwarfAttributeValue();
                    DwarfAttribute attribute = descriptionAttribute.Attribute;
                    DwarfFormat format = descriptionAttribute.Format;

                    switch (format)
                    {
                        case DwarfFormat.Address:
                            attributeValue.Type = DwarfAttributeValueType.Address;
                            attributeValue.Value = debugData.ReadUlong(addressSize);
                            break;

                        case DwarfFormat.Block:
                            attributeValue.Type = DwarfAttributeValueType.Block;
                            attributeValue.Value = debugData.ReadBlock(debugData.ULEB128());
                            break;

                        case DwarfFormat.Block1:
                            attributeValue.Type = DwarfAttributeValueType.Block;
                            attributeValue.Value = debugData.ReadBlock(debugData.ReadByte());
                            break;

                        case DwarfFormat.Block2:
                            attributeValue.Type = DwarfAttributeValueType.Block;
                            attributeValue.Value = debugData.ReadBlock(debugData.ReadUshort());
                            break;

                        case DwarfFormat.Block4:
                            attributeValue.Type = DwarfAttributeValueType.Block;
                            attributeValue.Value = debugData.ReadBlock(debugData.ReadUint());
                            break;

                        case DwarfFormat.Data1:
                            attributeValue.Type = DwarfAttributeValueType.Constant;
                            attributeValue.Value = (ulong)debugData.ReadByte();
                            break;

                        case DwarfFormat.Data2:
                            attributeValue.Type = DwarfAttributeValueType.Constant;
                            attributeValue.Value = (ulong)debugData.ReadUshort();
                            break;

                        case DwarfFormat.Data4:
                            attributeValue.Type = DwarfAttributeValueType.Constant;
                            attributeValue.Value = (ulong)debugData.ReadUint();
                            break;

                        case DwarfFormat.Data8:
                            attributeValue.Type = DwarfAttributeValueType.Constant;
                            attributeValue.Value = debugData.ReadUlong();
                            break;

                        case DwarfFormat.Data16:
                            attributeValue.Type = DwarfAttributeValueType.Constant;
                            attributeValue.Value = debugData.ReadBlock(16);
                            break;

                        case DwarfFormat.SData:
                            attributeValue.Type = DwarfAttributeValueType.Constant;
                            attributeValue.Value = (ulong)debugData.SLEB128();
                            break;

                        case DwarfFormat.UData:
                            attributeValue.Type = DwarfAttributeValueType.Constant;
                            attributeValue.Value = (ulong)debugData.ULEB128();
                            break;

                        case DwarfFormat.String:
                            attributeValue.Type = DwarfAttributeValueType.String;
                            attributeValue.Value = debugData.ReadString();
                            break;

                        case DwarfFormat.LineStrp:
                            attributeValue.Type = DwarfAttributeValueType.String;
                            int offsetStrp = debugData.ReadOffset(is64bit);
                            attributeValue.Value = debugLineStrings.ReadString(offsetStrp);
                            break;

                        case DwarfFormat.Strp:
                            attributeValue.Type = DwarfAttributeValueType.String;
                            offsetStrp = debugData.ReadOffset(is64bit);
                            attributeValue.Value = debugStrings.ReadString(offsetStrp);
                            break;

                        case DwarfFormat.StrpSup:
                            attributeValue.Type = DwarfAttributeValueType.String;
                            // NOTE: we don't support locating this value currently.
                            attributeValue.Offset = (ulong)debugData.ReadOffset(is64bit);
                            break;

                        case DwarfFormat.Flag:
                            attributeValue.Type = DwarfAttributeValueType.Flag;
                            attributeValue.Value = debugData.ReadByte() != 0;
                            break;

                        case DwarfFormat.FlagPresent:
                            attributeValue.Type = DwarfAttributeValueType.Flag;
                            attributeValue.Value = true;
                            break;

                        case DwarfFormat.Ref1:
                            attributeValue.Type = DwarfAttributeValueType.Reference;
                            attributeValue.Value = debugData.ReadByte() + (ulong)beginPosition;
                            break;

                        case DwarfFormat.Ref2:
                            attributeValue.Type = DwarfAttributeValueType.Reference;
                            attributeValue.Value = debugData.ReadUshort() + (ulong)beginPosition;
                            break;

                        case DwarfFormat.Ref4:
                            attributeValue.Type = DwarfAttributeValueType.Reference;
                            attributeValue.Value = debugData.ReadUint() + (ulong)beginPosition;
                            break;

                        case DwarfFormat.Ref8:
                            attributeValue.Type = DwarfAttributeValueType.Reference;
                            attributeValue.Value = debugData.ReadUlong() + (ulong)beginPosition;
                            break;

                        case DwarfFormat.RefUData:
                            attributeValue.Type = DwarfAttributeValueType.Reference;
                            attributeValue.Value = debugData.ULEB128() + (ulong)beginPosition;
                            break;

                        case DwarfFormat.RefAddr:
                            attributeValue.Type = DwarfAttributeValueType.Reference;
                            attributeValue.Value = (ulong)debugData.ReadOffset(is64bit);
                            break;

                        case DwarfFormat.RefSig8:
                            attributeValue.Type = DwarfAttributeValueType.Invalid;
                            debugData.Position += 8;
                            break;

                        case DwarfFormat.RefSup4:
                            attributeValue.Type = DwarfAttributeValueType.Reference;
                            attributeValue.Offset = debugData.ReadUint();
                            // We don't resolve this reference from supplemental data yet.
                            break;

                        case DwarfFormat.RefSup8:
                            attributeValue.Type = DwarfAttributeValueType.Reference;
                            attributeValue.Offset = debugData.ReadUlong();
                            // We don't resolve this reference from supplemental data yet.
                            break;

                        case DwarfFormat.ExpressionLocation:
                            attributeValue.Type = DwarfAttributeValueType.ExpressionLocation;
                            attributeValue.Value = debugData.ReadBlock(debugData.ULEB128());
                            break;

                        case DwarfFormat.SecOffset:
                            attributeValue.Type = DwarfAttributeValueType.SecOffset;
                            attributeValue.Value = (ulong)debugData.ReadOffset(is64bit);
                            if (attribute == DwarfAttribute.RankStrOffsetsBase)
                            {
                                indexOffset = (int)((ulong)attributeValue.Value / (ulong)(is64bit ? 8 : 4));
                            }
                            break;

                        case DwarfFormat.ImplicitConst:
                            attributeValue.Value = descriptionAttribute.Value;
                            break;

                        case DwarfFormat.Strx:
                        case DwarfFormat.GNUStrIndex:
                            attributeValue.Type = DwarfAttributeValueType.String;
                            attributeValue.Offset = debugData.ULEB128();
                            break;

                        case DwarfFormat.Strx1:
                            attributeValue.Type = DwarfAttributeValueType.String;
                            attributeValue.Offset = debugData.ReadByte();
                            break;

                        case DwarfFormat.Strx2:
                            attributeValue.Type = DwarfAttributeValueType.String;
                            attributeValue.Offset = debugData.ReadUshort();
                            break;

                        case DwarfFormat.Strx3:
                            attributeValue.Type = DwarfAttributeValueType.String;
                            attributeValue.Offset = debugData.ReadThreeBytes();
                            break;

                        case DwarfFormat.Strx4:
                            attributeValue.Type = DwarfAttributeValueType.String;
                            attributeValue.Offset = debugData.ReadUint();
                            break;

                        case DwarfFormat.Addrx:
                            attributeValue.Type = DwarfAttributeValueType.Address;
                            attributeValue.Value = debugData.ULEB128() + (ulong)beginPosition;
                            break;

                        // NOTE: we don't resolve any of these new DWARF5 address values yet.
                        case DwarfFormat.Addrx1:
                            attributeValue.Type = DwarfAttributeValueType.Address;
                            attributeValue.Offset = debugData.ReadByte();
                            break;

                        case DwarfFormat.Addrx2:
                            attributeValue.Type = DwarfAttributeValueType.Address;
                            attributeValue.Offset = debugData.ReadUshort();
                            break;

                        case DwarfFormat.Addrx3:
                            attributeValue.Type = DwarfAttributeValueType.Address;
                            attributeValue.Offset = debugData.ReadThreeBytes();
                            break;

                        case DwarfFormat.Addrx4:
                            attributeValue.Type = DwarfAttributeValueType.Address;
                            attributeValue.Offset = debugData.ReadUlong();
                            break;

                        case DwarfFormat.Rnglistx:
                            attributeValue.Type = DwarfAttributeValueType.SecOffset;
                            attributeValue.Value = debugData.ULEB128();
                            break;

                        case DwarfFormat.GNUAddrIndex:
                            break;

                        default:
                            throw new InvalidOperationException($"{attribute} : {format}");
                    }

                    if (attributes.ContainsKey(attribute))
                    {
                        if (attributes[attribute] != attributeValue)
                        {
                            attributes[attribute] = attributeValue;
                        }
                    }
                    else
                    {
                        attributes.Add(attribute, attributeValue);
                    }
                }

                if (indexOffset > -1)
                {
                    foreach (DwarfAttributeValue dwarfAttributeValue in attributes.Values)
                    {
                        if (dwarfAttributeValue.Offset == null ||
                            dwarfAttributeValue.Type != DwarfAttributeValueType.String)
                        {
                            // We current do not post-process all address types.
                            continue;
                        }

                        int debugStringOffsetIndex = Convert.ToInt32(dwarfAttributeValue.Value) + indexOffset;
                        int offset = debugStringOffsets[debugStringOffsetIndex];
                        dwarfAttributeValue.Value = debugStrings.ReadString(offset);
                    }
                }

                DwarfSymbol symbol = new DwarfSymbol()
                {
                    Tag = description.Tag,
                    Attributes = attributes,
                    Offset = dataPosition,
                };

                symbolsByOffset.Add(symbol.Offset, symbol);

                if (parents.Count > 0)
                {
                    parents.Peek().Children.Add(symbol);
                    symbol.Parent = parents.Peek();
                }
                else
                {
                    symbols.Add(symbol);
                }

                if (description.HasChildren)
                {
                    symbol.Children = new List<DwarfSymbol>();
                    parents.Push(symbol);
                }

                break;   // a wrong break here
            }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant