Home » Hacking » How to get and read a logcat/ Troubleshoot your own issues!

How to get and read a logcat/ Troubleshoot your own issues!

How to get and read a logcat/ Troubleshoot your own issues!

How to get and read a logcat/ Troubleshoot your own issues!

How to get & read a logcat/ Troubleshoot your own issues!

PLEASE USE THIS THREAD AS INTENDED, AS A STARTING POINT IN LEARNING TO READ THESE LOGS AND DIAGNOSE PROBLEMS YOURSELF. THANK YOU!

How to get and read a logcat/ Troubleshoot your own issues!
The Basics

I’m starting this thread in hopes of sharing some very useful information to all our new members and hopefully either teaching something new or being a good refresher for our experienced members. I’ve been asked before how to tell what errors are present in logcats, how I can understand all that mess, etc…

Well, I’m going to try my best to explain all of it. In this way, you can get your own logs and try to fix the problems, or know exactly what is causing your problems to help out the developers so they aren’t looking through thousands of lines of code for each persons issue.

Help us help you!

To begin with, we’ll need to have some understanding of adb.

Setting up JDK and SDK for ADB use.

Whats is ADB?

Quote:

ADB or ANDROID DEBUG BRIDGE is a command-line utility that is often used to communicate over the debug channel with a connected phone or virtual device (emulator). ADB can control your device over USB from a computer, copy files back and forth, install and uninstall apps and more…

How to get & read a logcat/ Troubleshoot your own issues!

What is needed

Quote:

Windows PC (using Win7 64bit as example)
Java JDK HERE
Android SDK HERE
Android device

**Setup for Java JDK**
Download the Windows x86 or x64 .exe from HERE . Run the exe and let it install to default location

How to get and read a logcat/ Troubleshoot your own issues!

 

**Error that SDK does not see Java installed**

 

Code:
I and many others have had to create a Enviroment Variable so the Android SDK will see the Java JDK.
After java has installed
Click start menu
Right click computer
Select properties
Top left at the bottom of the list is Advanced System Settings, select that
System properties will open and bottom right will be a Enviroment Variables button, select that
A popup will apper (Enviroment Variables)
Select New System variables (bottom section)
Variable name will be JAVA_HOME, case sensitive
Variable value will be C:\Program Files\Java\jre7
Select OK
Select OK again and it will close Environment Variables window
Now in the System Properties window, if the apply button on bottom right is not clickable, we need to make it clickable
So what I do is make a small change to the computer name tab, I just delete one letter from the name and the type the 
same letter (you do not actually need to change the name) and the apply button is now clickable, do so.
Now you might want to reboot your PC
Now that's set for when you go to install SDK it will see Java.

 

**Now to install Android SDK**


Download the SDK from HERE. Towards the bottom of the page is “Download other platforms”, select that. Scroll to “SDK Tools Only” section and in the Windows section select the installer.exe. Now you double click and run the installer

How to get and read a logcat/ Troubleshoot your own issues!

 

**Setup Android SDK**

 

Code:
Open this file path C:\Program files (x86)\Android\android-sdk and double click SDK Manager
It will open, top left is a Tools folder which has "Android SDK Tools" and "Android SDk Platform-tools" in it, check mark all 3 boxes
Bottom right is Install packages button, click it and accept liscences
Now you can navigate to the platform-tools folder and you will see adb now
Make sure you have you device drivers installed which I hope you would have already
Open settings on your device, scroll to Developer options and enable USB debugging
Plug device into PC and let drivers update/install
Now in the window where adb is, press shift+right click and select "Open command window here"
Type adb devices, if you have a device connected and it does not return a device, you need to install again.
If it does return a device you now can use adb for a veritey of functions, some of which I will cover.
**DISCLAIMER** I accept no responsibility if you brick, blow up or burn up your device, you are choosing to follow this and making your own decision**

How to get and read a logcat/ Troubleshoot your own issues!

Quote:

I have been a long time android user and forum user. The goal here is to create a simple How-To guide for some of you new to android or just new to flashing. This stems from myself being on these forums and helping users fix and troubleshoot things. My goal is to give you some basics to help with testing or troubleshooting and to teach you a thing or two. There will be several sections and updates along the way. The Note 2 will be used as the device, but these can be done on most other devices as well.

