[Lldb-commits] [PATCH] D91026: [lldb] [Host/freebsd] Set Arg0 for 'platform process list -v'

2020-11-08 Thread Michał Górny via Phabricator via lldb-commits
mgorny created this revision.
mgorny added reviewers: labath, krytarowski, emaste.
mgorny requested review of this revision.

Same fix as in NetBSD (a6712889f5f1702dfa535718abe400d1a83174c5).


https://reviews.llvm.org/D91026

Files:
  lldb/source/Host/freebsd/Host.cpp
  lldb/test/API/commands/platform/process/list/TestProcessList.py


Index: lldb/test/API/commands/platform/process/list/TestProcessList.py
===
--- lldb/test/API/commands/platform/process/list/TestProcessList.py
+++ lldb/test/API/commands/platform/process/list/TestProcessList.py
@@ -19,7 +19,6 @@
 
 @skipIfWindows  # https://bugs.llvm.org/show_bug.cgi?id=43702
 @skipIfRemote   # rdar://problem/66542336
-@expectedFailureAll(oslist=['freebsd'])
 def test_process_list_with_args(self):
 """Test process list show process args"""
 self.build()
Index: lldb/source/Host/freebsd/Host.cpp
===
--- lldb/source/Host/freebsd/Host.cpp
+++ lldb/source/Host/freebsd/Host.cpp
@@ -83,6 +83,7 @@
 match_info_ptr->GetProcessInfo().GetName(
 return false;
 
+  process_info.SetArg0(cstr);
   Args &proc_args = process_info.GetArguments();
   while (1) {
 const uint8_t *p = data.PeekData(offset, 1);


Index: lldb/test/API/commands/platform/process/list/TestProcessList.py
===
--- lldb/test/API/commands/platform/process/list/TestProcessList.py
+++ lldb/test/API/commands/platform/process/list/TestProcessList.py
@@ -19,7 +19,6 @@
 
 @skipIfWindows  # https://bugs.llvm.org/show_bug.cgi?id=43702
 @skipIfRemote   # rdar://problem/66542336
-@expectedFailureAll(oslist=['freebsd'])
 def test_process_list_with_args(self):
 """Test process list show process args"""
 self.build()
Index: lldb/source/Host/freebsd/Host.cpp
===
--- lldb/source/Host/freebsd/Host.cpp
+++ lldb/source/Host/freebsd/Host.cpp
@@ -83,6 +83,7 @@
 match_info_ptr->GetProcessInfo().GetName(
 return false;
 
+  process_info.SetArg0(cstr);
   Args &proc_args = process_info.GetArguments();
   while (1) {
 const uint8_t *p = data.PeekData(offset, 1);
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D91030: [lldb] [test] Extend watchpoint test to wait for thread to start

2020-11-08 Thread Michał Górny via Phabricator via lldb-commits
mgorny created this revision.
mgorny added reviewers: labath, krytarowski, emaste.
Herald added a subscriber: arichardson.
mgorny requested review of this revision.

TestWatchpointMultipleThreads currently accounts for two scenarios:
setting the watchpoint before a new thread starts (presumably, verifying
that it will be propagated to the new thread) and setting it after
the thread starts (presumably, verifying that a new watchpoint is set
on all threads).  However, the latter test currently assumes that
the thread will be reported to the debugger before the breakpoint is
hit.  This is not the case on FreeBSD and NetBSD.

On NetBSD, new threads do not inherit debug registers from their parent
threads.  Instead, LLDB copies them manually after the new thread is
reported.  Since the thread is actually reported after the second
breakpoint location, both tests effectively check the same behavior
(i.e. watchpoint being set before the new thread is reported).

On FreeBSD, new threads inherit debug registers and we seem to hit
an interesting race condition.  While the thread is reported after
the breakpoint is hit, the kernel seems to construct it and copy
the debug register before that happens.  As a result, setting
the watchpoint at the second breakpoint location modifies the debug
registers of the first thread after they have been copied to the second
thread but before the debugger is aware of it.  Therefore,
the watchpoint is not propagated to the second thread and the test
fails.

Extend the test to cover all three possible scenarios: setting
watchpoint before the thread is lanched, after it is launched but before
it is guaranteed to have started and after it has actually started.  Add
a second barrier to account for the last case.  This should ensure that
the second assumption (i.e. that the watchpoint is set on all currently
known threads) is actually tested on FreeBSD and NetBSD.


https://reviews.llvm.org/D91030

Files:
  
lldb/test/API/commands/watchpoints/multiple_threads/TestWatchpointMultipleThreads.py
  lldb/test/API/commands/watchpoints/multiple_threads/main.cpp


Index: lldb/test/API/commands/watchpoints/multiple_threads/main.cpp
===
--- lldb/test/API/commands/watchpoints/multiple_threads/main.cpp
+++ lldb/test/API/commands/watchpoints/multiple_threads/main.cpp
@@ -3,10 +3,11 @@
 #include 
 
 volatile uint32_t g_val = 0;
-pseudo_barrier_t g_barrier;
+pseudo_barrier_t g_barrier, g_barrier2;
 
 void thread_func() {
   pseudo_barrier_wait(g_barrier);
+  pseudo_barrier_wait(g_barrier2);
   printf("%s starting...\n", __FUNCTION__);
   for (uint32_t i = 0; i < 10; ++i)
 g_val = i;
@@ -15,11 +16,15 @@
 int main(int argc, char const *argv[]) {
   printf("Before running the thread\n");
   pseudo_barrier_init(g_barrier, 2);
+  pseudo_barrier_init(g_barrier2, 2);
   std::thread thread(thread_func);
 
-  printf("After running the thread\n");
+  printf("After launching the thread\n");
   pseudo_barrier_wait(g_barrier);
 
+  printf("After running the thread\n");
+  pseudo_barrier_wait(g_barrier2);
+
   thread.join();
 
   return 0;
Index: 
lldb/test/API/commands/watchpoints/multiple_threads/TestWatchpointMultipleThreads.py
===
--- 
lldb/test/API/commands/watchpoints/multiple_threads/TestWatchpointMultipleThreads.py
+++ 
lldb/test/API/commands/watchpoints/multiple_threads/TestWatchpointMultipleThreads.py
@@ -23,8 +23,12 @@
 self.do_watchpoint_test("Before running the thread")
 
 @expectedFailureAll(oslist=["freebsd"])
+def test_watchpoint_after_thread_launch(self):
+"""Test that we can hit a watchpoint we set after launching another 
thread"""
+self.do_watchpoint_test("After launching the thread")
+
 def test_watchpoint_after_thread_start(self):
-"""Test that we can hit a watchpoint we set after starting another 
thread"""
+"""Test that we can hit a watchpoint we set after another thread 
starts"""
 self.do_watchpoint_test("After running the thread")
 
 def do_watchpoint_test(self, line):


Index: lldb/test/API/commands/watchpoints/multiple_threads/main.cpp
===
--- lldb/test/API/commands/watchpoints/multiple_threads/main.cpp
+++ lldb/test/API/commands/watchpoints/multiple_threads/main.cpp
@@ -3,10 +3,11 @@
 #include 
 
 volatile uint32_t g_val = 0;
-pseudo_barrier_t g_barrier;
+pseudo_barrier_t g_barrier, g_barrier2;
 
 void thread_func() {
   pseudo_barrier_wait(g_barrier);
+  pseudo_barrier_wait(g_barrier2);
   printf("%s starting...\n", __FUNCTION__);
   for (uint32_t i = 0; i < 10; ++i)
 g_val = i;
@@ -15,11 +16,15 @@
 int main(int argc, char const *argv[]) {
   printf("Before running the thread\n");
   pseudo_barrier_init(g_barrier, 2);
+  pseudo_barrier_init(g_barrier2, 2);
   std::thread thread(thread_func);
 
-  printf("After running the thread\

[Lldb-commits] [PATCH] D91030: [lldb] [test] Extend watchpoint test to wait for thread to start

2020-11-08 Thread Michał Górny via Phabricator via lldb-commits
mgorny added a comment.

NB: I'm going to address the FreeBSD problem separately.


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

https://reviews.llvm.org/D91030

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


[Lldb-commits] [PATCH] D91032: [lldb] [Process/FreeBSDRemote] Explicitly copy dbregs to new threads

2020-11-08 Thread Michał Górny via Phabricator via lldb-commits
mgorny created this revision.
mgorny added reviewers: emaste, labath, krytarowski.
mgorny requested review of this revision.

Explicitly copy dbregs to new threads to ensure that watchpoints
are propagated properly.  Fixes the test failure due to apparent kernel
race between reporting a new thread and resuming main thread execution
that makes implicit inheritance of dbregs unreliable.  By copying them
explicitly, we ensure that the new thread correctly respects watchpoints
that were set after the thread was created but before it was reported.

The code is copied from the NetBSD plugin and modernized to use
llvm::Error.


https://reviews.llvm.org/D91032

Files:
  lldb/source/Plugins/Process/FreeBSDRemote/NativeProcessFreeBSD.cpp
  lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD.h
  
lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.cpp
  
lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.h
  lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.cpp
  lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.h
  
lldb/test/API/commands/watchpoints/multiple_threads/TestWatchpointMultipleThreads.py

Index: lldb/test/API/commands/watchpoints/multiple_threads/TestWatchpointMultipleThreads.py
===
--- lldb/test/API/commands/watchpoints/multiple_threads/TestWatchpointMultipleThreads.py
+++ lldb/test/API/commands/watchpoints/multiple_threads/TestWatchpointMultipleThreads.py
@@ -22,7 +22,6 @@
 """Test that we can hit a watchpoint we set before starting another thread"""
 self.do_watchpoint_test("Before running the thread")
 
-@expectedFailureAll(oslist=["freebsd"])
 def test_watchpoint_after_thread_launch(self):
 """Test that we can hit a watchpoint we set after launching another thread"""
 self.do_watchpoint_test("After launching the thread")
Index: lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.h
===
--- lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.h
+++ lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.h
@@ -64,7 +64,7 @@
   void SetRunning();
   void SetStepping();
 
-  Status CopyWatchpointsFrom(NativeThreadFreeBSD &source);
+  llvm::Error CopyWatchpointsFrom(NativeThreadFreeBSD &source);
 
   // Member Variables
   lldb::StateType m_state;
Index: lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.cpp
===
--- lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.cpp
+++ lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.cpp
@@ -273,3 +273,12 @@
 
   return Status("Clearing hardware breakpoint failed.");
 }
+
+llvm::Error NativeThreadFreeBSD::CopyWatchpointsFrom(NativeThreadFreeBSD &source) {
+  llvm::Error s = GetRegisterContext().CopyHardwareWatchpointsFrom(source.GetRegisterContext());
+  if (!s) {
+m_watchpoint_index_map = source.m_watchpoint_index_map;
+m_hw_break_index_map = source.m_hw_break_index_map;
+  }
+  return s;
+}
Index: lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.h
===
--- lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.h
+++ lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.h
@@ -50,6 +50,9 @@
 
   Status WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override;
 
+  llvm::Error
+  CopyHardwareWatchpointsFrom(NativeRegisterContextFreeBSD &source) override;
+
 private:
   // Private member types.
   enum { GPRegSet, FPRegSet, XSaveRegSet, DBRegSet };
Index: lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.cpp
===
--- lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.cpp
+++ lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.cpp
@@ -1169,4 +1169,19 @@
   }
 }
 
+llvm::Error NativeRegisterContextFreeBSD_x86_64::CopyHardwareWatchpointsFrom(
+NativeRegisterContextFreeBSD &source) {
+  auto &r_source = static_cast(source);
+  Status res = r_source.ReadRegisterSet(DBRegSet);
+  if (!res.Fail()) {
+// copy dbregs only if any watchpoints were set
+if ((r_source.m_dbr.dr[7] & 0xFF) == 0)
+  return llvm::Error::success();
+
+m_dbr = r_source.m_dbr;
+res = WriteRegisterSet(DBRegSet);
+  }
+  return res.ToError();
+}
+
 #endif // defined(__x86_64__)
Index: lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD.h
===
--- lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD.h
+++ lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD.h
@@ -29,6 +29,8 @@
   static Native

[Lldb-commits] [PATCH] D91032: [lldb] [Process/FreeBSDRemote] Explicitly copy dbregs to new threads

2020-11-08 Thread Michał Górny via Phabricator via lldb-commits
mgorny added a comment.

Alternatively, we could relist threads on every stop.


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

https://reviews.llvm.org/D91032

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


[Lldb-commits] [PATCH] D87173: Ignores functions that have a range starting outside of a code section

2020-11-08 Thread António Afonso via Phabricator via lldb-commits
aadsm updated this revision to Diff 303746.
aadsm added a comment.

Merged the 2 run/checks into one


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87173

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/test/Shell/SymbolFile/DWARF/function-entries-invalid-addresses.yaml

Index: lldb/test/Shell/SymbolFile/DWARF/function-entries-invalid-addresses.yaml
===
--- /dev/null
+++ lldb/test/Shell/SymbolFile/DWARF/function-entries-invalid-addresses.yaml
@@ -0,0 +1,367 @@
+# RUN: split-file %s %t
+# RUN: yaml2obj %t/test.yaml > %t/test.obj
+
+#--- checks.lldb-commands
+# RUN: %lldb %t/test.obj -b -o "settings set interpreter.stop-command-source-on-error false" -s %t/checks.lldb-commands | FileCheck %s
+
+image lookup -F main
+# CHECK-LABEL: image lookup -F main
+# CHECK: 1 match found {{.*}}
+
+image lookup -F foo
+# CHECK-LABEL: image lookup -F foo
+# CHECK-NOT: 1 match found {{.*}}
+
+#--- test.yaml
+# int foo() {
+# return 1;
+# }
+#
+# int main() {
+# return 0;
+# }
+--- !mach-o
+FileHeader:
+  magic:   0xFEEDFACF
+  cputype: 0x0107
+  cpusubtype:  0x0003
+  filetype:0x000A
+  ncmds:   7
+  sizeofcmds:  1400
+  flags:   0x
+  reserved:0x
+LoadCommands:
+  - cmd: LC_UUID
+cmdsize: 24
+uuid:FD292DBF-A309-369B-A588-00E20D0E84CF
+  - cmd: LC_BUILD_VERSION
+cmdsize: 24
+platform:1
+minos:   659200
+sdk: 659206
+ntools:  0
+  - cmd: LC_SYMTAB
+cmdsize: 24
+symoff:  4096
+nsyms:   3
+stroff:  4144
+strsize: 33
+  - cmd: LC_SEGMENT_64
+cmdsize: 72
+segname: __PAGEZERO
+vmaddr:  0
+vmsize:  4294967296
+fileoff: 0
+filesize:0
+maxprot: 0
+initprot:0
+nsects:  0
+flags:   0
+  - cmd: LC_SEGMENT_64
+cmdsize: 232
+segname: __TEXT
+vmaddr:  4294967296
+vmsize:  16384
+fileoff: 0
+filesize:0
+maxprot: 5
+initprot:5
+nsects:  2
+flags:   0
+Sections:
+  - sectname:__text
+segname: __TEXT
+addr:0x00013FA0
+size:24
+offset:  0x
+align:   4
+reloff:  0x
+nreloc:  0
+flags:   0x8400
+reserved1:   0x
+reserved2:   0x
+reserved3:   0x
+content: CFFAEDFE070103000A0007007805
+  - sectname:__unwind_info
+segname: __TEXT
+addr:0x00013FB8
+size:72
+offset:  0x
+align:   2
+reloff:  0x
+nreloc:  0
+flags:   0x
+reserved1:   0x
+reserved2:   0x
+reserved3:   0x
+content: CFFAEDFE070103000A00070078051B001800FD292DBFA309369BA58800E20D0E84CF32001800010F0A00
+  - cmd: LC_SEGMENT_64
+cmdsize: 72
+segname: __LINKEDIT
+vmaddr:  4294983680
+vmsize:  4096
+fileoff: 4096
+filesize:81
+maxprot: 1
+initprot:1
+nsects:  0
+flags:   0
+  - cmd: LC_SEGMENT_64
+cmdsize: 952
+segname: __DWARF
+vmaddr:  4294987776
+vmsize:  4096
+fileoff: 8192
+filesize:826
+maxprot: 7
+initprot:3
+nsects:  6
+flags:   0
+Sections:
+  - sectname:__debug_pubnames
+segname: __DWARF
+addr:0x00015052
+size:35
+offset:  0x2052
+align:   0
+reloff:  0x
+nreloc:  0
+flags:   0x
+reserved1:   0x
+reserved2:   0x
+reserved3:   0x
+  - sectname:__debug_pubtypes
+segname: __DWARF
+addr:0x00015075
+size:26
+offset:  0x2075
+align:

[Lldb-commits] [PATCH] D90857: [lldb] add a missing dependency on intrinsics_gen

2020-11-08 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

In D90857#2379761 , @teemperor wrote:

> Just to clarify: This only a dependency in the downstream Swift branch?

Judging by the error message, this dependency is not correct even in the swift 
fork. lldbSymbol does not have a direct dependency on llvmIR. It has a 
dependency on swift (through SwiftASTContext), and swift (through 
AST/Builtins.h) has a dependency on the generated headers.

So, the right fix should be to add a lldbSymbol->Swift dependency (if one isn't 
there already), and then a swift->LLVMIR dep.

Unless there are other, direct dependencies (include paths) from lldbSymbol to 
LLVMIR. However, I don't see any in the llvm repo, so it still sounds like 
something swifty...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90857

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