[Lldb-commits] [lldb] [lldb] Add missing include to SBLanguages.h (PR #111763)

2024-10-09 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben approved this pull request.

LGTM!

https://github.com/llvm/llvm-project/pull/111763
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Check for Python 'packaging' module at configuration time (PR #111747)

2024-10-09 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben approved this pull request.

Nice! LGTM!

https://github.com/llvm/llvm-project/pull/111747
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add SBTypeStaticField to SBDefines (PR #111560)

2024-10-08 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben approved this pull request.

LGTM!

https://github.com/llvm/llvm-project/pull/111560
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Unify implementation of CommandReturnObject::SetError(NFC) (PR #110707)

2024-10-01 Thread Med Ismail Bennani via lldb-commits

medismailben wrote:

> I actually think it's fine to change this behavior, I don't think anyone 
> would have expected SetError to AppendError...

If you feel strongly about this (I actually think you have a point), you could 
make `SetError` as deprecated and have it call a newly added `AppendError` API 
which makes more sense IMO.

https://github.com/llvm/llvm-project/pull/110707
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Unify implementation of CommandReturnObject::SetError(NFC) (PR #110707)

2024-10-01 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben commented:

LGTM!

https://github.com/llvm/llvm-project/pull/110707
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-10-01 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben approved this pull request.


https://github.com/llvm/llvm-project/pull/99736
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Inline expression evaluator error visualization (PR #106470)

2024-09-24 Thread Med Ismail Bennani via lldb-commits


@@ -486,19 +603,37 @@ bool 
CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
 
 result.SetStatus(eReturnStatusSuccessFinishResult);
   } else {
-const char *error_cstr = result_valobj_sp->GetError().AsCString();
-if (error_cstr && error_cstr[0]) {
-  const size_t error_cstr_len = strlen(error_cstr);
-  const bool ends_with_newline = error_cstr[error_cstr_len - 1] == 
'\n';
-  if (strstr(error_cstr, "error:") != error_cstr)
-error_stream.PutCString("error: ");
-  error_stream.Write(error_cstr, error_cstr_len);
-  if (!ends_with_newline)
-error_stream.EOL();
+// Retrieve the diagnostics.
+std::vector details;
+llvm::consumeError(
+llvm::handleErrors(result_valobj_sp->GetError().ToError(),
+   [&](DetailedExpressionError &error) {
+ details.push_back(error.GetDetail());
+   }));
+// Find the position of the expression in the command.
+std::optional expr_pos;
+size_t nchar = m_original_command.find(expr);
+if (nchar != std::string::npos)
+  expr_pos = nchar + GetDebugger().GetPrompt().size();
+
+if (!details.empty()) {
+  bool multiline = expr.contains('\n');
+  RenderDiagnosticDetails(error_stream, expr_pos, multiline, details);
 } else {
-  error_stream.PutCString("error: unknown error\n");
+  const char *error_cstr = result_valobj_sp->GetError().AsCString();
+  if (error_cstr && error_cstr[0]) {
+const size_t error_cstr_len = strlen(error_cstr);
+const bool ends_with_newline =
+error_cstr[error_cstr_len - 1] == '\n';
+if (strstr(error_cstr, "error:") != error_cstr)

medismailben wrote:

Instead of using c-string you could wrap it in an `llvm::StringRef` and 
simplify this part here.

https://github.com/llvm/llvm-project/pull/106470
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Inline expression evaluator error visualization (PR #106470)

2024-09-24 Thread Med Ismail Bennani via lldb-commits


@@ -8,6 +8,7 @@
 
 #include "lldb/Utility/Status.h"
 
+#include "lldb/Expression/DiagnosticManager.h"

medismailben wrote:

Is this addition necessary ? It doesn't look like anything else has been added 
to this file

https://github.com/llvm/llvm-project/pull/106470
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Inline expression evaluator error visualization (PR #106470)

2024-09-24 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben approved this pull request.

This is pretty cool! LGTM with comment!

https://github.com/llvm/llvm-project/pull/106470
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Inline expression evaluator error visualization (PR #106470)

2024-09-24 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben edited 
https://github.com/llvm/llvm-project/pull/106470
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Inline expression evaluator error visualization (PR #106470)

2024-09-24 Thread Med Ismail Bennani via lldb-commits


@@ -1887,7 +1887,8 @@ bool CommandInterpreter::HandleCommand(const char 
*command_line,
CommandReturnObject &result,
bool force_repeat_command) {
   std::string command_string(command_line);
-  std::string original_command_string(command_line);
+  std::string original_command_string(command_string);
+  std::string real_original_command_string(command_string);

medismailben wrote:

nit: does this makes the variable above not the real original command string :p 
? may be we can find a better name or write a comment explaining the nuance 
between the 2

https://github.com/llvm/llvm-project/pull/106470
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Store expression evaluator diagnostics in an llvm::Error (NFC) (PR #106442)

2024-09-24 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben deleted 
https://github.com/llvm/llvm-project/pull/106442
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Store expression evaluator diagnostics in an llvm::Error (NFC) (PR #106442)

2024-09-24 Thread Med Ismail Bennani via lldb-commits


@@ -61,8 +65,50 @@ std::string DiagnosticManager::GetString(char separator) {
   stream << message.drop_front(severity_pos + severity.size());
 stream << separator;
   }
+  return str;
+}
 
-  return ret;
+void DiagnosticManager::Dump(Log *log) {
+  if (!log)
+return;
+
+  std::string str = GetString();
+
+  // We want to remove the last '\n' because log->PutCString will add
+  // one for us.
+
+  if (str.size() && str.back() == '\n')
+str.pop_back();
+
+  log->PutString(str);
+}
+
+llvm::Error Diagnostic::GetAsError() const {
+  return llvm::make_error(m_detail);
+}
+
+llvm::Error
+DiagnosticManager::GetAsError(lldb::ExpressionResults result) const {
+  llvm::Error diags = Status::FromExpressionError(result, "").takeError();
+  for (const auto &diagnostic : m_diagnostics)
+diags = llvm::joinErrors(std::move(diags), diagnostic->GetAsError());
+  return diags;
+}
+
+llvm::Error DiagnosticManager::GetAsError(llvm::Twine msg) const {
+  llvm::Error diags = llvm::createStringError(msg);
+  for (const auto &diagnostic : m_diagnostics)
+diags = llvm::joinErrors(std::move(diags), diagnostic->GetAsError());
+  return diags;
+}
+
+void DiagnosticManager::AddDiagnostic(llvm::StringRef message,
+  lldb::Severity severity,
+  DiagnosticOrigin origin,
+  uint32_t compiler_id) {
+  m_diagnostics.emplace_back(std::make_unique(
+  origin, compiler_id,
+  DiagnosticDetail{{}, severity, message.str(), message.str()}));

medismailben wrote:

It would be nice to have the `SourceLocation` here to pass it to 
`DiagnosticDetail`

https://github.com/llvm/llvm-project/pull/106442
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Store expression evaluator diagnostics in an llvm::Error (NFC) (PR #106442)

2024-09-24 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben deleted 
https://github.com/llvm/llvm-project/pull/106442
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Store expression evaluator diagnostics in an llvm::Error (NFC) (PR #106442)

2024-09-24 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben approved this pull request.

LGTM with comments!

https://github.com/llvm/llvm-project/pull/106442
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Store expression evaluator diagnostics in an llvm::Error (NFC) (PR #106442)

2024-09-24 Thread Med Ismail Bennani via lldb-commits


@@ -33,16 +33,16 @@ class RemoteAwarePlatformTester : public 
RemoteAwarePlatform {
   MOCK_METHOD0(CalculateTrapHandlerSymbolNames, void());
 
   MOCK_METHOD2(ResolveExecutable,
-   std::pair(const ModuleSpec &,
-   const FileSpecList *));
+   std::pair(const ModuleSpec &,
+ const FileSpecList *));
   Status
   ResolveExecutable(const ModuleSpec &module_spec,
 lldb::ModuleSP &exe_module_sp,
 const FileSpecList *module_search_paths_ptr) /*override*/
   { // NOLINT(modernize-use-override)
 auto pair = ResolveExecutable(module_spec, module_search_paths_ptr);
 exe_module_sp = pair.second;
-return pair.first;
+return pair.first ? Status() : Status::FromErrorString("error");

medismailben wrote:

Can we return `{}` instead of `Status()` ?

https://github.com/llvm/llvm-project/pull/106442
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Store expression evaluator diagnostics in an llvm::Error (NFC) (PR #106442)

2024-09-24 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben edited 
https://github.com/llvm/llvm-project/pull/106442
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Store expression evaluator diagnostics in an llvm::Error (NFC) (PR #106442)

2024-09-24 Thread Med Ismail Bennani via lldb-commits


@@ -224,6 +224,14 @@ const char *Status::AsCString(const char 
*default_error_str) const {
 if (!m_string.empty() && m_string[m_string.size() - 1] == '\n')
   m_string.pop_back();
 
+  // FIXME: Workaround for ErrorList[ExpressionError, ...].
+  if (m_error.isA()) {
+while (!m_string.empty() && m_string[0] == '\n')
+  m_string = std::string(m_string.data() + 1, m_string.size() - 1);
+if (!m_string.empty() && m_string[m_string.size() - 1] != '\n')
+  m_string += '\n';
+  }

medismailben wrote:

It's not clear what this is trying to do. A comment would be nice here.

https://github.com/llvm/llvm-project/pull/106442
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Store expression evaluator diagnostics in an llvm::Error (NFC) (PR #106442)

2024-09-24 Thread Med Ismail Bennani via lldb-commits


@@ -27,15 +27,15 @@ TEST(StatusTest, Formatv) {
 }
 
 TEST(StatusTest, ErrorConstructor) {
-  EXPECT_TRUE(Status(llvm::Error::success()).Success());
+  EXPECT_TRUE(Status::FromError(llvm::Error::success()).Success());
 
-  Status eagain(
+  Status eagain = Status::FromError(
   llvm::errorCodeToError(std::error_code(EAGAIN, 
std::generic_category(;
   EXPECT_TRUE(eagain.Fail());
   EXPECT_EQ(eErrorTypePOSIX, eagain.GetType());
   EXPECT_EQ(Status::ValueType(EAGAIN), eagain.GetError());
 
-  Status foo(llvm::make_error(
+  Status foo = Status::FromError(llvm::make_error(
   "foo", llvm::inconvertibleErrorCode()));

medismailben wrote:

```suggestion
  Status foo = Status::FromError(llvm::createStringError("foo"));
```

https://github.com/llvm/llvm-project/pull/106442
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Store expression evaluator diagnostics in an llvm::Error (NFC) (PR #106442)

2024-09-24 Thread Med Ismail Bennani via lldb-commits


@@ -254,14 +256,46 @@ class ClangDiagnosticManagerAdapter : public 
clang::DiagnosticConsumer {
   std::string stripped_output =
   std::string(llvm::StringRef(m_output).trim());
 
-  auto new_diagnostic = std::make_unique(
-  stripped_output, severity, Info.getID());
+  // Translate the source location.
+  if (Info.hasSourceManager()) {
+DiagnosticDetail::SourceLocation loc;
+clang::SourceManager &sm = Info.getSourceManager();
+const clang::SourceLocation sloc = Info.getLocation();
+if (sloc.isValid()) {
+  const clang::FullSourceLoc fsloc(sloc, sm);
+  clang::PresumedLoc PLoc = fsloc.getPresumedLoc(true);
+  StringRef filename =
+  PLoc.isValid() ? PLoc.getFilename() : StringRef{};

medismailben wrote:

What about using `m_filename` if `PLoc` is invalid ?

https://github.com/llvm/llvm-project/pull/106442
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add the ability to define custom completers to the parsed_cmd template. (PR #109062)

2024-09-23 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben approved this pull request.

LGTM! Thanks for addressing my comments :) 

https://github.com/llvm/llvm-project/pull/109062
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/Interpreter] Introduce ScriptedStopHook{, Python}Interface & make use of it (PR #109498)

2024-09-20 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben closed 
https://github.com/llvm/llvm-project/pull/109498
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/Interpreter] Introduce ScriptedStopHook{, Python}Interface & make use of it (PR #109498)

2024-09-20 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben created 
https://github.com/llvm/llvm-project/pull/109498

This patch re-lands #105449 and fixes the various test failures.

>From 6faa2d6ccad438818dd80c601a31a883fe29c882 Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani 
Date: Fri, 20 Sep 2024 16:26:59 -0700
Subject: [PATCH 1/3] [lldb/Interpreter] Create
 ScriptedStopHook{,Python}Interface (NFC)

This patch introduces a new scripted interface for ScriptedStopHooks.

This will be used in a follow-up patch to call into the script methods.

Signed-off-by: Med Ismail Bennani 
---
 .../Interfaces/ScriptedStopHookInterface.h| 33 
 .../lldb/Interpreter/ScriptInterpreter.h  |  4 +
 lldb/include/lldb/lldb-forward.h  |  3 +
 .../Python/Interfaces/CMakeLists.txt  |  1 +
 .../ScriptInterpreterPythonInterfaces.cpp |  2 +
 .../ScriptInterpreterPythonInterfaces.h   |  1 +
 .../ScriptedStopHookPythonInterface.cpp   | 75 +++
 .../ScriptedStopHookPythonInterface.h | 51 +
 .../Python/ScriptInterpreterPython.cpp|  5 ++
 .../Python/ScriptInterpreterPythonImpl.h  |  2 +
 10 files changed, 177 insertions(+)
 create mode 100644 
lldb/include/lldb/Interpreter/Interfaces/ScriptedStopHookInterface.h
 create mode 100644 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedStopHookPythonInterface.cpp
 create mode 100644 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedStopHookPythonInterface.h

diff --git 
a/lldb/include/lldb/Interpreter/Interfaces/ScriptedStopHookInterface.h 
b/lldb/include/lldb/Interpreter/Interfaces/ScriptedStopHookInterface.h
new file mode 100644
index 00..a829e62351fe85
--- /dev/null
+++ b/lldb/include/lldb/Interpreter/Interfaces/ScriptedStopHookInterface.h
@@ -0,0 +1,33 @@
+//===-- ScriptedStopHookInterface.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_INTERPRETER_INTERFACES_SCRIPTEDSTOPHOOKINTERFACE_H
+#define LLDB_INTERPRETER_INTERFACES_SCRIPTEDSTOPHOOKINTERFACE_H
+
+#include "lldb/lldb-private.h"
+
+#include "ScriptedInterface.h"
+
+namespace lldb_private {
+class ScriptedStopHookInterface : public ScriptedInterface {
+public:
+  virtual llvm::Expected
+  CreatePluginObject(llvm::StringRef class_name, lldb::TargetSP target_sp,
+ const StructuredDataImpl &args_sp) = 0;
+
+  /// "handle_stop" will return a bool with the meaning "should_stop"...
+  /// If nothing is returned, we'll assume we are going to stop.
+  /// Also any errors should return true, since we should stop on error.
+  virtual llvm::Expected HandleStop(ExecutionContext &exe_ctx,
+  lldb::StreamSP &output_sp) {
+return true;
+  }
+};
+} // namespace lldb_private
+
+#endif // LLDB_INTERPRETER_INTERFACES_SCRIPTEDSTOPHOOKINTERFACE_H
diff --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h 
b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
index addb1394ab5652..8fabe6f250b084 100644
--- a/lldb/include/lldb/Interpreter/ScriptInterpreter.h
+++ b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
@@ -561,6 +561,10 @@ class ScriptInterpreter : public PluginInterface {
 return {};
   }
 
+  virtual lldb::ScriptedStopHookInterfaceSP CreateScriptedStopHookInterface() {
+return {};
+  }
+
   virtual StructuredData::ObjectSP
   CreateStructuredDataFromScriptObject(ScriptObject obj) {
 return {};
diff --git a/lldb/include/lldb/lldb-forward.h b/lldb/include/lldb/lldb-forward.h
index 5fb288ad43af48..d09edeeccaff1a 100644
--- a/lldb/include/lldb/lldb-forward.h
+++ b/lldb/include/lldb/lldb-forward.h
@@ -190,6 +190,7 @@ class ScriptInterpreterLocker;
 class ScriptedMetadata;
 class ScriptedPlatformInterface;
 class ScriptedProcessInterface;
+class ScriptedStopHookInterface;
 class ScriptedThreadInterface;
 class ScriptedThreadPlanInterface;
 class ScriptedSyntheticChildren;
@@ -408,6 +409,8 @@ typedef 
std::unique_ptr
 ScriptedPlatformInterfaceUP;
 typedef std::unique_ptr
 ScriptedProcessInterfaceUP;
+typedef std::shared_ptr
+ScriptedStopHookInterfaceSP;
 typedef std::shared_ptr
 ScriptedThreadInterfaceSP;
 typedef std::shared_ptr
diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt
index 6ba714ed1c263e..ee5e48ad5cdc37 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt
@@ -25,6 +25,7 @@ add_lldb_library(lldbPluginScriptInterpreterPythonInterfaces 
PLUGIN
   ScriptedPlatformPythonInterface.cpp
   ScriptedProcessPythonInterface.cpp
 

[Lldb-commits] [lldb] [lldb] Add support for disabling frame recognizers (PR #109219)

2024-09-20 Thread Med Ismail Bennani via lldb-commits

medismailben wrote:

@vogelsgesang Nice!

https://github.com/llvm/llvm-project/pull/109219
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/Interpreter] Propagate `script` output back to command return object (PR #109440)

2024-09-20 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben converted_to_draft 
https://github.com/llvm/llvm-project/pull/109440
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/Interpreter] Propagate `script` output back to command return object (PR #109440)

2024-09-20 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben created 
https://github.com/llvm/llvm-project/pull/109440

When running a oneliner script expression, if the script interpreter returned a 
value, that value would be printed to the debugger standard output straight 
from the interpreter instead of being propagated back to the command return 
object, which would then forward it to its output stream.

This implies that when evaluating a oneliner script expression (with 
`SBCommandInterpreter::HandleCommand`), the return value would get printed to 
stdout, but we would not be able to fetch it from the command return object.

This patch solves this issue by extending the default Python 
`InteractiveConsole` class to keep track of the return value, before include it 
to the command return object.

rdar://132420488

>From 77d1924a105ef60bf2328f7f67302b9d8f026c7a Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani 
Date: Mon, 19 Aug 2024 21:11:18 -0700
Subject: [PATCH] [lldb/Interpreter] Propagate `script` output back to command
 return object

When running a oneliner script expression, if the script interpreter
returned a value, that value would be printed to the debugger standard
output straight from the interpreter instead of being propagated back to
the command return object, which would then forward it to its output stream.

This implies that when evaluating a oneliner script expression (with
`SBCommandInterpreter::HandleCommand`), the return value would get
printed to stdout, but we would not be able to fetch it from the command
return object.

This patch solves this issue by extending the default Python
`InteractiveConsole` class to keep track of the return value, before
include it to the command return object.

rdar://132420488

Signed-off-by: Med Ismail Bennani 
---
 .../Interpreter/embedded_interpreter.py   | 39 +--
 .../Python/ScriptInterpreterPython.cpp|  7 +++-
 2 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/lldb/source/Interpreter/embedded_interpreter.py 
b/lldb/source/Interpreter/embedded_interpreter.py
index a487592ef1aee5..fd5c44d0121fbd 100644
--- a/lldb/source/Interpreter/embedded_interpreter.py
+++ b/lldb/source/Interpreter/embedded_interpreter.py
@@ -8,6 +8,8 @@
 import lldb
 import traceback
 
+from io import StringIO
+
 try:
 import readline
 import rlcompleter
@@ -116,19 +118,50 @@ def run_python_interpreter(local_dict):
 print("Script exited with code %s" % e.code)
 
 
+class LLDBInteractiveConsole(code.InteractiveConsole):
+def __init__(self, locals=None):
+super().__init__(locals)
+self.result_output = None
+
+### Implementation detail:
+### 
https://docs.python.org/3/library/code.html#code.InteractiveInterpreter.runsource
+def runsource(self, source, filename="", symbol="single"):
+# Redirect stdout to capture print statements
+old_stdout = sys.stdout
+sys.stdout = result_output = StringIO()
+
+try:
+compiled_code = self.compile(source, filename, symbol)
+if compiled_code is None:
+return False
+
+exec(compiled_code, self.locals)
+return True
+except Exception as e:
+self.showsyntaxerror(filename)
+return False
+finally:
+self.result_output = result_output
+sys.stdout = old_stdout
+
+def get_last_result(self):
+return self.result_output.getvalue()
+
 def run_one_line(local_dict, input_string):
 global g_run_one_line_str
 try:
 input_string = strip_and_check_exit(input_string)
-repl = code.InteractiveConsole(local_dict)
+repl = LLDBInteractiveConsole(local_dict)
 if input_string:
 # A newline is appended to support one-line statements containing
 # control flow. For example "if True: print(1)" silently does
 # nothing, but works with a newline: "if True: print(1)\n".
 input_string += "\n"
-repl.runsource(input_string)
+if repl.runsource(input_string):
+return repl.get_last_result()
 elif g_run_one_line_str:
-repl.runsource(g_run_one_line_str)
+if repl.runsource(g_run_one_line_str):
+return repl.get_last_result()
 except LLDBExit:
 pass
 except SystemExit as e:
diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp 
b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index 63691d24f0dadb..30b67ce48a4be9 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -884,9 +884,12 @@ bool ScriptInterpreterPythonImpl::ExecuteOneLine(
   PyRefType::Owned,
   PyObject_CallObject(m_run_one_line_function.get(),
   pargs.get()));
-  

[Lldb-commits] [lldb] [lldb/Interpreter] Introduce `ScriptedStopHook{, Python}Interface` & make use of it (PR #105449)

2024-09-19 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben closed 
https://github.com/llvm/llvm-project/pull/105449
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/Interpreter] Introduce `ScriptedStopHook{, Python}Interface` & make use of it (PR #105449)

2024-09-19 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben updated 
https://github.com/llvm/llvm-project/pull/105449

>From 3387de37a8c0da9174653062b0804494d8ebf53e Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani 
Date: Thu, 19 Sep 2024 23:29:13 -0700
Subject: [PATCH 1/3] [lldb/Interpreter] Create
 ScriptedStopHook{,Python}Interface (NFC)

This patch introduces a new scripted interface for ScriptedStopHooks.

This will be used in a follow-up patch to call into the script methods.

Signed-off-by: Med Ismail Bennani 
---
 .../Interfaces/ScriptedStopHookInterface.h| 33 
 .../lldb/Interpreter/ScriptInterpreter.h  |  4 +
 lldb/include/lldb/lldb-forward.h  |  3 +
 .../Python/Interfaces/CMakeLists.txt  |  1 +
 .../ScriptInterpreterPythonInterfaces.cpp |  2 +
 .../ScriptInterpreterPythonInterfaces.h   |  1 +
 .../ScriptedStopHookPythonInterface.cpp   | 75 +++
 .../ScriptedStopHookPythonInterface.h | 51 +
 .../Python/ScriptInterpreterPython.cpp|  5 ++
 .../Python/ScriptInterpreterPythonImpl.h  |  2 +
 10 files changed, 177 insertions(+)
 create mode 100644 
lldb/include/lldb/Interpreter/Interfaces/ScriptedStopHookInterface.h
 create mode 100644 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedStopHookPythonInterface.cpp
 create mode 100644 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedStopHookPythonInterface.h

diff --git 
a/lldb/include/lldb/Interpreter/Interfaces/ScriptedStopHookInterface.h 
b/lldb/include/lldb/Interpreter/Interfaces/ScriptedStopHookInterface.h
new file mode 100644
index 00..125e7f2077b543
--- /dev/null
+++ b/lldb/include/lldb/Interpreter/Interfaces/ScriptedStopHookInterface.h
@@ -0,0 +1,33 @@
+//===-- ScriptedStopHookInterface.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_INTERPRETER_INTERFACES_SCRIPTEDSTOPHOOKINTERFACE_H
+#define LLDB_INTERPRETER_INTERFACES_SCRIPTEDSTOPHOOKINTERFACE_H
+
+#include "lldb/lldb-private.h"
+
+#include "ScriptedInterface.h"
+
+namespace lldb_private {
+class ScriptedStopHookInterface : public ScriptedInterface {
+public:
+  virtual llvm::Expected
+  CreatePluginObject(llvm::StringRef class_name, lldb::TargetSP target_sp,
+ const StructuredDataImpl &args_sp) = 0;
+
+  /// "handle_stop" will return a bool with the meaning "should_stop"...
+  /// If nothing is returned, we'll assume we are going to stop.
+  /// Also any errors should return true, since we should stop on error.
+  virtual llvm::Expected HandleStop(ExecutionContext &exe_ctx,
+  lldb::StreamSP output_sp) {
+return true;
+  }
+};
+} // namespace lldb_private
+
+#endif // LLDB_INTERPRETER_INTERFACES_SCRIPTEDSTOPHOOKINTERFACE_H
diff --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h 
b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
index addb1394ab5652..8fabe6f250b084 100644
--- a/lldb/include/lldb/Interpreter/ScriptInterpreter.h
+++ b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
@@ -561,6 +561,10 @@ class ScriptInterpreter : public PluginInterface {
 return {};
   }
 
+  virtual lldb::ScriptedStopHookInterfaceSP CreateScriptedStopHookInterface() {
+return {};
+  }
+
   virtual StructuredData::ObjectSP
   CreateStructuredDataFromScriptObject(ScriptObject obj) {
 return {};
diff --git a/lldb/include/lldb/lldb-forward.h b/lldb/include/lldb/lldb-forward.h
index 5fb288ad43af48..d09edeeccaff1a 100644
--- a/lldb/include/lldb/lldb-forward.h
+++ b/lldb/include/lldb/lldb-forward.h
@@ -190,6 +190,7 @@ class ScriptInterpreterLocker;
 class ScriptedMetadata;
 class ScriptedPlatformInterface;
 class ScriptedProcessInterface;
+class ScriptedStopHookInterface;
 class ScriptedThreadInterface;
 class ScriptedThreadPlanInterface;
 class ScriptedSyntheticChildren;
@@ -408,6 +409,8 @@ typedef 
std::unique_ptr
 ScriptedPlatformInterfaceUP;
 typedef std::unique_ptr
 ScriptedProcessInterfaceUP;
+typedef std::shared_ptr
+ScriptedStopHookInterfaceSP;
 typedef std::shared_ptr
 ScriptedThreadInterfaceSP;
 typedef std::shared_ptr
diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt
index 6ba714ed1c263e..ee5e48ad5cdc37 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt
@@ -25,6 +25,7 @@ add_lldb_library(lldbPluginScriptInterpreterPythonInterfaces 
PLUGIN
   ScriptedPlatformPythonInterface.cpp
   ScriptedProcessPythonInterface.cpp
   ScriptedPythonInterface.cpp
+  ScriptedStopHookPythonInterface.cp

[Lldb-commits] [lldb] Add the ability to define custom completers to the parsed_cmd template. (PR #109062)

2024-09-19 Thread Med Ismail Bennani via lldb-commits


@@ -587,8 +587,150 @@ say
 SBCommandReturnObject and SBStream both support this file-like behavior by
 providing write() and flush() calls at the Python layer.
 
+The commands that are added using this Class definition are what lldb calls
+"raw" commands.  The command interpreter doesn't attempt to parse the command,
+doesn't handle option values, neither generating help for them, or their
+completion.  Raw commands are useful when the arguments passed to the command
+are unstructured, and having to protect them against lldb command parsing would
+be onerous.  For instance, "expr" is a raw command.
+
+You can also add scripted commands that implement the "parsed command", where
+the options and their types are specified, as well as the argument and argument
+types.  These commands look and act like the majority of lldb commands, and you
+can also add custom completions for the options and/or the arguments if you 
have
+special needs.
+
+The easiest way to do this is to derive your new command from the 
lldb.ParsedCommand
+class.  That responds in the same way to the help & repeat command interfaces, 
and
+provides some convenience methods, and most importantly an 
LLDBOptionValueParser,
+accessed throught lldb.ParsedCommand.get_parser().  The parser is used to set
+your command definitions, and to retrieve option values in the __call__ method.
+
+To set the command definition, implement the ParsedCommand abstract method:
+
+::
+
+   def setup_command_definition(self):
+
+This is called when your command is added to lldb.  In this method you add the
+options and their types, the option help strings, etc. to the command using 
the API:
+
+::
+
+def add_option(self, short_option, long_option, help, default,
+   dest = None, required=False, groups = None,
+   value_type=lldb.eArgTypeNone, completion_type=None,
+   enum_values=None):
+"""
+short_option: one character, must be unique, not required
+long_option:  no spaces, must be unique, required
+help: a usage string for this option, will print in the 
command help
+default:  the initial value for this option (if it has a value)
+dest: the name of the property that gives you access to the 
value for
+  this value.  Defaults to the long option if not provided.
+required: if true, this option must be provided or the command will 
error out
+groups: Which "option groups" does this option belong to.  This can 
either be
+a simple list (e.g. [1, 3, 4, 5]) or you can specify ranges by 
sublists:
+so [1, [3,5]] is the same as [1, 3, 4, 5].
+value_type: one of the lldb.eArgType enum values.  Some of the common 
arg
+types also have default completers, which will be applied 
automatically.
+completion_type: currently these are values form the 
lldb.CompletionType enum. If
+ you need custom completions, implement
handle_option_argument_completion.
+enum_values: An array of duples: ["element_name", "element_help"].  If 
provided,
+ only one of the enum elements is allowed.  The value will 
be the
+ element_name for the chosen enum element as a string.
+"""
+
+Similarly, you can add argument types to the command:
+
+::
+
+def make_argument_element(self, arg_type, repeat = "optional", groups = 
None):
+"""
+   arg_type: The argument type, one of the lldb.eArgType enum values.
+   repeat: Choose from the following options:
+   "plain" - one value
+   "optional" - zero or more values
+   "plus" - one or more values
+   groups: As with add_option.
+"""
+
+Then implement the body of the command by defining:
+
+::
+
+def __call__(self, debugger, args_array, exe_ctx, result):
+"""This is the command callback.  The option values are
+provided by the 'dest' properties on the parser.
+
+args_array: This is the list of arguments provided.
+exe_ctx: Gives the SBExecutionContext on which the
+ command should operate.
+result:  Any results of the command should be
+ written into this SBCommandReturnObject.
+"""
+
+This differs from the "raw" command's __call__ in that the arguments are 
already
+parsed into the args_array, and the option values are set in the parser, and
+can be accessed using their property name.  The LLDBOptionValueParser class has
+a couple of other handy methods:
+
+::
+def was_set(self, long_option_name):
+
+returns True if the option was specified on the command line.
+
+::
+def dest_for_option(self, long_option_name):
+"""
+This will return the value of the dest variable you defined for opt_name.
+Mostly useful for handle_completion where you get passed the long option.

[Lldb-commits] [lldb] Add the ability to define custom completers to the parsed_cmd template. (PR #109062)

2024-09-19 Thread Med Ismail Bennani via lldb-commits


@@ -587,8 +587,150 @@ say
 SBCommandReturnObject and SBStream both support this file-like behavior by
 providing write() and flush() calls at the Python layer.
 
+The commands that are added using this Class definition are what lldb calls
+"raw" commands.  The command interpreter doesn't attempt to parse the command,
+doesn't handle option values, neither generating help for them, or their
+completion.  Raw commands are useful when the arguments passed to the command
+are unstructured, and having to protect them against lldb command parsing would
+be onerous.  For instance, "expr" is a raw command.
+
+You can also add scripted commands that implement the "parsed command", where
+the options and their types are specified, as well as the argument and argument
+types.  These commands look and act like the majority of lldb commands, and you
+can also add custom completions for the options and/or the arguments if you 
have
+special needs.
+
+The easiest way to do this is to derive your new command from the 
lldb.ParsedCommand
+class.  That responds in the same way to the help & repeat command interfaces, 
and
+provides some convenience methods, and most importantly an 
LLDBOptionValueParser,
+accessed throught lldb.ParsedCommand.get_parser().  The parser is used to set
+your command definitions, and to retrieve option values in the __call__ method.
+
+To set the command definition, implement the ParsedCommand abstract method:
+
+::
+
+   def setup_command_definition(self):
+
+This is called when your command is added to lldb.  In this method you add the
+options and their types, the option help strings, etc. to the command using 
the API:
+
+::
+
+def add_option(self, short_option, long_option, help, default,
+   dest = None, required=False, groups = None,
+   value_type=lldb.eArgTypeNone, completion_type=None,
+   enum_values=None):
+"""
+short_option: one character, must be unique, not required
+long_option:  no spaces, must be unique, required
+help: a usage string for this option, will print in the 
command help
+default:  the initial value for this option (if it has a value)
+dest: the name of the property that gives you access to the 
value for
+  this value.  Defaults to the long option if not provided.
+required: if true, this option must be provided or the command will 
error out
+groups: Which "option groups" does this option belong to.  This can 
either be
+a simple list (e.g. [1, 3, 4, 5]) or you can specify ranges by 
sublists:
+so [1, [3,5]] is the same as [1, 3, 4, 5].
+value_type: one of the lldb.eArgType enum values.  Some of the common 
arg
+types also have default completers, which will be applied 
automatically.
+completion_type: currently these are values form the 
lldb.CompletionType enum. If
+ you need custom completions, implement
handle_option_argument_completion.
+enum_values: An array of duples: ["element_name", "element_help"].  If 
provided,
+ only one of the enum elements is allowed.  The value will 
be the
+ element_name for the chosen enum element as a string.
+"""
+
+Similarly, you can add argument types to the command:
+
+::
+
+def make_argument_element(self, arg_type, repeat = "optional", groups = 
None):
+"""
+   arg_type: The argument type, one of the lldb.eArgType enum values.
+   repeat: Choose from the following options:
+   "plain" - one value
+   "optional" - zero or more values
+   "plus" - one or more values
+   groups: As with add_option.
+"""
+
+Then implement the body of the command by defining:
+
+::
+
+def __call__(self, debugger, args_array, exe_ctx, result):
+"""This is the command callback.  The option values are
+provided by the 'dest' properties on the parser.
+
+args_array: This is the list of arguments provided.
+exe_ctx: Gives the SBExecutionContext on which the
+ command should operate.
+result:  Any results of the command should be
+ written into this SBCommandReturnObject.
+"""
+
+This differs from the "raw" command's __call__ in that the arguments are 
already
+parsed into the args_array, and the option values are set in the parser, and
+can be accessed using their property name.  The LLDBOptionValueParser class has
+a couple of other handy methods:
+
+::
+def was_set(self, long_option_name):
+
+returns True if the option was specified on the command line.
+
+::
+def dest_for_option(self, long_option_name):
+"""
+This will return the value of the dest variable you defined for opt_name.
+Mostly useful for handle_completion where you get passed the long option.

[Lldb-commits] [lldb] Add the ability to define custom completers to the parsed_cmd template. (PR #109062)

2024-09-19 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben edited 
https://github.com/llvm/llvm-project/pull/109062
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add the ability to define custom completers to the parsed_cmd template. (PR #109062)

2024-09-19 Thread Med Ismail Bennani via lldb-commits


@@ -43,7 +43,65 @@ def __call__(self, debugger, args_list, exe_ctx, result):
 will return True if the user set this option, and False if it was left at its 
default
 value.
 
-There are example commands in the lldb testsuite at:
+Custom Completions:
+
+You can also implement custom completers for your custom command, either for 
the
+arguments to your command or to the option values in your command.  If you use 
enum
+values or if your option/argument uses is one of the types we have completers 
for,
+you should not need to do this.  But if you have your own completeable types, 
or if
+you want completion of one option to be conditioned by other options on the 
command
+line, you can use this interface to take over the completion.  
+
+You can choose to add a completion for the option values defined for your 
command,
+or for the arguments, separately.  For the option values, define:
+
+def handle_option_argument_completion(self, long_option, cursor_pos):
+

medismailben wrote:

Use `.. code-block:: python`  so this gets rendered differently on the website

```suggestion

.. code-block:: python

def handle_option_argument_completion(self, long_option, 
cursor_pos):

```

https://github.com/llvm/llvm-project/pull/109062
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add the ability to define custom completers to the parsed_cmd template. (PR #109062)

2024-09-19 Thread Med Ismail Bennani via lldb-commits


@@ -1637,6 +1637,129 @@ class CommandObjectScriptingObjectParsed : public 
CommandObjectParsed {
 
 size_t GetNumOptions() { return m_num_options; }
 
+void PrepareOptionsForCompletion(CompletionRequest &request,
+ OptionElementVector &option_vec,
+ ExecutionContext *exe_ctx) {
+  // I'm not sure if we'll get into trouble doing an option parsing start
+  // and end in this context.  If so, then I'll have to directly tell the
+  // scripter to do this.
+  OptionParsingStarting(exe_ctx);
+  auto opt_defs = GetDefinitions();
+
+  // Iterate through the options we found so far, and push them into
+  // the scripted side.
+  for (auto option_elem : option_vec) {
+int cur_defs_index = option_elem.opt_defs_index;
+// If we don't recognize this option we can't set it.
+if (cur_defs_index == OptionArgElement::eUnrecognizedArg ||
+cur_defs_index == OptionArgElement::eBareDash ||
+cur_defs_index == OptionArgElement::eBareDoubleDash)
+  continue;
+bool option_has_arg = opt_defs[cur_defs_index].option_has_arg;
+llvm::StringRef cur_arg_value;
+if (option_has_arg) {
+  int cur_arg_pos = option_elem.opt_arg_pos;
+  if (cur_arg_pos != OptionArgElement::eUnrecognizedArg &&
+  cur_arg_pos != OptionArgElement::eBareDash &&
+  cur_arg_pos != OptionArgElement::eBareDoubleDash) {
+cur_arg_value =
+request.GetParsedLine().GetArgumentAtIndex(cur_arg_pos);
+  }
+}
+SetOptionValue(cur_defs_index, cur_arg_value, exe_ctx);
+  }
+  OptionParsingFinished(exe_ctx);
+}
+
+void
+ProcessCompletionDict(CompletionRequest &request,
+  StructuredData::DictionarySP &completion_dict_sp) {
+  // We don't know how to process an empty completion dict, our callers 
have
+  // to do that.
+  assert(completion_dict_sp && "Must have valid completion dict");
+  // First handle the case of a single completion:
+  llvm::StringRef completion;
+  // If the dictionary has one element "no-completion" then we return here
+  if (completion_dict_sp->GetValueForKeyAsString("no-completion",
+ completion))
+return;
+
+  if (completion_dict_sp->GetValueForKeyAsString("completion",
+ completion)) {
+llvm::StringRef mode_str;
+CompletionMode mode = CompletionMode::Normal;
+if (completion_dict_sp->GetValueForKeyAsString("mode", mode_str)) {
+  if (mode_str == "complete")
+mode = CompletionMode::Normal;
+  else if (mode_str == "partial")
+mode = CompletionMode::Partial;
+  else {
+// FIXME - how do I report errors here?
+return;
+  }
+}
+request.AddCompletion(completion, "", mode);
+return;
+  }
+  // The completions are required, the descriptions are not:
+  StructuredData::Array *completions;
+  StructuredData::Array *descriptions;
+  if (completion_dict_sp->GetValueForKeyAsArray("values", completions)) {
+completion_dict_sp->GetValueForKeyAsArray("descriptions", 
descriptions);
+size_t num_completions = completions->GetSize();
+for (size_t idx = 0; idx < num_completions; idx++) {
+  auto val = completions->GetItemAtIndexAsString(idx);
+  if (!val)
+// FIXME: How do I report this error?

medismailben wrote:

todo ?

https://github.com/llvm/llvm-project/pull/109062
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add the ability to define custom completers to the parsed_cmd template. (PR #109062)

2024-09-19 Thread Med Ismail Bennani via lldb-commits


@@ -587,8 +587,150 @@ say
 SBCommandReturnObject and SBStream both support this file-like behavior by
 providing write() and flush() calls at the Python layer.
 
+The commands that are added using this Class definition are what lldb calls
+"raw" commands.  The command interpreter doesn't attempt to parse the command,
+doesn't handle option values, neither generating help for them, or their
+completion.  Raw commands are useful when the arguments passed to the command
+are unstructured, and having to protect them against lldb command parsing would
+be onerous.  For instance, "expr" is a raw command.
+
+You can also add scripted commands that implement the "parsed command", where
+the options and their types are specified, as well as the argument and argument
+types.  These commands look and act like the majority of lldb commands, and you
+can also add custom completions for the options and/or the arguments if you 
have
+special needs.
+
+The easiest way to do this is to derive your new command from the 
lldb.ParsedCommand
+class.  That responds in the same way to the help & repeat command interfaces, 
and
+provides some convenience methods, and most importantly an 
LLDBOptionValueParser,
+accessed throught lldb.ParsedCommand.get_parser().  The parser is used to set
+your command definitions, and to retrieve option values in the __call__ method.
+
+To set the command definition, implement the ParsedCommand abstract method:
+
+::
+
+   def setup_command_definition(self):
+
+This is called when your command is added to lldb.  In this method you add the
+options and their types, the option help strings, etc. to the command using 
the API:
+
+::
+
+def add_option(self, short_option, long_option, help, default,
+   dest = None, required=False, groups = None,
+   value_type=lldb.eArgTypeNone, completion_type=None,
+   enum_values=None):
+"""
+short_option: one character, must be unique, not required
+long_option:  no spaces, must be unique, required
+help: a usage string for this option, will print in the 
command help
+default:  the initial value for this option (if it has a value)
+dest: the name of the property that gives you access to the 
value for
+  this value.  Defaults to the long option if not provided.
+required: if true, this option must be provided or the command will 
error out
+groups: Which "option groups" does this option belong to.  This can 
either be
+a simple list (e.g. [1, 3, 4, 5]) or you can specify ranges by 
sublists:
+so [1, [3,5]] is the same as [1, 3, 4, 5].
+value_type: one of the lldb.eArgType enum values.  Some of the common 
arg
+types also have default completers, which will be applied 
automatically.
+completion_type: currently these are values form the 
lldb.CompletionType enum. If
+ you need custom completions, implement
handle_option_argument_completion.
+enum_values: An array of duples: ["element_name", "element_help"].  If 
provided,
+ only one of the enum elements is allowed.  The value will 
be the
+ element_name for the chosen enum element as a string.
+"""
+
+Similarly, you can add argument types to the command:
+
+::
+
+def make_argument_element(self, arg_type, repeat = "optional", groups = 
None):
+"""
+   arg_type: The argument type, one of the lldb.eArgType enum values.
+   repeat: Choose from the following options:
+   "plain" - one value
+   "optional" - zero or more values
+   "plus" - one or more values
+   groups: As with add_option.
+"""
+
+Then implement the body of the command by defining:
+
+::
+
+def __call__(self, debugger, args_array, exe_ctx, result):
+"""This is the command callback.  The option values are
+provided by the 'dest' properties on the parser.
+
+args_array: This is the list of arguments provided.
+exe_ctx: Gives the SBExecutionContext on which the
+ command should operate.
+result:  Any results of the command should be
+ written into this SBCommandReturnObject.
+"""
+
+This differs from the "raw" command's __call__ in that the arguments are 
already
+parsed into the args_array, and the option values are set in the parser, and
+can be accessed using their property name.  The LLDBOptionValueParser class has
+a couple of other handy methods:
+
+::
+def was_set(self, long_option_name):
+
+returns True if the option was specified on the command line.
+
+::
+def dest_for_option(self, long_option_name):
+"""
+This will return the value of the dest variable you defined for opt_name.
+Mostly useful for handle_completion where you get passed the long option.

[Lldb-commits] [lldb] Add the ability to define custom completers to the parsed_cmd template. (PR #109062)

2024-09-19 Thread Med Ismail Bennani via lldb-commits


@@ -587,8 +587,150 @@ say
 SBCommandReturnObject and SBStream both support this file-like behavior by
 providing write() and flush() calls at the Python layer.
 
+The commands that are added using this Class definition are what lldb calls

medismailben wrote:

```suggestion
The commands that are added using this class definition are what lldb calls
```

https://github.com/llvm/llvm-project/pull/109062
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add the ability to define custom completers to the parsed_cmd template. (PR #109062)

2024-09-19 Thread Med Ismail Bennani via lldb-commits


@@ -587,8 +587,150 @@ say
 SBCommandReturnObject and SBStream both support this file-like behavior by
 providing write() and flush() calls at the Python layer.
 
+The commands that are added using this Class definition are what lldb calls
+"raw" commands.  The command interpreter doesn't attempt to parse the command,
+doesn't handle option values, neither generating help for them, or their
+completion.  Raw commands are useful when the arguments passed to the command
+are unstructured, and having to protect them against lldb command parsing would
+be onerous.  For instance, "expr" is a raw command.
+
+You can also add scripted commands that implement the "parsed command", where
+the options and their types are specified, as well as the argument and argument
+types.  These commands look and act like the majority of lldb commands, and you
+can also add custom completions for the options and/or the arguments if you 
have
+special needs.
+
+The easiest way to do this is to derive your new command from the 
lldb.ParsedCommand
+class.  That responds in the same way to the help & repeat command interfaces, 
and
+provides some convenience methods, and most importantly an 
LLDBOptionValueParser,
+accessed throught lldb.ParsedCommand.get_parser().  The parser is used to set
+your command definitions, and to retrieve option values in the __call__ method.
+
+To set the command definition, implement the ParsedCommand abstract method:
+
+::
+
+   def setup_command_definition(self):
+
+This is called when your command is added to lldb.  In this method you add the
+options and their types, the option help strings, etc. to the command using 
the API:
+
+::
+
+def add_option(self, short_option, long_option, help, default,
+   dest = None, required=False, groups = None,
+   value_type=lldb.eArgTypeNone, completion_type=None,
+   enum_values=None):
+"""
+short_option: one character, must be unique, not required
+long_option:  no spaces, must be unique, required
+help: a usage string for this option, will print in the 
command help
+default:  the initial value for this option (if it has a value)
+dest: the name of the property that gives you access to the 
value for
+  this value.  Defaults to the long option if not provided.
+required: if true, this option must be provided or the command will 
error out
+groups: Which "option groups" does this option belong to.  This can 
either be
+a simple list (e.g. [1, 3, 4, 5]) or you can specify ranges by 
sublists:
+so [1, [3,5]] is the same as [1, 3, 4, 5].
+value_type: one of the lldb.eArgType enum values.  Some of the common 
arg
+types also have default completers, which will be applied 
automatically.
+completion_type: currently these are values form the 
lldb.CompletionType enum. If
+ you need custom completions, implement
handle_option_argument_completion.
+enum_values: An array of duples: ["element_name", "element_help"].  If 
provided,
+ only one of the enum elements is allowed.  The value will 
be the
+ element_name for the chosen enum element as a string.
+"""
+
+Similarly, you can add argument types to the command:
+
+::
+
+def make_argument_element(self, arg_type, repeat = "optional", groups = 
None):
+"""
+   arg_type: The argument type, one of the lldb.eArgType enum values.
+   repeat: Choose from the following options:
+   "plain" - one value
+   "optional" - zero or more values
+   "plus" - one or more values
+   groups: As with add_option.
+"""
+
+Then implement the body of the command by defining:
+
+::
+
+def __call__(self, debugger, args_array, exe_ctx, result):
+"""This is the command callback.  The option values are
+provided by the 'dest' properties on the parser.
+
+args_array: This is the list of arguments provided.
+exe_ctx: Gives the SBExecutionContext on which the
+ command should operate.
+result:  Any results of the command should be
+ written into this SBCommandReturnObject.
+"""
+
+This differs from the "raw" command's __call__ in that the arguments are 
already
+parsed into the args_array, and the option values are set in the parser, and
+can be accessed using their property name.  The LLDBOptionValueParser class has
+a couple of other handy methods:
+
+::
+def was_set(self, long_option_name):
+
+returns True if the option was specified on the command line.
+
+::
+def dest_for_option(self, long_option_name):
+"""
+This will return the value of the dest variable you defined for opt_name.
+Mostly useful for handle_completion where you get passed the long option.

[Lldb-commits] [lldb] Add the ability to define custom completers to the parsed_cmd template. (PR #109062)

2024-09-19 Thread Med Ismail Bennani via lldb-commits


@@ -587,8 +587,150 @@ say
 SBCommandReturnObject and SBStream both support this file-like behavior by
 providing write() and flush() calls at the Python layer.
 
+The commands that are added using this Class definition are what lldb calls
+"raw" commands.  The command interpreter doesn't attempt to parse the command,
+doesn't handle option values, neither generating help for them, or their
+completion.  Raw commands are useful when the arguments passed to the command
+are unstructured, and having to protect them against lldb command parsing would
+be onerous.  For instance, "expr" is a raw command.
+
+You can also add scripted commands that implement the "parsed command", where
+the options and their types are specified, as well as the argument and argument
+types.  These commands look and act like the majority of lldb commands, and you
+can also add custom completions for the options and/or the arguments if you 
have
+special needs.
+
+The easiest way to do this is to derive your new command from the 
lldb.ParsedCommand
+class.  That responds in the same way to the help & repeat command interfaces, 
and
+provides some convenience methods, and most importantly an 
LLDBOptionValueParser,
+accessed throught lldb.ParsedCommand.get_parser().  The parser is used to set
+your command definitions, and to retrieve option values in the __call__ method.
+
+To set the command definition, implement the ParsedCommand abstract method:

medismailben wrote:

Are we missing a word here ?

```suggestion
To set up the command definition, implement the ParsedCommand abstract method:
```

https://github.com/llvm/llvm-project/pull/109062
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add the ability to define custom completers to the parsed_cmd template. (PR #109062)

2024-09-19 Thread Med Ismail Bennani via lldb-commits


@@ -43,7 +43,65 @@ def __call__(self, debugger, args_list, exe_ctx, result):
 will return True if the user set this option, and False if it was left at its 
default
 value.
 
-There are example commands in the lldb testsuite at:
+Custom Completions:
+
+You can also implement custom completers for your custom command, either for 
the
+arguments to your command or to the option values in your command.  If you use 
enum
+values or if your option/argument uses is one of the types we have completers 
for,
+you should not need to do this.  But if you have your own completeable types, 
or if
+you want completion of one option to be conditioned by other options on the 
command
+line, you can use this interface to take over the completion.  
+
+You can choose to add a completion for the option values defined for your 
command,
+or for the arguments, separately.  For the option values, define:
+
+def handle_option_argument_completion(self, long_option, cursor_pos):
+
+The line to be completed will be parsed up to the option containint the cursor 
position, 
+and the values will be set in the OptionValue parser object.  long_option will 
be
+the option name containing the cursor, and cursor_pos will be the position of 
the cursor
+in that option's value.  You can call the 
OVParser.dest_for_option(long_option) to get the
+value for that option.  The other options that came before the cursor in the 
command
+line will also be set in the OV Parser when the completion handler is called.

medismailben wrote:

```suggestion
in that option's value.  You can call the 
`OVParser.dest_for_option(long_option)` to get the
value for that option.  The other options that came before the cursor in the 
command
line will also be set in the `OVParser` when the completion handler is called.
```

https://github.com/llvm/llvm-project/pull/109062
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add the ability to define custom completers to the parsed_cmd template. (PR #109062)

2024-09-19 Thread Med Ismail Bennani via lldb-commits


@@ -43,7 +43,65 @@ def __call__(self, debugger, args_list, exe_ctx, result):
 will return True if the user set this option, and False if it was left at its 
default
 value.
 
-There are example commands in the lldb testsuite at:
+Custom Completions:
+
+You can also implement custom completers for your custom command, either for 
the
+arguments to your command or to the option values in your command.  If you use 
enum
+values or if your option/argument uses is one of the types we have completers 
for,
+you should not need to do this.  But if you have your own completeable types, 
or if
+you want completion of one option to be conditioned by other options on the 
command
+line, you can use this interface to take over the completion.  
+
+You can choose to add a completion for the option values defined for your 
command,
+or for the arguments, separately.  For the option values, define:
+
+def handle_option_argument_completion(self, long_option, cursor_pos):
+
+The line to be completed will be parsed up to the option containint the cursor 
position, 
+and the values will be set in the OptionValue parser object.  long_option will 
be
+the option name containing the cursor, and cursor_pos will be the position of 
the cursor
+in that option's value.  You can call the 
OVParser.dest_for_option(long_option) to get the
+value for that option.  The other options that came before the cursor in the 
command
+line will also be set in the OV Parser when the completion handler is called.
+
+For argument values, define:
+
+def handle_argument_completion(self, args, arg_pos, cursor_pos):
+

medismailben wrote:

ditto

https://github.com/llvm/llvm-project/pull/109062
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add the ability to define custom completers to the parsed_cmd template. (PR #109062)

2024-09-19 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben commented:

Overall, this looks fine. It would be nice to surround the keywords with 
backticks and the function definition with a `.. code-block:: python` so it 
gets rendered properly on the website.

https://github.com/llvm/llvm-project/pull/109062
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/Interpreter] Introduce `ScriptedStopHook{, Python}Interface` & make use of it (PR #105449)

2024-09-19 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben updated 
https://github.com/llvm/llvm-project/pull/105449

>From 89ed41f52916bdc67d244488e5ee1d7da7c7bb90 Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani 
Date: Tue, 20 Aug 2024 16:13:54 -0700
Subject: [PATCH 1/3] [lldb/Interpreter] Create
 ScriptedStopHook{,Python}Interface (NFC)

This patch introduces a new scripted interface for ScriptedStopHooks.

This will be used in a follow-up patch to call into the script methods.

Signed-off-by: Med Ismail Bennani 
---
 .../Interfaces/ScriptedStopHookInterface.h| 33 
 .../lldb/Interpreter/ScriptInterpreter.h  |  4 +
 lldb/include/lldb/lldb-forward.h  |  3 +
 .../Python/Interfaces/CMakeLists.txt  |  1 +
 .../ScriptInterpreterPythonInterfaces.cpp |  2 +
 .../ScriptInterpreterPythonInterfaces.h   |  1 +
 .../ScriptedStopHookPythonInterface.cpp   | 75 +++
 .../ScriptedStopHookPythonInterface.h | 50 +
 .../Python/ScriptInterpreterPython.cpp|  5 ++
 .../Python/ScriptInterpreterPythonImpl.h  |  2 +
 10 files changed, 176 insertions(+)
 create mode 100644 
lldb/include/lldb/Interpreter/Interfaces/ScriptedStopHookInterface.h
 create mode 100644 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedStopHookPythonInterface.cpp
 create mode 100644 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedStopHookPythonInterface.h

diff --git 
a/lldb/include/lldb/Interpreter/Interfaces/ScriptedStopHookInterface.h 
b/lldb/include/lldb/Interpreter/Interfaces/ScriptedStopHookInterface.h
new file mode 100644
index 00..125e7f2077b543
--- /dev/null
+++ b/lldb/include/lldb/Interpreter/Interfaces/ScriptedStopHookInterface.h
@@ -0,0 +1,33 @@
+//===-- ScriptedStopHookInterface.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_INTERPRETER_INTERFACES_SCRIPTEDSTOPHOOKINTERFACE_H
+#define LLDB_INTERPRETER_INTERFACES_SCRIPTEDSTOPHOOKINTERFACE_H
+
+#include "lldb/lldb-private.h"
+
+#include "ScriptedInterface.h"
+
+namespace lldb_private {
+class ScriptedStopHookInterface : public ScriptedInterface {
+public:
+  virtual llvm::Expected
+  CreatePluginObject(llvm::StringRef class_name, lldb::TargetSP target_sp,
+ const StructuredDataImpl &args_sp) = 0;
+
+  /// "handle_stop" will return a bool with the meaning "should_stop"...
+  /// If nothing is returned, we'll assume we are going to stop.
+  /// Also any errors should return true, since we should stop on error.
+  virtual llvm::Expected HandleStop(ExecutionContext &exe_ctx,
+  lldb::StreamSP output_sp) {
+return true;
+  }
+};
+} // namespace lldb_private
+
+#endif // LLDB_INTERPRETER_INTERFACES_SCRIPTEDSTOPHOOKINTERFACE_H
diff --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h 
b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
index addb1394ab5652..8fabe6f250b084 100644
--- a/lldb/include/lldb/Interpreter/ScriptInterpreter.h
+++ b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
@@ -561,6 +561,10 @@ class ScriptInterpreter : public PluginInterface {
 return {};
   }
 
+  virtual lldb::ScriptedStopHookInterfaceSP CreateScriptedStopHookInterface() {
+return {};
+  }
+
   virtual StructuredData::ObjectSP
   CreateStructuredDataFromScriptObject(ScriptObject obj) {
 return {};
diff --git a/lldb/include/lldb/lldb-forward.h b/lldb/include/lldb/lldb-forward.h
index 5fb288ad43af48..d09edeeccaff1a 100644
--- a/lldb/include/lldb/lldb-forward.h
+++ b/lldb/include/lldb/lldb-forward.h
@@ -190,6 +190,7 @@ class ScriptInterpreterLocker;
 class ScriptedMetadata;
 class ScriptedPlatformInterface;
 class ScriptedProcessInterface;
+class ScriptedStopHookInterface;
 class ScriptedThreadInterface;
 class ScriptedThreadPlanInterface;
 class ScriptedSyntheticChildren;
@@ -408,6 +409,8 @@ typedef 
std::unique_ptr
 ScriptedPlatformInterfaceUP;
 typedef std::unique_ptr
 ScriptedProcessInterfaceUP;
+typedef std::shared_ptr
+ScriptedStopHookInterfaceSP;
 typedef std::shared_ptr
 ScriptedThreadInterfaceSP;
 typedef std::shared_ptr
diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt
index 6ba714ed1c263e..ee5e48ad5cdc37 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt
@@ -25,6 +25,7 @@ add_lldb_library(lldbPluginScriptInterpreterPythonInterfaces 
PLUGIN
   ScriptedPlatformPythonInterface.cpp
   ScriptedProcessPythonInterface.cpp
   ScriptedPythonInterface.cpp
+  ScriptedStopHookPythonInterface.cp

[Lldb-commits] [lldb] [lldb/Interpreter] Introduce `ScriptedStopHook{, Python}Interface` & make use of it (PR #105449)

2024-09-19 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben updated 
https://github.com/llvm/llvm-project/pull/105449

>From 897dd358d3b15ec59e63068f7e328e914db49495 Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani 
Date: Thu, 19 Sep 2024 13:25:06 -0700
Subject: [PATCH] [lldb/Interpreter] Add requirements to Scripted Interface
 abstract methods

This patch adds new requirements to the Scripted Interface abstract
method checker to check the minimum number of argument for abstract
methods.

This check is done when creating the interface object so the object is
not created if the user implementation doesn't match the abstract method
requirement.

Signed-off-by: Med Ismail Bennani 
---
 .../Interfaces/ScriptedInterface.h|  17 +-
 .../OperatingSystemPythonInterface.h  |   5 +-
 .../ScriptedPlatformPythonInterface.h |  11 +-
 .../ScriptedProcessPythonInterface.h  |   9 +-
 .../Interfaces/ScriptedPythonInterface.h  | 160 +-
 .../ScriptedThreadPlanPythonInterface.h   |   3 +-
 .../ScriptedThreadPythonInterface.h   |   7 +-
 7 files changed, 158 insertions(+), 54 deletions(-)

diff --git a/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h 
b/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h
index 89c0b36d6fc2a1..a3dc52c435561f 100644
--- a/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h
+++ b/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h
@@ -31,7 +31,22 @@ class ScriptedInterface {
 return m_object_instance_sp;
   }
 
-  virtual llvm::SmallVector GetAbstractMethods() const = 
0;
+  struct AbstractMethodRequirement {
+llvm::StringLiteral name;
+size_t min_arg_count = 0;
+  };
+
+  virtual llvm::SmallVector
+  GetAbstractMethodRequirements() const = 0;
+
+  llvm::SmallVector const GetAbstractMethods() const {
+llvm::SmallVector abstract_methods;
+llvm::transform(GetAbstractMethodRequirements(), abstract_methods.begin(),
+[](const AbstractMethodRequirement &requirement) {
+  return requirement.name;
+});
+return abstract_methods;
+  }
 
   template 
   static Ret ErrorWithMessage(llvm::StringRef caller_name,
diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.h
 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.h
index 92358ac6c34f7e..102c3c39537686 100644
--- 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.h
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.h
@@ -31,8 +31,9 @@ class OperatingSystemPythonInterface
  StructuredData::DictionarySP args_sp,
  StructuredData::Generic *script_obj = nullptr) override;
 
-  llvm::SmallVector GetAbstractMethods() const override {
-return llvm::SmallVector({"get_thread_info"});
+  llvm::SmallVector
+  GetAbstractMethodRequirements() const override {
+return llvm::SmallVector({{"get_thread_info"}});
   }
 
   StructuredData::DictionarySP CreateThread(lldb::tid_t tid,
diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.h
 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.h
index 36a219a656993b..a0da1bbc31c70f 100644
--- 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.h
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.h
@@ -29,10 +29,13 @@ class ScriptedPlatformPythonInterface : public 
ScriptedPlatformInterface,
  StructuredData::DictionarySP args_sp,
  StructuredData::Generic *script_obj = nullptr) override;
 
-  llvm::SmallVector GetAbstractMethods() const override {
-return llvm::SmallVector(
-{"list_processes", "attach_to_process", "launch_process",
- "kill_process"});
+  llvm::SmallVector
+  GetAbstractMethodRequirements() const override {
+return llvm::SmallVector(
+{{"list_processes"},
+ {"attach_to_process", 2},
+ {"launch_process", 2},
+ {"kill_process", 2}});
   }
 
   StructuredData::DictionarySP ListProcesses() override;
diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.h
 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.h
index 1535d573e72f43..703b942fe5647c 100644
--- 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.h
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.h
@@ -31,9 +31,12 @@ class ScriptedProcessPythonInterface : public 
ScriptedProcessInterface,
  StructuredData::DictionarySP args_sp,
  StructuredData::Generic *script_obj = nullptr) override;
 
-  llvm::SmallVector GetAbstractM

[Lldb-commits] [lldb] [lldb/Interpreter] Add requirements to Scripted Interface abstract methods (PR #109063)

2024-09-19 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben closed 
https://github.com/llvm/llvm-project/pull/109063
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/Interpreter] Add requirements to Scripted Interface abstract methods (PR #109063)

2024-09-19 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben updated 
https://github.com/llvm/llvm-project/pull/109063

>From 897dd358d3b15ec59e63068f7e328e914db49495 Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani 
Date: Thu, 19 Sep 2024 13:25:06 -0700
Subject: [PATCH] [lldb/Interpreter] Add requirements to Scripted Interface
 abstract methods

This patch adds new requirements to the Scripted Interface abstract
method checker to check the minimum number of argument for abstract
methods.

This check is done when creating the interface object so the object is
not created if the user implementation doesn't match the abstract method
requirement.

Signed-off-by: Med Ismail Bennani 
---
 .../Interfaces/ScriptedInterface.h|  17 +-
 .../OperatingSystemPythonInterface.h  |   5 +-
 .../ScriptedPlatformPythonInterface.h |  11 +-
 .../ScriptedProcessPythonInterface.h  |   9 +-
 .../Interfaces/ScriptedPythonInterface.h  | 160 +-
 .../ScriptedThreadPlanPythonInterface.h   |   3 +-
 .../ScriptedThreadPythonInterface.h   |   7 +-
 7 files changed, 158 insertions(+), 54 deletions(-)

diff --git a/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h 
b/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h
index 89c0b36d6fc2a1..a3dc52c435561f 100644
--- a/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h
+++ b/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h
@@ -31,7 +31,22 @@ class ScriptedInterface {
 return m_object_instance_sp;
   }
 
-  virtual llvm::SmallVector GetAbstractMethods() const = 
0;
+  struct AbstractMethodRequirement {
+llvm::StringLiteral name;
+size_t min_arg_count = 0;
+  };
+
+  virtual llvm::SmallVector
+  GetAbstractMethodRequirements() const = 0;
+
+  llvm::SmallVector const GetAbstractMethods() const {
+llvm::SmallVector abstract_methods;
+llvm::transform(GetAbstractMethodRequirements(), abstract_methods.begin(),
+[](const AbstractMethodRequirement &requirement) {
+  return requirement.name;
+});
+return abstract_methods;
+  }
 
   template 
   static Ret ErrorWithMessage(llvm::StringRef caller_name,
diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.h
 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.h
index 92358ac6c34f7e..102c3c39537686 100644
--- 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.h
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.h
@@ -31,8 +31,9 @@ class OperatingSystemPythonInterface
  StructuredData::DictionarySP args_sp,
  StructuredData::Generic *script_obj = nullptr) override;
 
-  llvm::SmallVector GetAbstractMethods() const override {
-return llvm::SmallVector({"get_thread_info"});
+  llvm::SmallVector
+  GetAbstractMethodRequirements() const override {
+return llvm::SmallVector({{"get_thread_info"}});
   }
 
   StructuredData::DictionarySP CreateThread(lldb::tid_t tid,
diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.h
 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.h
index 36a219a656993b..a0da1bbc31c70f 100644
--- 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.h
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.h
@@ -29,10 +29,13 @@ class ScriptedPlatformPythonInterface : public 
ScriptedPlatformInterface,
  StructuredData::DictionarySP args_sp,
  StructuredData::Generic *script_obj = nullptr) override;
 
-  llvm::SmallVector GetAbstractMethods() const override {
-return llvm::SmallVector(
-{"list_processes", "attach_to_process", "launch_process",
- "kill_process"});
+  llvm::SmallVector
+  GetAbstractMethodRequirements() const override {
+return llvm::SmallVector(
+{{"list_processes"},
+ {"attach_to_process", 2},
+ {"launch_process", 2},
+ {"kill_process", 2}});
   }
 
   StructuredData::DictionarySP ListProcesses() override;
diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.h
 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.h
index 1535d573e72f43..703b942fe5647c 100644
--- 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.h
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.h
@@ -31,9 +31,12 @@ class ScriptedProcessPythonInterface : public 
ScriptedProcessInterface,
  StructuredData::DictionarySP args_sp,
  StructuredData::Generic *script_obj = nullptr) override;
 
-  llvm::SmallVector GetAbstractM

[Lldb-commits] [lldb] [lldb/Interpreter] Add requirements to Scripted Interface abstract methods (PR #109063)

2024-09-19 Thread Med Ismail Bennani via lldb-commits


@@ -186,36 +210,49 @@ class ScriptedPythonInterface : virtual public 
ScriptedInterface {
 if (!checker_or_err)
   return checker_or_err.takeError();
 
+llvm::Error abstract_method_errors = llvm::Error::success();
 for (const auto &method_checker : *checker_or_err)
   switch (method_checker.second) {
   case AbstractMethodCheckerCases::eNotImplemented:
-LLDB_LOG(GetLog(LLDBLog::Script),
- "Abstract method {0}.{1} not implemented.",
- obj_class_name.GetString(), method_checker.first);
+abstract_method_errors = llvm::joinErrors(
+std::move(abstract_method_errors),
+std::move(create_error("Abstract method {0}.{1} not implemented.",
+   obj_class_name.GetString(),
+   method_checker.first)));
 break;
   case AbstractMethodCheckerCases::eNotAllocated:
-LLDB_LOG(GetLog(LLDBLog::Script),
- "Abstract method {0}.{1} not allocated.",
- obj_class_name.GetString(), method_checker.first);
+abstract_method_errors = llvm::joinErrors(
+std::move(abstract_method_errors),
+std::move(create_error("Abstract method {0}.{1} not allocated.",
+   obj_class_name.GetString(),
+   method_checker.first)));
 break;
   case AbstractMethodCheckerCases::eNotCallable:
-LLDB_LOG(GetLog(LLDBLog::Script),
- "Abstract method {0}.{1} not callable.",
- obj_class_name.GetString(), method_checker.first);
+abstract_method_errors = llvm::joinErrors(
+std::move(abstract_method_errors),
+std::move(create_error("Abstract method {0}.{1} not callable.",
+   obj_class_name.GetString(),
+   method_checker.first)));
+break;
+  case AbstractMethodCheckerCases::eInvalidArgumentCount:
+abstract_method_errors = llvm::joinErrors(
+std::move(abstract_method_errors),
+std::move(create_error(
+"Abstract method {0}.{1} has unexpected argument count.",

medismailben wrote:

Yeah, it would just require more plumbing.

https://github.com/llvm/llvm-project/pull/109063
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/Interpreter] Add requirements to Scripted Interface abstract methods (PR #109063)

2024-09-18 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben updated 
https://github.com/llvm/llvm-project/pull/109063

>From e815d5f65a23987d0f27849346610c1770094b6f Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani 
Date: Wed, 18 Sep 2024 23:09:35 -0700
Subject: [PATCH] [lldb/Interpreter] Add requirements to Scripted Interface
 abstract methods

This patch adds new requirements to the Scripted Interface abstract
method checker to check the minimum number of argument for abstract
methods.

This check is done when creating the interface object so the object is
not created if the user implementation doesn't match the abstract method
requirement.

Signed-off-by: Med Ismail Bennani 
---
 .../Interfaces/ScriptedInterface.h|  17 ++-
 .../OperatingSystemPythonInterface.h  |   5 +-
 .../ScriptedPlatformPythonInterface.h |  11 +-
 .../ScriptedProcessPythonInterface.h  |   9 +-
 .../Interfaces/ScriptedPythonInterface.h  | 111 --
 .../ScriptedThreadPlanPythonInterface.h   |   3 +-
 .../ScriptedThreadPythonInterface.h   |   7 +-
 7 files changed, 112 insertions(+), 51 deletions(-)

diff --git a/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h 
b/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h
index 89c0b36d6fc2a1..a3dc52c435561f 100644
--- a/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h
+++ b/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h
@@ -31,7 +31,22 @@ class ScriptedInterface {
 return m_object_instance_sp;
   }
 
-  virtual llvm::SmallVector GetAbstractMethods() const = 
0;
+  struct AbstractMethodRequirement {
+llvm::StringLiteral name;
+size_t min_arg_count = 0;
+  };
+
+  virtual llvm::SmallVector
+  GetAbstractMethodRequirements() const = 0;
+
+  llvm::SmallVector const GetAbstractMethods() const {
+llvm::SmallVector abstract_methods;
+llvm::transform(GetAbstractMethodRequirements(), abstract_methods.begin(),
+[](const AbstractMethodRequirement &requirement) {
+  return requirement.name;
+});
+return abstract_methods;
+  }
 
   template 
   static Ret ErrorWithMessage(llvm::StringRef caller_name,
diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.h
 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.h
index 92358ac6c34f7e..102c3c39537686 100644
--- 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.h
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.h
@@ -31,8 +31,9 @@ class OperatingSystemPythonInterface
  StructuredData::DictionarySP args_sp,
  StructuredData::Generic *script_obj = nullptr) override;
 
-  llvm::SmallVector GetAbstractMethods() const override {
-return llvm::SmallVector({"get_thread_info"});
+  llvm::SmallVector
+  GetAbstractMethodRequirements() const override {
+return llvm::SmallVector({{"get_thread_info"}});
   }
 
   StructuredData::DictionarySP CreateThread(lldb::tid_t tid,
diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.h
 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.h
index 36a219a656993b..3031508f892322 100644
--- 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.h
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.h
@@ -29,10 +29,13 @@ class ScriptedPlatformPythonInterface : public 
ScriptedPlatformInterface,
  StructuredData::DictionarySP args_sp,
  StructuredData::Generic *script_obj = nullptr) override;
 
-  llvm::SmallVector GetAbstractMethods() const override {
-return llvm::SmallVector(
-{"list_processes", "attach_to_process", "launch_process",
- "kill_process"});
+  llvm::SmallVector
+  GetAbstractMethodRequirements() const override {
+return llvm::SmallVector(
+{{"list_processes"},
+ {"attach_to_process", 1},
+ {"launch_process", 1},
+ {"kill_process", 1}});
   }
 
   StructuredData::DictionarySP ListProcesses() override;
diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.h
 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.h
index 1535d573e72f43..fc645981b61b31 100644
--- 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.h
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.h
@@ -31,9 +31,12 @@ class ScriptedProcessPythonInterface : public 
ScriptedProcessInterface,
  StructuredData::DictionarySP args_sp,
  StructuredData::Generic *script_obj = nullptr) override;
 
-  llvm::SmallVector GetAbstract

[Lldb-commits] [lldb] Add docs and an example use of the scripted command get_flags API. (PR #109176)

2024-09-18 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben commented:

LGTM!

https://github.com/llvm/llvm-project/pull/109176
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/Interpreter] Add requirements to Scripted Interface abstract methods (PR #109063)

2024-09-18 Thread Med Ismail Bennani via lldb-commits


@@ -78,8 +100,11 @@ class ScriptedPythonInterface : virtual public 
ScriptedInterface {
 using namespace python;
 using Locker = ScriptInterpreterPythonImpl::Locker;
 
-auto create_error = [](std::string message) {
-  return llvm::createStringError(llvm::inconvertibleErrorCode(), message);
+Log *log = GetLog(LLDBLog::Script);
+auto create_error = [](llvm::StringRef format, auto &&...ts) {

medismailben wrote:

Made it an `llvm::StringLitteral` instead ;)

https://github.com/llvm/llvm-project/pull/109063
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add warning message to `session save` when transcript isn't saved. (PR #109020)

2024-09-18 Thread Med Ismail Bennani via lldb-commits

medismailben wrote:

> Maybe `interpreter.save-transcript` could be true by default as well. Any 
> feedback welcome.

Although that could be useful but I'm concerned of the performance aspect of 
it. Not everyone cares to save transcripts so I'm not sure it should be on by 
default. I like this patch because it explains to the user what they need to do 
to save the transaction (enable the settings), may be that's good enough.

https://github.com/llvm/llvm-project/pull/109020
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add warning message to `session save` when transcript isn't saved. (PR #109020)

2024-09-18 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben requested changes to this pull request.


https://github.com/llvm/llvm-project/pull/109020
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add warning message to `session save` when transcript isn't saved. (PR #109020)

2024-09-18 Thread Med Ismail Bennani via lldb-commits


@@ -3306,6 +3306,8 @@ bool CommandInterpreter::SaveTranscript(
   result.SetStatus(eReturnStatusSuccessFinishNoResult);
   result.AppendMessageWithFormat("Session's transcripts saved to %s\n",
  output_file->c_str());
+  if (!GetSaveTranscript())
+result.AppendError("Note: the setting interpreter.save-transcript is set 
to false, so the transcript might not have been recorded.");

medismailben wrote:

We should do this at the beginning of the function, before doing the work and 
return early if `save-transcript` is disabled.

https://github.com/llvm/llvm-project/pull/109020
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/Interpreter] Introduce `ScriptedStopHook{, Python}Interface` & make use of it (PR #105449)

2024-09-17 Thread Med Ismail Bennani via lldb-commits

medismailben wrote:

Depends on https://github.com/llvm/llvm-project/pull/109063/files

https://github.com/llvm/llvm-project/pull/105449
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/Interpreter] Add requirements to Scripted Interface abstract methods (PR #109063)

2024-09-17 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben created 
https://github.com/llvm/llvm-project/pull/109063

This patch adds new requirements to the Scripted Interface abstract method 
checker to check the minimum number of argument for abstract methods.

This check is done when creating the interface object so the object is not 
created if the user implementation doesn't match the abstract method 
requirement.

>From 91d993c5ccb6301037b5e28ae686bc8e6aef6efe Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani 
Date: Fri, 6 Sep 2024 14:00:23 -0700
Subject: [PATCH] [lldb/Interpreter] Add requirements to Scripted Interface
 abstract methods

This patch adds new requirements to the Scripted Interface abstract
method checker to check the minimum number of argument for abstract
methods.

This check is done when creating the interface object so the object is
not created if the user implementation doesn't match the abstract method
requirement.

Signed-off-by: Med Ismail Bennani 
---
 .../Interfaces/ScriptedInterface.h|  17 ++-
 .../OperatingSystemPythonInterface.h  |   5 +-
 .../ScriptedPlatformPythonInterface.h |  11 +-
 .../ScriptedProcessPythonInterface.h  |   9 +-
 .../Interfaces/ScriptedPythonInterface.h  | 107 --
 .../ScriptedThreadPlanPythonInterface.h   |   3 +-
 .../ScriptedThreadPythonInterface.h   |   7 +-
 7 files changed, 108 insertions(+), 51 deletions(-)

diff --git a/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h 
b/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h
index 89c0b36d6fc2a1..a3dc52c435561f 100644
--- a/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h
+++ b/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h
@@ -31,7 +31,22 @@ class ScriptedInterface {
 return m_object_instance_sp;
   }
 
-  virtual llvm::SmallVector GetAbstractMethods() const = 
0;
+  struct AbstractMethodRequirement {
+llvm::StringLiteral name;
+size_t min_arg_count = 0;
+  };
+
+  virtual llvm::SmallVector
+  GetAbstractMethodRequirements() const = 0;
+
+  llvm::SmallVector const GetAbstractMethods() const {
+llvm::SmallVector abstract_methods;
+llvm::transform(GetAbstractMethodRequirements(), abstract_methods.begin(),
+[](const AbstractMethodRequirement &requirement) {
+  return requirement.name;
+});
+return abstract_methods;
+  }
 
   template 
   static Ret ErrorWithMessage(llvm::StringRef caller_name,
diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.h
 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.h
index 92358ac6c34f7e..102c3c39537686 100644
--- 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.h
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.h
@@ -31,8 +31,9 @@ class OperatingSystemPythonInterface
  StructuredData::DictionarySP args_sp,
  StructuredData::Generic *script_obj = nullptr) override;
 
-  llvm::SmallVector GetAbstractMethods() const override {
-return llvm::SmallVector({"get_thread_info"});
+  llvm::SmallVector
+  GetAbstractMethodRequirements() const override {
+return llvm::SmallVector({{"get_thread_info"}});
   }
 
   StructuredData::DictionarySP CreateThread(lldb::tid_t tid,
diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.h
 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.h
index 36a219a656993b..3031508f892322 100644
--- 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.h
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.h
@@ -29,10 +29,13 @@ class ScriptedPlatformPythonInterface : public 
ScriptedPlatformInterface,
  StructuredData::DictionarySP args_sp,
  StructuredData::Generic *script_obj = nullptr) override;
 
-  llvm::SmallVector GetAbstractMethods() const override {
-return llvm::SmallVector(
-{"list_processes", "attach_to_process", "launch_process",
- "kill_process"});
+  llvm::SmallVector
+  GetAbstractMethodRequirements() const override {
+return llvm::SmallVector(
+{{"list_processes"},
+ {"attach_to_process", 1},
+ {"launch_process", 1},
+ {"kill_process", 1}});
   }
 
   StructuredData::DictionarySP ListProcesses() override;
diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.h
 
b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.h
index 1535d573e72f43..fc645981b61b31 100644
--- 
a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.h
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/Int

[Lldb-commits] [lldb] [lldb] Emit signpost intervals for progress events (NFC) (PR #108498)

2024-09-13 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/108498
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add a comment in the SB API doc about keeping the SB API's lightweight. (PR #108462)

2024-09-12 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben approved this pull request.


https://github.com/llvm/llvm-project/pull/108462
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Print a warning on checksum mismatch (PR #107968)

2024-09-11 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/107968
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang] [compiler-rt] [libcxx] [lldb] [llvm] Rename Sanitizer Coverage => Coverage Sanitizer (PR #106505)

2024-09-03 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben approved this pull request.

LGTM for lldb's part

https://github.com/llvm/llvm-project/pull/106505
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Change the implementation of Status to store an llvm::Error (NFC) (PR #106774)

2024-09-01 Thread Med Ismail Bennani via lldb-commits


@@ -97,7 +97,7 @@ class LLDB_API SBError {
   friend class lldb_private::ScriptInterpreter;
   friend class lldb_private::python::SWIGBridge;
 
-  SBError(const lldb_private::Status &error);
+  SBError(lldb_private::Status &&error);

medismailben wrote:

+1

https://github.com/llvm/llvm-project/pull/106774
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Change the implementation of Status to store an llvm::Error (NFC) (PR #106774)

2024-08-30 Thread Med Ismail Bennani via lldb-commits


@@ -96,16 +128,49 @@ Status Status::FromErrorStringWithFormat(const char 
*format, ...) {
   return Status(string);
 }
 
-llvm::Error Status::ToError() const {
-  if (Success())
+Status Status::FromExpressionError(lldb::ExpressionResults result,
+   std::string msg) {
+  return Status(llvm::make_error(
+  std::error_code(result, expression_category()), msg));
+}
+
+/// Creates a deep copy of all known errors and converts all other
+/// errors to a new llvm::StringError.
+static llvm::Error cloneError(llvm::Error &error) {

medismailben wrote:

nit: why isn't this starting with a capital letter like the other methods 
(camelCase vs. PascalCase) ?

https://github.com/llvm/llvm-project/pull/106774
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Change the implementation of Status to store an llvm::Error (NFC) (PR #106774)

2024-08-30 Thread Med Ismail Bennani via lldb-commits


@@ -133,36 +198,30 @@ static std::string RetrieveWin32ErrorString(uint32_t 
error_code) {
 }
 #endif
 
+std::string MachKernelError::message() const {
+#if defined(__APPLE__)
+  if (const char *s = ::mach_error_string(convertToErrorCode().value()))
+return s;
+#endif
+  return "MachKernelError";
+}
+
+std::string Win32Error::message() const {
+#if defined(_WIN32)
+  return RetrieveWin32ErrorString(convertToErrorCode().value());
+#endif
+  return "Win32Error";
+}
+
 // Get the error value as a NULL C string. The error string will be fetched and
 // cached on demand. The cached error string value will remain until the error
 // value is changed or cleared.
 const char *Status::AsCString(const char *default_error_str) const {
   if (Success())
 return nullptr;
 
-  if (m_string.empty()) {
-switch (m_type) {
-case eErrorTypeMachKernel:
-#if defined(__APPLE__)
-  if (const char *s = ::mach_error_string(m_code))
-m_string.assign(s);
-#endif
-  break;
-
-case eErrorTypePOSIX:
-  m_string = llvm::sys::StrError(m_code);
-  break;
+  m_string = llvm::toStringWithoutConsuming(m_error);

medismailben wrote:

TIL

https://github.com/llvm/llvm-project/pull/106774
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Change the implementation of Status to store an llvm::Error (NFC) (PR #106774)

2024-08-30 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben approved this pull request.

This is great! LGTM with comments.

https://github.com/llvm/llvm-project/pull/106774
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Change the implementation of Status to store an llvm::Error (NFC) (PR #106774)

2024-08-30 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben edited 
https://github.com/llvm/llvm-project/pull/106774
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Change the implementation of Status to store an llvm::Error (NFC) (PR #106774)

2024-08-30 Thread Med Ismail Bennani via lldb-commits


@@ -33,16 +33,16 @@ class RemoteAwarePlatformTester : public 
RemoteAwarePlatform {
   MOCK_METHOD0(CalculateTrapHandlerSymbolNames, void());
 
   MOCK_METHOD2(ResolveExecutable,
-   std::pair(const ModuleSpec &,
-   const FileSpecList *));
+   std::pair(const ModuleSpec &,
+ const FileSpecList *));
   Status
   ResolveExecutable(const ModuleSpec &module_spec,
 lldb::ModuleSP &exe_module_sp,
 const FileSpecList *module_search_paths_ptr) /*override*/
   { // NOLINT(modernize-use-override)
 auto pair = ResolveExecutable(module_spec, module_search_paths_ptr);
 exe_module_sp = pair.second;
-return pair.first;
+return pair.first ? Status() : Status::FromErrorString("error");

medismailben wrote:

```suggestion
return pair.first ? {} : Status::FromErrorString("error");
```

https://github.com/llvm/llvm-project/pull/106774
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Change the implementation of Status to store an llvm::Error (NFC) (PR #106774)

2024-08-30 Thread Med Ismail Bennani via lldb-commits


@@ -27,15 +27,15 @@ TEST(StatusTest, Formatv) {
 }
 
 TEST(StatusTest, ErrorConstructor) {
-  EXPECT_TRUE(Status(llvm::Error::success()).Success());
+  EXPECT_TRUE(Status::FromError(llvm::Error::success()).Success());
 
-  Status eagain(
+  Status eagain = Status::FromError(
   llvm::errorCodeToError(std::error_code(EAGAIN, 
std::generic_category(;
   EXPECT_TRUE(eagain.Fail());
   EXPECT_EQ(eErrorTypePOSIX, eagain.GetType());
   EXPECT_EQ(Status::ValueType(EAGAIN), eagain.GetError());
 
-  Status foo(llvm::make_error(
+  Status foo = Status::FromError(llvm::make_error(
   "foo", llvm::inconvertibleErrorCode()));

medismailben wrote:

```suggestion
  Status foo = Status::FromError(createStringError("foo"));
```

https://github.com/llvm/llvm-project/pull/106774
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Inline expression evaluator error visualization (PR #106470)

2024-08-29 Thread Med Ismail Bennani via lldb-commits


@@ -2076,7 +2077,11 @@ bool CommandInterpreter::HandleCommand(const char 
*command_line,
 }
 
 ElapsedTime elapsed(execute_time);
-cmd_obj->Execute(remainder.c_str(), result);
+size_t nchar = real_original_command_string.find(remainder);
+std::optional pos_in_cmd;
+if (nchar != std::string::npos)
+  pos_in_cmd = nchar + GetDebugger().GetPrompt().size();
+cmd_obj->Execute(remainder.c_str(), pos_in_cmd, result);

medismailben wrote:

> I think expr is probably the only command that is likely to ever echo its 
> command string into the output. That's not something most commands would do. 
> So this doesn't seem like a feature that should have as much prominence as 
> changing the API gives it. I don't want to have to worry about what this 
> means when I'm writing a new command, given the answer is almost surely to be 
> "not relevant".

I don't have a strong option about this (as long as we don't update all the 
`DoExecute` implementations), but I was under the impression that in the 
future, some commands could make use of it to point directly to what caused an 
error in their invocation. But again, we can have it be part of the expression 
for now.

https://github.com/llvm/llvm-project/pull/106470
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Inline expression evaluator error visualization (PR #106470)

2024-08-28 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben requested changes to this pull request.

Let's make `std::optional offset_in_command` a default member of the 
`CommandObject` base class to avoid changing all the `DoExecute` 
implementations, even when not needed.

https://github.com/llvm/llvm-project/pull/106470
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Inline expression evaluator error visualization (PR #106470)

2024-08-28 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben edited 
https://github.com/llvm/llvm-project/pull/106470
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Inline expression evaluator error visualization (PR #106470)

2024-08-28 Thread Med Ismail Bennani via lldb-commits


@@ -2076,7 +2077,11 @@ bool CommandInterpreter::HandleCommand(const char 
*command_line,
 }
 
 ElapsedTime elapsed(execute_time);
-cmd_obj->Execute(remainder.c_str(), result);
+size_t nchar = real_original_command_string.find(remainder);
+std::optional pos_in_cmd;
+if (nchar != std::string::npos)
+  pos_in_cmd = nchar + GetDebugger().GetPrompt().size();
+cmd_obj->Execute(remainder.c_str(), pos_in_cmd, result);

medismailben wrote:

Instead of updating every `DoExecute` implementations, it would be reasonable 
to have make this an optional member of the `CommandObject` base class so it 
can be accessed by the derived `CommandObject` classes that gonna use it.


The optional could be set in the non-virtual `CommandObject::Execute` command, 
since that's the one that calls the derived class `DoExecute` or may be by 
adding a setter to the `CommandObject` base class. 

This would greatly reduce the size of this patch.

https://github.com/llvm/llvm-project/pull/106470
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add Status::Detail to store expression evaluator diagnostics [… (PR #106442)

2024-08-28 Thread Med Ismail Bennani via lldb-commits


@@ -65,6 +65,23 @@ std::string DiagnosticManager::GetString(char separator) {
   return ret;
 }
 
+Status DiagnosticManager::GetAsStatus(lldb::ExpressionResults result) {
+  llvm::SmallVector details;
+  details.reserve(m_diagnostics.size());
+  for (const auto &diagnostic : m_diagnostics)
+details.push_back(diagnostic->GetDetail());
+  return Status::FromExpressionErrorDetails(result, std::move(details));
+}
+
+void DiagnosticManager::AddDiagnostic(llvm::StringRef message,
+  lldb::Severity severity,
+  DiagnosticOrigin origin,
+  uint32_t compiler_id) {
+  m_diagnostics.emplace_back(std::make_unique(
+  origin, compiler_id,
+  Status::Detail{{}, severity, message.str(), message.str()}));

medismailben wrote:

Looks like in this case, `Status::Detail::message` is the same as 
`Status::Detail::rendered`. Is that really what we want ? If so, do we need 
both variables then ?

https://github.com/llvm/llvm-project/pull/106442
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add Status::Detail to store expression evaluator diagnostics [… (PR #106442)

2024-08-28 Thread Med Ismail Bennani via lldb-commits


@@ -328,18 +328,19 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
 }
 
 if (!parse_success) {
-  std::string msg;
-  {
-llvm::raw_string_ostream os(msg);
-if (!diagnostic_manager.Diagnostics().empty())
-  os << diagnostic_manager.GetString();
-else
-  os << "expression failed to parse (no further compiler diagnostics)";
-if (target->GetEnableNotifyAboutFixIts() && fixed_expression &&
-!fixed_expression->empty())
-  os << "\nfixed expression suggested:\n  " << *fixed_expression;
+  if (target->GetEnableNotifyAboutFixIts() && fixed_expression &&
+  !fixed_expression->empty()) {
+std::string fixit =
+"fixed expression suggested:\n  " + *fixed_expression;
+diagnostic_manager.AddDiagnostic(fixit, lldb::eSeverityInfo,
+ eDiagnosticOriginLLDB);
   }
-  error = Status::FromExpressionError(execution_results, msg);
+  if (!diagnostic_manager.Diagnostics().size())
+error = Status::FromExpressionError(
+execution_results,
+"expression failed to parse (no further compiler diagnostics)");
+  else
+error = diagnostic_manager.GetAsStatus(execution_results);

medismailben wrote:

Assuming `AddDiagnostic` never fails to append a new fixit diagnostic, we will 
find ourselves in this `else` branch. However it looks like 
`DiagnosticManager::GetAsStatus` will always create a status object with a 
`lldb::eErrorTypeExpression` error type.

I'm wondering if fixits should actually be reported as errors ...

https://github.com/llvm/llvm-project/pull/106442
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add Status::Detail to store expression evaluator diagnostics [… (PR #106442)

2024-08-28 Thread Med Ismail Bennani via lldb-commits


@@ -130,13 +120,17 @@ class DiagnosticManager {
   m_diagnostics.back()->AppendMessage(str);
   }
 
-  // Returns a string containing errors in this format:
-  //
-  // "error: error text\n
-  // warning: warning text\n
-  // remark text\n"
+  /// Returns a string containing errors in this format:
+  ///
+  /// "error: error text\n
+  /// warning: warning text\n
+  /// remark text\n"
+  LLVM_DEPRECATED("Use GetAsStatus instead", "GetAsStatus()")

medismailben wrote:

Why does this need to be marked deprecated ? It's internal API, we could just 
get rid of it, right ?

https://github.com/llvm/llvm-project/pull/106442
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add Status::Detail to store expression evaluator diagnostics [… (PR #106442)

2024-08-28 Thread Med Ismail Bennani via lldb-commits


@@ -47,7 +48,34 @@ class Status {
   /// into ValueType.
   typedef uint32_t ValueType;
 
-  Status();
+  /// A customizable "detail" for an error. For example, expression
+  /// evaluation failures often have more than one diagnostic that the
+  /// UI layer might want to render differently.
+  ///
+  /// Running example:
+  ///   (lldb) expr 1+x
+  ///   error: :1:3: use of undeclared identifier 'foo'
+  ///   1+foo
+  /// ^
+  struct Detail {
+struct SourceLocation {
+  FileSpec file;
+  unsigned line = 0;
+  uint16_t column = 0;
+  uint16_t length = 0;
+  bool in_user_input = false;

medismailben wrote:

What are these 2 fields used for ?

https://github.com/llvm/llvm-project/pull/106442
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB][SBSaveCore] Add selectable memory regions to SBSaveCore (PR #105442)

2024-08-27 Thread Med Ismail Bennani via lldb-commits

medismailben wrote:

It looks like this broke lldb macOS bots: 
https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/as-lldb-cmake/10450/

@Jlalond can you take a look ? Thanks.

https://github.com/llvm/llvm-project/pull/105442
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Turn lldb_private::Status into a value type. (PR #106163)

2024-08-26 Thread Med Ismail Bennani via lldb-commits


@@ -56,19 +56,41 @@ class Status {
   ///
   /// \param[in] type
   /// The type for \a err.
-  explicit Status(ValueType err,
-  lldb::ErrorType type = lldb::eErrorTypeGeneric);
+  explicit Status(ValueType err, lldb::ErrorType type = 
lldb::eErrorTypeGeneric,
+  llvm::StringRef msg = {});
 
   Status(std::error_code EC);
 
-  explicit Status(const char *format, ...)
-  __attribute__((format(printf, 2, 3)));
+  /// Create a generic error with the message err_str.
+  explicit Status(std::string &&err_str);
+  /// Create a generic error with the message err_str.
+  explicit Status(llvm::StringRef err_str);
+
+  static Status FromErrorString(const char *format) {
+if (format)
+  return Status(std::string(format));
+return Status(std::string("null error"));

medismailben wrote:

```suggestion
return Status(llvm::StringRef("null error"));
```

This should be more efficient.

https://github.com/llvm/llvm-project/pull/106163
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Turn lldb_private::Status into a value type. (PR #106163)

2024-08-26 Thread Med Ismail Bennani via lldb-commits


@@ -15,7 +15,7 @@ def __init__(self, exe_ctx: lldb.SBExecutionContext, args: 
lldb.SBStructuredData
 def read_memory_at_address(
 self, addr: int, size: int, error: lldb.SBError
 ) -> lldb.SBData:
-error.SetErrorString("This is an invalid scripted process!")
+error = Status::FromErrorString("This is an invalid scripted process!")

medismailben wrote:

This is not valid python. The regex should only be applied to C++.

https://github.com/llvm/llvm-project/pull/106163
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Turn lldb_private::Status into a value type. (PR #106163)

2024-08-26 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben commented:

Cool stuff! I think this is fine except for the python files.

https://github.com/llvm/llvm-project/pull/106163
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Turn lldb_private::Status into a value type. (PR #106163)

2024-08-26 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben edited 
https://github.com/llvm/llvm-project/pull/106163
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang] [compiler-rt] [libcxx] [lld] [lldb] [llvm] [mlir] [polly] python: use raw strings for regex (PR #105990)

2024-08-26 Thread Med Ismail Bennani via lldb-commits

medismailben wrote:

Nice! Please make sure to run the python formatter (`darker`) before landing 
this.

https://github.com/llvm/llvm-project/pull/105990
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [llvm] [Docs] Use cacheable myst_heading_slug_func value (PR #104847)

2024-08-26 Thread Med Ismail Bennani via lldb-commits

medismailben wrote:

> Requires myst_parser 0.19.0 (specifically 
> [executablebooks/MyST-Parser#696](https://github.com/executablebooks/MyST-Parser/pull/696))
>  which is over a year old by now. Do we mandate any minimum version for these 
> dependencies?

Kinda: 
[llvm/docs/requirements.txt](https://github.com/llvm/llvm-project/blob/main/llvm/docs/requirements.txt)
 describes the dependencies required to build the documentation and their 
version. It looks like for `myst_parser` the builder should have version 2.0.0 
so your patch should be good.

https://github.com/llvm/llvm-project/pull/104847
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [llvm] [Docs] Use cacheable myst_heading_slug_func value (PR #104847)

2024-08-26 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/104847
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Remove limit on max memory read size (PR #105765)

2024-08-23 Thread Med Ismail Bennani via lldb-commits

medismailben wrote:

> both of the linux PR tests failed in Unwind/trap_frame_sym_ctx.test, I could 
> have sworn the only test failure I had before was in 
> TestMemoryReadMaximumSize.py, I don't see how this PR breaks that test case. 
> Hmm.

I believe that failure is unrelated to your PR since another user have the 
exact same issue in theirs: https://github.com/llvm/llvm-project/pull/105757. 
The issue seems to be resolved by 
https://github.com/llvm/llvm-project/pull/105695.

https://github.com/llvm/llvm-project/pull/105765
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Remove limit on max memory read size (PR #105765)

2024-08-23 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/105765
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Remove limit on max memory read size (PR #105765)

2024-08-22 Thread Med Ismail Bennani via lldb-commits


@@ -102,7 +102,7 @@ let Definition = "target" in {
 DefaultUnsignedValue<1024>,
 Desc<"Maximum number of characters to show when using %s in summary 
strings.">;
   def MaxMemReadSize: Property<"max-memory-read-size", "UInt64">,
-DefaultUnsignedValue<1024>,
+DefaultUnsignedValue<4294967295>,

medismailben wrote:

suggestion: Either make it hex, or instead of providing a default value here, 
initialize the CommandOption to UINT32_MAX

https://github.com/llvm/llvm-project/pull/105765
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/Interpreter] Introduce `ScriptedStopHook{, Python}Interface` & make use of it (PR #105449)

2024-08-20 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben created 
https://github.com/llvm/llvm-project/pull/105449

This patch introduces new `ScriptedStopHook{,Python}Interface` classes that 
make use of the Scripted Interface infrastructure and makes use of it in 
`StopHookScripted`.

It also relax the requirement on the number of argument for initializing 
scripting extension if the size of the interface parameter pack contains 1 less 
element than the extension maximum number of positional arguments for this 
initializer.
This addresses the cases where the embedded interpreter session dictionary is 
passed to the extension initializer which is not used most of the time.

>From 78ca8b931a30d13a6817eeea562e15cf373465e1 Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani 
Date: Tue, 20 Aug 2024 16:13:54 -0700
Subject: [PATCH 1/3] [lldb/Interpreter] Create
 ScriptedStopHook{,Python}Interface (NFC)

This patch introduces a new scripted interface for ScriptedStopHooks.

This will be used in a follow-up patch to call into the script methods.

Signed-off-by: Med Ismail Bennani 
---
 .../Interfaces/ScriptedStopHookInterface.h| 33 
 .../lldb/Interpreter/ScriptInterpreter.h  |  4 +
 lldb/include/lldb/lldb-forward.h  |  3 +
 .../Python/Interfaces/CMakeLists.txt  |  1 +
 .../ScriptInterpreterPythonInterfaces.cpp |  2 +
 .../ScriptInterpreterPythonInterfaces.h   |  1 +
 .../ScriptedStopHookPythonInterface.cpp   | 75 +++
 .../ScriptedStopHookPythonInterface.h | 50 +
 .../Python/ScriptInterpreterPython.cpp|  5 ++
 .../Python/ScriptInterpreterPythonImpl.h  |  2 +
 10 files changed, 176 insertions(+)
 create mode 100644 
lldb/include/lldb/Interpreter/Interfaces/ScriptedStopHookInterface.h
 create mode 100644 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedStopHookPythonInterface.cpp
 create mode 100644 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedStopHookPythonInterface.h

diff --git 
a/lldb/include/lldb/Interpreter/Interfaces/ScriptedStopHookInterface.h 
b/lldb/include/lldb/Interpreter/Interfaces/ScriptedStopHookInterface.h
new file mode 100644
index 00..125e7f2077b543
--- /dev/null
+++ b/lldb/include/lldb/Interpreter/Interfaces/ScriptedStopHookInterface.h
@@ -0,0 +1,33 @@
+//===-- ScriptedStopHookInterface.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_INTERPRETER_INTERFACES_SCRIPTEDSTOPHOOKINTERFACE_H
+#define LLDB_INTERPRETER_INTERFACES_SCRIPTEDSTOPHOOKINTERFACE_H
+
+#include "lldb/lldb-private.h"
+
+#include "ScriptedInterface.h"
+
+namespace lldb_private {
+class ScriptedStopHookInterface : public ScriptedInterface {
+public:
+  virtual llvm::Expected
+  CreatePluginObject(llvm::StringRef class_name, lldb::TargetSP target_sp,
+ const StructuredDataImpl &args_sp) = 0;
+
+  /// "handle_stop" will return a bool with the meaning "should_stop"...
+  /// If nothing is returned, we'll assume we are going to stop.
+  /// Also any errors should return true, since we should stop on error.
+  virtual llvm::Expected HandleStop(ExecutionContext &exe_ctx,
+  lldb::StreamSP output_sp) {
+return true;
+  }
+};
+} // namespace lldb_private
+
+#endif // LLDB_INTERPRETER_INTERFACES_SCRIPTEDSTOPHOOKINTERFACE_H
diff --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h 
b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
index 89a480a28880aa..71fbb8487e246a 100644
--- a/lldb/include/lldb/Interpreter/ScriptInterpreter.h
+++ b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
@@ -574,6 +574,10 @@ class ScriptInterpreter : public PluginInterface {
 return {};
   }
 
+  virtual lldb::ScriptedStopHookInterfaceSP CreateScriptedStopHookInterface() {
+return {};
+  }
+
   virtual StructuredData::ObjectSP
   CreateStructuredDataFromScriptObject(ScriptObject obj) {
 return {};
diff --git a/lldb/include/lldb/lldb-forward.h b/lldb/include/lldb/lldb-forward.h
index 337eff696fcf3f..874376e116efd5 100644
--- a/lldb/include/lldb/lldb-forward.h
+++ b/lldb/include/lldb/lldb-forward.h
@@ -190,6 +190,7 @@ class ScriptInterpreterLocker;
 class ScriptedMetadata;
 class ScriptedPlatformInterface;
 class ScriptedProcessInterface;
+class ScriptedStopHookInterface;
 class ScriptedThreadInterface;
 class ScriptedThreadPlanInterface;
 class ScriptedSyntheticChildren;
@@ -407,6 +408,8 @@ typedef 
std::unique_ptr
 ScriptedPlatformInterfaceUP;
 typedef std::unique_ptr
 ScriptedProcessInterfaceUP;
+typedef std::shared_ptr
+ScriptedStopHookInterfaceSP;
 typedef std::shared_ptr
 ScriptedThreadInterfaceSP;
 typedef std::shared_ptr
diff --git 
a/lldb/so

[Lldb-commits] [lldb] [lldb] Fix windows debug build after 9d07f43 (PR #104896)

2024-08-20 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben closed 
https://github.com/llvm/llvm-project/pull/104896
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Extend frame recognizers to hide frames from backtraces (PR #104523)

2024-08-19 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben edited 
https://github.com/llvm/llvm-project/pull/104523
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Extend frame recognizers to hide frames from backtraces (PR #104523)

2024-08-19 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben approved this pull request.

LGTM modulo comment.

https://github.com/llvm/llvm-project/pull/104523
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Extend frame recognizers to hide frames from backtraces (PR #104523)

2024-08-19 Thread Med Ismail Bennani via lldb-commits


@@ -123,8 +126,12 @@ class StackFrameRecognizerManager {
   lldb::StackFrameRecognizerSP GetRecognizerForFrame(lldb::StackFrameSP frame);
 
   lldb::RecognizedStackFrameSP RecognizeFrame(lldb::StackFrameSP frame);
+  /// Quick way to determine whether the list of recognizers has been modified.
+  uint16_t GetGeneration() const { return m_generation; }
 
 private:
+  void BumpGeneration();

medismailben wrote:

Can we comment what does the do ?

https://github.com/llvm/llvm-project/pull/104523
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Reland "[lldb] Reland 2402b3213c2f with `/H` to debug the windows build issue (PR #101672)

2024-08-18 Thread Med Ismail Bennani via lldb-commits

medismailben wrote:

> Okay, that sort of makes sense. However, unless you actually want to be able 
> to disable each of these plugins independently (which it sounds like you 
> don't), then this is a very.. baroque way to achieve the desired effect (to 
> have multiple (plugin) classes registered with the plugin manager).
> 
> All of that cmake plugin logic is just a very elaborate way to invoke 
> `SomeClass::Initialize()`. Plugins are registered through 
> `PluginManager::RegisterPlugin`. While the usual case is that the 
> `Initialize` function performs a single `RegisterPlugin` call (and pretty 
> much nothing else), nothing actually depends or enforces that, and we do have 
> "plugins" where a single plugin library registers more than plugin class 
> (e.g. `lldbPluginPlatformMacOSX`). I think it would be perfectly reasonable 
> to register all of these classes from 
> `ScriptInterpreterPythonInterfaces::Initialize` (and maybe even from 
> `ScriptInterpreterPython::Initialize`).

I was on vacation last week, I try to give a stab a this tomorrow, thanks for 
the suggestions :)

https://github.com/llvm/llvm-project/pull/101672
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Extend frame recognizers to hide frames from backtraces (PR #104523)

2024-08-17 Thread Med Ismail Bennani via lldb-commits


@@ -1048,6 +1048,9 @@ let Command = "thread backtrace" in {
   Arg<"FrameIndex">, Desc<"Frame in which to start the backtrace">;
   def thread_backtrace_extended : Option<"extended", "e">, Group<1>,
   Arg<"Boolean">, Desc<"Show the extended backtrace, if available">;
+  def thread_backtrace_full : Option<"filtered", "f">, Group<1>,
+  Arg<"Boolean">,

medismailben wrote:

suggestion: `-a`, `--all-frames` (like the option for `ls`) and in the help for 
that option we could mention that it shows all the frames including the ones 
hidden by a recognizer.

https://github.com/llvm/llvm-project/pull/104523
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Reland "[lldb] Reland 2402b3213c2f with `/H` to debug the windows build issue (PR #101672)

2024-08-15 Thread Med Ismail Bennani via lldb-commits

medismailben wrote:

Originally, they were built in a single library and I added a cmake variable to 
make it work but @bulbazord & @JDevlieghere were not too happy with that 
approach. I think their argument was that if they're each different plugins, 
they need to be built into separate libraries and we should make an exception 
at the cmake level. See 
https://github.com/llvm/llvm-project/pull/97273#discussion_r1663074864 for more 
context. 

https://github.com/llvm/llvm-project/pull/101672
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Reland "[lldb] Reland 2402b3213c2f with `/H` to debug the windows build issue (PR #101672)

2024-08-15 Thread Med Ismail Bennani via lldb-commits

medismailben wrote:

> `lldbPluginScriptInterpreterPythonScriptedThreadPlanPythonInterface` quite a 
> mouthful for just a single cpp file. Maybe all of the interfaces could be a 
> part of a single library?
> 
> That would end up with something like:
> 
> ```
> D:\build-lldb\tools\lldb\source\Plugins\ScriptInterpreter\Python\Interfaces\CMakeFiles\lldbPluginScriptInterpreterPythonInterfaces.dir\lldbPluginScriptInterpreterPythonInterfaces.pdb
> ```
> 
> .. which is 80 chars shorter?

They need to be in separate libraries because I use the 
`PluginManager::Register` method to register each plugin for them to be shown 
in the `scripting extension list` command. We could may be change the library 
name to be shorter but that would "break" the naming convention I guess.

https://github.com/llvm/llvm-project/pull/101672
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Extend frame recognizers to hide frames from backtraces (PR #104523)

2024-08-15 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben commented:

I think this is a pretty cool idea but can we make sure it works using python 
frame recognizers. I believe the user should also have the ability to hide 
certain frames if they want, like it doesn't have to be system or language 
runtime frames.

https://github.com/llvm/llvm-project/pull/104523
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Extend frame recognizers to hide frames from backtraces (PR #104523)

2024-08-15 Thread Med Ismail Bennani via lldb-commits


@@ -91,7 +91,7 @@ class StackFrameList {
 
   size_t GetStatus(Stream &strm, uint32_t first_frame, uint32_t num_frames,
bool show_frame_info, uint32_t num_frames_with_source,
-   bool show_unique = false,
+   bool show_unique = false, bool should_filter = true,

medismailben wrote:

Can we rename `should_filter` to `show_hidden`. The former sounds like we're 
just about to perform the filtering whereas the latter sounds like some frames 
have a "hidden" flag and we should show them based on that. Also that would 
make it more consistent with the other flags.

https://github.com/llvm/llvm-project/pull/104523
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Extend frame recognizers to hide frames from backtraces (PR #104523)

2024-08-15 Thread Med Ismail Bennani via lldb-commits


@@ -1048,6 +1048,9 @@ let Command = "thread backtrace" in {
   Arg<"FrameIndex">, Desc<"Frame in which to start the backtrace">;
   def thread_backtrace_extended : Option<"extended", "e">, Group<1>,
   Arg<"Boolean">, Desc<"Show the extended backtrace, if available">;
+  def thread_backtrace_full : Option<"filtered", "f">, Group<1>,
+  Arg<"Boolean">,

medismailben wrote:

```suggestion
```
If you make this a `Boolean` you have to pass an argument to the option 
(`thread backtrace -f true`). If you don't specify it, you don't have to parse 
the argument into a boolean `SetOptionValue`, you just have to check the short 
option and set your flag.

https://github.com/llvm/llvm-project/pull/104523
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Extend frame recognizers to hide frames from backtraces (PR #104523)

2024-08-15 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben edited 
https://github.com/llvm/llvm-project/pull/104523
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Extend frame recognizers to hide frames from backtraces (PR #104523)

2024-08-15 Thread Med Ismail Bennani via lldb-commits


@@ -979,6 +988,8 @@ size_t StackFrameList::GetStatus(Stream &strm, uint32_t 
first_frame,
 ++num_frames_displayed;
   }
 
+  if (filtered)
+strm << "Note: Some frames were hidden by frame recognizers\n";

medismailben wrote:

There is a `frame recognizer` multiword command so I think it's fine to expose 
it to the user.

https://github.com/llvm/llvm-project/pull/104523
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Remove Phabricator usernames from Code Owners file (PR #102590)

2024-08-14 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben approved this pull request.


https://github.com/llvm/llvm-project/pull/102590
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Move definition of SBSaveCoreOptions dtor out of header (PR #102539)

2024-08-08 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben approved this pull request.

LGTM!

https://github.com/llvm/llvm-project/pull/102539
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/Interpreter] Fix ambiguous partial command resolution (PR #101934)

2024-08-08 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben closed 
https://github.com/llvm/llvm-project/pull/101934
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


  1   2   3   4   5   6   7   8   9   10   >