[Lldb-commits] [PATCH] D89283: [trace][intel-pt] Implement the basic decoding functionality

2020-10-14 Thread walter erquinigo via Phabricator via lldb-commits
wallace updated this revision to Diff 298052.
wallace marked 11 inline comments as done.
wallace added a comment.

Changes:

- Changed the callback signature of ForEachInstruction to receive an 
Expected
- Use Expected more ubiquitously in IntelPTDecoder
- Use MemoryBuffer to read the trace file
- Implemented ProcessTrace::DoReadMemory, which now is used by libipt instead 
of loading each object file inside libipt
- Made the decoding function a little bit more readable
- Small fixes here and there

Notes:

- I added a small test where a instruction can't be decoded due to missing 
memory mapping. I'll add later more robust tests.
- I'm also not fond of the ProcessTrace class being implemented in a plugin, 
however, it seems that all processes are implemented that way and the main 
method for creating processes Target::CreateProcess relies on plugins for 
creating the right instance. I could create an overload of that class that 
receives a callback that creates a specific process class, although it might 
create an way to unintendendly bypass the existing Target::CreateProcess. 
Another option is to move the class to lldb core and  register the plugin from 
there, even though it'd be the only class doing that in the codebase. What do 
you think?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89283

Files:
  lldb/include/lldb/Target/Trace.h
  lldb/include/lldb/Target/TraceSessionFileParser.h
  lldb/include/lldb/Target/TraceThread.h
  lldb/include/lldb/lldb-forward.h
  lldb/source/Plugins/Process/Trace/ProcessTrace.cpp
  lldb/source/Plugins/Process/Trace/ProcessTrace.h
  lldb/source/Plugins/Trace/intel-pt/CMakeLists.txt
  lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
  lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
  lldb/source/Plugins/Trace/intel-pt/IntelPTDecoder.cpp
  lldb/source/Plugins/Trace/intel-pt/IntelPTDecoder.h
  lldb/source/Plugins/Trace/intel-pt/ThreadIntelPT.cpp
  lldb/source/Plugins/Trace/intel-pt/ThreadIntelPT.h
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.h
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPTSessionFileParser.cpp
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPTSessionFileParser.h
  lldb/source/Target/CMakeLists.txt
  lldb/source/Target/Thread.cpp
  lldb/source/Target/Trace.cpp
  lldb/source/Target/TraceSessionFileParser.cpp
  lldb/source/Target/TraceThread.cpp
  lldb/test/API/commands/trace/TestTraceDumpInstructions.py
  lldb/test/API/commands/trace/intelpt-trace/trace_bad_image.json
  lldb/test/API/commands/trace/intelpt-trace/trace_wrong_cpu.json

