[Lldb-commits] [lldb] [llvm] Add support for ondemand sourcefile fetch using python callback (PR #119118)

2024-12-07 Thread via lldb-commits

https://github.com/rchamala created 
https://github.com/llvm/llvm-project/pull/119118

None

>From 1b984ba9747618e277c8ffb2c48467aec7c2a6a3 Mon Sep 17 00:00:00 2001
From: shawbyoung 
Date: Mon, 10 Jun 2024 12:08:38 -0700
Subject: [PATCH 1/2] [BOLT][NFC] Add sink block to flow CFG in profile
 inference

Test Plan: tbd

Reviewers:
Subscribers:

Tasks:

Tags:

Differential Revision: https://phabricator.intern.facebook.com/D58380996
---
 bolt/lib/Profile/StaleProfileMatching.cpp | 38 ---
 .../Transforms/Utils/SampleProfileInference.h |  3 +-
 2 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp 
b/bolt/lib/Profile/StaleProfileMatching.cpp
index 365bc5389266df..8ecfb618072abf 100644
--- a/bolt/lib/Profile/StaleProfileMatching.cpp
+++ b/bolt/lib/Profile/StaleProfileMatching.cpp
@@ -309,22 +309,33 @@ createFlowFunction(const 
BinaryFunction::BasicBlockOrderType &BlockOrder) {
   FlowFunction Func;
 
   // Add a special "dummy" source so that there is always a unique entry point.
-  // Because of the extra source, for all other blocks in FlowFunction it holds
-  // that Block.Index == BB->getIndex() + 1
   FlowBlock EntryBlock;
   EntryBlock.Index = 0;
   Func.Blocks.push_back(EntryBlock);
 
+  auto BinaryBlockIsExit = [&](const BinaryBasicBlock &BB) {
+if (BB.successors().empty())
+  return true;
+return false;
+  };
+
   // Create FlowBlock for every basic block in the binary function
   for (const BinaryBasicBlock *BB : BlockOrder) {
 Func.Blocks.emplace_back();
 FlowBlock &Block = Func.Blocks.back();
 Block.Index = Func.Blocks.size() - 1;
+Block.HasSuccessors = BinaryBlockIsExit(*BB);
 (void)BB;
 assert(Block.Index == BB->getIndex() + 1 &&
"incorrectly assigned basic block index");
   }
 
+  // Add a special "dummy" sink block so there is always a unique sink
+  FlowBlock SinkBlock;
+  SinkBlock.Index = Func.Blocks.size();
+  Func.Blocks.push_back(SinkBlock);
+  Func.Sink = SinkBlock.Index;
+
   // Create FlowJump for each jump between basic blocks in the binary function
   std::vector InDegree(Func.Blocks.size(), 0);
   for (const BinaryBasicBlock *SrcBB : BlockOrder) {
@@ -360,18 +371,29 @@ createFlowFunction(const 
BinaryFunction::BasicBlockOrderType &BlockOrder) {
   // Add dummy edges to the extra sources. If there are multiple entry blocks,
   // add an unlikely edge from 0 to the subsequent ones
   assert(InDegree[0] == 0 && "dummy entry blocks shouldn't have predecessors");
-  for (uint64_t I = 1; I < Func.Blocks.size(); I++) {
+  for (uint64_t I = 1; I < BlockOrder.size() + 1; I++) {
 const BinaryBasicBlock *BB = BlockOrder[I - 1];
 if (BB->isEntryPoint() || InDegree[I] == 0) {
   Func.Jumps.emplace_back();
   FlowJump &Jump = Func.Jumps.back();
-  Jump.Source = 0;
+  Jump.Source = Func.Entry;
   Jump.Target = I;
   if (!BB->isEntryPoint())
 Jump.IsUnlikely = true;
 }
   }
 
+  // Add dummy edges from the exit blocks to the sink block.
+  for (uint64_t I = 1; I < BlockOrder.size() + 1; I++) {
+FlowBlock &Block = Func.Blocks[I];
+if (Block.HasSuccessors) {
+  Func.Jumps.emplace_back();
+  FlowJump &Jump = Func.Jumps.back();
+  Jump.Source = I;
+  Jump.Target = Func.Sink;
+}
+  }
+
   // Create necessary metadata for the flow function
   for (FlowJump &Jump : Func.Jumps) {
 assert(Jump.Source < Func.Blocks.size());
@@ -379,6 +401,7 @@ createFlowFunction(const 
BinaryFunction::BasicBlockOrderType &BlockOrder) {
 assert(Jump.Target < Func.Blocks.size());
 Func.Blocks[Jump.Target].PredJumps.push_back(&Jump);
   }
+
   return Func;
 }
 
@@ -395,7 +418,7 @@ void matchWeightsByHashes(BinaryContext &BC,
   const BinaryFunction::BasicBlockOrderType 
&BlockOrder,
   const yaml::bolt::BinaryFunctionProfile &YamlBF,
   FlowFunction &Func) {
-  assert(Func.Blocks.size() == BlockOrder.size() + 1);
+  assert(Func.Blocks.size() == BlockOrder.size() + 2);
 
   std::vector Blocks;
   std::vector BlendedHashes;
@@ -618,7 +641,7 @@ void assignProfile(BinaryFunction &BF,
FlowFunction &Func) {
   BinaryContext &BC = BF.getBinaryContext();
 
-  assert(Func.Blocks.size() == BlockOrder.size() + 1);
+  assert(Func.Blocks.size() == BlockOrder.size() + 2);
   for (uint64_t I = 0; I < BlockOrder.size(); I++) {
 FlowBlock &Block = Func.Blocks[I + 1];
 BinaryBasicBlock *BB = BlockOrder[I];
@@ -640,6 +663,9 @@ void assignProfile(BinaryFunction &BF,
   if (Jump->Flow == 0)
 continue;
 
+  // Skip the artificial sink block
+  if (Jump->Target == Func.Sink)
+continue;
   BinaryBasicBlock &SuccBB = *BlockOrder[Jump->Target - 1];
   // Check if the edge corresponds to a regular jump or a landing pad
   if (BB->getSuccessor(SuccBB.getLabel())) {
diff --git a/llvm/include/llvm/Transforms/Utils/SampleP

[Lldb-commits] [lldb] [llvm] Add support for ondemand sourcefile fetch using python callback (PR #119118)

2024-12-07 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/119118
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] do not show misleading error when there is no frame (PR #119103)

2024-12-07 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: oltolm (oltolm)


Changes

I am using VSCode with the official vscode-lldb extension. When I try to list 
the breakpoints in the debug console get the message:

```
br list
can't evaluate expressions when the process is running.
```

I know that this is wrong and you need to use
```
`br list
(lldb) br list
No breakpoints currently set.
```
but the error message is misleading. I cleaned up the code and now the error 
message is

```
br list
sbframe object is not valid.
```
which is still not perfect, but at least it's not misleading.

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


1 Files Affected:

- (modified) lldb/source/API/SBFrame.cpp (+24-36) 


``diff
diff --git a/lldb/source/API/SBFrame.cpp b/lldb/source/API/SBFrame.cpp
index 2300bec4d685d2..a5e106c97b1f24 100644
--- a/lldb/source/API/SBFrame.cpp
+++ b/lldb/source/API/SBFrame.cpp
@@ -6,7 +6,6 @@
 //
 
//===--===//
 
-#include 
 #include 
 #include 
 
@@ -18,11 +17,8 @@
 #include "lldb/Core/Address.h"
 #include "lldb/Core/Debugger.h"
 #include "lldb/Expression/ExpressionVariable.h"
-#include "lldb/Expression/UserExpression.h"
-#include "lldb/Host/Host.h"
 #include "lldb/Symbol/Block.h"
 #include "lldb/Symbol/Function.h"
-#include "lldb/Symbol/Symbol.h"
 #include "lldb/Symbol/SymbolContext.h"
 #include "lldb/Symbol/Variable.h"
 #include "lldb/Symbol/VariableList.h"
@@ -33,7 +29,6 @@
 #include "lldb/Target/StackFrameRecognizer.h"
 #include "lldb/Target/StackID.h"
 #include "lldb/Target/Target.h"
-#include "lldb/Target/Thread.h"
 #include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/Instrumentation.h"
 #include "lldb/Utility/LLDBLog.h"
@@ -43,7 +38,6 @@
 #include "lldb/ValueObject/ValueObjectVariable.h"
 
 #include "lldb/API/SBAddress.h"
-#include "lldb/API/SBDebugger.h"
 #include "lldb/API/SBExpressionOptions.h"
 #include "lldb/API/SBFormat.h"
 #include "lldb/API/SBStream.h"
@@ -603,11 +597,11 @@ SBValue SBFrame::FindValue(const char *name, ValueType 
value_type,
 stop_if_block_is_inlined_function,
 [frame](Variable *v) { return v->IsInScope(frame); },
 &variable_list);
-  if (value_type == eValueTypeVariableGlobal 
-  || value_type == eValueTypeVariableStatic) {
+  if (value_type == eValueTypeVariableGlobal ||
+  value_type == eValueTypeVariableStatic) {
 const bool get_file_globals = true;
-VariableList *frame_vars = frame->GetVariableList(get_file_globals,
-  nullptr);
+VariableList *frame_vars =
+frame->GetVariableList(get_file_globals, nullptr);
 if (frame_vars)
   frame_vars->AppendVariablesIfUnique(variable_list);
   }
@@ -790,14 +784,13 @@ SBValueList SBFrame::GetVariables(const 
lldb::SBVariablesOptions &options) {
   const bool statics = options.GetIncludeStatics();
   const bool arguments = options.GetIncludeArguments();
   const bool recognized_arguments =
-options.GetIncludeRecognizedArguments(SBTarget(exe_ctx.GetTargetSP()));
+  options.GetIncludeRecognizedArguments(SBTarget(exe_ctx.GetTargetSP()));
   const bool locals = options.GetIncludeLocals();
   const bool in_scope_only = options.GetInScopeOnly();
   const bool include_runtime_support_values =
   options.GetIncludeRuntimeSupportValues();
   const lldb::DynamicValueType use_dynamic = options.GetUseDynamic();
 
-
   std::set variable_set;
   Process *process = exe_ctx.GetProcessPtr();
   if (target && process) {
@@ -816,9 +809,11 @@ SBValueList SBFrame::GetVariables(const 
lldb::SBVariablesOptions &options) {
   if (num_variables) {
 size_t num_produced = 0;
 for (const VariableSP &variable_sp : *variable_list) {
-  if (INTERRUPT_REQUESTED(dbg, 
-"Interrupted getting frame variables with {0} of {1} "
-"produced.", num_produced, num_variables))
+  if (INTERRUPT_REQUESTED(
+  dbg,
+  "Interrupted getting frame variables with {0} of {1} "
+  "produced.",
+  num_produced, num_variables))
 return {};
 
   if (variable_sp) {
@@ -1012,33 +1007,26 @@ bool SBFrame::GetDescription(SBStream &description) {
 SBValue SBFrame::EvaluateExpression(const char *expr) {
   LLDB_INSTRUMENT_VA(this, expr);
 
-  SBValue result;
   std::unique_lock lock;
   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
 
   StackFrame *frame = exe_ctx.GetFramePtr();
   Target *target = exe_ctx.GetTargetPtr();
+  SBExpressionOptions options;
   if (frame && target) {
-SBExpressionOptions options;
 lldb::DynamicValueType fetch_dynamic_value =
 frame->CalculateTarget()->GetPreferDynamicValue();
 op

[Lldb-commits] [lldb] [lldb] do not show misleading error when there is no frame (PR #119103)

2024-12-07 Thread via lldb-commits

https://github.com/oltolm created 
https://github.com/llvm/llvm-project/pull/119103

I am using VSCode with the official vscode-lldb extension. When I try to list 
the breakpoints in the debug console get the message:

```
br list
can't evaluate expressions when the process is running.
```

I know that this is wrong and you need to use
```
`br list
(lldb) br list
No breakpoints currently set.
```
but the error message is misleading. I cleaned up the code and now the error 
message is

```
br list
sbframe object is not valid.
```
which is still not perfect, but at least it's not misleading.

>From 2458c4ea01eef4a100dfdd42f6f94fd610eb7a7d Mon Sep 17 00:00:00 2001
From: oltolm 
Date: Sat, 7 Dec 2024 17:24:07 +0100
Subject: [PATCH] lldb: do not show misleading error when there is no frame

# Conflicts:
#   lldb/source/API/SBFrame.cpp
---
 lldb/source/API/SBFrame.cpp | 60 +++--
 1 file changed, 24 insertions(+), 36 deletions(-)

diff --git a/lldb/source/API/SBFrame.cpp b/lldb/source/API/SBFrame.cpp
index 2300bec4d685d2..a5e106c97b1f24 100644
--- a/lldb/source/API/SBFrame.cpp
+++ b/lldb/source/API/SBFrame.cpp
@@ -6,7 +6,6 @@
 //
 
//===--===//
 
-#include 
 #include 
 #include 
 
@@ -18,11 +17,8 @@
 #include "lldb/Core/Address.h"
 #include "lldb/Core/Debugger.h"
 #include "lldb/Expression/ExpressionVariable.h"
-#include "lldb/Expression/UserExpression.h"
-#include "lldb/Host/Host.h"
 #include "lldb/Symbol/Block.h"
 #include "lldb/Symbol/Function.h"
-#include "lldb/Symbol/Symbol.h"
 #include "lldb/Symbol/SymbolContext.h"
 #include "lldb/Symbol/Variable.h"
 #include "lldb/Symbol/VariableList.h"
@@ -33,7 +29,6 @@
 #include "lldb/Target/StackFrameRecognizer.h"
 #include "lldb/Target/StackID.h"
 #include "lldb/Target/Target.h"
-#include "lldb/Target/Thread.h"
 #include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/Instrumentation.h"
 #include "lldb/Utility/LLDBLog.h"
@@ -43,7 +38,6 @@
 #include "lldb/ValueObject/ValueObjectVariable.h"
 
 #include "lldb/API/SBAddress.h"
-#include "lldb/API/SBDebugger.h"
 #include "lldb/API/SBExpressionOptions.h"
 #include "lldb/API/SBFormat.h"
 #include "lldb/API/SBStream.h"
@@ -603,11 +597,11 @@ SBValue SBFrame::FindValue(const char *name, ValueType 
value_type,
 stop_if_block_is_inlined_function,
 [frame](Variable *v) { return v->IsInScope(frame); },
 &variable_list);
-  if (value_type == eValueTypeVariableGlobal 
-  || value_type == eValueTypeVariableStatic) {
+  if (value_type == eValueTypeVariableGlobal ||
+  value_type == eValueTypeVariableStatic) {
 const bool get_file_globals = true;
-VariableList *frame_vars = frame->GetVariableList(get_file_globals,
-  nullptr);
+VariableList *frame_vars =
+frame->GetVariableList(get_file_globals, nullptr);
 if (frame_vars)
   frame_vars->AppendVariablesIfUnique(variable_list);
   }
@@ -790,14 +784,13 @@ SBValueList SBFrame::GetVariables(const 
lldb::SBVariablesOptions &options) {
   const bool statics = options.GetIncludeStatics();
   const bool arguments = options.GetIncludeArguments();
   const bool recognized_arguments =
-options.GetIncludeRecognizedArguments(SBTarget(exe_ctx.GetTargetSP()));
+  options.GetIncludeRecognizedArguments(SBTarget(exe_ctx.GetTargetSP()));
   const bool locals = options.GetIncludeLocals();
   const bool in_scope_only = options.GetInScopeOnly();
   const bool include_runtime_support_values =
   options.GetIncludeRuntimeSupportValues();
   const lldb::DynamicValueType use_dynamic = options.GetUseDynamic();
 
-
   std::set variable_set;
   Process *process = exe_ctx.GetProcessPtr();
   if (target && process) {
@@ -816,9 +809,11 @@ SBValueList SBFrame::GetVariables(const 
lldb::SBVariablesOptions &options) {
   if (num_variables) {
 size_t num_produced = 0;
 for (const VariableSP &variable_sp : *variable_list) {
-  if (INTERRUPT_REQUESTED(dbg, 
-"Interrupted getting frame variables with {0} of {1} "
-"produced.", num_produced, num_variables))
+  if (INTERRUPT_REQUESTED(
+  dbg,
+  "Interrupted getting frame variables with {0} of {1} "
+  "produced.",
+  num_produced, num_variables))
 return {};
 
   if (variable_sp) {
@@ -1012,33 +1007,26 @@ bool SBFrame::GetDescription(SBStream &description) {
 SBValue SBFrame::EvaluateExpression(const char *expr) {
   LLDB_INSTRUMENT_VA(this, expr);
 
-  SBValue result;
   std::unique_lock lock;
   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
 
   StackFrame *frame = exe_ctx.GetFramePtr();
   Target *target = exe_ctx.Get

[Lldb-commits] [lldb] [lldb] do not show misleading error when there is no frame (PR #119103)

2024-12-07 Thread via lldb-commits

github-actions[bot] wrote:




:warning: Python code formatter, darker found issues in your code. :warning:



You can test this locally with the following command:


``bash
darker --check --diff -r 
66f9448b4b14a117141a3efd014e1240b30b741f...64966cd9ede9cf0ba9f1275bfaa34e91d2688081
 lldb/test/API/python_api/run_locker/TestRunLocker.py
``





View the diff from darker here.


``diff
--- TestRunLocker.py2024-12-08 00:47:24.00 +
+++ TestRunLocker.py2024-12-08 00:51:15.157057 +
@@ -105,8 +105,6 @@
 result = lldb.SBCommandReturnObject()
 ret = interp.HandleCommand(
 "script var = lldb.frame.EvaluateExpression('SomethingToCall()'); 
var.GetError().GetCString()",
 result,
 )
-self.assertIn(
-"sbframe object is not valid", result.GetOutput()
-)
+self.assertIn("sbframe object is not valid", result.GetOutput())

``




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


[Lldb-commits] [lldb] [lldb] do not show misleading error when there is no frame (PR #119103)

2024-12-07 Thread via lldb-commits

https://github.com/oltolm updated 
https://github.com/llvm/llvm-project/pull/119103

>From 6af87f9c4dbf760eafc3a6474963b1418f66e53a Mon Sep 17 00:00:00 2001
From: oltolm 
Date: Sat, 7 Dec 2024 17:24:07 +0100
Subject: [PATCH] lldb: do not show misleading error when there is no frame

---
 lldb/source/API/SBFrame.cpp   | 60 ---
 .../python_api/run_locker/TestRunLocker.py|  4 +-
 2 files changed, 25 insertions(+), 39 deletions(-)

diff --git a/lldb/source/API/SBFrame.cpp b/lldb/source/API/SBFrame.cpp
index 2300bec4d685d2..a5e106c97b1f24 100644
--- a/lldb/source/API/SBFrame.cpp
+++ b/lldb/source/API/SBFrame.cpp
@@ -6,7 +6,6 @@
 //
 
//===--===//
 
-#include 
 #include 
 #include 
 
@@ -18,11 +17,8 @@
 #include "lldb/Core/Address.h"
 #include "lldb/Core/Debugger.h"
 #include "lldb/Expression/ExpressionVariable.h"
-#include "lldb/Expression/UserExpression.h"
-#include "lldb/Host/Host.h"
 #include "lldb/Symbol/Block.h"
 #include "lldb/Symbol/Function.h"
-#include "lldb/Symbol/Symbol.h"
 #include "lldb/Symbol/SymbolContext.h"
 #include "lldb/Symbol/Variable.h"
 #include "lldb/Symbol/VariableList.h"
@@ -33,7 +29,6 @@
 #include "lldb/Target/StackFrameRecognizer.h"
 #include "lldb/Target/StackID.h"
 #include "lldb/Target/Target.h"
-#include "lldb/Target/Thread.h"
 #include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/Instrumentation.h"
 #include "lldb/Utility/LLDBLog.h"
@@ -43,7 +38,6 @@
 #include "lldb/ValueObject/ValueObjectVariable.h"
 
 #include "lldb/API/SBAddress.h"
-#include "lldb/API/SBDebugger.h"
 #include "lldb/API/SBExpressionOptions.h"
 #include "lldb/API/SBFormat.h"
 #include "lldb/API/SBStream.h"
@@ -603,11 +597,11 @@ SBValue SBFrame::FindValue(const char *name, ValueType 
value_type,
 stop_if_block_is_inlined_function,
 [frame](Variable *v) { return v->IsInScope(frame); },
 &variable_list);
-  if (value_type == eValueTypeVariableGlobal 
-  || value_type == eValueTypeVariableStatic) {
+  if (value_type == eValueTypeVariableGlobal ||
+  value_type == eValueTypeVariableStatic) {
 const bool get_file_globals = true;
-VariableList *frame_vars = frame->GetVariableList(get_file_globals,
-  nullptr);
+VariableList *frame_vars =
+frame->GetVariableList(get_file_globals, nullptr);
 if (frame_vars)
   frame_vars->AppendVariablesIfUnique(variable_list);
   }
@@ -790,14 +784,13 @@ SBValueList SBFrame::GetVariables(const 
lldb::SBVariablesOptions &options) {
   const bool statics = options.GetIncludeStatics();
   const bool arguments = options.GetIncludeArguments();
   const bool recognized_arguments =
-options.GetIncludeRecognizedArguments(SBTarget(exe_ctx.GetTargetSP()));
+  options.GetIncludeRecognizedArguments(SBTarget(exe_ctx.GetTargetSP()));
   const bool locals = options.GetIncludeLocals();
   const bool in_scope_only = options.GetInScopeOnly();
   const bool include_runtime_support_values =
   options.GetIncludeRuntimeSupportValues();
   const lldb::DynamicValueType use_dynamic = options.GetUseDynamic();
 
-
   std::set variable_set;
   Process *process = exe_ctx.GetProcessPtr();
   if (target && process) {
@@ -816,9 +809,11 @@ SBValueList SBFrame::GetVariables(const 
lldb::SBVariablesOptions &options) {
   if (num_variables) {
 size_t num_produced = 0;
 for (const VariableSP &variable_sp : *variable_list) {
-  if (INTERRUPT_REQUESTED(dbg, 
-"Interrupted getting frame variables with {0} of {1} "
-"produced.", num_produced, num_variables))
+  if (INTERRUPT_REQUESTED(
+  dbg,
+  "Interrupted getting frame variables with {0} of {1} "
+  "produced.",
+  num_produced, num_variables))
 return {};
 
   if (variable_sp) {
@@ -1012,33 +1007,26 @@ bool SBFrame::GetDescription(SBStream &description) {
 SBValue SBFrame::EvaluateExpression(const char *expr) {
   LLDB_INSTRUMENT_VA(this, expr);
 
-  SBValue result;
   std::unique_lock lock;
   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
 
   StackFrame *frame = exe_ctx.GetFramePtr();
   Target *target = exe_ctx.GetTargetPtr();
+  SBExpressionOptions options;
   if (frame && target) {
-SBExpressionOptions options;
 lldb::DynamicValueType fetch_dynamic_value =
 frame->CalculateTarget()->GetPreferDynamicValue();
 options.SetFetchDynamicValue(fetch_dynamic_value);
-options.SetUnwindOnError(true);
-options.SetIgnoreBreakpoints(true);
-SourceLanguage language = target->GetLanguage();
-if (!language)
-  language = frame->GetLanguage();
-options.SetLanguage((SBSourceLanguageN

[Lldb-commits] [lldb] [lldb] do not show misleading error when there is no frame (PR #119103)

2024-12-07 Thread via lldb-commits

https://github.com/oltolm updated 
https://github.com/llvm/llvm-project/pull/119103

>From 64966cd9ede9cf0ba9f1275bfaa34e91d2688081 Mon Sep 17 00:00:00 2001
From: oltolm 
Date: Sat, 7 Dec 2024 17:24:07 +0100
Subject: [PATCH] lldb: do not show misleading error when there is no frame

---
 lldb/source/API/SBFrame.cpp   | 60 ---
 .../python_api/run_locker/TestRunLocker.py|  2 +-
 2 files changed, 25 insertions(+), 37 deletions(-)

diff --git a/lldb/source/API/SBFrame.cpp b/lldb/source/API/SBFrame.cpp
index 2300bec4d685d2..a5e106c97b1f24 100644
--- a/lldb/source/API/SBFrame.cpp
+++ b/lldb/source/API/SBFrame.cpp
@@ -6,7 +6,6 @@
 //
 
//===--===//
 
-#include 
 #include 
 #include 
 
@@ -18,11 +17,8 @@
 #include "lldb/Core/Address.h"
 #include "lldb/Core/Debugger.h"
 #include "lldb/Expression/ExpressionVariable.h"
-#include "lldb/Expression/UserExpression.h"
-#include "lldb/Host/Host.h"
 #include "lldb/Symbol/Block.h"
 #include "lldb/Symbol/Function.h"
-#include "lldb/Symbol/Symbol.h"
 #include "lldb/Symbol/SymbolContext.h"
 #include "lldb/Symbol/Variable.h"
 #include "lldb/Symbol/VariableList.h"
@@ -33,7 +29,6 @@
 #include "lldb/Target/StackFrameRecognizer.h"
 #include "lldb/Target/StackID.h"
 #include "lldb/Target/Target.h"
-#include "lldb/Target/Thread.h"
 #include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/Instrumentation.h"
 #include "lldb/Utility/LLDBLog.h"
@@ -43,7 +38,6 @@
 #include "lldb/ValueObject/ValueObjectVariable.h"
 
 #include "lldb/API/SBAddress.h"
-#include "lldb/API/SBDebugger.h"
 #include "lldb/API/SBExpressionOptions.h"
 #include "lldb/API/SBFormat.h"
 #include "lldb/API/SBStream.h"
@@ -603,11 +597,11 @@ SBValue SBFrame::FindValue(const char *name, ValueType 
value_type,
 stop_if_block_is_inlined_function,
 [frame](Variable *v) { return v->IsInScope(frame); },
 &variable_list);
-  if (value_type == eValueTypeVariableGlobal 
-  || value_type == eValueTypeVariableStatic) {
+  if (value_type == eValueTypeVariableGlobal ||
+  value_type == eValueTypeVariableStatic) {
 const bool get_file_globals = true;
-VariableList *frame_vars = frame->GetVariableList(get_file_globals,
-  nullptr);
+VariableList *frame_vars =
+frame->GetVariableList(get_file_globals, nullptr);
 if (frame_vars)
   frame_vars->AppendVariablesIfUnique(variable_list);
   }
@@ -790,14 +784,13 @@ SBValueList SBFrame::GetVariables(const 
lldb::SBVariablesOptions &options) {
   const bool statics = options.GetIncludeStatics();
   const bool arguments = options.GetIncludeArguments();
   const bool recognized_arguments =
-options.GetIncludeRecognizedArguments(SBTarget(exe_ctx.GetTargetSP()));
+  options.GetIncludeRecognizedArguments(SBTarget(exe_ctx.GetTargetSP()));
   const bool locals = options.GetIncludeLocals();
   const bool in_scope_only = options.GetInScopeOnly();
   const bool include_runtime_support_values =
   options.GetIncludeRuntimeSupportValues();
   const lldb::DynamicValueType use_dynamic = options.GetUseDynamic();
 
-
   std::set variable_set;
   Process *process = exe_ctx.GetProcessPtr();
   if (target && process) {
@@ -816,9 +809,11 @@ SBValueList SBFrame::GetVariables(const 
lldb::SBVariablesOptions &options) {
   if (num_variables) {
 size_t num_produced = 0;
 for (const VariableSP &variable_sp : *variable_list) {
-  if (INTERRUPT_REQUESTED(dbg, 
-"Interrupted getting frame variables with {0} of {1} "
-"produced.", num_produced, num_variables))
+  if (INTERRUPT_REQUESTED(
+  dbg,
+  "Interrupted getting frame variables with {0} of {1} "
+  "produced.",
+  num_produced, num_variables))
 return {};
 
   if (variable_sp) {
@@ -1012,33 +1007,26 @@ bool SBFrame::GetDescription(SBStream &description) {
 SBValue SBFrame::EvaluateExpression(const char *expr) {
   LLDB_INSTRUMENT_VA(this, expr);
 
-  SBValue result;
   std::unique_lock lock;
   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
 
   StackFrame *frame = exe_ctx.GetFramePtr();
   Target *target = exe_ctx.GetTargetPtr();
+  SBExpressionOptions options;
   if (frame && target) {
-SBExpressionOptions options;
 lldb::DynamicValueType fetch_dynamic_value =
 frame->CalculateTarget()->GetPreferDynamicValue();
 options.SetFetchDynamicValue(fetch_dynamic_value);
-options.SetUnwindOnError(true);
-options.SetIgnoreBreakpoints(true);
-SourceLanguage language = target->GetLanguage();
-if (!language)
-  language = frame->GetLanguage();
-options.SetLanguage((SBSourceLanguageN

[Lldb-commits] [lldb] [lldb] Add lookup by name to SBValue through new member property (PR #118814)

2024-12-07 Thread Dave Lee via lldb-commits

https://github.com/kastiglione updated 
https://github.com/llvm/llvm-project/pull/118814

>From 639fc6d87345c8d68a822032917102a4225df355 Mon Sep 17 00:00:00 2001
From: Dave Lee 
Date: Wed, 4 Dec 2024 14:37:24 -0800
Subject: [PATCH 1/5] [lldb] Add lookup by name to SBValue.child

---
 lldb/bindings/interface/SBValueExtensions.i| 6 --
 lldb/test/API/python_api/value/TestValueAPI.py | 8 +++-
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/lldb/bindings/interface/SBValueExtensions.i 
b/lldb/bindings/interface/SBValueExtensions.i
index bee9c27775d453..f743b8b9bc786f 100644
--- a/lldb/bindings/interface/SBValueExtensions.i
+++ b/lldb/bindings/interface/SBValueExtensions.i
@@ -7,7 +7,7 @@ STRING_EXTENSION_OUTSIDE(SBValue)
 return self.GetDynamicValue (eDynamicCanRunTarget)
 
 class children_access(object):
-'''A helper object that will lazily hand out thread for a process 
when supplied an index.'''
+'''A helper object that will lazily hand out child values when 
supplied an index or name.'''
 
 def __init__(self, sbvalue):
 self.sbvalue = sbvalue
@@ -23,6 +23,8 @@ STRING_EXTENSION_OUTSIDE(SBValue)
 if -count <= key < count:
 key %= count
 return self.sbvalue.GetChildAtIndex(key)
+elif isinstance(key, str):
+return self.sbvalue.GetChildMemberWithName(key)
 return None
 
 def get_child_access_object(self):
@@ -49,7 +51,7 @@ STRING_EXTENSION_OUTSIDE(SBValue)
 return self.GetNumChildren()
 
 children = property(get_value_child_list, None, doc='''A read only 
property that returns a list() of lldb.SBValue objects for the children of the 
value.''')
-child = property(get_child_access_object, None, doc='''A read only 
property that returns an object that can access children of a variable by index 
(child_value = value.children[12]).''')
+child = property(get_child_access_object, None, doc='''A read only 
property that returns an object that can access children of a variable by index 
or by name.''')
 name = property(GetName, None, doc='''A read only property that 
returns the name of this value as a string.''')
 type = property(GetType, None, doc='''A read only property that 
returns a lldb.SBType object that represents the type for this value.''')
 size = property(GetByteSize, None, doc='''A read only property that 
returns the size in bytes of this value.''')
diff --git a/lldb/test/API/python_api/value/TestValueAPI.py 
b/lldb/test/API/python_api/value/TestValueAPI.py
index 512100912d6fe7..eb6dbfe6362a43 100644
--- a/lldb/test/API/python_api/value/TestValueAPI.py
+++ b/lldb/test/API/python_api/value/TestValueAPI.py
@@ -140,10 +140,8 @@ def test(self):
 val_i = target.EvaluateExpression("i")
 val_s = target.EvaluateExpression("s")
 val_a = target.EvaluateExpression("a")
-self.assertTrue(
-val_s.GetChildMemberWithName("a").GetAddress().IsValid(), 
VALID_VARIABLE
-)
-self.assertTrue(val_s.GetChildMemberWithName("a").AddressOf(), 
VALID_VARIABLE)
+self.assertTrue(val_s.child["a"].GetAddress().IsValid(), 
VALID_VARIABLE)
+self.assertTrue(val_s.child["a"].AddressOf(), VALID_VARIABLE)
 self.assertTrue(val_a.Cast(val_i.GetType()).AddressOf(), 
VALID_VARIABLE)
 
 # Test some other cases of the Cast API.  We allow casts from one 
struct type
@@ -210,7 +208,7 @@ def test(self):
 weird_cast = f_var.Cast(val_s.GetType())
 self.assertSuccess(weird_cast.GetError(), "Can cast from a larger to a 
smaller")
 self.assertEqual(
-weird_cast.GetChildMemberWithName("a").GetValueAsSigned(0),
+weird_cast.child["a"].GetValueAsSigned(0),
 33,
 "Got the right value",
 )

>From c6f926b0e451f87af8c14baed3de55f4cb4240d5 Mon Sep 17 00:00:00 2001
From: Dave Lee 
Date: Thu, 5 Dec 2024 13:04:20 -0800
Subject: [PATCH 2/5] Support base class children

---
 lldb/bindings/interface/SBValueExtensions.i | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lldb/bindings/interface/SBValueExtensions.i 
b/lldb/bindings/interface/SBValueExtensions.i
index f743b8b9bc786f..c813de6c65c5c6 100644
--- a/lldb/bindings/interface/SBValueExtensions.i
+++ b/lldb/bindings/interface/SBValueExtensions.i
@@ -24,7 +24,12 @@ STRING_EXTENSION_OUTSIDE(SBValue)
 key %= count
 return self.sbvalue.GetChildAtIndex(key)
 elif isinstance(key, str):
-return self.sbvalue.GetChildMemberWithName(key)
+if child := self.sbvalue.GetChildMemberWithName(key)
+return child
+# Support base classes, which are children but not members.
+for child in self.sbvalue

[Lldb-commits] [lldb] [lldb] Add lookup by name to SBValue through new member property (PR #118814)

2024-12-07 Thread Dave Lee via lldb-commits


@@ -29,6 +29,19 @@ STRING_EXTENSION_OUTSIDE(SBValue)
 '''An accessor function that returns a children_access() object 
which allows lazy member variable access from a lldb.SBValue object.'''
 return self.children_access (self)
 
+def get_member_access_object(self):
+'''An accessor function that returns an interface which provides 
subscript based lookup of child members.'''
+class member_access:
+def __init__(self, valobj):
+self.valobj = valobj
+
+def __getitem__(self, key):
+if isinstance(key, str):
+return self.valobj.GetChildMemberWithName(key)
+raise TypeError("invalid subscript key")

kastiglione wrote:

I changed it to `member key must be a string`. Since the error is only raised 
when the key is not a string (a dynamic type check), I left out the semantic 
part of your suggested message.

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