This is an archive of the discontinued LLVM Phabricator instance.

[lldb] tab completion for breakpoint names
ClosedPublic

Authored by MrHate on May 27 2020, 11:40 PM.

Details

Summary
  1. created a common completion for breakpoint names;
  2. bound the breakpoint name common completion with eArgTypeBreakpointName;
  3. implemented the dedicated completion for breakpoint read -N.

Diff Detail

Event Timeline

MrHate created this revision.May 27 2020, 11:40 PM
teemperor requested changes to this revision.Jul 1 2020, 7:51 AM

Maybe I'm missing something, but this seems to be two very different independent patches in one (one for br read completion and one for br set which don't depend on each other)? If yes, then please split these up in the future. It's usually less work to review smaller patches (and it's just good practice to do so).

Just some minor points, beside that this LGTM.

@JDevlieghere Can you double check that the structured data use in this patch is fine?

lldb/source/Commands/CommandCompletions.cpp
631

Some small code style adjustments here:

for (const std::string &name : name_list)
  request.TryCompleteCurrentArg(name);

(no curly braces around the single statement body and using a reference because that's how LLVM is usually doing this).

lldb/source/Commands/CommandObjectBreakpoint.cpp
2115

Could you make this just an llvm::Optional<FileSpec> file_spec and then set that in the loop. Then you can drop the success variable.

2163

If you drop success than this can just be if (!bkpt_dict->GetValueForKeyAsArray("Names", names_array))

lldb/test/API/functionalities/completion/TestCompletion.py
654

Do we need the os.getcwd() here? This should work without if I understand correctly (also it avoids the whole issue of spaces in the path breaking this command).

654

There should also be a test for a invalid JSON file and one where the prefix couldn't be found (e.g., try completing "n" to nothing and "m" to "mm").

660

We just landed some improvements to this upstream, so this can now be self.assertSuccess(bp1.AddNameWithErrorHandling("nn")).

This revision now requires changes to proceed.Jul 1 2020, 7:51 AM
MrHate updated this revision to Diff 275473.Jul 3 2020, 6:02 PM
  1. replaced std::string with const std::string& in for loop;
  2. refactored the success segment with llvm::Optional<FileSpec> file_spec;
  3. added invalidation check in test.
JDevlieghere added inline comments.Jul 7 2020, 10:35 AM
lldb/include/lldb/Interpreter/CommandCompletions.h
106

Please clang-format the patch.

lldb/source/Commands/CommandObjectBreakpoint.cpp
2100–2172

While you're here you might as well remove this useless comment :-)

2116

Please convert these to StringRef and use its comparison operator.

2126

There's nothing wrong with using getValue() but the consensus across LLVM and LLDB is to use *file_spec.

lldb/test/API/functionalities/completion/breakpoints.json
35

As pointed out by phab.

JDevlieghere added inline comments.Jul 7 2020, 10:39 AM
lldb/source/Commands/CommandObjectBreakpoint.cpp
2133

The structured data looks good to me. I'm not convinced this is where that logic should live, but given the current implementation where all that stuff is implemented in the corresponding data structures, I think that's fine.

MrHate updated this revision to Diff 276295.Jul 7 2020, 6:21 PM
  1. clang-formatted related files;
  2. refactored line 2100 with StringRef;
  3. replaced files_pec.hasValue() to file_spec, file_spec.getValue() to *file_spec;
  4. removed an useless comment;
  5. added a new line at the end of breakpoints.json.
This revision was not accepted when it landed; it landed in state Needs Review.Aug 20 2020, 11:56 AM
This revision was automatically updated to reflect the committed changes.