Getting ANR traces from Android

I was working on an app today when it clearly had an ANR. Realizing there was a problem, I wanted to get the /data/anr/traces.txt file, but despite this being on an emulator, I could not simply adb pull /data/anr/traces.txt. Moreover, /data/anr wasn’t visible in Android Studio’s Device Explorer, and adb shell plus a cd and an ls had the files, but I couldn’t even cat them due to permissions issues (and, Google Play emulators do not have sudo).

So how do you get the ANR logs? adb bugreport bugreport.zip - unzip it, and, inside, there will be an FS/data/anr folder with all the relevant ANRs from the device. In theory, this should also works on an actual device as well.