[Lldb-commits] [PATCH] D134842: Improve dynamic loader support in DynamicLoaderPOSIXDYLD when using core files.

2022-10-03 Thread António Afonso via Phabricator via lldb-commits
aadsm added a comment.

Would it be possible to have a test for this? We would have probably found 
this, if we had a test at the time I rewrote this logic.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134842

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


[Lldb-commits] [PATCH] D96637: Make sure the interpreter module was loaded before making checks against it

2021-02-12 Thread António Afonso via Phabricator via lldb-commits
aadsm created this revision.
aadsm added reviewers: mgorny, labath, emaste.
aadsm requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This issue was introduced in https://reviews.llvm.org/D92187.
The guard I'm changing were is supposed to act when linux is loading the linker 
for the second time (due to differences in paths like symlinks).
This is done by checking `module_sp != m_interpreter_module.lock()` however 
this will be true when `m_interpreter_module` wasn't initialized, making linux 
unload the linker module (the most visible result here is that lldb will stop 
getting notified about new modules loaded by the process, because it can't set 
the rendezvous breakpoint again after the stepping over it once).
The `m_interpreter_module` is not getting initialize when it goes through this 
path: 
https://github.com/llvm/llvm-project/blob/dbfdb139f75470a9abc78e7c9faf743fdd963c2d/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp#L332,
 which happens when lldb was able to read the address from the dynamic section 
of the executable.

What I'm not sure about though, is if when we go through this path if we still 
load the linker twice on linux. If that's the case then it means we need to 
somehow set the m_interpreter_module instead of the fix I provide here. I've 
only tested this on Android.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96637

Files:
  lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp


