[Lldb-commits] [lldb] f3b7cc8 - [lldb/test] Add ability to terminate connection from a gdb-client handler

2021-11-19 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2021-11-19T18:00:14+01:00
New Revision: f3b7cc8bb2ea599e0c344e8ae16639667d9f0eff

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

LOG: [lldb/test] Add ability to terminate connection from a gdb-client handler

We were using the client socket close as a way to terminate the handler
thread. But this kind of concurrent access to the same socket is not
safe. It also complicates running the handler without a dedicated thread
(next patch).

Instead, here I add an explicit way for a packet handler to request
termination. Waiting for lldb to terminate the connection would almost
be sufficient, but in the pty test we want to keep the pty open so we
can examine its state. Ability to disconnect at an arbitrary point may
be useful for testing other aspects of lldb functionality as well.

The way this works is that now each packet handler can optionally return
a list of responses (instead of just one). One of those responses (it
only makes sense for it to be the last one) can be a special
RESPONSE_DISCONNECT object, which triggers a disconnection (via a new
TerminateConnectionException).

As the mock server now cleans up the connection whenever it disconnects,
the pty test needs to explicitly dup(2) the descriptors in order to
inspect the post-disconnect state.

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

Added: 


Modified: 
lldb/packages/Python/lldbsuite/test/gdbclientutils.py
lldb/test/API/functionalities/gdb_remote_client/TestPty.py

Removed: 




diff  --git a/lldb/packages/Python/lldbsuite/test/gdbclientutils.py 
b/lldb/packages/Python/lldbsuite/test/gdbclientutils.py
index 183e6a0c597a9..7fdf18e38b385 100644
--- a/lldb/packages/Python/lldbsuite/test/gdbclientutils.py
+++ b/lldb/packages/Python/lldbsuite/test/gdbclientutils.py
@@ -86,6 +86,7 @@ class MockGDBServerResponder:
 
 registerCount = 40
 packetLog = None
+class RESPONSE_DISCONNECT: pass
 
 def __init__(self):
 self.packetLog = []
@@ -327,7 +328,7 @@ def qRegisterInfo(self, num):
 return ""
 
 def k(self):
-return ""
+return ["W01", self.RESPONSE_DISCONNECT]
 
 """
 Raised when we receive a packet for which there is no default action.
@@ -492,17 +493,20 @@ def _run(self):
 self._receivedData = ""
 self._receivedDataOffset = 0
 data = None
-while True:
-try:
+try:
+while True:
 data = seven.bitcast_to_string(self._socket.recv())
 if data is None or len(data) == 0:
 break
 self._receive(data)
-except Exception as e:
-print("An exception happened when receiving the response from 
the gdb server. Closing the client...")
-traceback.print_exc()
-self._socket.close_connection()
-break
+except self.TerminateConnectionException:
+pass
+except Exception as e:
+print("An exception happened when receiving the response from the 
gdb server. Closing the client...")
+traceback.print_exc()
+finally:
+self._socket.close_connection()
+self._socket.close_server()
 
 def _receive(self, data):
 """
@@ -510,13 +514,10 @@ def _receive(self, data):
 Any leftover data is kept for parsing the next time around.
 """
 self._receivedData += data
-try:
+packet = self._parsePacket()
+while packet is not None:
+self._handlePacket(packet)
 packet = self._parsePacket()
-while packet is not None:
-self._handlePacket(packet)
-packet = self._parsePacket()
-except self.InvalidPacketException:
-self._socket.close_connection()
 
 def _parsePacket(self):
 """
@@ -583,6 +584,9 @@ def _parsePacket(self):
 self._receivedDataOffset = 0
 return packet
 
+def _sendPacket(self, packet):
+self._socket.sendall(seven.bitcast_to_bytes(frame_packet(packet)))
+
 def _handlePacket(self, packet):
 if packet is self.PACKET_ACK:
 # Ignore ACKs from the client. For the future, we can consider
@@ -600,14 +604,18 @@ def _handlePacket(self, packet):
 elif self.responder is not None:
 # Delegate everything else to our responder
 response = self.responder.respond(packet)
