[Lldb-commits] [clang] [lldb] [llvm] Attach pre work (PR #126484)

2025-02-10 Thread via lldb-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write 
permissions for the repository. In which case you can instead tag reviewers by 
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a 
review by "ping"ing the PR by adding a comment “Ping”. The common courtesy 
"ping" rate is once a week. Please remember that you are asking for valuable 
time from other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[Lldb-commits] [clang] [lldb] [llvm] Attach pre work (PR #126484)

2025-02-10 Thread Hemang Gadhavi via lldb-commits

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


[Lldb-commits] [clang] [lldb] [llvm] Attach pre work (PR #126484)

2025-02-10 Thread Hemang Gadhavi via lldb-commits

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


[Lldb-commits] [clang] [libc] [libcxx] [lldb] [llvm] [doc] Add Discord invite link alongside channel links (PR #126352)

2025-02-10 Thread David Spickett via lldb-commits

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


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


[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)

2025-02-10 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,284 @@
+//===-- DILEval.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/ValueObject/DILEval.h"
+#include "lldb/Symbol/VariableList.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/ValueObject/DILAST.h"
+#include "lldb/ValueObject/ValueObject.h"
+#include "lldb/ValueObject/ValueObjectRegister.h"
+#include "lldb/ValueObject/ValueObjectVariable.h"
+#include "llvm/Support/FormatAdapters.h"
+#include 
+
+namespace lldb_private::dil {
+
+static lldb::ValueObjectSP
+LookupStaticIdentifier(lldb::TargetSP target_sp,
+   const llvm::StringRef &name_ref,
+   ConstString unqualified_name) {
+  // List global variable with the same "basename". There can be many matches
+  // from other scopes (namespaces, classes), so we do additional filtering
+  // later.
+  VariableList variable_list;
+  ConstString name(name_ref);
+  target_sp->GetImages().FindGlobalVariables(name, 1, variable_list);
+  if (variable_list.Empty())
+return nullptr;
+
+  ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
+  if (exe_scope == nullptr)
+exe_scope = target_sp.get();
+  for (const lldb::VariableSP &var_sp : variable_list) {
+lldb::ValueObjectSP valobj_sp(
+ValueObjectVariable::Create(exe_scope, var_sp));
+if (valobj_sp && valobj_sp->GetVariable() &&
+(valobj_sp->GetVariable()->NameMatches(unqualified_name) ||
+ valobj_sp->GetVariable()->NameMatches(ConstString(name_ref
+  return valobj_sp;
+  }
+
+  return nullptr;
+}
+
+static lldb::VariableSP DILFindVariable(ConstString name,
+VariableList *variable_list) {
+  lldb::VariableSP exact_match;
+  std::vector possible_matches;
+
+  typedef std::vector collection;
+  typedef collection::iterator iterator;
+
+  iterator pos, end = variable_list->end();
+  for (pos = variable_list->begin(); pos != end; ++pos) {
+llvm::StringRef str_ref_name = pos->get()->GetName().GetStringRef();
+// Check for global vars, which might start with '::'.
+str_ref_name.consume_front("::");
+
+if (str_ref_name == name.GetStringRef())
+  possible_matches.push_back(*pos);
+else if (pos->get()->NameMatches(name))
+  possible_matches.push_back(*pos);
+  }
+
+  // Look for exact matches (favors local vars over global vars)
+  auto exact_match_it =
+  llvm::find_if(possible_matches, [&](lldb::VariableSP var_sp) {
+return var_sp->GetName() == name;
+  });
+
+  if (exact_match_it != llvm::adl_end(possible_matches))
+exact_match = *exact_match_it;
+
+  if (!exact_match)
+// Look for a global var exact match.
+for (auto var_sp : possible_matches) {
+  llvm::StringRef str_ref_name = var_sp->GetName().GetStringRef();
+  if (str_ref_name.size() > 2 && str_ref_name[0] == ':' &&
+  str_ref_name[1] == ':')
+str_ref_name = str_ref_name.drop_front(2);

labath wrote:

```suggestion
  str_ref_name.consume_front("::");
```

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


[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)

2025-02-10 Thread Pavel Labath via lldb-commits

https://github.com/labath commented:

After thinking about this more, I think I'd like to remove the parts related to 
accessing global variables from this patch. I have two reasons for that:
- it's not required functionality for the minimum viable product (which is 
replacing "frame variable") as the command does not support this functionality 
right now
- I still have questions about how this functionality is supposed to work, and 
I think it'd be better to discuss them separately, once the rest of the 
infrastructure is in place.

Registers are also not supported by "frame var", but I think the functionality 
there is clear, so I have no problem with including them in the initial patch.

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


[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)

2025-02-10 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,101 @@
+//===-- DILAST.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_VALUEOBJECT_DILAST_H
+#define LLDB_VALUEOBJECT_DILAST_H
+
+#include "lldb/ValueObject/ValueObject.h"
+#include 
+
+namespace lldb_private::dil {
+
+/// The various types DIL AST nodes (used by the DIL parser).
+enum class NodeKind {
+  eErrorNode,
+  eIdentifierNode,
+};
+
+/// Forward declaration, for use in DIL AST nodes. Definition is at the very
+/// end of this file.
+class Visitor;
+
+/// The rest of the classes in this file, except for the Visitor class at the
+/// very end, define all the types of AST nodes used by the DIL parser and
+/// expression evaluator. The DIL parser parses the input string and creates
+/// the AST parse tree from the AST nodes. The resulting AST node tree gets
+/// passed to the DIL expression evaluator, which evaluates the DIL AST nodes
+/// and creates/returns a ValueObjectSP containing the result.
+
+/// Base class for AST nodes used by the Data Inspection Language (DIL) parser.
+/// All of the specialized types of AST nodes inherit from this (virtual) base
+/// class.
+class DILASTNode {

labath wrote:

```suggestion
class ASTNode {
```

... given that this is already in the `dil` namespace?

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


[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)

2025-02-10 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,284 @@
+//===-- DILEval.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/ValueObject/DILEval.h"
+#include "lldb/Symbol/VariableList.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/ValueObject/DILAST.h"
+#include "lldb/ValueObject/ValueObject.h"
+#include "lldb/ValueObject/ValueObjectRegister.h"
+#include "lldb/ValueObject/ValueObjectVariable.h"
+#include "llvm/Support/FormatAdapters.h"
+#include 
+
+namespace lldb_private::dil {
+
+static lldb::ValueObjectSP
+LookupStaticIdentifier(lldb::TargetSP target_sp,
+   const llvm::StringRef &name_ref,
+   ConstString unqualified_name) {
+  // List global variable with the same "basename". There can be many matches
+  // from other scopes (namespaces, classes), so we do additional filtering
+  // later.
+  VariableList variable_list;
+  ConstString name(name_ref);
+  target_sp->GetImages().FindGlobalVariables(name, 1, variable_list);
+  if (variable_list.Empty())
+return nullptr;
+
+  ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
+  if (exe_scope == nullptr)
+exe_scope = target_sp.get();
+  for (const lldb::VariableSP &var_sp : variable_list) {
+lldb::ValueObjectSP valobj_sp(
+ValueObjectVariable::Create(exe_scope, var_sp));
+if (valobj_sp && valobj_sp->GetVariable() &&
+(valobj_sp->GetVariable()->NameMatches(unqualified_name) ||
+ valobj_sp->GetVariable()->NameMatches(ConstString(name_ref
+  return valobj_sp;
+  }
+
+  return nullptr;
+}
+
+static lldb::VariableSP DILFindVariable(ConstString name,
+VariableList *variable_list) {
+  lldb::VariableSP exact_match;
+  std::vector possible_matches;
+
+  typedef std::vector collection;
+  typedef collection::iterator iterator;
+
+  iterator pos, end = variable_list->end();
+  for (pos = variable_list->begin(); pos != end; ++pos) {
+llvm::StringRef str_ref_name = pos->get()->GetName().GetStringRef();
+// Check for global vars, which might start with '::'.
+str_ref_name.consume_front("::");
+
+if (str_ref_name == name.GetStringRef())
+  possible_matches.push_back(*pos);
+else if (pos->get()->NameMatches(name))
+  possible_matches.push_back(*pos);
+  }
+
+  // Look for exact matches (favors local vars over global vars)
+  auto exact_match_it =
+  llvm::find_if(possible_matches, [&](lldb::VariableSP var_sp) {
+return var_sp->GetName() == name;
+  });
+
+  if (exact_match_it != llvm::adl_end(possible_matches))
+exact_match = *exact_match_it;
+
+  if (!exact_match)
+// Look for a global var exact match.
+for (auto var_sp : possible_matches) {
+  llvm::StringRef str_ref_name = var_sp->GetName().GetStringRef();
+  if (str_ref_name.size() > 2 && str_ref_name[0] == ':' &&
+  str_ref_name[1] == ':')
+str_ref_name = str_ref_name.drop_front(2);
+  ConstString tmp_name(str_ref_name);
+  if (tmp_name == name) {
+exact_match = var_sp;
+break;
+  }
+}
+
+  // Take any match at this point.
+  if (!exact_match && possible_matches.size() > 0)
+exact_match = possible_matches[0];
+
+  return exact_match;
+}
+
+std::unique_ptr
+LookupIdentifier(const std::string &name,
+ std::shared_ptr ctx_scope,
+ lldb::DynamicValueType use_dynamic, CompilerType *scope_ptr) {
+  ConstString name_str(name);
+  llvm::StringRef name_ref = name_str.GetStringRef();
+
+  // Support $rax as a special syntax for accessing registers.
+  // Will return an invalid value in case the requested register doesn't exist.
+  if (name_ref.starts_with("$")) {
+lldb::ValueObjectSP value_sp;
+const char *reg_name = name_ref.drop_front(1).data();
+Target *target = ctx_scope->CalculateTarget().get();
+Process *process = ctx_scope->CalculateProcess().get();
+if (!target || !process)
+  return nullptr;
+
+StackFrame *stack_frame = ctx_scope->CalculateStackFrame().get();
+if (!stack_frame)
+  return nullptr;

labath wrote:

Instead of this, you should pass the stack frame (as ExecutionContextScope) 
directly from `StackFrame::GetValueForVariableExpressionPath`. There's no 
guarantee that the frame you get here will be the same one as you started with.

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


[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)

2025-02-10 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,106 @@
+//===-- DILEval.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_VALUEOBJECT_DILEVAL_H_
+#define LLDB_VALUEOBJECT_DILEVAL_H_
+
+#include "lldb/ValueObject/DILAST.h"
+#include "lldb/ValueObject/DILParser.h"
+#include 
+#include 
+
+namespace lldb_private {
+
+namespace dil {
+
+/// Class used to store & manipulate information about identifiers.
+class IdentifierInfo {
+public:
+  enum class Kind {
+eValue,
+eContextArg,
+  };
+
+  static std::unique_ptr FromValue(ValueObject &valobj) {
+CompilerType type;
+type = valobj.GetCompilerType();
+return std::unique_ptr(
+new IdentifierInfo(Kind::eValue, type, valobj.GetSP(), {}));
+  }
+
+  static std::unique_ptr FromContextArg(CompilerType type) {
+lldb::ValueObjectSP empty_value;
+return std::unique_ptr(
+new IdentifierInfo(Kind::eContextArg, type, empty_value, {}));
+  }
+
+  Kind GetKind() const { return m_kind; }
+  lldb::ValueObjectSP GetValue() const { return m_value; }
+
+  CompilerType GetType() { return m_type; }
+  bool IsValid() const { return m_type.IsValid(); }
+
+  IdentifierInfo(Kind kind, CompilerType type, lldb::ValueObjectSP value,
+ std::vector path)
+  : m_kind(kind), m_type(type), m_value(std::move(value)) {}
+
+private:
+  Kind m_kind;
+  CompilerType m_type;
+  lldb::ValueObjectSP m_value;
+};
+
+/// Given the name of an identifier (variable name, member name, type name,
+/// etc.), find the ValueObject for that name (if it exists) and create and
+/// return an IdentifierInfo object containing all the relevant information
+/// about that object (for DIL parsing and evaluating).
+std::unique_ptr LookupIdentifier(
+const std::string &name, std::shared_ptr ctx_scope,
+lldb::DynamicValueType use_dynamic, CompilerType *scope_ptr = nullptr);
+
+class DILInterpreter : Visitor {
+public:
+  DILInterpreter(lldb::TargetSP target, llvm::StringRef expr,
+ lldb::DynamicValueType use_dynamic,
+ std::shared_ptr exe_ctx_scope);
+
+  llvm::Expected DILEval(const DILASTNode *tree,
+  lldb::TargetSP target_sp);
+
+private:
+  lldb::ValueObjectSP DILEvalNode(const DILASTNode *node);
+
+  bool Success() { return m_error.Success(); }
+
+  void SetError(ErrorCode error_code, std::string error, uint32_t loc);
+
+  void Visit(const ErrorNode *node) override;
+  void Visit(const IdentifierNode *node) override;
+
+private:
+  // Used by the interpreter to create objects, perform casts, etc.
+  lldb::TargetSP m_target;
+
+  llvm::StringRef m_expr;
+
+  lldb::ValueObjectSP m_result;
+
+  lldb::ValueObjectSP m_scope;
+
+  lldb::DynamicValueType m_default_dynamic;
+
+  Status m_error;

labath wrote:

I agree with Adrian here. We'd like to avoid Statuses in new code, and I don't 
think we need one here. The argument about changing the return type in 
uncommitted code doesn't carry much weight with me. I don't think you *need* to 
do it (more on that later), but if you were to do it, here's what I have to say 
about that:

> I would have to do error type conversions in functions where they call 
> something that fails with llvm::expected of type A but the calling function 
> returns llvm::expected of type B

The way you normally do that is
```
if (!expected_a) return expected_a.takeError(); // automatically converted to 
Expected
// Do stuff with `a`
```

> add code to many of these sites to also update the current token to EOF

The existence of the current token is something I want to get rid of anyway, 
but one of the "nice" things about explicitly error passing is that you don't 
have to bother with maintaining state like this. If you return an Error, then 
the caller has to check it, and if all that the caller does is return 
immediately, then it doesn't really matter what's the state of the parser 
object -- the error will be bubbled up to the top of the stack, and nobody will 
touch the parser object.

>  It will actually make the code much messier and more complicated than it is 
> now.

I'm not sure if this is the case here, but I can see how it might be. There are 
situations where it's simpler to "plough ahead" and check for errors later. 
However, I don't think this means you can't use Error/Expected. While it is not 
common to have an Error object as a member, it's not unheard of either. The 
main thing we want to avoid is *long-lived* Error objects with unclear 
*destruction/check semantics*.

Long-livedness isn't really a problem here since the Parser object only exists 
while the expression is being parsed. That may be longer than usual bu

[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)

2025-02-10 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,284 @@
+//===-- DILEval.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/ValueObject/DILEval.h"
+#include "lldb/Symbol/VariableList.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/ValueObject/DILAST.h"
+#include "lldb/ValueObject/ValueObject.h"
+#include "lldb/ValueObject/ValueObjectRegister.h"
+#include "lldb/ValueObject/ValueObjectVariable.h"
+#include "llvm/Support/FormatAdapters.h"
+#include 
+
+namespace lldb_private::dil {
+
+static lldb::ValueObjectSP
+LookupStaticIdentifier(lldb::TargetSP target_sp,
+   const llvm::StringRef &name_ref,

labath wrote:

StringRef is normally passed [by 
value](https://llvm.org/docs/ProgrammersManual.html#the-stringref-class)

```suggestion
   llvm::StringRef name_ref,
```

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


[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)

2025-02-10 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)

2025-02-10 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,308 @@
+//===-- DILParser.cpp 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This implements the recursive descent parser for the Data Inspection
+// Language (DIL), and its helper functions, which will eventually underlie the
+// 'frame variable' command. The language that this parser recognizes is
+// described in lldb/docs/dil-expr-lang.ebnf
+//
+//===--===//
+
+#include "lldb/ValueObject/DILParser.h"
+#include "lldb/Target/ExecutionContextScope.h"
+#include "lldb/ValueObject/DILAST.h"
+#include "lldb/ValueObject/DILEval.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FormatAdapters.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+
+namespace lldb_private::dil {
+
+inline void TokenKindsJoinImpl(std::ostringstream &os, Token::Kind k) {
+  os << "'" << Token::GetTokenName(k).str() << "'";
+}
+
+template 
+inline void TokenKindsJoinImpl(std::ostringstream &os, Token::Kind k,
+   Ts... ks) {
+  TokenKindsJoinImpl(os, k);
+  os << ", ";
+  TokenKindsJoinImpl(os, ks...);
+}
+
+template 
+inline std::string TokenKindsJoin(Token::Kind k, Ts... ks) {
+  std::ostringstream os;
+  TokenKindsJoinImpl(os, k, ks...);
+
+  return os.str();
+}
+
+std::string FormatDiagnostics(llvm::StringRef text, const std::string &message,
+  uint32_t loc) {
+  // Get the source buffer and the location of the current token.
+  size_t loc_offset = (size_t)loc;
+
+  // Look for the start of the line.
+  size_t line_start = text.rfind('\n', loc_offset);
+  line_start = line_start == llvm::StringRef::npos ? 0 : line_start + 1;
+
+  // Look for the end of the line.
+  size_t line_end = text.find('\n', loc_offset);
+  line_end = line_end == llvm::StringRef::npos ? text.size() : line_end;
+

labath wrote:

This is unnecessary, `slice(something, npos)` works fine

```suggestion

```

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


[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)

2025-02-10 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,284 @@
+//===-- DILEval.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/ValueObject/DILEval.h"
+#include "lldb/Symbol/VariableList.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/ValueObject/DILAST.h"
+#include "lldb/ValueObject/ValueObject.h"
+#include "lldb/ValueObject/ValueObjectRegister.h"
+#include "lldb/ValueObject/ValueObjectVariable.h"
+#include "llvm/Support/FormatAdapters.h"
+#include 
+
+namespace lldb_private::dil {
+
+static lldb::ValueObjectSP
+LookupStaticIdentifier(lldb::TargetSP target_sp,
+   const llvm::StringRef &name_ref,
+   ConstString unqualified_name) {
+  // List global variable with the same "basename". There can be many matches
+  // from other scopes (namespaces, classes), so we do additional filtering
+  // later.
+  VariableList variable_list;
+  ConstString name(name_ref);
+  target_sp->GetImages().FindGlobalVariables(name, 1, variable_list);
+  if (variable_list.Empty())
+return nullptr;
+
+  ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
+  if (exe_scope == nullptr)
+exe_scope = target_sp.get();
+  for (const lldb::VariableSP &var_sp : variable_list) {
+lldb::ValueObjectSP valobj_sp(
+ValueObjectVariable::Create(exe_scope, var_sp));
+if (valobj_sp && valobj_sp->GetVariable() &&
+(valobj_sp->GetVariable()->NameMatches(unqualified_name) ||
+ valobj_sp->GetVariable()->NameMatches(ConstString(name_ref
+  return valobj_sp;
+  }
+
+  return nullptr;
+}
+
+static lldb::VariableSP DILFindVariable(ConstString name,
+VariableList *variable_list) {
+  lldb::VariableSP exact_match;
+  std::vector possible_matches;
+
+  typedef std::vector collection;
+  typedef collection::iterator iterator;
+
+  iterator pos, end = variable_list->end();
+  for (pos = variable_list->begin(); pos != end; ++pos) {
+llvm::StringRef str_ref_name = pos->get()->GetName().GetStringRef();
+// Check for global vars, which might start with '::'.
+str_ref_name.consume_front("::");
+
+if (str_ref_name == name.GetStringRef())
+  possible_matches.push_back(*pos);
+else if (pos->get()->NameMatches(name))
+  possible_matches.push_back(*pos);
+  }
+
+  // Look for exact matches (favors local vars over global vars)
+  auto exact_match_it =
+  llvm::find_if(possible_matches, [&](lldb::VariableSP var_sp) {
+return var_sp->GetName() == name;
+  });
+
+  if (exact_match_it != llvm::adl_end(possible_matches))
+exact_match = *exact_match_it;
+
+  if (!exact_match)
+// Look for a global var exact match.
+for (auto var_sp : possible_matches) {
+  llvm::StringRef str_ref_name = var_sp->GetName().GetStringRef();
+  if (str_ref_name.size() > 2 && str_ref_name[0] == ':' &&
+  str_ref_name[1] == ':')
+str_ref_name = str_ref_name.drop_front(2);
+  ConstString tmp_name(str_ref_name);
+  if (tmp_name == name) {

labath wrote:

This is shorter, faster, and doesn't pollute the global string pool.

```suggestion
  if (str_ref_name == name.GetStringRef()) {
```

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


[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)

2025-02-10 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,308 @@
+//===-- DILParser.cpp 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This implements the recursive descent parser for the Data Inspection
+// Language (DIL), and its helper functions, which will eventually underlie the
+// 'frame variable' command. The language that this parser recognizes is
+// described in lldb/docs/dil-expr-lang.ebnf
+//
+//===--===//
+
+#include "lldb/ValueObject/DILParser.h"
+#include "lldb/Target/ExecutionContextScope.h"
+#include "lldb/ValueObject/DILAST.h"
+#include "lldb/ValueObject/DILEval.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FormatAdapters.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+
+namespace lldb_private::dil {
+
+inline void TokenKindsJoinImpl(std::ostringstream &os, Token::Kind k) {
+  os << "'" << Token::GetTokenName(k).str() << "'";
+}
+
+template 
+inline void TokenKindsJoinImpl(std::ostringstream &os, Token::Kind k,
+   Ts... ks) {
+  TokenKindsJoinImpl(os, k);
+  os << ", ";
+  TokenKindsJoinImpl(os, ks...);
+}
+
+template 
+inline std::string TokenKindsJoin(Token::Kind k, Ts... ks) {
+  std::ostringstream os;
+  TokenKindsJoinImpl(os, k, ks...);
+
+  return os.str();
+}
+
+std::string FormatDiagnostics(llvm::StringRef text, const std::string &message,
+  uint32_t loc) {
+  // Get the source buffer and the location of the current token.
+  size_t loc_offset = (size_t)loc;
+
+  // Look for the start of the line.
+  size_t line_start = text.rfind('\n', loc_offset);
+  line_start = line_start == llvm::StringRef::npos ? 0 : line_start + 1;
+
+  // Look for the end of the line.
+  size_t line_end = text.find('\n', loc_offset);
+  line_end = line_end == llvm::StringRef::npos ? text.size() : line_end;
+
+  // Get a view of the current line in the source code and the position of the
+  // diagnostics pointer.
+  llvm::StringRef line = text.slice(line_start, line_end);
+  int32_t arrow = loc + 1; // Column offset starts at 1, not 0.
+
+  // Calculate the padding in case we point outside of the expression (this can
+  // happen if the parser expected something, but got EOF).˚
+  size_t expr_rpad = std::max(0, arrow - static_cast(line.size()));
+  size_t arrow_rpad = std::max(0, static_cast(line.size()) - arrow);
+
+  return llvm::formatv(": {1}\n{2}\n{3}", loc, message,
+   llvm::fmt_pad(line, 0, expr_rpad),
+   llvm::fmt_pad("^", arrow - 1, arrow_rpad));
+}
+
+DILParser::DILParser(llvm::StringRef dil_input_expr, DILLexer lexer,
+ std::shared_ptr exe_ctx_scope,
+ lldb::DynamicValueType use_dynamic, bool use_synthetic,
+ bool fragile_ivar, bool check_ptr_vs_member)
+: m_ctx_scope(exe_ctx_scope), m_input_expr(dil_input_expr),
+  m_dil_lexer(lexer), m_dil_token(lexer.GetCurrentToken()),
+  m_use_dynamic(use_dynamic), m_use_synthetic(use_synthetic),
+  m_fragile_ivar(fragile_ivar), m_check_ptr_vs_member(check_ptr_vs_member) 
{
+}
+
+llvm::Expected DILParser::Run() {
+  DILASTNodeUP expr;
+
+  expr = ParseExpression();
+
+  Expect(Token::Kind::eof);
+
+  if (m_error.Fail())
+return m_error.ToError();
+
+  return expr;
+}
+
+// Parse an expression.
+//
+//  expression:
+//primary_expression
+//
+DILASTNodeUP DILParser::ParseExpression() { return ParsePrimaryExpression(); }
+
+// Parse a primary_expression.
+//
+//  primary_expression:
+//id_expression
+//"this"
+//"(" expression ")"
+//
+DILASTNodeUP DILParser::ParsePrimaryExpression() {
+  if (m_dil_token.IsOneOf(Token::coloncolon, Token::identifier)) {
+// Save the source location for the diagnostics message.
+uint32_t loc = m_dil_token.GetLocation();
+auto identifier = ParseIdExpression();
+
+return std::make_unique(loc, identifier, m_use_dynamic,
+m_ctx_scope);
+  } else if (m_dil_token.Is(Token::l_paren)) {
+ConsumeToken();
+auto expr = ParseExpression();
+Expect(Token::r_paren);
+ConsumeToken();
+return expr;
+  }
+
+  BailOut(ErrorCode::kInvalidExpressionSyntax,
+  llvm::formatv("Unexpected token: {0}", 
TokenDescription(m_dil_token)),
+  m_dil_token.GetLocation());
+  return std::make_unique();
+}
+
+// Parse nested_name_specifier.
+//
+//  nested_name_specifier:
+//type_name "::"
+//namespace_name "::"
+//nested_name_specifier identifier "::"
+//
+std::string DILParser::ParseNestedNameSpecifier() {
+  // The first token in nested_name_specifier is always an identifier, or
+  // '(anonymous namespace)'.
+  if (m_dil_token.IsNot(Token::identifier) &&
+  m_dil_toke

[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)

2025-02-10 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,284 @@
+//===-- DILEval.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/ValueObject/DILEval.h"
+#include "lldb/Symbol/VariableList.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/ValueObject/DILAST.h"
+#include "lldb/ValueObject/ValueObject.h"
+#include "lldb/ValueObject/ValueObjectRegister.h"
+#include "lldb/ValueObject/ValueObjectVariable.h"
+#include "llvm/Support/FormatAdapters.h"
+#include 
+
+namespace lldb_private::dil {
+
+static lldb::ValueObjectSP
+LookupStaticIdentifier(lldb::TargetSP target_sp,
+   const llvm::StringRef &name_ref,
+   ConstString unqualified_name) {
+  // List global variable with the same "basename". There can be many matches
+  // from other scopes (namespaces, classes), so we do additional filtering
+  // later.
+  VariableList variable_list;
+  ConstString name(name_ref);
+  target_sp->GetImages().FindGlobalVariables(name, 1, variable_list);
+  if (variable_list.Empty())
+return nullptr;
+
+  ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
+  if (exe_scope == nullptr)
+exe_scope = target_sp.get();
+  for (const lldb::VariableSP &var_sp : variable_list) {
+lldb::ValueObjectSP valobj_sp(
+ValueObjectVariable::Create(exe_scope, var_sp));
+if (valobj_sp && valobj_sp->GetVariable() &&
+(valobj_sp->GetVariable()->NameMatches(unqualified_name) ||
+ valobj_sp->GetVariable()->NameMatches(ConstString(name_ref
+  return valobj_sp;
+  }
+
+  return nullptr;
+}
+
+static lldb::VariableSP DILFindVariable(ConstString name,
+VariableList *variable_list) {
+  lldb::VariableSP exact_match;
+  std::vector possible_matches;
+
+  typedef std::vector collection;
+  typedef collection::iterator iterator;
+
+  iterator pos, end = variable_list->end();
+  for (pos = variable_list->begin(); pos != end; ++pos) {
+llvm::StringRef str_ref_name = pos->get()->GetName().GetStringRef();
+// Check for global vars, which might start with '::'.
+str_ref_name.consume_front("::");
+
+if (str_ref_name == name.GetStringRef())
+  possible_matches.push_back(*pos);
+else if (pos->get()->NameMatches(name))
+  possible_matches.push_back(*pos);
+  }
+
+  // Look for exact matches (favors local vars over global vars)
+  auto exact_match_it =
+  llvm::find_if(possible_matches, [&](lldb::VariableSP var_sp) {
+return var_sp->GetName() == name;
+  });
+
+  if (exact_match_it != llvm::adl_end(possible_matches))
+exact_match = *exact_match_it;
+
+  if (!exact_match)
+// Look for a global var exact match.
+for (auto var_sp : possible_matches) {
+  llvm::StringRef str_ref_name = var_sp->GetName().GetStringRef();
+  if (str_ref_name.size() > 2 && str_ref_name[0] == ':' &&
+  str_ref_name[1] == ':')
+str_ref_name = str_ref_name.drop_front(2);
+  ConstString tmp_name(str_ref_name);
+  if (tmp_name == name) {
+exact_match = var_sp;
+break;
+  }
+}
+
+  // Take any match at this point.
+  if (!exact_match && possible_matches.size() > 0)
+exact_match = possible_matches[0];
+
+  return exact_match;
+}
+
+std::unique_ptr
+LookupIdentifier(const std::string &name,
+ std::shared_ptr ctx_scope,
+ lldb::DynamicValueType use_dynamic, CompilerType *scope_ptr) {
+  ConstString name_str(name);
+  llvm::StringRef name_ref = name_str.GetStringRef();
+
+  // Support $rax as a special syntax for accessing registers.
+  // Will return an invalid value in case the requested register doesn't exist.
+  if (name_ref.starts_with("$")) {
+lldb::ValueObjectSP value_sp;
+const char *reg_name = name_ref.drop_front(1).data();
+Target *target = ctx_scope->CalculateTarget().get();
+Process *process = ctx_scope->CalculateProcess().get();
+if (!target || !process)
+  return nullptr;
+
+StackFrame *stack_frame = ctx_scope->CalculateStackFrame().get();
+if (!stack_frame)
+  return nullptr;
+
+lldb::RegisterContextSP reg_ctx(stack_frame->GetRegisterContext());
+if (!reg_ctx)
+  return nullptr;
+
+if (const RegisterInfo *reg_info = 
reg_ctx->GetRegisterInfoByName(reg_name))
+  value_sp = ValueObjectRegister::Create(stack_frame, reg_ctx, reg_info);
+
+if (value_sp)
+  return IdentifierInfo::FromValue(*value_sp);
+
+return nullptr;
+  }
+
+  // Internally values don't have global scope qualifier in their names and
+  // LLDB doesn't support queries with it too.
+  bool global_scope = false;
+  if (name_ref.starts_with("::")) {
+name_ref = na

[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)

2025-02-10 Thread Pavel Labath via lldb-commits


@@ -511,22 +514,57 @@ ValueObjectSP 
StackFrame::GetValueForVariableExpressionPath(
 VariableSP &var_sp, Status &error) {
   ExecutionContext exe_ctx;
   CalculateExecutionContext(exe_ctx);
+
   bool use_DIL = exe_ctx.GetTargetRef().GetUseDIL(&exe_ctx);
+
   if (use_DIL)
 return DILGetValueForVariableExpressionPath(var_expr, use_dynamic, options,
 var_sp, error);
-
-  return LegacyGetValueForVariableExpressionPath(var_expr, use_dynamic, 
options,
- var_sp, error);
+  else
+return LegacyGetValueForVariableExpressionPath(var_expr, use_dynamic,
+   options, var_sp, error);
 }
 
 ValueObjectSP StackFrame::DILGetValueForVariableExpressionPath(
 llvm::StringRef var_expr, lldb::DynamicValueType use_dynamic,
 uint32_t options, lldb::VariableSP &var_sp, Status &error) {
-  // This is a place-holder for the calls into the DIL parser and
-  // evaluator.  For now, just call the "real" frame variable implementation.
-  return LegacyGetValueForVariableExpressionPath(var_expr, use_dynamic, 
options,
- var_sp, error);
+
+  const bool check_ptr_vs_member =
+  (options & eExpressionPathOptionCheckPtrVsMember) != 0;
+  const bool no_fragile_ivar =
+  (options & eExpressionPathOptionsNoFragileObjcIvar) != 0;
+  const bool no_synth_child =
+  (options & eExpressionPathOptionsNoSyntheticChildren) != 0;
+
+  // Lex the expression.
+  auto lex_or_err = dil::DILLexer::Create(var_expr);
+  if (!lex_or_err) {
+error = Status::FromError(lex_or_err.takeError());
+return ValueObjectSP();
+  }
+  dil::DILLexer lexer = *lex_or_err;

labath wrote:

No need for a copy here.

```suggestion
  dil::DILLexer &lexer = *lex_or_err;
```

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


[Lldb-commits] [lldb] [llvm] [lldb-dap] Support column breakpoints (PR #125347)

2025-02-10 Thread LLVM Continuous Integration via lldb-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`openmp-offload-libc-amdgpu-runtime` running on `omp-vega20-1` while building 
`lldb,llvm` at step 7 "Add check check-offload".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/73/builds/12955


Here is the relevant piece of the build log for the reference

```
Step 7 (Add check check-offload) failure: test (failure)
 TEST 'libomptarget :: amdgcn-amd-amdhsa :: 
api/omp_host_call.c' FAILED 
Exit Code: 2

Command Output (stdout):
--
# RUN: at line 1
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang 
-fopenmp-I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test 
-I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -L 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib -L 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
  -nogpulib 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib
  -fopenmp-targets=amdgcn-amd-amdhsa 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/api/omp_host_call.c
 -o 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/api/Output/omp_host_call.c.tmp
 -Xoffload-linker -lc -Xoffload-linker -lm 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a
 && 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/api/Output/omp_host_call.c.tmp
 | 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/FileCheck
 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/api/omp_host_call.c
# executed command: 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang 
-fopenmp -I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test 
-I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -L 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib -L 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -nogpulib 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib
 -fopenmp-targets=amdgcn-amd-amdhsa 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/api/omp_host_call.c
 -o 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/api/Output/omp_host_call.c.tmp
 -Xoffload-linker -lc -Xoffload-linker -lm 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a
# executed command: 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/api/Output/omp_host_call.c.tmp
# note: command had no output on stdout or stderr
# error: command failed with exit status: -11
# executed command: 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/FileCheck
 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/api/omp_host_call.c
# .---command stderr
# | FileCheck error: '' is empty.
# | FileCheck command line:  
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/FileCheck
 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/api/omp_host_call.c
# `-
# error: command failed with exit status: 2

--




```



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


[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)

2025-02-10 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,284 @@
+//===-- DILEval.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/ValueObject/DILEval.h"
+#include "lldb/Symbol/VariableList.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/ValueObject/DILAST.h"
+#include "lldb/ValueObject/ValueObject.h"
+#include "lldb/ValueObject/ValueObjectRegister.h"
+#include "lldb/ValueObject/ValueObjectVariable.h"
+#include "llvm/Support/FormatAdapters.h"
+#include 
+
+namespace lldb_private::dil {
+
+static lldb::ValueObjectSP
+LookupStaticIdentifier(lldb::TargetSP target_sp,
+   const llvm::StringRef &name_ref,
+   ConstString unqualified_name) {
+  // List global variable with the same "basename". There can be many matches
+  // from other scopes (namespaces, classes), so we do additional filtering
+  // later.
+  VariableList variable_list;
+  ConstString name(name_ref);
+  target_sp->GetImages().FindGlobalVariables(name, 1, variable_list);
+  if (variable_list.Empty())
+return nullptr;
+
+  ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
+  if (exe_scope == nullptr)
+exe_scope = target_sp.get();
+  for (const lldb::VariableSP &var_sp : variable_list) {
+lldb::ValueObjectSP valobj_sp(
+ValueObjectVariable::Create(exe_scope, var_sp));
+if (valobj_sp && valobj_sp->GetVariable() &&
+(valobj_sp->GetVariable()->NameMatches(unqualified_name) ||
+ valobj_sp->GetVariable()->NameMatches(ConstString(name_ref
+  return valobj_sp;
+  }
+
+  return nullptr;
+}
+
+static lldb::VariableSP DILFindVariable(ConstString name,
+VariableList *variable_list) {
+  lldb::VariableSP exact_match;
+  std::vector possible_matches;
+
+  typedef std::vector collection;
+  typedef collection::iterator iterator;
+
+  iterator pos, end = variable_list->end();
+  for (pos = variable_list->begin(); pos != end; ++pos) {
+llvm::StringRef str_ref_name = pos->get()->GetName().GetStringRef();
+// Check for global vars, which might start with '::'.
+str_ref_name.consume_front("::");
+
+if (str_ref_name == name.GetStringRef())
+  possible_matches.push_back(*pos);
+else if (pos->get()->NameMatches(name))
+  possible_matches.push_back(*pos);
+  }
+
+  // Look for exact matches (favors local vars over global vars)
+  auto exact_match_it =
+  llvm::find_if(possible_matches, [&](lldb::VariableSP var_sp) {
+return var_sp->GetName() == name;
+  });
+
+  if (exact_match_it != llvm::adl_end(possible_matches))
+exact_match = *exact_match_it;
+
+  if (!exact_match)
+// Look for a global var exact match.
+for (auto var_sp : possible_matches) {
+  llvm::StringRef str_ref_name = var_sp->GetName().GetStringRef();
+  if (str_ref_name.size() > 2 && str_ref_name[0] == ':' &&
+  str_ref_name[1] == ':')
+str_ref_name = str_ref_name.drop_front(2);
+  ConstString tmp_name(str_ref_name);
+  if (tmp_name == name) {
+exact_match = var_sp;
+break;
+  }
+}
+
+  // Take any match at this point.
+  if (!exact_match && possible_matches.size() > 0)
+exact_match = possible_matches[0];
+
+  return exact_match;
+}
+
+std::unique_ptr
+LookupIdentifier(const std::string &name,
+ std::shared_ptr ctx_scope,
+ lldb::DynamicValueType use_dynamic, CompilerType *scope_ptr) {
+  ConstString name_str(name);
+  llvm::StringRef name_ref = name_str.GetStringRef();
+
+  // Support $rax as a special syntax for accessing registers.
+  // Will return an invalid value in case the requested register doesn't exist.
+  if (name_ref.starts_with("$")) {
+lldb::ValueObjectSP value_sp;
+const char *reg_name = name_ref.drop_front(1).data();

labath wrote:

```suggestion
  if (name.consume_front("$")) {
lldb::ValueObjectSP value_sp;
```

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


[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)

2025-02-10 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,284 @@
+//===-- DILEval.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/ValueObject/DILEval.h"
+#include "lldb/Symbol/VariableList.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/ValueObject/DILAST.h"
+#include "lldb/ValueObject/ValueObject.h"
+#include "lldb/ValueObject/ValueObjectRegister.h"
+#include "lldb/ValueObject/ValueObjectVariable.h"
+#include "llvm/Support/FormatAdapters.h"
+#include 
+
+namespace lldb_private::dil {
+
+static lldb::ValueObjectSP
+LookupStaticIdentifier(lldb::TargetSP target_sp,
+   const llvm::StringRef &name_ref,
+   ConstString unqualified_name) {
+  // List global variable with the same "basename". There can be many matches
+  // from other scopes (namespaces, classes), so we do additional filtering
+  // later.
+  VariableList variable_list;
+  ConstString name(name_ref);
+  target_sp->GetImages().FindGlobalVariables(name, 1, variable_list);
+  if (variable_list.Empty())
+return nullptr;
+
+  ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
+  if (exe_scope == nullptr)
+exe_scope = target_sp.get();
+  for (const lldb::VariableSP &var_sp : variable_list) {
+lldb::ValueObjectSP valobj_sp(
+ValueObjectVariable::Create(exe_scope, var_sp));
+if (valobj_sp && valobj_sp->GetVariable() &&
+(valobj_sp->GetVariable()->NameMatches(unqualified_name) ||
+ valobj_sp->GetVariable()->NameMatches(ConstString(name_ref
+  return valobj_sp;
+  }
+
+  return nullptr;
+}
+
+static lldb::VariableSP DILFindVariable(ConstString name,
+VariableList *variable_list) {
+  lldb::VariableSP exact_match;
+  std::vector possible_matches;
+
+  typedef std::vector collection;
+  typedef collection::iterator iterator;
+
+  iterator pos, end = variable_list->end();
+  for (pos = variable_list->begin(); pos != end; ++pos) {
+llvm::StringRef str_ref_name = pos->get()->GetName().GetStringRef();
+// Check for global vars, which might start with '::'.
+str_ref_name.consume_front("::");
+
+if (str_ref_name == name.GetStringRef())
+  possible_matches.push_back(*pos);
+else if (pos->get()->NameMatches(name))
+  possible_matches.push_back(*pos);
+  }
+
+  // Look for exact matches (favors local vars over global vars)
+  auto exact_match_it =
+  llvm::find_if(possible_matches, [&](lldb::VariableSP var_sp) {
+return var_sp->GetName() == name;
+  });
+
+  if (exact_match_it != llvm::adl_end(possible_matches))
+exact_match = *exact_match_it;
+
+  if (!exact_match)
+// Look for a global var exact match.
+for (auto var_sp : possible_matches) {
+  llvm::StringRef str_ref_name = var_sp->GetName().GetStringRef();
+  if (str_ref_name.size() > 2 && str_ref_name[0] == ':' &&
+  str_ref_name[1] == ':')
+str_ref_name = str_ref_name.drop_front(2);
+  ConstString tmp_name(str_ref_name);
+  if (tmp_name == name) {
+exact_match = var_sp;
+break;
+  }
+}
+
+  // Take any match at this point.
+  if (!exact_match && possible_matches.size() > 0)
+exact_match = possible_matches[0];
+
+  return exact_match;
+}
+
+std::unique_ptr
+LookupIdentifier(const std::string &name,
+ std::shared_ptr ctx_scope,
+ lldb::DynamicValueType use_dynamic, CompilerType *scope_ptr) {
+  ConstString name_str(name);
+  llvm::StringRef name_ref = name_str.GetStringRef();

labath wrote:

Let's not have three variables for the same string. ConstString construction is 
relatively expensive, so construct it only on the code paths where it's 
actually needed.
```suggestion
LookupIdentifier(llvm::StringRef name,
 std::shared_ptr ctx_scope,
 lldb::DynamicValueType use_dynamic, CompilerType *scope_ptr) {
```

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


[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)

2025-02-10 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,308 @@
+//===-- DILParser.cpp 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This implements the recursive descent parser for the Data Inspection
+// Language (DIL), and its helper functions, which will eventually underlie the
+// 'frame variable' command. The language that this parser recognizes is
+// described in lldb/docs/dil-expr-lang.ebnf
+//
+//===--===//
+
+#include "lldb/ValueObject/DILParser.h"
+#include "lldb/Target/ExecutionContextScope.h"
+#include "lldb/ValueObject/DILAST.h"
+#include "lldb/ValueObject/DILEval.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FormatAdapters.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+
+namespace lldb_private::dil {
+
+inline void TokenKindsJoinImpl(std::ostringstream &os, Token::Kind k) {
+  os << "'" << Token::GetTokenName(k).str() << "'";
+}
+
+template 
+inline void TokenKindsJoinImpl(std::ostringstream &os, Token::Kind k,
+   Ts... ks) {
+  TokenKindsJoinImpl(os, k);
+  os << ", ";
+  TokenKindsJoinImpl(os, ks...);
+}
+
+template 
+inline std::string TokenKindsJoin(Token::Kind k, Ts... ks) {
+  std::ostringstream os;
+  TokenKindsJoinImpl(os, k, ks...);
+
+  return os.str();
+}
+
+std::string FormatDiagnostics(llvm::StringRef text, const std::string &message,
+  uint32_t loc) {
+  // Get the source buffer and the location of the current token.
+  size_t loc_offset = (size_t)loc;
+
+  // Look for the start of the line.
+  size_t line_start = text.rfind('\n', loc_offset);
+  line_start = line_start == llvm::StringRef::npos ? 0 : line_start + 1;
+
+  // Look for the end of the line.
+  size_t line_end = text.find('\n', loc_offset);
+  line_end = line_end == llvm::StringRef::npos ? text.size() : line_end;
+
+  // Get a view of the current line in the source code and the position of the
+  // diagnostics pointer.
+  llvm::StringRef line = text.slice(line_start, line_end);
+  int32_t arrow = loc + 1; // Column offset starts at 1, not 0.
+
+  // Calculate the padding in case we point outside of the expression (this can
+  // happen if the parser expected something, but got EOF).˚
+  size_t expr_rpad = std::max(0, arrow - static_cast(line.size()));
+  size_t arrow_rpad = std::max(0, static_cast(line.size()) - arrow);
+
+  return llvm::formatv(": {1}\n{2}\n{3}", loc, message,
+   llvm::fmt_pad(line, 0, expr_rpad),
+   llvm::fmt_pad("^", arrow - 1, arrow_rpad));
+}
+
+DILParser::DILParser(llvm::StringRef dil_input_expr, DILLexer lexer,
+ std::shared_ptr exe_ctx_scope,
+ lldb::DynamicValueType use_dynamic, bool use_synthetic,
+ bool fragile_ivar, bool check_ptr_vs_member)
+: m_ctx_scope(exe_ctx_scope), m_input_expr(dil_input_expr),
+  m_dil_lexer(lexer), m_dil_token(lexer.GetCurrentToken()),
+  m_use_dynamic(use_dynamic), m_use_synthetic(use_synthetic),
+  m_fragile_ivar(fragile_ivar), m_check_ptr_vs_member(check_ptr_vs_member) 
{
+}
+
+llvm::Expected DILParser::Run() {
+  DILASTNodeUP expr;
+
+  expr = ParseExpression();
+
+  Expect(Token::Kind::eof);
+
+  if (m_error.Fail())
+return m_error.ToError();
+
+  return expr;
+}
+
+// Parse an expression.
+//
+//  expression:
+//primary_expression
+//
+DILASTNodeUP DILParser::ParseExpression() { return ParsePrimaryExpression(); }
+
+// Parse a primary_expression.
+//
+//  primary_expression:
+//id_expression
+//"this"

labath wrote:

no this

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


[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)

2025-02-10 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Adjust the for loop condition to prevent unintended increments in ExpandRLE (NFC) (PR #94844)

2025-02-10 Thread Shivam Gupta via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Adjust the for loop condition to prevent unintended increments in ExpandRLE (NFC) (PR #94844)

2025-02-10 Thread Shivam Gupta via lldb-commits

xgupta wrote:

Could not understand the right fix. Better it to leave it.

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


[Lldb-commits] [clang] [libc] [libcxx] [lldb] [llvm] [doc] Add Discord invite link alongside channel links (PR #126352)

2025-02-10 Thread David Spickett via lldb-commits

DavidSpickett wrote:

I also looked at this but got into a rabbit hole finding out whether you could 
have channel specific invites. I think you can, but I don't think it actually 
helps us. As the other problem we have had is invites expiring, so the fewer 
unique invite links the better.

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


[Lldb-commits] [lldb] [lldb] Support disassembling discontinuous functions (PR #126505)

2025-02-10 Thread Pavel Labath via lldb-commits


@@ -262,9 +269,11 @@ CommandObjectDisassemble::GetContainingAddressRanges() {
 addr, eSymbolContextEverything, sc, resolve_tail_call_address);
 if (sc.function || sc.symbol) {
   AddressRange range;
-  sc.GetAddressRange(eSymbolContextFunction | eSymbolContextSymbol, 0,
- false, range);
-  ranges.push_back(range);
+  for (uint32_t idx = 0;
+   sc.GetAddressRange(eSymbolContextFunction | eSymbolContextSymbol,
+  idx, false, range);
+   ++idx)
+ranges.push_back(range);
 }

labath wrote:

I'm not sure what you mean. Can you elaborate?

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


[Lldb-commits] [lldb] [lldb] Support disassembling discontinuous functions (PR #126505)

2025-02-10 Thread Pavel Labath via lldb-commits


@@ -82,20 +82,25 @@
 # CHECK-NEXT: (lldb) disassemble --name case2
 # CHECK-NEXT: command-disassemble.s.tmp`n1::case2:
 # CHECK-NEXT: command-disassemble.s.tmp[0x2044] <+0>: int$0x32
-# CHECK-NEXT: warning: Not disassembling a range because it is very large 
[0x2046-0x4046). To disassemble specify an instruction 
count limit, start/stop addresses or use the --force option.
+# CHECK-NEXT: warning: Not disassembling a function because it is very large 
[0x2046-0x4046). To disassemble specify an instruction 
count limit, start/stop addresses or use the --force option.
 # CHECK-NEXT: (lldb) disassemble --name case3
-# CHECK-NEXT: error: Not disassembling a range because it is very large 
[0x4046-0x6046). To disassemble specify an instruction 
count limit, start/stop addresses or use the --force option.
-# CHECK-NEXT: Not disassembling a range because it is very large 
[0x6046-0x8046). To disassemble specify an instruction 
count limit, start/stop addresses or use the --force option.
+# CHECK-NEXT: error: Not disassembling a function because it is very large 
[0x6046-0x7046)[0x9046-0xa046). 
To disassemble specify an instruction count limit, start/stop addresses or use 
the --force option.

labath wrote:

Currently it will print  `limit` instructions from every range (this is shown 
in the next test case, line 89). This is mainly a side-effect of the fact that 
we don't make much of a difference between two ranges belonging to the same 
function and two ranges from two different functions, but maybe it also kind of 
slightly makes sense? At least it avoids us needing to worry about which range 
will contain the entry point (the ranges are sorted so it might not be the 
first one)

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


[Lldb-commits] [lldb] [lldb] Support disassembling discontinuous functions (PR #126505)

2025-02-10 Thread David Spickett via lldb-commits


@@ -82,20 +82,25 @@
 # CHECK-NEXT: (lldb) disassemble --name case2
 # CHECK-NEXT: command-disassemble.s.tmp`n1::case2:
 # CHECK-NEXT: command-disassemble.s.tmp[0x2044] <+0>: int$0x32
-# CHECK-NEXT: warning: Not disassembling a range because it is very large 
[0x2046-0x4046). To disassemble specify an instruction 
count limit, start/stop addresses or use the --force option.
+# CHECK-NEXT: warning: Not disassembling a function because it is very large 
[0x2046-0x4046). To disassemble specify an instruction 
count limit, start/stop addresses or use the --force option.
 # CHECK-NEXT: (lldb) disassemble --name case3
-# CHECK-NEXT: error: Not disassembling a range because it is very large 
[0x4046-0x6046). To disassemble specify an instruction 
count limit, start/stop addresses or use the --force option.
-# CHECK-NEXT: Not disassembling a range because it is very large 
[0x6046-0x8046). To disassemble specify an instruction 
count limit, start/stop addresses or use the --force option.
+# CHECK-NEXT: error: Not disassembling a function because it is very large 
[0x6046-0x7046)[0x9046-0xa046). 
To disassemble specify an instruction count limit, start/stop addresses or use 
the --force option.

DavidSpickett wrote:

If you specify a limit does it start from the lowest address of the function or 
the entry point. I'd guess lowest address, because there's no way to say "100 
forward and 100 backwards".

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


[Lldb-commits] [lldb] [lldb] Support disassembling discontinuous functions (PR #126505)

2025-02-10 Thread Pavel Labath via lldb-commits

https://github.com/labath created 
https://github.com/llvm/llvm-project/pull/126505

The command already supported disassembling multiple ranges, among other 
reasons because inline functions can be discontinuous. The main thing that was 
missing was being able to retrieve the function ranges from the top level 
function object.

The output of the command for the case where the function entry point is not 
its lowest address is somewhat confusing (we're showing negative offsets), but 
it is correct.

>From 96957acfb6847343df50a641c6de03199c924f72 Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Thu, 9 Jan 2025 13:02:24 +0100
Subject: [PATCH] [lldb] Support disassembling discontinuous functions

The command already supported disassembling multiple ranges, among other
reasons because inline functions can be discontinuous. The main thing
that was missing was being able to retrieve the function ranges from the
top level function object.

The output of the command for the case where the function entry point is
not its lowest address is somewhat confusing (we're showing negative
offsets), but it is correct.
---
 .../Commands/CommandObjectDisassemble.cpp |  88 +++---
 .../Commands/CommandObjectDisassemble.h   |   3 +-
 lldb/source/Symbol/SymbolContext.cpp  |   4 +-
 .../test/Shell/Commands/command-disassemble.s | 112 --
 4 files changed, 154 insertions(+), 53 deletions(-)

diff --git a/lldb/source/Commands/CommandObjectDisassemble.cpp 
b/lldb/source/Commands/CommandObjectDisassemble.cpp
index 5b131fe86dedbae..d116188966daa49 100644
--- a/lldb/source/Commands/CommandObjectDisassemble.cpp
+++ b/lldb/source/Commands/CommandObjectDisassemble.cpp
@@ -21,6 +21,7 @@
 #include "lldb/Target/SectionLoadList.h"
 #include "lldb/Target/StackFrame.h"
 #include "lldb/Target/Target.h"
+#include 
 
 static constexpr unsigned default_disasm_byte_size = 32;
 static constexpr unsigned default_disasm_num_ins = 4;
@@ -236,19 +237,25 @@ CommandObjectDisassemble::CommandObjectDisassemble(
 
 CommandObjectDisassemble::~CommandObjectDisassemble() = default;
 
-llvm::Error CommandObjectDisassemble::CheckRangeSize(const AddressRange &range,
- llvm::StringRef what) {
+llvm::Expected>
+CommandObjectDisassemble::CheckRangeSize(std::vector ranges,
+ llvm::StringRef what) {
+  addr_t total_range_size = 0;
+  for (const AddressRange &r : ranges)
+total_range_size += r.GetByteSize();
+
   if (m_options.num_instructions > 0 || m_options.force ||
-  range.GetByteSize() < GetDebugger().GetStopDisassemblyMaxSize())
-return llvm::Error::success();
+  total_range_size < GetDebugger().GetStopDisassemblyMaxSize())
+return ranges;
+
   StreamString msg;
   msg << "Not disassembling " << what << " because it is very large ";
-  range.Dump(&msg, &GetTarget(), Address::DumpStyleLoadAddress,
- Address::DumpStyleFileAddress);
+  for (const AddressRange &r: ranges)
+r.Dump(&msg, &GetTarget(), Address::DumpStyleLoadAddress,
+   Address::DumpStyleFileAddress);
   msg << ". To disassemble specify an instruction count limit, start/stop "
  "addresses or use the --force option.";
-  return llvm::createStringError(llvm::inconvertibleErrorCode(),
- msg.GetString());
+  return llvm::createStringError(msg.GetString());
 }
 
 llvm::Expected>
@@ -262,9 +269,11 @@ CommandObjectDisassemble::GetContainingAddressRanges() {
 addr, eSymbolContextEverything, sc, resolve_tail_call_address);
 if (sc.function || sc.symbol) {
   AddressRange range;
-  sc.GetAddressRange(eSymbolContextFunction | eSymbolContextSymbol, 0,
- false, range);
-  ranges.push_back(range);
+  for (uint32_t idx = 0;
+   sc.GetAddressRange(eSymbolContextFunction | eSymbolContextSymbol,
+  idx, false, range);
+   ++idx)
+ranges.push_back(range);
 }
   };
 
@@ -292,9 +301,7 @@ CommandObjectDisassemble::GetContainingAddressRanges() {
 m_options.symbol_containing_addr);
   }
 
-  if (llvm::Error err = CheckRangeSize(ranges[0], "the function"))
-return std::move(err);
-  return ranges;
+  return CheckRangeSize(std::move(ranges), "the function");
 }
 
 llvm::Expected>
@@ -304,29 +311,24 @@ CommandObjectDisassemble::GetCurrentFunctionRanges() {
   if (!frame) {
 if (process) {
   return llvm::createStringError(
-  llvm::inconvertibleErrorCode(),
-  "Cannot disassemble around the current "
-  "function without the process being stopped.\n");
-} else {
-  return llvm::createStringError(llvm::inconvertibleErrorCode(),
- "Cannot disassemble around the current "
- "function without a selected frame: "
- "no currently running process.\n");
+  

[Lldb-commits] [lldb] [lldb] Support disassembling discontinuous functions (PR #126505)

2025-02-10 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)


Changes

The command already supported disassembling multiple ranges, among other 
reasons because inline functions can be discontinuous. The main thing that was 
missing was being able to retrieve the function ranges from the top level 
function object.

The output of the command for the case where the function entry point is not 
its lowest address is somewhat confusing (we're showing negative offsets), but 
it is correct.

---
Full diff: https://github.com/llvm/llvm-project/pull/126505.diff


4 Files Affected:

- (modified) lldb/source/Commands/CommandObjectDisassemble.cpp (+47-41) 
- (modified) lldb/source/Commands/CommandObjectDisassemble.h (+2-1) 
- (modified) lldb/source/Symbol/SymbolContext.cpp (+2-2) 
- (modified) lldb/test/Shell/Commands/command-disassemble.s (+103-9) 


``diff
diff --git a/lldb/source/Commands/CommandObjectDisassemble.cpp 
b/lldb/source/Commands/CommandObjectDisassemble.cpp
index 5b131fe86dedbae..d116188966daa49 100644
--- a/lldb/source/Commands/CommandObjectDisassemble.cpp
+++ b/lldb/source/Commands/CommandObjectDisassemble.cpp
@@ -21,6 +21,7 @@
 #include "lldb/Target/SectionLoadList.h"
 #include "lldb/Target/StackFrame.h"
 #include "lldb/Target/Target.h"
+#include 
 
 static constexpr unsigned default_disasm_byte_size = 32;
 static constexpr unsigned default_disasm_num_ins = 4;
@@ -236,19 +237,25 @@ CommandObjectDisassemble::CommandObjectDisassemble(
 
 CommandObjectDisassemble::~CommandObjectDisassemble() = default;
 
-llvm::Error CommandObjectDisassemble::CheckRangeSize(const AddressRange &range,
- llvm::StringRef what) {
+llvm::Expected>
+CommandObjectDisassemble::CheckRangeSize(std::vector ranges,
+ llvm::StringRef what) {
+  addr_t total_range_size = 0;
+  for (const AddressRange &r : ranges)
+total_range_size += r.GetByteSize();
+
   if (m_options.num_instructions > 0 || m_options.force ||
-  range.GetByteSize() < GetDebugger().GetStopDisassemblyMaxSize())
-return llvm::Error::success();
+  total_range_size < GetDebugger().GetStopDisassemblyMaxSize())
+return ranges;
+
   StreamString msg;
   msg << "Not disassembling " << what << " because it is very large ";
-  range.Dump(&msg, &GetTarget(), Address::DumpStyleLoadAddress,
- Address::DumpStyleFileAddress);
+  for (const AddressRange &r: ranges)
+r.Dump(&msg, &GetTarget(), Address::DumpStyleLoadAddress,
+   Address::DumpStyleFileAddress);
   msg << ". To disassemble specify an instruction count limit, start/stop "
  "addresses or use the --force option.";
-  return llvm::createStringError(llvm::inconvertibleErrorCode(),
- msg.GetString());
+  return llvm::createStringError(msg.GetString());
 }
 
 llvm::Expected>
@@ -262,9 +269,11 @@ CommandObjectDisassemble::GetContainingAddressRanges() {
 addr, eSymbolContextEverything, sc, resolve_tail_call_address);
 if (sc.function || sc.symbol) {
   AddressRange range;
-  sc.GetAddressRange(eSymbolContextFunction | eSymbolContextSymbol, 0,
- false, range);
-  ranges.push_back(range);
+  for (uint32_t idx = 0;
+   sc.GetAddressRange(eSymbolContextFunction | eSymbolContextSymbol,
+  idx, false, range);
+   ++idx)
+ranges.push_back(range);
 }
   };
 
@@ -292,9 +301,7 @@ CommandObjectDisassemble::GetContainingAddressRanges() {
 m_options.symbol_containing_addr);
   }
 
-  if (llvm::Error err = CheckRangeSize(ranges[0], "the function"))
-return std::move(err);
-  return ranges;
+  return CheckRangeSize(std::move(ranges), "the function");
 }
 
 llvm::Expected>
@@ -304,29 +311,24 @@ CommandObjectDisassemble::GetCurrentFunctionRanges() {
   if (!frame) {
 if (process) {
   return llvm::createStringError(
-  llvm::inconvertibleErrorCode(),
-  "Cannot disassemble around the current "
-  "function without the process being stopped.\n");
-} else {
-  return llvm::createStringError(llvm::inconvertibleErrorCode(),
- "Cannot disassemble around the current "
- "function without a selected frame: "
- "no currently running process.\n");
+  "Cannot disassemble around the current function without the process "
+  "being stopped.\n");
 }
+return llvm::createStringError(
+"Cannot disassemble around the current function without a selected "
+"frame: no currently running process.\n");
   }
-  SymbolContext sc(
-  frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextSymbol));
-  AddressRange range;
+  SymbolContext sc =
+  frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextSymbol);
+  std::vector ranges;
   if (sc.fun

[Lldb-commits] [lldb] [lldb] Support disassembling discontinuous functions (PR #126505)

2025-02-10 Thread via lldb-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff aebe6c5d7f88a05a29ef6c643482ca7eaf994b19 
96957acfb6847343df50a641c6de03199c924f72 --extensions cpp,h -- 
lldb/source/Commands/CommandObjectDisassemble.cpp 
lldb/source/Commands/CommandObjectDisassemble.h 
lldb/source/Symbol/SymbolContext.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/source/Commands/CommandObjectDisassemble.cpp 
b/lldb/source/Commands/CommandObjectDisassemble.cpp
index d116188966..f66c67577c 100644
--- a/lldb/source/Commands/CommandObjectDisassemble.cpp
+++ b/lldb/source/Commands/CommandObjectDisassemble.cpp
@@ -250,7 +250,7 @@ 
CommandObjectDisassemble::CheckRangeSize(std::vector ranges,
 
   StreamString msg;
   msg << "Not disassembling " << what << " because it is very large ";
-  for (const AddressRange &r: ranges)
+  for (const AddressRange &r : ranges)
 r.Dump(&msg, &GetTarget(), Address::DumpStyleLoadAddress,
Address::DumpStyleFileAddress);
   msg << ". To disassemble specify an instruction count limit, start/stop "

``




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


[Lldb-commits] [lldb] [lldb] Fixing edge cases in "command source" (PR #126526)

2025-02-10 Thread Pavel Labath via lldb-commits

https://github.com/labath updated 
https://github.com/llvm/llvm-project/pull/126526

>From fda9035cddce78e2109462c9cec176bcb96392d8 Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Mon, 10 Feb 2025 15:20:05 +0100
Subject: [PATCH] [lldb] Fixing edge cases in "command source"

While looking at how to make Function::GetEndLineSourceInfo (which is
only used in "command source") work with discontinuous functions, I
realized there are other corner cases that this function doesn't handle.

The code assumed that the last line entry in the function will also
correspond to the last source line. This is probably true for
unoptimized code, but I don't think we can rely on the optimizer to
preserve this property. What's worse, the code didn't check that the
last line entry belonged to the same file as the first one, so if this
line entry was the result of inlining, we could end up using a line from
a completely different file.

To fix this, I change the algorithm to iterate over all line entries in
the function (which belong to the same file) and find the max line
number out of those. This way we can naturally handle the discontinuous
case as well.

This implementations is going to be slower than the previous one, but I
don't think that matters, because:
- this command is only used rarely, and interactively
- we have plenty of other code which iterates through the line table

I added some basic tests for the function operation. I don't claim the
tests to be comprehensive, or that the function handles all edge cases,
but test framework created here could be used for testing other
fixes/edge cases as well.
---
 lldb/include/lldb/Symbol/Function.h   |  15 +-
 lldb/source/Commands/CommandObjectSource.cpp  |  14 +-
 lldb/source/Symbol/Function.cpp   |  44 +--
 .../test/Shell/Commands/command-source-list.s | 265 ++
 4 files changed, 304 insertions(+), 34 deletions(-)
 create mode 100644 lldb/test/Shell/Commands/command-source-list.s

diff --git a/lldb/include/lldb/Symbol/Function.h 
b/lldb/include/lldb/Symbol/Function.h
index f3b956139f3c5b..ee3a8304fc5b37 100644
--- a/lldb/include/lldb/Symbol/Function.h
+++ b/lldb/include/lldb/Symbol/Function.h
@@ -15,6 +15,7 @@
 #include "lldb/Expression/DWARFExpressionList.h"
 #include "lldb/Symbol/Block.h"
 #include "lldb/Utility/UserID.h"
+#include "lldb/lldb-forward.h"
 #include "llvm/ADT/ArrayRef.h"
 
 #include 
@@ -460,6 +461,7 @@ class Function : public UserID, public SymbolContextScope {
   }
 
   lldb::LanguageType GetLanguage() const;
+
   /// Find the file and line number of the source location of the start of the
   /// function.  This will use the declaration if present and fall back on the
   /// line table if that fails.  So there may NOT be a line table entry for
@@ -473,16 +475,9 @@ class Function : public UserID, public SymbolContextScope {
   void GetStartLineSourceInfo(lldb::SupportFileSP &source_file_sp,
   uint32_t &line_no);
 
-  /// Find the file and line number of the source location of the end of the
-  /// function.
-  ///
-  ///
-  /// \param[out] source_file
-  /// The source file.
-  ///
-  /// \param[out] line_no
-  /// The line number.
-  void GetEndLineSourceInfo(FileSpec &source_file, uint32_t &line_no);
+  using SourceRange = Range;
+  /// Find the file and line number range of the function.
+  llvm::Expected> GetSourceInfo();
 
   /// Get the outgoing call edges from this function, sorted by their return
   /// PC addresses (in increasing order).
diff --git a/lldb/source/Commands/CommandObjectSource.cpp 
b/lldb/source/Commands/CommandObjectSource.cpp
index 936783216f6ff5..81bf1769808bad 100644
--- a/lldb/source/Commands/CommandObjectSource.cpp
+++ b/lldb/source/Commands/CommandObjectSource.cpp
@@ -784,14 +784,12 @@ class CommandObjectSourceList : public 
CommandObjectParsed {
 
   if (sc.block == nullptr) {
 // Not an inlined function
-sc.function->GetStartLineSourceInfo(start_file, start_line);
-if (start_line == 0) {
-  result.AppendErrorWithFormat("Could not find line information for "
-   "start of function: \"%s\".\n",
-   source_info.function.GetCString());
-  return 0;
-}
-sc.function->GetEndLineSourceInfo(end_file, end_line);
+auto expected_info = sc.function->GetSourceInfo();
+if (!expected_info)
+  result.AppendError(llvm::toString(expected_info.takeError()));
+start_file = expected_info->first;
+start_line = expected_info->second.GetRangeBase();
+end_line = expected_info->second.GetRangeEnd();
   } else {
 // We have an inlined function
 start_file = source_info.line_entry.file_sp;
diff --git a/lldb/source/Symbol/Function.cpp b/lldb/source/Symbol/Function.cpp
index 11a43a9172ea67..9fbda97b7cc483 100644
--- a/lldb/source/Symbol/Function.cpp
+++ b/lldb/source/Symbol/Function.

[Lldb-commits] [lldb] [lldb] Fixing edge cases in "command source" (PR #126526)

2025-02-10 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)


Changes

While looking at how to make Function::GetEndLineSourceInfo (which is only used 
in "command source") work with discontinuous functions, I realized there are 
other corner cases that this function doesn't handle.

The code assumed that the last line entry in the function will also correspond 
to the last source line. This is probably true for unoptimized code, but I 
don't think we can rely on the optimizer to preserve this property. What's 
worse, the code didn't check that the last line entry belonged to the same file 
as the first one, so if this line entry was the result of inlining, we could 
end up using a line from a completely different file.

To fix this, I change the algorithm to iterate over all line entries in the 
function (which belong to the same file) and find the max line number out of 
those. This way we can naturally handle the discontinuous case as well.

This implementations is going to be slower than the previous one, but I don't 
think that matters, because:
- this command is only used rarely, and interactively
- we have plenty of other code which iterates through the line table

I added some basic tests for the function operation. I don't claim the tests to 
be comprehensive, or that the function handles all edge cases, but test 
framework created here could be used for testing other fixes/edge cases as well.

---
Full diff: https://github.com/llvm/llvm-project/pull/126526.diff


4 Files Affected:

- (modified) lldb/include/lldb/Symbol/Function.h (+5-10) 
- (modified) lldb/source/Commands/CommandObjectSource.cpp (+6-8) 
- (modified) lldb/source/Symbol/Function.cpp (+27-16) 
- (added) lldb/test/Shell/Commands/command-source-list.s (+265) 


``diff
diff --git a/lldb/include/lldb/Symbol/Function.h 
b/lldb/include/lldb/Symbol/Function.h
index f3b956139f3c5b..ee3a8304fc5b37 100644
--- a/lldb/include/lldb/Symbol/Function.h
+++ b/lldb/include/lldb/Symbol/Function.h
@@ -15,6 +15,7 @@
 #include "lldb/Expression/DWARFExpressionList.h"
 #include "lldb/Symbol/Block.h"
 #include "lldb/Utility/UserID.h"
+#include "lldb/lldb-forward.h"
 #include "llvm/ADT/ArrayRef.h"
 
 #include 
@@ -460,6 +461,7 @@ class Function : public UserID, public SymbolContextScope {
   }
 
   lldb::LanguageType GetLanguage() const;
+
   /// Find the file and line number of the source location of the start of the
   /// function.  This will use the declaration if present and fall back on the
   /// line table if that fails.  So there may NOT be a line table entry for
@@ -473,16 +475,9 @@ class Function : public UserID, public SymbolContextScope {
   void GetStartLineSourceInfo(lldb::SupportFileSP &source_file_sp,
   uint32_t &line_no);
 
-  /// Find the file and line number of the source location of the end of the
-  /// function.
-  ///
-  ///
-  /// \param[out] source_file
-  /// The source file.
-  ///
-  /// \param[out] line_no
-  /// The line number.
-  void GetEndLineSourceInfo(FileSpec &source_file, uint32_t &line_no);
+  using SourceRange = Range;
+  /// Find the file and line number range of the function.
+  llvm::Expected> GetSourceInfo();
 
   /// Get the outgoing call edges from this function, sorted by their return
   /// PC addresses (in increasing order).
diff --git a/lldb/source/Commands/CommandObjectSource.cpp 
b/lldb/source/Commands/CommandObjectSource.cpp
index 936783216f6ff5..81bf1769808bad 100644
--- a/lldb/source/Commands/CommandObjectSource.cpp
+++ b/lldb/source/Commands/CommandObjectSource.cpp
@@ -784,14 +784,12 @@ class CommandObjectSourceList : public 
CommandObjectParsed {
 
   if (sc.block == nullptr) {
 // Not an inlined function
-sc.function->GetStartLineSourceInfo(start_file, start_line);
-if (start_line == 0) {
-  result.AppendErrorWithFormat("Could not find line information for "
-   "start of function: \"%s\".\n",
-   source_info.function.GetCString());
-  return 0;
-}
-sc.function->GetEndLineSourceInfo(end_file, end_line);
+auto expected_info = sc.function->GetSourceInfo();
+if (!expected_info)
+  result.AppendError(llvm::toString(expected_info.takeError()));
+start_file = expected_info->first;
+start_line = expected_info->second.GetRangeBase();
+end_line = expected_info->second.GetRangeEnd();
   } else {
 // We have an inlined function
 start_file = source_info.line_entry.file_sp;
diff --git a/lldb/source/Symbol/Function.cpp b/lldb/source/Symbol/Function.cpp
index 11a43a9172ea67..2594fecb27ceb2 100644
--- a/lldb/source/Symbol/Function.cpp
+++ b/lldb/source/Symbol/Function.cpp
@@ -320,25 +320,36 @@ void Function::GetStartLineSourceInfo(SupportFileSP 
&source_file_sp,
   }
 }
 
-void Function::GetEndLineSourceInfo(FileSpec &source_file, uint32_t &line_no) {
-  lin

[Lldb-commits] [lldb] [lldb] Fixing edge cases in "command source" (PR #126526)

2025-02-10 Thread Pavel Labath via lldb-commits

https://github.com/labath created 
https://github.com/llvm/llvm-project/pull/126526

While looking at how to make Function::GetEndLineSourceInfo (which is only used 
in "command source") work with discontinuous functions, I realized there are 
other corner cases that this function doesn't handle.

The code assumed that the last line entry in the function will also correspond 
to the last source line. This is probably true for unoptimized code, but I 
don't think we can rely on the optimizer to preserve this property. What's 
worse, the code didn't check that the last line entry belonged to the same file 
as the first one, so if this line entry was the result of inlining, we could 
end up using a line from a completely different file.

To fix this, I change the algorithm to iterate over all line entries in the 
function (which belong to the same file) and find the max line number out of 
those. This way we can naturally handle the discontinuous case as well.

This implementations is going to be slower than the previous one, but I don't 
think that matters, because:
- this command is only used rarely, and interactively
- we have plenty of other code which iterates through the line table

I added some basic tests for the function operation. I don't claim the tests to 
be comprehensive, or that the function handles all edge cases, but test 
framework created here could be used for testing other fixes/edge cases as well.

>From a4745b1361390140125947c63cd0afa9cc0f57e9 Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Mon, 10 Feb 2025 15:20:05 +0100
Subject: [PATCH] [lldb] Fixing edge cases in "command source"

While looking at how to make Function::GetEndLineSourceInfo (which is
only used in "command source") work with discontinuous functions, I
realized there are other corner cases that this function doesn't handle.

The code assumed that the last line entry in the function will also
correspond to the last source line. This is probably true for
unoptimized code, but I don't think we can rely on the optimizer to
preserve this property. What's worse, the code didn't check that the
last line entry belonged to the same file as the first one, so if this
line entry was the result of inlining, we could end up using a line from
a completely different file.

To fix this, I change the algorithm to iterate over all line entries in
the function (which belong to the same file) and find the max line
number out of those. This way we can naturally handle the discontinuous
case as well.

This implementations is going to be slower than the previous one, but I
don't think that matters, because:
- this command is only used rarely, and interactively
- we have plenty of other code which iterates through the line table

I added some basic tests for the function operation. I don't claim the
tests to be comprehensive, or that the function handles all edge cases,
but test framework created here could be used for testing other
fixes/edge cases as well.
---
 lldb/include/lldb/Symbol/Function.h   |  15 +-
 lldb/source/Commands/CommandObjectSource.cpp  |  14 +-
 lldb/source/Symbol/Function.cpp   |  43 +--
 .../test/Shell/Commands/command-source-list.s | 265 ++
 4 files changed, 303 insertions(+), 34 deletions(-)
 create mode 100644 lldb/test/Shell/Commands/command-source-list.s

diff --git a/lldb/include/lldb/Symbol/Function.h 
b/lldb/include/lldb/Symbol/Function.h
index f3b956139f3c5b..ee3a8304fc5b37 100644
--- a/lldb/include/lldb/Symbol/Function.h
+++ b/lldb/include/lldb/Symbol/Function.h
@@ -15,6 +15,7 @@
 #include "lldb/Expression/DWARFExpressionList.h"
 #include "lldb/Symbol/Block.h"
 #include "lldb/Utility/UserID.h"
+#include "lldb/lldb-forward.h"
 #include "llvm/ADT/ArrayRef.h"
 
 #include 
@@ -460,6 +461,7 @@ class Function : public UserID, public SymbolContextScope {
   }
 
   lldb::LanguageType GetLanguage() const;
+
   /// Find the file and line number of the source location of the start of the
   /// function.  This will use the declaration if present and fall back on the
   /// line table if that fails.  So there may NOT be a line table entry for
@@ -473,16 +475,9 @@ class Function : public UserID, public SymbolContextScope {
   void GetStartLineSourceInfo(lldb::SupportFileSP &source_file_sp,
   uint32_t &line_no);
 
-  /// Find the file and line number of the source location of the end of the
-  /// function.
-  ///
-  ///
-  /// \param[out] source_file
-  /// The source file.
-  ///
-  /// \param[out] line_no
-  /// The line number.
-  void GetEndLineSourceInfo(FileSpec &source_file, uint32_t &line_no);
+  using SourceRange = Range;
+  /// Find the file and line number range of the function.
+  llvm::Expected> GetSourceInfo();
 
   /// Get the outgoing call edges from this function, sorted by their return
   /// PC addresses (in increasing order).
diff --git a/lldb/source/Commands/CommandObjectSource.cpp 
b/lldb/source/Commands/CommandObjectSource.cpp

[Lldb-commits] [lldb] [lldb] Support disassembling discontinuous functions (PR #126505)

2025-02-10 Thread David Spickett via lldb-commits


@@ -262,9 +269,11 @@ CommandObjectDisassemble::GetContainingAddressRanges() {
 addr, eSymbolContextEverything, sc, resolve_tail_call_address);
 if (sc.function || sc.symbol) {
   AddressRange range;
-  sc.GetAddressRange(eSymbolContextFunction | eSymbolContextSymbol, 0,
- false, range);
-  ranges.push_back(range);
+  for (uint32_t idx = 0;
+   sc.GetAddressRange(eSymbolContextFunction | eSymbolContextSymbol,
+  idx, false, range);
+   ++idx)
+ranges.push_back(range);
 }

DavidSpickett wrote:

Can't comment on the line, but above:
```
const auto &get_range = [&](Address addr) {
```
It gets multiple ranges now.

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


[Lldb-commits] [lldb] [lldb] Support disassembling discontinuous functions (PR #126505)

2025-02-10 Thread David Spickett via lldb-commits


@@ -82,20 +82,25 @@
 # CHECK-NEXT: (lldb) disassemble --name case2
 # CHECK-NEXT: command-disassemble.s.tmp`n1::case2:
 # CHECK-NEXT: command-disassemble.s.tmp[0x2044] <+0>: int$0x32
-# CHECK-NEXT: warning: Not disassembling a range because it is very large 
[0x2046-0x4046). To disassemble specify an instruction 
count limit, start/stop addresses or use the --force option.
+# CHECK-NEXT: warning: Not disassembling a function because it is very large 
[0x2046-0x4046). To disassemble specify an instruction 
count limit, start/stop addresses or use the --force option.
 # CHECK-NEXT: (lldb) disassemble --name case3
-# CHECK-NEXT: error: Not disassembling a range because it is very large 
[0x4046-0x6046). To disassemble specify an instruction 
count limit, start/stop addresses or use the --force option.
-# CHECK-NEXT: Not disassembling a range because it is very large 
[0x6046-0x8046). To disassemble specify an instruction 
count limit, start/stop addresses or use the --force option.
+# CHECK-NEXT: error: Not disassembling a function because it is very large 
[0x6046-0x7046)[0x9046-0xa046). 
To disassemble specify an instruction count limit, start/stop addresses or use 
the --force option.

DavidSpickett wrote:

All the options are a bit strange but yes that achieves the objective of not 
spamming the terminal in a way where it would be hard to tell where the output 
begins and ends. Which is especially important if the function spans multiple 
ranges.

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


[Lldb-commits] [clang] [libc] [libcxx] [lldb] [llvm] [doc] Add Discord invite link alongside channel links (PR #126352)

2025-02-10 Thread Aaron Ballman via lldb-commits

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

LGTM!

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


[Lldb-commits] [lldb] [lldb] Fixing edge cases in "command source" (PR #126526)

2025-02-10 Thread Jonas Devlieghere via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Fixing edge cases in "command source" (PR #126526)

2025-02-10 Thread Jonas Devlieghere via lldb-commits


@@ -784,14 +784,12 @@ class CommandObjectSourceList : public 
CommandObjectParsed {
 
   if (sc.block == nullptr) {
 // Not an inlined function
-sc.function->GetStartLineSourceInfo(start_file, start_line);
-if (start_line == 0) {
-  result.AppendErrorWithFormat("Could not find line information for "
-   "start of function: \"%s\".\n",
-   source_info.function.GetCString());
-  return 0;
-}
-sc.function->GetEndLineSourceInfo(end_file, end_line);
+auto expected_info = sc.function->GetSourceInfo();
+if (!expected_info)
+  result.AppendError(llvm::toString(expected_info.takeError()));

JDevlieghere wrote:

Was this supposed to retain the `return 0;`? Now you're dereferencing 
`expected_info` even if it contains an error. 

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


[Lldb-commits] [lldb] [lldb] Fixing edge cases in "command source" (PR #126526)

2025-02-10 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere commented:

Makes sense. Seems like a more-than-fair tradeoff between correctness and 
performance. 

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


[Lldb-commits] [lldb] [lldb][telemetry] Implement LLDB Telemetry (part 1) (PR #119716)

2025-02-10 Thread Vy Nguyen via lldb-commits

oontvoo wrote:

@JDevlieghere  Hi, do you have any further comment/feedback  on this? If not, I 
plan to merge the PR this afternoon. Thanks!

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


[Lldb-commits] [lldb] [lldb] Implement a statusline in LLDB (PR #121860)

2025-02-10 Thread Jonas Devlieghere via lldb-commits

JDevlieghere wrote:

> Looks like 
> `lldb/test/API/functionalities/progress_reporting/TestTrimmedProgressReporting.py`
>  was deleted entirely. Was this intentional?

Yes, because this replaces the old in-line progress printing. The statusline 
still trims messages that don't fit and progress isn't any special. I can add a 
test to the statusline for that, but because PExpect is line-oriented it's 
going to be pretty heavy-weight (i.e. duplicate the existing test in a smaller 
window). 

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


[Lldb-commits] [lldb] [lldb-dap] Implement `runInTerminal` for Windows (PR #121269)

2025-02-10 Thread John Harrison via lldb-commits


@@ -24,41 +30,95 @@ using namespace llvm;
 
 namespace lldb_dap {
 
-FifoFile::FifoFile(StringRef path) : m_path(path) {}
-
+FifoFile::FifoFile(StringRef path)
+: m_path(path), m_file(fopen(path.data(), "r+")) {
+  std::error_code EC;
+  if (m_file == nullptr) {
+EC = std::error_code(errno, std::generic_category());
+llvm::errs() << "Failed to open fifo file " << path << ": " << EC.message()
+ << "\n";
+std::terminate();
+  }
+  if (setvbuf(m_file, NULL, _IONBF, 0))
+llvm::errs() << "Error setting unbuffered mode on C FILE\n";
+}
+FifoFile::FifoFile(StringRef path, FILE *f) : m_path(path), m_file(f) {}
+FifoFile::FifoFile(FifoFile &&other)
+: m_path(other.m_path), m_file(other.m_file) {
+  other.m_path.clear();
+  other.m_file = nullptr;
+}
 FifoFile::~FifoFile() {
+  if (m_file)
+fclose(m_file);
 #if !defined(_WIN32)
+  // Unreferenced named pipes are deleted automatically on Win32
   unlink(m_path.c_str());
 #endif
 }
 
-Expected> CreateFifoFile(StringRef path) {
-#if defined(_WIN32)
-  return createStringError(inconvertibleErrorCode(), "Unimplemented");
+// This probably belongs to llvm::sys::fs as another FSEntity type
+std::error_code createUniqueNamedPipe(const Twine &prefix, StringRef suffix,
+  int &result_fd,
+  SmallVectorImpl &result_path) {
+  const char *middle = suffix.empty() ? "-%%" : "-%%.";
+  auto EC = sys::fs::getPotentiallyUniqueFileName(
+#ifdef _WIN32
+  ".\\pipe\\LOCAL\\"
+#else
+  "/tmp/"
+#endif
+  + prefix + middle + suffix,
+  result_path);
+  if (EC)
+return EC;
+  result_path.push_back(0);
+  const char *path = result_path.data();
+#ifdef _WIN32
+  HANDLE h = ::CreateNamedPipeA(
+  path, PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE,
+  PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, 1, 1024, 1024, 0, NULL);
+  if (h == INVALID_HANDLE_VALUE)
+return llvm::mapLastWindowsError();
+  result_fd = _open_osfhandle((intptr_t)h, _O_TEXT | _O_RDWR);
+  if (result_fd == -1)
+return llvm::mapLastWindowsError();
 #else
-  if (int err = mkfifo(path.data(), 0600))
-return createStringError(std::error_code(err, std::generic_category()),
- "Couldn't create fifo file: %s", path.data());
-  return std::make_shared(path);
+  if (mkfifo(path, 0600) == -1)
+return std::error_code(errno, std::generic_category());
+  EC = openFileForWrite(result_path, result_fd, sys::fs::CD_OpenExisting,
+sys::fs::OF_None, 0600);
+  if (EC)
+return EC;
 #endif
+  result_path.pop_back();
+  return std::error_code();
 }
 
-FifoFileIO::FifoFileIO(StringRef fifo_file, StringRef other_endpoint_name)
-: m_fifo_file(fifo_file), m_other_endpoint_name(other_endpoint_name) {}
+FifoFileIO::FifoFileIO(FifoFile &&fifo_file, StringRef other_endpoint_name)
+: m_fifo_file(std::move(fifo_file)),
+  m_other_endpoint_name(other_endpoint_name) {}
 
 Expected FifoFileIO::ReadJSON(std::chrono::milliseconds timeout) {
   // We use a pointer for this future, because otherwise its normal destructor
   // would wait for the getline to end, rendering the timeout useless.
   std::optional line;
   std::future *future =
   new std::future(std::async(std::launch::async, [&]() {
-std::ifstream reader(m_fifo_file, std::ifstream::in);
-std::string buffer;
-std::getline(reader, buffer);
-if (!buffer.empty())
-  line = buffer;
+rewind(m_fifo_file.m_file);
+constexpr size_t buffer_size = 2048;

ashgti wrote:

Here the buffer is 2048 but when the file is created its 1024. Should we have a 
common default buffer size?

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


[Lldb-commits] [lldb] [lldb-dap] Implement `runInTerminal` for Windows (PR #121269)

2025-02-10 Thread John Harrison via lldb-commits


@@ -24,41 +30,95 @@ using namespace llvm;
 
 namespace lldb_dap {
 
-FifoFile::FifoFile(StringRef path) : m_path(path) {}
-
+FifoFile::FifoFile(StringRef path)
+: m_path(path), m_file(fopen(path.data(), "r+")) {
+  std::error_code EC;
+  if (m_file == nullptr) {
+EC = std::error_code(errno, std::generic_category());
+llvm::errs() << "Failed to open fifo file " << path << ": " << EC.message()
+ << "\n";
+std::terminate();
+  }
+  if (setvbuf(m_file, NULL, _IONBF, 0))
+llvm::errs() << "Error setting unbuffered mode on C FILE\n";

ashgti wrote:

Like above, this should return an error if this fails instead.

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


[Lldb-commits] [lldb] [lldb-dap] Implement `runInTerminal` for Windows (PR #121269)

2025-02-10 Thread John Harrison via lldb-commits


@@ -21,21 +23,28 @@ namespace lldb_dap {
 /// The file is destroyed when the destructor is invoked.
 struct FifoFile {
   FifoFile(llvm::StringRef path);
+  FifoFile(llvm::StringRef path, FILE *f);
+  FifoFile(FifoFile &&other);
+
+  FifoFile(const FifoFile &) = delete;
+  FifoFile &operator=(const FifoFile &) = delete;
 
   ~FifoFile();
 
   std::string m_path;
+  FILE *m_file;
 };
 
-/// Create a fifo file in the filesystem.
+/// Create and open a named pipe with a unique name.
 ///
-/// \param[in] path
-/// The path for the fifo file.
+/// The arguments have identical meanings to those of
+/// llvm::sys::fs::createTemporaryFile.
 ///
-/// \return
-/// A \a std::shared_ptr if the file could be created, or an
-/// \a llvm::Error in case of failures.
-llvm::Expected> CreateFifoFile(llvm::StringRef path);
+/// Note that the resulting filename is further prepended by \c 
\\.\pipe\\LOCAL\
+/// on Windows and \c /tmp on other platforms.
+std::error_code createUniqueNamedPipe(const llvm::Twine &prefix,

ashgti wrote:

Should this return an `llvm::Error` instead of a `std::error_code`? 
`llvm::Error` has stronger requirements for handling errors.

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


[Lldb-commits] [lldb] [lldb-dap] Implement `runInTerminal` for Windows (PR #121269)

2025-02-10 Thread John Harrison via lldb-commits


@@ -24,41 +30,95 @@ using namespace llvm;
 
 namespace lldb_dap {
 
-FifoFile::FifoFile(StringRef path) : m_path(path) {}
-
+FifoFile::FifoFile(StringRef path)
+: m_path(path), m_file(fopen(path.data(), "r+")) {
+  std::error_code EC;
+  if (m_file == nullptr) {
+EC = std::error_code(errno, std::generic_category());
+llvm::errs() << "Failed to open fifo file " << path << ": " << EC.message()
+ << "\n";
+std::terminate();
+  }
+  if (setvbuf(m_file, NULL, _IONBF, 0))
+llvm::errs() << "Error setting unbuffered mode on C FILE\n";
+}
+FifoFile::FifoFile(StringRef path, FILE *f) : m_path(path), m_file(f) {}
+FifoFile::FifoFile(FifoFile &&other)
+: m_path(other.m_path), m_file(other.m_file) {
+  other.m_path.clear();
+  other.m_file = nullptr;
+}
 FifoFile::~FifoFile() {
+  if (m_file)
+fclose(m_file);
 #if !defined(_WIN32)
+  // Unreferenced named pipes are deleted automatically on Win32
   unlink(m_path.c_str());
 #endif
 }
 
-Expected> CreateFifoFile(StringRef path) {
-#if defined(_WIN32)
-  return createStringError(inconvertibleErrorCode(), "Unimplemented");
+// This probably belongs to llvm::sys::fs as another FSEntity type
+std::error_code createUniqueNamedPipe(const Twine &prefix, StringRef suffix,
+  int &result_fd,
+  SmallVectorImpl &result_path) {
+  const char *middle = suffix.empty() ? "-%%" : "-%%.";
+  auto EC = sys::fs::getPotentiallyUniqueFileName(
+#ifdef _WIN32
+  ".\\pipe\\LOCAL\\"
+#else
+  "/tmp/"
+#endif
+  + prefix + middle + suffix,
+  result_path);
+  if (EC)
+return EC;
+  result_path.push_back(0);
+  const char *path = result_path.data();
+#ifdef _WIN32
+  HANDLE h = ::CreateNamedPipeA(
+  path, PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE,
+  PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, 1, 1024, 1024, 0, NULL);
+  if (h == INVALID_HANDLE_VALUE)
+return llvm::mapLastWindowsError();
+  result_fd = _open_osfhandle((intptr_t)h, _O_TEXT | _O_RDWR);
+  if (result_fd == -1)
+return llvm::mapLastWindowsError();
 #else
-  if (int err = mkfifo(path.data(), 0600))
-return createStringError(std::error_code(err, std::generic_category()),
- "Couldn't create fifo file: %s", path.data());
-  return std::make_shared(path);
+  if (mkfifo(path, 0600) == -1)
+return std::error_code(errno, std::generic_category());
+  EC = openFileForWrite(result_path, result_fd, sys::fs::CD_OpenExisting,
+sys::fs::OF_None, 0600);
+  if (EC)
+return EC;
 #endif
+  result_path.pop_back();

ashgti wrote:

Any reason why this is being removed from the end of the path? I think thats 
the `\0` char (pushed on line 75).

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


[Lldb-commits] [lldb] [lldb-dap] Implement `runInTerminal` for Windows (PR #121269)

2025-02-10 Thread John Harrison via lldb-commits


@@ -158,13 +156,25 @@ std::string 
RunInTerminalDebugAdapterCommChannel::GetLauncherError() {
 }
 
 Expected> CreateRunInTerminalCommFile() {
+  int comm_fd;
   SmallString<256> comm_file;
-  if (std::error_code EC = sys::fs::getPotentiallyUniqueTempFileName(
-  "lldb-dap-run-in-terminal-comm", "", comm_file))
+  if (std::error_code EC = createUniqueNamedPipe(
+  "lldb-dap-run-in-terminal-comm", "", comm_fd, comm_file))
 return createStringError(EC, "Error making unique file name for "
  "runInTerminal communication files");
-
-  return CreateFifoFile(comm_file.str());
+  FILE *cf = fdopen(comm_fd, "r+");
+  if (setvbuf(cf, NULL, _IONBF, 0))
+return createStringError(std::error_code(errno, std::generic_category()),
+ "Error setting unbuffered mode on C FILE");
+  // There is no portable way to conjure an ofstream from HANDLE, so use FILE *
+  // llvm::raw_fd_stream does not support getline() and there is no
+  // llvm::buffer_istream

ashgti wrote:

If you have the path, can't you use that to open the file with `std::ofstream`?

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


[Lldb-commits] [lldb] [lldb-dap] Implement `runInTerminal` for Windows (PR #121269)

2025-02-10 Thread John Harrison via lldb-commits


@@ -24,41 +30,95 @@ using namespace llvm;
 
 namespace lldb_dap {
 
-FifoFile::FifoFile(StringRef path) : m_path(path) {}
+std::error_code EC;
 
+FifoFile::FifoFile(StringRef path)
+: m_path(path), m_file(fopen(path.data(), "r+")) {
+  if (m_file == nullptr) {
+EC = std::error_code(errno, std::generic_category());
+llvm::errs() << "Failed to open fifo file " << path << ": " << EC.message()
+ << "\n";
+std::terminate();
+  }
+  if (setvbuf(m_file, NULL, _IONBF, 0))
+llvm::errs() << "Error setting unbuffered mode on C FILE\n";
+}
+FifoFile::FifoFile(StringRef path, FILE *f) : m_path(path), m_file(f) {}
+FifoFile::FifoFile(FifoFile &&other)
+: m_path(other.m_path), m_file(other.m_file) {
+  other.m_file = nullptr;
+}
 FifoFile::~FifoFile() {
+  if (m_file)
+fclose(m_file);
 #if !defined(_WIN32)
+  // Unreferenced named pipes are deleted automatically on Win32
   unlink(m_path.c_str());
 #endif
 }
 
-Expected> CreateFifoFile(StringRef path) {
-#if defined(_WIN32)
-  return createStringError(inconvertibleErrorCode(), "Unimplemented");
+// This probably belongs to llvm::sys::fs as another FSEntity type
+std::error_code createNamedPipe(const Twine &Prefix, StringRef Suffix,
+int &ResultFd,
+SmallVectorImpl &ResultPath) {
+  const char *Middle = Suffix.empty() ? "-%%" : "-%%.";
+  auto EC = sys::fs::getPotentiallyUniqueFileName(
+#ifdef _WIN32
+  ".\\pipe\\LOCAL\\"
+#else
+  "/tmp/"
+#endif
+  + Prefix + Middle + Suffix,
+  ResultPath);
+  if (EC)
+return EC;
+  ResultPath.push_back(0);
+  const char *path = ResultPath.data();
+#ifdef _WIN32
+  HANDLE h = ::CreateNamedPipeA(
+  path, PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE,
+  PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, 1, 1024, 1024, 0, NULL);
+  if (h == INVALID_HANDLE_VALUE)
+return std::error_code(::GetLastError(), std::system_category());
+  ResultFd = _open_osfhandle((intptr_t)h, _O_TEXT | _O_RDWR);
+  if (ResultFd == -1)
+return std::error_code(::GetLastError(), std::system_category());
 #else
-  if (int err = mkfifo(path.data(), 0600))
-return createStringError(std::error_code(err, std::generic_category()),
- "Couldn't create fifo file: %s", path.data());
-  return std::make_shared(path);
+  if (mkfifo(path, 0600) == -1)
+return std::error_code(errno, std::generic_category());
+  EC = openFileForWrite(ResultPath, ResultFd, sys::fs::CD_OpenExisting,
+sys::fs::OF_None, 0600);
+  if (EC)
+return EC;
 #endif
+  ResultPath.pop_back();
+  return std::error_code();
 }
 
-FifoFileIO::FifoFileIO(StringRef fifo_file, StringRef other_endpoint_name)
-: m_fifo_file(fifo_file), m_other_endpoint_name(other_endpoint_name) {}
+FifoFileIO::FifoFileIO(FifoFile &&fifo_file, StringRef other_endpoint_name)
+: m_fifo_file(std::move(fifo_file)),
+  m_other_endpoint_name(other_endpoint_name) {}
 
 Expected FifoFileIO::ReadJSON(std::chrono::milliseconds timeout) {
   // We use a pointer for this future, because otherwise its normal destructor
   // would wait for the getline to end, rendering the timeout useless.
   std::optional line;
   std::future *future =
   new std::future(std::async(std::launch::async, [&]() {
-std::ifstream reader(m_fifo_file, std::ifstream::in);
-std::string buffer;
-std::getline(reader, buffer);
-if (!buffer.empty())
-  line = buffer;
+rewind(m_fifo_file.m_file);

ashgti wrote:

I think the flow of the logic here is:

* `lldb-dap` (pid 1) opens the fifo
* pid 1 sends sends the `runInTerminal` command.
* pid 1 reads from the fifo (waiting for data)
* `lldb-dap --launch-target` (pid 2) starts
* pid 2 opens the fifo
* pid 2 spawns the new process
* pid 2 writes to the fifo (something like `{"pid":2}\n`) 
* pid 1 finishes the initial read from the fifo
* pid 1 lldb attaches to the process started by pid 2

This should mean that the parent side only reads from the file and the child 
side only writes to the file. Additionally, I think they're only each 
performing 1 write/read on each side so their respective file positions should 
still be at the beginning of the file after opening.

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


[Lldb-commits] [lldb] [lldb-dap] Implement `runInTerminal` for Windows (PR #121269)

2025-02-10 Thread John Harrison via lldb-commits


@@ -24,41 +30,95 @@ using namespace llvm;
 
 namespace lldb_dap {
 
-FifoFile::FifoFile(StringRef path) : m_path(path) {}
+std::error_code EC;
 
+FifoFile::FifoFile(StringRef path)
+: m_path(path), m_file(fopen(path.data(), "r+")) {
+  if (m_file == nullptr) {
+EC = std::error_code(errno, std::generic_category());
+llvm::errs() << "Failed to open fifo file " << path << ": " << EC.message()
+ << "\n";
+std::terminate();
+  }
+  if (setvbuf(m_file, NULL, _IONBF, 0))
+llvm::errs() << "Error setting unbuffered mode on C FILE\n";
+}
+FifoFile::FifoFile(StringRef path, FILE *f) : m_path(path), m_file(f) {}
+FifoFile::FifoFile(FifoFile &&other)
+: m_path(other.m_path), m_file(other.m_file) {
+  other.m_file = nullptr;
+}
 FifoFile::~FifoFile() {
+  if (m_file)
+fclose(m_file);
 #if !defined(_WIN32)
+  // Unreferenced named pipes are deleted automatically on Win32
   unlink(m_path.c_str());
 #endif
 }
 
-Expected> CreateFifoFile(StringRef path) {
-#if defined(_WIN32)
-  return createStringError(inconvertibleErrorCode(), "Unimplemented");
+// This probably belongs to llvm::sys::fs as another FSEntity type
+std::error_code createNamedPipe(const Twine &Prefix, StringRef Suffix,
+int &ResultFd,
+SmallVectorImpl &ResultPath) {
+  const char *Middle = Suffix.empty() ? "-%%" : "-%%.";
+  auto EC = sys::fs::getPotentiallyUniqueFileName(
+#ifdef _WIN32
+  ".\\pipe\\LOCAL\\"
+#else
+  "/tmp/"

ashgti wrote:

`/tmp` is not always the appropriate platform path for non-windows platforms. 
Thats my main concern.

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


[Lldb-commits] [lldb] [lldb-dap] Implement `runInTerminal` for Windows (PR #121269)

2025-02-10 Thread John Harrison via lldb-commits


@@ -24,41 +30,95 @@ using namespace llvm;
 
 namespace lldb_dap {
 
-FifoFile::FifoFile(StringRef path) : m_path(path) {}
-
+FifoFile::FifoFile(StringRef path)
+: m_path(path), m_file(fopen(path.data(), "r+")) {
+  std::error_code EC;
+  if (m_file == nullptr) {
+EC = std::error_code(errno, std::generic_category());
+llvm::errs() << "Failed to open fifo file " << path << ": " << EC.message()
+ << "\n";
+std::terminate();
+  }
+  if (setvbuf(m_file, NULL, _IONBF, 0))
+llvm::errs() << "Error setting unbuffered mode on C FILE\n";
+}
+FifoFile::FifoFile(StringRef path, FILE *f) : m_path(path), m_file(f) {}
+FifoFile::FifoFile(FifoFile &&other)
+: m_path(other.m_path), m_file(other.m_file) {
+  other.m_path.clear();
+  other.m_file = nullptr;
+}
 FifoFile::~FifoFile() {
+  if (m_file)
+fclose(m_file);
 #if !defined(_WIN32)
+  // Unreferenced named pipes are deleted automatically on Win32
   unlink(m_path.c_str());
 #endif
 }
 
-Expected> CreateFifoFile(StringRef path) {
-#if defined(_WIN32)
-  return createStringError(inconvertibleErrorCode(), "Unimplemented");
+// This probably belongs to llvm::sys::fs as another FSEntity type
+std::error_code createUniqueNamedPipe(const Twine &prefix, StringRef suffix,
+  int &result_fd,
+  SmallVectorImpl &result_path) {
+  const char *middle = suffix.empty() ? "-%%" : "-%%.";
+  auto EC = sys::fs::getPotentiallyUniqueFileName(
+#ifdef _WIN32
+  ".\\pipe\\LOCAL\\"
+#else
+  "/tmp/"
+#endif
+  + prefix + middle + suffix,
+  result_path);
+  if (EC)
+return EC;
+  result_path.push_back(0);
+  const char *path = result_path.data();
+#ifdef _WIN32
+  HANDLE h = ::CreateNamedPipeA(
+  path, PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE,
+  PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, 1, 1024, 1024, 0, NULL);
+  if (h == INVALID_HANDLE_VALUE)
+return llvm::mapLastWindowsError();
+  result_fd = _open_osfhandle((intptr_t)h, _O_TEXT | _O_RDWR);
+  if (result_fd == -1)
+return llvm::mapLastWindowsError();
 #else
-  if (int err = mkfifo(path.data(), 0600))
-return createStringError(std::error_code(err, std::generic_category()),
- "Couldn't create fifo file: %s", path.data());
-  return std::make_shared(path);
+  if (mkfifo(path, 0600) == -1)
+return std::error_code(errno, std::generic_category());
+  EC = openFileForWrite(result_path, result_fd, sys::fs::CD_OpenExisting,
+sys::fs::OF_None, 0600);
+  if (EC)
+return EC;
 #endif
+  result_path.pop_back();
+  return std::error_code();
 }
 
-FifoFileIO::FifoFileIO(StringRef fifo_file, StringRef other_endpoint_name)
-: m_fifo_file(fifo_file), m_other_endpoint_name(other_endpoint_name) {}
+FifoFileIO::FifoFileIO(FifoFile &&fifo_file, StringRef other_endpoint_name)
+: m_fifo_file(std::move(fifo_file)),
+  m_other_endpoint_name(other_endpoint_name) {}
 
 Expected FifoFileIO::ReadJSON(std::chrono::milliseconds timeout) {
   // We use a pointer for this future, because otherwise its normal destructor
   // would wait for the getline to end, rendering the timeout useless.
   std::optional line;
   std::future *future =
   new std::future(std::async(std::launch::async, [&]() {
-std::ifstream reader(m_fifo_file, std::ifstream::in);
-std::string buffer;
-std::getline(reader, buffer);
-if (!buffer.empty())
-  line = buffer;
+rewind(m_fifo_file.m_file);
+constexpr size_t buffer_size = 2048;
+char buffer[buffer_size];
+char *ptr = fgets(buffer, buffer_size, m_fifo_file.m_file);
+if (ptr == nullptr || *ptr == 0)
+  return;
+size_t len = strlen(buffer);
+if (len <= 1)
+  return;
+buffer[len - 1] = '\0'; // remove newline
+line = buffer;

ashgti wrote:

The previous version would get a full line, however this new version will read 
until the buffer is full or EOF. The JSON used is smaller than the buffer size, 
so this should be okay, but if the JSON value was changed then this could be an 
issue.

Should we read until EOF? Or Should we read until we find a newline 
specifically?

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


[Lldb-commits] [lldb] [lldb-dap] Implement `runInTerminal` for Windows (PR #121269)

2025-02-10 Thread John Harrison via lldb-commits


@@ -24,41 +30,95 @@ using namespace llvm;
 
 namespace lldb_dap {
 
-FifoFile::FifoFile(StringRef path) : m_path(path) {}
-
+FifoFile::FifoFile(StringRef path)
+: m_path(path), m_file(fopen(path.data(), "r+")) {
+  std::error_code EC;
+  if (m_file == nullptr) {
+EC = std::error_code(errno, std::generic_category());
+llvm::errs() << "Failed to open fifo file " << path << ": " << EC.message()
+ << "\n";
+std::terminate();

ashgti wrote:

Its a bit odd for this to fully terminate the running program if the allocation 
fails.

Can we adjust this to use either have a static `create` function that returns 
an `llvm::Expected` or have an `open` method that returns an 
`llvm::Error` instead of terminating the running program.

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


[Lldb-commits] [lldb] [lldb] Support disassembling discontinuous functions (PR #126505)

2025-02-10 Thread Pavel Labath via lldb-commits

https://github.com/labath updated 
https://github.com/llvm/llvm-project/pull/126505

>From a716420ee79ea03cd64cf79f1e1f727b86960995 Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Thu, 9 Jan 2025 13:02:24 +0100
Subject: [PATCH] [lldb] Support disassembling discontinuous functions

The command already supported disassembling multiple ranges, among other
reasons because inline functions can be discontinuous. The main thing
that was missing was being able to retrieve the function ranges from the
top level function object.

The output of the command for the case where the function entry point is
not its lowest address is somewhat confusing (we're showing negative
offsets), but it is correct.
---
 .../Commands/CommandObjectDisassemble.cpp |  88 +++---
 .../Commands/CommandObjectDisassemble.h   |   3 +-
 lldb/source/Symbol/SymbolContext.cpp  |   4 +-
 .../test/Shell/Commands/command-disassemble.s | 112 --
 4 files changed, 154 insertions(+), 53 deletions(-)

diff --git a/lldb/source/Commands/CommandObjectDisassemble.cpp 
b/lldb/source/Commands/CommandObjectDisassemble.cpp
index 5b131fe86dedbae..f66c67577c0bedf 100644
--- a/lldb/source/Commands/CommandObjectDisassemble.cpp
+++ b/lldb/source/Commands/CommandObjectDisassemble.cpp
@@ -21,6 +21,7 @@
 #include "lldb/Target/SectionLoadList.h"
 #include "lldb/Target/StackFrame.h"
 #include "lldb/Target/Target.h"
+#include 
 
 static constexpr unsigned default_disasm_byte_size = 32;
 static constexpr unsigned default_disasm_num_ins = 4;
@@ -236,19 +237,25 @@ CommandObjectDisassemble::CommandObjectDisassemble(
 
 CommandObjectDisassemble::~CommandObjectDisassemble() = default;
 
-llvm::Error CommandObjectDisassemble::CheckRangeSize(const AddressRange &range,
- llvm::StringRef what) {
+llvm::Expected>
+CommandObjectDisassemble::CheckRangeSize(std::vector ranges,
+ llvm::StringRef what) {
+  addr_t total_range_size = 0;
+  for (const AddressRange &r : ranges)
+total_range_size += r.GetByteSize();
+
   if (m_options.num_instructions > 0 || m_options.force ||
-  range.GetByteSize() < GetDebugger().GetStopDisassemblyMaxSize())
-return llvm::Error::success();
+  total_range_size < GetDebugger().GetStopDisassemblyMaxSize())
+return ranges;
+
   StreamString msg;
   msg << "Not disassembling " << what << " because it is very large ";
-  range.Dump(&msg, &GetTarget(), Address::DumpStyleLoadAddress,
- Address::DumpStyleFileAddress);
+  for (const AddressRange &r : ranges)
+r.Dump(&msg, &GetTarget(), Address::DumpStyleLoadAddress,
+   Address::DumpStyleFileAddress);
   msg << ". To disassemble specify an instruction count limit, start/stop "
  "addresses or use the --force option.";
-  return llvm::createStringError(llvm::inconvertibleErrorCode(),
- msg.GetString());
+  return llvm::createStringError(msg.GetString());
 }
 
 llvm::Expected>
@@ -262,9 +269,11 @@ CommandObjectDisassemble::GetContainingAddressRanges() {
 addr, eSymbolContextEverything, sc, resolve_tail_call_address);
 if (sc.function || sc.symbol) {
   AddressRange range;
-  sc.GetAddressRange(eSymbolContextFunction | eSymbolContextSymbol, 0,
- false, range);
-  ranges.push_back(range);
+  for (uint32_t idx = 0;
+   sc.GetAddressRange(eSymbolContextFunction | eSymbolContextSymbol,
+  idx, false, range);
+   ++idx)
+ranges.push_back(range);
 }
   };
 
@@ -292,9 +301,7 @@ CommandObjectDisassemble::GetContainingAddressRanges() {
 m_options.symbol_containing_addr);
   }
 
-  if (llvm::Error err = CheckRangeSize(ranges[0], "the function"))
-return std::move(err);
-  return ranges;
+  return CheckRangeSize(std::move(ranges), "the function");
 }
 
 llvm::Expected>
@@ -304,29 +311,24 @@ CommandObjectDisassemble::GetCurrentFunctionRanges() {
   if (!frame) {
 if (process) {
   return llvm::createStringError(
-  llvm::inconvertibleErrorCode(),
-  "Cannot disassemble around the current "
-  "function without the process being stopped.\n");
-} else {
-  return llvm::createStringError(llvm::inconvertibleErrorCode(),
- "Cannot disassemble around the current "
- "function without a selected frame: "
- "no currently running process.\n");
+  "Cannot disassemble around the current function without the process "
+  "being stopped.\n");
 }
+return llvm::createStringError(
+"Cannot disassemble around the current function without a selected "
+"frame: no currently running process.\n");
   }
-  SymbolContext sc(
-  frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextSymbol));
-  AddressRange range;
+  SymbolCo

[Lldb-commits] [clang] [lldb] [lldb] Analyze enum promotion type during parsing (PR #115005)

2025-02-10 Thread Michael Buch via lldb-commits


@@ -2367,11 +2370,27 @@ size_t DWARFASTParserClang::ParseChildEnumerators(
 }
 
 if (name && name[0] && got_value) {
-  m_ast.AddEnumerationValueToEnumerationType(
+  auto ECD = m_ast.AddEnumerationValueToEnumerationType(
   clang_type, decl, name, enum_value, enumerator_byte_size * 8);
+  EnumConstants.emplace_back(static_cast(ECD));
   ++enumerators_added;
 }
   }
+
+  clang::EnumDecl *enum_decl =

Michael137 wrote:

Please move this back into `TypeSystemClang::CompleteTagDeclarationDefinition` 
so we don't need to make `setNumNegativeBits`/`setNumPositiveBits` public. And 
instead just pass the values to `completeDefinition`.

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


[Lldb-commits] [lldb] [lldb] Support disassembling discontinuous functions (PR #126505)

2025-02-10 Thread David Spickett via lldb-commits


@@ -82,20 +82,25 @@
 # CHECK-NEXT: (lldb) disassemble --name case2
 # CHECK-NEXT: command-disassemble.s.tmp`n1::case2:
 # CHECK-NEXT: command-disassemble.s.tmp[0x2044] <+0>: int$0x32
-# CHECK-NEXT: warning: Not disassembling a range because it is very large 
[0x2046-0x4046). To disassemble specify an instruction 
count limit, start/stop addresses or use the --force option.
+# CHECK-NEXT: warning: Not disassembling a function because it is very large 
[0x2046-0x4046). To disassemble specify an instruction 
count limit, start/stop addresses or use the --force option.
 # CHECK-NEXT: (lldb) disassemble --name case3
-# CHECK-NEXT: error: Not disassembling a range because it is very large 
[0x4046-0x6046). To disassemble specify an instruction 
count limit, start/stop addresses or use the --force option.
-# CHECK-NEXT: Not disassembling a range because it is very large 
[0x6046-0x8046). To disassemble specify an instruction 
count limit, start/stop addresses or use the --force option.
+# CHECK-NEXT: error: Not disassembling a function because it is very large 
[0x6046-0x7046)[0x9046-0xa046). 
To disassemble specify an instruction count limit, start/stop addresses or use 
the --force option.

DavidSpickett wrote:

But then does that make it not useful, because it won't start at the prologue?

Do we have any idea what order the chunks are in? I guess not, because in 
theory it could jump between them at runtime, maybe even revisit them.

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


[Lldb-commits] [lldb] [lldb] Support disassembling discontinuous functions (PR #126505)

2025-02-10 Thread David Spickett via lldb-commits

https://github.com/DavidSpickett commented:

Negative offset makes sense to me given that it's relative to the symbol of the 
function. Will be interesting to see how users interpret it though.

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


[Lldb-commits] [lldb] [lldb] Support disassembling discontinuous functions (PR #126505)

2025-02-10 Thread David Spickett via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Support disassembling discontinuous functions (PR #126505)

2025-02-10 Thread David Spickett via lldb-commits


@@ -262,9 +269,11 @@ CommandObjectDisassemble::GetContainingAddressRanges() {
 addr, eSymbolContextEverything, sc, resolve_tail_call_address);
 if (sc.function || sc.symbol) {
   AddressRange range;
-  sc.GetAddressRange(eSymbolContextFunction | eSymbolContextSymbol, 0,
- false, range);
-  ranges.push_back(range);
+  for (uint32_t idx = 0;
+   sc.GetAddressRange(eSymbolContextFunction | eSymbolContextSymbol,
+  idx, false, range);
+   ++idx)
+ranges.push_back(range);
 }

DavidSpickett wrote:

Should this be `get_ranges` now that it pushes onto the vector?

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


[Lldb-commits] [lldb] [lldb] Support disassembling discontinuous functions (PR #126505)

2025-02-10 Thread David Spickett via lldb-commits


@@ -82,20 +82,25 @@
 # CHECK-NEXT: (lldb) disassemble --name case2
 # CHECK-NEXT: command-disassemble.s.tmp`n1::case2:
 # CHECK-NEXT: command-disassemble.s.tmp[0x2044] <+0>: int$0x32
-# CHECK-NEXT: warning: Not disassembling a range because it is very large 
[0x2046-0x4046). To disassemble specify an instruction 
count limit, start/stop addresses or use the --force option.
+# CHECK-NEXT: warning: Not disassembling a function because it is very large 
[0x2046-0x4046). To disassemble specify an instruction 
count limit, start/stop addresses or use the --force option.

DavidSpickett wrote:

Would be nice if this was `function "name"` but not in the scope of this PR.

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


[Lldb-commits] [clang] [lldb] [lldb] Analyze enum promotion type during parsing (PR #115005)

2025-02-10 Thread Michael Buch via lldb-commits

Michael137 wrote:

> @Michael137 Changed the first argument of `computeEnumBits` to an `ArrayRef` 
> to avoid the template and so it can be still seamlessly used from Sema. On 
> LLDB side, I had to create a `SmallVector` and put enum constants there at 
> the point of their creation (`AddEnumerationValueToEnumerationType` returns a 
> pointer anyway) so that it can be passed to `computeEnumBits` as is. It's 
> only a vector of pointers, and it's discarded after, so if it's not a problem 
> here, I'll make the same changes in the Sema PR.

I don't think they necessarily had an issue with the template. It'd be silly 
for us to pay for the cost of constructing an intermediate vector if we're in 
control of the API and could avoid the work altogether. I'll comment on the 
other PR but I'd rather not construct this temporary just so we can pass it as 
an `ArrayRef`

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


[Lldb-commits] [lldb] [lldb] Fixing edge cases in "command source" (PR #126526)

2025-02-10 Thread via lldb-commits

jimingham wrote:

"command source" is another lldb command which this PR is not about...

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


[Lldb-commits] [lldb] [lldb] Fixing edge cases in "command source" (PR #126526)

2025-02-10 Thread via lldb-commits


@@ -320,25 +320,37 @@ void Function::GetStartLineSourceInfo(SupportFileSP 
&source_file_sp,
   }
 }
 
-void Function::GetEndLineSourceInfo(FileSpec &source_file, uint32_t &line_no) {
-  line_no = 0;
-  source_file.Clear();
-
-  // The -1 is kind of cheesy, but I want to get the last line entry for the
-  // given function, not the first entry of the next.
-  Address scratch_addr(GetAddressRange().GetBaseAddress());
-  scratch_addr.SetOffset(scratch_addr.GetOffset() +
- GetAddressRange().GetByteSize() - 1);
-
+llvm::Expected>
+Function::GetSourceInfo() {
+  SupportFileSP source_file_sp;
+  uint32_t start_line;
+  GetStartLineSourceInfo(source_file_sp, start_line);
   LineTable *line_table = m_comp_unit->GetLineTable();
-  if (line_table == nullptr)
-return;
+  if (start_line == 0 || !line_table) {

jimingham wrote:

Is the assumption here that the first source line of a function can never 
legitimately be a compiler-generated line that we assign 0?  Is that guaranteed 
even in optimized code?

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


[Lldb-commits] [lldb] [lldb] Fixing edge cases in "command source" (PR #126526)

2025-02-10 Thread via lldb-commits


@@ -784,14 +784,12 @@ class CommandObjectSourceList : public 
CommandObjectParsed {
 
   if (sc.block == nullptr) {
 // Not an inlined function
-sc.function->GetStartLineSourceInfo(start_file, start_line);
-if (start_line == 0) {
-  result.AppendErrorWithFormat("Could not find line information for "
-   "start of function: \"%s\".\n",
-   source_info.function.GetCString());
-  return 0;
-}
-sc.function->GetEndLineSourceInfo(end_file, end_line);
+auto expected_info = sc.function->GetSourceInfo();
+if (!expected_info)
+  result.AppendError(llvm::toString(expected_info.takeError()));

jimingham wrote:

This probably also means we're missing a test for when this fails?

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


[Lldb-commits] [lldb] [lldb] Devirtualize GetValueProperties (NFC) (PR #126583)

2025-02-10 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)


Changes

Nobody is overriding GetValueProperties, so in practice we're always using 
`m_collection_sp`, which means we don't need to check the pointer. The temlated 
helpers were already operating on `m_collection_sp` directly so this makes the 
rest of the class consistent.

---
Full diff: https://github.com/llvm/llvm-project/pull/126583.diff


2 Files Affected:

- (modified) lldb/include/lldb/Core/UserSettingsController.h (+1-3) 
- (modified) lldb/source/Core/UserSettingsController.cpp (+7-26) 


``diff
diff --git a/lldb/include/lldb/Core/UserSettingsController.h 
b/lldb/include/lldb/Core/UserSettingsController.h
index 32da7e05f7040f7..29e892fdba45bf3 100644
--- a/lldb/include/lldb/Core/UserSettingsController.h
+++ b/lldb/include/lldb/Core/UserSettingsController.h
@@ -38,9 +38,7 @@ class Properties {
 
   virtual ~Properties();
 
-  virtual lldb::OptionValuePropertiesSP GetValueProperties() const {
-// This function is virtual in case subclasses want to lazily implement
-// creating the properties.
+  lldb::OptionValuePropertiesSP GetValueProperties() const {
 return m_collection_sp;
   }
 
diff --git a/lldb/source/Core/UserSettingsController.cpp 
b/lldb/source/Core/UserSettingsController.cpp
index b57c1b0eef9b472..5408d64b406471f 100644
--- a/lldb/source/Core/UserSettingsController.cpp
+++ b/lldb/source/Core/UserSettingsController.cpp
@@ -40,64 +40,45 @@ Properties::~Properties() = default;
 lldb::OptionValueSP
 Properties::GetPropertyValue(const ExecutionContext *exe_ctx,
  llvm::StringRef path, Status &error) const {
-  OptionValuePropertiesSP properties_sp(GetValueProperties());
-  if (properties_sp)
-return properties_sp->GetSubValue(exe_ctx, path, error);
-  return lldb::OptionValueSP();
+  return m_collection_sp->GetSubValue(exe_ctx, path, error);
 }
 
 Status Properties::SetPropertyValue(const ExecutionContext *exe_ctx,
 VarSetOperationType op,
 llvm::StringRef path,
 llvm::StringRef value) {
-  OptionValuePropertiesSP properties_sp(GetValueProperties());
-  if (properties_sp)
-return properties_sp->SetSubValue(exe_ctx, op, path, value);
-  return Status::FromErrorString("no properties");
+  return m_collection_sp->SetSubValue(exe_ctx, op, path, value);
 }
 
 void Properties::DumpAllPropertyValues(const ExecutionContext *exe_ctx,
Stream &strm, uint32_t dump_mask,
bool is_json) {
-  OptionValuePropertiesSP properties_sp(GetValueProperties());
-  if (!properties_sp)
-return;
-
   if (is_json) {
-llvm::json::Value json = properties_sp->ToJSON(exe_ctx);
+llvm::json::Value json = m_collection_sp->ToJSON(exe_ctx);
 strm.Printf("%s", llvm::formatv("{0:2}", json).str().c_str());
   } else
-properties_sp->DumpValue(exe_ctx, strm, dump_mask);
+m_collection_sp->DumpValue(exe_ctx, strm, dump_mask);
 }
 
 void Properties::DumpAllDescriptions(CommandInterpreter &interpreter,
  Stream &strm) const {
   strm.PutCString("Top level variables:\n\n");
 
-  OptionValuePropertiesSP properties_sp(GetValueProperties());
-  if (properties_sp)
-return properties_sp->DumpAllDescriptions(interpreter, strm);
+  return m_collection_sp->DumpAllDescriptions(interpreter, strm);
 }
 
 Status Properties::DumpPropertyValue(const ExecutionContext *exe_ctx,
  Stream &strm,
  llvm::StringRef property_path,
  uint32_t dump_mask, bool is_json) {
-  OptionValuePropertiesSP properties_sp(GetValueProperties());
-  if (properties_sp) {
-return properties_sp->DumpPropertyValue(exe_ctx, strm, property_path,
+  return m_collection_sp->DumpPropertyValue(exe_ctx, strm, property_path,
 dump_mask, is_json);
-  }
-  return Status::FromErrorString("empty property list");
 }
 
 size_t
 Properties::Apropos(llvm::StringRef keyword,
 std::vector &matching_properties) const {
-  OptionValuePropertiesSP properties_sp(GetValueProperties());
-  if (properties_sp) {
-properties_sp->Apropos(keyword, matching_properties);
-  }
+  m_collection_sp->Apropos(keyword, matching_properties);
   return matching_properties.size();
 }
 

``




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


[Lldb-commits] [lldb] 622b8ed - [lldb] Fix a warning

2025-02-10 Thread Kazu Hirata via lldb-commits

Author: Kazu Hirata
Date: 2025-02-10T15:54:57-08:00
New Revision: 622b8edfc2485b21802778d1f4ae7aed340e

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

LOG: [lldb] Fix a warning

This patch fixes:

  lldb/source/Core/Telemetry.cpp:44:20: error: unused function
  'MakeUUID' [-Werror,-Wunused-function]

Added: 


Modified: 
lldb/source/Core/Telemetry.cpp

Removed: 




diff  --git a/lldb/source/Core/Telemetry.cpp b/lldb/source/Core/Telemetry.cpp
index a474a7663a0185a..d479488bbc39949 100644
--- a/lldb/source/Core/Telemetry.cpp
+++ b/lldb/source/Core/Telemetry.cpp
@@ -41,7 +41,7 @@ void LLDBBaseTelemetryInfo::serialize(Serializer &serializer) 
const {
 serializer.write("end_time", ToNanosec(end_time.value()));
 }
 
-static std::string MakeUUID(lldb_private::Debugger *debugger) {
+[[maybe_unused]] static std::string MakeUUID(lldb_private::Debugger *debugger) 
{
   uint8_t random_bytes[16];
   if (auto ec = llvm::getRandomBytes(random_bytes, 16)) {
 LLDB_LOG(GetLog(LLDBLog::Object),



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


[Lldb-commits] [lldb] [lldb][telemetry] Implement LLDB Telemetry (part 1) (PR #119716)

2025-02-10 Thread Kazu Hirata via lldb-commits

kazutakahirata wrote:

@oontvoo I've checked in 622b8edfc2485b21802778d1f4ae7aed340e to fix a 
warning.  I've put `[[maybe_unused]]` instead of removing the function, 
guessing that you might use this function in subsequent patches.

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


[Lldb-commits] [lldb] [lldb] Devirtualize GetValueProperties (NFC) (PR #126583)

2025-02-10 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere created 
https://github.com/llvm/llvm-project/pull/126583

Nobody is overriding GetValueProperties, so in practice we're always using 
`m_collection_sp`, which means we don't need to check the pointer. The temlated 
helpers were already operating on `m_collection_sp` directly so this makes the 
rest of the class consistent.

>From 56965c286f108b717b804ea549f4cc43b96d3214 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Mon, 10 Feb 2025 11:25:41 -0800
Subject: [PATCH] [lldb] Devirtualize GetValueProperties (NFC)

Nobody is overriding GetValueProperties, so in practice we're always
using `m_collection_sp`, which means we don't need to check the pointer.
The temlated helpers were already operating on `m_collection_sp`
directly so this makes the rest of the class consistent.
---
 .../lldb/Core/UserSettingsController.h|  4 +--
 lldb/source/Core/UserSettingsController.cpp   | 33 ---
 2 files changed, 8 insertions(+), 29 deletions(-)

diff --git a/lldb/include/lldb/Core/UserSettingsController.h 
b/lldb/include/lldb/Core/UserSettingsController.h
index 32da7e05f7040f7..29e892fdba45bf3 100644
--- a/lldb/include/lldb/Core/UserSettingsController.h
+++ b/lldb/include/lldb/Core/UserSettingsController.h
@@ -38,9 +38,7 @@ class Properties {
 
   virtual ~Properties();
 
-  virtual lldb::OptionValuePropertiesSP GetValueProperties() const {
-// This function is virtual in case subclasses want to lazily implement
-// creating the properties.
+  lldb::OptionValuePropertiesSP GetValueProperties() const {
 return m_collection_sp;
   }
 
diff --git a/lldb/source/Core/UserSettingsController.cpp 
b/lldb/source/Core/UserSettingsController.cpp
index b57c1b0eef9b472..5408d64b406471f 100644
--- a/lldb/source/Core/UserSettingsController.cpp
+++ b/lldb/source/Core/UserSettingsController.cpp
@@ -40,64 +40,45 @@ Properties::~Properties() = default;
 lldb::OptionValueSP
 Properties::GetPropertyValue(const ExecutionContext *exe_ctx,
  llvm::StringRef path, Status &error) const {
-  OptionValuePropertiesSP properties_sp(GetValueProperties());
-  if (properties_sp)
-return properties_sp->GetSubValue(exe_ctx, path, error);
-  return lldb::OptionValueSP();
+  return m_collection_sp->GetSubValue(exe_ctx, path, error);
 }
 
 Status Properties::SetPropertyValue(const ExecutionContext *exe_ctx,
 VarSetOperationType op,
 llvm::StringRef path,
 llvm::StringRef value) {
-  OptionValuePropertiesSP properties_sp(GetValueProperties());
-  if (properties_sp)
-return properties_sp->SetSubValue(exe_ctx, op, path, value);
-  return Status::FromErrorString("no properties");
+  return m_collection_sp->SetSubValue(exe_ctx, op, path, value);
 }
 
 void Properties::DumpAllPropertyValues(const ExecutionContext *exe_ctx,
Stream &strm, uint32_t dump_mask,
bool is_json) {
-  OptionValuePropertiesSP properties_sp(GetValueProperties());
-  if (!properties_sp)
-return;
-
   if (is_json) {
-llvm::json::Value json = properties_sp->ToJSON(exe_ctx);
+llvm::json::Value json = m_collection_sp->ToJSON(exe_ctx);
 strm.Printf("%s", llvm::formatv("{0:2}", json).str().c_str());
   } else
-properties_sp->DumpValue(exe_ctx, strm, dump_mask);
+m_collection_sp->DumpValue(exe_ctx, strm, dump_mask);
 }
 
 void Properties::DumpAllDescriptions(CommandInterpreter &interpreter,
  Stream &strm) const {
   strm.PutCString("Top level variables:\n\n");
 
-  OptionValuePropertiesSP properties_sp(GetValueProperties());
-  if (properties_sp)
-return properties_sp->DumpAllDescriptions(interpreter, strm);
+  return m_collection_sp->DumpAllDescriptions(interpreter, strm);
 }
 
 Status Properties::DumpPropertyValue(const ExecutionContext *exe_ctx,
  Stream &strm,
  llvm::StringRef property_path,
  uint32_t dump_mask, bool is_json) {
-  OptionValuePropertiesSP properties_sp(GetValueProperties());
-  if (properties_sp) {
-return properties_sp->DumpPropertyValue(exe_ctx, strm, property_path,
+  return m_collection_sp->DumpPropertyValue(exe_ctx, strm, property_path,
 dump_mask, is_json);
-  }
-  return Status::FromErrorString("empty property list");
 }
 
 size_t
 Properties::Apropos(llvm::StringRef keyword,
 std::vector &matching_properties) const {
-  OptionValuePropertiesSP properties_sp(GetValueProperties());
-  if (properties_sp) {
-properties_sp->Apropos(keyword, matching_properties);
-  }
+  m_collection_sp->Apropos(keyword, matching_properties);
   return matching_properties.size();
 }
 

___
lldb-commits mailing list
lld

[Lldb-commits] [lldb] Define TelemetryVendor plugin. (PR #126588)

2025-02-10 Thread Vy Nguyen via lldb-commits

https://github.com/oontvoo created 
https://github.com/llvm/llvm-project/pull/126588

Details:

Upstream in LLDB, we will have a default TelemetryVendor plugin will provide a 
default Config and NULL TelemetryManager. Downstream vendors can extend this to 
provide a vendor-specific Config along with a functional TelemetryManager 
instance.

>From c7734011094995c64137de6f8122033d2a981610 Mon Sep 17 00:00:00 2001
From: Vy Nguyen 
Date: Mon, 10 Feb 2025 14:44:11 -0500
Subject: [PATCH] Define TelemetryVendor plugin.

Details:

Upstream in LLDB, we will have a default TelemetryVendor plugin will provide a 
default Config and NULL TelemetryManager.
Downstream vendors can extend this to provide a vendor-specific Config along 
with a functional TelemetryManager instance.
---
 lldb/include/lldb/Core/TelemetryVendor.h | 39 +
 lldb/source/Core/TelemetryVendor.cpp | 43 
 2 files changed, 82 insertions(+)
 create mode 100644 lldb/include/lldb/Core/TelemetryVendor.h
 create mode 100644 lldb/source/Core/TelemetryVendor.cpp

diff --git a/lldb/include/lldb/Core/TelemetryVendor.h 
b/lldb/include/lldb/Core/TelemetryVendor.h
new file mode 100644
index 000..a2ab3b69fde4225
--- /dev/null
+++ b/lldb/include/lldb/Core/TelemetryVendor.h
@@ -0,0 +1,39 @@
+//===-- TelemetryVendor.h 
-===//
+//
+// 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_CORE_TELEMETRYVENDOR_H
+#define LLDB_CORE_TELEMETRYVENDOR_H
+
+#include "lldb/Core/PluginInterface.h"
+#include "lldb/Core/Telemetry.h"
+#include "llvm/Telemetry/Telemetry.h"
+
+#include 
+
+namespace lldb_private {
+
+class TelemetryVendor : public PluginInterface {
+public:
+  TelemetryVendor() = default;
+
+  llvm::StringRef GetPluginName() override;
+
+  static void Initialize();
+
+  static void Terminate();
+
+  static std::unique_ptr GetTelemetryConfig();
+  static void
+  SetTelemetryConfig(std::unique_ptr config);
+
+  static lldb::TelemetryManagerSP GetTelemetryManager();
+  static void SetTelemetryManager(const lldb::TelemetryManagerSP &manager_sp);
+};
+
+} // namespace lldb_private
+#endif // LLDB_CORE_TELEMETRYVENDOR_H
diff --git a/lldb/source/Core/TelemetryVendor.cpp 
b/lldb/source/Core/TelemetryVendor.cpp
new file mode 100644
index 000..520a01b9b1c7a3e
--- /dev/null
+++ b/lldb/source/Core/TelemetryVendor.cpp
@@ -0,0 +1,43 @@
+//===-- TelemetryVendor.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/Core/TelemetryVendor.h"
+
+namespace lldb_private {
+
+llvm::StringRef TelemetryVendor::GetPluginName() {
+  return "UpstreamTelemetryVendor";
+}
+
+void TelemetryVendor::Initialize() {
+  // The default (upstream) impl will have telemetry disabled by default.
+  SetTelemetryConfig(
+  std::make_unique(/*enable_telemetry*/ false));
+  SetTelemetryManager(nullptr);
+}
+
+static std::unique_ptr current_config;
+std::unique_ptr TelemetryVendor::GetTelemetryConfig() 
{
+  return current_config;
+}
+
+void TelemetryVendor::SetTelemetryConfig(
+std::unique_ptr config) {
+  current_config = std::move(config);
+}
+
+lldb::TelemetryManagerSP TelemetryVendor::GetTelemetryManager() {
+  static TelemteryManagerSP g_telemetry_manager_sp;
+  return g_telemetry_manager_sp;
+}
+
+void SetTelemetryManager(const lldb::TelemetryManagerSP &manager_sp) {
+  GetTelemetryManager() = manager_sp;
+}
+
+} // namespace lldb_private

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


[Lldb-commits] [lldb] Define TelemetryVendor plugin. (PR #126588)

2025-02-10 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Vy Nguyen (oontvoo)


Changes

Details:

Upstream in LLDB, we will have a default TelemetryVendor plugin will provide a 
default Config and NULL TelemetryManager. Downstream vendors can extend this to 
provide a vendor-specific Config along with a functional TelemetryManager 
instance.

---
Full diff: https://github.com/llvm/llvm-project/pull/126588.diff


2 Files Affected:

- (added) lldb/include/lldb/Core/TelemetryVendor.h (+39) 
- (added) lldb/source/Core/TelemetryVendor.cpp (+43) 


``diff
diff --git a/lldb/include/lldb/Core/TelemetryVendor.h 
b/lldb/include/lldb/Core/TelemetryVendor.h
new file mode 100644
index 000..a2ab3b69fde4225
--- /dev/null
+++ b/lldb/include/lldb/Core/TelemetryVendor.h
@@ -0,0 +1,39 @@
+//===-- TelemetryVendor.h 
-===//
+//
+// 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_CORE_TELEMETRYVENDOR_H
+#define LLDB_CORE_TELEMETRYVENDOR_H
+
+#include "lldb/Core/PluginInterface.h"
+#include "lldb/Core/Telemetry.h"
+#include "llvm/Telemetry/Telemetry.h"
+
+#include 
+
+namespace lldb_private {
+
+class TelemetryVendor : public PluginInterface {
+public:
+  TelemetryVendor() = default;
+
+  llvm::StringRef GetPluginName() override;
+
+  static void Initialize();
+
+  static void Terminate();
+
+  static std::unique_ptr GetTelemetryConfig();
+  static void
+  SetTelemetryConfig(std::unique_ptr config);
+
+  static lldb::TelemetryManagerSP GetTelemetryManager();
+  static void SetTelemetryManager(const lldb::TelemetryManagerSP &manager_sp);
+};
+
+} // namespace lldb_private
+#endif // LLDB_CORE_TELEMETRYVENDOR_H
diff --git a/lldb/source/Core/TelemetryVendor.cpp 
b/lldb/source/Core/TelemetryVendor.cpp
new file mode 100644
index 000..520a01b9b1c7a3e
--- /dev/null
+++ b/lldb/source/Core/TelemetryVendor.cpp
@@ -0,0 +1,43 @@
+//===-- TelemetryVendor.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/Core/TelemetryVendor.h"
+
+namespace lldb_private {
+
+llvm::StringRef TelemetryVendor::GetPluginName() {
+  return "UpstreamTelemetryVendor";
+}
+
+void TelemetryVendor::Initialize() {
+  // The default (upstream) impl will have telemetry disabled by default.
+  SetTelemetryConfig(
+  std::make_unique(/*enable_telemetry*/ false));
+  SetTelemetryManager(nullptr);
+}
+
+static std::unique_ptr current_config;
+std::unique_ptr TelemetryVendor::GetTelemetryConfig() 
{
+  return current_config;
+}
+
+void TelemetryVendor::SetTelemetryConfig(
+std::unique_ptr config) {
+  current_config = std::move(config);
+}
+
+lldb::TelemetryManagerSP TelemetryVendor::GetTelemetryManager() {
+  static TelemteryManagerSP g_telemetry_manager_sp;
+  return g_telemetry_manager_sp;
+}
+
+void SetTelemetryManager(const lldb::TelemetryManagerSP &manager_sp) {
+  GetTelemetryManager() = manager_sp;
+}
+
+} // namespace lldb_private

``




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


[Lldb-commits] [lldb] [lldb] Add a test for terminal dimensions (PR #126598)

2025-02-10 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere created 
https://github.com/llvm/llvm-project/pull/126598

Add a test for the term-width and term-height settings.

>From 6a12b9282228b24691dfcd4d8ec4d2b240747f54 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Mon, 10 Feb 2025 12:58:00 -0800
Subject: [PATCH] [lldb] Add a test for terminal dimensions

Add a test for the term-width and term-height settings.
---
 .../driver/terminal/TestTerminalDimensions.py | 22 +++
 1 file changed, 22 insertions(+)
 create mode 100644 lldb/test/API/driver/terminal/TestTerminalDimensions.py

diff --git a/lldb/test/API/driver/terminal/TestTerminalDimensions.py 
b/lldb/test/API/driver/terminal/TestTerminalDimensions.py
new file mode 100644
index 000..264cfa5950bfd33
--- /dev/null
+++ b/lldb/test/API/driver/terminal/TestTerminalDimensions.py
@@ -0,0 +1,22 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+from lldbsuite.test.lldbpexpect import PExpectTest
+
+
+class TerminalDimensionsTest(PExpectTest):
+NO_DEBUG_INFO_TESTCASE = True
+
+@skipIfAsan
+def test(self):
+"""Test that the lldb driver correctly reports the (PExpect) terminal 
dimension."""
+self.launch(dimensions=(40, 40), timeout=1)
+
+# Tests clear all the settings so we lose the launch values. Resize the
+# window to update the settings. These new values need to be different
+# to trigger a SIGWINCH.
+self.child.setwinsize(20, 60)
+
+self.expect("settings show term-height", ["term-height (unsigned) = 
20"])
+self.expect("settings show term-width", ["term-width (unsigned) = 60"])

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


[Lldb-commits] [lldb] [lldb] Add a test for terminal dimensions (PR #126598)

2025-02-10 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)


Changes

Add a test for the term-width and term-height settings.

---
Full diff: https://github.com/llvm/llvm-project/pull/126598.diff


1 Files Affected:

- (added) lldb/test/API/driver/terminal/TestTerminalDimensions.py (+22) 


``diff
diff --git a/lldb/test/API/driver/terminal/TestTerminalDimensions.py 
b/lldb/test/API/driver/terminal/TestTerminalDimensions.py
new file mode 100644
index 000..264cfa5950bfd33
--- /dev/null
+++ b/lldb/test/API/driver/terminal/TestTerminalDimensions.py
@@ -0,0 +1,22 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+from lldbsuite.test.lldbpexpect import PExpectTest
+
+
+class TerminalDimensionsTest(PExpectTest):
+NO_DEBUG_INFO_TESTCASE = True
+
+@skipIfAsan
+def test(self):
+"""Test that the lldb driver correctly reports the (PExpect) terminal 
dimension."""
+self.launch(dimensions=(40, 40), timeout=1)
+
+# Tests clear all the settings so we lose the launch values. Resize the
+# window to update the settings. These new values need to be different
+# to trigger a SIGWINCH.
+self.child.setwinsize(20, 60)
+
+self.expect("settings show term-height", ["term-height (unsigned) = 
20"])
+self.expect("settings show term-width", ["term-width (unsigned) = 60"])

``




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


[Lldb-commits] [lldb] [lldb] Add a test for terminal dimensions (PR #126598)

2025-02-10 Thread Jonas Devlieghere via lldb-commits

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


[Lldb-commits] [lldb] [lldb][telemetry] Implement LLDB Telemetry (part 1) (PR #119716)

2025-02-10 Thread Vy Nguyen via lldb-commits

https://github.com/oontvoo updated 
https://github.com/llvm/llvm-project/pull/119716

>From b7216d7c3edd5974d84612586fbabdef19037387 Mon Sep 17 00:00:00 2001
From: Vy Nguyen 
Date: Thu, 26 Dec 2024 20:50:40 -0500
Subject: [PATCH 01/15] Implement LLDB Telemetry (Part 1)

This contains only the concrete implementation of the framework to be used but 
no usages yet.

This is a subset of PR/98528.

I plan to send a few follow-up patches:
part2 : includes changes in the plugin-manager to set up the plugin stuff (ie., 
how to create a default vs vendor impl)
part3 (all of the following can be done in parallel):
* part 3_a: define DebuggerTelemetryInfo and related methods to collect data 
about debugger startup/exit
* part 3_b: define TargetTelemetryInfo and related methods to collect data 
about debug target(s)
* part 3_c: define CommandTelemetryInfo and related methods to collect data 
about debug-commands
* part 3_d: define ClientTelemtryInfo and related methods to collect data about 
lldb-dap/any other client
---
 lldb/include/lldb/Core/Telemetry.h| 101 ++
 lldb/include/lldb/lldb-enumerations.h |   4 +-
 lldb/source/Core/CMakeLists.txt   |   2 +
 lldb/source/Core/Telemetry.cpp|  92 +++
 lldb/test/CMakeLists.txt  |   3 +
 5 files changed, 200 insertions(+), 2 deletions(-)
 create mode 100644 lldb/include/lldb/Core/Telemetry.h
 create mode 100644 lldb/source/Core/Telemetry.cpp

diff --git a/lldb/include/lldb/Core/Telemetry.h 
b/lldb/include/lldb/Core/Telemetry.h
new file mode 100644
index 000..882511efd804d23
--- /dev/null
+++ b/lldb/include/lldb/Core/Telemetry.h
@@ -0,0 +1,101 @@
+//===-- Telemetry.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_CORE_TELEMETRY_H
+#define LLDB_CORE_TELEMETRY_H
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "lldb/Core/StructuredDataImpl.h"
+#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Utility/StructuredData.h"
+#include "lldb/lldb-forward.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/JSON.h"
+#include "llvm/Telemetry/Telemetry.h"
+
+namespace lldb_private {
+
+using llvm::telemetry::Destination;
+using llvm::telemetry::KindType;
+using llvm::telemetry::Serializer;
+using llvm::telemetry::TelemetryInfo;
+
+struct LldbEntryKind : public ::llvm::telemetry::EntryKind {
+  static const KindType BaseInfo = 0b11000;
+};
+
+/// Defines a convenient type for timestamp of various events.
+/// This is used by the EventStats below.
+using SteadyTimePoint = std::chrono::time_point;
+
+/// Various time (and possibly memory) statistics of an event.
+struct EventStats {
+  // REQUIRED: Start time of an event
+  SteadyTimePoint start;
+  // OPTIONAL: End time of an event - may be empty if not meaningful.
+  std::optional end;
+  // TBD: could add some memory stats here too?
+
+  EventStats() = default;
+  EventStats(SteadyTimePoint start) : start(start) {}
+  EventStats(SteadyTimePoint start, SteadyTimePoint end)
+  : start(start), end(end) {}
+};
+
+/// Describes the exit signal of an event.
+struct ExitDescription {
+  int exit_code;
+  std::string description;
+};
+
+struct LldbBaseTelemetryInfo : public TelemetryInfo {
+  EventStats stats;
+
+  std::optional exit_desc;
+
+  Debugger *debugger;
+
+  // For dyn_cast, isa, etc operations.
+  KindType getKind() const override { return LldbEntryKind::BaseInfo; }
+
+  static bool classof(const TelemetryInfo *t) {
+// Subclasses of this is also acceptable.
+return (t->getKind() & LldbEntryKind::BaseInfo) == LldbEntryKind::BaseInfo;
+  }
+
+  void serialize(Serializer &serializer) const override;
+};
+
+/// The base Telemetry manager instance in LLDB
+/// This class declares additional instrumentation points
+/// applicable to LLDB.
+class TelemetryManager : public llvm::telemetry::Manager {
+public:
+  TelemetryManager(std::unique_ptr config);
+
+  llvm::Error dispatch(TelemetryInfo *entry) override;
+
+  void addDestination(std::unique_ptr destination) override;
+
+private:
+  std::unique_ptr m_config;
+  const std::string m_session_uuid;
+  std::vector> m_destinations;
+};
+
+} // namespace lldb_private
+#endif // LLDB_CORE_TELEMETRY_H
diff --git a/lldb/include/lldb/lldb-enumerations.h 
b/lldb/include/lldb/lldb-enumerations.h
index 0094fcd596fdf70..f63e446b6042f62 100644
--- a/lldb/include/lldb/lldb-enumerations.h
+++ b/lldb/include/lldb/lldb-enumerations.h
@@ -257,8 +257,8 @@ enum StopReason {
 };
 
 /// Command Return Status Types.
-enum ReturnStatus {
-  eReturnStatusInvalid,
+enum ReturnStatus : int {
+  eReturnStatusInva

[Lldb-commits] [lldb] 50317ca - [lldb][telemetry] Implement LLDB Telemetry (part 1) (#119716)

2025-02-10 Thread via lldb-commits

Author: Vy Nguyen
Date: 2025-02-10T13:59:52-05:00
New Revision: 50317ca13f6ad9b2196f92f8c719f5c31e5d6812

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

LOG: [lldb][telemetry] Implement LLDB Telemetry (part 1) (#119716)

Details:
- This is a subset of PR/98528.( Pavel's suggestion was to split up the
patch to make reviewing easier)
- This contains only the concrete implementation of the framework to be
used but no usages yet.
- I plan to send a few follow-up patches:
+ part2 : includes changes in the plugin-manager to set up the plugin
stuff (ie., how to create a default vs vendor impl)
  + part3 (all of the following can be done in parallel):
* part 3_a: define DebuggerTelemetryInfo and related methods to collect
data about debugger startup/exit
* part 3_b: define TargetTelemetryInfo and related methods to collect
data about debug target(s)
* part 3_c: define CommandTelemetryInfo and related methods to collect
data about debug-commands
* part 3_d: define ClientTelemtryInfo and related methods to collect
data about lldb-dap/any other client

-

Co-authored-by: Pavel Labath 
Co-authored-by: Jonas Devlieghere 

Added: 
lldb/include/lldb/Core/Telemetry.h
lldb/source/Core/Telemetry.cpp

Modified: 
lldb/source/Core/CMakeLists.txt

Removed: 




diff  --git a/lldb/include/lldb/Core/Telemetry.h 
b/lldb/include/lldb/Core/Telemetry.h
new file mode 100644
index 000..60a7097de5eeef5
--- /dev/null
+++ b/lldb/include/lldb/Core/Telemetry.h
@@ -0,0 +1,74 @@
+//===-- Telemetry.h 
---===//
+//
+// 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_CORE_TELEMETRY_H
+#define LLDB_CORE_TELEMETRY_H
+
+#include "lldb/Core/StructuredDataImpl.h"
+#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Utility/StructuredData.h"
+#include "lldb/lldb-forward.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/JSON.h"
+#include "llvm/Telemetry/Telemetry.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+namespace lldb_private {
+namespace telemetry {
+
+struct LLDBEntryKind : public ::llvm::telemetry::EntryKind {
+  static const llvm::telemetry::KindType BaseInfo = 0b11000;
+};
+
+/// Defines a convenient type for timestamp of various events.
+using SteadyTimePoint = std::chrono::time_point;
+struct LLDBBaseTelemetryInfo : public llvm::telemetry::TelemetryInfo {
+  /// Start time of an event
+  SteadyTimePoint start_time;
+  /// End time of an event - may be empty if not meaningful.
+  std::optional end_time;
+  // TBD: could add some memory stats here too?
+
+  Debugger *debugger;
+
+  // For dyn_cast, isa, etc operations.
+  llvm::telemetry::KindType getKind() const override {
+return LLDBEntryKind::BaseInfo;
+  }
+
+  static bool classof(const llvm::telemetry::TelemetryInfo *t) {
+// Subclasses of this is also acceptable.
+return (t->getKind() & LLDBEntryKind::BaseInfo) == LLDBEntryKind::BaseInfo;
+  }
+
+  void serialize(llvm::telemetry::Serializer &serializer) const override;
+};
+
+/// The base Telemetry manager instance in LLDB
+/// This class declares additional instrumentation points
+/// applicable to LLDB.
+class TelemetryManager : public llvm::telemetry::Manager {
+public:
+  TelemetryManager(std::unique_ptr config);
+
+  llvm::Error preDispatch(llvm::telemetry::TelemetryInfo *entry) override;
+
+private:
+  std::unique_ptr m_config;
+};
+
+} // namespace telemetry
+} // namespace lldb_private
+#endif // LLDB_CORE_TELEMETRY_H

diff  --git a/lldb/source/Core/CMakeLists.txt b/lldb/source/Core/CMakeLists.txt
index 6d14f7a87764e05..4b1f41816201608 100644
--- a/lldb/source/Core/CMakeLists.txt
+++ b/lldb/source/Core/CMakeLists.txt
@@ -16,6 +16,11 @@ if (LLDB_ENABLE_CURSES)
   endif()
 endif()
 
+if (LLVM_BUILD_TELEMETRY)
+   set(TELEMETRY_SOURCES Telemetry.cpp)
+   set(TELEMETRY_DEPS Telemetry)
+endif()
+
 # TODO: Add property `NO_PLUGIN_DEPENDENCIES` to lldbCore
 add_lldb_library(lldbCore
   Address.cpp
@@ -55,7 +60,8 @@ add_lldb_library(lldbCore
   ThreadedCommunication.cpp
   UserSettingsController.cpp
   Value.cpp
-
+  ${TELEMETRY_SOURCES}
+  PARTIAL_SOURCES_INTENDED
   DEPENDS
 clang-tablegen-targets
 
@@ -80,6 +86,7 @@ add_lldb_library(lldbCore
 Support
 Demangle
 TargetParser
+${TELEMETRY_DEPS}
   )
 
 add_dependencies(lldbCore

diff  --git a/lldb/source/Core/Telemetry.cpp b/lldb/source/Core/Telemetry.cpp
new file mode 100644
index 000..a474a7663a0185a

[Lldb-commits] [lldb] [lldb][telemetry] Implement LLDB Telemetry (part 1) (PR #119716)

2025-02-10 Thread Vy Nguyen via lldb-commits

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


[Lldb-commits] [lldb] [lldb-dap] Silence Wunused-result warning (PR #126580)

2025-02-10 Thread Keith Smiley via lldb-commits

https://github.com/keith created 
https://github.com/llvm/llvm-project/pull/126580

None

>From bb41fdf6021c7a62bf77096bc4ce31e8e9311577 Mon Sep 17 00:00:00 2001
From: Keith Smiley 
Date: Mon, 10 Feb 2025 19:00:31 +
Subject: [PATCH] [lldb-dap] Silence Wunused-result warning

---
 lldb/tools/lldb-dap/OutputRedirector.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/tools/lldb-dap/OutputRedirector.cpp 
b/lldb/tools/lldb-dap/OutputRedirector.cpp
index 7935e17a653bec3..a23572ab7ae0425 100644
--- a/lldb/tools/lldb-dap/OutputRedirector.cpp
+++ b/lldb/tools/lldb-dap/OutputRedirector.cpp
@@ -86,7 +86,7 @@ void OutputRedirector::Stop() {
 // write descriptor is duplicated (to stdout/err or to another process).
 // Write a null byte to ensure the read call returns.
 char buf[] = "\0";
-::write(fd, buf, sizeof(buf));
+(void)::write(fd, buf, sizeof(buf));
 ::close(fd);
 m_forwarder.join();
   }

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


[Lldb-commits] [lldb] [lldb-dap] Silence Wunused-result warning (PR #126580)

2025-02-10 Thread Keith Smiley via lldb-commits

keith wrote:

showed up since 
https://github.com/llvm/llvm-project/commit/adb9ef035552d7fc42a34560677f89f4f6421295

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


[Lldb-commits] [lldb] [lldb-dap] Silence Wunused-result warning (PR #126580)

2025-02-10 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Keith Smiley (keith)


Changes



---
Full diff: https://github.com/llvm/llvm-project/pull/126580.diff


1 Files Affected:

- (modified) lldb/tools/lldb-dap/OutputRedirector.cpp (+1-1) 


``diff
diff --git a/lldb/tools/lldb-dap/OutputRedirector.cpp 
b/lldb/tools/lldb-dap/OutputRedirector.cpp
index 7935e17a653bec3..a23572ab7ae0425 100644
--- a/lldb/tools/lldb-dap/OutputRedirector.cpp
+++ b/lldb/tools/lldb-dap/OutputRedirector.cpp
@@ -86,7 +86,7 @@ void OutputRedirector::Stop() {
 // write descriptor is duplicated (to stdout/err or to another process).
 // Write a null byte to ensure the read call returns.
 char buf[] = "\0";
-::write(fd, buf, sizeof(buf));
+(void)::write(fd, buf, sizeof(buf));
 ::close(fd);
 m_forwarder.join();
   }

``




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


[Lldb-commits] [lldb] [lldb-dap] Silence Wunused-result warning (PR #126580)

2025-02-10 Thread Keith Smiley via lldb-commits

keith wrote:

```
lldb/tools/lldb-dap/OutputRedirector.cpp:89:5: error: ignoring return value of 
function declared with 'warn_unused_result' attribute [-Werror,-Wunused-result]
   89 | ::write(fd, buf, sizeof(buf));
  | ^~~ 
1 error generated.
```

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


[Lldb-commits] [lldb] [lldb] Assert on invalid default {S, U}Int64 (NFC) (PR #126590)

2025-02-10 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere created 
https://github.com/llvm/llvm-project/pull/126590

Both the default value and the min/max value are within LLDB's control, so an 
assert is more appropriate than a runtime check.

>From 4c2391af01c626719de14aa975988df921b5bfd7 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Mon, 10 Feb 2025 11:56:52 -0800
Subject: [PATCH] [lldb] Assert on invalid default {S,U}Int64 (NFC)

Both the default value and the min/max value are within LLDB's control,
so an assert is more appropriate than a runtime check.

(cherry picked from commit 1a1d0d5a12e310e23e8fd63eaa810c6af5420312)
---
 lldb/include/lldb/Interpreter/OptionValueSInt64.h |  9 -
 lldb/include/lldb/Interpreter/OptionValueUInt64.h | 13 ++---
 2 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/lldb/include/lldb/Interpreter/OptionValueSInt64.h 
b/lldb/include/lldb/Interpreter/OptionValueSInt64.h
index 3cf41d38c0ef0c5..f7e72684e4102f9 100644
--- a/lldb/include/lldb/Interpreter/OptionValueSInt64.h
+++ b/lldb/include/lldb/Interpreter/OptionValueSInt64.h
@@ -68,11 +68,10 @@ class OptionValueSInt64 : public 
Cloneable {
   }
 
   bool SetDefaultValue(int64_t value) {
-if (value >= m_min_value && value <= m_max_value) {
-  m_default_value = value;
-  return true;
-}
-return false;
+assert(value >= m_min_value && value <= m_max_value &&
+   "disallowed default value");
+m_default_value = value;
+return true;
   }
 
   void SetMinimumValue(int64_t v) { m_min_value = v; }
diff --git a/lldb/include/lldb/Interpreter/OptionValueUInt64.h 
b/lldb/include/lldb/Interpreter/OptionValueUInt64.h
index 07076075790c674..5cccff177cb1d60 100644
--- a/lldb/include/lldb/Interpreter/OptionValueUInt64.h
+++ b/lldb/include/lldb/Interpreter/OptionValueUInt64.h
@@ -73,18 +73,17 @@ class OptionValueUInt64 : public 
Cloneable {
   }
 
   bool SetDefaultValue(uint64_t value) {
-if (value >= m_min_value && value <= m_max_value) {
-  m_default_value = value;
-  return true;
-}
-return false;
+assert(value >= m_min_value && value <= m_max_value &&
+   "disallowed default value");
+m_default_value = value;
+return true;
   }
 
-  void SetMinimumValue(int64_t v) { m_min_value = v; }
+  void SetMinimumValue(uint64_t v) { m_min_value = v; }
 
   uint64_t GetMinimumValue() const { return m_min_value; }
 
-  void SetMaximumValue(int64_t v) { m_max_value = v; }
+  void SetMaximumValue(uint64_t v) { m_max_value = v; }
 
   uint64_t GetMaximumValue() const { return m_max_value; }
 

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


[Lldb-commits] [lldb] [lldb] Assert on invalid default {S, U}Int64 (NFC) (PR #126590)

2025-02-10 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)


Changes

Both the default value and the min/max value are within LLDB's control, so an 
assert is more appropriate than a runtime check.

---
Full diff: https://github.com/llvm/llvm-project/pull/126590.diff


2 Files Affected:

- (modified) lldb/include/lldb/Interpreter/OptionValueSInt64.h (+4-5) 
- (modified) lldb/include/lldb/Interpreter/OptionValueUInt64.h (+6-7) 


``diff
diff --git a/lldb/include/lldb/Interpreter/OptionValueSInt64.h 
b/lldb/include/lldb/Interpreter/OptionValueSInt64.h
index 3cf41d38c0ef0c5..f7e72684e4102f9 100644
--- a/lldb/include/lldb/Interpreter/OptionValueSInt64.h
+++ b/lldb/include/lldb/Interpreter/OptionValueSInt64.h
@@ -68,11 +68,10 @@ class OptionValueSInt64 : public 
Cloneable {
   }
 
   bool SetDefaultValue(int64_t value) {
-if (value >= m_min_value && value <= m_max_value) {
-  m_default_value = value;
-  return true;
-}
-return false;
+assert(value >= m_min_value && value <= m_max_value &&
+   "disallowed default value");
+m_default_value = value;
+return true;
   }
 
   void SetMinimumValue(int64_t v) { m_min_value = v; }
diff --git a/lldb/include/lldb/Interpreter/OptionValueUInt64.h 
b/lldb/include/lldb/Interpreter/OptionValueUInt64.h
index 07076075790c674..5cccff177cb1d60 100644
--- a/lldb/include/lldb/Interpreter/OptionValueUInt64.h
+++ b/lldb/include/lldb/Interpreter/OptionValueUInt64.h
@@ -73,18 +73,17 @@ class OptionValueUInt64 : public 
Cloneable {
   }
 
   bool SetDefaultValue(uint64_t value) {
-if (value >= m_min_value && value <= m_max_value) {
-  m_default_value = value;
-  return true;
-}
-return false;
+assert(value >= m_min_value && value <= m_max_value &&
+   "disallowed default value");
+m_default_value = value;
+return true;
   }
 
-  void SetMinimumValue(int64_t v) { m_min_value = v; }
+  void SetMinimumValue(uint64_t v) { m_min_value = v; }
 
   uint64_t GetMinimumValue() const { return m_min_value; }
 
-  void SetMaximumValue(int64_t v) { m_max_value = v; }
+  void SetMaximumValue(uint64_t v) { m_max_value = v; }
 
   uint64_t GetMaximumValue() const { return m_max_value; }
 

``




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


[Lldb-commits] [lldb] [lldb] Synchronize Debugger's stdout and stderr at the StreamFile level (PR #126630)

2025-02-10 Thread Alex Langford via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Synchronize Debugger's stdout and stderr at the StreamFile level (PR #126630)

2025-02-10 Thread Alex Langford via lldb-commits


@@ -7574,7 +7574,9 @@ IOHandlerCursesGUI::IOHandlerCursesGUI(Debugger &debugger)
 void IOHandlerCursesGUI::Activate() {
   IOHandler::Activate();
   if (!m_app_ap) {
-m_app_ap = std::make_unique(GetInputFILE(), GetOutputFILE());
+m_app_ap = std::make_unique(

bulbazord wrote:

nit: while you're here, `m_app_ap` -> `m_app_up`? auto pointers are dead, long 
live auto pointers!

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


[Lldb-commits] [lldb] [lldb] Synchronize Debugger's stdout and stderr at the StreamFile level (PR #126630)

2025-02-10 Thread Alex Langford via lldb-commits

https://github.com/bulbazord commented:

Overall looks fine, kind of terrified of the number of unguarded `fprintf` 
calls in Editline, but maybe it's fine?

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


[Lldb-commits] [lldb] [lldb] Synchronize Debugger's stdout and stderr at the StreamFile level (PR #126630)

2025-02-10 Thread Alex Langford via lldb-commits


@@ -393,7 +394,7 @@ void Editline::MoveCursor(CursorLocation from, 
CursorLocation to) {
   int fromLine = GetLineIndexForLocation(from, editline_cursor_row);
   int toLine = GetLineIndexForLocation(to, editline_cursor_row);
   if (toLine != fromLine) {
-fprintf(m_output_file,
+fprintf(m_output_stream_sp->GetFile().GetStream(),

bulbazord wrote:

There are a lot of unguarded calls to `fprintf` and `fputs` in this file. Are 
there some guarantees about the state of the synchronized stream when these 
functions are executed? Or do we just have tons of unsynchronized writes to the 
output stream? :D 

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


[Lldb-commits] [lldb] [lldb][telemetry] Implement LLDB Telemetry (part 1) (PR #119716)

2025-02-10 Thread Jonas Devlieghere via lldb-commits


@@ -0,0 +1,74 @@
+//===-- Telemetry.h 
---===//
+//
+// 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_CORE_TELEMETRY_H
+#define LLDB_CORE_TELEMETRY_H
+
+#include "lldb/Core/StructuredDataImpl.h"
+#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Utility/StructuredData.h"
+#include "lldb/lldb-forward.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/JSON.h"
+#include "llvm/Telemetry/Telemetry.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+namespace lldb_private {
+namespace telemetry {
+
+struct LLDBEntryKind : public ::llvm::telemetry::EntryKind {
+  static const llvm::telemetry::KindType BaseInfo = 0b11000;
+};
+
+/// Defines a convenient type for timestamp of various events.
+using SteadyTimePoint = std::chrono::time_point;
+struct LLDBBaseTelemetryInfo : public llvm::telemetry::TelemetryInfo {
+  /// Start time of an event
+  SteadyTimePoint start_time;
+  /// End time of an event - may be empty if not meaningful.
+  std::optional end_time;
+  // TBD: could add some memory stats here too?
+
+  Debugger *debugger;
+
+  // For dyn_cast, isa, etc operations.

JDevlieghere wrote:

Everywhere else we use `/// LLVM RTTI support.`

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


[Lldb-commits] [lldb] [lldb][telemetry] Implement LLDB Telemetry (part 1) (PR #119716)

2025-02-10 Thread Jonas Devlieghere via lldb-commits


@@ -0,0 +1,69 @@
+//===-- Telemetry.cpp 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "lldb/Core/Telemetry.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/UUID.h"
+#include "lldb/lldb-enumerations.h"
+#include "lldb/lldb-forward.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/RandomNumberGenerator.h"
+#include "llvm/Telemetry/Telemetry.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+
+namespace lldb_private {
+namespace telemetry {
+
+using ::llvm::Error;
+using ::llvm::telemetry::Destination;
+using ::llvm::telemetry::Serializer;
+using ::llvm::telemetry::TelemetryInfo;
+
+static uint64_t ToNanosec(const SteadyTimePoint Point) {
+  return std::chrono::nanoseconds(Point.time_since_epoch()).count();
+}
+
+void LLDBBaseTelemetryInfo::serialize(Serializer &serializer) const {
+  serializer.write("entry_kind", getKind());
+  serializer.write("session_id", SessionId);
+  serializer.write("start_time", ToNanosec(start_time));
+  if (end_time.has_value())
+serializer.write("end_time", ToNanosec(end_time.value()));
+}
+
+static std::string MakeUUID(lldb_private::Debugger *debugger) {
+  uint8_t random_bytes[16];
+  if (auto ec = llvm::getRandomBytes(random_bytes, 16)) {
+LLDB_LOG(GetLog(LLDBLog::Object),
+ "Failed to generate random bytes for UUID: {0}", ec.message());
+// fallback to using timestamp + debugger ID.
+return llvm::formatv(
+"{0}_{1}", std::chrono::steady_clock::now().time_since_epoch().count(),
+debugger->GetID());
+  }
+  return lldb_private::UUID(random_bytes).GetAsString();
+}
+
+TelemetryManager::TelemetryManager(
+std::unique_ptr config)

JDevlieghere wrote:

You're using `using ::llvm::telemetry::Foo` for some other things but not for 
the Config. Why not use `using namespace llvm::telemetry` instead? 

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


[Lldb-commits] [lldb] [lldb][telemetry] Implement LLDB Telemetry (part 1) (PR #119716)

2025-02-10 Thread Jonas Devlieghere via lldb-commits


@@ -0,0 +1,74 @@
+//===-- Telemetry.h 
---===//
+//
+// 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_CORE_TELEMETRY_H
+#define LLDB_CORE_TELEMETRY_H
+
+#include "lldb/Core/StructuredDataImpl.h"
+#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Utility/StructuredData.h"
+#include "lldb/lldb-forward.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/JSON.h"
+#include "llvm/Telemetry/Telemetry.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+namespace lldb_private {
+namespace telemetry {
+
+struct LLDBEntryKind : public ::llvm::telemetry::EntryKind {
+  static const llvm::telemetry::KindType BaseInfo = 0b11000;
+};
+
+/// Defines a convenient type for timestamp of various events.
+using SteadyTimePoint = std::chrono::time_point;
+struct LLDBBaseTelemetryInfo : public llvm::telemetry::TelemetryInfo {
+  /// Start time of an event
+  SteadyTimePoint start_time;
+  /// End time of an event - may be empty if not meaningful.
+  std::optional end_time;
+  // TBD: could add some memory stats here too?
+
+  Debugger *debugger;
+
+  // For dyn_cast, isa, etc operations.
+  llvm::telemetry::KindType getKind() const override {
+return LLDBEntryKind::BaseInfo;
+  }
+
+  static bool classof(const llvm::telemetry::TelemetryInfo *t) {
+// Subclasses of this is also acceptable.
+return (t->getKind() & LLDBEntryKind::BaseInfo) == LLDBEntryKind::BaseInfo;
+  }
+
+  void serialize(llvm::telemetry::Serializer &serializer) const override;
+};
+
+/// The base Telemetry manager instance in LLDB

JDevlieghere wrote:

Nit: missing period. 

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


[Lldb-commits] [lldb] [lldb][telemetry] Implement LLDB Telemetry (part 1) (PR #119716)

2025-02-10 Thread Jonas Devlieghere via lldb-commits


@@ -0,0 +1,69 @@
+//===-- Telemetry.cpp 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "lldb/Core/Telemetry.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/UUID.h"
+#include "lldb/lldb-enumerations.h"
+#include "lldb/lldb-forward.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/RandomNumberGenerator.h"
+#include "llvm/Telemetry/Telemetry.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+
+namespace lldb_private {
+namespace telemetry {
+
+using ::llvm::Error;
+using ::llvm::telemetry::Destination;
+using ::llvm::telemetry::Serializer;
+using ::llvm::telemetry::TelemetryInfo;
+
+static uint64_t ToNanosec(const SteadyTimePoint Point) {
+  return std::chrono::nanoseconds(Point.time_since_epoch()).count();
+}
+
+void LLDBBaseTelemetryInfo::serialize(Serializer &serializer) const {
+  serializer.write("entry_kind", getKind());
+  serializer.write("session_id", SessionId);
+  serializer.write("start_time", ToNanosec(start_time));
+  if (end_time.has_value())
+serializer.write("end_time", ToNanosec(end_time.value()));
+}
+
+static std::string MakeUUID(lldb_private::Debugger *debugger) {

JDevlieghere wrote:

`s/lldb_private:://`, goes for the whole file. 

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


[Lldb-commits] [lldb] [lldb] Add a test for terminal dimensions (PR #126598)

2025-02-10 Thread Jonas Devlieghere via lldb-commits


@@ -0,0 +1,22 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+from lldbsuite.test.lldbpexpect import PExpectTest
+
+
+class TerminalDimensionsTest(PExpectTest):
+NO_DEBUG_INFO_TESTCASE = True
+
+@skipIfAsan
+def test(self):
+"""Test that the lldb driver correctly reports the (PExpect) terminal 
dimension."""
+self.launch(dimensions=(40, 40), timeout=1)

JDevlieghere wrote:

They matter in the sense that they need to be different (noted in the comment 
below). I. need to remove the `, timeout=1` because that was just for local 
debugging. 

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


[Lldb-commits] [lldb] [lldb] Add a test for terminal dimensions (PR #126598)

2025-02-10 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere updated 
https://github.com/llvm/llvm-project/pull/126598

>From 6a12b9282228b24691dfcd4d8ec4d2b240747f54 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Mon, 10 Feb 2025 12:58:00 -0800
Subject: [PATCH 1/2] [lldb] Add a test for terminal dimensions

Add a test for the term-width and term-height settings.
---
 .../driver/terminal/TestTerminalDimensions.py | 22 +++
 1 file changed, 22 insertions(+)
 create mode 100644 lldb/test/API/driver/terminal/TestTerminalDimensions.py

diff --git a/lldb/test/API/driver/terminal/TestTerminalDimensions.py 
b/lldb/test/API/driver/terminal/TestTerminalDimensions.py
new file mode 100644
index 000..264cfa5950bfd33
--- /dev/null
+++ b/lldb/test/API/driver/terminal/TestTerminalDimensions.py
@@ -0,0 +1,22 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+from lldbsuite.test.lldbpexpect import PExpectTest
+
+
+class TerminalDimensionsTest(PExpectTest):
+NO_DEBUG_INFO_TESTCASE = True
+
+@skipIfAsan
+def test(self):
+"""Test that the lldb driver correctly reports the (PExpect) terminal 
dimension."""
+self.launch(dimensions=(40, 40), timeout=1)
+
+# Tests clear all the settings so we lose the launch values. Resize the
+# window to update the settings. These new values need to be different
+# to trigger a SIGWINCH.
+self.child.setwinsize(20, 60)
+
+self.expect("settings show term-height", ["term-height (unsigned) = 
20"])
+self.expect("settings show term-width", ["term-width (unsigned) = 60"])

>From e277b6e964305daafc4e561c3a78baac961149af Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Mon, 10 Feb 2025 14:38:23 -0800
Subject: [PATCH 2/2] Remove timeout

---
 lldb/test/API/driver/terminal/TestTerminalDimensions.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/test/API/driver/terminal/TestTerminalDimensions.py 
b/lldb/test/API/driver/terminal/TestTerminalDimensions.py
index 264cfa5950bfd33..9ab3745613994a6 100644
--- a/lldb/test/API/driver/terminal/TestTerminalDimensions.py
+++ b/lldb/test/API/driver/terminal/TestTerminalDimensions.py
@@ -11,7 +11,7 @@ class TerminalDimensionsTest(PExpectTest):
 @skipIfAsan
 def test(self):
 """Test that the lldb driver correctly reports the (PExpect) terminal 
dimension."""
-self.launch(dimensions=(40, 40), timeout=1)
+self.launch(dimensions=(40, 40))
 
 # Tests clear all the settings so we lose the launch values. Resize the
 # window to update the settings. These new values need to be different

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


[Lldb-commits] [lldb] [lldb][telemetry] Implement LLDB Telemetry (part 1) (PR #119716)

2025-02-10 Thread Jonas Devlieghere via lldb-commits


@@ -0,0 +1,69 @@
+//===-- Telemetry.cpp 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "lldb/Core/Telemetry.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/UUID.h"
+#include "lldb/lldb-enumerations.h"
+#include "lldb/lldb-forward.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/RandomNumberGenerator.h"
+#include "llvm/Telemetry/Telemetry.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+
+namespace lldb_private {
+namespace telemetry {
+
+using ::llvm::Error;
+using ::llvm::telemetry::Destination;
+using ::llvm::telemetry::Serializer;
+using ::llvm::telemetry::TelemetryInfo;
+
+static uint64_t ToNanosec(const SteadyTimePoint Point) {
+  return std::chrono::nanoseconds(Point.time_since_epoch()).count();
+}
+
+void LLDBBaseTelemetryInfo::serialize(Serializer &serializer) const {
+  serializer.write("entry_kind", getKind());
+  serializer.write("session_id", SessionId);
+  serializer.write("start_time", ToNanosec(start_time));
+  if (end_time.has_value())
+serializer.write("end_time", ToNanosec(end_time.value()));
+}
+
+static std::string MakeUUID(lldb_private::Debugger *debugger) {
+  uint8_t random_bytes[16];
+  if (auto ec = llvm::getRandomBytes(random_bytes, 16)) {
+LLDB_LOG(GetLog(LLDBLog::Object),
+ "Failed to generate random bytes for UUID: {0}", ec.message());
+// fallback to using timestamp + debugger ID.

JDevlieghere wrote:

`s/fallback/Fallback/`

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


[Lldb-commits] [lldb] [lldb] Add a test for terminal dimensions (PR #126598)

2025-02-10 Thread Jonas Devlieghere via lldb-commits

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


[Lldb-commits] [lldb] d81b604 - [lldb] Add a test for terminal dimensions (#126598)

2025-02-10 Thread via lldb-commits

Author: Jonas Devlieghere
Date: 2025-02-10T14:46:03-08:00
New Revision: d81b604656c189a9d4e9f0d14b0f4d52f454deac

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

LOG: [lldb] Add a test for terminal dimensions (#126598)

Add a test for the `term-width` and `term-height` settings. I thought I
was hitting bug because in my statusline test I was getting the default
values when running under PExpect. It turned out hat the issue is that
we clear the settings at the start of the test. The Editline tests
aren't affected by this because Editline provides its own functions to
get the terminal dimensions and explicitly does not rely on LLDB's
settings (presumably exactly because of this behavior).

Added: 
lldb/test/API/driver/terminal/TestTerminalDimensions.py

Modified: 


Removed: 




diff  --git a/lldb/test/API/driver/terminal/TestTerminalDimensions.py 
b/lldb/test/API/driver/terminal/TestTerminalDimensions.py
new file mode 100644
index 000..9ab3745613994a6
--- /dev/null
+++ b/lldb/test/API/driver/terminal/TestTerminalDimensions.py
@@ -0,0 +1,22 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+from lldbsuite.test.lldbpexpect import PExpectTest
+
+
+class TerminalDimensionsTest(PExpectTest):
+NO_DEBUG_INFO_TESTCASE = True
+
+@skipIfAsan
+def test(self):
+"""Test that the lldb driver correctly reports the (PExpect) terminal 
dimension."""
+self.launch(dimensions=(40, 40))
+
+# Tests clear all the settings so we lose the launch values. Resize the
+# window to update the settings. These new values need to be 
diff erent
+# to trigger a SIGWINCH.
+self.child.setwinsize(20, 60)
+
+self.expect("settings show term-height", ["term-height (unsigned) = 
20"])
+self.expect("settings show term-width", ["term-width (unsigned) = 60"])



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


[Lldb-commits] [lldb] [lldb] Assert on invalid default {S, U}Int64 (NFC) (PR #126590)

2025-02-10 Thread Alex Langford via lldb-commits


@@ -68,11 +68,10 @@ class OptionValueSInt64 : public 
Cloneable {
   }
 
   bool SetDefaultValue(int64_t value) {
-if (value >= m_min_value && value <= m_max_value) {
-  m_default_value = value;
-  return true;
-}
-return false;
+assert(value >= m_min_value && value <= m_max_value &&

bulbazord wrote:

A few things I'd like to make sure of:
- What happens in release configurations where assertions are compiled out? 
Might this allow you to set an invalid value?
- Can you call `SetDefaultValue` by typing a command in lldb? If so, an 
assertion seems like the wrong way of catching this. I ask because this is in 
OptionValue, which are involved in parsing commands in LLDB.

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


[Lldb-commits] [lldb] [lldb] [darwin] Upstream a few DriverKit cases (PR #126604)

2025-02-10 Thread Jason Molenda via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Fix ubsan violation with plugin loading (PR #126652)

2025-02-10 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Keith Smiley (keith)


Changes

This typedef doesn't match the signature below, specifically the signature 
takes a `lldb:SBDebugger` vs this was defined as `lldb:SBDebugger&`.

```
lldb/source/API/SBDebugger.cpp:199:13: runtime error: call to function 
lldb::PluginInitialize(lldb::SBDebugger) through pointer to incorrect function 
type 'bool (*)(lldb::SBDebugger &)'
.../CustomPlugin.cpp:134: note: lldb::PluginInitialize(lldb::SBDebugger) 
defined here
```

---
Full diff: https://github.com/llvm/llvm-project/pull/126652.diff


1 Files Affected:

- (modified) lldb/source/API/SBDebugger.cpp (+1-1) 


``diff
diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index 4e6b22492a0d1c2..bdb8e538b99f861 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -185,7 +185,7 @@ lldb::SBError SBDebugger::InitializeWithErrorHandling() {
 llvm::sys::DynamicLibrary dynlib =
 llvm::sys::DynamicLibrary::getPermanentLibrary(spec.GetPath().c_str());
 if (dynlib.isValid()) {
-  typedef bool (*LLDBCommandPluginInit)(lldb::SBDebugger & debugger);
+  typedef bool (*LLDBCommandPluginInit)(lldb::SBDebugger debugger);
 
   lldb::SBDebugger debugger_sb(debugger_sp);
   // This calls the bool lldb::PluginInitialize(lldb::SBDebugger debugger)

``




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


[Lldb-commits] [lldb] [lldb][telemetry] Implement LLDB Telemetry (part 1) (PR #119716)

2025-02-10 Thread via lldb-commits

jimingham wrote:

This PR caused the llvm Standalone bot build to fail, for instance:

https://ci.swift.org/view/all/job/llvm.org/view/LLDB/job/lldb-cmake-standalone/1328/consoleText

Can someone fix that build problem?

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


[Lldb-commits] [lldb] [lldb] Fix ubsan violation with plugin loading (PR #126652)

2025-02-10 Thread Keith Smiley via lldb-commits

https://github.com/keith created 
https://github.com/llvm/llvm-project/pull/126652

This typedef doesn't match the signature below, specifically the signature 
takes a `lldb:SBDebugger` vs this was defined as `lldb:SBDebugger&`.

```
lldb/source/API/SBDebugger.cpp:199:13: runtime error: call to function 
lldb::PluginInitialize(lldb::SBDebugger) through pointer to incorrect function 
type 'bool (*)(lldb::SBDebugger &)'
.../CustomPlugin.cpp:134: note: lldb::PluginInitialize(lldb::SBDebugger) 
defined here
```

>From 52cdc7332d58157e4bc10ebb66ea93c17f052c5f Mon Sep 17 00:00:00 2001
From: Keith Smiley 
Date: Tue, 11 Feb 2025 02:06:36 +
Subject: [PATCH] [lldb] Fix ubsan violation with plugin loading

This typedef doesn't match the signature below, specifically the
signature takes a `lldb:SBDebugger` vs this was defined as
`lldb:SBDebugger&`.

```
lldb/source/API/SBDebugger.cpp:199:13: runtime error: call to function 
lldb::PluginInitialize(lldb::SBDebugger) through pointer to incorrect function 
type 'bool (*)(lldb::SBDebugger &)'
.../CustomPlugin.cpp:134: note: lldb::PluginInitialize(lldb::SBDebugger) 
defined here
```
---
 lldb/source/API/SBDebugger.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index 4e6b22492a0d1c2..bdb8e538b99f861 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -185,7 +185,7 @@ lldb::SBError SBDebugger::InitializeWithErrorHandling() {
 llvm::sys::DynamicLibrary dynlib =
 llvm::sys::DynamicLibrary::getPermanentLibrary(spec.GetPath().c_str());
 if (dynlib.isValid()) {
-  typedef bool (*LLDBCommandPluginInit)(lldb::SBDebugger & debugger);
+  typedef bool (*LLDBCommandPluginInit)(lldb::SBDebugger debugger);
 
   lldb::SBDebugger debugger_sb(debugger_sp);
   // This calls the bool lldb::PluginInitialize(lldb::SBDebugger debugger)

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


[Lldb-commits] [lldb] [lldb] [darwin] Upstream a few DriverKit cases (PR #126604)

2025-02-10 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jason Molenda (jasonmolenda)


Changes

A DriverKit process is a kernel extension that runs in userland, instead of 
running in the kernel address space/priv levels, they've been around a couple 
of years.  From lldb's perspective a DriverKit process is no different from any 
other userland level process, but it has a different Triple so we need to 
handle those cases in the lldb codebase.  Some of the DriverKit triple handling 
had been upstreamed to llvm-project, but I noticed a few cases that had not 
yet.  Cleaning that up.

---
Full diff: https://github.com/llvm/llvm-project/pull/126604.diff


8 Files Affected:

- (modified) 
lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp 
(+4-2) 
- (modified) 
lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp (+2) 
- (modified) 
lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp (+2-1) 
- (modified) 
lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp 
(+2-1) 
- (modified) lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp (+1) 
- (modified) lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp 
(+2-1) 
- (modified) lldb/source/Utility/ArchSpec.cpp (+6) 
- (modified) lldb/unittests/Utility/ArchSpecTest.cpp (+6) 


``diff
diff --git 
a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp 
b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
index ab013e79047ea30..b8941dae0107838 100644
--- 
a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
+++ 
b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
@@ -168,8 +168,9 @@ DynamicLoader 
*DynamicLoaderDarwinKernel::CreateInstance(Process *process,
 case llvm::Triple::IOS:
 case llvm::Triple::TvOS:
 case llvm::Triple::WatchOS:
-case llvm::Triple::XROS:
 case llvm::Triple::BridgeOS:
+case llvm::Triple::DriverKit:
+case llvm::Triple::XROS:
   if (triple_ref.getVendor() != llvm::Triple::Apple) {
 return nullptr;
   }
@@ -243,6 +244,7 @@ 
DynamicLoaderDarwinKernel::SearchForKernelWithDebugHints(Process *process) {
   Status read_err;
   addr_t kernel_addresses_64[] = {
   0xfff02010ULL,
+  0xfe004010ULL, // newest arm64 devices, large memory support
   0xfff04010ULL, // newest arm64 devices
   0xff804010ULL, // 2014-2015-ish arm64 devices
   0xff802010ULL, // oldest arm64 devices
@@ -1092,7 +1094,7 @@ void 
DynamicLoaderDarwinKernel::LoadKernelModuleIfNeeded() {
   static ConstString arm64_T1Sz_value("gT1Sz");
   const Symbol *symbol =
   m_kernel.GetModule()->FindFirstSymbolWithNameAndType(
-  kext_summary_symbol, eSymbolTypeData);
+  kext_summary_symbol, eSymbolTypeAny);
   if (symbol) {
 m_kext_summary_header_ptr_addr = symbol->GetAddress();
 // Update all image infos
diff --git 
a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp 
b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
index 14d05a1a4494cfe..f9b49c50355d5a1 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
@@ -419,6 +419,8 @@ bool DynamicLoaderDarwin::JSONImageInformationIntoImageInfo(
 image_infos[i].os_type = llvm::Triple::WatchOS;
   else if (os_name == "bridgeos")
 image_infos[i].os_type = llvm::Triple::BridgeOS;
+  else if (os_name == "driverkit")
+image_infos[i].os_type = llvm::Triple::DriverKit;
   else if (os_name == "xros")
 image_infos[i].os_type = llvm::Triple::XROS;
   else if (os_name == "maccatalyst") {
diff --git 
a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp 
b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
index 5b11059bcc50cbb..08bef4999eb9adc 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
@@ -55,8 +55,9 @@ DynamicLoader *DynamicLoaderMacOS::CreateInstance(Process 
*process,
   case llvm::Triple::IOS:
   case llvm::Triple::TvOS:
   case llvm::Triple::WatchOS:
-  case llvm::Triple::XROS:
   case llvm::Triple::BridgeOS:
+  case llvm::Triple::DriverKit:
+  case llvm::Triple::XROS:
 create = triple_ref.getVendor() == llvm::Triple::Apple;
 break;
   default:
diff --git 
a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp 
b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
index 8fc77cbe1170129..b05ed1ce2c8230b 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYL

[Lldb-commits] [lldb] [lldb] [darwin] Upstream a few DriverKit cases (PR #126604)

2025-02-10 Thread Jason Molenda via lldb-commits

https://github.com/jasonmolenda created 
https://github.com/llvm/llvm-project/pull/126604

A DriverKit process is a kernel extension that runs in userland, instead of 
running in the kernel address space/priv levels, they've been around a couple 
of years.  From lldb's perspective a DriverKit process is no different from any 
other userland level process, but it has a different Triple so we need to 
handle those cases in the lldb codebase.  Some of the DriverKit triple handling 
had been upstreamed to llvm-project, but I noticed a few cases that had not 
yet.  Cleaning that up.

>From a8323ec70bc4c40b02272fa540b1b00fe69c88d5 Mon Sep 17 00:00:00 2001
From: Jason Molenda 
Date: Mon, 10 Feb 2025 13:41:55 -0800
Subject: [PATCH] [lldb] [darwin] Upstream a few DriverKit cases

A DriverKit process is a kernel extension that runs in userland,
instead of running in the kernel address space/priv levels, they've
been around a couple of years.  From lldb's perspective a DriverKit
process is no different from any other userland level process, but
it has a different Triple so we need to handle those cases in the
lldb codebase.  Some of the DriverKit triple handling had been
upstreamed to llvm-project, but I noticed a few cases that had not
yet.  Cleaning that up.
---
 .../Darwin-Kernel/DynamicLoaderDarwinKernel.cpp | 6 --
 .../DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp   | 2 ++
 .../DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp| 3 ++-
 .../DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp   | 3 ++-
 .../source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp | 1 +
 .../Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp| 3 ++-
 lldb/source/Utility/ArchSpec.cpp| 6 ++
 lldb/unittests/Utility/ArchSpecTest.cpp | 6 ++
 8 files changed, 25 insertions(+), 5 deletions(-)

diff --git 
a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp 
b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
index ab013e79047ea30..b8941dae0107838 100644
--- 
a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
+++ 
b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
@@ -168,8 +168,9 @@ DynamicLoader 
*DynamicLoaderDarwinKernel::CreateInstance(Process *process,
 case llvm::Triple::IOS:
 case llvm::Triple::TvOS:
 case llvm::Triple::WatchOS:
-case llvm::Triple::XROS:
 case llvm::Triple::BridgeOS:
+case llvm::Triple::DriverKit:
+case llvm::Triple::XROS:
   if (triple_ref.getVendor() != llvm::Triple::Apple) {
 return nullptr;
   }
@@ -243,6 +244,7 @@ 
DynamicLoaderDarwinKernel::SearchForKernelWithDebugHints(Process *process) {
   Status read_err;
   addr_t kernel_addresses_64[] = {
   0xfff02010ULL,
+  0xfe004010ULL, // newest arm64 devices, large memory support
   0xfff04010ULL, // newest arm64 devices
   0xff804010ULL, // 2014-2015-ish arm64 devices
   0xff802010ULL, // oldest arm64 devices
@@ -1092,7 +1094,7 @@ void 
DynamicLoaderDarwinKernel::LoadKernelModuleIfNeeded() {
   static ConstString arm64_T1Sz_value("gT1Sz");
   const Symbol *symbol =
   m_kernel.GetModule()->FindFirstSymbolWithNameAndType(
-  kext_summary_symbol, eSymbolTypeData);
+  kext_summary_symbol, eSymbolTypeAny);
   if (symbol) {
 m_kext_summary_header_ptr_addr = symbol->GetAddress();
 // Update all image infos
diff --git 
a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp 
b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
index 14d05a1a4494cfe..f9b49c50355d5a1 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
@@ -419,6 +419,8 @@ bool DynamicLoaderDarwin::JSONImageInformationIntoImageInfo(
 image_infos[i].os_type = llvm::Triple::WatchOS;
   else if (os_name == "bridgeos")
 image_infos[i].os_type = llvm::Triple::BridgeOS;
+  else if (os_name == "driverkit")
+image_infos[i].os_type = llvm::Triple::DriverKit;
   else if (os_name == "xros")
 image_infos[i].os_type = llvm::Triple::XROS;
   else if (os_name == "maccatalyst") {
diff --git 
a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp 
b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
index 5b11059bcc50cbb..08bef4999eb9adc 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp
@@ -55,8 +55,9 @@ DynamicLoader *DynamicLoaderMacOS::CreateInstance(Process 
*process,
   case llvm::Triple::IOS:
   case llvm::Triple::TvOS:
   case llvm::Triple::WatchOS:
-  case llvm::Triple::XROS:
   case llvm::Triple::BridgeOS:

[Lldb-commits] [lldb] [lldb][sbapi] Namespace CommandReturnObjectCallbackResult in SBDefines (PR #126606)

2025-02-10 Thread Chelsea Cassanova via lldb-commits

https://github.com/chelcassanova created 
https://github.com/llvm/llvm-project/pull/126606

A new callback was added with the type
CommandReturnObjectCallbackResult, this commit namespaces that type to match 
the format of other callback functions that have a non-primitive return type in 
the lldb namespace.

rdar://144553496

>From 24292242731772a603ad35241294faa4ef52c4f3 Mon Sep 17 00:00:00 2001
From: Chelsea Cassanova 
Date: Mon, 10 Feb 2025 14:00:51 -0800
Subject: [PATCH] [lldb][sbapi] Namespace CommandReturnObjectCallbackResult in
 SBDefines

A new callback was added with the type
CommandReturnObjectCallbackResult, this commit namespaces that type to
match the format of other callback functions have a return type in the
lldb namespace.

rdar://144553496
---
 lldb/include/lldb/API/SBDefines.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/include/lldb/API/SBDefines.h 
b/lldb/include/lldb/API/SBDefines.h
index b7b5cc06546f86d..ed5a80da117a50a 100644
--- a/lldb/include/lldb/API/SBDefines.h
+++ b/lldb/include/lldb/API/SBDefines.h
@@ -144,7 +144,7 @@ typedef bool (*SBBreakpointHitCallback)(void *baton, 
lldb::SBProcess &process,
 typedef void (*SBDebuggerDestroyCallback)(lldb::user_id_t debugger_id,
   void *baton);
 
-typedef CommandReturnObjectCallbackResult (*SBCommandPrintCallback)(
+typedef lldb::CommandReturnObjectCallbackResult (*SBCommandPrintCallback)(
 lldb::SBCommandReturnObject &result, void *baton);
 
 typedef lldb::SBError (*SBPlatformLocateModuleCallback)(

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


  1   2   >