Skip to content

Commit

Permalink
Cleanup more code
Browse files Browse the repository at this point in the history
  • Loading branch information
xoofx committed Sep 18, 2024
1 parent 2ea5f34 commit ec9dad0
Show file tree
Hide file tree
Showing 17 changed files with 230 additions and 321 deletions.
1 change: 1 addition & 0 deletions src/LibObjectFile/Ar/ArSymbolTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Diagnostics;
using System.Text;
using LibObjectFile.Diagnostics;
using LibObjectFile.IO;

namespace LibObjectFile.Ar;

Expand Down
54 changes: 27 additions & 27 deletions src/LibObjectFile/Dwarf/DwarfDIE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,33 +297,33 @@ protected unsafe void SetAttributeValue<TValue>(DwarfAttributeKind kind, TValue?
AddAttribute(new DwarfAttribute() { Kind = kind, ValueAsObject = value});
}

protected void SetAttributeLinkValue<TLink>(DwarfAttributeKind kind, TLink link) where TLink : IObjectFileNodeLink
{
for (int i = 0; i < _attributes.Count; i++)
{
var attr = _attributes[i];
if (attr.Kind == kind)
{
if (link == null)
{
RemoveAttributeAt(i);
}
else
{
attr.ValueAsU64 = link.GetRelativeOffset();
attr.ValueAsObject = link.GetObjectFileNode();
}
return;
}
}

AddAttribute(new DwarfAttribute()
{
Kind = kind,
ValueAsU64 = link.GetRelativeOffset(),
ValueAsObject = link.GetObjectFileNode()
});
}
//protected void SetAttributeLinkValue<TLink>(DwarfAttributeKind kind, TLink link) where TLink : IObjectFileNodeLink
//{
// for (int i = 0; i < _attributes.Count; i++)
// {
// var attr = _attributes[i];
// if (attr.Kind == kind)
// {
// if (link == null)
// {
// RemoveAttributeAt(i);
// }
// else
// {
// attr.ValueAsU64 = link.GetRelativeOffset();
// attr.ValueAsObject = link.GetObjectFileNode();
// }
// return;
// }
// }

// AddAttribute(new DwarfAttribute()
// {
// Kind = kind,
// ValueAsU64 = link.GetRelativeOffset(),
// ValueAsObject = link.GetObjectFileNode()
// });
//}

protected unsafe void SetAttributeValueOpt<TValue>(DwarfAttributeKind kind, TValue? value) where TValue : unmanaged
{
Expand Down
14 changes: 7 additions & 7 deletions src/LibObjectFile/Dwarf/DwarfFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void Write(DwarfWriterContext writerContext)
writer.AddressSize = writerContext.AddressSize;
writer.EnableRelocation = writerContext.EnableRelocation;

writer.Log = writerContext.DebugLinePrinter;
writer.DebugLog = writerContext.DebugLinePrinter;
if (writerContext.DebugLineStream != null)
{
writer.Stream = writerContext.DebugLineStream;
Expand All @@ -159,7 +159,7 @@ public void Write(DwarfWriterContext writerContext)
LineSection.Write(writer);
}

writer.Log = null;
writer.DebugLog = null;
if (writerContext.DebugAbbrevStream != null)
{
writer.Stream = writerContext.DebugAbbrevStream;
Expand Down Expand Up @@ -376,7 +376,7 @@ public static DwarfFile Read(DwarfReaderContext readerContext)
var dwarf = new DwarfFile();
var reader = new DwarfReader(readerContext, dwarf, new DiagnosticBag());

reader.Log = null;
reader.DebugLog = null;
if (readerContext.DebugAbbrevStream != null)
{
reader.Stream = readerContext.DebugAbbrevStream;
Expand All @@ -391,14 +391,14 @@ public static DwarfFile Read(DwarfReaderContext readerContext)
dwarf.StringTable.Read(reader);
}

reader.Log = readerContext.DebugLinePrinter;
reader.DebugLog = readerContext.DebugLinePrinter;
if (readerContext.DebugLineStream != null)
{
reader.Stream = readerContext.DebugLineStream;
reader.CurrentSection = dwarf.LineSection;
dwarf.LineSection.Read(reader);
}
reader.Log = null;
reader.DebugLog = null;

if (readerContext.DebugAddressRangeStream != null)
{
Expand All @@ -407,15 +407,15 @@ public static DwarfFile Read(DwarfReaderContext readerContext)
dwarf.AddressRangeTable.Read(reader);
}

reader.Log = null;
reader.DebugLog = null;
if (readerContext.DebugLocationStream != null)
{
reader.Stream = readerContext.DebugLocationStream;
reader.CurrentSection = dwarf.LocationSection;
dwarf.LocationSection.Read(reader);
}

reader.Log = null;
reader.DebugLog = null;
if (readerContext.DebugInfoStream != null)
{
reader.Stream = readerContext.DebugInfoStream;
Expand Down
2 changes: 1 addition & 1 deletion src/LibObjectFile/Dwarf/DwarfLineProgramTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public DwarfLineSequence RemoveLineSequenceAt(int index)

public override void Read(DwarfReader reader)
{
var log = reader.Log;
var log = reader.DebugLog;
var startOfSection = reader.Position;

reader.OffsetToLineProgramTable.Add(startOfSection, this);
Expand Down
1 change: 1 addition & 0 deletions src/LibObjectFile/Dwarf/DwarfStreamExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.IO;
using LibObjectFile.IO;

namespace LibObjectFile.Dwarf;

Expand Down
1 change: 1 addition & 0 deletions src/LibObjectFile/Dwarf/DwarfStringTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using LibObjectFile.IO;

namespace LibObjectFile.Dwarf;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// This file is licensed under the BSD-Clause 2 license.
// See the license.txt file in the project root for more information.

namespace LibObjectFile;
namespace LibObjectFile.Elf;

/// <summary>
/// Defines the way a value is calculated.
/// </summary>
public enum ValueKind
public enum ElfOffsetCalculationMode
{
/// <summary>
/// The associated value is automatically calculated by the system.
Expand Down
4 changes: 2 additions & 2 deletions src/LibObjectFile/Elf/ElfReader{TDecoder}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ private void VerifyAndFixProgramHeadersAndSections()
// If we found a section, we will bind the program header to this section
// and switch the offset calculation to auto
segment.Range = section;
segment.OffsetKind = ValueKind.Auto;
segment.OffsetCalculationMode = ElfOffsetCalculationMode.Auto;
break;
}
}
Expand Down Expand Up @@ -690,7 +690,7 @@ private void VerifyAndFixProgramHeadersAndSections()
segment.Range = new ElfSegmentRange(beginSection, segment.Position - beginSection.Position, endSection, (long)(segmentEndOffset - endSection.Position));
}

segment.OffsetKind = ValueKind.Auto;
segment.OffsetCalculationMode = ElfOffsetCalculationMode.Auto;
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/LibObjectFile/Elf/ElfSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace LibObjectFile.Elf;
/// </summary>
public sealed class ElfSegment : ElfObject
{
public ValueKind OffsetKind { get; set; }
public ElfOffsetCalculationMode OffsetCalculationMode { get; set; }

/// <summary>
/// Gets or sets the type of this segment.
Expand Down Expand Up @@ -55,7 +55,7 @@ public override void UpdateLayout(ElfVisitorContext context)
{
var diagnostics = context.Diagnostics;

if (OffsetKind == ValueKind.Auto)
if (OffsetCalculationMode == ElfOffsetCalculationMode.Auto)
{
Position = Range.Offset;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.IO;
using LibObjectFile.IO;

namespace LibObjectFile.Elf;

Expand Down
Loading

0 comments on commit ec9dad0

Please sign in to comment.