[Lldb-commits] [PATCH] D92643: [lldb] Lookup static const members in FindGlobalVariables

2021-02-09 Thread Andy Yankovsky via Phabricator via lldb-commits
werat updated this revision to Diff 322309.
werat added a comment.

Change DW_AT_decl_file handling as per @jankratochvil comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92643

Files:
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/test/API/python_api/target/globals/Makefile
  lldb/test/API/python_api/target/globals/TestTargetGlobals.py
  lldb/test/API/python_api/target/globals/main.cpp

Index: lldb/test/API/python_api/target/globals/main.cpp
===
--- /dev/null
+++ lldb/test/API/python_api/target/globals/main.cpp
@@ -0,0 +1,12 @@
+class Vars {
+public:
+  inline static double inline_static = 1.5;
+  static constexpr int static_constexpr = 2;
+  static const int static_const_out_out_class;
+};
+
+const int Vars::static_const_out_out_class = 3;
+
+char global_var_of_char_type = 'X';
+
+int main() {}
Index: lldb/test/API/python_api/target/globals/TestTargetGlobals.py
===
--- /dev/null
+++ lldb/test/API/python_api/target/globals/TestTargetGlobals.py
@@ -0,0 +1,42 @@
+"""
+Test SBTarget::FindGlobalVariables API.
+"""
+
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+
+class TargetAPITestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+@add_test_categories(['pyapi'])
+def test_find_global_variables(self):
+"""Exercise SBTarget.FindGlobalVariables() API."""
+self.build()
+
+# Don't need to launch a process, since we're only interested in
+# looking up global variables.
+target = self.dbg.CreateTarget(self.getBuildArtifact())
+
+def test_global_var(query, name, type_name, value):
+value_list = target.FindGlobalVariables(query, 1)
+self.assertEqual(value_list.GetSize(), 1)
+var = value_list.GetValueAtIndex(0)
+self.DebugSBValue(var)
+self.assertTrue(var)
+self.assertEqual(var.GetName(), name)
+self.assertEqual(var.GetTypeName(), type_name)
+self.assertEqual(var.GetValue(), value)
+
+test_global_var(
+"Vars::inline_static",
+"Vars::inline_static", "double", "1.5")
+test_global_var(
+"Vars::static_constexpr",
+"Vars::static_constexpr", "const int", "2")
+test_global_var(
+"Vars::static_const_out_out_class",
+"Vars::static_const_out_out_class", "const int", "3")
+test_global_var(
+"global_var_of_char_type",
+"::global_var_of_char_type", "char", "'X'")
Index: lldb/test/API/python_api/target/globals/Makefile
===
--- /dev/null
+++ lldb/test/API/python_api/target/globals/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -372,6 +372,10 @@
 
   lldb_private::Type *ResolveTypeUID(const DIERef &die_ref);
 
+  lldb::VariableSP
+  ParseStaticConstMemberDIE(const lldb_private::SymbolContext &sc,
+const DWARFDIE &die);
+
   lldb::VariableSP ParseVariableDIE(const lldb_private::SymbolContext &sc,
 const DWARFDIE &die,
 const lldb::addr_t func_low_pc);
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -2147,6 +2147,47 @@
 return variables.GetSize() - original_size < max_matches;
   });
 
+  // If we don't have enough matches and the variable context is not empty, try
+  // to resolve the context as a type and look for static const members.
+  if (variables.GetSize() - original_size < max_matches && !context.empty()) {
+llvm::StringRef type_scope;
+llvm::StringRef type_name;
+TypeClass type_class;
+if (!Type::GetTypeScopeAndBasename(context, type_scope, type_name,
+   type_class))
+  type_name = context;
+
+m_index->GetTypes(ConstString(type_name), [&](DWARFDIE parent) {
+  llvm::StringRef parent_type_name = GetDWARFDeclContext(parent)
+ .GetQualifiedNameAsConstString()
+ .GetStringRef();
+
+  // This type is from another scope, skip it.
+  if (!parent_type_name.endswith(context))
+return true;
+
+  auto *dwar

[Lldb-commits] [PATCH] D92643: [lldb] Lookup static const members in FindGlobalVariables

2021-02-09 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp:3162
+case DW_AT_decl_file:
+  decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(
+  form_value.Unsigned()));

jankratochvil wrote:
> Here should be according to my D91014:
> ```
> decl.SetFile(attributes.CompileUnitAtIndex(i)->GetFile(
> ```
> 
Thanks, didn't know about that


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92643

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


[Lldb-commits] [PATCH] D95947: [lldb] [Process/FreeBSDRemote] Introduce powerpc support

2021-02-09 Thread Michał Górny via Phabricator via lldb-commits
mgorny added a comment.

In D95947#2549602 , @jrtc27 wrote:

> In D95947#2549599 , @mgorny wrote:
>
>> @jrtc27 , does this look good?
>
> Yep, assuming it still works.

Yes, it does.

@labath, do you have any comments?


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

https://reviews.llvm.org/D95947

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


[Lldb-commits] [PATCH] D96202: [lldb/test] Automatically find debug servers to test

2021-02-09 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

In D96202#2549497 , @JDevlieghere 
wrote:

> This will break my "run the tests against an Xcode install", but it seems 
> like I should be able to work around that looking for debugserver in the 
> LLDB.framework in `get_debugserver_exe`. Overall this is a pretty nice 
> cleanup so seems like a fair trade-off. LGTM.

What exactly is that use case? Do you want to run the tests with the 
debugserver that comes with that xcode install? If that's the case, then I 
would expect this to just work, as lldb knows that in a framework build, the 
"support executable directory" is located inside the framework: 
https://github.com/llvm/llvm-project/blob/main/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm#L138


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96202

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


[Lldb-commits] [PATCH] D96276: [lldb] Inline invariant params to AppleThreadPlanStepThrough (NFC)

2021-02-09 Thread Dave Lee via Phabricator via lldb-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG230939244937: [lldb] Inline invariant params to 
AppleThreadPlanStepThrough (NFC) (authored by kastiglione).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96276

Files:
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.h

Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.h
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.h
+++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.h
@@ -24,8 +24,7 @@
 public:
   AppleThreadPlanStepThroughObjCTrampoline(
   Thread &thread, AppleObjCTrampolineHandler &trampoline_handler,
-  ValueList &values, lldb::addr_t isa_addr, lldb::addr_t sel_addr,
-  bool stop_others);
+  ValueList &values, lldb::addr_t isa_addr, lldb::addr_t sel_addr);
 
   ~AppleThreadPlanStepThroughObjCTrampoline() override;
 
@@ -39,7 +38,9 @@
 
   bool ShouldStop(Event *event_ptr) override;
 
-  bool StopOthers() override { return m_stop_others; }
+  // The step through code might have to fill in the cache, so it is not safe
+  // to run only one thread.
+  bool StopOthers() override { return false; }
 
   // The base class MischiefManaged does some cleanup - so you have to call it
   // in your MischiefManaged derived class.
@@ -69,15 +70,13 @@
   FunctionCaller *m_impl_function; /// This is a pointer to a impl function that
/// is owned by the client that pushes this
/// plan.
-  bool m_stop_others;  /// Whether we should stop other threads.
 };
 
 class AppleThreadPlanStepThroughDirectDispatch: public ThreadPlanStepOut {
 public:
-  AppleThreadPlanStepThroughDirectDispatch(
-  Thread &thread, AppleObjCTrampolineHandler &handler,
-  llvm::StringRef dispatch_func_name, bool stop_others,
-  LazyBool step_in_avoids_code_without_debug_info);
+  AppleThreadPlanStepThroughDirectDispatch(Thread &thread,
+   AppleObjCTrampolineHandler &handler,
+   llvm::StringRef dispatch_func_name);
 
   ~AppleThreadPlanStepThroughDirectDispatch() override;
 
@@ -85,7 +84,7 @@
 
   bool ShouldStop(Event *event_ptr) override;
 
-  bool StopOthers() override { return m_stop_others; }
+  bool StopOthers() override { return false; }
 
   bool MischiefManaged() override;
 
@@ -107,7 +106,6 @@
   std::vector m_msgSend_bkpts; /// Breakpoints on the objc
/// dispatch functions.
   bool m_at_msg_send;  /// Are we currently handling an msg_send
-  bool m_stop_others;  /// Whether we should stop other threads.
 
 };
 
Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp
+++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp
@@ -30,15 +30,13 @@
 AppleThreadPlanStepThroughObjCTrampoline::
 AppleThreadPlanStepThroughObjCTrampoline(
 Thread &thread, AppleObjCTrampolineHandler &trampoline_handler,
-ValueList &input_values, lldb::addr_t isa_addr, lldb::addr_t sel_addr,
-bool stop_others)
+ValueList &input_values, lldb::addr_t isa_addr, lldb::addr_t sel_addr)
 : ThreadPlan(ThreadPlan::eKindGeneric,
  "MacOSX Step through ObjC Trampoline", thread, eVoteNoOpinion,
  eVoteNoOpinion),
   m_trampoline_handler(trampoline_handler),
   m_args_addr(LLDB_INVALID_ADDRESS), m_input_values(input_values),
