[Lldb-commits] [PATCH] D67583: Fix swig python package path

2019-09-19 Thread Hal Gentz via Phabricator via lldb-commits
ZeGentzy added a comment.

In D67583#1674912 , @hhb wrote:

> I don't have the right environment to try your command. But I didn't see 
> anything obviously problematic.
>
> Can you try the following:
>
>   cd /src/llvm-project/lldb/scripts/Python
>
>
> Then run the following python program:
>
>   import sys
>   sys.path.append('/src/llvm-project/lldb/scripts/Python')
>   import finishSwigPythonLLDB
>   vDictArgs = {"--srcRoot": "/src/llvm-project/lldb",
>"--targetDir": "/src/out/./lib32",
>"--cfgBldDir": "/src/out/tools/lldb/scripts",
>"--prefix": "/src/out",
>"--cmakeBuildConfiguration": ".",
>"--lldbLibDir": "lib32",
>"-m": None,
>   }
>   finishSwigPythonLLDB.get_framework_python_dir(vDictArgs)
>
>
> For me the output is:
>
>   (True, '/src/out/./lib/python2.7/site-packages/lldb', '')
>
>
> Notice that the lib part don't have 32 suffix, even we specified that in 
> parameters.
>
> I kind of feeling that we should change this script to simply return 
> targetDir. There's no good reason to use get_python_lib() and depend on 
> python's implementation. But I don't know enough to make this decision...


Unfortunately, the script does not seam to be functional:

  $ python a.py 
  Traceback (most recent call last):
File "a.py", line 3, in 
  import finishSwigPythonLLDB
File 
"/home/gentz/Documents/aur/gfx/backups/second/llvm-git-gentz/llvm-git-gentz/src/llvm-project32/lldb/scripts/Python/finishSwigPythonLLDB.py",
 line 47, in 
  import utilsOsType  # Determine the OS type this script is running on
  ModuleNotFoundError: No module named 'utilsOsType'
  
  $ python2 a.py  
  Traceback (most recent call last):
File "a.py", line 3, in 
  import finishSwigPythonLLDB
File 
"/home/gentz/Documents/aur/gfx/backups/second/llvm-git-gentz/llvm-git-gentz/src/llvm-project32/lldb/scripts/Python/finishSwigPythonLLDB.py",
 line 47, in 
  import utilsOsType  # Determine the OS type this script is running on
  ImportError: No module named utilsOsType
  
  $ pwd 
  
/home/gentz/Documents/aur/gfx/backups/second/llvm-git-gentz/llvm-git-gentz/src/llvm-project32/lldb/scripts/Python


Repository:
  rL LLVM

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

https://reviews.llvm.org/D67583



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


[Lldb-commits] [PATCH] D67760: [lldb] Decouple importing the std C++ module from the way the program is compiled

2019-09-19 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor created this revision.
teemperor added reviewers: aprantl, shafik.
teemperor added a project: C++ modules in LLDB.
Herald added subscribers: lldb-commits, JDevlieghere, abidh, mgorny.
Herald added a reviewer: jdoerfert.
Herald added a project: LLDB.

At the moment, when trying to import the `std` module in LLDB, we look at the 
imported modules used in the compiled program
and try to infer the Clang configuration we need from the DWARF module-import. 
That was the initial idea but turned out to
cause a few problems or inconveniences:

- It requires that users compile their programs with C++ modules. Given how 
experimental C++ modules are makes this feature inaccessible

for many users. Also it means that people can't just get the benefits of this 
feature for free when we activate it by default
(and we can't just close all the associated bug reports).

- Relying on DWARF's imported module tags (that are only emitted by default on 
macOS) means this can only be used when using DWARF (and with -glldb on Linux).
- We essentially hardcoded the C standard library paths on some platforms 
(Linux) or just couldn't support this feature on other platforms (macOS).

This patch drops the whole idea of looking at the imported module DWARF tags 
and instead just uses the support files of the compilation unit.
If we look at the support files and see file paths that indicate where the C 
standard library and libc++ are, we can just create the module
configuration this information. This fixes all the problems above which means 
we can enable all the tests now on Linux, macOS and with other debug information
than what we currently had. The only debug information specific code is now the 
iteration over external type module when -gmodules is used (as `std` and also 
the
`Darwin` module are their own external type module with their own files).

The meat of this patch is the CppModuleConfiguration which looks at the file 
paths from the compilation unit and then figures out the include paths
based on those paths. It's quite conservative in that it only enables modules 
if we find a single C library and single libc++ library. It's still missing some
test mode where we try to compile an expression before we actually activate the 
config for the user (which probably also needs some caching mechanism),
but for now it works and makes the feature usable.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D67760

Files:
  lldb/include/lldb/Symbol/CompileUnit.h
  lldb/include/lldb/Symbol/SymbolFile.h
  lldb/include/lldb/Target/Platform.h
  
lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/basic/Makefile
  
lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/basic/TestImportStdModule.py
  
lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/conflicts/Makefile
  
lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/conflicts/TestStdModuleWithConflicts.py
  
lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/deque-basic/Makefile
  
lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/deque-basic/TestBasicDeque.py
  
lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/deque-dbg-info-content/Makefile
  
lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/deque-dbg-info-content/TestDbgInfoContentDeque.py
  
lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/forward_list-basic/Makefile
  
lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/forward_list-basic/TestBasicForwardList.py
  
lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/forward_list-dbg-info-content/Makefile
  
lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/forward_list-dbg-info-content/TestDbgInfoContentForwardList.py
  
lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/list-basic/Makefile
  
lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/list-basic/TestBasicList.py
  
lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/list-dbg-info-content/Makefile
  
lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentList.py
  
lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/no-std-module/Makefile
  
lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/no-std-module/TestMissingStdModule.py
  
lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/queue/Makefile
  
lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/queue/TestQueue.py
  
lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/shared_ptr-dbg-info-content/Makefile
  
lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/shared_ptr-dbg-info-content/TestSharedPtrDbgInfoContent.py
  
lldb/p

[Lldb-commits] [PATCH] D67227: [lldb] Extend and document TestIRInterpreter.py

2019-09-19 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor added inline comments.



Comment at: 
lldb/packages/Python/lldbsuite/test/commands/expression/ir-interpreter/TestIRInterpreter.py:54
+# Shifting longer than size of a type also doesn't work.
+if rhs.value <= 0 or rhs.value >= 7:
+return False

