[Lldb-commits] [lldb] fb1dc77 - [lldb][NFC] Silence missing case warnings in TypeSystemClang::GetTypeBitAlign due to new RISC-V V types

2021-02-18 Thread Raphael Isemann via lldb-commits

Author: Raphael Isemann
Date: 2021-02-18T09:03:18+01:00
New Revision: fb1dc77bfd24c32a5231face77e0bc4323b67c68

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

LOG: [lldb][NFC] Silence missing case warnings in 
TypeSystemClang::GetTypeBitAlign due to new RISC-V V types

Those types were added in D92715. This just silences the warning but doesn't
actually add support for those types to LLDB.

Added: 


Modified: 
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Removed: 




diff  --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp 
b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index c15b15e736fb..e26515789d0f 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -4889,6 +4889,75 @@ lldb::Encoding 
TypeSystemClang::GetEncoding(lldb::opaque_compiler_type_t type,
 case clang::BuiltinType::SveFloat64x4:
   break;
 
+// RISC-V V builtin types.
+case clang::BuiltinType::RvvInt8mf8:
+case clang::BuiltinType::RvvInt8mf4:
+case clang::BuiltinType::RvvInt8mf2:
+case clang::BuiltinType::RvvInt8m1:
+case clang::BuiltinType::RvvInt8m2:
+case clang::BuiltinType::RvvInt8m4:
+case clang::BuiltinType::RvvInt8m8:
+case clang::BuiltinType::RvvUint8mf8:
+case clang::BuiltinType::RvvUint8mf4:
+case clang::BuiltinType::RvvUint8mf2:
+case clang::BuiltinType::RvvUint8m1:
+case clang::BuiltinType::RvvUint8m2:
+case clang::BuiltinType::RvvUint8m4:
+case clang::BuiltinType::RvvUint8m8:
+case clang::BuiltinType::RvvInt16mf4:
+case clang::BuiltinType::RvvInt16mf2:
+case clang::BuiltinType::RvvInt16m1:
+case clang::BuiltinType::RvvInt16m2:
+case clang::BuiltinType::RvvInt16m4:
+case clang::BuiltinType::RvvInt16m8:
+case clang::BuiltinType::RvvUint16mf4:
+case clang::BuiltinType::RvvUint16mf2:
+case clang::BuiltinType::RvvUint16m1:
+case clang::BuiltinType::RvvUint16m2:
+case clang::BuiltinType::RvvUint16m4:
+case clang::BuiltinType::RvvUint16m8:
+case clang::BuiltinType::RvvInt32mf2:
+case clang::BuiltinType::RvvInt32m1:
+case clang::BuiltinType::RvvInt32m2:
+case clang::BuiltinType::RvvInt32m4:
+case clang::BuiltinType::RvvInt32m8:
+case clang::BuiltinType::RvvUint32mf2:
+case clang::BuiltinType::RvvUint32m1:
+case clang::BuiltinType::RvvUint32m2:
+case clang::BuiltinType::RvvUint32m4:
+case clang::BuiltinType::RvvUint32m8:
+case clang::BuiltinType::RvvInt64m1:
+case clang::BuiltinType::RvvInt64m2:
+case clang::BuiltinType::RvvInt64m4:
+case clang::BuiltinType::RvvInt64m8:
+case clang::BuiltinType::RvvUint64m1:
+case clang::BuiltinType::RvvUint64m2:
+case clang::BuiltinType::RvvUint64m4:
+case clang::BuiltinType::RvvUint64m8:
+case clang::BuiltinType::RvvFloat16mf4:
+case clang::BuiltinType::RvvFloat16mf2:
+case clang::BuiltinType::RvvFloat16m1:
+case clang::BuiltinType::RvvFloat16m2:
+case clang::BuiltinType::RvvFloat16m4:
+case clang::BuiltinType::RvvFloat16m8:
+case clang::BuiltinType::RvvFloat32mf2:
+case clang::BuiltinType::RvvFloat32m1:
+case clang::BuiltinType::RvvFloat32m2:
+case clang::BuiltinType::RvvFloat32m4:
+case clang::BuiltinType::RvvFloat32m8:
+case clang::BuiltinType::RvvFloat64m1:
+case clang::BuiltinType::RvvFloat64m2:
+case clang::BuiltinType::RvvFloat64m4:
+case clang::BuiltinType::RvvFloat64m8:
+case clang::BuiltinType::RvvBool1:
+case clang::BuiltinType::RvvBool2:
+case clang::BuiltinType::RvvBool4:
+case clang::BuiltinType::RvvBool8:
+case clang::BuiltinType::RvvBool16:
+case clang::BuiltinType::RvvBool32:
+case clang::BuiltinType::RvvBool64:
+  break;
+
 case clang::BuiltinType::IncompleteMatrixIdx:
   break;
 }



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


[Lldb-commits] [PATCH] D96939: [lldb] Add a note to the core file loading error message that mentions archives

2021-02-18 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added inline comments.



Comment at: lldb/source/Commands/CommandObjectTarget.cpp:431
+  result.AppendMessage(
+  "Note: If the passed file is a compressed file archive 
containing"
+  " a core file, you first need to manually extract the core file "

For consistency with `warning` and `error`, `Note` should be lowercase. 

[begin potential yak shaving]
It would be nice to extend `CommandReturnObject` with the notion of notes. That 
way they could be colored in the same way that `error` and `warning` are. 
LLVM's `WithColor` already has a dedicated `note` color. 
[end potential yak shaving]


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

https://reviews.llvm.org/D96939

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


[Lldb-commits] [PATCH] D96939: [lldb] Add a note to the core file loading error message that mentions archives

2021-02-18 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor updated this revision to Diff 324546.
teemperor added a comment.

- Made `note:` lower case


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

https://reviews.llvm.org/D96939

Files:
  lldb/source/Commands/CommandObjectTarget.cpp


Index: lldb/source/Commands/CommandObjectTarget.cpp
===
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ lldb/source/Commands/CommandObjectTarget.cpp
@@ -427,6 +427,10 @@
   result.AppendErrorWithFormatv(
   "Unable to find process plug-in for core file '{0}'\n",
   core_file.GetPath());
+  result.AppendMessage(
+  "note: If the passed file is a compressed file archive 
containing"
+  " a core file, you first need to manually extract the core file "
+  " from the archive before trying to load it.\n");
   result.SetStatus(eReturnStatusFailed);
 }
   } else {


Index: lldb/source/Commands/CommandObjectTarget.cpp
===
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ lldb/source/Commands/CommandObjectTarget.cpp
@@ -427,6 +427,10 @@
   result.AppendErrorWithFormatv(
   "Unable to find process plug-in for core file '{0}'\n",
   core_file.GetPath());
+  result.AppendMessage(
+  "note: If the passed file is a compressed file archive containing"
+  " a core file, you first need to manually extract the core file "
+  " from the archive before trying to load it.\n");
   result.SetStatus(eReturnStatusFailed);
 }
   } else {
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D96939: [lldb] Add a note to the core file loading error message that mentions archives

2021-02-18 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda added a comment.

Thanks for taking time to deal with this annoying error message.  Should we 
just remove the "Unable to find process plug-in for core file" text altogether? 
 It means nothing unless you work on lldb and understand the plugin system.  
"Unrecognized core file format" is equivalent and more helpful to the user I 
think.


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

https://reviews.llvm.org/D96939

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


[Lldb-commits] [PATCH] D96939: [lldb] Add a note to the core file loading error message that mentions archives

2021-02-18 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor added inline comments.



Comment at: lldb/source/Commands/CommandObjectTarget.cpp:431
+  result.AppendMessage(
+  "Note: If the passed file is a compressed file archive 
containing"
+  " a core file, you first need to manually extract the core file "

JDevlieghere wrote:
> For consistency with `warning` and `error`, `Note` should be lowercase. 
> 
> [begin potential yak shaving]
> It would be nice to extend `CommandReturnObject` with the notion of notes. 
> That way they could be colored in the same way that `error` and `warning` 
> are. LLVM's `WithColor` already has a dedicated `note` color. 
> [end potential yak shaving]
Fixed the typo.

+1 to the 'note' variation. I'll see if we can make that happen but not as a 
dependency of this commit (we anyway already have some other places where this 
should be done).


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

https://reviews.llvm.org/D96939

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


[Lldb-commits] [PATCH] D96939: [lldb] Add a note to the core file loading error message that mentions archives

2021-02-18 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added inline comments.



Comment at: lldb/source/Commands/CommandObjectTarget.cpp:431
+  result.AppendMessage(
+  "Note: If the passed file is a compressed file archive 
containing"
+  " a core file, you first need to manually extract the core file "

teemperor wrote:
> JDevlieghere wrote:
> > For consistency with `warning` and `error`, `Note` should be lowercase. 
> > 
> > [begin potential yak shaving]
> > It would be nice to extend `CommandReturnObject` with the notion of notes. 
> > That way they could be colored in the same way that `error` and `warning` 
> > are. LLVM's `WithColor` already has a dedicated `note` color. 
> > [end potential yak shaving]
> Fixed the typo.
> 
> +1 to the 'note' variation. I'll see if we can make that happen but not as a 
> dependency of this commit (we anyway already have some other places where 
> this should be done).
Yep, definitely something for a separate patch.


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

https://reviews.llvm.org/D96939

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


[Lldb-commits] [PATCH] D96939: [lldb] Add a note to the core file loading error message that mentions archives

2021-02-18 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda added a comment.

I mean, I'm also fine with suggesting that the file might be compressed, 
because this is a REAL common source of an unrecognized core file format.  But 
also we can more clearly say "Doesn't look like a core file to me" and also 
noting that compression is something to look at is cool.


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

https://reviews.llvm.org/D96939

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


[Lldb-commits] [PATCH] D96939: [lldb] Add a note to the core file loading error message that mentions archives

2021-02-18 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor added a comment.

In D96939#2570810 , @jasonmolenda 
wrote:

> I mean, I'm also fine with suggesting that the file might be compressed, 
> because this is a REAL common source of an unrecognized core file format.  
> But also we can more clearly say "Doesn't look like a core file to me" and 
> also noting that compression is something to look at is cool.

What about:

  error: Couldn't recognise core file format of .
  note: If the file is a core file in a compressed file archive, it first needs 
to be manually extracted before it can be loaded.


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

https://reviews.llvm.org/D96939

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


[Lldb-commits] [PATCH] D96939: [lldb] Add a note to the core file loading error message that mentions archives

2021-02-18 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda added a comment.

In D96939#2570830 , @teemperor wrote:

> What about:
>
>   error: Couldn't recognise core file format of .
>   note: If the file is a core file in a compressed file archive, it first 
> needs to be manually extracted before it can be loaded.

Looks good to me.  Although I would write it with the freedom spelling of 
recognize. :)


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

https://reviews.llvm.org/D96939

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


[Lldb-commits] [PATCH] D96939: [lldb] Add a note to the core file loading error message that mentions archives

2021-02-18 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor added a comment.

In D96939#2570831 , @jasonmolenda 
wrote:

> In D96939#2570830 , @teemperor wrote:
>
>> What about:
>>
>>   error: Couldn't recognise core file format of .
>>   note: If the file is a core file in a compressed file archive, it first 
>> needs to be manually extracted before it can be loaded.
>
> Looks good to me.  Although I would write it with the freedom spelling of 
> recognize. :)

We could compromise and spell it as `recogniße` (which combines s and z into 
one letter).


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

https://reviews.llvm.org/D96939

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


[Lldb-commits] [PATCH] D96939: [lldb] Add a note to the core file loading error message that mentions archives

2021-02-18 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda added a comment.

In D96939#2570834 , @teemperor wrote:

> In D96939#2570831 , @jasonmolenda 
> wrote:
>
>> In D96939#2570830 , @teemperor 
>> wrote:
>>
>>> What about:
>>>
>>>   error: Couldn't recognise core file format of .
>>>   note: If the file is a core file in a compressed file archive, it first 
>>> needs to be manually extracted before it can be loaded.
>>
>> Looks good to me.  Although I would write it with the freedom spelling of 
>> recognize. :)
>
> We could compromise and spell it as `recogniße` (which combines s and z into 
> one letter).

im ded. :crabpls:


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

https://reviews.llvm.org/D96939

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


[Lldb-commits] [PATCH] D96939: [lldb] Add a note to the core file loading error message that mentions archives

2021-02-18 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor updated this revision to Diff 324551.
teemperor added a comment.

- Also clarify error message.


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

https://reviews.llvm.org/D96939

Files:
  lldb/source/Commands/CommandObjectTarget.cpp


Index: lldb/source/Commands/CommandObjectTarget.cpp
===
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ lldb/source/Commands/CommandObjectTarget.cpp
@@ -425,8 +425,12 @@
   }
 } else {
   result.AppendErrorWithFormatv(
-  "Unable to find process plug-in for core file '{0}'\n",
+  "Couldn't recognize core file format of '{0}'\n",
   core_file.GetPath());
+  result.AppendMessage(
+  "note: If the file is a core file in a compressed file archive, "
+  "it first needs to be manually extracted before it can be "
+  "loaded.");
   result.SetStatus(eReturnStatusFailed);
 }
   } else {


Index: lldb/source/Commands/CommandObjectTarget.cpp
===
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ lldb/source/Commands/CommandObjectTarget.cpp
@@ -425,8 +425,12 @@
   }
 } else {
   result.AppendErrorWithFormatv(
-  "Unable to find process plug-in for core file '{0}'\n",
+  "Couldn't recognize core file format of '{0}'\n",
   core_file.GetPath());
+  result.AppendMessage(
+  "note: If the file is a core file in a compressed file archive, "
+  "it first needs to be manually extracted before it can be "
+  "loaded.");
   result.SetStatus(eReturnStatusFailed);
 }
   } else {
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D95711: [lldb/Interpreter] Add ScriptInterpreter Wrapper for ScriptedProcess

2021-02-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 324558.
mib added a comment.

Make `ScriptedProcessInterface` a `unique_ptr` instead of `shared_ptr` in 
`ScriptInterpreter`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95711

Files:
  lldb/bindings/python/python-wrapper.swig
  lldb/include/lldb/API/SBData.h
  lldb/include/lldb/API/SBError.h
  lldb/include/lldb/API/SBThreadPlan.h
  lldb/include/lldb/Interpreter/ScriptInterpreter.h
  lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
  lldb/include/lldb/lldb-forward.h
  lldb/source/Interpreter/CMakeLists.txt
  lldb/source/Interpreter/ScriptInterpreter.cpp
  lldb/source/Interpreter/ScriptedProcessInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
  lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
  
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
  lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp

Index: lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
===
--- lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
+++ lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
@@ -12,6 +12,7 @@
 
 #include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h"
 #include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h"
+#include "lldb/API/SBError.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Host/HostInfo.h"
 
@@ -153,6 +154,14 @@
   return 0;
 }
 
+extern "C" void *LLDBSWIGPython_CastPyObjectToSBData(void *data) {
+  return nullptr;
+}
+
+extern "C" void *LLDBSWIGPython_CastPyObjectToSBError(void *data) {
+  return nullptr;
+}
+
 extern "C" void *LLDBSWIGPython_CastPyObjectToSBValue(void *data) {
   return nullptr;
 }
@@ -207,6 +216,13 @@
   return nullptr;
 }
 