-  m_isa_addr(isa_addr), m_sel_addr(sel_addr), m_impl_function(nullptr),
-  m_stop_others(stop_others) {}
+  m_isa_addr(isa_addr), m_sel_addr(sel_addr), m_impl_function(nullptr) {}
 
 // Destructor
 AppleThreadPlanStepThroughObjCTrampoline::
@@ -66,7 +64,7 @@
 EvaluateExpressionOptions options;
 options.SetUnwindOnError(true);
 options.SetIgnoreBreakpoints(true);
-options.SetStopOthers(m_stop_others);
+options.SetStopOthers(false);
 GetThread().CalculateExecutionContext(exc_ctx);
 m_func_sp = m_impl_function->GetThreadPlanToCallFunction(
 ex

[Lldb-commits] [lldb] 2309392 - [lldb] Inline invariant params to AppleThreadPlanStepThrough (NFC)

2021-02-09 Thread Dave Lee via lldb-commits

Author: Dave Lee
Date: 2021-02-09T08:03:51-08:00
New Revision: 2309392449376295a70354273500730be0f28510

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

LOG: [lldb] Inline invariant params to AppleThreadPlanStepThrough (NFC)

These two `AppleThreadPlanStepThrough` thread plans have parameterized behavior
that is unutilized. To make their interface and implementation simpler, this
change inlines those outside parameters.

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

Added: 


Modified: 

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.h

Removed: 




diff  --git 
a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
 
b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
index bcc1f6fd339f..f1d18f11b267 100644
--- 
a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
+++ 
b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
@@ -1157,13 +1157,8 @@ 
AppleObjCTrampolineHandler::GetStepThroughDispatchPlan(Thread &thread,
 flag_value.GetScalar() = 0; // FIXME - Set to 0 when debugging is done.
   dispatch_values.PushValue(flag_value);
 
-  // The step through code might have to fill in the cache, so it
-  // is not safe to run only one thread.  So we override the
-  // stop_others value passed in to us here:
-  const bool trampoline_stop_others = false;
   ret_plan_sp = std::make_shared(
-  thread, *this, dispatch_values, isa_addr, sel_addr,
-  trampoline_stop_others);
+  thread, *this, dispatch_values, isa_addr, sel_addr);
   if (log) {
 StreamString s;
 ret_plan_sp->GetDescription(&s, eDescriptionLevelFull);
@@ -1182,13 +1177,9 @@ 
AppleObjCTrampolineHandler::GetStepThroughDispatchPlan(Thread &thread,
 MsgsendMap::iterator pos;
 pos = m_opt_dispatch_map.find(curr_pc);
 if (pos != m_opt_dispatch_map.end()) {
-
   const char *opt_name = g_opt_dispatch_names[(*pos).second];
-
-  bool trampoline_stop_others = false;
-  LazyBool step_in_should_stop = eLazyBoolCalculate;
-  ret_plan_sp = std::make_shared 
(
-  thread, *this, opt_name, trampoline_stop_others, 
step_in_should_stop);
+  ret_plan_sp = std::make_shared(
+  thread, *this, opt_name);
 }
   }
 

diff  --git 
a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp
 
b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp
index 653e007c7b5f..fe31cfc28c6e 100644
--- 
a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp
+++ 
b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp
@@ -30,15 +30,13 @@ using namespace lldb_private;
 AppleThreadPlanStepThroughObjCTrampoline::
 AppleThreadPlanStepThroughObjCTrampoline(
 Thread &thread, AppleObjCTrampolineHandler &trampoline_handler,
-ValueList &input_values, lldb::addr_t isa_addr, lldb::addr_t sel_addr,
-bool stop_others)
+ValueList &input_values, lldb::addr_t isa_addr, lldb::addr_t sel_addr)
 : ThreadPlan(ThreadPlan::eKindGeneric,
  "MacOSX Step through ObjC Trampoline", thread, eVoteNoOpinion,
  eVoteNoOpinion),
   m_trampoline_handler(trampoline_handler),
   m_args_addr(LLDB_INVALID_ADDRESS), m_input_values(input_values),
-  m_isa_addr(isa_addr), m_sel_addr(sel_addr), m_impl_function(nullptr),
-  m_stop_others(stop_others) {}
+  m_isa_addr(isa_addr), m_sel_addr(sel_addr), m_impl_function(nullptr) {}
 
 // Destructor
 AppleThreadPlanStepThroughObjCTrampoline::
@@ -66,7 +64,7 @@ bool 
AppleThreadPlanStepThroughObjCTrampoline::InitializeFunctionCaller() {
 EvaluateExpressionOptions options;
 options.SetUnwindOnError(true);
 options.SetIgnoreBreakpoints(true);
-options.SetStopOthers(m_stop_others);
+options.SetStopOthers(false);
 GetThread().CalculateExecutionContext(exc_ctx);
 m_func_sp = m_impl_function->GetThreadPlanToCallFunction(
 exc_ctx, m_args_addr, options, diagnostics);
@@ -157,7 +155,7 @@ bool 
AppleThreadPlanStepThroughObjCTrampoline::ShouldStop(Event *event_ptr) {
   const bool first_insn = true;
   const uint32_t frame_idx = 0;
   m_run_to_sp = GetThread().QueueThreadPlanForStepOutNoShouldStop(
-  abo

[Lldb-commits] [PATCH] D96202: [lldb/test] Automatically find debug servers to test

2021-02-09 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added a comment.

In D96202#2550712 , @labath wrote:

> In D96202#2549497 , @JDevlieghere 
> wrote:
>
>> This will break my "run the tests against an Xcode install", but it seems 
>> like I should be able to work around that looking for debugserver in the 
>> LLDB.framework in `get_debugserver_exe`. Overall this is a pretty nice 
>> cleanup so seems like a fair trade-off. LGTM.
>
> What exactly is that use case? Do you want to run the tests with the 
> debugserver that comes with that xcode install? If that's the case, then I 
> would expect this to just work, as lldb knows that in a framework build, the 
> "support executable directory" is located inside the framework: 
> https://github.com/llvm/llvm-project/blob/main/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm#L138

Even better, that's exactly the logic I had in mind, but I was going to add it 
in dotest based on the `--framework` argument. Cool, cool, cool.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96202

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


[Lldb-commits] [PATCH] D95100: [lldb/Commands] Fix short option collision for `process launch`

2021-02-09 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision as: JDevlieghere.
JDevlieghere added a comment.
This revision is now accepted and ready to land.

LGTM, since nobody raised any concerns I think this is fine to land.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95100

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


[Lldb-commits] [PATCH] D95947: [lldb] [Process/FreeBSDRemote] Introduce powerpc support

2021-02-09 Thread Pavel Labath via Phabricator via lldb-commits
labath accepted this revision.
labath added a comment.

Seems legit.


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

https://reviews.llvm.org/D95947

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


[Lldb-commits] [PATCH] D95947: [lldb] [Process/FreeBSDRemote] Introduce powerpc support

2021-02-09 Thread Michał Górny via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbd03f6df51d1: [lldb] [Process/FreeBSDRemote] Introduce 
powerpc support (authored by mgorny).
Herald added a project: LLDB.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95947

Files:
  lldb/source/Host/common/NativeProcessProtocol.cpp
  lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
  lldb/source/Plugins/Process/FreeBSDRemote/CMakeLists.txt
  
lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_powerpc.cpp
  
lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_powerpc.h
  lldb/source/Plugins/Process/Utility/RegisterInfos_powerpc.h
  lldb/unittests/Process/Utility/RegisterContextFreeBSDTest.cpp

Index: lldb/unittests/Process/Utility/RegisterContextFreeBSDTest.cpp
===
--- lldb/unittests/Process/Utility/RegisterContextFreeBSDTest.cpp
+++ lldb/unittests/Process/Utility/RegisterContextFreeBSDTest.cpp
@@ -19,7 +19,9 @@
 
 #include "Plugins/Process/Utility/RegisterContextFreeBSD_i386.h"
 #include "Plugins/Process/Utility/RegisterContextFreeBSD_mips64.h"
+#include "Plugins/Process/Utility/RegisterContextFreeBSD_powerpc.h"
 #include "Plugins/Process/Utility/RegisterContextFreeBSD_x86_64.h"
+#include "Plugins/Process/Utility/RegisterContextPOSIX_powerpc.h"
 #include "Plugins/Process/Utility/RegisterInfoPOSIX_arm.h"
 #include "Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h"
 #include "Plugins/Process/Utility/lldb-arm-register-enums.h"
@@ -458,3 +460,95 @@
 }
 
 #endif // defined(__mips64__)
+
+#if defined(__powerpc__)
+
+#define EXPECT_GPR_PPC(lldb_reg, fbsd_reg)\
+  EXPECT_THAT(GetRegParams(reg_ctx, gpr_##lldb_reg##_powerpc),  \
+  ::testing::Pair(offsetof(reg, fbsd_reg),   \
+  sizeof(reg::fbsd_reg)))
+#define EXPECT_FPU_PPC(lldb_reg, fbsd_reg)   \
+  EXPECT_THAT(GetRegParams(reg_ctx, fpr_##lldb_reg##_powerpc),   \
+  ::testing::Pair(offsetof(fpreg, fbsd_reg) + base_offset, \
+  sizeof(fpreg::fbsd_reg)))
+
+TEST(RegisterContextFreeBSDTest, powerpc32) {
+  ArchSpec arch{"powerpc-unknown-freebsd"};
+  RegisterContextFreeBSD_powerpc32 reg_ctx{arch};
+
+  EXPECT_GPR_PPC(r0, fixreg[0]);
+  EXPECT_GPR_PPC(r1, fixreg[1]);
+  EXPECT_GPR_PPC(r2, fixreg[2]);
+  EXPECT_GPR_PPC(r3, fixreg[3]);
+  EXPECT_GPR_PPC(r4, fixreg[4]);
+  EXPECT_GPR_PPC(r5, fixreg[5]);
+  EXPECT_GPR_PPC(r6, fixreg[6]);
+  EXPECT_GPR_PPC(r7, fixreg[7]);
+  EXPECT_GPR_PPC(r8, fixreg[8]);
+  EXPECT_GPR_PPC(r9, fixreg[9]);
+  EXPECT_GPR_PPC(r10, fixreg[10]);
+  EXPECT_GPR_PPC(r11, fixreg[11]);
+  EXPECT_GPR_PPC(r12, fixreg[12]);
+  EXPECT_GPR_PPC(r13, fixreg[13]);
+  EXPECT_GPR_PPC(r14, fixreg[14]);
+  EXPECT_GPR_PPC(r15, fixreg[15]);
+  EXPECT_GPR_PPC(r16, fixreg[16]);
+  EXPECT_GPR_PPC(r17, fixreg[17]);
+  EXPECT_GPR_PPC(r18, fixreg[18]);
+  EXPECT_GPR_PPC(r19, fixreg[19]);
+  EXPECT_GPR_PPC(r20, fixreg[20]);
+  EXPECT_GPR_PPC(r21, fixreg[21]);
+  EXPECT_GPR_PPC(r22, fixreg[22]);
+  EXPECT_GPR_PPC(r23, fixreg[23]);
+  EXPECT_GPR_PPC(r24, fixreg[24]);
+  EXPECT_GPR_PPC(r25, fixreg[25]);
+  EXPECT_GPR_PPC(r26, fixreg[26]);
+  EXPECT_GPR_PPC(r27, fixreg[27]);
+  EXPECT_GPR_PPC(r28, fixreg[28]);
+  EXPECT_GPR_PPC(r29, fixreg[29]);
+  EXPECT_GPR_PPC(r30, fixreg[30]);
+  EXPECT_GPR_PPC(r31, fixreg[31]);
+  EXPECT_GPR_PPC(lr, lr);
+  EXPECT_GPR_PPC(cr, cr);
+  EXPECT_GPR_PPC(xer, xer);
+  EXPECT_GPR_PPC(ctr, ctr);
+  EXPECT_GPR_PPC(pc, pc);
+
+  size_t base_offset = reg_ctx.GetRegisterInfo()[fpr_f0_powerpc].byte_offset;
+
+  EXPECT_FPU_PPC(f0, fpreg[0]);
+  EXPECT_FPU_PPC(f1, fpreg[1]);
+  EXPECT_FPU_PPC(f2, fpreg[2]);
+  EXPECT_FPU_PPC(f3, fpreg[3]);
+  EXPECT_FPU_PPC(f4, fpreg[4]);
+  EXPECT_FPU_PPC(f5, fpreg[5]);
+  EXPECT_FPU_PPC(f6, fpreg[6]);
+  EXPECT_FPU_PPC(f7, fpreg[7]);
+  EXPECT_FPU_PPC(f8, fpreg[8]);
+  EXPECT_FPU_PPC(f9, fpreg[9]);
+  EXPECT_FPU_PPC(f10, fpreg[10]);
+  EXPECT_FPU_PPC(f11, fpreg[11]);
+  EXPECT_FPU_PPC(f12, fpreg[12]);
+  EXPECT_FPU_PPC(f13, fpreg[13]);
+  EXPECT_FPU_PPC(f14, fpreg[14]);
+  EXPECT_FPU_PPC(f15, fpreg[15]);
+  EXPECT_FPU_PPC(f16, fpreg[16]);
+  EXPECT_FPU_PPC(f17, fpreg[17]);
+  EXPECT_FPU_PPC(f18, fpreg[18]);
+  EXPECT_FPU_PPC(f19, fpreg[19]);
+  EXPECT_FPU_PPC(f20, fpreg[20]);
+  EXPECT_FPU_PPC(f21, fpreg[21]);
+  EXPECT_FPU_PPC(f22, fpreg[22]);
+  EXPECT_FPU_PPC(f23, fpreg[23]);
+  EXPECT_FPU_PPC(f24, fpreg[24]);
+  EXPECT_FPU_PPC(f25, fpreg[25]);
+  EXPECT_FPU_PPC(f26, fpreg[26]);
+  EXPECT_FPU_PPC(f27, fpreg[27]);
+  EXPECT_FPU_PPC(f28, fpreg[28]);
+  EXPECT_FPU_PPC(f29, fpreg[29]);
+  EXPECT_FPU_PPC(f30, fpreg[30]);
+  EXPECT_FPU_PPC(f31, fpreg[31]);
+  EXPECT_FPU_PPC(fpscr, fpscr);
+}
+
+#endif // defined(__powerpc__)
Index: lld

[Lldb-commits] [lldb] bd03f6d - [lldb] [Process/FreeBSDRemote] Introduce powerpc support

2021-02-09 Thread Michał Górny via lldb-commits

Author: Michał Górny
Date: 2021-02-09T21:10:45+01:00
New Revision: bd03f6df51d161551a0439d8f51e2640a218048f

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

LOG: [lldb] [Process/FreeBSDRemote] Introduce powerpc support

Introduce a minimal support for the 32-bit powerpc platform.  This
includes support for GPR and FPR registers.  I also needed to add
software breakpoint opcode for PPC32/PPC64 (big endian), and to fix
offsets in RegisterInfos_powerpc.h (used only by FreeBSD register
context to be globally unique rather than relative to each struct).

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

Added: 

lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_powerpc.cpp

lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_powerpc.h

Modified: 
lldb/source/Host/common/NativeProcessProtocol.cpp
lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
lldb/source/Plugins/Process/FreeBSDRemote/CMakeLists.txt
lldb/source/Plugins/Process/Utility/RegisterInfos_powerpc.h
lldb/unittests/Process/Utility/RegisterContextFreeBSDTest.cpp

Removed: 




diff  --git a/lldb/source/Host/common/NativeProcessProtocol.cpp 
b/lldb/source/Host/common/NativeProcessProtocol.cpp
index 493e14cb904b..070fda664678 100644
--- a/lldb/source/Host/common/NativeProcessProtocol.cpp
+++ b/lldb/source/Host/common/NativeProcessProtocol.cpp
@@ -522,7 +522,8 @@ 
NativeProcessProtocol::GetSoftwareBreakpointTrapOpcode(size_t size_hint) {
   static const uint8_t g_mips64_opcode[] = {0x00, 0x00, 0x00, 0x0d};
   static const uint8_t g_mips64el_opcode[] = {0x0d, 0x00, 0x00, 0x00};
   static const uint8_t g_s390x_opcode[] = {0x00, 0x01};
-  static const uint8_t g_ppc64le_opcode[] = {0x08, 0x00, 0xe0, 0x7f}; // trap
+  static const uint8_t g_ppc_opcode[] = {0x7f, 0xe0, 0x00, 0x08}; // trap
+  static const uint8_t g_ppcle_opcode[] = {0x08, 0x00, 0xe0, 0x7f}; // trap
 
   switch (GetArchitecture().GetMachine()) {
   case llvm::Triple::aarch64:
@@ -544,8 +545,12 @@ 
NativeProcessProtocol::GetSoftwareBreakpointTrapOpcode(size_t size_hint) {
   case llvm::Triple::systemz:
 return llvm::makeArrayRef(g_s390x_opcode);
 
+  case llvm::Triple::ppc:
+  case llvm::Triple::ppc64:
+return llvm::makeArrayRef(g_ppc_opcode);
+
   case llvm::Triple::ppc64le:
-return llvm::makeArrayRef(g_ppc64le_opcode);
+return llvm::makeArrayRef(g_ppcle_opcode);
 
   default:
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
@@ -568,6 +573,8 @@ size_t 
NativeProcessProtocol::GetSoftwareBreakpointPCOffset() {
   case llvm::Triple::mips64el:
   case llvm::Triple::mips:
   case llvm::Triple::mipsel:
+  case llvm::Triple::ppc:
+  case llvm::Triple::ppc64:
   case llvm::Triple::ppc64le:
 // On these architectures the PC doesn't get updated for breakpoint hits.
 return 0;

diff  --git a/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp 
b/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
index 7994e602703a..e16c573b93f9 100644
--- a/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
+++ b/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
@@ -256,6 +256,7 @@ bool PlatformFreeBSD::CanDebugProcess() {
   case llvm::Triple::aarch64:
   case llvm::Triple::arm:
   case llvm::Triple::mips64:
+  case llvm::Triple::ppc:
   case llvm::Triple::x86:
   case llvm::Triple::x86_64:
 use_legacy_plugin = !!getenv("FREEBSD_LEGACY_PLUGIN");

diff  --git a/lldb/source/Plugins/Process/FreeBSDRemote/CMakeLists.txt 
b/lldb/source/Plugins/Process/FreeBSDRemote/CMakeLists.txt
index 826d7162967a..7480154d9998 100644
--- a/lldb/source/Plugins/Process/FreeBSDRemote/CMakeLists.txt
+++ b/lldb/source/Plugins/Process/FreeBSDRemote/CMakeLists.txt
@@ -4,6 +4,7 @@ add_lldb_library(lldbPluginProcessFreeBSDRemote
   NativeRegisterContextFreeBSD_arm.cpp
   NativeRegisterContextFreeBSD_arm64.cpp
   NativeRegisterContextFreeBSD_mips64.cpp
+  NativeRegisterContextFreeBSD_powerpc.cpp
   NativeRegisterContextFreeBSD_x86_64.cpp
   NativeThreadFreeBSD.cpp
 

diff  --git 
a/lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_powerpc.cpp
 
b/lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_powerpc.cpp
new file mode 100644
index ..f923507b595d
--- /dev/null
+++ 
b/lldb/source/Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD_powerpc.cpp
@@ -0,0 +1,289 @@
+//===-- NativeRegisterContextFreeBSD_powerpc.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
+//
+//===-

[Lldb-commits] [PATCH] D96366: Remove uneeded CopyType from BlockPointerSyntheticFrontEnd

2021-02-09 Thread Shafik Yaghmour via Phabricator via lldb-commits
shafik created this revision.
shafik added reviewers: teemperor, aprantl.
shafik requested review of this revision.

`BlockPointerSyntheticFrontEnd` does a `CopyType` which results in it copying 
the type back into its own context. This will result in a call to 
`ASTImporterDelegate::setOrigin` with `&decl->getASTContext() == origin.ctx` 
this can result in an infinite recursion later on in `ASTImporter` since it 
will attempt to find the decl in its origin which will be itself.


https://reviews.llvm.org/D96366

Files:
  lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
  lldb/test/API/lang/c/blocks/TestBlocks.py
  lldb/test/API/lang/c/blocks/main.c


Index: lldb/test/API/lang/c/blocks/main.c
===
--- lldb/test/API/lang/c/blocks/main.c
+++ lldb/test/API/lang/c/blocks/main.c
@@ -1,5 +1,17 @@
 #include 
 
+struct CG {int x; int y;};
+
+int g(int (^callback)(struct CG)) {
+   struct CG cg = {.x=1,.y=2};
+
+   int z = callback(cg); // Set breakpoint 2 here.
+
+   return z;
+}
+
+int h(struct CG cg){return 42;}
+
 int main()
 {
 int c = 1;
@@ -17,5 +29,12 @@
 printf("%d\n", add(3, 4));
 printf("%d\n", neg(-5)); // Set breakpoint 1 here.
 
+int (^add_struct)(struct CG) = ^int(struct CG cg)
+{
+return cg.x + cg.y;
+};
+
+g(add_struct);
+
 return 0;
 }
Index: lldb/test/API/lang/c/blocks/TestBlocks.py
===
--- lldb/test/API/lang/c/blocks/TestBlocks.py
+++ lldb/test/API/lang/c/blocks/TestBlocks.py
@@ -20,6 +20,7 @@
 # Find the line numbers to break at.
 self.lines.append(line_number('main.c', '// Set breakpoint 0 here.'))
 self.lines.append(line_number('main.c', '// Set breakpoint 1 here.'))
+self.lines.append(line_number('main.c', '// Set breakpoint 2 here.'))
 
 def launch_common(self):
 self.build()
@@ -51,6 +52,10 @@
 self.expect("expression (int)neg (-12)", VARIABLES_DISPLAYED_CORRECTLY,
 substrs=["= 12"])
 
+self.wait_for_breakpoint()
+
+self.expect_expr("h(cg)", result_type="int", result_value="42")
+
 @skipUnlessDarwin
 def test_define(self):
 self.launch_common()
Index: lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
===
--- lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
+++ lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
@@ -74,14 +74,12 @@
 const CompilerType reserved_type =
 clang_ast_context->GetBasicType(lldb::eBasicTypeInt);
 const char *const FuncPtr_name("__FuncPtr");
-const CompilerType FuncPtr_type =
-clang_ast_importer->CopyType(*clang_ast_context, 
function_pointer_type);
 
 m_block_struct_type = clang_ast_context->CreateStructForIdentifier(
 ConstString(), {{isa_name, isa_type},
 {flags_name, flags_type},
 {reserved_name, reserved_type},
-{FuncPtr_name, FuncPtr_type}});
+{FuncPtr_name, function_pointer_type}});
   }
 
   ~BlockPointerSyntheticFrontEnd() override = default;


Index: lldb/test/API/lang/c/blocks/main.c
===
--- lldb/test/API/lang/c/blocks/main.c
+++ lldb/test/API/lang/c/blocks/main.c
@@ -1,5 +1,17 @@
 #include 
 
+struct CG {int x; int y;};
+
+int g(int (^callback)(struct CG)) {
+   struct CG cg = {.x=1,.y=2};
+
+   int z = callback(cg); // Set breakpoint 2 here.
+
+   return z;
+}
+
+int h(struct CG cg){return 42;}
+
 int main()
 {
 int c = 1;
@@ -17,5 +29,12 @@
 printf("%d\n", add(3, 4));
 printf("%d\n", neg(-5)); // Set breakpoint 1 here.
 
+int (^add_struct)(struct CG) = ^int(struct CG cg)
+{
+return cg.x + cg.y;
+};
+
+g(add_struct);
+
 return 0;
 }
Index: lldb/test/API/lang/c/blocks/TestBlocks.py
===
--- lldb/test/API/lang/c/blocks/TestBlocks.py
+++ lldb/test/API/lang/c/blocks/TestBlocks.py
@@ -20,6 +20,7 @@
 # Find the line numbers to break at.
 self.lines.append(line_number('main.c', '// Set breakpoint 0 here.'))
 self.lines.append(line_number('main.c', '// Set breakpoint 1 here.'))
+self.lines.append(line_number('main.c', '// Set breakpoint 2 here.'))
 
 def launch_common(self):
 self.build()
@@ -51,6 +52,10 @@
 self.expect("expression (int)neg (-12)", VARIABLES_DISPLAYED_CORRECTLY,
 substrs=["= 12"])
 
+self.wait_for_breakpoint()
+
+self.expect_expr("h(cg)", result_type="int", result_value="42")
+
 @skipUnlessDarwin
 def test_define(self):
 self.launch_common()
Index: lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
===
--- lldb/source/Plugins

[Lldb-commits] [PATCH] D96366: Remove uneeded CopyType from BlockPointerSyntheticFrontEnd

2021-02-09 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor accepted this revision.
teemperor added a comment.
This revision is now accepted and ready to land.

LGTM, thank you!




Comment at: lldb/test/API/lang/c/blocks/main.c:10
+
+   return z;
+}

4 spaces indentation instead of 3 (2 would probably be better, but this was 
already written with 4 so let's just keep the file in one code style).


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

https://reviews.llvm.org/D96366

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


[Lldb-commits] [PATCH] D96368: Document the "extra_args" parameter to scripted breakpoint callbacks

2021-02-09 Thread Jim Ingham via Phabricator via lldb-commits
jingham created this revision.
jingham added a reviewer: JDevlieghere.
jingham requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

I forgot to document this when adding the feature.  Added docs here in both the 
python-reference.rst and in the command help.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96368

Files:
  lldb/docs/use/python-reference.rst
  lldb/source/Commands/CommandObjectBreakpointCommand.cpp


Index: lldb/source/Commands/CommandObjectBreakpointCommand.cpp
===
--- lldb/source/Commands/CommandObjectBreakpointCommand.cpp
+++ lldb/source/Commands/CommandObjectBreakpointCommand.cpp
@@ -117,14 +117,22 @@
 
 --python-function myutils.breakpoint_callback
 
-The function itself must have the following prototype:
+The function itself must have either of the following prototypes:
 
 def breakpoint_callback(frame, bp_loc, dict):
   # Your code goes here
 
+or:
+
+def breakpoint_callback(frame, bp_loc, extra_args, dict):
+  # Your code goes here
+
 )"
 "The arguments are the same as the arguments passed to generated 
functions as \
-described above.  Note that the global variable 'lldb.frame' will NOT be 
updated when \
+described above.  In the second form, any -k and -v pairs provided to the 
command will \ 
+be packaged into a SBDictionary in an SBStructuredData and passed as the 
extra_args parameter. \
+\n\n\  
+Note that the global variable 'lldb.frame' will NOT be updated when \
 this function is called, so be sure to use the 'frame' argument. The 'frame' 
argument \
 can get you to the thread via frame.GetThread(), the thread can get you to the 
\
 process via thread.GetProcess(), and the process can get you back to the 
target \
Index: lldb/docs/use/python-reference.rst
===
--- lldb/docs/use/python-reference.rst
+++ lldb/docs/use/python-reference.rst
@@ -182,20 +182,32 @@
   def breakpoint_function_wrapper(frame, bp_loc, dict):
  # Your code goes here
 
+or:
 
-++---+---+
-| Argument   | Type  | Description 

  |
-++---+---+
-| **frame**  | **lldb.SBFrame**  | The current stack frame where 
the breakpoint got hit. 
|
-||   | The object will always be 
valid.  
|
-||   | This **frame** argument might 
*not* match the currently selected stack frame found in the **lldb** module 
global variable **lldb.frame**. |
-++---+---+
-| **bp_loc** | **lldb.SBBreakpointLocation** | The breakpoint location that 
just got hit. Breakpoints are represented by **lldb.SBBreakpoint**  
 |
-||   | objects. These breakpoint 
objects can have one or more locations. These locations 
|
-||   | are represented by 
**lldb.SBBreakpointLocation** objects.  
   |
-++---+---+
-| **dict**   | **dict**  | The python session dictionary 
as a standard python dictionary object. 
|
-++---+---+
+::
+
+  def breakpoint_function_wrapper(frame, bp_loc, extra_args, dict):
+ # Your code goes here
+
+
+++---+---+
+| Argument   | Type  | Description 

[Lldb-commits] [PATCH] D96370: Pass enviroment variables to python scripts.

2021-02-09 Thread Rumeet Dhindsa via Phabricator via lldb-commits
rdhindsa created this revision.
rdhindsa added a reviewer: labath.
rdhindsa requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

It enables environment variables set for lldb targets to be passed to python 
scripts. This allows the user to put Python scripts at different locations, but 
being able to import them by setting pythonpath.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96370

Files:
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
  lldb/test/Shell/ScriptInterpreter/Python/Inputs/environ.py
  lldb/test/Shell/ScriptInterpreter/Python/pass_environment.test


Index: lldb/test/Shell/ScriptInterpreter/Python/pass_environment.test
===
--- /dev/null
+++ lldb/test/Shell/ScriptInterpreter/Python/pass_environment.test
@@ -0,0 +1,10 @@
+# REQUIRES: python
+
+# RUN: %lldb --batch \
+# RUN:--script-language python \
+# RUN:-O 'settings append target.env-vars PYTHONPATH=/tmp' \
+# RUN:-O 'command script import %S/Inputs/environ.py' \
+# RUN:-O 'test' 2>&1  | FileCheck %s
+
+# CHECK: :/tmp
+# CHECK: '/tmp'
Index: lldb/test/Shell/ScriptInterpreter/Python/Inputs/environ.py
===
--- /dev/null
+++ lldb/test/Shell/ScriptInterpreter/Python/Inputs/environ.py
@@ -0,0 +1,10 @@
+import os
+import sys
+
+def test(debugger, command, result, internal_dict):
+  print(os.environ["PYTHONPATH"])
+  print(sys.path)
+
+def __lldb_init_module(debugger, internal_dict):
+  debugger.HandleCommand('command script add -f environ.test test')
+
Index: 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
@@ -341,6 +341,8 @@
  lldb::user_id_t watch_id);
   static void InitializePrivate();
 
+  static void SetPythonEnvironment(Debugger& debugger);
+
   class SynchronicityHandler {
   private:
 lldb::DebuggerSP m_debugger_sp;
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -537,6 +537,8 @@
   PyRun_SimpleString(run_string.GetData());
   run_string.Clear();
 
+  SetPythonEnvironment(m_debugger);
+
   run_string.Printf("run_one_line (%s, 'import lldb.embedded_interpreter; from 
"
 "lldb.embedded_interpreter import run_python_interpreter; "
 "from lldb.embedded_interpreter import run_one_line')",
@@ -3269,6 +3271,26 @@
  "from lldb.embedded_interpreter import run_one_line");
 }
 
+void ScriptInterpreterPythonImpl::SetPythonEnvironment(Debugger &debugger) {
+  StreamString run_string;
+  lldb::TargetSP target_get = debugger.GetTargetList().GetSelectedTarget();
+  const Environment &env = target_get->GetGlobalProperties()->GetEnvironment();
+
+  PyRun_SimpleString("import os");
+  for (const auto &KV : env) {
+if (strcmp(KV.getKey().data(), "PYTHONPATH") == 0 ||
+strcmp(KV.getKey().data(), "PATH") == 0) {
+  run_string.Clear();
+  run_string.Printf(
+  "os.environ[\"%s\"] = os.environ.get(\"%s\",\"\")+ os.pathsep +"
+  "\"%s\"",
+  KV.getKey().data(), KV.getKey().data(), KV.getValue().data());
+  PyRun_SimpleString(run_string.GetData());
+  AddToSysPath(AddLocation::End, KV.getValue().data());
+}
+  }
+}
+
 void ScriptInterpreterPythonImpl::AddToSysPath(AddLocation location,
std::string path) {
   std::string path_copy;


Index: lldb/test/Shell/ScriptInterpreter/Python/pass_environment.test
===
--- /dev/null
+++ lldb/test/Shell/ScriptInterpreter/Python/pass_environment.test
@@ -0,0 +1,10 @@
+# REQUIRES: python
+
+# RUN: %lldb --batch \
+# RUN:--script-language python \
+# RUN:-O 'settings append target.env-vars PYTHONPATH=/tmp' \
+# RUN:-O 'command script import %S/Inputs/environ.py' \
+# RUN:-O 'test' 2>&1  | FileCheck %s
+
+# CHECK: :/tmp
+# CHECK: '/tmp'
Index: lldb/test/Shell/ScriptInterpreter/Python/Inputs/environ.py
===
--- /dev/null
+++ lldb/test/Shell/ScriptInterpreter/Python/Inputs/environ.py
@@ -0,0 +1,10 @@
+import os
+import sys
+
+def test(debugger, command, result, internal_dict):
+  print(os.environ["PYTHONPATH"])
+  print(sys.path)
+
+def __lldb_init_module(debugger, intern

[Lldb-commits] [PATCH] D96368: Document the "extra_args" parameter to scripted breakpoint callbacks

2021-02-09 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96368

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


[Lldb-commits] [PATCH] D96370: Pass enviroment variables to python scripts.

2021-02-09 Thread Rumeet Dhindsa via Phabricator via lldb-commits
rdhindsa updated this revision to Diff 322510.

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

https://reviews.llvm.org/D96370

Files:
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
  lldb/test/Shell/ScriptInterpreter/Python/Inputs/environ.py
  lldb/test/Shell/ScriptInterpreter/Python/pass_environment.test


Index: lldb/test/Shell/ScriptInterpreter/Python/pass_environment.test
===
--- /dev/null
+++ lldb/test/Shell/ScriptInterpreter/Python/pass_environment.test
@@ -0,0 +1,10 @@
+# REQUIRES: python
+
+# RUN: %lldb --batch \
+# RUN:--script-language python \
+# RUN:-O 'settings append target.env-vars PYTHONPATH=/tmp' \
+# RUN:-O 'command script import %S/Inputs/environ.py' \
+# RUN:-O 'test' 2>&1  | FileCheck %s
+
+# CHECK: :/tmp
+# CHECK: '/tmp'
Index: lldb/test/Shell/ScriptInterpreter/Python/Inputs/environ.py
===
--- /dev/null
+++ lldb/test/Shell/ScriptInterpreter/Python/Inputs/environ.py
@@ -0,0 +1,10 @@
+import os
+import sys
+
+def test(debugger, command, result, internal_dict):
+  print(os.environ["PYTHONPATH"])
+  print(sys.path)
+
+def __lldb_init_module(debugger, internal_dict):
+  debugger.HandleCommand('command script add -f environ.test test')
+
Index: 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
@@ -341,6 +341,8 @@
  lldb::user_id_t watch_id);
   static void InitializePrivate();
 
+  static void SetPythonEnvironment(Debugger &debugger);
+
   class SynchronicityHandler {
   private:
 lldb::DebuggerSP m_debugger_sp;
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -537,6 +537,8 @@
   PyRun_SimpleString(run_string.GetData());
   run_string.Clear();
 
+  SetPythonEnvironment(m_debugger);
+
   run_string.Printf("run_one_line (%s, 'import lldb.embedded_interpreter; from 
"
 "lldb.embedded_interpreter import run_python_interpreter; "
 "from lldb.embedded_interpreter import run_one_line')",
@@ -3269,6 +3271,26 @@
  "from lldb.embedded_interpreter import run_one_line");
 }
 
+void ScriptInterpreterPythonImpl::SetPythonEnvironment(Debugger &debugger) {
+  StreamString run_string;
+  lldb::TargetSP target_get = debugger.GetTargetList().GetSelectedTarget();
+  const Environment &env = target_get->GetGlobalProperties()->GetEnvironment();
+
+  PyRun_SimpleString("import os");
+  for (const auto &KV : env) {
+if (strcmp(KV.getKey().data(), "PYTHONPATH") == 0 ||
+strcmp(KV.getKey().data(), "PATH") == 0) {
+  run_string.Clear();
+  run_string.Printf(
+  "os.environ[\"%s\"] = os.environ.get(\"%s\",\"\")+ os.pathsep +"
+  "\"%s\"",
+  KV.getKey().data(), KV.getKey().data(), KV.getValue().data());
+  PyRun_SimpleString(run_string.GetData());
+  AddToSysPath(AddLocation::End, KV.getValue().data());
+}
+  }
+}
+
 void ScriptInterpreterPythonImpl::AddToSysPath(AddLocation location,
std::string path) {
   std::string path_copy;


Index: lldb/test/Shell/ScriptInterpreter/Python/pass_environment.test
===
--- /dev/null
+++ lldb/test/Shell/ScriptInterpreter/Python/pass_environment.test
@@ -0,0 +1,10 @@
+# REQUIRES: python
+
+# RUN: %lldb --batch \
+# RUN:--script-language python \
+# RUN:-O 'settings append target.env-vars PYTHONPATH=/tmp' \
+# RUN:-O 'command script import %S/Inputs/environ.py' \
+# RUN:-O 'test' 2>&1  | FileCheck %s
+
+# CHECK: :/tmp
+# CHECK: '/tmp'
Index: lldb/test/Shell/ScriptInterpreter/Python/Inputs/environ.py
===
--- /dev/null
+++ lldb/test/Shell/ScriptInterpreter/Python/Inputs/environ.py
@@ -0,0 +1,10 @@
+import os
+import sys
+
+def test(debugger, command, result, internal_dict):
+  print(os.environ["PYTHONPATH"])
+  print(sys.path)
+
+def __lldb_init_module(debugger, internal_dict):
+  debugger.HandleCommand('command script add -f environ.test test')
+
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
+++ lldb

[Lldb-commits] [PATCH] D96370: Pass enviroment variables to python scripts.

2021-02-09 Thread Jim Ingham via Phabricator via lldb-commits
jingham requested changes to this revision.
jingham added a comment.
This revision now requires changes to proceed.

Modifying the target environment in order to add something to the host lldb's 
PYTHONPATH seems very counterintuitive to me.  It is misusing the purpose of 
the target environment setting.  And it could cause confusion if you set this 
up (say in your .lldbinit) and then months later wondered why some Python 
program you were debugging ended up finding python modules in weird places...  
If you want to have a way to add to lldb's python interpreter's path when 
starting lldb, then there should be a setting for that specific purpose.

Also, this would need some sort of documention.  There's no way anybody could 
discover this feature without reading the lldb sources.

Also also, if I put:

script import sys; sys.path.append("/some/directory")

in my .lldbinit, wouldn't that do the same thing your patch does, but in a much 
more straightforward way?  I don't see the advantage of doing this in a 
setting, and certainly not in the target env-vars setting.




Comment at: 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp:3280
+  PyRun_SimpleString("import os");
+  for (const auto &KV : env) {
+if (strcmp(KV.getKey().data(), "PYTHONPATH") == 0 ||

lldb local variables should always be lower case, and should be words.  I'm 
assuming the this is called KV because it's a key/value entry, but it took me 
too much time to guess that. "key_value" or something would make this easier to 
read.


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

https://reviews.llvm.org/D96370

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


[Lldb-commits] [lldb] 365b186 - Add documentation for the extra_args parameter to breakpoint commands.

2021-02-09 Thread Jim Ingham via lldb-commits

Author: Jim Ingham
Date: 2021-02-09T15:33:36-08:00
New Revision: 365b186c242b0c3516d7dbb174f3a258c1c8361c

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

LOG: Add documentation for the extra_args parameter to breakpoint commands.

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

Added: 


Modified: 
lldb/docs/use/python-reference.rst
lldb/source/Commands/CommandObjectBreakpointCommand.cpp

Removed: 




diff  --git a/lldb/docs/use/python-reference.rst 
b/lldb/docs/use/python-reference.rst
index e5542bb5b0ae..f3ce744128c9 100644
--- a/lldb/docs/use/python-reference.rst
+++ b/lldb/docs/use/python-reference.rst
@@ -182,20 +182,32 @@ arguments:
   def breakpoint_function_wrapper(frame, bp_loc, dict):
  # Your code goes here
 
+or:
 
-++---+---+
-| Argument   | Type  | Description 

  |
-++---+---+
-| **frame**  | **lldb.SBFrame**  | The current stack frame where 
the breakpoint got hit. 
|
-||   | The object will always be 
valid.  
|
-||   | This **frame** argument might 
*not* match the currently selected stack frame found in the **lldb** module 
global variable **lldb.frame**. |
-++---+---+
-| **bp_loc** | **lldb.SBBreakpointLocation** | The breakpoint location that 
just got hit. Breakpoints are represented by **lldb.SBBreakpoint**  
 |
-||   | objects. These breakpoint 
objects can have one or more locations. These locations 
|
-||   | are represented by 
**lldb.SBBreakpointLocation** objects.  
   |
-++---+---+
-| **dict**   | **dict**  | The python session dictionary 
as a standard python dictionary object. 
|
-++---+---+
+::
+
+  def breakpoint_function_wrapper(frame, bp_loc, extra_args, dict):
+ # Your code goes here
+
+
+++---+---+
+| Argument   | Type  | Description 

  |
+++---+---+
+| **frame**  | **lldb.SBFrame**  | The current stack frame 
where the breakpoint got hit.   
  |
+||   | The object will always be 
valid.  
|
+||   | This **frame** argument 
might *not* match the currently selected stack frame found in the **lldb** 
module global variable **lldb.frame**. |
+++---+---+
+| **bp_loc** | **lldb.SBBreakpointLocation** | The breakpoint location 
that just got 

[Lldb-commits] [PATCH] D96368: Document the "extra_args" parameter to scripted breakpoint callbacks

2021-02-09 Thread Jim Ingham via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG365b186c242b: Add documentation for the extra_args parameter 
to breakpoint commands. (authored by jingham).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96368

Files:
  lldb/docs/use/python-reference.rst
  lldb/source/Commands/CommandObjectBreakpointCommand.cpp


Index: lldb/source/Commands/CommandObjectBreakpointCommand.cpp
===
--- lldb/source/Commands/CommandObjectBreakpointCommand.cpp
+++ lldb/source/Commands/CommandObjectBreakpointCommand.cpp
@@ -117,14 +117,22 @@
 
 --python-function myutils.breakpoint_callback
 
-The function itself must have the following prototype:
+The function itself must have either of the following prototypes:
 
 def breakpoint_callback(frame, bp_loc, dict):
   # Your code goes here
 
+or:
+
+def breakpoint_callback(frame, bp_loc, extra_args, dict):
+  # Your code goes here
+
 )"
 "The arguments are the same as the arguments passed to generated 
functions as \
-described above.  Note that the global variable 'lldb.frame' will NOT be 
updated when \
+described above.  In the second form, any -k and -v pairs provided to the 
command will \ 
+be packaged into a SBDictionary in an SBStructuredData and passed as the 
extra_args parameter. \
+\n\n\  
+Note that the global variable 'lldb.frame' will NOT be updated when \
 this function is called, so be sure to use the 'frame' argument. The 'frame' 
argument \
 can get you to the thread via frame.GetThread(), the thread can get you to the 
\
 process via thread.GetProcess(), and the process can get you back to the 
target \
Index: lldb/docs/use/python-reference.rst
===
--- lldb/docs/use/python-reference.rst
+++ lldb/docs/use/python-reference.rst
@@ -182,20 +182,32 @@
   def breakpoint_function_wrapper(frame, bp_loc, dict):
  # Your code goes here
 
+or:
 
-++---+---+
-| Argument   | Type  | Description 

  |
-++---+---+
-| **frame**  | **lldb.SBFrame**  | The current stack frame where 
the breakpoint got hit. 
|
-||   | The object will always be 
valid.  
|
-||   | This **frame** argument might 
*not* match the currently selected stack frame found in the **lldb** module 
global variable **lldb.frame**. |
-++---+---+
-| **bp_loc** | **lldb.SBBreakpointLocation** | The breakpoint location that 
just got hit. Breakpoints are represented by **lldb.SBBreakpoint**  
 |
-||   | objects. These breakpoint 
objects can have one or more locations. These locations 
|
-||   | are represented by 
**lldb.SBBreakpointLocation** objects.  
   |
-++---+---+
-| **dict**   | **dict**  | The python session dictionary 
as a standard python dictionary object. 
|
-++---+---+
+::
+
+  def breakpoint_function_wrapper(frame, bp_loc, extra_args, dict):
+ # Your code goes here
+
+
+++---+---+
+| Argument   | Type  | Description 
  

[Lldb-commits] [lldb] ffd7be6 - Remove trailing spaces after \ in comments.

2021-02-09 Thread Jim Ingham via lldb-commits

Author: Jim Ingham
Date: 2021-02-09T16:06:47-08:00
New Revision: ffd7be65d0efbe8448b8fa051ad213be51e8c367

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

LOG: Remove trailing spaces after \ in comments.

Added: 


Modified: 
lldb/source/Commands/CommandObjectBreakpointCommand.cpp

Removed: 




diff  --git a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp 
b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp
index 241a75e7fbb2..1b2149525d80 100644
--- a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp
+++ b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp
@@ -129,9 +129,9 @@ def breakpoint_callback(frame, bp_loc, extra_args, dict):
 
 )"
 "The arguments are the same as the arguments passed to generated 
functions as \
-described above.  In the second form, any -k and -v pairs provided to the 
command will \ 
+described above.  In the second form, any -k and -v pairs provided to the 
command will \
 be packaged into a SBDictionary in an SBStructuredData and passed as the 
extra_args parameter. \
-\n\n\  
+\n\n\
 Note that the global variable 'lldb.frame' will NOT be updated when \
 this function is called, so be sure to use the 'frame' argument. The 'frame' 
argument \
 can get you to the thread via frame.GetThread(), the thread can get you to the 
\



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


[Lldb-commits] [lldb] 4f14c17 - [LLDB] Remove uneeded CopyType from BlockPointerSyntheticFrontEnd

2021-02-09 Thread Shafik Yaghmour via lldb-commits

Author: Shafik Yaghmour
Date: 2021-02-09T16:11:28-08:00
New Revision: 4f14c17df70916913d71914343dd4f6c709e218d

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

LOG: [LLDB] Remove uneeded CopyType from BlockPointerSyntheticFrontEnd

BlockPointerSyntheticFrontEnd does a CopyType which results in it copying the 
type
back into its own context. This will result in a call to 
ASTImporterDelegate::setOrigin
with &decl->getASTContext() == origin.ctx this can result in an infinite 
recursion
later on in ASTImporter since it will attempt to find the decl in its origin 
which will be itself.

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

Added: 


Modified: 
lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
lldb/test/API/lang/c/blocks/TestBlocks.py
lldb/test/API/lang/c/blocks/main.c

Removed: 




diff  --git a/lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
index 35788a6445c2..1c498a2ddc11 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
@@ -74,14 +74,12 @@ class BlockPointerSyntheticFrontEnd : public 
SyntheticChildrenFrontEnd {
 const CompilerType reserved_type =
 clang_ast_context->GetBasicType(lldb::eBasicTypeInt);
 const char *const FuncPtr_name("__FuncPtr");
-const CompilerType FuncPtr_type =
-clang_ast_importer->CopyType(*clang_ast_context, 
function_pointer_type);
 
 m_block_struct_type = clang_ast_context->CreateStructForIdentifier(
 ConstString(), {{isa_name, isa_type},
 {flags_name, flags_type},
 {reserved_name, reserved_type},
-{FuncPtr_name, FuncPtr_type}});
+{FuncPtr_name, function_pointer_type}});
   }
 
   ~BlockPointerSyntheticFrontEnd() override = default;

diff  --git a/lldb/test/API/lang/c/blocks/TestBlocks.py 
b/lldb/test/API/lang/c/blocks/TestBlocks.py
index cd82d1592481..99ea22a69dd6 100644
--- a/lldb/test/API/lang/c/blocks/TestBlocks.py
+++ b/lldb/test/API/lang/c/blocks/TestBlocks.py
@@ -20,6 +20,7 @@ def setUp(self):
 # Find the line numbers to break at.
 self.lines.append(line_number('main.c', '// Set breakpoint 0 here.'))
 self.lines.append(line_number('main.c', '// Set breakpoint 1 here.'))
+self.lines.append(line_number('main.c', '// Set breakpoint 2 here.'))
 
 def launch_common(self):
 self.build()
@@ -51,6 +52,10 @@ def test_expr(self):
 self.expect("expression (int)neg (-12)", VARIABLES_DISPLAYED_CORRECTLY,
 substrs=["= 12"])
 
+self.wait_for_breakpoint()
+
+self.expect_expr("h(cg)", result_type="int", result_value="42")
+
 @skipUnlessDarwin
 def test_define(self):
 self.launch_common()

diff  --git a/lldb/test/API/lang/c/blocks/main.c 
b/lldb/test/API/lang/c/blocks/main.c
index 415e6c6d033d..b1b215ec2331 100644
--- a/lldb/test/API/lang/c/blocks/main.c
+++ b/lldb/test/API/lang/c/blocks/main.c
@@ -1,5 +1,17 @@
 #include 
 
+struct CG {int x; int y;};
+
+int g(int (^callback)(struct CG)) {
+   struct CG cg = {.x=1,.y=2};
+
+   int z = callback(cg); // Set breakpoint 2 here.
+
+   return z;
+}
+
+int h(struct CG cg){return 42;}
+
 int main()
 {
 int c = 1;
@@ -17,5 +29,12 @@ int main()
 printf("%d\n", add(3, 4));
 printf("%d\n", neg(-5)); // Set breakpoint 1 here.
 
+int (^add_struct)(struct CG) = ^int(struct CG cg)
+{
+return cg.x + cg.y;
+};
+
+g(add_struct);
+
 return 0;
 }



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


[Lldb-commits] [PATCH] D96366: Remove uneeded CopyType from BlockPointerSyntheticFrontEnd

2021-02-09 Thread Shafik Yaghmour via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4f14c17df709: [LLDB] Remove uneeded CopyType from 
BlockPointerSyntheticFrontEnd (authored by shafik).
Herald added a project: LLDB.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96366

Files:
  lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
  lldb/test/API/lang/c/blocks/TestBlocks.py
  lldb/test/API/lang/c/blocks/main.c


Index: lldb/test/API/lang/c/blocks/main.c
===
--- lldb/test/API/lang/c/blocks/main.c
+++ lldb/test/API/lang/c/blocks/main.c
@@ -1,5 +1,17 @@
 #include 
 
+struct CG {int x; int y;};
+
+int g(int (^callback)(struct CG)) {
+   struct CG cg = {.x=1,.y=2};
+
+   int z = callback(cg); // Set breakpoint 2 here.
+
+   return z;
+}
+
+int h(struct CG cg){return 42;}
+
 int main()
 {
 int c = 1;
@@ -17,5 +29,12 @@
 printf("%d\n", add(3, 4));
 printf("%d\n", neg(-5)); // Set breakpoint 1 here.
 
+int (^add_struct)(struct CG) = ^int(struct CG cg)
+{
+return cg.x + cg.y;
+};
+
+g(add_struct);
+
 return 0;
 }
Index: lldb/test/API/lang/c/blocks/TestBlocks.py
===
--- lldb/test/API/lang/c/blocks/TestBlocks.py
+++ lldb/test/API/lang/c/blocks/TestBlocks.py
@@ -20,6 +20,7 @@
 # Find the line numbers to break at.
 self.lines.append(line_number('main.c', '// Set breakpoint 0 here.'))
 self.lines.append(line_number('main.c', '// Set breakpoint 1 here.'))
+self.lines.append(line_number('main.c', '// Set breakpoint 2 here.'))
 
 def launch_common(self):
 self.build()
@@ -51,6 +52,10 @@
 self.expect("expression (int)neg (-12)", VARIABLES_DISPLAYED_CORRECTLY,
 substrs=["= 12"])
 
+self.wait_for_breakpoint()
+
+self.expect_expr("h(cg)", result_type="int", result_value="42")
+
 @skipUnlessDarwin
 def test_define(self):
 self.launch_common()
Index: lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
===
--- lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
+++ lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
@@ -74,14 +74,12 @@
 const CompilerType reserved_type =
 clang_ast_context->GetBasicType(lldb::eBasicTypeInt);
 const char *const FuncPtr_name("__FuncPtr");
-const CompilerType FuncPtr_type =
-clang_ast_importer->CopyType(*clang_ast_context, 
function_pointer_type);
 
 m_block_struct_type = clang_ast_context->CreateStructForIdentifier(
 ConstString(), {{isa_name, isa_type},
 {flags_name, flags_type},
 {reserved_name, reserved_type},
-{FuncPtr_name, FuncPtr_type}});
+{FuncPtr_name, function_pointer_type}});
   }
 
   ~BlockPointerSyntheticFrontEnd() override = default;


Index: lldb/test/API/lang/c/blocks/main.c
===
--- lldb/test/API/lang/c/blocks/main.c
+++ lldb/test/API/lang/c/blocks/main.c
@@ -1,5 +1,17 @@
 #include 
 
+struct CG {int x; int y;};
+
+int g(int (^callback)(struct CG)) {
+   struct CG cg = {.x=1,.y=2};
+
+   int z = callback(cg); // Set breakpoint 2 here.
+
+   return z;
+}
+
+int h(struct CG cg){return 42;}
+
 int main()
 {
 int c = 1;
@@ -17,5 +29,12 @@
 printf("%d\n", add(3, 4));
 printf("%d\n", neg(-5)); // Set breakpoint 1 here.
 
+int (^add_struct)(struct CG) = ^int(struct CG cg)
+{
+return cg.x + cg.y;
+};
+
+g(add_struct);
+
 return 0;
 }
Index: lldb/test/API/lang/c/blocks/TestBlocks.py
===
--- lldb/test/API/lang/c/blocks/TestBlocks.py
+++ lldb/test/API/lang/c/blocks/TestBlocks.py
@@ -20,6 +20,7 @@
 # Find the line numbers to break at.
 self.lines.append(line_number('main.c', '// Set breakpoint 0 here.'))
 self.lines.append(line_number('main.c', '// Set breakpoint 1 here.'))
+self.lines.append(line_number('main.c', '// Set breakpoint 2 here.'))
 
 def launch_common(self):
 self.build()
@@ -51,6 +52,10 @@
 self.expect("expression (int)neg (-12)", VARIABLES_DISPLAYED_CORRECTLY,
 substrs=["= 12"])
 
+self.wait_for_breakpoint()
+
+self.expect_expr("h(cg)", result_type="int", result_value="42")
+
 @skipUnlessDarwin
 def test_define(self):
 self.launch_common()
Index: lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
===
--- lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
+++ lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp
@@ -74,14 +74,12 @@
 const CompilerType reserved_type

[Lldb-commits] [PATCH] D96368: Document the "extra_args" parameter to scripted breakpoint callbacks

2021-02-09 Thread Dave Lee via Phabricator via lldb-commits
kastiglione added inline comments.



Comment at: lldb/source/Commands/CommandObjectBreakpointCommand.cpp:127
+
+def breakpoint_callback(frame, bp_loc, extra_args, dict):
+  # Your code goes here

How about `internal_dict`, the name used elsewhere, and since in this example 
`dict` would shadow the python `dict()` constructor.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96368

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


[Lldb-commits] [lldb] 483ec13 - Use internal_dict everywhere we refer to the python session dict in docs.

2021-02-09 Thread Jim Ingham via lldb-commits

Author: Jim Ingham
Date: 2021-02-09T17:48:47-08:00
New Revision: 483ec136da7193de781a5284f1c37929cc27c05c

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

LOG: Use internal_dict everywhere we refer to the python session dict in docs.

Added: 


Modified: 
lldb/docs/use/python-reference.rst
lldb/source/Commands/CommandObjectBreakpointCommand.cpp

Removed: 




diff  --git a/lldb/docs/use/python-reference.rst 
b/lldb/docs/use/python-reference.rst
index f3ce744128c9..a1bdc87ab912 100644
--- a/lldb/docs/use/python-reference.rst
+++ b/lldb/docs/use/python-reference.rst
@@ -179,35 +179,35 @@ arguments:
 
 ::
 
-  def breakpoint_function_wrapper(frame, bp_loc, dict):
+  def breakpoint_function_wrapper(frame, bp_loc, internal_dict):
  # Your code goes here
 
 or:
 
 ::
 
-  def breakpoint_function_wrapper(frame, bp_loc, extra_args, dict):
+  def breakpoint_function_wrapper(frame, bp_loc, extra_args, internal_dict):
  # Your code goes here
 
 
-++---+---+
-| Argument   | Type  | Description 

  |
-++---+---+
-| **frame**  | **lldb.SBFrame**  | The current stack frame 
where the breakpoint got hit.   
  |
-||   | The object will always be 
valid.  
|
-||   | This **frame** argument 
might *not* match the currently selected stack frame found in the **lldb** 
module global variable **lldb.frame**. |
-++---+---+
-| **bp_loc** | **lldb.SBBreakpointLocation** | The breakpoint location 
that just got hit. Breakpoints are represented by **lldb.SBBreakpoint** 
  |
-||   | objects. These breakpoint 
objects can have one or more locations. These locations 
|
-||   | are represented by 
**lldb.SBBreakpointLocation** objects.  
   |
-++---+---+
-| **extra_args** | **lldb.SBStructuredData** | **Optional** If your 
breakpoint callback function takes this extra parameter, then when the callback 
gets added to a breakpoint, its  |
-||   | contents can parametrize 
this use of the callback.  For instance, instead of writing a callback that 
stops when the caller is "Foo",  |
-||   | you could take the function 
name from a field in the **extra_args**, making the callback more general.  The 
**-k** and **-v** options |
-||   | to **breakpoint command 
add** will be passed as a Dictionary in the **extra_args** parameter, or you 
can provide it with the SB API's.|
-++---+---+
-| **dict**   | **dict**  | The python session 
dictionary as a standard python dictionary object.  
   |
-++---+---+
++---+---+---+
+| Argument  | Type  | Description  

[Lldb-commits] [PATCH] D96368: Document the "extra_args" parameter to scripted breakpoint callbacks

2021-02-09 Thread Jim Ingham via Phabricator via lldb-commits
jingham added inline comments.



Comment at: lldb/source/Commands/CommandObjectBreakpointCommand.cpp:127
+
+def breakpoint_callback(frame, bp_loc, extra_args, dict):
+  # Your code goes here

kastiglione wrote:
> How about `internal_dict`, the name used elsewhere, and since in this example 
> `dict` would shadow the python `dict()` constructor.
Did this as a follow-on.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96368

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