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. OnTouchListener does not receive all MotionEvents in MapActivity

Within a MapActivity on an Eclair test phone, I have installed an
OnTouchListener to only listen for screen taps.  If I just tap the
screen it receives events OK.  I can keep doing this indefinitely, and
it works OK.  I am not interested in anything fancy.  I don't care
about move events or guessture detection, just taps.  However, after I
perform a multi-touch activity to expand or contract the map view, the
OnTouchListener no longer receives any callbacks whatsoever.  The
multi-touch continues to work, but I no longer receive *any* event
callbacks in the OnTouchListener.  The essential parts of my code are

private class MyTouchListener implements View.OnTouchListener {
    public boolean onTouch(View view, MotionEvent event) {

        int action = event.getAction();
        if (action == MotionEvent.ACTION_DOWN) {
                mPosX = event.getX();
                mPosY = event.getY();
                processEvent(mPosX, mPosY);
                return true;
        return false;

   public void onCreate(Bundle savedInstanceState) {


        MapView myMapView = (MapView) findViewById(R.id.mapview);
        TouchListener mTouchListener = new TouchListener();
        // other stuff here

Within mapview.xml, I have the following


Does anyone know how to fix this so that my OnTouchListener can
integrate cohesively with the default multi-touch activity code inside
of the MapActivity class?  What do I need to do so that my
OnTouchListener receives callbacks after multi-touch activity?


2. Clicking Rotated ListView gives wrong/original coordinates

I have a ListView that can have one or more clickable items. When I
apply a rotate animation the coordinates that are clicked correspond
to the original position of the ListView items. For example a list
with one item in portrait mode rotated 180 degrees will have the item
upside down on the bottom of the screen, but the item gets the click
event when I click the top of the screen. 180 degrees is just an
example I want to be able to move an arbitrary angle. I've looked
through all the listView properties but none seem to have any effect
on the clickable coordinates. I would assume
willChangeTransformationMatrix would do the trick but it doesn't,
neither does invalidate or invalidateViews.

Is there a property I'm overlooking or how would I go about moving the
coordinates to the right place (clicking the item from the rotated
position not the original)?

Alternatively is there a way to rotate the listView without animation
and achieve the effect I'm expecting?


sample code- list items highlight correctly when clicked, rotate with
dpad_center, after rotated items highlight when original position is
clicked. I've tried animating the animation, animationSet, and
layoutAnimationController all same result.

import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.LayoutAnimationController;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;

public class ToDoList extends Activity {
   ListView myListView;
  /** Called when the activity is first created. */
  public void onCreate(Bundle savedInstanceState) {
    final ListView myListView = new ListView(this);

    final ArrayList<String> todoItems = new ArrayList<String>();
    todoItems.add(0, "asdf");
    todoItems.add(0, "1234");

    // Create the array adapter to bind the array to the listview
    final ArrayAdapter<String> aa;
    aa = new

    // Bind the array adapter to the listview.
    myListView.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
          if (event.getAction() == KeyEvent.ACTION_DOWN)
            if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER)
              RotateAnimation  ranim = new RotateAnimation(0f, 180f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
             ranim.setInterpolator(new LinearInterpolator());
             AnimationSet set = new AnimationSet(true);
             set.setInterpolator(new LinearInterpolator());
             LayoutAnimationController controller = new
LayoutAnimationController(set, 0.5f);
              controller.setInterpolator(new LinearInterpolator());
              return true;
          return false;


3. WebView in tabHost

4. How to trigger onTouch/onKeyPress event for '+' (plus) symbol

5. Problem styleable custom attributes on custom view

6. editText not updated

7. Problem with Audio Record and Audio Track