[Lldb-commits] [lldb] a4a0844 - [lldb] Don't use static locals for return value storage in some *AsCString functions

2020-07-30 Thread Raphael Isemann via lldb-commits

Author: Raphael Isemann
Date: 2020-07-30T12:17:42+02:00
New Revision: a4a0844248d4a68a866b9c4e18ae89fa49a83ec0

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

LOG: [lldb] Don't use static locals for return value storage in some *AsCString 
functions

Let's just return a std::string to make this safe. formatv seemed overkill for 
formatting
the return values as they all just append an integer value to a constant string.

Reviewed By: labath

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

Added: 


Modified: 
lldb/include/lldb/Core/Communication.h
lldb/include/lldb/Target/Thread.h
lldb/source/Core/Communication.cpp
lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
lldb/source/Target/Thread.cpp
lldb/source/Target/ThreadPlanCallFunction.cpp
lldb/source/Target/ThreadPlanStepOverBreakpoint.cpp

Removed: 




diff  --git a/lldb/include/lldb/Core/Communication.h 
b/lldb/include/lldb/Core/Communication.h
index 6b65974f9522..354c4bbcc283 100644
--- a/lldb/include/lldb/Core/Communication.h
+++ b/lldb/include/lldb/Core/Communication.h
@@ -285,7 +285,7 @@ class Communication : public Broadcaster {
   ///
   void SynchronizeWithReadThread();
 
-  static const char *ConnectionStatusAsCString(lldb::ConnectionStatus status);
+  static std::string ConnectionStatusAsString(lldb::ConnectionStatus status);
 
   bool GetCloseOnEOF() const { return m_close_on_eof; }
 

diff  --git a/lldb/include/lldb/Target/Thread.h 
b/lldb/include/lldb/Target/Thread.h
index 205a0d965c63..066b8e1845c0 100644
--- a/lldb/include/lldb/Target/Thread.h
+++ b/lldb/include/lldb/Target/Thread.h
@@ -253,9 +253,9 @@ class Thread : public std::enable_shared_from_this,
 
   bool ThreadStoppedForAReason();
 
-  static const char *RunModeAsCString(lldb::RunMode mode);
+  static std::string RunModeAsString(lldb::RunMode mode);
 
-  static const char *StopReasonAsCString(lldb::StopReason reason);
+  static std::string StopReasonAsString(lldb::StopReason reason);
 
   virtual const char *GetInfo() { return nullptr; }
 

diff  --git a/lldb/source/Core/Communication.cpp 
b/lldb/source/Core/Communication.cpp
index 859f5be74b43..b50cd0ecab5c 100644
--- a/lldb/source/Core/Communication.cpp
+++ b/lldb/source/Core/Communication.cpp
@@ -339,7 +339,7 @@ lldb::thread_result_t 
Communication::ReadThread(lldb::thread_arg_t p) {
   }
   if (error.Fail())
 LLDB_LOG(log, "error: {0}, status = {1}", error,
- Communication::ConnectionStatusAsCString(status));
+ Communication::ConnectionStatusAsString(status));
   break;
 case eConnectionStatusInterrupted: // Synchronization signal from
// SynchronizeWithReadThread()
@@ -355,7 +355,7 @@ lldb::thread_result_t 
Communication::ReadThread(lldb::thread_arg_t p) {
 case eConnectionStatusTimedOut: // Request timed out
   if (error.Fail())
 LLDB_LOG(log, "error: {0}, status = {1}", error,
- Communication::ConnectionStatusAsCString(status));
+ Communication::ConnectionStatusAsString(status));
   break;
 }
   }
@@ -416,8 +416,8 @@ void 
Communication::SetConnection(std::unique_ptr connection) {
   m_connection_sp = std::move(connection);
 }
 
