This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Unify default/hijack listener between Process{Attach,Launch}Info (NFC)
ClosedPublic

Authored by mib on Apr 14 2023, 4:56 PM.

Details

Summary

This patch is a simple refactor that unifies the default and hijack
listener methods and attributes between ProcessAttachInfo and
ProcessLaunchInfo.

These 2 classes are both derived from the ProcessInfo base class so this
patch moves the listeners attributes and getter/setter methods to the
base class.

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>

Diff Detail

Event Timeline

mib created this revision.Apr 14 2023, 4:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 14 2023, 4:56 PM
mib requested review of this revision.Apr 14 2023, 4:56 PM

Creating a ProcessAttachInfo from a ProcessLaunchInfo with this change means they'll have different listeners. Is that ProcessLaunchInfo kept around for any other reason? Or is it just made to create the ProcessAttachInfo? This seems like a reasonable move to me, but I'm not sure how LaunchInfo and AttachInfo might interact.

mib added a comment.EditedApr 20 2023, 2:12 PM

Creating a ProcessAttachInfo from a ProcessLaunchInfo with this change means they'll have different listeners. Is that ProcessLaunchInfo kept around for any other reason? Or is it just made to create the ProcessAttachInfo? This seems like a reasonable move to me, but I'm not sure how LaunchInfo and AttachInfo might interact.

@bulbazord Not sure what you mean ... We need to convert to the ProcessLaunchInfo into a ProcessAttachInfo when the user ask use to launch a process but we end up asking the platform to do the launch after which we attach to the process. In both cases, we use the default listener (the debugger listener if the user didn't provide a custom listener).

Creating a ProcessAttachInfo from a ProcessLaunchInfo with this change means they'll have different listeners. Is that ProcessLaunchInfo kept around for any other reason? Or is it just made to create the ProcessAttachInfo? This seems like a reasonable move to me, but I'm not sure how LaunchInfo and AttachInfo might interact.

@bulbazord Not sure what you mean ... We need to convert to the ProcessLaunchInfo into a ProcessAttachInfo when the user ask use to launch a process but we end up asking the platform to do the launch after which we attach to the process. In both cases, we use the default listener (the debugger listener if the user didn't provide a custom listener).

What I'm not sure about is that the ProcessAttachInfo constructor we're using takes a ProcessLaunchInfo as an argument and fills in its fields with it. It used to be that ProcessAttachInfo would get its Listener and HijackListener from the ProcessLaunchInfo passed in. Now, they could have different Listeners and HijackListeners. When we create a ProcessAttachInfo from a ProcessLaunchInfo, is it expected that these 2 things will diverge in that way? Do we use the ProcessLaunchInfo that we build the ProcessAttachInfo with in any other way?

mib added a comment.Apr 21 2023, 11:18 AM

Creating a ProcessAttachInfo from a ProcessLaunchInfo with this change means they'll have different listeners. Is that ProcessLaunchInfo kept around for any other reason? Or is it just made to create the ProcessAttachInfo? This seems like a reasonable move to me, but I'm not sure how LaunchInfo and AttachInfo might interact.

@bulbazord Not sure what you mean ... We need to convert to the ProcessLaunchInfo into a ProcessAttachInfo when the user ask use to launch a process but we end up asking the platform to do the launch after which we attach to the process. In both cases, we use the default listener (the debugger listener if the user didn't provide a custom listener).

What I'm not sure about is that the ProcessAttachInfo constructor we're using takes a ProcessLaunchInfo as an argument and fills in its fields with it. It used to be that ProcessAttachInfo would get its Listener and HijackListener from the ProcessLaunchInfo passed in. Now, they could have different Listeners and HijackListeners. When we create a ProcessAttachInfo from a ProcessLaunchInfo, is it expected that these 2 things will diverge in that way? Do we use the ProcessLaunchInfo that we build the ProcessAttachInfo with in any other way?

We had to do that previously because ProcessLaunchInfo and ProcessAttachInfo were not related (they were not derived from the same base class). With this patch, I hoisted the the m_listener_sp and m_hijack_listener_sp with their getters and setters into the ProcessInfo class from which both the ProcessAttachInfo and ProcessLaunchInfo are derived. So by calling the copy constructor for ProcessInfo (see inline comment), that should also copy the listener and hijack listener from the process launch info into the process attach info.

lldb/include/lldb/Target/Process.h
122

Because we moved m_listener_sp and m_hijack_listener_sp to ProcessInfo and since both Process{Attach,Launch}Info are derived from that class, this should also copy the listeners.

bulbazord added inline comments.Apr 21 2023, 3:28 PM
lldb/include/lldb/Target/Process.h
122

I don't think that's true? We're taking a different subclass and initializing from that, we have to be explicit about which fields are copied over, no? Maybe I'm missing something here.

Either way, I'm not sure it really matters unless the ProcessLaunchInfo and ProcessAttachInfo necessarily need to be in sync. Do they?

bulbazord added inline comments.Apr 21 2023, 3:42 PM
lldb/include/lldb/Target/Process.h
122

Wait, I'm being silly, you're doing operator= there. Okay, sorry for all the noise, I think I was just confused.

bulbazord accepted this revision.Apr 21 2023, 3:43 PM

I don't have an issue here then. LGTM

This revision is now accepted and ready to land.Apr 21 2023, 3:43 PM
mib marked 2 inline comments as done.Apr 21 2023, 3:57 PM