Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Core/Output/Dumper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ private void DumpTypedData(SegmentMap map, IProcessorArchitecture arch, ImageMap
{
if (!map.TryFindSegment(item.Address, out var segment) || segment.MemoryArea == null)
return;
if (item.Name != null) {
w.Write("\t\t;;; {0}", item.Name);
w.WriteLine();
}
WriteLabel(item.Address, w);

var rdr = arch.CreateImageReader(segment.MemoryArea, item.Address);
Expand Down
107 changes: 102 additions & 5 deletions src/Core/Output/TypedDataDumper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,99 @@ public TypedDataDumper(EndianImageReader rdr, uint cbSize, Formatter stm)
public void VisitArray(ArrayType at)
{
var addrEnd = rdr.Address + cbSize;
for (int i = 0; at.IsUnbounded || i < at.Length; ++i)

if (at.ElementType.Domain < Domain.Composite)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relying on an enum's value in this way is fragile. Consider exposing a DataType.IsComposite property in a separate PR` to accomplish this.

{
if (!rdr.IsValid || addrEnd <= rdr.Address)
return;
at.ElementType.Accept(this);
int offset = 0;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There appears to be a lot of duplication here; could this code and the code in VisitPrimitiveType be harmonized?

bool clean = true;
for (int i = 0; at.IsUnbounded || i < at.Length; ++i)
{
if (!rdr.IsValid || addrEnd <= rdr.Address)
{
return;
}
if (offset % 16 == 0)
{
if (!clean)
{
fmt.WriteLine();
fmt.Write(" ");
clean = true;
}
switch (at.ElementType.Size)
{
default:
case 1:
fmt.WriteKeyword("db");
fmt.Write("\t");
break;
case 2:
fmt.WriteKeyword("dw");
fmt.Write("\t");
break;
case 4:
fmt.WriteKeyword("dd");
fmt.Write("\t");
break;
case 8:
fmt.WriteKeyword("dq");
fmt.Write("\t");
break;
}
}
if (!clean)
{
fmt.Write(",");
}
switch (at.ElementType.Size)
{
default:
case 1:
byte b = rdr.ReadByte();
if (at.ElementType.Domain == Domain.Character && 0x20 <= b && b < 0x7F)
{
fmt.Write(string.Format("'{0}'", (char)b));
}
else
{
fmt.Write(string.Format("0x{0:X2}", b));
}
offset += 1;
break;
case 2:
fmt.Write(string.Format("0x{0:X4}", rdr.ReadUInt16()));
offset += 2;
break;
case 4:
fmt.Write(string.Format("0x{0:X8}", rdr.ReadUInt32()));
offset += 4;
break;
case 8:
fmt.Write(string.Format("0x{0:X16}", rdr.ReadUInt64()));
offset += 8;
break;
}
clean = false;
}
if (!clean) {
fmt.WriteLine();
clean = true;
}
}
else {
bool clean = true;
for (int i = 0; at.IsUnbounded || i < at.Length; ++i)
{
if (!rdr.IsValid || addrEnd <= rdr.Address)
return;

if (!clean) {
fmt.Write(" ");
clean = true;
}
at.ElementType.Accept(this);
clean = false;
}
}
}

Expand Down Expand Up @@ -179,10 +267,12 @@ public void VisitString(StringType str)
fmt.Write("\t");
bool inStringLiteral = false;
string sep = "";
int size = str.Length;
int i = 0;
while (rdr.TryReadByte(out byte b))
{
//$REVIEW: assumes ASCII.
if (0x20 >= b && b < 0x7F)
if (0x20 <= b && b < 0x7F)
{
if (!inStringLiteral)
{
Expand All @@ -198,13 +288,20 @@ public void VisitString(StringType str)
if (inStringLiteral)
{
fmt.Write('\'');
inStringLiteral = false;
}
fmt.Write(sep);
sep = ",";
fmt.Write(string.Format("0x{0:X2}", b));
if (b == 0)
break;
}
i++;
Debug.Assert(i < size);
}
if (inStringLiteral)
{

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a unit tests to show how this is an improvement.

fmt.Write('\'');
}
fmt.WriteLine();
return;
Expand Down