-const char *
-Communication::ConnectionStatusAsCString(lldb::ConnectionStatus status) {
+std::string
+Communication::ConnectionStatusAsString(lldb::ConnectionStatus status) {
   switch (status) {
   case eConnectionStatusSuccess:
 return "success";
@@ -435,8 +435,5 @@ 
Communication::ConnectionStatusAsCString(lldb::ConnectionStatus status) {
 return "interrupted";
   }
 
-  static char unknown_state_string[64];
-  snprintf(unknown_state_string, sizeof(unknown_state_string),
-   "ConnectionStatus = %i", status);
-  return unknown_state_string;
+  return "@" + std::to_string(status);
 }

diff  --git a/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp 
b/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp
index 06190d0c036d..dc283fce8104 100644
--- a/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp
+++ b/lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp
@@ -194,12 +194,11 @@ size_t 
CommunicationKDP::WaitForPacketWithTimeoutMicroSecondsNoLock(
  : std::chrono::microseconds(timeout_usec),
  status, &error);
 
-LLDB_LOGV(log, 
-  "Read (buffer, sizeof(buffer), timeout_usec = 0x{0:x}, "
-  "status = {1}, error = {2}) => bytes_read = {4}",
-  timeout_usec,
-  Communication::ConnectionStatusAsCString(status),
-  error, 

[Lldb-commits] [PATCH] D84505: [lldb] Don't use static locals for return value storage in some *AsCString functions

2020-07-30 Thread Raphael Isemann via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa4a0844248d4: [lldb] Don't use static locals for return 
value storage in some *AsCString… (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/D84505/new/

https://reviews.llvm.org/D84505

Files:
  lldb/include/lldb/Core/Communication.h
  lldb/include/lldb/Target/Thread.h
  lldb/source/Core/Communication.cpp
  lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
  lldb/source/Target/Thread.cpp
  lldb/source/Target/ThreadPlanCallFunction.cpp
  lldb/source/Target/ThreadPlanStepOverBreakpoint.cpp

Index: lldb/source/Target/ThreadPlanStepOverBreakpoint.cpp
===
--- lldb/source/Target/ThreadPlanStepOverBreakpoint.cpp
+++ lldb/source/Target/ThreadPlanStepOverBreakpoint.cpp
@@ -62,8 +62,8 @@
 StopReason reason = stop_info_sp->GetStopReason();
 
 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
-LLDB_LOGF(log, "Step over breakpoint stopped for reason: %s.",
-  Thread::StopReasonAsCString(reason));
+LLDB_LOG(log, "Step over breakpoint stopped for reason: {0}.",
+ Thread::StopReasonAsString(reason));
 
 switch (reason) {
   case eStopReasonTrace:
Index: lldb/source/Target/ThreadPlanCallFunction.cpp
===
--- lldb/source/Target/ThreadPlanCallFunction.cpp
+++ lldb/source/Target/ThreadPlanCallFunction.cpp
@@ -260,9 +260,9 @@
 stop_reason = eStopReasonNone;
   else
 stop_reason = m_real_stop_info_sp->GetStopReason();
-  LLDB_LOGF(log,
-"ThreadPlanCallFunction::PlanExplainsStop: Got stop reason - %s.",
-Thread::StopReasonAsCString(stop_reason));
+  LLDB_LOG(log,
+   "ThreadPlanCallFunction::PlanExplainsStop: Got stop reason - {0}.",
+   Thread::StopReasonAsString(stop_reason));
 
   if (stop_reason == eStopReasonBreakpoint && BreakpointsExplainStop())
 return true;
Index: lldb/source/Target/Thread.cpp
===
--- lldb/source/Target/Thread.cpp
+++ lldb/source/Target/Thread.cpp
@@ -1661,7 +1661,7 @@
   return GetStackFrameList()->GetStackFrameSPForStackFramePtr(stack_frame_ptr);
 }
 
-const char *Thread::StopReasonAsCString(lldb::StopReason reason) {
+std::string Thread::StopReasonAsString(lldb::StopReason reason) {
   switch (reason) {
   case eStopReasonInvalid:
 return "invalid";
@@ -1687,13 +1687,10 @@
 return "instrumentation break";
   }
 
-  static char unknown_state_string[64];
-  snprintf(unknown_state_string, sizeof(unknown_state_string),
-   "StopReason = %i", reason);
-  return unknown_state_string;
+  return "StopReason = " + std::to_string(reason);
 }
 
-const char *Thread::RunModeAsCString(lldb::RunMode mode) {
+std::string Thread::RunModeAsString(lldb::RunMode mode) {
   switch (mode) {
   case eOnlyThisThread:
 return "only this thread";
@@ -1703,10 +1700,7 @@
 return "only during stepping";
   }
 
-  static char unknown_state_string[64];
-  snprintf(unknown_state_string, sizeof(unknown_state_string), "RunMode = %i",
-   mode);
-  return unknown_state_string;
+  return "RunMode = " + std::to_string(mode);
 }
 
 size_t Thread::GetStatus(Stream &strm, uint32_t start_frame,
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -284,7 +284,7 @@
 LLDB_LOGV(log,
   "Read(buffer, sizeof(buffer), timeout = {0}, "
   "status = {1}, error = {2}) => bytes_read = {3}",
-  timeout, Communication::ConnectionStatusAsCString(status), error,
+  timeout, Communication::ConnectionStatusAsString(status), error,
   bytes_read);
 
 if (bytes_read > 0) {
Index: lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp
===
--- lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp
+++ lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp
@@ -194,12 +194,11 @@
  : std::chrono::microseconds(timeout_usec),
  status, &error);
 
-LLDB_LOGV(log, 
-  "Read (buffer, sizeof(buffer), timeout_usec = 0x{0:x}, "
-  "status = {1}, error = {2}) => bytes_read = {4}",
-  timeout_usec,
-  Communication::ConnectionStatusAsCString(status),
-  error, bytes_read);
+LLDB_LOGV(log,
+  "Read (buffer, 

[Lldb-commits] [PATCH] D81001: [lldb] Display autosuggestion part in gray if there is one possible suggestion

2020-07-30 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor added a comment.

I'm not hitting the same bug here, but I do hit a different bug. If I have a 
autosuggestion and then type another character that causes a shorter 
autosuggestion to display, then the old text of the autosuggestion is not 
deleted from the terminal.

For example:

  > ./build/bin/lldb -o "settings set show-autosuggestion true"
  (lldb) settings set show-autosuggestion true
  (lldb) help frame var
  [...]
  (lldb) help frame info
  [...]
  (lldb) help frame v[aro]

[ ] is the grey text.

"help frame " correctly shows "help frame var info" which is the last command, 
but typing the "v" will cause that only "help frame var" is left as a valid 
autosuggestion. However the "o" from "info" is not clear, but only the "inf" 
part ovewritten with "var".

Tbh, I'm not sure what's the best fix for this. I don't think we can clear all 
following characters in the line with some control character (correct me if I'm 
wrong). We could adding spaces into the autosuggestion string to fill the rest 
of the line though (this way the old characters in the buffer are getting 
ovewritten).


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

https://reviews.llvm.org/D81001

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


[Lldb-commits] [PATCH] D84815: [LLDB] Improve PDB discovery

2020-07-30 Thread Adrian McCarthy via Phabricator via lldb-commits
amccarth added a comment.

Thanks.  Working on a test.

I found a description of how the Windows debuggers look for PDBs, and it's 
different than what I expected:

1. The directory that contains the binary
2. The build path embedded in the binary
3. (if enabled) The symbol server cache
4. (if enabled) That symbol server

LLDB currently has only step 2.  This patch adds step 1, but it adds it as the 
_second_ step.  And that's it.  I figured it might also look locally on the 
PATH or some "well-known" locations, but nope.

(It's buried in a paragraph in this long article by John Robbins:  
https://www.wintellect.com/pdb-files-what-every-developer-must-know/)


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

https://reviews.llvm.org/D84815

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


[Lldb-commits] [lldb] b6635b5 - [lldb] Add SBCommandInterpreterRunOptions to LLDB.h

2020-07-30 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2020-07-30T08:46:19-07:00
New Revision: b6635b5b15cb1c160776493a982302a854df332e

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

LOG: [lldb] Add SBCommandInterpreterRunOptions to LLDB.h

Added: 


Modified: 
lldb/include/lldb/API/LLDB.h

Removed: 




diff  --git a/lldb/include/lldb/API/LLDB.h b/lldb/include/lldb/API/LLDB.h
index 83c38d3b6166..f7390cfabf01 100644
--- a/lldb/include/lldb/API/LLDB.h
+++ b/lldb/include/lldb/API/LLDB.h
@@ -17,6 +17,7 @@
 #include "lldb/API/SBBreakpointName.h"
 #include "lldb/API/SBBroadcaster.h"
 #include "lldb/API/SBCommandInterpreter.h"
+#include "lldb/API/SBCommandInterpreterRunOptions.h"
 #include "lldb/API/SBCommandReturnObject.h"
 #include "lldb/API/SBCommunication.h"
 #include "lldb/API/SBCompileUnit.h"



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


[Lldb-commits] [lldb] 09cb6f2 - [lldb][NFC][test] Fix comment referring to FileCheck instead of yaml2obj

2020-07-30 Thread Jordan Rupprecht via lldb-commits

Author: Jordan Rupprecht
Date: 2020-07-30T09:47:44-07:00
New Revision: 09cb6f233d3d18cb17ba00188cbc32a414ec0c82

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

LOG: [lldb][NFC][test] Fix comment referring to FileCheck instead of yaml2obj

Added: 


Modified: 
lldb/packages/Python/lldbsuite/test/lldbtest.py

Removed: 




diff  --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py 
b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 4aad2867cf8f..e4bf6eb569cf 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -1608,7 +1608,7 @@ def yaml2obj(self, yaml_path, obj_path):
 """
 yaml2obj_bin = configuration.get_yaml2obj_path()
 if not yaml2obj_bin:
-self.assertTrue(False, "No valid FileCheck executable specified")
+self.assertTrue(False, "No valid yaml2obj executable specified")
 command = [yaml2obj_bin, "-o=%s" % obj_path, yaml_path]
 system([command])
 



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


[Lldb-commits] [lldb] be198e0 - [lldb][test] Move registers-target-xml-reading target to the correct test location.

2020-07-30 Thread Jordan Rupprecht via lldb-commits

Author: Jordan Rupprecht
Date: 2020-07-30T10:28:32-07:00
New Revision: be198e03ebba264baadfd2ed383b1725633c43ea

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

LOG: [lldb][test] Move registers-target-xml-reading target to the correct test 
location.

This test was added in D74217 (and the `.categories` file later added in 
ccf1c30cde6e1e763e7c9cdd48a609a805166699) around the same time I moved the test 
tree from `lldb/packages/Python/lldbsuite/test` to `lldb/test/API` (D71151). 
Since this got lost in the move, it isn't running. (I introduced an intentional 
syntax error, and `ninja check-lldb` passes).

I moved it to the correct location, and now it runs and passes -- locally, at 
least -- as `ninja 
check-lldb-api-tools-lldb-server-registers-target-xml-reading`.

Added: 
lldb/test/API/tools/lldb-server/.categories
lldb/test/API/tools/lldb-server/registers-target-xml-reading/Makefile

lldb/test/API/tools/lldb-server/registers-target-xml-reading/TestGdbRemoteTargetXmlPacket.py
lldb/test/API/tools/lldb-server/registers-target-xml-reading/main.cpp

Modified: 


Removed: 
lldb/packages/Python/lldbsuite/test/tools/lldb-server/.categories

lldb/packages/Python/lldbsuite/test/tools/lldb-server/registers-target-xml-reading/Makefile

lldb/packages/Python/lldbsuite/test/tools/lldb-server/registers-target-xml-reading/TestGdbRemoteTargetXmlPacket.py

lldb/packages/Python/lldbsuite/test/tools/lldb-server/registers-target-xml-reading/main.cpp



diff  --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/.categories 
b/lldb/test/API/tools/lldb-server/.categories
similarity index 100%
rename from lldb/packages/Python/lldbsuite/test/tools/lldb-server/.categories
rename to lldb/test/API/tools/lldb-server/.categories

diff  --git 
a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/registers-target-xml-reading/Makefile
 b/lldb/test/API/tools/lldb-server/registers-target-xml-reading/Makefile
similarity index 100%
rename from 
lldb/packages/Python/lldbsuite/test/tools/lldb-server/registers-target-xml-reading/Makefile
rename to lldb/test/API/tools/lldb-server/registers-target-xml-reading/Makefile

diff  --git 
a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/registers-target-xml-reading/TestGdbRemoteTargetXmlPacket.py
 
b/lldb/test/API/tools/lldb-server/registers-target-xml-reading/TestGdbRemoteTargetXmlPacket.py
similarity index 99%
rename from 
lldb/packages/Python/lldbsuite/test/tools/lldb-server/registers-target-xml-reading/TestGdbRemoteTargetXmlPacket.py
rename to 
lldb/test/API/tools/lldb-server/registers-target-xml-reading/TestGdbRemoteTargetXmlPacket.py
index 530e2ce80023..51f3d3595640 100644
--- 
a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/registers-target-xml-reading/TestGdbRemoteTargetXmlPacket.py
+++ 
b/lldb/test/API/tools/lldb-server/registers-target-xml-reading/TestGdbRemoteTargetXmlPacket.py
@@ -66,4 +66,4 @@ def test_g_target_xml_returns_correct_data(self):
 self.assertEqual(q_info_reg["format"], xml_info_reg.get("format"))
 self.assertEqual(q_info_reg["bitsize"], 
xml_info_reg.get("bitsize"))
 self.assertEqual(q_info_reg["offset"], xml_info_reg.get("offset"))
-self.assertEqual(q_info_reg["encoding"], 
xml_info_reg.get("encoding"))
\ No newline at end of file
+self.assertEqual(q_info_reg["encoding"], 
xml_info_reg.get("encoding"))

diff  --git 
a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/registers-target-xml-reading/main.cpp
 b/lldb/test/API/tools/lldb-server/registers-target-xml-reading/main.cpp
similarity index 100%
rename from 
lldb/packages/Python/lldbsuite/test/tools/lldb-server/registers-target-xml-reading/main.cpp
rename to lldb/test/API/tools/lldb-server/registers-target-xml-reading/main.cpp



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


[Lldb-commits] [lldb] 41909e9 - [lldb] Add copy ctor/assignment operator to SBCommandInterpreterRunOptions

2020-07-30 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2020-07-30T10:39:30-07:00
New Revision: 41909e96824b73162431e84cbba071b1ff4f6341

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

LOG: [lldb] Add copy ctor/assignment operator to SBCommandInterpreterRunOptions

Added: 


Modified: 
lldb/include/lldb/API/SBCommandInterpreterRunOptions.h
lldb/source/API/SBCommandInterpreterRunOptions.cpp

Removed: 




diff  --git a/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h 
b/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h
index 82d6feedc02e..3c00513faaa7 100644
--- a/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h
+++ b/lldb/include/lldb/API/SBCommandInterpreterRunOptions.h
@@ -26,8 +26,12 @@ class LLDB_API SBCommandInterpreterRunOptions {
 
 public:
   SBCommandInterpreterRunOptions();
+  SBCommandInterpreterRunOptions(const SBCommandInterpreterRunOptions &rhs);
   ~SBCommandInterpreterRunOptions();
 
+  SBCommandInterpreterRunOptions &
+  operator=(const SBCommandInterpreterRunOptions &rhs);
+
   bool GetStopOnContinue() const;
 
   void SetStopOnContinue(bool);

diff  --git a/lldb/source/API/SBCommandInterpreterRunOptions.cpp 
b/lldb/source/API/SBCommandInterpreterRunOptions.cpp
index fcfbf5e5401a..da800e8b7804 100644
--- a/lldb/source/API/SBCommandInterpreterRunOptions.cpp
+++ b/lldb/source/API/SBCommandInterpreterRunOptions.cpp
@@ -24,8 +24,29 @@ 
SBCommandInterpreterRunOptions::SBCommandInterpreterRunOptions() {
   m_opaque_up = std::make_unique();
 }
 
+SBCommandInterpreterRunOptions::SBCommandInterpreterRunOptions(
+const SBCommandInterpreterRunOptions &rhs)
+: m_opaque_up() {
+  LLDB_RECORD_CONSTRUCTOR(SBCommandInterpreterRunOptions,
+  (const lldb::SBCommandInterpreterRunOptions &), rhs);
+
+  m_opaque_up = std::make_unique(rhs.ref());
+}
+
 SBCommandInterpreterRunOptions::~SBCommandInterpreterRunOptions() = default;
 
+SBCommandInterpreterRunOptions &SBCommandInterpreterRunOptions::operator=(
+const SBCommandInterpreterRunOptions &rhs) {
+  LLDB_RECORD_METHOD(lldb::SBCommandInterpreterRunOptions &,
+ SBCommandInterpreterRunOptions, operator=,
+ (const lldb::SBCommandInterpreterRunOptions &), rhs);
+
+  if (this == &rhs)
+return LLDB_RECORD_RESULT(*this);
+  *m_opaque_up = *rhs.m_opaque_up;
+  return LLDB_RECORD_RESULT(*this);
+}
+
 bool SBCommandInterpreterRunOptions::GetStopOnContinue() const {
   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreterRunOptions,
GetStopOnContinue);
@@ -190,12 +211,11 @@ 
SBCommandInterpreterRunResult::~SBCommandInterpreterRunResult() = default;
 SBCommandInterpreterRunResult &SBCommandInterpreterRunResult::operator=(
 const SBCommandInterpreterRunResult &rhs) {
   LLDB_RECORD_METHOD(lldb::SBCommandInterpreterRunResult &,
- SBCommandInterpreterRunResult,
- operator=,(const lldb::SBCommandInterpreterRunResult &),
- rhs);
+ SBCommandInterpreterRunResult, operator=,
+ (const lldb::SBCommandInterpreterRunResult &), rhs);
 
   if (this == &rhs)
-return *this;
+return LLDB_RECORD_RESULT(*this);
   *m_opaque_up = *rhs.m_opaque_up;
   return LLDB_RECORD_RESULT(*this);
 }
@@ -220,6 +240,11 @@ namespace repro {
 
 template <> void RegisterMethods(Registry &R) {
   LLDB_REGISTER_CONSTRUCTOR(SBCommandInterpreterRunOptions, ());
+  LLDB_REGISTER_CONSTRUCTOR(SBCommandInterpreterRunOptions,
+(const lldb::SBCommandInterpreterRunOptions &));
+  LLDB_REGISTER_METHOD(lldb::SBCommandInterpreterRunOptions &,
+   SBCommandInterpreterRunOptions, operator=,
+   (const lldb::SBCommandInterpreterRunOptions &));
   LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions,
  GetStopOnContinue, ());
   LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetStopOnContinue,
@@ -260,8 +285,8 @@ template <> void 
RegisterMethods(Registry &R) {
   LLDB_REGISTER_CONSTRUCTOR(SBCommandInterpreterRunResult,
 (const lldb::SBCommandInterpreterRunResult &));
   LLDB_REGISTER_METHOD(lldb::SBCommandInterpreterRunResult &,
-   SBCommandInterpreterRunResult,
-   operator=,(const lldb::SBCommandInterpreterRunResult 
&));
+   SBCommandInterpreterRunResult, operator=,
+   (const lldb::SBCommandInterpreterRunResult &));
   LLDB_REGISTER_METHOD_CONST(int, SBCommandInterpreterRunResult,
  GetNumberOfErrors, ());
   LLDB_REGISTER_METHOD_CONST(lldb::CommandInterpreterResult,



__

[Lldb-commits] [PATCH] D84954: [lldb] Make Target::CleanupProcess consistent for breakpoints and watchpoints

2020-07-30 Thread Tatyana Krasnukha via Phabricator via lldb-commits
tatyana-krasnukha created this revision.
tatyana-krasnukha added a reviewer: jingham.
tatyana-krasnukha added a project: LLDB.
Herald added subscribers: lldb-commits, JDevlieghere.
tatyana-krasnukha requested review of this revision.

Target clears watchpoints hit count but doesn't do the same for breakpoints. As 
was discussed in D84527 , this behavior should 
be unified.

Now responsibility for cleanup lies on *List symmetrically for breakpoints and 
watchpoints.

The test case verifies that hit counts are reset to 0 after killing the process.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84954

Files:
  lldb/include/lldb/Breakpoint/Breakpoint.h
  lldb/include/lldb/Breakpoint/BreakpointList.h
  lldb/include/lldb/Breakpoint/BreakpointLocation.h
  lldb/include/lldb/Breakpoint/BreakpointLocationList.h
  lldb/include/lldb/Breakpoint/WatchpointList.h
  lldb/include/lldb/Target/Target.h
  lldb/source/Breakpoint/Breakpoint.cpp
  lldb/source/Breakpoint/BreakpointList.cpp
  lldb/source/Breakpoint/BreakpointLocationList.cpp
  lldb/source/Breakpoint/WatchpointList.cpp
  lldb/source/Target/Target.cpp
  
lldb/test/API/functionalities/breakpoint/breakpoint_hit_count/TestBreakpointHitCount.py

Index: lldb/test/API/functionalities/breakpoint/breakpoint_hit_count/TestBreakpointHitCount.py
===
--- lldb/test/API/functionalities/breakpoint/breakpoint_hit_count/TestBreakpointHitCount.py
+++ lldb/test/API/functionalities/breakpoint/breakpoint_hit_count/TestBreakpointHitCount.py
@@ -19,15 +19,32 @@
 def test_breakpoint_location_hit_count(self):
 """Use Python APIs to check breakpoint hit count."""
 self.build()
-self.do_test_breakpoint_location_hit_count()
+target = self.create_target()
+breakpoint = self.create_breakpoint(target)
+process = self.launch_process(target)
+self.do_test_breakpoint_location_hit_count(process, breakpoint)
+
+def test_breakpoint_hit_count_cleanup(self):
+"""Use Python APIs to check that breakpoint hit count is cleared
+   as well as locations hit counts when process dies."""
+self.build()
+target = self.create_target()
+breakpoint = self.create_breakpoint(target)
+process = self.launch_process(target)
+self.do_test_breakpoint_location_hit_count(process, breakpoint)
+
+# Kill the process and launch a new one.
+status = process.Kill()
+self.assertTrue(status, "The process was killed.")
+new_process = self.launch_process(target)
+
+# Test hit location of the existing breakpoint. It should be like we didn't have hits before.
+self.do_test_breakpoint_location_hit_count(new_process, breakpoint)
 
 def test_breakpoint_one_shot(self):
 """Check that one-shot breakpoints trigger only once."""
 self.build()
-
-exe = self.getBuildArtifact("a.out")
-target = self.dbg.CreateTarget(exe)
-self.assertTrue(target, VALID_TARGET)
+target = self.create_target()
 
 self.runCmd("tb a")
 process = target.LaunchSimple(
@@ -54,13 +71,14 @@
 self.a_float_body_line_no = line_number(
 'main.cpp', '// Breakpoint Location 2')
 
-def do_test_breakpoint_location_hit_count(self):
-"""Use Python APIs to check breakpoint hit count."""
+def create_target(self):
 exe = self.getBuildArtifact("a.out")
 
 target = self.dbg.CreateTarget(exe)
 self.assertTrue(target, VALID_TARGET)
+return target
 
+def create_breakpoint(self, target):
 # Create a breakpoint in main.cpp by name 'a',
 # there should be two locations.
 breakpoint = target.BreakpointCreateByName('a', 'a.out')
@@ -79,11 +97,19 @@
 location2.IsEnabled(),
 VALID_BREAKPOINT_LOCATION)
 
+return breakpoint
+
+def launch_process(self, target):
 # Launch the process, and do not stop at entry point.
 process = target.LaunchSimple(
 None, None, self.get_process_working_directory())
 self.assertTrue(process, PROCESS_IS_VALID)
 
+return process
+
+def do_test_breakpoint_location_hit_count(self, process, breakpoint):
+"""Use Python APIs to check breakpoint hit count."""
+
 # Verify 1st breakpoint location is hit.
 from lldbsuite.test.lldbutil import get_stopped_thread
 thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
@@ -129,5 +155,3 @@
 self.assertEqual(location2.GetHitCount(), 2)
 self.assertEqual(location1.GetHitCount(), 1)
 self.assertEqual(breakpoint.GetHitCount(), 3)
-
-process.Continue()
Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@

[Lldb-commits] [PATCH] D84957: [lldb/Process/Windows] Trying to kill exited/detached process in not error

2020-07-30 Thread Tatyana Krasnukha via Phabricator via lldb-commits
tatyana-krasnukha created this revision.
tatyana-krasnukha added a reviewer: asmith.
tatyana-krasnukha added a project: LLDB.
Herald added subscribers: lldb-commits, JDevlieghere.
tatyana-krasnukha requested review of this revision.

Don't report an error, just log this happened.
This fixes a lot of "CLEANUP ERROR"s for the test-suite on Windows and makes 
ProcessWindows consistent with the other processes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84957

Files:
  lldb/source/Plugins/Process/Windows/Common/ProcessDebugger.cpp


Index: lldb/source/Plugins/Process/Windows/Common/ProcessDebugger.cpp
===
--- lldb/source/Plugins/Process/Windows/Common/ProcessDebugger.cpp
+++ lldb/source/Plugins/Process/Windows/Common/ProcessDebugger.cpp
@@ -227,22 +227,21 @@
 debugger_thread = m_session_data->m_debugger;
   }
 
-  Status error;
-  if (state != eStateExited && state != eStateDetached) {
-LLDB_LOG(
-log, "Shutting down process {0}.",
-debugger_thread->GetProcess().GetNativeProcess().GetSystemHandle());
-error = debugger_thread->StopDebugging(true);
-
-// By the time StopDebugging returns, there is no more debugger thread, so
-// we can be assured that no other thread will race for the session data.
-m_session_data.reset();
-  } else {
-error.SetErrorStringWithFormat("cannot destroy process %" PRIx64
-   " while state = %d",
-   GetDebuggedProcessId(), state);
-LLDB_LOG(log, "error: {0}", error);
+  if (state == eStateExited || state == eStateDetached) {
+LLDB_LOG(log, "warning: cannot destroy process {0}  while state = {1}",
+GetDebuggedProcessId(), state);
+return Status();
   }
+
+  LLDB_LOG(
+  log, "Shutting down process {0}.",
+  debugger_thread->GetProcess().GetNativeProcess().GetSystemHandle());
+  auto error = debugger_thread->StopDebugging(true);
+
+  // By the time StopDebugging returns, there is no more debugger thread, so
+  // we can be assured that no other thread will race for the session data.
+  m_session_data.reset();
+
   return error;
 }
 


Index: lldb/source/Plugins/Process/Windows/Common/ProcessDebugger.cpp
===
--- lldb/source/Plugins/Process/Windows/Common/ProcessDebugger.cpp
+++ lldb/source/Plugins/Process/Windows/Common/ProcessDebugger.cpp
@@ -227,22 +227,21 @@
 debugger_thread = m_session_data->m_debugger;
   }
 
-  Status error;
-  if (state != eStateExited && state != eStateDetached) {
-LLDB_LOG(
-log, "Shutting down process {0}.",
-debugger_thread->GetProcess().GetNativeProcess().GetSystemHandle());
-error = debugger_thread->StopDebugging(true);
-
-// By the time StopDebugging returns, there is no more debugger thread, so
-// we can be assured that no other thread will race for the session data.
-m_session_data.reset();
-  } else {
-error.SetErrorStringWithFormat("cannot destroy process %" PRIx64
-   " while state = %d",
-   GetDebuggedProcessId(), state);
-LLDB_LOG(log, "error: {0}", error);
+  if (state == eStateExited || state == eStateDetached) {
+LLDB_LOG(log, "warning: cannot destroy process {0}  while state = {1}",
+GetDebuggedProcessId(), state);
+return Status();
   }
+
+  LLDB_LOG(
+  log, "Shutting down process {0}.",
+  debugger_thread->GetProcess().GetNativeProcess().GetSystemHandle());
+  auto error = debugger_thread->StopDebugging(true);
+
+  // By the time StopDebugging returns, there is no more debugger thread, so
+  // we can be assured that no other thread will race for the session data.
+  m_session_data.reset();
+
   return error;
 }
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D84966: Remove special Hexagon packet traversal code

2020-07-30 Thread Ted Woodward via Phabricator via lldb-commits
ted created this revision.
ted added reviewers: clayborg, jingham, labath.
Herald added a project: LLDB.
ted requested review of this revision.
Herald added a subscriber: JDevlieghere.

On Hexagon, breakpoints need to be on the first instruction of a packet.
When the LLVM disassembler for Hexagon returned 32 bit instructions, we
needed code to find the start of the current packet. Now that the LLVM
disassembler for Hexagon returns packets instead of instructions, we always
have the first instruction of the packet. Remove the packet traversal code
because it can cause problems when the next packet has more than one
instruction.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84966

Files:
  lldb/include/lldb/Core/Disassembler.h
  lldb/source/Core/Disassembler.cpp
  lldb/source/Target/Process.cpp
  lldb/source/Target/ThreadPlanStepRange.cpp

Index: lldb/source/Target/ThreadPlanStepRange.cpp
===
--- lldb/source/Target/ThreadPlanStepRange.cpp
+++ lldb/source/Target/ThreadPlanStepRange.cpp
@@ -327,10 +327,9 @@
   if (instructions == nullptr)
 return false;
   else {
-Target &target = GetThread().GetProcess()->GetTarget();
 const bool ignore_calls = GetKind() == eKindStepOverRange;
 uint32_t branch_index =
-instructions->GetIndexOfNextBranchInstruction(pc_index, target,
+instructions->GetIndexOfNextBranchInstruction(pc_index,
   ignore_calls, 
   &m_found_calls);
 
Index: lldb/source/Target/Process.cpp
===
--- lldb/source/Target/Process.cpp
+++ lldb/source/Target/Process.cpp
@@ -5948,7 +5948,7 @@
   }
 
   uint32_t branch_index =
-  insn_list->GetIndexOfNextBranchInstruction(insn_offset, target,
+  insn_list->GetIndexOfNextBranchInstruction(insn_offset,
  false /* ignore_calls*/,
  nullptr);
   if (branch_index == UINT32_MAX) {
Index: lldb/source/Core/Disassembler.cpp
===
--- lldb/source/Core/Disassembler.cpp
+++ lldb/source/Core/Disassembler.cpp
@@ -990,17 +990,15 @@
 
 uint32_t
 InstructionList::GetIndexOfNextBranchInstruction(uint32_t start,
- Target &target,
  bool ignore_calls,
  bool *found_calls) const {
   size_t num_instructions = m_instructions.size();
 
   uint32_t next_branch = UINT32_MAX;
-  size_t i;
   
   if (found_calls)
 *found_calls = false;
-  for (i = start; i < num_instructions; i++) {
+  for (size_t i = start; i < num_instructions; i++) {
 if (m_instructions[i]->DoesBranch()) {
   if (ignore_calls && m_instructions[i]->IsCall()) {
 if (found_calls)
@@ -1012,42 +1010,6 @@
 }
   }
 
-  // Hexagon needs the first instruction of the packet with the branch. Go
-  // backwards until we find an instruction marked end-of-packet, or until we
-  // hit start.
-  if (target.GetArchitecture().GetTriple().getArch() == llvm::Triple::hexagon) {
-// If we didn't find a branch, find the last packet start.
-if (next_branch == UINT32_MAX) {
-  i = num_instructions - 1;
-}
-
-while (i > start) {
-  --i;
-
-  Status error;
-  uint32_t inst_bytes;
-  bool prefer_file_cache = false; // Read from process if process is running
-  lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
-  target.ReadMemory(m_instructions[i]->GetAddress(), prefer_file_cache,
-&inst_bytes, sizeof(inst_bytes), error, &load_addr);
-  // If we have an error reading memory, return start
-  if (!error.Success())
-return start;
-  // check if this is the last instruction in a packet bits 15:14 will be
-  // 11b or 00b for a duplex
-  if (((inst_bytes & 0xC000) == 0xC000) ||
-  ((inst_bytes & 0xC000) == 0x)) {
-// instruction after this should be the start of next packet
-next_branch = i + 1;
-break;
-  }
-}
-
-if (next_branch == UINT32_MAX) {
-  // We couldn't find the previous packet, so return start
-  next_branch = start;
-}
-  }
   return next_branch;
 }
 
Index: lldb/include/lldb/Core/Disassembler.h
===
--- lldb/include/lldb/Core/Disassembler.h
+++ lldb/include/lldb/Core/Disassembler.h
@@ -279,9 +279,6 @@
   /// @param[in] start
   /// The instruction index of the first instruction to check.
   ///
-  /// @param[in] target
-  /// A LLDB target object that is used to resolve addresses.
-  ///
   /// @param[in] ignore_calls
   /// It true, then fine the first branch instruction that isn't
   /// a funct

[Lldb-commits] [PATCH] D84955: Report an error if a CLI option lacks an argument

2020-07-30 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere requested changes to this revision.
JDevlieghere added a comment.
This revision now requires changes to proceed.

Thanks for fixing this. I do have a few comments but the logic looks good.




Comment at: lldb/test/Shell/Driver/TestError.test:1
+RUN: not %lldb --arch 2>&1 | FileCheck %s --check-prefix ARGMISSING
+ARGMISSING: error: argument to '--arch' is missing

Since there's only one prefix to check you can omit `--check-prefix ARGMISSING` 
and just use CHECK as the prefix on the next line. 



Comment at: lldb/tools/driver/Driver.cpp:873
+   << "' is missing\n";
+llvm::errs() << "Use '" << argv0
+ << " --help' for a complete list of options.\n";

Let's move this and the next line out of check here and below the check for 
unknown options, so that the user gets to see both errors at once. That way we 
also don't have to duplicate the error message. 


Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D84955

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


[Lldb-commits] [lldb] 3bb4889 - [lldb/Test] Use self.assertIn in TestGdbRemoteTargetXmlPacket

2020-07-30 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2020-07-30T11:48:35-07:00
New Revision: 3bb48898bc8af58884d4aa6279d4281938c07e76

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

LOG: [lldb/Test] Use self.assertIn in TestGdbRemoteTargetXmlPacket

On the ARM buildbot the returned architecture is `armv8l` while
getArchitecture() just returns `arm`.

Added: 


Modified: 

lldb/test/API/tools/lldb-server/registers-target-xml-reading/TestGdbRemoteTargetXmlPacket.py

Removed: 




diff  --git 
a/lldb/test/API/tools/lldb-server/registers-target-xml-reading/TestGdbRemoteTargetXmlPacket.py
 
b/lldb/test/API/tools/lldb-server/registers-target-xml-reading/TestGdbRemoteTargetXmlPacket.py
index 51f3d3595640..5ef074c1802c 100644
--- 
a/lldb/test/API/tools/lldb-server/registers-target-xml-reading/TestGdbRemoteTargetXmlPacket.py
+++ 
b/lldb/test/API/tools/lldb-server/registers-target-xml-reading/TestGdbRemoteTargetXmlPacket.py
@@ -43,7 +43,7 @@ def test_g_target_xml_returns_correct_data(self):
 
 architecture = root.find("architecture")
 self.assertIsNotNone(architecture)
-self.assertEqual(architecture.text, self.getArchitecture())
+self.assertIn(self.getArchitecture(), architecture.text)
 
 feature = root.find("feature")
 self.assertIsNotNone(feature)



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


[Lldb-commits] [PATCH] D84966: Remove special Hexagon packet traversal code

2020-07-30 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added a comment.

LGTM after fixing clang format related changes seen in "Lint: Pre-merge checks"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84966

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


[Lldb-commits] [PATCH] D84974: Enable Launching the Debugee in VSCode Terminal

2020-07-30 Thread Yifan Shen via Phabricator via lldb-commits
aelitashen created this revision.
aelitashen added reviewers: wallace, clayborg.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.
aelitashen requested review of this revision.
Herald added a subscriber: JDevlieghere.

When turn on "Launch In Terminal" in IDE, the debugee will be launched inside 
the integrated terminal so that user can input values for debugging. The 
current version adds a response handler for the runInTerminal response from IDE 
to lldb. lldb will attach the program after the response is received.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84974

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

Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -98,6 +98,7 @@
 };
 
 typedef void (*RequestCallback)(const llvm::json::Object &command);
+typedef void (*ResponseCallback)(const llvm::json::Object &command);
 
 enum LaunchMethod { Launch, Attach, AttachForSuspendedLaunch };
 
@@ -1357,6 +1358,8 @@
 filters.emplace_back(CreateExceptionBreakpointFilter(exc_bp));
   }
   body.try_emplace("exceptionBreakpointFilters", std::move(filters));
+  // The debug adapter supports launching a debugee in intergrated VScode terminal.
+  body.try_emplace("supportsRunInTerminalRequest", true);
   // The debug adapter supports stepping back via the stepBack and
   // reverseContinue requests.
   body.try_emplace("supportsStepBack", false);
@@ -1488,66 +1491,113 @@
 return;
   }
 
-  // Instantiate a launch info instance for the target.
-  auto launch_info = g_vsc.target.GetLaunchInfo();
-
-  // Grab the current working directory if there is one and set it in the
-  // launch info.
-  const auto cwd = GetString(arguments, "cwd");
-  if (!cwd.empty())
-launch_info.SetWorkingDirectory(cwd.data());
-
-  // Extract any extra arguments and append them to our program arguments for
-  // when we launch
-  auto args = GetStrings(arguments, "args");
-  if (!args.empty())
-launch_info.SetArguments(MakeArgv(args).data(), true);
-
-  // Pass any environment variables along that the user specified.
-  auto envs = GetStrings(arguments, "env");
-  if (!envs.empty())
-launch_info.SetEnvironmentEntries(MakeArgv(envs).data(), true);
-
-  auto flags = launch_info.GetLaunchFlags();
-
-  if (GetBoolean(arguments, "disableASLR", true))
-flags |= lldb::eLaunchFlagDisableASLR;
-  if (GetBoolean(arguments, "disableSTDIO", false))
-flags |= lldb::eLaunchFlagDisableSTDIO;
-  if (GetBoolean(arguments, "shellExpandArguments", false))
-flags |= lldb::eLaunchFlagShellExpandArguments;
-  const bool detatchOnError = GetBoolean(arguments, "detachOnError", false);
-  launch_info.SetDetachOnError(detatchOnError);
-  launch_info.SetLaunchFlags(flags | lldb::eLaunchFlagDebug |
- lldb::eLaunchFlagStopAtEntry);
-
-  // Run any pre run LLDB commands the user specified in the launch.json
-  g_vsc.RunPreRunCommands();
-  if (launchCommands.empty()) {
-// Disable async events so the launch will be successful when we return from
-// the launch call and the launch will happen synchronously
-g_vsc.debugger.SetAsync(false);
-g_vsc.target.Launch(launch_info, error);
-g_vsc.debugger.SetAsync(true);
+  if (GetBoolean(arguments, "launchInTerminal", false)) {
+llvm::json::Object reverseRequest;
+reverseRequest.try_emplace("type", "request");
+reverseRequest.try_emplace("command", "runInTerminal");
+reverseRequest.try_emplace("seq", 100);
+llvm::json::Object runInTerminalArgs;
+runInTerminalArgs.try_emplace("kind", "integrated");
+runInTerminalArgs.try_emplace("cwd", GetString(arguments, "cwd"));
+std::vector commands = GetStrings(arguments, "args");
+commands.insert(commands.begin(), std::string(GetString(arguments, "program").data()));
+runInTerminalArgs.try_emplace("args", commands);
+std::vector envVars = GetStrings(arguments, "env");
+llvm::json::Object environment;
+for(std::string envVar : envVars) {
+  size_t ind = envVar.find("=");
+  environment.try_emplace(envVar.substr(0, ind), envVar.substr(ind+1));
+}
+runInTerminalArgs.try_emplace("env", llvm::json::Value(std::move(environment)));
+reverseRequest.try_emplace("arguments", llvm::json::Value(std::move(runInTerminalArgs)));
+g_vsc.SendJSON(llvm::json::Value(std::move(reverseRequest)));
+// g_vsc.SendJSON(llvm::json::Value(std::move(response)));
   } else {
-g_vsc.RunLLDBCommands("Running launchCommands:", launchCommands);
-// The custom commands might have created a new target so we should use the
-// selected target after these commands are run.
-g_vsc.target = g_vsc.debugger.GetSelectedTarget();
+// Instantiate a launch info instance for the target.
+auto launch_info = g_vsc.target.GetLaunchInfo();
+
+// Grab the current work

[Lldb-commits] [PATCH] D84974: [WIP] Enable Launching the Debugee in VSCode Terminal

2020-07-30 Thread walter erquinigo via Phabricator via lldb-commits
wallace requested changes to this revision.
wallace added a comment.
This revision now requires changes to proceed.

This is very good for a first implementation. You need to write a test for this 
as well. Once this works, you have to work on the launcher helper Greg and I 
mentioned to you that will help you guarantee you can always attach to the 
target.

Regarding the test, you have to build the python code that will mimic the 
runInTerminal reverse request, along with its response, which will just launch 
the debuggee inside a terminal.

For launching a process inside a shell from python, you can use the 
subprocess.run function and pass the shell=True attribute.

For adding the runInTerminal reverse request in python, take a look at the file 
packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py. You can see 
examples like request_launch, where it sends data and waits for a response 
using the send_recv method. You should add support for reverse requests.




Comment at: lldb/tools/lldb-vscode/lldb-vscode.cpp:1361
   body.try_emplace("exceptionBreakpointFilters", std::move(filters));
+  // The debug adapter supports launching a debugee in intergrated VScode 
terminal.
+  body.try_emplace("supportsRunInTerminalRequest", true);

s/VScode/VSCode



Comment at: lldb/tools/lldb-vscode/lldb-vscode.cpp:1494
 
-  // Instantiate a launch info instance for the target.
-  auto launch_info = g_vsc.target.GetLaunchInfo();
-
-  // Grab the current working directory if there is one and set it in the
-  // launch info.
-  const auto cwd = GetString(arguments, "cwd");
-  if (!cwd.empty())
-launch_info.SetWorkingDirectory(cwd.data());
-
-  // Extract any extra arguments and append them to our program arguments for
-  // when we launch
-  auto args = GetStrings(arguments, "args");
-  if (!args.empty())
-launch_info.SetArguments(MakeArgv(args).data(), true);
-
-  // Pass any environment variables along that the user specified.
-  auto envs = GetStrings(arguments, "env");
-  if (!envs.empty())
-launch_info.SetEnvironmentEntries(MakeArgv(envs).data(), true);
-
-  auto flags = launch_info.GetLaunchFlags();
-
-  if (GetBoolean(arguments, "disableASLR", true))
-flags |= lldb::eLaunchFlagDisableASLR;
-  if (GetBoolean(arguments, "disableSTDIO", false))
-flags |= lldb::eLaunchFlagDisableSTDIO;
-  if (GetBoolean(arguments, "shellExpandArguments", false))
-flags |= lldb::eLaunchFlagShellExpandArguments;
-  const bool detatchOnError = GetBoolean(arguments, "detachOnError", false);
-  launch_info.SetDetachOnError(detatchOnError);
-  launch_info.SetLaunchFlags(flags | lldb::eLaunchFlagDebug |
- lldb::eLaunchFlagStopAtEntry);
-
-  // Run any pre run LLDB commands the user specified in the launch.json
-  g_vsc.RunPreRunCommands();
-  if (launchCommands.empty()) {
-// Disable async events so the launch will be successful when we return 
from
-// the launch call and the launch will happen synchronously
-g_vsc.debugger.SetAsync(false);
-g_vsc.target.Launch(launch_info, error);
-g_vsc.debugger.SetAsync(true);
+  if (GetBoolean(arguments, "launchInTerminal", false)) {
+llvm::json::Object reverseRequest;

move the entire contents of this if to another function for readability



Comment at: lldb/tools/lldb-vscode/lldb-vscode.cpp:1498
+reverseRequest.try_emplace("command", "runInTerminal");
+reverseRequest.try_emplace("seq", 100);
+llvm::json::Object runInTerminalArgs;

does it work if you don't specify the "seq" number? If it works without it, I 
would leave it empty



Comment at: lldb/tools/lldb-vscode/lldb-vscode.cpp:1501
+runInTerminalArgs.try_emplace("kind", "integrated");
+runInTerminalArgs.try_emplace("cwd", GetString(arguments, "cwd"));
+std::vector commands = GetStrings(arguments, "args");

what if cwd is not specified in the arguments? I imagine this might break or at 
least the IDE wouldn't be able to launch the target properly. 
If "cwd" is not defined, then use `llvm::sys::fs::current_path()` instead. Does 
this make sense @clayborg ?



Comment at: lldb/tools/lldb-vscode/lldb-vscode.cpp:1507-1510
+for(std::string envVar : envVars) {
+  size_t ind = envVar.find("=");
+  environment.try_emplace(envVar.substr(0, ind), envVar.substr(ind+1));
+}

run clang-format



Comment at: lldb/tools/lldb-vscode/lldb-vscode.cpp:1514
+g_vsc.SendJSON(llvm::json::Value(std::move(reverseRequest)));
+// g_vsc.SendJSON(llvm::json::Value(std::move(response)));
   } else {

remove this comment



Comment at: lldb/tools/lldb-vscode/lldb-vscode.cpp:1514
+g_vsc.SendJSON(llvm::json::Value(std::move(reverseRequest)));
+// g_vsc.SendJSON(llvm::json::Value(std::move(response)));
   } else {

wallace wro

[Lldb-commits] [PATCH] D84954: [lldb] Make Target::CleanupProcess consistent for breakpoints and watchpoints

2020-07-30 Thread Tatyana Krasnukha via Phabricator via lldb-commits
tatyana-krasnukha updated this revision to Diff 282030.
tatyana-krasnukha added a comment.

TestAddressBreakpoints.py fails on the last check - it expects hit count to be 
saved after re-launching the process. Removed that check.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84954

Files:
  lldb/include/lldb/Breakpoint/Breakpoint.h
  lldb/include/lldb/Breakpoint/BreakpointList.h
  lldb/include/lldb/Breakpoint/BreakpointLocation.h
  lldb/include/lldb/Breakpoint/BreakpointLocationList.h
  lldb/include/lldb/Breakpoint/WatchpointList.h
  lldb/include/lldb/Target/Target.h
  lldb/source/Breakpoint/Breakpoint.cpp
  lldb/source/Breakpoint/BreakpointList.cpp
  lldb/source/Breakpoint/BreakpointLocationList.cpp
  lldb/source/Breakpoint/WatchpointList.cpp
  lldb/source/Target/Target.cpp
  
lldb/test/API/functionalities/breakpoint/address_breakpoints/TestAddressBreakpoints.py
  
lldb/test/API/functionalities/breakpoint/breakpoint_hit_count/TestBreakpointHitCount.py

Index: lldb/test/API/functionalities/breakpoint/breakpoint_hit_count/TestBreakpointHitCount.py
===
--- lldb/test/API/functionalities/breakpoint/breakpoint_hit_count/TestBreakpointHitCount.py
+++ lldb/test/API/functionalities/breakpoint/breakpoint_hit_count/TestBreakpointHitCount.py
@@ -19,15 +19,32 @@
 def test_breakpoint_location_hit_count(self):
 """Use Python APIs to check breakpoint hit count."""
 self.build()
-self.do_test_breakpoint_location_hit_count()
+target = self.create_target()
+breakpoint = self.create_breakpoint(target)
+process = self.launch_process(target)
+self.do_test_breakpoint_location_hit_count(process, breakpoint)
+
+def test_breakpoint_hit_count_cleanup(self):
+"""Use Python APIs to check that breakpoint hit count is cleared
+   as well as locations hit counts when process dies."""
+self.build()
+target = self.create_target()
+breakpoint = self.create_breakpoint(target)
+process = self.launch_process(target)
+self.do_test_breakpoint_location_hit_count(process, breakpoint)
+
+# Kill the process and launch a new one.
+status = process.Kill()
+self.assertTrue(status, "The process was killed.")
+new_process = self.launch_process(target)
+
+# Test hit location of the existing breakpoint. It should be like we didn't have hits before.
+self.do_test_breakpoint_location_hit_count(new_process, breakpoint)
 
 def test_breakpoint_one_shot(self):
 """Check that one-shot breakpoints trigger only once."""
 self.build()
-
-exe = self.getBuildArtifact("a.out")
-target = self.dbg.CreateTarget(exe)
-self.assertTrue(target, VALID_TARGET)
+target = self.create_target()
 
 self.runCmd("tb a")
 process = target.LaunchSimple(
@@ -54,13 +71,14 @@
 self.a_float_body_line_no = line_number(
 'main.cpp', '// Breakpoint Location 2')
 
-def do_test_breakpoint_location_hit_count(self):
-"""Use Python APIs to check breakpoint hit count."""
+def create_target(self):
 exe = self.getBuildArtifact("a.out")
 
 target = self.dbg.CreateTarget(exe)
 self.assertTrue(target, VALID_TARGET)
+return target
 
+def create_breakpoint(self, target):
 # Create a breakpoint in main.cpp by name 'a',
 # there should be two locations.
 breakpoint = target.BreakpointCreateByName('a', 'a.out')
@@ -79,11 +97,19 @@
 location2.IsEnabled(),
 VALID_BREAKPOINT_LOCATION)
 
+return breakpoint
+
+def launch_process(self, target):
 # Launch the process, and do not stop at entry point.
 process = target.LaunchSimple(
 None, None, self.get_process_working_directory())
 self.assertTrue(process, PROCESS_IS_VALID)
 
+return process
+
+def do_test_breakpoint_location_hit_count(self, process, breakpoint):
+"""Use Python APIs to check breakpoint hit count."""
+
 # Verify 1st breakpoint location is hit.
 from lldbsuite.test.lldbutil import get_stopped_thread
 thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
@@ -129,5 +155,3 @@
 self.assertEqual(location2.GetHitCount(), 2)
 self.assertEqual(location1.GetHitCount(), 1)
 self.assertEqual(breakpoint.GetHitCount(), 3)
-
-process.Continue()
Index: lldb/test/API/functionalities/breakpoint/address_breakpoints/TestAddressBreakpoints.py
===
--- lldb/test/API/functionalities/breakpoint/address_breakpoints/TestAddressBreakpoints.py
+++ lldb/test/API/functionalities/breakpoint/address_breakpoints/TestAddressBreakpoints.py
@@ -72,20 +72,3 @@
 

[Lldb-commits] [lldb] 8c1a31d - [lldb/Docs] Add lldb-arm-ubuntu to the list of bots

2020-07-30 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2020-07-30T13:47:21-07:00
New Revision: 8c1a31d83313e4d43509177193f1de14cf897c05

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

LOG: [lldb/Docs] Add lldb-arm-ubuntu to the list of bots

Added: 


Modified: 
lldb/docs/resources/bots.rst

Removed: 




diff  --git a/lldb/docs/resources/bots.rst b/lldb/docs/resources/bots.rst
index efe8c7116b01..6df7dade9814 100644
--- a/lldb/docs/resources/bots.rst
+++ b/lldb/docs/resources/bots.rst
@@ -10,6 +10,7 @@ LLVM Buildbot is the place where volunteers provide build 
machines. Everyone can
 * `lldb-x64-windows-ninja 
`_
 * `lldb-x86_64-debian `_
 * `lldb-aarch64-ubuntu 
`_
+* `lldb-arm-ubuntu `_
 * `lldb-x86_64-fedora `_
 
 Documentation



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


[Lldb-commits] [lldb] 02c1bba - [lldb/Docs] Remove stale bot on GreenDragon and add reproducer one

2020-07-30 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2020-07-30T13:51:16-07:00
New Revision: 02c1bba67009041a999220f370e81376883d7a65

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

LOG: [lldb/Docs] Remove stale bot on GreenDragon and add reproducer one

 - Remove the link to the Python 3 job which no longer exists.
 - Add a link to the reproducer job.

Added: 


Modified: 
lldb/docs/resources/bots.rst

Removed: 




diff  --git a/lldb/docs/resources/bots.rst b/lldb/docs/resources/bots.rst
index 6df7dade9814..d9ddcde41abc 100644
--- a/lldb/docs/resources/bots.rst
+++ b/lldb/docs/resources/bots.rst
@@ -13,14 +13,6 @@ LLVM Buildbot is the place where volunteers provide build 
machines. Everyone can
 * `lldb-arm-ubuntu `_
 * `lldb-x86_64-fedora `_
 
-Documentation
--
-
-The documentation bot validates that the website builds correctly with Sphinx.
-It does not generate the website itself, which happens on a separate server.
-
-* `lldb-sphinx-docs `_
-
 GreenDragon
 ---
 
@@ -29,7 +21,14 @@ GreenDragon builds and tests LLDB on macOS. It has a 
`dedicated tab
 
 * `lldb-cmake `_
 * `lldb-cmake-matrix 
`_
-* `lldb-cmake-python3 
`_
+* `lldb-cmake-reproducers 
`_
 * `lldb-cmake-standalone 
`_
 * `lldb-cmake-sanitized 
`_
 
+Documentation
+-
+
+The documentation bot validates that the website builds correctly with Sphinx.
+It does not generate the website itself, which happens on a separate server.
+
+* `lldb-sphinx-docs `_



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


[Lldb-commits] [PATCH] D84263: [debugserver/Apple Silicon] Handoff connections when attaching to translated processes

2020-07-30 Thread Davide Italiano via Phabricator via lldb-commits
davide updated this revision to Diff 282073.
davide added a comment.

Added the check that Jason requested.


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

https://reviews.llvm.org/D84263

Files:
  lldb/tools/debugserver/source/DNB.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
@@ -878,6 +878,8 @@
// -F localhost:1234 -- /bin/ls"
 {NULL, 0, NULL, 0}};
 
+int communication_fd = -1;
+
 // main
 int main(int argc, char *argv[]) {
   // If debugserver is launched with DYLD_INSERT_LIBRARIES, unset it so we
@@ -944,7 +946,6 @@
   int ch;
   int long_option_index = 0;
   int debug = 0;
-  int communication_fd = -1;
   std::string compile_options;
   std::string waitfor_pid_name; // Wait for a process that starts with this 
name
   std::string attach_pid_name;
Index: lldb/tools/debugserver/source/DNB.cpp
===
--- lldb/tools/debugserver/source/DNB.cpp
+++ lldb/tools/debugserver/source/DNB.cpp
@@ -442,6 +442,39 @@
   if (err_str && err_len > 0)
 err_str[0] = '\0';
 
+  if (getenv("LLDB_DEBUGSERVER_PATH") == NULL) {
+int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PID,
+ static_cast(attach_pid)};
+struct kinfo_proc processInfo;
+size_t bufsize = sizeof(processInfo);
+if (sysctl(mib, (unsigned)(sizeof(mib) / sizeof(int)), &processInfo,
+   &bufsize, NULL, 0) == 0 &&
+bufsize > 0) {
+
+  if ((processInfo.kp_proc.p_flag & P_TRANSLATED) == P_TRANSLATED) {
+const char *translated_debugserver =
+"/Library/Apple/usr/libexec/oah/debugserver";
+char fdstr[16];
+char pidstr[16];
+extern int communication_fd;
+
+if (communication_fd == -1) {
+  fprintf(stderr, "Trying to attach to a translated process with the "
+  "native debugserver, exiting...\n");
+  exit(1);
+}
+
+snprintf(fdstr, sizeof(fdstr), "--fd=%d", communication_fd);
+snprintf(pidstr, sizeof(pidstr), "--attach=%d", attach_pid);
+execl(translated_debugserver, "--native-regs", "--setsid", fdstr,
+  "--handoff-attach-from-native", pidstr, (char *)0);
+DNBLogThreadedIf(LOG_PROCESS, "Failed to launch debugserver for "
+ "translated process: ", errno, strerror(errno));
+__builtin_trap();
+  }
+}
+  }
+
   pid_t pid = INVALID_NUB_PROCESS;
   MachProcessSP processSP(new MachProcess);
   if (processSP.get()) {


Index: lldb/tools/debugserver/source/debugserver.cpp
===
--- lldb/tools/debugserver/source/debugserver.cpp
+++ lldb/tools/debugserver/source/debugserver.cpp
@@ -878,6 +878,8 @@
// -F localhost:1234 -- /bin/ls"
 {NULL, 0, NULL, 0}};
 
+int communication_fd = -1;
+
 // main
 int main(int argc, char *argv[]) {
   // If debugserver is launched with DYLD_INSERT_LIBRARIES, unset it so we
@@ -944,7 +946,6 @@
   int ch;
   int long_option_index = 0;
   int debug = 0;
-  int communication_fd = -1;
   std::string compile_options;
   std::string waitfor_pid_name; // Wait for a process that starts with this name
   std::string attach_pid_name;
Index: lldb/tools/debugserver/source/DNB.cpp
===
--- lldb/tools/debugserver/source/DNB.cpp
+++ lldb/tools/debugserver/source/DNB.cpp
@@ -442,6 +442,39 @@
   if (err_str && err_len > 0)
 err_str[0] = '\0';
 
+  if (getenv("LLDB_DEBUGSERVER_PATH") == NULL) {
+int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PID,
+ static_cast(attach_pid)};
+struct kinfo_proc processInfo;
+size_t bufsize = sizeof(processInfo);
+if (sysctl(mib, (unsigned)(sizeof(mib) / sizeof(int)), &processInfo,
+   &bufsize, NULL, 0) == 0 &&
+bufsize > 0) {
+
+  if ((processInfo.kp_proc.p_flag & P_TRANSLATED) == P_TRANSLATED) {
+const char *translated_debugserver =
+"/Library/Apple/usr/libexec/oah/debugserver";
+char fdstr[16];
+char pidstr[16];
+extern int communication_fd;
+
+if (communication_fd == -1) {
+  fprintf(stderr, "Trying to attach to a translated process with the "
+  "native debugserver, exiting...\n");
+  exit(1);
+}
+
+snprintf(fdstr, sizeof(fdstr), "--fd=%d", communication_fd);
+snprintf(pidstr, sizeof(pidstr), "--attach=%d", attach_pid);
+execl(translated_debugserver, "--native-regs", "--setsid", fdstr,
+  "--handoff-attach-from-native", pidstr, (char *)0);
+DNBLogThreadedIf(LOG_PROCESS, "Failed to launch debugserver for "
+ "translated proc

[Lldb-commits] [PATCH] D84263: [debugserver/Apple Silicon] Handoff connections when attaching to translated processes

2020-07-30 Thread Davide Italiano via Phabricator via lldb-commits
davide accepted this revision.
davide added a comment.
This revision is now accepted and ready to land.

Reviewed by Jason privately.


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

https://reviews.llvm.org/D84263

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


[Lldb-commits] [lldb] 5760575 - [debugserver/Apple Silicon] Handoff connections when attaching to translated processes

2020-07-30 Thread Davide Italiano via lldb-commits

Author: Davide Italiano
Date: 2020-07-30T16:21:05-07:00
New Revision: 57605758b5de3726eec1d6e587de1003af1ab5b7

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

LOG: [debugserver/Apple Silicon] Handoff connections when attaching to 
translated processes

When we detect a process that the native debugserver cannot handle,
handoff the connection fd to the translated debugserver.

Added: 


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

Removed: 




diff  --git a/lldb/tools/debugserver/source/DNB.cpp 
b/lldb/tools/debugserver/source/DNB.cpp
index 0830ea36a91a..3c1cd85dc310 100644
--- a/lldb/tools/debugserver/source/DNB.cpp
+++ b/lldb/tools/debugserver/source/DNB.cpp
@@ -442,6 +442,39 @@ nub_process_t DNBProcessAttach(nub_process_t attach_pid,
   if (err_str && err_len > 0)
 err_str[0] = '\0';
 
+  if (getenv("LLDB_DEBUGSERVER_PATH") == NULL) {
+int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PID,
+ static_cast(attach_pid)};
+struct kinfo_proc processInfo;
+size_t bufsize = sizeof(processInfo);
+if (sysctl(mib, (unsigned)(sizeof(mib) / sizeof(int)), &processInfo,
+   &bufsize, NULL, 0) == 0 &&
+bufsize > 0) {
+
+  if ((processInfo.kp_proc.p_flag & P_TRANSLATED) == P_TRANSLATED) {
+const char *translated_debugserver =
+"/Library/Apple/usr/libexec/oah/debugserver";
+char fdstr[16];
+char pidstr[16];
+extern int communication_fd;
+
+if (communication_fd == -1) {
+  fprintf(stderr, "Trying to attach to a translated process with the "
+  "native debugserver, exiting...\n");
+  exit(1);
+}
+
+snprintf(fdstr, sizeof(fdstr), "--fd=%d", communication_fd);
+snprintf(pidstr, sizeof(pidstr), "--attach=%d", attach_pid);
+execl(translated_debugserver, "--native-regs", "--setsid", fdstr,
+  "--handoff-attach-from-native", pidstr, (char *)0);
+DNBLogThreadedIf(LOG_PROCESS, "Failed to launch debugserver for "
+ "translated process: ", errno, strerror(errno));
+__builtin_trap();
+  }
+}
+  }
+
   pid_t pid = INVALID_NUB_PROCESS;
   MachProcessSP processSP(new MachProcess);
   if (processSP.get()) {

diff  --git a/lldb/tools/debugserver/source/debugserver.cpp 
b/lldb/tools/debugserver/source/debugserver.cpp
index 42205dedf4bb..410ea7c310fa 100644
--- a/lldb/tools/debugserver/source/debugserver.cpp
+++ b/lldb/tools/debugserver/source/debugserver.cpp
@@ -878,6 +878,8 @@ static struct option g_long_options[] = {
// -F localhost:1234 -- /bin/ls"
 {NULL, 0, NULL, 0}};
 
+int communication_fd = -1;
+
 // main
 int main(int argc, char *argv[]) {
   // If debugserver is launched with DYLD_INSERT_LIBRARIES, unset it so we
@@ -944,7 +946,6 @@ int main(int argc, char *argv[]) {
   int ch;
   int long_option_index = 0;
   int debug = 0;
-  int communication_fd = -1;
   std::string compile_options;
   std::string waitfor_pid_name; // Wait for a process that starts with this 
name
   std::string attach_pid_name;



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


[Lldb-commits] [PATCH] D84974: [WIP] Enable Launching the Debugee in VSCode Terminal

2020-07-30 Thread Greg Clayton via Phabricator via lldb-commits
clayborg requested changes to this revision.
clayborg added a comment.

So there is a fundamental change needed for this patch to work. I tried to 
fully detail this in the inline comments. Let me know if you have any questions.




Comment at: lldb/tools/lldb-vscode/lldb-vscode.cpp:1498
+reverseRequest.try_emplace("command", "runInTerminal");
+reverseRequest.try_emplace("seq", 100);
+llvm::json::Object runInTerminalArgs;

wallace wrote:
> does it work if you don't specify the "seq" number? If it works without it, I 
> would leave it empty
Remove this line. I will explain more in next inline comment!



Comment at: lldb/tools/lldb-vscode/lldb-vscode.cpp:1501
+runInTerminalArgs.try_emplace("kind", "integrated");
+runInTerminalArgs.try_emplace("cwd", GetString(arguments, "cwd"));
+std::vector commands = GetStrings(arguments, "args");

wallace wrote:
> what if cwd is not specified in the arguments? I imagine this might break or 
> at least the IDE wouldn't be able to launch the target properly. 
> If "cwd" is not defined, then use `llvm::sys::fs::current_path()` instead. 
> Does this make sense @clayborg ?
yes, we need to set this correctly if it isn't set in the launch.json and your 
suggestion makes sense.



Comment at: lldb/tools/lldb-vscode/lldb-vscode.cpp:1513
+reverseRequest.try_emplace("arguments", 
llvm::json::Value(std::move(runInTerminalArgs)));
+g_vsc.SendJSON(llvm::json::Value(std::move(reverseRequest)));
+// g_vsc.SendJSON(llvm::json::Value(std::move(response)));

So I am not sure we need to do all of the response handler stuff since we need 
to get the result of this before we can proceed. So we need to be able to send 
this request and receive the response right here. So we need to add that 
ability to VSCode (the type definition of g_vsc).

This code should be:

```
llvm::json::Object reverseResponse = 
g_vsc.SendReverseRequest(llvm::json::Value(std::move(reverseRequest)));
```
Then we need to extract the pid from the response right in this function. Right 
now we don't have a thread that is listening for more packets, we just have the 
main thread getting the current packet ("launch" in this case) and we are 
currently handling this function, so there is no way we will get a response in 
this function if we don't do this.

You will need to write the "SendReverseRequest()" function in VSCode and it 
will rely on refactoring that I mentioned below in the main() function where we 
make VSCode::GetObject() and VSCode::HandleObject() and uses the new 
"PacketStatus" enum. The SendReverseRequest function will do something like:

```
struct VSCode {
...
  uint32_t reverse_request_seq = 0;  
  PacketStatus SendReverseRequest(const llvm::json::Value &request, 
llvm::json::Object &response) {
// Put the right "seq" into the packet here, so we don't have to do it from
// where we send the reverse request.
request.try_emplace("seq", ++reverse_request_seq);
SendJSON(request);
bool got_response = false;
while (!got_response) {
  llvm::json::Object response;
  Status status = GetObject(response);
  if (status == PacketStatus::Success) {
const auto packet_type = GetString(response, "type");
if (packet_type == "response")
  return status;
// Not our response, we got another packet
   HandleObject(response)
  } else {
return status;
  }
}
  }
```

The "VSCode::GetResponse" is a new function as well that we will make from 




Comment at: lldb/tools/lldb-vscode/lldb-vscode.cpp:2987-3012
 std::string json = g_vsc.ReadJSON();
 if (json.empty())
   break;
 
 llvm::StringRef json_sref(json);
 llvm::Expected json_value = 
llvm::json::parse(json_sref);
 if (!json_value) {

We need to move these lines into VSCode.h and VSCode.cpp into a function called 
GetObject():

``` 
enum class PacketStatus {
  Success = 0
  EndOfFile,
  JSONMalformed,
  JSONNotObject
};

PacketStatus VSCode::GetObject(llvm::json::Object &object) {
  std::string json =ReadJSON();
  if (json.empty())
  return PacketStatus::EndOfFile;

  llvm::StringRef json_sref(json);
  llvm::Expected json_value = llvm::json::parse(json_sref);
  if (!json_value) {
auto error = json_value.takeError();
if (log) {
  std::string error_str;
  llvm::raw_string_ostream strm(error_str);
  strm << error;
  strm.flush();
  *log << "error: failed to parse JSON: " << error_str << std::endl
 << json << std::endl;
}
return PacketStatus::JSONMalformed;
  }
  object = std::move(json_value->getAsObject());
  if (!object) {
if (log)
  *log << "error: json packet isn't a object" << std::endl;
return PacketStatus::JSONNotObject;
  }
  return PacketStatus::Success;
}
```
This will allow us to use this function in the VSCode::SendReverseReque

[Lldb-commits] [PATCH] D84974: [WIP] Enable Launching the Debugee in VSCode Terminal

2020-07-30 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added inline comments.



Comment at: lldb/tools/lldb-vscode/lldb-vscode.cpp:1576
+}
+void response_runInTerminal(const llvm::json::Object &reverseRequest) {
+  g_vsc.is_attach = true;

wallace wrote:
> mention here that VSCode doesn't respond back the pid of the target, so we 
> can only attach by process name, which is already set up in the 
> request_launch method
The response has the process ID of what we need to attach to right? Why do we 
need to do this by name?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84974

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


[Lldb-commits] [lldb] abf546d - debguserver's type sniffer to only treat .app things that end in .app

2020-07-30 Thread Jason Molenda via lldb-commits

Author: Jason Molenda
Date: 2020-07-30T21:14:33-07:00
New Revision: abf546dd4f8326b821244b67eaa79ada7757d877

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

LOG: debguserver's type sniffer to only treat .app things that end in .app

On an iOS device, if debugserver is left to figure out how to launch
the binary provided, it looks at the filename to see if it contains
".app" and asks FrontBoard to launch it.  However, if this is actually
a command line app with the characters ".app" in the name, it would
end up trying to launch that via the FrontBoard calls even though it
needed to be launched via posix_spawn.  For instance, a command line
program called com.application.tester.

Jim suggested this patch where we only send binaries that end in ".app"
to FrontBoard.

Often debugsever is invoked with a --launch command line argument to
specify the launch method, and none of this code is hit in that
instance.



Added: 


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

Removed: 




diff  --git a/lldb/tools/debugserver/source/debugserver.cpp 
b/lldb/tools/debugserver/source/debugserver.cpp
index 410ea7c310fa..4e6aa39e52d3 100644
--- a/lldb/tools/debugserver/source/debugserver.cpp
+++ b/lldb/tools/debugserver/source/debugserver.cpp
@@ -156,6 +156,20 @@ RNBRunLoopMode RNBRunLoopGetStartModeFromRemote(RNBRemote 
*remote) {
   return eRNBRunLoopModeExit;
 }
 
+// Check the name to see if it ends with .app
+static bool is_dot_app (const char *app_name) {
+  size_t len = strlen(app_name);
+  if (len < 4)
+return false;
+  
+  if (app_name[len - 4] == '.' &&
+  app_name[len - 3] == 'a' && 
+  app_name[len - 2] == 'p' &&
+  app_name[len - 1] == 'p')
+return true;
+  return false;
+}
+
 // This run loop mode will wait for the process to launch and hit its
 // entry point. It will currently ignore all events except for the
 // process state changed event, where it watches for the process stopped
@@ -200,17 +214,17 @@ RNBRunLoopMode RNBRunLoopLaunchInferior(RNBRemote *remote,
 
 #if defined WITH_FBS
 // Check if we have an app bundle, if so launch using BackBoard Services.
-if (strstr(inferior_argv[0], ".app")) {
+if (is_dot_app(inferior_argv[0])) {
   launch_flavor = eLaunchFlavorFBS;
 }
 #elif defined WITH_BKS
 // Check if we have an app bundle, if so launch using BackBoard Services.
-if (strstr(inferior_argv[0], ".app")) {
+if (is_dot_app(inferior_argv[0])) {
   launch_flavor = eLaunchFlavorBKS;
 }
 #elif defined WITH_SPRINGBOARD
 // Check if we have an app bundle, if so launch using SpringBoard.
-if (strstr(inferior_argv[0], ".app")) {
+if (is_dot_app(inferior_argv[0])) {
   launch_flavor = eLaunchFlavorSpringBoard;
 }
 #endif
@@ -1499,17 +1513,17 @@ int main(int argc, char *argv[]) {
 
 #if defined WITH_FBS
   // Check if we have an app bundle, if so launch using SpringBoard.
-  if (waitfor_pid_name.find(".app") != std::string::npos) {
+  if (is_dot_app(waitfor_pid_name.c_str())) {
 launch_flavor = eLaunchFlavorFBS;
   }
 #elif defined WITH_BKS
   // Check if we have an app bundle, if so launch using SpringBoard.
-  if (waitfor_pid_name.find(".app") != std::string::npos) {
+  if (is_dot_app(waitfor_pid_name.c_str())) {
 launch_flavor = eLaunchFlavorBKS;
   }
 #elif defined WITH_SPRINGBOARD
   // Check if we have an app bundle, if so launch using SpringBoard.
-  if (waitfor_pid_name.find(".app") != std::string::npos) {
+  if (is_dot_app(waitfor_pid_name.c_str())) {
 launch_flavor = eLaunchFlavorSpringBoard;
   }
 #endif



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