-# Handle packet framing since we don't want to bother tests with it.
-if response is not None:
-framed = frame_packet(response)
-self._socket.sendall(seven.bitcast_to_bytes(framed))
+if not isinstance(response, list):
+response = [res

[Lldb-commits] [PATCH] D114156: [lldb/test] Add ability to terminate connection from a gdb-client handler

2021-11-19 Thread Pavel Labath via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf3b7cc8bb2ea: [lldb/test] Add ability to terminate 
connection from a gdb-client handler (authored by labath).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114156

Files:
  lldb/packages/Python/lldbsuite/test/gdbclientutils.py
  lldb/test/API/functionalities/gdb_remote_client/TestPty.py

Index: lldb/test/API/functionalities/gdb_remote_client/TestPty.py
===
--- lldb/test/API/functionalities/gdb_remote_client/TestPty.py
+++ lldb/test/API/functionalities/gdb_remote_client/TestPty.py
@@ -12,10 +12,14 @@
 
 def get_term_attrs(self):
 import termios
-return termios.tcgetattr(self.server._socket._secondary)
+return termios.tcgetattr(self._secondary_socket)
 
 def setUp(self):
 super().setUp()
+# Duplicate the pty descriptors so we can inspect the pty state after
+# they are closed
+self._primary_socket = os.dup(self.server._socket._primary.name)
+self._secondary_socket = os.dup(self.server._socket._secondary.name)
 self.orig_attr = self.get_term_attrs()
 
 def assert_raw_mode(self, current_attr):
Index: lldb/packages/Python/lldbsuite/test/gdbclientutils.py
===
--- lldb/packages/Python/lldbsuite/test/gdbclientutils.py
+++ lldb/packages/Python/lldbsuite/test/gdbclientutils.py
@@ -86,6 +86,7 @@
 
 registerCount = 40
 packetLog = None
+class RESPONSE_DISCONNECT: pass
 
 def __init__(self):
 self.packetLog = []
@@ -327,7 +328,7 @@
 return ""
 
 def k(self):
-return ""
+return ["W01", self.RESPONSE_DISCONNECT]
 
 """
 Raised when we receive a packet for which there is no default action.
@@ -492,17 +493,20 @@
 self._receivedData = ""
 self._receivedDataOffset = 0
 data = None
-while True:
-try:
+try:
+while True:
 data = seven.bitcast_to_string(self._socket.recv())
 if data is None or len(data) == 0:
 break
 self._receive(data)
-except Exception as e:
-print("An exception happened when receiving the response from the gdb server. Closing the client...")
-traceback.print_exc()
-self._socket.close_connection()
-break
+except self.TerminateConnectionException:
+pass
+except Exception as e:
+print("An exception happened when receiving the response from the gdb server. Closing the client...")
+traceback.print_exc()
+finally:
+self._socket.close_connection()
+self._socket.close_server()
 
 def _receive(self, data):
 """
@@ -510,13 +514,10 @@
 Any leftover data is kept for parsing the next time around.
 """
 self._receivedData += data
-try:
+packet = self._parsePacket()
+while packet is not None:
+self._handlePacket(packet)
 packet = self._parsePacket()
-while packet is not None:
-self._handlePacket(packet)
-packet = self._parsePacket()
-except self.InvalidPacketException:
-self._socket.close_connection()
 
 def _parsePacket(self):
 """
@@ -583,6 +584,9 @@
 self._receivedDataOffset = 0
 return packet
 
+def _sendPacket(self, packet):
+self._socket.sendall(seven.bitcast_to_bytes(frame_packet(packet)))
+
 def _handlePacket(self, packet):
 if packet is self.PACKET_ACK:
 # Ignore ACKs from the client. For the future, we can consider
@@ -600,14 +604,18 @@
 elif self.responder is not None:
 # Delegate everything else to our responder
 response = self.responder.respond(packet)
-# Handle packet framing since we don't want to bother tests with it.
-if response is not None:
-framed = frame_packet(response)
-self._socket.sendall(seven.bitcast_to_bytes(framed))
+if not isinstance(response, list):
+response = [response]
+for part in response:
+if part is MockGDBServerResponder.RESPONSE_DISCONNECT:
+raise self.TerminateConnectionException()
+self._sendPacket(part)
 
 PACKET_ACK = object()
 PACKET_INTERRUPT = object()
 
-class InvalidPacketException(Exception):
+class TerminateConnectionException(Exception):
 pass
 
+class InvalidPacketException(Exception):
+pass
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 587a397 - Skip tests when compiler with older versions of clang

2021-11-19 Thread Adrian Prantl via lldb-commits

Author: Adrian Prantl
Date: 2021-11-19T09:05:48-08:00
New Revision: 587a397917b267fb570cf9f6c7dd0f718b51d9de

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

LOG: Skip tests when compiler with older versions of clang

Added: 


Modified: 

lldb/test/API/commands/expression/import-std-module/unique_ptr/TestUniquePtrFromStdModule.py
lldb/test/API/functionalities/mtc/simple/TestMTCSimple.py
lldb/test/API/lang/objc/modules-compile-error/TestModulesCompileError.py
lldb/test/API/tools/lldb-server/TestLldbGdbServer.py

Removed: 




diff  --git 
a/lldb/test/API/commands/expression/import-std-module/unique_ptr/TestUniquePtrFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/unique_ptr/TestUniquePtrFromStdModule.py
index 878315b8eafdc..f8e1aa708f57c 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/unique_ptr/TestUniquePtrFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/unique_ptr/TestUniquePtrFromStdModule.py
@@ -13,6 +13,7 @@ class TestUniquePtr(TestBase):
 
 @add_test_categories(["libc++"])
 @skipIf(compiler=no_match("clang"))
+@skipIf(compiler="clang", compiler_version=['<', '9.0'])
 @skipIfLinux # s.reset() causes link errors on ubuntu 18.04/Clang 9
 def test(self):
 self.build()

diff  --git a/lldb/test/API/functionalities/mtc/simple/TestMTCSimple.py 
b/lldb/test/API/functionalities/mtc/simple/TestMTCSimple.py
index 23fe72ea50122..a4deb96c75ac9 100644
--- a/lldb/test/API/functionalities/mtc/simple/TestMTCSimple.py
+++ b/lldb/test/API/functionalities/mtc/simple/TestMTCSimple.py
@@ -15,6 +15,7 @@ class MTCSimpleTestCase(TestBase):
 mydir = TestBase.compute_mydir(__file__)
 
 @skipUnlessDarwin
+@skipIf(compiler="clang", compiler_version=['<', '9.0'])
 def test(self):
 self.mtc_dylib_path = findMainThreadCheckerDylib()
 if self.mtc_dylib_path == "":
@@ -24,6 +25,7 @@ def test(self):
 self.mtc_tests()
 
 @skipIf(archs=['i386'])
+@skipIf(compiler="clang", compiler_version=['<', '9.0'])
 def mtc_tests(self):
 self.assertNotEqual(self.mtc_dylib_path, "")
 

diff  --git 
a/lldb/test/API/lang/objc/modules-compile-error/TestModulesCompileError.py 
b/lldb/test/API/lang/objc/modules-compile-error/TestModulesCompileError.py
index 610d001a67836..36cf050011c8e 100644
--- a/lldb/test/API/lang/objc/modules-compile-error/TestModulesCompileError.py
+++ b/lldb/test/API/lang/objc/modules-compile-error/TestModulesCompileError.py
@@ -7,6 +7,7 @@ class TestCase(TestBase):
 
 mydir = TestBase.compute_mydir(__file__)
 
+@skipIf(compiler="clang", compiler_version=['<', '11.0'])
 def test(self):
 self.build()
 lldbutil.run_to_source_breakpoint(self, "// break here", 
lldb.SBFileSpec("main.m"))

diff  --git a/lldb/test/API/tools/lldb-server/TestLldbGdbServer.py 
b/lldb/test/API/tools/lldb-server/TestLldbGdbServer.py
index 2f76654c47b12..01ae2428f3388 100644
--- a/lldb/test/API/tools/lldb-server/TestLldbGdbServer.py
+++ b/lldb/test/API/tools/lldb-server/TestLldbGdbServer.py
@@ -390,12 +390,14 @@ def Hg_switches_to_3_threads(self, pass_pid=False):
 self.assertEqual(int(context.get("thread_id"), 16), thread)
 
 @expectedFailureAll(oslist=["windows"]) # expect 4 threads
+@skipIf(compiler="clang", compiler_version=['<', '11.0'])
 def test_Hg_switches_to_3_threads_launch(self):
 self.build()
 self.set_inferior_startup_launch()
 self.Hg_switches_to_3_threads()
 
 @expectedFailureAll(oslist=["windows"]) # expecting one more thread
+@skipIf(compiler="clang", compiler_version=['<', '11.0'])
 def test_Hg_switches_to_3_threads_attach(self):
 self.build()
 self.set_inferior_startup_attach()
@@ -403,6 +405,7 @@ def test_Hg_switches_to_3_threads_attach(self):
 
 @expectedFailureAll(oslist=["windows"]) # expect 4 threads
 @add_test_categories(["llgs"])
+@skipIf(compiler="clang", compiler_version=['<', '11.0'])
 def test_Hg_switches_to_3_threads_attach_pass_correct_pid(self):
 self.build()
 self.set_inferior_startup_attach()



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


[Lldb-commits] [PATCH] D114259: [lldb] Fix [some] leaks in python bindings

2021-11-19 Thread Pavel Labath via Phabricator via lldb-commits
labath created this revision.
labath added reviewers: JDevlieghere, jingham.
labath requested review of this revision.
Herald added a project: LLDB.

Using an lldb_private object in the bindings involves three steps

- wrapping the object in it's lldb::SB variant
- using swig to convert/wrap that to a PyObject
- wrapping *that* in a lldb_private::python::PythonObject

Our SBTypeToSWIGWrapper was only handling the middle part. This doesn't
just result in increased boilerplate in the callers, but is also a
functionality problem, as it's very hard to get the lifetime of of all
of these objects right. Most of the callers are creating the SB object
(step 1) on the stack, which means that we end up with dangling python
objects after the function terminates. Most of the time this isn't a
problem, because the python code does not need to persist the objects.
However, there are legitimate cases where they can do it (and even if
the use case is not completely legitimate, crashing is not the best
response to that).

For this reason, some of our code creates the SB object on the heap, but
it has another problem -- it never gets cleaned up.

This patch begins to add a new function (ToSWIGWrapper), which does all
of the three steps, while properly taking care of ownership. In the
first step, I have converted most of the leaky code (except for
SBStructuredData, which needs a bit more work).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114259

Files:
  lldb/bindings/python/python-swigsafecast.swig
  lldb/bindings/python/python-wrapper.swig
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  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
@@ -129,7 +129,7 @@
 
 extern "C" void *LLDBSwigPythonCreateScriptedBreakpointResolver(
 const char *python_class_name, const char *session_dictionary_name,
-lldb_private::StructuredDataImpl *args, lldb::BreakpointSP &bkpt_sp) {
+lldb_private::StructuredDataImpl *args, const lldb::BreakpointSP &bkpt_sp) {
   return nullptr;
 }
 
@@ -248,7 +248,7 @@
 
 extern "C" bool LLDBSWIGPythonRunScriptKeywordProcess(
 const char *python_function_name, const char *session_dictionary_name,
-lldb::ProcessSP &process, std::string &output) {
+const lldb::ProcessSP &process, std::string &output) {
   return false;
 }
 
@@ -260,7 +260,7 @@
 
 extern "C" bool LLDBSWIGPythonRunScriptKeywordTarget(
 const char *python_function_name, const char *session_dictionary_name,
-lldb::TargetSP &target, std::string &output) {
+const lldb::TargetSP &target, std::string &output) {
   return false;
 }
 
@@ -272,7 +272,7 @@
 
 extern "C" bool LLDBSWIGPythonRunScriptKeywordValue(
 const char *python_function_name, const char *session_dictionary_name,
-lldb::ValueObjectSP &value, std::string &output) {
+const lldb::ValueObjectSP &value, std::string &output) {
   return false;
 }
 
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -127,7 +127,7 @@
 
 extern "C" void *LLDBSwigPythonCreateScriptedBreakpointResolver(
 const char *python_class_name, const char *session_dictionary_name,
-lldb_private::StructuredDataImpl *args, lldb::BreakpointSP &bkpt_sp);
+lldb_private::StructuredDataImpl *args, const lldb::BreakpointSP &bkpt_sp);
 
 extern "C" unsigned int
 LLDBSwigPythonCallBreakpointResolver(void *implementor, const char *method_name,
@@ -196,7 +196,7 @@
 
 extern "C" bool LLDBSWIGPythonRunScriptKeywordProcess(
 const char *python_function_name, const char *session_dictionary_name,
-lldb::ProcessSP &process, std::string &output);
+const lldb::ProcessSP &process, std::string &output);
 
 extern "C" bool LLDBSWIGPythonRunScriptKeywordThread(
 const char *python_function_name, const char *session_dictionary_name,
@@ -204,7 +204,7 @@
 
 extern "C" bool LLDBSWIGPythonRunScriptKeywordTarget(
 const char *python_function_name, const char *session_dictionary_name,
-lldb::TargetSP &target, std::string &output);
+const lldb::TargetSP &target, std::string &output);
 
 extern "C" bool LLDBSWIGPythonRunScriptKeywordFrame(
 const char *python_function_name, const char *session_dictionary_name,
@@ -212,7 +212,7 @@
 
 extern "C" bool LLDBSWIGPythonRunScriptKeywordValue(
 const char *python_function_name, const char *session_dictionary_name,
-lldb::ValueObjectSP &value, std::string &output);
+const lldb::ValueObjectSP &value, std::string &output);
 
 extern "C" void *
 LLDBSW

