[Lldb-commits] [PATCH] D101250: Wrap edit line configuration calls into helper functions

2021-04-25 Thread Neal via Phabricator via lldb-commits
nealsid created this revision.
nealsid requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Currently we call el_set directly to configure the editor in the libedit 
wrapper.  There are some cases in which this causes extra casting, but we pass 
captureless lambdas as function pointers, which should work out of the box.  
Since el_set takes varargs, if the cast is incorrect or if the cast is not 
present, it causes a run time failure rather than compile error.  This change 
makes it so a few different types of configuration is done inside a helper 
function to provide type safety and eliminate that casting.  I didn't do all 
edit line configuration because I'm not sure how important it was in other 
cases and it might require something more general keep up with libedit's 
signature.  I'm open to suggestions, though.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101250

Files:
  lldb/include/lldb/Host/Editline.h
  lldb/source/Host/common/Editline.cpp

Index: lldb/source/Host/common/Editline.cpp
===
--- lldb/source/Host/common/Editline.cpp
+++ lldb/source/Host/common/Editline.cpp
@@ -1102,6 +1102,21 @@
   return CC_REDISPLAY;
 }
 
+void Editline::AddFunctionToEditLine(const EditLineCharType *command,
+ const EditLineCharType *helptext,
+ EditlineCommandCallbackType callbackFn) {
+  el_wset(m_editline, EL_ADDFN, command, helptext, callbackFn);
+}
+
+void Editline::SetEditLinePromptCallback(
+EditlinePromptCallbackType callbackFn) {
+  el_set(m_editline, EL_PROMPT, callbackFn);
+}
+
+void Editline::SetGetCharacterFunction(EditlineGetCharCallbackType callbackFn) {
+  el_wset(m_editline, EL_GETCFN, callbackFn);
+}
+
 void Editline::ConfigureEditor(bool multiline) {
   if (m_editline && m_multiline_enabled == multiline)
 return;
@@ -1128,74 +1143,83 @@
   el_set(m_editline, EL_CLIENTDATA, this);
   el_set(m_editline, EL_SIGNAL, 0);
   el_set(m_editline, EL_EDITOR, "emacs");
-  el_set(m_editline, EL_PROMPT,
- (EditlinePromptCallbackType)([](EditLine *editline) {
-   return Editline::InstanceFor(editline)->Prompt();
- }));
 
-  el_wset(m_editline, EL_GETCFN, (EditlineGetCharCallbackType)([](
- EditLine *editline, EditLineGetCharType *c) {
-return Editline::InstanceFor(editline)->GetCharacter(c);
-  }));
+  SetGetCharacterFunction([](EditLine *editline, EditLineGetCharType *c) {
+return Editline::InstanceFor(editline)->GetCharacter(c);
+  });
+
+  SetEditLinePromptCallback([](EditLine *editline) {
+return Editline::InstanceFor(editline)->Prompt();
+  });
 
   // Commands used for multiline support, registered whether or not they're
   // used
-  el_wset(m_editline, EL_ADDFN, EditLineConstString("lldb-break-line"),
-  EditLineConstString("Insert a line break"),
-  (EditlineCommandCallbackType)([](EditLine *editline, int ch) {
-return Editline::InstanceFor(editline)->BreakLineCommand(ch);
-  }));
-  el_wset(m_editline, EL_ADDFN, EditLineConstString("lldb-end-or-add-line"),
-  EditLineConstString("End editing or continue when incomplete"),
-  (EditlineCommandCallbackType)([](EditLine *editline, int ch) {
-return Editline::InstanceFor(editline)->EndOrAddLineCommand(ch);
-  }));
-  el_wset(m_editline, EL_ADDFN, EditLineConstString("lldb-delete-next-char"),
-  EditLineConstString("Delete next character"),
-  (EditlineCommandCallbackType)([](EditLine *editline, int ch) {
-return Editline::InstanceFor(editline)->DeleteNextCharCommand(ch);
-  }));
-  el_wset(
-  m_editline, EL_ADDFN, EditLineConstString("lldb-delete-previous-char"),
+  AddFunctionToEditLine(
+  EditLineConstString("lldb-break-line"),
+  EditLineConstString("Insert a line break"),
+  [](EditLine *editline, int ch) {
+return Editline::InstanceFor(editline)->BreakLineCommand(ch);
+  });
+
+  AddFunctionToEditLine(
+  EditLineConstString("lldb-end-or-add-line"),
+  EditLineConstString("End editing or continue when incomplete"),
+  [](EditLine *editline, int ch) {
+return Editline::InstanceFor(editline)->EndOrAddLineCommand(ch);
+  });
+  AddFunctionToEditLine(
+  EditLineConstString("lldb-delete-next-char"),
+  EditLineConstString("Delete next character"),
+  [](EditLine *editline, int ch) {
+return Editline::InstanceFor(editline)->DeleteNextCharCommand(ch);
+  });
+  AddFunctionToEditLine(
+  EditLineConstString("lldb-delete-previous-char"),
   EditLineConstString("Delete previous character"),
-  (EditlineCommandCallbackType)([](EditLine *editline, int ch) {
+  [](EditLine *editline, int ch) {
 return Editline::InstanceFor(editline)->DeletePreviousCharComm

[Lldb-commits] [PATCH] D101237: [lldb] Fix [[no_unique_address]] and libstdc++ 11's std::unique_ptr

2021-04-25 Thread Jan Kratochvil via Phabricator via lldb-commits
jankratochvil added a comment.

In D101237#2714971 , @teemperor wrote:

> grep tells me that attribute also influences a bunch of other things in 
> subtle ways (It seems to potentially influence ABIs and Obj-C encodings?) and 
> we don't really know what other things this might influence in the future. So 
> I have the suspicion that putting that attr on all record fields might break 
> something in a subtle way.

I have a similar feeling but without a proof of anything ...

> In any case, what LLDB is usually doing is these situations is inferring from 
> the existing debug information. I assume by looking at the 
> `DW_AT_data_member_locations` values we could determine what the 
> no_unique_address fields are in our record (and then only put the attributes 
> on that)?

... LLDB can become overcomplicated as if you remove the 
`[[no_unique_address]]` from this testcase's `class B` the only effect on DWARF 
is for `class C`:

   0x0033:   DW_TAG_structure_type
   DW_AT_calling_convention   (DW_CC_pass_by_value)
   DW_AT_name ("C")
  -DW_AT_byte_size(0x01)
  +DW_AT_byte_size(0x02)
   DW_AT_decl_file("uniqX.C")
   DW_AT_decl_line(5)
  
   0x003c: DW_TAG_inheritance
 DW_AT_type   (0x004f "B")
 DW_AT_data_member_location   (0x00)
  
   0x0042: DW_TAG_member
 DW_AT_name   ("c")
 DW_AT_type   (0x006e "char")
 DW_AT_decl_file  ("uniqX.C")
 DW_AT_decl_line  (6)
  -  DW_AT_data_member_location   (0x00)
  +  DW_AT_data_member_location   (0x01)
  
   0x004e: NULL

As LLDB could be already using `class B` as `CompilerType` LLDB will need to 
create a second/new `CompilerType` for `class B` when creating `CompilerType` 
for `class C`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101237/new/

https://reviews.llvm.org/D101237

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D101237: [lldb] Fix [[no_unique_address]] and libstdc++ 11's std::unique_ptr

2021-04-25 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor added a comment.

You're right, we can't fix up the types afterwards so I guess inferring the 
attribute isn't an option here.

I'll try to find some time to properly look at this next week, but in the 
meantime I pushed your bug report into creduce over night and that's what it 
spit out (I pasted the same into the bug report):

  template  struct b { [[__no_unique_address__]] a c; };
  template  struct e;
  template 
  struct e : e<1, g...>, b {};
  template  struct e : b {};
  template  class h : e<0, d...> {};
  class A {
struct i {};
using j = i;
h k;
  } iup;
  int main() {
return sizeof(iup);
  }


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101237/new/

https://reviews.llvm.org/D101237

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D101237: [lldb] Fix [[no_unique_address]] and libstdc++ 11's std::unique_ptr

2021-04-25 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor added a comment.

Ignore my comments above. I assumed we didn't have a minimal crash reproducer 
from the comment in the dependent patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101237/new/

https://reviews.llvm.org/D101237

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 65f2a75 - [lldb] [Process/FreeBSD] Report fork/vfork events to LLGS

2021-04-25 Thread Michał Górny via lldb-commits

Author: Michał Górny
Date: 2021-04-25T19:40:46+02:00
New Revision: 65f2a757371e687cee6c36788fde1dab22895df7

URL: 
https://github.com/llvm/llvm-project/commit/65f2a757371e687cee6c36788fde1dab22895df7
DIFF: 
https://github.com/llvm/llvm-project/commit/65f2a757371e687cee6c36788fde1dab22895df7.diff

LOG: [lldb] [Process/FreeBSD] Report fork/vfork events to LLGS

Differential Revision: https://reviews.llvm.org/D100547

Added: 


Modified: 
lldb/packages/Python/lldbsuite/test/dotest.py
lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp
lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.h
lldb/source/Plugins/Process/FreeBSD/NativeThreadFreeBSD.cpp
lldb/source/Plugins/Process/FreeBSD/NativeThreadFreeBSD.h

Removed: 




diff  --git a/lldb/packages/Python/lldbsuite/test/dotest.py 
b/lldb/packages/Python/lldbsuite/test/dotest.py
index b3a6fb318d969..d48c578d7d75d 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest.py
@@ -863,7 +863,7 @@ def checkForkVForkSupport():
 from lldbsuite.test import lldbplatformutil
 
 platform = lldbplatformutil.getPlatform()
-if platform not in ["linux"]:
+if platform not in ["freebsd", "linux"]:
 configuration.skip_categories.append("fork")
 
 

diff  --git a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp 
b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp
index 67a7b737c7d6c..6d9a7d7f0d9c1 100644
--- a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp
+++ b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp
@@ -128,13 +128,19 @@ NativeProcessFreeBSD::Factory::Attach(
   return std::move(process_up);
 }
 
+NativeProcessFreeBSD::Extension
+NativeProcessFreeBSD::Factory::GetSupportedExtensions() const {
+  return Extension::multiprocess | Extension::fork | Extension::vfork;
+}
+
 // Public Instance Methods
 
 NativeProcessFreeBSD::NativeProcessFreeBSD(::pid_t pid, int terminal_fd,
NativeDelegate &delegate,
const ArchSpec &arch,
MainLoop &mainloop)
-: NativeProcessELF(pid, terminal_fd, delegate), m_arch(arch) {
+: NativeProcessELF(pid, terminal_fd, delegate), m_arch(arch),
+  m_main_loop(mainloop) {
   if (m_terminal_fd != -1) {
 Status status = EnsureFDFlags(m_terminal_fd, O_NONBLOCK);
 assert(status.Success());
@@ -247,19 +253,6 @@ void NativeProcessFreeBSD::MonitorSIGTRAP(lldb::pid_t pid) 
{
 return;
   }
 
-  if (info.pl_flags & PL_FLAG_FORKED) {
-MonitorClone(info.pl_child_pid);
-return;
-  }
-
-  if (info.pl_flags & PL_FLAG_VFORK_DONE) {
-Status error =
-PtraceWrapper(PT_CONTINUE, pid, reinterpret_cast(1), 0);
-if (error.Fail())
-  SetState(StateType::eStateInvalid);
-return;
-  }
-
   if (info.pl_lwpid > 0) {
 for (const auto &t : m_threads) {
   if (t->GetID() == static_cast(info.pl_lwpid))
@@ -271,6 +264,26 @@ void NativeProcessFreeBSD::MonitorSIGTRAP(lldb::pid_t pid) 
{
info.pl_lwpid);
   }
 
+  if (info.pl_flags & PL_FLAG_FORKED) {
+assert(thread);
+MonitorClone(info.pl_child_pid, info.pl_flags & PL_FLAG_VFORKED, *thread);
+return;
+  }
+
+  if (info.pl_flags & PL_FLAG_VFORK_DONE) {
+assert(thread);
+if ((m_enabled_extensions & Extension::vfork) == Extension::vfork) {
+  thread->SetStoppedByVForkDone();
+  SetState(StateType::eStateStopped, true);
+} else {
+  Status error =
+  PtraceWrapper(PT_CONTINUE, pid, reinterpret_cast(1), 0);
+  if (error.Fail())
+SetState(StateType::eStateInvalid);
+}
+return;
+  }
+
   if (info.pl_flags & PL_FLAG_SI) {
 assert(info.pl_siginfo.si_signo == SIGTRAP);
 LLDB_LOG(log, "SIGTRAP siginfo: si_code = {0}, pid = {1}",
@@ -933,7 +946,8 @@ bool NativeProcessFreeBSD::SupportHardwareSingleStepping() 
const {
   return !m_arch.IsMIPS();
 }
 
-void NativeProcessFreeBSD::MonitorClone(::pid_t child_pid) {
+void NativeProcessFreeBSD::MonitorClone(::pid_t child_pid, bool is_vfork,
+NativeThreadFreeBSD &parent_thread) {
   Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
   LLDB_LOG(log, "fork, child_pid={0}", child_pid);
 
@@ -955,16 +969,42 @@ void NativeProcessFreeBSD::MonitorClone(::pid_t 
child_pid) {
 return;
   }
 
-  MainLoop unused_loop;
-  NativeProcessFreeBSD child_process{static_cast<::pid_t>(child_pid),
- m_terminal_fd, m_delegate, m_arch,
- unused_loop};
-  child_process.Detach();
-  Status pt_error =
-  PtraceWrapper(PT_CONTINUE, GetID(), reinterpret_cast(1), 0);
-  if (pt_error.Fail()) {
-LLDB_LOG_ERROR(log, pt_error.ToError(),
-   "unable to resume parent

[Lldb-commits] [lldb] 0621502 - [lldb] [Process/NetBSD] Report fork/vfork events to LLGS

2021-04-25 Thread Michał Górny via lldb-commits

Author: Michał Górny
Date: 2021-04-25T19:40:59+02:00
New Revision: 06215023f450ce25bb608fcdb78fd1f310b23c70

URL: 
https://github.com/llvm/llvm-project/commit/06215023f450ce25bb608fcdb78fd1f310b23c70
DIFF: 
https://github.com/llvm/llvm-project/commit/06215023f450ce25bb608fcdb78fd1f310b23c70.diff

LOG: [lldb] [Process/NetBSD] Report fork/vfork events to LLGS

Differential Revision: https://reviews.llvm.org/D100554

Added: 


Modified: 
lldb/packages/Python/lldbsuite/test/dotest.py
lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp
lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.h

Removed: 




diff  --git a/lldb/packages/Python/lldbsuite/test/dotest.py 
b/lldb/packages/Python/lldbsuite/test/dotest.py
index d48c578d7d75d..6e5bd6b393560 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest.py
@@ -863,7 +863,7 @@ def checkForkVForkSupport():
 from lldbsuite.test import lldbplatformutil
 
 platform = lldbplatformutil.getPlatform()
-if platform not in ["freebsd", "linux"]:
+if platform not in ["freebsd", "linux", "netbsd"]:
 configuration.skip_categories.append("fork")
 
 

diff  --git a/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp 
b/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
index 1f357e3e96d79..7d860e30774cf 100644
--- a/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
+++ b/lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
@@ -133,13 +133,19 @@ NativeProcessNetBSD::Factory::Attach(
   return std::move(process_up);
 }
 
+NativeProcessNetBSD::Extension
+NativeProcessNetBSD::Factory::GetSupportedExtensions() const {
+  return Extension::multiprocess | Extension::fork | Extension::vfork;
+}
+
 // Public Instance Methods
 
 NativeProcessNetBSD::NativeProcessNetBSD(::pid_t pid, int terminal_fd,
  NativeDelegate &delegate,
  const ArchSpec &arch,
  MainLoop &mainloop)
-: NativeProcessELF(pid, terminal_fd, delegate), m_arch(arch) {
+: NativeProcessELF(pid, terminal_fd, delegate), m_arch(arch),
+  m_main_loop(mainloop) {
   if (m_terminal_fd != -1) {
 Status status = EnsureFDFlags(m_terminal_fd, O_NONBLOCK);
 assert(status.Success());
@@ -264,14 +270,23 @@ void NativeProcessNetBSD::MonitorSIGTRAP(lldb::pid_t pid) 
{
   return;
 }
 
+assert(thread);
 if (pst.pe_report_event == PTRACE_VFORK_DONE) {
-  Status error =
-  PtraceWrapper(PT_CONTINUE, pid, reinterpret_cast(1), 0);
-  if (error.Fail())
-SetState(StateType::eStateInvalid);
-  return;
-} else
-  MonitorClone(pst.pe_other_pid);
+  if ((m_enabled_extensions & Extension::vfork) == Extension::vfork) {
+thread->SetStoppedByVForkDone();
+SetState(StateType::eStateStopped, true);
+  } else {
+Status error =
+PtraceWrapper(PT_CONTINUE, pid, reinterpret_cast(1), 0);
+if (error.Fail())
+  SetState(StateType::eStateInvalid);
+  }
+} else {
+  assert(pst.pe_report_event == PTRACE_FORK ||
+ pst.pe_report_event == PTRACE_VFORK);
+  MonitorClone(pst.pe_other_pid, pst.pe_report_event == PTRACE_VFORK,
+   *thread);
+}
 return;
   }
   case TRAP_LWP: {
@@ -994,7 +1009,8 @@ Status NativeProcessNetBSD::ReinitializeThreads() {
   return error;
 }
 
-void NativeProcessNetBSD::MonitorClone(::pid_t child_pid) {
+void NativeProcessNetBSD::MonitorClone(::pid_t child_pid, bool is_vfork,
+   NativeThreadNetBSD &parent_thread) {
   Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
   LLDB_LOG(log, "clone, child_pid={0}", child_pid);
 
@@ -1016,16 +1032,43 @@ void NativeProcessNetBSD::MonitorClone(::pid_t 
child_pid) {
 return;
   }
 
-  MainLoop unused_loop;
-  NativeProcessNetBSD child_process{static_cast<::pid_t>(child_pid),
-m_terminal_fd, m_delegate, m_arch,
-unused_loop};
-  child_process.Detach();
-  Status pt_error =
-  PtraceWrapper(PT_CONTINUE, GetID(), reinterpret_cast(1), 0);
-  if (pt_error.Fail()) {
-LLDB_LOG_ERROR(log, std::move(pt_error.ToError()),
-   "unable to resume parent process {1}: {0}", GetID());
-SetState(StateType::eStateInvalid);
+  ptrace_siginfo_t info;
+  const auto siginfo_err =
+  PtraceWrapper(PT_GET_SIGINFO, child_pid, &info, sizeof(info));
+  if (siginfo_err.Fail()) {
+LLDB_LOG(log, "PT_GET_SIGINFO failed {0}", siginfo_err);
+return;
+  }
+  assert(info.psi_lwpid >= 0);
+  lldb::tid_t child_tid = info.psi_lwpid;
+
+  std::uniqu

[Lldb-commits] [PATCH] D100547: [lldb] [Process/FreeBSD] Report fork/vfork events to LLGS

2021-04-25 Thread Michał Górny via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG65f2a757371e: [lldb] [Process/FreeBSD] Report fork/vfork 
events to LLGS (authored by mgorny).
Herald added a project: LLDB.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100547/new/

https://reviews.llvm.org/D100547

Files:
  lldb/packages/Python/lldbsuite/test/dotest.py
  lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp
  lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.h
  lldb/source/Plugins/Process/FreeBSD/NativeThreadFreeBSD.cpp
  lldb/source/Plugins/Process/FreeBSD/NativeThreadFreeBSD.h

Index: lldb/source/Plugins/Process/FreeBSD/NativeThreadFreeBSD.h
===
--- lldb/source/Plugins/Process/FreeBSD/NativeThreadFreeBSD.h
+++ lldb/source/Plugins/Process/FreeBSD/NativeThreadFreeBSD.h
@@ -59,6 +59,9 @@
   void SetStoppedByTrace();
   void SetStoppedByExec();
   void SetStoppedByWatchpoint(uint32_t wp_index);
+  void SetStoppedByFork(lldb::pid_t child_pid, lldb::tid_t child_tid);
+  void SetStoppedByVFork(lldb::pid_t child_pid, lldb::tid_t child_tid);
+  void SetStoppedByVForkDone();
   void SetStoppedWithNoReason();
   void SetStopped();
   void SetRunning();
Index: lldb/source/Plugins/Process/FreeBSD/NativeThreadFreeBSD.cpp
===
--- lldb/source/Plugins/Process/FreeBSD/NativeThreadFreeBSD.cpp
+++ lldb/source/Plugins/Process/FreeBSD/NativeThreadFreeBSD.cpp
@@ -130,6 +130,30 @@
   m_stop_info.details.signal.signo = SIGTRAP;
 }
 
+void NativeThreadFreeBSD::SetStoppedByFork(lldb::pid_t child_pid,
+   lldb::tid_t child_tid) {
+  SetStopped();
+
+  m_stop_info.reason = StopReason::eStopReasonFork;
+  m_stop_info.details.fork.child_pid = child_pid;
+  m_stop_info.details.fork.child_tid = child_tid;
+}
+
+void NativeThreadFreeBSD::SetStoppedByVFork(lldb::pid_t child_pid,
+lldb::tid_t child_tid) {
+  SetStopped();
+
+  m_stop_info.reason = StopReason::eStopReasonVFork;
+  m_stop_info.details.fork.child_pid = child_pid;
+  m_stop_info.details.fork.child_tid = child_tid;
+}
+
+void NativeThreadFreeBSD::SetStoppedByVForkDone() {
+  SetStopped();
+
+  m_stop_info.reason = StopReason::eStopReasonVForkDone;
+}
+
 void NativeThreadFreeBSD::SetStoppedWithNoReason() {
   SetStopped();
 
Index: lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.h
===
--- lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.h
+++ lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.h
@@ -39,6 +39,8 @@
 llvm::Expected>
 Attach(lldb::pid_t pid, NativeDelegate &native_delegate,
MainLoop &mainloop) const override;
+
+Extension GetSupportedExtensions() const override;
   };
 
   // NativeProcessProtocol Interface
@@ -96,6 +98,7 @@
 private:
   MainLoop::SignalHandleUP m_sigchld_handle;
   ArchSpec m_arch;
+  MainLoop& m_main_loop;
   LazyBool m_supports_mem_region = eLazyBoolCalculate;
   std::vector> m_mem_region_cache;
 
@@ -113,7 +116,8 @@
   void MonitorSIGSTOP(lldb::pid_t pid);
   void MonitorSIGTRAP(lldb::pid_t pid);
   void MonitorSignal(lldb::pid_t pid, int signal);
-  void MonitorClone(::pid_t child_pid);
+  void MonitorClone(::pid_t child_pid, bool is_vfork,
+NativeThreadFreeBSD &parent_thread);
 
   Status PopulateMemoryRegionCache();
   void SigchldHandler();
Index: lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp
===
--- lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp
+++ lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp
@@ -128,13 +128,19 @@
   return std::move(process_up);
 }
 
+NativeProcessFreeBSD::Extension
+NativeProcessFreeBSD::Factory::GetSupportedExtensions() const {
+  return Extension::multiprocess | Extension::fork | Extension::vfork;
+}
+
 // Public Instance Methods
 
 NativeProcessFreeBSD::NativeProcessFreeBSD(::pid_t pid, int terminal_fd,
NativeDelegate &delegate,
const ArchSpec &arch,
MainLoop &mainloop)
-: NativeProcessELF(pid, terminal_fd, delegate), m_arch(arch) {
+: NativeProcessELF(pid, terminal_fd, delegate), m_arch(arch),
+  m_main_loop(mainloop) {
   if (m_terminal_fd != -1) {
 Status status = EnsureFDFlags(m_terminal_fd, O_NONBLOCK);
 assert(status.Success());
@@ -247,19 +253,6 @@
 return;
   }
 
-  if (info.pl_flags & PL_FLAG_FORKED) {
-MonitorClone(info.pl_child_pid);
-return;
-  }
-
-  if (info.pl_flags & PL_FLAG_VFORK_DONE) {
-Status error =
-PtraceWrapper(PT_CONTINUE, pid, reinterpret_cast(1), 0)

[Lldb-commits] [PATCH] D100554: [lldb] [Process/NetBSD] Report fork/vfork events to LLGS

2021-04-25 Thread Michał Górny via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG06215023f450: [lldb] [Process/NetBSD] Report fork/vfork 
events to LLGS (authored by mgorny).
Herald added a project: LLDB.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100554/new/

https://reviews.llvm.org/D100554

Files:
  lldb/packages/Python/lldbsuite/test/dotest.py
  lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
  lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
  lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp
  lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.h

Index: lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.h
===
--- lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.h
+++ lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.h
@@ -59,6 +59,9 @@
   void SetStoppedByTrace();
   void SetStoppedByExec();
   void SetStoppedByWatchpoint(uint32_t wp_index);
+  void SetStoppedByFork(lldb::pid_t child_pid, lldb::tid_t child_tid);
+  void SetStoppedByVFork(lldb::pid_t child_pid, lldb::tid_t child_tid);
+  void SetStoppedByVForkDone();
   void SetStoppedWithNoReason();
   void SetStopped();
   void SetRunning();
Index: lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp
===
--- lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp
+++ lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp
@@ -130,6 +130,30 @@
   m_stop_info.details.signal.signo = SIGTRAP;
 }
 
+void NativeThreadNetBSD::SetStoppedByFork(lldb::pid_t child_pid,
+   lldb::tid_t child_tid) {
+  SetStopped();
+
+  m_stop_info.reason = StopReason::eStopReasonFork;
+  m_stop_info.details.fork.child_pid = child_pid;
+  m_stop_info.details.fork.child_tid = child_tid;
+}
+
+void NativeThreadNetBSD::SetStoppedByVFork(lldb::pid_t child_pid,
+lldb::tid_t child_tid) {
+  SetStopped();
+
+  m_stop_info.reason = StopReason::eStopReasonVFork;
+  m_stop_info.details.fork.child_pid = child_pid;
+  m_stop_info.details.fork.child_tid = child_tid;
+}
+
+void NativeThreadNetBSD::SetStoppedByVForkDone() {
+  SetStopped();
+
+  m_stop_info.reason = StopReason::eStopReasonVForkDone;
+}
+
 void NativeThreadNetBSD::SetStoppedWithNoReason() {
   SetStopped();
 
Index: lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
===
--- lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
+++ lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
@@ -36,6 +36,8 @@
 llvm::Expected>
 Attach(lldb::pid_t pid, NativeDelegate &native_delegate,
MainLoop &mainloop) const override;
+
+Extension GetSupportedExtensions() const override;
   };
 
   // NativeProcessProtocol Interface
@@ -89,6 +91,7 @@
 private:
   MainLoop::SignalHandleUP m_sigchld_handle;
   ArchSpec m_arch;
+  MainLoop& m_main_loop;
   LazyBool m_supports_mem_region = eLazyBoolCalculate;
   std::vector> m_mem_region_cache;
 
@@ -106,7 +109,8 @@
   void MonitorSIGSTOP(lldb::pid_t pid);
   void MonitorSIGTRAP(lldb::pid_t pid);
   void MonitorSignal(lldb::pid_t pid, int signal);
-  void MonitorClone(::pid_t child_pid);
+  void MonitorClone(::pid_t child_pid, bool is_vfork,
+NativeThreadNetBSD &parent_thread);
 
   Status PopulateMemoryRegionCache();
   void SigchldHandler();
Index: lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
===
--- lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
+++ lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
@@ -133,13 +133,19 @@
   return std::move(process_up);
 }
 
+NativeProcessNetBSD::Extension
+NativeProcessNetBSD::Factory::GetSupportedExtensions() const {
+  return Extension::multiprocess | Extension::fork | Extension::vfork;
+}
+
 // Public Instance Methods
 
 NativeProcessNetBSD::NativeProcessNetBSD(::pid_t pid, int terminal_fd,
  NativeDelegate &delegate,
  const ArchSpec &arch,
  MainLoop &mainloop)
-: NativeProcessELF(pid, terminal_fd, delegate), m_arch(arch) {
+: NativeProcessELF(pid, terminal_fd, delegate), m_arch(arch),
+  m_main_loop(mainloop) {
   if (m_terminal_fd != -1) {
 Status status = EnsureFDFlags(m_terminal_fd, O_NONBLOCK);
 assert(status.Success());
@@ -264,14 +270,23 @@
   return;
 }
 
+assert(thread);
 if (pst.pe_report_event == PTRACE_VFORK_DONE) {
-  Status error =
-  PtraceWrapper(PT_CONTINUE, pid, reinterpret_cast(1), 0);
-  if (error.Fail())
-SetState(StateType::eStateInvalid);
-  return;
-} else
-  Mon