shafik wrote:
> teemperor wrote:
> > shafik wrote:
> > > I may be missing something here but this looks like it should be `32` 
> > > instead of `7` or rather `sizeof(int)*8`
> > > 
> > > When we say doesn't work do we mean undefined behavior?
> > Good catch, originally that was supposed to be `> 7` so that we don't 
> > overflow any data type (assuming we ever extend the test to char). But I 
> > can change it to `>= 32` until we actually use any 8-bit type.
> > 
> > And 'doesn't work' means that it will literally cause the test to fail and 
> > this test stops working. The interpreter will do something else than the 
> > JIT in these cases which is a bug. We probably should detect UB when 
> > interpreting these expressions and throw an error, but that's a whole new 
> > story. This is more about adding testing to the existing code.
> if I am not missing anything here in C++ and C the operands of expressions 
> undergo the usual arithmetic conversions and for integral types they undergo 
> integer promotions. This means that the smallest type should be `int` or 
> `unsigned int`.
> 
> [More details](https://stackoverflow.com/a/24372323/1708801).
Done, thanks!



Comment at: 
lldb/packages/Python/lldbsuite/test/commands/expression/ir-interpreter/TestIRInterpreter.py:110
+variable_list.append(v)
+interp_result = self.frame().EvaluateExpression(
+v.decl_expr, nojit_options).GetValueAsUnsigned()

shafik wrote:
> You don't see to use `interp_result` here
Yeah, seems that declaring a $variable in LLDB just returns some nonsensical 
value and a meaningless error... We will know if we have an error later, but at 
the moment there doesn't seem to be any early error checking we can do here.


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

https://reviews.llvm.org/D67227



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


[Lldb-commits] [PATCH] D67227: [lldb] Extend and document TestIRInterpreter.py

2019-09-19 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor updated this revision to Diff 220857.
teemperor marked 7 inline comments as done.
teemperor added a comment.

- Addressed feedback.


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

https://reviews.llvm.org/D67227

Files:
  
lldb/packages/Python/lldbsuite/test/commands/expression/ir-interpreter/TestIRInterpreter.py

Index: lldb/packages/Python/lldbsuite/test/commands/expression/ir-interpreter/TestIRInterpreter.py
===
--- lldb/packages/Python/lldbsuite/test/commands/expression/ir-interpreter/TestIRInterpreter.py
+++ lldb/packages/Python/lldbsuite/test/commands/expression/ir-interpreter/TestIRInterpreter.py
@@ -5,6 +5,7 @@
 from __future__ import print_function
 
 import unittest2
+import ctypes
 
 import lldb
 from lldbsuite.test.decorators import *
@@ -40,6 +41,37 @@
 
 self.runCmd("run", RUN_SUCCEEDED)
 
+class Variable:
+def __init__(self, uid, type, value):
+self.name = "$i_" + str(uid) + "_" + type.replace(" ", "_")
+self.type = type
+self.value = value
+# The value may be different if it's negative and we have an
+# unsigned type. Let's ask Python for the actual converted value on
+# the current platform.
+if type == "unsigned int":
+self.value = ctypes.c_uint(self.value)
+elif "unsigned" in type:
+assert False, "Unsupported unsigned type: " + type
+self.decl_expr = type + " " + self.name + " = " + str(self.value)
+
+class Operator:
+def __init__(self, name):
+   self.name = name
+
+def can_handle_operands(self, lhs, rhs):
+"""True iff this operator can handle the variables as operands."""
+if self.name in ['<<', '>>']:
+# Shifting negative values, shifting by negative values and
+# shifting by too large values will make this test fail (as
+# the interpreter will evaluate this differently than the JIT).
+# FIXME: This is probably a bug in the IRInterpreter.
+if lhs.value <= 0:
+return False
+if rhs.value <= 0 or rhs.value >= 32:
+return False
+return True
+
 @add_test_categories(['pyapi'])
 # getpid() is POSIX, among other problems, see bug
 @expectedFailureAll(
@@ -50,35 +82,74 @@
 oslist=['linux'],
 archs=['arm'],
 bugnumber="llvm.org/pr27868")
-def test_ir_interpreter(self):
+def test_ir_interpreter_int_ops(self):
 self.build_and_run()
 
+# Normal expression options we use for JITed expressions.
 options = lldb.SBExpressionOptions()
 options.SetLanguage(lldb.eLanguageTypeC_plus_plus)
 
-set_up_expressions = ["int $i = 9", "int $j = 3", "int $k = 5"]
-
-expressions = ["$i + $j",
-   "$i - $j",
-   "$i * $j",
-   "$i / $j",
-   "$i % $k",
-   "$i << $j",
-   "$i & $j",
-   "$i | $j",
-   "$i ^ $j"]
-
-for expression in set_up_expressions:
-self.frame().EvaluateExpression(expression, options)
-
-for expression in expressions:
+# Expression options that prevent that we use the JIT.
+nojit_options = lldb.SBExpressionOptions()
+nojit_options.SetLanguage(lldb.eLanguageTypeC_plus_plus)
+nojit_options.SetAllowJIT(False)
+
+# List of operators the interpreter supports and we want to test.
+operators = ['+', '-', '*', '%', '/',
+ '<<', '>>', '&', '|', '^',
+ '>', '<', '>=', '<=', '!=', '==']
+operator_list = []
+for opname in operators:
+operator_list.append(self.Operator(opname))
+
+# Variable types that should be tested with the operators.
+types_to_test = ['int', 'unsigned int']
+
+# Values these variables can have.
+values_to_test = [255, 256, -1, 0, 1, 255, 256]
+
+# Id for every variable to give them unique names.
+uid = 0
+# Define a variable for every type and for every value in LLDB.
+variable_list = []
+for t in types_to_test:
+for value in values_to_test:
+v = self.Variable(uid, t, value)
+variable_list.append(v)
+# FIXME: We should check for errors here, but declaring
+# $variables just returns some empty error it seems...
+self.frame().EvaluateExpression(v.decl_expr, nojit_options)
+uid += 1
+
+# Create a list of expressions that use every operator.
+exprs_to_run = []
+for op in operator_list:
+# Try all combinations of variables with the operator.
+   

[Lldb-commits] [PATCH] D65555: [lldb] [Process/NetBSD] Enable reporting of new and exited threads [WIP]

2019-09-19 Thread Michał Górny via Phabricator via lldb-commits
mgorny abandoned this revision.
mgorny added a comment.

The problem is to complex too be implemented in smaller blocks. I'm going to 
close this in favor of a single unified patch in D64647 
.


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

https://reviews.llvm.org/D6



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


[Lldb-commits] [PATCH] D64647: [lldb] [Process/NetBSD] Multithread support

2019-09-19 Thread Michał Górny via Phabricator via lldb-commits
mgorny updated this revision to Diff 220871.
mgorny marked 5 inline comments as done.
mgorny retitled this revision from "[lldb] [Process/NetBSD] Implement 
per-thread execution control" to " [lldb] [Process/NetBSD] Multithread 
support".
mgorny edited the summary of this revision.
Herald added a reviewer: jfb.

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

https://reviews.llvm.org/D64647

Files:
  
lldb/packages/Python/lldbsuite/test/functionalities/thread/concurrent_events/TestConcurrentBreakpointOneDelayBreakpointThreads.py
  
lldb/packages/Python/lldbsuite/test/functionalities/thread/concurrent_events/TestConcurrentCrashWithBreak.py
  
lldb/packages/Python/lldbsuite/test/functionalities/thread/concurrent_events/TestConcurrentCrashWithSignal.py
  
lldb/packages/Python/lldbsuite/test/functionalities/thread/concurrent_events/TestConcurrentDelayedCrashWithBreakpointSignal.py
  
lldb/packages/Python/lldbsuite/test/functionalities/thread/concurrent_events/TestConcurrentTwoBreakpointThreads.py
  
lldb/packages/Python/lldbsuite/test/functionalities/thread/exit_during_step/TestExitDuringStep.py
  
lldb/packages/Python/lldbsuite/test/functionalities/thread/step_out/TestThreadStepOut.py
  lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
  lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
  lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp
  lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.h

Index: lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.h
===
--- lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.h
+++ lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.h
@@ -48,6 +48,10 @@
 private:
   // Interface for friend classes
 
+  Status Resume();
+  Status SingleStep();
+  Status Suspend();
+
   void SetStoppedBySignal(uint32_t signo, const siginfo_t *info = nullptr);
   void SetStoppedByBreakpoint();
   void SetStoppedByTrace();
Index: lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp
===
--- lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp
+++ lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp
@@ -17,6 +17,11 @@
 #include "lldb/Utility/RegisterValue.h"
 #include "lldb/Utility/State.h"
 
+// clang-format off
+#include 
+#include 
+// clang-format on
+
 #include 
 
 using namespace lldb;
@@ -30,6 +35,38 @@
 NativeRegisterContextNetBSD::CreateHostNativeRegisterContextNetBSD(process.GetArchitecture(), *this)
 ), m_stop_description() {}
 
