Skip to content

[LLVM][Support] check for error return from dladdr. #138369

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 7, 2025
Merged
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
34 changes: 21 additions & 13 deletions llvm/lib/Support/Unix/Signals.inc
Original file line number Diff line number Diff line change
Expand Up @@ -826,30 +826,38 @@ void llvm::sys::PrintStackTrace(raw_ostream &OS, int Depth) {
int width = 0;
for (int i = 0; i < depth; ++i) {
Dl_info dlinfo;
dladdr(StackTrace[i], &dlinfo);
const char *name = strrchr(dlinfo.dli_fname, '/');

int nwidth;
if (!name)
nwidth = strlen(dlinfo.dli_fname);
else
nwidth = strlen(name) - 1;
if (dladdr(StackTrace[i], &dlinfo) == 0) {
nwidth = 7; // "(error)"
} else {
const char *name = strrchr(dlinfo.dli_fname, '/');

if (!name)
nwidth = strlen(dlinfo.dli_fname);
else
nwidth = strlen(name) - 1;
}

if (nwidth > width)
width = nwidth;
}

for (int i = 0; i < depth; ++i) {
Dl_info dlinfo;
dladdr(StackTrace[i], &dlinfo);

OS << format("%-2d", i);

const char *name = strrchr(dlinfo.dli_fname, '/');
if (!name)
OS << format(" %-*s", width, static_cast<const char *>(dlinfo.dli_fname));
else
OS << format(" %-*s", width, name + 1);
if (dladdr(StackTrace[i], &dlinfo) == 0) {
OS << format(" %-*s", width, static_cast<const char *>("(error)"));
dlinfo.dli_sname = nullptr;
} else {
const char *name = strrchr(dlinfo.dli_fname, '/');
if (!name)
OS << format(" %-*s", width,
static_cast<const char *>(dlinfo.dli_fname));
else
OS << format(" %-*s", width, name + 1);
}

OS << format(" %#0*lx", (int)(sizeof(void *) * 2) + 2,
(unsigned long)StackTrace[i]);
Expand Down