[Lldb-commits] [PATCH] D108090: [lldb/lua] Supplement Lua bindings for lldb module

2021-10-12 Thread Siger Young via Phabricator via lldb-commits
siger-young updated this revision to Diff 378971.
siger-young added a comment.

Pull and merge conflicts, will soon be merged into main.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108090

Files:
  lldb/CMakeLists.txt
  lldb/bindings/lua/CMakeLists.txt
  lldb/bindings/lua/lua-typemaps.swig
  lldb/bindings/lua/lua-wrapper.swig
  lldb/bindings/lua/lua.swig
  lldb/source/API/liblldb-private.exports
  lldb/source/API/liblldb.exports
  lldb/test/API/lit.site.cfg.py.in
  lldb/test/API/lldbtest.py
  lldb/test/API/lua_api/Makefile
  lldb/test/API/lua_api/TestBreakpointAPI.lua
  lldb/test/API/lua_api/TestComprehensive.lua
  lldb/test/API/lua_api/TestFileHandle.lua
  lldb/test/API/lua_api/TestLuaAPI.py
  lldb/test/API/lua_api/TestProcessAPI.lua
  lldb/test/API/lua_api/lua_lldb_test.lua
  lldb/test/API/lua_api/main.c

Index: lldb/test/API/lua_api/main.c
===
--- /dev/null
+++ lldb/test/API/lua_api/main.c
@@ -0,0 +1,35 @@
+#include 
+
+void BFunction()
+{
+}
+
+void AFunction()
+{
+printf("I am a function.\n");
+}
+
+int main(int argc, const char *argv[])
+{
+int inited = 0xDEADBEEF;
+int sum = 0;
+if(argc > 1)
+{
+for(int i = 0; i < argc; i++)
+{
+puts(argv[i]);
+}
+if(argc > 2)
+{
+return argc;
+}
+}
+AFunction();
+for(int i = 1; i <= 100; i++)
+{
+BFunction();
+sum += i;
+}
+printf("sum = %d\n", sum);
+return 0;
+}
Index: lldb/test/API/lua_api/lua_lldb_test.lua
===
--- /dev/null
+++ lldb/test/API/lua_api/lua_lldb_test.lua
@@ -0,0 +1,155 @@
+-- Make lldb available in global
+lldb = require('lldb')
+
+-- Global assertion functions
+function assertTrue(x)
+if not x then error('assertTrue failure') end
+end
+
+function assertFalse(x)
+if x then error('assertNotNil failure') end
+end
+
+function assertNotNil(x)
+if x == nil then error('assertNotNil failure') end
+end
+
+function assertEquals(x, y)
+if type(x) == 'table' and type(y) == 'table' then
+for k, _ in pairs(x) do
+assertEquals(x[k], y[k])
+end
+elseif type(x) ~= type(y) then
+error('assertEquals failure')
+elseif x ~= y then
+error('assertEquals failure')
+end
+end
+
+function assertStrContains(x, y)
+if not string.find(x, y, 1, true) then
+error('assertStrContains failure')
+end
+end
+
+-- Global helper functions
+function read_file_non_empty_lines(f)
+local lines = {}
+while true do
+local line = f:read('*l')
+if not line then break end
+if line ~= '\n' then table.insert(lines, line) end
+end
+return lines
+end
+
+function split_lines(str)
+local lines = {}
+for line in str:gmatch("[^\r\n]+") do
+table.insert(lines, line)
+end
+return lines
+end
+
+function get_stopped_threads(process, reason)
+local threads = {}
+for i = 0, process:GetNumThreads() - 1 do
+local t = process:GetThreadAtIndex(i)
+if t:IsValid() and t:GetStopReason() == reason then
+table.insert(threads, t)
+end
+end
+return threads
+end
+
+function get_stopped_thread(process, reason)
+local threads = get_stopped_threads(process, reason)
+if #threads ~= 0 then return threads[1]
+else return nil end
+end
+
+-- Test helper
+
+local _M = {}
+local _m = {}
+
+local _mt = { __index = _m }
+
+function _M.create_test(name, exe, output, input)
+print('[lldb/lua] Create test ' .. name)
+exe = exe or os.getenv('TEST_EXE')
+output = output or os.getenv('TEST_OUTPUT')
+input = input or os.getenv('TEST_INPUT')
+lldb.SBDebugger.Initialize()
+local debugger = lldb.SBDebugger.Create()
+-- Ensure that debugger is created
+assertNotNil(debugger)
+assertTrue(debugger:IsValid())
+
+debugger:SetAsync(false)
+
+local lua_language = debugger:GetScriptingLanguage('lua')
+assertNotNil(lua_language)
+debugger:SetScriptLanguage(lua_language)
+
+local test = setmetatable({
+output = output,
+input = input,
+name = name,
+exe = exe,
+debugger = debugger
+}, _mt)
+_G[name] = test
+return test
+end
+
+function _m:create_target(exe)
+local target
+if not exe then exe = self.exe end
+target = self.debugger:CreateTarget(exe)
+-- Ensure that target is created
+assertNotNil(target)
+assertTrue(target:IsValid())
+return target
+end
+
+function _m:handle_command(command, collect)
+if collect == nil then collect = true end
+if collect then
+local ret = lldb.SBCommandReturnObject()
+local interpreter = self.debugger:GetCommandInterpreter()
+assertTrue(interpreter:IsValid())
+interpreter:HandleCommand(com

[Lldb-commits] [PATCH] D111634: [lldb] Print embedded nuls in char arrays (PR44649)

2021-10-12 Thread Pavel Labath via Phabricator via lldb-commits
labath created this revision.
labath added reviewers: teemperor, jingham.
labath requested review of this revision.
Herald added a project: LLDB.

When we know the bounds of the array, print any embedded nuls instead of
treating them as terminators. An exception to this rule is made for the
nul character at the very end of the string. We don't print that, as
otherwise 99% of the strings would end in \0. This way the strings
usually come out the same as how the user typed it into the compiler
(char foo[] = "with\0nuls"). It also matches how they come out in gdb.

This resolves a FIXME left from D111399 , and 
leaves another FIXME for dealing
with nul characters in "escape-non-printables=false" mode. In this mode the
characters cause the entire summary string to be terminated prematurely.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111634

Files:
  lldb/source/Core/ValueObject.cpp
  
lldb/test/API/functionalities/data-formatter/builtin-formats/TestBuiltinFormats.py
  lldb/test/API/functionalities/data-formatter/stringprinter/main.cpp
  lldb/test/Shell/SymbolFile/DWARF/x86/DW_AT_const_value.s

Index: lldb/test/Shell/SymbolFile/DWARF/x86/DW_AT_const_value.s
===
--- lldb/test/Shell/SymbolFile/DWARF/x86/DW_AT_const_value.s
+++ lldb/test/Shell/SymbolFile/DWARF/x86/DW_AT_const_value.s
@@ -17,7 +17,7 @@
 ## Variables specified using string forms. This behavior purely speculative -- I
 ## don't know of any compiler that would represent character strings this way.
 # CHECK: (char [7]) string = "string"
-# CHECK: (char [7]) strp = "strp"
+# CHECK: (char [7]) strp = "strp\0\0"
 ## Bogus attribute form. Let's make sure we don't crash at least.
 # CHECK: (char [7]) ref4 = 
 ## A variable of pointer type.
Index: lldb/test/API/functionalities/data-formatter/stringprinter/main.cpp
===
--- lldb/test/API/functionalities/data-formatter/stringprinter/main.cpp
+++ lldb/test/API/functionalities/data-formatter/stringprinter/main.cpp
@@ -8,11 +8,12 @@
 
 int main (int argc, char const *argv[])
 {
-A a, b;
+A a, b, c;
 // Deliberately write past the end of data to test that the formatter stops
 // at the end of array.
 memcpy(a.data, "FOOBAR", 7);
 memcpy(b.data, "FO\0BAR", 7);
+memcpy(c.data, "F\0O\0AR", 7);
 std::string stdstring("Hello\t\tWorld\nI am here\t\tto say hello\n"); //%self.addTearDownHook(lambda x: x.runCmd("setting set escape-non-printables true"))
 const char* constcharstar = stdstring.c_str();
 std::string longstring(
@@ -33,13 +34,14 @@
 return 0; //% if self.TraceOn(): self.runCmd('frame variable')
 //% self.expect_var_path('stdstring', summary='"Hello\\t\\tWorld\\nI am here\\t\\tto say hello\\n"')
 //% self.expect_var_path('constcharstar', summary='"Hello\\t\\tWorld\\nI am here\\t\\tto say hello\\n"')
+//% self.expect_var_path("a.data", summary='"FOOB"')
+//% self.expect_var_path("b.data", summary=r'"FO\0B"')
+//% self.expect_var_path("c.data", summary=r'"F\0O"')
 //% self.runCmd("setting set escape-non-printables false")
 //% self.expect_var_path('stdstring', summary='"Hello\t\tWorld\nI am here\t\tto say hello\n"')
 //% self.expect_var_path('constcharstar', summary='"Hello\t\tWorld\nI am here\t\tto say hello\n"')
 //% self.assertTrue(self.frame().FindVariable('longstring').GetSummary().endswith('"...'))
 //% self.assertTrue(self.frame().FindVariable('longconstcharstar').GetSummary().endswith('"...'))
-//% self.expect_var_path("a.data", summary='"FOOB"')
-// FIXME: Should this be "FO\0B" instead?
-//% self.expect_var_path("b.data", summary='"FO"')
+// FIXME: make "b.data" and "c.data" work sanely
 }
 
Index: lldb/test/API/functionalities/data-formatter/builtin-formats/TestBuiltinFormats.py
===
--- lldb/test/API/functionalities/data-formatter/builtin-formats/TestBuiltinFormats.py
+++ lldb/test/API/functionalities/data-formatter/builtin-formats/TestBuiltinFormats.py
@@ -90,8 +90,8 @@
 
 # Different character arrays.
 # FIXME: Passing a 'const char *' will ignore any given format,
-self.assertIn('= " \\U001b\\a\\b\\f\\n\\r\\t\\vaA09"\n', self.getFormatted("character array", "cstring"))
-self.assertIn('= " \\U001b\\a\\b\\f\\n\\r\\t\\vaA09"\n', self.getFormatted("c-string", "cstring"))
+self.assertIn(r'= " \U001b\a\b\f\n\r\t\vaA09\0"', self.getFormatted("character array", "cstring"))
+self.assertIn(r'= " \U001b\a\b\f\n\r\t\vaA09\0"', self.getFormatted("c-string", "cstring"))
 self.assertIn(' = " \\e\\a\\b\\f\\n\\r\\t\\vaA09" " \\U001b\\a\\b\\f\\n\\r\\t\\vaA09"\n',
   self.getFormatted("c-string", "(char *)cstring"))
 self.assertIn('=\n', self.getFormatted("c-string", "(

[Lldb-commits] [lldb] bda5fe8 - [lldb] [gdb-remote] Fix displaying i387_ext & vec regs with gdbserver

2021-10-12 Thread Michał Górny via lldb-commits

Author: Michał Górny
Date: 2021-10-12T15:16:06+02:00
New Revision: bda5fe8f0c049f8c805572ba9eb92ce6044e7999

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

LOG: [lldb] [gdb-remote] Fix displaying i387_ext & vec regs with gdbserver

Adjust the encoding and format applied to i387_ext and vec* type
registers from gdbserver to match lldb-server.  Both types are now
displayed as vector of uint8 instead of float and integer formats used
before.  Additionally, this fixes display of STi registers when they do
not carry floating-point data (they are also used to hold MMX vectors).

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

Added: 


Modified: 
lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
lldb/test/API/functionalities/gdb_remote_client/TestGDBServerTargetXML.py

Removed: 




diff  --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp 
b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index 0e77ab01d0bd0..1a5f4a2beea89 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -4312,10 +4312,12 @@ bool ParseRegisters(XMLNode feature_node, 
GdbServerTargetInfo &target_info,
   } else if (gdb_type == "data_ptr" || gdb_type == "code_ptr") {
 reg_info.format = eFormatAddressInfo;
 reg_info.encoding = eEncodingUint;
-  } else if (gdb_type == "i387_ext" || gdb_type == "float") {
+  } else if (gdb_type == "float") {
 reg_info.format = eFormatFloat;
 reg_info.encoding = eEncodingIEEE754;
-  } else if (gdb_type == "aarch64v") {
+  } else if (gdb_type == "aarch64v" ||
+ llvm::StringRef(gdb_type).startswith("vec") ||
+ gdb_type == "i387_ext") {
 reg_info.format = eFormatVectorOfUInt8;
 reg_info.encoding = eEncodingVector;
   }

diff  --git 
a/lldb/test/API/functionalities/gdb_remote_client/TestGDBServerTargetXML.py 
b/lldb/test/API/functionalities/gdb_remote_client/TestGDBServerTargetXML.py
index 1a83b673cac0f..0533aec27eaa9 100644
--- a/lldb/test/API/functionalities/gdb_remote_client/TestGDBServerTargetXML.py
+++ b/lldb/test/API/functionalities/gdb_remote_client/TestGDBServerTargetXML.py
@@ -151,6 +151,18 @@ def haltReason(self):
 self.match("register read flags",
["eflags = 0x94939291"])
 
+# both stX and xmmX should be displayed as vectors
+self.match("register read st0",
+   ["st0 = {0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 
0x0a}"])
+self.match("register read st1",
+   ["st1 = {0x11 0x12 0x13 0x14 0x15 0x16 0x17 0x18 0x19 
0x1a}"])
+self.match("register read xmm0",
+   ["xmm0 = {0x81 0x82 0x83 0x84 0x85 0x86 0x87 0x88 "
+"0x89 0x8a 0x8b 0x8c 0x8d 0x8e 0x8f 0x90}"])
+self.match("register read xmm1",
+   ["xmm1 = {0x91 0x92 0x93 0x94 0x95 0x96 0x97 0x98 "
+"0x99 0x9a 0x9b 0x9c 0x9d 0x9e 0x9f 0xa0}"])
+
 @skipIfXmlSupportMissing
 @skipIfRemote
 @skipIfLLVMTargetMissing("X86")
@@ -265,6 +277,18 @@ def haltReason(self):
 self.match("register read flags",
["eflags = 0x94939291"])
 
+# both stX and xmmX should be displayed as vectors
+self.match("register read st0",
+   ["st0 = {0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 
0x0a}"])
+self.match("register read st1",
+   ["st1 = {0x11 0x12 0x13 0x14 0x15 0x16 0x17 0x18 0x19 
0x1a}"])
+self.match("register read xmm0",
+   ["xmm0 = {0x81 0x82 0x83 0x84 0x85 0x86 0x87 0x88 "
+"0x89 0x8a 0x8b 0x8c 0x8d 0x8e 0x8f 0x90}"])
+self.match("register read xmm1",
+   ["xmm1 = {0x91 0x92 0x93 0x94 0x95 0x96 0x97 0x98 "
+"0x99 0x9a 0x9b 0x9c 0x9d 0x9e 0x9f 0xa0}"])
+
 @skipIfXmlSupportMissing
 @skipIfRemote
 @skipIfLLVMTargetMissing("AArch64")



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


[Lldb-commits] [PATCH] D108468: [lldb] [gdb-remote] Fix displaying i387_ext & vec regs with gdbserver

2021-10-12 Thread Michał Górny 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 rGbda5fe8f0c04: [lldb] [gdb-remote] Fix displaying i387_ext 
& vec regs with gdbserver (authored by mgorny).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D108468?vs=369419&id=379001#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108468

Files:
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  lldb/test/API/functionalities/gdb_remote_client/TestGDBServerTargetXML.py


Index: lldb/test/API/functionalities/gdb_remote_client/TestGDBServerTargetXML.py
===
--- lldb/test/API/functionalities/gdb_remote_client/TestGDBServerTargetXML.py
+++ lldb/test/API/functionalities/gdb_remote_client/TestGDBServerTargetXML.py
@@ -151,6 +151,18 @@
 self.match("register read flags",
["eflags = 0x94939291"])
 
+# both stX and xmmX should be displayed as vectors
+self.match("register read st0",
+   ["st0 = {0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 
0x0a}"])
+self.match("register read st1",
+   ["st1 = {0x11 0x12 0x13 0x14 0x15 0x16 0x17 0x18 0x19 
0x1a}"])
+self.match("register read xmm0",
+   ["xmm0 = {0x81 0x82 0x83 0x84 0x85 0x86 0x87 0x88 "
+"0x89 0x8a 0x8b 0x8c 0x8d 0x8e 0x8f 0x90}"])
+self.match("register read xmm1",
+   ["xmm1 = {0x91 0x92 0x93 0x94 0x95 0x96 0x97 0x98 "
+"0x99 0x9a 0x9b 0x9c 0x9d 0x9e 0x9f 0xa0}"])
+
 @skipIfXmlSupportMissing
 @skipIfRemote
 @skipIfLLVMTargetMissing("X86")
@@ -265,6 +277,18 @@
 self.match("register read flags",
["eflags = 0x94939291"])
 
+# both stX and xmmX should be displayed as vectors
+self.match("register read st0",
+   ["st0 = {0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 
0x0a}"])
+self.match("register read st1",
+   ["st1 = {0x11 0x12 0x13 0x14 0x15 0x16 0x17 0x18 0x19 
0x1a}"])
+self.match("register read xmm0",
+   ["xmm0 = {0x81 0x82 0x83 0x84 0x85 0x86 0x87 0x88 "
+"0x89 0x8a 0x8b 0x8c 0x8d 0x8e 0x8f 0x90}"])
+self.match("register read xmm1",
+   ["xmm1 = {0x91 0x92 0x93 0x94 0x95 0x96 0x97 0x98 "
+"0x99 0x9a 0x9b 0x9c 0x9d 0x9e 0x9f 0xa0}"])
+
 @skipIfXmlSupportMissing
 @skipIfRemote
 @skipIfLLVMTargetMissing("AArch64")
Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -4312,10 +4312,12 @@
   } else if (gdb_type == "data_ptr" || gdb_type == "code_ptr") {
 reg_info.format = eFormatAddressInfo;
 reg_info.encoding = eEncodingUint;
-  } else if (gdb_type == "i387_ext" || gdb_type == "float") {
+  } else if (gdb_type == "float") {
 reg_info.format = eFormatFloat;
 reg_info.encoding = eEncodingIEEE754;
-  } else if (gdb_type == "aarch64v") {
+  } else if (gdb_type == "aarch64v" ||
+ llvm::StringRef(gdb_type).startswith("vec") ||
+ gdb_type == "i387_ext") {
 reg_info.format = eFormatVectorOfUInt8;
 reg_info.encoding = eEncodingVector;
   }


Index: lldb/test/API/functionalities/gdb_remote_client/TestGDBServerTargetXML.py
===
--- lldb/test/API/functionalities/gdb_remote_client/TestGDBServerTargetXML.py
+++ lldb/test/API/functionalities/gdb_remote_client/TestGDBServerTargetXML.py
@@ -151,6 +151,18 @@
 self.match("register read flags",
["eflags = 0x94939291"])
 
+# both stX and xmmX should be displayed as vectors
+self.match("register read st0",
+   ["st0 = {0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a}"])
+self.match("register read st1",
+   ["st1 = {0x11 0x12 0x13 0x14 0x15 0x16 0x17 0x18 0x19 0x1a}"])
+self.match("register read xmm0",
+   ["xmm0 = {0x81 0x82 0x83 0x84 0x85 0x86 0x87 0x88 "
+"0x89 0x8a 0x8b 0x8c 0x8d 0x8e 0x8f 0x90}"])
+self.match("register read xmm1",
+   ["xmm1 = {0x91 0x92 0x93 0x94 0x95 0x96 0x97 0x98 "
+"0x99 0x9a 0x9b 0x9c 0x9d 0x9e 0x9f 0xa0}"])
+
 @skipIfXmlSupportMissing
 @skipIfRemote
 @skipIfLLVMTargetMissing("X86")
@@ -265,6 +277,18 @@
 self.match("register read flags",
["eflags = 0x94939291"])
 
+  

[Lldb-commits] [lldb] 6de63b3 - [lldb/lua] Force Lua version to be 5.3

2021-10-12 Thread Siger Yang via lldb-commits

Author: Siger Yang
Date: 2021-10-12T21:34:15+08:00
New Revision: 6de63b3ba5e2dbb5994d329623fbf933e319ea7a

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

LOG: [lldb/lua] Force Lua version to be 5.3

Due to CMake cache, find_package in FindLuaAndSwig.cmake
will be ignored. This commit adds EXACT and REQUIRED flags
to it and removes find_package in Lua ScriptInterpreter.

Signed-off-by: Siger Yang 

Reviewed By: tammela, JDevlieghere

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

Added: 


Modified: 
lldb/cmake/modules/FindLuaAndSwig.cmake
lldb/source/Plugins/ScriptInterpreter/Lua/CMakeLists.txt

Removed: 




diff  --git a/lldb/cmake/modules/FindLuaAndSwig.cmake 
b/lldb/cmake/modules/FindLuaAndSwig.cmake
index f6251bbd1042c..982616169a05e 100644
--- a/lldb/cmake/modules/FindLuaAndSwig.cmake
+++ b/lldb/cmake/modules/FindLuaAndSwig.cmake
@@ -9,7 +9,7 @@ if(LUA_LIBRARIES AND LUA_INCLUDE_DIR AND SWIG_EXECUTABLE)
 else()
   find_package(SWIG 3.0)
   if (SWIG_FOUND)
-find_package(Lua 5.3)
+find_package(Lua 5.3 EXACT)
 if(LUA_FOUND AND SWIG_FOUND)
   mark_as_advanced(
 LUA_LIBRARIES

diff  --git a/lldb/source/Plugins/ScriptInterpreter/Lua/CMakeLists.txt 
b/lldb/source/Plugins/ScriptInterpreter/Lua/CMakeLists.txt
index f5c62ee3a54f3..498bd97839510 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Lua/CMakeLists.txt
+++ b/lldb/source/Plugins/ScriptInterpreter/Lua/CMakeLists.txt
@@ -1,5 +1,3 @@
-find_package(Lua REQUIRED)
-
 add_lldb_library(lldbPluginScriptInterpreterLua PLUGIN
   Lua.cpp
   ScriptInterpreterLua.cpp



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


[Lldb-commits] [PATCH] D108515: [lldb/lua] Force Lua version to be 5.3

2021-10-12 Thread Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6de63b3ba5e2: [lldb/lua] Force Lua version to be 5.3 
(authored by Siger Yang ).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108515

Files:
  lldb/cmake/modules/FindLuaAndSwig.cmake
  lldb/source/Plugins/ScriptInterpreter/Lua/CMakeLists.txt


Index: lldb/source/Plugins/ScriptInterpreter/Lua/CMakeLists.txt
===
--- lldb/source/Plugins/ScriptInterpreter/Lua/CMakeLists.txt
+++ lldb/source/Plugins/ScriptInterpreter/Lua/CMakeLists.txt
@@ -1,5 +1,3 @@
-find_package(Lua REQUIRED)
-
 add_lldb_library(lldbPluginScriptInterpreterLua PLUGIN
   Lua.cpp
   ScriptInterpreterLua.cpp
Index: lldb/cmake/modules/FindLuaAndSwig.cmake
===
--- lldb/cmake/modules/FindLuaAndSwig.cmake
+++ lldb/cmake/modules/FindLuaAndSwig.cmake
@@ -9,7 +9,7 @@
 else()
   find_package(SWIG 3.0)
   if (SWIG_FOUND)
-find_package(Lua 5.3)
+find_package(Lua 5.3 EXACT)
 if(LUA_FOUND AND SWIG_FOUND)
   mark_as_advanced(
 LUA_LIBRARIES


Index: lldb/source/Plugins/ScriptInterpreter/Lua/CMakeLists.txt
===
--- lldb/source/Plugins/ScriptInterpreter/Lua/CMakeLists.txt
+++ lldb/source/Plugins/ScriptInterpreter/Lua/CMakeLists.txt
@@ -1,5 +1,3 @@
-find_package(Lua REQUIRED)
-
 add_lldb_library(lldbPluginScriptInterpreterLua PLUGIN
   Lua.cpp
   ScriptInterpreterLua.cpp
Index: lldb/cmake/modules/FindLuaAndSwig.cmake
===
--- lldb/cmake/modules/FindLuaAndSwig.cmake
+++ lldb/cmake/modules/FindLuaAndSwig.cmake
@@ -9,7 +9,7 @@
 else()
   find_package(SWIG 3.0)
   if (SWIG_FOUND)
-find_package(Lua 5.3)
+find_package(Lua 5.3 EXACT)
 if(LUA_FOUND AND SWIG_FOUND)
   mark_as_advanced(
 LUA_LIBRARIES
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D108090: [lldb/lua] Supplement Lua bindings for lldb module

2021-10-12 Thread Phabricator via lldb-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG67f94e5a9745: [lldb/lua] Supplement Lua bindings for lldb 
module (authored by Siger Yang ).

Changed prior to commit:
  https://reviews.llvm.org/D108090?vs=378971&id=379026#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108090

Files:
  lldb/CMakeLists.txt
  lldb/bindings/lua/CMakeLists.txt
  lldb/bindings/lua/lua-typemaps.swig
  lldb/bindings/lua/lua-wrapper.swig
  lldb/bindings/lua/lua.swig
  lldb/source/API/liblldb-private.exports
  lldb/source/API/liblldb.exports
  lldb/test/API/lit.site.cfg.py.in
  lldb/test/API/lldbtest.py
  lldb/test/API/lua_api/Makefile
  lldb/test/API/lua_api/TestBreakpointAPI.lua
  lldb/test/API/lua_api/TestComprehensive.lua
  lldb/test/API/lua_api/TestFileHandle.lua
  lldb/test/API/lua_api/TestLuaAPI.py
  lldb/test/API/lua_api/TestProcessAPI.lua
  lldb/test/API/lua_api/lua_lldb_test.lua
  lldb/test/API/lua_api/main.c

Index: lldb/test/API/lua_api/main.c
===
--- /dev/null
+++ lldb/test/API/lua_api/main.c
@@ -0,0 +1,35 @@
+#include 
+
+void BFunction()
+{
+}
+
+void AFunction()
+{
+printf("I am a function.\n");
+}
+
+int main(int argc, const char *argv[])
+{
+int inited = 0xDEADBEEF;
+int sum = 0;
+if(argc > 1)
+{
+for(int i = 0; i < argc; i++)
+{
+puts(argv[i]);
+}
+if(argc > 2)
+{
+return argc;
+}
+}
+AFunction();
+for(int i = 1; i <= 100; i++)
+{
+BFunction();
+sum += i;
+}
+printf("sum = %d\n", sum);
+return 0;
+}
Index: lldb/test/API/lua_api/lua_lldb_test.lua
===
--- /dev/null
+++ lldb/test/API/lua_api/lua_lldb_test.lua
@@ -0,0 +1,155 @@
+-- Make lldb available in global
+lldb = require('lldb')
+
+-- Global assertion functions
+function assertTrue(x)
+if not x then error('assertTrue failure') end
+end
+
+function assertFalse(x)
+if x then error('assertNotNil failure') end
+end
+
+function assertNotNil(x)
+if x == nil then error('assertNotNil failure') end
+end
+
+function assertEquals(x, y)
+if type(x) == 'table' and type(y) == 'table' then
+for k, _ in pairs(x) do
+assertEquals(x[k], y[k])
+end
+elseif type(x) ~= type(y) then
+error('assertEquals failure')
+elseif x ~= y then
+error('assertEquals failure')
+end
+end
+
+function assertStrContains(x, y)
+if not string.find(x, y, 1, true) then
+error('assertStrContains failure')
+end
+end
+
+-- Global helper functions
+function read_file_non_empty_lines(f)
+local lines = {}
+while true do
+local line = f:read('*l')
+if not line then break end
+if line ~= '\n' then table.insert(lines, line) end
+end
+return lines
+end
+
+function split_lines(str)
+local lines = {}
+for line in str:gmatch("[^\r\n]+") do
+table.insert(lines, line)
+end
+return lines
+end
+
+function get_stopped_threads(process, reason)
+local threads = {}
+for i = 0, process:GetNumThreads() - 1 do
+local t = process:GetThreadAtIndex(i)
+if t:IsValid() and t:GetStopReason() == reason then
+table.insert(threads, t)
+end
+end
+return threads
+end
+
+function get_stopped_thread(process, reason)
+local threads = get_stopped_threads(process, reason)
+if #threads ~= 0 then return threads[1]
+else return nil end
+end
+
+-- Test helper
+
+local _M = {}
+local _m = {}
+
+local _mt = { __index = _m }
+
+function _M.create_test(name, exe, output, input)
+print('[lldb/lua] Create test ' .. name)
+exe = exe or os.getenv('TEST_EXE')
+output = output or os.getenv('TEST_OUTPUT')
+input = input or os.getenv('TEST_INPUT')
+lldb.SBDebugger.Initialize()
+local debugger = lldb.SBDebugger.Create()
+-- Ensure that debugger is created
+assertNotNil(debugger)
+assertTrue(debugger:IsValid())
+
+debugger:SetAsync(false)
+
+local lua_language = debugger:GetScriptingLanguage('lua')
+assertNotNil(lua_language)
+debugger:SetScriptLanguage(lua_language)
+
+local test = setmetatable({
+output = output,
+input = input,
+name = name,
+exe = exe,
+debugger = debugger
+}, _mt)
+_G[name] = test
+return test
+end
+
+function _m:create_target(exe)
+local target
+if not exe then exe = self.exe end
+target = self.debugger:CreateTarget(exe)
+-- Ensure that target is created
+assertNotNil(target)
+assertTrue(target:IsValid())
+return target
+end
+
+function _m:handle_command(command, collect)
+if collect == nil then 

[Lldb-commits] [lldb] 67f94e5 - [lldb/lua] Supplement Lua bindings for lldb module

2021-10-12 Thread Siger Yang via lldb-commits

Author: Siger Yang
Date: 2021-10-12T22:10:21+08:00
New Revision: 67f94e5a9745665dd62550c75cb16569fbb0059d

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

LOG: [lldb/lua] Supplement Lua bindings for lldb module

Add necessary typemaps for Lua bindings, together with some other files.

Signed-off-by: Siger Yang 

Reviewed By: tammela

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

Added: 
lldb/test/API/lua_api/Makefile
lldb/test/API/lua_api/TestBreakpointAPI.lua
lldb/test/API/lua_api/TestComprehensive.lua
lldb/test/API/lua_api/TestFileHandle.lua
lldb/test/API/lua_api/TestLuaAPI.py
lldb/test/API/lua_api/TestProcessAPI.lua
lldb/test/API/lua_api/lua_lldb_test.lua
lldb/test/API/lua_api/main.c

Modified: 
lldb/CMakeLists.txt
lldb/bindings/lua/CMakeLists.txt
lldb/bindings/lua/lua-typemaps.swig
lldb/bindings/lua/lua-wrapper.swig
lldb/bindings/lua/lua.swig
lldb/source/API/liblldb-private.exports
lldb/source/API/liblldb.exports
lldb/test/API/lit.site.cfg.py.in
lldb/test/API/lldbtest.py

Removed: 




diff  --git a/lldb/CMakeLists.txt b/lldb/CMakeLists.txt
index 594c769141b43..028dadbb8c73c 100644
--- a/lldb/CMakeLists.txt
+++ b/lldb/CMakeLists.txt
@@ -51,6 +51,13 @@ if (LLDB_ENABLE_PYTHON)
 CACHE STRING "Path where Python modules are installed, relative to install 
prefix")
 endif ()
 
+if (LLDB_ENABLE_LUA)
+  find_program(Lua_EXECUTABLE lua5.3)
+  set(LLDB_LUA_DEFAULT_RELATIVE_PATH "lib/lua/5.3")
+  set(LLDB_LUA_RELATIVE_PATH ${LLDB_LUA_DEFAULT_RELATIVE_PATH}
+CACHE STRING "Path where Lua modules are installed, relative to install 
prefix")
+endif ()
+
 if (LLDB_ENABLE_PYTHON OR LLDB_ENABLE_LUA)
   add_subdirectory(bindings)
 endif ()
@@ -94,6 +101,16 @@ if (LLDB_ENABLE_PYTHON)
   finish_swig_python("lldb-python" "${lldb_python_bindings_dir}" 
"${lldb_python_target_dir}")
 endif()
 
+if (LLDB_ENABLE_LUA)
+  if(LLDB_BUILD_FRAMEWORK)
+set(lldb_lua_target_dir 
"${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Lua")
+  else()
+set(lldb_lua_target_dir 
"${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_LUA_RELATIVE_PATH}")
+  endif()
+  get_target_property(lldb_lua_bindings_dir swig_wrapper_lua BINARY_DIR)
+  finish_swig_lua("lldb-lua" "${lldb_lua_bindings_dir}" 
"${lldb_lua_target_dir}")
+endif()
+
 option(LLDB_INCLUDE_TESTS "Generate build targets for the LLDB unit tests." 
${LLVM_INCLUDE_TESTS})
 if(LLDB_INCLUDE_TESTS)
   add_subdirectory(test)

diff  --git a/lldb/bindings/lua/CMakeLists.txt 
b/lldb/bindings/lua/CMakeLists.txt
index 7148f13704560..1a739a9805ec8 100644
--- a/lldb/bindings/lua/CMakeLists.txt
+++ b/lldb/bindings/lua/CMakeLists.txt
@@ -17,3 +17,55 @@ add_custom_command(
 add_custom_target(swig_wrapper_lua ALL DEPENDS
   ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapLua.cpp
 )
+
+function(create_lua_package swig_target working_dir pkg_dir)
+  cmake_parse_arguments(ARG "NOINIT" "" "FILES" ${ARGN})
+  add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM
+COMMAND ${CMAKE_COMMAND} -E make_directory ${pkg_dir}
+WORKING_DIRECTORY ${working_dir})
+endfunction()
+
+function(finish_swig_lua swig_target lldb_lua_bindings_dir lldb_lua_target_dir)
+  add_custom_target(${swig_target} ALL VERBATIM
+COMMAND ${CMAKE_COMMAND} -E make_directory ${lldb_lua_target_dir}
+DEPENDS swig_wrapper_lua
+COMMENT "LLDB Lua API")
+  if(LLDB_BUILD_FRAMEWORK)
+set(LIBLLDB_SYMLINK_DEST 
"${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/LLDB")
+  else()
+set(LIBLLDB_SYMLINK_DEST 
"${LLVM_SHLIB_OUTPUT_INTDIR}/liblldb${CMAKE_SHARED_LIBRARY_SUFFIX}")
+  endif()
+  if(WIN32)
+if(CMAKE_BUILD_TYPE STREQUAL Debug)
+  set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb_d.pyd")
+else()
+  set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb.pyd")
+endif()
+  else()
+set(LIBLLDB_SYMLINK_OUTPUT_FILE "lldb.so")
+  endif()
+  create_relative_symlink(${swig_target} ${LIBLLDB_SYMLINK_DEST}
+  ${lldb_lua_target_dir} 
${LIBLLDB_SYMLINK_OUTPUT_FILE})
+  set(lldb_lua_library_target "${swig_target}-library")
+  add_custom_target(${lldb_lua_library_target})
+  add_dependencies(${lldb_lua_library_target} ${swig_target})
+
+  # Ensure we do the Lua post-build step when building lldb.
+  add_dependencies(lldb ${swig_target})
+
+  if(LLDB_BUILD_FRAMEWORK)
+set(LLDB_LUA_INSTALL_PATH 
${LLDB_FRAMEWORK_INSTALL_DIR}/LLDB.framework/Resources/Python)
+  else()
+set(LLDB_LUA_INSTALL_PATH ${LLDB_LUA_RELATIVE_PATH})
+  endif()
+  install(DIRECTORY ${lldb_lua_target_dir}/
+  DESTINATION ${LLDB_LUA_INSTALL_PATH}
+  COMPONENT ${lldb_lua_library_target})
+
+  set(lldb_lua_library_install_target "install-${lldb_lua_library_target}")
+  if (NOT LLVM_ENABLE_IDE)
+add_llvm_install

[Lldb-commits] [PATCH] D111659: [lldb] Skip several lldb tests that are flaky on Windows

2021-10-12 Thread Stella Stamenova via Phabricator via lldb-commits
stella.stamenova created this revision.
stella.stamenova added a reviewer: labath.
stella.stamenova requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

These tests fail every 10 or so runs on Windows causing both local failures as 
well as buildbot failures.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111659

Files:
  lldb/test/API/commands/process/attach/TestProcessAttach.py
  
lldb/test/API/commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py
  lldb/test/API/tools/lldb-server/TestGdbRemoteAttachOrWait.py
  lldb/test/API/tools/lldb-server/TestGdbRemoteAttachWait.py


Index: lldb/test/API/tools/lldb-server/TestGdbRemoteAttachWait.py
===
--- lldb/test/API/tools/lldb-server/TestGdbRemoteAttachWait.py
+++ lldb/test/API/tools/lldb-server/TestGdbRemoteAttachWait.py
@@ -13,6 +13,7 @@
 
 mydir = TestBase.compute_mydir(__file__)
 
+@skipIfWindows # This test is flaky on Windows
 def test_attach_with_vAttachWait(self):
 exe = '%s_%d' % (self.testMethodName, os.getpid())
 
Index: lldb/test/API/tools/lldb-server/TestGdbRemoteAttachOrWait.py
===
--- lldb/test/API/tools/lldb-server/TestGdbRemoteAttachOrWait.py
+++ lldb/test/API/tools/lldb-server/TestGdbRemoteAttachOrWait.py
@@ -13,6 +13,7 @@
 
 mydir = TestBase.compute_mydir(__file__)
 
+@skipIfWindows # This test is flaky on Windows
 def test_launch_before_attach_with_vAttachOrWait(self):
 exe = '%s_%d' % (self.testMethodName, os.getpid())
 self.build(dictionary={'EXE': exe})
@@ -57,6 +58,7 @@
 reported_pid = int(pid_text, base=16)
 self.assertEqual(reported_pid, inferior.pid)
 
+@skipIfWindows # This test is flaky on Windows
 def test_launch_after_attach_with_vAttachOrWait(self):
 exe = '%s_%d' % (self.testMethodName, os.getpid())
 self.build(dictionary={'EXE': exe})
Index: 
lldb/test/API/commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py
===
--- 
lldb/test/API/commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py
+++ 
lldb/test/API/commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py
@@ -16,6 +16,7 @@
 NO_DEBUG_INFO_TESTCASE = True
 
 @skipIfRemote
+@skipIfWindows # This test is flaky on Windows
 def test_target_auto_install_main_executable(self):
 if lldbgdbserverutils.get_lldb_server_exe() is None:
   self.skipTest("lldb-server not found")
Index: lldb/test/API/commands/process/attach/TestProcessAttach.py
===
--- lldb/test/API/commands/process/attach/TestProcessAttach.py
+++ lldb/test/API/commands/process/attach/TestProcessAttach.py
@@ -101,6 +101,7 @@
 process = target.GetProcess()
 self.assertTrue(process, PROCESS_IS_VALID)
 
+@skipIfWindows # This test is flaky on Windows
 @expectedFailureNetBSD
 def test_attach_to_process_by_id_correct_executable_offset(self):
 """


Index: lldb/test/API/tools/lldb-server/TestGdbRemoteAttachWait.py
===
--- lldb/test/API/tools/lldb-server/TestGdbRemoteAttachWait.py
+++ lldb/test/API/tools/lldb-server/TestGdbRemoteAttachWait.py
@@ -13,6 +13,7 @@
 
 mydir = TestBase.compute_mydir(__file__)
 
+@skipIfWindows # This test is flaky on Windows
 def test_attach_with_vAttachWait(self):
 exe = '%s_%d' % (self.testMethodName, os.getpid())
 
Index: lldb/test/API/tools/lldb-server/TestGdbRemoteAttachOrWait.py
===
--- lldb/test/API/tools/lldb-server/TestGdbRemoteAttachOrWait.py
+++ lldb/test/API/tools/lldb-server/TestGdbRemoteAttachOrWait.py
@@ -13,6 +13,7 @@
 
 mydir = TestBase.compute_mydir(__file__)
 
+@skipIfWindows # This test is flaky on Windows
 def test_launch_before_attach_with_vAttachOrWait(self):
 exe = '%s_%d' % (self.testMethodName, os.getpid())
 self.build(dictionary={'EXE': exe})
@@ -57,6 +58,7 @@
 reported_pid = int(pid_text, base=16)
 self.assertEqual(reported_pid, inferior.pid)
 
+@skipIfWindows # This test is flaky on Windows
 def test_launch_after_attach_with_vAttachOrWait(self):
 exe = '%s_%d' % (self.testMethodName, os.getpid())
 self.build(dictionary={'EXE': exe})
Index: lldb/test/API/commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py
===
--- lldb/test/API/commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py
+++ lldb/test/API/commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py
@@ -16,6 +16

[Lldb-commits] [PATCH] D110827: [LLDB] Provide target specific directories to libclang

2021-10-12 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added a comment.

In D110827#3042820 , @kpdev42 wrote:

> In D110827#3034767 , @clayborg 
> wrote:
>
>> Should we be testing if these directories exist before trying to use them? 
>> Might be nice to avoid compiler warnings if the compiler will emit warnings 
>> or errors if these directories don't exist.
>
> I think testing if these directories exists may be a little bit redundant 
> because clang ignores non-existent include paths passed with -I

no worries then

>> LLDB also tests with compilers that were built, like when LLDB builds clang 
>> and uses that clang and clang++ that it built to run the test suite. If we 
>> had settings in LLDB that users could set, then the test suite would be able 
>> to use the include files for the compiler that is being used instead of 
>> always defaulting to the system headers.
>
> Could you please clarify: "LLDB builds clang" - here you mean clang which was 
> build with LLDB? And I would like to mention that starting from 
> https://reviews.llvm.org/D89013 libcxx puts __config_site header to target 
> specific folder

We often build the full clang compiler during LLDB builds and then use the 
clang we built as the compiler when running our test suite. So anything we can 
do to make sure what ever clang we use for building the test suite binaries has 
all of the headers that it was built with along with any support library 
headers (libcxx, etc) that would be great.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110827

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


[Lldb-commits] [PATCH] D110804: Add a new command "target metrics".

2021-10-12 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added a comment.

In D110804#3037504 , @JDevlieghere 
wrote:

> Thanks Greg! Following Pavel's suggestion in D110893 
> , could you split up this patch into 
> smaller ones? I think that will make it a lot easier to review and discuss.

Will do


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110804

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


[Lldb-commits] [PATCH] D110298: Add "command multiword add" and the ability to add script commands into a user multiword hierarchy

2021-10-12 Thread Jim Ingham via Phabricator via lldb-commits
jingham updated this revision to Diff 379145.
jingham marked an inline comment as done.
jingham added a comment.

I changed the command name from "command multiword" to "command container".

Greg noted that "multiword" is what we used for these but it's actually not a 
great description of what you are adding.   "Command Containers" seems closer.  
It doesn't also reflect the fact that you can nest containers in containers, 
but I think that's not going to confuse anyone.

That's the best name I could come up with, but I do think it's better than 
"command multiword".

I also addressed Jonas' comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110298

Files:
  lldb/include/lldb/Interpreter/CommandCompletions.h
  lldb/include/lldb/Interpreter/CommandInterpreter.h
  lldb/include/lldb/Interpreter/CommandObject.h
  lldb/include/lldb/Interpreter/CommandObjectMultiword.h
  lldb/source/API/SBCommandInterpreter.cpp
  lldb/source/Commands/CommandCompletions.cpp
  lldb/source/Commands/CommandObjectApropos.cpp
  lldb/source/Commands/CommandObjectCommands.cpp
  lldb/source/Commands/CommandObjectHelp.cpp
  lldb/source/Commands/CommandObjectMultiword.cpp
  lldb/source/Commands/Options.td
  lldb/source/Interpreter/CommandInterpreter.cpp
  lldb/source/Interpreter/CommandObject.cpp
  lldb/test/API/commands/command/container/TestContainerCommands.py
  lldb/test/API/commands/command/container/welcome.py
  lldb/test/API/commands/command/invalid-args/TestInvalidArgsCommand.py
  lldb/test/API/commands/command/script/TestCommandScript.py
  lldb/test/API/commands/expression/char/main.cpp
  lldb/test/API/functionalities/completion/TestCompletion.py
  lldb/unittests/Interpreter/CMakeLists.txt
  lldb/unittests/Interpreter/TestCommandPaths.cpp

Index: lldb/unittests/Interpreter/TestCommandPaths.cpp
===
--- /dev/null
+++ lldb/unittests/Interpreter/TestCommandPaths.cpp
@@ -0,0 +1,159 @@
+//===-- ProcessEventDataTest.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Interpreter/CommandInterpreter.h"
+#include "lldb/Interpreter/CommandObject.h"
+#include "lldb/Interpreter/CommandObjectMultiword.h"
+#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Utility/Args.h"
+#include "lldb/Utility/Reproducer.h"
+#include "lldb/Utility/Status.h"
+
+#include "gtest/gtest.h"
+
+using namespace lldb_private;
+using namespace lldb_private::repro;
+using namespace lldb;
+
+namespace {
+class VerifyUserMultiwordCmdPathTest : public ::testing::Test {
+  void SetUp() override {
+llvm::cantFail(Reproducer::Initialize(ReproducerMode::Off, llvm::None));
+FileSystem::Initialize();
+HostInfo::Initialize();
+PlatformMacOSX::Initialize();
+  }
+  void TearDown() override {
+PlatformMacOSX::Terminate();
+HostInfo::Terminate();
+FileSystem::Terminate();
+Reproducer::Terminate();
+  }
+};
+} // namespace
+
+class CommandObjectLeaf : public CommandObjectParsed {
+public:
+  CommandObjectLeaf(CommandInterpreter &interpreter)
+  : CommandObjectParsed(interpreter, "dummy subcommand leaf",
+"Does nothing", "dummy subcommand leaf") {
+SetIsUserCommand(true);
+  }
+
+protected:
+  virtual bool DoExecute(Args &command, CommandReturnObject &result) {
+result.SetStatus(eReturnStatusSuccessFinishResult);
+result.AppendMessage("I did nothing");
+return true;
+  }
+};
+
+class CommandObjectMultiwordSubDummy : public CommandObjectMultiword {
+public:
+  CommandObjectMultiwordSubDummy(CommandInterpreter &interpreter)
+  : CommandObjectMultiword(interpreter, "dummy subcommand", "Does nothing",
+   "dummy subcommand") {
+SetIsUserCommand(true);
+LoadSubCommand("leaf", CommandObjectSP(new CommandObjectLeaf(interpreter)));
+  }
+
+  ~CommandObjectMultiwordSubDummy() override = default;
+};
+
+class CommandObjectMultiwordDummy : public CommandObjectMultiword {
+public:
+  CommandObjectMultiwordDummy(CommandInterpreter &interpreter)
+  : CommandObjectMultiword(interpreter, "dummy", "Does nothing", "dummy") {
+SetIsUserCommand(true);
+LoadSubCommand(
+"subcommand",
+CommandObjectSP(new CommandObjectMultiwordSubDummy(interpreter)));
+  }
+
+  ~CommandObjectMultiwordDummy() override = default;
+};
+
+// Pass in the command path to args.  If success is true, we make sure the MWC
+// returned matches the test string.  I

[Lldb-commits] [PATCH] D110298: Add "command multiword add" and the ability to add script commands into a user multiword hierarchy

2021-10-12 Thread Jim Ingham via Phabricator via lldb-commits
jingham added inline comments.



Comment at: lldb/source/Commands/CommandObjectMultiword.cpp:121-129
+  const char *error_str = nullptr;
+  if (!can_replace)
+error_str = "sub-command already exists";
+  if (!(*pos).second->IsUserCommand())
+error_str = "can't replace a builtin subcommand";
+
+  if (error_str) {

JDevlieghere wrote:
> This inline diff looks more confusing than anything, but basically I just 
> switched the errors around (instead of the current fall-through) and return 
> the error immediately. 
This isn't an early return vrs. not early return thing, since the if's are just 
deciding which error to print, then we return directly if there was an error.

, I like my version better.  Your version hides the error message in the 
middle of two copies of all the llvm::createStringError goo, which makes it 
much harder to read, IMO.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110298

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


[Lldb-commits] [lldb] 1b81581 - [lldb][test] Remove Intel MPX tests

2021-10-12 Thread Fangrui Song via lldb-commits

Author: Fangrui Song
Date: 2021-10-12T16:16:58-07:00
New Revision: 1b81581feec8cb6361d898dea17ed2f0ad7e5b13

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

LOG: [lldb][test] Remove Intel MPX tests

Intel MPX failed to gain wide adoption and has been deprecated for a while.
GCC 9.1 removed Intel MPX support. Linux kernel removed MPX in 2019.
glibc 2.35 will remove the support.

Added: 


Modified: 


Removed: 
lldb/test/API/commands/register/register/intel_xtended_registers/Makefile

lldb/test/API/commands/register/register/intel_xtended_registers/TestMPXRegisters.py
lldb/test/API/commands/register/register/intel_xtended_registers/main.cpp

lldb/test/API/commands/register/register/intel_xtended_registers/mpx_bound_violation/Makefile

lldb/test/API/commands/register/register/intel_xtended_registers/mpx_bound_violation/TestBoundViolation.py

lldb/test/API/commands/register/register/intel_xtended_registers/mpx_bound_violation/main.cpp

lldb/test/API/commands/register/register/intel_xtended_registers/mpx_offset_intersection/Makefile

lldb/test/API/commands/register/register/intel_xtended_registers/mpx_offset_intersection/TestMPXOffsetIntersection.py

lldb/test/API/commands/register/register/intel_xtended_registers/mpx_offset_intersection/main.cpp



diff  --git 
a/lldb/test/API/commands/register/register/intel_xtended_registers/Makefile 
b/lldb/test/API/commands/register/register/intel_xtended_registers/Makefile
deleted file mode 100644
index 5cc7382f1d92f..0
--- a/lldb/test/API/commands/register/register/intel_xtended_registers/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
-CXX_SOURCES := main.cpp
-
-CFLAGS_EXTRAS := -mmpx -fcheck-pointer-bounds -fuse-ld=bfd
-
-include Makefile.rules

diff  --git 
a/lldb/test/API/commands/register/register/intel_xtended_registers/TestMPXRegisters.py
 
b/lldb/test/API/commands/register/register/intel_xtended_registers/TestMPXRegisters.py
deleted file mode 100644
index 5644855868b3a..0
--- 
a/lldb/test/API/commands/register/register/intel_xtended_registers/TestMPXRegisters.py
+++ /dev/null
@@ -1,61 +0,0 @@
-"""
-Test the Intel(R) MPX registers.
-"""
-
-
-
-import lldb
-from lldbsuite.test.decorators import *
-from lldbsuite.test.lldbtest import *
-from lldbsuite.test import lldbutil
-
-
-class RegisterCommandsTestCase(TestBase):
-
-mydir = TestBase.compute_mydir(__file__)
-
-@skipIf(compiler="clang")
-@skipIf(oslist=no_match(['linux']))
-@skipIf(archs=no_match(['i386', 'x86_64']))
-@skipIf(oslist=["linux"], compiler="gcc", compiler_version=["<", "5"]) 
#GCC version >= 5 supports Intel(R) MPX.
-def test_mpx_registers_with_example_code(self):
-"""Test Intel(R) MPX registers with example code."""
-self.build()
-self.mpx_registers_with_example_code()
-
-def mpx_registers_with_example_code(self):
-"""Test Intel(R) MPX registers after running example code."""
-self.line = line_number('main.cpp', '// Set a break point here.')
-
-exe = self.getBuildArtifact("a.out")
-self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
-
-lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.line, 
num_expected_locations=1)
-self.runCmd("run", RUN_SUCCEEDED)
-
-target = self.dbg.GetSelectedTarget()
-process = target.GetProcess()
-
-if (process.GetState() == lldb.eStateExited):
-self.skipTest("Intel(R) MPX is not supported.")
-else:
-self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
-substrs = ["stop reason = breakpoint 1."])
-
-if self.getArchitecture() == 'x86_64':
-self.expect("register read -s 3",
-substrs = ['bnd0 = {0x0010 
0xffe6}',
-   'bnd1 = {0x0020 
0xffd6}',
-   'bnd2 = {0x0030 
0xffc6}',
-   'bnd3 = {0x0040 
0xffb6}',
-   'bndcfgu = {0x01 0x80 0xb5 0x76 0xff 0x7f 
0x00 0x00}',
-   'bndstatus = {0x02 0x80 0xb5 0x76 0xff 0x7f 
0x00 0x00}'])
-if self.getArchitecture() == 'i386':
-self.expect("register read -s 3",
-substrs = ['bnd0 = {0x0010 
0xffe6}',
-   'bnd1 = {0x0020 
0xffd6}',
-   'bnd2 = {0x0030 
0xffc6}',
-   'bnd3 = {0x0040 
0xffb6}',
-   'bndcfgu = {0x01 0xd

[Lldb-commits] [PATCH] D111686: Modify "statistics dump" to dump JSON.

2021-10-12 Thread Greg Clayton via Phabricator via lldb-commits
clayborg created this revision.
clayborg added reviewers: jingham, labath, aprantl, JDevlieghere, aadsm, 
wallace, jdoerfert.
Herald added a subscriber: mgorny.
clayborg requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This patch is a smaller version of a previous patch 
https://reviews.llvm.org/D110804.

This patch modifies the output of "statistics dump" to be able to get stats 
from the current target. It adds 3 new stats as well. The output of "statistics 
dump" is now emitted as JSON so that it can be used to track performance and 
statistics and the output could be used to populate a database that tracks 
performance. Sample output looks like:

(lldb) statistics dump
{

  "expressionEvaluation": {
"failures": 0,
"successes": 0
  },
  "firstStopTime": 0.3416449280001,
  "frameVariable": {
"failures": 0,
"successes": 0
  },
  "launchOrAttachTime": 0.3196960540001,
  "targetCreateTime": 0.00408630398

}

The top level keys are:

"expressionEvaluation" which replaces the previous stats that were emitted as 
plain text. This dictionary contains the success and fail counts.
"frameVariable" which replaces the previous stats for "frame variable" that 
were emitted as plain text. This dictionary contains the success and fail 
counts.
"targetCreateTime" contains the number of seconds it took to create the target 
and load dependent libraries (if they were enabled) and also will contain 
symbol preloading times if that setting is enabled.
"launchOrAttachTime" is the time it takes from when the launch/attach is 
initiated to when the first private stop occurs.
"firstStopTime" is the time in seconds that it takes to stop at the first stop 
that is presented to the user via the LLDB interface. This value will only have 
meaning if you set a known breakpoint or stop location in your code that you 
want to measure as a performance test.

This diff is also meant as a place to discuess what we want out of the 
"statistics dump" command before adding more funcionality. It is also meant to 
clean up the previous code that was storting statistics in a vector of numbers 
within the lldb_private::Target class.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111686

Files:
  lldb/include/lldb/Target/Process.h
  lldb/include/lldb/Target/Statistics.h
  lldb/include/lldb/Target/Target.h
  lldb/include/lldb/Utility/ElapsedTime.h
  lldb/include/lldb/lldb-forward.h
  lldb/packages/Python/lldbsuite/test/lldbtest.py
  lldb/source/API/SBTarget.cpp
  lldb/source/Commands/CommandObjectExpression.cpp
  lldb/source/Commands/CommandObjectFrame.cpp
  lldb/source/Commands/CommandObjectStats.cpp
  lldb/source/Target/CMakeLists.txt
  lldb/source/Target/Process.cpp
  lldb/source/Target/Statistics.cpp
  lldb/source/Target/Target.cpp
  lldb/test/API/commands/statistics/basic/TestStats.py
  lldb/test/API/functionalities/stats_api/TestStatisticsAPI.py

Index: lldb/test/API/functionalities/stats_api/TestStatisticsAPI.py
===
--- lldb/test/API/functionalities/stats_api/TestStatisticsAPI.py
+++ lldb/test/API/functionalities/stats_api/TestStatisticsAPI.py
@@ -10,6 +10,8 @@
 class TestStatsAPI(TestBase):
 mydir = TestBase.compute_mydir(__file__)
 
+NO_DEBUG_INFO_TESTCASE = True
+
 def test_stats_api(self):
 self.build()
 exe = self.getBuildArtifact("a.out")
@@ -26,9 +28,18 @@
 stats = target.GetStatistics()
 stream = lldb.SBStream()
 res = stats.GetAsJSON(stream)
-stats_json = sorted(json.loads(stream.GetData()))
-self.assertEqual(len(stats_json), 4)
-self.assertIn("Number of expr evaluation failures", stats_json)
-self.assertIn("Number of expr evaluation successes", stats_json)
-self.assertIn("Number of frame var failures", stats_json)
-self.assertIn("Number of frame var successes", stats_json)
+stats_json = json.loads(stream.GetData())
+self.assertEqual('expressionEvaluation' in stats_json, True,
+'Make sure the "expressionEvaluation" key in in target.GetStatistics()')
+self.assertEqual('frameVariable' in stats_json, True,
+'Make sure the "frameVariable" key in in target.GetStatistics()')
+expressionEvaluation = stats_json['expressionEvaluation']
+self.assertEqual('successes' in expressionEvaluation, True,
+'Make sure the "successes" key in in "expressionEvaluation" dictionary"')
+self.assertEqual('failures' in expressionEvaluation, True,
+'Make sure the "failures" key in in "expressionEvaluation" dictionary"')
+frameVariable = stats_json['frameVariable']
+self.assertEqual('successes' in frameVariable, True,
+'Make sure the "successes" key in in "frameVariable" dictionary"')
+self.assertEqual('failures' in frameVariable, True,
+ 

[Lldb-commits] [PATCH] D110804: Add a new command "target metrics".

2021-10-12 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added a comment.

I have broken out the target only settings to make this patch smaller into: 
https://reviews.llvm.org/D111686


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110804

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