+Status NativeThreadNetBSD::Resume() {
+  Status ret = NativeProcessNetBSD::PtraceWrapper(PT_RESUME, m_process.GetID(),
+  nullptr, GetID());
+  if (!ret.Success())
+return ret;
+  ret = NativeProcessNetBSD::PtraceWrapper(PT_CLEARSTEP, m_process.GetID(),
+   nullptr, GetID());
+  if (ret.Success())
+SetRunning();
+  return ret;
+}
+
+Status NativeThreadNetBSD::SingleStep() {
+  Status ret = NativeProcessNetBSD::PtraceWrapper(PT_RESUME, m_process.GetID(),
+  nullptr, GetID());
+  if (!ret.Success())
+return ret;
+  ret = NativeProcessNetBSD::PtraceWrapper(PT_SETSTEP, m_process.GetID(),
+   nullptr, GetID());
+  if (ret.Success())
+SetStepping();
+  return ret;
+}
+
+Status NativeThreadNetBSD::Suspend() {
+  Status ret = NativeProcessNetBSD::PtraceWrapper(PT_SUSPEND, m_process.GetID(),
+  nullptr, GetID());
+  if (ret.Success())
+SetStopped();
+  return ret;
+}
+
 void NativeThreadNetBSD::SetStoppedBySignal(uint32_t signo,
 const siginfo_t *info) {
   Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
Index: lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
===
--- lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
+++ lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
@@ -98,6 +98,7 @@
   bool HasThreadNoLock(lldb::tid_t thread_id);
 
   NativeThreadNetBSD &AddThread(lldb::tid_t thread_id);
+  void RemoveThread(lldb::tid_t thread_id);
 
   void MonitorCallback(lldb::pid_t pid, int signal);
   void MonitorExited(lldb::pid_t pid, WaitStatus status);
Index: lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
===
--- lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
+++ lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
@@ -9,7 +9,6 @@
 #include "NativeProcessNetBSD.h"
 
 
-
 #include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
 #include "lldb/Host/HostProcess.h"
 #include "lldb/Host/common/NativeRegisterContext.h"
@@ -99,6 +98,17 @@
   pid, launch_info.GetPTY().ReleaseMasterFileDescriptor(), native_dele

[Lldb-commits] [PATCH] D64647: [lldb] [Process/NetBSD] Multithread support

2019-09-19 Thread Michał Górny via Phabricator via lldb-commits
mgorny added a comment.
Herald added a subscriber: dexonsmith.

So I've made some progress on this. However, I'm stuck and I'd use some help 
going forward.

I've made a trivial two-threaded program:

  #include 
  #include 
  #include 
  #include 
  
  void* thread_func(void* x) {
printf("thread 1\n");
int i;
for (i = 0; i < 100; i++)
{
printf("t2 %d\n", i);
sleep(3);
}
return NULL;
  }
  
  int main() {
pthread_t t;
  
printf("step 1\n");
assert(!pthread_create(&t, NULL, thread_func, NULL));
printf("step 2\n");
int i;
for (i = 0; i < 100; i++)
{
printf("t1 %d\n", i);
sleep(3);
}
assert(!pthread_join(t, NULL));
printf("step 3\n");
  
return 0;
  }

Now, if I start it, then issue `process interrupt`, then `thread continue 1`, 
everything works as expected. However, if I interrupt it again and then `thread 
continue 2` (i.e. try to change the thread running), nothing happens.

According to the gdb-remote log, `vCont` is received but nothing is sent back 
(though normally stdout should happen). If I send any other command, 
lldb-server dies:

  1568906517.952658892 <  16> read packet: $vCont;c:0002#a4
  1568906874.978140354 <   1> read packet: 
  lldb-server exiting...

According to the posix log, Resume is working as expected.

  1568906976.934143305 NativeProcessNetBSD.cpp:Resume   
no action specified for pid 12124 tid 1
  1568906976.934377670 NativeProcessNetBSD.cpp:Resume   
processing resume action state suspended signal 2147483647 for pid 12124 
tid 1
  1568906976.934622765 NativeProcessNetBSD.cpp:Resume   
processing resume action state running signal 2147483647 for pid 12124 tid 2

I suspect I'm not setting some state correctly but I so far haven't managed to 
figure out which.


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

https://reviews.llvm.org/D64647



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


[Lldb-commits] [PATCH] D67583: Fix swig python package path

2019-09-19 Thread Haibo Huang via Phabricator via lldb-commits
hhb added a comment.

Oh sorry my mistake. The current directory should be llvm-project/lldb/scripts. 
I.e.

  cd /src/llvm-project/lldb/scripts


Repository:
  rL LLVM

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

https://reviews.llvm.org/D67583



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


[Lldb-commits] [PATCH] D67774: [Mangle] Check ExternalASTSource before adding prefix to asm label names

2019-09-19 Thread Vedant Kumar via Phabricator via lldb-commits
vsk created this revision.
vsk added reviewers: teemperor, jasonmolenda, rjmccall.

LLDB may synthesize decls using asm labels. These decls cannot have a
mangle different than the one specified in the label name. I.e., the
mangle-suppression prefix should not be added.

Fixes an expression evaluation failure in lldb's TestVirtual.py on iOS.

rdar://45827323


https://reviews.llvm.org/D67774

Files:
  clang/include/clang/AST/ExternalASTSource.h
  clang/lib/AST/Mangle.cpp
  clang/test/Import/asm-label-mangle/Inputs/asm-label.cpp
  clang/test/Import/asm-label-mangle/test.cpp
  clang/tools/clang-import-test/clang-import-test.cpp
  lldb/include/lldb/Symbol/ClangExternalASTSourceCommon.h

Index: lldb/include/lldb/Symbol/ClangExternalASTSourceCommon.h
===
--- lldb/include/lldb/Symbol/ClangExternalASTSourceCommon.h
+++ lldb/include/lldb/Symbol/ClangExternalASTSourceCommon.h
@@ -132,6 +132,11 @@
 
   static ClangExternalASTSourceCommon *Lookup(clang::ExternalASTSource *source);
 
+  // Request that no "hidden" prefix is added to the mangle for asm labels.
+  // LLDB synthesizes many decls as simple asm labels: these synthesized decls
+  // cannot have a mangle different than the one specified in the label name.
+  bool UseGlobalPrefixInAsmLabelMangle() override { return false; }
+
 private:
   typedef llvm::DenseMap MetadataMap;
 
Index: clang/tools/clang-import-test/clang-import-test.cpp
===
--- clang/tools/clang-import-test/clang-import-test.cpp
+++ clang/tools/clang-import-test/clang-import-test.cpp
@@ -231,6 +231,18 @@
 
 namespace {
 
+// A mock ExternalASTMerger, used for testing purposes.
+class MockExternalASTMerger : public clang::ExternalASTMerger {
+public:
+  MockExternalASTMerger(const ImporterTarget &Target,
+llvm::ArrayRef Sources)
+  : clang::ExternalASTMerger(Target, Sources) {}
+
+  // Disallow use of a global prefix in the mangle for asm labels. This is
+  // required by lldb.
+  bool UseGlobalPrefixInAsmLabelMangle() override { return false; }
+};
+
 /// A container for a CompilerInstance (possibly with an ExternalASTMerger
 /// attached to its ASTContext).
 ///
@@ -265,7 +277,7 @@
   for (CIAndOrigins &Import : Imports)
 Sources.push_back({Import.getASTContext(), Import.getFileManager(),
Import.getOriginMap()});
-  auto ES = std::make_unique(Target, Sources);
+  auto ES = std::make_unique(Target, Sources);
   CI.getASTContext().setExternalSource(ES.release());
   CI.getASTContext().getTranslationUnitDecl()->setHasExternalVisibleStorage();
 }
Index: clang/test/Import/asm-label-mangle/test.cpp
===
--- /dev/null
+++ clang/test/Import/asm-label-mangle/test.cpp
@@ -0,0 +1,9 @@
+// RUN: clang-import-test -dump-ir -import %S/Inputs/asm-label.cpp -expression %s | FileCheck %s
+
+// The asm label mangle should not include a mangle-suppression prefix.
+
+// CHECK: define void @someotherfunc
+
+void expr() {
+  S1().func1();
+}
Index: clang/test/Import/asm-label-mangle/Inputs/asm-label.cpp
===
--- /dev/null
+++ clang/test/Import/asm-label-mangle/Inputs/asm-label.cpp
@@ -0,0 +1,4 @@
+struct S1 {
+  void func1() __asm("someotherfunc") {
+  }
+};
Index: clang/lib/AST/Mangle.cpp
===
--- clang/lib/AST/Mangle.cpp
+++ clang/lib/AST/Mangle.cpp
@@ -127,10 +127,13 @@
 // tricks normally used for producing aliases (PR9177). Fortunately the
 // llvm mangler on ELF is a nop, so we can just avoid adding the \01
 // marker.  We also avoid adding the marker if this is an alias for an
-// LLVM intrinsic.
+// LLVM intrinsic, or if the external AST source which provided the decl
+// opts out of this behavior.
 char GlobalPrefix =
 getASTContext().getTargetInfo().getDataLayout().getGlobalPrefix();
-if (GlobalPrefix && !ALA->getLabel().startswith("llvm."))
+ExternalASTSource *Source = getASTContext().getExternalSource();
+if (GlobalPrefix && !ALA->getLabel().startswith("llvm.") &&
+(!Source || Source->UseGlobalPrefixInAsmLabelMangle()))
   Out << '\01'; // LLVM IR Marker for __asm("foo")
 
 Out << ALA->getLabel();
Index: clang/include/clang/AST/ExternalASTSource.h
===
--- clang/include/clang/AST/ExternalASTSource.h
+++ clang/include/clang/AST/ExternalASTSource.h
@@ -104,6 +104,10 @@
   /// The default implementation of this method is a no-op.
   virtual Decl *GetExternalDecl(uint32_t ID);
 
+  /// Allow use of a global prefix (as defined in DataLayout) in the mangle
+  /// for asm labels. Defaults to true.
+  virtual bool UseGlobalPrefixInAsmLabelMangle() { return true; }
+
   /// Resolve a selector ID into a selector.
   ///
   //

[Lldb-commits] [PATCH] D67774: [Mangle] Check ExternalASTSource before adding prefix to asm label names

2019-09-19 Thread John McCall via Phabricator via lldb-commits
rjmccall added inline comments.



Comment at: clang/lib/AST/Mangle.cpp:137
+(!Source || Source->UseGlobalPrefixInAsmLabelMangle()))
   Out << '\01'; // LLVM IR Marker for __asm("foo")
 

