From c03572215c8b518eb5e05dc2638f320260445f98 Mon Sep 17 00:00:00 2001 From: Barbara Rosiak Date: Wed, 14 Jan 2026 11:35:28 -0800 Subject: [PATCH 1/4] Fix truncated exe file name in mini dump name --- .../debug/createdump/crashinfounix.cpp | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/coreclr/debug/createdump/crashinfounix.cpp b/src/coreclr/debug/createdump/crashinfounix.cpp index b0bcb0b8c2d3b8..7c95a156eaca2e 100644 --- a/src/coreclr/debug/createdump/crashinfounix.cpp +++ b/src/coreclr/debug/createdump/crashinfounix.cpp @@ -585,6 +585,33 @@ GetStatus(pid_t pid, pid_t* ppid, pid_t* tgid, std::string* name) { if (name != nullptr) { + // Try reading the executable name from the /proc//exe link. + char exePath[128]; + int chars = snprintf(exePath, sizeof(exePath), "/proc/%d/exe", pid); + if (chars > 0 && (size_t)chars < sizeof(exePath)) + { + struct stat sb; + if (lstat(exePath, &sb) != -1) + { + ssize_t bufSize = sb.st_size == 0 ? 4096 : sb.st_size + 1; + char *buf = (char*) malloc(bufSize); + if (buf != NULL) + { + ssize_t nbytes = readlink(exePath, buf, bufSize); + if (nbytes != -1) + { + buf[nbytes] = '\0'; + char* executableName = strrchr(buf, '/'); + *name = strdup((executableName != nullptr) ? (executableName + 1) : buf); + free(buf); + continue; + } + free(buf); + } + } + } + + // Failed to read the executable name from the link, fallback to name from status. char* n = strchr(line + 6, '\n'); if (n != nullptr) { From 04aa5380af62a52c4d46d07da82ab2b3a65758c3 Mon Sep 17 00:00:00 2001 From: Barbara Rosiak Date: Mon, 19 Jan 2026 16:53:07 -0800 Subject: [PATCH 2/4] Apply pr suggestions --- src/coreclr/debug/createdump/crashinfounix.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/coreclr/debug/createdump/crashinfounix.cpp b/src/coreclr/debug/createdump/crashinfounix.cpp index 7c95a156eaca2e..457bcf5f9b7ae0 100644 --- a/src/coreclr/debug/createdump/crashinfounix.cpp +++ b/src/coreclr/debug/createdump/crashinfounix.cpp @@ -591,18 +591,18 @@ GetStatus(pid_t pid, pid_t* ppid, pid_t* tgid, std::string* name) if (chars > 0 && (size_t)chars < sizeof(exePath)) { struct stat sb; - if (lstat(exePath, &sb) != -1) + if (lstat(exePath, &sb) != -1) { ssize_t bufSize = sb.st_size == 0 ? 4096 : sb.st_size + 1; - char *buf = (char*) malloc(bufSize); - if (buf != NULL) + char *buf = static_cast(malloc(bufSize)); + if (buf != nullptr) { - ssize_t nbytes = readlink(exePath, buf, bufSize); - if (nbytes != -1) + ssize_t nbytes = readlink(exePath, buf, bufSize - 1); + if (nbytes != -1) { - buf[nbytes] = '\0'; + buf[nbytes] = '\0'; char* executableName = strrchr(buf, '/'); - *name = strdup((executableName != nullptr) ? (executableName + 1) : buf); + *name = (executableName != nullptr) ? (executableName + 1) : buf; free(buf); continue; } @@ -610,7 +610,7 @@ GetStatus(pid_t pid, pid_t* ppid, pid_t* tgid, std::string* name) } } } - + // Failed to read the executable name from the link, fallback to name from status. char* n = strchr(line + 6, '\n'); if (n != nullptr) From e8e4c251a458dc538b04f7c7319d7e51cc0073eb Mon Sep 17 00:00:00 2001 From: Barbara Rosiak Date: Tue, 20 Jan 2026 11:43:55 -0800 Subject: [PATCH 3/4] Refactor method --- .../debug/createdump/crashinfounix.cpp | 69 +++++++++++-------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/src/coreclr/debug/createdump/crashinfounix.cpp b/src/coreclr/debug/createdump/crashinfounix.cpp index 457bcf5f9b7ae0..812b3c45e302fa 100644 --- a/src/coreclr/debug/createdump/crashinfounix.cpp +++ b/src/coreclr/debug/createdump/crashinfounix.cpp @@ -12,7 +12,7 @@ extern uint8_t g_debugHeaderCookie[4]; int g_readProcessMemoryErrno = 0; -bool GetStatus(pid_t pid, pid_t* ppid, pid_t* tgid, std::string* name); +bool GetProcessInfo(pid_t pid, pid_t* ppid, pid_t* tgid, std::string* name); bool CrashInfo::Initialize() @@ -65,8 +65,7 @@ CrashInfo::Initialize() m_fdPagemap = -1; } - // Get the process info - if (!GetStatus(m_pid, &m_ppid, &m_tgid, &m_name)) + if (!GetProcessInfo(m_pid, &m_ppid, &m_tgid, &m_name)) { return false; } @@ -585,33 +584,6 @@ GetStatus(pid_t pid, pid_t* ppid, pid_t* tgid, std::string* name) { if (name != nullptr) { - // Try reading the executable name from the /proc//exe link. - char exePath[128]; - int chars = snprintf(exePath, sizeof(exePath), "/proc/%d/exe", pid); - if (chars > 0 && (size_t)chars < sizeof(exePath)) - { - struct stat sb; - if (lstat(exePath, &sb) != -1) - { - ssize_t bufSize = sb.st_size == 0 ? 4096 : sb.st_size + 1; - char *buf = static_cast(malloc(bufSize)); - if (buf != nullptr) - { - ssize_t nbytes = readlink(exePath, buf, bufSize - 1); - if (nbytes != -1) - { - buf[nbytes] = '\0'; - char* executableName = strrchr(buf, '/'); - *name = (executableName != nullptr) ? (executableName + 1) : buf; - free(buf); - continue; - } - free(buf); - } - } - } - - // Failed to read the executable name from the link, fallback to name from status. char* n = strchr(line + 6, '\n'); if (n != nullptr) { @@ -627,6 +599,43 @@ GetStatus(pid_t pid, pid_t* ppid, pid_t* tgid, std::string* name) return true; } +bool +GetProcessInfo(pid_t pid, pid_t* ppid, pid_t* tgid, std::string* name) +{ + if(!GetStatus(pid, ppid, tgid, name)) + { + return false; + } + + // Try reading the executable name from the /proc//exe link. Prefer this name to the + // one reported by status if it is available because the status name is often truncated + // Try reading the executable name from the /proc//exe link. + char exePath[128]; + int chars = snprintf(exePath, sizeof(exePath), "/proc/%d/exe", pid); + if (chars > 0 && (size_t)chars < sizeof(exePath)) + { + struct stat sb; + if (lstat(exePath, &sb) != -1) + { + ssize_t bufSize = sb.st_size == 0 ? 4096 : sb.st_size + 1; + char *buf = static_cast(malloc(bufSize)); + if (buf != nullptr) + { + ssize_t nbytes = readlink(exePath, buf, bufSize - 1); + if (nbytes != -1) + { + buf[nbytes] = '\0'; + char* executableName = strrchr(buf, '/'); + *name = (executableName != nullptr) ? (executableName + 1) : buf; + } + free(buf); + } + } + } + + return true; +} + void ModuleInfo::LoadModule() { From cf29435edc5aa93d3e63da2f26a915acf0fc7815 Mon Sep 17 00:00:00 2001 From: Barbara Rosiak <76071368+barosiak@users.noreply.github.com> Date: Tue, 20 Jan 2026 13:05:58 -0800 Subject: [PATCH 4/4] Remove repeating comment Co-authored-by: Noah Falk --- src/coreclr/debug/createdump/crashinfounix.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/coreclr/debug/createdump/crashinfounix.cpp b/src/coreclr/debug/createdump/crashinfounix.cpp index 812b3c45e302fa..e4ac6bcd55905e 100644 --- a/src/coreclr/debug/createdump/crashinfounix.cpp +++ b/src/coreclr/debug/createdump/crashinfounix.cpp @@ -609,7 +609,6 @@ GetProcessInfo(pid_t pid, pid_t* ppid, pid_t* tgid, std::string* name) // Try reading the executable name from the /proc//exe link. Prefer this name to the // one reported by status if it is available because the status name is often truncated - // Try reading the executable name from the /proc//exe link. char exePath[128]; int chars = snprintf(exePath, sizeof(exePath), "/proc/%d/exe", pid); if (chars > 0 && (size_t)chars < sizeof(exePath))