This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Fix 'memory write' to not allow specifying values when writing file contents
ClosedPublic

Authored by RamNalamothu on Nov 24 2021, 10:20 AM.

Details

Summary

Currently the 'memory write' command allows specifying the values when
writing the file contents to memory but the values are actually ignored. This
patch fixes that by erroring out when values are specified in such cases.

Diff Detail

Event Timeline

RamNalamothu requested review of this revision.Nov 24 2021, 10:20 AM
RamNalamothu created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptNov 24 2021, 10:20 AM
DavidSpickett added inline comments.Nov 25 2021, 2:07 AM
lldb/source/Interpreter/CommandObject.cpp
457

(like I said on the other diff)

What does it mean for an arg_entry to be empty? (please add the answer as a comment in the code as well)

I think this is avoiding trying to index [0] on an empty arg lower down:

} else {
  StreamString names;
  for (int j = 0; j < num_alternatives; ++j) {
    if (j > 0)
      names.Printf(" | ");
    names.Printf("%s", GetArgumentName(arg_entry[j].arg_type));
  }

  std::string name_str = std::string(names.GetString());
  switch (arg_entry[0].arg_repetition) {

Which is fine but I'm not sure if arg_entry being empty is unusual enough to prefer an assert rather than skipping over it.

lldb/test/API/commands/memory/write/TestMemoryWrite.py
2

I wasn't expecting such thorough tests, this is great!

50

You don't need to add these comments. The output is clear enough from the expect parameters.

58

I think error=False is the default so you can leave it out here. We tend to add error=True for the few times we want a failure.

82

So here I'd remove the comment and add "error: " to the start of the substr.

95

Again this is the default, the vast majority of the time we want a match so we only call out the few where we don't.

97

You could skip this line. Small thing but we're not testing the general usage printing infrastructure here just the specifics in the following 2 lines.

lldb/test/API/commands/memory/write/main.cpp
1 ↗(On Diff #389533)

Trivial thing, but this file has no need to be .cpp since it's plain c.

Address review comments.

RamNalamothu marked 6 inline comments as done.Nov 25 2021, 9:23 AM

Thanks for the comments.

I wasn't familiar with the Pyhton test infrastructure so I took the files from commands/memory/read and updated as needed here. All the comments etc came from that.

I think I addressed all the feedback.

DavidSpickett accepted this revision.Nov 26 2021, 1:47 AM

All the comments etc came from that.

Yeah it's a bit of a judgement call so it's a safe bet to add them and see what review thinks. I know for sure there are plenty of tests with way more cryptic expectations that don't have comments :)

This LGTM.

lldb/test/API/commands/memory/write/Makefile
3

I was gonna say you can drop this but I see a few other tests with it, and it won't harm anything.

This revision is now accepted and ready to land.Nov 26 2021, 1:47 AM