This is one of those bugs where looking at the code really reveals a lot of 
problematic behavior.

`AsmLabelAttr` is generally assumed to carry a literal label, i.e. it should 
not have the global prefix added to it.  We should not be changing that 
assumption globally just based on whether an `ExternalASTSource` has been set 
up; that's going to break in any sort of non-uniform situation, e.g. if an LLDB 
user writes a declaration with an asm label, or if we import a Clang module 
where a declaration has an asm label.  Either `ExternalASTSource`s should be 
putting the real (prefixed) symbol name in the `AsmLabelAttr`, or they should 
be making `AsmLabelAttr`s that are different somehow, e.g. by giving 
`AsmLabelAttr` a flag (which doesn't need to be spellable in the source 
language) saying whether the label is literal or subject to global prefixing.

Separately, it seems to me that if the `AsmLabelAttr` is literal but the label 
happens to include the global prefix, we should strip the prefix from the label 
and not add a `\01` so that we get a consistent symbol name in LLVM.


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

https://reviews.llvm.org/D67774



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


[Lldb-commits] [PATCH] D67774: [Mangle] Check ExternalASTSource before adding prefix to asm label names

2019-09-19 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor requested changes to this revision.
teemperor added a comment.
This revision now requires changes to proceed.

I wonder what's the motivation for making this a setting in the 
ExternalASTSource? Opposed to e.g. storing a bit in AsmLabelAttr, which we 
could squeeze in by maybe stealing a bit from `labelLength`? Having this as a 
global setting in the ExternalASTSource seems like it could end up in a lot of 
confusion when we refactor our ExternalASTSources and this unexpectedly breaks. 
Especially since multiplexing ExternalASTSources is a thing people do 
(including LLDB itself), so if one source wants this feature on and the other 
doesn't, then we are in a dead end.

Also I wonder what happens with our real declarations we get from Clang modules 
(ObjC for now and C++ in the future). They now also share this setting even 
though they could use asm labels for legitimate reasons (even though I'm not 
sure I ever saw one being used in practice).

One minor bug I found: You need to turn this on in  `SemaSourceWithPriorities` 
and maybe also `ExternalASTSourceWrapper` (see ASTUtils.h) otherwise this seems 
to regress when using C++ modules and mangling stuff for an expression (I 
couldn't use `ClangExternalASTSourceCommon` there as we needed a 
clang::SemaSource).


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

https://reviews.llvm.org/D67774



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


[Lldb-commits] [PATCH] D67776: Use UnixSignals::ShouldSuppress to filter out signals a process expects

2019-09-19 Thread Tatyana Krasnukha via Phabricator via lldb-commits
tatyana-krasnukha created this revision.
tatyana-krasnukha added reviewers: JDevlieghere, jingham.
tatyana-krasnukha added a project: LLDB.
Herald added a subscriber: lldb-commits.