Index: lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
===
--- lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
+++ lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
@@ -441,6 +441,7 @@
   if (module_sp.get()) {
 if (module_sp->GetObjectFile()->GetBaseAddress().GetLoadAddress(
 &m_process->GetTarget()) == m_interpreter_base &&
+m_interpreter_module.lock() &&
 module_sp != m_interpreter_module.lock()) {
   // If this is a duplicate instance of ld.so, unload it.  We may end 
up
   // with it if we load it via a different path than before (symlink


Index: lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
===
--- lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
+++ lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
@@ -441,6 +441,7 @@
   if (module_sp.get()) {
 if (module_sp->GetObjectFile()->GetBaseAddress().GetLoadAddress(
 &m_process->GetTarget()) == m_interpreter_base &&
+m_interpreter_module.lock() &&
 module_sp != m_interpreter_module.lock()) {
   // If this is a duplicate instance of ld.so, unload it.  We may end up
   // with it if we load it via a different path than before (symlink
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D96680: [lldb-vscode] Emit the breakpoint changed event on location resolved

2021-02-14 Thread António Afonso via Phabricator via lldb-commits
aadsm created this revision.
aadsm added reviewers: clayborg, labath, wallace, kusmour.
aadsm requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

VSCode was not being informed whenever a location had been resolved (after 
being initated as non-resolved), so even though it was actually resolved, the 
IDE would show a hollow dot (instead of a red dot) because it didn't know about 
the change.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96680

Files:
  lldb/tools/lldb-vscode/lldb-vscode.cpp


Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -417,7 +417,8 @@
   // of wether the locations were added or removed, the breakpoint
   // ins't going away, so we the reason is always "changed".
   if ((event_type & lldb::eBreakpointEventTypeLocationsAdded ||
-   event_type & lldb::eBreakpointEventTypeLocationsRemoved) &&
+   event_type & lldb::eBreakpointEventTypeLocationsRemoved ||
+   event_type & lldb::eBreakpointEventTypeLocationsResolved) &&
   bp.MatchesName(BreakpointBase::GetBreakpointLabel())) {
 auto bp_event = CreateEventObject("breakpoint");
 llvm::json::Object body;


Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -417,7 +417,8 @@
   // of wether the locations were added or removed, the breakpoint
   // ins't going away, so we the reason is always "changed".
   if ((event_type & lldb::eBreakpointEventTypeLocationsAdded ||
-   event_type & lldb::eBreakpointEventTypeLocationsRemoved) &&
+   event_type & lldb::eBreakpointEventTypeLocationsRemoved ||
+   event_type & lldb::eBreakpointEventTypeLocationsResolved) &&
   bp.MatchesName(BreakpointBase::GetBreakpointLabel())) {
 auto bp_event = CreateEventObject("breakpoint");
 llvm::json::Object body;
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D96637: Make sure the interpreter module was loaded before making checks against it

2021-02-16 Thread António Afonso via Phabricator via lldb-commits
aadsm added a comment.

> We should have a test for this.

how do you recommend doing this? I spent a couple of hours on this but got no 
where. From what I understood we should prefer lit tests, so I was thinking of 
creating a binary that dlopens a module. However, I wasn't able to create a 
binary that I can start and capture its pid address so that I can attach to. 
Here's what I've tried so far:

  // RUN: cp %s %s.cpp
  // RUN: %clang -g -O0 --target=x86_64-linux-gnu %s.cpp -o %s.out
  // RUN: PID=$(%s.out)
  // RUN: %lldb -p $PID -b -o 'target list' | FileCheck %s
  // RUN: kill -9 $PID
  // CHECK: foo
  
  #include 
  #include 
  
  int main() {
  pid_t pid = fork();
  if (pid > 0) {
  // parent process, print child pid
  printf("%d", pid);
  return 0;
  } else if (pid < 0) {
  printf("Unable to fork\n");
  return -1;
  }
  // child process
  pause();
  }

The lit test get stuck on `// RUN: PID=$(%s.out)`. Not sure why, the parent 
process shouldn't wait on its children..


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96637

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


[Lldb-commits] [PATCH] D96680: [lldb-vscode] Emit the breakpoint changed event on location resolved

2021-02-18 Thread António Afonso via Phabricator via lldb-commits
aadsm updated this revision to Diff 324864.
aadsm added a comment.

Add api test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96680

Files:
  lldb/packages/Python/lldbsuite/test/decorators.py
  lldb/test/API/functionalities/module_load_attach/Makefile
  lldb/test/API/functionalities/module_load_attach/TestModuleLoadAttach.py
  lldb/test/API/functionalities/module_load_attach/feature.c
  lldb/test/API/functionalities/module_load_attach/main.c
  lldb/tools/lldb-vscode/lldb-vscode.cpp

Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -417,7 +417,8 @@
   // of wether the locations were added or removed, the breakpoint
   // ins't going away, so we the reason is always "changed".
   if ((event_type & lldb::eBreakpointEventTypeLocationsAdded ||
-   event_type & lldb::eBreakpointEventTypeLocationsRemoved) &&
+   event_type & lldb::eBreakpointEventTypeLocationsRemoved ||
+   event_type & lldb::eBreakpointEventTypeLocationsResolved) &&
   bp.MatchesName(BreakpointBase::GetBreakpointLabel())) {
 auto bp_event = CreateEventObject("breakpoint");
 llvm::json::Object body;
Index: lldb/test/API/functionalities/module_load_attach/main.c
===
--- /dev/null
+++ lldb/test/API/functionalities/module_load_attach/main.c
@@ -0,0 +1,15 @@
+#include 
+#include 
+#include 
+
+volatile int flip_to_1_to_continue = 0;
+
+int main() {
+  lldb_enable_attach();
+  while (! flip_to_1_to_continue) // Wait for debugger to attach
+sleep(1);
+  // dlopen the feature
+  void *feature = dlopen("libfeature.so", RTLD_NOW);
+  assert(feature && "dlopen failed?");
+  return 0; // break after dlopen
+}
Index: lldb/test/API/functionalities/module_load_attach/feature.c
===
--- /dev/null
+++ lldb/test/API/functionalities/module_load_attach/feature.c
@@ -0,0 +1 @@
+extern void feature() {}
Index: lldb/test/API/functionalities/module_load_attach/TestModuleLoadAttach.py
===
--- /dev/null
+++ lldb/test/API/functionalities/module_load_attach/TestModuleLoadAttach.py
@@ -0,0 +1,37 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def build_launch_and_attach(self):
+self.build()
+# launch
+exe = self.getBuildArtifact("a.out")
+popen = self.spawnSubprocess(exe)
+# attach
+target = self.dbg.CreateTarget(exe)
+self.assertTrue(target, VALID_TARGET)
+listener = lldb.SBListener("my.attach.listener")
+error = lldb.SBError()
+process = target.AttachToProcessWithID(listener, popen.pid, error)
+self.assertTrue(error.Success() and process, PROCESS_IS_VALID)
+return process
+
+@skipIfRemote
+@skipUnlessLinux
+@no_debug_info_test
+def test_x(self):
+process = self.build_launch_and_attach()
+thread = process.GetSelectedThread()
+thread.GetSelectedFrame().EvaluateExpression("flip_to_1_to_continue = 1")
+# Continue so that dlopen is called.
+breakpoint = self.target().BreakpointCreateBySourceRegex(
+"// break after dlopen", lldb.SBFileSpec("main.c"))
+self.assertNotEqual(breakpoint.GetNumResolvedLocations(), 0)
+stopped_threads = lldbutil.continue_to_breakpoint(self.process(), breakpoint)
+feature_module = self.dbg.GetSelectedTarget().FindModule(lldb.SBFileSpec("libfeature.so"))
+self.assertTrue(feature_module.IsValid())
Index: lldb/test/API/functionalities/module_load_attach/Makefile
===
--- /dev/null
+++ lldb/test/API/functionalities/module_load_attach/Makefile
@@ -0,0 +1,10 @@
+C_SOURCES := main.c
+LD_EXTRAS := -Wl,-rpath "-Wl,$(shell pwd)"
+USE_LIBDL := 1
+
+feature:
+	$(MAKE) -f $(MAKEFILE_RULES) \
+		DYLIB_ONLY=YES DYLIB_NAME=feature DYLIB_C_SOURCES=feature.c
+all: feature
+
+include Makefile.rules
Index: lldb/packages/Python/lldbsuite/test/decorators.py
===
--- lldb/packages/Python/lldbsuite/test/decorators.py
+++ lldb/packages/Python/lldbsuite/test/decorators.py
@@ -622,6 +622,10 @@
 """Decorate the item to skip tests that should be skipped on any non Darwin platform."""
 return skipUnlessPlatform(lldbplatformutil.getDarwinOSTriples())(func)
 
+def skipUnlessLinux(func):
+"""Decorate the item to skip tests that should be skipped on any non-Linux platfo

[Lldb-commits] [PATCH] D96680: [lldb-vscode] Emit the breakpoint changed event on location resolved

2021-02-18 Thread António Afonso via Phabricator via lldb-commits
aadsm updated this revision to Diff 324865.
aadsm added a comment.

revert last amend: added the test to the wrong diff


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96680

Files:
  lldb/tools/lldb-vscode/lldb-vscode.cpp


Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -417,7 +417,8 @@
   // of wether the locations were added or removed, the breakpoint
   // ins't going away, so we the reason is always "changed".
   if ((event_type & lldb::eBreakpointEventTypeLocationsAdded ||
-   event_type & lldb::eBreakpointEventTypeLocationsRemoved) &&
+   event_type & lldb::eBreakpointEventTypeLocationsRemoved ||
+   event_type & lldb::eBreakpointEventTypeLocationsResolved) &&
   bp.MatchesName(BreakpointBase::GetBreakpointLabel())) {
 auto bp_event = CreateEventObject("breakpoint");
 llvm::json::Object body;


Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -417,7 +417,8 @@
   // of wether the locations were added or removed, the breakpoint
   // ins't going away, so we the reason is always "changed".
   if ((event_type & lldb::eBreakpointEventTypeLocationsAdded ||
-   event_type & lldb::eBreakpointEventTypeLocationsRemoved) &&
+   event_type & lldb::eBreakpointEventTypeLocationsRemoved ||
+   event_type & lldb::eBreakpointEventTypeLocationsResolved) &&
   bp.MatchesName(BreakpointBase::GetBreakpointLabel())) {
 auto bp_event = CreateEventObject("breakpoint");
 llvm::json::Object body;
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D96637: Make sure the interpreter module was loaded before making checks against it

2021-02-18 Thread António Afonso via Phabricator via lldb-commits
aadsm updated this revision to Diff 324866.
aadsm added a comment.

Add api test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96637

Files:
  lldb/packages/Python/lldbsuite/test/decorators.py
  lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
  lldb/test/API/functionalities/module_load_attach/Makefile
  lldb/test/API/functionalities/module_load_attach/TestModuleLoadAttach.py
  lldb/test/API/functionalities/module_load_attach/feature.c
  lldb/test/API/functionalities/module_load_attach/main.c

Index: lldb/test/API/functionalities/module_load_attach/main.c
===
--- /dev/null
+++ lldb/test/API/functionalities/module_load_attach/main.c
@@ -0,0 +1,15 @@
+#include 
+#include 
+#include 
+
+volatile int flip_to_1_to_continue = 0;
+
+int main() {
+  lldb_enable_attach();
+  while (! flip_to_1_to_continue) // Wait for debugger to attach
+sleep(1);
+  // dlopen the feature
+  void *feature = dlopen("libfeature.so", RTLD_NOW);
+  assert(feature && "dlopen failed?");
+  return 0; // break after dlopen
+}
Index: lldb/test/API/functionalities/module_load_attach/feature.c
===
--- /dev/null
+++ lldb/test/API/functionalities/module_load_attach/feature.c
@@ -0,0 +1 @@
+extern void feature() {}
Index: lldb/test/API/functionalities/module_load_attach/TestModuleLoadAttach.py
===
--- /dev/null
+++ lldb/test/API/functionalities/module_load_attach/TestModuleLoadAttach.py
@@ -0,0 +1,37 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def build_launch_and_attach(self):
+self.build()
+# launch
+exe = self.getBuildArtifact("a.out")
+popen = self.spawnSubprocess(exe)
+# attach
+target = self.dbg.CreateTarget(exe)
+self.assertTrue(target, VALID_TARGET)
+listener = lldb.SBListener("my.attach.listener")
+error = lldb.SBError()
+process = target.AttachToProcessWithID(listener, popen.pid, error)
+self.assertTrue(error.Success() and process, PROCESS_IS_VALID)
+return process
+
+@skipIfRemote
+@skipUnlessLinux
+@no_debug_info_test
+def test_x(self):
+process = self.build_launch_and_attach()
+thread = process.GetSelectedThread()
+thread.GetSelectedFrame().EvaluateExpression("flip_to_1_to_continue = 1")
+# Continue so that dlopen is called.
+breakpoint = self.target().BreakpointCreateBySourceRegex(
+"// break after dlopen", lldb.SBFileSpec("main.c"))
+self.assertNotEqual(breakpoint.GetNumResolvedLocations(), 0)
+stopped_threads = lldbutil.continue_to_breakpoint(self.process(), breakpoint)
+feature_module = self.dbg.GetSelectedTarget().FindModule(lldb.SBFileSpec("libfeature.so"))
+self.assertTrue(feature_module.IsValid())
Index: lldb/test/API/functionalities/module_load_attach/Makefile
===
--- /dev/null
+++ lldb/test/API/functionalities/module_load_attach/Makefile
@@ -0,0 +1,10 @@
+C_SOURCES := main.c
+LD_EXTRAS := -Wl,-rpath "-Wl,$(shell pwd)"
+USE_LIBDL := 1
+
+feature:
+	$(MAKE) -f $(MAKEFILE_RULES) \
+		DYLIB_ONLY=YES DYLIB_NAME=feature DYLIB_C_SOURCES=feature.c
+all: feature
+
+include Makefile.rules
Index: lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
===
--- lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
+++ lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
@@ -441,6 +441,7 @@
   if (module_sp.get()) {
 if (module_sp->GetObjectFile()->GetBaseAddress().GetLoadAddress(
 &m_process->GetTarget()) == m_interpreter_base &&
+m_interpreter_module.lock() &&
 module_sp != m_interpreter_module.lock()) {
   // If this is a duplicate instance of ld.so, unload it.  We may end up
   // with it if we load it via a different path than before (symlink
Index: lldb/packages/Python/lldbsuite/test/decorators.py
===
--- lldb/packages/Python/lldbsuite/test/decorators.py
+++ lldb/packages/Python/lldbsuite/test/decorators.py
@@ -622,6 +622,10 @@
 """Decorate the item to skip tests that should be skipped on any non Darwin platform."""
 return skipUnlessPlatform(lldbplatformutil.getDarwinOSTriples())(func)
 
+def skipUnlessLinux(func):
+"""Decorate the item to skip tests that should be skipped on any non-Linux platform."""
+return skipUnlessPlatform(["linux"])(func)

[Lldb-commits] [PATCH] D96637: Make sure the interpreter module was loaded before making checks against it

2021-02-18 Thread António Afonso via Phabricator via lldb-commits
aadsm added a comment.

> I don't think this does what you think it does. The $() doesn't give you the 
> process id of anything -- it substitutes a string by the result of running 
> that string as a shell command. So, the PID variable would get the (entire) 
> stdout of %s.out

I'm confused here, "the PID variable would get the (entire) stdout of %s.out" 
is exactly what I'm expecting to happen, the stdout of the program is its pid.

I was finally able to figure out what the issue was. I thought `pause()` would 
continue once the debugger attached because it sends a signal, but that doesn't 
seem to be the case?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96637

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


[Lldb-commits] [PATCH] D96680: [lldb-vscode] Emit the breakpoint changed event on location resolved

2021-02-19 Thread António Afonso via Phabricator via lldb-commits
aadsm updated this revision to Diff 325117.
aadsm added a comment.

Add test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96680

Files:
  lldb/test/API/tools/lldb-vscode/breakpoint-events/Makefile
  
lldb/test/API/tools/lldb-vscode/breakpoint-events/TestVSCode_breakpointLocationResolvedEvent.py
  lldb/test/API/tools/lldb-vscode/breakpoint-events/dylib.c
  lldb/test/API/tools/lldb-vscode/breakpoint-events/dylib_loader.c
  lldb/tools/lldb-vscode/lldb-vscode.cpp

Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -417,7 +417,8 @@
   // of wether the locations were added or removed, the breakpoint
   // ins't going away, so we the reason is always "changed".
   if ((event_type & lldb::eBreakpointEventTypeLocationsAdded ||
-   event_type & lldb::eBreakpointEventTypeLocationsRemoved) &&
+   event_type & lldb::eBreakpointEventTypeLocationsRemoved ||
+   event_type & lldb::eBreakpointEventTypeLocationsResolved) &&
   bp.MatchesName(BreakpointBase::GetBreakpointLabel())) {
 auto bp_event = CreateEventObject("breakpoint");
 llvm::json::Object body;
Index: lldb/test/API/tools/lldb-vscode/breakpoint-events/dylib_loader.c
===
--- /dev/null
+++ lldb/test/API/tools/lldb-vscode/breakpoint-events/dylib_loader.c
@@ -0,0 +1,15 @@
+#include 
+#include 
+#include 
+
+volatile int flip_to_1_to_continue = 0;
+
+int main() {
+  lldb_enable_attach();
+  while (! flip_to_1_to_continue) // Wait for debugger to attach
+sleep(1);
+  // dlopen the feature
+  void *dylib = dlopen("libdylib.so", RTLD_LAZY);
+  assert(dylib && "dlopen failed?");
+  return 0; // break after dlopen
+}
Index: lldb/test/API/tools/lldb-vscode/breakpoint-events/dylib.c
===
--- /dev/null
+++ lldb/test/API/tools/lldb-vscode/breakpoint-events/dylib.c
@@ -0,0 +1,3 @@
+extern void foo() {
+// breakpoint dylib
+}
Index: lldb/test/API/tools/lldb-vscode/breakpoint-events/TestVSCode_breakpointLocationResolvedEvent.py
===
--- /dev/null
+++ lldb/test/API/tools/lldb-vscode/breakpoint-events/TestVSCode_breakpointLocationResolvedEvent.py
@@ -0,0 +1,71 @@
+"""
+Test lldb-vscode setBreakpoints request
+"""
+
+
+import unittest2
+import vscode
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+import lldbvscode_testcase
+import os
+
+
+class TestVSCode_breakpointLocationResolvedEvent(lldbvscode_testcase.VSCodeTestCaseBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def build_launch_and_attach(self):
+self.build_and_create_debug_adaptor()
+# launch externally
+exe = self.getBuildArtifact("dylib_loader")
+popen = self.spawnSubprocess(exe)
+# attach
+self.attach(exe, popen.pid)
+
+def set_breakpoint(self, filename, comment):
+source_basename = filename
+source_path = os.path.join(os.getcwd(), source_basename)
+bp_line = line_number(filename, comment)
+return self.vscode.request_setBreakpoints(source_path,
+  [bp_line])
+
+@skipUnlessPlatform(["linux"])
+def test_breakpoint_location_resolved_event(self):
+'''
+This test sets a breakpoint in a shared library before it's loaded.
+This will make the client receive a breakpoint notification of
+unresolved location. Once the library is loaded the client should
+receive another change event indicating the location is resolved.
+'''
+self.build_launch_and_attach()
+self.set_breakpoint('dylib_loader.c', 'break after dlopen')
+response = self.set_breakpoint('dylib.c', 'breakpoint dylib')
+if response:
+breakpoints = response['body']['breakpoints']
+for breakpoint in breakpoints:
+bp_id = breakpoint['id']
+self.assertFalse(breakpoint['verified'],
+"expect dylib breakpoint to be unverified")
+break
+response = self.vscode.request_evaluate("flip_to_1_to_continue = 1")
+self.assertTrue(response['success'])
+
+self.continue_to_next_stop()
+self.assertTrue(len(self.vscode.breakpoint_events) > 1,
+"make sure we got a breakpoint event")
+
+# find the last breakpoint event for bp_id
+for event in reversed(self.vscode.breakpoint_events):
+if event['body']['breakpoint']['id'] == bp_id:
+break
+body = eve

[Lldb-commits] [PATCH] D96680: [lldb-vscode] Emit the breakpoint changed event on location resolved

2021-02-19 Thread António Afonso via Phabricator via lldb-commits
aadsm updated this revision to Diff 325118.
aadsm added a comment.

Removed unnecessary comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96680

Files:
  lldb/test/API/tools/lldb-vscode/breakpoint-events/Makefile
  
lldb/test/API/tools/lldb-vscode/breakpoint-events/TestVSCode_breakpointLocationResolvedEvent.py
  lldb/test/API/tools/lldb-vscode/breakpoint-events/dylib.c
  lldb/test/API/tools/lldb-vscode/breakpoint-events/dylib_loader.c
  lldb/tools/lldb-vscode/lldb-vscode.cpp

Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -417,7 +417,8 @@
   // of wether the locations were added or removed, the breakpoint
   // ins't going away, so we the reason is always "changed".
   if ((event_type & lldb::eBreakpointEventTypeLocationsAdded ||
-   event_type & lldb::eBreakpointEventTypeLocationsRemoved) &&
+   event_type & lldb::eBreakpointEventTypeLocationsRemoved ||
+   event_type & lldb::eBreakpointEventTypeLocationsResolved) &&
   bp.MatchesName(BreakpointBase::GetBreakpointLabel())) {
 auto bp_event = CreateEventObject("breakpoint");
 llvm::json::Object body;
Index: lldb/test/API/tools/lldb-vscode/breakpoint-events/dylib_loader.c
===
--- /dev/null
+++ lldb/test/API/tools/lldb-vscode/breakpoint-events/dylib_loader.c
@@ -0,0 +1,14 @@
+#include 
+#include 
+#include 
+
+volatile int flip_to_1_to_continue = 0;
+
+int main() {
+  lldb_enable_attach();
+  while (! flip_to_1_to_continue) // Wait for debugger to attach
+sleep(1);
+  void *dylib = dlopen("libdylib.so", RTLD_LAZY);
+  assert(dylib && "dlopen failed?");
+  return 0; // break after dlopen
+}
Index: lldb/test/API/tools/lldb-vscode/breakpoint-events/dylib.c
===
--- /dev/null
+++ lldb/test/API/tools/lldb-vscode/breakpoint-events/dylib.c
@@ -0,0 +1,3 @@
+extern void foo() {
+// breakpoint dylib
+}
Index: lldb/test/API/tools/lldb-vscode/breakpoint-events/TestVSCode_breakpointLocationResolvedEvent.py
===
--- /dev/null
+++ lldb/test/API/tools/lldb-vscode/breakpoint-events/TestVSCode_breakpointLocationResolvedEvent.py
@@ -0,0 +1,71 @@
+"""
+Test lldb-vscode setBreakpoints request
+"""
+
+
+import unittest2
+import vscode
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+import lldbvscode_testcase
+import os
+
+
+class TestVSCode_breakpointLocationResolvedEvent(lldbvscode_testcase.VSCodeTestCaseBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def build_launch_and_attach(self):
+self.build_and_create_debug_adaptor()
+# launch externally
+exe = self.getBuildArtifact("dylib_loader")
+popen = self.spawnSubprocess(exe)
+# attach
+self.attach(exe, popen.pid)
+
+def set_breakpoint(self, filename, comment):
+source_basename = filename
+source_path = os.path.join(os.getcwd(), source_basename)
+bp_line = line_number(filename, comment)
+return self.vscode.request_setBreakpoints(source_path,
+  [bp_line])
+
+@skipUnlessPlatform(["linux"])
+def test_breakpoint_location_resolved_event(self):
+'''
+This test sets a breakpoint in a shared library before it's loaded.
+This will make the client receive a breakpoint notification of
+unresolved location. Once the library is loaded the client should
+receive another change event indicating the location is resolved.
+'''
+self.build_launch_and_attach()
+self.set_breakpoint('dylib_loader.c', 'break after dlopen')
+response = self.set_breakpoint('dylib.c', 'breakpoint dylib')
+if response:
+breakpoints = response['body']['breakpoints']
+for breakpoint in breakpoints:
+bp_id = breakpoint['id']
+self.assertFalse(breakpoint['verified'],
+"expect dylib breakpoint to be unverified")
+break
+response = self.vscode.request_evaluate("flip_to_1_to_continue = 1")
+self.assertTrue(response['success'])
+
+self.continue_to_next_stop()
+self.assertTrue(len(self.vscode.breakpoint_events) > 1,
+"make sure we got a breakpoint event")
+
+# find the last breakpoint event for bp_id
+for event in reversed(self.vscode.breakpoint_events):
+if event['body']['breakpoint']['id'] == bp_id:
+break
+body = event['bo

[Lldb-commits] [PATCH] D96637: Make sure the interpreter module was loaded before making checks against it

2021-02-20 Thread António Afonso via Phabricator via lldb-commits
aadsm added inline comments.



Comment at: 
lldb/test/API/functionalities/module_load_attach/TestModuleLoadAttach.py:28
+def test_x(self):
+process = self.build_launch_and_attach()
+thread = process.GetSelectedThread()

clayborg wrote:
> Is this racy? What happens on a really slow system? Can we fail to attach? If 
> we do attach, are we guaranteed to be at a place where we can set 
> "flip_to_1_to_continue = 1"? The nice thing is it is a global variable that 
> we should be able to set no matter where we stop. 
> Is this racy?

I don't think so because we already have a pid at that point in time, so we 
should always be able to attach.

> If we do attach, are we guaranteed to be at a place where we can set 
> "flip_to_1_to_continue = 1"?

yeah, that's exactly why I made it global. I could also wait until there's a 
`flip_to_1_to_continue` in the scope if you think it's worthwhile.



Comment at: 
lldb/test/API/functionalities/module_load_attach/TestModuleLoadAttach.py:32-33
+# Continue so that dlopen is called.
+breakpoint = self.target().BreakpointCreateBySourceRegex(
+"// break after dlopen", lldb.SBFileSpec("main.c"))
+self.assertNotEqual(breakpoint.GetNumResolvedLocations(), 0)

clayborg wrote:
> Don't we need to break before the dlopen and make sure we don't have a 
> libfeature.so in our module list, then run over the dlopen and verify we do 
> see it afterwards? Wasn't this bug that we will see shared libraries 
> correctly one time when we attach, but just not get any updates after this??
that was a completely different bug and I have a different test for that 
situation as well.
Something that I could test though, is that before we got an update for an 
unresolved breakpoint to make sure we did indeed transitioned from unresolved 
-> resolved.

I'll add that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96637

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


[Lldb-commits] [PATCH] D96637: Make sure the interpreter module was loaded before making checks against it

2021-02-20 Thread António Afonso via Phabricator via lldb-commits
aadsm added inline comments.



Comment at: 
lldb/test/API/functionalities/module_load_attach/TestModuleLoadAttach.py:32-33
+# Continue so that dlopen is called.
+breakpoint = self.target().BreakpointCreateBySourceRegex(
+"// break after dlopen", lldb.SBFileSpec("main.c"))
+self.assertNotEqual(breakpoint.GetNumResolvedLocations(), 0)

aadsm wrote:
> clayborg wrote:
> > Don't we need to break before the dlopen and make sure we don't have a 
> > libfeature.so in our module list, then run over the dlopen and verify we do 
> > see it afterwards? Wasn't this bug that we will see shared libraries 
> > correctly one time when we attach, but just not get any updates after this??
> that was a completely different bug and I have a different test for that 
> situation as well.
> Something that I could test though, is that before we got an update for an 
> unresolved breakpoint to make sure we did indeed transitioned from unresolved 
> -> resolved.
> 
> I'll add that.
Forget this, I shouldn't be answering comments in the morning.

> that was a completely different bug and I have a different test for that 
> situation as well.
> Something that I could test though, is that before we got an update for an 
> unresolved breakpoint to make sure we did indeed transitioned from unresolved 
> -> resolved.
> 
> I'll add that.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96637

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


[Lldb-commits] [PATCH] D96637: Make sure the interpreter module was loaded before making checks against it

2021-02-20 Thread António Afonso via Phabricator via lldb-commits
aadsm updated this revision to Diff 325221.
aadsm added a comment.

Checks the module is not loaded right after we attach


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96637

Files:
  lldb/packages/Python/lldbsuite/test/decorators.py
  lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
  lldb/test/API/functionalities/module_load_attach/Makefile
  lldb/test/API/functionalities/module_load_attach/TestModuleLoadAttach.py
  lldb/test/API/functionalities/module_load_attach/feature.c
  lldb/test/API/functionalities/module_load_attach/main.c

Index: lldb/test/API/functionalities/module_load_attach/main.c
===
--- /dev/null
+++ lldb/test/API/functionalities/module_load_attach/main.c
@@ -0,0 +1,15 @@
+#include 
+#include 
+#include 
+
+volatile int flip_to_1_to_continue = 0;
+
+int main() {
+  lldb_enable_attach();
+  while (! flip_to_1_to_continue) // Wait for debugger to attach
+sleep(1);
+  // dlopen the feature
+  void *feature = dlopen("libfeature.so", RTLD_NOW);
+  assert(feature && "dlopen failed?");
+  return 0; // break after dlopen
+}
Index: lldb/test/API/functionalities/module_load_attach/feature.c
===
--- /dev/null
+++ lldb/test/API/functionalities/module_load_attach/feature.c
@@ -0,0 +1 @@
+extern void feature() {}
Index: lldb/test/API/functionalities/module_load_attach/TestModuleLoadAttach.py
===
--- /dev/null
+++ lldb/test/API/functionalities/module_load_attach/TestModuleLoadAttach.py
@@ -0,0 +1,49 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def build_launch_and_attach(self):
+self.build()
+# launch
+exe = self.getBuildArtifact("a.out")
+popen = self.spawnSubprocess(exe)
+# attach
+target = self.dbg.CreateTarget(exe)
+self.assertTrue(target, VALID_TARGET)
+listener = lldb.SBListener("my.attach.listener")
+error = lldb.SBError()
+process = target.AttachToProcessWithID(listener, popen.pid, error)
+self.assertTrue(error.Success() and process, PROCESS_IS_VALID)
+return process
+
+def assertModuleIsLoaded(self, module_name):
+feature_module = self.dbg.GetSelectedTarget().FindModule(lldb.SBFileSpec(module_name))
+self.assertTrue(feature_module.IsValid(), f"Module {module_name} should be loaded")
+
+def assertModuleIsNotLoaded(self, module_name):
+feature_module = self.dbg.GetSelectedTarget().FindModule(lldb.SBFileSpec(module_name))
+self.assertFalse(feature_module.IsValid(), f"Module {module_name} should not be loaded")
+
+@skipIfRemote
+@skipUnlessLinux
+@no_debug_info_test
+def test(self):
+'''
+This test makes sure that after attach lldb still gets notifications
+about new modules being loaded by the process
+'''
+process = self.build_launch_and_attach()
+thread = process.GetSelectedThread()
+self.assertModuleIsNotLoaded("libfeature.so")
+thread.GetSelectedFrame().EvaluateExpression("flip_to_1_to_continue = 1")
+# Continue so that dlopen is called.
+breakpoint = self.target().BreakpointCreateBySourceRegex(
+"// break after dlopen", lldb.SBFileSpec("main.c"))
+self.assertNotEqual(breakpoint.GetNumResolvedLocations(), 0)
+stopped_threads = lldbutil.continue_to_breakpoint(self.process(), breakpoint)
+self.assertModuleIsLoaded("libfeature.so")
Index: lldb/test/API/functionalities/module_load_attach/Makefile
===
--- /dev/null
+++ lldb/test/API/functionalities/module_load_attach/Makefile
@@ -0,0 +1,10 @@
+C_SOURCES := main.c
+LD_EXTRAS := -Wl,-rpath "-Wl,$(shell pwd)"
+USE_LIBDL := 1
+
+feature:
+	$(MAKE) -f $(MAKEFILE_RULES) \
+		DYLIB_ONLY=YES DYLIB_NAME=feature DYLIB_C_SOURCES=feature.c
+all: feature
+
+include Makefile.rules
Index: lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
===
--- lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
+++ lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
@@ -441,6 +441,7 @@
   if (module_sp.get()) {
 if (module_sp->GetObjectFile()->GetBaseAddress().GetLoadAddress(
 &m_process->GetTarget()) == m_interpreter_base &&
+m_interpreter_module.lock() &&
 module_sp != m_interpreter_module.lock()) {
   // If this is a duplicate instance of ld.so, unload it.  We may end up
   // with i

[Lldb-commits] [PATCH] D96637: Make sure the interpreter module was loaded before making checks against it

2021-02-21 Thread António Afonso via Phabricator via lldb-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa83a825e9902: Make sure the interpreter module was loaded 
before making checks against it (authored by aadsm).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96637

Files:
  lldb/packages/Python/lldbsuite/test/decorators.py
  lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
  lldb/test/API/functionalities/module_load_attach/Makefile
  lldb/test/API/functionalities/module_load_attach/TestModuleLoadAttach.py
  lldb/test/API/functionalities/module_load_attach/feature.c
  lldb/test/API/functionalities/module_load_attach/main.c

Index: lldb/test/API/functionalities/module_load_attach/main.c
===
--- /dev/null
+++ lldb/test/API/functionalities/module_load_attach/main.c
@@ -0,0 +1,15 @@
+#include 
+#include 
+#include 
+
+volatile int flip_to_1_to_continue = 0;
+
+int main() {
+  lldb_enable_attach();
+  while (! flip_to_1_to_continue) // Wait for debugger to attach
+sleep(1);
+  // dlopen the feature
+  void *feature = dlopen("libfeature.so", RTLD_NOW);
+  assert(feature && "dlopen failed?");
+  return 0; // break after dlopen
+}
Index: lldb/test/API/functionalities/module_load_attach/feature.c
===
--- /dev/null
+++ lldb/test/API/functionalities/module_load_attach/feature.c
@@ -0,0 +1 @@
+extern void feature() {}
Index: lldb/test/API/functionalities/module_load_attach/TestModuleLoadAttach.py
===
--- /dev/null
+++ lldb/test/API/functionalities/module_load_attach/TestModuleLoadAttach.py
@@ -0,0 +1,49 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def build_launch_and_attach(self):
+self.build()
+# launch
+exe = self.getBuildArtifact("a.out")
+popen = self.spawnSubprocess(exe)
+# attach
+target = self.dbg.CreateTarget(exe)
+self.assertTrue(target, VALID_TARGET)
+listener = lldb.SBListener("my.attach.listener")
+error = lldb.SBError()
+process = target.AttachToProcessWithID(listener, popen.pid, error)
+self.assertTrue(error.Success() and process, PROCESS_IS_VALID)
+return process
+
+def assertModuleIsLoaded(self, module_name):
+feature_module = self.dbg.GetSelectedTarget().FindModule(lldb.SBFileSpec(module_name))
+self.assertTrue(feature_module.IsValid(), f"Module {module_name} should be loaded")
+
+def assertModuleIsNotLoaded(self, module_name):
+feature_module = self.dbg.GetSelectedTarget().FindModule(lldb.SBFileSpec(module_name))
+self.assertFalse(feature_module.IsValid(), f"Module {module_name} should not be loaded")
+
+@skipIfRemote
+@skipUnlessLinux
+@no_debug_info_test
+def test(self):
+'''
+This test makes sure that after attach lldb still gets notifications
+about new modules being loaded by the process
+'''
+process = self.build_launch_and_attach()
+thread = process.GetSelectedThread()
+self.assertModuleIsNotLoaded("libfeature.so")
+thread.GetSelectedFrame().EvaluateExpression("flip_to_1_to_continue = 1")
+# Continue so that dlopen is called.
+breakpoint = self.target().BreakpointCreateBySourceRegex(
+"// break after dlopen", lldb.SBFileSpec("main.c"))
+self.assertNotEqual(breakpoint.GetNumResolvedLocations(), 0)
+stopped_threads = lldbutil.continue_to_breakpoint(self.process(), breakpoint)
+self.assertModuleIsLoaded("libfeature.so")
Index: lldb/test/API/functionalities/module_load_attach/Makefile
===
--- /dev/null
+++ lldb/test/API/functionalities/module_load_attach/Makefile
@@ -0,0 +1,10 @@
+C_SOURCES := main.c
+LD_EXTRAS := -Wl,-rpath "-Wl,$(shell pwd)"
+USE_LIBDL := 1
+
+feature:
+	$(MAKE) -f $(MAKEFILE_RULES) \
+		DYLIB_ONLY=YES DYLIB_NAME=feature DYLIB_C_SOURCES=feature.c
+all: feature
+
+include Makefile.rules
Index: lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
===
--- lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
+++ lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
@@ -441,6 +441,7 @@
   if (module_sp.get()) {
 if (module_sp->GetObjectFile()->GetBaseAddress().GetLoadAddress(
 &m_process->GetTarget()) == m_in

[Lldb-commits] [PATCH] D96637: Make sure the interpreter module was loaded before making checks against it

2021-02-21 Thread António Afonso via Phabricator via lldb-commits
aadsm added a comment.

oh no, I picked the wrong commit to land :(. I think this is fine because I 
already addressed the comments, but if there's still something I should work on 
here, I'll put another diff up.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96637

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


[Lldb-commits] [PATCH] D96680: [lldb-vscode] Emit the breakpoint changed event on location resolved

2021-02-21 Thread António Afonso 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 rG1f21d488bd79: [lldb-vscode] Emit the breakpoint changed 
event on location resolved (authored by aadsm).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96680

Files:
  lldb/test/API/tools/lldb-vscode/breakpoint-events/Makefile
  
lldb/test/API/tools/lldb-vscode/breakpoint-events/TestVSCode_breakpointLocationResolvedEvent.py
  lldb/test/API/tools/lldb-vscode/breakpoint-events/dylib.c
  lldb/test/API/tools/lldb-vscode/breakpoint-events/dylib_loader.c
  lldb/tools/lldb-vscode/lldb-vscode.cpp

Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -417,7 +417,8 @@
   // of wether the locations were added or removed, the breakpoint
   // ins't going away, so we the reason is always "changed".
   if ((event_type & lldb::eBreakpointEventTypeLocationsAdded ||
-   event_type & lldb::eBreakpointEventTypeLocationsRemoved) &&
+   event_type & lldb::eBreakpointEventTypeLocationsRemoved ||
+   event_type & lldb::eBreakpointEventTypeLocationsResolved) &&
   bp.MatchesName(BreakpointBase::GetBreakpointLabel())) {
 auto bp_event = CreateEventObject("breakpoint");
 llvm::json::Object body;
Index: lldb/test/API/tools/lldb-vscode/breakpoint-events/dylib_loader.c
===
--- /dev/null
+++ lldb/test/API/tools/lldb-vscode/breakpoint-events/dylib_loader.c
@@ -0,0 +1,14 @@
+#include 
+#include 
+#include 
+
+volatile int flip_to_1_to_continue = 0;
+
+int main() {
+  lldb_enable_attach();
+  while (! flip_to_1_to_continue) // Wait for debugger to attach
+sleep(1);
+  void *dylib = dlopen("libdylib.so", RTLD_LAZY);
+  assert(dylib && "dlopen failed?");
+  return 0; // break after dlopen
+}
Index: lldb/test/API/tools/lldb-vscode/breakpoint-events/dylib.c
===
--- /dev/null
+++ lldb/test/API/tools/lldb-vscode/breakpoint-events/dylib.c
@@ -0,0 +1,3 @@
+extern void foo() {
+// breakpoint dylib
+}
Index: lldb/test/API/tools/lldb-vscode/breakpoint-events/TestVSCode_breakpointLocationResolvedEvent.py
===
--- /dev/null
+++ lldb/test/API/tools/lldb-vscode/breakpoint-events/TestVSCode_breakpointLocationResolvedEvent.py
@@ -0,0 +1,71 @@
+"""
+Test lldb-vscode setBreakpoints request
+"""
+
+
+import unittest2
+import vscode
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+import lldbvscode_testcase
+import os
+
+
+class TestVSCode_breakpointLocationResolvedEvent(lldbvscode_testcase.VSCodeTestCaseBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def build_launch_and_attach(self):
+self.build_and_create_debug_adaptor()
+# launch externally
+exe = self.getBuildArtifact("dylib_loader")
+popen = self.spawnSubprocess(exe)
+# attach
+self.attach(exe, popen.pid)
+
+def set_breakpoint(self, filename, comment):
+source_basename = filename
+source_path = os.path.join(os.getcwd(), source_basename)
+bp_line = line_number(filename, comment)
+return self.vscode.request_setBreakpoints(source_path,
+  [bp_line])
+
+@skipUnlessPlatform(["linux"])
+def test_breakpoint_location_resolved_event(self):
+'''
+This test sets a breakpoint in a shared library before it's loaded.
+This will make the client receive a breakpoint notification of
+unresolved location. Once the library is loaded the client should
+receive another change event indicating the location is resolved.
+'''
+self.build_launch_and_attach()
+self.set_breakpoint('dylib_loader.c', 'break after dlopen')
+response = self.set_breakpoint('dylib.c', 'breakpoint dylib')
+if response:
+breakpoints = response['body']['breakpoints']
+for breakpoint in breakpoints:
+bp_id = breakpoint['id']
+self.assertFalse(breakpoint['verified'],
+"expect dylib breakpoint to be unverified")
+break
+response = self.vscode.request_evaluate("flip_to_1_to_continue = 1")
+self.assertTrue(response['success'])
+
+self.continue_to_next_stop()
+self.assertTrue(len(self.vscode.breakpoint_events) > 1,
+"make sure we got a breakpoint event")
+
+# find the last breakpoint event for bp_id
+for e

[Lldb-commits] [PATCH] D86235: Fix swig scripts install target name

2020-08-19 Thread António Afonso via Phabricator via lldb-commits
aadsm created this revision.
aadsm added reviewers: JDevlieghere, wallace, clayborg.
Herald added subscribers: lldb-commits, mgorny.
Herald added a project: LLDB.
aadsm requested review of this revision.

LLVM install component targets needs to be in the form of: 
install-{target}[-stripped]

I tested with:

  cmake ... -DLLVM_ENABLE_PROJECTS="clang;lldb" 
-DLLVM_DISTRIBUTION_COMPONENTS="lldb;liblldb;finish_swig_python_scripts" ...
  DESTDIR=... ninja install-distribution

@JDevlieghere `finish_swig_python_scripts` is a really weird name for a 
distribution component, any reason that it has to be this way?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86235

Files:
  lldb/bindings/python/CMakeLists.txt


Index: lldb/bindings/python/CMakeLists.txt
===
--- lldb/bindings/python/CMakeLists.txt
+++ lldb/bindings/python/CMakeLists.txt
@@ -164,7 +164,7 @@
 string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" 
lldb_python_target_dir ${lldb_python_target_dir})
   endif()
   set(swig_scripts_target "${swig_target}_scripts")
-  set(swig_scripts_install_target "${swig_target}_scripts_install")
+  set(swig_scripts_install_target "install-${swig_scripts_target}")
   add_custom_target(${swig_scripts_target})
   add_dependencies(${swig_scripts_target} ${swig_target})
   install(DIRECTORY ${lldb_python_target_dir}/../


Index: lldb/bindings/python/CMakeLists.txt
===
--- lldb/bindings/python/CMakeLists.txt
+++ lldb/bindings/python/CMakeLists.txt
@@ -164,7 +164,7 @@
 string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" lldb_python_target_dir ${lldb_python_target_dir})
   endif()
   set(swig_scripts_target "${swig_target}_scripts")
-  set(swig_scripts_install_target "${swig_target}_scripts_install")
+  set(swig_scripts_install_target "install-${swig_scripts_target}")
   add_custom_target(${swig_scripts_target})
   add_dependencies(${swig_scripts_target} ${swig_target})
   install(DIRECTORY ${lldb_python_target_dir}/../
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D86235: Fix swig scripts install target name

2020-08-19 Thread António Afonso via Phabricator via lldb-commits
aadsm added a comment.

@JDevlieghere thanks for the quick review, but on the name I mean the actual 
`finish_swig_python_scripts`, this sounds like a step name and not a component 
distributed by llvm like `liblldb` ot `lldb-server`. That was the reason at the 
time I named it `lldb-python-scripts` because it was very clear what was being 
installed.
Would you be fine with me changing `swig_scripts_target` back to 
`lldb-python-scripts`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86235

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


[Lldb-commits] [PATCH] D77480: Fix illegal early call to PyBuffer_Release in swig typemaps

2020-08-21 Thread António Afonso via Phabricator via lldb-commits
aadsm added inline comments.



Comment at: lldb/bindings/python/python-typemaps.swig:500
+  }
+};
+

labath wrote:
> Could you also `= delete` the copy operations to make sure nothing funny 
> happens with those.
The `= delete` is unsupported in SWIG 2, only in 3: 
http://www.swig.org/Doc3.0/CPlusPlus11.html#CPlusPlus11_defaulted_deleted
Do we really need it, or is there a workaround it, or should we just bump the 
minimum requirements to SWIG 3?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77480

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


[Lldb-commits] [PATCH] D77480: Fix illegal early call to PyBuffer_Release in swig typemaps

2020-08-21 Thread António Afonso via Phabricator via lldb-commits
aadsm added inline comments.



Comment at: lldb/bindings/python/python-typemaps.swig:500
+  }
+};
+

lawrence_danna wrote:
> lawrence_danna wrote:
> > aadsm wrote:
> > > labath wrote:
> > > > Could you also `= delete` the copy operations to make sure nothing 
> > > > funny happens with those.
> > > The `= delete` is unsupported in SWIG 2, only in 3: 
> > > http://www.swig.org/Doc3.0/CPlusPlus11.html#CPlusPlus11_defaulted_deleted
> > > Do we really need it, or is there a workaround it, or should we just bump 
> > > the minimum requirements to SWIG 3?
> > It shouldn't be strictly necessary.  I put it in so if for some reason one 
> > of these values gets copied, it would result in a compiler error instead of 
> > a crash.
> This type could also just be moved into a header so swig doesn't need to 
> parse it.
ah nice, of course, I can do this. thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77480

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


[Lldb-commits] [PATCH] D86235: Fix swig scripts install target name

2020-08-21 Thread António Afonso via Phabricator via lldb-commits
aadsm updated this revision to Diff 287106.
aadsm edited the summary of this revision.
aadsm added a comment.

Updated to use more friendly component name `lldb-python-scripts` name instead 
of `finish_swig_python_scripts`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86235

Files:
  lldb/bindings/python/CMakeLists.txt


Index: lldb/bindings/python/CMakeLists.txt
===
--- lldb/bindings/python/CMakeLists.txt
+++ lldb/bindings/python/CMakeLists.txt
@@ -163,17 +163,17 @@
 string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" 
LLDB_PYTHON_INSTALL_PATH ${LLDB_PYTHON_INSTALL_PATH})
 string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" 
lldb_python_target_dir ${lldb_python_target_dir})
   endif()
-  set(swig_scripts_target "${swig_target}_scripts")
-  set(swig_scripts_install_target "${swig_target}_scripts_install")
-  add_custom_target(${swig_scripts_target})
-  add_dependencies(${swig_scripts_target} ${swig_target})
+  set(python_scripts_target "lldb-python-scripts")
+  set(python_scripts_install_target "install-${python_scripts_target}")
+  add_custom_target(${python_scripts_target})
+  add_dependencies(${python_scripts_target} ${swig_target})
   install(DIRECTORY ${lldb_python_target_dir}/../
   DESTINATION ${LLDB_PYTHON_INSTALL_PATH}
-  COMPONENT ${swig_scripts_target})
+  COMPONENT ${python_scripts_target})
   if (NOT LLVM_ENABLE_IDE)
-add_llvm_install_targets(${swig_scripts_install_target}
- COMPONENT ${swig_scripts_target}
- DEPENDS ${swig_scripts_target})
+add_llvm_install_targets(${python_scripts_install_target}
+ COMPONENT ${python_scripts_target}
+ DEPENDS ${python_scripts_target})
   endif()
 
   # Add a Post-Build Event to copy the custom Python DLL to the lldb binaries 
dir so that Windows can find it when launching


Index: lldb/bindings/python/CMakeLists.txt
===
--- lldb/bindings/python/CMakeLists.txt
+++ lldb/bindings/python/CMakeLists.txt
@@ -163,17 +163,17 @@
 string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" LLDB_PYTHON_INSTALL_PATH ${LLDB_PYTHON_INSTALL_PATH})
 string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" lldb_python_target_dir ${lldb_python_target_dir})
   endif()
-  set(swig_scripts_target "${swig_target}_scripts")
-  set(swig_scripts_install_target "${swig_target}_scripts_install")
-  add_custom_target(${swig_scripts_target})
-  add_dependencies(${swig_scripts_target} ${swig_target})
+  set(python_scripts_target "lldb-python-scripts")
+  set(python_scripts_install_target "install-${python_scripts_target}")
+  add_custom_target(${python_scripts_target})
+  add_dependencies(${python_scripts_target} ${swig_target})
   install(DIRECTORY ${lldb_python_target_dir}/../
   DESTINATION ${LLDB_PYTHON_INSTALL_PATH}
-  COMPONENT ${swig_scripts_target})
+  COMPONENT ${python_scripts_target})
   if (NOT LLVM_ENABLE_IDE)
-add_llvm_install_targets(${swig_scripts_install_target}
- COMPONENT ${swig_scripts_target}
- DEPENDS ${swig_scripts_target})
+add_llvm_install_targets(${python_scripts_install_target}
+ COMPONENT ${python_scripts_target}
+ DEPENDS ${python_scripts_target})
   endif()
 
   # Add a Post-Build Event to copy the custom Python DLL to the lldb binaries dir so that Windows can find it when launching
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D86235: Fix swig scripts install target name

2020-08-21 Thread António Afonso 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 rG02bf5632a94d: Fix swig scripts install target name (authored 
by aadsm).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86235

Files:
  lldb/bindings/python/CMakeLists.txt


Index: lldb/bindings/python/CMakeLists.txt
===
--- lldb/bindings/python/CMakeLists.txt
+++ lldb/bindings/python/CMakeLists.txt
@@ -163,17 +163,17 @@
 string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" 
LLDB_PYTHON_INSTALL_PATH ${LLDB_PYTHON_INSTALL_PATH})
 string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" 
lldb_python_target_dir ${lldb_python_target_dir})
   endif()
-  set(swig_scripts_target "${swig_target}_scripts")
-  set(swig_scripts_install_target "${swig_target}_scripts_install")
-  add_custom_target(${swig_scripts_target})
-  add_dependencies(${swig_scripts_target} ${swig_target})
+  set(python_scripts_target "lldb-python-scripts")
+  set(python_scripts_install_target "install-${python_scripts_target}")
+  add_custom_target(${python_scripts_target})
+  add_dependencies(${python_scripts_target} ${swig_target})
   install(DIRECTORY ${lldb_python_target_dir}/../
   DESTINATION ${LLDB_PYTHON_INSTALL_PATH}
-  COMPONENT ${swig_scripts_target})
+  COMPONENT ${python_scripts_target})
   if (NOT LLVM_ENABLE_IDE)
-add_llvm_install_targets(${swig_scripts_install_target}
- COMPONENT ${swig_scripts_target}
- DEPENDS ${swig_scripts_target})
+add_llvm_install_targets(${python_scripts_install_target}
+ COMPONENT ${python_scripts_target}
+ DEPENDS ${python_scripts_target})
   endif()
 
   # Add a Post-Build Event to copy the custom Python DLL to the lldb binaries 
dir so that Windows can find it when launching


Index: lldb/bindings/python/CMakeLists.txt
===
--- lldb/bindings/python/CMakeLists.txt
+++ lldb/bindings/python/CMakeLists.txt
@@ -163,17 +163,17 @@
 string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" LLDB_PYTHON_INSTALL_PATH ${LLDB_PYTHON_INSTALL_PATH})
 string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" lldb_python_target_dir ${lldb_python_target_dir})
   endif()
-  set(swig_scripts_target "${swig_target}_scripts")
-  set(swig_scripts_install_target "${swig_target}_scripts_install")
-  add_custom_target(${swig_scripts_target})
-  add_dependencies(${swig_scripts_target} ${swig_target})
+  set(python_scripts_target "lldb-python-scripts")
+  set(python_scripts_install_target "install-${python_scripts_target}")
+  add_custom_target(${python_scripts_target})
+  add_dependencies(${python_scripts_target} ${swig_target})
   install(DIRECTORY ${lldb_python_target_dir}/../
   DESTINATION ${LLDB_PYTHON_INSTALL_PATH}
-  COMPONENT ${swig_scripts_target})
+  COMPONENT ${python_scripts_target})
   if (NOT LLVM_ENABLE_IDE)
-add_llvm_install_targets(${swig_scripts_install_target}
- COMPONENT ${swig_scripts_target}
- DEPENDS ${swig_scripts_target})
+add_llvm_install_targets(${python_scripts_install_target}
+ COMPONENT ${python_scripts_target}
+ DEPENDS ${python_scripts_target})
   endif()
 
   # Add a Post-Build Event to copy the custom Python DLL to the lldb binaries dir so that Windows can find it when launching
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D86381: Move Py_buffer_RAII to .h file so SWIG 2 doesnt have to parse it

2020-08-21 Thread António Afonso via Phabricator via lldb-commits
aadsm created this revision.
aadsm added reviewers: clayborg, wallace, lawrence_danna.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.
aadsm requested review of this revision.
Herald added a subscriber: JDevlieghere.

`struct Py_buffer_RAII` definition uses explicit deleted functions which are 
not supported by SWIG 2 (only 3).
To get around this I moved this struct to an .h file that is included to avoid 
being parsed by swig.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86381

Files:
  lldb/bindings/python/python-typemaps.h
  lldb/bindings/python/python-typemaps.swig


Index: lldb/bindings/python/python-typemaps.swig
===
--- lldb/bindings/python/python-typemaps.swig
+++ lldb/bindings/python/python-typemaps.swig
@@ -1,5 +1,11 @@
 /* Typemap definitions, to allow SWIG to properly handle 'char**' data types. 
*/
 
+%inline %{
+
+#include "../bindings/python/python-typemaps.h"
+
+%}
+
 %typemap(in) char ** {
   /* Check if is a list  */
   if (PythonList::Check($input)) {
@@ -61,7 +67,7 @@
 
 %typemap(in) lldb::tid_t {
   PythonObject obj = Retain($input);
-  lldb::tid_t value = unwrapOrSetPythonException(As(obj)); 
+  lldb::tid_t value = unwrapOrSetPythonException(As(obj));
   if (PyErr_Occurred())
 return nullptr;
   $1 = value;
@@ -476,21 +482,6 @@
 }
 }
 
-%inline %{
-
-struct Py_buffer_RAII {
-  Py_buffer buffer = {};
-  Py_buffer_RAII() {};
-  Py_buffer &operator=(const Py_buffer_RAII &) = delete;
-  Py_buffer_RAII(const Py_buffer_RAII &) = delete;
-  ~Py_buffer_RAII() {
-if (buffer.obj)
-  PyBuffer_Release(&buffer);
-  }
-};
-
-%}
-
 // These two pybuffer macros are copied out of swig/Lib/python/pybuffer.i,
 // and fixed so they will not crash if PyObject_GetBuffer fails.
 // https://github.com/swig/swig/issues/1640
Index: lldb/bindings/python/python-typemaps.h
===
--- /dev/null
+++ lldb/bindings/python/python-typemaps.h
@@ -0,0 +1,12 @@
+// Defined here instead of a .swig file because SWIG 2 doesn't support
+// explicit deleted functions.
+struct Py_buffer_RAII {
+  Py_buffer buffer = {};
+  Py_buffer_RAII() {};
+  Py_buffer &operator=(const Py_buffer_RAII &) = delete;
+  Py_buffer_RAII(const Py_buffer_RAII &) = delete;
+  ~Py_buffer_RAII() {
+if (buffer.obj)
+  PyBuffer_Release(&buffer);
+  }
+};


Index: lldb/bindings/python/python-typemaps.swig
===
--- lldb/bindings/python/python-typemaps.swig
+++ lldb/bindings/python/python-typemaps.swig
@@ -1,5 +1,11 @@
 /* Typemap definitions, to allow SWIG to properly handle 'char**' data types. */
 
+%inline %{
+
+#include "../bindings/python/python-typemaps.h"
+
+%}
+
 %typemap(in) char ** {
   /* Check if is a list  */
   if (PythonList::Check($input)) {
@@ -61,7 +67,7 @@
 
 %typemap(in) lldb::tid_t {
   PythonObject obj = Retain($input);
-  lldb::tid_t value = unwrapOrSetPythonException(As(obj)); 
+  lldb::tid_t value = unwrapOrSetPythonException(As(obj));
   if (PyErr_Occurred())
 return nullptr;
   $1 = value;
@@ -476,21 +482,6 @@
 }
 }
 
-%inline %{
-
-struct Py_buffer_RAII {
-  Py_buffer buffer = {};
-  Py_buffer_RAII() {};
-  Py_buffer &operator=(const Py_buffer_RAII &) = delete;
-  Py_buffer_RAII(const Py_buffer_RAII &) = delete;
-  ~Py_buffer_RAII() {
-if (buffer.obj)
-  PyBuffer_Release(&buffer);
-  }
-};
-
-%}
-
 // These two pybuffer macros are copied out of swig/Lib/python/pybuffer.i,
 // and fixed so they will not crash if PyObject_GetBuffer fails.
 // https://github.com/swig/swig/issues/1640
Index: lldb/bindings/python/python-typemaps.h
===
--- /dev/null
+++ lldb/bindings/python/python-typemaps.h
@@ -0,0 +1,12 @@
+// Defined here instead of a .swig file because SWIG 2 doesn't support
+// explicit deleted functions.
+struct Py_buffer_RAII {
+  Py_buffer buffer = {};
+  Py_buffer_RAII() {};
+  Py_buffer &operator=(const Py_buffer_RAII &) = delete;
+  Py_buffer_RAII(const Py_buffer_RAII &) = delete;
+  ~Py_buffer_RAII() {
+if (buffer.obj)
+  PyBuffer_Release(&buffer);
+  }
+};
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D86381: Move Py_buffer_RAII to .h file so SWIG 2 doesnt have to parse it

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

Added include guards, clang-format and python include


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86381

Files:
  lldb/bindings/python/python-typemaps.h
  lldb/bindings/python/python-typemaps.swig


Index: lldb/bindings/python/python-typemaps.swig
===
--- lldb/bindings/python/python-typemaps.swig
+++ lldb/bindings/python/python-typemaps.swig
@@ -1,5 +1,11 @@
 /* Typemap definitions, to allow SWIG to properly handle 'char**' data types. 
*/
 
+%inline %{
+
+#include "../bindings/python/python-typemaps.h"
+
+%}
+
 %typemap(in) char ** {
   /* Check if is a list  */
   if (PythonList::Check($input)) {
@@ -61,7 +67,7 @@
 
 %typemap(in) lldb::tid_t {
   PythonObject obj = Retain($input);
-  lldb::tid_t value = unwrapOrSetPythonException(As(obj)); 
+  lldb::tid_t value = unwrapOrSetPythonException(As(obj));
   if (PyErr_Occurred())
 return nullptr;
   $1 = value;
@@ -476,21 +482,6 @@
 }
 }
 
-%inline %{
-
-struct Py_buffer_RAII {
-  Py_buffer buffer = {};
-  Py_buffer_RAII() {};
-  Py_buffer &operator=(const Py_buffer_RAII &) = delete;
-  Py_buffer_RAII(const Py_buffer_RAII &) = delete;
-  ~Py_buffer_RAII() {
-if (buffer.obj)
-  PyBuffer_Release(&buffer);
-  }
-};
-
-%}
-
 // These two pybuffer macros are copied out of swig/Lib/python/pybuffer.i,
 // and fixed so they will not crash if PyObject_GetBuffer fails.
 // https://github.com/swig/swig/issues/1640
Index: lldb/bindings/python/python-typemaps.h
===
--- /dev/null
+++ lldb/bindings/python/python-typemaps.h
@@ -0,0 +1,19 @@
+#ifndef LLDB_BINDINGS_PYTHON_PYTHONTYPEMAPS_H
+#define LLDB_BINDINGS_PYTHON_PYTHONTYPEMAPS_H
+
+#include "../source/Plugins/ScriptInterpreter/Python/lldb-python.h"
+
+// Defined here instead of a .swig file because SWIG 2 doesn't support
+// explicit deleted functions.
+struct Py_buffer_RAII {
+  Py_buffer buffer = {};
+  Py_buffer_RAII(){};
+  Py_buffer &operator=(const Py_buffer_RAII &) = delete;
+  Py_buffer_RAII(const Py_buffer_RAII &) = delete;
+  ~Py_buffer_RAII() {
+if (buffer.obj)
+  PyBuffer_Release(&buffer);
+  }
+};
+
+#endif // LLDB_BINDINGS_PYTHON_PYTHONTYPEMAPS_H


Index: lldb/bindings/python/python-typemaps.swig
===
--- lldb/bindings/python/python-typemaps.swig
+++ lldb/bindings/python/python-typemaps.swig
@@ -1,5 +1,11 @@
 /* Typemap definitions, to allow SWIG to properly handle 'char**' data types. */
 
+%inline %{
+
+#include "../bindings/python/python-typemaps.h"
+
+%}
+
 %typemap(in) char ** {
   /* Check if is a list  */
   if (PythonList::Check($input)) {
@@ -61,7 +67,7 @@
 
 %typemap(in) lldb::tid_t {
   PythonObject obj = Retain($input);
-  lldb::tid_t value = unwrapOrSetPythonException(As(obj)); 
+  lldb::tid_t value = unwrapOrSetPythonException(As(obj));
   if (PyErr_Occurred())
 return nullptr;
   $1 = value;
@@ -476,21 +482,6 @@
 }
 }
 
-%inline %{
-
-struct Py_buffer_RAII {
-  Py_buffer buffer = {};
-  Py_buffer_RAII() {};
-  Py_buffer &operator=(const Py_buffer_RAII &) = delete;
-  Py_buffer_RAII(const Py_buffer_RAII &) = delete;
-  ~Py_buffer_RAII() {
-if (buffer.obj)
-  PyBuffer_Release(&buffer);
-  }
-};
-
-%}
-
 // These two pybuffer macros are copied out of swig/Lib/python/pybuffer.i,
 // and fixed so they will not crash if PyObject_GetBuffer fails.
 // https://github.com/swig/swig/issues/1640
Index: lldb/bindings/python/python-typemaps.h
===
--- /dev/null
+++ lldb/bindings/python/python-typemaps.h
@@ -0,0 +1,19 @@
+#ifndef LLDB_BINDINGS_PYTHON_PYTHONTYPEMAPS_H
+#define LLDB_BINDINGS_PYTHON_PYTHONTYPEMAPS_H
+
+#include "../source/Plugins/ScriptInterpreter/Python/lldb-python.h"
+
+// Defined here instead of a .swig file because SWIG 2 doesn't support
+// explicit deleted functions.
+struct Py_buffer_RAII {
+  Py_buffer buffer = {};
+  Py_buffer_RAII(){};
+  Py_buffer &operator=(const Py_buffer_RAII &) = delete;
+  Py_buffer_RAII(const Py_buffer_RAII &) = delete;
+  ~Py_buffer_RAII() {
+if (buffer.obj)
+  PyBuffer_Release(&buffer);
+  }
+};
+
+#endif // LLDB_BINDINGS_PYTHON_PYTHONTYPEMAPS_H
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D86381: Move Py_buffer_RAII to .h file so SWIG 2 doesnt have to parse it

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

Moved the header file to be in Plugins/ScriptInterpreter/Python so clang-tidy 
doesn't get confused solving include paths.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86381

Files:
  lldb/bindings/python/python-typemaps.swig
  lldb/source/Plugins/ScriptInterpreter/Python/lldb-python-typemaps.h


Index: lldb/source/Plugins/ScriptInterpreter/Python/lldb-python-typemaps.h
===
--- /dev/null
+++ lldb/source/Plugins/ScriptInterpreter/Python/lldb-python-typemaps.h
@@ -0,0 +1,19 @@
+#ifndef LLDB_SOURCE_PLUGINS_SCRIPTINTERPRETER_PYTHON_LLDB_PYTHON_TYPEMAPS_H
+#define LLDB_SOURCE_PLUGINS_SCRIPTINTERPRETER_PYTHON_LLDB_PYTHON_TYPEMAPS_H
+
+#include "lldb-python.h"
+
+// Defined here instead of a .swig file because SWIG 2 doesn't support
+// explicit deleted functions.
+struct Py_buffer_RAII {
+  Py_buffer buffer = {};
+  Py_buffer_RAII(){};
+  Py_buffer &operator=(const Py_buffer_RAII &) = delete;
+  Py_buffer_RAII(const Py_buffer_RAII &) = delete;
+  ~Py_buffer_RAII() {
+if (buffer.obj)
+  PyBuffer_Release(&buffer);
+  }
+};
+
+#endif // LLDB_SOURCE_PLUGINS_SCRIPTINTERPRETER_PYTHON_LLDB_PYTHON_TYPEMAPS_H
Index: lldb/bindings/python/python-typemaps.swig
===
--- lldb/bindings/python/python-typemaps.swig
+++ lldb/bindings/python/python-typemaps.swig
@@ -1,5 +1,11 @@
 /* Typemap definitions, to allow SWIG to properly handle 'char**' data types. 
*/
 
+%inline %{
+
+#include "../source/Plugins/ScriptInterpreter/Python/lldb-python-typemaps.h"
+
+%}
+
 %typemap(in) char ** {
   /* Check if is a list  */
   if (PythonList::Check($input)) {
@@ -61,7 +67,7 @@
 
 %typemap(in) lldb::tid_t {
   PythonObject obj = Retain($input);
-  lldb::tid_t value = unwrapOrSetPythonException(As(obj)); 
+  lldb::tid_t value = unwrapOrSetPythonException(As(obj));
   if (PyErr_Occurred())
 return nullptr;
   $1 = value;
@@ -476,21 +482,6 @@
 }
 }
 
-%inline %{
-
-struct Py_buffer_RAII {
-  Py_buffer buffer = {};
-  Py_buffer_RAII() {};
-  Py_buffer &operator=(const Py_buffer_RAII &) = delete;
-  Py_buffer_RAII(const Py_buffer_RAII &) = delete;
-  ~Py_buffer_RAII() {
-if (buffer.obj)
-  PyBuffer_Release(&buffer);
-  }
-};
-
-%}
-
 // These two pybuffer macros are copied out of swig/Lib/python/pybuffer.i,
 // and fixed so they will not crash if PyObject_GetBuffer fails.
 // https://github.com/swig/swig/issues/1640


Index: lldb/source/Plugins/ScriptInterpreter/Python/lldb-python-typemaps.h
===
--- /dev/null
+++ lldb/source/Plugins/ScriptInterpreter/Python/lldb-python-typemaps.h
@@ -0,0 +1,19 @@
+#ifndef LLDB_SOURCE_PLUGINS_SCRIPTINTERPRETER_PYTHON_LLDB_PYTHON_TYPEMAPS_H
+#define LLDB_SOURCE_PLUGINS_SCRIPTINTERPRETER_PYTHON_LLDB_PYTHON_TYPEMAPS_H
+
+#include "lldb-python.h"
+
+// Defined here instead of a .swig file because SWIG 2 doesn't support
+// explicit deleted functions.
+struct Py_buffer_RAII {
+  Py_buffer buffer = {};
+  Py_buffer_RAII(){};
+  Py_buffer &operator=(const Py_buffer_RAII &) = delete;
+  Py_buffer_RAII(const Py_buffer_RAII &) = delete;
+  ~Py_buffer_RAII() {
+if (buffer.obj)
+  PyBuffer_Release(&buffer);
+  }
+};
+
+#endif // LLDB_SOURCE_PLUGINS_SCRIPTINTERPRETER_PYTHON_LLDB_PYTHON_TYPEMAPS_H
Index: lldb/bindings/python/python-typemaps.swig
===
--- lldb/bindings/python/python-typemaps.swig
+++ lldb/bindings/python/python-typemaps.swig
@@ -1,5 +1,11 @@
 /* Typemap definitions, to allow SWIG to properly handle 'char**' data types. */
 
+%inline %{
+
+#include "../source/Plugins/ScriptInterpreter/Python/lldb-python-typemaps.h"
+
+%}
+
 %typemap(in) char ** {
   /* Check if is a list  */
   if (PythonList::Check($input)) {
@@ -61,7 +67,7 @@
 
 %typemap(in) lldb::tid_t {
   PythonObject obj = Retain($input);
-  lldb::tid_t value = unwrapOrSetPythonException(As(obj)); 
+  lldb::tid_t value = unwrapOrSetPythonException(As(obj));
   if (PyErr_Occurred())
 return nullptr;
   $1 = value;
@@ -476,21 +482,6 @@
 }
 }
 
-%inline %{
-
-struct Py_buffer_RAII {
-  Py_buffer buffer = {};
-  Py_buffer_RAII() {};
-  Py_buffer &operator=(const Py_buffer_RAII &) = delete;
-  Py_buffer_RAII(const Py_buffer_RAII &) = delete;
-  ~Py_buffer_RAII() {
-if (buffer.obj)
-  PyBuffer_Release(&buffer);
-  }
-};
-
-%}
-
 // These two pybuffer macros are copied out of swig/Lib/python/pybuffer.i,
 // and fixed so they will not crash if PyObject_GetBuffer fails.
 // https://github.com/swig/swig/issues/1640
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D86381: Move Py_buffer_RAII to .h file so SWIG 2 doesnt have to parse it

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

After reading a bit more how clang-tidy works this isn't fixable because it 
actually needs to compile it. I also didn't find a way to exclude a file from 
it.
My plan is to just land this and then make a PR to add this file to 
https://github.com/google/llvm-premerge-checks/blob/master/scripts/clang-tidy.ignore


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86381

Files:
  lldb/bindings/python/python-typemaps.h
  lldb/bindings/python/python-typemaps.swig


Index: lldb/bindings/python/python-typemaps.swig
===
--- lldb/bindings/python/python-typemaps.swig
+++ lldb/bindings/python/python-typemaps.swig
@@ -1,5 +1,11 @@
 /* Typemap definitions, to allow SWIG to properly handle 'char**' data types. 
*/
 
+%inline %{
+
+#include "../bindings/python/python-typemaps.h"
+
+%}
+
 %typemap(in) char ** {
   /* Check if is a list  */
   if (PythonList::Check($input)) {
@@ -61,7 +67,7 @@
 
 %typemap(in) lldb::tid_t {
   PythonObject obj = Retain($input);
-  lldb::tid_t value = unwrapOrSetPythonException(As(obj)); 
+  lldb::tid_t value = unwrapOrSetPythonException(As(obj));
   if (PyErr_Occurred())
 return nullptr;
   $1 = value;
@@ -476,21 +482,6 @@
 }
 }
 
-%inline %{
-
-struct Py_buffer_RAII {
-  Py_buffer buffer = {};
-  Py_buffer_RAII() {};
-  Py_buffer &operator=(const Py_buffer_RAII &) = delete;
-  Py_buffer_RAII(const Py_buffer_RAII &) = delete;
-  ~Py_buffer_RAII() {
-if (buffer.obj)
-  PyBuffer_Release(&buffer);
-  }
-};
-
-%}
-
 // These two pybuffer macros are copied out of swig/Lib/python/pybuffer.i,
 // and fixed so they will not crash if PyObject_GetBuffer fails.
 // https://github.com/swig/swig/issues/1640
Index: lldb/bindings/python/python-typemaps.h
===
--- /dev/null
+++ lldb/bindings/python/python-typemaps.h
@@ -0,0 +1,17 @@
+#ifndef LLDB_BINDINGS_PYTHON_PYTHON_TYPEMAPS_H
+#define LLDB_BINDINGS_PYTHON_PYTHON_TYPEMAPS_H
+
+// Defined here instead of a .swig file because SWIG 2 doesn't support
+// explicit deleted functions.
+struct Py_buffer_RAII {
+  Py_buffer buffer = {};
+  Py_buffer_RAII(){};
+  Py_buffer &operator=(const Py_buffer_RAII &) = delete;
+  Py_buffer_RAII(const Py_buffer_RAII &) = delete;
+  ~Py_buffer_RAII() {
+if (buffer.obj)
+  PyBuffer_Release(&buffer);
+  }
+};
+
+#endif // LLDB_BINDINGS_PYTHON_PYTHON_TYPEMAPS_H


Index: lldb/bindings/python/python-typemaps.swig
===
--- lldb/bindings/python/python-typemaps.swig
+++ lldb/bindings/python/python-typemaps.swig
@@ -1,5 +1,11 @@
 /* Typemap definitions, to allow SWIG to properly handle 'char**' data types. */
 
+%inline %{
+
+#include "../bindings/python/python-typemaps.h"
+
+%}
+
 %typemap(in) char ** {
   /* Check if is a list  */
   if (PythonList::Check($input)) {
@@ -61,7 +67,7 @@
 
 %typemap(in) lldb::tid_t {
   PythonObject obj = Retain($input);
-  lldb::tid_t value = unwrapOrSetPythonException(As(obj)); 
+  lldb::tid_t value = unwrapOrSetPythonException(As(obj));
   if (PyErr_Occurred())
 return nullptr;
   $1 = value;
@@ -476,21 +482,6 @@
 }
 }
 
-%inline %{
-
-struct Py_buffer_RAII {
-  Py_buffer buffer = {};
-  Py_buffer_RAII() {};
-  Py_buffer &operator=(const Py_buffer_RAII &) = delete;
-  Py_buffer_RAII(const Py_buffer_RAII &) = delete;
-  ~Py_buffer_RAII() {
-if (buffer.obj)
-  PyBuffer_Release(&buffer);
-  }
-};
-
-%}
-
 // These two pybuffer macros are copied out of swig/Lib/python/pybuffer.i,
 // and fixed so they will not crash if PyObject_GetBuffer fails.
 // https://github.com/swig/swig/issues/1640
Index: lldb/bindings/python/python-typemaps.h
===
--- /dev/null
+++ lldb/bindings/python/python-typemaps.h
@@ -0,0 +1,17 @@
+#ifndef LLDB_BINDINGS_PYTHON_PYTHON_TYPEMAPS_H
+#define LLDB_BINDINGS_PYTHON_PYTHON_TYPEMAPS_H
+
+// Defined here instead of a .swig file because SWIG 2 doesn't support
+// explicit deleted functions.
+struct Py_buffer_RAII {
+  Py_buffer buffer = {};
+  Py_buffer_RAII(){};
+  Py_buffer &operator=(const Py_buffer_RAII &) = delete;
+  Py_buffer_RAII(const Py_buffer_RAII &) = delete;
+  ~Py_buffer_RAII() {
+if (buffer.obj)
+  PyBuffer_Release(&buffer);
+  }
+};
+
+#endif // LLDB_BINDINGS_PYTHON_PYTHON_TYPEMAPS_H
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D86402: Avoid creating lldb-python-scripts target more than once

2020-08-22 Thread António Afonso via Phabricator via lldb-commits
aadsm created this revision.
aadsm added a reviewer: JDevlieghere.
Herald added subscribers: lldb-commits, mgorny.
Herald added a project: LLDB.
aadsm requested review of this revision.

This addresses the issue raised here 
https://reviews.llvm.org/rG02bf5632a94da6c3570df002804f8d3f79c11bfc
The `finish_swig_python` function might be called more than once so we need to 
make sure that the
`lldb-python-scripts` target is only created once.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86402

Files:
  lldb/bindings/python/CMakeLists.txt


Index: lldb/bindings/python/CMakeLists.txt
===
--- lldb/bindings/python/CMakeLists.txt
+++ lldb/bindings/python/CMakeLists.txt
@@ -165,16 +165,19 @@
   endif()
   set(python_scripts_target "lldb-python-scripts")
   set(python_scripts_install_target "install-${python_scripts_target}")
-  add_custom_target(${python_scripts_target})
+  # This function might be called multiple times but we only need to create 
the custom target once.
+  if (NOT TARGET ${python_scripts_target})
+add_custom_target(${python_scripts_target})
+if (NOT LLVM_ENABLE_IDE)
+  add_llvm_install_targets(${python_scripts_install_target}
+  COMPONENT ${python_scripts_target}
+  DEPENDS ${python_scripts_target})
+endif()
+  endif()
   add_dependencies(${python_scripts_target} ${swig_target})
   install(DIRECTORY ${lldb_python_target_dir}/../
   DESTINATION ${LLDB_PYTHON_INSTALL_PATH}
   COMPONENT ${python_scripts_target})
-  if (NOT LLVM_ENABLE_IDE)
-add_llvm_install_targets(${python_scripts_install_target}
- COMPONENT ${python_scripts_target}
- DEPENDS ${python_scripts_target})
-  endif()
 
   # Add a Post-Build Event to copy the custom Python DLL to the lldb binaries 
dir so that Windows can find it when launching
   # lldb.exe or any other executables that were linked with liblldb.


Index: lldb/bindings/python/CMakeLists.txt
===
--- lldb/bindings/python/CMakeLists.txt
+++ lldb/bindings/python/CMakeLists.txt
@@ -165,16 +165,19 @@
   endif()
   set(python_scripts_target "lldb-python-scripts")
   set(python_scripts_install_target "install-${python_scripts_target}")
-  add_custom_target(${python_scripts_target})
+  # This function might be called multiple times but we only need to create the custom target once.
+  if (NOT TARGET ${python_scripts_target})
+add_custom_target(${python_scripts_target})
+if (NOT LLVM_ENABLE_IDE)
+  add_llvm_install_targets(${python_scripts_install_target}
+  COMPONENT ${python_scripts_target}
+  DEPENDS ${python_scripts_target})
+endif()
+  endif()
   add_dependencies(${python_scripts_target} ${swig_target})
   install(DIRECTORY ${lldb_python_target_dir}/../
   DESTINATION ${LLDB_PYTHON_INSTALL_PATH}
   COMPONENT ${python_scripts_target})
-  if (NOT LLVM_ENABLE_IDE)
-add_llvm_install_targets(${python_scripts_install_target}
- COMPONENT ${python_scripts_target}
- DEPENDS ${python_scripts_target})
-  endif()
 
   # Add a Post-Build Event to copy the custom Python DLL to the lldb binaries dir so that Windows can find it when launching
   # lldb.exe or any other executables that were linked with liblldb.
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D86381: Move Py_buffer_RAII to .h file so SWIG 2 doesnt have to parse it

2020-08-22 Thread António Afonso 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 rG5d8eedee917d: Move Py_buffer_RAII to .h file so SWIG 2 
doesnt have to parse it (authored by aadsm).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86381

Files:
  lldb/bindings/python/python-typemaps.h
  lldb/bindings/python/python-typemaps.swig


Index: lldb/bindings/python/python-typemaps.swig
===
--- lldb/bindings/python/python-typemaps.swig
+++ lldb/bindings/python/python-typemaps.swig
@@ -1,5 +1,11 @@
 /* Typemap definitions, to allow SWIG to properly handle 'char**' data types. 
*/
 
+%inline %{
+
+#include "../bindings/python/python-typemaps.h"
+
+%}
+
 %typemap(in) char ** {
   /* Check if is a list  */
   if (PythonList::Check($input)) {
@@ -61,7 +67,7 @@
 
 %typemap(in) lldb::tid_t {
   PythonObject obj = Retain($input);
-  lldb::tid_t value = unwrapOrSetPythonException(As(obj)); 
+  lldb::tid_t value = unwrapOrSetPythonException(As(obj));
   if (PyErr_Occurred())
 return nullptr;
   $1 = value;
@@ -476,21 +482,6 @@
 }
 }
 
-%inline %{
-
-struct Py_buffer_RAII {
-  Py_buffer buffer = {};
-  Py_buffer_RAII() {};
-  Py_buffer &operator=(const Py_buffer_RAII &) = delete;
-  Py_buffer_RAII(const Py_buffer_RAII &) = delete;
-  ~Py_buffer_RAII() {
-if (buffer.obj)
-  PyBuffer_Release(&buffer);
-  }
-};
-
-%}
-
 // These two pybuffer macros are copied out of swig/Lib/python/pybuffer.i,
 // and fixed so they will not crash if PyObject_GetBuffer fails.
 // https://github.com/swig/swig/issues/1640
Index: lldb/bindings/python/python-typemaps.h
===
--- /dev/null
+++ lldb/bindings/python/python-typemaps.h
@@ -0,0 +1,17 @@
+#ifndef LLDB_BINDINGS_PYTHON_PYTHON_TYPEMAPS_H
+#define LLDB_BINDINGS_PYTHON_PYTHON_TYPEMAPS_H
+
+// Defined here instead of a .swig file because SWIG 2 doesn't support
+// explicit deleted functions.
+struct Py_buffer_RAII {
+  Py_buffer buffer = {};
+  Py_buffer_RAII(){};
+  Py_buffer &operator=(const Py_buffer_RAII &) = delete;
+  Py_buffer_RAII(const Py_buffer_RAII &) = delete;
+  ~Py_buffer_RAII() {
+if (buffer.obj)
+  PyBuffer_Release(&buffer);
+  }
+};
+
+#endif // LLDB_BINDINGS_PYTHON_PYTHON_TYPEMAPS_H


Index: lldb/bindings/python/python-typemaps.swig
===
--- lldb/bindings/python/python-typemaps.swig
+++ lldb/bindings/python/python-typemaps.swig
@@ -1,5 +1,11 @@
 /* Typemap definitions, to allow SWIG to properly handle 'char**' data types. */
 
+%inline %{
+
+#include "../bindings/python/python-typemaps.h"
+
+%}
+
 %typemap(in) char ** {
   /* Check if is a list  */
   if (PythonList::Check($input)) {
@@ -61,7 +67,7 @@
 
 %typemap(in) lldb::tid_t {
   PythonObject obj = Retain($input);
-  lldb::tid_t value = unwrapOrSetPythonException(As(obj)); 
+  lldb::tid_t value = unwrapOrSetPythonException(As(obj));
   if (PyErr_Occurred())
 return nullptr;
   $1 = value;
@@ -476,21 +482,6 @@
 }
 }
 
-%inline %{
-
-struct Py_buffer_RAII {
-  Py_buffer buffer = {};
-  Py_buffer_RAII() {};
-  Py_buffer &operator=(const Py_buffer_RAII &) = delete;
-  Py_buffer_RAII(const Py_buffer_RAII &) = delete;
-  ~Py_buffer_RAII() {
-if (buffer.obj)
-  PyBuffer_Release(&buffer);
-  }
-};
-
-%}
-
 // These two pybuffer macros are copied out of swig/Lib/python/pybuffer.i,
 // and fixed so they will not crash if PyObject_GetBuffer fails.
 // https://github.com/swig/swig/issues/1640
Index: lldb/bindings/python/python-typemaps.h
===
--- /dev/null
+++ lldb/bindings/python/python-typemaps.h
@@ -0,0 +1,17 @@
+#ifndef LLDB_BINDINGS_PYTHON_PYTHON_TYPEMAPS_H
+#define LLDB_BINDINGS_PYTHON_PYTHON_TYPEMAPS_H
+
+// Defined here instead of a .swig file because SWIG 2 doesn't support
+// explicit deleted functions.
+struct Py_buffer_RAII {
+  Py_buffer buffer = {};
+  Py_buffer_RAII(){};
+  Py_buffer &operator=(const Py_buffer_RAII &) = delete;
+  Py_buffer_RAII(const Py_buffer_RAII &) = delete;
+  ~Py_buffer_RAII() {
+if (buffer.obj)
+  PyBuffer_Release(&buffer);
+  }
+};
+
+#endif // LLDB_BINDINGS_PYTHON_PYTHON_TYPEMAPS_H
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D86402: Avoid creating lldb-python-scripts target more than once

2020-08-22 Thread António Afonso via Phabricator via lldb-commits
aadsm added a comment.

Sounds good, will update. In my mind it would be easier to just install all 
configured python scripts by specifying a single distribution component.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86402

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


[Lldb-commits] [PATCH] D86402: Avoid creating lldb-python-scripts target more than once

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

Update to create 2 separate install targets


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86402

Files:
  lldb/CMakeLists.txt
  lldb/bindings/python/CMakeLists.txt


Index: lldb/bindings/python/CMakeLists.txt
===
--- lldb/bindings/python/CMakeLists.txt
+++ lldb/bindings/python/CMakeLists.txt
@@ -163,7 +163,7 @@
 string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" 
LLDB_PYTHON_INSTALL_PATH ${LLDB_PYTHON_INSTALL_PATH})
 string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" 
lldb_python_target_dir ${lldb_python_target_dir})
   endif()
-  set(python_scripts_target "lldb-python-scripts")
+  set(python_scripts_target "${swig_target}-scripts")
   set(python_scripts_install_target "install-${python_scripts_target}")
   add_custom_target(${python_scripts_target})
   add_dependencies(${python_scripts_target} ${swig_target})
Index: lldb/CMakeLists.txt
===
--- lldb/CMakeLists.txt
+++ lldb/CMakeLists.txt
@@ -86,7 +86,7 @@
 set(lldb_python_target_dir 
"${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_PYTHON_RELATIVE_PATH}/lldb")
   endif()
   get_target_property(lldb_python_bindings_dir swig_wrapper_python BINARY_DIR)
-  finish_swig_python("finish_swig_python" "${lldb_python_bindings_dir}" 
"${lldb_python_target_dir}")
+  finish_swig_python("lldb-python" "${lldb_python_bindings_dir}" 
"${lldb_python_target_dir}")
 endif()
 
 option(LLDB_INCLUDE_TESTS "Generate build targets for the LLDB unit tests." 
${LLVM_INCLUDE_TESTS})


Index: lldb/bindings/python/CMakeLists.txt
===
--- lldb/bindings/python/CMakeLists.txt
+++ lldb/bindings/python/CMakeLists.txt
@@ -163,7 +163,7 @@
 string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" LLDB_PYTHON_INSTALL_PATH ${LLDB_PYTHON_INSTALL_PATH})
 string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" lldb_python_target_dir ${lldb_python_target_dir})
   endif()
-  set(python_scripts_target "lldb-python-scripts")
+  set(python_scripts_target "${swig_target}-scripts")
   set(python_scripts_install_target "install-${python_scripts_target}")
   add_custom_target(${python_scripts_target})
   add_dependencies(${python_scripts_target} ${swig_target})
Index: lldb/CMakeLists.txt
===
--- lldb/CMakeLists.txt
+++ lldb/CMakeLists.txt
@@ -86,7 +86,7 @@
 set(lldb_python_target_dir "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_PYTHON_RELATIVE_PATH}/lldb")
   endif()
   get_target_property(lldb_python_bindings_dir swig_wrapper_python BINARY_DIR)
-  finish_swig_python("finish_swig_python" "${lldb_python_bindings_dir}" "${lldb_python_target_dir}")
+  finish_swig_python("lldb-python" "${lldb_python_bindings_dir}" "${lldb_python_target_dir}")
 endif()
 
 option(LLDB_INCLUDE_TESTS "Generate build targets for the LLDB unit tests." ${LLVM_INCLUDE_TESTS})
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D86402: Avoid creating lldb-python-scripts target more than once

2020-08-22 Thread António Afonso via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG52381938bcc8: Create ${swig_target}-scripts target instead 
of lldb-python-scripts (authored by aadsm).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86402

Files:
  lldb/CMakeLists.txt
  lldb/bindings/python/CMakeLists.txt


Index: lldb/bindings/python/CMakeLists.txt
===
--- lldb/bindings/python/CMakeLists.txt
+++ lldb/bindings/python/CMakeLists.txt
@@ -163,7 +163,7 @@
 string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" 
LLDB_PYTHON_INSTALL_PATH ${LLDB_PYTHON_INSTALL_PATH})
 string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" 
lldb_python_target_dir ${lldb_python_target_dir})
   endif()
-  set(python_scripts_target "lldb-python-scripts")
+  set(python_scripts_target "${swig_target}-scripts")
   set(python_scripts_install_target "install-${python_scripts_target}")
   add_custom_target(${python_scripts_target})
   add_dependencies(${python_scripts_target} ${swig_target})
Index: lldb/CMakeLists.txt
===
--- lldb/CMakeLists.txt
+++ lldb/CMakeLists.txt
@@ -86,7 +86,7 @@
 set(lldb_python_target_dir 
"${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_PYTHON_RELATIVE_PATH}/lldb")
   endif()
   get_target_property(lldb_python_bindings_dir swig_wrapper_python BINARY_DIR)
-  finish_swig_python("finish_swig_python" "${lldb_python_bindings_dir}" 
"${lldb_python_target_dir}")
+  finish_swig_python("lldb-python" "${lldb_python_bindings_dir}" 
"${lldb_python_target_dir}")
 endif()
 
 option(LLDB_INCLUDE_TESTS "Generate build targets for the LLDB unit tests." 
${LLVM_INCLUDE_TESTS})


Index: lldb/bindings/python/CMakeLists.txt
===
--- lldb/bindings/python/CMakeLists.txt
+++ lldb/bindings/python/CMakeLists.txt
@@ -163,7 +163,7 @@
 string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" LLDB_PYTHON_INSTALL_PATH ${LLDB_PYTHON_INSTALL_PATH})
 string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" lldb_python_target_dir ${lldb_python_target_dir})
   endif()
-  set(python_scripts_target "lldb-python-scripts")
+  set(python_scripts_target "${swig_target}-scripts")
   set(python_scripts_install_target "install-${python_scripts_target}")
   add_custom_target(${python_scripts_target})
   add_dependencies(${python_scripts_target} ${swig_target})
Index: lldb/CMakeLists.txt
===
--- lldb/CMakeLists.txt
+++ lldb/CMakeLists.txt
@@ -86,7 +86,7 @@
 set(lldb_python_target_dir "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_PYTHON_RELATIVE_PATH}/lldb")
   endif()
   get_target_property(lldb_python_bindings_dir swig_wrapper_python BINARY_DIR)
-  finish_swig_python("finish_swig_python" "${lldb_python_bindings_dir}" "${lldb_python_target_dir}")
+  finish_swig_python("lldb-python" "${lldb_python_bindings_dir}" "${lldb_python_target_dir}")
 endif()
 
 option(LLDB_INCLUDE_TESTS "Generate build targets for the LLDB unit tests." ${LLVM_INCLUDE_TESTS})
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D87172: Check if debug line sequences are starting after the first code segment

2020-09-04 Thread António Afonso via Phabricator via lldb-commits
aadsm created this revision.
aadsm added reviewers: clayborg, labath.
Herald added subscribers: lldb-commits, mgorny.
Herald added a project: LLDB.
aadsm requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: sstefan1, JDevlieghere.

I found a few cases where entries in the debug_line for a specific line of code 
have invalid entries (the address is outside of a code section or no section at 
all) and also valid entries. When this happens lldb might not set the 
breakpoint because the first line entry it will find in the line table might be 
the invalid one and since it's range is "invalid" no location is resolved. To 
get around this I changed the way we parse the line sequences to ignore those 
starting at an address under the first code segment.
Greg suggested to implement it this way so we don't need to check all sections 
for every line sequence.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87172

Files:
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/unittests/SymbolFile/DWARF/CMakeLists.txt
  lldb/unittests/SymbolFile/DWARF/Inputs/test-invalid-offsets.yaml
  lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp

Index: lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
@@ -14,6 +14,7 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 
+#include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h"
 #include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
 #include "Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDataExtractor.h"
@@ -40,8 +41,8 @@
 using namespace lldb_private;
 
 class SymbolFileDWARFTests : public testing::Test {
-  SubsystemRAII
+  SubsystemRAII
   subsystems;
 
 public:
@@ -70,7 +71,7 @@
 TEST_F(SymbolFileDWARFTests, TestAbbrevOrder1Start1) {
   // Test that if we have a .debug_abbrev that contains ordered abbreviation
   // codes that start at 1, that we get O(1) access.
-  
+
   const auto byte_order = eByteOrderLittle;
   const uint8_t addr_size = 4;
   StreamString encoder(Stream::eBinary, addr_size, byte_order);
@@ -81,7 +82,7 @@
   encoder.PutULEB128(DW_FORM_strp);
   encoder.PutULEB128(0);
   encoder.PutULEB128(0);
-  
+
   encoder.PutULEB128(2); // Abbrev code 2
   encoder.PutULEB128(DW_TAG_subprogram);
   encoder.PutHex8(DW_CHILDREN_no);
@@ -89,9 +90,9 @@
   encoder.PutULEB128(DW_FORM_strp);
   encoder.PutULEB128(0);
   encoder.PutULEB128(0);
-  
+
   encoder.PutULEB128(0); // Abbrev code 0 (termination)
- 
+
   DWARFDataExtractor data;
   data.SetData(encoder.GetData(), encoder.GetSize(), byte_order);
   DWARFAbbreviationDeclarationSet abbrev_set;
@@ -101,7 +102,7 @@
   // Make sure we have O(1) access to each abbreviation by making sure the
   // index offset is 1 and not UINT32_MAX
   EXPECT_EQ(abbrev_set.GetIndexOffset(), 1u);
-  
+
   auto abbrev1 = abbrev_set.GetAbbreviationDeclaration(1);
   EXPECT_EQ(abbrev1->Tag(), DW_TAG_compile_unit);
   EXPECT_TRUE(abbrev1->HasChildren());
@@ -115,7 +116,7 @@
 TEST_F(SymbolFileDWARFTests, TestAbbrevOrder1Start5) {
   // Test that if we have a .debug_abbrev that contains ordered abbreviation
   // codes that start at 5, that we get O(1) access.
-  
+
   const auto byte_order = eByteOrderLittle;
   const uint8_t addr_size = 4;
   StreamString encoder(Stream::eBinary, addr_size, byte_order);
@@ -126,7 +127,7 @@
   encoder.PutULEB128(DW_FORM_strp);
   encoder.PutULEB128(0);
   encoder.PutULEB128(0);
-  
+
   encoder.PutULEB128(6); // Abbrev code 6
   encoder.PutULEB128(DW_TAG_subprogram);
   encoder.PutHex8(DW_CHILDREN_no);
@@ -134,9 +135,9 @@
   encoder.PutULEB128(DW_FORM_strp);
   encoder.PutULEB128(0);
   encoder.PutULEB128(0);
-  
+
   encoder.PutULEB128(0); // Abbrev code 0 (termination)
-  
+
   DWARFDataExtractor data;
   data.SetData(encoder.GetData(), encoder.GetSize(), byte_order);
   DWARFAbbreviationDeclarationSet abbrev_set;
@@ -146,7 +147,7 @@
   // Make sure we have O(1) access to each abbreviation by making sure the
   // index offset is 5 and not UINT32_MAX
   EXPECT_EQ(abbrev_set.GetIndexOffset(), 5u);
-  
+
   auto abbrev1 = abbrev_set.GetAbbreviationDeclaration(5);
   EXPECT_EQ(abbrev1->Tag(), DW_TAG_compile_unit);
   EXPECT_TRUE(abbrev1->HasChildren());
@@ -160,7 +161,7 @@
 TEST_F(SymbolFileDWARFTests, TestAbbrevOutOfOrder) {
   // Test that if we have a .debug_abbrev that contains unordered abbreviation
   // codes, that we can access the information correctly.
-  
+
   const auto byte_order = eByteOrderLittle;
   const uint8_t addr_size = 4;
   StreamString encoder(Stream::eBinary, addr_size, byte_order);
@@ -171,7 +172,7 @@
   encoder.PutULEB128(DW_FORM_strp);
   encoder.PutULEB128(0);
   encoder.PutULEB128(

[Lldb-commits] [PATCH] D87172: Check if debug line sequences are starting after the first code segment

2020-09-04 Thread António Afonso via Phabricator via lldb-commits
aadsm added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp:441
+  if (first_code_section_sp)
+m_first_code_address = first_code_section_sp->GetFileAddress();
+}

I'm actually not 100% sure about this, can there be new code sections added 
after this?



Comment at: lldb/unittests/SymbolFile/DWARF/Inputs/test-invalid-offsets.yaml:520
+  Data:0
+...

I generated this yaml with the code that is at the top, and then changed it to 
replicate the bug ,here's what the line table looks like:


```
AddressLine   Column File   ISA Discriminator Flags
-- -- -- -- --- - -
0x00010f80  1  0  1   0 0  is_stmt
0x00010f84  2  5  1   0 0  is_stmt prologue_end
0x00010f8b  2  5  1   0 0  is_stmt end_sequence
0x00010f90  5  0  1   0 0  is_stmt
0x00010f90  5  0  1   0 0  is_stmt end_sequence
0x000f  2 13  1   0 0  is_stmt prologue_end
0x0014  2  9  1   0 0
0x0017  3 12  1   0 0  is_stmt
0x001d  3 12  1   0 0  end_sequence
```

Now that I think about it maybe I should also copy this into this file as a 
comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87172

___
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-09-04 Thread António Afonso via Phabricator via lldb-commits
aadsm created this revision.
aadsm added reviewers: clayborg, labath.
Herald added a reviewer: shafik.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.
aadsm requested review of this revision.
Herald added a subscriber: JDevlieghere.

This is a similar patch to https://reviews.llvm.org/D87172. Greg said we should 
also do it for functions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87173

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/unittests/SymbolFile/DWARF/Inputs/test-invalid-offsets.yaml
  lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp


Index: lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
@@ -35,14 +35,16 @@
 #include "lldb/Utility/ArchSpec.h"
 #include "lldb/Utility/DataEncoder.h"
 #include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/Reproducer.h"
 #include "lldb/Utility/StreamString.h"
 
 using namespace lldb;
 using namespace lldb_private;
 
 class SymbolFileDWARFTests : public testing::Test {
-  SubsystemRAII
+  SubsystemRAII
   subsystems;
 
 public:
@@ -367,3 +369,27 @@
   ASSERT_NE(section_sp.get(), nullptr);
   EXPECT_EQ(section_sp->GetType(), eSectionTypeCode);
 }
+
+TEST_F(SymbolFileDWARFTests, EnsureAllParseFunctionsExistInCodeSections) {
+  auto ExpectedFile = TestFile::fromYamlFile("test-invalid-offsets.yaml");
+  ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded());
+
+  lldb::ModuleSP module_sp =
+  std::make_shared(ExpectedFile->moduleSpec());
+  SymbolFile *symfile = module_sp->GetSymbolFile();
+  ASSERT_NE(symfile, nullptr);
+
+  SymbolContextList sc_list;
+  RegularExpression regex(".");
+  symfile->FindFunctions(regex, false, sc_list);
+  ASSERT_EQ(sc_list.GetSize(), 1U);
+
+  SymbolContext sc;
+  sc_list.GetContextAtIndex(0, sc);
+  EXPECT_STREQ(sc.function->GetName().AsCString(), "main");
+
+  auto section_sp =
+  sc.function->GetAddressRange().GetBaseAddress().GetSection();
+  ASSERT_NE(section_sp.get(), nullptr);
+  EXPECT_EQ(section_sp->GetType(), eSectionTypeCode);
+}
Index: lldb/unittests/SymbolFile/DWARF/Inputs/test-invalid-offsets.yaml
===
--- lldb/unittests/SymbolFile/DWARF/Inputs/test-invalid-offsets.yaml
+++ lldb/unittests/SymbolFile/DWARF/Inputs/test-invalid-offsets.yaml
@@ -408,8 +408,8 @@
 - Value:   0x00010F80
 - Value:   0x0030
 - AbbrCode:0x0002
-  Values:
-- Value:   0x00010F80
+  Values: # DW_TAG_subprogram foo
+- Value:   0x0F80 # DW_AT_low_pc points to 
invalid loc
 - Value:   0x000B
 - Value:   0x0001
   BlockData:   [ 0x56 ]
@@ -420,7 +420,7 @@
 - Value:   0x006F
 - Value:   0x0001
 - AbbrCode:0x0003
-  Values:
+  Values: # DW_TAG_subprogram main
 - Value:   0x00010F90
 - Value:   0x0020
 - Value:   0x0001
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -2262,7 +2262,9 @@
 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
 }
 
-if (func_range.GetBaseAddress().IsValid()) {
+auto base_address = func_range.GetBaseAddress();
+if (base_address.IsSectionOffset() &&
+base_address.GetSection()->GetType() == eSectionTypeCode) {
   Mangled func_name;
   if (mangled)
 func_name.SetValue(ConstString(mangled), true);


Index: lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
@@ -35,14 +35,16 @@
 #include "lldb/Utility/ArchSpec.h"
 #include "lldb/Utility/DataEncoder.h"
 #include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/Reproducer.h"
 #include "lldb/Utility/StreamString.h"
 
 using namespace lldb;
 using namespace lldb_private;
 
 class SymbolFileDWARFTests : public testing::Test {
-  SubsystemRAII
+  SubsystemRAII
   subsystems;
 
 public:
@@ -367,3 +369,27 @@
   ASSERT_NE(section_sp.get(), nullptr);
   EXPECT_EQ(section_sp->GetType(), eSectionTypeCode);
 }
+
+TEST_F(SymbolFileDWARFTests, EnsureAllParseFunctionsExistInCodeSections) {
+  auto ExpectedFile = TestFile::fromYamlFile("test-invalid-offsets.yaml"

[Lldb-commits] [PATCH] D87172: Check if debug line sequences are starting after the first code segment

2020-09-04 Thread António Afonso via Phabricator via lldb-commits
aadsm added inline comments.



Comment at: lldb/unittests/SymbolFile/DWARF/Inputs/test-invalid-offsets.yaml:1
+# int foo() {
+# return 42;

I should rename this to `test-invalid-addresses.yaml` instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87172

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


[Lldb-commits] [PATCH] D87172: Check if debug line sequences are starting after the first code segment

2020-09-04 Thread António Afonso via Phabricator via lldb-commits
aadsm added inline comments.



Comment at: lldb/unittests/SymbolFile/DWARF/Inputs/test-invalid-offsets.yaml:520
+  Data:0
+...

clayborg wrote:
> aadsm wrote:
> > I generated this yaml with the code that is at the top, and then changed it 
> > to replicate the bug ,here's what the line table looks like:
> > 
> > 
> > ```
> > AddressLine   Column File   ISA Discriminator Flags
> > -- -- -- -- --- - -
> > 0x00010f80  1  0  1   0 0  is_stmt
> > 0x00010f84  2  5  1   0 0  is_stmt 
> > prologue_end
> > 0x00010f8b  2  5  1   0 0  is_stmt 
> > end_sequence
> > 0x00010f90  5  0  1   0 0  is_stmt
> > 0x00010f90  5  0  1   0 0  is_stmt 
> > end_sequence
> > 0x000f  2 13  1   0 0  is_stmt 
> > prologue_end
> > 0x0014  2  9  1   0 0
> > 0x0017  3 12  1   0 0  is_stmt
> > 0x001d  3 12  1   0 0  end_sequence
> > ```
> > 
> > Now that I think about it maybe I should also copy this into this file as a 
> > comment.
> Would line table work just fine without your fix since the good address comes 
> first? Or do we end up with multiple locations? I thought I remembered you 
> thinking that it would pick the first one. Am I remembering correctly?
yeah, I was wrong, they end up being order by address, so the issue is there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87172

___
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-09-04 Thread António Afonso via Phabricator via lldb-commits
aadsm added inline comments.



Comment at: 
lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:2265-2267
+auto base_address = func_range.GetBaseAddress();
+if (base_address.IsSectionOffset() &&
+base_address.GetSection()->GetType() == eSectionTypeCode) {

clayborg wrote:
> This is a bit more expensive than comparing against the m_first_code_address 
> like we do in D87172. We could just modify the "if" statement on line 2256:
> 
> ```
> if (lowest_func_addr >= m_first_code_address && 
> lowest_func_addr != LLDB_INVALID_ADDRESS &&
> lowest_func_addr <= highest_func_addr) {
> ```
yeah, I was not expecting to matter that much since it's only 2 function calls?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87173

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


[Lldb-commits] [PATCH] D87172: Check if debug line sequences are starting after the first code segment

2020-09-05 Thread António Afonso via Phabricator via lldb-commits
aadsm added inline comments.



Comment at: lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp:74
   // codes that start at 1, that we get O(1) access.
-  
+
   const auto byte_order = eByteOrderLittle;

clayborg wrote:
> remove whitespace only changes please. Ditto for all whitespace only changes 
> below.
Can I make an argument to allow this on diffs? Most repos have a no trailing 
whitespace rule and because of this most editors are configured to remote 
trailing whitespaces on save. I've also just checked this is the case for LLVM: 
https://llvm.org/docs/CodingStandards.html#whitespace

I can either:
1) git add -i (which is a pain), or
2) configure my editor to not remove trailing white spaces for this project 
(which I guess it should be fine since clang-format takes care of it in the end)

Doing 2) is pretty easy to me (but it also means everyone else has to do it), 
since LLVM code convention is to disallow trailing whitespaces I could split 
this into 2 diffs, one with the bug fix and another one with trailing 
whitespace removal only (so no one else has the same problem with this file in 
the future). I don't see what is the advantage of having 2 diffs (just more 
work) so that's why I'm making the case to allow removal of trailing 
whitespaces in the files of a diff.

What do you think?





Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87172

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


[Lldb-commits] [PATCH] D87172: Check if debug line sequences are starting after the first code segment

2020-09-05 Thread António Afonso via Phabricator via lldb-commits
aadsm updated this revision to Diff 290112.
aadsm added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87172

Files:
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/unittests/SymbolFile/DWARF/CMakeLists.txt
  lldb/unittests/SymbolFile/DWARF/Inputs/test-invalid-addresses.yaml
  lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp

Index: lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
@@ -14,6 +14,7 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 
+#include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h"
 #include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
 #include "Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDataExtractor.h"
@@ -40,8 +41,8 @@
 using namespace lldb_private;
 
 class SymbolFileDWARFTests : public testing::Test {
-  SubsystemRAII
+  SubsystemRAII
   subsystems;
 
 public:
@@ -70,7 +71,7 @@
 TEST_F(SymbolFileDWARFTests, TestAbbrevOrder1Start1) {
   // Test that if we have a .debug_abbrev that contains ordered abbreviation
   // codes that start at 1, that we get O(1) access.
-  
+
   const auto byte_order = eByteOrderLittle;
   const uint8_t addr_size = 4;
   StreamString encoder(Stream::eBinary, addr_size, byte_order);
@@ -81,7 +82,7 @@
   encoder.PutULEB128(DW_FORM_strp);
   encoder.PutULEB128(0);
   encoder.PutULEB128(0);
-  
+
   encoder.PutULEB128(2); // Abbrev code 2
   encoder.PutULEB128(DW_TAG_subprogram);
   encoder.PutHex8(DW_CHILDREN_no);
@@ -89,9 +90,9 @@
   encoder.PutULEB128(DW_FORM_strp);
   encoder.PutULEB128(0);
   encoder.PutULEB128(0);
-  
+
   encoder.PutULEB128(0); // Abbrev code 0 (termination)
- 
+
   DWARFDataExtractor data;
   data.SetData(encoder.GetData(), encoder.GetSize(), byte_order);
   DWARFAbbreviationDeclarationSet abbrev_set;
@@ -101,7 +102,7 @@
   // Make sure we have O(1) access to each abbreviation by making sure the
   // index offset is 1 and not UINT32_MAX
   EXPECT_EQ(abbrev_set.GetIndexOffset(), 1u);
-  
+
   auto abbrev1 = abbrev_set.GetAbbreviationDeclaration(1);
   EXPECT_EQ(abbrev1->Tag(), DW_TAG_compile_unit);
   EXPECT_TRUE(abbrev1->HasChildren());
@@ -115,7 +116,7 @@
 TEST_F(SymbolFileDWARFTests, TestAbbrevOrder1Start5) {
   // Test that if we have a .debug_abbrev that contains ordered abbreviation
   // codes that start at 5, that we get O(1) access.
-  
+
   const auto byte_order = eByteOrderLittle;
   const uint8_t addr_size = 4;
   StreamString encoder(Stream::eBinary, addr_size, byte_order);
@@ -126,7 +127,7 @@
   encoder.PutULEB128(DW_FORM_strp);
   encoder.PutULEB128(0);
   encoder.PutULEB128(0);
-  
+
   encoder.PutULEB128(6); // Abbrev code 6
   encoder.PutULEB128(DW_TAG_subprogram);
   encoder.PutHex8(DW_CHILDREN_no);
@@ -134,9 +135,9 @@
   encoder.PutULEB128(DW_FORM_strp);
   encoder.PutULEB128(0);
   encoder.PutULEB128(0);
-  
+
   encoder.PutULEB128(0); // Abbrev code 0 (termination)
-  
+
   DWARFDataExtractor data;
   data.SetData(encoder.GetData(), encoder.GetSize(), byte_order);
   DWARFAbbreviationDeclarationSet abbrev_set;
@@ -146,7 +147,7 @@
   // Make sure we have O(1) access to each abbreviation by making sure the
   // index offset is 5 and not UINT32_MAX
   EXPECT_EQ(abbrev_set.GetIndexOffset(), 5u);
-  
+
   auto abbrev1 = abbrev_set.GetAbbreviationDeclaration(5);
   EXPECT_EQ(abbrev1->Tag(), DW_TAG_compile_unit);
   EXPECT_TRUE(abbrev1->HasChildren());
@@ -160,7 +161,7 @@
 TEST_F(SymbolFileDWARFTests, TestAbbrevOutOfOrder) {
   // Test that if we have a .debug_abbrev that contains unordered abbreviation
   // codes, that we can access the information correctly.
-  
+
   const auto byte_order = eByteOrderLittle;
   const uint8_t addr_size = 4;
   StreamString encoder(Stream::eBinary, addr_size, byte_order);
@@ -171,7 +172,7 @@
   encoder.PutULEB128(DW_FORM_strp);
   encoder.PutULEB128(0);
   encoder.PutULEB128(0);
-  
+
   encoder.PutULEB128(1); // Abbrev code 1
   encoder.PutULEB128(DW_TAG_subprogram);
   encoder.PutHex8(DW_CHILDREN_no);
@@ -179,9 +180,9 @@
   encoder.PutULEB128(DW_FORM_strp);
   encoder.PutULEB128(0);
   encoder.PutULEB128(0);
-  
+
   encoder.PutULEB128(0); // Abbrev code 0 (termination)
-  
+
   DWARFDataExtractor data;
   data.SetData(encoder.GetData(), encoder.GetSize(), byte_order);
   DWARFAbbreviationDeclarationSet abbrev_set;
@@ -191,7 +192,7 @@
   // Make sure we don't have O(1) access to each abbreviation by making sure
   // the index offset is UINT32_MAX
   EXPECT_EQ(abbrev_set.GetIndexOffset(), UINT32_MAX);
-  
+
   auto abbrev1 = abbrev_set.GetAbbreviationDeclaration(2);
   EXPECT_EQ(abbrev1->Tag(), DW_TAG_compile_un

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

2020-09-05 Thread António Afonso via Phabricator via lldb-commits
aadsm updated this revision to Diff 290113.
aadsm added a comment.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.

Check lowest code address instead of checking if the section is code.


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/unittests/SymbolFile/DWARF/Inputs/test-invalid-addresses.yaml
  lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp

Index: lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
===
--- lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
@@ -35,14 +35,16 @@
 #include "lldb/Utility/ArchSpec.h"
 #include "lldb/Utility/DataEncoder.h"
 #include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/Reproducer.h"
 #include "lldb/Utility/StreamString.h"
 
 using namespace lldb;
 using namespace lldb_private;
 
 class SymbolFileDWARFTests : public testing::Test {
-  SubsystemRAII
+  SubsystemRAII
   subsystems;
 
 public:
@@ -367,3 +369,27 @@
   ASSERT_NE(section_sp.get(), nullptr);
   EXPECT_EQ(section_sp->GetType(), eSectionTypeCode);
 }
+
+TEST_F(SymbolFileDWARFTests, EnsureAllParseFunctionsExistInCodeSections) {
+  auto ExpectedFile = TestFile::fromYamlFile("test-invalid-offsets.yaml");
+  ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded());
+
+  lldb::ModuleSP module_sp =
+  std::make_shared(ExpectedFile->moduleSpec());
+  SymbolFile *symfile = module_sp->GetSymbolFile();
+  ASSERT_NE(symfile, nullptr);
+
+  SymbolContextList sc_list;
+  RegularExpression regex(".");
+  symfile->FindFunctions(regex, false, sc_list);
+  ASSERT_EQ(sc_list.GetSize(), 1U);
+
+  SymbolContext sc;
+  sc_list.GetContextAtIndex(0, sc);
+  EXPECT_STREQ(sc.function->GetName().AsCString(), "main");
+
+  auto section_sp =
+  sc.function->GetAddressRange().GetBaseAddress().GetSection();
+  ASSERT_NE(section_sp.get(), nullptr);
+  EXPECT_EQ(section_sp->GetType(), eSectionTypeCode);
+}
Index: lldb/unittests/SymbolFile/DWARF/Inputs/test-invalid-addresses.yaml
===
--- lldb/unittests/SymbolFile/DWARF/Inputs/test-invalid-addresses.yaml
+++ lldb/unittests/SymbolFile/DWARF/Inputs/test-invalid-addresses.yaml
@@ -420,8 +420,8 @@
 - Value:   0x00010F80
 - Value:   0x0030
 - AbbrCode:0x0002
-  Values:
-- Value:   0x00010F80
+  Values: # DW_TAG_subprogram foo
+- Value:   0x0F80 # DW_AT_low_pc points to invalid loc
 - Value:   0x000B
 - Value:   0x0001
   BlockData:   [ 0x56 ]
@@ -432,7 +432,7 @@
 - Value:   0x006F
 - Value:   0x0001
 - AbbrCode:0x0003
-  Values:
+  Values: # DW_TAG_subprogram main
 - Value:   0x00010F90
 - Value:   0x0020
 - Value:   0x0001
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -779,7 +779,8 @@
   if (!dwarf_ast)
 return nullptr;
 
-  return dwarf_ast->ParseFunctionFromDWARF(comp_unit, die);
+  return dwarf_ast->ParseFunctionFromDWARF(comp_unit, die,
+   m_first_code_address);
 }
 
 lldb::addr_t SymbolFileDWARF::FixupAddress(lldb::addr_t file_addr) {
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
@@ -47,7 +47,8 @@
 
   lldb_private::Function *
   ParseFunctionFromDWARF(lldb_private::CompileUnit &comp_unit,
- const DWARFDIE &die) override;
+ const DWARFDIE &die,
+ lldb::addr_t first_code_address) override;
 
   bool
   CompleteTypeFromDWARF(const DWARFDIE &die, lldb_private::Type *type,
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -2226,8 +2226,10 @@
   retur

[Lldb-commits] [PATCH] D87868: [RFC] When calling the process mmap try to call all found instead of just the first one

2020-09-17 Thread António Afonso via Phabricator via lldb-commits
aadsm created this revision.
aadsm added reviewers: clayborg, jingham, JDevlieghere.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.
aadsm requested review of this revision.

I found an issue where the expression evaluation doesn't work (for non trivial 
exprs) when the leak sanitizer is enabled in the process being debugged.
lldb defaults to interpertation because it thinks it can't JIT it (and most 
interesting exprs can't be interpreted). The JIT check fails because calling 
the process's mmap fails.

I debugged the InferiorCallMmap function to figure this out. This function 
finds all functions with mmap name in it and executes the first one in that 
list.
When asan is enabled (and by default on linux it turns on the leak sanitizer) 
it introduces a new mmap symbol in the binary (the only that will be called 
instead of the real one). This can be found here: 
https://github.com/llvm/llvm-project/blob/master/compiler-rt/lib/sanitizer_common/symbolizer/sanitizer_wrappers.cpp#L155-L160.
 And there is also another new function named __interceptor_mmap which 
registers the call for the sanitizer I think. You can find that one here (I 
think): 
https://github.com/llvm/llvm-project/blob/6148cca70888ead020a808279043fd013ca72a2a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc#L7304-L7313.

When lldb calls the redefined mmap it will return -1 but will be able to 
allocate memory if it calls the __interceptor_mmap though. Both functions end 
up calling __internal_mmap but the big difference between the two is that the 
redefiend mmap also checks the return of internal_mmap with `internal_iserror` 
and will return -1 when it fails the check. Here's the code for that: 
https://github.com/llvm/llvm-project/blob/6148cca70888ead020a808279043fd013ca72a2a/compiler-rt/lib/sanitizer_common/sanitizer_syscall_linux_x86_64.inc#L83-L90.
 Not really sure why to be honest. I tried to debug but it was not simple 
inside the ThreadPlanCallFunction, I tried to enable SINGLE_STEP_EXPRESSIONS 
but then the process kind of dies on me.

I came up with a simple fix to get around this which is to try each mmap we 
find (and not only the first one) until we find one that works. Another 
possible solution is to see if  internal_mmap exists and call that one if it 
does.. I feel it's a bit more implementation dependent though, while the loop 
sounds more future proof (I'm assuming calling a bunch of mmaps until one 
actually works won't launch missiles).

Thoughts?

(This implemention is not final, it should be possible to move a bunch of 
things out of the loop I believe)
Not really sure how to add for review so adding a few people I've seen in the 
code.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87868

Files:
  lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp


Index: lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
===
--- lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
+++ lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
@@ -48,9 +48,9 @@
   ConstString("mmap"), eFunctionNameTypeFull, include_symbols,
   include_inlines, sc_list);
   const uint32_t count = sc_list.GetSize();
-  if (count > 0) {
+  for (uint32_t i = 0; i < count; i++) {
 SymbolContext sc;
-if (sc_list.GetContextAtIndex(0, sc)) {
+if (sc_list.GetContextAtIndex(i, sc)) {
   const uint32_t range_scope =
   eSymbolContextFunction | eSymbolContextSymbol;
   const bool use_inline_block_range = false;
@@ -112,10 +112,10 @@
   LLDB_INVALID_ADDRESS);
   if (process->GetAddressByteSize() == 4) {
 if (allocated_addr == UINT32_MAX)
-  return false;
+  continue;
   } else if (process->GetAddressByteSize() == 8) {
 if (allocated_addr == UINT64_MAX)
-  return false;
+  continue;
   }
   return true;
 }


Index: lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
===
--- lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
+++ lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
@@ -48,9 +48,9 @@
   ConstString("mmap"), eFunctionNameTypeFull, include_symbols,
   include_inlines, sc_list);
   const uint32_t count = sc_list.GetSize();
-  if (count > 0) {
+  for (uint32_t i = 0; i < count; i++) {
 SymbolContext sc;
-if (sc_list.GetContextAtIndex(0, sc)) {
+if (sc_list.GetContextAtIndex(i, sc)) {
   const uint32_t range_scope =
   eSymbolContextFunction | eSymbolContextSymbol;
   const bool use_inline_block_range = false;
@@ -112,10 +112,10 @@
   LLDB_INVALID_ADDRESS);
   if (process->GetAddressByteSize() == 4) {
 if (allocated_addr == UINT32_MAX)
-   

[Lldb-commits] [PATCH] D87172: Check if debug line sequences are starting after the first code segment

2020-09-20 Thread António Afonso via Phabricator via lldb-commits
aadsm added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h:520
   std::vector m_lldb_cu_to_dwarf_unit;
+  lldb::addr_t m_first_code_address = LLDB_INVALID_ADDRESS;
 };

labath wrote:
> clayborg wrote:
> > A lengthy comment would be great here. Maybe something like:
> > 
> > ```
> > /// Many linkers will concatenate all available DWARF, even if parts of 
> > that DWARF
> > /// should have been dead stripped. Some linkers will place tombstone 
> > values in for
> > /// addresses that should have been dead stripped, with a value like -1 or 
> > -2. But many
> > /// linkers will apply a relocation and attempt to set the value to zero. 
> > This is problematic
> > /// in that we can end up with many addresses that are zero or close to 
> > zero due to there
> > /// being an addend on the relocation whose base is at zero. Here we 
> > attempt to avoid 
> > /// addresses that are zero or close to zero by finding the first valid 
> > code address by looking
> > /// at the sections and finding the first one that has read + execute 
> > permissions. This allows
> > /// us to do a quick and cheap comparison against this address when parsing 
> > line tables and
> > /// parsing functions where the DWARF should have been dead stripped.
> > ```
> To me, "should have been stripped" implies that the linkers are doing 
> something wrong, as if they were required to parse and rewrite the dwarf in 
> the input files. However, there is nothing in the DWARF or ELF specs that 
> would support that, and the linkers are simply doing what the specs say, and 
> what linkers have been doing since the dawn of time -- concatenate things.
> 
> It would be better to just state the facts here, instead of passing judgement 
> (or make an appearance of doing that).
@clayborg can you clarify this comment like @labath suggests?



Comment at: 
lldb/unittests/SymbolFile/DWARF/Inputs/test-invalid-addresses.yaml:203-254
+  - sectname:__apple_names
+segname: __DWARF
+addr:0x0001223C
+size:116
+offset:  0x223C
+align:   0
+reloff:  0x

labath wrote:
> I guess these (and debug_pub(types/names), and possible debug_aranges) are 
> not really needed for this test.
I changed the line table by hand but forgot to add comments there.



Comment at: lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp:349-369
+
+TEST_F(SymbolFileDWARFTests, EnsureLineEntriesExistInAfterFirstCodeSection) {
+  auto ExpectedFile = TestFile::fromYamlFile("test-invalid-addresses.yaml");
+  ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded());
+
+  lldb::ModuleSP module_sp =
+  std::make_shared(ExpectedFile->moduleSpec());

labath wrote:
> I think this would be better as a shell test (if for nothing else, then 
> because other line table tests are written that way). `image lookup` is 
> pretty much a direct equivalent to `ResolveSymbolContext`, but its output is 
> more readable, and its easier to fiddle with these kinds of tests.
I think what you describe is an end to end test but here I explicitly want to 
test the SymbolFileDWARF code because that's what I changed, it's more like a 
unit test.
I would prefer to stay away from an end to end test for this particular change 
because 1) knowing that `image lookup` calls `ResolveSymbolContext` is an 
implementation detail 2) The output of `image lookup` could change over time, 
3) Other bugs unrelated to this could be introduced that will make `image 
lookup` show a different content as well and fail the test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87172

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


[Lldb-commits] [PATCH] D80659: [lldb-vscode] Redirect stderr and stdout to DAPs console message

2020-09-20 Thread António Afonso via Phabricator via lldb-commits
aadsm added a comment.

> Why would we be doing something (particularly a thing which will be hard to 
> do in a cross-platform manner, and will very likely border on, or downright 
> cross into, undefined behavior territory), if we get that from vscode for 
> free?

I'm not sure what you mean with get this for free on vscode... Right now 
lldb-vscode will just crash if there's any command in the lldbinit that outputs 
to stdout because it pollutes the protocol, I don't think think there's 
anything vscode can do about this. But even if it did vscode is not the only 
client of lldb-vscode, there are multiple others: 
https://microsoft.github.io/debug-adapter-protocol/implementors/tools/.

I haven't answered this yet because I was trying to figure out why this only 
happens when parsing the lldbinit. I was looking into the 
CommandInterpreter{Python} code but to be honest it's not easy to figure out 
because there are multiple levels of indirection when it comes to processing 
the IO of the python interpreter, but it seems that the stdout while executing 
the lldbinit script is being flushed right away to the ImmediateOutputStream 
but haven't figure out when this is set in the case of 
`CommandInterpreter::IOHandlerInputComplete`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80659

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


[Lldb-commits] [PATCH] D87868: [RFC] When calling the process mmap try to call all found instead of just the first one

2020-09-21 Thread António Afonso via Phabricator via lldb-commits
aadsm added a comment.



> It seems like calling any 'mmap' definition should work. Is the interposed 
> mmap implementation failing and correctly returning -1, or is it succeeding 
> and incorrectly returning -1? In either case, it seems like it's worth 
> digging into why it's failing / returning the wrong result

@vsk, yeah, this is what I've tried to do before I submitted this diff. It 
should work because it works when lldb is not attached. I wanted to step into 
it (by defining SINGLE_STEP_EXPRESSIONS) and see what's going on but the 
process crashes on me when I do that. It has to work just because if I call 
`__interceptor_mmap` it works and the only difference between those two is that 
one calls `internal_iserror`. InferiorCallMmap uses ThreadPlanCallFunction 
which seems to ignore breakpoints because it uses the subplan "run to address" 
that makes sure it only stops at the address given so it has been hard to put a 
breakpoint there. The only exception to this is when I define the 
SINGLE_STEP_EXPRESSIONS but like I said the process crashes or something, don't 
remember anymore. I can try again.

@clayborg I'll try that.

Thanks everyone for their input, I'll follow up on this next week because right 
now I'm on vacation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87868

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


[Lldb-commits] [PATCH] D87868: [RFC] When calling the process mmap try to call all found instead of just the first one

2020-10-05 Thread António Afonso via Phabricator via lldb-commits
aadsm updated this revision to Diff 296220.
aadsm added a comment.

I explored Greg's suggestion of checking if the functions were external 
symbols. As suspected the overriden mmap is not external, so we can use this 
check to avoid calling it!

It does look to me that Pavel's suggestion is the way to go in the future but I 
don't have the knowledge to implement the suggestion nor (unfortunately) the 
bandwidth to gain that knowledge right. In the meanwhile I was hoping we could 
go with this new version of the patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87868

Files:
  lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp


Index: lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
===
--- lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
+++ lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
@@ -48,9 +48,10 @@
   ConstString("mmap"), eFunctionNameTypeFull, include_symbols,
   include_inlines, sc_list);
   const uint32_t count = sc_list.GetSize();
-  if (count > 0) {
+  for (uint32_t i = 0; i < count; i++) {
 SymbolContext sc;
-if (sc_list.GetContextAtIndex(0, sc)) {
+if (sc_list.GetContextAtIndex(i, sc) &&
+(sc.symbol->IsExternal() || sc.symbol->IsWeak())) {
   const uint32_t range_scope =
   eSymbolContextFunction | eSymbolContextSymbol;
   const bool use_inline_block_range = false;


Index: lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
===
--- lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
+++ lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
@@ -48,9 +48,10 @@
   ConstString("mmap"), eFunctionNameTypeFull, include_symbols,
   include_inlines, sc_list);
   const uint32_t count = sc_list.GetSize();
-  if (count > 0) {
+  for (uint32_t i = 0; i < count; i++) {
 SymbolContext sc;
-if (sc_list.GetContextAtIndex(0, sc)) {
+if (sc_list.GetContextAtIndex(i, sc) &&
+(sc.symbol->IsExternal() || sc.symbol->IsWeak())) {
   const uint32_t range_scope =
   eSymbolContextFunction | eSymbolContextSymbol;
   const bool use_inline_block_range = false;
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D87868: [RFC] When calling the process mmap try to call all found instead of just the first one

2020-10-05 Thread António Afonso via Phabricator via lldb-commits
aadsm added inline comments.



Comment at: lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp:54
+if (sc_list.GetContextAtIndex(i, sc) &&
+(sc.symbol->IsExternal() || sc.symbol->IsWeak())) {
   const uint32_t range_scope =

clayborg wrote:
> Why are we checking "IsWeak()" here?
A weak symbol is also an external symbol, but it's weak in the sense that 
another external symbol with the same name will take precedence over it (as far 
as I understood).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87868

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


[Lldb-commits] [PATCH] D87868: [RFC] When calling the process mmap try to call all found instead of just the first one

2020-10-06 Thread António Afonso via Phabricator via lldb-commits
aadsm added inline comments.



Comment at: lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp:54
+if (sc_list.GetContextAtIndex(i, sc) &&
+(sc.symbol->IsExternal() || sc.symbol->IsWeak())) {
   const uint32_t range_scope =

labath wrote:
> clayborg wrote:
> > aadsm wrote:
> > > clayborg wrote:
> > > > Why are we checking "IsWeak()" here?
> > > A weak symbol is also an external symbol, but it's weak in the sense that 
> > > another external symbol with the same name will take precedence over it 
> > > (as far as I understood).
> > I think we only need to check for external here. Any weak symbol will also 
> > need to be external, but if it isn't we don't want that symbol.
> Your understanding is correct, at least at the object file level -- I'm not 
> sure whether `IsWeak()` implies `IsExternal()` inside lldb. However, I would 
> actually argue for removal of IsWeak() for a different reason -- any weak 
> definition of mmap is not going to be used by the process since libc already 
> has a strong definition of that symbol.
> 
> If we really end up in a situation where we only have a weak mmap symbol 
> around, then this is probably a sufficiently strange setup that we don't want 
> to be randomly calling that function.
All (with the exception of the one overriden by the leak sanitizer) mmap 
symbols in the symbol table are Weak bound but none are External bound, this 
was the main reason that lead me to investigate the difference between the two.

Not sure how to check how lldb interprets the Weak overall, but I think it kind 
of does, because that's what I saw when I dumped the symbol table:
```
(lldb) target modules dump symtab libc.so.6
   Debug symbol
   |Synthetic symbol
   ||Externally Visible
   |||
Index   UserID DSX TypeFile Address/Value Load Address   Size   
Flags  Name
--- -- --- --- -- -- 
-- -- --
...
[ 6945]   6947   X Code0x0010b5e0 0x769db5e0 
0x00f9 0x0012 __mmap
...
```

Another solution I thought was to add a IsLocal to the Symbol (and use 
!IsLocal) but then not really sure how to implement this for all Symbols not 
ELFSymbol.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87868

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


[Lldb-commits] [PATCH] D87868: [RFC] When calling the process mmap try to call all found instead of just the first one

2020-10-06 Thread António Afonso via Phabricator via lldb-commits
aadsm added inline comments.



Comment at: lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp:36
 
 bool lldb_private::InferiorCallMmap(Process *process, addr_t &allocated_addr,
 addr_t addr, addr_t length, unsigned prot,

clayborg wrote:
> Might be nice to return a llvm::Error here instead of pool? Maybe to help 
> explain what went wrong? like any of:
> 
> "thread required to call mmap"
> "couldn't find any symbols named 'mmap'"
> "no external symbols named 'mmap' were found"
> "mmap call failed" (for when it returns UINT32_MAX for 4 byte addresses or 
> UINT64_MAX for 8 byte addresses"
> 
> It have been nice to see a nice error message during the expression 
> evaluation prior to this fix. At the very least we should log to the 
> expression log channel that mmap failed if we choose not to return an error.
I'd prefer to make this part of another diff and focus this one on the fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87868

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


[Lldb-commits] [PATCH] D87172: Check if debug line sequences are starting after the first code segment

2020-10-18 Thread António Afonso via Phabricator via lldb-commits
aadsm updated this revision to Diff 298906.
aadsm added a comment.

Addressed all comments:

- Moved initialization code to InitializeObject
- Moved to lit test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87172

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

Index: lldb/test/Shell/SymbolFile/DWARF/line-entries-invalid-addresses.yaml
===
--- /dev/null
+++ lldb/test/Shell/SymbolFile/DWARF/line-entries-invalid-addresses.yaml
@@ -0,0 +1,420 @@
+# RUN: yaml2obj %s > %t
+# RUN: %lldb %t -b -o "image lookup -f main.cpp -l 2 -v" | FileCheck %s
+# CHECK: LineEntry: {{.*}}main.cpp:2:{{.*}}
+
+# int foo() {
+# return 42;
+# }
+#
+# int main() {
+# int x = foo();
+# return x;
+# }
+# dwarfdump -debug-line:
+# AddressLine   Column File   ISA Discriminator Flags
+# -- -- -- -- --- - -
+# 0x00010f80  1  0  1   0 0  is_stmt
+# 0x00010f84  2  5  1   0 0  is_stmt prologue_end
+# 0x00010f8b  2  5  1   0 0  is_stmt end_sequence
+# 0x00010f90  5  0  1   0 0  is_stmt
+# 0x00010f90  5  0  1   0 0  is_stmt end_sequence
+# 0x000f  2 13  1   0 0  is_stmt prologue_end
+# 0x0014  2  9  1   0 0
+# 0x0017  3 12  1   0 0  is_stmt
+# 0x001d  3 12  1   0 0  end_sequence
+--- !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:605D6BBF-4DB2-39F7-8068-F9BB3896DF0C
+  - 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: 37
+  - 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:  4096
+fileoff: 0
+filesize:0
+maxprot: 5
+initprot:5
+nsects:  2
+flags:   0
+Sections:
+  - sectname:__text
+segname: __TEXT
+addr:0x00010F80
+size:48
+offset:  0x
+align:   4
+reloff:  0x
+nreloc:  0
+flags:   0x8400
+reserved1:   0x
+reserved2:   0x
+reserved3:   0x
+content: CFFAEDFE070103000A00070078051B001800605D6BBF4DB239F7
+  - sectname:__unwind_info
+segname: __TEXT
+addr:0x00010FB0
+size:72
+offset:  0x
+align:   2
+reloff:  0x
+nreloc:  0
+flags:   0x
+reserved1:   0x
+reserved2:   0x
+reserved3:   0x
+content: CFFAEDFE070103000A00070078051B001800605D6BBF4DB239F78068F9BB3896DF0C32001800010F0A00
+  - cmd: LC_SEGMENT_64
+cmdsize: 72
+segname: __LINKEDIT
+vmaddr:  4294971392
+vmsize:  4096
+fileoff: 4096
+filesize:85
+maxprot: 1
+initprot:1
+nsects:  0
+flags:   0
+  - cmd: LC_SEGMENT_64
+cmdsize: 952
+segname: __DWARF
+vmaddr:  4294975488
+vmsize:  4096
+fileoff: 8192
+filesize:839
+maxprot: 7
+initprot:3
+nsects:  4
+flags:   0
+Sections:
+  - sectname:__debug_line
+segname: __DWARF
+ad

[Lldb-commits] [PATCH] D68069: Explicitly set entry point arch when it's thumb

2019-09-27 Thread António Afonso via Phabricator via lldb-commits
aadsm added a comment.

>   Not everyone has both of these things enabled (particularly having lld is 
> less common), but they are things that one _can_ enable no matter what is his 
> host or target architecture, so I am not worried by that. And as tests like 
> these become more common, I expect more people will start having these 
> enabled by default.

Will the tests running on the build bots have lld, arm enabled?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68069



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


[Lldb-commits] [PATCH] D68069: Explicitly set entry point arch when it's thumb

2019-09-27 Thread António Afonso via Phabricator via lldb-commits
aadsm added a comment.

>   (substituting llvm-mc for as and ld.lld for linker).

I was not able to figure out how to generate the object file with llvm-mc 
correctly. I've tried a few variations of the triple (e.g.: `armv7-eabi`) but I 
never end up with the same code that I have in the assembly: `# RUN: llvm-mc 
-triple=thumbv7 %s -filetype=obj -o %t.o`. Any idea here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68069



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


[Lldb-commits] [PATCH] D68069: Explicitly set entry point arch when it's thumb

2019-09-30 Thread António Afonso via Phabricator via lldb-commits
aadsm updated this revision to Diff 222490.
aadsm added a comment.

Add lit test to check dissassembly


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68069

Files:
  lldb/lit/SymbolFile/dissassemble-entry-point.s
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp

Index: lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
===
--- lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
+++ lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
@@ -172,3 +172,131 @@
   Uuid.SetFromStringRef("1b8a73ac238390e32a7ff4ac8ebe4d6a41ecf5c9", 20);
   EXPECT_EQ(Spec.GetUUID(), Uuid);
 }
+
+TEST_F(ObjectFileELFTest, GetSymtab_NoSymEntryPointArmThumbAddressClass) {
+  /*
+  // nosym-entrypoint-arm-thumb.s
+  .global _Start
+  .thumb_func
+  _start:
+  mov r0, #42
+  mov r7, #1
+  svc #0
+  // arm-linux-androideabi-as nosym-entrypoint-arm-thumb.s
+  //   -o nosym-entrypoint-arm-thumb.o
+  // arm-linux-androideabi-ld nosym-entrypoint-arm-thumb.o
+  //   -o nosym-entrypoint-arm-thumb -e 0x8075 -s
+  */
+  auto ExpectedFile = TestFile::fromYaml(R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_ARM
+  Flags:   [ EF_ARM_SOFT_FLOAT, EF_ARM_EABI_VER5 ]
+  Entry:   0x8075
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+Address: 0x8074
+AddressAlign:0x0002
+Content: 2A20012700DF
+  - Name:.data
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+Content: ''
+  - Name:.bss
+Type:SHT_NOBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+  - Name:.note.gnu.gold-version
+Type:SHT_NOTE
+AddressAlign:0x0004
+Content: 040009000400474E5500676F6C6420312E313100
+  - Name:.ARM.attributes
+Type:SHT_ARM_ATTRIBUTES
+AddressAlign:0x0001
+Content: '41130061656162690001090006020901'
+...
+)");
+  ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded());
+
+  ModuleSpec spec{FileSpec(ExpectedFile->name())};
+  spec.GetSymbolFileSpec().SetFile(ExpectedFile->name(),
+   FileSpec::Style::native);
+  auto module_sp = std::make_shared(spec);
+
+  auto entry_point_addr = module_sp->GetObjectFile()->GetEntryPointAddress();
+  ASSERT_TRUE(entry_point_addr.GetOffset() & 1);
+  // Decrease the offsite by 1 to make it into a breakable address since this
+  // is Thumb.
+  entry_point_addr.SetOffset(entry_point_addr.GetOffset() - 1);
+  ASSERT_EQ(entry_point_addr.GetAddressClass(),
+AddressClass::eCodeAlternateISA);
+}
+
+TEST_F(ObjectFileELFTest, GetSymtab_NoSymEntryPointArmAddressClass) {
+  /*
+  // nosym-entrypoint-arm.s
+  .global _Start
+  _start:
+  movs r0, #42
+  movs r7, #1
+  svc #0
+  // arm-linux-androideabi-as nosym-entrypoint-arm.s
+  //   -o nosym-entrypoint-arm.o
+  // arm-linux-androideabi-ld nosym-entrypoint-arm.o
+  //   -o nosym-entrypoint-arm -e 0x8074 -s
+  */
+  auto ExpectedFile = TestFile::fromYaml(R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_ARM
+  Flags:   [ EF_ARM_SOFT_FLOAT, EF_ARM_EABI_VER5 ]
+  Entry:   0x8074
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+Address: 0x8074
+AddressAlign:0x0004
+Content: 2A00A0E30170A0E300EF
+  - Name:.data
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+Content: ''
+  - Name:.bss
+Type:SHT_NOBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+  - Name:.note.gnu.gold-version
+Type:SHT_NOTE
+AddressAlign:0x0004
+Content: 040009000400474E5500676F6C6420312E313100
+  - Name:.ARM.attributes
+Type:SHT_ARM_ATTRIBUTES
+AddressAlign:0x0001
+Content: '41130061656162690001090006010801'
+...
+)");
+  ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded());
+
+  ModuleSpe

[Lldb-commits] [PATCH] D68069: Explicitly set entry point arch when it's thumb

2019-10-01 Thread António Afonso via Phabricator via lldb-commits
aadsm updated this revision to Diff 222680.
aadsm added a comment.

Update tests and fix logic to correctly add the symtab entry.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68069

Files:
  lldb/lit/SymbolFile/dissassemble-entry-point.s
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp

Index: lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
===
--- lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
+++ lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
@@ -172,3 +172,131 @@
   Uuid.SetFromStringRef("1b8a73ac238390e32a7ff4ac8ebe4d6a41ecf5c9", 20);
   EXPECT_EQ(Spec.GetUUID(), Uuid);
 }
+
+TEST_F(ObjectFileELFTest, GetSymtab_NoSymEntryPointArmThumbAddressClass) {
+  /*
+  // nosym-entrypoint-arm-thumb.s
+  .global _Start
+  .thumb_func
+  _start:
+  mov r0, #42
+  mov r7, #1
+  svc #0
+  // arm-linux-androideabi-as nosym-entrypoint-arm-thumb.s
+  //   -o nosym-entrypoint-arm-thumb.o
+  // arm-linux-androideabi-ld nosym-entrypoint-arm-thumb.o
+  //   -o nosym-entrypoint-arm-thumb -e 0x8075 -s
+  */
+  auto ExpectedFile = TestFile::fromYaml(R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_ARM
+  Flags:   [ EF_ARM_SOFT_FLOAT, EF_ARM_EABI_VER5 ]
+  Entry:   0x8075
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+Address: 0x8074
+AddressAlign:0x0002
+Content: 2A20012700DF
+  - Name:.data
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+Content: ''
+  - Name:.bss
+Type:SHT_NOBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+  - Name:.note.gnu.gold-version
+Type:SHT_NOTE
+AddressAlign:0x0004
+Content: 040009000400474E5500676F6C6420312E313100
+  - Name:.ARM.attributes
+Type:SHT_ARM_ATTRIBUTES
+AddressAlign:0x0001
+Content: '41130061656162690001090006020901'
+...
+)");
+  ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded());
+
+  ModuleSpec spec{FileSpec(ExpectedFile->name())};
+  spec.GetSymbolFileSpec().SetFile(ExpectedFile->name(),
+   FileSpec::Style::native);
+  auto module_sp = std::make_shared(spec);
+
+  auto entry_point_addr = module_sp->GetObjectFile()->GetEntryPointAddress();
+  ASSERT_TRUE(entry_point_addr.GetOffset() & 1);
+  // Decrease the offsite by 1 to make it into a breakable address since this
+  // is Thumb.
+  entry_point_addr.SetOffset(entry_point_addr.GetOffset() - 1);
+  ASSERT_EQ(entry_point_addr.GetAddressClass(),
+AddressClass::eCodeAlternateISA);
+}
+
+TEST_F(ObjectFileELFTest, GetSymtab_NoSymEntryPointArmAddressClass) {
+  /*
+  // nosym-entrypoint-arm.s
+  .global _Start
+  _start:
+  movs r0, #42
+  movs r7, #1
+  svc #0
+  // arm-linux-androideabi-as nosym-entrypoint-arm.s
+  //   -o nosym-entrypoint-arm.o
+  // arm-linux-androideabi-ld nosym-entrypoint-arm.o
+  //   -o nosym-entrypoint-arm -e 0x8074 -s
+  */
+  auto ExpectedFile = TestFile::fromYaml(R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_ARM
+  Flags:   [ EF_ARM_SOFT_FLOAT, EF_ARM_EABI_VER5 ]
+  Entry:   0x8074
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+Address: 0x8074
+AddressAlign:0x0004
+Content: 2A00A0E30170A0E300EF
+  - Name:.data
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+Content: ''
+  - Name:.bss
+Type:SHT_NOBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+  - Name:.note.gnu.gold-version
+Type:SHT_NOTE
+AddressAlign:0x0004
+Content: 040009000400474E5500676F6C6420312E313100
+  - Name:.ARM.attributes
+Type:SHT_ARM_ATTRIBUTES
+AddressAlign:0x0001
+Content: '41130061656162690001090006010801'
+...
+)");
+  ASSERT_THAT_EXPECTED(ExpectedFile, llvm::S

[Lldb-commits] [PATCH] D68069: Explicitly set entry point arch when it's thumb

2019-10-02 Thread António Afonso via Phabricator via lldb-commits
aadsm added a comment.

I actually just completely missed the first comment on the .s test and forgot 
about the comment 😇.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68069



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


[Lldb-commits] [PATCH] D68069: Explicitly set entry point arch when it's thumb

2019-10-02 Thread António Afonso via Phabricator via lldb-commits
aadsm updated this revision to Diff 222848.
aadsm added a comment.

Update comment and test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68069

Files:
  lldb/lit/SymbolFile/dissassemble-entry-point.s
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp

Index: lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
===
--- lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
+++ lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
@@ -172,3 +172,131 @@
   Uuid.SetFromStringRef("1b8a73ac238390e32a7ff4ac8ebe4d6a41ecf5c9", 20);
   EXPECT_EQ(Spec.GetUUID(), Uuid);
 }
+
+TEST_F(ObjectFileELFTest, GetSymtab_NoSymEntryPointArmThumbAddressClass) {
+  /*
+  // nosym-entrypoint-arm-thumb.s
+  .global _Start
+  .thumb_func
+  _start:
+  mov r0, #42
+  mov r7, #1
+  svc #0
+  // arm-linux-androideabi-as nosym-entrypoint-arm-thumb.s
+  //   -o nosym-entrypoint-arm-thumb.o
+  // arm-linux-androideabi-ld nosym-entrypoint-arm-thumb.o
+  //   -o nosym-entrypoint-arm-thumb -e 0x8075 -s
+  */
+  auto ExpectedFile = TestFile::fromYaml(R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_ARM
+  Flags:   [ EF_ARM_SOFT_FLOAT, EF_ARM_EABI_VER5 ]
+  Entry:   0x8075
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+Address: 0x8074
+AddressAlign:0x0002
+Content: 2A20012700DF
+  - Name:.data
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+Content: ''
+  - Name:.bss
+Type:SHT_NOBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+  - Name:.note.gnu.gold-version
+Type:SHT_NOTE
+AddressAlign:0x0004
+Content: 040009000400474E5500676F6C6420312E313100
+  - Name:.ARM.attributes
+Type:SHT_ARM_ATTRIBUTES
+AddressAlign:0x0001
+Content: '41130061656162690001090006020901'
+...
+)");
+  ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded());
+
+  ModuleSpec spec{FileSpec(ExpectedFile->name())};
+  spec.GetSymbolFileSpec().SetFile(ExpectedFile->name(),
+   FileSpec::Style::native);
+  auto module_sp = std::make_shared(spec);
+
+  auto entry_point_addr = module_sp->GetObjectFile()->GetEntryPointAddress();
+  ASSERT_TRUE(entry_point_addr.GetOffset() & 1);
+  // Decrease the offsite by 1 to make it into a breakable address since this
+  // is Thumb.
+  entry_point_addr.SetOffset(entry_point_addr.GetOffset() - 1);
+  ASSERT_EQ(entry_point_addr.GetAddressClass(),
+AddressClass::eCodeAlternateISA);
+}
+
+TEST_F(ObjectFileELFTest, GetSymtab_NoSymEntryPointArmAddressClass) {
+  /*
+  // nosym-entrypoint-arm.s
+  .global _Start
+  _start:
+  movs r0, #42
+  movs r7, #1
+  svc #0
+  // arm-linux-androideabi-as nosym-entrypoint-arm.s
+  //   -o nosym-entrypoint-arm.o
+  // arm-linux-androideabi-ld nosym-entrypoint-arm.o
+  //   -o nosym-entrypoint-arm -e 0x8074 -s
+  */
+  auto ExpectedFile = TestFile::fromYaml(R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_ARM
+  Flags:   [ EF_ARM_SOFT_FLOAT, EF_ARM_EABI_VER5 ]
+  Entry:   0x8074
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+Address: 0x8074
+AddressAlign:0x0004
+Content: 2A00A0E30170A0E300EF
+  - Name:.data
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+Content: ''
+  - Name:.bss
+Type:SHT_NOBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+  - Name:.note.gnu.gold-version
+Type:SHT_NOTE
+AddressAlign:0x0004
+Content: 040009000400474E5500676F6C6420312E313100
+  - Name:.ARM.attributes
+Type:SHT_ARM_ATTRIBUTES
+AddressAlign:0x0001
+Content: '41130061656162690001090006010801'
+...
+)");
+  ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded());
+
+  ModuleSpec spec{File

[Lldb-commits] [PATCH] D68370: Componentize lldb/scripts to use with LLVM_DISTRIBUTION_COMPONENTS

2019-10-02 Thread António Afonso via Phabricator via lldb-commits
aadsm created this revision.
aadsm added reviewers: labath, xiaobai, clayborg, lanza.
Herald added subscribers: lldb-commits, mgorny.
Herald added a project: LLDB.

I'd like to install lldb using the install-distribution target with 
LLVM_DISTRIBUTION_COMPONENTS but this is currently not possible as the 
lldb/scripts do not provide any component we can use and install the python 
scripts.
For this effect I created an lldb-scripts target and added the 
install-lldb-scripts llvm install target.

I tested with:
cmake ... -DLLVM_ENABLE_PROJECTS="clang;lldb" 
-DLLVM_DISTRIBUTION_COMPONENTS="lldb;liblldb;lldb-scripts" ...
DESTDIR=... ninja install-distribution

Then checked with bin/lldb -x -o 'script import lldb'

Question:
Since the lldb component is basically useless without at least liblldb would it 
make sense to make it depending on liblldb and this new lldb-scripts components?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68370

Files:
  lldb/scripts/CMakeLists.txt


Index: lldb/scripts/CMakeLists.txt
===
--- lldb/scripts/CMakeLists.txt
+++ lldb/scripts/CMakeLists.txt
@@ -69,5 +69,14 @@
 OUTPUT_STRIP_TRAILING_WHITESPACE)
 
   # Install the LLDB python module
-  install(DIRECTORY ${SWIG_PYTHON_DIR}/ DESTINATION ${SWIG_INSTALL_DIR})
+  add_custom_target(lldb-scripts)
+  add_dependencies(lldb-scripts finish_swig)
+  install(DIRECTORY ${SWIG_PYTHON_DIR}/
+DESTINATION ${SWIG_INSTALL_DIR}
+COMPONENT lldb-scripts)
+  if (NOT LLVM_ENABLE_IDE)
+add_llvm_install_targets(install-lldb-scripts
+ COMPONENT lldb-scripts
+ DEPENDS lldb-scripts)
+  endif()
 endif()


Index: lldb/scripts/CMakeLists.txt
===
--- lldb/scripts/CMakeLists.txt
+++ lldb/scripts/CMakeLists.txt
@@ -69,5 +69,14 @@
 OUTPUT_STRIP_TRAILING_WHITESPACE)
 
   # Install the LLDB python module
-  install(DIRECTORY ${SWIG_PYTHON_DIR}/ DESTINATION ${SWIG_INSTALL_DIR})
+  add_custom_target(lldb-scripts)
+  add_dependencies(lldb-scripts finish_swig)
+  install(DIRECTORY ${SWIG_PYTHON_DIR}/
+DESTINATION ${SWIG_INSTALL_DIR}
+COMPONENT lldb-scripts)
+  if (NOT LLVM_ENABLE_IDE)
+add_llvm_install_targets(install-lldb-scripts
+ COMPONENT lldb-scripts
+ DEPENDS lldb-scripts)
+  endif()
 endif()
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D68069: Explicitly set entry point arch when it's thumb

2019-10-02 Thread António Afonso via Phabricator via lldb-commits
aadsm updated this revision to Diff 222967.
aadsm added a comment.

Remove .global _Start


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68069

Files:
  lldb/lit/SymbolFile/dissassemble-entry-point.s
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp

Index: lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
===
--- lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
+++ lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
@@ -172,3 +172,129 @@
   Uuid.SetFromStringRef("1b8a73ac238390e32a7ff4ac8ebe4d6a41ecf5c9", 20);
   EXPECT_EQ(Spec.GetUUID(), Uuid);
 }
+
+TEST_F(ObjectFileELFTest, GetSymtab_NoSymEntryPointArmThumbAddressClass) {
+  /*
+  // nosym-entrypoint-arm-thumb.s
+  .thumb_func
+  _start:
+  mov r0, #42
+  mov r7, #1
+  svc #0
+  // arm-linux-androideabi-as nosym-entrypoint-arm-thumb.s
+  //   -o nosym-entrypoint-arm-thumb.o
+  // arm-linux-androideabi-ld nosym-entrypoint-arm-thumb.o
+  //   -o nosym-entrypoint-arm-thumb -e 0x8075 -s
+  */
+  auto ExpectedFile = TestFile::fromYaml(R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_ARM
+  Flags:   [ EF_ARM_SOFT_FLOAT, EF_ARM_EABI_VER5 ]
+  Entry:   0x8075
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+Address: 0x8074
+AddressAlign:0x0002
+Content: 2A20012700DF
+  - Name:.data
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+Content: ''
+  - Name:.bss
+Type:SHT_NOBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+  - Name:.note.gnu.gold-version
+Type:SHT_NOTE
+AddressAlign:0x0004
+Content: 040009000400474E5500676F6C6420312E313100
+  - Name:.ARM.attributes
+Type:SHT_ARM_ATTRIBUTES
+AddressAlign:0x0001
+Content: '41130061656162690001090006020901'
+...
+)");
+  ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded());
+
+  ModuleSpec spec{FileSpec(ExpectedFile->name())};
+  spec.GetSymbolFileSpec().SetFile(ExpectedFile->name(),
+   FileSpec::Style::native);
+  auto module_sp = std::make_shared(spec);
+
+  auto entry_point_addr = module_sp->GetObjectFile()->GetEntryPointAddress();
+  ASSERT_TRUE(entry_point_addr.GetOffset() & 1);
+  // Decrease the offsite by 1 to make it into a breakable address since this
+  // is Thumb.
+  entry_point_addr.SetOffset(entry_point_addr.GetOffset() - 1);
+  ASSERT_EQ(entry_point_addr.GetAddressClass(),
+AddressClass::eCodeAlternateISA);
+}
+
+TEST_F(ObjectFileELFTest, GetSymtab_NoSymEntryPointArmAddressClass) {
+  /*
+  // nosym-entrypoint-arm.s
+  _start:
+  movs r0, #42
+  movs r7, #1
+  svc #0
+  // arm-linux-androideabi-as nosym-entrypoint-arm.s
+  //   -o nosym-entrypoint-arm.o
+  // arm-linux-androideabi-ld nosym-entrypoint-arm.o
+  //   -o nosym-entrypoint-arm -e 0x8074 -s
+  */
+  auto ExpectedFile = TestFile::fromYaml(R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_ARM
+  Flags:   [ EF_ARM_SOFT_FLOAT, EF_ARM_EABI_VER5 ]
+  Entry:   0x8074
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+Address: 0x8074
+AddressAlign:0x0004
+Content: 2A00A0E30170A0E300EF
+  - Name:.data
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+Content: ''
+  - Name:.bss
+Type:SHT_NOBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+  - Name:.note.gnu.gold-version
+Type:SHT_NOTE
+AddressAlign:0x0004
+Content: 040009000400474E5500676F6C6420312E313100
+  - Name:.ARM.attributes
+Type:SHT_ARM_ATTRIBUTES
+AddressAlign:0x0001
+Content: '41130061656162690001090006010801'
+...
+)");
+  ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded());
+
+  ModuleSpec spec{FileSpec(ExpectedFile->name())};
+  spec.G

[Lldb-commits] [PATCH] D68370: Componentize lldb/scripts to use with LLVM_DISTRIBUTION_COMPONENTS

2019-10-03 Thread António Afonso via Phabricator via lldb-commits
aadsm updated this revision to Diff 223094.
aadsm added a comment.

Rename lldb-scripts to lldb-python-scripts


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68370

Files:
  lldb/scripts/CMakeLists.txt


Index: lldb/scripts/CMakeLists.txt
===
--- lldb/scripts/CMakeLists.txt
+++ lldb/scripts/CMakeLists.txt
@@ -69,5 +69,14 @@
 OUTPUT_STRIP_TRAILING_WHITESPACE)
 
   # Install the LLDB python module
-  install(DIRECTORY ${SWIG_PYTHON_DIR}/ DESTINATION ${SWIG_INSTALL_DIR})
+  add_custom_target(lldb-python-scripts)
+  add_dependencies(lldb-python-scripts finish_swig)
+  install(DIRECTORY ${SWIG_PYTHON_DIR}/
+DESTINATION ${SWIG_INSTALL_DIR}
+COMPONENT lldb-scripts)
+  if (NOT LLVM_ENABLE_IDE)
+add_llvm_install_targets(install-lldb-python-scripts
+ COMPONENT lldb-python-scripts
+ DEPENDS lldb-python-scripts)
+  endif()
 endif()


Index: lldb/scripts/CMakeLists.txt
===
--- lldb/scripts/CMakeLists.txt
+++ lldb/scripts/CMakeLists.txt
@@ -69,5 +69,14 @@
 OUTPUT_STRIP_TRAILING_WHITESPACE)
 
   # Install the LLDB python module
-  install(DIRECTORY ${SWIG_PYTHON_DIR}/ DESTINATION ${SWIG_INSTALL_DIR})
+  add_custom_target(lldb-python-scripts)
+  add_dependencies(lldb-python-scripts finish_swig)
+  install(DIRECTORY ${SWIG_PYTHON_DIR}/
+DESTINATION ${SWIG_INSTALL_DIR}
+COMPONENT lldb-scripts)
+  if (NOT LLVM_ENABLE_IDE)
+add_llvm_install_targets(install-lldb-python-scripts
+ COMPONENT lldb-python-scripts
+ DEPENDS lldb-python-scripts)
+  endif()
 endif()
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D68069: Explicitly set entry point arch when it's thumb

2019-10-03 Thread António Afonso via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL373680: Explicitly set entry point arch when it's thumb 
(authored by aadsm, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D68069?vs=222967&id=223121#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D68069

Files:
  lldb/trunk/lit/SymbolFile/dissassemble-entry-point.s
  lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/trunk/unittests/ObjectFile/ELF/TestObjectFileELF.cpp

Index: lldb/trunk/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
===
--- lldb/trunk/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
+++ lldb/trunk/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
@@ -172,3 +172,129 @@
   Uuid.SetFromStringRef("1b8a73ac238390e32a7ff4ac8ebe4d6a41ecf5c9", 20);
   EXPECT_EQ(Spec.GetUUID(), Uuid);
 }
+
+TEST_F(ObjectFileELFTest, GetSymtab_NoSymEntryPointArmThumbAddressClass) {
+  /*
+  // nosym-entrypoint-arm-thumb.s
+  .thumb_func
+  _start:
+  mov r0, #42
+  mov r7, #1
+  svc #0
+  // arm-linux-androideabi-as nosym-entrypoint-arm-thumb.s
+  //   -o nosym-entrypoint-arm-thumb.o
+  // arm-linux-androideabi-ld nosym-entrypoint-arm-thumb.o
+  //   -o nosym-entrypoint-arm-thumb -e 0x8075 -s
+  */
+  auto ExpectedFile = TestFile::fromYaml(R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_ARM
+  Flags:   [ EF_ARM_SOFT_FLOAT, EF_ARM_EABI_VER5 ]
+  Entry:   0x8075
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+Address: 0x8074
+AddressAlign:0x0002
+Content: 2A20012700DF
+  - Name:.data
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+Content: ''
+  - Name:.bss
+Type:SHT_NOBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+  - Name:.note.gnu.gold-version
+Type:SHT_NOTE
+AddressAlign:0x0004
+Content: 040009000400474E5500676F6C6420312E313100
+  - Name:.ARM.attributes
+Type:SHT_ARM_ATTRIBUTES
+AddressAlign:0x0001
+Content: '41130061656162690001090006020901'
+...
+)");
+  ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded());
+
+  ModuleSpec spec{FileSpec(ExpectedFile->name())};
+  spec.GetSymbolFileSpec().SetFile(ExpectedFile->name(),
+   FileSpec::Style::native);
+  auto module_sp = std::make_shared(spec);
+
+  auto entry_point_addr = module_sp->GetObjectFile()->GetEntryPointAddress();
+  ASSERT_TRUE(entry_point_addr.GetOffset() & 1);
+  // Decrease the offsite by 1 to make it into a breakable address since this
+  // is Thumb.
+  entry_point_addr.SetOffset(entry_point_addr.GetOffset() - 1);
+  ASSERT_EQ(entry_point_addr.GetAddressClass(),
+AddressClass::eCodeAlternateISA);
+}
+
+TEST_F(ObjectFileELFTest, GetSymtab_NoSymEntryPointArmAddressClass) {
+  /*
+  // nosym-entrypoint-arm.s
+  _start:
+  movs r0, #42
+  movs r7, #1
+  svc #0
+  // arm-linux-androideabi-as nosym-entrypoint-arm.s
+  //   -o nosym-entrypoint-arm.o
+  // arm-linux-androideabi-ld nosym-entrypoint-arm.o
+  //   -o nosym-entrypoint-arm -e 0x8074 -s
+  */
+  auto ExpectedFile = TestFile::fromYaml(R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_ARM
+  Flags:   [ EF_ARM_SOFT_FLOAT, EF_ARM_EABI_VER5 ]
+  Entry:   0x8074
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+Address: 0x8074
+AddressAlign:0x0004
+Content: 2A00A0E30170A0E300EF
+  - Name:.data
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+Content: ''
+  - Name:.bss
+Type:SHT_NOBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+  - Name:.note.gnu.gold-version
+Type:SHT_NOTE
+AddressAlign:0x0004
+Content: 040009000400474E5500676F6C6420312E313100
+  - Name:.ARM.attributes
+Type

[Lldb-commits] [PATCH] D68069: Explicitly set entry point arch when it's thumb

2019-10-03 Thread António Afonso via Phabricator via lldb-commits
aadsm added a comment.

I ended reverting this because of SymbolFile/Breakpad/symtab.test. It seems 
that in this test we add symbols after the synthetic entry point symbol is 
added creating confusion.
I think I'll need to change the code that adds symbols in Symtab to explicitly 
check if we're overlapping the synthetic entry point and reduce the entry point 
or remove it in the case it overlaps at the beginning.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D68069



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


[Lldb-commits] [PATCH] D68069: Explicitly set entry point arch when it's thumb

2019-10-04 Thread António Afonso via Phabricator via lldb-commits
aadsm added a comment.

Ok. Initially I thought that with the entry point we were making big 
assumptions there but after reading the parse unwind symbols I guess it's 
really no big difference. 
I guess my main concern is that the user can no longer create symbols within 
the span of the entry point symbol, even if they happen to know better (it's 
not even possible to manually remove symbols). But like you said, the same is 
true with the other synthetic symbols..


Repository:
  rL LLVM

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

https://reviews.llvm.org/D68069



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


[Lldb-commits] [PATCH] D68370: Componentize lldb/scripts to use with LLVM_DISTRIBUTION_COMPONENTS

2019-10-04 Thread António Afonso via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL373768: Componentize lldb/scripts to use with 
LLVM_DISTRIBUTION_COMPONENTS (authored by aadsm, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D68370?vs=223094&id=223251#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D68370

Files:
  lldb/trunk/scripts/CMakeLists.txt


Index: lldb/trunk/scripts/CMakeLists.txt
===
--- lldb/trunk/scripts/CMakeLists.txt
+++ lldb/trunk/scripts/CMakeLists.txt
@@ -69,5 +69,14 @@
 OUTPUT_STRIP_TRAILING_WHITESPACE)
 
   # Install the LLDB python module
-  install(DIRECTORY ${SWIG_PYTHON_DIR}/ DESTINATION ${SWIG_INSTALL_DIR})
+  add_custom_target(lldb-python-scripts)
+  add_dependencies(lldb-python-scripts finish_swig)
+  install(DIRECTORY ${SWIG_PYTHON_DIR}/
+DESTINATION ${SWIG_INSTALL_DIR}
+COMPONENT lldb-scripts)
+  if (NOT LLVM_ENABLE_IDE)
+add_llvm_install_targets(install-lldb-python-scripts
+ COMPONENT lldb-python-scripts
+ DEPENDS lldb-python-scripts)
+  endif()
 endif()


Index: lldb/trunk/scripts/CMakeLists.txt
===
--- lldb/trunk/scripts/CMakeLists.txt
+++ lldb/trunk/scripts/CMakeLists.txt
@@ -69,5 +69,14 @@
 OUTPUT_STRIP_TRAILING_WHITESPACE)
 
   # Install the LLDB python module
-  install(DIRECTORY ${SWIG_PYTHON_DIR}/ DESTINATION ${SWIG_INSTALL_DIR})
+  add_custom_target(lldb-python-scripts)
+  add_dependencies(lldb-python-scripts finish_swig)
+  install(DIRECTORY ${SWIG_PYTHON_DIR}/
+DESTINATION ${SWIG_INSTALL_DIR}
+COMPONENT lldb-scripts)
+  if (NOT LLVM_ENABLE_IDE)
+add_llvm_install_targets(install-lldb-python-scripts
+ COMPONENT lldb-python-scripts
+ DEPENDS lldb-python-scripts)
+  endif()
 endif()
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D68533: Explicitly set entry point arch when it's thumb [Second Try]

2019-10-04 Thread António Afonso via Phabricator via lldb-commits
aadsm created this revision.
aadsm added reviewers: clayborg, labath, wallace, espindola.
aadsm added a project: LLDB.

This is a redo of D68069  because I reverted 
it due to some concerns that were now addressed along with the new comments 
that @labath added.

I found a case where the main android binary (app_process32) had thumb code at 
its entry point but no entry in the symbol table indicating this. This made 
lldb set a 4 byte breakpoint at that address (we default to arm code) instead 
of a 2 byte one (like we should for thumb).
The big deal with this is that the expression evaluator uses the entry point as 
a way to know when a JITed expression has finished executing by putting a 
breakpoint there. Because of this, evaluating expressions on certain android 
devices (Google Pixel something) made the process crash.
This was fixed by checking this specific situation when we parse the symbol 
table and add an artificial symbol for this 2 byte range and indicating that 
it's arm thumb.

I created 2 unit tests for this, one to check that now we know that the entry 
point is arm thumb, and the other to make sure we didn't change the behaviour 
for arm code.

I also run the following on the command line with the `app_process32` where I 
found the issue:
**Before:**

  (lldb) dis -s 0x1640 -e 0x1644
  app_process32[0x1640]: .long  0xf0004668; unknown opcode

**After:**

  (lldb) dis -s 0x1640 -e 0x1644
  app_process32`:
  app_process32[0x1640] <+0>: movr0, sp
  app_process32[0x1642]:  andeq  r0, r0, r0


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68533

Files:
  lldb/lit/SymbolFile/Breakpad/symtab.test
  lldb/lit/SymbolFile/dissassemble-entry-point.s
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp

Index: lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
===
--- lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
+++ lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
@@ -172,3 +172,129 @@
   Uuid.SetFromStringRef("1b8a73ac238390e32a7ff4ac8ebe4d6a41ecf5c9", 20);
   EXPECT_EQ(Spec.GetUUID(), Uuid);
 }
+
+TEST_F(ObjectFileELFTest, GetSymtab_NoSymEntryPointArmThumbAddressClass) {
+  /*
+  // nosym-entrypoint-arm-thumb.s
+  .thumb_func
+  _start:
+  mov r0, #42
+  mov r7, #1
+  svc #0
+  // arm-linux-androideabi-as nosym-entrypoint-arm-thumb.s
+  //   -o nosym-entrypoint-arm-thumb.o
+  // arm-linux-androideabi-ld nosym-entrypoint-arm-thumb.o
+  //   -o nosym-entrypoint-arm-thumb -e 0x8075 -s
+  */
+  auto ExpectedFile = TestFile::fromYaml(R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_ARM
+  Flags:   [ EF_ARM_SOFT_FLOAT, EF_ARM_EABI_VER5 ]
+  Entry:   0x8075
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+Address: 0x8074
+AddressAlign:0x0002
+Content: 2A20012700DF
+  - Name:.data
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+Content: ''
+  - Name:.bss
+Type:SHT_NOBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+  - Name:.note.gnu.gold-version
+Type:SHT_NOTE
+AddressAlign:0x0004
+Content: 040009000400474E5500676F6C6420312E313100
+  - Name:.ARM.attributes
+Type:SHT_ARM_ATTRIBUTES
+AddressAlign:0x0001
+Content: '41130061656162690001090006020901'
+...
+)");
+  ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded());
+
+  ModuleSpec spec{FileSpec(ExpectedFile->name())};
+  spec.GetSymbolFileSpec().SetFile(ExpectedFile->name(),
+   FileSpec::Style::native);
+  auto module_sp = std::make_shared(spec);
+
+  auto entry_point_addr = module_sp->GetObjectFile()->GetEntryPointAddress();
+  ASSERT_TRUE(entry_point_addr.GetOffset() & 1);
+  // Decrease the offsite by 1 to make it into a breakable address since this
+  // is Thumb.
+  entry_point_addr.SetOffset(entry_point_addr.GetOffset() - 1);
+  ASSERT_EQ(entry_point_addr.GetAddressClass(),
+AddressClass::eCodeAlternateISA);
+}
+
+TEST_F(ObjectFileELFTest, GetSymtab_NoSymEntryPointArmAddressClass) {
+  /*
+  // nosym-entrypoint-arm.s
+  _start:
+  movs r0, #42
+  movs r7, #1
+  svc #0
+  // arm-linux-androideabi-as nosym-entrypoint-arm.s
+  //   -o nosym-entrypoint-arm.o
+  // arm-linux-androideabi-ld nosym-entrypoint-arm.o
+  //   -o nosym-entrypoint-arm -e 0x

[Lldb-commits] [PATCH] D68533: Explicitly set entry point arch when it's thumb [Second Try]

2019-10-07 Thread António Afonso via Phabricator via lldb-commits
aadsm updated this revision to Diff 223707.
aadsm added a comment.

Don't destroy the Breakpad test purpose.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68533

Files:
  lldb/lit/SymbolFile/Breakpad/Inputs/basic-elf.yaml
  lldb/lit/SymbolFile/Breakpad/symtab.test
  lldb/lit/SymbolFile/dissassemble-entry-point.s
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp

Index: lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
===
--- lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
+++ lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
@@ -172,3 +172,129 @@
   Uuid.SetFromStringRef("1b8a73ac238390e32a7ff4ac8ebe4d6a41ecf5c9", 20);
   EXPECT_EQ(Spec.GetUUID(), Uuid);
 }
+
+TEST_F(ObjectFileELFTest, GetSymtab_NoSymEntryPointArmThumbAddressClass) {
+  /*
+  // nosym-entrypoint-arm-thumb.s
+  .thumb_func
+  _start:
+  mov r0, #42
+  mov r7, #1
+  svc #0
+  // arm-linux-androideabi-as nosym-entrypoint-arm-thumb.s
+  //   -o nosym-entrypoint-arm-thumb.o
+  // arm-linux-androideabi-ld nosym-entrypoint-arm-thumb.o
+  //   -o nosym-entrypoint-arm-thumb -e 0x8075 -s
+  */
+  auto ExpectedFile = TestFile::fromYaml(R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_ARM
+  Flags:   [ EF_ARM_SOFT_FLOAT, EF_ARM_EABI_VER5 ]
+  Entry:   0x8075
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+Address: 0x8074
+AddressAlign:0x0002
+Content: 2A20012700DF
+  - Name:.data
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+Content: ''
+  - Name:.bss
+Type:SHT_NOBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+  - Name:.note.gnu.gold-version
+Type:SHT_NOTE
+AddressAlign:0x0004
+Content: 040009000400474E5500676F6C6420312E313100
+  - Name:.ARM.attributes
+Type:SHT_ARM_ATTRIBUTES
+AddressAlign:0x0001
+Content: '41130061656162690001090006020901'
+...
+)");
+  ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded());
+
+  ModuleSpec spec{FileSpec(ExpectedFile->name())};
+  spec.GetSymbolFileSpec().SetFile(ExpectedFile->name(),
+   FileSpec::Style::native);
+  auto module_sp = std::make_shared(spec);
+
+  auto entry_point_addr = module_sp->GetObjectFile()->GetEntryPointAddress();
+  ASSERT_TRUE(entry_point_addr.GetOffset() & 1);
+  // Decrease the offsite by 1 to make it into a breakable address since this
+  // is Thumb.
+  entry_point_addr.SetOffset(entry_point_addr.GetOffset() - 1);
+  ASSERT_EQ(entry_point_addr.GetAddressClass(),
+AddressClass::eCodeAlternateISA);
+}
+
+TEST_F(ObjectFileELFTest, GetSymtab_NoSymEntryPointArmAddressClass) {
+  /*
+  // nosym-entrypoint-arm.s
+  _start:
+  movs r0, #42
+  movs r7, #1
+  svc #0
+  // arm-linux-androideabi-as nosym-entrypoint-arm.s
+  //   -o nosym-entrypoint-arm.o
+  // arm-linux-androideabi-ld nosym-entrypoint-arm.o
+  //   -o nosym-entrypoint-arm -e 0x8074 -s
+  */
+  auto ExpectedFile = TestFile::fromYaml(R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_ARM
+  Flags:   [ EF_ARM_SOFT_FLOAT, EF_ARM_EABI_VER5 ]
+  Entry:   0x8074
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+Address: 0x8074
+AddressAlign:0x0004
+Content: 2A00A0E30170A0E300EF
+  - Name:.data
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+Content: ''
+  - Name:.bss
+Type:SHT_NOBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+  - Name:.note.gnu.gold-version
+Type:SHT_NOTE
+AddressAlign:0x0004
+Content: 040009000400474E5500676F6C6420312E313100
+  - Name:.ARM.attributes
+Type:SHT_ARM_ATTRIBUTES
+AddressAlign:0x0001
+Content: '41130061656162690001090006010801'
+...
+)");
+  ASS

[Lldb-commits] [PATCH] D68533: Explicitly set entry point arch when it's thumb [Second Try]

2019-10-08 Thread António Afonso via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGad6690afa3e6: Explicitly set entry point arch when it's 
thumb [Second Try] (authored by aadsm).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68533

Files:
  lldb/lit/SymbolFile/Breakpad/Inputs/basic-elf.yaml
  lldb/lit/SymbolFile/Breakpad/symtab.test
  lldb/lit/SymbolFile/dissassemble-entry-point.s
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp

Index: lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
===
--- lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
+++ lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
@@ -172,3 +172,129 @@
   Uuid.SetFromStringRef("1b8a73ac238390e32a7ff4ac8ebe4d6a41ecf5c9", 20);
   EXPECT_EQ(Spec.GetUUID(), Uuid);
 }
+
+TEST_F(ObjectFileELFTest, GetSymtab_NoSymEntryPointArmThumbAddressClass) {
+  /*
+  // nosym-entrypoint-arm-thumb.s
+  .thumb_func
+  _start:
+  mov r0, #42
+  mov r7, #1
+  svc #0
+  // arm-linux-androideabi-as nosym-entrypoint-arm-thumb.s
+  //   -o nosym-entrypoint-arm-thumb.o
+  // arm-linux-androideabi-ld nosym-entrypoint-arm-thumb.o
+  //   -o nosym-entrypoint-arm-thumb -e 0x8075 -s
+  */
+  auto ExpectedFile = TestFile::fromYaml(R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_ARM
+  Flags:   [ EF_ARM_SOFT_FLOAT, EF_ARM_EABI_VER5 ]
+  Entry:   0x8075
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+Address: 0x8074
+AddressAlign:0x0002
+Content: 2A20012700DF
+  - Name:.data
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+Content: ''
+  - Name:.bss
+Type:SHT_NOBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+  - Name:.note.gnu.gold-version
+Type:SHT_NOTE
+AddressAlign:0x0004
+Content: 040009000400474E5500676F6C6420312E313100
+  - Name:.ARM.attributes
+Type:SHT_ARM_ATTRIBUTES
+AddressAlign:0x0001
+Content: '41130061656162690001090006020901'
+...
+)");
+  ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded());
+
+  ModuleSpec spec{FileSpec(ExpectedFile->name())};
+  spec.GetSymbolFileSpec().SetFile(ExpectedFile->name(),
+   FileSpec::Style::native);
+  auto module_sp = std::make_shared(spec);
+
+  auto entry_point_addr = module_sp->GetObjectFile()->GetEntryPointAddress();
+  ASSERT_TRUE(entry_point_addr.GetOffset() & 1);
+  // Decrease the offsite by 1 to make it into a breakable address since this
+  // is Thumb.
+  entry_point_addr.SetOffset(entry_point_addr.GetOffset() - 1);
+  ASSERT_EQ(entry_point_addr.GetAddressClass(),
+AddressClass::eCodeAlternateISA);
+}
+
+TEST_F(ObjectFileELFTest, GetSymtab_NoSymEntryPointArmAddressClass) {
+  /*
+  // nosym-entrypoint-arm.s
+  _start:
+  movs r0, #42
+  movs r7, #1
+  svc #0
+  // arm-linux-androideabi-as nosym-entrypoint-arm.s
+  //   -o nosym-entrypoint-arm.o
+  // arm-linux-androideabi-ld nosym-entrypoint-arm.o
+  //   -o nosym-entrypoint-arm -e 0x8074 -s
+  */
+  auto ExpectedFile = TestFile::fromYaml(R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_ARM
+  Flags:   [ EF_ARM_SOFT_FLOAT, EF_ARM_EABI_VER5 ]
+  Entry:   0x8074
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+Address: 0x8074
+AddressAlign:0x0004
+Content: 2A00A0E30170A0E300EF
+  - Name:.data
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+Content: ''
+  - Name:.bss
+Type:SHT_NOBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+  - Name:.note.gnu.gold-version
+Type:SHT_NOTE
+AddressAlign:0x0004
+Content: 040009000400474E5500676F6C6420312E313100
+  - Name:.ARM.attributes
+Type:SHT_ARM_ATTRIBUTES
+AddressAlign:0x0001
+ 

[Lldb-commits] [PATCH] D68533: Explicitly set entry point arch when it's thumb [Second Try]

2019-10-09 Thread António Afonso via Phabricator via lldb-commits
aadsm added a comment.

@shafik thanks, checking.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68533



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


[Lldb-commits] [PATCH] D68533: Explicitly set entry point arch when it's thumb [Second Try]

2019-10-09 Thread António Afonso via Phabricator via lldb-commits
aadsm added a comment.

@shafik I just pushed a fix, the issue was because on mac there are more 
unnamed symbols so the number didn't match, I changed it to match any number 
since this can easily change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68533



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


[Lldb-commits] [PATCH] D69589: [lldb] Refactor all POST_BUILD commands into targets

2019-11-03 Thread António Afonso via Phabricator via lldb-commits
aadsm requested changes to this revision.
aadsm added a comment.
This revision now requires changes to proceed.

I'm sorry to reject but this diff breaks `install-distribution` on Darwin. 
Here's how to repro:

  $ mkdir -p ~/Projects/llvm-build/Release && cd ~/Projects/llvm-build/Release
  $ cmake -G Ninja \
   -DLLVM_ENABLE_PROJECTS="clang;lldb" \
   -DCMAKE_BUILD_TYPE=Release \
   -DLLVM_ENABLE_ASSERTIONS=OFF \
   -DLLDB_INCLUDE_TESTS=OFF \
   -DLLVM_DISTRIBUTION_COMPONENTS="lldb;liblldb" \
   -C ../../llvm-project/lldb/cmake/caches/Apple-lldb-macOS.cmake \
   -S../../llvm-project/llvm
  $ DESTDIR=$PWD/install/usr install-distribution
  ninja: error: 'bin/LLDB.framework/LLDB', needed by 
'bin/LLDB.framework/Resources/Python/lldb/_lldb.so', missing and no known rule 
to make it

The reason I found this is because I was having an issue where `_lldb.so` was 
being generated on the build but it was not being copied to the install 
directory.
After some mucking around I realized that the `install-liblldb` target installs 
the python scripts but it's `lldb` that generates the symlink as a `POST_BUILD` 
command (before this diff). I think in some situations the `install-liblldb` 
runs before that `POST_BUILD` command has run. At least I'm able to repro this 
quite consistently and once `ninja install-distribution` is finished `_lldb.so` 
exists on the build directory but not on the install one (and I can see all 
files in the python module being copied except that one in the ninja log when 
running the install step).

I fixed this locally by doing this (this fix doesn't really feel good but not 
sure what's the best way to do it):

  if(LLDB_BUILD_FRAMEWORK)
# When building as framework liblldb is responsible to install the python
# scripts. However, we need to make sure that all swig components have been
# properly finished.
add_dependencies(install-liblldb finish_swig)
add_dependencies(install-liblldb-stripped finish_swig)
  else()
# Install the LLDB python module
...
  endif()

Then I found this diff that hasn't landed yet and tried it (I think there's a 
race condition caused by the POST_BUILD command but not sure) out and stumbled 
upon this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69589



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


[Lldb-commits] [PATCH] D69589: [lldb] Refactor all POST_BUILD commands into targets

2019-11-04 Thread António Afonso via Phabricator via lldb-commits
aadsm accepted this revision.
aadsm added a comment.
This revision is now accepted and ready to land.

This is great! it's so much better. Thank so much for looking into this and 
fixing it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69589



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


[Lldb-commits] [PATCH] D69589: [lldb] Refactor all POST_BUILD commands into targets

2019-11-04 Thread António Afonso via Phabricator via lldb-commits
aadsm added a comment.

@hhb fwiw, I still get the same error with this diff (after applying it on top 
of D69834 ). But D69834 
 by itself works great!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69589



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


[Lldb-commits] [PATCH] D69589: [lldb] Refactor all POST_BUILD commands into targets

2019-11-05 Thread António Afonso via Phabricator via lldb-commits
aadsm added a comment.

@hhb I just did, and get the same error as well :(
`ninja: error: 'bin/LLDB.framework/LLDB', needed by 
'bin/LLDB.framework/Resources/Python/lldb/_lldb.so', missing and no known rule 
to make it`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69589



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


[Lldb-commits] [PATCH] D69589: [lldb] Refactor all POST_BUILD commands into targets

2019-11-06 Thread António Afonso via Phabricator via lldb-commits
aadsm added a comment.

Yeah, weird. I wonder if this is something cmake does implicitly when the 
target is defined as `FRAMEWORK`: 
https://cmake.org/cmake/help/latest/prop_tgt/FRAMEWORK.html


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69589



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


[Lldb-commits] [PATCH] D69931: Add cmake variables to specify a python framework to ship with lldb

2019-11-06 Thread António Afonso via Phabricator via lldb-commits
aadsm created this revision.
aadsm added reviewers: hhb, sgraenitz, xiaobai, smeenai.
Herald added subscribers: lldb-commits, mgorny.
Herald added a project: LLDB.

I want to be able to specify which python framework to use for lldb in macos. 
With python2.7 we could just rely on the MacOS one but python3.7 is not shipped 
with the OS.
An alternative is to use the one shipped with Xcode but that could be path 
dependent or maybe the user doesn't have Xcode installed at all.
A definite solution is to just ship a python framework with lldb. To make this 
possible I added two new variables:

`PYTHON_FRAMEWORK_DIR`: with the path of the Python.framework to ship and link 
against
`PYTHON_FRAMEWORK_INSTALL_RPATH`: If the install_path of the python binary uses 
an @rpath then we need to be able to set this accordingly.

Here's an example:

  
-DPYTHON_FRAMEWORK_DIR="/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework"
  -DPYTHON_FRAMEWORK_INSTALL_RPATH="@loader_path/../../../"

What do you think?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69931

Files:
  lldb/cmake/modules/LLDBFramework.cmake


Index: lldb/cmake/modules/LLDBFramework.cmake
===
--- lldb/cmake/modules/LLDBFramework.cmake
+++ lldb/cmake/modules/LLDBFramework.cmake
@@ -120,3 +120,14 @@
 COMMENT "LLDB.framework: copy clang vendor-specific headers"
   )
 endif()
+
+# Import Python framework if specified
+if(PYTHON_FRAMEWORK_DIR)
+  install(DIRECTORY ${PYTHON_FRAMEWORK_DIR}
+DESTINATION ${LLDB_FRAMEWORK_INSTALL_DIR}
+COMPONENT liblldb)
+  if(PYTHON_FRAMEWORK_INSTALL_RPATH)
+set_property(TARGET liblldb APPEND PROPERTY INSTALL_RPATH
+  ${PYTHON_FRAMEWORK_INSTALL_RPATH})
+  endif()
+endif()


Index: lldb/cmake/modules/LLDBFramework.cmake
===
--- lldb/cmake/modules/LLDBFramework.cmake
+++ lldb/cmake/modules/LLDBFramework.cmake
@@ -120,3 +120,14 @@
 COMMENT "LLDB.framework: copy clang vendor-specific headers"
   )
 endif()
+
+# Import Python framework if specified
+if(PYTHON_FRAMEWORK_DIR)
+  install(DIRECTORY ${PYTHON_FRAMEWORK_DIR}
+DESTINATION ${LLDB_FRAMEWORK_INSTALL_DIR}
+COMPONENT liblldb)
+  if(PYTHON_FRAMEWORK_INSTALL_RPATH)
+set_property(TARGET liblldb APPEND PROPERTY INSTALL_RPATH
+  ${PYTHON_FRAMEWORK_INSTALL_RPATH})
+  endif()
+endif()
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D69931: Add cmake variables to specify a python framework to ship with lldb

2019-11-08 Thread António Afonso via Phabricator via lldb-commits
aadsm added a comment.

That should work fine yeah. It should be a matter of adding 
`"@loader_path/../../../"` to the rpath.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69931



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


[Lldb-commits] [PATCH] D69931: Add cmake variables to specify a python framework to ship with lldb

2019-11-11 Thread António Afonso via Phabricator via lldb-commits
aadsm added a comment.

> The proposed path in this patch, -rpath "@loader_path/../../../", uses the 
> @loader_path expansion which is the directory containing the binary that the 
> load command is in (in this case liblldb's directory). Popping 3 directories 
> up from that is likely not sane in most build configurations, but if it works 
> for you meh...

This is exactly what Apple ships with Xcode today:

  $ otool -l 
/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/liblldbPluginScriptInterpreterPython3.dylib
 | grep RPATH -A 2
cmd LC_RPATH
cmdsize 72
   path @loader_path/../../../../../../../../Library/Frameworks/ 
(offset 12)
  --
cmd LC_RPATH
cmdsize 72
   path @loader_path/../../../../../Developer/Library/Frameworks/ 
(offset 12)
  --
cmd LC_RPATH
cmdsize 72
   path @loader_path/../../../../Developer/Library/Frameworks/ (offset 
12)
  --
cmd LC_RPATH
cmdsize 48
   path @loader_path/../../../../Frameworks (offset 12)
  --
cmd LC_RPATH
cmdsize 40
   path @loader_path/../../../ (offset 12)
  
  $ otool -L 
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/Python3
  
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/Python3:
@rpath/Python3.framework/Versions/3.7/Python3 (compatibility version 
3.7.0, current version 3.7.0)

But they build liblldbPluginScriptInterpreterPython3 as a dylib instead of 
statically inside liblldb (so that they can have both 2.7 and 3.7).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69931



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


[Lldb-commits] [PATCH] D69931: Add cmake variables to specify a python framework to ship with lldb

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

Updating to only add an rpath that points to the directory where 
LLDB.frameworks gets installed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69931

Files:
  lldb/cmake/modules/LLDBFramework.cmake


Index: lldb/cmake/modules/LLDBFramework.cmake
===
--- lldb/cmake/modules/LLDBFramework.cmake
+++ lldb/cmake/modules/LLDBFramework.cmake
@@ -120,3 +120,7 @@
 COMMENT "LLDB.framework: copy clang vendor-specific headers"
   )
 endif()
+
+# Add an rpath pointing to the directory where LLDB.framework is installed.
+set_property(TARGET liblldb APPEND PROPERTY INSTALL_RPATH
+  "@loader_path/../../../")


Index: lldb/cmake/modules/LLDBFramework.cmake
===
--- lldb/cmake/modules/LLDBFramework.cmake
+++ lldb/cmake/modules/LLDBFramework.cmake
@@ -120,3 +120,7 @@
 COMMENT "LLDB.framework: copy clang vendor-specific headers"
   )
 endif()
+
+# Add an rpath pointing to the directory where LLDB.framework is installed.
+set_property(TARGET liblldb APPEND PROPERTY INSTALL_RPATH
+  "@loader_path/../../../")
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D69931: Add rpath to liblldb so vendors can ship their own python framework (or others)

2019-11-11 Thread António Afonso via Phabricator via lldb-commits
aadsm updated this revision to Diff 228765.
aadsm edited the summary of this revision.
aadsm added a comment.

Clarify the point of the install_path


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69931

Files:
  lldb/cmake/modules/LLDBFramework.cmake


Index: lldb/cmake/modules/LLDBFramework.cmake
===
--- lldb/cmake/modules/LLDBFramework.cmake
+++ lldb/cmake/modules/LLDBFramework.cmake
@@ -120,3 +120,8 @@
 COMMENT "LLDB.framework: copy clang vendor-specific headers"
   )
 endif()
+
+# Add an rpath pointing to the directory where LLDB.framework is installed.
+# This allows frameworks (relying on @rpath) to be installed in the same 
folder and found at runtime.
+set_property(TARGET liblldb APPEND PROPERTY INSTALL_RPATH
+  "@loader_path/../../../")


Index: lldb/cmake/modules/LLDBFramework.cmake
===
--- lldb/cmake/modules/LLDBFramework.cmake
+++ lldb/cmake/modules/LLDBFramework.cmake
@@ -120,3 +120,8 @@
 COMMENT "LLDB.framework: copy clang vendor-specific headers"
   )
 endif()
+
+# Add an rpath pointing to the directory where LLDB.framework is installed.
+# This allows frameworks (relying on @rpath) to be installed in the same folder and found at runtime.
+set_property(TARGET liblldb APPEND PROPERTY INSTALL_RPATH
+  "@loader_path/../../../")
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D70252: [Docs] Add Python caveats under the development section

2019-11-14 Thread António Afonso via Phabricator via lldb-commits
aadsm added a comment.

Thank you for writing this up! I was thinking how I would find this.. I don't 
see myself clicking on the "Caveats" link (could also be a me problem though). 
Could we also add a link to it in this section? 
https://lldb.llvm.org/resources/build.html#id22. Something like "NOTE: You need 
to use the python binary you built with, check caveats to learn more"?


Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D70252



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


[Lldb-commits] [PATCH] D64013: Correctly use GetLoadedModuleList to take advantage of libraries-svr4

2019-07-22 Thread António Afonso via Phabricator via lldb-commits
aadsm updated this revision to Diff 211241.
aadsm added a comment.

Handle error returned by GetLoadedModuleList


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64013

Files:
  lldb/include/lldb/Target/Process.h
  lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp
  lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.h
  lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
  lldb/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h

Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
===
--- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
+++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
@@ -200,9 +200,9 @@
 
   llvm::VersionTuple GetHostOSVersion() override;
 
-  size_t LoadModules(LoadedModuleInfoList &module_list) override;
+  llvm::Error LoadModules() override;
 
-  size_t LoadModules() override;
+  llvm::Expected GetLoadedModuleList() override;
 
   Status GetFileLoadAddress(const FileSpec &file, bool &is_loaded,
 lldb::addr_t &load_addr) override;
@@ -391,9 +391,6 @@
   // Query remote GDBServer for register information
   bool GetGDBServerRegisterInfo(ArchSpec &arch);
 
-  // Query remote GDBServer for a detailed loaded library list
-  Status GetLoadedModuleList(LoadedModuleInfoList &);
-
   lldb::ModuleSP LoadModuleAtAddress(const FileSpec &file,
  lldb::addr_t link_map,
  lldb::addr_t base_addr,
Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -2400,7 +2400,12 @@
 ostr.Printf("%" PRIu64 " %" PRIu32, wp_addr, wp_index);
 description = ostr.GetString();
   } else if (key.compare("library") == 0) {
-LoadModules();
+auto error = LoadModules();
+if (error) {
+  Log *log(
+  ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
+  LLDB_LOG_ERROR(log, std::move(error), "Failed to load modules: {0}");
+}
   } else if (key.size() == 2 && ::isxdigit(key[0]) && ::isxdigit(key[1])) {
 uint32_t reg = UINT32_MAX;
 if (!key.getAsInteger(16, reg))
@@ -2756,9 +2761,13 @@
 
   // the loaded module list can also provides a link map address
   if (addr == LLDB_INVALID_ADDRESS) {
-LoadedModuleInfoList list;
-if (GetLoadedModuleList(list).Success())
-  addr = list.m_link_map;
+llvm::Expected list = GetLoadedModuleList();
+if (!list) {
+  Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
+  LLDB_LOG_ERROR(log, list.takeError(), "Failed to read module list: {0}");
+} else {
+  addr = list->m_link_map;
+}
   }
 
   return addr;
@@ -4705,29 +4714,30 @@
   return m_register_info.GetNumRegisters() > 0;
 }
 
-Status ProcessGDBRemote::GetLoadedModuleList(LoadedModuleInfoList &list) {
+llvm::Expected ProcessGDBRemote::GetLoadedModuleList() {
   // Make sure LLDB has an XML parser it can use first
   if (!XMLDocument::XMLEnabled())
-return Status(0, ErrorType::eErrorTypeGeneric);
+return llvm::createStringError(llvm::inconvertibleErrorCode(),
+   "XML parsing not available");
 
   Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS);
   if (log)
 log->Printf("ProcessGDBRemote::%s", __FUNCTION__);
 
+  LoadedModuleInfoList list;
   GDBRemoteCommunicationClient &comm = m_gdb_comm;
   bool can_use_svr4 = GetGlobalPluginProperties()->GetUseSVR4();
 
   // check that we have extended feature read support
   if (can_use_svr4 && comm.GetQXferLibrariesSVR4ReadSupported()) {
-list.clear();
-
 // request the loaded library list
 std::string raw;
 lldb_private::Status lldberr;
 
 if (!comm.ReadExtFeature(ConstString("libraries-svr4"), ConstString(""),
  raw, lldberr))
-  return Status(0, ErrorType::eErrorTypeGeneric);
+  return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "Error in libraries-svr4 packet");
 
 // parse the xml file in memory
 if (log)
@@ -4735,11 +4745,14 @@
 XMLDocument doc;
 
 if (!doc.ParseMemory(raw.c_str(), raw.size(), "noname.xml"))
-  return Status(0, ErrorType::eErrorTypeGeneric);
+  return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "Error reading noname.xml");
 
 XMLNode root_element = doc.GetRootElement("library-list-svr4");
 if (!root_eleme

[Lldb-commits] [PATCH] D65129: Test load unloading of modules with libraries-svr4

2019-07-22 Thread António Afonso via Phabricator via lldb-commits
aadsm created this revision.
aadsm added reviewers: labath, clayborg, xiaobai.
Herald added subscribers: lldb-commits, srhines.
Herald added a project: LLDB.

This doubles the 3 tests running right now on linux by also executing each test 
with libraries-svr4 enabled.
Not sure if there's a better way to do this as I had to copy/paste all the 
decorators as well...


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65129

Files:
  
lldb/packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py


Index: 
lldb/packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py
===
--- 
lldb/packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py
+++ 
lldb/packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py
@@ -93,6 +93,13 @@
 "Unable copy 'libloadunload_d.so' to '%s'.\n>>> %s" %
 (wd, err.GetCString()))
 
+def setSvr4Support(self, enabled):
+self.runCmd(
+"settings set plugin.process.gdb-remote.use-libraries-svr4 
{enabled}".format(
+enabled="true" if enabled else "false"
+)
+)
+
 # libloadunload_d.so does not appear in the image list because executable
 # dependencies are resolved relative to the debuggers PWD. Bug?
 @expectedFailureAll(oslist=["linux"])
@@ -224,6 +231,20 @@
 @skipIfFreeBSD  # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase 
support
 @skipIfWindows  # Windows doesn't have dlopen and friends, dynamic 
libraries work differently
 def test_lldb_process_load_and_unload_commands(self):
+self.setSvr4Support(False)
+self.run_lldb_process_load_and_unload_commands()
+
+@expectedFailureAll(
+bugnumber="llvm.org/pr25805",
+hostoslist=["windows"],
+triple='.*-android')
+@skipIfFreeBSD  # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase 
support
+@skipIfWindows  # Windows doesn't have dlopen and friends, dynamic 
libraries work differently
+def test_lldb_process_load_and_unload_commands_with_svr4(self):
+self.setSvr4Support(True)
+self.run_lldb_process_load_and_unload_commands()
+
+def run_lldb_process_load_and_unload_commands(self):
 """Test that lldb process load/unload command work correctly."""
 self.copy_shlibs_to_remote()
 
@@ -295,6 +316,15 @@
 
 @skipIfFreeBSD  # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase 
support
 def test_load_unload(self):
+self.setSvr4Support(False)
+self.run_load_unload()
+
+@skipIfFreeBSD  # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase 
support
+def test_load_unload_with_svr4(self):
+self.setSvr4Support(True)
+self.run_load_unload()
+
+def run_load_unload(self):
 """Test breakpoint by name works correctly with dlopen'ing."""
 self.copy_shlibs_to_remote()
 
@@ -335,6 +365,16 @@
 @skipIfFreeBSD  # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase 
support
 @skipIfWindows  # Windows doesn't have dlopen and friends, dynamic 
libraries work differently
 def test_step_over_load(self):
+self.setSvr4Support(False)
+self.run_step_over_load()
+
+@skipIfFreeBSD  # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase 
support
+@skipIfWindows  # Windows doesn't have dlopen and friends, dynamic 
libraries work differently
+def test_step_over_load_with_svr4(self):
+self.setSvr4Support(True)
+self.run_step_over_load()
+
+def run_step_over_load(self):
 """Test stepping over code that loads a shared library works 
correctly."""
 self.copy_shlibs_to_remote()
 


Index: lldb/packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py
===
--- lldb/packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py
+++ lldb/packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py
@@ -93,6 +93,13 @@
 "Unable copy 'libloadunload_d.so' to '%s'.\n>>> %s" %
 (wd, err.GetCString()))
 
+def setSvr4Support(self, enabled):
+self.runCmd(
+"settings set plugin.process.gdb-remote.use-libraries-svr4 {enabled}".format(
+enabled="true" if enabled else "false"
+)
+)
+
 # libloadunload_d.so does not appear in the image list because executable
 # dependencies are resolved relative to the debuggers PWD. Bug?
 @expectedFailureAll(oslist=["linux"])
@@ -224,6 +231,20 @@
 @skipIfFreeBSD  # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase support
 @skipIfWindows  # Windows doesn't have dlopen and friends, dynamic libraries work differently
 def test_lldb_process_load_and_unload_commands(self):
+self.setSvr4Support(False)

[Lldb-commits] [PATCH] D65123: Restore tests for lldb-server and lldb-vscode removed at rL366590

2019-07-23 Thread António Afonso via Phabricator via lldb-commits
aadsm added a comment.

@jankratochvil interesting, we're also not able to run the lldb-vscode tests 
and it was on my todo list to take a look. Although I didn't realize it was a 
common think I thought it was specific to the environment where I was trying to 
run them. /cc @xiaobai. Thanks for looking into this!


Repository:
  rL LLVM

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

https://reviews.llvm.org/D65123



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


[Lldb-commits] [PATCH] D65123: Restore tests for lldb-server and lldb-vscode removed at rL366590

2019-07-23 Thread António Afonso via Phabricator via lldb-commits
aadsm added a comment.

@Hui what do you mean? the history is still there:

  $ git log 
lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
  commit a61c247ce189efe7641dccb8ad7f85f60fc72220 (master)
  Author: Antonio Afonso 
  Date:   Mon Jul 22 23:35:05 2019 +
  
  Restore tests for lldb-server and lldb-vscode removed at rL366590
  
  commit b45853f173139c7c3078b97f53e7a6eba6148c13
  Author: Raphael Isemann 
  Date:   Fri Jul 19 15:55:23 2019 +
  
  [lldb][NFC] Cleanup mentions and code related to lldb-mi
  
  commit 08c38f77c5fb4d3735ec215032fed8ee6730b3db
  Author: Pavel Labath 
  Date:   Mon Jul 1 12:41:20 2019 +
  
  Revert "Implement xfer:libraries-svr4:read packet"
  ...


Repository:
  rL LLVM

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

https://reviews.llvm.org/D65123



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


[Lldb-commits] [PATCH] D62503: Add ReadCStringFromMemory for faster string reads

2019-07-23 Thread António Afonso via Phabricator via lldb-commits
aadsm added a comment.

I've just done these 2 steps:

- Revert rL364751  (which is a revert itself)
- Revert 9c10b620c061 
 (will 
re-apply this one)

Should be fine since now we have an option that is false by default. Will then 
land D64013 .


Repository:
  rL LLVM

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

https://reviews.llvm.org/D62503



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


[Lldb-commits] [PATCH] D65171: [LLDB] Find debugserver in Command Line Tools as well

2019-07-23 Thread António Afonso via Phabricator via lldb-commits
aadsm created this revision.
aadsm added reviewers: clayborg, JDevlieghere.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This might be an edge case in regular use but if you're shipping an lldb 
version with no debugserver lldb will try to use the System one.
However, lldb only knows how to find the Xcode one and not the Command Line 
Tools one. This diff fixes that.

We try to find debugserver with 
`PlatformDarwin::LocateExecutable("debugserver")`, we call `xcode-select -p` to 
get the path and then assume this path is of Xcode.

The changes I did are:

- Change `PlatformDarwin::LocateExecutable` to also add the Command Line Tools 
directory to the list of paths to search for debugserver.
- Created a new function to find the Command Line Tools directory named 
`GetCommandLineToolsLibraryPath`.
- Refactored the code that calls `xcode-select -p` into its own function 
`GetXcodeSelectPath()`. There were 2 identical pieces of code for this so I 
reduced it to one and used this function everywhere instead.
- I also changed `PlatformDarwin::GetSDKDirectoryForModules` to use the `SDKs` 
directory that exists in the Command Line Tools installation.

I'm not sure how to create tests for this. PlatformDarwinTest is really limited 
and I couldn't find how to mock Filesystem::Instance() so I could create a 
virtual file system.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65171

Files:
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp

Index: lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
===
--- lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -1107,6 +1107,34 @@
   return false;
 }
 
+static FileSpec GetXcodeSelectPath() {
+  static FileSpec g_xcode_select_filespec;
+
+  if (!g_xcode_select_filespec) {
+FileSpec xcode_select_cmd("/usr/bin/xcode-select");
+if (FileSystem::Instance().Exists(xcode_select_cmd)) {
+  int exit_status = -1;
+  int signo = -1;
+  std::string command_output;
+  Status status =
+  Host::RunShellCommand("/usr/bin/xcode-select --print-path",
+nullptr, // current working directory
+&exit_status, &signo, &command_output,
+std::chrono::seconds(2), // short timeout
+false);  // don't run in a shell
+  if (status.Success() && exit_status == 0 && !command_output.empty()) {
+size_t first_non_newline = command_output.find_last_not_of("\r\n");
+if (first_non_newline != std::string::npos) {
+  command_output.erase(first_non_newline + 1);
+}
+g_xcode_select_filespec = FileSpec(command_output);
+  }
+}
+  }
+
+  return g_xcode_select_filespec;
+}
+
 // Return a directory path like /Applications/Xcode.app/Contents/Developer
 const char *PlatformDarwin::GetDeveloperDirectory() {
   std::lock_guard guard(m_mutex);
@@ -1164,34 +1192,10 @@
 }
 
 if (!developer_dir_path_valid) {
-  FileSpec xcode_select_cmd("/usr/bin/xcode-select");
-  if (FileSystem::Instance().Exists(xcode_select_cmd)) {
-int exit_status = -1;
-int signo = -1;
-std::string command_output;
-Status error =
-Host::RunShellCommand("/usr/bin/xcode-select --print-path",
-  nullptr, // current working directory
-  &exit_status, &signo, &command_output,
-  std::chrono::seconds(2), // short timeout
-  false); // don't run in a shell
-if (error.Success() && exit_status == 0 && !command_output.empty()) {
-  const char *cmd_output_ptr = command_output.c_str();
-  developer_dir_path[sizeof(developer_dir_path) - 1] = '\0';
-  size_t i;
-  for (i = 0; i < sizeof(developer_dir_path) - 1; i++) {
-if (cmd_output_ptr[i] == '\r' || cmd_output_ptr[i] == '\n' ||
-cmd_output_ptr[i] == '\0')
-  break;
-developer_dir_path[i] = cmd_output_ptr[i];
-  }
-  developer_dir_path[i] = '\0';
-
-  FileSpec devel_dir(developer_dir_path);
-  if (FileSystem::Instance().IsDirectory(devel_dir)) {
-developer_dir_path_valid = true;
-  }
-}
+  FileSpec devel_dir = GetXcodeSelectPath();
+  if (FileSystem::Instance().IsDirectory(devel_dir)) {
+devel_dir.GetPath(&developer_dir_path[0], sizeof(developer_dir_path));
+developer_dir_path_valid = true;
   }
 }
 
@@ -1333,29 +1337,11 @@
 g_xcode_filespec = CheckPathForXcode(developer_dir_spec);
   }
 
-  // Fall back to using "xcrun" to find the selected Xcode
+  // Fall back to using "xcode-select" to find the selected Xcode
   if (!g_xc

[Lldb-commits] [PATCH] D64013: Correctly use GetLoadedModuleList to take advantage of libraries-svr4

2019-07-24 Thread António Afonso via Phabricator via lldb-commits
aadsm updated this revision to Diff 211661.
aadsm added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64013

Files:
  lldb/include/lldb/Target/Process.h
  lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp
  lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.h
  lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
  lldb/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h

Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
===
--- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
+++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
@@ -200,9 +200,9 @@
 
   llvm::VersionTuple GetHostOSVersion() override;
 
-  size_t LoadModules(LoadedModuleInfoList &module_list) override;
+  llvm::Error LoadModules() override;
 
-  size_t LoadModules() override;
+  llvm::Expected GetLoadedModuleList() override;
 
   Status GetFileLoadAddress(const FileSpec &file, bool &is_loaded,
 lldb::addr_t &load_addr) override;
@@ -391,9 +391,6 @@
   // Query remote GDBServer for register information
   bool GetGDBServerRegisterInfo(ArchSpec &arch);
 
-  // Query remote GDBServer for a detailed loaded library list
-  Status GetLoadedModuleList(LoadedModuleInfoList &);
-
   lldb::ModuleSP LoadModuleAtAddress(const FileSpec &file,
  lldb::addr_t link_map,
  lldb::addr_t base_addr,
Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -2390,7 +2390,12 @@
 ostr.Printf("%" PRIu64 " %" PRIu32, wp_addr, wp_index);
 description = ostr.GetString();
   } else if (key.compare("library") == 0) {
-LoadModules();
+auto error = LoadModules();
+if (error) {
+  Log *log(
+  ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
+  LLDB_LOG_ERROR(log, std::move(error), "Failed to load modules: {0}");
+}
   } else if (key.size() == 2 && ::isxdigit(key[0]) && ::isxdigit(key[1])) {
 uint32_t reg = UINT32_MAX;
 if (!key.getAsInteger(16, reg))
@@ -2742,9 +2747,13 @@
 
   // the loaded module list can also provides a link map address
   if (addr == LLDB_INVALID_ADDRESS) {
-LoadedModuleInfoList list;
-if (GetLoadedModuleList(list).Success())
-  addr = list.m_link_map;
+llvm::Expected list = GetLoadedModuleList();
+if (!list) {
+  Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
+  LLDB_LOG_ERROR(log, list.takeError(), "Failed to read module list: {0}");
+} else {
+  addr = list->m_link_map;
+}
   }
 
   return addr;
@@ -4682,39 +4691,43 @@
   return m_register_info.GetNumRegisters() > 0;
 }
 
-Status ProcessGDBRemote::GetLoadedModuleList(LoadedModuleInfoList &list) {
+llvm::Expected ProcessGDBRemote::GetLoadedModuleList() {
   // Make sure LLDB has an XML parser it can use first
   if (!XMLDocument::XMLEnabled())
-return Status(0, ErrorType::eErrorTypeGeneric);
+return llvm::createStringError(llvm::inconvertibleErrorCode(),
+   "XML parsing not available");
 
   Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS);
   LLDB_LOGF(log, "ProcessGDBRemote::%s", __FUNCTION__);
 
+  LoadedModuleInfoList list;
   GDBRemoteCommunicationClient &comm = m_gdb_comm;
   bool can_use_svr4 = GetGlobalPluginProperties()->GetUseSVR4();
 
   // check that we have extended feature read support
   if (can_use_svr4 && comm.GetQXferLibrariesSVR4ReadSupported()) {
-list.clear();
-
 // request the loaded library list
 std::string raw;
 lldb_private::Status lldberr;
 
 if (!comm.ReadExtFeature(ConstString("libraries-svr4"), ConstString(""),
  raw, lldberr))
-  return Status(0, ErrorType::eErrorTypeGeneric);
+  return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "Error in libraries-svr4 packet");
 
 // parse the xml file in memory
 LLDB_LOGF(log, "parsing: %s", raw.c_str());
 XMLDocument doc;
 
 if (!doc.ParseMemory(raw.c_str(), raw.size(), "noname.xml"))
-  return Status(0, ErrorType::eErrorTypeGeneric);
+  return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "Error reading noname.xml");
 
 XMLNode root_element = doc.GetRootElement("library-list-svr4");
 if (!root_element)
-  return Status();
+  ret

[Lldb-commits] [PATCH] D64013: Correctly use GetLoadedModuleList to take advantage of libraries-svr4

2019-07-25 Thread António Afonso via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL367020: Correctly use GetLoadedModuleList to take advantage 
of libraries-svr4 (authored by aadsm, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64013?vs=211661&id=211745#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64013

Files:
  lldb/trunk/include/lldb/Target/Process.h
  lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp
  lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.h
  lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
  
lldb/trunk/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp
  lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h

Index: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
===
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
@@ -200,9 +200,9 @@
 
   llvm::VersionTuple GetHostOSVersion() override;
 
-  size_t LoadModules(LoadedModuleInfoList &module_list) override;
+  llvm::Error LoadModules() override;
 
-  size_t LoadModules() override;
+  llvm::Expected GetLoadedModuleList() override;
 
   Status GetFileLoadAddress(const FileSpec &file, bool &is_loaded,
 lldb::addr_t &load_addr) override;
@@ -391,9 +391,6 @@
   // Query remote GDBServer for register information
   bool GetGDBServerRegisterInfo(ArchSpec &arch);
 
-  // Query remote GDBServer for a detailed loaded library list
-  Status GetLoadedModuleList(LoadedModuleInfoList &);
-
   lldb::ModuleSP LoadModuleAtAddress(const FileSpec &file,
  lldb::addr_t link_map,
  lldb::addr_t base_addr,
Index: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
===
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -2390,7 +2390,12 @@
 ostr.Printf("%" PRIu64 " %" PRIu32, wp_addr, wp_index);
 description = ostr.GetString();
   } else if (key.compare("library") == 0) {
-LoadModules();
+auto error = LoadModules();
+if (error) {
+  Log *log(
+  ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
+  LLDB_LOG_ERROR(log, std::move(error), "Failed to load modules: {0}");
+}
   } else if (key.size() == 2 && ::isxdigit(key[0]) && ::isxdigit(key[1])) {
 uint32_t reg = UINT32_MAX;
 if (!key.getAsInteger(16, reg))
@@ -2742,9 +2747,13 @@
 
   // the loaded module list can also provides a link map address
   if (addr == LLDB_INVALID_ADDRESS) {
-LoadedModuleInfoList list;
-if (GetLoadedModuleList(list).Success())
-  addr = list.m_link_map;
+llvm::Expected list = GetLoadedModuleList();
+if (!list) {
+  Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
+  LLDB_LOG_ERROR(log, list.takeError(), "Failed to read module list: {0}");
+} else {
+  addr = list->m_link_map;
+}
   }
 
   return addr;
@@ -4682,39 +4691,43 @@
   return m_register_info.GetNumRegisters() > 0;
 }
 
-Status ProcessGDBRemote::GetLoadedModuleList(LoadedModuleInfoList &list) {
+llvm::Expected ProcessGDBRemote::GetLoadedModuleList() {
   // Make sure LLDB has an XML parser it can use first
   if (!XMLDocument::XMLEnabled())
-return Status(0, ErrorType::eErrorTypeGeneric);
+return llvm::createStringError(llvm::inconvertibleErrorCode(),
+   "XML parsing not available");
 
   Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS);
   LLDB_LOGF(log, "ProcessGDBRemote::%s", __FUNCTION__);
 
+  LoadedModuleInfoList list;
   GDBRemoteCommunicationClient &comm = m_gdb_comm;
   bool can_use_svr4 = GetGlobalPluginProperties()->GetUseSVR4();
 
   // check that we have extended feature read support
   if (can_use_svr4 && comm.GetQXferLibrariesSVR4ReadSupported()) {
-list.clear();
-
 // request the loaded library list
 std::string raw;
 lldb_private::Status lldberr;
 
 if (!comm.ReadExtFeature(ConstString("libraries-svr4"), ConstString(""),
  raw, lldberr))
-  return Status(0, ErrorType::eErrorTypeGeneric);
+  return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "Error in libraries-svr4 packet");
 
 // parse the xml file in memory
 LLDB_LOGF(log, "parsing: %s", raw.c_str());
 XMLDocument doc;
 
 if (!doc.ParseMemory(raw.c_str()

[Lldb-commits] [PATCH] D65171: [LLDB] Find debugserver in Command Line Tools as well

2019-07-25 Thread António Afonso via Phabricator via lldb-commits
aadsm added a comment.

@clayborg, yes, I made sure of that, we always first check the Xcode path.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65171



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


[Lldb-commits] [PATCH] D65171: [LLDB] Find debugserver in Command Line Tools as well

2019-07-25 Thread António Afonso via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL367052: [LLDB] Find debugserver in Command Line Tools as 
well (authored by aadsm, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65171?vs=211372&id=211815#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D65171

Files:
  lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp

Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
===
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -1102,6 +1102,34 @@
   return false;
 }
 
+static FileSpec GetXcodeSelectPath() {
+  static FileSpec g_xcode_select_filespec;
+
+  if (!g_xcode_select_filespec) {
+FileSpec xcode_select_cmd("/usr/bin/xcode-select");
+if (FileSystem::Instance().Exists(xcode_select_cmd)) {
+  int exit_status = -1;
+  int signo = -1;
+  std::string command_output;
+  Status status =
+  Host::RunShellCommand("/usr/bin/xcode-select --print-path",
+nullptr, // current working directory
+&exit_status, &signo, &command_output,
+std::chrono::seconds(2), // short timeout
+false);  // don't run in a shell
+  if (status.Success() && exit_status == 0 && !command_output.empty()) {
+size_t first_non_newline = command_output.find_last_not_of("\r\n");
+if (first_non_newline != std::string::npos) {
+  command_output.erase(first_non_newline + 1);
+}
+g_xcode_select_filespec = FileSpec(command_output);
+  }
+}
+  }
+
+  return g_xcode_select_filespec;
+}
+
 // Return a directory path like /Applications/Xcode.app/Contents/Developer
 const char *PlatformDarwin::GetDeveloperDirectory() {
   std::lock_guard guard(m_mutex);
@@ -1159,34 +1187,10 @@
 }
 
 if (!developer_dir_path_valid) {
-  FileSpec xcode_select_cmd("/usr/bin/xcode-select");
-  if (FileSystem::Instance().Exists(xcode_select_cmd)) {
-int exit_status = -1;
-int signo = -1;
-std::string command_output;
-Status error =
-Host::RunShellCommand("/usr/bin/xcode-select --print-path",
-  nullptr, // current working directory
-  &exit_status, &signo, &command_output,
-  std::chrono::seconds(2), // short timeout
-  false); // don't run in a shell
-if (error.Success() && exit_status == 0 && !command_output.empty()) {
-  const char *cmd_output_ptr = command_output.c_str();
-  developer_dir_path[sizeof(developer_dir_path) - 1] = '\0';
-  size_t i;
-  for (i = 0; i < sizeof(developer_dir_path) - 1; i++) {
-if (cmd_output_ptr[i] == '\r' || cmd_output_ptr[i] == '\n' ||
-cmd_output_ptr[i] == '\0')
-  break;
-developer_dir_path[i] = cmd_output_ptr[i];
-  }
-  developer_dir_path[i] = '\0';
-
-  FileSpec devel_dir(developer_dir_path);
-  if (FileSystem::Instance().IsDirectory(devel_dir)) {
-developer_dir_path_valid = true;
-  }
-}
+  FileSpec devel_dir = GetXcodeSelectPath();
+  if (FileSystem::Instance().IsDirectory(devel_dir)) {
+devel_dir.GetPath(&developer_dir_path[0], sizeof(developer_dir_path));
+developer_dir_path_valid = true;
   }
 }
 
@@ -1328,29 +1332,11 @@
 g_xcode_filespec = CheckPathForXcode(developer_dir_spec);
   }
 
-  // Fall back to using "xcrun" to find the selected Xcode
+  // Fall back to using "xcode-select" to find the selected Xcode
   if (!g_xcode_filespec) {
-int status = 0;
-int signo = 0;
-std::string output;
-const char *command = "/usr/bin/xcode-select -p";
-lldb_private::Status error = Host::RunShellCommand(
-command, // shell command to run
-nullptr, // current working directory
-&status, // Put the exit status of the process in here
-&signo,  // Put the signal that caused the process to exit in here
-&output, // Get the output from the command and place it in this
- // string
-std::chrono::seconds(3));
-if (status == 0 && !output.empty()) {
-  size_t first_non_newline = output.find_last_not_of("\r\n");
-  if (first_non_newline != std::string::npos) {
-output.erase(first_non_newline + 1);
-  }
-  output.append("/..");
-
-  g_xcode_filespec = CheckPathForXcode(FileSpec(output));

[Lldb-commits] [PATCH] D65129: Test load unloading of modules with libraries-svr4

2019-07-29 Thread António Afonso via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL367247: Test load unloading of modules with libraries-svr4 
(authored by aadsm, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65129?vs=211242&id=212202#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D65129

Files:
  
lldb/trunk/packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py


Index: 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py
===
--- 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py
+++ 
lldb/trunk/packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py
@@ -93,6 +93,13 @@
 "Unable copy 'libloadunload_d.so' to '%s'.\n>>> %s" %
 (wd, err.GetCString()))
 
+def setSvr4Support(self, enabled):
+self.runCmd(
+"settings set plugin.process.gdb-remote.use-libraries-svr4 
{enabled}".format(
+enabled="true" if enabled else "false"
+)
+)
+
 # libloadunload_d.so does not appear in the image list because executable
 # dependencies are resolved relative to the debuggers PWD. Bug?
 @expectedFailureAll(oslist=["linux"])
@@ -224,6 +231,20 @@
 @skipIfFreeBSD  # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase 
support
 @skipIfWindows  # Windows doesn't have dlopen and friends, dynamic 
libraries work differently
 def test_lldb_process_load_and_unload_commands(self):
+self.setSvr4Support(False)
+self.run_lldb_process_load_and_unload_commands()
+
+@expectedFailureAll(
+bugnumber="llvm.org/pr25805",
+hostoslist=["windows"],
+triple='.*-android')
+@skipIfFreeBSD  # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase 
support
+@skipIfWindows  # Windows doesn't have dlopen and friends, dynamic 
libraries work differently
+def test_lldb_process_load_and_unload_commands_with_svr4(self):
+self.setSvr4Support(True)
+self.run_lldb_process_load_and_unload_commands()
+
+def run_lldb_process_load_and_unload_commands(self):
 """Test that lldb process load/unload command work correctly."""
 self.copy_shlibs_to_remote()
 
@@ -295,6 +316,15 @@
 
 @skipIfFreeBSD  # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase 
support
 def test_load_unload(self):
+self.setSvr4Support(False)
+self.run_load_unload()
+
+@skipIfFreeBSD  # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase 
support
+def test_load_unload_with_svr4(self):
+self.setSvr4Support(True)
+self.run_load_unload()
+
+def run_load_unload(self):
 """Test breakpoint by name works correctly with dlopen'ing."""
 self.copy_shlibs_to_remote()
 
@@ -335,6 +365,16 @@
 @skipIfFreeBSD  # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase 
support
 @skipIfWindows  # Windows doesn't have dlopen and friends, dynamic 
libraries work differently
 def test_step_over_load(self):
+self.setSvr4Support(False)
+self.run_step_over_load()
+
+@skipIfFreeBSD  # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase 
support
+@skipIfWindows  # Windows doesn't have dlopen and friends, dynamic 
libraries work differently
+def test_step_over_load_with_svr4(self):
+self.setSvr4Support(True)
+self.run_step_over_load()
+
+def run_step_over_load(self):
 """Test stepping over code that loads a shared library works 
correctly."""
 self.copy_shlibs_to_remote()
 


Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py
===
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py
@@ -93,6 +93,13 @@
 "Unable copy 'libloadunload_d.so' to '%s'.\n>>> %s" %
 (wd, err.GetCString()))
 
+def setSvr4Support(self, enabled):
+self.runCmd(
+"settings set plugin.process.gdb-remote.use-libraries-svr4 {enabled}".format(
+enabled="true" if enabled else "false"
+)
+)
+
 # libloadunload_d.so does not appear in the image list because executable
 # dependencies are resolved relative to the debuggers PWD. Bug?
 @expectedFailureAll(oslist=["linux"])
@@ -224,6 +231,20 @@
 @skipIfFreeBSD  # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase support
 @skipIfWindows  # Windows doesn't have dlopen and friends, dynamic libraries work differently
 def test_lldb_process_

[Lldb-commits] [PATCH] D65949: unittests: Use yaml2obj as a library instead of an external process

2019-08-08 Thread António Afonso via Phabricator via lldb-commits
aadsm added a comment.

I can see the appeal of having the contents next to the logic that is testing 
it, but I'm somewhat concerned for the cases where it includes +1000 lines of 
YAML in the test file. I think for those cases it might make sense to consider 
these fixtures and be in their own file?


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

https://reviews.llvm.org/D65949



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


[Lldb-commits] [PATCH] D68069: Explicitly set entry point arch when it's thumb

2019-09-25 Thread António Afonso via Phabricator via lldb-commits
aadsm created this revision.
aadsm added reviewers: clayborg, labath, wallace.
Herald added subscribers: lldb-commits, MaskRay, kristof.beyls, arichardson, 
emaste, srhines.
Herald added a reviewer: espindola.
Herald added a project: LLDB.

I found a case where the main android binary (app_process32) had thumb code at 
its entry point but no entry in the symbol table indicating this. This made 
lldb set a 4 byte breakpoint at that address (we default to arm code) instead 
of a 2 byte one (like we should for thumb).
The big deal with this is that the expression evaluator uses the entry point as 
a way to know when a JITed expression has finished executing by putting a 
breakpoint there. Because of this, evaluating expressions on certain android 
devices (Google Pixel something) made the process crash.
This was fixed by checking this specific situation when we parse the symbol 
table and add an artificial symbol for this 2 byte range and indicating that 
it's arm thumb.

I created 2 unit tests for this, one to check that now we know that the entry 
point is arm thumb, and the other to make sure we didn't change the behaviour 
for arm code.

I also run the following on the command line with the `app_process32` where I 
found the issue:
**Before:**

  (lldb) dis -s 0x1640 -e 0x1644
  app_process32[0x1640]: .long  0xf0004668; unknown opcode

**After:**

  (lldb) dis -s 0x1640 -e 0x1644
  app_process32`:
  app_process32[0x1640] <+0>: movr0, sp
  app_process32[0x1642]:  andeq  r0, r0, r0


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68069

Files:
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp

Index: lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
===
--- lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
+++ lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
@@ -172,3 +172,131 @@
   Uuid.SetFromStringRef("1b8a73ac238390e32a7ff4ac8ebe4d6a41ecf5c9", 20);
   EXPECT_EQ(Spec.GetUUID(), Uuid);
 }
+
+TEST_F(ObjectFileELFTest, GetSymtab_NoSymEntryPointArmThumbAddressClass) {
+  /*
+  // nosym-entrypoint-arm-thumb.s
+  .global _Start
+  .thumb_func
+  _start:
+  mov r0, #42
+  mov r7, #1
+  svc #0
+  // arm-linux-androideabi-as nosym-entrypoint-arm-thumb.s
+  //   -o nosym-entrypoint-arm-thumb.o
+  // arm-linux-androideabi-ld nosym-entrypoint-arm-thumb.o
+  //   -o nosym-entrypoint-arm-thumb -e 0x8075 -s
+  */
+  auto ExpectedFile = TestFile::fromYaml(R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_ARM
+  Flags:   [ EF_ARM_SOFT_FLOAT, EF_ARM_EABI_VER5 ]
+  Entry:   0x8075
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+Address: 0x8074
+AddressAlign:0x0002
+Content: 2A20012700DF
+  - Name:.data
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+Content: ''
+  - Name:.bss
+Type:SHT_NOBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+  - Name:.note.gnu.gold-version
+Type:SHT_NOTE
+AddressAlign:0x0004
+Content: 040009000400474E5500676F6C6420312E313100
+  - Name:.ARM.attributes
+Type:SHT_ARM_ATTRIBUTES
+AddressAlign:0x0001
+Content: '41130061656162690001090006020901'
+...
+)");
+  ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded());
+
+  ModuleSpec spec{FileSpec(ExpectedFile->name())};
+  spec.GetSymbolFileSpec().SetFile(ExpectedFile->name(),
+   FileSpec::Style::native);
+  auto module_sp = std::make_shared(spec);
+
+  auto entry_point_addr = module_sp->GetObjectFile()->GetEntryPointAddress();
+  ASSERT_TRUE(entry_point_addr.GetOffset() & 1);
+  // Decrease the offsite by 1 to make it into a breakable address since this
+  // is Thumb.
+  entry_point_addr.SetOffset(entry_point_addr.GetOffset() - 1);
+  ASSERT_EQ(entry_point_addr.GetAddressClass(),
+AddressClass::eCodeAlternateISA);
+}
+
+TEST_F(ObjectFileELFTest, GetSymtab_NoSymEntryPointArmAddressClass) {
+  /*
+  // nosym-entrypoint-arm.s
+  .global _Start
+  _start:
+  mov r0, #42
+  mov r7, #1
+  svc #0
+  // arm-linux-androideabi-as nosym-entrypoint-arm.s
+  //   -o nosym-entrypoint-arm.o
+  // arm-linux-androideabi-ld nosym-entrypoint-arm.o
+  //   -o nosym-entrypoint-arm -e 0x8074 -s
+  */
+  auto ExpectedFile = TestFile::fromYaml(R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32

[Lldb-commits] [PATCH] D68069: Explicitly set entry point arch when it's thumb

2019-09-26 Thread António Afonso via Phabricator via lldb-commits
aadsm marked an inline comment as done.
aadsm added a comment.

> For the test, what would you say to writing that as a lit test instead 
> (testing the address class deduction via the disassemble command you 
> mentioned)?

I was actually keen on this since lit is the only type of test I haven't used 
yet but then thought that it wouldn't really test my change directly (just 
indirectly). I know I put that as a test in my summary but it was more like a 
sanity check. The real test here is checking the address class (which is what 
is changed in the code). There are different things in lldb that uses that like 
setting a breakpoint or disassembling instructions, that's why I don't feel 
that testing the consequence is the ideal test. What do you think?

> The yaml is actually fairly readable as is, but given that you felt the need 
> to include the commands used to produce that input, it might be better to 
> actually produce that file via the commands as a part of the test 
> (substituting llvm-mc for as and ld.lld for linker).

I just put it there for completion sake, I always like to have the source of 
things when I didn't do it by hand. In this case I prefer to have the yaml 
because I'm not sure if in all scenarios that we run the test we'll be able to 
assemble arm assembly into an object?




Comment at: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp:2737-2738
+  0,  // Offset in section or symbol value.
+  2,  // Size.
+  true,   // Size is valid.
+  false,  // Contains linker annotations?

labath wrote:
> This is pretty arbitrary. Would it be possible to just set 
> size_is_valid=false, and let the usual symbol size deduction logic figure out 
> something reasonable here?
To be honest I'm not sure how the size_is_valid = false is used as I've only 
seen it being used when going through the EH frame FDE entries.

Setting the size to 0 is problematic though, when the symbol is added to the 
symtab its size will automatically span to the next function symbol boundary. I 
think this can be dangerous because the symtab for the object file might not 
have all function boundaries defined and in the event that we have mixed 
arm/thumb code in it, it will incorrectly mark arm code as thumb. This is why I 
wanted to be conservative here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68069



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


[Lldb-commits] [PATCH] D68069: Explicitly set entry point arch when it's thumb

2019-09-26 Thread António Afonso via Phabricator via lldb-commits
aadsm updated this revision to Diff 222063.
aadsm added a comment.

Use GetNextSyntheticSymbolName() to generate the symbol name


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68069

Files:
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp

Index: lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
===
--- lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
+++ lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
@@ -172,3 +172,131 @@
   Uuid.SetFromStringRef("1b8a73ac238390e32a7ff4ac8ebe4d6a41ecf5c9", 20);
   EXPECT_EQ(Spec.GetUUID(), Uuid);
 }
+
+TEST_F(ObjectFileELFTest, GetSymtab_NoSymEntryPointArmThumbAddressClass) {
+  /*
+  // nosym-entrypoint-arm-thumb.s
+  .global _Start
+  .thumb_func
+  _start:
+  mov r0, #42
+  mov r7, #1
+  svc #0
+  // arm-linux-androideabi-as nosym-entrypoint-arm-thumb.s
+  //   -o nosym-entrypoint-arm-thumb.o
+  // arm-linux-androideabi-ld nosym-entrypoint-arm-thumb.o
+  //   -o nosym-entrypoint-arm-thumb -e 0x8075 -s
+  */
+  auto ExpectedFile = TestFile::fromYaml(R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_ARM
+  Flags:   [ EF_ARM_SOFT_FLOAT, EF_ARM_EABI_VER5 ]
+  Entry:   0x8075
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+Address: 0x8074
+AddressAlign:0x0002
+Content: 2A20012700DF
+  - Name:.data
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+Content: ''
+  - Name:.bss
+Type:SHT_NOBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+  - Name:.note.gnu.gold-version
+Type:SHT_NOTE
+AddressAlign:0x0004
+Content: 040009000400474E5500676F6C6420312E313100
+  - Name:.ARM.attributes
+Type:SHT_ARM_ATTRIBUTES
+AddressAlign:0x0001
+Content: '41130061656162690001090006020901'
+...
+)");
+  ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded());
+
+  ModuleSpec spec{FileSpec(ExpectedFile->name())};
+  spec.GetSymbolFileSpec().SetFile(ExpectedFile->name(),
+   FileSpec::Style::native);
+  auto module_sp = std::make_shared(spec);
+
+  auto entry_point_addr = module_sp->GetObjectFile()->GetEntryPointAddress();
+  ASSERT_TRUE(entry_point_addr.GetOffset() & 1);
+  // Decrease the offsite by 1 to make it into a breakable address since this
+  // is Thumb.
+  entry_point_addr.SetOffset(entry_point_addr.GetOffset() - 1);
+  ASSERT_EQ(entry_point_addr.GetAddressClass(),
+AddressClass::eCodeAlternateISA);
+}
+
+TEST_F(ObjectFileELFTest, GetSymtab_NoSymEntryPointArmAddressClass) {
+  /*
+  // nosym-entrypoint-arm.s
+  .global _Start
+  _start:
+  mov r0, #42
+  mov r7, #1
+  svc #0
+  // arm-linux-androideabi-as nosym-entrypoint-arm.s
+  //   -o nosym-entrypoint-arm.o
+  // arm-linux-androideabi-ld nosym-entrypoint-arm.o
+  //   -o nosym-entrypoint-arm -e 0x8074 -s
+  */
+  auto ExpectedFile = TestFile::fromYaml(R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_ARM
+  Flags:   [ EF_ARM_SOFT_FLOAT, EF_ARM_EABI_VER5 ]
+  Entry:   0x8074
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+Address: 0x8074
+AddressAlign:0x0004
+Content: 2A00A0E30170A0E300EF
+  - Name:.data
+Type:SHT_PROGBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+Content: ''
+  - Name:.bss
+Type:SHT_NOBITS
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+Address: 0x9000
+AddressAlign:0x0001
+  - Name:.note.gnu.gold-version
+Type:SHT_NOTE
+AddressAlign:0x0004
+Content: 040009000400474E5500676F6C6420312E313100
+  - Name:.ARM.attributes
+Type:SHT_ARM_ATTRIBUTES
+AddressAlign:0x0001
+Content: '41130061656162690001090006010801'
+...
+)");
+  ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded());
+
+  ModuleSpec spec{FileSpec(ExpectedF

[Lldb-commits] [PATCH] D61235: Add more information to the log timer dump

2019-04-27 Thread António Afonso via Phabricator via lldb-commits
aadsm created this revision.
aadsm added a reviewer: clayborg.
Herald added subscribers: lldb-commits, abidh, jfb, erik.pilkington, aprantl.
Herald added a project: LLDB.

The `log timer dump` is showing the time of the function itself minus any 
function that is called from this one that also happens to be timed. However, 
this is really not obvious and it also makes it hard to understand the time 
spent in total and also which children are actually taking the time.
To get a better reading of the timer dump I added the total, children (which I 
named child) and also the hit count. I used these timers to figure out a 
performance issue and only after adding this things were more clear to me.

It looks like this:

  (lldb) log timer dump
  35.447713617 sec (total: 35.449s; child: 0.001s; count: 1374) for void 
SymbolFileDWARF::Index()
  29.717921481 sec (total: 29.718s; child: 0.000s; count: 8230500) for const 
lldb_private::ConstString 
&lldb_private::Mangled::GetDemangledName(lldb::LanguageType) const
  21.049508865 sec (total: 24.683s; child: 3.633s; count: 1399) for void 
lldb_private::Symtab::InitNameIndexes()
  ...


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D61235

Files:
  lldb/include/lldb/Utility/Timer.h
  lldb/source/Utility/Timer.cpp


Index: lldb/source/Utility/Timer.cpp
===
--- lldb/source/Utility/Timer.cpp
+++ lldb/source/Utility/Timer.cpp
@@ -41,6 +41,9 @@
 
 Timer::Category::Category(const char *cat) : m_name(cat) {
   m_nanos.store(0, std::memory_order_release);
+  m_nanos_total.store(0, std::memory_order_release);
+  m_nanos_child.store(0, std::memory_order_release);
+  m_count.store(0, std::memory_order_release);
   Category *expected = g_categories;
   do {
 m_next = expected;
@@ -93,6 +96,10 @@
 
   // Keep total results for each category so we can dump results.
   m_category.m_nanos += std::chrono::nanoseconds(timer_dur).count();
+  m_category.m_nanos_total += std::chrono::nanoseconds(total_dur).count();
+  m_category.m_nanos_child +=
+  std::chrono::nanoseconds(m_child_duration).count();
+  m_category.m_count++;
 }
 
 void Timer::SetDisplayDepth(uint32_t depth) { g_display_depth = depth; }
@@ -101,24 +108,38 @@
  * - returns whether a person is less than another person
  */
 
-typedef std::pair TimerEntry;
+struct Stats {
+  uint64_t nanos;
+  uint64_t nanos_total;
+  uint64_t nanos_child;
+  uint64_t count;
+};
+typedef std::pair TimerEntry;
 
 static bool CategoryMapIteratorSortCriterion(const TimerEntry &lhs,
  const TimerEntry &rhs) {
-  return lhs.second > rhs.second;
+  return lhs.second.nanos > rhs.second.nanos;
 }
 
 void Timer::ResetCategoryTimes() {
-  for (Category *i = g_categories; i; i = i->m_next)
+  for (Category *i = g_categories; i; i = i->m_next) {
 i->m_nanos.store(0, std::memory_order_release);
+i->m_nanos_total.store(0, std::memory_order_release);
+i->m_nanos_child.store(0, std::memory_order_release);
+i->m_count.store(0, std::memory_order_release);
+  }
 }
 
 void Timer::DumpCategoryTimes(Stream *s) {
   std::vector sorted;
   for (Category *i = g_categories; i; i = i->m_next) {
 uint64_t nanos = i->m_nanos.load(std::memory_order_acquire);
+uint64_t nanos_total = i->m_nanos_total.load(std::memory_order_acquire);
+uint64_t nanos_child = i->m_nanos_child.load(std::memory_order_acquire);
+uint64_t count = i->m_count.load(std::memory_order_acquire);
+Stats stats{nanos, nanos_total, nanos_child, count};
 if (nanos)
-  sorted.push_back(std::make_pair(i->m_name, nanos));
+  sorted.push_back(std::make_pair(i->m_name, stats));
   }
   if (sorted.empty())
 return; // Later code will break without any elements.
@@ -127,5 +148,9 @@
   llvm::sort(sorted.begin(), sorted.end(), CategoryMapIteratorSortCriterion);
 
   for (const auto &timer : sorted)
-s->Printf("%.9f sec for %s\n", timer.second / 10., timer.first);
+s->Printf("%.9f sec (total: %.3fs; child: %.3fs; count: %llu) for %s\n",
+  timer.second.nanos / 10.,
+  timer.second.nanos_total / 10.,
+  timer.second.nanos_child / 10., timer.second.count,
+  timer.first);
 }
Index: lldb/include/lldb/Utility/Timer.h
===
--- lldb/include/lldb/Utility/Timer.h
+++ lldb/include/lldb/Utility/Timer.h
@@ -30,6 +30,9 @@
 friend class Timer;
 const char *m_name;
 std::atomic m_nanos;
+std::atomic m_nanos_total;
+std::atomic m_nanos_child;
+std::atomic m_count;
 std::atomic m_next;
 
 DISALLOW_COPY_AND_ASSIGN(Category);


Index: lldb/source/Utility/Timer.cpp
===
--- lldb/source/Utility/Timer.cpp
+++ lldb/source/Utility/Timer.cpp
@@ -41,6 +41,9 @@
 
 Timer::Category::Category(const char *cat) : m_name(cat) {
   m_nanos.sto

[Lldb-commits] [PATCH] D61247: Add more information to the log timer dump

2019-04-28 Thread António Afonso via Phabricator via lldb-commits
aadsm created this revision.
Herald added subscribers: lldb-commits, jfb, erik.pilkington, aprantl.
Herald added a project: LLDB.
aadsm abandoned this revision.

The `log timer dump` is showing the time of the function itself minus any 
function that is called from this one that also happens to be timed. However, 
this is really not obvious and it also makes it hard to understand the time 
spent in total and also which children are actually taking the time.
To get a better reading of the timer dump I added the total, children (which I 
abbreviated to child) and also the hit count. I used these timers to figure out 
a performance issue and only after adding this things were more clear to me.

It looks like this:

  (lldb) log timer dump
  35.447713617 sec (total: 35.449s; child: 0.001s; count: 1374) for void 
SymbolFileDWARF::Index()
  29.717921481 sec (total: 29.718s; child: 0.000s; count: 8230500) for const 
lldb_private::ConstString 
&lldb_private::Mangled::GetDemangledName(lldb::LanguageType) const
  21.049508865 sec (total: 24.683s; child: 3.633s; count: 1399) for void 
lldb_private::Symtab::InitNameIndexes()
  ...


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D61247

Files:
  lldb/include/lldb/Utility/Timer.h
  lldb/source/Utility/Timer.cpp
  lldb/unittests/Utility/TimerTest.cpp

Index: lldb/unittests/Utility/TimerTest.cpp
===
--- lldb/unittests/Utility/TimerTest.cpp
+++ lldb/unittests/Utility/TimerTest.cpp
@@ -61,7 +61,9 @@
   StreamString ss;
   Timer::DumpCategoryTimes(&ss);
   double seconds1, seconds2;
-  ASSERT_EQ(2, sscanf(ss.GetData(), "%lf sec for CAT1%*[\n ]%lf sec for CAT2",
+  ASSERT_EQ(2, sscanf(ss.GetData(),
+  "%lf sec (total: %*lfs; child: %*lfs; count: %*d) for "
+  "CAT1%*[\n ]%lf sec for CAT2",
   &seconds1, &seconds2))
   << "String: " << ss.GetData();
   EXPECT_LT(0.01, seconds1);
@@ -69,3 +71,36 @@
   EXPECT_LT(0.001, seconds2);
   EXPECT_GT(0.1, seconds2);
 }
+
+TEST(TimerTest, CategoryTimesStats) {
+  Timer::ResetCategoryTimes();
+  {
+static Timer::Category tcat1("CAT1");
+Timer t1(tcat1, ".");
+std::this_thread::sleep_for(std::chrono::milliseconds(100));
+static Timer::Category tcat2("CAT2");
+Timer t2(tcat2, ".");
+std::this_thread::sleep_for(std::chrono::milliseconds(10));
+Timer t3(tcat2, ".");
+std::this_thread::sleep_for(std::chrono::milliseconds(10));
+  }
+  // Example output:
+  // 0.102982273 sec (total: 0.126s; child: 0.023s; count: 1) for CAT1
+  // 0.023058228 sec (total: 0.036s; child: 0.012s; count: 2) for CAT2
+  StreamString ss;
+  Timer::DumpCategoryTimes(&ss);
+  double seconds1, total1, child1, seconds2;
+  int count1, count2;
+  ASSERT_EQ(
+  6, sscanf(ss.GetData(),
+"%lf sec (total: %lfs; child: %lfs; count: %d) for CAT1%*[\n "
+"]%lf sec (total: %*lfs; child: %*lfs; count: %d) for CAT2",
+&seconds1, &total1, &child1, &count1, &seconds2, &count2))
+  << "String: " << ss.GetData();
+  EXPECT_GT(total1 - child1, seconds1 - 0.001);
+  EXPECT_LT(total1 - child1, seconds1 + 0.001);
+  EXPECT_EQ(1, count1);
+  EXPECT_GT(child1, seconds2 - 0.001);
+  EXPECT_LT(child1, seconds2 + 0.001);
+  EXPECT_EQ(2, count2);
+}
Index: lldb/source/Utility/Timer.cpp
===
--- lldb/source/Utility/Timer.cpp
+++ lldb/source/Utility/Timer.cpp
@@ -41,6 +41,9 @@
 
 Timer::Category::Category(const char *cat) : m_name(cat) {
   m_nanos.store(0, std::memory_order_release);
+  m_nanos_total.store(0, std::memory_order_release);
+  m_nanos_child.store(0, std::memory_order_release);
+  m_count.store(0, std::memory_order_release);
   Category *expected = g_categories;
   do {
 m_next = expected;
@@ -93,6 +96,10 @@
 
   // Keep total results for each category so we can dump results.
   m_category.m_nanos += std::chrono::nanoseconds(timer_dur).count();
+  m_category.m_nanos_total += std::chrono::nanoseconds(total_dur).count();
+  m_category.m_nanos_child +=
+  std::chrono::nanoseconds(m_child_duration).count();
+  m_category.m_count++;
 }
 
 void Timer::SetDisplayDepth(uint32_t depth) { g_display_depth = depth; }
@@ -101,24 +108,38 @@
  * - returns whether a person is less than another person
  */
 
-typedef std::pair TimerEntry;
+struct Stats {
+  uint64_t nanos;
+  uint64_t nanos_total;
+  uint64_t nanos_child;
+  uint64_t count;
+};
+typedef std::pair TimerEntry;
 
 static bool CategoryMapIteratorSortCriterion(const TimerEntry &lhs,
  const TimerEntry &rhs) {
-  return lhs.second > rhs.second;
+  return lhs.second.nanos > rhs.second.nanos;
 }
 
 void Timer::ResetCategoryTimes() {
-  for (Category *i = g_categories; i; i = i->m_next)
+  for (Category *i = g_categories; i; i = i->m_next) {
 i->m_nanos.store(0, std::memory_order_release);
+i-

[Lldb-commits] [PATCH] D61235: Add more information to the log timer dump

2019-04-28 Thread António Afonso via Phabricator via lldb-commits
aadsm updated this revision to Diff 197048.
aadsm added a comment.

Fix and add unit test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61235

Files:
  lldb/include/lldb/Utility/Timer.h
  lldb/source/Utility/Timer.cpp
  lldb/unittests/Utility/TimerTest.cpp

Index: lldb/unittests/Utility/TimerTest.cpp
===
--- lldb/unittests/Utility/TimerTest.cpp
+++ lldb/unittests/Utility/TimerTest.cpp
@@ -61,7 +61,9 @@
   StreamString ss;
   Timer::DumpCategoryTimes(&ss);
   double seconds1, seconds2;
-  ASSERT_EQ(2, sscanf(ss.GetData(), "%lf sec for CAT1%*[\n ]%lf sec for CAT2",
+  ASSERT_EQ(2, sscanf(ss.GetData(),
+  "%lf sec (total: %*lfs; child: %*lfs; count: %*d) for "
+  "CAT1%*[\n ]%lf sec for CAT2",
   &seconds1, &seconds2))
   << "String: " << ss.GetData();
   EXPECT_LT(0.01, seconds1);
@@ -69,3 +71,36 @@
   EXPECT_LT(0.001, seconds2);
   EXPECT_GT(0.1, seconds2);
 }
+
+TEST(TimerTest, CategoryTimesStats) {
+  Timer::ResetCategoryTimes();
+  {
+static Timer::Category tcat1("CAT1");
+Timer t1(tcat1, ".");
+std::this_thread::sleep_for(std::chrono::milliseconds(100));
+static Timer::Category tcat2("CAT2");
+Timer t2(tcat2, ".");
+std::this_thread::sleep_for(std::chrono::milliseconds(10));
+Timer t3(tcat2, ".");
+std::this_thread::sleep_for(std::chrono::milliseconds(10));
+  }
+  // Example output:
+  // 0.102982273 sec (total: 0.126s; child: 0.023s; count: 1) for CAT1
+  // 0.023058228 sec (total: 0.036s; child: 0.012s; count: 2) for CAT2
+  StreamString ss;
+  Timer::DumpCategoryTimes(&ss);
+  double seconds1, total1, child1, seconds2;
+  int count1, count2;
+  ASSERT_EQ(
+  6, sscanf(ss.GetData(),
+"%lf sec (total: %lfs; child: %lfs; count: %d) for CAT1%*[\n "
+"]%lf sec (total: %*lfs; child: %*lfs; count: %d) for CAT2",
+&seconds1, &total1, &child1, &count1, &seconds2, &count2))
+  << "String: " << ss.GetData();
+  EXPECT_GT(total1 - child1, seconds1 - 0.001);
+  EXPECT_LT(total1 - child1, seconds1 + 0.001);
+  EXPECT_EQ(1, count1);
+  EXPECT_GT(child1, seconds2 - 0.001);
+  EXPECT_LT(child1, seconds2 + 0.001);
+  EXPECT_EQ(2, count2);
+}
Index: lldb/source/Utility/Timer.cpp
===
--- lldb/source/Utility/Timer.cpp
+++ lldb/source/Utility/Timer.cpp
@@ -41,6 +41,9 @@
 
 Timer::Category::Category(const char *cat) : m_name(cat) {
   m_nanos.store(0, std::memory_order_release);
+  m_nanos_total.store(0, std::memory_order_release);
+  m_nanos_child.store(0, std::memory_order_release);
+  m_count.store(0, std::memory_order_release);
   Category *expected = g_categories;
   do {
 m_next = expected;
@@ -93,6 +96,10 @@
 
   // Keep total results for each category so we can dump results.
   m_category.m_nanos += std::chrono::nanoseconds(timer_dur).count();
+  m_category.m_nanos_total += std::chrono::nanoseconds(total_dur).count();
+  m_category.m_nanos_child +=
+  std::chrono::nanoseconds(m_child_duration).count();
+  m_category.m_count++;
 }
 
 void Timer::SetDisplayDepth(uint32_t depth) { g_display_depth = depth; }
@@ -101,24 +108,38 @@
  * - returns whether a person is less than another person
  */
 
-typedef std::pair TimerEntry;
+struct Stats {
+  uint64_t nanos;
+  uint64_t nanos_total;
+  uint64_t nanos_child;
+  uint64_t count;
+};
+typedef std::pair TimerEntry;
 
 static bool CategoryMapIteratorSortCriterion(const TimerEntry &lhs,
  const TimerEntry &rhs) {
-  return lhs.second > rhs.second;
+  return lhs.second.nanos > rhs.second.nanos;
 }
 
 void Timer::ResetCategoryTimes() {
-  for (Category *i = g_categories; i; i = i->m_next)
+  for (Category *i = g_categories; i; i = i->m_next) {
 i->m_nanos.store(0, std::memory_order_release);
+i->m_nanos_total.store(0, std::memory_order_release);
+i->m_nanos_child.store(0, std::memory_order_release);
+i->m_count.store(0, std::memory_order_release);
+  }
 }
 
 void Timer::DumpCategoryTimes(Stream *s) {
   std::vector sorted;
   for (Category *i = g_categories; i; i = i->m_next) {
 uint64_t nanos = i->m_nanos.load(std::memory_order_acquire);
+uint64_t nanos_total = i->m_nanos_total.load(std::memory_order_acquire);
+uint64_t nanos_child = i->m_nanos_child.load(std::memory_order_acquire);
+uint64_t count = i->m_count.load(std::memory_order_acquire);
+Stats stats{nanos, nanos_total, nanos_child, count};
 if (nanos)
-  sorted.push_back(std::make_pair(i->m_name, nanos));
+  sorted.push_back(std::make_pair(i->m_name, stats));
   }
   if (sorted.empty())
 return; // Later code will break without any elements.
@@ -127,5 +148,9 @@
   llvm::sort(sorted.begin(), sorted.end(), CategoryMapIteratorSortCriterion);
 
   for (const a

[Lldb-commits] [PATCH] D61235: Add more information to the log timer dump

2019-04-28 Thread António Afonso via Phabricator via lldb-commits
aadsm updated this revision to Diff 197049.
aadsm added a comment.

Move struct to anonymous namespace


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61235

Files:
  lldb/include/lldb/Utility/Timer.h
  lldb/source/Utility/Timer.cpp
  lldb/unittests/Utility/TimerTest.cpp

Index: lldb/unittests/Utility/TimerTest.cpp
===
--- lldb/unittests/Utility/TimerTest.cpp
+++ lldb/unittests/Utility/TimerTest.cpp
@@ -61,7 +61,9 @@
   StreamString ss;
   Timer::DumpCategoryTimes(&ss);
   double seconds1, seconds2;
-  ASSERT_EQ(2, sscanf(ss.GetData(), "%lf sec for CAT1%*[\n ]%lf sec for CAT2",
+  ASSERT_EQ(2, sscanf(ss.GetData(),
+  "%lf sec (total: %*lfs; child: %*lfs; count: %*d) for "
+  "CAT1%*[\n ]%lf sec for CAT2",
   &seconds1, &seconds2))
   << "String: " << ss.GetData();
   EXPECT_LT(0.01, seconds1);
@@ -69,3 +71,36 @@
   EXPECT_LT(0.001, seconds2);
   EXPECT_GT(0.1, seconds2);
 }
+
+TEST(TimerTest, CategoryTimesStats) {
+  Timer::ResetCategoryTimes();
+  {
+static Timer::Category tcat1("CAT1");
+Timer t1(tcat1, ".");
+std::this_thread::sleep_for(std::chrono::milliseconds(100));
+static Timer::Category tcat2("CAT2");
+Timer t2(tcat2, ".");
+std::this_thread::sleep_for(std::chrono::milliseconds(10));
+Timer t3(tcat2, ".");
+std::this_thread::sleep_for(std::chrono::milliseconds(10));
+  }
+  // Example output:
+  // 0.102982273 sec (total: 0.126s; child: 0.023s; count: 1) for CAT1
+  // 0.023058228 sec (total: 0.036s; child: 0.012s; count: 2) for CAT2
+  StreamString ss;
+  Timer::DumpCategoryTimes(&ss);
+  double seconds1, total1, child1, seconds2;
+  int count1, count2;
+  ASSERT_EQ(
+  6, sscanf(ss.GetData(),
+"%lf sec (total: %lfs; child: %lfs; count: %d) for CAT1%*[\n "
+"]%lf sec (total: %*lfs; child: %*lfs; count: %d) for CAT2",
+&seconds1, &total1, &child1, &count1, &seconds2, &count2))
+  << "String: " << ss.GetData();
+  EXPECT_GT(total1 - child1, seconds1 - 0.001);
+  EXPECT_LT(total1 - child1, seconds1 + 0.001);
+  EXPECT_EQ(1, count1);
+  EXPECT_GT(child1, seconds2 - 0.001);
+  EXPECT_LT(child1, seconds2 + 0.001);
+  EXPECT_EQ(2, count2);
+}
Index: lldb/source/Utility/Timer.cpp
===
--- lldb/source/Utility/Timer.cpp
+++ lldb/source/Utility/Timer.cpp
@@ -41,6 +41,9 @@
 
 Timer::Category::Category(const char *cat) : m_name(cat) {
   m_nanos.store(0, std::memory_order_release);
+  m_nanos_total.store(0, std::memory_order_release);
+  m_nanos_child.store(0, std::memory_order_release);
+  m_count.store(0, std::memory_order_release);
   Category *expected = g_categories;
   do {
 m_next = expected;
@@ -93,6 +96,10 @@
 
   // Keep total results for each category so we can dump results.
   m_category.m_nanos += std::chrono::nanoseconds(timer_dur).count();
+  m_category.m_nanos_total += std::chrono::nanoseconds(total_dur).count();
+  m_category.m_nanos_child +=
+  std::chrono::nanoseconds(m_child_duration).count();
+  m_category.m_count++;
 }
 
 void Timer::SetDisplayDepth(uint32_t depth) { g_display_depth = depth; }
@@ -100,25 +107,40 @@
 /* binary function predicate:
  * - returns whether a person is less than another person
  */
-
-typedef std::pair TimerEntry;
+namespace {
+struct Stats {
+  uint64_t nanos;
+  uint64_t nanos_total;
+  uint64_t nanos_child;
+  uint64_t count;
+};
+} // namespace
+typedef std::pair TimerEntry;
 
 static bool CategoryMapIteratorSortCriterion(const TimerEntry &lhs,
  const TimerEntry &rhs) {
-  return lhs.second > rhs.second;
+  return lhs.second.nanos > rhs.second.nanos;
 }
 
 void Timer::ResetCategoryTimes() {
-  for (Category *i = g_categories; i; i = i->m_next)
+  for (Category *i = g_categories; i; i = i->m_next) {
 i->m_nanos.store(0, std::memory_order_release);
+i->m_nanos_total.store(0, std::memory_order_release);
+i->m_nanos_child.store(0, std::memory_order_release);
+i->m_count.store(0, std::memory_order_release);
+  }
 }
 
 void Timer::DumpCategoryTimes(Stream *s) {
   std::vector sorted;
   for (Category *i = g_categories; i; i = i->m_next) {
 uint64_t nanos = i->m_nanos.load(std::memory_order_acquire);
+uint64_t nanos_total = i->m_nanos_total.load(std::memory_order_acquire);
+uint64_t nanos_child = i->m_nanos_child.load(std::memory_order_acquire);
+uint64_t count = i->m_count.load(std::memory_order_acquire);
+Stats stats{nanos, nanos_total, nanos_child, count};
 if (nanos)
-  sorted.push_back(std::make_pair(i->m_name, nanos));
+  sorted.push_back(std::make_pair(i->m_name, stats));
   }
   if (sorted.empty())
 return; // Later code will break without any elements.
@@ -127,5 +149,9 @@
   llvm::sort(sorted.be

[Lldb-commits] [PATCH] D61235: Add more information to the log timer dump

2019-04-28 Thread António Afonso via Phabricator via lldb-commits
aadsm marked an inline comment as done.
aadsm added inline comments.



Comment at: lldb/unittests/Utility/TimerTest.cpp:100-101
+  << "String: " << ss.GetData();
+  EXPECT_GT(total1 - child1, seconds1 - 0.001);
+  EXPECT_LT(total1 - child1, seconds1 + 0.001);
+  EXPECT_EQ(1, count1);

davide wrote:
> this seems ... very fragile.
that's a good point. I'm not that familiar with the ieee754 to know what's a 
safe interval here, do you know?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61235



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


[Lldb-commits] [PATCH] D61235: Add more information to the log timer dump

2019-04-29 Thread António Afonso via Phabricator via lldb-commits
aadsm planned changes to this revision.
aadsm marked 2 inline comments as done.
aadsm added inline comments.



Comment at: lldb/source/Utility/Timer.cpp:110-123
+namespace {
+struct Stats {
+  uint64_t nanos;
+  uint64_t nanos_total;
+  uint64_t nanos_child;
+  uint64_t count;
+};

labath wrote:
> You can just move the `const char *` into the `Stats` struct and get rid of 
> the std::pair. Then the `CategoryMapIteratorSortCriterion` thingy can also 
> become a regular operator<.
ah yeah, that will be much better.



Comment at: lldb/unittests/Utility/TimerTest.cpp:89
+  // 0.102982273 sec (total: 0.126s; child: 0.023s; count: 1) for CAT1
+  // 0.023058228 sec (total: 0.036s; child: 0.012s; count: 2) for CAT2
+  StreamString ss;

labath wrote:
> I'm not sure this second line is really helpful here. Looking at this output, 
> I would have never guessed that these numbers mean we were running two 
> recursive timers belonging to the same category, and the entire thing 
> finished in 20ms.
> 
> Maybe this isn't a real usage problem, as normally we don't have recursive 
> timers (I believe), but in that case, we probably shouldn't have them in this 
> test either (as right now it is the only documentation about how these times 
> are supposed to work). 
> 
> What's the reason for using recursive timers here? If you just wanted to 
> check that the invocation count is 2, then you can wrap the two timers in 
> `{}` blocks, so that they execute "sequentially" instead of recursively. 
> (Which I guess would match the typical scenario where a timer-enabled 
> function calls another timer-enabled function two times in a loop.)
you're totally right, I actually didn't think much about it when I wrote the 
test but this should definitely be sequential not recursive.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61235



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


[Lldb-commits] [PATCH] D61235: Add more information to the log timer dump

2019-04-29 Thread António Afonso via Phabricator via lldb-commits
aadsm marked an inline comment as done.
aadsm added inline comments.



Comment at: lldb/unittests/Utility/TimerTest.cpp:100-101
+  << "String: " << ss.GetData();
+  EXPECT_GT(total1 - child1, seconds1 - 0.001);
+  EXPECT_LT(total1 - child1, seconds1 + 0.001);
+  EXPECT_EQ(1, count1);

labath wrote:
> aadsm wrote:
> > davide wrote:
> > > this seems ... very fragile.
> > that's a good point. I'm not that familiar with the ieee754 to know what's 
> > a safe interval here, do you know?
> I think you want to use `EXPECT_DOUBLE_EQ` here.
It still doesn't help me :(

```
Expected: total1 - child1
  Which is: 0.02
To be equal to: seconds1
  Which is: 0.10054
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61235



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


  1   2   3   >