[Lldb-commits] [PATCH] D16728: [lldb-mi] print real error message in "-data-evaluate-expression"

Eugene Leviant via lldb-commits lldb-commits at lists.llvm.org
Fri Jan 29 09:25:08 PST 2016


evgeny777 created this revision.
evgeny777 added reviewers: abidh, ki.stfu.
evgeny777 added a subscriber: lldb-commits.

Unlike "-var-create", the "-data-evaluate-expression" command always prints "Could not evaluate expression" when error occurs.

http://reviews.llvm.org/D16728

Files:
  packages/Python/lldbsuite/test/tools/lldb-mi/variable/TestMiVar.py
  tools/lldb-mi/MICmdCmdData.cpp
  tools/lldb-mi/MICmdCmdData.h

Index: tools/lldb-mi/MICmdCmdData.h
===================================================================
--- tools/lldb-mi/MICmdCmdData.h
+++ tools/lldb-mi/MICmdCmdData.h
@@ -32,6 +32,7 @@
 
 // Third party headers:
 #include "lldb/API/SBCommandReturnObject.h"
+#include "lldb/API/SBError.h"
 
 // In-house headers:
 #include "MICmdBase.h"
@@ -71,6 +72,7 @@
   private:
     bool m_bExpressionValid;     // True = yes is valid, false = not valid
     bool m_bEvaluatedExpression; // True = yes is expression evaluated, false = failed
+    lldb::SBError m_Error;       // Error object, which is examined when m_bEvaluatedExpression is false 
     CMIUtilString m_strValue;
     CMICmnMIValueTuple m_miValueTuple;
     bool m_bFoundInvalidChar; // True = yes found unexpected character in the expression, false = all ok
Index: tools/lldb-mi/MICmdCmdData.cpp
===================================================================
--- tools/lldb-mi/MICmdCmdData.cpp
+++ tools/lldb-mi/MICmdCmdData.cpp
@@ -117,7 +117,8 @@
 
     lldb::SBFrame frame = thread.GetSelectedFrame();
     lldb::SBValue value = frame.EvaluateExpression(rExpression.c_str());
-    if (!value.IsValid() || value.GetError().Fail())
+    m_Error = value.GetError();
+    if (!value.IsValid() || m_Error.Fail())
         value = frame.FindVariable(rExpression.c_str());
     const CMICmnLLDBUtilSBValue utilValue(value, true);
     if (!utilValue.IsValid() || utilValue.IsValueUnknown())
@@ -177,8 +178,10 @@
             m_miResultRecord = miRecordResult;
             return MIstatus::success;
         }
-
-        const CMICmnMIValueConst miValueConst("Could not evaluate expression");
+        CMIUtilString mi_error_msg = "Could not evaluate expression";
+        if (const char* err_msg = m_Error.GetCString())
+            mi_error_msg = err_msg;
+        const CMICmnMIValueConst miValueConst(mi_error_msg.Escape(true));
         const CMICmnMIValueResult miValueResult("msg", miValueConst);
         const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error, miValueResult);
         m_miResultRecord = miRecordResult;
Index: packages/Python/lldbsuite/test/tools/lldb-mi/variable/TestMiVar.py
===================================================================
--- packages/Python/lldbsuite/test/tools/lldb-mi/variable/TestMiVar.py
+++ packages/Python/lldbsuite/test/tools/lldb-mi/variable/TestMiVar.py
@@ -36,7 +36,7 @@
         self.runCmd("-var-create var1 * undef")
         self.expect("\^error,msg=\"error: error: use of undeclared identifier \'undef\'\\\\nerror: 1 errors parsing expression\\\\n\"")
         self.runCmd("-data-evaluate-expression undef")
-        self.expect("\^error,msg=\"Could not evaluate expression\"")
+        self.expect("\^error,msg=\"error: use of undeclared identifier \'undef\'\\\\nerror: 1 errors parsing expression\\\\n\"")
 
         # Print global "g_MyVar", modify, delete and create again
         self.runCmd("-data-evaluate-expression g_MyVar")


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16728.46391.patch
Type: text/x-patch
Size: 3013 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20160129/549b9561/attachment.bin>


More information about the lldb-commits mailing list