Usually, SIGTARP, SIGINT and SIGSTOP don't imply a crash. Rely on process 
signals' ShouldSuppress to filter such kind of signals out.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D67776

Files:
  include/lldb/Interpreter/CommandInterpreter.h
  include/lldb/Interpreter/CommandReturnObject.h
  source/Commands/CommandObjectProcess.cpp
  source/Interpreter/CommandInterpreter.cpp
  source/Interpreter/CommandReturnObject.cpp

Index: source/Interpreter/CommandReturnObject.cpp
===
--- source/Interpreter/CommandReturnObject.cpp
+++ source/Interpreter/CommandReturnObject.cpp
@@ -33,8 +33,7 @@
 
 CommandReturnObject::CommandReturnObject()
 : m_out_stream(), m_err_stream(), m_status(eReturnStatusStarted),
-  m_did_change_process_state(false), m_interactive(true),
-  m_abnormal_stop_was_expected(false) {}
+  m_did_change_process_state(false), m_interactive(true) {}
 
 CommandReturnObject::~CommandReturnObject() {}
 
Index: source/Interpreter/CommandInterpreter.cpp
===
--- source/Interpreter/CommandInterpreter.cpp
+++ source/Interpreter/CommandInterpreter.cpp
@@ -63,8 +63,10 @@
 #include "lldb/Utility/Args.h"
 
 #include "lldb/Target/Process.h"
+#include "lldb/Target/StopInfo.h"
 #include "lldb/Target/TargetList.h"
 #include "lldb/Target/Thread.h"
+#include "lldb/Target/UnixSignals.h"
 
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
@@ -2141,6 +2143,39 @@
   return platform_sp;
 }
 
+bool CommandInterpreter::DidProcessStopAbnormally() const {
+  TargetSP target_sp = m_debugger.GetTargetList().GetSelectedTarget();
+  if (!target_sp)
+return false;
+
+  ProcessSP process_sp(target_sp->GetProcessSP());
+  if (!process_sp)
+return false;
+
+  if (eStateStopped != process_sp->GetState())
+return false;
+
+  for (const auto &thread_sp : process_sp->GetThreadList().Threads()) {
+StopInfoSP stop_info = thread_sp->GetStopInfo();
+if (!stop_info)
+  return false;
+
+StopReason reason = stop_info->GetStopReason();
+if (eStopReasonException == reason || eStopReasonInstrumentation == reason)
+  return true;
+
+if (eStopReasonSignal == reason) {
+  const auto stop_signal = static_cast(stop_info->GetValue());
+  UnixSignalsSP signals = process_sp->GetUnixSignals();
+  if (!signals || !signals->GetShouldSuppress(stop_signal))
+// The signal is not of known suppressable signals, so it is abnormal.
+return true;
+}
+  }
+
+  return false;
+}
+
 void CommandInterpreter::HandleCommands(const StringList &commands,
 ExecutionContext *override_context,
 CommandInterpreterRunOptions &options,
@@ -2251,38 +2286,22 @@
 }
 
 // Also check for "stop on crash here:
-bool should_stop = false;
-if (tmp_result.GetDidChangeProcessState() && options.GetStopOnCrash()) {
-  TargetSP target_sp(m_debugger.GetTargetList().GetSelectedTarget());
-  if (target_sp) {
-ProcessSP process_sp(target_sp->GetProcessSP());
-if (process_sp) {
-  for (ThreadSP thread_sp : process_sp->GetThreadList().Threads()) {
-StopReason reason = thread_sp->GetStopReason();
-if (reason == eStopReasonSignal || reason == eStopReasonException ||
-reason == eStopReasonInstrumentation) {
-  should_stop = true;
-  break;
-}
-  }
-}
-  }
-  if (should_stop) {
-if (idx != num_lines - 1)
-  result.AppendErrorWithFormat(
-  "Aborting reading of commands after command #%" PRIu64
-  ": '%s' stopped with a signal or exception.\n",
-  (uint64_t)idx + 1, cmd);
-else
-  result.AppendMessageWithFormat(
-  "Command #%" PRIu64 " '%s' stopped with a signal or exception.\n",
-  (uint64_t)idx + 1, cmd);
+if (tmp_result.GetDidChangeProcessState() && options.GetStopOnCrash() &&
+DidProcessStopAbnormally()) {
+  if (idx != num_lines - 1)
+result.AppendErrorWithFormat(
+"Aborting reading of commands after command #%" PRIu64
+": '%s' stopped with a signal or exception.\n",
+(uint64_t)idx + 1, cmd);
+  else
+result.AppendMessageWithFormat(
+"Command #%" PRIu64 " '%s' stopped with a signal or exception.\n",
+(uint64_t)idx + 1, cmd);
 
-result.SetStatus(tmp_result.GetStatus());
-m_debugger.SetAsyncExecution(old_async_execution);
+  result.SetStatus(tmp_result.GetStatus());
+  m_debugger.SetAsyncExecution(old_async_execution);
 
-return;
-  }
+  re

[Lldb-commits] [PATCH] D67583: Fix swig python package path

2019-09-19 Thread Hal Gentz via Phabricator via lldb-commits
ZeGentzy added a comment.

In D67583#1675415 , @hhb wrote:

> Oh sorry my mistake. The current directory should be 
> llvm-project/lldb/scripts. I.e.
>
>   cd /src/llvm-project/lldb/scripts
>


Maybe I'm doing something wrong, but that does not work either.

  $ python a.py   
  Traceback (most recent call last):
File "a.py", line 3, in 
  import finishSwigPythonLLDB
  ModuleNotFoundError: No module named 'finishSwigPythonLLDB'
  
  $ python2 a.py
  Traceback (most recent call last):
File "a.py", line 3, in 
  import finishSwigPythonLLDB
  ImportError: No module named finishSwigPythonLLDB
  
  $ pwd 
  
/home/gentz/Documents/aur/gfx/backups/second/llvm-git-gentz/llvm-git-gentz/src/llvm-project32/lldb/scripts
  
  $ cat a.py
  import sys
  sys.path.append('/src/llvm-project/lldb/scripts/Python')
  import finishSwigPythonLLDB
  vDictArgs = {"--srcRoot": "/src/llvm-project/lldb",
   "--targetDir": "/src/out/./lib32",
   "--cfgBldDir": "/src/out/tools/lldb/scripts",
   "--prefix": "/src/out",
   "--cmakeBuildConfiguration": ".",
   "--lldbLibDir": "lib32",
   "-m": None,
  }
  finishSwigPythonLLDB.get_framework_python_dir(vDictArgs)




Repository:
  rL LLVM

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

https://reviews.llvm.org/D67583



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


[Lldb-commits] [PATCH] D67583: Fix swig python package path

2019-09-19 Thread Haibo Huang via Phabricator via lldb-commits
hhb added a comment.

I'm making a change in finishSwigPythonLLDB.py to write directly to targetDir. 
This way we don't have the problem to guess where the files are written.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D67583



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


[Lldb-commits] [PATCH] D67583: Fix swig python package path

2019-09-19 Thread Haibo Huang via Phabricator via lldb-commits
hhb added a comment.

In D67583#1675697 , @ZeGentzy wrote:

> In D67583#1675415 , @hhb wrote:
>
> > Oh sorry my mistake. The current directory should be 
> > llvm-project/lldb/scripts. I.e.
> >
> >   cd /src/llvm-project/lldb/scripts
> >
>
>
> Maybe I'm doing something wrong, but that does not work either.
>
>   $ python a.py   
>   Traceback (most recent call last):
> File "a.py", line 3, in 
>   import finishSwigPythonLLDB
>   ModuleNotFoundError: No module named 'finishSwigPythonLLDB'
>  
>   $ python2 a.py
>   Traceback (most recent call last):
> File "a.py", line 3, in 
>   import finishSwigPythonLLDB
>   ImportError: No module named finishSwigPythonLLDB
>  
>   $ pwd 
>   
> /home/gentz/Documents/aur/gfx/backups/second/llvm-git-gentz/llvm-git-gentz/src/llvm-project32/lldb/scripts
>  
>   $ cat a.py
>   import sys
>   sys.path.append('/src/llvm-project/lldb/scripts/Python')
>   import finishSwigPythonLLDB
>   vDictArgs = {"--srcRoot": "/src/llvm-project/lldb",
>"--targetDir": "/src/out/./lib32",
>"--cfgBldDir": "/src/out/tools/lldb/scripts",
>"--prefix": "/src/out",
>"--cmakeBuildConfiguration": ".",
>"--lldbLibDir": "lib32",
>"-m": None,
>   }
>   finishSwigPythonLLDB.get_framework_python_dir(vDictArgs)
>


My theory now is that your python has a different implementation of 
get_python_lib(). After all we should not guess what python would do. I'm 
making a change.
If you still interested in testing that, you can fix the path in a.py...


Repository:
  rL LLVM

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

https://reviews.llvm.org/D67583



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


[Lldb-commits] [PATCH] D67781: Revert "Fix swig python package path"

2019-09-19 Thread Haibo Huang via Phabricator via lldb-commits
hhb created this revision.
hhb added reviewers: JDevlieghere, ZeGentzy.
Herald added subscribers: lldb-commits, mgorny.
Herald added a project: LLDB.

This reverts commit 5a115e81cdd40c758b10c382aeffc0c8de6930e2 
.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67781

Files:
  lldb/scripts/CMakeLists.txt


Index: lldb/scripts/CMakeLists.txt
===
--- lldb/scripts/CMakeLists.txt
+++ lldb/scripts/CMakeLists.txt
@@ -42,15 +42,13 @@
 )
 
 if(NOT LLDB_BUILD_FRAMEWORK)
-  # The path here should match the result of python function
-  # distutils.sysconfig.get_python_lib().
-  if(CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
-set(swig_python_subdir Lib/site-packages)
+  if(CMAKE_SYSTEM_NAME MATCHES "Windows")
+set(swig_python_subdir site-packages)
   else()
-set(swig_python_subdir 
lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR})
+set(swig_python_subdir 
python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR})
   endif()
 
