[Lldb-commits] [lldb] 280ae10 - [LLDB] fix error message for one-line breakpoint scripts

Pedro Tammela via lldb-commits lldb-commits at lists.llvm.org
Mon Dec 7 03:28:26 PST 2020


Author: Pedro Tammela
Date: 2020-12-07T11:21:07Z
New Revision: 280ae10774abac63d4c9fdaf99598afe3053540a

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

LOG: [LLDB] fix error message for one-line breakpoint scripts

LLDB is ignoring compilation errors for one-line breakpoint scripts.
This patch fixes the issues and now the error message of the
ScriptInterpreter is shown to the user.

I had to remove a new-line character for the Lua interpreter since it
was duplicated.

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

Added: 
    lldb/test/Shell/ScriptInterpreter/Lua/fail_breakpoint_oneline.test
    lldb/test/Shell/ScriptInterpreter/Python/fail_breakpoint_oneline.test

Modified: 
    lldb/source/Commands/CommandObjectBreakpointCommand.cpp
    lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp
index 792e90ff27a1..caaf3bfb482f 100644
--- a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp
+++ b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp
@@ -414,22 +414,23 @@ are no syntax errors may indicate that a function was declared but never called.
       // to set or collect command callback.  Otherwise, call the methods
       // associated with this object.
       if (m_options.m_use_script_language) {
+        Status error;
         ScriptInterpreter *script_interp = GetDebugger().GetScriptInterpreter(
             /*can_create=*/true, m_options.m_script_language);
         // Special handling for one-liner specified inline.
         if (m_options.m_use_one_liner) {
-          script_interp->SetBreakpointCommandCallback(
+          error = script_interp->SetBreakpointCommandCallback(
               m_bp_options_vec, m_options.m_one_liner.c_str());
         } else if (!m_func_options.GetName().empty()) {
-          Status error = script_interp->SetBreakpointCommandCallbackFunction(
+          error = script_interp->SetBreakpointCommandCallbackFunction(
               m_bp_options_vec, m_func_options.GetName().c_str(),
               m_func_options.GetStructuredData());
-          if (!error.Success())
-            result.SetError(error);
         } else {
           script_interp->CollectDataForBreakpointCommandCallback(
               m_bp_options_vec, result);
         }
+        if (!error.Success())
+          result.SetError(error);
       } else {
         // Special handling for one-liner specified inline.
         if (m_options.m_use_one_liner)

diff  --git a/lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp b/lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
index ca1d181a6940..fb3628a3107c 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
@@ -86,7 +86,7 @@ llvm::Error Lua::RegisterBreakpointCallback(void *baton, const char *body) {
   std::string func_str = llvm::formatv(fmt_str, body).str();
   if (luaL_dostring(m_lua_state, func_str.c_str()) != LUA_OK) {
     llvm::Error e = llvm::make_error<llvm::StringError>(
-        llvm::formatv("{0}\n", lua_tostring(m_lua_state, -1)),
+        llvm::formatv("{0}", lua_tostring(m_lua_state, -1)),
         llvm::inconvertibleErrorCode());
     // Pop error message from the stack.
     lua_pop(m_lua_state, 2);

diff  --git a/lldb/test/Shell/ScriptInterpreter/Lua/fail_breakpoint_oneline.test b/lldb/test/Shell/ScriptInterpreter/Lua/fail_breakpoint_oneline.test
new file mode 100644
index 000000000000..b418889345d7
--- /dev/null
+++ b/lldb/test/Shell/ScriptInterpreter/Lua/fail_breakpoint_oneline.test
@@ -0,0 +1,5 @@
+# REQUIRES: lua
+# RUN: %lldb -s %s --script-language lua 2>&1 | FileCheck %s
+b main
+breakpoint command add -s lua -o '1234_foo'
+# CHECK: error: {{.*}} unexpected symbol near '1234'

diff  --git a/lldb/test/Shell/ScriptInterpreter/Python/fail_breakpoint_oneline.test b/lldb/test/Shell/ScriptInterpreter/Python/fail_breakpoint_oneline.test
new file mode 100644
index 000000000000..d38df16aaf1f
--- /dev/null
+++ b/lldb/test/Shell/ScriptInterpreter/Python/fail_breakpoint_oneline.test
@@ -0,0 +1,7 @@
+# REQUIRES: python
+# UNSUPPORTED: lldb-repro
+#
+# RUN: %lldb -s %s --script-language python 2>&1 | FileCheck %s
+b main
+breakpoint command add -s python -o "1234_foo"
+# CHECK: error: SyntaxError({{.*}})


        


More information about the lldb-commits mailing list