This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Fix bug where memory read --outfile is not truncating the file
ClosedPublic

Authored by JDevlieghere on Apr 5 2021, 10:16 AM.

Details

Summary

The memory read --outfile command should truncate the output when unless --append-outfile. Fix the bug and add a test.

rdar://76062318

Diff Detail

Event Timeline

JDevlieghere requested review of this revision.Apr 5 2021, 10:16 AM
JDevlieghere created this revision.
teemperor requested changes to this revision.Apr 6 2021, 6:18 AM

Thanks for the patch! I'll be extra nit-picky about the test to make up for the great meme steal of 2021.

lldb/test/API/functionalities/memory/read/TestMemoryRead.py
145

Single use var (I guess you can't reuse that as a common prefix as the address expression has to be the last arg).

148

self.assertTrue(res.Succeeded(), "memory read failed:" + res.GetError())

153

I believe usually we use self.getBuildArtifact("memory-read-output") for that. If you open a named temp file here (and don't close it), then the second open can fail on Windows.

165

Can we ever hit this? We just get an exception in the for loop above (and the exception won't be very useful to diagnose the failure).

You can do this:

lines = [s.strip() for s in lines]
expected = [s.strip() for s in expected]
self.assertEqual(lines, expected)

(assertEqual actually explains which elements are missing/additional/different for lists)

172

Could you write some garbage into the file between the two tests here?

This revision now requires changes to proceed.Apr 6 2021, 6:18 AM
JDevlieghere marked 5 inline comments as done.Apr 6 2021, 8:33 AM

Thanks for the patch! I'll be extra nit-picky about the test to make up for the great meme steal of 2021.

Credit was given, so I do not consider it theft.

teemperor accepted this revision.Apr 6 2021, 8:36 AM

LGTM now beside the now redundant import

lldb/test/API/functionalities/memory/read/TestMemoryRead.py
7

No longer needed

167

I see you have taken my suggestion literally

This revision is now accepted and ready to land.Apr 6 2021, 8:36 AM
This revision was landed with ongoing or failed builds.Apr 6 2021, 9:16 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptApr 6 2021, 9:16 AM