-  set(SWIG_PYTHON_DIR 
${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${swig_python_subdir})
+  set(SWIG_PYTHON_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${swig_python_subdir})
   set(SWIG_INSTALL_DIR lib${LLVM_LIBDIR_SUFFIX})
 
   # Install the LLDB python module


Index: lldb/scripts/CMakeLists.txt
===
--- lldb/scripts/CMakeLists.txt
+++ lldb/scripts/CMakeLists.txt
@@ -42,15 +42,13 @@
 )
 
 if(NOT LLDB_BUILD_FRAMEWORK)
-  # The path here should match the result of python function
-  # distutils.sysconfig.get_python_lib().
-  if(CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
-set(swig_python_subdir Lib/site-packages)
+  if(CMAKE_SYSTEM_NAME MATCHES "Windows")
+set(swig_python_subdir site-packages)
   else()
-set(swig_python_subdir lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR})
+set(swig_python_subdir python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR})
   endif()
 
-  set(SWIG_PYTHON_DIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${swig_python_subdir})
+  set(SWIG_PYTHON_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${swig_python_subdir})
   set(SWIG_INSTALL_DIR lib${LLVM_LIBDIR_SUFFIX})
 
   # Install the LLDB python module
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D67781: Revert "Fix swig python package path"

2019-09-19 Thread Haibo Huang via Phabricator via lldb-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL372364: Revert "Fix swig python package path" 
(authored by hhb, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D67781?vs=220927&id=220928#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D67781

Files:
  lldb/trunk/scripts/CMakeLists.txt


Index: lldb/trunk/scripts/CMakeLists.txt
===
--- lldb/trunk/scripts/CMakeLists.txt
+++ lldb/trunk/scripts/CMakeLists.txt
@@ -42,15 +42,13 @@
 )
 
 if(NOT LLDB_BUILD_FRAMEWORK)
-  # The path here should match the result of python function
-  # distutils.sysconfig.get_python_lib().
-  if(CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
-set(swig_python_subdir Lib/site-packages)
+  if(CMAKE_SYSTEM_NAME MATCHES "Windows")
+set(swig_python_subdir site-packages)
   else()
-set(swig_python_subdir 
lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR})
+set(swig_python_subdir 
python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR})
   endif()
 
-  set(SWIG_PYTHON_DIR 
${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${swig_python_subdir})
+  set(SWIG_PYTHON_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${swig_python_subdir})
   set(SWIG_INSTALL_DIR lib${LLVM_LIBDIR_SUFFIX})
 
   # Install the LLDB python module


Index: lldb/trunk/scripts/CMakeLists.txt
===
--- lldb/trunk/scripts/CMakeLists.txt
+++ lldb/trunk/scripts/CMakeLists.txt
@@ -42,15 +42,13 @@
 )
 
 if(NOT LLDB_BUILD_FRAMEWORK)
-  # The path here should match the result of python function
-  # distutils.sysconfig.get_python_lib().
-  if(CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
-set(swig_python_subdir Lib/site-packages)
+  if(CMAKE_SYSTEM_NAME MATCHES "Windows")
+set(swig_python_subdir site-packages)
   else()
-set(swig_python_subdir lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR})
+set(swig_python_subdir python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR})
   endif()
 
-  set(SWIG_PYTHON_DIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${swig_python_subdir})
+  set(SWIG_PYTHON_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${swig_python_subdir})
   set(SWIG_INSTALL_DIR lib${LLVM_LIBDIR_SUFFIX})
 
   # Install the LLDB python module
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D67583: Fix swig python package path

2019-09-19 Thread Hal Gentz via Phabricator via lldb-commits
ZeGentzy added a comment.

In D67583#1675714 , @hhb wrote:

> My theory now is that your python has a different implementation of 
> get_python_lib(). After all we should not guess what python would do. I'm 
> making a change.
>  If you still interested in testing that, you can fix the path in a.py...


Oh, derp, I completely missed that. I get `(True, 
'/src/out/./lib/python3.7/site-packages/lldb', '')` for python and `(True, 
'/src/out/./lib/python2.7/site-packages/lldb', '')` for python2.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D67583



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


[Lldb-commits] [PATCH] D67786: support for arbitrary python file objects

2019-09-19 Thread Lawrence D'Anna via Phabricator via lldb-commits
lawrence_danna abandoned this revision.
lawrence_danna added a comment.

will re-submit as individual patches.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67786



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


