This is an archive of the discontinued LLVM Phabricator instance.

[LLDB][GUI] Add Create Target form
ClosedPublic

Authored by OmarEmaraDev on Jul 16 2021, 2:21 PM.

Details

Summary

This patch adds a Create Target form for the LLDB GUI. Additionally, an
Arch Field was introduced to input an arch and the file and directory
fields now have a required property.

Diff Detail

Event Timeline

OmarEmaraDev created this revision.Jul 16 2021, 2:21 PM
OmarEmaraDev requested review of this revision.Jul 16 2021, 2:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 16 2021, 2:21 PM

This doesn't support remote files yet, I am still having trouble testing those. Also, there is also an unrelated clang-format change, not sure if I should revert it or keep it.

clayborg requested changes to this revision.Jul 16 2021, 3:47 PM

Great start! Many inlined comments.

lldb/source/Core/IOHandlerCursesGUI.cpp
1309

It should be a property of the FileFieldDelegate if the file is for the current system. We might be specifying a file on a remote system, so it doesn't always have to exist, nor should it be resolved on the current system. When creating a target we would always want to specify this file should exist on the current system.

1315

Should this to into the FieldDelegate so we don't need to put it into both FileFieldDelegate and DirectoryFieldDelegate? Then the default FieldDelegate::FieldDelegateExitCallback() function could be:

virtual void FieldDelegate::FieldDelegateExitCallback() {
  if (!m_required)
    return;
  // Check value with another virtual function?
  FieldDelegateValueIsValid();
}

This seems like many fields would want to require being set and we don't want to re-invent this for each kind of field.

1346

It should be a property of the DirectoryFieldDelegate if the directory is for the current system. We might be specifying a working directory on a remote system, so it doesn't always have to exist, nor should it be resolved on the current system. So if this is for the current system, then it is ok to resolve, else, we need to just use the path as is.

1912

Should we add a "bool resolve_local_path" so we know if we should resolve the path on the local system as mentioned above?

1922

Should we add a "bool resolve_local_path" so we know if we should resolve the path on the local system as mentioned above?

2569
2573

we should add a "Platform" TextField that is populated with all of the platform names. The default value should be the currently selected platform. To get a list of all platform plug-in names you can do this like you did for the process plug-ins:

static const char *GetPlatformPluginNameAtIndex(uint32_t idx);

To get the current selected platform:

ConstString default_platform_name;
lldb::PlatformSP platform_sp = debugger.GetPlatformList()GetSelectedPlatform()
if (platform_sp)
  default_platform_name = platform_sp->GetName();

This will help with remote targets. The main reason we need this is many linux or android binaries have very minimal target triples encoded into the ELF files, so we often need to specify "remote-android" or "remote-linux" when creating targets. The user can of course set the "Architecture" with a fully specified triple, but they can also avoid setting the arch and just specify the platform.

2576
2609

Won't this be taken care of already by the File field? We should construct the FileDelegate so that:

  • the file must exist
  • the file gets resolved on the local system
  • the file field is required

This way, the only way for the user to get to the "Create" button if is if they already were able to set a valid and required by the FileFieldDelegate class.

2614–2618

No need to do this here, we will get an error back from the target creation below in the "status". So this can be removed. Also, our FileFieldDelegate should have already shown an error if the file doesn't exist right?

2620

Set the platform name if one was selected and it wasn't the currently selected one

2624

Maybe add a GetPlatformOptions()?

2637–2639

Remove extra braces on single line if statements (LLVM coding guidelines).

2643–2652

Remove, these should have been verified by the FileFieldDelegate already.

2662–2664

Remove extra braces on single line if statements (LLVM coding guidelines).

2668–2677

Remove as FileFieldDelegate should have taken care of this already, or the process_sp->LoadCore() will return a valid error.

2686–2688

Remove extra braces on single line if statements (LLVM coding guidelines).

This revision now requires changes to proceed.Jul 16 2021, 3:47 PM

This doesn't support remote files yet, I am still having trouble testing those.

If you want to set that up we have some docs for it:
https://lldb.llvm.org/use/remote.html
https://lldb.llvm.org/use/qemu-testing.html

This is mostly how I work on AArch64 changes. That said there are some tricky bits getting the networking setup so I'm happy to try this out for you if you want.

I'll keep an eye on this change.

