1# `dumpstate` development tips 2 3## To build `dumpstate` 4 5Do a full build first: 6 7``` 8m -j dumpstate 9``` 10 11Then incremental ones: 12 13``` 14mmm -j frameworks/native/cmds/dumpstate 15``` 16 17If you're working on device-specific code, you might need to build them as well. 18Example: 19 20``` 21mmm -j frameworks/native/cmds/dumpstate device/acme/secret_device/dumpstate/ hardware/interfaces/dumpstate 22``` 23 24## Dumpstate philosophy: exec not link 25 26Never link code directly into dumpstate. Dumpstate should execute many 27binaries and collect the results. In general, code should fail hard fail fast, 28but dumpstate is the last to solve many Android bugs. Oftentimes, failures 29in core Android infrastructure or tools are issues that cause problems in 30bugreport directly, so bugreport should not rely on these tools working. 31We want dumpstate to have as minimal of code loaded in process so that 32only that core subset needs to be bugfree for bugreport to work. Even if 33many pieces of Android break, that should not prevent dumpstate from 34working. 35 36## To build, deploy, and take a bugreport 37 38``` 39mmm -j frameworks/native/cmds/dumpstate && adb push ${OUT}/system/bin/dumpstate system/bin && adb push ${OUT}/system/lib64/*dumpstate*.so /system/lib64/ && adb shell am bug-report 40``` 41 42Make sure that the device is remounted before running the above command. * If 43you're working with `userdebug` variant, you may need to run the following to 44remount your device: 45 46``` 47 adb root && adb remount -R && adb wait-for-device && adb root && adb remount 48``` 49 50* If you're working with `eng` variant, you may need to run the following to 51 remount your device: 52 53 ``` 54 adb root && adb remount 55 ``` 56 57## To build, deploy, and run unit tests 58 59First create `/data/nativetest64`: 60 61``` 62adb shell mkdir /data/nativetest64 63``` 64 65Then run: 66 67``` 68mmm -j frameworks/native/cmds/dumpstate/ && adb push ${OUT}/data/nativetest64/dumpstate_* /data/nativetest64 && adb shell /data/nativetest64/dumpstate_test/dumpstate_test 69``` 70 71And to run just one test (for example, `DumpstateTest.RunCommandNoArgs`): 72 73``` 74mmm -j frameworks/native/cmds/dumpstate/ && adb push ${OUT}/data/nativetest64/dumpstate_test* /data/nativetest64 && adb shell /data/nativetest64/dumpstate_test/dumpstate_test --gtest_filter=DumpstateTest.RunCommandNoArgs 75``` 76 77## To take quick bugreports 78 79``` 80adb shell setprop dumpstate.dry_run true 81``` 82 83## To emulate a device with user build 84 85``` 86adb shell setprop dumpstate.unroot true 87``` 88 89## To change the `dumpstate` version 90 91``` 92adb shell setprop dumpstate.version VERSION_NAME 93``` 94 95Example: 96 97``` 98adb shell setprop dumpstate.version split-dumpsys && adb shell dumpstate -v 99``` 100 101Then to restore the default version: 102 103``` 104adb shell setprop dumpstate.version default 105``` 106 107## To set Bugreport API workflow for bugreport 108 109``` 110adb shell setprop settings_call_bugreport_api true 111``` 112 113## Code style and formatting 114 115Use the style defined at the 116[Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html) and 117make sure to run the following command prior to `repo upload`: 118 119``` 120git clang-format --style=file HEAD~ 121``` 122 123## Useful Bash tricks 124 125``` 126export BR_DIR=/bugreports 127 128alias br='adb shell cmd activity bug-report' 129alias ls_bugs='adb shell ls -l ${BR_DIR}/' 130 131unzip_bug() { 132 adb pull ${BR_DIR}/$1 && emacs $1 && mv $1 /tmp 133} 134 135less_bug() { 136 adb pull ${BR_DIR}/$1 && less $1 && mv $1 /tmp 137} 138 139rm_bugs() { 140 if [ -z "${BR_DIR}" ] ; then echo "Variable BR_DIR not set"; else adb shell rm -rf ${BR_DIR}/*; fi 141} 142 143``` 144