[Lldb-commits] [lldb] [lldb-dap] Implement command directives (PR #74808)

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Fri Dec 8 20:42:54 PST 2023


================
@@ -33,14 +39,49 @@ void RunLLDBCommands(llvm::StringRef prefix,
       const char *error = result.GetError();
       strm << error;
     }
+  };
+
+  lldb::SBCommandInterpreter interp = g_dap.debugger.GetCommandInterpreter();
+  for (llvm::StringRef command : commands) {
+    lldb::SBCommandReturnObject result;
+    bool quiet_on_success = false;
+    bool abort_on_error = false;
+
+    while (parse_command_directives) {
+      if (command.starts_with("?")) {
+        command = command.drop_front();
+        quiet_on_success = true;
+      } else if (command.starts_with("!")) {
+        command = command.drop_front();
+        abort_on_error = true;
+      } else {
+        break;
+      }
+    }
+
+    interp.HandleCommand(command.str().c_str(), result);
+
+    if (!result.Succeeded() && abort_on_error) {
+      std::string output;
+      llvm::raw_string_ostream os(output);
+      print_result(command, result, os);
+      os << "\nTerminating the debug session due to the critical failure of "
+            "the last executed command...\n";
+      g_dap.SendOutput(OutputType::Console, output);
+      std::abort();
+    }
+
+    if (!(result.Succeeded() && quiet_on_success))
+      print_result(command, result, strm);
----------------
clayborg wrote:

This logic can be cleaned up a bit:
```
// The if statement below is assuming we always print out `!` prefixed lines. 
// The only time we don't print is when we have `quiet_on_success == true` and
// we have an error. 
const bool got_error = !result.Succeeded();
if (quiet_on_success ? got_error : true)
  print_result(command, result, strm);
if (abort_on_error && got_error) {
  fatal_error = true; // Set the "bool &fatal_error" parameter to true
  return; // Stop running commands if we need to abort due to error
}
```

https://github.com/llvm/llvm-project/pull/74808


More information about the lldb-commits mailing list