How to get and read a logcat/ Troubleshoot your own issues!

 

**Easy ADB**

Why not

make a simple way to get a ADB log when trouble shooting, instead 
of using an app from the market. Plus it will pull a log upon boot, ever 
had it where your testing something and it wont boot and the Developer 
wants you to get a log, but you either don't have ADB or know how to 
use ADB. This is for you!! Thanks goes to Kenny Glass, CNexus for the 
idea and Gruesomewolf for the bat file edit.

What you need
Windows PC
Android device
Easy ADB.zip attached to this post

Whats included
Your basic ADB parts to be able to run without needing the SDK installed
LOG.bat file
Reboot.bat (Reboots device)
Recovery.bat (Sends device to recovery)
Download mode.bat (Sends device to download mode (ODIN mode))

How to record log cat using LOG.bat
You will download the zip
Extract to your desktop for easy access
Plug your device in to your PC
Open the ADB folder
Right click the LOG bat file, select run as admin (might not need to)
It will open a command window
Select ANY key to continue or control-c to quit
Wait for it to return to press any key to continue
Now you will have a text file called LOG, that is you LOG cat using ADB
You are now done and can send it to whomever or read it over yourself.

How to get and read a logcat/ Troubleshoot your own issues!

 

**Pushing system apps (Root Needed) (Will be posting screencasts of this also)**

How to get & read a logcat/ Troubleshoot your own issues!

Quote:

Have you come across someone posting something or telling you to push this app? I know I push them all the time. This can be used for MORE than just apps!! You can push just about everything. This will cover pushing a system app to the /system/app folder AND pushing a framework.jar to /system/framework folder. I will cover this using Root Explorer (paid) and ES File (free)

Code:
What you need
Android device
A file explorer with root access (Root Explorer, ES File or any others)
Whatever file, apk or etc you need to install

How to push a system app
Download Root Explorer or ES File from the store

(Root Explorer Instructions)
Open Root Explorer
Grant SU permissions
Navigate to the app you are going to be pushing (click + at bottom of screen to add EXT SD card tab)
Long press apk
Select copy
Top left tab says root, click and scroll to system folder, click and then click app folder
Bottom of screen says copy here, select that
Now scroll to the apk you just copied there and long press it
Select permissions, change them to only having the first vertical row and top of middle row checked (Attached Screenshot)
Click OK
Press home button
Now reboot to recovery and wipe cache and dalvik cache, then reboot.

(ES File Instructions)
Open ES File
Top left is a device/globe icon
Select tools, root explorer, Mount R/W
Grant SU permissions
Click device/globe
Select Local and then the SD card where the apk your wanting to install is located
Go to the folder when the apk is
Long press it and select copy
Now press the device/globe again and select local and then device
Scroll to system folder, click it
Now click app folder
Bottom of the screen, select paste
Scroll to the apk you just copied and long press it
Bottom right is more, select that then properties
Now you will change permissions to first vertical row and top middle checked only (attached Screenshot)
Click OK
Press home button
Now reboot to recovery and wipe cache and dalvik cache, then reboot.

How to get & read a logcat/ Troubleshoot your own issues!

Code:
Pushing System framework and other system files (Root Needed)
[Notice you will move to system folder and change permissions there, So if the device reboots or things lockup, you have already changed permissions and can just go to recovery and do your wipes]

(Root Explorer Instructions)
Open Root Explorer
Grant SU permissions
Navigate to the file you are going to be pushing (click + at bottom of screen to add EXT SD card tab)
Long press the file name
Select copy
Top left tab says root, click and scroll to system folder
Bottom of screen says copy here, select that (Place file here fist so you can change permissions now)
Now scroll to the file you just copied there and long press it
Select permissions, change them to only having the first vertical row and top of middle row checked (Attached Screenshot) (or if there is different permissions change accordingly)
Click OK
Scroll to the file you installing
Long press and select MOVE
Now open the folder or folders the file belongs in (framework for framework.jar for example)
Bottom left click move here
Press home button
Now reboot to recovery and wipe cache and dalvik cache, then reboot.

