-
Notifications
You must be signed in to change notification settings - Fork 253
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?
Conversation
galenh
commented
Aug 15, 2024
- When StringType size is calculated, save it to the underlying ArrayType.
- Re-used existing DataTypes from Globals instead of re-creating them when collecting types.
- Fix an inverted "<=" error.
- Print linear arrays on a single line.
Hello @galenh ; thanks for your PR. I have some comments that need to be addressed before accepting it. Also, as a new contributor, don't forget to add yourself to the |
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.
I've finished the review. There are some issues that must be addressed before I can accept the PR. Notably, as it stands right now neither the unit tests nor the regression tests are passing.
Consider running:
msbuild /t:run_unit_tests /v:m /m /p:Platform=x64 /p:Configuration=Release|Debug
msbuild /t:run_regressions /v:m /m /p:Platform=x86 /p:Configuration=Release|Debug
to discover where the test failures are.
@@ -0,0 +1,27 @@ | |||
{ | |||
// Use IntelliSense to find out which attributes exist for C# debugging |
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.
@@ -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 comment
The 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
/ #endif
. Instead consider opening an issue to add support for changing the formatting of unsigned numbers, controlled by user preference. There we can discuss how this would best be accomplished.
@@ -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 comment
The 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 GlobalDataWriterTests.cs
unit tests to match, so the CI pipeline will fail. Make sure there is a unit tests to cover this case.
There is the beginning of a code prettifier in Core\Output\PrettyPrinter.cs
that should be able to format arrays nicely. Consider opening an issue and using that class to make data output prettier.
src/Core/Output/TypedDataDumper.cs
Outdated
@@ -182,7 +182,7 @@ public void VisitString(StringType str) | |||
while (rdr.TryReadByte(out byte b)) | |||
{ | |||
//$REVIEW: assumes ASCII. | |||
if (0x20 <= b && b < 0x7F) | |||
if (0x20 >= b && b < 0x7F) |
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.
You've introduced a bug. This expression will print out ASCII control characters (those whose code points are < 0x20) which is not the intent of this code. Running the unit tests would have caught this mistake. Please revert this 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 comment
The 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.
@@ -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); | |||
if (dt == null) |
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.
Consider using the dt is null
syntax here.
src/Reko-decompiler.sln
Outdated
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.
SLN files are notoriously hard to view the diff on. What is the nature of the changes you've made here?
src/binall.cmd
Outdated
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.
This looks like a private cmd file you've added. What is the purpose of "binall"? Could it be accomplished using Reko's release script? What is a LasertType\LaserImage
?
src/buildall.cmd
Outdated
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.
I'd prefer it if this was placed in the src/tools
directory, to avoid clutter in the src
directory.
src/cleanall.cmd
Outdated
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.
Have you considered using git clean -dfX
instead of this?
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.
I've added a few more comments. The changes are starting to become overwhelming, and could benefit from being broken up into separate, more focused PR's
@@ -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 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; |
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.
There appears to be a lot of duplication here; could this code and the code in VisitPrimitiveType
be harmonized?
Debug.Assert(i < size); | ||
} | ||
if (inStringLiteral) | ||
{ |
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.
Please add a unit tests to show how this is an improvement.