Skip to content

Commit b2d1752

Browse files
committed
chore: rework regex
1 parent 642f101 commit b2d1752

1 file changed

Lines changed: 9 additions & 20 deletions

File tree

dd-java-agent/agent-crashtracking/src/main/java/datadog/crashtracking/parsers/HotspotCrashLogParser.java

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ public HotspotCrashLogParser() {
6060
private static final Pattern SPACE_SPLITTER = Pattern.compile("\\s+");
6161
private static final Pattern NEWLINE_SPLITTER = Pattern.compile("\n");
6262
private static final Pattern SIGNAL_PARSER = Pattern.compile("\\s*(\\w+) \\((\\w+)\\).*");
63+
// Groups: 1=si_signo, 2=signal name, 3=si_code, 4=si_code name,
64+
// 5=si_addr (null for SI_USER), 6=si_pid (null for si_addr), 7=si_uid (null for si_addr)
6365
private static final Pattern SIGINFO_PARSER =
6466
Pattern.compile(
65-
"siginfo:\\s+si_signo:\\s+(\\d+)\\s+\\((\\w+)\\),\\s+si_code:\\s+(\\d+)\\s+\\(([^)]+)\\),\\s+si_addr:\\s+(0x[0-9a-fA-F]+)");
66-
private static final Pattern SIGINFO_SI_USER_PARSER =
67-
Pattern.compile(
68-
"siginfo:\\s+si_signo:\\s+(\\d+)\\s+\\((\\w+)\\),\\s+si_code:\\s+(\\d+)\\s+\\(([^)]+)\\),\\s+si_pid:\\s+(\\d+),\\s+si_uid:\\s+(\\d+)");
67+
"siginfo:\\s+si_signo:\\s+(\\d+)\\s+\\((\\w+)\\),\\s+si_code:\\s+(\\d+)\\s+\\(([^)]+)\\),\\s+"
68+
+ "(?:si_addr:\\s+(0x[0-9a-fA-F]+)|si_pid:\\s+(\\d+),\\s+si_uid:\\s+(\\d+))");
6969
private static final Pattern DYNAMIC_LIBS_PATH_PARSER =
7070
Pattern.compile("^(?:0x)?[0-9a-fA-F]+(?:-[0-9a-fA-F]+)?\\s+(?:[^\\s/\\[]+\\s+)*(.*)$");
7171

@@ -278,29 +278,18 @@ public CrashLog parse(String uuid, String crashLog) {
278278
break;
279279
case STACKTRACE:
280280
if (line.startsWith("siginfo:")) {
281-
// siginfo: si_signo: 11 (SIGSEGV), si_code: 1 (SEGV_MAPERR), si_addr:
282-
// 0x0000000000000070
281+
// siginfo: si_signo: 11 (SIGSEGV), si_code: 1 (SEGV_MAPERR), si_addr: 0x70
282+
// siginfo: si_signo: 11 (SIGSEGV), si_code: 0 (SI_USER), si_pid: 554848, si_uid: 1000
283283
final Matcher siginfoMatcher = SIGINFO_PARSER.matcher(line);
284284
if (siginfoMatcher.matches()) {
285285
Integer number = safelyParseInt(siginfoMatcher.group(1));
286286
String name = siginfoMatcher.group(2);
287287
Integer siCode = safelyParseInt(siginfoMatcher.group(3));
288288
String sigAction = siginfoMatcher.group(4);
289289
String address = siginfoMatcher.group(5);
290-
sigInfo = new SigInfo(number, name, siCode, sigAction, address, null, null);
291-
} else {
292-
// siginfo: si_signo: 11 (SIGSEGV), si_code: 0 (SI_USER), si_pid: 554848, si_uid:
293-
// 1000
294-
final Matcher siUserMatcher = SIGINFO_SI_USER_PARSER.matcher(line);
295-
if (siUserMatcher.matches()) {
296-
Integer number = safelyParseInt(siUserMatcher.group(1));
297-
String name = siUserMatcher.group(2);
298-
Integer siCode = safelyParseInt(siUserMatcher.group(3));
299-
String sigAction = siUserMatcher.group(4);
300-
Integer siPid = safelyParseInt(siUserMatcher.group(5));
301-
Integer siUid = safelyParseInt(siUserMatcher.group(6));
302-
sigInfo = new SigInfo(number, name, siCode, sigAction, null, siPid, siUid);
303-
}
290+
Integer siPid = safelyParseInt(siginfoMatcher.group(6));
291+
Integer siUid = safelyParseInt(siginfoMatcher.group(7));
292+
sigInfo = new SigInfo(number, name, siCode, sigAction, address, siPid, siUid);
304293
}
305294
} else if (line.contains("P R O C E S S")) {
306295
state = State.SEEK_DYNAMIC_LIBRARIES;

0 commit comments

Comments
 (0)