(ES File instructions)
Open ES File
Top left is a device/globe icon
Select tools, root explorer, Mount R/W
Grant SU permissions
Click device/globe
Select Local and then the SD card where the file your wanting to install is located
Go to the folder where the file is
Long press it and select copy
Now press the device/globe again and select local and then device
Scroll to system folder, click it
Bottom of the screen select paste
Scroll to the file you just copied and long press it
Bottom right is more, select that then properties
Now you will change permissions to first vertical row and top middle checked only (attached Screenshot)(or if there is different permissions change accordingly)
Click OK
Scroll to the file your installing
Long press it and select cut
Now open the folder or folders the file belongs in (framework for framework.jar for example)
Bottom of the screen select paste
Press home button
Now reboot to recovery and wipe cache and dalvik cache, then reboot.
Logcats

How to get and read a logcat/ Troubleshoot your own issues!

 First, we'll need to know how to get a logcat. With the plethora of new users this has been the subject of many, many discussions. When asked to get a logcat, they don't know how.


Tools and Requirements
 First of all, you'll absolutely NEED to have usb debugging enabled. To do this go to SETTINGS, navigate down to DEVELOPER OPTIONS and select it, if they are not on use the toggle in the top right corner and select USB DEBUGGING ( See attached screen shots )

 Secondly, you'll absolutely NEED to have the ANDROID SDK grab it here
 Install the SDK on the root of your computer. DO NOT change the SDK name to include any spaces as it will fail!

 Also be sure to grab your device specific drivers, if they aren't already installed. Some devices will install them automatically, while others require a simple google search.

 Now that you've got everything you need, lets grab a logcat!

How to get a Logcat

Windows

Navigate to where you've installed the sdk. Once you've gotten into the sdk, you're going to look for "PLATFORM TOOLS" folder, inside hold shift + right click on any empty space, select "OPEN COMMAND WINDOW HERE"
 Connect your phone to your PC via usb cable, in the command window type "adb devices" without the quotes. If you've set everything up properly it should return an alpha-numeric value, this is your device ID. If not, you've missed a step or installed sdk in the wrong manner. Go back and double check your steps.

 Now that we know you're connected there are a few options, you can run the logcat in command window, or you can export it to a .txt file.

 To see the log in command window just type "adb logcat" (again no quotes) and the log will scroll through your screen. To stop scrolling so you can investigate hit ctrl + c 

 To export to a .txt file (I personally prefer this method) type "adb logcat > logcat.txt". You can name the logcat anything you want, for example "adb logcat > MyError.txt" just be sure not to include spaces or special characters in the name of the file.



MAC/Linux
 "Instructions:

 Install your device driver for using adb. Everything you need will you find here
 Download adb executable for your OS (Download: Windows | Linux | Mac). Paste it somewhere.
 Connect your android device.
 Verify if "Settings > Developer options > USB debugging" is checked, if not, simply check it.
 Open a command promt (windows) or terminal (linux / mac). How to do it: On Windows: windows + r > enter "cmd" (without quotes) > click enter | On Linux: You don't know how to open a terminal? LOL | On Mac: Type Terminal into Spotlight and open it
 CD to the directory where the adb executable is located. On Windows: Go to the directory where you downloaded the adb executable, Shift+Right Click and select "Open Console" (or similar) | On Linux / Mac: Rightclick in the directory and select "Open Terminal here" (or simply CD into the directory)
 Type in your cmd/terminal: adb devices to verify your device is properly connected.
 If your device is properly selected, type in adb logcat to show the mighty and magic logcat aka stacktrace.
 Reproduce your error (or whatever) on your device.
reading and understanding logcat output
Reading a Logcat

Ok, so now we have our log but what do we do with it?
There are a few things that you need to know before you’ll understand what is what.
Preceding every line in a logcat is a class, you can learn about them here.
These will look like this and I have placed the meaning next to each:

Code:
E/       Error - I would hope this is self explanatory
F/       Fatal Error - Again pretty self explanatory
I/        Information - This is pretty tricky, the information class shows what the system is doing, but it can also show you errors so read it carefully!
D/      Dalvikvm - This class will show what the dalvik processes are doing, but can also show you where mistakes are
W/     Warning - Warnings are basically errors, but less severe. Usually it will show you missing resources, conflicting or missing paths, etc...
V/      Verbose - Basically everything the phone is doing
S/      Silent - You will not see silent

Ok so lets see some examples. Some of these will be more in-depth than others simply because there is more to it.

Code:
D/dalvikvm( 1853): DexOpt: --- BEGIN 'core.jar' (bootstrap=1) ---
Here we see that the dalvik process has begun to optimize our system files.
D/dalvikvm( 2162): DexOpt: 'Lcom/sec/android/seccamera/SecCamera$OnMultiFrameShotEventListener;' has an earlier definition; blocking out
Here you can see that the Dalvik process has already defined the called method, and is skipping the optimization
I/PackageManager( 2130): /system/app/sCloudSyncBrowser.apk changed; collecting certs
The information class is showing that there has been a change made to this apk, and is verifying the signature.
W/ResourceType( 2130): Failure getting entry for 0x7f050020 (t=4 e=32) in package 0 (error -75)
D/PhoneStatusBar( 2792): Added status bar view
D/PhoneStatusBar( 2792): disable: < expand icons alerts ticker system_info back home recent clock >
W/PackageManager( 2130): Failure retrieving xml 0x7f050020 in package com.maxmpz.audioplayer
W/PackageManager( 2130): android.content.res.Resources$NotFoundException: Resource ID #0x7f050020
W/PackageManager( 2130): at android.content.res.Resources.getValue(Resources.java:1339)
W/PackageManager( 2130): at android.content.res.Resources.loadXmlResourceParser(Resources.java:2445)
W/PackageManager( 2130): at android.content.res.Resources.getXml(Resources.java:1227)
W/PackageManager( 2130): at android.app.ApplicationPackageManager.getXml(ApplicationPackageManager.java:1080)
W/PackageManager( 2130): at android.content.pm.PackageItemInfo.loadXmlMetaData(PackageItemInfo.java:227)
W/PackageManager( 2130): at com.android.server.AppWidgetServiceImpl.parseProviderInfoXml(AppWidgetServiceImpl.java:1264)
W/PackageManager( 2130): at com.android.server.AppWidgetServiceImpl.addProviderLocked(AppWidgetServiceImpl.java:1162)
W/PackageManager( 2130): at com.android.server.AppWidgetServiceImpl.loadAppWidgetList(AppWidgetServiceImpl.java:1148)
W/PackageManager( 2130): at com.android.server.AppWidgetServiceImpl.ensureStateLoadedLocked(AppWidgetServiceImpl.java:391)
W/PackageManager( 2130): at com.android.server.AppWidgetServiceImpl.systemReady(AppWidgetServiceImpl.java:211)
W/PackageManager( 2130): at com.android.server.AppWidgetService.systemReady(AppWidgetService.java:156)
W/PackageManager( 2130): at com.android.server.ServerThread$1.run(SystemServer.java:1882)
W/PackageManager( 2130): at com.android.server.am.ActivityManagerService.systemReady(ActivityManagerService.java:8250)
W/PackageManager( 2130): at com.android.server.am.ActivityManagerService$9$1.run(ActivityManagerService.java:8152)
W/PackageManager( 2130): at android.os.Handler.handleCallback(Handler.java:615)
W/PackageManager( 2130): at android.os.Handler.dispatchMessage(Handler.java:92)
W/PackageManager( 2130): at android.os.Looper.loop(Looper.java:137)
W/PackageManager( 2130): at com.android.server.am.ActivityManagerService$AThread.run(ActivityManagerService.java:1563)
W/ResourceType( 2130): Failure getting entry for 0x7f050021 (t=4 e=33) in package 0 (error -75)
W/PackageManager( 2130): Failure retrieving xml 0x7f050021 in package com.maxmpz.audioplayer
W/PackageManager( 2130): android.content.res.Resources$NotFoundException: Resource ID #0x7f050021
W/PackageManager( 2130): at android.content.res.Resources.getValue(Resources.java:1339)
W/PackageManager( 2130): at android.content.res.Resources.loadXmlResourceParser(Resources.java:2445)
W/PackageManager( 2130): at android.content.res.Resources.getXml(Resources.java:1227)
W/PackageManager( 2130): at android.app.ApplicationPackageManager.getXml(ApplicationPackageManager.java:1080)
W/PackageManager( 2130): at android.content.pm.PackageItemInfo.loadXmlMetaData(PackageItemInfo.java:227)
W/PackageManager( 2130): at com.android.server.AppWidgetServiceImpl.parseProviderInfoXml(AppWidgetServiceImpl.java:1264)
W/PackageManager( 2130): at com.android.server.AppWidgetServiceImpl.addProviderLocked(AppWidgetServiceImpl.java:1162)
W/PackageManager( 2130): at com.android.server.AppWidgetServiceImpl.loadAppWidgetList(AppWidgetServiceImpl.java:1148)
W/PackageManager( 2130): at com.android.server.AppWidgetServiceImpl.ensureStateLoadedLocked(AppWidgetServiceImpl.java:391)
W/PackageManager( 2130): at com.android.server.AppWidgetServiceImpl.systemReady(AppWidgetServiceImpl.java:211)
W/PackageManager( 2130): at com.android.server.AppWidgetService.systemReady(AppWidgetService.java:156)
W/PackageManager( 2130): at com.android.server.ServerThread$1.run(SystemServer.java:1882)
W/PackageManager( 2130): at com.android.server.am.ActivityManagerService.systemReady(ActivityManagerService.java:8250)
W/PackageManager( 2130): at com.android.server.am.ActivityManagerService$9$1.run(ActivityManagerService.java:8152)
W/PackageManager( 2130): at android.os.Handler.handleCallback(Handler.java:615)
W/PackageManager( 2130): at android.os.Handler.dispatchMessage(Handler.java:92)
W/PackageManager( 2130): at android.os.Looper.loop(Looper.java:137)
W/PackageManager( 2130): at com.android.server.am.ActivityManagerService$AThread.run(ActivityManagerService.java:1563)
Here is a great example of the warning class showing missing resources.
I/dalvikvm( 1853): Could not find method android.app.IActivityManager.resizeArrangedWindow, referenced from method android.app.ActivityManager.resizeArrangedWindow
W/dalvikvm( 1853): VFY: unable to resolve interface method 3769: Landroid/app/IActivityManager;.resizeArrangedWindow (IILandroid/graphics/Rect;)Landroid/graphics/Rect;
D/dalvikvm( 1853): VFY: replacing opcode 0x72 at 0x0004
A prime example of Information class showing an "error", these will usually be listed in information class if they don't have a great impact of the functionality of the device.
F/PackageManager( 2014): Unable to backup package manager settings,  current changes will be lost at reboot
E/DropBoxManagerService(2014):  Can't write: system_server_wtf
E/DropBoxManagerService(2014):  java.io.FileNotFoundException: /data/system/dropbox/drop21.tmp: open failed: EROFS (Read-only file system)
E/DropBoxManagerService(2014):  at libcore.io.IoBridge.open(IoBridge.java:416)
E/DropBoxManagerService(2014):  at java.io.FileOutputStream.(FileOutputStream.java:88)
E/DropBoxManagerService(2014):  at java.io.FileOutputStream.(FileOutputStream.java:73)
E/DropBoxManagerService(2014):  at com.android.server.DropBoxManagerService.add(DropBoxManagerService.java:208)
E/DropBoxManagerService(2014):  at android.os.DropBoxManager.addText(DropBoxManager.java:272)
E/DropBoxManagerService(2014):  at com.android.server.am.ActivityManagerService$13.run(ActivityManagerService.java:8281)
E/DropBoxManagerService(2014):  at com.android.server.am.ActivityManagerService.addErrorToDropBox(ActivityManagerService.java:8288)
E/DropBoxManagerService(2014):  at com.android.server.am.ActivityManagerService.handleApplicationWtf(ActivityManagerService.java:8099)
E/DropBoxManagerService(2014):  at com.android.internal.os.RuntimeInit.wtf(RuntimeInit.java:329)
E/DropBoxManagerService(2014):  at android.util.Log$1.onTerribleFailure(Log.java:103)
E/DropBoxManagerService(2014):  at android.util.Log.wtf(Log.java:278)
E/DropBoxManagerService(2014):  at android.util.Log.wtf(Log.java:255)
E/DropBoxManagerService(2014):  at com.android.server.pm.Settings.writeLPr(Settings.java:1115)
E/DropBoxManagerService(2014):  at com.android.server.pm.PackageManagerService.unloadMediaPackages(PackageManagerService.java:9314)
E/DropBoxManagerService(2014):  at com.android.server.pm.PackageManagerService.updateExternalMediaStatusInner(PackageManagerService.java:9128)
E/DropBoxManagerService(2014):  at com.android.server.pm.PackageManagerService.access$3800(PackageManagerService.java:165)
E/DropBoxManagerService(2014):  at com.android.server.pm.PackageManagerService$10.run(PackageManagerService.java:9017)
E/DropBoxManagerService(2014):  at android.os.Handler.handleCallback(Handler.java:615)
E/DropBoxManagerService(2014):  at android.os.Handler.dispatchMessage(Handler.java:92)
E/DropBoxManagerService(2014):  at android.os.Looper.loop(Looper.java:137)
E/DropBoxManagerService(2014):  at android.os.HandlerThread.run(HandlerThread.java:60)
E/DropBoxManagerService(2014):  Caused by: libcore.io.ErrnoException: open failed: EROFS (Read-only file system)
E/DropBoxManagerService(2014):  at libcore.io.Posix.open(Native Method)
E/DropBoxManagerService(2014):  at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
E/DropBoxManagerService(2014):  at libcore.io.IoBridge.open(IoBridge.java:400)
E/DropBoxManagerService(2014):  ... 20 more
Here we have the Fatal and Error classes.

