[Lldb-commits] [PATCH] D120100: [lldb/bindings] Expose the progress reporting machinery to the SWIG interface

2022-02-21 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib marked an inline comment as done.
mib added inline comments.



Comment at: lldb/bindings/interface/SBDebugger.i:126-129
+%apply uint64_t& INOUT { uint64_t& progress_id };
+%apply uint64_t& INOUT { uint64_t& completed };
+%apply uint64_t& INOUT { uint64_t& total };
+%apply bool& INOUT { bool& is_debugger_specific };

@labath In my understanding, these tell SWIG to return return the reference 
values as a tuple. They are pre-pending the function return value. I'll write a 
follow-up patch to test it.



Comment at: 
lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py:22-23
+listener = lldb.SBListener("lldb.progress.listener")
+listener.StartListeningForEvents(test_broadcaster,
+ self.eBroadcastBitStopProgressThread)
+

labath wrote:
> There is a race here, where some (or even all) of the progress events will be 
> generated before the listener actually starts listening for them. You need to 
> ensure that the listener setup happens-before the events are generated. The 
> easiest way to achieve that is to set up the listening on the main thread.
Thanks for catching that, I'll update the test.



Comment at: 
lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py:42
+
+@skipUnlessDarwin
+def test_dwarf_symbol_loading_progress_report(self):

labath wrote:
> Why?
So far, I know that Linux and macOS report some basic progress events when 
reading DWARF, but I'm not sure other platforms do, so I might be able to only 
skip windows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120100

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


[Lldb-commits] [lldb] ab28488 - [C++20][Modules][1/8] Track valid import state.

2022-02-21 Thread Iain Sandoe via lldb-commits

Author: Iain Sandoe
Date: 2022-02-21T09:09:37Z
New Revision: ab28488efe6de6f8fa856a1dfd8c0320d41d7608

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

LOG: [C++20][Modules][1/8] Track valid import state.

In C++20 modules imports must be together and at the start of the module.
Rather than growing more ad-hoc flags to test state, this keeps track of the
phase of of a valid module TU (first decl, global module frag, module,
private module frag).  If the phasing is broken (with some diagnostic) the
pattern does not conform to a valid C++20 module, and we set the state
accordingly.

We can thus issue diagnostics when imports appear in the wrong places and
decouple the C++20 modules state from other module variants (modules-ts and
clang modules).  Additionally, we attempt to diagnose wrong imports before
trying to find the module where possible (the latter will generally emit an
unhelpful diagnostic about the module not being available).

Although this generally simplifies the handling of C++20 module import
diagnostics, the motivation was that, in particular, it allows detecting
invalid imports like:

import module A;

int some_decl();

import module B;

where being in a module purview is insufficient to identify them.

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

Added: 
clang/test/Modules/cxx20-import-diagnostics-a.cpp

Modified: 
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/Sema.h
clang/lib/Interpreter/IncrementalParser.cpp
clang/lib/Parse/ParseAST.cpp
clang/lib/Parse/ParseObjc.cpp
clang/lib/Parse/Parser.cpp
clang/lib/Sema/SemaModule.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index e23810f402365..f21e841bcdd38 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1539,6 +1539,10 @@ def err_private_module_fragment_expected_semi : Error<
 def err_missing_before_module_end : Error<"expected %0 at end of module">;
 def err_unsupported_module_partition : Error<
   "sorry, module partitions are not yet supported">;
+def err_import_not_allowed_here : Error<
+  "imports must immediately follow the module declaration">;
+def err_import_in_wrong_fragment : Error<
+  "module%select{| partition}0 imports cannot be in the 
%select{global|private}1 module fragment">;
 
 def err_export_empty : Error<"export declaration cannot be empty">;
 }

diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 981800a7e2356..08d492a7ec721 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -464,14 +464,17 @@ class Parser : public CodeCompletionHandler {
   void Initialize();
 
   /// Parse the first top-level declaration in a translation unit.
-  bool ParseFirstTopLevelDecl(DeclGroupPtrTy &Result);
+  bool ParseFirstTopLevelDecl(DeclGroupPtrTy &Result,
+  Sema::ModuleImportState &ImportState);
 
   /// ParseTopLevelDecl - Parse one top-level declaration. Returns true if
   /// the EOF was encountered.
-  bool ParseTopLevelDecl(DeclGroupPtrTy &Result, bool IsFirstDecl = false);
+  bool ParseTopLevelDecl(DeclGroupPtrTy &Result,
+ Sema::ModuleImportState &ImportState);
   bool ParseTopLevelDecl() {
 DeclGroupPtrTy Result;
-return ParseTopLevelDecl(Result);
+Sema::ModuleImportState IS = Sema::ModuleImportState::NotACXX20Module;
+return ParseTopLevelDecl(Result, IS);
   }
 
   /// ConsumeToken - Consume the current 'peek token' and lex the next one.
@@ -3491,8 +3494,9 @@ class Parser : public CodeCompletionHandler {
 
   
//======//
   // Modules
-  DeclGroupPtrTy ParseModuleDecl(bool IsFirstDecl);
-  Decl *ParseModuleImport(SourceLocation AtLoc);
+  DeclGroupPtrTy ParseModuleDecl(Sema::ModuleImportState &ImportState);
+  Decl *ParseModuleImport(SourceLocation AtLoc,
+  Sema::ModuleImportState &ImportState);
   bool parseMisplacedModuleImport();
   bool tryParseMisplacedModuleImport() {
 tok::TokenKind Kind = Tok.getKind();

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index c1e846c55dee7..dfa12ad40b72a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2949,11 +2949,24 @@ class Sema final {
 Implementation, ///< 'module X;'
   };
 
+  /// An enumeration to represent the transition of states in parsing module
+  /// fragments and imports.  If we are not parsing a C+

[Lldb-commits] [PATCH] D119548: [lldb] Fix race condition between lldb-vscode and stop hooks executor

2022-02-21 Thread Ilya Nozhkin via Phabricator via lldb-commits
ilya-nozhkin added a comment.

In D119548#3334776 , @labath wrote:

> Do you need someone to commit this for you? (I can probably do that tomorrow)

Yes, that would be nice. I don't have commit access.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119548

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


[Lldb-commits] [PATCH] D120100: [lldb/bindings] Expose the progress reporting machinery to the SWIG interface

2022-02-21 Thread Pavel Labath via Phabricator via lldb-commits
labath added inline comments.



Comment at: lldb/bindings/interface/SBDebugger.i:126-129
+%apply uint64_t& INOUT { uint64_t& progress_id };
+%apply uint64_t& INOUT { uint64_t& completed };
+%apply uint64_t& INOUT { uint64_t& total };
+%apply bool& INOUT { bool& is_debugger_specific };

mib wrote:
> @labath In my understanding, these tell SWIG to return return the reference 
> values as a tuple. They are pre-pending the function return value. I'll write 
> a follow-up patch to test it.
Ah, that's cool. So it takes the `in` value as a regular argument, and provides 
the `out` value in the return value.

I don't suppose there's any chance of making this an `out`-only argument, to 
avoid the dummy input argument ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120100

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


[Lldb-commits] [PATCH] D119167: [lldb/test] Remove sleeps from some lldb-server tests

2022-02-21 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl added a comment.

This looks amazing! Thanks, Pavel.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119167

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


[Lldb-commits] [PATCH] D120105: Remove recursive include of GDBRemoteCommunicationServerCommon.h

2022-02-21 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl accepted this revision.
aprantl added a comment.
This revision is now accepted and ready to land.

This is funny.


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

https://reviews.llvm.org/D120105

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


[Lldb-commits] [PATCH] D119915: Replace use of double underscore in identifiers

2022-02-21 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl added a comment.
Herald added a subscriber: JDevlieghere.

Nice.




Comment at: lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp:261
 if (m_pair_ptr) {
-  auto __i_(valobj_sp->GetChildMemberWithName(g___i_, true));
+  auto __i_(valobj_sp->GetChildMemberWithName(g_i_, true));
   if (!__i_) {

This one also contains a double __?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119915

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


[Lldb-commits] [PATCH] D120101: [lldb] Fix (unintentional) recursion in CommandObjectRegexCommand

2022-02-21 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere updated this revision to Diff 410326.
JDevlieghere marked 2 inline comments as done.
JDevlieghere added a comment.

- Allow using `%0`
- Return an error when using an out of range index


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

https://reviews.llvm.org/D120101

Files:
  lldb/include/lldb/Interpreter/CommandReturnObject.h
  lldb/source/Commands/CommandObjectRegexCommand.cpp
  lldb/source/Commands/CommandObjectRegexCommand.h
  lldb/source/Interpreter/CommandReturnObject.cpp
  lldb/unittests/Interpreter/CMakeLists.txt
  lldb/unittests/Interpreter/TestRegexCommand.cpp

Index: lldb/unittests/Interpreter/TestRegexCommand.cpp
===
--- /dev/null
+++ lldb/unittests/Interpreter/TestRegexCommand.cpp
@@ -0,0 +1,68 @@
+//===-- TestRegexCommand.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Commands/CommandObjectRegexCommand.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gtest/gtest.h"
+
+using namespace lldb_private;
+using namespace lldb;
+
+namespace {
+class TestRegexCommand : public CommandObjectRegexCommand {
+public:
+  using CommandObjectRegexCommand::SubstituteVariables;
+
+  static std::string
+  Substitute(llvm::StringRef input,
+ const llvm::SmallVectorImpl &replacements) {
+llvm::Expected str = SubstituteVariables(input, replacements);
+if (!str)
+  return llvm::toString(str.takeError());
+return *str;
+  }
+};
+} // namespace
+
+TEST(RegexCommandTest, SubstituteVariablesSuccess) {
+  const llvm::SmallVector substitutions = {"all", "foo",
+   "bar", "baz"};
+
+  EXPECT_EQ(TestRegexCommand::Substitute("%0", substitutions), "all");
+  EXPECT_EQ(TestRegexCommand::Substitute("%1", substitutions), "foo");
+  EXPECT_EQ(TestRegexCommand::Substitute("%2", substitutions), "bar");
+  EXPECT_EQ(TestRegexCommand::Substitute("%3", substitutions), "baz");
+  EXPECT_EQ(TestRegexCommand::Substitute("%1%2%3", substitutions), "foobarbaz");
+  EXPECT_EQ(TestRegexCommand::Substitute("#%1#%2#%3#", substitutions),
+"#foo#bar#baz#");
+}
+
+TEST(RegexCommandTest, SubstituteVariablesFailed) {
+  const llvm::SmallVector substitutions = {"all", "foo",
+   "bar", "baz"};
+
+  ASSERT_THAT_EXPECTED(
+  TestRegexCommand::SubstituteVariables("%1%2%3%4", substitutions),
+  llvm::Failed());
+  ASSERT_THAT_EXPECTED(
+  TestRegexCommand::SubstituteVariables("%5", substitutions),
+  llvm::Failed());
+  ASSERT_THAT_EXPECTED(
+  TestRegexCommand::SubstituteVariables("%11", substitutions),
+  llvm::Failed());
+}
+
+TEST(RegexCommandTest, SubstituteVariablesNoRecursion) {
+  const llvm::SmallVector substitutions = {"all", "%2",
+   "%3", "%4"};
+  EXPECT_EQ(TestRegexCommand::Substitute("%0", substitutions), "all");
+  EXPECT_EQ(TestRegexCommand::Substitute("%1", substitutions), "%2");
+  EXPECT_EQ(TestRegexCommand::Substitute("%2", substitutions), "%3");
+  EXPECT_EQ(TestRegexCommand::Substitute("%3", substitutions), "%4");
+  EXPECT_EQ(TestRegexCommand::Substitute("%1%2%3", substitutions), "%2%3%4");
+}
Index: lldb/unittests/Interpreter/CMakeLists.txt
===
--- lldb/unittests/Interpreter/CMakeLists.txt
+++ lldb/unittests/Interpreter/CMakeLists.txt
@@ -4,6 +4,7 @@
   TestOptionArgParser.cpp
   TestOptionValue.cpp
   TestOptionValueFileColonLine.cpp
+  TestRegexCommand.cpp
 
   LINK_LIBS
   lldbCore
@@ -14,4 +15,5 @@
   lldbUtilityHelpers
   lldbInterpreter
   lldbPluginPlatformMacOSX
+  LLVMTestingSupport
 )
Index: lldb/source/Interpreter/CommandReturnObject.cpp
===
--- lldb/source/Interpreter/CommandReturnObject.cpp
+++ lldb/source/Interpreter/CommandReturnObject.cpp
@@ -109,6 +109,11 @@
   AppendError(error.AsCString(fallback_error_cstr));
 }
 
+void CommandReturnObject::SetError(llvm::Error error) {
+  if (error)
+AppendError(llvm::toString(std::move(error)));
+}
+
 // Similar to AppendError, but do not prepend 'Status: ' to message, and don't
 // append "\n" to the end of it.
 
Index: lldb/source/Commands/CommandObjectRegexCommand.h
===
--- lldb/source/Commands/CommandObjectRegexCommand.h
+++ lldb/source/Commands/CommandObjectRegexCommand.h
@@ -39,6 +39,11 @@
 protected:
   bool DoExecute(llvm::StringRef command, CommandReturnObject &result) override;
 
+  /// Substitute vari

[Lldb-commits] [PATCH] D120284: [lldb/test] Fix TestProgressReporting.py race issue with the event listener

2022-02-21 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib created this revision.
mib added a reviewer: labath.
mib added a project: LLDB.
Herald added a subscriber: JDevlieghere.
mib requested review of this revision.
Herald added a subscriber: lldb-commits.

This patch is a follow-up of D120100  to 
address some feedbacks from
@labath.

This should mainly fix the race issue with the even listener by moving
the listener setup to the main thread.

This also updates the test to check it the inout arguments are returned
in a tuple and re-enables the test on linux.

Signed-off-by: Med Ismail Bennani 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120284

Files:
  lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py


Index: lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
===
--- lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
+++ lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
@@ -17,41 +17,43 @@
 TestBase.setUp(self)
 self.progress_events = []
 
-def fetch_events(self, test_broadcaster):
-listener = lldb.SBListener("lldb.progress.listener")
-listener.StartListeningForEvents(test_broadcaster,
- self.eBroadcastBitStopProgressThread)
-
-progress_broadcaster = self.dbg.GetBroadcaster()
-progress_broadcaster.AddListener(listener, 
lldb.SBDebugger.eBroadcastBitProgress)
-
+def fetch_events(self):
 event = lldb.SBEvent()
 
 done = False
 while not done:
-if listener.WaitForEvent(1, event):
+if self.listener.WaitForEvent(1, event):
 event_mask = event.GetType();
-if event.BroadcasterMatchesRef(test_broadcaster):
+if event.BroadcasterMatchesRef(self.test_broadcaster):
 if event_mask & self.eBroadcastBitStopProgressThread:
 done = True;
-elif event.BroadcasterMatchesRef(progress_broadcaster):
-message = lldb.SBDebugger().GetProgressFromEvent(event, 0, 
0, 0, False);
+elif event.BroadcasterMatchesRef(self.progress_broadcaster):
+ret_args = lldb.SBDebugger().GetProgressFromEvent(event, 
0, 0, 0, False);
+self.assertGreater(len(ret_args), 1)
+
+message = ret_args[0]
 if message:
 self.progress_events.append((message, event))
 
-@skipUnlessDarwin
+@skipIf(oslist=no_match(['darwin','macos','linux']))
 def test_dwarf_symbol_loading_progress_report(self):
 """Test that we are able to fetch dwarf symbol loading progress 
events"""
 self.build()
 
-test_broadcaster = lldb.SBBroadcaster('lldb.broadcaster.test')
-listener_thread = threading.Thread(target=self.fetch_events,
-   args=[test_broadcaster])
+self.listener = lldb.SBListener("lldb.progress.listener")
+self.test_broadcaster = lldb.SBBroadcaster('lldb.broadcaster.test')
+self.listener.StartListeningForEvents(self.test_broadcaster,
+ self.eBroadcastBitStopProgressThread)
+
+self.progress_broadcaster = self.dbg.GetBroadcaster()
+self.progress_broadcaster.AddListener(self.listener, 
lldb.SBDebugger.eBroadcastBitProgress)
+
+listener_thread = threading.Thread(target=self.fetch_events)
 listener_thread.start()
 
 lldbutil.run_to_source_breakpoint(self, 'break here', 
lldb.SBFileSpec('main.c'))
 
-
test_broadcaster.BroadcastEventByType(self.eBroadcastBitStopProgressThread)
+
self.test_broadcaster.BroadcastEventByType(self.eBroadcastBitStopProgressThread)
 listener_thread.join()
 
 self.assertTrue(len(self.progress_events) > 0)


Index: lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
===
--- lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
+++ lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
@@ -17,41 +17,43 @@
 TestBase.setUp(self)
 self.progress_events = []
 
-def fetch_events(self, test_broadcaster):
-listener = lldb.SBListener("lldb.progress.listener")
-listener.StartListeningForEvents(test_broadcaster,
- self.eBroadcastBitStopProgressThread)
-
-progress_broadcaster = self.dbg.GetBroadcaster()
-progress_broadcaster.AddListener(listener, lldb.SBDebugger.eBroadcastBitProgress)
-
+def fetch_events(self):
 event = lldb.SBEvent()
 
 done = False
 while not done:
-if listener.WaitForEvent(1, event):
+if self.listener.WaitForEvent(1, event):
  

[Lldb-commits] [PATCH] D120100: [lldb/bindings] Expose the progress reporting machinery to the SWIG interface

2022-02-21 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib marked 3 inline comments as done.
mib added a comment.

@labath I addressed your comments in D120284  
:)




Comment at: lldb/bindings/interface/SBDebugger.i:126-129
+%apply uint64_t& INOUT { uint64_t& progress_id };
+%apply uint64_t& INOUT { uint64_t& completed };
+%apply uint64_t& INOUT { uint64_t& total };
+%apply bool& INOUT { bool& is_debugger_specific };

labath wrote:
> mib wrote:
> > @labath In my understanding, these tell SWIG to return return the reference 
> > values as a tuple. They are pre-pending the function return value. I'll 
> > write a follow-up patch to test it.
> Ah, that's cool. So it takes the `in` value as a regular argument, and 
> provides the `out` value in the return value.
> 
> I don't suppose there's any chance of making this an `out`-only argument, to 
> avoid the dummy input argument ?
I don't think SWIG offers such thing unfortunately.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120100

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


[Lldb-commits] [PATCH] D119915: Replace use of double underscore in identifiers

2022-02-21 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added a comment.

Assuming all issues have been fixed, can you add this clang-tidy check to the 
`.clang-tidy` file in the root of the repository? That should make it less 
likely this regresses again in the future.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119915

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


[Lldb-commits] [PATCH] D120292: [lldb] Add lldb.find helper function

2022-02-21 Thread Dave Lee via Phabricator via lldb-commits
kastiglione created this revision.
kastiglione added reviewers: mib, JDevlieghere, jasonmolenda.
kastiglione requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Add `lldb.find()`, a function for interactive lookup and discovery of SB API.

>From the lldb console, this function can be used as follows:

  (lldb) script lldb.find("register")
  lldb.SBFrame.FindRegister
  lldb.SBFrame.GetRegisters
  lldb.SBFrame.get_registers_access
  lldb.SBFrame.register
  lldb.SBFrame.registers
  
  (lldb) sc lldb.find("Disassemble")
  Help on function Disassemble in lldb.SBFrame:
  
  lldb.SBFrame.Disassemble = Disassemble(self) -> 'char const *'
  Disassemble(SBFrame self) -> char const *

In the first case, multiple matches were printed. In the second case, only one
match was found, and so its `help()` documentation was printed.

The results compose with the builtin `help()` function:

  (lldb) sc help(lldb.SBFrame.FindRegister)
  ...

If called often enough, a `command regex` can come in handy:

  command regex findapi
  s/(.+)/script lldb.find("%1")/

Which allows it to be called as `findapi register`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120292

Files:
  lldb/bindings/python/python-extensions.swig


Index: lldb/bindings/python/python-extensions.swig
===
--- lldb/bindings/python/python-extensions.swig
+++ lldb/bindings/python/python-extensions.swig
@@ -523,9 +523,39 @@
 
 def __ne__(self, other):
 return not self.__eq__(other)
-%}
 
-%pythoncode %{
+
+def find(pattern, flags=re.I):
+"""
+Find matching SB methods/properties. See also Python's builtin `help()`.
+"""
+import lldb
+import re
+
+regex = re.compile(pattern, flags)
+
+# Gather matching methods and properties.
+methods = []
+
+for attr in dir(lldb):
+value = getattr(lldb, attr)
+if not isinstance(value, type):
+continue
+
+class_name = attr
+class_type = value
+for method_name in dir(class_type):
+if regex.search(method_name):
+methods.append(f"lldb.{class_name}.{method_name}")
+
+if len(methods) == 1:
+# For one match, print its help.
+help(methods[0])
+return
+
+# Print the name of each matching method or property.
+print(*methods, sep="\n")
+
 
 class SBSyntheticValueProvider(object):
 def __init__(self,valobj):
@@ -547,10 +577,6 @@
 return False
 
 
-%}
-
-%pythoncode %{
-
 # given an lldb.SBBasicType it returns a tuple
 # (is_numeric, is_signed)
 # the value of is_signed is undefined if is_numeric == false


Index: lldb/bindings/python/python-extensions.swig
===
--- lldb/bindings/python/python-extensions.swig
+++ lldb/bindings/python/python-extensions.swig
@@ -523,9 +523,39 @@
 
 def __ne__(self, other):
 return not self.__eq__(other)
-%}
 
-%pythoncode %{
+
+def find(pattern, flags=re.I):
+"""
+Find matching SB methods/properties. See also Python's builtin `help()`.
+"""
+import lldb
+import re
+
+regex = re.compile(pattern, flags)
+
+# Gather matching methods and properties.
+methods = []
+
+for attr in dir(lldb):
+value = getattr(lldb, attr)
+if not isinstance(value, type):
+continue
+
+class_name = attr
+class_type = value
+for method_name in dir(class_type):
+if regex.search(method_name):
+methods.append(f"lldb.{class_name}.{method_name}")
+
+if len(methods) == 1:
+# For one match, print its help.
+help(methods[0])
+return
+
+# Print the name of each matching method or property.
+print(*methods, sep="\n")
+
 
 class SBSyntheticValueProvider(object):
 def __init__(self,valobj):
@@ -547,10 +577,6 @@
 return False
 
 
-%}
-
-%pythoncode %{
-
 # given an lldb.SBBasicType it returns a tuple
 # (is_numeric, is_signed)
 # the value of is_signed is undefined if is_numeric == false
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 14101f4 - [LLDB] Remove recursive include of GDBRemoteCommunicationServerCommon.h

2022-02-21 Thread Shafik Yaghmour via lldb-commits

Author: Shafik Yaghmour
Date: 2022-02-21T18:46:12-08:00
New Revision: 14101f48d205b6cbf65b28c469d898e90e3995d2

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

LOG: [LLDB] Remove recursive include of GDBRemoteCommunicationServerCommon.h

GDBRemoteCommunicationServerCommon.h includes itself, removing this include.

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

Added: 


Modified: 
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h

Removed: 




diff  --git 
a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h 
b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h
index 029972348ef01..f696cb5c61c66 100644
--- 
a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h
+++ 
b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h
@@ -15,7 +15,6 @@
 #include "lldb/lldb-private-forward.h"
 
 #include "GDBRemoteCommunicationServer.h"
-#include "GDBRemoteCommunicationServerCommon.h"
 
 class StringExtractorGDBRemote;
 



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


[Lldb-commits] [PATCH] D120105: Remove recursive include of GDBRemoteCommunicationServerCommon.h

2022-02-21 Thread Shafik Yaghmour via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG14101f48d205: [LLDB] Remove recursive include of 
GDBRemoteCommunicationServerCommon.h (authored by shafik).
Herald added a project: LLDB.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120105

Files:
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h


Index: 
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h
@@ -15,7 +15,6 @@
 #include "lldb/lldb-private-forward.h"
 
 #include "GDBRemoteCommunicationServer.h"
-#include "GDBRemoteCommunicationServerCommon.h"
 
 class StringExtractorGDBRemote;
 


Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h
@@ -15,7 +15,6 @@
 #include "lldb/lldb-private-forward.h"
 
 #include "GDBRemoteCommunicationServer.h"
-#include "GDBRemoteCommunicationServerCommon.h"
 
 class StringExtractorGDBRemote;
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D120292: [lldb] Add lldb.find helper function

2022-02-21 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda added a comment.

Nice.  tbh when I'm SB API scripting, I am often sitting in include/lldb/API 
and grepping for keywords, because I can't remember exactly which class 
provides the API, or what arguments it takes or whatever.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120292

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


[Lldb-commits] [PATCH] D120292: [lldb] Add lldb.find helper function

2022-02-21 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! Could you add a little test to exercise the command ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120292

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


[Lldb-commits] [PATCH] D120284: [lldb/test] Fix TestProgressReporting.py race issue with the event listener

2022-02-21 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 410449.

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

https://reviews.llvm.org/D120284

Files:
  lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py


Index: lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
===
--- lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
+++ lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
@@ -17,41 +17,43 @@
 TestBase.setUp(self)
 self.progress_events = []
 
-def fetch_events(self, test_broadcaster):
-listener = lldb.SBListener("lldb.progress.listener")
-listener.StartListeningForEvents(test_broadcaster,
- self.eBroadcastBitStopProgressThread)
-
-progress_broadcaster = self.dbg.GetBroadcaster()
-progress_broadcaster.AddListener(listener, 
lldb.SBDebugger.eBroadcastBitProgress)
-
+def fetch_events(self):
 event = lldb.SBEvent()
 
 done = False
 while not done:
-if listener.WaitForEvent(1, event):
+if self.listener.WaitForEvent(1, event):
 event_mask = event.GetType();
-if event.BroadcasterMatchesRef(test_broadcaster):
+if event.BroadcasterMatchesRef(self.test_broadcaster):
 if event_mask & self.eBroadcastBitStopProgressThread:
 done = True;
-elif event.BroadcasterMatchesRef(progress_broadcaster):
-message = lldb.SBDebugger().GetProgressFromEvent(event, 0, 
0, 0, False);
+elif event.BroadcasterMatchesRef(self.progress_broadcaster):
+ret_args = lldb.SBDebugger().GetProgressFromEvent(event, 
0, 0, 0, False);
+self.assertGreater(len(ret_args), 1)
+
+message = ret_args[0]
 if message:
 self.progress_events.append((message, event))
 
-@skipUnlessDarwin
+@skipIf(oslist=no_match(['darwin','macos','linux']))
 def test_dwarf_symbol_loading_progress_report(self):
 """Test that we are able to fetch dwarf symbol loading progress 
events"""
 self.build()
 
-test_broadcaster = lldb.SBBroadcaster('lldb.broadcaster.test')
-listener_thread = threading.Thread(target=self.fetch_events,
-   args=[test_broadcaster])
+self.listener = lldb.SBListener("lldb.progress.listener")
+self.test_broadcaster = lldb.SBBroadcaster('lldb.broadcaster.test')
+self.listener.StartListeningForEvents(self.test_broadcaster,
+  
self.eBroadcastBitStopProgressThread)
+
+self.progress_broadcaster = self.dbg.GetBroadcaster()
+self.progress_broadcaster.AddListener(self.listener, 
lldb.SBDebugger.eBroadcastBitProgress)
+
+listener_thread = threading.Thread(target=self.fetch_events)
 listener_thread.start()
 
 lldbutil.run_to_source_breakpoint(self, 'break here', 
lldb.SBFileSpec('main.c'))
 
-
test_broadcaster.BroadcastEventByType(self.eBroadcastBitStopProgressThread)
+
self.test_broadcaster.BroadcastEventByType(self.eBroadcastBitStopProgressThread)
 listener_thread.join()
 
-self.assertTrue(len(self.progress_events) > 0)
+self.assertGreater(len(self.progress_events), 0)


Index: lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
===
--- lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
+++ lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
@@ -17,41 +17,43 @@
 TestBase.setUp(self)
 self.progress_events = []
 
-def fetch_events(self, test_broadcaster):
-listener = lldb.SBListener("lldb.progress.listener")
-listener.StartListeningForEvents(test_broadcaster,
- self.eBroadcastBitStopProgressThread)
-
-progress_broadcaster = self.dbg.GetBroadcaster()
-progress_broadcaster.AddListener(listener, lldb.SBDebugger.eBroadcastBitProgress)
-
+def fetch_events(self):
 event = lldb.SBEvent()
 
 done = False
 while not done:
-if listener.WaitForEvent(1, event):
+if self.listener.WaitForEvent(1, event):
 event_mask = event.GetType();
-if event.BroadcasterMatchesRef(test_broadcaster):
+if event.BroadcasterMatchesRef(self.test_broadcaster):
 if event_mask & self.eBroadcastBitStopProgressThread:
 done = True;
-elif event.BroadcasterMatchesRef(progress_broadcaster):
-message = lldb.SBDebugger().GetProgressFromEvent(event, 0, 0