8207832: serviceability/sa/ClhsdbCDSCore.java failed with "Couldn't find core file location"

Handle %p in /proc/sys/kernel/core_pattern

Reviewed-by: dholmes, hseigel
This commit is contained in:
Ioi Lam 2018-08-15 19:22:46 -07:00
parent e12ee81ff0
commit bd57506f87
3 changed files with 16 additions and 2 deletions

View file

@ -5793,11 +5793,21 @@ int os::get_core_path(char* buffer, size_t bufferSize) {
core_pattern[ret] = '\0'; core_pattern[ret] = '\0';
} }
// Replace the %p in the core pattern with the process id. NOTE: we do this
// only if the pattern doesn't start with "|", and we support only one %p in
// the pattern.
char *pid_pos = strstr(core_pattern, "%p"); char *pid_pos = strstr(core_pattern, "%p");
const char* tail = (pid_pos != NULL) ? (pid_pos + 2) : ""; // skip over the "%p"
int written; int written;
if (core_pattern[0] == '/') { if (core_pattern[0] == '/') {
written = jio_snprintf(buffer, bufferSize, "%s", core_pattern); if (pid_pos != NULL) {
*pid_pos = '\0';
written = jio_snprintf(buffer, bufferSize, "%s%d%s", core_pattern,
current_process_id(), tail);
} else {
written = jio_snprintf(buffer, bufferSize, "%s", core_pattern);
}
} else { } else {
char cwd[PATH_MAX]; char cwd[PATH_MAX];
@ -5810,6 +5820,10 @@ int os::get_core_path(char* buffer, size_t bufferSize) {
written = jio_snprintf(buffer, bufferSize, written = jio_snprintf(buffer, bufferSize,
"\"%s\" (or dumping to %s/core.%d)", "\"%s\" (or dumping to %s/core.%d)",
&core_pattern[1], p, current_process_id()); &core_pattern[1], p, current_process_id());
} else if (pid_pos != NULL) {
*pid_pos = '\0';
written = jio_snprintf(buffer, bufferSize, "%s/%s%d%s", p, core_pattern,
current_process_id(), tail);
} else { } else {
written = jio_snprintf(buffer, bufferSize, "%s/%s", p, core_pattern); written = jio_snprintf(buffer, bufferSize, "%s/%s", p, core_pattern);
} }

View file

@ -88,7 +88,6 @@ runtime/SharedArchiveFile/SASymbolTableTest.java 8193639 solaris-all
# :hotspot_serviceability # :hotspot_serviceability
serviceability/sa/ClhsdbAttach.java 8193639 solaris-all serviceability/sa/ClhsdbAttach.java 8193639 solaris-all
serviceability/sa/ClhsdbCDSCore.java 8207832 linux-x64
serviceability/sa/ClhsdbCDSJstackPrintAll.java 8193639 solaris-all serviceability/sa/ClhsdbCDSJstackPrintAll.java 8193639 solaris-all
serviceability/sa/ClhsdbField.java 8193639 solaris-all serviceability/sa/ClhsdbField.java 8193639 solaris-all
serviceability/sa/ClhsdbFindPC.java 8193639 solaris-all serviceability/sa/ClhsdbFindPC.java 8193639 solaris-all

View file

@ -201,6 +201,7 @@ public class ClhsdbCDSCore {
.get(); .get();
stringWithLocation = stringWithLocation.substring(stringWithLocation stringWithLocation = stringWithLocation.substring(stringWithLocation
.indexOf(LOCATIONS_STRING) + LOCATIONS_STRING.length()); .indexOf(LOCATIONS_STRING) + LOCATIONS_STRING.length());
System.out.println("getCoreFileLocation found stringWithLocation = " + stringWithLocation);
String coreWithPid; String coreWithPid;
if (stringWithLocation.contains("or ")) { if (stringWithLocation.contains("or ")) {
Matcher m = Pattern.compile("or.* ([^ ]+[^\\)])\\)?").matcher(stringWithLocation); Matcher m = Pattern.compile("or.* ([^ ]+[^\\)])\\)?").matcher(stringWithLocation);