How to get and read a logcat/ Troubleshoot your own issues!

Ok, so now we have seen some examples, lets learn to decipher them

The beautiful thing about these logs is that they tell you exactly what and where everything is, as long as you know what you’re looking at.
I’m only going to use the one line to show you how to read a log, as the format is exactly the same for any class.

Code:
E/DropBoxManagerService(2014):  at com.android.server.am.ActivityManagerService.addErrorToDropBox(ActivityManagerService.java:8288)
So here we have the printed error from logcat, the format used is as follows
Class/Process/Location
Important! The log WILL NOT tell you what apk or jar the error occurs in, this is the hardest part of debugging!
In the above error we see
Class = E/
Process = DropBoxManagerService
Location = com.android.server.am.ActivityManagerService.addErrorToDropBox(ActivityManagerService.java:8288) (Folder directory.File Name. Method)
I know from all my digging that the specified path is in services.jar so once I have services.jar decompiled I'll follow the path laid out. (Decompile "apkname".odex for odexed roms and classes.dex for deodexed roms)
These paths will always be located in the smali folder! For example I open my classes.dex folder after decompiling and see a smali folder, I'll open that and then I have options. The . after every word is a folder directory ( same as / in your computer directory )
The specified path says com. so I'll open the com folder, next I'm directed to android, then server, then am folder.
Now I should see a bunch of files and possibly some folders, if there is no folder name that matches the next directory it is a file!
ActivityManagerService is a filename, so I'll open that file using NotePad++ and search for the specified method which is addErrorToDropBox.
From here I can use another file to compare the lines to find my error, or I can know exactly where the error occured and report my problem to a helpful dev or member.