[Lldb-commits] [PATCH] D67789: bugfix: File::GetWaitableHandle() should call fileno()

2019-09-19 Thread Lawrence D'Anna via Phabricator via lldb-commits
lawrence_danna created this revision.
lawrence_danna added reviewers: JDevlieghere, jasonmolenda.
Herald added a project: LLDB.

If the file has m_stream, it may not have a m_descriptor.
GetWaitableHandle() should call GetDescriptor(), which will call
fileno(), so it will get waitable descriptor whenever one is available.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67789

Files:
  lldb/source/Host/common/File.cpp


Index: lldb/source/Host/common/File.cpp
===
--- lldb/source/Host/common/File.cpp
+++ lldb/source/Host/common/File.cpp
@@ -91,7 +91,7 @@
   return kInvalidDescriptor;
 }
 
-IOObject::WaitableHandle File::GetWaitableHandle() { return m_descriptor; }
+IOObject::WaitableHandle File::GetWaitableHandle() { return GetDescriptor(); }
 
 void File::SetDescriptor(int fd, bool transfer_ownership) {
   if (IsValid())


Index: lldb/source/Host/common/File.cpp
===
--- lldb/source/Host/common/File.cpp
+++ lldb/source/Host/common/File.cpp
@@ -91,7 +91,7 @@
   return kInvalidDescriptor;
 }
 
-IOObject::WaitableHandle File::GetWaitableHandle() { return m_descriptor; }
+IOObject::WaitableHandle File::GetWaitableHandle() { return GetDescriptor(); }
 
 void File::SetDescriptor(int fd, bool transfer_ownership) {
   if (IsValid())
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D67790: prepare_binding_Python: print readable errors if SWIG fails

2019-09-19 Thread Lawrence D'Anna via Phabricator via lldb-commits
lawrence_danna created this revision.
lawrence_danna added reviewers: JDevlieghere, jasonmolenda.
Herald added a project: LLDB.

When swig fails, all the errors are squished onto one line with `\n` quoting.
It's very hard to read.   This will print them out in a more reasonable format.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67790

Files:
  lldb/scripts/Python/prepare_binding_Python.py


Index: lldb/scripts/Python/prepare_binding_Python.py
===
--- lldb/scripts/Python/prepare_binding_Python.py
+++ lldb/scripts/Python/prepare_binding_Python.py
@@ -231,11 +231,13 @@
 swig_stdout, swig_stderr = process.communicate()
 return_code = process.returncode
 if return_code != 0:
+swig_stdout = swig_stdout.decode('utf8', errors='replace').rstrip()
+swig_stderr = swig_stderr.decode('utf8', errors='replace').rstrip()
+swig_stdout = re.sub(r'^(?=.)', 'stdout: ', swig_stdout, 
flags=re.MULTILINE)
+swig_stderr = re.sub(r'^(?=.)', 'stderr: ', swig_stderr, 
flags=re.MULTILINE)
 logging.error(
-"swig failed with error code %d: stdout=%s, stderr=%s",
-return_code,
-swig_stdout,
-swig_stderr)
+"swig failed with error code %d\n%s%s",
+return_code, swig_stdout, swig_stderr)
 logging.error(
 "command line:\n%s", ' '.join(command))
 sys.exit(return_code)


Index: lldb/scripts/Python/prepare_binding_Python.py
===
--- lldb/scripts/Python/prepare_binding_Python.py
+++ lldb/scripts/Python/prepare_binding_Python.py
@@ -231,11 +231,13 @@
 swig_stdout, swig_stderr = process.communicate()
 return_code = process.returncode
 if return_code != 0:
+swig_stdout = swig_stdout.decode('utf8', errors='replace').rstrip()
+swig_stderr = swig_stderr.decode('utf8', errors='replace').rstrip()
+swig_stdout = re.sub(r'^(?=.)', 'stdout: ', swig_stdout, flags=re.MULTILINE)
+swig_stderr = re.sub(r'^(?=.)', 'stderr: ', swig_stderr, flags=re.MULTILINE)
 logging.error(
-"swig failed with error code %d: stdout=%s, stderr=%s",
-return_code,
-swig_stdout,
-swig_stderr)
+"swig failed with error code %d\n%s%s",
+return_code, swig_stdout, swig_stderr)
 logging.error(
 "command line:\n%s", ' '.join(command))
 sys.exit(return_code)
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D38829: Python: SetOutputFileHandle doesn't work with IOBase

2019-09-19 Thread Lawrence D'Anna via Phabricator via lldb-commits
lawrence_danna abandoned this revision.
lawrence_danna added a comment.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

I've reworked this -- finally -- as zturner suggested.  I'll be posting it as a 
bunch of individual commits, so i'm abandoning this one.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D38829



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


[Lldb-commits] [PATCH] D67791: dotest.py: bugfix: test filters with -f do not work on Python3

2019-09-19 Thread Lawrence D'Anna via Phabricator via lldb-commits
lawrence_danna created this revision.
lawrence_danna added reviewers: JDevlieghere, jasonmolenda.
Herald added a project: LLDB.

`dotest -f` does not work on Python3.

The name types.UnboundMethodType was an alias for types.MethodType in
2.7, but it does not exist in python3.   MethodType works in both.

Also the actual type returned from SomeClass.some_method in python3
will be types.Function, not MethodType.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67791

Files:
  lldb/third_party/Python/module/unittest2/unittest2/loader.py


Index: lldb/third_party/Python/module/unittest2/unittest2/loader.py
===
--- lldb/third_party/Python/module/unittest2/unittest2/loader.py
+++ lldb/third_party/Python/module/unittest2/unittest2/loader.py
@@ -117,7 +117,7 @@
 return self.loadTestsFromModule(obj)
 elif isinstance(obj, type) and issubclass(obj, unittest.TestCase):
 return self.loadTestsFromTestCase(obj)
