I am writing an app to capture tombstones logs.
How to get the default location of tombstones logs in any Android device?
Even if the tombstones logs are not available yet, where do they get stored when any crash or something happen?
AFAIK these logs get saved in '/data/tombstones/' but is this path universal across all devices?
Do I need to read some property from "adb shell getprop" etc in the code dynamically?
If you haven't rooted you device, you should use bugreport adb command:
adb bugreport ./bugreport.zip
Inside the zip you will have everything you need to analyse.
In order to disassembly the tombstone:
get the AOSP source code and follow the instructions of the https://source.android.com/setup/start until the lunch command.
Run the command (replace tombstone_01 by the interest file):
disassemble_tombstone.py ./bugreport/FS/data/tombstones/tombstone_01
More tools do debug the bugreport.zip in https://source.android.com/devices/tech/debug
Not to say this can't change in the future (and of course, being open source any vendor could modify this if they choose), but tombstone files are written by debuggerd in the engrave_tombstone() function implemented in tombstone.cpp (formerly tombstone.c):
https://android.googlesource.com/platform/system/core/+/master/debuggerd/tombstone.cpp
This uses a hardcoded path using the macro:
#define TOMBSTONE_DIR "/data/tombstones"
Even the Java side of Android uses the hardcoded path:
https://android.googlesource.com/platform/frameworks/base/+/master/core/java/com/android/server/BootReceiver.java
And it appears that using /data/tombstones goes at least back to Android 1.6 Donut's debuggerd
You may run below command at "/" directory from "adb shell" to locate tombstones location for a specific device.
find . |grep tombs
The path is NOT universal, in fact that isn't one I've seen in a long time. Generally when a tombstone occurs you get a line in logcat saying where the logs are. Otherwise you need to poke around.
Related
I am trying to use pelican (python) on Android (in termux). It fails when pelican tries to write to /tmp which near as I can tell, does not exist, and/or is a read-only file system.
The error is from os.py, in makedirs(name, mode)
OSError: [Errno 30] Read-only file system: '/tmp'
How do I tell any sort of script on Android to use a different location for /tmp?
How do I tell python on Android (in Termux) to use a different location for /tmp?
What is the Android equivalent of /tmp?
Editing to respond to suggestion this is a duplicate:
I found that answer helpful, but it doesn't pertain to this question.
I tried the instructions suggested here: https://stackoverflow.com/a/18280309/608970 and found that by setting TMP, TMPDIR and TEMP that I can indeed change /tmp for python and create tmp files, IF the script uses the tempfile module.
Apparently, pelican does not. Which leaves my original question, in Android what is the model for /tmp, how do we port arbitrary scripts, and does it require a change to the code, or can it be otherwise fixed by changing the Android environment the code works within?
According to https://stackoverflow.com/a/41105574/493161, it's /data/local/tmp, but my experience with termux is that it cannot read many/most files and directories that can be seen using adb from the desktop, and has write access to nothing (that I've found) outside its own files. I'd suggest mkdir $HOME/tmp instead, and using that.
Some of the other answers on that same question have good information on the lack of /tmp. Note that /data/local/tmp does not have the sticky ("t") bit set, nor does it have full read/write access to all users, as does Linux.
A better answer for many use cases is to use the file sharing options built into termux, documented at https://wiki.termux.com/wiki/Sharing_Data
$ termux-setup-storage
$ cp test.png ~/storage/downloads
$ xdg-open ~/storage/downloads/test.png
i am having a prob with my cm11 logcat, when i use logcat with ANY parameters, the adb echos
ioctl: not a typewriter
and if i use just logcat, it gives me
read: unexpected length. Expected 28146, got 5100...
Have tried fixes from other threads
EDIT: after trying something, it now says /dev/log/main no such file or directory
Pimp My ROM was causing it. If you mess with the enable/disable features section, you might turn off android logger. I am still not sure if i should have this option on or off, as i cant remember the default.
When it is set to disable the logger, it adds a line to its own script in init.d :
rm -f /dev/log/main.
Caused my computer to lag because of a program looking for my phone's logs, checking constantly.
To solve, go to pimp my rom, init.d editor (under rescue package maker) and delete the 99Pimpmyrom script
I've been experiencing a great deal of instability on my Verizon Galaxy S III, and I believe it's related to the WiFi driver, or at least something in the networking stack. I get daily full system crashes that cause soft reboots of the OS.
In order to trace to the root of the issue, I'd like to see historical crash data for the Android OS. Please note that I am NOT developing an app, and I do not want instruction on how to use LogCat to trace issues within an in-development app. I want to see the Android system crash logs, but I'm not sure where to look for them.
After ANR happens, you would find call stack of related process at /data/anr/traces.txt
After application crashes, you might find call stack of crashed application under /data/tombstones directory.
See Android: How to get kernel logs after kernel panic?
It looks like /data/dontpanic/ should contain some "apanic" files, but only if the kernel's apanic support is enabled, and it worked. (I haven't seen anything there in my case, but maybe you'll be luckier than I ...)
crash report can be found at default path: /data/anr/
some manufacture place in custom path like: /data/system/ckerror
use cmd: adb pull /data/anr "dest path"
example:
in windows cmd prompt:
adb pull /data/anr c:\trace
The document states that
Android stores trace information when it experiences an ANR. On older OS releases, there's >a single /data/anr/traces.txt file on the device.
On newer OS releases, there are multiple >/data/anr/anr_* files. You can access ANR traces from a device or emulator by using >Android Debug Bridge (adb) as root:
adb root
adb shell ls /data/anr
adb pull /data/anr/<filename>
Usually the every crash is stored in traces.txt file under /data/anr/ folder of internal storage. Try checking this file.
I found a file call crash.txt inside the directory /data/Logging which seems to contain brief stack-traces from the last several crashes that occurred on the device.
I'm in trouble with my android device in which log folder under /dev is unreachable or maybe even does not exists.
$ pwd
pwd
/dev
$ cd log
cd log
cd: can't cd to log
$
So LogCat is out-of-service and I cannot view device's stdout or stderr logs in DDMS.
I googled a little bit and tried to find some information for about this problem:
http://developer.android.com/guide/developing/tools/adb.html#alternativebuffers
Viewing stdout and stderr topic seemed to be useful but this thread says it is unsupported :
Why is redirecting stdout/stderr on android not working?
Here is another one having the same problem:
"Unable to open log device '/dev/log/main': No such file or directory"
I found a temporary solution to dump my logs in a file on device manually but as usual I cannot monitor system just my application logs.
Is there any solution you can suggest? Any way to redirect stdout and stderr logs to files,console etc.?
Any kind of help will be appreciated.
Solution:
On call screen
type *#*#2846579#*#*
opens system management menu
Project menu -> background settings -> Log setting
Log level setting -> VERBOSE
Log switch -> LOG on
Dump and Log -> Checked all the boxes
Restart device.
Thats all.
What device is this? If it ships with Market, it must pass the CDD, and that includes having the development tools needed for app development which includes logcat support (though this just means the logcat command, technically the implementation could be different). For such a device the manufacturer must supply an update to make it compatible.
If it is not a compatible device, all bets are off, and you will just need to get help from the manufacturers or any hackers who are working with the device.
RunO NesrE - I finally found the solution to this.
There is a recent post on the xda-developers forum for a different Huawei phone with the same problem and it has a fix.
http://forum.xda-developers.com/showpost.php?p=17774398&postcount=93
It worked a treat on my Huawei Sonic (U8650).
I know that the boot up log can be obtained by pulling out contents of kmsg or dmesg through ADB.
But I'm not aware of how to retrieve the shutdown logs in Android as there's no /var folder in Android (place where most desktop linux distros generally store their shutdown logs).
So how can I obtain the shutdown logs in Android?
Look in some locations such as these:
/proc/last_kmsg
/data/tombstones/
/data/dontpanic/
/data/system/dropbox/
(This list isn't strictly kernel logs, including framework and application logs too, which are also sometimes of interest)
One work around I found for collecting shutdown logs in Android is to run adb pull /proc/kmsg C:\Logs.txt on the host PC and then switch off the device. You will get the logs till the USB communication between the host and the device snaps! I know this is only one case out of the numerous shutdown scenarios but I haven't found satisfactory answers for other cases!
TL;DR:
Run command through adb that copies logcat and proc/kmsg to a file and keep it running even when adb disconnects with nohup, disown or setsid. Probably needs busybox, needs root and adb root, too.
setsid cat proc/kmsg > /sdcard/kmsg.txt &
and
logcat -v long -f /sdcard/logcat.txt (somehow only works without setsid)
Or add normal copy commands to some startup script.
/TL;DR
You can constantly copy proc/kmsg and logcat to a file on your android device or a microSD card to get the logs even after adb disconnects.
You need root access and adb root access for this to work. For the latter, use the setting in the developer options if you have a custom rom or the adbd insecure app.
After using adb shell to get your android shell, type su to get superuser access.
Then you not only need to put an ampersand (&) after the command but also make sure that the command keeps running after adb disconnects. That is done by nohup, disown or setsid (see here for usage).
If it doesn't work because you don't have these commands, you need to install busybox.
See my question here.
See here for how to get logcat and kernel logs and print it to some file or merge it.
See developer.android.com/tools/help/logcat.html for parameters for the logcat command.
In the end you could have a command like setsid cat proc/kmsg > /sdcard/kmsg.txt & for the kernel messages.
For logcat you could have one of the following commands: logcat -v long -f /sdcard/logcat.txt or logcat -v long > /sdcard/logcat.txt
I don't know why, but sometimes it didn't work with setsid and just didn't copy continuously but stopped shortly after executing the command. In these situations, it also showed up when entering jobs, which it didn't otherwise. Then it just worked without setsid, it stayed alive after disconnecting and reconnecting. I guess you must just try when the file does keep getting larger. If someone figured out why it is behaving like it is... let me know and I'll edit the answer.
Probably adding the commands to a startup script could be a solution for some, too.
Hope this helps.
fightcookie
Newer phones do NOT use any of these locations so if you're reading this article then as of now
The kernel crash logs are now in /sys/fs/pstore instead of /proc/last_kmsg
I was looking for the same thing, and finally, I found the answer!
In android 8 all logs are located in \data\log\android_logs\... including apps and kernel logs. Kernel logs are called kmsgcat-log_timestamp_.gz
edit: Although this is a very old thread, I think the answer might be helpful.