I hope that this has been a good learning experience and will help you to understand any issues you are facing.

Bootloops and Filtering your logs
Getting a Logcat during the dreaded Bootloop

The only difference between grabbing a logcat while running and grabbing one during a bootloop is the program you’re going to use. Instead of the standard adb bridge, we’ll be using the adb monitor tool. You can find this tool under the “TOOLS” folder. Open the “Tools” folder, right click on any empty space and select “Open Command Window Here”
Once the window is open, type “monitor” (without the quotes) and press enter. A whole new program will open listing the device ID and subfolders (your devices partitions)
IMPORTANT! The device ID may not show up right away, THIS IS OK! I found that it took about three bootloop cycles to actually connect.
Once you see the device ID, within a few seconds you should see the “system” partition listed underneath. Select it.
Down in the bottom left corner select the “Logcat” tab. From here, you can grab the logcat in a txt format or just watch it scroll.

There’s a great guide below that goes a little more in depth and has updated information about the requirements for a log during bootloops.

Consider this guide an extension for the above thread, making an easy how-to for developers to point people to.

What this guide is NOT:
– A guide on how to pull a logcat in general
– A guide on how to setup adb on a computer

This guide is/will:
-Assume you know how to connect via adb
-Assume you have installed drivers and adb
-A way to show common users to get the logs the developers need