-elif (isinstance(obj, types.UnboundMethodType) and
+elif (isinstance(obj, (types.MethodType, types.FunctionType)) and
   isinstance(parent, type) and
   issubclass(parent, case.TestCase)):
 return self.suiteClass([parent(obj.__name__)])


Index: lldb/third_party/Python/module/unittest2/unittest2/loader.py
===
--- lldb/third_party/Python/module/unittest2/unittest2/loader.py
+++ lldb/third_party/Python/module/unittest2/unittest2/loader.py
@@ -117,7 +117,7 @@
 return self.loadTestsFromModule(obj)
 elif isinstance(obj, type) and issubclass(obj, unittest.TestCase):
 return self.loadTestsFromTestCase(obj)
-elif (isinstance(obj, types.UnboundMethodType) and
+elif (isinstance(obj, (types.MethodType, types.FunctionType)) and
   isinstance(parent, type) and
   issubclass(parent, case.TestCase)):
 return self.suiteClass([parent(obj.__name__)])
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D67792: bugfix: llvm_private::File::GetStream() can fail if m_options == 0

2019-09-19 Thread Lawrence D'Anna via Phabricator via lldb-commits
lawrence_danna created this revision.
lawrence_danna added reviewers: JDevlieghere, jasonmolenda.
Herald added a project: LLDB.

It's not clear from the header a File created with a descriptor will be
not be usable by LLDB unless SetOptions is also called, but it is.

This is because some parts of  LLDB relies on GetStream() to use the
file, and that in turn relies on calling fdopen on the descriptor.  When
calling fdopen, GetStream relies on m_options to determine the access
mode.   If m_options has never been set, GetStream() will fail.

Instead of giving up if m_options==0, GetStream() will now call fcntl to
get the access flags.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67792

Files:
  lldb/source/Host/common/File.cpp


Index: lldb/source/Host/common/File.cpp
===
--- lldb/source/Host/common/File.cpp
+++ lldb/source/Host/common/File.cpp
@@ -103,7 +103,22 @@
 FILE *File::GetStream() {
   if (!StreamIsValid()) {
 if (DescriptorIsValid()) {
-  const char *mode = GetStreamOpenModeFromOptions(m_options);
+  const char *mode = nullptr;
+  if (m_options) {
+mode = GetStreamOpenModeFromOptions(m_options);
+  } else {
+   int fdflags = ::fcntl(m_descriptor, F_GETFL);
+   if (fdflags >= 0) {
+  if (fdflags & O_RDWR) {
+mode = "r+";
+  } else if (fdflags & O_WRONLY) {
+mode = "w";
+  } else {
+mode = "r";
+  }
+}
+  }
+
   if (mode) {
 if (!m_should_close_fd) {
 // We must duplicate the file descriptor if we don't own it because when you


Index: lldb/source/Host/common/File.cpp
===
--- lldb/source/Host/common/File.cpp
+++ lldb/source/Host/common/File.cpp
@@ -103,7 +103,22 @@
 FILE *File::GetStream() {
   if (!StreamIsValid()) {
 if (DescriptorIsValid()) {
-  const char *mode = GetStreamOpenModeFromOptions(m_options);
+  const char *mode = nullptr;
+  if (m_options) {
+mode = GetStreamOpenModeFromOptions(m_options);
+  } else {
+   int fdflags = ::fcntl(m_descriptor, F_GETFL);
+   if (fdflags >= 0) {
+  if (fdflags & O_RDWR) {
+mode = "r+";
+  } else if (fdflags & O_WRONLY) {
+mode = "w";
+  } else {
+mode = "r";
+  }
+}
+  }
+
   if (mode) {
 if (!m_should_close_fd) {
 // We must duplicate the file descriptor if we don't own it because when you
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D67793: new api class: SBFile

2019-09-19 Thread Lawrence D'Anna via Phabricator via lldb-commits
lawrence_danna created this revision.
lawrence_danna added reviewers: JDevlieghere, jasonmolenda, zturner, jingham.
Herald added a subscriber: mgorny.
Herald added a project: LLDB.

SBFile is a scripting API wrapper for lldb_private::File

This is the first step in a rework of https://reviews.llvm.org/D38829

The ultimate goal is support for arbitrary python file objects for 
reading and writing, including objects which have no file descriptor 
and override the read() and write() functions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67793

Files:
  lldb/include/lldb/API/LLDB.h
  lldb/include/lldb/API/SBDefines.h
  lldb/include/lldb/API/SBError.h
  lldb/include/lldb/API/SBFile.h
  lldb/include/lldb/lldb-forward.h
  lldb/scripts/interface/SBFile.i
  lldb/scripts/lldb.swig
  lldb/source/API/CMakeLists.txt
  lldb/source/API/SBFile.cpp

Index: lldb/source/API/SBFile.cpp
===
--- /dev/null
+++ lldb/source/API/SBFile.cpp
@@ -0,0 +1,78 @@
+//===-- SBFile.cpp --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/API/SBFile.h"
+#include "lldb/API/SBError.h"
+#include "lldb/Host/File.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+SBFile::~SBFile() {}
+
+SBFile::SBFile () {}
+
+void SBFile::SetStream(FILE *file, bool transfer_ownership) {
+m_opaque_up = std::make_unique(file, transfer_ownership);
+}
+
+void SBFile::SetDescriptor(int fd, bool transfer_owndership) {
+m_opaque_up = std::make_unique(fd, transfer_owndership);
+}
+
+SBError SBFile::Read(uint8_t *buf, size_t num_bytes, size_t *bytes_read) {
+SBError error;
+if (!m_opaque_up) {
+error.SetErrorString("invalid SBFile");
+*bytes_read = 0;
+} else {
+Status status = m_opaque_up->Read(buf, num_bytes);
+error.SetError(status);
+*bytes_read = num_bytes;
+}
+return error;
+}
+
+SBError SBFile::Write(const uint8_t *buf, size_t num_bytes, size_t *bytes_written) {
+SBError error;
+if (!m_opaque_up) {
+error.SetErrorString("invalid SBFile");
+*bytes_written = 0;
+} else {
+Status status = m_opaque_up->Write(buf, num_bytes);
+error.SetError(status);
+*bytes_written = num_bytes;
+}
+return error;
+}
+
+SBError SBFile::Flush() {
+SBError error;
+if (!m_opaque_up) {
+error.SetErrorString("invalid SBFile");
+} else {
+Status status = m_opaque_up->Flush();
+error.SetError(status);
+}
+return error;
+}
+
+bool SBFile::IsValid() const {
+return m_opaque_up && m_opaque_up->IsValid();
+}
+
+SBError SBFile::Close() {
+SBError error;
+if (m_opaque_up) {
+Status status = m_opaque_up->Close();
+error.SetError(status);
+}
+return error;
+}
+
+
Index: lldb/source/API/CMakeLists.txt
===
--- lldb/source/API/CMakeLists.txt
+++ lldb/source/API/CMakeLists.txt
@@ -34,6 +34,7 @@
   SBExecutionContext.cpp
   SBExpressionOptions.cpp
   SBFileSpec.cpp
+  SBFile.cpp
   SBFileSpecList.cpp
   SBFrame.cpp
   SBFunction.cpp
Index: lldb/scripts/lldb.swig
===
--- lldb/scripts/lldb.swig
+++ lldb/scripts/lldb.swig
@@ -123,6 +123,7 @@
 #include "lldb/API/SBExecutionContext.h"
 #include "lldb/API/SBExpressionOptions.h"
 #include "lldb/API/SBFileSpec.h"
+#include "lldb/API/SBFile.h"
 #include "lldb/API/SBFileSpecList.h"
 #include "lldb/API/SBFrame.h"
 #include "lldb/API/SBFunction.h"
@@ -210,6 +211,7 @@
 %include "./interface/SBExecutionContext.i"
 %include "./interface/SBExpressionOptions.i"
 %include "./interface/SBFileSpec.i"
+%include "./interface/SBFile.i"
 %include "./interface/SBFileSpecList.i"
 %include "./interface/SBFrame.i"
 %include "./interface/SBFunction.i"
Index: lldb/scripts/interface/SBFile.i
===
--- /dev/null
+++ lldb/scripts/interface/SBFile.i
@@ -0,0 +1,43 @@
+//===-- SWIG Interface for SBFile -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+%include 
+
+%pybuffer_binary(const uint8_t *buf, size_t num_bytes);
+%pybuffer_mutable_binary(uint8_t *buf, size_t num_bytes);
+
+namespace lldb {
+
+%feature("docstring",
+"Represents a file."
+) SBFile;
+
+class SBFile
+{
+public:
+
+SBFile();
+~SBF