Unexpected extra byte occurring in binary logcat entry stream

by Hal » Tue, 23 Nov 2010 14:53:24 GMT

Sponsored Links
 I've been implementing a logcat reader in java which uses the binary
output of logcat (-B switch) rather than the text based formats. My
code works for many of the entries, but frequently the binary log
entries have an extra byte inserted which I can't account for, making
the payload the wrong size.

program itself and the logging apis, the binary format seems to be:

Header (20 bytes total):
[payloadlength]  2 bytes
[unused padding] 2 bytes
[PID]            4 bytes
[Thread ID]      4 bytes
[time seconds]   4 bytes
[time nanosecs]  4 bytes
[payload]        payloadlength bytes

Payload section of the header is (payloadlength bytes total):
[log priority]            1 byte
[null terminated tag]     unknown length, < payloadlength
[null terminated log msg] unknown length, < payloadlength

This file defines the struct: 
 http://www.google.com/codesearch/p?hl=en #2wSbThBwwIw/include/cutils/logger.h&l=15

The extra byte I'm seeing occours after the nanosecond timestamp and
before the log priority of the payload. e.g. Here is a hex dump of one
of the log entries with the phantom byte:

The byte (in this instance) is 0x1D at offset 0x14
0000:0000 | 2E 00 0D 0A  C0 7C 00 00  00 9A 00 00  00 EC BA E5  4C
| ....|.......L
0000:0011 | EB E8 AA 1D  03 4B 65 79  67 75 61 72  64 56 69 65  77 |
0000:0022 | 4D 65 64 69  61 74 6F 72  00 68 61 6E  64 6C 65 57  61 |
0000:0033 | 6B 65 57 68  65 6E 52 65  61 64 79 28  32 36 29 00     |

The extra byte shifts the payload by 1, so the payload length becomes
incorrect. I can't see where this byte is coming from.

I also tried the LogReceiver class in ddmlib, but that also fails to
handle extra byte and produces garbage after it hits an entry with the
extra byte:
 http://www.google.com/codesearch/p?hl=en #cZwlSNS7aEw/sdk/ddms/libs/ddmlib/src/com/android/ddmlib/log/LogReceiver.java&sa=N&cd=2&ct=rc

Here is a quick python script which demonstrates the problem. It reads
and prints binary log entries in the expected format. It will raise an
exception when it encounters an entry with an unexpected byte:

The logcat program itself successfully reinterprets the binary format
without jumping through any hoops, so I can only guess it's some kind
of struct alignment artifact. Anyone encountered this or got any idea
why the extra byte is appearing?


Re: Unexpected extra byte occurring in binary logcat entry stream

by fadden » Wed, 24 Nov 2010 08:54:15 GMT



I noticed that you have 0D 0A, suggesting that something is doing a
text conversion (CR or LF --> CRLF).


Sponsored Links

Other Threads

1. Problems with Android Calendar functions


i need a calendar function in my app, but i have problems to
determinate the day of the week from the chosen Date. I tried much and
it seems like a bug to me. Here's the code:

TimeZone zone = TimeZone.getDefault();
GregorianCalendar calendar = new GregorianCalendar(zone);

calendar.set( 2009 , 6 , 1);

                if( calendar.get(Calendar.DAY_OF_WEEK) == calendar.get
(Calendar.MONDAY) ){
                } else if (calendar.get(Calendar.DAY_OF_WEEK) == calendar.get
(Calendar.TUESDAY) ){
                } else if (calendar.get(Calendar.DAY_OF_WEEK) == calendar.get
(Calendar.WEDNESDAY) ){
                } else if (calendar.get(Calendar.DAY_OF_WEEK) == calendar.get
(Calendar.THURSDAY) ){
                } else if (calendar.get(Calendar.DAY_OF_WEEK) == calendar.get
(Calendar.FRIDAY) ){
                } else if (calendar.get(Calendar.DAY_OF_WEEK) == calendar.get
(Calendar.SATURDAY) ){
                } else if (calendar.get(Calendar.DAY_OF_WEEK) == calendar.get
(Calendar.SUNDAY) ){

It prints Saturday, actually June the first is a Monday.

I tried other values:
calendar.set( 2009 , 7 , 1); prints Monday, but is actually a
calendar.set( 2009 , 8 , 1); -> Saturday, correct
calendar.set( 2009 , 9 , 1); -> Saturday, should be tuesday
calendar.set( 2009 , 10 , 1); -> Wednesday , should be a Thursday

Does anyone know what's wrong here? Thanks in advance

Regards, Pascal

2. long duration a/v sync in opencore

Hi all & esp. PV engineers,
I am working on a hard bug found during long duration video playback by
OpenCORE v1.0 and it hangs mediaserver.

I find an extremely old email talking about bugs related to long duration
avsync playback of opencore by Dave Sparks. It seems to be about OpenCORE
v1.0. I'd like to know the details about this bug, e.g. description and root
cause and workarounds? Thanks.

Please refer to the following statements by Dave Sparks. Thanks.


3. animations constrained by transformations?

4. Preferred method of copying arrays

5. YouTube app Intent and Extras

6. Create custom mime type handler

7. Slow to load emulator with eclipse