Index: lldb/test/API/commands/trace/intelpt-trace/trace_wrong_cpu.json
===
--- /dev/null
+++ lldb/test/API/commands/trace/intelpt-trace/trace_wrong_cpu.json
@@ -0,0 +1,31 @@
+{
+  "trace": {
+"type": "intel-pt",
+"pt_cpu": {
+  "vendor": "intel",
+  "family": 2123123,
+  "model": 12123123,
+  "stepping": 1231231
+}
+  },
+  "processes": [
+{
+  "pid": 1234,
+  "triple": "x86_64-*-linux",
+  "threads": [
+{
+  "tid": 3842849,
+  "traceFile": "3842849.trace"
+}
+  ],
+  "modules": [
+{
+  "file": "a.out",
+  "systemPath": "a.out",
+  "loadAddress": "0x0040",
+  "uuid": "6AA9A4E2-6F28-2F33-377D-59FECE874C71-5B41261A"
+}
+  ]
+}
+  ]
+}
Index: lldb/test/API/commands/trace/intelpt-trace/trace_bad_image.json
===
--- /dev/null
+++ lldb/test/API/commands/trace/intelpt-trace/trace_bad_image.json
@@ -0,0 +1,31 @@
+{
+  "trace": {
+"type": "intel-pt",
+"pt_cpu": {
+  "vendor": "intel",
+  "family": 6,
+  "model": 79,
+  "stepping": 1
+}
+  },
+  "processes": [
+{
+  "pid": 1234,
+  "triple": "x86_64-*-linux",
+  "threads": [
+{
+  "tid": 3842849,
+  "traceFile": "3842849.trace"
+}
+  ],
+  "modules": [
+{
+  "file": "a.out",
+  "systemPath": "a.out",
+  "loadAddress": "0x00F0",
+  "uuid": "6AA9A4E2-6F28-2F33-377D-59FECE874C71-5B41261A"
+}
+  ]
+}
+  ]
+}
Index: lldb/test/API/commands/trace/TestTraceDumpInstructions.py
===
--- lldb/test/API/commands/trace/TestTraceDumpInstructions.py
+++ lldb/test/API/commands/trace/TestTraceDumpInstructions.py
@@ -39,18 +39,40 @@
 substrs=["intel-pt"])
 
 self.expect("thread trace dump instructions",
-substrs=['thread #1: tid = 3842849, total instructions = 1000',
- 'would print 20 instructions from position 0'])
+substrs=['''thread #1: tid = 3842849, total instructions = 21
+  [ 0] 0x40052d
+  [ 1] 0x4005

[Lldb-commits] [PATCH] D89310: [lldb] Reject redefinitions of persistent variables

2020-10-14 Thread Raphael Isemann via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcb81e662a589: [lldb] Reject redefinitions of persistent 
variables (authored by teemperor).
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89310

Files:
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
  
lldb/test/API/commands/expression/persistent_variables/TestPersistentVariables.py

Index: lldb/test/API/commands/expression/persistent_variables/TestPersistentVariables.py
===
--- lldb/test/API/commands/expression/persistent_variables/TestPersistentVariables.py
+++ lldb/test/API/commands/expression/persistent_variables/TestPersistentVariables.py
@@ -41,3 +41,19 @@
 # Test that $200 wasn't created by the previous expression.
 self.expect("expr $200", error=True,
 substrs=["use of undeclared identifier '$200'"])
+
+# Try redeclaring the persistent variable with the same type.
+# This should be rejected as we treat them as if they are globals.
+self.expect("expr int $i = 123", error=True,
+substrs=["error: redefinition of persistent variable '$i'"])
+self.expect_expr("$i", result_type="int", result_value="5")
+
+# Try redeclaring the persistent variable with another type. Should
+# also be rejected.
+self.expect("expr long $i = 123", error=True,
+substrs=["error: redefinition of persistent variable '$i'"])
+self.expect_expr("$i", result_type="int", result_value="5")
+
+# Try assigning the persistent variable a new value.
+self.expect("expr $i = 55")
+self.expect_expr("$i", result_type="int", result_value="55")
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -1078,6 +1078,7 @@
   ClangExpressionDeclMap *decl_map = type_system_helper->DeclMap();
   if (decl_map) {
 decl_map->InstallCodeGenerator(&m_compiler->getASTConsumer());
+decl_map->InstallDiagnosticManager(diagnostic_manager);
 
 clang::ExternalASTSource *ast_source = decl_map->CreateProxy();
 
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
@@ -102,6 +102,8 @@
 
   void InstallCodeGenerator(clang::ASTConsumer *code_gen);
 
+  void InstallDiagnosticManager(DiagnosticManager &diag_manager);
+
   /// Disable the state needed for parsing and IR transformation.
   void DidParse();
 
@@ -330,6 +332,8 @@
 clang::ASTConsumer *m_code_gen = nullptr; ///< If non-NULL, a code generator
   ///that receives new top-level
   ///functions.
+DiagnosticManager *m_diagnostics = nullptr;
+
   private:
 ParserVars(const ParserVars &) = delete;
 const ParserVars &operator=(const ParserVars &) = delete;
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -19,6 +19,7 @@
 #include "lldb/Core/ModuleSpec.h"
 #include "lldb/Core/ValueObjectConstResult.h"
 #include "lldb/Core/ValueObjectVariable.h"
+#include "lldb/Expression/DiagnosticManager.h"
 #include "lldb/Expression/Materializer.h"
 #include "lldb/Symbol/CompileUnit.h"
 #include "lldb/Symbol/CompilerDecl.h"
@@ -125,6 +126,12 @@
   m_parser_vars->m_code_gen = code_gen;
 }
 
+void ClangExpressionDeclMap::InstallDiagnosticManager(
+DiagnosticManager &diag_manager) {
+  assert(m_parser_vars);
+  m_parser_vars->m_diagnostics = &diag_manager;
+}
+
 void ClangExpressionDeclMap::DidParse() {
   if (m_parser_vars && m_parser_vars->m_persistent_vars) {
 for (size_t entity_index = 0, num_entities = m_found_entities.GetSize();
@@ -196,6 +203,17 @@
   if (ast == nullptr)
 return false;
 
+  // Check if we already declared a persistent variable with the same name.
+  if (lldb::ExpressionVariableSP conflicting_var =
+  m_parser_vars->m_persistent_vars->GetVariable(name)) {
+std::string msg = llvm::formatv("redefinition of persistent variable '{0}'",
+  

[Lldb-commits] [lldb] cb81e66 - [lldb] Reject redefinitions of persistent variables

2020-10-14 Thread Raphael Isemann via lldb-commits

Author: Raphael Isemann
Date: 2020-10-14T10:24:35+02:00
New Revision: cb81e662a58908913f342520e4c010564a68126a

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

LOG: [lldb] Reject redefinitions of persistent variables

Currently one can redefine a persistent variable and LLDB will just silently
ignore the second definition:

```
(lldb) expr int $i = 1
(lldb) expr int $i = 2
(lldb) expr $i
(int) $i = 1
```

This patch makes this an error and rejects the expression with the second
definition.

A nice follow up would be to refactor LLDB's persistent variables to not just be
a pair of type and name, but also contain some way to obtain the original
declaration and source code that declared the variable. That way we could
actually make a full diagnostic as we would get from redefining a variable twice
in the same expression.

Reviewed By: labath, shafik, JDevlieghere

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

Added: 


Modified: 
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp

lldb/test/API/commands/expression/persistent_variables/TestPersistentVariables.py

Removed: 




diff  --git 
a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
index 8c49898e1d6c..7d8cd85500ae 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -19,6 +19,7 @@
 #include "lldb/Core/ModuleSpec.h"
 #include "lldb/Core/ValueObjectConstResult.h"
 #include "lldb/Core/ValueObjectVariable.h"
+#include "lldb/Expression/DiagnosticManager.h"
 #include "lldb/Expression/Materializer.h"
 #include "lldb/Symbol/CompileUnit.h"
 #include "lldb/Symbol/CompilerDecl.h"
@@ -125,6 +126,12 @@ void ClangExpressionDeclMap::InstallCodeGenerator(
   m_parser_vars->m_code_gen = code_gen;
 }
 
+void ClangExpressionDeclMap::InstallDiagnosticManager(
+DiagnosticManager &diag_manager) {
+  assert(m_parser_vars);
+  m_parser_vars->m_diagnostics = &diag_manager;
+}
+
 void ClangExpressionDeclMap::DidParse() {
   if (m_parser_vars && m_parser_vars->m_persistent_vars) {
 for (size_t entity_index = 0, num_entities = m_found_entities.GetSize();
@@ -196,6 +203,17 @@ bool ClangExpressionDeclMap::AddPersistentVariable(const 
NamedDecl *decl,
   if (ast == nullptr)
 return false;
 
+  // Check if we already declared a persistent variable with the same name.
+  if (lldb::ExpressionVariableSP conflicting_var =
+  m_parser_vars->m_persistent_vars->GetVariable(name)) {
+std::string msg = llvm::formatv("redefinition of persistent variable 
'{0}'",
+name).str();
+m_parser_vars->m_diagnostics->AddDiagnostic(
+msg, DiagnosticSeverity::eDiagnosticSeverityError,
+DiagnosticOrigin::eDiagnosticOriginLLDB);
+return false;
+  }
+
   if (m_parser_vars->m_materializer && is_result) {
 Status err;
 

diff  --git 
a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
index 6974535a8993..0c81d46c6c52 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
@@ -102,6 +102,8 @@ class ClangExpressionDeclMap : public ClangASTSource {
 
   void InstallCodeGenerator(clang::ASTConsumer *code_gen);
 
+  void InstallDiagnosticManager(DiagnosticManager &diag_manager);
+
   /// Disable the state needed for parsing and IR transformation.
   void DidParse();
 
@@ -330,6 +332,8 @@ class ClangExpressionDeclMap : public ClangASTSource {
 clang::ASTConsumer *m_code_gen = nullptr; ///< If non-NULL, a code 
generator
   ///that receives new top-level
   ///functions.
+DiagnosticManager *m_diagnostics = nullptr;
+
   private:
 ParserVars(const ParserVars &) = delete;
 const ParserVars &operator=(const ParserVars &) = delete;

diff  --git 
a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 8ad39ecd2707..bd0d831f0ca7 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -1078,6 +1078,7 @@ ClangExpressionParser::ParseInternal(DiagnosticManager 
&diagnostic_manager,
   ClangExpressionDeclMap *decl_map = type_system_helper->DeclMap();
   if (de

[Lldb-commits] [PATCH] D89248: [lldb] [test/Register] Add read/write tests for multithreaded process

2020-10-14 Thread Pavel Labath via Phabricator via lldb-commits
labath accepted this revision.
labath added a comment.
This revision is now accepted and ready to land.

lg


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

https://reviews.llvm.org/D89248

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


[Lldb-commits] [PATCH] D89248: [lldb] [test/Register] Add read/write tests for multithreaded process

2020-10-14 Thread Michał Górny via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcaedbc317a5a: [lldb] [test/Register] Add read/write tests 
for multithreaded process (authored by mgorny).
Herald added a project: LLDB.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89248

Files:
  lldb/test/Shell/Register/Inputs/x86-multithread-read.cpp
  lldb/test/Shell/Register/Inputs/x86-multithread-write.cpp
  lldb/test/Shell/Register/x86-multithread-read.test
  lldb/test/Shell/Register/x86-multithread-write.test

Index: lldb/test/Shell/Register/x86-multithread-write.test
===
--- /dev/null
+++ lldb/test/Shell/Register/x86-multithread-write.test
@@ -0,0 +1,31 @@
+# XFAIL: system-windows
+# XFAIL: system-darwin
+# REQUIRES: native && (target-x86 || target-x86_64)
+# RUN: %clangxx_host %p/Inputs/x86-multithread-write.cpp -o %t -pthread
+# RUN: %lldb -b -s %s %t | FileCheck %s
+
+process launch
+# CHECK: Process {{[0-9]+}} stopped
+
+register write eax 0x05060708
+register write ebx 0x15161718
+# TODO: the need to call 'read' is probably a bug in the Linux plugin
+register read st0
+register write st0 "{0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x00 0x40}"
+
+process continue
+# CHECK-DAG: eax = 0x05060708
+# CHECK-DAG: ebx = 0x15161718
+# CHECK-DAG: st0 = { 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x00 0x40 }
+# CHECK: Process {{[0-9]+}} stopped
+
+register write eax 0x25262728
+register write ebx 0x35363738
+register read st0
+register write st0 "{0x11 0x21 0x31 0x41 0x51 0x61 0x71 0x81 0x00 0xc0}"
+
+process continue
+# CHECK-DAG: eax = 0x25262728
+# CHECK-DAG: ebx = 0x35363738
+# CHECK-DAG: st0 = { 0x11 0x21 0x31 0x41 0x51 0x61 0x71 0x81 0x00 0xc0 }
+# CHECK: Process {{[0-9]+}} exited with status = 0
Index: lldb/test/Shell/Register/x86-multithread-read.test
===
--- /dev/null
+++ lldb/test/Shell/Register/x86-multithread-read.test
@@ -0,0 +1,23 @@
+# XFAIL: system-windows
+# REQUIRES: native && (target-x86 || target-x86_64)
+# RUN: %clangxx_host %p/Inputs/x86-multithread-read.cpp -o %t -pthread
+# RUN: %lldb -b -s %s %t | FileCheck %s
+
+process launch
+# CHECK: Process {{[0-9]+}} stopped
+
+register read --all
+# CHECK-DAG: eax = 0x05060708
+# CHECK-DAG: ebx = 0x15161718
+# CHECK-DAG: st{{(mm)?}}0 = {0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x00 0x40}
+
+process continue
+# CHECK: Process {{[0-9]+}} stopped
+
+register read --all
+# CHECK-DAG: eax = 0x25262728
+# CHECK-DAG: ebx = 0x35363738
+# CHECK-DAG: st{{(mm)?}}0 = {0x11 0x21 0x31 0x41 0x51 0x61 0x71 0x81 0x00 0xc0}
+
+process continue
+# CHECK: Process {{[0-9]+}} exited with status = 0
Index: lldb/test/Shell/Register/Inputs/x86-multithread-write.cpp
===
--- /dev/null
+++ lldb/test/Shell/Register/Inputs/x86-multithread-write.cpp
@@ -0,0 +1,66 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+
+std::mutex t1_mutex, t2_mutex;
+
+struct test_data {
+  uint32_t eax;
+  uint32_t ebx;
+
+  struct alignas(16) {
+uint8_t data[10];
+  } st0;
+};
+
+constexpr test_data filler = {
+  .eax = 0x,
+  .ebx = 0x,
+  .st0 = {{0x1f, 0x2f, 0x3f, 0x4f, 0x5f, 0x6f, 0x7f, 0x8f, 0x80, 0x40}},
+};
+
+void t_func(std::mutex &t_mutex) {
+  std::lock_guard t_lock(t_mutex);
+  test_data out = filler;
+
+  asm volatile(
+"finit\t\n"
+"fldt %2\t\n"
+"int3\n\t"
+"fstpt %2\t\n"
+: "+a"(out.eax), "+b"(out.ebx)
+: "m"(out.st0)
+: "memory", "st"
+  );
+
+  printf("eax = 0x%08" PRIx32 "\n", out.eax);
+  printf("ebx = 0x%08" PRIx32 "\n", out.ebx);
+  printf("st0 = { ");
+  for (int i = 0; i < sizeof(out.st0.data); ++i)
+printf("0x%02" PRIx8 " ", out.st0.data[i]);
+  printf("}\n");
+}
+
+int main() {
+  // block both threads from proceeding
+  std::unique_lock m1_lock(t1_mutex);
+  std::unique_lock m2_lock(t2_mutex);
+
+  // start both threads
+  std::thread t1(t_func, std::ref(t1_mutex));
+  std::thread t2(t_func, std::ref(t2_mutex));
+
+  // release lock on thread 1 to make it interrupt the program
+  m1_lock.unlock();
+  // wait for thread 1 to finish
+  t1.join();
+
+  // release lock on thread 2
+  m2_lock.unlock();
+  // wait for thread 2 to finish
+  t2.join();
+
+  return 0;
+}
Index: lldb/test/Shell/Register/Inputs/x86-multithread-read.cpp
===
--- /dev/null
+++ lldb/test/Shell/Register/Inputs/x86-multithread-read.cpp
@@ -0,0 +1,61 @@
+#include 
+#include 
+#include 
+
+std::mutex t1_mutex, t2_mutex;
+
+struct test_data {
+  uint32_t eax;
+  uint32_t ebx;
+
+  struct alignas(16) {
+uint64_t mantissa;
+uint16_t sign_exp;
+  } st0;
+};
+
+void t_func(std::mutex &t_mutex, const test_data &t_data) {
+  std::lock_guard t_lock(t_mutex);
+
+  asm volatile(
+"finit\t\n"
+"fldt %2\t\n"
+

[Lldb-commits] [lldb] caedbc3 - [lldb] [test/Register] Add read/write tests for multithreaded process

2020-10-14 Thread Michał Górny via lldb-commits

Author: Michał Górny
Date: 2020-10-14T11:08:36+02:00
New Revision: caedbc317a5a4f046c345c136387e3ca199d8503

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

LOG: [lldb] [test/Register] Add read/write tests for multithreaded process

Add a test to verify that 'register read' and 'register write' commands
work correctly in a multithreaded program, in particular that they read
or write registers for the correct thread.  The tests use locking
to ensure that events are serialized and the test can execute reliably.

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

Added: 
lldb/test/Shell/Register/Inputs/x86-multithread-read.cpp
lldb/test/Shell/Register/Inputs/x86-multithread-write.cpp
lldb/test/Shell/Register/x86-multithread-read.test
lldb/test/Shell/Register/x86-multithread-write.test

Modified: 


Removed: 




diff  --git a/lldb/test/Shell/Register/Inputs/x86-multithread-read.cpp 
b/lldb/test/Shell/Register/Inputs/x86-multithread-read.cpp
new file mode 100644
index ..c5f571fc1d2c
--- /dev/null
+++ b/lldb/test/Shell/Register/Inputs/x86-multithread-read.cpp
@@ -0,0 +1,61 @@
+#include 
+#include 
+#include 
+
+std::mutex t1_mutex, t2_mutex;
+
+struct test_data {
+  uint32_t eax;
+  uint32_t ebx;
+
+  struct alignas(16) {
+uint64_t mantissa;
+uint16_t sign_exp;
+  } st0;
+};
+
+void t_func(std::mutex &t_mutex, const test_data &t_data) {
+  std::lock_guard t_lock(t_mutex);
+
+  asm volatile(
+"finit\t\n"
+"fldt %2\t\n"
+"int3\n\t"
+:
+: "a"(t_data.eax), "b"(t_data.ebx), "m"(t_data.st0)
+: "st"
+  );
+}
+
+int main() {
+  test_data t1_data = {
+.eax = 0x05060708,
+.ebx = 0x15161718,
+.st0 = {0x8070605040302010, 0x4000},
+  };
+  test_data t2_data = {
+.eax = 0x25262728,
+.ebx = 0x35363738,
+.st0 = {0x8171615141312111, 0xc000},
+  };
+
+  // block both threads from proceeding
+  std::unique_lock m1_lock(t1_mutex);
+  std::unique_lock m2_lock(t2_mutex);
+
+  // start both threads
+  std::thread t1(t_func, std::ref(t1_mutex), std::ref(t1_data));
+  std::thread t2(t_func, std::ref(t2_mutex), std::ref(t2_data));
+
+  // release lock on thread 1 to make it interrupt the program
+  m1_lock.unlock();
+  // wait for thread 1 to finish
+  t1.join();
+
+  // release lock on thread 2
+  m2_lock.unlock();
+  // wait for thread 2 to finish
+  t2.join();
+
+  return 0;
+}

diff  --git a/lldb/test/Shell/Register/Inputs/x86-multithread-write.cpp 
b/lldb/test/Shell/Register/Inputs/x86-multithread-write.cpp
new file mode 100644
index ..320f9e938e5b
--- /dev/null
+++ b/lldb/test/Shell/Register/Inputs/x86-multithread-write.cpp
@@ -0,0 +1,66 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+
+std::mutex t1_mutex, t2_mutex;
+
+struct test_data {
+  uint32_t eax;
+  uint32_t ebx;
+
+  struct alignas(16) {
+uint8_t data[10];
+  } st0;
+};
+
+constexpr test_data filler = {
+  .eax = 0x,
+  .ebx = 0x,
+  .st0 = {{0x1f, 0x2f, 0x3f, 0x4f, 0x5f, 0x6f, 0x7f, 0x8f, 0x80, 0x40}},
+};
+
+void t_func(std::mutex &t_mutex) {
+  std::lock_guard t_lock(t_mutex);
+  test_data out = filler;
+
+  asm volatile(
+"finit\t\n"
+"fldt %2\t\n"
+"int3\n\t"
+"fstpt %2\t\n"
+: "+a"(out.eax), "+b"(out.ebx)
+: "m"(out.st0)
+: "memory", "st"
+  );
+
+  printf("eax = 0x%08" PRIx32 "\n", out.eax);
+  printf("ebx = 0x%08" PRIx32 "\n", out.ebx);
+  printf("st0 = { ");
+  for (int i = 0; i < sizeof(out.st0.data); ++i)
+printf("0x%02" PRIx8 " ", out.st0.data[i]);
+  printf("}\n");
+}
+
+int main() {
+  // block both threads from proceeding
+  std::unique_lock m1_lock(t1_mutex);
+  std::unique_lock m2_lock(t2_mutex);
+
+  // start both threads
+  std::thread t1(t_func, std::ref(t1_mutex));
+  std::thread t2(t_func, std::ref(t2_mutex));
+
+  // release lock on thread 1 to make it interrupt the program
+  m1_lock.unlock();
+  // wait for thread 1 to finish
+  t1.join();
+
+  // release lock on thread 2
+  m2_lock.unlock();
+  // wait for thread 2 to finish
+  t2.join();
+
+  return 0;
+}

diff  --git a/lldb/test/Shell/Register/x86-multithread-read.test 
b/lldb/test/Shell/Register/x86-multithread-read.test
new file mode 100644
index ..6bff2b155758
--- /dev/null
+++ b/lldb/test/Shell/Register/x86-multithread-read.test
@@ -0,0 +1,23 @@
+# XFAIL: system-windows
+# REQUIRES: native && (target-x86 || target-x86_64)
+# RUN: %clangxx_host %p/Inputs/x86-multithread-read.cpp -o %t -pthread
+# RUN: %lldb -b -s %s %t | FileCheck %s
+
+process launch
+# CHECK: Process {{[0-9]+}} stopped
+
+register read --all
+# CHECK-DAG: eax = 0x05060708
+# CHECK-DAG: ebx = 0x15161718
+# CHECK-DAG: st{{(mm)?}}0 = {0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x00 0x40}
+
+process continue
+# CHECK: Process {{[0

[Lldb-commits] [PATCH] D89315: [debugserver] Add option to propagate SIGSEGV to target process

2020-10-14 Thread Alessandro Arzilli via Phabricator via lldb-commits
aarzilli updated this revision to Diff 298077.
aarzilli added a comment.

> I wonder if the implementation would be less intrusive (and keep some of 
> these functions from adding to their already too many arguments) if you added 
> this flag to the RNBContext that RNBRemote holds onto.

Done.

> You might even get away with treating this as a launch flavor (which it sort 
> of is), though to do that you'd have to make the launch flavor OR-able which 
> might be more work than its worth.

I'm not familiar enough with the codebase to do this.


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

https://reviews.llvm.org/D89315

Files:
  lldb/tools/debugserver/source/DNB.cpp
  lldb/tools/debugserver/source/DNB.h
  lldb/tools/debugserver/source/MacOSX/MachProcess.h
  lldb/tools/debugserver/source/MacOSX/MachProcess.mm
  lldb/tools/debugserver/source/MacOSX/MachTask.h
  lldb/tools/debugserver/source/MacOSX/MachTask.mm
  lldb/tools/debugserver/source/RNBContext.h
  lldb/tools/debugserver/source/RNBRemote.cpp
  lldb/tools/debugserver/source/debugserver.cpp

Index: lldb/tools/debugserver/source/debugserver.cpp
===
--- lldb/tools/debugserver/source/debugserver.cpp
+++ lldb/tools/debugserver/source/debugserver.cpp
@@ -247,7 +247,8 @@
   nub_process_t pid = DNBProcessLaunch(
   resolved_path, &inferior_argv[0], &inferior_envp[0], cwd, stdin_path,
   stdout_path, stderr_path, no_stdio, launch_flavor, g_disable_aslr,
-  process_event, launch_err_str, sizeof(launch_err_str));
+  process_event, ctx.GetUnmaskSignals(), launch_err_str,
+  sizeof(launch_err_str));
 
   g_pid = pid;
 
@@ -368,7 +369,8 @@
   DNBLogThreadedIf(LOG_RNB_MINIMAL, "%s Attaching to pid %i...", __FUNCTION__,
attach_pid);
   char err_str[1024];
-  pid = DNBProcessAttach(attach_pid, NULL, err_str, sizeof(err_str));
+  pid = DNBProcessAttach(attach_pid, NULL, ctx.GetUnmaskSignals(), err_str,
+ sizeof(err_str));
   g_pid = pid;
 
   if (pid == INVALID_NUB_PROCESS) {
@@ -889,6 +891,10 @@
  'F'}, // When debugserver launches the process, forward debugserver's
// current environment variables to the child process ("./debugserver
// -F localhost:1234 -- /bin/ls"
+{"unmask-signals", no_argument, NULL,
+ 'U'}, // debugserver will ignore EXC_MASK_BAD_ACCESS,
+   // EXC_MASK_BAD_INSTRUCTION and EXC_MASK_ARITHMETIC, which results in
+   // SIGSEGV, SIGILL and SIGFPE being propagated to the target process.
 {NULL, 0, NULL, 0}};
 
 int communication_fd = -1;
@@ -1260,6 +1266,10 @@
   forward_env = true;
   break;
 
+case 'U':
+  ctx.SetUnmaskSignals(true);
+  break;
+
 case '2':
   // File descriptor passed to this process during fork/exec and is already
   // open and ready for communication.
@@ -1515,7 +1525,8 @@
  waitfor_pid_name.c_str());
 nub_process_t pid = DNBProcessAttachWait(
 waitfor_pid_name.c_str(), launch_flavor, ignore_existing,
-timeout_ptr, waitfor_interval, err_str, sizeof(err_str));
+timeout_ptr, waitfor_interval, ctx.GetUnmaskSignals(), err_str,
+sizeof(err_str));
 g_pid = pid;
 
 if (pid == INVALID_NUB_PROCESS) {
@@ -1550,7 +1561,8 @@
 
 RNBLogSTDOUT("Attaching to process %s...\n", attach_pid_name.c_str());
 nub_process_t pid = DNBProcessAttachByName(
-attach_pid_name.c_str(), timeout_ptr, err_str, sizeof(err_str));
+attach_pid_name.c_str(), timeout_ptr, ctx.GetUnmaskSignals(),
+err_str, sizeof(err_str));
 g_pid = pid;
 if (pid == INVALID_NUB_PROCESS) {
   ctx.LaunchStatus().SetError(-1, DNBError::Generic);
Index: lldb/tools/debugserver/source/RNBRemote.cpp
===
--- lldb/tools/debugserver/source/RNBRemote.cpp
+++ lldb/tools/debugserver/source/RNBRemote.cpp
@@ -3928,7 +3928,8 @@
   const bool ignore_existing = true;
   attach_pid = DNBProcessAttachWait(
   attach_name.c_str(), m_ctx.LaunchFlavor(), ignore_existing, NULL,
-  1000, err_str, sizeof(err_str), RNBRemoteShouldCancelCallback);
+  1000, Context().GetUnmaskSignals(), err_str, sizeof(err_str),
+  RNBRemoteShouldCancelCallback);
 
 } else if (strstr(p, "vAttachOrWait;") == p) {
   p += strlen("vAttachOrWait;");
@@ -3940,7 +3941,8 @@
   const bool ignore_existing = false;
   attach_pid = DNBProcessAttachWait(
   attach_name.c_str(), m_ctx.LaunchFlavor(), ignore_existing, NULL,
-  1000, err_str, sizeof(err_str), RNBRemoteShouldCancelCallback);
+  1000, Context().GetUnmaskSignals(), err_str, sizeof(err_str),
+  RNBRemoteShouldCancelCallback);
 } else if (strstr(p, "vAttachName;") == p) {
   p += strlen("vAttachName;");
   if (!GetProcessName

[Lldb-commits] [PATCH] D89334: [lldb] Support Python imports relative the to the current file being sourced

2020-10-14 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

The main question on my mind is should we be adding the directory of the python 
file to the path (which is what I believe is happening now), or if we should 
add the directory of the command file that is being sourced (and adjust the way 
we import the file). The main impact of this is how will the imported module 
"see" itself (what will it's name be), and how it will be able to import other 
modules.

Imagine the user has the following (reasonable, I think) file structure.

  $ROOT/utils/consult_oracle.py
  $ROOT/automatic_bug_finder/main.py # uses consult_oracle.py
  $ROOT/awesome_backtrace_analyzer/main.py # uses consult_oracle.py
  $ROOT/install_super_scripts.lldbinit # calls command script import 
awesome_backtrace_analyzer/main.py

If "command script import awesome_backtrace_analyzer/main.py" ends up adding 
`$ROOT/awesome_backtrace_analyzer`  to the path, then this module will have a 
hard time importing the modules it depends on (it would either have to use 
weird relative imports, or mess with sys.path itself. If we add just `$ROOT` 
then it could simply `import utils.consult_oracle`.

I think setting the import path to $ROOT would actually make the sys.path 
manipulation serve some useful purpose (and also reduce the number of sys.path 
entries we add). If, on the other hand, we are not interested making 
cross-module imports work "out of the box" (like, we could say that it's the 
responsibility of individual modules to ensure that), we could also try to 
import the file without messing with sys.path at all 
(https://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path
 gives one way to do that).




Comment at: lldb/include/lldb/Interpreter/CommandInterpreter.h:554
 
+  FileSpec GetCurrentSourceDir();
+

A comment would be very useful here.


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

https://reviews.llvm.org/D89334

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


[Lldb-commits] [PATCH] D88483: Add possibility to get module from SBType

2020-10-14 Thread Ilya Bukonkin via Phabricator via lldb-commits
fallkrum added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88483

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


[Lldb-commits] [PATCH] D89227: [lldb] Note difference in vFile:pread/pwrite format for lldb

2020-10-14 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett added a comment.

> After some undefined transition period :) we change lldb to assume the 
> correct gdb-compatible behavior.
>
> The biggest hurdle for changing the default are iOS/watchOS devices out in 
> the field - we cannot update the old debugservers that run on them, so we 
> often need lldb to communicate with debugservers that are 4-5 years old (I 
> forget the exact OS matrix for what Xcode supports for debugging, but it goes 
> back a ways).

Ok then I agree the qSupported idea makes the most sense.

> Just to confirm one quick detail (I couldn't remember for sure and had to 
> check) - if we strtoul will stop parsing when it finds a character outside 
> the range of the specified base. e.g. calling strtoul("0x100", nullptr, 10) 
> will yield 0; strtoul("10f", nullptr, 10) will yield 10.

Yeah, what I wrote in the doc wasn't correct either. lldb-server ends up using 
a base of 0:

  size_t count = packet.GetU64(SIZE_MAX);
  uint64_t GetU64(uint64_t fail_value, int base = 0);
  uint64_t StringExtractor::GetU64(uint64_t fail_value, int base) {
  <...>
  uint64_t result = ::strtoull(cstr, &end, base);

So it'll accept decimal, hex *with* 0x or octal. (lucky I've never seen anyone 
0 pad the numbers)

> I think we should revert David's doc change to lldb-platform-packets.txt 
> which says that either base10 or base16 can be used. David, what do you think.

I will revert it. I could correct it but that's opening the door to more 
options and will just make the qSupported idea more complicated. (I'll update 
the bug I raised too)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89227

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


[Lldb-commits] [PATCH] D89383: [lldb] Correct vFile:pread/pwrite packet docs

2020-10-14 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett created this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.
DavidSpickett requested review of this revision.
Herald added a subscriber: JDevlieghere.

The statement that lldb-server can handle
decimal and hex numbers is misleading.
(it can only handle hex with 0x prefix)

Mentioning non decimal numbers at all
is just creating more confusion for anyone
who tries to use them with lldb-server.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89383

Files:
  lldb/docs/lldb-platform-packets.txt


Index: lldb/docs/lldb-platform-packets.txt
===
--- lldb/docs/lldb-platform-packets.txt
+++ lldb/docs/lldb-platform-packets.txt
@@ -416,7 +416,6 @@
 //The gdb-remote serial protocol documentation says that numbers
 //in "vFile:" packets should be hexidecimal. Instead lldb uses
 //decimal for the number of bytes and offset.
-//lldb-server can process either format.
 
 
 //--
@@ -440,7 +439,7 @@
 //  COMPATIBILITY
 //The gdb-remote serial protocol documentation says that numbers
 //in "vFile:" packets should be hexidecimal. Instead lldb uses
-//decimal for the offset. lldb-server can process either format.
+//decimal for the offset.
 
 
 


Index: lldb/docs/lldb-platform-packets.txt
===
--- lldb/docs/lldb-platform-packets.txt
+++ lldb/docs/lldb-platform-packets.txt
@@ -416,7 +416,6 @@
 //The gdb-remote serial protocol documentation says that numbers
 //in "vFile:" packets should be hexidecimal. Instead lldb uses
 //decimal for the number of bytes and offset.
-//lldb-server can process either format.
 
 
 //--
@@ -440,7 +439,7 @@
 //  COMPATIBILITY
 //The gdb-remote serial protocol documentation says that numbers
 //in "vFile:" packets should be hexidecimal. Instead lldb uses
-//decimal for the offset. lldb-server can process either format.
+//decimal for the offset.
 
 
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D89335: [lldb] Generic support for caching register set reads/writes [WIP]

2020-10-14 Thread Michał Górny via Phabricator via lldb-commits
mgorny planned changes to this revision.
mgorny added a comment.

Ok, this is going to have to wait. I've found some hard bug in NetBSD's xstate 
support and don't have time+resources to figure it out at the moment.


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

https://reviews.llvm.org/D89335

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


[Lldb-commits] [PATCH] D89335: [lldb] Generic support for caching register set reads/writes [WIP]

2020-10-14 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

I'm wondering if this could be implemented as some kind of a separate class 
which you "mix" into your register context when you want to do caching. 
Possibly something like this:

  class NRCLinux_MyArch: public NRCLinux, private RCCache::Backend {
RCCache m_cache;
  
NRCLinux_MyArch(...) : m_cache(this) {}
  
// NRC interface
ReadRegister(...) override { return m_cache.ReadRegister(...); }
...
  
// Backend interface
ReadReally(...) override { action happens here }
  };

That would enable individual register contexts to explicitly opt into caching, 
which might be cleaner in the long term, as I anticipate it will take a very 
long time to convert all registers contexts to the new way of doing things.




Comment at: 
lldb/source/Plugins/Process/Utility/NativeRegisterContextRegisterInfo.h:25
+
+#define LLDB_INVALID_REGSET UINT32_MAX
+

I think using `Optional` would be better. Although, I'm not sure what 
are the cases where a register does not belong to any register set.



Comment at: 
lldb/source/Plugins/Process/Utility/NativeRegisterContextRegisterInfo.h:64-83
+  virtual Status ReadRegisterSet(uint32_t set) {
+return Status("not implemented");
+  }
+
+  virtual Status WriteRegisterSet(uint32_t set) {
+return Status("not implemented");
+  }

I think new interfaces should use llvm::Error/Expected


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

https://reviews.llvm.org/D89335

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


[Lldb-commits] [PATCH] D89227: [lldb] Note difference in vFile:pread/pwrite format for lldb

2020-10-14 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

Yeah, using qSupport also works. It just seems like it would be possible to 
handle this particular issue without adding the generic framework, so  I was 
throwing that idea out too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89227

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


[Lldb-commits] [lldb] 6bb123b - [lldb] Modernize PseudoTerminal::OpenFirstAvailablePrimary

2020-10-14 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2020-10-14T14:55:03+02:00
New Revision: 6bb123b819c61c61197ec2ba54ceb6d16e9121cf

URL: 
https://github.com/llvm/llvm-project/commit/6bb123b819c61c61197ec2ba54ceb6d16e9121cf
DIFF: 
https://github.com/llvm/llvm-project/commit/6bb123b819c61c61197ec2ba54ceb6d16e9121cf.diff

LOG: [lldb] Modernize PseudoTerminal::OpenFirstAvailablePrimary

replace char*+length combo with llvm::Error

Added: 


Modified: 
lldb/include/lldb/Host/PseudoTerminal.h
lldb/source/Host/common/ProcessLaunchInfo.cpp
lldb/source/Host/common/PseudoTerminal.cpp
lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
lldb/unittests/Editline/CMakeLists.txt
lldb/unittests/Editline/EditlineTest.cpp
lldb/unittests/Host/MainLoopTest.cpp

Removed: 




diff  --git a/lldb/include/lldb/Host/PseudoTerminal.h 
b/lldb/include/lldb/Host/PseudoTerminal.h
index c2258f15e551..cf4f0c3769a5 100644
--- a/lldb/include/lldb/Host/PseudoTerminal.h
+++ b/lldb/include/lldb/Host/PseudoTerminal.h
@@ -9,11 +9,11 @@
 #ifndef LLDB_HOST_PSEUDOTERMINAL_H
 #define LLDB_HOST_PSEUDOTERMINAL_H
 
+#include "lldb/lldb-defines.h"
+#include "llvm/Support/Error.h"
 #include 
 #include 
 
-#include "lldb/lldb-defines.h"
-
 namespace lldb_private {
 
 /// \class PseudoTerminal PseudoTerminal.h "lldb/Host/PseudoTerminal.h"
@@ -128,18 +128,9 @@ class PseudoTerminal {
   /// Flags to use when calling \c posix_openpt(\a oflag).
   /// A value of "O_RDWR|O_NOCTTY" is suggested.
   ///
-  /// \param[out] error_str
-  /// An pointer to an error that can describe any errors that
-  /// occur. This can be NULL if no error status is desired.
-  ///
-  /// \return
-  /// \b true when the primary files descriptor is
-  /// successfully opened.
-  /// \b false if anything goes wrong.
-  ///
   /// \see PseudoTerminal::GetPrimaryFileDescriptor() @see
   /// PseudoTerminal::ReleasePrimaryFileDescriptor()
-  bool OpenFirstAvailablePrimary(int oflag, char *error_str, size_t error_len);
+  llvm::Error OpenFirstAvailablePrimary(int oflag);
 
   /// Open the secondary for the current primary pseudo terminal.
   ///

diff  --git a/lldb/source/Host/common/ProcessLaunchInfo.cpp 
b/lldb/source/Host/common/ProcessLaunchInfo.cpp
index a4729a28ce74..851069d0f20f 100644
--- a/lldb/source/Host/common/ProcessLaunchInfo.cpp
+++ b/lldb/source/Host/common/ProcessLaunchInfo.cpp
@@ -218,10 +218,9 @@ llvm::Error ProcessLaunchInfo::SetUpPtyRedirection() {
   // do for now.
   open_flags |= O_CLOEXEC;
 #endif
-  if (!m_pty->OpenFirstAvailablePrimary(open_flags, nullptr, 0)) {
-return llvm::createStringError(llvm::inconvertibleErrorCode(),
-   "PTY::OpenFirstAvailablePrimary failed");
-  }
+  if (llvm::Error Err = m_pty->OpenFirstAvailablePrimary(open_flags))
+return Err;
+
   const FileSpec secondary_file_spec(m_pty->GetSecondaryName());
 
   // Only use the secondary tty if we don't have anything specified for

diff  --git a/lldb/source/Host/common/PseudoTerminal.cpp 
b/lldb/source/Host/common/PseudoTerminal.cpp
index 4668b09f4fdb..8f0c3018363f 100644
--- a/lldb/source/Host/common/PseudoTerminal.cpp
+++ b/lldb/source/Host/common/PseudoTerminal.cpp
@@ -65,52 +65,32 @@ void PseudoTerminal::CloseSecondaryFileDescriptor() {
   }
 }
 
-// Open the first available pseudo terminal with OFLAG as the permissions. The
-// file descriptor is stored in this object and can be accessed with the
-// PrimaryFileDescriptor() accessor. The ownership of the primary file
-// descriptor can be released using the ReleasePrimaryFileDescriptor() 
accessor.
-// If this object has a valid primary files descriptor when its destructor is
-// called, it will close the primary file descriptor, therefore clients must
-// call ReleasePrimaryFileDescriptor() if they wish to use the primary file
-// descriptor after this object is out of scope or destroyed.
-//
-// RETURNS:
-//  True when successful, false indicating an error occurred.
-bool PseudoTerminal::OpenFirstAvailablePrimary(int oflag, char *error_str,
-   size_t error_len) {
-  if (error_str)
-error_str[0] = '\0';
-
+llvm::Error PseudoTerminal::OpenFirstAvailablePrimary(int oflag) {
 #if LLDB_ENABLE_POSIX
   // Open the primary side of a pseudo terminal
   m_primary_fd = ::posix_openpt(oflag);
   if (m_primary_fd < 0) {
-if (error_str)
-  ErrnoToStr(error_str, error_len);
-return false;
+return llvm::errorCodeToError(
+std::error_code(errno, std::generic_category()));
   }
 
   // Grant access to the secondary pseudo terminal
   if (::grantpt(m_primary_fd) < 0) {
-if (error_str)
-  ErrnoToStr(error_str, error_len);
+std::error_code EC(errno, std::generic_category());
 ClosePrimaryFileDescriptor();
-return false;
+return llvm::errorCodeToError(EC);
   }
 
   // Clear the lock flag on th

[Lldb-commits] [lldb] 2c4226f - [lldb-server][linux] Add ability to allocate memory

2020-10-14 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2020-10-14T15:02:09+02:00
New Revision: 2c4226f8ac2c925d7e1d59d1de1660cd1dd63f31

URL: 
https://github.com/llvm/llvm-project/commit/2c4226f8ac2c925d7e1d59d1de1660cd1dd63f31
DIFF: 
https://github.com/llvm/llvm-project/commit/2c4226f8ac2c925d7e1d59d1de1660cd1dd63f31.diff

LOG: [lldb-server][linux] Add ability to allocate memory

This patch adds support for the _M and _m gdb-remote packets, which
(de)allocate memory in the inferior. This works by "injecting" a
m(un)map syscall into the inferior. This consists of:
- finding an executable page of memory
- writing the syscall opcode to it
- setting up registers according to the os syscall convention
- single stepping over the syscall

The advantage of this approach over calling the mmap function is that
this works even in case the mmap function is buggy or unavailable. The
disadvantage is it is more platform-dependent, which is why this patch
only works on X86 (_32 and _64) right now. Adding support for other
linux architectures should be easy and consist of defining the
appropriate syscall constants. Adding support for other OSes depends on
the its ability to do a similar trick.

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

Added: 
lldb/test/API/tools/lldb-server/memory-allocation/Makefile

lldb/test/API/tools/lldb-server/memory-allocation/TestGdbRemoteMemoryAllocation.py
lldb/test/API/tools/lldb-server/memory-allocation/main.c
lldb/test/Shell/Expr/nodefaultlib.cpp

Modified: 
lldb/include/lldb/Host/common/NativeProcessProtocol.h
lldb/source/Plugins/Process/FreeBSDRemote/NativeProcessFreeBSD.cpp
lldb/source/Plugins/Process/FreeBSDRemote/NativeProcessFreeBSD.h
lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
lldb/source/Plugins/Process/Linux/NativeProcessLinux.h
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux.h
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.h
lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp
lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.h
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h
lldb/test/API/lang/c/stepping/TestStepAndBreakpoints.py
lldb/unittests/TestingSupport/Host/NativeProcessTestUtils.h

Removed: 




diff  --git a/lldb/include/lldb/Host/common/NativeProcessProtocol.h 
b/lldb/include/lldb/Host/common/NativeProcessProtocol.h
index 2faab6f587cd..8bdad5965a6c 100644
--- a/lldb/include/lldb/Host/common/NativeProcessProtocol.h
+++ b/lldb/include/lldb/Host/common/NativeProcessProtocol.h
@@ -17,6 +17,7 @@
 #include "lldb/Utility/ArchSpec.h"
 #include "lldb/Utility/Status.h"
 #include "lldb/Utility/TraceOptions.h"
+#include "lldb/Utility/UnimplementedError.h"
 #include "lldb/lldb-private-forward.h"
 #include "lldb/lldb-types.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -112,10 +113,14 @@ class NativeProcessProtocol {
   virtual Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size,
  size_t &bytes_written) = 0;
 
-  virtual Status AllocateMemory(size_t size, uint32_t permissions,
-lldb::addr_t &addr) = 0;
+  virtual llvm::Expected AllocateMemory(size_t size,
+  uint32_t permissions) {
+return llvm::make_error();
+  }
 
-  virtual Status DeallocateMemory(lldb::addr_t addr) = 0;
+  virtual llvm::Error DeallocateMemory(lldb::addr_t addr) {
+return llvm::make_error();
+  }
 
   virtual lldb::addr_t GetSharedLibraryInfoAddress() = 0;
 

diff  --git 
a/lldb/source/Plugins/Process/FreeBSDRemote/NativeProcessFreeBSD.cpp 
b/lldb/source/Plugins/Process/FreeBSDRemote/NativeProcessFreeBSD.cpp
index 4a50d8e4b960..e99d38f57eea 100644
--- a/lldb/source/Plugins/Process/FreeBSDRemote/NativeProcessFreeBSD.cpp
+++ b/lldb/source/Plugins/Process/FreeBSDRemote/NativeProcessFreeBSD.cpp
@@ -543,15 +543,6 @@ Status NativeProcessFreeBSD::PopulateMemoryRegionCache() {
   return Status();
 }
 
-Status NativeProcessFreeBSD::AllocateMemory(size_t size, uint32_t permissions,
-lldb::addr_t &addr) {
-  return Status("Unimplemented");
-}
-
-Status NativeProcessFreeBSD::DeallocateMemory(lldb::addr_t addr) {
-  return Status("Unimplemented");
-}
-
 lldb::addr_t NativeProcessFreeBSD::GetSharedLibraryInfoAddress() {
   // punt on this for now
   return LLDB_INVALID_ADDRESS;

diff  --git a/lldb/source/Plugins/Process/FreeBSDRemote/NativeProcessFreeBSD.h 
b/lldb/source/Plugins/Process/FreeBSDRemote/NativeProcessFreeBSD.h
index e1334c3bcf5d..8b4ae9889474

[Lldb-commits] [PATCH] D89124: [lldb-server][linux] Add ability to allocate memory

2020-10-14 Thread Pavel Labath 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 rG2c4226f8ac2c: [lldb-server][linux] Add ability to allocate 
memory (authored by labath).

Changed prior to commit:
  https://reviews.llvm.org/D89124?vs=297876&id=298134#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89124

Files:
  lldb/include/lldb/Host/common/NativeProcessProtocol.h
  lldb/source/Plugins/Process/FreeBSDRemote/NativeProcessFreeBSD.cpp
  lldb/source/Plugins/Process/FreeBSDRemote/NativeProcessFreeBSD.h
  lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
  lldb/source/Plugins/Process/Linux/NativeProcessLinux.h
  lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux.h
  lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp
  lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.h
  lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
  lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
  lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp
  lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.h
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h
  lldb/test/API/lang/c/stepping/TestStepAndBreakpoints.py
  lldb/test/API/tools/lldb-server/memory-allocation/Makefile
  
lldb/test/API/tools/lldb-server/memory-allocation/TestGdbRemoteMemoryAllocation.py
  lldb/test/API/tools/lldb-server/memory-allocation/main.c
  lldb/test/Shell/Expr/nodefaultlib.cpp
  lldb/unittests/TestingSupport/Host/NativeProcessTestUtils.h

Index: lldb/unittests/TestingSupport/Host/NativeProcessTestUtils.h
===
--- lldb/unittests/TestingSupport/Host/NativeProcessTestUtils.h
+++ lldb/unittests/TestingSupport/Host/NativeProcessTestUtils.h
@@ -41,9 +41,6 @@
   MOCK_METHOD0(Detach, Status());
   MOCK_METHOD1(Signal, Status(int Signo));
   MOCK_METHOD0(Kill, Status());
-  MOCK_METHOD3(AllocateMemory,
-   Status(size_t Size, uint32_t Permissions, addr_t &Addr));
-  MOCK_METHOD1(DeallocateMemory, Status(addr_t Addr));
   MOCK_METHOD0(GetSharedLibraryInfoAddress, addr_t());
   MOCK_METHOD0(UpdateThreads, size_t());
   MOCK_CONST_METHOD0(GetAuxvData,
@@ -147,4 +144,4 @@
 };
 } // namespace lldb_private
 
-#endif
\ No newline at end of file
+#endif
Index: lldb/test/Shell/Expr/nodefaultlib.cpp
===
--- /dev/null
+++ lldb/test/Shell/Expr/nodefaultlib.cpp
@@ -0,0 +1,16 @@
+// Test that we're able to evaluate expressions in inferiors without the
+// standard library (and mmap-like functions in particular).
+
+// REQUIRES: native
+// XFAIL: system-linux && !(target-x86 || target-x86_64)
+// XFAIL: system-netbsd || system-freebsd
+
+// RUN: %build %s --nodefaultlib -o %t
+// RUN: %lldb %t -o "b main" -o run -o "p call_me(5, 6)" -o exit \
+// RUN:   | FileCheck %s
+
+// CHECK: (int) $0 = 30
+
+int call_me(int x, long y) { return x * y; }
+
+int main() { return call_me(4, 5); }
Index: lldb/test/API/tools/lldb-server/memory-allocation/main.c
===
--- /dev/null
+++ lldb/test/API/tools/lldb-server/memory-allocation/main.c
@@ -0,0 +1 @@
+int main() { return 0; }
Index: lldb/test/API/tools/lldb-server/memory-allocation/TestGdbRemoteMemoryAllocation.py
===
--- /dev/null
+++ lldb/test/API/tools/lldb-server/memory-allocation/TestGdbRemoteMemoryAllocation.py
@@ -0,0 +1,101 @@
+
+import gdbremote_testcase
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+supported_linux_archs = ["x86_64", "i386"]
+supported_oses = ["linux"]
+
+class TestGdbRemoteMemoryAllocation(gdbremote_testcase.GdbRemoteTestCaseBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def allocate(self, size, permissions):
+self.test_sequence.add_log_lines(["read packet: $_M{:x},{}#00".format(size, permissions),
+  {"direction": "send",
+   "regex":
+   r"^\$([0-9a-f]+)#[0-9a-fA-F]{2}$",
+   "capture": {
+   1: "addr"}},
+  ],
+ True)
+context = self.expect_gdbremote_sequence()
+self.assertIsNotNone(context)
+
+addr = int(context.get("addr"), 16)
+self.test_sequence.add_log_lines(["read packet: $qMemoryRegionInfo:{:x}#00".format(addr),
+  {"direction": "send",
+

[Lldb-commits] [PATCH] D82863: [LLDB] Add support to resize SVE registers at run-time

2020-10-14 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

In D82863#2324560 , @omjavaid wrote:

> In D82863#2321647 , @labath wrote:
>
>> In D82863#2321370 , @omjavaid wrote:
>>
>>> In D82863#2320342 , @jasonmolenda 
>>> wrote:
>>>
 The original g/G packets were designed for little embedded systems where 
 the stub had to be very small and dumb, and could just memcpy the payload 
 in the packet into the register context & back out again.  Any sensible 
 design today would, at least, have some form of an array of regnum:regval 
 to eliminate many of the problems.

> Unless of course, we make sure SVE regs come last, but that imposes some 
> constraints on future registers sets. I suppose we might be able to say 
> that all variable-length or otherwise-funny registers must come last.

 Yeah, Omair's patch currently assumes that the SVE regs come last already 
 when they copy & truncate the registers context to heap.  I fear that 
 we'll get to armv12 and we'll be adding registers after the SVE and wonder 
 why they're being truncated somewhere in lldb. :)
>>
>> Well.. we could design it such that the SVE registers (and any other 
>> dynamically-sized regs) always come last. Then they wouldn't impact the 
>> offsets of static registers.
>>
>> I don't think we have a requirement that newer register sets must be 
>> appended. Or at least, we shouldn't have, as now both intel and arm have cpu 
>> features (and registers) that may be arbitrarily combined in future 
>> processors.
>
> For now I am considering variable sized registers i-e SVE Z and P registers 
> to always come last which is currently the case and will be in future patches 
> which add support for Pointer Authentication and MTE registers.
>
 @omjavaid , what do you think about disabling g/G when we're working with 
 SVE registers (GDBRemoteCommunicationClient::AvoidGPackets)?  There are 
 some gdb-remote stubs that can *only* read/write registers with g/G, but I 
 think it's reasonable to say "you must implement p/P for a target with 
 SVE", that's a generic packet shared by both lldb and gdb.  We could add a 
 more-modern g/G replacement packet, but no one would have that 
 implemented, and if they were going to add anything, I'd have them 
 implement p/P unless it's perf problems and they need a read-all-registers 
 / write-all-registers packet that works with SVE.
>
> Just scrolling through GDB log one of the answers about target XML is that 
> target XML is not exchanged for native connection where gdbserver is not 
> being used. For gdbserver connection, target xml is exchanged onces per 
> connection and register sizes are updated based on vg after that internally. 
> However testing gdb with same executable as the one I wrote for LLDB was 
> having gdb remote connection crash which could be something to do with SVE or 
> some other bug.

Interesting.

I started drafting an email to the gdb mailing list to try to clarify this 
thing. For that, I was re-reading the gdb docs for the qXfer:target.xml packet, 
 I realized that the gdb interpretation is mostly unambiguous about this thing:

- **regnum**: The register’s number. If omitted, . 
This register number is used to read or write the register; e.g. it is used in 
the remote p and P packets, and **registers appear in the g and G packets in 
order of increasing register number**.

I'm sure that whoever wrote this did not have variable-length registers in 
mind. However, it's interpretation for variable-length registers is pretty 
clear: take each register, and dump its bytes in sequence (no matter many of 
them are in the register at this particular time). The reason this is 
unambiguous is because gdb does not have the "offset" attribute of the "reg" 
element, and so the only way to find its 'g' offset is via this algorithm. And 
given your explanation about "switching" target.xml descriptions at runtime, 
I'm would expect this is what is happening within gdb.

The problem is that he "offset" attribute (added by lldb) makes things 
ambiguous, as it provides another way to find a register in the 'g' blob. So 
how about we "fix" that ambiguity by having lldb-server omit the "offset" 
attribute for variable-length registers?

Sending it over is actively harmful, as the value is very likely to be wrong, 
and I believe that in your current implementation these numbers are pretty much 
ignored by the client anyway. Lldb should already have code to automatically 
compute the regiser offsets when the "offset" attribute is missing (though it's 
possible it may not handle partially missing values correctly). This code would 
need to be extended to recompute those offsets whenever register sizes change 
(which is roughly what this patch does). We could also extend the parser with a 

[Lldb-commits] [lldb] ea3a547 - [lldb] Remove bogus ProcessMonitor forward-decls

2020-10-14 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2020-10-14T16:43:45+02:00
New Revision: ea3a547f0be20d86b041778ae8e2779f2031f714

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

LOG: [lldb] Remove bogus ProcessMonitor forward-decls

This class is not used in those files.

Added: 


Modified: 
lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm.h
lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm64.h
lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_mips64.h
lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_powerpc.h
lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_s390x.h
lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.h

Removed: 




diff  --git a/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm.h 
b/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm.h
index 6e7d47d5e50a..099c37d46f49 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm.h
+++ b/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm.h
@@ -14,8 +14,6 @@
 #include "lldb/Target/RegisterContext.h"
 #include "lldb/Utility/Log.h"
 
-class ProcessMonitor;
-
 class RegisterContextPOSIX_arm : public lldb_private::RegisterContext {
 public:
   RegisterContextPOSIX_arm(

diff  --git a/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm64.h 
b/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm64.h
index c5fda7c1f041..a3f07bb2823b 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm64.h
+++ b/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm64.h
@@ -14,8 +14,6 @@
 #include "lldb/Target/RegisterContext.h"
 #include "lldb/Utility/Log.h"
 
-class ProcessMonitor;
-
 class RegisterContextPOSIX_arm64 : public lldb_private::RegisterContext {
 public:
   RegisterContextPOSIX_arm64(

diff  --git a/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_mips64.h 
b/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_mips64.h
index 1843a2a6aff3..b66dc3f44524 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_mips64.h
+++ b/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_mips64.h
@@ -14,10 +14,6 @@
 #include "lldb/Target/RegisterContext.h"
 #include "lldb/Utility/Log.h"
 
-using namespace lldb_private;
-
-class ProcessMonitor;
-
 class RegisterContextPOSIX_mips64 : public lldb_private::RegisterContext {
 public:
 

diff  --git 
a/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_powerpc.h 
b/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_powerpc.h
index e2c33461c8f1..5dd8c890da6e 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_powerpc.h
+++ b/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_powerpc.h
@@ -14,8 +14,6 @@
 #include "lldb/Target/RegisterContext.h"
 #include "lldb/Utility/Log.h"
 
-class ProcessMonitor;
-
 // Internal codes for all powerpc registers.
 enum {
   k_first_gpr_powerpc,

diff  --git a/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_s390x.h 
b/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_s390x.h
index 7df732d13ffa..7027af04f0bb 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_s390x.h
+++ b/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_s390x.h
@@ -15,8 +15,6 @@
 #include "lldb/Target/RegisterContext.h"
 #include "lldb/Utility/Log.h"
 
-class ProcessMonitor;
-
 class RegisterContextPOSIX_s390x : public lldb_private::RegisterContext {
 public:
   RegisterContextPOSIX_s390x(

diff  --git a/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.h 
b/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.h
index c4886ae618a2..81d467311c4f 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.h
+++ b/lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.h
@@ -15,8 +15,6 @@
 #include "lldb/Target/RegisterContext.h"
 #include "lldb/Utility/Log.h"
 
-class ProcessMonitor;
-
 class RegisterContextPOSIX_x86 : public lldb_private::RegisterContext {
 public:
   RegisterContextPOSIX_x86(lldb_private::Thread &thread,



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


[Lldb-commits] [lldb] 36f22cd - [lldb] Fix TestGdbRemoteMemoryAllocation on windows

2020-10-14 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2020-10-14T16:46:10+02:00
New Revision: 36f22cd28d5e57c197ea374048a06dbdc5a08214

URL: 
https://github.com/llvm/llvm-project/commit/36f22cd28d5e57c197ea374048a06dbdc5a08214
DIFF: 
https://github.com/llvm/llvm-project/commit/36f22cd28d5e57c197ea374048a06dbdc5a08214.diff

LOG: [lldb] Fix TestGdbRemoteMemoryAllocation on windows

It appears that memory allocation actually works on windows (but it was
not fully wired up before 2c4226f8).

Added: 


Modified: 

lldb/test/API/tools/lldb-server/memory-allocation/TestGdbRemoteMemoryAllocation.py

Removed: 




diff  --git 
a/lldb/test/API/tools/lldb-server/memory-allocation/TestGdbRemoteMemoryAllocation.py
 
b/lldb/test/API/tools/lldb-server/memory-allocation/TestGdbRemoteMemoryAllocation.py
index 64e0782f4bf8..5c8e4621ce3b 100644
--- 
a/lldb/test/API/tools/lldb-server/memory-allocation/TestGdbRemoteMemoryAllocation.py
+++ 
b/lldb/test/API/tools/lldb-server/memory-allocation/TestGdbRemoteMemoryAllocation.py
@@ -6,7 +6,7 @@
 
 
 supported_linux_archs = ["x86_64", "i386"]
-supported_oses = ["linux"]
+supported_oses = ["linux", "windows"]
 
 class TestGdbRemoteMemoryAllocation(gdbremote_testcase.GdbRemoteTestCaseBase):
 



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


[Lldb-commits] [PATCH] D88483: Add possibility to get module from SBType

2020-10-14 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere requested changes to this revision.
JDevlieghere added inline comments.
This revision now requires changes to proceed.



Comment at: lldb/source/API/SBType.cpp:504
+if (!IsValid())
+return sb_module;
+

mib wrote:
> It would be nice to record the return value for the reproducers.
Not just nice, it's mandatory. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88483

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


[Lldb-commits] [PATCH] D89334: [lldb] Support Python imports relative the to the current file being sourced

2020-10-14 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added a comment.

In D89334#2329667 , @labath wrote:

> The main question on my mind is should we be adding the directory of the 
> python file to the path (which is what I believe is happening now), or if we 
> should add the directory of the command file that is being sourced (and 
> adjust the way we import the file). The main impact of this is how will the 
> imported module "see" itself (what will it's name be), and how it will be 
> able to import other modules.
>
> Imagine the user has the following (reasonable, I think) file structure.
>
>   $ROOT/utils/consult_oracle.py
>   $ROOT/automatic_bug_finder/main.py # uses consult_oracle.py
>   $ROOT/awesome_backtrace_analyzer/main.py # uses consult_oracle.py
>   $ROOT/install_super_scripts.lldbinit # calls command script import 
> awesome_backtrace_analyzer/main.py
>
> If "command script import awesome_backtrace_analyzer/main.py" ends up adding 
> `$ROOT/awesome_backtrace_analyzer`  to the path, then this module will have a 
> hard time importing the modules it depends on (it would either have to use 
> weird relative imports, or mess with sys.path itself. If we add just `$ROOT` 
> then it could simply `import utils.consult_oracle`.

I guess then the user should have called `command script import 
awesome_backtrace_analyzer` to import the package rather than the `main.py` 
inside it. But I get your point. FWIW just adding the `$ROOT` is how I did the 
original implementation before adding the tests for the nested directories and 
`.py` files that Dave suggested. It would solve this issues but then doesn't 
support those scenarios. I don't know if it would be less confusing that you 
can't pass a relative path to a `.py` file or that you can't import another 
module as you described.

> I think setting the import path to $ROOT would actually make the sys.path 
> manipulation serve some useful purpose (and also reduce the number of 
> sys.path entries we add). If, on the other hand, we are not interested making 
> cross-module imports work "out of the box" (like, we could say that it's the 
> responsibility of individual modules to ensure that), we could also try to 
> import the file without messing with sys.path at all 
> (https://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path
>  gives one way to do that).

I would prefer this approach if it didn't require to name the module ourself. 
Any heuristic will have the risk of being ambitious as well (which is probably 
why the API makes you specify the module name).


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

https://reviews.llvm.org/D89334

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


[Lldb-commits] [PATCH] D89124: [lldb-server][linux] Add ability to allocate memory

2020-10-14 Thread Stella Stamenova via Phabricator via lldb-commits
stella.stamenova added a comment.

It looks like this changed caused a failure on the windows bot and your follow 
up change to fix the test left it still broken. Can you have a look?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89124

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


[Lldb-commits] [PATCH] D89408: [trace] rename ThreadIntelPT into TraceTrace

2020-10-14 Thread walter erquinigo via Phabricator via lldb-commits
wallace created this revision.
wallace added reviewers: labath, clayborg.
Herald added subscribers: lldb-commits, mgorny.
Herald added a project: LLDB.
wallace requested review of this revision.
Herald added a subscriber: JDevlieghere.

Renamed ThreadIntelPT to TreaceThread, making it a top-level class. I noticed 
that this class can and shuld work for any trace plugin and there's nothing 
intel-pt specific in it.
With that TraceThread change, I was able to move most of the json file parsing 
logic to the base class TraceSessionFileParser, which makes adding new plug-ins 
easier.

This originally was part of https://reviews.llvm.org/D89283


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89408

Files:
  lldb/include/lldb/Target/TraceSessionFileParser.h
  lldb/include/lldb/Target/TraceThread.h
  lldb/include/lldb/lldb-forward.h
  lldb/source/Plugins/Trace/intel-pt/CMakeLists.txt
  lldb/source/Plugins/Trace/intel-pt/ThreadIntelPT.cpp
  lldb/source/Plugins/Trace/intel-pt/ThreadIntelPT.h
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.h
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPTSessionFileParser.cpp
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPTSessionFileParser.h
  lldb/source/Target/CMakeLists.txt
  lldb/source/Target/TraceSessionFileParser.cpp
  lldb/source/Target/TraceThread.cpp

Index: lldb/source/Target/TraceThread.cpp
===
--- lldb/source/Target/TraceThread.cpp
+++ lldb/source/Target/TraceThread.cpp
@@ -1,4 +1,4 @@
-//===-- ThreadIntelPT.cpp -===//
+//===-- TraceThread.cpp ---===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,7 +6,7 @@
 //
 //===--===//
 
-#include "ThreadIntelPT.h"
+#include "lldb/Target/TraceThread.h"
 
 #include 
 
@@ -16,11 +16,10 @@
 
 using namespace lldb;
 using namespace lldb_private;
-using namespace lldb_private::trace_intel_pt;
 
-void ThreadIntelPT::RefreshStateAfterStop() {}
+void TraceThread::RefreshStateAfterStop() {}
 
-RegisterContextSP ThreadIntelPT::GetRegisterContext() {
+RegisterContextSP TraceThread::GetRegisterContext() {
   if (!m_reg_context_sp)
 m_reg_context_sp = CreateRegisterContextForFrame(nullptr);
 
@@ -28,11 +27,13 @@
 }
 
 RegisterContextSP
-ThreadIntelPT::CreateRegisterContextForFrame(StackFrame *frame) {
+TraceThread::CreateRegisterContextForFrame(StackFrame *frame) {
   // Eventually this will calculate the register context based on the current
   // trace position.
   return std::make_shared(
   *this, 0, GetProcess()->GetAddressByteSize(), LLDB_INVALID_ADDRESS);
 }
 
-bool ThreadIntelPT::CalculateStopInfo() { return false; }
+bool TraceThread::CalculateStopInfo() { return false; }
+
+const FileSpec &TraceThread::GetTraceFile() const { return m_trace_file; }
Index: lldb/source/Target/TraceSessionFileParser.cpp
===
--- lldb/source/Target/TraceSessionFileParser.cpp
+++ lldb/source/Target/TraceSessionFileParser.cpp
@@ -10,8 +10,11 @@
 
 #include 
 
+#include "lldb/Core/Debugger.h"
 #include "lldb/Core/Module.h"
+#include "lldb/Target/Process.h"
 #include "lldb/Target/Target.h"
+#include "lldb/Target/TraceThread.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -34,7 +37,6 @@
   ModuleSpec module_spec;
   module_spec.GetFileSpec() = local_file_spec;
   module_spec.GetPlatformFileSpec() = system_file_spec;
-  module_spec.SetObjectOffset(module.load_address.value);
 
   if (module.uuid.hasValue())
 module_spec.GetUUID().SetFromStringRef(*module.uuid);
@@ -42,7 +44,14 @@
   Status error;
   ModuleSP module_sp =
   target_sp->GetOrCreateModule(module_spec, /*notify*/ false, &error);
-  return error.ToError();
+
+  if (error.Fail())
+return error.ToError();
+
+  bool load_addr_changed = false;
+  module_sp->SetLoadAddress(*target_sp, module.load_address.value, false,
+load_addr_changed);
+  return llvm::Error::success();
 }
 
 Error TraceSessionFileParser::CreateJSONError(json::Path::Root &root,
@@ -87,6 +96,55 @@
   return schema_builder.str();
 }
 
+void TraceSessionFileParser::ParseThread(ProcessSP &process_sp,
+ const JSONThread &thread) {
+  lldb::tid_t tid = static_cast(thread.tid);
+
+  FileSpec trace_file(thread.trace_file);
+  NormalizePath(trace_file);
+
+  ThreadSP thread_sp =
+  std::make_shared(*process_sp, tid, trace_file);
+  process_sp->GetThreadList().AddThread(thread_sp);
+}
+
+Expected
+TraceSessionFileParser::ParseProcess(const JSONProcess &process) {
+  TargetSP target_sp;
+  Status error = m_debugger.GetTargetList().CreateTarget(
+  m_debugger, /*user_exe_

[Lldb-commits] [PATCH] D88483: Add possibility to get module from SBType

2020-10-14 Thread Ilya Bukonkin via Phabricator via lldb-commits
fallkrum updated this revision to Diff 298184.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88483

Files:
  lldb/bindings/interface/SBType.i
  lldb/include/lldb/API/SBModule.h
  lldb/include/lldb/API/SBType.h
  lldb/include/lldb/Symbol/Type.h
  lldb/source/API/SBType.cpp
  lldb/source/Symbol/Type.cpp

Index: lldb/source/Symbol/Type.cpp
===
--- lldb/source/Symbol/Type.cpp
+++ lldb/source/Symbol/Type.cpp
@@ -727,6 +727,14 @@
   return ModuleSP();
 }
 
+ModuleSP Type::GetExeModule() {
+  if (m_compiler_type) {
+SymbolFile *symbol_file = m_compiler_type.GetTypeSystem()->GetSymbolFile();
+return symbol_file->GetObjectFile()->GetModule();
+  }
+  return ModuleSP();
+}
+
 TypeAndOrName::TypeAndOrName(TypeSP &in_type_sp) {
   if (in_type_sp) {
 m_compiler_type = in_type_sp->GetForwardCompilerType();
@@ -821,6 +829,7 @@
 void TypeImpl::SetType(const lldb::TypeSP &type_sp) {
   if (type_sp) {
 m_static_type = type_sp->GetForwardCompilerType();
+m_exe_module_wp = type_sp->GetExeModule();
 m_module_wp = type_sp->GetModule();
   } else {
 m_static_type.Clear();
@@ -847,6 +856,15 @@
 }
 
 bool TypeImpl::CheckModule(lldb::ModuleSP &module_sp) const {
+  return CheckModuleCommon(m_module_wp, module_sp);
+}
+
+bool TypeImpl::CheckExeModule(lldb::ModuleSP &module_sp) const {
+  return CheckModuleCommon(m_exe_module_wp, module_sp);
+}
+
+bool TypeImpl::CheckModuleCommon(const lldb::ModuleWP &input_module_wp,
+ lldb::ModuleSP &module_sp) const {
   // Check if we have a module for this type. If we do and the shared pointer
   // is can be successfully initialized with m_module_wp, return true. Else
   // return false if we didn't have a module, or if we had a module and it has
@@ -855,7 +873,7 @@
   // this function returns true. If we have a module, the "module_sp" will be
   // filled in with a strong reference to the module so that the module will at
   // least stay around long enough for the type query to succeed.
-  module_sp = m_module_wp.lock();
+  module_sp = input_module_wp.lock();
   if (!module_sp) {
 lldb::ModuleWP empty_module_wp;
 // If either call to "std::weak_ptr::owner_before(...) value returns true,
@@ -863,9 +881,9 @@
 // reference to a valid shared pointer. This helps us know if we had a
 // valid reference to a section which is now invalid because the module it
 // was in was deleted
-if (empty_module_wp.owner_before(m_module_wp) ||
-m_module_wp.owner_before(empty_module_wp)) {
-  // m_module_wp had a valid reference to a module, but all strong
+if (empty_module_wp.owner_before(input_module_wp) ||
+input_module_wp.owner_before(empty_module_wp)) {
+  // input_module_wp had a valid reference to a module, but all strong
   // references have been released and the module has been deleted
   return false;
 }
@@ -899,6 +917,13 @@
   m_dynamic_type.Clear();
 }
 
+ModuleSP TypeImpl::GetModule() {
+  lldb::ModuleSP module_sp;
+  if (CheckExeModule(module_sp))
+return module_sp;
+  return nullptr;
+}
+
 ConstString TypeImpl::GetName() const {
   ModuleSP module_sp;
   if (CheckModule(module_sp)) {
Index: lldb/source/API/SBType.cpp
===
--- lldb/source/API/SBType.cpp
+++ lldb/source/API/SBType.cpp
@@ -9,6 +9,7 @@
 #include "lldb/API/SBType.h"
 #include "SBReproducerPrivate.h"
 #include "lldb/API/SBDefines.h"
+#include "lldb/API/SBModule.h"
 #include "lldb/API/SBStream.h"
 #include "lldb/API/SBTypeEnumMember.h"
 #include "lldb/Core/Mangled.h"
@@ -495,6 +496,17 @@
   return m_opaque_sp->GetCompilerType(true).GetTypeInfo();
 }
 
+lldb::SBModule SBType::GetModule() {
+  LLDB_RECORD_METHOD_NO_ARGS(lldb::SBModule, SBType, GetModule);
+
+  lldb::SBModule sb_module;
+  if (!IsValid())
+return LLDB_RECORD_RESULT(sb_module);
+
+  sb_module.SetSP(m_opaque_sp->GetModule());
+  return LLDB_RECORD_RESULT(sb_module);
+}
+
 const char *SBType::GetName() {
   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBType, GetName);
 
@@ -950,6 +962,7 @@
(uint32_t));
   LLDB_REGISTER_METHOD(bool, SBType, IsTypeComplete, ());
   LLDB_REGISTER_METHOD(uint32_t, SBType, GetTypeFlags, ());
+  LLDB_REGISTER_METHOD(lldb::SBModule, SBType, GetModule, ());
   LLDB_REGISTER_METHOD(const char *, SBType, GetName, ());
   LLDB_REGISTER_METHOD(const char *, SBType, GetDisplayTypeName, ());
   LLDB_REGISTER_METHOD(lldb::TypeClass, SBType, GetTypeClass, ());
Index: lldb/include/lldb/Symbol/Type.h
===
--- lldb/include/lldb/Symbol/Type.h
+++ lldb/include/lldb/Symbol/Type.h
@@ -114,6 +114,14 @@
   // Type instances. They can store a weak pointer to the Module;
   lldb::ModuleSP GetModule();
 
+  /*
+   GetModule may return module for compi

[Lldb-commits] [PATCH] D89315: [debugserver] Add option to propagate SIGSEGV to target process

2020-10-14 Thread Jim Ingham via Phabricator via lldb-commits
jingham added a comment.

Thanks, that's a little better.

It would be even nicer if the DNB API's you are adding "unmask_signals" to 
would take the Context instead.  At this point they are pulling the launch 
flavor and the unmask signals from the context, so just getting the RNBContext 
would be cleaner.  If you feel motivated to make that change as well, that 
would be great.  But this is also okay as it stands.


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

https://reviews.llvm.org/D89315

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


[Lldb-commits] [lldb] ff30bff - [lldb] [Process/FreeBSDRemote] Support YMM reg via PT_*XSTATE

2020-10-14 Thread Michał Górny via lldb-commits

Author: Michał Górny
Date: 2020-10-14T19:56:46+02:00
New Revision: ff30bff136743817dae66029f512cdb3a009937f

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

LOG: [lldb] [Process/FreeBSDRemote] Support YMM reg via PT_*XSTATE

Add a framework for reading/writing extended register sets via
PT_GETXSTATE/PT_GETXSTATE_INFO/PT_SETXSTATE, and use it to support
YMM0..YMM15.  The code is prepared to handle arbitrary XSAVE extensions,
including correct offset handling.

This fixes Shell/Register/*ymm* tests.

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

Added: 


Modified: 

lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.cpp

lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.h

Removed: 




diff  --git 
a/lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.cpp
 
b/lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.cpp
index 157b2167f2ff..fd8e600ca25f 100644
--- 
a/lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.cpp
+++ 
b/lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.cpp
@@ -10,7 +10,11 @@
 
 #include "NativeRegisterContextFreeBSD_x86_64.h"
 
+// clang-format off
 #include 
+#include 
+#include 
+// clang-format on
 
 #include "lldb/Host/HostInfo.h"
 #include "lldb/Utility/DataBufferHeap.h"
@@ -18,6 +22,7 @@
 #include "lldb/Utility/RegisterValue.h"
 #include "lldb/Utility/Status.h"
 
+#include "NativeProcessFreeBSD.h"
 #include "Plugins/Process/Utility/RegisterContextFreeBSD_i386.h"
 #include "Plugins/Process/Utility/RegisterContextFreeBSD_x86_64.h"
 
@@ -392,7 +397,7 @@ int 
NativeRegisterContextFreeBSD_x86_64::GetSetForNativeRegNum(
 if (reg_num >= k_first_fpr_i386 && reg_num <= k_last_fpr_i386)
   return FPRegSet;
 if (reg_num >= k_first_avx_i386 && reg_num <= k_last_avx_i386)
-  return -1; // AVX
+  return XSaveRegSet; // AVX
 if (reg_num >= k_first_mpxr_i386 && reg_num <= k_last_mpxr_i386)
   return -1; // MPXR
 if (reg_num >= k_first_mpxc_i386 && reg_num <= k_last_mpxc_i386)
@@ -406,7 +411,7 @@ int 
NativeRegisterContextFreeBSD_x86_64::GetSetForNativeRegNum(
 if (reg_num >= k_first_fpr_x86_64 && reg_num <= k_last_fpr_x86_64)
   return FPRegSet;
 if (reg_num >= k_first_avx_x86_64 && reg_num <= k_last_avx_x86_64)
-  return -1; // AVX
+  return XSaveRegSet; // AVX
 if (reg_num >= k_first_mpxr_x86_64 && reg_num <= k_last_mpxr_x86_64)
   return -1; // MPXR
 if (reg_num >= k_first_mpxc_x86_64 && reg_num <= k_last_mpxc_x86_64)
@@ -433,6 +438,27 @@ Status 
NativeRegisterContextFreeBSD_x86_64::ReadRegisterSet(uint32_t set) {
 #endif
   case DBRegSet:
 return DoRegisterSet(PT_GETDBREGS, &m_dbr);
+  case XSaveRegSet: {
+struct ptrace_xstate_info info;
+Status ret = NativeProcessFreeBSD::PtraceWrapper(
+PT_GETXSTATE_INFO, GetProcessPid(), &info, sizeof(info));
+if (!ret.Success())
+  return ret;
+
+assert(info.xsave_mask & XFEATURE_ENABLED_X87);
+assert(info.xsave_mask & XFEATURE_ENABLED_SSE);
+
+m_xsave_offsets[YMMXSaveSet] = LLDB_INVALID_XSAVE_OFFSET;
+if (info.xsave_mask & XFEATURE_ENABLED_YMM_HI128) {
+  uint32_t eax, ecx, edx;
+  __get_cpuid_count(0x0D, 2, &eax, &m_xsave_offsets[YMMXSaveSet], &ecx,
+&edx);
+}
+
+m_xsave.resize(info.xsave_len);
+return NativeProcessFreeBSD::PtraceWrapper(PT_GETXSTATE, GetProcessPid(),
+   m_xsave.data(), m_xsave.size());
+  }
   }
   llvm_unreachable("NativeRegisterContextFreeBSD_x86_64::ReadRegisterSet");
 }
@@ -449,6 +475,11 @@ Status 
NativeRegisterContextFreeBSD_x86_64::WriteRegisterSet(uint32_t set) {
 #endif
   case DBRegSet:
 return DoRegisterSet(PT_SETDBREGS, &m_dbr);
+  case XSaveRegSet:
+// ReadRegisterSet() must always be called before WriteRegisterSet().
+assert(m_xsave.size() > 0);
+return NativeProcessFreeBSD::PtraceWrapper(PT_SETXSTATE, GetProcessPid(),
+   m_xsave.data(), m_xsave.size());
   }
   llvm_unreachable("NativeRegisterContextFreeBSD_x86_64::WriteRegisterSet");
 }
@@ -713,6 +744,39 @@ NativeRegisterContextFreeBSD_x86_64::ReadRegister(const 
RegisterInfo *reg_info,
reg_info->byte_size, endian::InlHostByteOrder());
 #endif
 break;
+  case lldb_ymm0_x86_64:
+  case lldb_ymm1_x86_64:
+  case lldb_ymm2_x86_64:
+  case lldb_ymm3_x86_64:
+  case lldb_ymm4_x86_64:
+  case lldb_ymm5_x86_64:
+  case lldb_ymm6_x86_64:
+  case lldb_ymm7_x86_64:
+  case lldb_ymm8_x86_64:
+  case lldb_ymm9_x86_64:
+  case lldb_ymm10_x86_64:
+  case lldb_ymm11_x86_64:
+  case lldb_ymm12_x86_64:
+  

[Lldb-commits] [PATCH] D89193: [lldb] [Process/FreeBSDRemote] Support YMM reg via PT_*XSTATE

2020-10-14 Thread Michał Górny via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGff30bff13674: [lldb] [Process/FreeBSDRemote] Support YMM reg 
via PT_*XSTATE (authored by mgorny).
Herald added a project: LLDB.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89193

Files:
  
lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.cpp
  
lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.h

Index: lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.h
===
--- lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.h
+++ lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.h
@@ -22,6 +22,8 @@
 #include "Plugins/Process/Utility/RegisterContext_x86.h"
 #include "Plugins/Process/Utility/lldb-x86-register-enums.h"
 
+#define LLDB_INVALID_XSAVE_OFFSET UINT32_MAX
+
 namespace lldb_private {
 namespace process_freebsd {
 
@@ -75,7 +77,11 @@
 
 private:
   // Private member types.
-  enum { GPRegSet, FPRegSet, DBRegSet };
+  enum { GPRegSet, FPRegSet, XSaveRegSet, DBRegSet };
+  enum {
+YMMXSaveSet,
+MaxXSaveSet = YMMXSaveSet,
+  };
 
   // Private member variables.
   struct reg m_gpr;
@@ -85,6 +91,8 @@
   struct xmmreg m_fpr;
 #endif
   struct dbreg m_dbr;
+  std::vector m_xsave;
+  std::array m_xsave_offsets;
 
   int GetSetForNativeRegNum(int reg_num) const;
   int GetDR(int num) const;
Index: lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.cpp
===
--- lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.cpp
+++ lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.cpp
@@ -10,7 +10,11 @@
 
 #include "NativeRegisterContextFreeBSD_x86_64.h"
 
+// clang-format off
 #include 
+#include 
+#include 
+// clang-format on
 
 #include "lldb/Host/HostInfo.h"
 #include "lldb/Utility/DataBufferHeap.h"
@@ -18,6 +22,7 @@
 #include "lldb/Utility/RegisterValue.h"
 #include "lldb/Utility/Status.h"
 
+#include "NativeProcessFreeBSD.h"
 #include "Plugins/Process/Utility/RegisterContextFreeBSD_i386.h"
 #include "Plugins/Process/Utility/RegisterContextFreeBSD_x86_64.h"
 
@@ -392,7 +397,7 @@
 if (reg_num >= k_first_fpr_i386 && reg_num <= k_last_fpr_i386)
   return FPRegSet;
 if (reg_num >= k_first_avx_i386 && reg_num <= k_last_avx_i386)
-  return -1; // AVX
+  return XSaveRegSet; // AVX
 if (reg_num >= k_first_mpxr_i386 && reg_num <= k_last_mpxr_i386)
   return -1; // MPXR
 if (reg_num >= k_first_mpxc_i386 && reg_num <= k_last_mpxc_i386)
@@ -406,7 +411,7 @@
 if (reg_num >= k_first_fpr_x86_64 && reg_num <= k_last_fpr_x86_64)
   return FPRegSet;
 if (reg_num >= k_first_avx_x86_64 && reg_num <= k_last_avx_x86_64)
-  return -1; // AVX
+  return XSaveRegSet; // AVX
 if (reg_num >= k_first_mpxr_x86_64 && reg_num <= k_last_mpxr_x86_64)
   return -1; // MPXR
 if (reg_num >= k_first_mpxc_x86_64 && reg_num <= k_last_mpxc_x86_64)
@@ -433,6 +438,27 @@
 #endif
   case DBRegSet:
 return DoRegisterSet(PT_GETDBREGS, &m_dbr);
+  case XSaveRegSet: {
+struct ptrace_xstate_info info;
+Status ret = NativeProcessFreeBSD::PtraceWrapper(
+PT_GETXSTATE_INFO, GetProcessPid(), &info, sizeof(info));
+if (!ret.Success())
+  return ret;
+
+assert(info.xsave_mask & XFEATURE_ENABLED_X87);
+assert(info.xsave_mask & XFEATURE_ENABLED_SSE);
+
+m_xsave_offsets[YMMXSaveSet] = LLDB_INVALID_XSAVE_OFFSET;
+if (info.xsave_mask & XFEATURE_ENABLED_YMM_HI128) {
+  uint32_t eax, ecx, edx;
+  __get_cpuid_count(0x0D, 2, &eax, &m_xsave_offsets[YMMXSaveSet], &ecx,
+&edx);
+}
+
+m_xsave.resize(info.xsave_len);
+return NativeProcessFreeBSD::PtraceWrapper(PT_GETXSTATE, GetProcessPid(),
+   m_xsave.data(), m_xsave.size());
+  }
   }
   llvm_unreachable("NativeRegisterContextFreeBSD_x86_64::ReadRegisterSet");
 }
@@ -449,6 +475,11 @@
 #endif
   case DBRegSet:
 return DoRegisterSet(PT_SETDBREGS, &m_dbr);
+  case XSaveRegSet:
+// ReadRegisterSet() must always be called before WriteRegisterSet().
+assert(m_xsave.size() > 0);
+return NativeProcessFreeBSD::PtraceWrapper(PT_SETXSTATE, GetProcessPid(),
+   m_xsave.data(), m_xsave.size());
   }
   llvm_unreachable("NativeRegisterContextFreeBSD_x86_64::WriteRegisterSet");
 }
@@ -713,6 +744,39 @@
reg_info->byte_size, endian::InlHostByteOrder());
 #endif
 break;
+  case lldb_ymm0_x86_64:
+  case lldb_ymm1_x86_64:
+  case lldb_ymm2_x86_64:
+  case lldb_ymm3_x86_64:
+  case lldb_ymm4_x86_64:
+  case lldb_ymm5_x86_64:
+  case lldb_ymm6_x86_64:
+  case 

[Lldb-commits] [PATCH] D89413: [lldb] [Process/FreeBSDRemote] Initial multithreading support

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

Implement initial support for watching thread creation and termination.
Update ptrace() calls to correctly indicate requested thread.
Watchpoints are not supported yet.

This patch fixes at least multithreaded register tests.


https://reviews.llvm.org/D89413

Files:
  lldb/source/Plugins/Process/FreeBSDRemote/NativeProcessFreeBSD.cpp
  lldb/source/Plugins/Process/FreeBSDRemote/NativeProcessFreeBSD.h
  lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD.cpp
  lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD.h
  
lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.cpp
  lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.cpp

Index: lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.cpp
===
--- lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.cpp
+++ lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.cpp
@@ -40,32 +40,27 @@
   m_stop_description() {}
 
 Status NativeThreadFreeBSD::Resume() {
-  Status ret = NativeProcessFreeBSD::PtraceWrapper(PT_RESUME, m_process.GetID(),
-   nullptr, GetID());
+  Status ret = NativeProcessFreeBSD::PtraceWrapper(PT_RESUME, GetID());
   if (!ret.Success())
 return ret;
-  ret = NativeProcessFreeBSD::PtraceWrapper(PT_CLEARSTEP, m_process.GetID(),
-nullptr, GetID());
+  ret = NativeProcessFreeBSD::PtraceWrapper(PT_CLEARSTEP, GetID());
   if (ret.Success())
 SetRunning();
   return ret;
 }
 
 Status NativeThreadFreeBSD::SingleStep() {
-  Status ret = NativeProcessFreeBSD::PtraceWrapper(PT_RESUME, m_process.GetID(),
-   nullptr, GetID());
+  Status ret = NativeProcessFreeBSD::PtraceWrapper(PT_RESUME, GetID());
   if (!ret.Success())
 return ret;
-  ret = NativeProcessFreeBSD::PtraceWrapper(PT_SETSTEP, m_process.GetID(),
-nullptr, GetID());
+  ret = NativeProcessFreeBSD::PtraceWrapper(PT_SETSTEP, GetID());
   if (ret.Success())
 SetStepping();
   return ret;
 }
 
 Status NativeThreadFreeBSD::Suspend() {
-  Status ret = NativeProcessFreeBSD::PtraceWrapper(
-  PT_SUSPEND, m_process.GetID(), nullptr, GetID());
+  Status ret = NativeProcessFreeBSD::PtraceWrapper(PT_SUSPEND, GetID());
   if (ret.Success())
 SetStopped();
   return ret;
Index: lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.cpp
===
--- lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.cpp
+++ lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.cpp
@@ -429,15 +429,15 @@
 Status NativeRegisterContextFreeBSD_x86_64::ReadRegisterSet(uint32_t set) {
   switch (set) {
   case GPRegSet:
-return DoRegisterSet(PT_GETREGS, &m_gpr);
+return NativeProcessFreeBSD::PtraceWrapper(PT_GETREGS, m_thread.GetID(), &m_gpr);
   case FPRegSet:
 #if defined(__x86_64__)
-return DoRegisterSet(PT_GETFPREGS, &m_fpr);
+return NativeProcessFreeBSD::PtraceWrapper(PT_GETFPREGS, m_thread.GetID(), &m_fpr);
 #else
-return DoRegisterSet(PT_GETXMMREGS, &m_fpr);
+return NativeProcessFreeBSD::PtraceWrapper(PT_GETXMMREGS, m_thread.GetID(), &m_fpr);
 #endif
   case DBRegSet:
-return DoRegisterSet(PT_GETDBREGS, &m_dbr);
+return NativeProcessFreeBSD::PtraceWrapper(PT_GETDBREGS, m_thread.GetID(), &m_dbr);
   case XSaveRegSet: {
 struct ptrace_xstate_info info;
 Status ret = NativeProcessFreeBSD::PtraceWrapper(
@@ -466,15 +466,15 @@
 Status NativeRegisterContextFreeBSD_x86_64::WriteRegisterSet(uint32_t set) {
   switch (set) {
   case GPRegSet:
-return DoRegisterSet(PT_SETREGS, &m_gpr);
+return NativeProcessFreeBSD::PtraceWrapper(PT_SETREGS, m_thread.GetID(), &m_gpr);
   case FPRegSet:
 #if defined(__x86_64__)
-return DoRegisterSet(PT_SETFPREGS, &m_fpr);
+return NativeProcessFreeBSD::PtraceWrapper(PT_SETFPREGS, m_thread.GetID(), &m_fpr);
 #else
-return DoRegisterSet(PT_SETXMMREGS, &m_fpr);
+return NativeProcessFreeBSD::PtraceWrapper(PT_SETXMMREGS, m_thread.GetID(), &m_fpr);
 #endif
   case DBRegSet:
-return DoRegisterSet(PT_SETDBREGS, &m_dbr);
+return NativeProcessFreeBSD::PtraceWrapper(PT_SETDBREGS, m_thread.GetID(), &m_dbr);
   case XSaveRegSet:
 // ReadRegisterSet() must always be called before WriteRegisterSet().
 assert(m_xsave.size() > 0);
Index: lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD.h
===
--- lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD.h
+++ lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFre

[Lldb-commits] [lldb] a1ab2b7 - [lldb] More memory allocation test fixes

2020-10-14 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2020-10-14T20:43:47+02:00
New Revision: a1ab2b773b6d78ec71edfebd2474c403cbe77977

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

LOG: [lldb] More memory allocation test fixes

XFAIL nodefaultlib.cpp on darwin - the test does not pass there

XFAIL TestGdbRemoteMemoryAllocation on windows - memory is allocated
with incorrect permissions

Added: 


Modified: 

lldb/test/API/tools/lldb-server/memory-allocation/TestGdbRemoteMemoryAllocation.py
lldb/test/Shell/Expr/nodefaultlib.cpp

Removed: 




diff  --git 
a/lldb/test/API/tools/lldb-server/memory-allocation/TestGdbRemoteMemoryAllocation.py
 
b/lldb/test/API/tools/lldb-server/memory-allocation/TestGdbRemoteMemoryAllocation.py
index 5c8e4621ce3b..954eb23f05af 100644
--- 
a/lldb/test/API/tools/lldb-server/memory-allocation/TestGdbRemoteMemoryAllocation.py
+++ 
b/lldb/test/API/tools/lldb-server/memory-allocation/TestGdbRemoteMemoryAllocation.py
@@ -46,6 +46,7 @@ def allocate(self, size, permissions):
 
 @skipIf(oslist=no_match(supported_oses))
 @skipIf(oslist=["linux"], archs=no_match(supported_linux_archs))
+@expectedFailureAll(oslist=["windows"]) # Memory allocated with incorrect 
permissions
 @llgs_test
 def test_supported(self):
 """Make sure (de)allocation works on platforms where it's supposed to
@@ -61,6 +62,7 @@ def test_supported(self):
 self.allocate(0x1100, "rwx")
 
 @skipIf(oslist=["linux"], archs=supported_linux_archs)
+@skipIf(oslist=supported_oses)
 @llgs_test
 def test_unsupported(self):
 """Make sure we get an "unsupported" error on platforms where the

diff  --git a/lldb/test/Shell/Expr/nodefaultlib.cpp 
b/lldb/test/Shell/Expr/nodefaultlib.cpp
index 1bd1b6390989..5c4f19d40efc 100644
--- a/lldb/test/Shell/Expr/nodefaultlib.cpp
+++ b/lldb/test/Shell/Expr/nodefaultlib.cpp
@@ -3,12 +3,13 @@
 
 // REQUIRES: native
 // XFAIL: system-linux && !(target-x86 || target-x86_64)
-// XFAIL: system-netbsd || system-freebsd
+// XFAIL: system-netbsd || system-freebsd || system-darwin
 
 // RUN: %build %s --nodefaultlib -o %t
 // RUN: %lldb %t -o "b main" -o run -o "p call_me(5, 6)" -o exit \
 // RUN:   | FileCheck %s
 
+// CHECK: p call_me(5, 6)
 // CHECK: (int) $0 = 30
 
 int call_me(int x, long y) { return x * y; }



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


[Lldb-commits] [PATCH] D89124: [lldb-server][linux] Add ability to allocate memory

2020-10-14 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

It looks like the windows lldb-server implementation does not support all 
permission combinations (`ConvertLldbToWinApiProtect` in 
`ProcessDebugger.cpp`). I've xfailed the test for now -- I'll try to add the 
missing bits tomorrow.

I've also messed up the decorators on one of the tests.

a1ab2b77  
should get that green again, I hope.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89124

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


[Lldb-commits] [PATCH] D89408: [trace] rename ThreadIntelPT to TraceTrace

2020-10-14 Thread walter erquinigo via Phabricator via lldb-commits
wallace updated this revision to Diff 298208.
wallace added a comment.

some cleanup


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89408

Files:
  lldb/include/lldb/Target/TraceSessionFileParser.h
  lldb/include/lldb/Target/TraceThread.h
  lldb/include/lldb/lldb-forward.h
  lldb/source/Plugins/Trace/intel-pt/CMakeLists.txt
  lldb/source/Plugins/Trace/intel-pt/ThreadIntelPT.cpp
  lldb/source/Plugins/Trace/intel-pt/ThreadIntelPT.h
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.h
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPTSessionFileParser.cpp
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPTSessionFileParser.h
  lldb/source/Target/CMakeLists.txt
  lldb/source/Target/TraceSessionFileParser.cpp
  lldb/source/Target/TraceThread.cpp

Index: lldb/source/Target/TraceThread.cpp
===
--- lldb/source/Target/TraceThread.cpp
+++ lldb/source/Target/TraceThread.cpp
@@ -1,4 +1,4 @@
-//===-- ThreadIntelPT.cpp -===//
+//===-- TraceThread.cpp ---===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,7 +6,7 @@
 //
 //===--===//
 
-#include "ThreadIntelPT.h"
+#include "lldb/Target/TraceThread.h"
 
 #include 
 
@@ -16,11 +16,10 @@
 
 using namespace lldb;
 using namespace lldb_private;
-using namespace lldb_private::trace_intel_pt;
 
-void ThreadIntelPT::RefreshStateAfterStop() {}
+void TraceThread::RefreshStateAfterStop() {}
 
-RegisterContextSP ThreadIntelPT::GetRegisterContext() {
+RegisterContextSP TraceThread::GetRegisterContext() {
   if (!m_reg_context_sp)
 m_reg_context_sp = CreateRegisterContextForFrame(nullptr);
 
@@ -28,11 +27,13 @@
 }
 
 RegisterContextSP
-ThreadIntelPT::CreateRegisterContextForFrame(StackFrame *frame) {
+TraceThread::CreateRegisterContextForFrame(StackFrame *frame) {
   // Eventually this will calculate the register context based on the current
   // trace position.
   return std::make_shared(
   *this, 0, GetProcess()->GetAddressByteSize(), LLDB_INVALID_ADDRESS);
 }
 
-bool ThreadIntelPT::CalculateStopInfo() { return false; }
+bool TraceThread::CalculateStopInfo() { return false; }
+
+const FileSpec &TraceThread::GetTraceFile() const { return m_trace_file; }
Index: lldb/source/Target/TraceSessionFileParser.cpp
===
--- lldb/source/Target/TraceSessionFileParser.cpp
+++ lldb/source/Target/TraceSessionFileParser.cpp
@@ -10,8 +10,11 @@
 
 #include 
 
+#include "lldb/Core/Debugger.h"
 #include "lldb/Core/Module.h"
+#include "lldb/Target/Process.h"
 #include "lldb/Target/Target.h"
+#include "lldb/Target/TraceThread.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -34,7 +37,6 @@
   ModuleSpec module_spec;
   module_spec.GetFileSpec() = local_file_spec;
   module_spec.GetPlatformFileSpec() = system_file_spec;
-  module_spec.SetObjectOffset(module.load_address.value);
 
   if (module.uuid.hasValue())
 module_spec.GetUUID().SetFromStringRef(*module.uuid);
@@ -42,7 +44,14 @@
   Status error;
   ModuleSP module_sp =
   target_sp->GetOrCreateModule(module_spec, /*notify*/ false, &error);
-  return error.ToError();
+
+  if (error.Fail())
+return error.ToError();
+
+  bool load_addr_changed = false;
+  module_sp->SetLoadAddress(*target_sp, module.load_address.value, false,
+load_addr_changed);
+  return llvm::Error::success();
 }
 
 Error TraceSessionFileParser::CreateJSONError(json::Path::Root &root,
@@ -87,6 +96,80 @@
   return schema_builder.str();
 }
 
+TraceThreadSP TraceSessionFileParser::ParseThread(ProcessSP &process_sp,
+  const JSONThread &thread) {
+  lldb::tid_t tid = static_cast(thread.tid);
+
+  FileSpec trace_file(thread.trace_file);
+  NormalizePath(trace_file);
+
+  TraceThreadSP thread_sp =
+  std::make_shared(*process_sp, tid, trace_file);
+  process_sp->GetThreadList().AddThread(thread_sp);
+  return thread_sp;
+}
+
+Expected
+TraceSessionFileParser::ParseProcess(const JSONProcess &process) {
+  TargetSP target_sp;
+  Status error = m_debugger.GetTargetList().CreateTarget(
+  m_debugger, /*user_exe_path*/ StringRef(), process.triple,
+  eLoadDependentsNo,
+  /*platform_options*/ nullptr, target_sp);
+
+  if (!target_sp)
+return error.ToError();
+
+  ParsedProcess parsed_process;
+  parsed_process.target_sp = target_sp;
+
+  m_debugger.GetTargetList().SetSelectedTarget(target_sp.get());
+
+  ProcessSP process_sp(target_sp->CreateProcess(
+  /*listener*/ nullptr, "trace",
+  /*crash_file*/ nullptr));
+  process_sp->SetID(stat

[Lldb-commits] [PATCH] D89358: Add an API to get an SBBreakpoint's owning SBTarget

2020-10-14 Thread Jim Ingham via Phabricator via lldb-commits
jingham updated this revision to Diff 298210.
jingham added a comment.

Use lldb-instr instead of hand-generating the reproducer wrappers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89358

Files:
  lldb/bindings/interface/SBBreakpoint.i
  lldb/include/lldb/API/SBBreakpoint.h
  lldb/source/API/SBBreakpoint.cpp
  lldb/test/API/python_api/breakpoint/TestBreakpointAPI.py


Index: lldb/test/API/python_api/breakpoint/TestBreakpointAPI.py
===
--- lldb/test/API/python_api/breakpoint/TestBreakpointAPI.py
+++ lldb/test/API/python_api/breakpoint/TestBreakpointAPI.py
@@ -66,6 +66,9 @@
 location = breakpoint.GetLocationAtIndex(0)
 self.assertTrue(location.IsValid())
 
+# Make sure the breakpoint's target is right:
+self.assertEqual(target, breakpoint.GetTarget(), "Breakpoint reports 
its target correctly")
+
 self.assertTrue(self.dbg.DeleteTarget(target))
 self.assertFalse(breakpoint.IsValid())
 self.assertFalse(location.IsValid())
Index: lldb/source/API/SBBreakpoint.cpp
===
--- lldb/source/API/SBBreakpoint.cpp
+++ lldb/source/API/SBBreakpoint.cpp
@@ -81,6 +81,16 @@
   return m_opaque_wp.lock() != rhs.m_opaque_wp.lock();
 }
 
+SBTarget SBBreakpoint::GetTarget() const {
+  LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBTarget, SBBreakpoint, GetTarget);
+
+  BreakpointSP bkpt_sp = GetSP();
+  if (bkpt_sp)
+return LLDB_RECORD_RESULT(SBTarget(bkpt_sp->GetTargetSP()));
+
+  return LLDB_RECORD_RESULT(SBTarget());
+}
+
 break_id_t SBBreakpoint::GetID() const {
   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::break_id_t, SBBreakpoint, GetID);
 
@@ -987,6 +997,7 @@
SBBreakpoint, operator==,(const lldb::SBBreakpoint &));
   LLDB_REGISTER_METHOD(bool,
SBBreakpoint, operator!=,(const lldb::SBBreakpoint &));
+  LLDB_REGISTER_METHOD_CONST(lldb::SBTarget, SBBreakpoint, GetTarget, ());
   LLDB_REGISTER_METHOD_CONST(lldb::break_id_t, SBBreakpoint, GetID, ());
   LLDB_REGISTER_METHOD_CONST(bool, SBBreakpoint, IsValid, ());
   LLDB_REGISTER_METHOD_CONST(bool, SBBreakpoint, operator bool, ());
Index: lldb/include/lldb/API/SBBreakpoint.h
===
--- lldb/include/lldb/API/SBBreakpoint.h
+++ lldb/include/lldb/API/SBBreakpoint.h
@@ -42,6 +42,8 @@
 
   void ClearAllBreakpointSites();
 
+  lldb::SBTarget GetTarget() const;
+
   lldb::SBBreakpointLocation FindLocationByAddress(lldb::addr_t vm_addr);
 
   lldb::break_id_t FindLocationIDByAddress(lldb::addr_t vm_addr);
Index: lldb/bindings/interface/SBBreakpoint.i
===
--- lldb/bindings/interface/SBBreakpoint.i
+++ lldb/bindings/interface/SBBreakpoint.i
@@ -100,6 +100,9 @@
 void
 ClearAllBreakpointSites ();
 
+lldb::SBTarget
+GetTarget() const;
+  
 lldb::SBBreakpointLocation
 FindLocationByAddress (lldb::addr_t vm_addr);
 


Index: lldb/test/API/python_api/breakpoint/TestBreakpointAPI.py
===
--- lldb/test/API/python_api/breakpoint/TestBreakpointAPI.py
+++ lldb/test/API/python_api/breakpoint/TestBreakpointAPI.py
@@ -66,6 +66,9 @@
 location = breakpoint.GetLocationAtIndex(0)
 self.assertTrue(location.IsValid())
 
+# Make sure the breakpoint's target is right:
+self.assertEqual(target, breakpoint.GetTarget(), "Breakpoint reports its target correctly")
+
 self.assertTrue(self.dbg.DeleteTarget(target))
 self.assertFalse(breakpoint.IsValid())
 self.assertFalse(location.IsValid())
Index: lldb/source/API/SBBreakpoint.cpp
===
--- lldb/source/API/SBBreakpoint.cpp
+++ lldb/source/API/SBBreakpoint.cpp
@@ -81,6 +81,16 @@
   return m_opaque_wp.lock() != rhs.m_opaque_wp.lock();
 }
 
+SBTarget SBBreakpoint::GetTarget() const {
+  LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBTarget, SBBreakpoint, GetTarget);
+
+  BreakpointSP bkpt_sp = GetSP();
+  if (bkpt_sp)
+return LLDB_RECORD_RESULT(SBTarget(bkpt_sp->GetTargetSP()));
+
+  return LLDB_RECORD_RESULT(SBTarget());
+}
+
 break_id_t SBBreakpoint::GetID() const {
   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::break_id_t, SBBreakpoint, GetID);
 
@@ -987,6 +997,7 @@
SBBreakpoint, operator==,(const lldb::SBBreakpoint &));
   LLDB_REGISTER_METHOD(bool,
SBBreakpoint, operator!=,(const lldb::SBBreakpoint &));
+  LLDB_REGISTER_METHOD_CONST(lldb::SBTarget, SBBreakpoint, GetTarget, ());
   LLDB_REGISTER_METHOD_CONST(lldb::break_id_t, SBBreakpoint, GetID, ());
   LLDB_REGISTER_METHOD_CONST(bool, SBBreakpoint, IsValid, ());
   LLDB_REGISTER_METHOD_CONST(bool, SBBreakpoint, operator bool,

[Lldb-commits] [PATCH] D89408: [trace] rename ThreadIntelPT to TraceThread

2020-10-14 Thread walter erquinigo via Phabricator via lldb-commits
wallace updated this revision to Diff 298211.
wallace added a comment.

nits


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89408

Files:
  lldb/include/lldb/Target/TraceSessionFileParser.h
  lldb/include/lldb/Target/TraceThread.h
  lldb/include/lldb/lldb-forward.h
  lldb/source/Plugins/Trace/intel-pt/CMakeLists.txt
  lldb/source/Plugins/Trace/intel-pt/ThreadIntelPT.cpp
  lldb/source/Plugins/Trace/intel-pt/ThreadIntelPT.h
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.h
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPTSessionFileParser.cpp
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPTSessionFileParser.h
  lldb/source/Target/CMakeLists.txt
  lldb/source/Target/TraceSessionFileParser.cpp
  lldb/source/Target/TraceThread.cpp

Index: lldb/source/Target/TraceThread.cpp
===
--- lldb/source/Target/TraceThread.cpp
+++ lldb/source/Target/TraceThread.cpp
@@ -1,4 +1,4 @@
-//===-- ThreadIntelPT.cpp -===//
+//===-- TraceThread.cpp ---===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,7 +6,7 @@
 //
 //===--===//
 
-#include "ThreadIntelPT.h"
+#include "lldb/Target/TraceThread.h"
 
 #include 
 
@@ -16,11 +16,10 @@
 
 using namespace lldb;
 using namespace lldb_private;
-using namespace lldb_private::trace_intel_pt;
 
-void ThreadIntelPT::RefreshStateAfterStop() {}
+void TraceThread::RefreshStateAfterStop() {}
 
-RegisterContextSP ThreadIntelPT::GetRegisterContext() {
+RegisterContextSP TraceThread::GetRegisterContext() {
   if (!m_reg_context_sp)
 m_reg_context_sp = CreateRegisterContextForFrame(nullptr);
 
@@ -28,11 +27,13 @@
 }
 
 RegisterContextSP
-ThreadIntelPT::CreateRegisterContextForFrame(StackFrame *frame) {
+TraceThread::CreateRegisterContextForFrame(StackFrame *frame) {
   // Eventually this will calculate the register context based on the current
   // trace position.
   return std::make_shared(
   *this, 0, GetProcess()->GetAddressByteSize(), LLDB_INVALID_ADDRESS);
 }
 
-bool ThreadIntelPT::CalculateStopInfo() { return false; }
+bool TraceThread::CalculateStopInfo() { return false; }
+
+const FileSpec &TraceThread::GetTraceFile() const { return m_trace_file; }
Index: lldb/source/Target/TraceSessionFileParser.cpp
===
--- lldb/source/Target/TraceSessionFileParser.cpp
+++ lldb/source/Target/TraceSessionFileParser.cpp
@@ -10,8 +10,11 @@
 
 #include 
 
+#include "lldb/Core/Debugger.h"
 #include "lldb/Core/Module.h"
+#include "lldb/Target/Process.h"
 #include "lldb/Target/Target.h"
+#include "lldb/Target/TraceThread.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -87,6 +90,80 @@
   return schema_builder.str();
 }
 
+TraceThreadSP TraceSessionFileParser::ParseThread(ProcessSP &process_sp,
+  const JSONThread &thread) {
+  lldb::tid_t tid = static_cast(thread.tid);
+
+  FileSpec trace_file(thread.trace_file);
+  NormalizePath(trace_file);
+
+  TraceThreadSP thread_sp =
+  std::make_shared(*process_sp, tid, trace_file);
+  process_sp->GetThreadList().AddThread(thread_sp);
+  return thread_sp;
+}
+
+Expected
+TraceSessionFileParser::ParseProcess(const JSONProcess &process) {
+  TargetSP target_sp;
+  Status error = m_debugger.GetTargetList().CreateTarget(
+  m_debugger, /*user_exe_path*/ StringRef(), process.triple,
+  eLoadDependentsNo,
+  /*platform_options*/ nullptr, target_sp);
+
+  if (!target_sp)
+return error.ToError();
+
+  ParsedProcess parsed_process;
+  parsed_process.target_sp = target_sp;
+
+  m_debugger.GetTargetList().SetSelectedTarget(target_sp.get());
+
+  ProcessSP process_sp(target_sp->CreateProcess(
+  /*listener*/ nullptr, "trace",
+  /*crash_file*/ nullptr));
+  process_sp->SetID(static_cast(process.pid));
+
+  for (const JSONThread &thread : process.threads)
+parsed_process.threads.push_back(ParseThread(process_sp, thread));
+
+  for (const JSONModule &module : process.modules)
+if (Error err = ParseModule(target_sp, module))
+  return std::move(err);
+
+  if (!process.threads.empty())
+process_sp->GetThreadList().SetSelectedThreadByIndexID(0);
+
+  // We invoke DidAttach to create a correct stopped state for the process and
+  // its threads.
+  ArchSpec process_arch;
+  process_sp->DidAttach(process_arch);
+
+  return parsed_process;
+}
+
+Expected>
+TraceSessionFileParser::ParseProcesses(
+const std::vector &processes) {
+  std::vector parsed_processes;
+
+  auto onError = [&]() {
+// Delete all targets that were created so far in case 

[Lldb-commits] [PATCH] D89413: [lldb] [Process/FreeBSDRemote] Initial multithreading support

2020-10-14 Thread Michał Górny via Phabricator via lldb-commits
mgorny updated this revision to Diff 298226.
mgorny added a comment.

Forgot to run `clang-format`.


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

https://reviews.llvm.org/D89413

Files:
  lldb/source/Plugins/Process/FreeBSDRemote/NativeProcessFreeBSD.cpp
  lldb/source/Plugins/Process/FreeBSDRemote/NativeProcessFreeBSD.h
  lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD.cpp
  lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD.h
  
lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.cpp
  lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.cpp

Index: lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.cpp
===
--- lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.cpp
+++ lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.cpp
@@ -40,32 +40,27 @@
   m_stop_description() {}
 
 Status NativeThreadFreeBSD::Resume() {
-  Status ret = NativeProcessFreeBSD::PtraceWrapper(PT_RESUME, m_process.GetID(),
-   nullptr, GetID());
+  Status ret = NativeProcessFreeBSD::PtraceWrapper(PT_RESUME, GetID());
   if (!ret.Success())
 return ret;
-  ret = NativeProcessFreeBSD::PtraceWrapper(PT_CLEARSTEP, m_process.GetID(),
-nullptr, GetID());
+  ret = NativeProcessFreeBSD::PtraceWrapper(PT_CLEARSTEP, GetID());
   if (ret.Success())
 SetRunning();
   return ret;
 }
 
 Status NativeThreadFreeBSD::SingleStep() {
-  Status ret = NativeProcessFreeBSD::PtraceWrapper(PT_RESUME, m_process.GetID(),
-   nullptr, GetID());
+  Status ret = NativeProcessFreeBSD::PtraceWrapper(PT_RESUME, GetID());
   if (!ret.Success())
 return ret;
-  ret = NativeProcessFreeBSD::PtraceWrapper(PT_SETSTEP, m_process.GetID(),
-nullptr, GetID());
+  ret = NativeProcessFreeBSD::PtraceWrapper(PT_SETSTEP, GetID());
   if (ret.Success())
 SetStepping();
   return ret;
 }
 
 Status NativeThreadFreeBSD::Suspend() {
-  Status ret = NativeProcessFreeBSD::PtraceWrapper(
-  PT_SUSPEND, m_process.GetID(), nullptr, GetID());
+  Status ret = NativeProcessFreeBSD::PtraceWrapper(PT_SUSPEND, GetID());
   if (ret.Success())
 SetStopped();
   return ret;
Index: lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.cpp
===
--- lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.cpp
+++ lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_x86_64.cpp
@@ -429,15 +429,19 @@
 Status NativeRegisterContextFreeBSD_x86_64::ReadRegisterSet(uint32_t set) {
   switch (set) {
   case GPRegSet:
-return DoRegisterSet(PT_GETREGS, &m_gpr);
+return NativeProcessFreeBSD::PtraceWrapper(PT_GETREGS, m_thread.GetID(),
+   &m_gpr);
   case FPRegSet:
 #if defined(__x86_64__)
-return DoRegisterSet(PT_GETFPREGS, &m_fpr);
+return NativeProcessFreeBSD::PtraceWrapper(PT_GETFPREGS, m_thread.GetID(),
+   &m_fpr);
 #else
-return DoRegisterSet(PT_GETXMMREGS, &m_fpr);
+return NativeProcessFreeBSD::PtraceWrapper(PT_GETXMMREGS, m_thread.GetID(),
+   &m_fpr);
 #endif
   case DBRegSet:
-return DoRegisterSet(PT_GETDBREGS, &m_dbr);
+return NativeProcessFreeBSD::PtraceWrapper(PT_GETDBREGS, m_thread.GetID(),
+   &m_dbr);
   case XSaveRegSet: {
 struct ptrace_xstate_info info;
 Status ret = NativeProcessFreeBSD::PtraceWrapper(
@@ -466,15 +470,19 @@
 Status NativeRegisterContextFreeBSD_x86_64::WriteRegisterSet(uint32_t set) {
   switch (set) {
   case GPRegSet:
-return DoRegisterSet(PT_SETREGS, &m_gpr);
+return NativeProcessFreeBSD::PtraceWrapper(PT_SETREGS, m_thread.GetID(),
+   &m_gpr);
   case FPRegSet:
 #if defined(__x86_64__)
-return DoRegisterSet(PT_SETFPREGS, &m_fpr);
+return NativeProcessFreeBSD::PtraceWrapper(PT_SETFPREGS, m_thread.GetID(),
+   &m_fpr);
 #else
-return DoRegisterSet(PT_SETXMMREGS, &m_fpr);
+return NativeProcessFreeBSD::PtraceWrapper(PT_SETXMMREGS, m_thread.GetID(),
+   &m_fpr);
 #endif
   case DBRegSet:
-return DoRegisterSet(PT_SETDBREGS, &m_dbr);
+return NativeProcessFreeBSD::PtraceWrapper(PT_SETDBREGS, m_thread.GetID(),
+   &m_dbr);
   case XSaveRegSet:
 // ReadRegisterSet() must always be called before WriteRegisterSet().
 assert(m_xsave.size() > 0);
Index: lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD.h
=

[Lldb-commits] [PATCH] D89155: [lldb] Minidump: check for .text hash match with directory

2020-10-14 Thread Greg Clayton via Phabricator via lldb-commits
clayborg accepted this revision.
clayborg added a comment.
This revision is now accepted and ready to land.

Sorry for the delay, I was out of town until today. Changes look good! Always 
good to have more robust support for finding binaries in the sysroot.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89155

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


[Lldb-commits] [PATCH] D89428: Add support for more OS types to AddClangModuleCompilationOptionsForSDKType()

2020-10-14 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl created this revision.
aprantl added reviewers: JDevlieghere, teemperor.
aprantl requested review of this revision.

[This is upstreaming an Apple Silicon support patch rdar://problem/66927829]

This patch also avoids hardcoding the clang options, which makes it less likely 
for them to become out-of-date.

  

rdar://problem/63791367


https://reviews.llvm.org/D89428

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
@@ -1521,25 +1521,20 @@
 
   StreamString minimum_version_option;
   bool use_current_os_version = false;
+  // If the SDK type is for the host OS, use its version number.
+  auto get_host_os = []() { return HostInfo::GetTargetTriple().getOS(); };
   switch (sdk_type) {
+  case XcodeSDK::Type::MacOSX:
+use_current_os_version = get_host_os() == llvm::Triple::MacOSX;
+break;
   case XcodeSDK::Type::iPhoneOS:
-#if defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
-use_current_os_version = true;
-#else
-use_current_os_version = false;
-#endif
+use_current_os_version = get_host_os() == llvm::Triple::IOS;
 break;
-
-  case XcodeSDK::Type::iPhoneSimulator:
-use_current_os_version = false;
+  case XcodeSDK::Type::AppleTVOS:
+use_current_os_version = get_host_os() == llvm::Triple::TvOS;
 break;
-
-  case XcodeSDK::Type::MacOSX:
-#if defined(__i386__) || defined(__x86_64__)
-use_current_os_version = true;
-#else
-use_current_os_version = false;
-#endif
+  case XcodeSDK::Type::watchOS:
+use_current_os_version = get_host_os() == llvm::Triple::WatchOS;
 break;
   default:
 break;
@@ -1559,31 +1554,40 @@
 }
   }
   // Only add the version-min options if we got a version from somewhere
-  if (!version.empty()) {
+  if (!version.empty() && sdk_type != XcodeSDK::Type::Linux) {
+#define OPTION(PREFIX, NAME, VAR, ...) const char *opt_##VAR = NAME;
+#include "clang/Driver/Options.inc"
+#undef OPTION
+minimum_version_option.PutCString("-");
 switch (sdk_type) {
-case XcodeSDK::Type::iPhoneOS:
-  minimum_version_option.PutCString("-mios-version-min=");
-  minimum_version_option.PutCString(version.getAsString());
+case XcodeSDK::Type::MacOSX:
+  minimum_version_option.PutCString(opt_mmacosx_version_min_EQ);
   break;
 case XcodeSDK::Type::iPhoneSimulator:
-  minimum_version_option.PutCString("-mios-simulator-version-min=");
-  minimum_version_option.PutCString(version.getAsString());
+  minimum_version_option.PutCString(opt_mios_simulator_version_min_EQ);
   break;
-case XcodeSDK::Type::MacOSX:
-  minimum_version_option.PutCString("-mmacosx-version-min=");
-  minimum_version_option.PutCString(version.getAsString());
+case XcodeSDK::Type::iPhoneOS:
+  minimum_version_option.PutCString(opt_mios_version_min_EQ);
+  break;
+case XcodeSDK::Type::AppleTVSimulator:
+  minimum_version_option.PutCString(opt_mtvos_simulator_version_min_EQ);
+  break;
+case XcodeSDK::Type::AppleTVOS:
+  minimum_version_option.PutCString(opt_mtvos_simulator_version_min_EQ);
   break;
 case XcodeSDK::Type::WatchSimulator:
-  minimum_version_option.PutCString("-mwatchos-simulator-version-min=");
-  minimum_version_option.PutCString(version.getAsString());
+  minimum_version_option.PutCString(opt_mwatchos_simulator_version_min_EQ);
   break;
-case XcodeSDK::Type::AppleTVSimulator:
-  minimum_version_option.PutCString("-mtvos-version-min=");
-  minimum_version_option.PutCString(version.getAsString());
+case XcodeSDK::Type::watchOS:
+  minimum_version_option.PutCString(opt_mwatchos_version_min_EQ);
   break;
-default:
+case XcodeSDK::Type::bridgeOS:
+  minimum_version_option.PutCString(opt_mwatchos_version_min_EQ);
+  break;
+case XcodeSDK::Type::Linux:
   llvm_unreachable("unsupported sdk");
 }
+minimum_version_option.PutCString(version.getAsString());
 options.push_back(std::string(minimum_version_option.GetString()));
   }
 


Index: lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
===
--- lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -1521,25 +1521,20 @@
 
   StreamString minimum_version_option;
   bool use_current_os_version = false;
+  // If the SDK type is for the host OS, use its version number.
+  auto get_host_os = []() { return HostInfo::GetTargetTriple().getOS(); };
   switch (sdk_type) {
+  case XcodeSDK::Type::MacOSX:
+use_current_os_version = get_host_os() == llvm::Triple::MacOSX;
+break;
   case XcodeSDK::Type::iPhoneOS:
-#if defined(__arm__) || defined(__arm64__) || 

[Lldb-commits] [PATCH] D89283: [trace][intel-pt] Implement the basic decoding functionality

2020-10-14 Thread walter erquinigo via Phabricator via lldb-commits
wallace updated this revision to Diff 298253.
wallace added a comment.

- Moved the non intel-pt changes to D89408 
- Added some more complex tests:
  - A multifile case in which even the dynamic linker code is decoded
  - A variation of that case that doesn't declare the dynamic linker in the 
json file, which results in a trace with a missing block of instructions, but 
still is able to decode main.cpp
- Some general cleanup


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89283

Files:
  lldb/include/lldb/Target/Trace.h
  lldb/source/Plugins/Process/Trace/ProcessTrace.cpp
  lldb/source/Plugins/Process/Trace/ProcessTrace.h
  lldb/source/Plugins/Trace/intel-pt/CMakeLists.txt
  lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
  lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
  lldb/source/Plugins/Trace/intel-pt/IntelPTDecoder.cpp
  lldb/source/Plugins/Trace/intel-pt/IntelPTDecoder.h
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.h
  lldb/source/Target/Trace.cpp
  lldb/source/Target/TraceSessionFileParser.cpp
  lldb/test/API/commands/trace/TestTraceDumpInstructions.py
  lldb/test/API/commands/trace/intelpt-trace-multi-file/a.out
  lldb/test/API/commands/trace/intelpt-trace-multi-file/bar.cpp
  lldb/test/API/commands/trace/intelpt-trace-multi-file/bar.h
  lldb/test/API/commands/trace/intelpt-trace-multi-file/foo.cpp
  lldb/test/API/commands/trace/intelpt-trace-multi-file/foo.h
  lldb/test/API/commands/trace/intelpt-trace-multi-file/ld-2.17.so
  lldb/test/API/commands/trace/intelpt-trace-multi-file/libbar.so
  lldb/test/API/commands/trace/intelpt-trace-multi-file/libfoo.so
  lldb/test/API/commands/trace/intelpt-trace-multi-file/main.cpp
  lldb/test/API/commands/trace/intelpt-trace-multi-file/multi-file-no-ld.json
  lldb/test/API/commands/trace/intelpt-trace-multi-file/multi-file.json
  lldb/test/API/commands/trace/intelpt-trace-multi-file/multi-file.trace
  lldb/test/API/commands/trace/intelpt-trace/trace_bad_image.json
  lldb/test/API/commands/trace/intelpt-trace/trace_wrong_cpu.json
  lldb/tools/intel-features/intel-pt/Decoder.cpp

Index: lldb/tools/intel-features/intel-pt/Decoder.cpp
===
--- lldb/tools/intel-features/intel-pt/Decoder.cpp
+++ lldb/tools/intel-features/intel-pt/Decoder.cpp
@@ -248,6 +248,8 @@
   }
 }
 
+#include 
+
 void Decoder::ReadTraceDataAndImageInfo(lldb::SBProcess &sbprocess,
 lldb::tid_t tid, lldb::SBError &sberror,
 ThreadTraceInfo &threadTraceInfo) {
@@ -255,6 +257,7 @@
   // for the first time in class
   lldb::SBTrace &trace = threadTraceInfo.GetUniqueTraceInstance();
   Buffer &pt_buffer = threadTraceInfo.GetPTBuffer();
+
   lldb::SBError error;
   if (pt_buffer.size() == 0) {
 lldb::SBTraceOptions traceoptions;
@@ -295,6 +298,11 @@
   }
   std::fill(pt_buffer.begin() + bytes_written, pt_buffer.end(), 0);
 
+  std::ofstream of("/tmp/multi-file.trace", std::ios::binary | std::ios::out);
+  for (auto bait : pt_buffer)
+of << bait;
+  of.close();
+
   // Get information of all the modules of the inferior
   lldb::SBTarget sbtarget = sbprocess.GetTarget();
   ReadExecuteSectionInfos &readExecuteSectionInfos =
Index: lldb/test/API/commands/trace/intelpt-trace/trace_wrong_cpu.json
===
--- /dev/null
+++ lldb/test/API/commands/trace/intelpt-trace/trace_wrong_cpu.json
@@ -0,0 +1,31 @@
+{
+  "trace": {
+"type": "intel-pt",
+"pt_cpu": {
+  "vendor": "intel",
+  "family": 2123123,
+  "model": 12123123,
+  "stepping": 1231231
+}
+  },
+  "processes": [
+{
+  "pid": 1234,
+  "triple": "x86_64-*-linux",
+  "threads": [
+{
+  "tid": 3842849,
+  "traceFile": "3842849.trace"
+}
+  ],
+  "modules": [
+{
+  "file": "a.out",
+  "systemPath": "a.out",
+  "loadAddress": "0x0040",
+  "uuid": "6AA9A4E2-6F28-2F33-377D-59FECE874C71-5B41261A"
+}
+  ]
+}
+  ]
+}
Index: lldb/test/API/commands/trace/intelpt-trace/trace_bad_image.json
===
--- /dev/null
+++ lldb/test/API/commands/trace/intelpt-trace/trace_bad_image.json
@@ -0,0 +1,31 @@
+{
+  "trace": {
+"type": "intel-pt",
+"pt_cpu": {
+  "vendor": "intel",
+  "family": 6,
+  "model": 79,
+  "stepping": 1
+}
+  },
+  "processes": [
+{
+  "pid": 1234,
+  "triple": "x86_64-*-linux",
+  "threads": [
+{
+  "tid": 3842849,
+  "traceFile": "3842849.trace"
+}
+  ],
+  "modules": [
+{
+  "file": "a.out",
+  "systemPath": "a.out",
+  "loadAddress": "0x00

Re: [Lldb-commits] Upcoming upgrade of LLVM buildbot

2020-10-14 Thread Vitaly Buka via lldb-commits
I switched sanitizers and two rnk@ bots back to the primary server.
http://lab.llvm.org:8011/#/waterfall?tags=sanitizer

On Tue, 13 Oct 2020 at 22:42, Vitaly Buka  wrote:

> They do on staging.
> http://lab.llvm.org:8014/#/builders/sanitizer-windows
> http://lab.llvm.org:8014/#/builders/clang-x64-windows-msvc
>
> Galina, when do you plan to push this to the primary server?
> If it's a few days, I'd rather keep bots on staging to have colors.
>
>
>
> On Tue, 13 Oct 2020 at 11:11, Reid Kleckner  wrote:
>
>> FWIW, I don't see any issues with my two bots that use buildbot annotated
>> commands:
>> http://lab.llvm.org:8011/#/builders/sanitizer-windows
>> http://lab.llvm.org:8011/#/builders/clang-x64-windows-msvc
>> The individual steps don't highlight as green or red, but that's OK for
>> now.
>>
>> On Mon, Oct 12, 2020 at 7:19 PM Galina Kistanova 
>> wrote:
>>
>>> We have a better version of AnnotatedCommand on the staging. It should
>>> be a functional equivalent of the old one.
>>> We need to stress test it well before moving to the production build bot.
>>>
>>> For that we need all sanitizer + other bots which use the
>>> AnnotatedCommand directly or indirectly moved temporarily to the staging.
>>>
>>> Please let me know when that could be arranged.
>>>
>>> Thanks
>>>
>>> Galina
>>>
>>> On Mon, Oct 12, 2020 at 11:39 AM Reid Kleckner  wrote:
>>>
 On Wed, Oct 7, 2020 at 4:32 PM Galina Kistanova via lldb-commits <
 lldb-commits@lists.llvm.org> wrote:

> They are online now -
> http://lab.llvm.org:8011/#/waterfall?tags=sanitizer
>
> AnnotatedCommand has severe design conflict with the new buildbot.
> We have changed it to be safe and still do something useful, but it
> will need more love and care.
>
> Please let me know if you have some spare time to work on porting
> AnnotatedCommand.
>

 That's unfortunate, it would've been good to know that earlier. I and
 another team member have spent a fair amount of time porting things to use
 more AnnotatedCommand steps, because it gives us the flexibility to test
 steps locally and make changes to the steps without restarting the buildbot
 master. IMO that is the Right Way to define steps: a script that you can
 run locally on a machine that satisfies the OS and dep requirements of the
 script.

 I am restarting the two bots that I am responsible for, and may need
 some help debugging further issues soon. I'll let you know.

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


Re: [Lldb-commits] Upcoming upgrade of LLVM buildbot

2020-10-14 Thread Galina Kistanova via lldb-commits
Thanks everyone!

I would like to keep the bots in the staging till Friday. And if everything
is good, then apply the changes to the production and let you move all the
green bots back there.

Thanks

Galina


On Tue, Oct 13, 2020 at 10:43 PM Vitaly Buka  wrote:

> They do on staging.
> http://lab.llvm.org:8014/#/builders/sanitizer-windows
> http://lab.llvm.org:8014/#/builders/clang-x64-windows-msvc
>
> Galina, when do you plan to push this to the primary server?
> If it's a few days, I'd rather keep bots on staging to have colors.
>
>
>
> On Tue, 13 Oct 2020 at 11:11, Reid Kleckner  wrote:
>
>> FWIW, I don't see any issues with my two bots that use buildbot annotated
>> commands:
>> http://lab.llvm.org:8011/#/builders/sanitizer-windows
>> http://lab.llvm.org:8011/#/builders/clang-x64-windows-msvc
>> The individual steps don't highlight as green or red, but that's OK for
>> now.
>>
>> On Mon, Oct 12, 2020 at 7:19 PM Galina Kistanova 
>> wrote:
>>
>>> We have a better version of AnnotatedCommand on the staging. It should
>>> be a functional equivalent of the old one.
>>> We need to stress test it well before moving to the production build bot.
>>>
>>> For that we need all sanitizer + other bots which use the
>>> AnnotatedCommand directly or indirectly moved temporarily to the staging.
>>>
>>> Please let me know when that could be arranged.
>>>
>>> Thanks
>>>
>>> Galina
>>>
>>> On Mon, Oct 12, 2020 at 11:39 AM Reid Kleckner  wrote:
>>>
 On Wed, Oct 7, 2020 at 4:32 PM Galina Kistanova via lldb-commits <
 lldb-commits@lists.llvm.org> wrote:

> They are online now -
> http://lab.llvm.org:8011/#/waterfall?tags=sanitizer
>
> AnnotatedCommand has severe design conflict with the new buildbot.
> We have changed it to be safe and still do something useful, but it
> will need more love and care.
>
> Please let me know if you have some spare time to work on porting
> AnnotatedCommand.
>

 That's unfortunate, it would've been good to know that earlier. I and
 another team member have spent a fair amount of time porting things to use
 more AnnotatedCommand steps, because it gives us the flexibility to test
 steps locally and make changes to the steps without restarting the buildbot
 master. IMO that is the Right Way to define steps: a script that you can
 run locally on a machine that satisfies the OS and dep requirements of the
 script.

 I am restarting the two bots that I am responsible for, and may need
 some help debugging further issues soon. I'll let you know.

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


[Lldb-commits] [lldb] b198568 - Fix typeo in attach failed error message.

2020-10-14 Thread Jason Molenda via lldb-commits

Author: Jason Molenda
Date: 2020-10-14T23:31:24-07:00
New Revision: b19856881c1624df8b667d672193be52dfa23846

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

LOG: Fix typeo in attach failed error message.


Added: 


Modified: 
lldb/tools/debugserver/source/RNBRemote.cpp

Removed: 




diff  --git a/lldb/tools/debugserver/source/RNBRemote.cpp 
b/lldb/tools/debugserver/source/RNBRemote.cpp
index b66cc8f583e8..aef41a5dba43 100644
--- a/lldb/tools/debugserver/source/RNBRemote.cpp
+++ b/lldb/tools/debugserver/source/RNBRemote.cpp
@@ -4052,8 +4052,8 @@ rnb_err_t RNBRemote::HandlePacket_v(const char *p) {
 if (strcmp (err_str, "unable to start the exception thread") == 0) {
   snprintf (err_str, sizeof (err_str) - 1,
 "Not allowed to attach to process.  Look in the console "
-"messages (Console.app), near the debugserver entries "
-"when the attached failed.  The subsystem that denied "
+"messages (Console.app), near the debugserver entries, "
+"when the attach failed.  The subsystem that denied "
 "the attach permission will likely have logged an "
 "informative message about why it was denied.");
   err_str[sizeof (err_str) - 1] = '\0';



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


[Lldb-commits] [PATCH] D89283: [trace][intel-pt] Implement the basic decoding functionality

2020-10-14 Thread walter erquinigo via Phabricator via lldb-commits
wallace updated this revision to Diff 298311.
wallace added a comment.

cleanup


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89283

Files:
  lldb/include/lldb/Target/Trace.h
  lldb/source/Plugins/Process/Trace/ProcessTrace.cpp
  lldb/source/Plugins/Process/Trace/ProcessTrace.h
  lldb/source/Plugins/Trace/intel-pt/CMakeLists.txt
  lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
  lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
  lldb/source/Plugins/Trace/intel-pt/IntelPTDecoder.cpp
  lldb/source/Plugins/Trace/intel-pt/IntelPTDecoder.h
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.h
  lldb/source/Target/Trace.cpp
  lldb/source/Target/TraceSessionFileParser.cpp
  lldb/test/API/commands/trace/TestTraceDumpInstructions.py
  lldb/test/API/commands/trace/intelpt-trace-multi-file/a.out
  lldb/test/API/commands/trace/intelpt-trace-multi-file/bar.cpp
  lldb/test/API/commands/trace/intelpt-trace-multi-file/bar.h
  lldb/test/API/commands/trace/intelpt-trace-multi-file/foo.cpp
  lldb/test/API/commands/trace/intelpt-trace-multi-file/foo.h
  lldb/test/API/commands/trace/intelpt-trace-multi-file/ld-2.17.so
  lldb/test/API/commands/trace/intelpt-trace-multi-file/libbar.so
  lldb/test/API/commands/trace/intelpt-trace-multi-file/libfoo.so
  lldb/test/API/commands/trace/intelpt-trace-multi-file/main.cpp
  lldb/test/API/commands/trace/intelpt-trace-multi-file/multi-file-no-ld.json
  lldb/test/API/commands/trace/intelpt-trace-multi-file/multi-file.json
  lldb/test/API/commands/trace/intelpt-trace-multi-file/multi-file.trace
  lldb/test/API/commands/trace/intelpt-trace/trace_bad_image.json
  lldb/test/API/commands/trace/intelpt-trace/trace_wrong_cpu.json
  lldb/tools/intel-features/intel-pt/Decoder.cpp

Index: lldb/tools/intel-features/intel-pt/Decoder.cpp
===
--- lldb/tools/intel-features/intel-pt/Decoder.cpp
+++ lldb/tools/intel-features/intel-pt/Decoder.cpp
@@ -248,6 +248,8 @@
   }
 }
 
+#include 
+
 void Decoder::ReadTraceDataAndImageInfo(lldb::SBProcess &sbprocess,
 lldb::tid_t tid, lldb::SBError &sberror,
 ThreadTraceInfo &threadTraceInfo) {
@@ -255,6 +257,7 @@
   // for the first time in class
   lldb::SBTrace &trace = threadTraceInfo.GetUniqueTraceInstance();
   Buffer &pt_buffer = threadTraceInfo.GetPTBuffer();
+
   lldb::SBError error;
   if (pt_buffer.size() == 0) {
 lldb::SBTraceOptions traceoptions;
@@ -295,6 +298,11 @@
   }
   std::fill(pt_buffer.begin() + bytes_written, pt_buffer.end(), 0);
 
+  std::ofstream of("/tmp/multi-file.trace", std::ios::binary | std::ios::out);
+  for (auto bait : pt_buffer)
+of << bait;
+  of.close();
+
   // Get information of all the modules of the inferior
   lldb::SBTarget sbtarget = sbprocess.GetTarget();
   ReadExecuteSectionInfos &readExecuteSectionInfos =
Index: lldb/test/API/commands/trace/intelpt-trace/trace_wrong_cpu.json
===
--- /dev/null
+++ lldb/test/API/commands/trace/intelpt-trace/trace_wrong_cpu.json
@@ -0,0 +1,31 @@
+{
+  "trace": {
+"type": "intel-pt",
+"pt_cpu": {
+  "vendor": "intel",
+  "family": 2123123,
+  "model": 12123123,
+  "stepping": 1231231
+}
+  },
+  "processes": [
+{
+  "pid": 1234,
+  "triple": "x86_64-*-linux",
+  "threads": [
+{
+  "tid": 3842849,
+  "traceFile": "3842849.trace"
+}
+  ],
+  "modules": [
+{
+  "file": "a.out",
+  "systemPath": "a.out",
+  "loadAddress": "0x0040",
+  "uuid": "6AA9A4E2-6F28-2F33-377D-59FECE874C71-5B41261A"
+}
+  ]
+}
+  ]
+}
Index: lldb/test/API/commands/trace/intelpt-trace/trace_bad_image.json
===
--- /dev/null
+++ lldb/test/API/commands/trace/intelpt-trace/trace_bad_image.json
@@ -0,0 +1,31 @@
+{
+  "trace": {
+"type": "intel-pt",
+"pt_cpu": {
+  "vendor": "intel",
+  "family": 6,
+  "model": 79,
+  "stepping": 1
+}
+  },
+  "processes": [
+{
+  "pid": 1234,
+  "triple": "x86_64-*-linux",
+  "threads": [
+{
+  "tid": 3842849,
+  "traceFile": "3842849.trace"
+}
+  ],
+  "modules": [
+{
+  "file": "a.out",
+  "systemPath": "a.out",
+  "loadAddress": "0x00F0",
+  "uuid": "6AA9A4E2-6F28-2F33-377D-59FECE874C71-5B41261A"
+}
+  ]
+}
+  ]
+}
Index: lldb/test/API/commands/trace/intelpt-trace-multi-file/multi-file.json
===
--- /dev/null
+++ lldb/test/API/commands/trace/intelpt-trace-multi-file/multi-file.json
@@ -0,0 +1,49 @@
+{
+  "trace":