[Lldb-commits] [PATCH] D91508: [LLDB/Lua] add support for one-liner breakpoint callback

2020-11-27 Thread Pedro Tammela via Phabricator via lldb-commits
tammela updated this revision to Diff 308029.
tammela marked 3 inline comments as done.
tammela added a comment.

Addressing review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91508

Files:
  lldb/bindings/lua/lua-swigsafecast.swig
  lldb/bindings/lua/lua-wrapper.swig
  lldb/bindings/lua/lua.swig
  lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
  lldb/source/Plugins/ScriptInterpreter/Lua/Lua.h
  lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
  lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h
  lldb/test/Shell/ScriptInterpreter/Lua/breakpoint_oneline_callback.test
  lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp

Index: lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp
===
--- lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp
+++ lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp
@@ -13,6 +13,30 @@
 
 extern "C" int luaopen_lldb(lua_State *L) { return 0; }
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
+
+// Disable warning C4190: 'LLDBSwigPythonBreakpointCallbackFunction' has
+// C-linkage specified, but returns UDT 'llvm::Expected' which is
+// incompatible with C
+#if _MSC_VER
+#pragma warning (push)
+#pragma warning (disable : 4190)
+#endif
+
+extern "C" llvm::Expected
+LLDBSwigLuaBreakpointCallbackFunction(lua_State *L,
+  lldb::StackFrameSP &stop_frame_sp,
+  lldb::BreakpointLocationSP &bp_loc_sp) {
+  return false;
+}
+
+#if _MSC_VER
+#pragma warning (pop)
+#endif
+
+#pragma clang diagnostic pop
+
 TEST(LuaTest, RunValid) {
   Lua lua;
   llvm::Error error = lua.Run("foo = 1");
Index: lldb/test/Shell/ScriptInterpreter/Lua/breakpoint_oneline_callback.test
===
--- /dev/null
+++ lldb/test/Shell/ScriptInterpreter/Lua/breakpoint_oneline_callback.test
@@ -0,0 +1,18 @@
+# REQUIRES: lua
+# RUN: echo "int main() { return 0; }" | %clang_host -x c - -o %t
+# RUN: %lldb -s %s --script-language lua %t 2>&1 | FileCheck %s
+b main
+breakpoint command add -s lua -o 'return false'
+run
+# CHECK: Process {{[0-9]+}} exited with status = 0
+breakpoint command add -s lua -o 'print(frame)'
+run
+# CHECK: frame #0
+# CHECK: Process {{[0-9]+}} exited with status = 0
+breakpoint command add -s lua -o "return true"
+run
+# CHECK: Process {{[0-9]+}} stopped
+breakpoint command add -s lua -o 'error("my error message")'
+run
+# CHECK: my error message
+# CHECK: Process {{[0-9]+}} stopped
Index: lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h
===
--- lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h
+++ lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h
@@ -10,11 +10,20 @@
 #define liblldb_ScriptInterpreterLua_h_
 
 #include "lldb/Interpreter/ScriptInterpreter.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/lldb-enumerations.h"
 
 namespace lldb_private {
 class Lua;
 class ScriptInterpreterLua : public ScriptInterpreter {
 public:
+  class CommandDataLua : public BreakpointOptions::CommandData {
+  public:
+CommandDataLua() : BreakpointOptions::CommandData() {
+  interpreter = lldb::eScriptLanguageLua;
+}
+  };
+
   ScriptInterpreterLua(Debugger &debugger);
 
   ~ScriptInterpreterLua() override;
@@ -41,6 +50,11 @@
 
   static const char *GetPluginDescriptionStatic();
 
+  static bool BreakpointCallbackFunction(void *baton,
+ StoppointCallbackContext *context,
+ lldb::user_id_t break_id,
+ lldb::user_id_t break_loc_id);
+
   // PluginInterface protocol
   lldb_private::ConstString GetPluginName() override;
 
@@ -51,6 +65,9 @@
   llvm::Error EnterSession(lldb::user_id_t debugger_id);
   llvm::Error LeaveSession();
 
+  Status SetBreakpointCommandCallback(BreakpointOptions *bp_options,
+  const char *command_body_text) override;
+
 private:
   std::unique_ptr m_lua;
   bool m_session_is_active = false;
Index: lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
@@ -8,14 +8,17 @@
 
 #include "ScriptInterpreterLua.h"
 #include "Lua.h"
+#include "lldb/Breakpoint/StoppointCallbackContext.h"
 #include "lldb/Core/Debugger.h"
 #include "lldb/Core/PluginManager.h"
 #include "lldb/Core/StreamFile.h"
 #include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Target/ExecutionContext.h"
 #include "lldb/Utility/Stream.h"
 #include "lldb/Utility/StringList.h"
 #i

[Lldb-commits] [PATCH] D91508: [LLDB/Lua] add support for one-liner breakpoint callback

2020-11-27 Thread Pedro Tammela via Phabricator via lldb-commits
tammela added inline comments.



Comment at: lldb/bindings/lua/lua-wrapper.swig:21-22
+{
+   lldb::SBFrame sb_frame(stop_frame_sp);
+   lldb::SBBreakpointLocation sb_bp_loc(bp_loc_sp);
+

labath wrote:
> What's up with the copying? Is it to ensure the callback does not modify the 
> caller's values? If so, you could just drop the `&` from the signature, and 
> have the compiler copy these for you...
`SBFrame` and `SBBreakpointLocation` only provide copy constructors. I can't 
see the difference between the two strategies, could you elaborate? 



Comment at: lldb/bindings/lua/lua-wrapper.swig:25-26
+   // Get the Lua callback
+   lua_pushlightuserdata(L, baton);
+   lua_gettable(L, LUA_REGISTRYINDEX);
+

labath wrote:
> Is there a reason this function has to be in this file? It would be nice all 
> the baton/registry handling was happening in the same place...
My reasoning was to have the `lua_pcall` on the same function that pushes the 
Lua callback but I changed to your version as it's clearer who is handling the 
baton (`Lua` class)



Comment at: 
lldb/test/Shell/ScriptInterpreter/Lua/breakpoint_oneline_callback.test:5
+b main
+breakpoint command add -s lua -o 'print(frame)'
+run

labath wrote:
> Could we also have a test where calling the callback raises an error? And for 
> the different values of the "stop" argument that can be returned from the 
> callback? And when compiling the callback expression results in an error?
Apparently when the user sets the breakpoint and it fails to compile the code 
lldb will not report any errors and it will fail silently.  I will address this 
particular test case in another patch since it affects Python as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91508

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


[Lldb-commits] [PATCH] D92223: [lldb] Add support for looking up static const members

2020-11-27 Thread Andy Yankovsky via Phabricator via lldb-commits
werat created this revision.
Herald added subscribers: lldb-commits, arphaman.
Herald added a project: LLDB.
werat requested review of this revision.
Herald added a subscriber: JDevlieghere.

Static const/constexpr members might have only DW_TAG_member entry with a
DW_AT_const_value attribute. Since there is no corresponding DW_TAG_variable
entry, these values are currently not indexed in the DWARF index and are not
available via SBTarget::FindGlobalVariables() API.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92223

Files:
  lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  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,15 @@
+struct Foo {
+  static constexpr int static_constexpr_int = 1;
+  static constexpr unsigned int static_constexpr_uint =
+  static_constexpr_int + 1;
+  static const int static_const_out_out_class;
+};
+
+const int Foo::static_const_out_out_class = 3;
+
+char global_var_of_char_type = 'X';
+
+int main() {
+  // Set a break at entry to main.
+  return 0;
+}
Index: lldb/test/API/python_api/target/globals/TestTargetGlobals.py
===
--- /dev/null
+++ lldb/test/API/python_api/target/globals/TestTargetGlobals.py
@@ -0,0 +1,68 @@
+"""
+Test SBTarget::FindGlobalVariables API.
+"""
+
+from __future__ import print_function
+
+import unittest2
+import os
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TargetAPITestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def setUp(self):
+# Call super's setUp().
+TestBase.setUp(self)
+# Find the line number to of function 'main'.
+self.line = line_number("main.cpp", "// Set a break at entry to main.")
+
+@add_test_categories(['pyapi'])
+def test_find_global_variables(self):
+"""Exercise SBTarget.FindGlobalVariables() API."""
+self.build()
+self.setTearDownCleanup()
+
+# Create a target by the debugger.
+target = self.dbg.CreateTarget(self.getBuildArtifact())
+self.assertTrue(target, VALID_TARGET)
+
+# Create the breakpoint inside function 'main'.
+breakpoint = target.BreakpointCreateByLocation('main.cpp', self.line)
+self.assertTrue(breakpoint, VALID_BREAKPOINT)
+
+# Now launch the process, and do not stop at entry point.
+process = target.LaunchSimple(
+None, None, self.get_process_working_directory())
+self.assertTrue(process, PROCESS_IS_VALID)
+# Make sure we hit our breakpoint:
+thread = lldbutil.get_one_thread_stopped_at_breakpoint(
+process, breakpoint)
+self.assertTrue(thread, "Thread is valid")
+
+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(
+"Foo::static_constexpr_int",
+"Foo::static_constexpr_int", "const int", "1")
+test_global_var(
+"Foo::static_constexpr_uint",
+"Foo::static_constexpr_uint", "const unsigned int", "2")
+test_global_var(
+"Foo::static_const_out_out_class",
+"Foo::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.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -2120,7 +2120,8 @@
   sc.module_sp = m_objfile_sp->GetModule();
 assert(sc.module_sp);
 
-if (die.Tag() != DW_TAG_variable)
+// Look only for variables and members with static const data.
+if (die.Tag() != DW_TAG_variable && die.Tag() != DW_TAG_member)
   return true;
 
 auto *dwarf_cu = llvm::dyn_c

[Lldb-commits] [PATCH] D92223: [lldb] Add support for looking up static const members

2020-11-27 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor added reviewers: labath, jankratochvil.
teemperor added a comment.

Not sure who's the right person to review the 
SymbolFileDWARF.cpp/ManualDWARFIndex.cpp, but Pavel/Jan touched that not too 
long ago.

(D81471  might also be an interested patch for 
you. That one is just waiting on me to add some of the requested tests).




Comment at: lldb/test/API/python_api/target/globals/TestTargetGlobals.py:5
+
+from __future__ import print_function
+

Unused import



Comment at: lldb/test/API/python_api/target/globals/TestTargetGlobals.py:8
+import unittest2
+import os
+from lldbsuite.test.decorators import *

Also unused?



Comment at: lldb/test/API/python_api/target/globals/TestTargetGlobals.py:45
+process, breakpoint)
+self.assertTrue(thread, "Thread is valid")
+

The code between here and `self.build()` can be simplified to:

```
self.build()
   target, _, _, _ lldbutil.run_to_source_breakpoint(self, "// Set a break 
at entry to main.", lldb.SBFileSpec("main.cpp"))
```
And then the `setUp` can also be removed.

FWIW, I believe we don't need to launch any process for this test, so this 
might be enough to test this (while being a much faster test):
```
self.build()
target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92223

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


[Lldb-commits] [PATCH] D92223: [lldb] Add support for looking up static const members

2020-11-27 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added reviewers: jarin, aprantl, shafik.
werat added a comment.

Hi, please, take a look at this patch.

It seems Pavel already did some work for class-level static const variables in 
https://reviews.llvm.org/D86615, although that didn't work the case I've 
encountered.

In my example (which is also reflected in the test I've added), class-level 
static constexpr variable is presented in DWARF only via `DW_TAG_member` with 
`DW_AT_const_value`. The code one the lookup path looks only at 
`DW_TAG_variable`, which are not present.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92223

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


[Lldb-commits] [PATCH] D92223: [lldb] Add support for looking up static const members

2020-11-27 Thread Andy Yankovsky via Phabricator via lldb-commits
werat updated this revision to Diff 308052.
werat added a comment.

Simplified test according to teemperor's comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92223

Files:
  lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  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,15 @@
+struct Foo {
+  static constexpr int static_constexpr_int = 1;
+  static constexpr unsigned int static_constexpr_uint =
+  static_constexpr_int + 1;
+  static const int static_const_out_out_class;
+};
+
+const int Foo::static_const_out_out_class = 3;
+
+char global_var_of_char_type = 'X';
+
+int main() {
+  // Set a break at entry to main.
+  return 0;
+}
Index: lldb/test/API/python_api/target/globals/TestTargetGlobals.py
===
--- /dev/null
+++ lldb/test/API/python_api/target/globals/TestTargetGlobals.py
@@ -0,0 +1,51 @@
+"""
+Test SBTarget::FindGlobalVariables API.
+"""
+
+import unittest2
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TargetAPITestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def setUp(self):
+# Call super's setUp().
+TestBase.setUp(self)
+# Find the line number to of function 'main'.
+self.line = line_number("main.cpp", "// Set a break at entry to main.")
+
+@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(
+"Foo::static_constexpr_int",
+"Foo::static_constexpr_int", "const int", "1")
+test_global_var(
+"Foo::static_constexpr_uint",
+"Foo::static_constexpr_uint", "const unsigned int", "2")
+test_global_var(
+"Foo::static_const_out_out_class",
+"Foo::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.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -2120,7 +2120,8 @@
   sc.module_sp = m_objfile_sp->GetModule();
 assert(sc.module_sp);
 
-if (die.Tag() != DW_TAG_variable)
+// Look only for variables and members with static const data.
+if (die.Tag() != DW_TAG_variable && die.Tag() != DW_TAG_member)
   return true;
 
 auto *dwarf_cu = llvm::dyn_cast(die.GetCU());
@@ -3103,7 +3104,7 @@
   ModuleSP module = GetObjectFile()->GetModule();
 
   if (tag != DW_TAG_variable && tag != DW_TAG_constant &&
-  (tag != DW_TAG_formal_parameter || !sc.function))
+  tag != DW_TAG_member && (tag != DW_TAG_formal_parameter || !sc.function))
 return nullptr;
 
   DWARFAttributes attributes;
@@ -3177,6 +3178,12 @@
 }
   }
 
+  if (tag == DW_TAG_member && !const_value_form.IsValid()) {
+// Allows only members with DW_AT_const_value attribute, i.e. static const
+// or static constexr.
+return nullptr;
+  }
+
   // Prefer DW_AT_location over DW_AT_const_value. Both can be emitted e.g.
   // for static constexpr member variables -- DW_AT_const_value will be
   // present in the class declaration and DW_AT_location in the DIE defining
@@ -3236,10 +3243,11 @@
 
   const DWARFDIE parent_context_die = GetDeclContextDIEContainingDIE(die);
   const dw_tag_t parent_tag = die.GetParent().Tag();

[Lldb-commits] [PATCH] D92223: [lldb] Add support for looking up static const members

2020-11-27 Thread Andy Yankovsky via Phabricator via lldb-commits
werat updated this revision to Diff 308053.
werat added a comment.

Remove unused field


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92223

Files:
  lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  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,15 @@
+struct Foo {
+  static constexpr int static_constexpr_int = 1;
+  static constexpr unsigned int static_constexpr_uint =
+  static_constexpr_int + 1;
+  static const int static_const_out_out_class;
+};
+
+const int Foo::static_const_out_out_class = 3;
+
+char global_var_of_char_type = 'X';
+
+int main() {
+  // Set a break at entry to main.
+  return 0;
+}
Index: lldb/test/API/python_api/target/globals/TestTargetGlobals.py
===
--- /dev/null
+++ lldb/test/API/python_api/target/globals/TestTargetGlobals.py
@@ -0,0 +1,49 @@
+"""
+Test SBTarget::FindGlobalVariables API.
+"""
+
+import unittest2
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TargetAPITestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def setUp(self):
+# Call super's setUp().
+TestBase.setUp(self)
+
+@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(
+"Foo::static_constexpr_int",
+"Foo::static_constexpr_int", "const int", "1")
+test_global_var(
+"Foo::static_constexpr_uint",
+"Foo::static_constexpr_uint", "const unsigned int", "2")
+test_global_var(
+"Foo::static_const_out_out_class",
+"Foo::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.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -2120,7 +2120,8 @@
   sc.module_sp = m_objfile_sp->GetModule();
 assert(sc.module_sp);
 
-if (die.Tag() != DW_TAG_variable)
+// Look only for variables and members with static const data.
+if (die.Tag() != DW_TAG_variable && die.Tag() != DW_TAG_member)
   return true;
 
 auto *dwarf_cu = llvm::dyn_cast(die.GetCU());
@@ -3103,7 +3104,7 @@
   ModuleSP module = GetObjectFile()->GetModule();
 
   if (tag != DW_TAG_variable && tag != DW_TAG_constant &&
-  (tag != DW_TAG_formal_parameter || !sc.function))
+  tag != DW_TAG_member && (tag != DW_TAG_formal_parameter || !sc.function))
 return nullptr;
 
   DWARFAttributes attributes;
@@ -3177,6 +3178,12 @@
 }
   }
 
+  if (tag == DW_TAG_member && !const_value_form.IsValid()) {
+// Allows only members with DW_AT_const_value attribute, i.e. static const
+// or static constexr.
+return nullptr;
+  }
+
   // Prefer DW_AT_location over DW_AT_const_value. Both can be emitted e.g.
   // for static constexpr member variables -- DW_AT_const_value will be
   // present in the class declaration and DW_AT_location in the DIE defining
@@ -3236,10 +3243,11 @@
 
   const DWARFDIE parent_context_die = GetDeclContextDIEContainingDIE(die);
   const dw_tag_t parent_tag = die.GetParent().Tag();
-  bool is_static_member = (parent_tag == DW_TAG_compile_unit ||
-   parent_tag == DW_TAG_partial_unit) &&
-  (parent_

[Lldb-commits] [PATCH] D92249: [LLDB/Python] Fix segfault on Python scripted breakpoints

2020-11-27 Thread Pedro Tammela via Phabricator via lldb-commits
tammela created this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.
tammela requested review of this revision.
Herald added a subscriber: JDevlieghere.

The code that calls into the ScriptInterpreter was not considering the
case that it receives a Lua interpreter.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92249

Files:
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  lldb/test/Shell/ScriptInterpreter/Python/scripted_breakpoint_lua.test


Index: lldb/test/Shell/ScriptInterpreter/Python/scripted_breakpoint_lua.test
===
--- /dev/null
+++ lldb/test/Shell/ScriptInterpreter/Python/scripted_breakpoint_lua.test
@@ -0,0 +1,8 @@
+# REQUIRES: python
+# UNSUPPORTED: lldb-repro
+#
+# RUN: cat %s | %lldb --script-language lua 2>&1 | FileCheck %s
+b main
+breakpoint command add -s python -o 'print(frame); return False'
+run
+# CHECK: frame #0
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "lldb/Host/Config.h"
+#include "lldb/lldb-enumerations.h"
 
 #if LLDB_ENABLE_PYTHON
 
@@ -2274,7 +2275,8 @@
 return true;
 
   Debugger &debugger = target->GetDebugger();
-  ScriptInterpreter *script_interpreter = debugger.GetScriptInterpreter();
+  ScriptInterpreter *script_interpreter =
+  debugger.GetScriptInterpreter(true, eScriptLanguagePython);
   ScriptInterpreterPythonImpl *python_interpreter =
   (ScriptInterpreterPythonImpl *)script_interpreter;
 


Index: lldb/test/Shell/ScriptInterpreter/Python/scripted_breakpoint_lua.test
===
--- /dev/null
+++ lldb/test/Shell/ScriptInterpreter/Python/scripted_breakpoint_lua.test
@@ -0,0 +1,8 @@
+# REQUIRES: python
+# UNSUPPORTED: lldb-repro
+#
+# RUN: cat %s | %lldb --script-language lua 2>&1 | FileCheck %s
+b main
+breakpoint command add -s python -o 'print(frame); return False'
+run
+# CHECK: frame #0
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "lldb/Host/Config.h"
+#include "lldb/lldb-enumerations.h"
 
 #if LLDB_ENABLE_PYTHON
 
@@ -2274,7 +2275,8 @@
 return true;
 
   Debugger &debugger = target->GetDebugger();
-  ScriptInterpreter *script_interpreter = debugger.GetScriptInterpreter();
+  ScriptInterpreter *script_interpreter =
+  debugger.GetScriptInterpreter(true, eScriptLanguagePython);
   ScriptInterpreterPythonImpl *python_interpreter =
   (ScriptInterpreterPythonImpl *)script_interpreter;
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits