diff --git a/audio/core/all-versions/default/Android.bp b/audio/core/all-versions/default/Android.bp index 86380a5d40..df688fd909 100644 --- a/audio/core/all-versions/default/Android.bp +++ b/audio/core/all-versions/default/Android.bp @@ -48,6 +48,8 @@ cc_defaults { "libhidlbase", "liblog", "libmedia_helper", + "libmediautils_vendor", + "libmemunreachable", "libutils", "android.hardware.audio.common-util", ], diff --git a/audio/core/all-versions/default/Device.cpp b/audio/core/all-versions/default/Device.cpp index 98a59b9ff2..ac5a3ba8ef 100644 --- a/audio/core/all-versions/default/Device.cpp +++ b/audio/core/all-versions/default/Device.cpp @@ -30,6 +30,8 @@ #include #include +#include +#include #include @@ -501,9 +503,32 @@ Return Device::debugDump(const hidl_handle& fd) { } #endif -Return Device::debug(const hidl_handle& fd, const hidl_vec& /* options */) { +Return Device::debug(const hidl_handle& fd, const hidl_vec& options) { if (fd.getNativeHandle() != nullptr && fd->numFds == 1) { - analyzeStatus("dump", mDevice->dump(mDevice, fd->data[0])); + const int fd0 = fd->data[0]; + bool dumpMem = false; + bool unreachableMemory = false; + for (const auto& option : options) { + if (option == "-m") { + dumpMem = true; + } else if (option == "--unreachable") { + unreachableMemory = true; + } + } + + if (dumpMem) { + dprintf(fd0, "\nDumping memory:\n"); + std::string s = dumpMemoryAddresses(100 /* limit */); + write(fd0, s.c_str(), s.size()); + } + if (unreachableMemory) { + dprintf(fd0, "\nDumping unreachable memory:\n"); + // TODO - should limit be an argument parameter? + std::string s = GetUnreachableMemoryString(true /* contents */, 100 /* limit */); + write(fd0, s.c_str(), s.size()); + } + + analyzeStatus("dump", mDevice->dump(mDevice, fd0)); } return Void(); }