I am currently breaking this patch into smaller independent viable patches as suggested.

lldb/source/Core/IOHandlerCursesGUI.cpp
1309

I was trying to add properties that indicates if the file is local or not and if it should be resolved or not. But they all seems identical to the need_to_exist property. If m_need_to_exist is false, then the file will not be resolved and will not be checked with the host file system (Which is what we want to remote files). If it is true, then it will be resolved and checked with the host file system (Which is what we want for local files). So adding more properties might be redundant? What do you think?

1315

The fields that can have a required property is the TextField and its derivatives (File, Directory, and Number), so we can can add this logic there. This is implemented in D106458.

2609

D106459 implements the necessary bits to allow for this.

Thanks @DavidSpickett! I will look into this and let you know how it goes.

I am currently breaking this patch into smaller independent viable patches as suggested.

That will make reviews much easier. Are you going to land the other smaller diffs first and then update this one after hey have landed?

lldb/source/Core/IOHandlerCursesGUI.cpp
1309

That sounds fine. No need to add more fields that don't make sense

1315

Sounds good!

2609

Sounds good!

Are you going to land the other smaller diffs first and then update this one after hey have landed?

Yes. There is much dependency between patches, so the smaller ones will have to land first then we will rebase this one on main. Also, notice that the smaller patches might conflict with each other, so I will have to rebase some of them once other land.

lldb/source/Core/IOHandlerCursesGUI.cpp
2573

The required field is implemented in D106483.

Are you going to land the other smaller diffs first and then update this one after hey have landed?

Yes. There is much dependency between patches, so the smaller ones will have to land first then we will rebase this one on main. Also, notice that the smaller patches might conflict with each other, so I will have to rebase some of them once other land.

Indeed! I applied two patches already, and the last one https://reviews.llvm.org/D106483 is conflicting. Ping me back when you get the conflicts resolved and we can move forward.

  • Rebase on main.
  • Add basic remote debugging support.

I still can't get remote debugging to work unfortunately, or maybe I don't understand it really. The way I understand it is as follows:

  • If the remote file is specified, then that means we are creating a target for remote debugging.
  • If the remote file doesn't exist, we upload the executable to the location specified by the remote file.
  • If the remote file exists but the executable doesn't exist, then the remote file is downloaded to the local file. (Why? And does that mean the executable needn't exist if the remote file is specified? And also, does that mean the executable isn't a required field?)
  • Everything happens using the platform of the created target, which is specified in the platform field. (When/Where does the connection with the server get established? platform connect connects the currently selected platform, but the target have its own platform which may not necessary be the currently selected one.)
clayborg requested changes to this revision.Jul 27 2021, 4:12 PM

Many inline comments with simple fixes! Very close.

lldb/source/Core/IOHandlerCursesGUI.cpp
2569

Lots of "true, true" and "true, false" in the file field parameters. Add comments with parameter names:

m_executable_field = AddFileField("Executable", "", *need_to_exist=*/true, /*required=*/true);
2570–2573

Ditto for all these: add comment variable names as suggested above.

2574

inlined comment for "false" above

2601

I would vote to shorten this string with something like "Executable only" with no trailing '.' character.

2602

remove the '.'

2603

remote the '.'

2609

remove the '.'. You might want to create a constexpr string value as a static outside of the functions and use them in GetLoadDependentFilesChoices() and GetLoadDependentFiles(). The static would be:

static constexpr const char *kLoadDependentFilesNo = "No";
static constexpr const char *kLoadDependentFilesYes = "Yes";
static constexpr const char *kLoadDependentFilesExecOnly = "Only for executable files";

Then use these in the GetLoadDependentFilesChoices() and GetLoadDependentFiles() functions. That way if you change the strings, you only have to change one location.

2611

remove the '.'

2681–2696

Remove all of this (getting the platform, putting the file), no need to do anything other than module_sp->SetPlatformFileSpec(...) that you are doing below. This information will be used in Process::Launch(...) to do the right thing.

This revision now requires changes to proceed.Jul 27 2021, 4:12 PM
  • Address review comments
clayborg accepted this revision.Jul 28 2021, 4:10 PM

Looks good!

This revision is now accepted and ready to land.Jul 28 2021, 4:10 PM
This revision was landed with ongoing or failed builds.Jul 29 2021, 1:28 PM
This revision was automatically updated to reflect the committed changes.