1# How to enable host (server) adb traces for bug reports: 2 3> :warning: **This will enable tracing permanently**. These instructions are 4 well suited for tools managing adb lifecycle (like Android Studio). 5Once done, it is recommended to undoing the changes made here and then 6restarting adb via `adb kill-server ; adb server`. 7 8## 1. Set the environment variable 9 10### On MacOS/Linux 11 12Add the following line to `~/.bashrc` (.zshrc on MacOS 10.15+:W 13). 14 15``` 16ADB_TRACE=all 17``` 18 19### On Windows 20 21Add the global variable via the `System Properties` window. 22In the `Advanced` tab, click on `Environment Variables`. Add the Variable/ 23Value to the `User variables` list. Alternatively, you can bring up the same 24window by searching for "Edit Environment Variables". 25 26## 2. Cycle adb server 27 28Shutdown adb server via command `adb kill-server`. Close the current terminal, 29open a new one, and start adb server via `adb server`. 30 31## 3. Locate the log files 32 33### On MacOS/Linux 34 35The log files are located in `$TMPDIR` which is almost always `/tmp`. Log files 36are created on a per uid basis, `adb.<UID>.log`. 37 38### On Windows 39 40The log files are located in `%TEMP%` which is often `C:\Users\<USERNAME>\AppData\Local\Temp`. 41The filename is always `adb.log`. 42 43# How to capture device-side logs for adb bug reports (needs root privilege): 44 45Device-side (adbd) debugging is best accomplished from a post-mortem standpoint, because real-time 46debugging is impossible given the fact that adb itself is the underlying 47debugging channel. 48 49## 1. Set trace mask on and restart the daemon 50Device logs tend to be noisy so reproduce the problem 51as soon as possible, collect the logs and turn tracing off. 52 53$ adb shell setprop persist.adb.trace_mask 1 54$ adb shell pkill adbd 55 56## 2. Collect the logs using `adb pull` and turn off tracing 57$ adb shell 58sargo:/ # cd /data/adb 59sargo:/data/adb # ls -al 60total 23 61drwx------ 2 root root 3488 2022-02-08 18:04 . 62drwxrwx--x 49 system system 4096 2022-01-18 12:13 .. 63-rw------- 1 root root 8521 2022-02-08 18:05 adb-2022-02-08-18-04-49-18527 64 65From the host: 66$adb pull /data/adb/adb-2022-02-08-18-04-49-18527 67 68## Error(s) that you may run into, and resolution: 69You may run into errors either during `adb shell` or `adb pull`. 70Make sure you are running as root. 71 72$ adb shell setprop persist.adb.trace_mask 0 73Failed to set property 'persist.adb.trace_mask' to '0'. 74See dmesg for error reason. 75$ adb root 76$ adb shell setprop persist.adb.trace_mask 0 77 78