-
Notifications
You must be signed in to change notification settings - Fork 254
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
Improve handling of nul-terminated string in Globals. #1350
base: master
Are you sure you want to change the base?
Changes from all commits
7953bb7
a134333
c680779
9a4086b
0b902e9
a33145c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
// Use IntelliSense to find out which attributes exist for C# debugging | ||
// Use hover for the description of the existing attributes | ||
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": ".NET Core Launch (console)", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build", | ||
// If you have changed target frameworks, make sure to update the program path. | ||
"program": "${workspaceFolder}/src/Drivers/WindowsDecompiler/bin/x64/Debug/net6.0-windows/WindowsDecompiler.exe", | ||
"args": [], | ||
"cwd": "${workspaceFolder}/src/Drivers/WindowsDecompiler", | ||
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console | ||
"console": "internalConsole", | ||
"stopAtEntry": false | ||
}, | ||
{ | ||
"name": ".NET Core Attach", | ||
"type": "coreclr", | ||
"request": "attach", | ||
"processId": "${command:pickProcess}" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
|
||
{ | ||
// Use IntelliSense to find out which attributes exist for C# debugging | ||
// Use hover for the description of the existing attributes | ||
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md | ||
"name": ".NET Core Launch (console)", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build", | ||
// If you have changed target frameworks, make sure to update the program path. | ||
"program": "${workspaceFolder}/bin/Debug/net8.0/astred.dll", "cwd": "${workspaceFolder}", | ||
"args": [], | ||
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console | ||
"console": "integratedTerminal", | ||
"stopAtEntry": false | ||
}, | ||
{ | ||
"name": "debug Astred easy", "stopAtEntry": false, | ||
"type": "coreclr", "request": "launch", "console": "integratedTerminal", "preLaunchTask": "build", | ||
"program": "${workspaceFolder}/bin/Debug/net8.0/astred.dll", "cwd": "${workspaceFolder}", | ||
"args": [ "-full", "tests/easycpp/easy.cpp", "-treedump", "tests/easycpp/easy.cpp",], | ||
}, | ||
{ | ||
"name": ".NET Core Attach", | ||
"type": "coreclr", | ||
"request": "attach" | ||
}, | ||
{ | ||
"name": "reko li.dcproject", "stopAtEntry": false, | ||
"type": "coreclr", "request": "launch", "console": "integratedTerminal", | ||
"program": "${workspaceFolder}\\..\\..\\LaserType\\LaserImage\\reko-private\\reko.dll", | ||
"cwd": "${workspaceFolder}\\..\\..\\LaserType\\LaserImage", | ||
"args": [ "--env", "ms-dos", "--dasm-bytes", "--dasm-address", "li.dcproject" ], | ||
}, | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,13 +100,15 @@ private string UnsignedRepresentation(Constant u) | |
else | ||
{ | ||
var sb = new StringBuilder(); | ||
#if USE_TILDA_IF_SMALLER | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a user preference, and it shouldn't be coded using |
||
if ((p & msb) != 0 && | ||
Bits.BitCount(m & p) > Bits.BitCount(m & ~p)) | ||
{ | ||
sb.Append('~'); | ||
p = m & ~p; | ||
hexRep = p.ToString("X", CultureInfo.InvariantCulture); | ||
} | ||
#endif | ||
sb.Append("0x"); | ||
int length = hexRep.Length; | ||
int pad; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,19 +205,17 @@ public bool VisitArray(ArrayType at) | |
fmt.Terminate(); | ||
fmt.Indent(); | ||
fmt.Write("{"); | ||
fmt.Terminate(); | ||
fmt.Indentation += fmt.TabSize; | ||
fmt.Write(" "); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You've changed the rendering of arrays so that they are rendered on a single line. What happens when an array of 1000 entries is encountered? I prefer the current state of affairs, until Reko can prettify the output source. In addition, you haven't changed the There is the beginning of a code prettifier in |
||
|
||
bool ok = true; | ||
for (int i = 0; i < at.Length; ++i) | ||
{ | ||
fmt.Indent(); | ||
ok = at.ElementType.Accept(this); | ||
fmt.Terminate(","); | ||
if (i < at.Length - 1) { | ||
fmt.Write(","); | ||
} | ||
} | ||
|
||
fmt.Indentation -= fmt.TabSize; | ||
fmt.Indent(); | ||
fmt.Write("}"); | ||
return ok; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#region License | ||
/* | ||
/* | ||
* Copyright (C) 1999-2024 John Källén. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
|
@@ -31,7 +31,7 @@ public class TypedDataDumper : IDataTypeVisitor | |
private readonly uint cbSize; | ||
private readonly Formatter fmt; | ||
|
||
public TypedDataDumper(EndianImageReader rdr, uint cbSize, Formatter stm) | ||
public TypedDataDumper(EndianImageReader rdr, uint cbSize, Formatter stm) | ||
{ | ||
this.rdr = rdr; | ||
this.cbSize = cbSize; | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
{ | ||
if (!rdr.IsValid || addrEnd <= rdr.Address) | ||
return; | ||
at.ElementType.Accept(this); | ||
int offset = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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; | ||
} | ||
} | ||
} | ||
|
||
|
@@ -179,6 +267,8 @@ 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. | ||
|
@@ -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) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -669,6 +669,7 @@ public uint GetDataSize(IProcessorArchitecture arch, Address addr, DataType dt) | |
return 0; | ||
while (rdr.IsValid && !rdr.ReadNullCharTerminator(strDt.ElementType)) | ||
; | ||
strDt.Length = (int) (rdr.Address - addr); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a little unhappy about mutating the string data type when it's being used in what semantically is a read-only query type function. Consider looking at setting the size when the string is created. |
||
return (uint) (rdr.Address - addr); | ||
} | ||
else | ||
|
@@ -840,6 +841,29 @@ public void AddGlobalField(Address address, DataType dt, string name) | |
fields.Add(offset, dt, name); | ||
} | ||
|
||
public DataType? FindGlobalField(Address address) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a doc comment for this new method. |
||
{ | ||
int offset; | ||
StructureFieldCollection fields; | ||
if (address.Selector.HasValue && | ||
SegmentMap.TryFindSegment(address, out var seg)) | ||
{ | ||
offset = (int) address.Offset; | ||
fields = seg.Fields.Fields; | ||
} | ||
else | ||
{ | ||
offset = (int) address.ToLinear(); | ||
fields = GlobalFields.Fields; | ||
} | ||
var globalField = fields.AtOffset(offset); | ||
if (globalField != null) | ||
{ | ||
return globalField.DataType; | ||
} | ||
return null; | ||
} | ||
|
||
/// <summary> | ||
/// Add new imported external procedure if there is not one with same | ||
/// import name. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,7 +109,11 @@ public void CollectUserGlobalVariableTypes() | |
{ | ||
if (ud.Value.DataType != null) | ||
{ | ||
var dt = ud.Value.DataType.Accept(deser); | ||
var dt = program.FindGlobalField(ud.Key); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you write a unit tests in |
||
if (dt == null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using the |
||
{ | ||
dt = ud.Value.DataType.Accept(deser); | ||
} | ||
AddGlobalField(dt, ud.Key, ud.Value.Name); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why this file is here, and not in
.vscode
? I'm not familiar with the significance of the leading underscore.