Skip to content

Commit 17a02a3

Browse files
cferris1000Gerrit Code Review
authored andcommitted
Merge "Clean up logging code."
2 parents fcc16c5 + c637ada commit 17a02a3

File tree

1 file changed

+19
-27
lines changed

1 file changed

+19
-27
lines changed

debuggerd/libdebuggerd/tombstone.cpp

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ static EventTagMap* g_eventTagMap = NULL;
474474

475475
static void dump_log_file(log_t* log, pid_t pid, const char* filename, unsigned int tail) {
476476
bool first = true;
477-
struct logger_list* logger_list;
477+
logger_list* logger_list;
478478

479479
if (!log->should_retrieve_logcat) {
480480
return;
@@ -488,11 +488,9 @@ static void dump_log_file(log_t* log, pid_t pid, const char* filename, unsigned
488488
return;
489489
}
490490

491-
struct log_msg log_entry;
492-
493491
while (true) {
492+
log_msg log_entry;
494493
ssize_t actual = android_logger_list_read(logger_list, &log_entry);
495-
struct logger_entry* entry;
496494

497495
if (actual < 0) {
498496
if (actual == -EINTR) {
@@ -515,8 +513,6 @@ static void dump_log_file(log_t* log, pid_t pid, const char* filename, unsigned
515513
// high-frequency debug diagnostics should just be written to
516514
// the tombstone file.
517515

518-
entry = &log_entry.entry_v1;
519-
520516
if (first) {
521517
_LOG(log, logtype::LOGS, "--------- %slog %s\n",
522518
tail ? "tail end of " : "", filename);
@@ -527,37 +523,32 @@ static void dump_log_file(log_t* log, pid_t pid, const char* filename, unsigned
527523
//
528524
// We want to display it in the same format as "logcat -v threadtime"
529525
// (although in this case the pid is redundant).
530-
static const char* kPrioChars = "!.VDIWEFS";
531-
unsigned hdr_size = log_entry.entry.hdr_size;
532-
if (!hdr_size) {
533-
hdr_size = sizeof(log_entry.entry_v1);
534-
}
535-
if ((hdr_size < sizeof(log_entry.entry_v1)) ||
536-
(hdr_size > sizeof(log_entry.entry))) {
537-
continue;
538-
}
539-
char* msg = reinterpret_cast<char*>(log_entry.buf) + hdr_size;
540-
541526
char timeBuf[32];
542-
time_t sec = static_cast<time_t>(entry->sec);
527+
time_t sec = static_cast<time_t>(log_entry.entry.sec);
543528
struct tm tmBuf;
544529
struct tm* ptm;
545530
ptm = localtime_r(&sec, &tmBuf);
546531
strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", ptm);
547532

548533
if (log_entry.id() == LOG_ID_EVENTS) {
549534
if (!g_eventTagMap) {
550-
g_eventTagMap = android_openEventTagMap(NULL);
535+
g_eventTagMap = android_openEventTagMap(nullptr);
551536
}
552537
AndroidLogEntry e;
553538
char buf[512];
554-
android_log_processBinaryLogBuffer(entry, &e, g_eventTagMap, buf, sizeof(buf));
555-
_LOG(log, logtype::LOGS, "%s.%03d %5d %5d %c %-8.*s: %s\n",
556-
timeBuf, entry->nsec / 1000000, entry->pid, entry->tid,
557-
'I', (int)e.tagLen, e.tag, e.message);
539+
if (android_log_processBinaryLogBuffer(&log_entry.entry_v1, &e, g_eventTagMap, buf,
540+
sizeof(buf)) == 0) {
541+
_LOG(log, logtype::LOGS, "%s.%03d %5d %5d %c %-8.*s: %s\n", timeBuf,
542+
log_entry.entry.nsec / 1000000, log_entry.entry.pid, log_entry.entry.tid, 'I',
543+
(int)e.tagLen, e.tag, e.message);
544+
}
558545
continue;
559546
}
560547

548+
char* msg = log_entry.msg();
549+
if (msg == nullptr) {
550+
continue;
551+
}
561552
unsigned char prio = msg[0];
562553
char* tag = msg + 1;
563554
msg = tag + strlen(tag) + 1;
@@ -568,20 +559,21 @@ static void dump_log_file(log_t* log, pid_t pid, const char* filename, unsigned
568559
*nl-- = '\0';
569560
}
570561

562+
static const char* kPrioChars = "!.VDIWEFS";
571563
char prioChar = (prio < strlen(kPrioChars) ? kPrioChars[prio] : '?');
572564

573565
// Look for line breaks ('\n') and display each text line
574566
// on a separate line, prefixed with the header, like logcat does.
575567
do {
576568
nl = strchr(msg, '\n');
577-
if (nl) {
569+
if (nl != nullptr) {
578570
*nl = '\0';
579571
++nl;
580572
}
581573

582-
_LOG(log, logtype::LOGS, "%s.%03d %5d %5d %c %-8s: %s\n",
583-
timeBuf, entry->nsec / 1000000, entry->pid, entry->tid,
584-
prioChar, tag, msg);
574+
_LOG(log, logtype::LOGS, "%s.%03d %5d %5d %c %-8s: %s\n", timeBuf,
575+
log_entry.entry.nsec / 1000000, log_entry.entry.pid, log_entry.entry.tid, prioChar, tag,
576+
msg);
585577
} while ((msg = nl));
586578
}
587579

0 commit comments

Comments
 (0)