Skip to content

Commit

Permalink
Fix parsing of hexadecimal TIDs
Browse files Browse the repository at this point in the history
Issue: #354
  • Loading branch information
mlopatkin committed Jan 3, 2024
1 parent b4b41fb commit 7f60315
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class DelegateLong extends RegexLogcatParserDelegate {
" ",
SEP_OPT, // TODO(mlopatkin): actually, an uid can be there.
// pid:tid, e.g. " 1172: 1172" or "12345:12345"
// tid can be hexadecimal
// see https://android.googlesource.com/platform/system/logging/+/1c3851559e27b532e5c6768cbb79033de24b0d31
PID_REGEX, ":", SEP_OPT, TID_REGEX,
" ",
// priority and left-aligned tag. Tag has to be trimmed before feeding it upstream.
Expand Down Expand Up @@ -203,7 +205,7 @@ private class CurrentMessage {
public CurrentMessage(Matcher matcher) {
timestamp = parseTimestamp(matcher.group(1));
pid = Integer.parseInt(matcher.group(2));
tid = Integer.parseInt(matcher.group(3));
tid = Integer.decode(matcher.group(3));
priority = Priority.fromChar(matcher.group(4));
// TODO(mlopatkin): we probably need to trim tags of other formats.
tag = CharMatcher.whitespace().trimTrailingFrom(matcher.group(5));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract class RegexLogcatParserDelegate implements Closeable {
static final String PID_REGEX = ID_REGEX;
static final String PID_BRACKETS = "\\(\\s*" + PID_REGEX + "\\)";

static final String TID_REGEX = ID_REGEX;
static final String TID_REGEX = "(0x[0-9a-fA-F]+|\\d+)";
static final String TAG_REGEX = "(.*?)";
static final String PRIORITY_REGEX = "([AVDIWEF])";
static final String MESSAGE_REGEX = "(.*)";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ record -> assertThatRecord(record)
.satisfies(r -> assertThatRecord(r).hasMessage(third), atIndex(2));
}


@ParameterizedTest(name = "parses PID {1} and TID {2} out of `{0}`")
@CsvSource({
"' 1234: 4321', 1234, 4321",
Expand All @@ -162,6 +161,7 @@ record -> assertThatRecord(record)
"'654321: 3', 654321, 3",
"' 1:654321', 1, 654321",
"'654321:123456', 654321, 123456",
"' 1165:0x48d', 1165, 1165",
})
void parsesPidAndTid(String pidTid, int expectedPid, int expectedTid) {
assertOnlyParsedRecord(LogcatParsers::logcatLong, lines(String.format("""
Expand Down

0 comments on commit 7f60315

Please sign in to comment.