+extern "C" void *LLDBSwigPythonCreateScriptedProcess(
+const char *python_class_name, const char *session_dictionary_name,
+const lldb::TargetSP &target_sp, StructuredDataImpl *args_impl,
+std::string &error_string) {
+  return nullptr;
+}
+
 extern "C" void *
 LLDBSWIGPython_CreateFrameRecognizer(const char *python_class_name,
  const char *session_dictionary_name) {
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
===
--- /dev/null
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
@@ -0,0 +1,61 @@
+//===-- ScriptedProcessPythonInterface.h *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPROCESSPYTHONINTERFACE_H
+#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPROCESSPYTHONINTERFACE_H
+
+#include "lldb/Host/Config.h"
+
+#if LLDB_ENABLE_PYTHON
+
+#include "lldb/Interpreter/ScriptedProcessInterface.h"
+
+namespace lldb_private {
+class ScriptInterpreterPythonImpl;
+class ScriptedProcessPythonInterface : public ScriptedProcessInterface {
+public:
+  ScriptedProcessPythonInterface(ScriptInterpreterPythonImpl &interpreter)
+  : ScriptedProcessInterface(), m_interpreter(interpreter) {}
+
+  StructuredData::GenericSP
+  CreatePluginObject(const llvm::StringRef class_name, lldb::TargetSP target_sp,
+ StructuredData::DictionarySP args_sp) override;
+
+  Status Launch() override;
+
+  Status Resume() override;
+
+  lldb::MemoryRegionInfoSP
+  GetMemoryRegionContainingAddress(lldb::addr_t address) override;
+
+  StructuredData::DictionarySP GetThreadWithID(lldb::tid_t tid) override;
+
+  StructuredData::DictionarySP GetRegistersForThread(lldb::tid_t tid) override;
+
+  lldb::DataExtractorSP ReadMemoryAtAddress(lldb::addr_t address, size_t size,
+Status &error) override;
+
+  StructuredData::DictionarySP GetLoadedImages() override;
+
+  lldb::pid_t GetProcessID() override;
+
+  bool IsAlive() override;
+
+protected:
+  size_t GetGenericInteger(llvm::StringRef method_name);
+  Status LaunchOrResume(llvm::StringRef method_name);
+
+private:
+  // The lifetime is managed by the ScriptInterpreter
+  ScriptInterpreterPythonImpl &m_interpreter;
+  StructuredData::GenericSP m_object_instance_sp;
+};
+

[Lldb-commits] [PATCH] D95712: [lldb/bindings] Add Python ScriptedProcess base class to lldb module

2021-02-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 324562.
mib marked 3 inline comments as done.
mib added a comment.

Address @JDevlieghere comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95712

Files:
  lldb/bindings/python/CMakeLists.txt
  lldb/examples/python/scripted_process/my_scripted_process.py
  lldb/examples/python/scripted_process/scripted_process.py
  lldb/test/API/functionalities/scripted_process/Makefile
  lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
  lldb/test/API/functionalities/scripted_process/main.c

Index: lldb/test/API/functionalities/scripted_process/main.c
===
--- /dev/null
+++ lldb/test/API/functionalities/scripted_process/main.c
@@ -0,0 +1,5 @@
+#include 
+
+int main() {
+  return 0; // break here
+}
Index: lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
===
--- /dev/null
+++ lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
@@ -0,0 +1,45 @@
+"""
+Test python scripted process in lldb
+"""
+
+import os
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+from lldbsuite.test import lldbtest
+
+
+class PlatformProcessCrashInfoTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def setUp(self):
+TestBase.setUp(self)
+self.source = "main.c"
+
+def tearDown(self):
+TestBase.tearDown(self)
+
+def test_python_plugin_package(self):
+"""Test that the lldb python module has a `plugins.scripted_process`
+package."""
+self.expect('script import lldb.plugins',
+substrs=["ModuleNotFoundError"], matching=False)
+
+self.expect('script dir(lldb.plugins)',
+substrs=["scripted_process"])
+
+self.expect('script import lldb.plugins.scripted_process',
+substrs=["ModuleNotFoundError"], matching=False)
+
+self.expect('script dir(lldb.plugins.scripted_process)',
+substrs=["ScriptedProcess"])
+
+self.expect('script from lldb.plugins.scripted_process import ScriptedProcess',
+substrs=["ImportError"], matching=False)
+
+self.expect('script dir(ScriptedProcess)',
+substrs=["launch"])
+
Index: lldb/test/API/functionalities/scripted_process/Makefile
===
--- /dev/null
+++ lldb/test/API/functionalities/scripted_process/Makefile
@@ -0,0 +1,4 @@
+C_SOURCES := main.c
+
+include Makefile.rules
+
Index: lldb/examples/python/scripted_process/scripted_process.py
===
--- /dev/null
+++ lldb/examples/python/scripted_process/scripted_process.py
@@ -0,0 +1,179 @@
+from abc import ABCMeta, abstractmethod
+import six
+
+import lldb
+
+@six.add_metaclass(ABCMeta)
+class ScriptedProcess:
+
+"""
+The base class for a scripted process.
+
+Most of the base class methods are `@abstractmethod` that need to be
+overwritten by the inheriting class.
+
+DISCLAIMER: THIS INTERFACE IS STILL UNDER DEVELOPMENT AND NOT STABLE.
+THE METHODS EXPOSED MIGHT CHANGE IN THE FUTURE.
+
+args (lldb.SBStructuredData): Dictionary holding arbitrary values
+target (lldb.SBTarget): Target launching the scripted process.
+
+get_memory_region_containing_address(addr: int) -> lldb.SBMemoryRegionInfo:
+Get the memory region for the scripted process, containing a
+specific address.
+
+get_thread_with_id(tid: int) -> Dict:
+Get the scripted process thread with a specific ID.
+
+get_registers_for_thread(tid:int) -> Dict:
+Get the register context dictionary for a certain thread.
+
+read_memory_at_address(addr:int, size:int) -> lldb.SBData:
+Get a memory buffer from the scripted process at a certain address,
+of a certain size.
+
+get_loaded_images() -> List:
+Get the list of loaded images for the scripted process.
+
+get_process_id() -> int:
+Get the scripted process identifier.
+
+launch() -> lldb.SBError:
+Simulate the scripted process launch.
+
+resume() -> lldb.SBError:
+Simulate the scripted process resume.
+
+is_alive() -> bool:
+Check if the scripted process is alive.
+"""
+
+@abstractmethod
+def __init__(self, target, args):
+""" Construct a scripted process.
+
+Args:
+target (lldb.SBTarget): The target launching the scripted process.
+args (lldb.SBStructuredData): A Dictionary holding arbitrary
+key/value pairs used by the scripted process.
+"""
+self.target = None
+self.args = None
+if 

[Lldb-commits] [PATCH] D95713: [lldb/Plugins] Add ScriptedProcess Process Plugin

2021-02-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 324564.
mib marked 4 inline comments as done.
mib added a comment.

Address @JDevlieghere feedbacks:

- Make test more portable
- Add helper function to get the `ScriptedProcessInterface`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95713

Files:
  lldb/bindings/python/CMakeLists.txt
  lldb/examples/python/scripted_process/my_scripted_process.py
  lldb/examples/python/scripted_process/scripted_process.py
  lldb/include/lldb/Target/Process.h
  lldb/source/Plugins/Process/CMakeLists.txt
  lldb/source/Plugins/Process/scripted/CMakeLists.txt
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
  lldb/source/Plugins/Process/scripted/ScriptedProcess.h
  lldb/source/Target/Target.cpp
  lldb/test/API/functionalities/scripted_process/Makefile
  lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
  lldb/test/API/functionalities/scripted_process/main.c

Index: lldb/test/API/functionalities/scripted_process/main.c
===
--- /dev/null
+++ lldb/test/API/functionalities/scripted_process/main.c
@@ -0,0 +1,5 @@
+#include 
+
+int main() {
+  return 0; // break here
+}
Index: lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
===
--- /dev/null
+++ lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
@@ -0,0 +1,67 @@
+"""
+Test python scripted process in lldb
+"""
+
+import os
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+from lldbsuite.test import lldbtest
+
+
+class PlatformProcessCrashInfoTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def setUp(self):
+TestBase.setUp(self)
+self.source = "main.c"
+
+def tearDown(self):
+TestBase.tearDown(self)
+
+def test_python_plugin_package(self):
+"""Test that the lldb python module has a `plugins.scripted_process`
+package."""
+self.expect('script import lldb.plugins',
+substrs=["ModuleNotFoundError"], matching=False)
+
+self.expect('script dir(lldb.plugins)',
+substrs=["scripted_process"])
+
+self.expect('script import lldb.plugins.scripted_process',
+substrs=["ModuleNotFoundError"], matching=False)
+
+self.expect('script dir(lldb.plugins.scripted_process)',
+substrs=["ScriptedProcess"])
+
+self.expect('script from lldb.plugins.scripted_process import ScriptedProcess',
+substrs=["ImportError"], matching=False)
+
+self.expect('script dir(ScriptedProcess)',
+substrs=["launch"])
+
+
+
+def test_launch_scripted_process(self):
+"""Test that we can launch an lldb scripted process and check its
+process ID """
+self.build()
+target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
+self.assertTrue(target, VALID_TARGET)
+
+scripted_process_example_relpath = ['..','..','..','..','examples','python','scripted_process','my_scripted_process.py']
+os.environ['SKIP_SCRIPTED_PROCESS_LAUNCH'] = '1'
+self.runCmd("command script import " + os.path.join(self.getSourceDir(),
+scripted_process_example_relpath))
+
+launch_info = lldb.SBLaunchInfo(None)
+launch_info.SetProcessPluginName('ScriptedProcess')
+launch_info.SetScriptedProcessClassName('my_scripted_process.MyScriptedProcess')
+
+error = lldb.SBError()
+process = target.Launch(launch_info, error)
+self.assertTrue(process, PROCESS_IS_VALID)
+self.assertEqual(process.GetProcessID(), 42)
Index: lldb/test/API/functionalities/scripted_process/Makefile
===
--- /dev/null
+++ lldb/test/API/functionalities/scripted_process/Makefile
@@ -0,0 +1,4 @@
+C_SOURCES := main.c
+
+include Makefile.rules
+
Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -2950,7 +2950,7 @@
   // If we're not already connected to the process, and if we have a platform
   // that can launch a process for debugging, go ahead and do that here.
   if (state != eStateConnected && platform_sp &&
-  platform_sp->CanDebugProcess()) {
+  platform_sp->CanDebugProcess() && !launch_info.IsScriptedProcess()) {
 LLDB_LOGF(log, "Target::%s asking the platform to debug the process",
   __FUNCTION__);
 
Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.h
===
--- /dev/null
+++ lldb/source/Plugins/Process/s

[Lldb-commits] [PATCH] D96947: [lldb] Prevent double new lines behind errors/warning/messages from LLDB commands

2021-02-18 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor created this revision.
teemperor added a reviewer: LLDB.
teemperor added a project: LLDB.
Herald added a subscriber: JDevlieghere.
teemperor requested review of this revision.

The current API for printing errors/warnings/messages from LLDB commands 
sometimes
adds newlines behind the messages for the caller. However, this happens 
unconditionally
so when the caller already specified a trailing newline in the error message 
(or is trying to print
a generated error message that ends in a newline), LLDB ends up printing both 
the automatically
added newline and the one that was in the error message string. This leads to 
all the randomly
appearing new lines in error such as:

  (lldb) command a
  error: 'command alias' requires at least two arguments
  (lldb) apropos a b
  error: 'apropos' must be called with exactly one argument.
  
  (lldb) why is there an empty line behind the second error?

This code adds a check that only appends the new line if the passed message 
doesn't already
contain a trailing new line.


https://reviews.llvm.org/D96947

Files:
  lldb/include/lldb/Interpreter/CommandReturnObject.h
  lldb/source/Commands/CommandObjectMemory.cpp
  lldb/source/Interpreter/CommandReturnObject.cpp
  lldb/test/Shell/Commands/command-disassemble.s


Index: lldb/test/Shell/Commands/command-disassemble.s
===
--- lldb/test/Shell/Commands/command-disassemble.s
+++ lldb/test/Shell/Commands/command-disassemble.s
@@ -6,16 +6,12 @@
 
 # CHECK:  (lldb) disassemble
 # CHECK-NEXT: error: Cannot disassemble around the current function without a 
selected frame.
-# CHECK-EMPTY:
 # CHECK-NEXT: (lldb) disassemble --line
 # CHECK-NEXT: error: Cannot disassemble around the current line without a 
selected frame.
-# CHECK-EMPTY:
 # CHECK-NEXT: (lldb) disassemble --frame
 # CHECK-NEXT: error: Cannot disassemble around the current function without a 
selected frame.
-# CHECK-EMPTY:
 # CHECK-NEXT: (lldb) disassemble --pc
 # CHECK-NEXT: error: Cannot disassemble around the current PC without a 
selected frame.
-# CHECK-EMPTY:
 # CHECK-NEXT: (lldb) disassemble --start-address 0x0
 # CHECK-NEXT: command-disassemble.s.tmp`foo:
 # CHECK-NEXT: command-disassemble.s.tmp[0x0] <+0>:   int$0x10
Index: lldb/source/Interpreter/CommandReturnObject.cpp
===
--- lldb/source/Interpreter/CommandReturnObject.cpp
+++ lldb/source/Interpreter/CommandReturnObject.cpp
@@ -90,28 +90,25 @@
 void CommandReturnObject::AppendMessage(llvm::StringRef in_string) {
   if (in_string.empty())
 return;
-  GetOutputStream() << in_string << "\n";
+  GetOutputStream() << in_string;
+  if (!in_string.endswith("\n"))
+GetOutputStream() << '\n';
 }
 
 void CommandReturnObject::AppendWarning(llvm::StringRef in_string) {
   if (in_string.empty())
 return;
-  warning(GetErrorStream()) << in_string << '\n';
-}
-
-// Similar to AppendWarning, but do not prepend 'warning: ' to message, and
-// don't append "\n" to the end of it.
-
-void CommandReturnObject::AppendRawWarning(llvm::StringRef in_string) {
-  if (in_string.empty())
-return;
-  GetErrorStream() << in_string;
+  warning(GetErrorStream()) << in_string;
+  if (!in_string.endswith("\n"))
+GetErrorStream() << '\n';
 }
 
 void CommandReturnObject::AppendError(llvm::StringRef in_string) {
   if (in_string.empty())
 return;
-  error(GetErrorStream()) << in_string << '\n';
+  error(GetErrorStream()) << in_string;
+  if (!in_string.endswith("\n"))
+GetErrorStream() << '\n';
 }
 
 void CommandReturnObject::SetError(const Status &error,
Index: lldb/source/Commands/CommandObjectMemory.cpp
===
--- lldb/source/Commands/CommandObjectMemory.cpp
+++ lldb/source/Commands/CommandObjectMemory.cpp
@@ -356,8 +356,8 @@
   result.AppendErrorWithFormat("%s takes a start address expression with "
"an optional end address expression.\n",
m_cmd_name.c_str());
-  result.AppendRawWarning("Expressions should be quoted if they contain "
-  "spaces or other special characters.\n");
+  result.AppendWarning("Expressions should be quoted if they contain "
+   "spaces or other special characters.");
   result.SetStatus(eReturnStatusFailed);
   return false;
 }
Index: lldb/include/lldb/Interpreter/CommandReturnObject.h
===
--- lldb/include/lldb/Interpreter/CommandReturnObject.h
+++ lldb/include/lldb/Interpreter/CommandReturnObject.h
@@ -95,8 +95,6 @@
   void AppendMessageWithFormat(const char *format, ...)
   __attribute__((format(printf, 2, 3)));
 
-  void AppendRawWarning(llvm::StringRef in_string);
-
   void AppendWarning(llvm::StringRef in_string);
 
   void AppendWarningWithFormat(const char *forma

[Lldb-commits] [PATCH] D96947: [lldb] Prevent double new lines behind errors/warning/messages from LLDB commands

2021-02-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib accepted this revision.
mib added a comment.
This revision is now accepted and ready to land.

LGTM!


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

https://reviews.llvm.org/D96947

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


[Lldb-commits] [PATCH] D96947: [lldb] Prevent double new lines behind errors/warning/messages from LLDB commands

2021-02-18 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor added a comment.

FWIW, I am very interested in finding out how we can over-engineer this. I do 
believe there is potential to let tablegen generate the error message strings 
which then could also check the new lines for us.


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

https://reviews.llvm.org/D96947

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


[Lldb-commits] [PATCH] D96947: [lldb] Prevent double new lines behind errors/warning/messages from LLDB commands

2021-02-18 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor added a comment.

Also I'm going to clean the existing error messages from redundant newlines in 
a separate NFC commit.


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

https://reviews.llvm.org/D96947

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


[Lldb-commits] [PATCH] D95711: [lldb/Interpreter] Add ScriptInterpreter Wrapper for ScriptedProcess

2021-02-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 324579.
mib added a comment.

Remove `ScriptedProcessInterface.cpp` from the Interpreter's `CMakeLists.txt` 
since the file doesn't exist.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95711

Files:
  lldb/bindings/python/python-wrapper.swig
  lldb/include/lldb/API/SBData.h
  lldb/include/lldb/API/SBError.h
  lldb/include/lldb/API/SBThreadPlan.h
  lldb/include/lldb/Interpreter/ScriptInterpreter.h
  lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
  lldb/include/lldb/lldb-forward.h
  lldb/source/Interpreter/ScriptInterpreter.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
  lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
  
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
  lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp

Index: lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
===
--- lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
+++ lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
@@ -12,6 +12,7 @@
 
 #include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h"
 #include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h"
+#include "lldb/API/SBError.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Host/HostInfo.h"
 
@@ -153,6 +154,14 @@
   return 0;
 }
 
+extern "C" void *LLDBSWIGPython_CastPyObjectToSBData(void *data) {
+  return nullptr;
+}
+
+extern "C" void *LLDBSWIGPython_CastPyObjectToSBError(void *data) {
+  return nullptr;
+}
+
 extern "C" void *LLDBSWIGPython_CastPyObjectToSBValue(void *data) {
   return nullptr;
 }
@@ -207,6 +216,13 @@
   return nullptr;
 }
 
+extern "C" void *LLDBSwigPythonCreateScriptedProcess(
+const char *python_class_name, const char *session_dictionary_name,
+const lldb::TargetSP &target_sp, StructuredDataImpl *args_impl,
+std::string &error_string) {
+  return nullptr;
+}
+
 extern "C" void *
 LLDBSWIGPython_CreateFrameRecognizer(const char *python_class_name,
  const char *session_dictionary_name) {
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
===
--- /dev/null
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
@@ -0,0 +1,61 @@
+//===-- ScriptedProcessPythonInterface.h *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPROCESSPYTHONINTERFACE_H
+#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPROCESSPYTHONINTERFACE_H
+
+#include "lldb/Host/Config.h"
+
+#if LLDB_ENABLE_PYTHON
+
+#include "lldb/Interpreter/ScriptedProcessInterface.h"
+
+namespace lldb_private {
+class ScriptInterpreterPythonImpl;
+class ScriptedProcessPythonInterface : public ScriptedProcessInterface {
+public:
+  ScriptedProcessPythonInterface(ScriptInterpreterPythonImpl &interpreter)
+  : ScriptedProcessInterface(), m_interpreter(interpreter) {}
+
+  StructuredData::GenericSP
+  CreatePluginObject(const llvm::StringRef class_name, lldb::TargetSP target_sp,
+ StructuredData::DictionarySP args_sp) override;
+
+  Status Launch() override;
+
+  Status Resume() override;
+
+  lldb::MemoryRegionInfoSP
+  GetMemoryRegionContainingAddress(lldb::addr_t address) override;
+
+  StructuredData::DictionarySP GetThreadWithID(lldb::tid_t tid) override;
+
+  StructuredData::DictionarySP GetRegistersForThread(lldb::tid_t tid) override;
+
+  lldb::DataExtractorSP ReadMemoryAtAddress(lldb::addr_t address, size_t size,
+Status &error) override;
+
+  StructuredData::DictionarySP GetLoadedImages() override;
+
+  lldb::pid_t GetProcessID() override;
+
+  bool IsAlive() override;
+
+protected:
+  size_t GetGenericInteger(llvm::StringRef method_name);
+  Status LaunchOrResume(llvm::StringRef method_name);
+
+private:
+  // The lifetime is managed by the ScriptInterpreter
+  ScriptInterpreterPythonImpl &m_interpreter;
+  StructuredData::GenericSP m_object_instance_sp;
+};
+} // namespace lldb_private
+
+#endif // LLDB_ENABLE_PYTHON
+#endif // LLDB_PLUGIN

[Lldb-commits] [PATCH] D96947: [lldb] Prevent double new lines behind errors/warning/messages from LLDB commands

2021-02-18 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett added a comment.

Thanks for looking at this, I had the same confusion adding some new commands.


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

https://reviews.llvm.org/D96947

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


[Lldb-commits] [PATCH] D95713: [lldb/Plugins] Add ScriptedProcess Process Plugin

2021-02-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 324587.
mib added a comment.

Fix test typo.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95713

Files:
  lldb/bindings/python/CMakeLists.txt
  lldb/include/lldb/Target/Process.h
  lldb/source/Plugins/Process/CMakeLists.txt
  lldb/source/Plugins/Process/scripted/CMakeLists.txt
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
  lldb/source/Plugins/Process/scripted/ScriptedProcess.h
  lldb/source/Target/Target.cpp
  lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py

Index: lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
===
--- lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
+++ lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
@@ -11,7 +11,7 @@
 from lldbsuite.test import lldbtest
 
 
-class PlatformProcessCrashInfoTestCase(TestBase):
+class ScriptedProcesTestCase(TestBase):
 
 mydir = TestBase.compute_mydir(__file__)
 
@@ -43,3 +43,23 @@
 self.expect('script dir(ScriptedProcess)',
 substrs=["launch"])
 
+def test_launch_scripted_process(self):
+"""Test that we can launch an lldb scripted process and check its
+process ID """
+self.build()
+target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
+self.assertTrue(target, VALID_TARGET)
+
+scripted_process_example_relpath = ['..','..','..','..','examples','python','scripted_process','my_scripted_process.py']
+os.environ['SKIP_SCRIPTED_PROCESS_LAUNCH'] = '1'
+self.runCmd("command script import " + os.path.join(self.getSourceDir(),
+*scripted_process_example_relpath))
+
+launch_info = lldb.SBLaunchInfo(None)
+launch_info.SetProcessPluginName('ScriptedProcess')
+launch_info.SetScriptedProcessClassName('my_scripted_process.MyScriptedProcess')
+
+error = lldb.SBError()
+process = target.Launch(launch_info, error)
+self.assertTrue(process, PROCESS_IS_VALID)
+self.assertEqual(process.GetProcessID(), 42)
Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -2950,7 +2950,7 @@
   // If we're not already connected to the process, and if we have a platform
   // that can launch a process for debugging, go ahead and do that here.
   if (state != eStateConnected && platform_sp &&
-  platform_sp->CanDebugProcess()) {
+  platform_sp->CanDebugProcess() && !launch_info.IsScriptedProcess()) {
 LLDB_LOGF(log, "Target::%s asking the platform to debug the process",
   __FUNCTION__);
 
Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.h
===
--- /dev/null
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.h
@@ -0,0 +1,111 @@
+//===-- ScriptedProcess.h - -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLDB_SOURCE_PLUGINS_SCRIPTED_PROCESS_H
+#define LLDB_SOURCE_PLUGINS_SCRIPTED_PROCESS_H
+
+#include "lldb/Target/Process.h"
+#include "lldb/Utility/ConstString.h"
+#include "lldb/Utility/Status.h"
+
+namespace lldb_private {
+
+class ScriptedProcess : public Process {
+protected:
+  class LaunchInfo {
+  public:
+LaunchInfo(const ProcessLaunchInfo &launch_info) {
+  m_class_name = launch_info.GetScriptedProcessClassName();
+  m_dictionary_sp = launch_info.GetScriptedProcessDictionarySP();
+}
+
+std::string GetClassName() const { return m_class_name; }
+StructuredData::DictionarySP GetDictionarySP() const {
+  return m_dictionary_sp;
+}
+
+  private:
+std::string m_class_name;
+StructuredData::DictionarySP m_dictionary_sp;
+  };
+
+public:
+  static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp,
+lldb::ListenerSP listener_sp,
+const FileSpec *crash_file_path,
+bool can_connect);
+
+  static void Initialize();
+
+  static void Terminate();
+
+  static ConstString GetPluginNameStatic();
+
+  static const char *GetPluginDescriptionStatic();
+
+  ScriptedProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
+  const ScriptedProcess::LaunchInfo &launch_info);
+
+  ~ScriptedProcess() override;
+
+  bool CanDebug(lldb::TargetSP target_sp,
+bool plugin_specified_by_name

[Lldb-commits] [PATCH] D96807: Modify TypePrinter to differentiate between anonymous struct and unnamed struct

2021-02-18 Thread Aaron Ballman via Phabricator via lldb-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!


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

https://reviews.llvm.org/D96807

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


[Lldb-commits] [lldb] 004a264 - [lldb] Fix shared library directory computation on windows

2021-02-18 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2021-02-18T15:37:52+01:00
New Revision: 004a264f8c923922ecd34255bcb10f4adaa27ac5

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

LOG: [lldb] Fix shared library directory computation on windows

Our code for locating the shared library directory works via dladdr (or
the windows equivalent) to locate the path of an address known to reside
in liblldb. This works great for C++ programs, but there's a catch.

When (lib)lldb is used from python (like in our test suite), this dladdr
call will return a path to the _lldb.so (or such) file in the python
directory. To compensate for this, we have code which attempts to
resolve this symlink, to ensure we get the canonical location. However,
here's the second catch.

On windows, this file is not a symlink (but a copy), so this logic
fails. Since most of our other paths are derived from the liblldb
location, all of these paths will be wrong, when running the test suite.
One effect of this was the failure to find lldb-server in D96202.

To fix this issue, I add some windows-specific code to locate the
liblldb directory. Since it cannot rely on symlinks, it works by
manually walking the directory tree -- essentially doing the opposite of
what we do when computing the python directory.

To avoid python leaking back into the host code, I implement this with
the help of a callback which can be passed to HostInfo::Initialize in
order to assist with the directory location. The callback lives inside
the python plugin.

I also strenghten the existing path test to ensure the returned path is
the right one.

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

Added: 


Modified: 
lldb/include/lldb/Host/HostInfoBase.h
lldb/include/lldb/Host/linux/HostInfoLinux.h
lldb/include/lldb/Host/windows/HostInfoWindows.h
lldb/include/lldb/Initialization/SystemInitializerCommon.h
lldb/source/API/SystemInitializerFull.cpp
lldb/source/Host/common/HostInfoBase.cpp
lldb/source/Host/linux/HostInfoLinux.cpp
lldb/source/Host/windows/HostInfoWindows.cpp
lldb/source/Initialization/SystemInitializerCommon.cpp
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
lldb/test/API/functionalities/paths/TestPaths.py
lldb/tools/lldb-server/SystemInitializerLLGS.h
lldb/tools/lldb-test/SystemInitializerTest.cpp

Removed: 




diff  --git a/lldb/include/lldb/Host/HostInfoBase.h 
b/lldb/include/lldb/Host/HostInfoBase.h
index 15bb168aad97..b4fbd88c9304 100644
--- a/lldb/include/lldb/Host/HostInfoBase.h
+++ b/lldb/include/lldb/Host/HostInfoBase.h
@@ -37,7 +37,13 @@ class HostInfoBase {
   ~HostInfoBase() {}
 
 public:
-  static void Initialize();
+  /// A helper function for determining the liblldb location. It receives a
+  /// FileSpec with the location of file containing _this_ code. It can
+  /// (optionally) replace it with a file spec pointing to a more canonical
+  /// copy.
+  using SharedLibraryDirectoryHelper = void(FileSpec &this_file);
+
+  static void Initialize(SharedLibraryDirectoryHelper *helper = nullptr);
   static void Terminate();
 
   /// Gets the host target triple.

diff  --git a/lldb/include/lldb/Host/linux/HostInfoLinux.h 
b/lldb/include/lldb/Host/linux/HostInfoLinux.h
index b1c7f9c805bf..e8080033cd8f 100644
--- a/lldb/include/lldb/Host/linux/HostInfoLinux.h
+++ b/lldb/include/lldb/Host/linux/HostInfoLinux.h
@@ -27,7 +27,7 @@ class HostInfoLinux : public HostInfoPosix {
   ~HostInfoLinux();
 
 public:
-  static void Initialize();
+  static void Initialize(SharedLibraryDirectoryHelper *helper = nullptr);
 
   static llvm::VersionTuple GetOSVersion();
   static bool GetOSBuildString(std::string &s);

diff  --git a/lldb/include/lldb/Host/windows/HostInfoWindows.h 
b/lldb/include/lldb/Host/windows/HostInfoWindows.h
index 209d9da08214..400a3f4649bd 100644
--- a/lldb/include/lldb/Host/windows/HostInfoWindows.h
+++ b/lldb/include/lldb/Host/windows/HostInfoWindows.h
@@ -25,7 +25,7 @@ class HostInfoWindows : public HostInfoBase {
   ~HostInfoWindows();
 
 public:
-  static void Initialize();
+  static void Initialize(SharedLibraryDirectoryHelper *helper = nullptr);
   static void Terminate();
 
   static size_t GetPageSize();

diff  --git a/lldb/include/lldb/Initialization/SystemInitializerCommon.h 
b/lldb/include/lldb/Initialization/SystemInitializerCommon.h
index 3a5081680879..d918b1125a57 100644
--- a/lldb/include/lldb/Initialization/SystemInitializerCommon.h
+++ b/lldb/include/lldb/Initialization/SystemInitializerCommon.h
@@ -10,6 +10,7 @@
 #define LLDB_INITIALIZATION_SYSTEMINITIALIZERCOMMON_H
 
 #include "SystemInitializer.h"
+#include "lldb/Host/HostInfo.h"
 
 namespace lldb_private {
 /// Init

[Lldb-commits] [PATCH] D96779: [lldb] Fix shared library directory computation on windows

2021-02-18 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 rG004a264f8c92: [lldb] Fix shared library directory 
computation on windows (authored by labath).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96779

Files:
  lldb/include/lldb/Host/HostInfoBase.h
  lldb/include/lldb/Host/linux/HostInfoLinux.h
  lldb/include/lldb/Host/windows/HostInfoWindows.h
  lldb/include/lldb/Initialization/SystemInitializerCommon.h
  lldb/source/API/SystemInitializerFull.cpp
  lldb/source/Host/common/HostInfoBase.cpp
  lldb/source/Host/linux/HostInfoLinux.cpp
  lldb/source/Host/windows/HostInfoWindows.cpp
  lldb/source/Initialization/SystemInitializerCommon.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
  lldb/test/API/functionalities/paths/TestPaths.py
  lldb/tools/lldb-server/SystemInitializerLLGS.h
  lldb/tools/lldb-test/SystemInitializerTest.cpp

Index: lldb/tools/lldb-test/SystemInitializerTest.cpp
===
--- lldb/tools/lldb-test/SystemInitializerTest.cpp
+++ lldb/tools/lldb-test/SystemInitializerTest.cpp
@@ -22,7 +22,8 @@
 
 using namespace lldb_private;
 
-SystemInitializerTest::SystemInitializerTest() = default;
+SystemInitializerTest::SystemInitializerTest()
+: SystemInitializerCommon(nullptr) {}
 SystemInitializerTest::~SystemInitializerTest() = default;
 
 llvm::Error SystemInitializerTest::Initialize() {
Index: lldb/tools/lldb-server/SystemInitializerLLGS.h
===
--- lldb/tools/lldb-server/SystemInitializerLLGS.h
+++ lldb/tools/lldb-server/SystemInitializerLLGS.h
@@ -14,6 +14,8 @@
 
 class SystemInitializerLLGS : public lldb_private::SystemInitializerCommon {
 public:
+  SystemInitializerLLGS() : SystemInitializerCommon(nullptr) {}
+
   llvm::Error Initialize() override;
   void Terminate() override;
 };
Index: lldb/test/API/functionalities/paths/TestPaths.py
===
--- lldb/test/API/functionalities/paths/TestPaths.py
+++ lldb/test/API/functionalities/paths/TestPaths.py
@@ -8,6 +8,7 @@
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 from lldbsuite.test import lldbutil
+from lldbsuite.test import lldbplatformutil
 
 
 class TestPaths(TestBase):
@@ -29,7 +30,18 @@
 for path_type in dir_path_types:
 f = lldb.SBHostOS.GetLLDBPath(path_type)
 # No directory path types should have the filename set
-self.assertTrue(f.GetFilename() is None)
+self.assertIsNone(f.GetFilename())
+
+shlib_dir = lldb.SBHostOS.GetLLDBPath(lldb.ePathTypeLLDBShlibDir).GetDirectory()
+if lldbplatformutil.getHostPlatform() == 'windows':
+filenames = ['liblldb.dll']
+elif lldbplatformutil.getHostPlatform() == 'darwin':
+filenames = ['LLDB', 'liblldb.dylib']
+else:
+filenames = ['liblldb.so']
+self.assertTrue(any([os.path.exists(os.path.join(shlib_dir, f)) for f in
+filenames]), "shlib_dir = " + shlib_dir)
+
 
 @no_debug_info_test
 def test_directory_doesnt_end_with_slash(self):
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
@@ -51,6 +51,7 @@
   static lldb_private::ConstString GetPluginNameStatic();
   static const char *GetPluginDescriptionStatic();
   static FileSpec GetPythonDir();
+  static void SharedLibraryDirectoryHelper(FileSpec &this_file);
 
 protected:
   static void ComputePythonDirForApple(llvm::SmallVectorImpl &path);
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -410,6 +410,31 @@
   return g_spec;
 }
 
+void ScriptInterpreterPython::SharedLibraryDirectoryHelper(
+FileSpec &this_file) {
+  // When we're loaded from python, this_file will point to the file inside the
+  // python package directory. Replace it with the one in the lib directory.
+#ifdef _WIN32
+  // On windows, we need to manually back out of the python tree, and go into
+  // the bin directory. This is pretty much the inverse of what ComputePythonDir
+  // does.
+  if (this_file.GetFileNameExtension() == ConstString(".pyd")) {
+this_file.RemoveLastPathComponent(); // _lldb.pyd or _lldb_d.pyd
+this_file.RemoveLastPathCompo

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

2021-02-18 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

Yeah, I'm with Greg. Although I would recommend using lit tests in general, I 
don't think they're a good fit for anything that involves attaching, or other 
kinds of inter-process synchronization. Once you start dealing with 
subprocesses you're entering very messy (and unportable) waters. Just make this 
a dotest test. You can base this off of one of the existing attach tests 
there...

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

I don't think this does what you think it does. The `$()` doesn't give you the 
process id of anything -- it substitutes a string by the result of running that 
string **as a shell command**. So, the PID variable would get the (entire) 
stdout of `%s.out`. Obviously, the command has to terminate in order for it to 
be able to compute that...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96637

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


[Lldb-commits] [PATCH] D96548: [lldb] [Process/FreeBSDRemote] Introduce aarch64 hw break/watchpoint support

2021-02-18 Thread Mitchell Horne via Phabricator via lldb-commits
mhorne added a comment.

The FreeBSD API usage looks correct to me, but I can't comment on too much more 
than that. The code could benefit from fewer unnamed constants.

I should also note that it is my intention to merge the FreeBSD watchpoint 
patches into the 13.0 branch, in about a week's time. So your 
`__FreeBSD_version` checks will need to be updated after that point.




Comment at: 
lldb/source/Plugins/Process/Utility/NativeRegisterContextBreakWatchpoint_arm64.cpp:57
+  control_value |= ((1 << size) - 1) << 5;
+  control_value |= (2 << 1) | 1;
+

These magic numbers would be better with names. I see quite a few instances of 
checking/setting the enable bit, but it is not obvious what is being done 
unless you already understand the control register layout.


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

https://reviews.llvm.org/D96548

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


[Lldb-commits] [PATCH] D96817: Fix deep copying for OptionValue classes

2021-02-18 Thread Tatyana Krasnukha via Phabricator via lldb-commits
tatyana-krasnukha added a comment.

I created D96817  - a demonstrative example of 
the CRTP-based version of this patch. Please, take a look.


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

https://reviews.llvm.org/D96817

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


[Lldb-commits] [PATCH] D96548: [lldb] [Process/FreeBSDRemote] Introduce aarch64 hw break/watchpoint support

2021-02-18 Thread Tatyana Krasnukha via Phabricator via lldb-commits
tatyana-krasnukha added a comment.

clang-tidy would not be happy;)




Comment at: lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp:665
+return SetHardwareBreakpoint(addr, size);
   else
 return SetSoftwareBreakpoint(addr, size);

Redundant `else` after `return`.



Comment at: 
lldb/source/Plugins/Process/Utility/NativeRegisterContextBreakWatchpoint_arm64.cpp:441
+return m_hwp_regs[wp_index].real_addr;
+  else
+return LLDB_INVALID_ADDRESS;

Redundant `else` after `return`.



Comment at: 
lldb/source/Plugins/Process/Utility/NativeRegisterContextBreakWatchpoint_arm64.cpp:456
+return m_hwp_regs[wp_index].hit_addr;
+  else
+return LLDB_INVALID_ADDRESS;

Redundant `else` after `return`.


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

https://reviews.llvm.org/D96548

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


[Lldb-commits] [lldb] 1b8d2ec - [lldb] Un-XFAIL TestFormatters on windows

2021-02-18 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2021-02-18T18:47:20+01:00
New Revision: 1b8d2ec07142d3517c0236064b1b8d281319b02a

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

LOG: [lldb] Un-XFAIL TestFormatters on windows

The test passes after D96779.

Added: 


Modified: 
lldb/test/API/commands/expression/formatters/TestFormatters.py

Removed: 




diff  --git a/lldb/test/API/commands/expression/formatters/TestFormatters.py 
b/lldb/test/API/commands/expression/formatters/TestFormatters.py
index b400c6daa6d0..dda773e29e91 100644
--- a/lldb/test/API/commands/expression/formatters/TestFormatters.py
+++ b/lldb/test/API/commands/expression/formatters/TestFormatters.py
@@ -21,7 +21,6 @@ def setUp(self):
 self.line = line_number('main.cpp',
 '// Stop here')
 
-@expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765")
 @skipIfTargetAndroid()  # skipping to avoid crashing the test runner
 @expectedFailureAndroid('llvm.org/pr24691')  # we hit an assertion in clang
 def test(self):



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


[Lldb-commits] [lldb] 612384f - [lldb] Remove unused code in ScriptInterpreterPython

2021-02-18 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2021-02-18T10:38:54-08:00
New Revision: 612384f6e01194a4689b6663f039145b3d01ddce

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

LOG: [lldb] Remove unused code in ScriptInterpreterPython

Remove the unused code I noticed when working on d6e80578fc5e and do
some other minor cleanups in the vicinity.

Added: 


Modified: 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

Removed: 




diff  --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp 
b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index 68409b724905..b3f72066195b 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -2877,7 +2877,7 @@ bool ScriptInterpreterPythonImpl::LoadScriptingModule(
   bool does_contain = false;
   // this call will succeed if the module was ever imported in any Debugger
   // in the lifetime of the process in which this LLDB framework is living
-  bool was_imported_globally =
+  const bool was_imported_globally =
   (ExecuteOneLineWithReturn(
command_stream.GetData(),
ScriptInterpreterPythonImpl::eScriptReturnTypeBool, &does_contain,
@@ -2885,20 +2885,15 @@ bool ScriptInterpreterPythonImpl::LoadScriptingModule(
.SetEnableIO(false)
.SetSetLLDBGlobals(false)) &&
does_contain);
-  // this call will fail if the module was not imported in this Debugger
-  // before
-  command_stream.Clear();
-  command_stream.Printf("sys.getrefcount(%s)", module_name.c_str());
-  bool was_imported_locally = GetSessionDictionary()
-  .GetItemForKey(PythonString(module_name))
-  .IsAllocated();
-
-  bool was_imported = (was_imported_globally || was_imported_locally);
+  const bool was_imported_locally =
+  GetSessionDictionary()
+  .GetItemForKey(PythonString(module_name))
+  .IsAllocated();
 
   // now actually do the import
   command_stream.Clear();
 
-  if (was_imported) {
+  if (was_imported_globally || was_imported_locally) {
 if (!was_imported_locally)
   command_stream.Printf("import %s ; reload_module(%s)",
 module_name.c_str(), module_name.c_str());



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


[Lldb-commits] [PATCH] D95712: [lldb/bindings] Add Python ScriptedProcess base class to lldb module

2021-02-18 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision as: JDevlieghere.
JDevlieghere added a comment.

This LGTM. @labath are you fine with landing this and incrementally improving 
the interface?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95712

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


[Lldb-commits] [PATCH] D95713: [lldb/Plugins] Add ScriptedProcess Process Plugin

2021-02-18 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.
This revision is now accepted and ready to land.

This LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95713

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


[Lldb-commits] [PATCH] D96778: [lldb] Fix handling of `DW_AT_decl_file` according to D91014

2021-02-18 Thread Jan Kratochvil via Phabricator via lldb-commits
jankratochvil added a comment.

In D96778#2566208 , @dblaikie wrote:

> I expect it'd be good to have a test case showing the sort of DWARF that DWZ 
> produces for cross-CU references of enumerators.

Here is a new testcase for the second (`DW_TAG_variable`) fix: 
https://people.redhat.com/jkratoch/D96778-test.patch
I cannot update the patch here.

DWZ can produce such case from GCC output (not used for the testcase): `g++ -o 
inlinevar inlinevar{1,2}.C -Wall -g -O2;dwz ./inlinevar`
Such case is never produced clang output as the `DW_TAG_variable declaration` 
is not merged by `clang -flto` and DWZ for unknown reason does not merge the 
clang variant. I did merge it for the testcase from clang output by hand.

I did not try a testcase for the enumerators if possible at all.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96778

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


[Lldb-commits] [PATCH] D96548: [lldb] [Process/FreeBSDRemote] Introduce aarch64 hw break/watchpoint support

2021-02-18 Thread Muhammad Omair Javaid via Phabricator via lldb-commits
omjavaid added a comment.

This looks fine to me builds ok on AArch64/Linux with no testsuite regressions.

I am wondering Whats the need for version checks? you are excluding hardware 
breakpoint mangement code from the build but then that lldb-server executable 
may well run on FreeBSD version which actually supports HW breakpoints. Isnt 
there a dynamic way of checking support for hardware break/watch points. May be 
query hardware debug registers and if it fails just disable hardware 
breakpoints for that thread.

Moreover, can we shrink class name NativeRegisterContextBreakWatchpoint_arm64 
to may be NativeDebugRegisterContext_arm64.


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

https://reviews.llvm.org/D96548

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


[Lldb-commits] [PATCH] D96778: [lldb] Fix handling of `DW_AT_decl_file` according to D91014

2021-02-18 Thread David Blaikie via Phabricator via lldb-commits
dblaikie added a comment.

In D96778#2572405 , @jankratochvil 
wrote:

> In D96778#2566208 , @dblaikie wrote:
>
>> I expect it'd be good to have a test case showing the sort of DWARF that DWZ 
>> produces for cross-CU references of enumerators.
>
> Here is a new testcase for the second (`DW_TAG_variable`) fix: 
> https://people.redhat.com/jkratoch/D96778-test.patch
> I cannot update the patch here.

Ah, cool - for the final version of this, I'd suggest the author/whomever rolls 
this into one file with two CUs - bit easier to deal with. You could remove a 
bunch of extraneous DWARF too - since it's hardcoded DWARF, the 
subprogram/inlined subroutine/etc could be removed from CU1, leaving only the 
abstract subprogram and variable, both to be referenced from CU2.

> DWZ can produce such case from GCC output (not used for the testcase): `g++ 
> -o inlinevar inlinevar{1,2}.C -Wall -g -O2;dwz ./inlinevar`
> Such case is never produced clang output as the `DW_TAG_variable declaration` 
> is not merged by `clang -flto` and DWZ for unknown reason does not merge the 
> clang variant. I did merge it for the testcase from clang output by hand.
>
> I did not try a testcase for the enumerators if possible at all.

Could you provide the source code for this - I wouldn't mind trying it out and 
seeing what might be different/why DWZ doesn't understand this.

The LTO point you make is an interesting one too... yeah, for non-inlined (but 
inline linkage) functions LLVM during LTO deduplicates correctly, but this 
doesn't work out once inlining happens.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96778

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


[Lldb-commits] [PATCH] D96778: [lldb] Fix handling of `DW_AT_decl_file` according to D91014

2021-02-18 Thread Jan Kratochvil via Phabricator via lldb-commits
jankratochvil added a comment.

In D96778#2572816 , @dblaikie wrote:

> rolls this into one file with two CUs - bit easier to deal with.

Then one could not use the `.file` directives and one would need to code also 
`.debug_line` by hand.

> You could remove a bunch of extraneous DWARF too - since it's hardcoded 
> DWARF, the subprogram/inlined subroutine/etc could be removed from CU1, 
> leaving only the abstract subprogram and variable, both to be referenced from 
> CU2.

True, I have removed it now.

> Could you provide the source code for this - I wouldn't mind trying it out 
> and seeing what might be different/why DWZ doesn't understand this.

dwz will merge it without -flto but not with -flto: 
http://people.redhat.com/jkratoch/inlinevar.d.tar.xz
Personally I am not interested in DWZ, I am implementing it only as a 
compatibility with existing file format, IMNSHO DWZ should be dropped.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96778

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


[Lldb-commits] [lldb] 31fa76f - [lldb] Check that files exists before handing them off to FileCollector

2021-02-18 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2021-02-18T16:16:15-08:00
New Revision: 31fa76fd24adea755e4368674a59385d2c5b0cc7

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

LOG: [lldb] Check that files exists before handing them off to FileCollector

The FileCollector asserts that paths passed to addDirectory are indeed
directories. For that to work, the file needs to actually exist. In the
downstream Swift fork we have tests that remove files during testing,
which resulted in this assertion getting triggered.

Added: 


Modified: 
lldb/source/Utility/Reproducer.cpp

Removed: 




diff  --git a/lldb/source/Utility/Reproducer.cpp 
b/lldb/source/Utility/Reproducer.cpp
index f302cce4436f..d9207b1eb49f 100644
--- a/lldb/source/Utility/Reproducer.cpp
+++ b/lldb/source/Utility/Reproducer.cpp
@@ -374,7 +374,7 @@ static llvm::Error addPaths(StringRef path,
   SmallVector paths;
   (*buffer)->getBuffer().split(paths, '\0');
   for (StringRef p : paths) {
-if (!p.empty())
+if (!p.empty() && llvm::sys::fs::exists(p))
   callback(p);
   }
 



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


[Lldb-commits] [PATCH] D95712: [lldb/bindings] Add Python ScriptedProcess base class to lldb module

2021-02-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 324809.
mib added a comment.

Remove repetitive documentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95712

Files:
  lldb/bindings/python/CMakeLists.txt
  lldb/examples/python/scripted_process/my_scripted_process.py
  lldb/examples/python/scripted_process/scripted_process.py
  lldb/test/API/functionalities/scripted_process/Makefile
  lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
  lldb/test/API/functionalities/scripted_process/main.c

Index: lldb/test/API/functionalities/scripted_process/main.c
===
--- /dev/null
+++ lldb/test/API/functionalities/scripted_process/main.c
@@ -0,0 +1,5 @@
+#include 
+
+int main() {
+  return 0; // break here
+}
Index: lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
===
--- /dev/null
+++ lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
@@ -0,0 +1,45 @@
+"""
+Test python scripted process in lldb
+"""
+
+import os
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+from lldbsuite.test import lldbtest
+
+
+class PlatformProcessCrashInfoTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def setUp(self):
+TestBase.setUp(self)
+self.source = "main.c"
+
+def tearDown(self):
+TestBase.tearDown(self)
+
+def test_python_plugin_package(self):
+"""Test that the lldb python module has a `plugins.scripted_process`
+package."""
+self.expect('script import lldb.plugins',
+substrs=["ModuleNotFoundError"], matching=False)
+
+self.expect('script dir(lldb.plugins)',
+substrs=["scripted_process"])
+
+self.expect('script import lldb.plugins.scripted_process',
+substrs=["ModuleNotFoundError"], matching=False)
+
+self.expect('script dir(lldb.plugins.scripted_process)',
+substrs=["ScriptedProcess"])
+
+self.expect('script from lldb.plugins.scripted_process import ScriptedProcess',
+substrs=["ImportError"], matching=False)
+
+self.expect('script dir(ScriptedProcess)',
+substrs=["launch"])
+
Index: lldb/test/API/functionalities/scripted_process/Makefile
===
--- /dev/null
+++ lldb/test/API/functionalities/scripted_process/Makefile
@@ -0,0 +1,4 @@
+C_SOURCES := main.c
+
+include Makefile.rules
+
Index: lldb/examples/python/scripted_process/scripted_process.py
===
--- /dev/null
+++ lldb/examples/python/scripted_process/scripted_process.py
@@ -0,0 +1,147 @@
+from abc import ABCMeta, abstractmethod
+import six
+
+import lldb
+
+@six.add_metaclass(ABCMeta)
+class ScriptedProcess:
+
+"""
+The base class for a scripted process.
+
+Most of the base class methods are `@abstractmethod` that need to be
+overwritten by the inheriting class.
+
+DISCLAIMER: THIS INTERFACE IS STILL UNDER DEVELOPMENT AND NOT STABLE.
+THE METHODS EXPOSED MIGHT CHANGE IN THE FUTURE.
+"""
+
+@abstractmethod
+def __init__(self, target, args):
+""" Construct a scripted process.
+
+Args:
+target (lldb.SBTarget): The target launching the scripted process.
+args (lldb.SBStructuredData): A Dictionary holding arbitrary
+key/value pairs used by the scripted process.
+"""
+self.target = None
+self.args = None
+if isinstance(target, lldb.SBTarget) and target.IsValid():
+self.target = target
+if isinstance(args, lldb.SBStructuredData) and args.IsValid():
+self.args = args
+
+@abstractmethod
+def get_memory_region_containing_address(addr):
+""" Get the memory region for the scripted process, containing a
+specific address.
+
+Args:
+addr (int): Address to look for in the scripted process memory
+regions.
+
+Returns:
+lldb.SBMemoryRegionInfo: The memory region containing the address.
+None if out of bounds.
+"""
+pass
+
+@abstractmethod
+def get_thread_with_id(tid):
+""" Get the scripted process thread with a specific ID.
+
+Args:
+tid (int): Thread ID to look for in the scripted process.
+
+Returns:
+Dict: The thread represented as a dictionary, withr the
+tid thread ID. None if tid doesn't match any of the scripted
+process threads.
+"""
+pass
+
+@abstractmethod
+def get_registers_for_thread(tid):
+  

[Lldb-commits] [PATCH] D96548: [lldb] [Process/FreeBSDRemote] Introduce aarch64 hw break/watchpoint support

2021-02-18 Thread Michał Górny via Phabricator via lldb-commits
mgorny added a comment.

In D96548#2572770 , @omjavaid wrote:

> I am wondering Whats the need for version checks? you are excluding hardware 
> breakpoint mangement code from the build but then that lldb-server executable 
> may well run on FreeBSD version which actually supports HW breakpoints. Isnt 
> there a dynamic way of checking support for hardware break/watch points. May 
> be query hardware debug registers and if it fails just disable hardware 
> breakpoints for that thread.

The code relies on `struct` members that are only present with this version. 
I'd like to avoid copying implementation details like that into the code.

> Moreover, can we shrink class name NativeRegisterContextBreakWatchpoint_arm64 
> to may be NativeDebugRegisterContext_arm64.

I generally leave naming decisions to @labath ;-).


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

https://reviews.llvm.org/D96548

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


[Lldb-commits] [PATCH] D95713: [lldb/Plugins] Add ScriptedProcess Process Plugin

2021-02-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 324813.
mib added a comment.

Test `ScriptedProcess::ReadMemory`
Test launching the scripted process from both the command line and from the 
`SBAPI`.


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

https://reviews.llvm.org/D95713

Files:
  lldb/bindings/python/CMakeLists.txt
  lldb/include/lldb/Target/Process.h
  lldb/source/Plugins/Process/CMakeLists.txt
  lldb/source/Plugins/Process/scripted/CMakeLists.txt
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
  lldb/source/Plugins/Process/scripted/ScriptedProcess.h
  lldb/source/Target/Target.cpp
  lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py

Index: lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
===
--- lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
+++ lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
@@ -11,7 +11,7 @@
 from lldbsuite.test import lldbtest
 
 
-class PlatformProcessCrashInfoTestCase(TestBase):
+class ScriptedProcesTestCase(TestBase):
 
 mydir = TestBase.compute_mydir(__file__)
 
@@ -43,3 +43,55 @@
 self.expect('script dir(ScriptedProcess)',
 substrs=["launch"])
 
+def test_launch_scripted_process_sbapi(self):
+"""Test that we can launch an lldb scripted process using the SBAPI,
+check its process ID and read string from memory."""
+self.build()
+target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
+self.assertTrue(target, VALID_TARGET)
+
+scripted_process_example_relpath = ['..','..','..','..','examples','python','scripted_process','my_scripted_process.py']
+os.environ['SKIP_SCRIPTED_PROCESS_LAUNCH'] = '1'
+self.runCmd("command script import " + os.path.join(self.getSourceDir(),
+*scripted_process_example_relpath))
+
+launch_info = lldb.SBLaunchInfo(None)
+launch_info.SetProcessPluginName('ScriptedProcess')
+launch_info.SetScriptedProcessClassName('my_scripted_process.MyScriptedProcess')
+
+error = lldb.SBError()
+process = target.Launch(launch_info, error)
+self.assertTrue(process, PROCESS_IS_VALID)
+self.assertEqual(process.GetProcessID(), 42)
+
+hello_world = 'Hello, world!'
+memory_read = process.ReadCStringFromMemory(0x500,
+len(hello_world) + 1, # NULL byte
+error)
+
+self.assertTrue(error.Success(), "Failed to read memory from scripted process.")
+self.assertEqual(hello_world, memory_read)
+
+def test_launch_scripted_process_cli(self):
+"""Test that we can launch an lldb scripted process from the command
+line, check its process ID and read string from memory."""
+self.build()
+target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
+self.assertTrue(target, VALID_TARGET)
+
+scripted_process_example_relpath = ['..','..','..','..','examples','python','scripted_process','my_scripted_process.py']
+self.runCmd("command script import " + os.path.join(self.getSourceDir(),
+*scripted_process_example_relpath))
+
+process = target.GetProcess()
+self.assertTrue(process, PROCESS_IS_VALID)
+self.assertEqual(process.GetProcessID(), 42)
+
+error = lldb.SBError()
+hello_world = 'Hello, world!'
+memory_read = process.ReadCStringFromMemory(0x500,
+len(hello_world) + 1, # NULL byte
+error)
+
+self.assertTrue(error.Success(), "Failed to read memory from scripted process.")
+self.assertEqual(hello_world, memory_read)
Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -2950,7 +2950,7 @@
   // If we're not already connected to the process, and if we have a platform
   // that can launch a process for debugging, go ahead and do that here.
   if (state != eStateConnected && platform_sp &&
-  platform_sp->CanDebugProcess()) {
+  platform_sp->CanDebugProcess() && !launch_info.IsScriptedProcess()) {
 LLDB_LOGF(log, "Target::%s asking the platform to debug the process",
   __FUNCTION__);
 
Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.h
===
--- /dev/null
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.h
@@ -0,0 +1,111 @@
+//===-- ScriptedProcess.h - -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache Lice

[Lldb-commits] [PATCH] D96807: Modify TypePrinter to differentiate between anonymous struct and unnamed struct

2021-02-18 Thread Shafik Yaghmour via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
shafik marked an inline comment as done.
Closed by commit rGecb90b55454e: Modify TypePrinter to differentiate between 
anonymous struct and unnamed struct (authored by shafik).
Herald added projects: clang, LLDB.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96807

Files:
  clang/lib/AST/TypePrinter.cpp
  clang/test/AST/ast-dump-decl-json.c
  clang/test/AST/ast-dump-enum-json.cpp
  clang/test/AST/ast-dump-openmp-cancel.c
  clang/test/AST/ast-dump-openmp-cancellation-point.c
  clang/test/AST/ast-dump-openmp-distribute-parallel-for-simd.c
  clang/test/AST/ast-dump-openmp-distribute-parallel-for.c
  clang/test/AST/ast-dump-openmp-distribute-simd.c
  clang/test/AST/ast-dump-openmp-distribute.c
  clang/test/AST/ast-dump-openmp-for-simd.c
  clang/test/AST/ast-dump-openmp-for.c
  clang/test/AST/ast-dump-openmp-ordered.c
  clang/test/AST/ast-dump-openmp-parallel-for-simd.c
  clang/test/AST/ast-dump-openmp-parallel-for.c
  clang/test/AST/ast-dump-openmp-parallel-sections.c
  clang/test/AST/ast-dump-openmp-parallel.c
  clang/test/AST/ast-dump-openmp-section.c
  clang/test/AST/ast-dump-openmp-sections.c
  clang/test/AST/ast-dump-openmp-simd.c
  clang/test/AST/ast-dump-openmp-single.c
  clang/test/AST/ast-dump-openmp-target-data.c
  clang/test/AST/ast-dump-openmp-target-enter-data.c
  clang/test/AST/ast-dump-openmp-target-exit-data.c
  clang/test/AST/ast-dump-openmp-target-parallel-for-simd.c
  clang/test/AST/ast-dump-openmp-target-parallel-for.c
  clang/test/AST/ast-dump-openmp-target-parallel.c
  clang/test/AST/ast-dump-openmp-target-simd.c
  clang/test/AST/ast-dump-openmp-target-teams-distribute-parallel-for-simd.c
  clang/test/AST/ast-dump-openmp-target-teams-distribute-parallel-for.c
  clang/test/AST/ast-dump-openmp-target-teams-distribute-simd.c
  clang/test/AST/ast-dump-openmp-target-teams-distribute.c
  clang/test/AST/ast-dump-openmp-target-teams.c
  clang/test/AST/ast-dump-openmp-target-update.c
  clang/test/AST/ast-dump-openmp-target.c
  clang/test/AST/ast-dump-openmp-task.c
  clang/test/AST/ast-dump-openmp-taskgroup.c
  clang/test/AST/ast-dump-openmp-taskloop-simd.c
  clang/test/AST/ast-dump-openmp-taskloop.c
  clang/test/AST/ast-dump-openmp-teams-distribute-parallel-for-simd.c
  clang/test/AST/ast-dump-openmp-teams-distribute-parallel-for.c
  clang/test/AST/ast-dump-openmp-teams-distribute-simd.c
  clang/test/AST/ast-dump-openmp-teams-distribute.c
  clang/test/AST/ast-dump-openmp-teams.c
  clang/test/AST/ast-dump-records-json.cpp
  clang/test/AST/ast-dump-records.c
  clang/test/AST/ast-dump-records.cpp
  clang/test/AST/ast-dump-stmt-json.m
  clang/test/ASTMerge/struct/test.c
  clang/test/Analysis/cfg.cpp
  clang/test/Analysis/padding_c.c
  clang/test/Index/print-type.c
  clang/test/Index/print-type.cpp
  clang/test/Layout/ms-x86-alias-avoidance-padding.cpp
  clang/test/PCH/stmt-openmp_structured_block-bit.cpp
  clang/test/Sema/assign.c
  clang/test/Sema/switch.c
  clang/test/SemaCXX/condition.cpp
  clang/test/SemaCXX/enum.cpp
  clang/test/SemaCXX/warn-sign-conversion.cpp
  
lldb/test/Shell/SymbolFile/DWARF/clang-ast-from-dwarf-unamed-and-anon-structs.cpp
  lldb/test/Shell/SymbolFile/DWARF/debug-types-missing-signature.test

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


[Lldb-commits] [lldb] 1e08193 - Fix for Modify TypePrinter to differentiate between anonymous struct and unnamed struct

2021-02-18 Thread Shafik Yaghmour via lldb-commits

Author: Shafik Yaghmour
Date: 2021-02-18T17:57:40-08:00
New Revision: 1e0819395657a9306f609849dcd3be9d7fb0c894

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

LOG: Fix for Modify TypePrinter to differentiate between anonymous struct and 
unnamed struct

One of the lldb tests needed additional fixes.

Added: 


Modified: 
lldb/test/Shell/SymbolFile/DWARF/debug-types-missing-signature.test

Removed: 




diff  --git 
a/lldb/test/Shell/SymbolFile/DWARF/debug-types-missing-signature.test 
b/lldb/test/Shell/SymbolFile/DWARF/debug-types-missing-signature.test
index 8dddea063578..8bdc2219cc1c 100644
--- a/lldb/test/Shell/SymbolFile/DWARF/debug-types-missing-signature.test
+++ b/lldb/test/Shell/SymbolFile/DWARF/debug-types-missing-signature.test
@@ -22,5 +22,5 @@ PRINTEC: use of undeclared identifier 'EC'
 
 RUN: %lldb %t -b -o "target variable a e ec" | FileCheck --check-prefix=VARS %s
 VARS: (const (unnamed struct)) a = {}
-VARS: (const (anonymous enum)) e = 0x1
-VARS: (const (anonymous enum)) ec = 0x1
+VARS: (const (unnamed enum)) e = 0x1
+VARS: (const (unnamed enum)) ec = 0x1



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


[Lldb-commits] [lldb] 080ba85 - Revert "Fix for Modify TypePrinter to differentiate between anonymous struct and unnamed struct"

2021-02-18 Thread Shafik Yaghmour via lldb-commits

Author: Shafik Yaghmour
Date: 2021-02-18T18:17:24-08:00
New Revision: 080ba851c61604f9c00117b584191c67cfc468cd

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

LOG: Revert "Fix for Modify TypePrinter to differentiate between anonymous 
struct and unnamed struct"

I missed clangd test suite and may need some time to get those working, so 
reverting for now.

This reverts commit 1e0819395657a9306f609849dcd3be9d7fb0c894.

Added: 


Modified: 
lldb/test/Shell/SymbolFile/DWARF/debug-types-missing-signature.test

Removed: 




diff  --git 
a/lldb/test/Shell/SymbolFile/DWARF/debug-types-missing-signature.test 
b/lldb/test/Shell/SymbolFile/DWARF/debug-types-missing-signature.test
index 8bdc2219cc1c..8dddea063578 100644
--- a/lldb/test/Shell/SymbolFile/DWARF/debug-types-missing-signature.test
+++ b/lldb/test/Shell/SymbolFile/DWARF/debug-types-missing-signature.test
@@ -22,5 +22,5 @@ PRINTEC: use of undeclared identifier 'EC'
 
 RUN: %lldb %t -b -o "target variable a e ec" | FileCheck --check-prefix=VARS %s
 VARS: (const (unnamed struct)) a = {}
-VARS: (const (unnamed enum)) e = 0x1
-VARS: (const (unnamed enum)) ec = 0x1
+VARS: (const (anonymous enum)) e = 0x1
+VARS: (const (anonymous enum)) ec = 0x1



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


[Lldb-commits] [PATCH] D96807: Modify TypePrinter to differentiate between anonymous struct and unnamed struct

2021-02-18 Thread Shafik Yaghmour via Phabricator via lldb-commits
shafik added a comment.
Herald added a subscriber: JDevlieghere.

Reverted the changes because I missed the clangd test suite and don't know how 
long it will take to fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96807

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


[Lldb-commits] [PATCH] D97017: [lldb-server] Exit the DataAvailableCallback loop when `done` or `interrupt` are set

2021-02-18 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere created this revision.
JDevlieghere added reviewers: labath, omjavaid.
JDevlieghere requested review of this revision.

When looking at `GDBRemoteCommunicationServerLLGS::DataAvailableCallback` I 
noticed that the `done` and `interrupt` flags are currently being ignored. I 
assumed the reason is that `GetPacketAndSendResponse ` always returns either 
`PacketResult::Success` or `PacketResult::ErrorReplyTimeout` but there are 
plenty of code paths that return `PacketResult::Success` but set `done` or 
`interrupt` to true.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D97017

Files:
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp


Index: 
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -1060,6 +1060,11 @@
   m_mainloop.RequestTermination();
   break;
 }
+
+if (done || interrupt) {
+  m_mainloop.RequestTermination();
+  break;
+}
   }
 }
 


Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -1060,6 +1060,11 @@
   m_mainloop.RequestTermination();
   break;
 }
+
+if (done || interrupt) {
+  m_mainloop.RequestTermination();
+  break;
+}
   }
 }
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

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

Add api test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96680

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

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

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

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

revert last amend: added the test to the wrong diff


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96680

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


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


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


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

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

Add api test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96637

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

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

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

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

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

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

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


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96637

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


[Lldb-commits] [lldb] d82ecb0 - LanguageRuntime can provide an UnwindPlan for special occasions

2021-02-18 Thread Jason Molenda via lldb-commits

Author: Jason Molenda
Date: 2021-02-18T23:23:15-08:00
New Revision: d82ecb0ac72261189ec3a5dccd3ad55aeafe07b4

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

LOG: LanguageRuntime can provide an UnwindPlan for special occasions

Add a facility in the LanguageRuntime to provide a special
UnwindPlan based on the register values in a RegisterContext,
instead of using the return-pc to find a function and use its
normal UnwindPlans.

Needed when the runtime has special stack frames that we want
to show the user, but aren't actually on the real stack.
Specifically for Swift asynchronous functions.

With feedback from Greg Clayton, Jonas Devlieghere, Dave Lee



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

Added: 


Modified: 
lldb/include/lldb/Target/LanguageRuntime.h
lldb/source/Target/LanguageRuntime.cpp
lldb/source/Target/RegisterContextUnwind.cpp

Removed: 




diff  --git a/lldb/include/lldb/Target/LanguageRuntime.h 
b/lldb/include/lldb/Target/LanguageRuntime.h
index a3897adfe46a..a8fc3eed0674 100644
--- a/lldb/include/lldb/Target/LanguageRuntime.h
+++ b/lldb/include/lldb/Target/LanguageRuntime.h
@@ -173,7 +173,30 @@ class LanguageRuntime : public Runtime, public 
PluginInterface {
   virtual bool isA(const void *ClassID) const { return ClassID == &ID; }
   static char ID;
 
+  /// A language runtime may be able to provide a special UnwindPlan for
+  /// the frame represented by the register contents \a regctx when that
+  /// frame is not following the normal ABI conventions.
+  /// Instead of using the normal UnwindPlan for the function, we will use
+  /// this special UnwindPlan for this one backtrace.
+  /// One example of this would be a language that has asynchronous functions,
+  /// functions that may not be currently-executing, while waiting on other
+  /// asynchronous calls they made, but are part of a logical backtrace that
+  /// we want to show the developer because that's how they think of the
+  /// program flow.
+  static lldb::UnwindPlanSP
+  GetRuntimeUnwindPlan(lldb_private::Thread &thread,
+   lldb_private::RegisterContext *regctx);
+
 protected:
+  // The static GetRuntimeUnwindPlan method above is only implemented in the
+  // base class; subclasses may override this protected member if they can
+  // provide one of these UnwindPlans.
+  virtual lldb::UnwindPlanSP
+  GetRuntimeUnwindPlan(lldb::ProcessSP process_sp,
+   lldb_private::RegisterContext *regctx) {
+return lldb::UnwindPlanSP();
+  }
+
   LanguageRuntime(Process *process);
 };
 

diff  --git a/lldb/source/Target/LanguageRuntime.cpp 
b/lldb/source/Target/LanguageRuntime.cpp
index f2e2febf8b88..0b3b0e179af5 100644
--- a/lldb/source/Target/LanguageRuntime.cpp
+++ b/lldb/source/Target/LanguageRuntime.cpp
@@ -259,6 +259,21 @@ BreakpointSP LanguageRuntime::CreateExceptionBreakpoint(
   return exc_breakpt_sp;
 }
 
+UnwindPlanSP LanguageRuntime::GetRuntimeUnwindPlan(Thread &thread,
+   RegisterContext *regctx) {
+  ProcessSP process_sp = thread.GetProcess();
+  if (!process_sp.get())
+return UnwindPlanSP();
+  for (const lldb::LanguageType lang_type : Language::GetSupportedLanguages()) 
{
+if (LanguageRuntime *runtime = process_sp->GetLanguageRuntime(lang_type)) {
+  UnwindPlanSP plan_sp = runtime->GetRuntimeUnwindPlan(process_sp, regctx);
+  if (plan_sp.get())
+return plan_sp;
+}
+  }
+  return UnwindPlanSP();
+}
+
 void LanguageRuntime::InitializeCommands(CommandObject *parent) {
   if (!parent)
 return;

diff  --git a/lldb/source/Target/RegisterContextUnwind.cpp 
b/lldb/source/Target/RegisterContextUnwind.cpp
index a677121d8279..355d18977c92 100644
--- a/lldb/source/Target/RegisterContextUnwind.cpp
+++ b/lldb/source/Target/RegisterContextUnwind.cpp
@@ -24,6 +24,7 @@
 #include "lldb/Target/ABI.h"
 #include "lldb/Target/DynamicLoader.h"
 #include "lldb/Target/ExecutionContext.h"
+#include "lldb/Target/LanguageRuntime.h"
 #include "lldb/Target/Platform.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/SectionLoadList.h"
@@ -283,6 +284,22 @@ void RegisterContextUnwind::InitializeNonZerothFrame() {
 return;
   }
 
+  ExecutionContext exe_ctx(m_thread.shared_from_this());
+  Process *process = exe_ctx.GetProcessPtr();
+
+  // Some languages may have a logical parent stack frame which is
+  // not a real stack frame, but the programmer would consider it to
+  // be the caller of the frame, e.g. Swift asynchronous frames.
+  //
+  // A LanguageRuntime may provide an UnwindPlan that is used in this
+  // stack trace base on the RegisterContext contents, intsead
+  // of the normal UnwindPlans we would use for the return-pc.
+  UnwindPlanSP lang_runtime_pla

[Lldb-commits] [PATCH] D96839: Add a callout to the LanguageRuntime to override the normal UnwindPlan used for a frame

2021-02-18 Thread Jason Molenda 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 rGd82ecb0ac722: LanguageRuntime can provide an UnwindPlan for 
special occasions (authored by jasonmolenda).

Changed prior to commit:
  https://reviews.llvm.org/D96839?vs=324191&id=324894#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96839

Files:
  lldb/include/lldb/Target/LanguageRuntime.h
  lldb/source/Target/LanguageRuntime.cpp
  lldb/source/Target/RegisterContextUnwind.cpp

Index: lldb/source/Target/RegisterContextUnwind.cpp
===
--- lldb/source/Target/RegisterContextUnwind.cpp
+++ lldb/source/Target/RegisterContextUnwind.cpp
@@ -24,6 +24,7 @@
 #include "lldb/Target/ABI.h"
 #include "lldb/Target/DynamicLoader.h"
 #include "lldb/Target/ExecutionContext.h"
+#include "lldb/Target/LanguageRuntime.h"
 #include "lldb/Target/Platform.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/SectionLoadList.h"
@@ -283,6 +284,22 @@
 return;
   }
 
+  ExecutionContext exe_ctx(m_thread.shared_from_this());
+  Process *process = exe_ctx.GetProcessPtr();
+
+  // Some languages may have a logical parent stack frame which is
+  // not a real stack frame, but the programmer would consider it to
+  // be the caller of the frame, e.g. Swift asynchronous frames.
+  //
+  // A LanguageRuntime may provide an UnwindPlan that is used in this
+  // stack trace base on the RegisterContext contents, intsead
+  // of the normal UnwindPlans we would use for the return-pc.
+  UnwindPlanSP lang_runtime_plan_sp =
+  LanguageRuntime::GetRuntimeUnwindPlan(m_thread, this);
+  if (lang_runtime_plan_sp.get()) {
+UnwindLogMsg("This is an async frame");
+  }
+
   addr_t pc;
   if (!ReadGPRValue(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC, pc)) {
 UnwindLogMsg("could not get pc value");
@@ -290,8 +307,6 @@
 return;
   }
 
-  ExecutionContext exe_ctx(m_thread.shared_from_this());
-  Process *process = exe_ctx.GetProcessPtr();
   // Let ABIs fixup code addresses to make sure they are valid. In ARM ABIs
   // this will strip bit zero in case we read a PC from memory or from the LR.
   ABI *abi = process->GetABI().get();
@@ -522,12 +537,43 @@
 }
   }
 
-  // We've set m_frame_type and m_sym_ctx before this call.
-  m_fast_unwind_plan_sp = GetFastUnwindPlanForFrame();
-
   UnwindPlan::RowSP active_row;
   RegisterKind row_register_kind = eRegisterKindGeneric;
 
+  // If we have LanguageRuntime UnwindPlan for this unwind, use those
+  // rules to find the caller frame instead of the function's normal
+  // UnwindPlans.  The full unwind plan for this frame will be
+  // the LanguageRuntime-provided unwind plan, and there will not be a
+  // fast unwind plan.
+  if (lang_runtime_plan_sp.get()) {
+active_row =
+lang_runtime_plan_sp->GetRowForFunctionOffset(m_current_offset);
+row_register_kind = lang_runtime_plan_sp->GetRegisterKind();
+if (!ReadFrameAddress(row_register_kind, active_row->GetCFAValue(),
+  m_cfa)) {
+  UnwindLogMsg("Cannot set cfa");
+} else {
+  m_full_unwind_plan_sp = lang_runtime_plan_sp;
+  if (log) {
+StreamString active_row_strm;
+active_row->Dump(active_row_strm, lang_runtime_plan_sp.get(), &m_thread,
+ m_start_pc.GetLoadAddress(exe_ctx.GetTargetPtr()));
+UnwindLogMsg("async active row: %s", active_row_strm.GetData());
+  }
+  UnwindLogMsg("m_cfa = 0x%" PRIx64 " m_afa = 0x%" PRIx64, m_cfa, m_afa);
+  UnwindLogMsg(
+  "initialized async frame current pc is 0x%" PRIx64
+  " cfa is 0x%" PRIx64 " afa is 0x%" PRIx64,
+  (uint64_t)m_current_pc.GetLoadAddress(exe_ctx.GetTargetPtr()),
+  (uint64_t)m_cfa, (uint64_t)m_afa);
+
+  return;
+}
+  }
+
+  // We've set m_frame_type and m_sym_ctx before this call.
+  m_fast_unwind_plan_sp = GetFastUnwindPlanForFrame();
+
   // Try to get by with just the fast UnwindPlan if possible - the full
   // UnwindPlan may be expensive to get (e.g. if we have to parse the entire
   // eh_frame section of an ObjectFile for the first time.)
Index: lldb/source/Target/LanguageRuntime.cpp
===
--- lldb/source/Target/LanguageRuntime.cpp
+++ lldb/source/Target/LanguageRuntime.cpp
@@ -259,6 +259,21 @@
   return exc_breakpt_sp;
 }
 
+UnwindPlanSP LanguageRuntime::GetRuntimeUnwindPlan(Thread &thread,
+   RegisterContext *regctx) {
+  ProcessSP process_sp = thread.GetProcess();
+  if (!process_sp.get())
+return UnwindPlanSP();
+  for (const lldb::LanguageType lang_type : Language::GetSupportedLanguages()) {
+if (LanguageRuntime *runtime = process_sp->GetLanguageRuntime(lang_type)) {
+  UnwindPlanSP plan_sp = runti

[Lldb-commits] [PATCH] D96548: [lldb] [Process/FreeBSDRemote] Introduce aarch64 hw break/watchpoint support

2021-02-18 Thread Muhammad Omair Javaid via Phabricator via lldb-commits
omjavaid added a comment.

In D96548#2573245 , @mgorny wrote:

> In D96548#2572770 , @omjavaid wrote:
>
>> I am wondering Whats the need for version checks? you are excluding hardware 
>> breakpoint mangement code from the build but then that lldb-server 
>> executable may well run on FreeBSD version which actually supports HW 
>> breakpoints. Isnt there a dynamic way of checking support for hardware 
>> break/watch points. May be query hardware debug registers and if it fails 
>> just disable hardware breakpoints for that thread.
>
> The code relies on `struct` members that are only present with this version. 
> I'd like to avoid copying implementation details like that into the code.

Only concern here is that someone might be cross-compiling lldb-server on an 
older system but eventually using it on a target which supports HW 
break/watchpoints. What chances do you think we have for such a scenario? if 
this is rare then this should be ok.

>> Moreover, can we shrink class name 
>> NativeRegisterContextBreakWatchpoint_arm64 to may be 
>> NativeDebugRegisterContext_arm64.
>
> I generally leave naming decisions to @labath ;-).

Lets see what @labath has to say... IMO Debug Register is a general term used 
in other architecture specs for referring to hardware debug capabilities like 
breakpoints watchpoints etc.


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

https://reviews.llvm.org/D96548

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