-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[lldb-dap] Return an llvm::Error instead of calling exit directly (NFC) #128951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Return an `llvm::Error` from `LaunchRunInTerminalTarget` instead of calling `exit()` directly.
@llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) ChangesReturn an Full diff: https://github.com/llvm/llvm-project/pull/128951.diff 1 Files Affected:
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index 1c6bd7e903409..6b31f9d3cfe54 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -197,12 +197,13 @@ static void printHelp(LLDBDAPOptTable &table, llvm::StringRef tool_name) {
//
// In case of errors launching the target, a suitable error message will be
// emitted to the debug adaptor.
-static void LaunchRunInTerminalTarget(llvm::opt::Arg &target_arg,
- llvm::StringRef comm_file,
- lldb::pid_t debugger_pid, char *argv[]) {
+static llvm::Error LaunchRunInTerminalTarget(llvm::opt::Arg &target_arg,
+ llvm::StringRef comm_file,
+ lldb::pid_t debugger_pid,
+ char *argv[]) {
#if defined(_WIN32)
- llvm::errs() << "runInTerminal is only supported on POSIX systems\n";
- exit(EXIT_FAILURE);
+ return llvm::createStringError(
+ "runInTerminal is only supported on POSIX systems");
#else
// On Linux with the Yama security module enabled, a process can only attach
@@ -214,10 +215,8 @@ static void LaunchRunInTerminalTarget(llvm::opt::Arg &target_arg,
#endif
RunInTerminalLauncherCommChannel comm_channel(comm_file);
- if (llvm::Error err = comm_channel.NotifyPid()) {
- llvm::errs() << llvm::toString(std::move(err)) << "\n";
- exit(EXIT_FAILURE);
- }
+ if (llvm::Error err = comm_channel.NotifyPid())
+ return err;
// We will wait to be attached with a timeout. We don't wait indefinitely
// using a signal to prevent being paused forever.
@@ -228,8 +227,7 @@ static void LaunchRunInTerminalTarget(llvm::opt::Arg &target_arg,
timeout_env_var != nullptr ? atoi(timeout_env_var) : 20000;
if (llvm::Error err = comm_channel.WaitUntilDebugAdaptorAttaches(
std::chrono::milliseconds(timeout_in_ms))) {
- llvm::errs() << llvm::toString(std::move(err)) << "\n";
- exit(EXIT_FAILURE);
+ return err;
}
const char *target = target_arg.getValue();
@@ -237,8 +235,8 @@ static void LaunchRunInTerminalTarget(llvm::opt::Arg &target_arg,
std::string error = std::strerror(errno);
comm_channel.NotifyError(error);
- llvm::errs() << error << "\n";
- exit(EXIT_FAILURE);
+ return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ std::move(error));
#endif
}
@@ -469,13 +467,18 @@ int main(int argc, char *argv[]) {
}
}
int target_args_pos = argc;
- for (int i = 0; i < argc; i++)
+ for (int i = 0; i < argc; i++) {
if (strcmp(argv[i], "--launch-target") == 0) {
target_args_pos = i + 1;
break;
}
- LaunchRunInTerminalTarget(*target_arg, comm_file->getValue(), pid,
- argv + target_args_pos);
+ }
+ if (llvm::Error err =
+ LaunchRunInTerminalTarget(*target_arg, comm_file->getValue(), pid,
+ argv + target_args_pos)) {
+ llvm::errs() << llvm::toString(std::move(err)) << '\n';
+ return EXIT_FAILURE;
+ }
} else {
llvm::errs() << "\"--launch-target\" requires \"--comm-file\" to be "
"specified\n";
|
slackito
approved these changes
Feb 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
ashgti
approved these changes
Feb 26, 2025
joaosaffran
pushed a commit
to joaosaffran/llvm-project
that referenced
this pull request
Mar 3, 2025
…C) (llvm#128951) Return an `llvm::Error` from `LaunchRunInTerminalTarget` instead of calling `exit()` directly.
SquallATF
pushed a commit
to SquallATF/llvm-project
that referenced
this pull request
Mar 8, 2025
…C) (llvm#128951) Return an `llvm::Error` from `LaunchRunInTerminalTarget` instead of calling `exit()` directly.
SquallATF
pushed a commit
to SquallATF/llvm-project
that referenced
this pull request
Mar 20, 2025
…C) (llvm#128951) Return an `llvm::Error` from `LaunchRunInTerminalTarget` instead of calling `exit()` directly.
SquallATF
pushed a commit
to SquallATF/llvm-project
that referenced
this pull request
Apr 2, 2025
…C) (llvm#128951) Return an `llvm::Error` from `LaunchRunInTerminalTarget` instead of calling `exit()` directly.
SquallATF
pushed a commit
to SquallATF/llvm-project
that referenced
this pull request
Apr 17, 2025
…C) (llvm#128951) Return an `llvm::Error` from `LaunchRunInTerminalTarget` instead of calling `exit()` directly.
SquallATF
pushed a commit
to SquallATF/llvm-project
that referenced
this pull request
Apr 30, 2025
…C) (llvm#128951) Return an `llvm::Error` from `LaunchRunInTerminalTarget` instead of calling `exit()` directly.
SquallATF
pushed a commit
to SquallATF/llvm-project
that referenced
this pull request
May 15, 2025
…C) (llvm#128951) Return an `llvm::Error` from `LaunchRunInTerminalTarget` instead of calling `exit()` directly.
SquallATF
pushed a commit
to SquallATF/llvm-project
that referenced
this pull request
May 29, 2025
…C) (llvm#128951) Return an `llvm::Error` from `LaunchRunInTerminalTarget` instead of calling `exit()` directly.
SquallATF
pushed a commit
to SquallATF/llvm-project
that referenced
this pull request
Jun 13, 2025
…C) (llvm#128951) Return an `llvm::Error` from `LaunchRunInTerminalTarget` instead of calling `exit()` directly.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Return an
llvm::Error
fromLaunchRunInTerminalTarget
instead of callingexit()
directly.