Skip to content

[libc] Add line numbers to libc utility error messages #94010

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
merged 1 commit into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions libc/utils/gpu/loader/Loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

#include "utils/gpu/server/llvmlibc_rpc_server.h"

#include "llvm-libc-types/rpc_opcodes_t.h"
#include "include/llvm-libc-types/test_rpc_opcodes_t.h"
#include "llvm-libc-types/rpc_opcodes_t.h"

#include <cstddef>
#include <cstdint>
Expand Down Expand Up @@ -98,14 +98,17 @@ void *copy_environment(char **envp, Allocator alloc) {
return copy_argument_vector(envc, envp, alloc);
}

inline void handle_error(const char *msg) {
fprintf(stderr, "%s\n", msg);
inline void handle_error_impl(const char *file, int32_t line, const char *msg) {
fprintf(stderr, "%s:%d:0: Error: %s\n", file, line, msg);
exit(EXIT_FAILURE);
}

inline void handle_error(rpc_status_t) {
handle_error("Failure in the RPC server\n");
inline void handle_error_impl(const char *file, int32_t line,
rpc_status_t err) {
fprintf(stderr, "%s:%d:0: Error: %d\n", file, line, err);
exit(EXIT_FAILURE);
}
#define handle_error(X) handle_error_impl(__FILE__, __LINE__, X)

template <uint32_t lane_size>
inline void register_rpc_callbacks(rpc_device_t device) {
Expand Down
5 changes: 3 additions & 2 deletions libc/utils/gpu/loader/amdgpu/Loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ struct implicit_args_t {
};

/// Print the error code and exit if \p code indicates an error.
static void handle_error(hsa_status_t code) {
static void handle_error_impl(const char *file, int32_t line,
hsa_status_t code) {
if (code == HSA_STATUS_SUCCESS || code == HSA_STATUS_INFO_BREAK)
return;

const char *desc;
if (hsa_status_string(code, &desc) != HSA_STATUS_SUCCESS)
desc = "Unknown error";
fprintf(stderr, "%s\n", desc);
fprintf(stderr, "%s:%d:0: Error: %s\n", file, line, desc);
exit(EXIT_FAILURE);
}

Expand Down
6 changes: 3 additions & 3 deletions libc/utils/gpu/loader/nvptx/Loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@
using namespace llvm;
using namespace object;

static void handle_error(CUresult err) {
static void handle_error_impl(const char *file, int32_t line, CUresult err) {
if (err == CUDA_SUCCESS)
return;

const char *err_str = nullptr;
CUresult result = cuGetErrorString(err, &err_str);
if (result != CUDA_SUCCESS)
fprintf(stderr, "Unknown Error\n");
fprintf(stderr, "%s:%d:0: Unknown Error\n", file, line);
else
fprintf(stderr, "%s\n", err_str);
fprintf(stderr, "%s:%d:0: Error: %s\n", file, line, err_str);
exit(1);
}

Expand Down
Loading