DebugCommand.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (C) 2017 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "DebugCommand.h"
  17. #include "Lshal.h"
  18. #include <hidl-util/FQName.h>
  19. namespace android {
  20. namespace lshal {
  21. std::string DebugCommand::getName() const {
  22. return "debug";
  23. }
  24. std::string DebugCommand::getSimpleDescription() const {
  25. return "Debug a specified HAL.";
  26. }
  27. Status DebugCommand::parseArgs(const Arg &arg) {
  28. if (optind >= arg.argc) {
  29. return USAGE;
  30. }
  31. // Optargs cannnot be used because the flag should not be considered set
  32. // if it should really be contained in mOptions.
  33. if (std::string(arg.argv[optind]) == "-E") {
  34. mExcludesParentInstances = true;
  35. optind++;
  36. }
  37. mInterfaceName = arg.argv[optind];
  38. ++optind;
  39. for (; optind < arg.argc; ++optind) {
  40. mOptions.push_back(arg.argv[optind]);
  41. }
  42. return OK;
  43. }
  44. Status DebugCommand::main(const Arg &arg) {
  45. Status status = parseArgs(arg);
  46. if (status != OK) {
  47. return status;
  48. }
  49. auto pair = splitFirst(mInterfaceName, '/');
  50. FQName fqName;
  51. if (!FQName::parse(pair.first, &fqName) || fqName.isIdentifier() || !fqName.isFullyQualified()) {
  52. mLshal.err() << "Invalid fully-qualified name '" << pair.first << "'\n\n";
  53. return USAGE;
  54. }
  55. return mLshal.emitDebugInfo(
  56. pair.first, pair.second.empty() ? "default" : pair.second, mOptions,
  57. mExcludesParentInstances,
  58. mLshal.out().buf(),
  59. mLshal.err());
  60. }
  61. void DebugCommand::usage() const {
  62. static const std::string debug =
  63. "debug:\n"
  64. " lshal debug [-E] <interface> [options [options [...]]] \n"
  65. " Print debug information of a specified interface.\n"
  66. " -E: excludes debug output if HAL is actually a subclass.\n"
  67. " <inteface>: Format is `[email protected]::IFoo/default`.\n"
  68. " If instance name is missing `default` is used.\n"
  69. " options: space separated options to IBase::debug.\n";
  70. mLshal.err() << debug;
  71. }
  72. } // namespace lshal
  73. } // namespace android