[Lldb-commits] [PATCH] D114259: [lldb] Fix [some] leaks in python bindings

2021-11-19 Thread Pavel Labath via Phabricator via lldb-commits
labath added inline comments.



Comment at: lldb/bindings/python/python-swigsafecast.swig:61-67
+PythonObject ToSWIGWrapper(std::unique_ptr value_sb) {
+  return ToSWIGHelper(value_sb.release(), SWIGTYPE_p_lldb__SBValue);
+}
+
+PythonObject ToSWIGWrapper(lldb::ValueObjectSP value_sp) {
+  return ToSWIGWrapper(std::make_unique(std::move(value_sp)));
+}

I have two of these, because one of the functions wants to modify the SB object 
before passing it to python. It's not a super common use case, but I think 
there will be a couple more of these. I have also considered having a function 
returning a `(PythonObject, SBValue*)` pair, but it seemed more complicated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114259

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


[Lldb-commits] [PATCH] D114259: [lldb] Fix [some] leaks in python bindings

2021-11-19 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.

Nice cleanup. LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114259

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


[Lldb-commits] [PATCH] D114266: [formatters] Draft Optional PR

2021-11-19 Thread Danil Stefaniuc via Phabricator via lldb-commits
danilashtefan created this revision.
danilashtefan requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114266