So I personally build for devices I don’t own. A LOT. So, should it bootloop(specifically this) or not boot at all, I NEED these logs to help fix the problem. Most users are willing to do so….. as long as you teach them. So this is my one-size-fits-all guide to this.

Note: Later, I will do a write-up on how to pull kernel logs as an extension to this in the second post

To pull a logcat during a bootloop, you need to have adb permissive. This can be done several ways. I have added to the build.prop manually before but that was in TWRP and is a pain to guide users on. It’s SUPPOSED to be done with the ramdisk, but I can’t ask users to pull their ramdisk and edit it and reflash. So I have made a flashable zip to extract ramdisk and add a permissive adb property to default.prop

The zip will be in the downloads below, all you need to do is flash it when you see a ROM is bootlooping.

Note: Some kernels may not work with this, and it’s based off of Anykernel. If the zip fails, don’t worry, it has a fallback that it will add same thing to build.prop, and that should usually work.

After flashing, hook the phone/tablet up to your computer and run this in your Terminal:
On Linux:

Code:
adb logcat >  ~/log.txt

That will store logcat into your home folder.
On Windows:

Code:
adb logcat >  %UserProfile%/Desktop/log.txt

That will store logcat on your Desktop.

How do I stop logging?
You can either stop logging by hitting [CTRL] + C in the terminal or by unplugging device.

How do I know when to stop logging?
Usually, you can safely stop logging after about one minute for MOST problems, BUT I believe 5 minutes of logging would be the best bet to stop logging, so all the errors are caught.

How do I get the log to the developer?
You can get a log to a developer by Dropbox, Google Drive, or a file sharing site, but personally I like pasting sites like hastebin.com, pastebin.com, or paste.ubuntu.com. This is a developers/users personal preference though. Personally, I really, really like hastebin. For a pasting site, just open it in your browser and open the log with notepad or equivalent, and do [CTRL] + A and [CTRL] + C to copy the whole log, then paste onto the site. Then share the link the site gives you with the developer.

LogcatFlasher-0.1.zip

How to get & read a logcat/ Troubleshoot your own issues!

How do I get the log, when I didn’t even get to the boot animation?
Usually, this is a kernel problem, and is almost deserving of it’s own write-up

So your kernel didn’t boot. Well dang. This can be one of the worst problems. So, I’m going to HOPE you have TWRP, since CWM is pretty much dead.

This is more advanced, because you have to use Terminal command in TWRP.

Now, don’t be daunted by this, since it’s terminal commands, it’s quite easy.

As a general rule of thumb(there are different devices with different kernel logs, though), 3.10 kernels(pretty much anything in the last 2 years) have a log in /sys/fs/pstore/console-ramoops and 3.4 and prior kernels have /proc/last_kmsg.

You can see kernel version in Settings -> About Phone

So to pull these logs, you need to be in TWRP DIRECTLY after a failed boot.

Go to Advanced->Terminal Command and type these commands in. One will fail the other will work. Should both of them fail, restart and try to boot again, then go back to TWRP.

Code:
cp /proc/last_kmsg /sdcard/kernellog.txt
Code:
cp /sys/fs/pstore/console-ramoops /sdcard/kernellog.txt

Now you can restore your backup and boot normally. Once you’ve booted up, you can either share the files with Google Drive or Dropbox or whatever in Android, or you can pull them to your computer with these Terminal commands:
On Linux:

Code:
adb pull /sdcard/kernellog.txt ~/kernellog.txt

That will store log into your home folder.
On Windows:

Code:
adb pull /sdcard/kernellog.txt %UserProfile%/Desktop/kernellog.txt

That will store log onto your Desktop.

Then share log like you would in the above post

How to Filter your Logcat

Lets say you want to find only the logs for a specific app or process, searching through thousands of lines can be a pain. Luckily, adb allows you to filter your logs based on application tags!
Here’s how:

Code:
adb logcat ActivityManager:I MyApp:D *:S

This filter basically says “Show me only logs for ActivityManager at an Information or above level, and all logs for ‘MyApp’ with a priority level of Debug and higher” The *:S is important here, this makes all other tags Silent so that it ensures only the filtered tags are shown in your log.How’s that for handy?

How to get & read a logcat/ Troubleshoot your own issues!

Demesg (kernel) Logs

For a demesg log you’ll want to follow the same instructions as above to get into adb terminal.
Once there, type adb devices to verify you’re connected. Now you can pull a log by simply typing “adb shell dmesg > dmesg.txt” (without the quotatons” This will place the logs in the same folder that you launched terminal from (platform-tools)

Also, for more detailed information and a few other useful commands check below

How to get kernel messages from Android?

In developing kernel code, it is quite useful to get kernel messages as soon as possible. If the kernel code is loaded early in the boot process, one might not even get any kernel message before the device hangs… Fortunately, these are common challenges developers encounter, and there are already some good solutions for them.

Standard “dmesg”

To invoke the “dmesg” from the control PC, one can simply run


# adb shell dmesg

Continuously “tail” the kernel message?

Linux users may use tail -f to get kernel messages. However, because “syslogd” is possibly not included in Android, there is no such logs, and one may find that the directory “/var” is not even created.

# tail -f /var/log/messages

Fortunately, there is a kernel file /proc/kmsg which does exactly the same thing. One can just run the following command to continuously dump the kernel messages.

# adb shell cat /proc/kmsg

Redirecting kernel messages

If the phone doesn’t even boot up to a stable state where the ADB commands can be used, one might be interested in redirecting the kernel messages to some places where they can be seen. This is to leverage the “console=” command for the kernel.

For different devices, there may be different ports where the messages can be redirected to. If the serial port on the device is enabled, one can use use the serial port. On MSM chips, there is a UART port which may be used. For this, one can use “console=ttyMSM2,115200n8” and the availability of the port can be checked in “/dev” if one wants to use it.

Currently, there is a possibility to use the USB serial ports too. One may want to check if they work on the device. The USB serial port is a software serial port emulated through the USB interface. It often has the names “ttyUSB*” or “ttyHSUSB*”. On Android devices, if one sees “ttyUSB*”, those may be ports provided by the USB gadget drivers (/kernel/drivers/usb/gadget), which could be used as the console (add console=ttyUSB0,9600n8). If one sees “ttyHSUSB*”, they may be a bit different. These may be provided by MSM platform USB drivers, and some might not support the “console” yet. For curious readers, in order to be used as a console, a device driver has to register itself as a console provider by calling register_console in kernel/printk.c, and it has to provide some callbacks for printk to write kernel messages. So the device driver developer would have to explicitly support this for the device driver to be used as a console.

Other methods?

There are also other ways to get kernel messages during boot, one can check out the netconsole, Linux-aware Trace32 (JTAG), or simply dump kernel messages on the LCD — “console=tty0”. The later might not always be the most convenient to read but it provides some quick way to see what has happened without touching the drivers or hardware configuration.

Back to “tail -f” a little bit. Before I realized that “cat /proc/kmsg” would do just what I wanted, the way I did was using a small app to continuously invoke the syscall “klogctl” to read new kernel messages. If one is interested, the source code is here: klog.c. It can be compiled by adding into Android toolbox makefile (system/core/toolbox/Android.mk)

How to get and read a logcat/ Troubleshoot your own issues!

Leave a Reply

Your email address will not be published. Required fields are marked *