[Lldb-commits] [lldb] d10c0c7 - [lldb] Migrate condition evaluation failure to ReportError

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Wed Mar 16 22:54:07 PDT 2022


Author: Jonas Devlieghere
Date: 2022-03-16T22:54:02-07:00
New Revision: d10c0c7b187d6a5d7a24544d70998f8d348b4dfd

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

LOG: [lldb] Migrate condition evaluation failure to ReportError

Migrate to using ReportError to report a failure to evaluate a
watchpoint condition. I had already done so for the parallel code for
breakpoints.

In the process, I noticed that I accidentally regressed the error
reporting for breakpoint conditions by dropping the call to
GetDescription. This patch rectifies that and adds a test.

Because the call to GetDescription expects a Stream*, I also switches
from using a raw_string_ostream to a StreamString for both breakpoints
and watchpoints.

Added: 
    lldb/test/Shell/Breakpoint/invalid-condition.test

Modified: 
    lldb/source/Target/StopInfo.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Target/StopInfo.cpp b/lldb/source/Target/StopInfo.cpp
index f6cf3e55ce233..08c50ea5e62c9 100644
--- a/lldb/source/Target/StopInfo.cpp
+++ b/lldb/source/Target/StopInfo.cpp
@@ -452,19 +452,18 @@ class StopInfoBreakpoint : public StopInfo {
 
               if (!condition_error.Success()) {
                 const char *err_str =
-                    condition_error.AsCString("<Unknown Error>");
+                    condition_error.AsCString("<unknown error>");
                 LLDB_LOGF(log, "Error evaluating condition: \"%s\"\n", err_str);
 
-                std::string error_message;
-                llvm::raw_string_ostream os(error_message);
-                os << "stopped due to an error evaluating condition of "
-                      "breakpoint "
-                   << bp_loc_sp->GetConditionText() << '\n';
-                os << err_str;
-                os.flush();
+                StreamString strm;
+                strm << "stopped due to an error evaluating condition of "
+                        "breakpoint ";
+                bp_loc_sp->GetDescription(&strm, eDescriptionLevelBrief);
+                strm << ": \"" << bp_loc_sp->GetConditionText() << "\"\n";
+                strm << err_str;
 
                 Debugger::ReportError(
-                    std::move(error_message),
+                    strm.GetString().str(),
                     exe_ctx.GetTargetRef().GetDebugger().GetID());
               } else {
                 LLDB_LOGF(log,
@@ -860,20 +859,18 @@ class StopInfoWatchpoint : public StopInfo {
               }
             }
           } else {
-            StreamSP error_sp = debugger.GetAsyncErrorStream();
-            error_sp->Printf(
-                "Stopped due to an error evaluating condition of watchpoint ");
-            wp_sp->GetDescription(error_sp.get(), eDescriptionLevelBrief);
-            error_sp->Printf(": \"%s\"", wp_sp->GetConditionText());
-            error_sp->EOL();
-            const char *err_str = error.AsCString("<Unknown Error>");
+            const char *err_str = error.AsCString("<unknown error>");
             LLDB_LOGF(log, "Error evaluating condition: \"%s\"\n", err_str);
 
-            error_sp->PutCString(err_str);
-            error_sp->EOL();
-            error_sp->Flush();
-            // If the condition fails to be parsed or run, we should stop.
-            m_should_stop = true;
+            StreamString strm;
+            strm << "stopped due to an error evaluating condition of "
+                    "watchpoint ";
+            wp_sp->GetDescription(&strm, eDescriptionLevelBrief);
+            strm << ": \"" << wp_sp->GetConditionText() << "\"\n";
+            strm << err_str;
+
+            Debugger::ReportError(strm.GetString().str(),
+                                  exe_ctx.GetTargetRef().GetDebugger().GetID());
           }
         }
 

diff  --git a/lldb/test/Shell/Breakpoint/invalid-condition.test b/lldb/test/Shell/Breakpoint/invalid-condition.test
new file mode 100644
index 0000000000000..5990600a9560c
--- /dev/null
+++ b/lldb/test/Shell/Breakpoint/invalid-condition.test
@@ -0,0 +1,5 @@
+# RUN: %clang_host %p/Inputs/dummy-target.c -o %t.out
+# RUN: %lldb -b -o "br s -n main -c 'bogus'" -o "run" %t.out 2>&1 | FileCheck %s
+
+# CHECK: error: stopped due to an error evaluating condition of breakpoint 1.1: "bogus"
+# CHECK-NEXT: Couldn't parse conditional expression


        


More information about the lldb-commits mailing list