Files:
  lldb/examples/synthetic/gnu_libstdcpp.py
  lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp


Index: lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
===
--- lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -913,6 +913,11 @@
   SyntheticChildrenSP(new ScriptedSyntheticChildren(
   stl_deref_flags,
   "lldb.formatters.cpp.gnu_libstdcpp.StdMapLikeSynthProvider")));
+  cpp_category_sp->GetRegexTypeSyntheticsContainer()->Add(
+  RegularExpression("^std::optional<.+>(( )?&)?$"),
+  SyntheticChildrenSP(new ScriptedSyntheticChildren(
+  stl_synth_flags,
+  "lldb.formatters.cpp.gnu_libstdcpp.StdOptionalSynthProvider")));
   cpp_category_sp->GetRegexTypeSyntheticsContainer()->Add(
   RegularExpression("^std::multiset<.+> >(( )?&)?$"),
   SyntheticChildrenSP(new ScriptedSyntheticChildren(
Index: lldb/examples/synthetic/gnu_libstdcpp.py
===
--- lldb/examples/synthetic/gnu_libstdcpp.py
+++ lldb/examples/synthetic/gnu_libstdcpp.py
@@ -8,6 +8,46 @@
 # You are encouraged to look at the STL implementation for your platform
 # before relying on these formatters to do the right thing for your setup
 
+class StdOptionalSynthProvider:
+def __init__(self, valobj, dict):
+self.valobj = valobj
+
+def update(self):
+try:
+self.payload = self.valobj.GetChildMemberWithName('_M_payload')
+self.engaged = self.payload.GetChildMemberWithName('_M_engaged')
+self.payload_payload= 
self.payload.GetChildMemberWithName('_M_payload')
+except:
+pass
+return False
+
+def has_value(self):
+logger = lldb.formatters.Logger.Logger()
+try:
+return self.engaged.GetValueAsUnsigned(0) == 1
+except:
+logger >> "Error determining engaged value"
+return False
+
+def num_children(self):
+logger = lldb.formatters.Logger.Logger()
+try:
+num_children = 1 if self.has_value() else 0
+return num_children
+except:
+logger >> "Error determining number of children"
+
+def get_child_index(self, name):
+try:
+return int(name.lstrip('[').rstrip(']'))
+except:
+return -1
+
+def get_child_at_index(self, index):
+self.payload_value = 
self.payload_payload.GetChildMemberWithName("_M_value").GetValue()
+if (self.has_value() == False):
+pass
+return self.payload_value
 
 class AbstractListSynthProvider:
 def __init__(self, valobj, dict, has_prev):


Index: lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
===
--- lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -913,6 +913,11 @@
   SyntheticChildrenSP(new ScriptedSyntheticChildren(
   stl_deref_flags,
   "lldb.formatters.cpp.gnu_libstdcpp.StdMapLikeSynthProvider")));
+  cpp_category_sp->GetRegexTypeSyntheticsContainer()->Add(
+  RegularExpression("^std::optional<.+>(( )?&)?$"),
+  SyntheticChildrenSP(new ScriptedSyntheticChildren(
+  stl_synth_flags,
+  "lldb.formatters.cpp.gnu_libstdcpp.StdOptionalSynthProvider")));
   cpp_category_sp->GetRegexTypeSyntheticsContainer()->Add(
   RegularExpression("^std::multiset<.+> >(( )?&)?$"),
   SyntheticChildrenSP(new ScriptedSyntheticChildren(
Index: lldb/examples/synthetic/gnu_libstdcpp.py
===
--- lldb/examples/synthetic/gnu_libstdcpp.py
+++ lldb/examples/synthetic/gnu_libstdcpp.py
@@ -8,6 +8,46 @@
 # You are encouraged to look at the STL implementation for your platform
 # before relying on these formatters to do the right thing for your setup
 
+class StdOptionalSynthProvider:
+def __init__(self, valobj, dict):
+self.valobj = valobj
+
+def update(self):
+try:
+self.payload = self.valobj.GetChildMemberWithName('_M_payload')
+self.engaged = self.payload.GetChildMemberWithName('_M_engaged')
+self.payload_payload= self.payload.GetChildMemberWithName('_M_payload')
+except:
+pass
+return False
+
+def has_value(self):
+logger = lldb.formatters.Logger.Logger()
+try:
+return self.engaged.GetValueAsUnsigned(0) == 1
+except:
+logger >> "Error determining engaged value"
+  

[Lldb-commits] [PATCH] D112222: [LLDB] libcxx summary formatters for std::string_view

2021-11-19 Thread Ben Jackson via Phabricator via lldb-commits
puremourning added a comment.

In D11#3141363 , @jingham wrote:

> In D11#3141355 , @puremourning 
> wrote:
>
>> Sorry, but is anything further required from me on this patch ?
>
> You addressed an issue Shafik asked you to, so then he should make sure he's 
> happy with the change and mark the patch accepted.  OTOH we're all busy so 
> it's easy to let this sort of thing drop.  On your end, you should wait a 
> polite interval then issue a gentle ping in his direction...  A week is an 
> okay interval, I think, so now would be appropriate.

Sure, I wasn't nagging, just checking :) I completely understand how these 
things go. There's no rush.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D11

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


[Lldb-commits] [PATCH] D112222: [LLDB] libcxx summary formatters for std::string_view

2021-11-19 Thread Shafik Yaghmour via Phabricator via lldb-commits
shafik accepted this revision.
shafik added a comment.
This revision is now accepted and ready to land.

Apologies, this dropped off my radar it LGTM, thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D11

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


[Lldb-commits] [PATCH] D114288: [NFC] Refactor symbol table parsing.

2021-11-19 Thread Greg Clayton via Phabricator via lldb-commits
clayborg created this revision.
clayborg added reviewers: labath, jingham, JDevlieghere.
Herald added subscribers: sbc100, emaste.
clayborg requested review of this revision.
Herald added subscribers: lldb-commits, MaskRay, aheejin.
Herald added a project: LLDB.

Symbol table parsing has evolved over the years and many plug-ins contained 
duplicate code in the ObjectFile::GetSymtab() that used to be pure virtual. 
With this change, the "Symbtab *ObjectFile::GetSymtab()" is no longer virtual 
and will end up calling a new "void ObjectFile::ParseSymtab(Symtab &symtab)" 
pure virtual function to actually do the parsing. This helps centralize the 
code for parsing the symbol table and allows the ObjectFile base class to do 
all of the common work, like taking the necessary locks and creating the symbol 
table object itself. Plug-ins now just need to parse when they are asked to 
parse as the ParseSymtab function will only get called once.

This is a retry of the original patch https://reviews.llvm.org/D113965 which 
was reverted. There was a deadlock in the Manual DWARF indexing code during 
symbol preloading where the module was asked on the main thread to preload its 
symbols, and this would in turn cause the DWARF manual indexing to use a thread 
pool to index all of the compile units, and if there were relocations on the 
debug information sections, these threads could ask the ObjectFile to load 
section contents, which could cause a call to ObjectFileELF::RelocateSection() 
which would ask for the symbol table from the module and it would deadlock. We 
can't lock the module in ObjectFile::GetSymtab(), so the solution I am using is 
to use a llvm::once_flag to create the symbol table object once and then lock 
the Symtab object. Since all APIs on the symbol table use this lock, this will 
prevent anyone from using the symbol table before it is parsed and finalized 
and will avoid the deadlock I mentioned. ObjectFileELF::GetSymtab() was never 
locking the module lock before and would put off creating the symbol table 
until somewhere inside ObjectFileELF::GetSymtab(). Now we create it one time 
inside of the ObjectFile::GetSymtab() and immediately lock it which should be 
safe enough. This avoids the deadlocks and still provides safety.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114288

Files:
  lldb/include/lldb/Symbol/ObjectFile.h
  lldb/include/lldb/Symbol/Symtab.h
  lldb/source/Core/Module.cpp
  lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp
  lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
  lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp
  lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
  lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.h
  lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
  lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
  lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
  lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.h
  lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
  lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
  lldb/source/Symbol/ObjectFile.cpp
  lldb/source/Symbol/Symtab.cpp

Index: lldb/source/Symbol/Symtab.cpp
===
--- lldb/source/Symbol/Symtab.cpp
+++ lldb/source/Symbol/Symtab.cpp
@@ -997,10 +997,15 @@
   }
 }
 
-void Symtab::CalculateSymbolSizes() {
+void Symtab::Finalize() {
   std::lock_guard guard(m_mutex);
-  // Size computation happens inside InitAddressIndexes.
+  // Calculate the size of symbols inside InitAddressIndexes.
   InitAddressIndexes();
+  // Shrink to fit the symbols so we don't waste memory
+  if (m_symbols.capacity() > m_symbols.size()) {
+collection new_symbols(m_symbols.begin(), m_symbols.end());
+m_symbols.swap(new_symbols);
+  }
 }
 
 Symbol *Symtab::FindSymbolAtFileAddress(addr_t file_addr) {
Index: lldb/source/Symbol/ObjectFile.cpp
===
--- lldb/source/Symbol/ObjectFile.cpp
+++ lldb/source/Symbol/ObjectFile.cpp
@@ -244,7 +244,7 @@
   m_type(eTypeInvalid), m_strata(eStrataInvalid),
   m_file_offset(file_offset), m_length(length), m_data(), m_process_wp(),
   m_memory_addr(LLDB_INVALID_ADDRESS), m_sections_up(), m_symtab_up(),
-  m_synthetic_symbol_idx(0) {
+  m_symtab_once_up(new llvm::once_flag()) {
   if (file_spec_ptr)
 m_file = *file_spec_ptr;
   if (data_sp)
@@ -265,7 +265,7 @@
 : ModuleChild(module_sp), m_file(), m_type(eTypeInvalid),
   m_strata(eStrataInvalid), m_file_offset(0), m_length(0), m_data(),
   m_process_wp(process_

[Lldb-commits] [PATCH] D113965: [NFC] Refactor symbol table parsing.

2021-11-19 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added a comment.

I resubmitted with a fix in https://reviews.llvm.org/D114288


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113965

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