blob: 0952db6e72c98e610ccc016c0b9e8684bbc9b47c [file] [log] [blame]
Yifan Hong48dc9f82017-05-09 19:33:08 -07001/*
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
17#include "DebugCommand.h"
18
19#include "Lshal.h"
20
Steven Moreland3481c9a2018-01-04 17:14:17 -080021#include <hidl-util/FQName.h>
22
Yifan Hong48dc9f82017-05-09 19:33:08 -070023namespace android {
24namespace lshal {
25
Yifan Hong795b6ec2017-09-13 11:25:28 -070026std::string DebugCommand::getName() const {
27 return "debug";
28}
29
30std::string DebugCommand::getSimpleDescription() const {
31 return "Debug a specified HAL.";
32}
33
Yifan Honga8bedc62017-09-08 18:00:31 -070034Status DebugCommand::parseArgs(const Arg &arg) {
Yifan Hong48dc9f82017-05-09 19:33:08 -070035 if (optind >= arg.argc) {
Yifan Hong48dc9f82017-05-09 19:33:08 -070036 return USAGE;
37 }
Steven Moreland5f328892018-01-18 14:38:07 -080038
39 // Optargs cannnot be used because the flag should not be considered set
40 // if it should really be contained in mOptions.
41 if (std::string(arg.argv[optind]) == "-E") {
42 mExcludesParentInstances = true;
43 optind++;
44 }
45
Yifan Hong48dc9f82017-05-09 19:33:08 -070046 mInterfaceName = arg.argv[optind];
47 ++optind;
48 for (; optind < arg.argc; ++optind) {
49 mOptions.push_back(arg.argv[optind]);
50 }
51 return OK;
52}
53
Yifan Honga8bedc62017-09-08 18:00:31 -070054Status DebugCommand::main(const Arg &arg) {
55 Status status = parseArgs(arg);
Yifan Hong48dc9f82017-05-09 19:33:08 -070056 if (status != OK) {
57 return status;
58 }
Steven Moreland3481c9a2018-01-04 17:14:17 -080059
Yifan Hong48dc9f82017-05-09 19:33:08 -070060 auto pair = splitFirst(mInterfaceName, '/');
Steven Moreland3481c9a2018-01-04 17:14:17 -080061
Steven Morelandd4f32b32018-03-06 14:47:58 -080062 FQName fqName;
63 if (!FQName::parse(pair.first, &fqName) || fqName.isIdentifier() || !fqName.isFullyQualified()) {
Steven Moreland3481c9a2018-01-04 17:14:17 -080064 mLshal.err() << "Invalid fully-qualified name '" << pair.first << "'\n\n";
65 return USAGE;
66 }
67
Yifan Hong48dc9f82017-05-09 19:33:08 -070068 return mLshal.emitDebugInfo(
69 pair.first, pair.second.empty() ? "default" : pair.second, mOptions,
Steven Moreland5f328892018-01-18 14:38:07 -080070 mExcludesParentInstances,
Yifan Hong48dc9f82017-05-09 19:33:08 -070071 mLshal.out().buf(),
72 mLshal.err());
73}
74
Yifan Honga8bedc62017-09-08 18:00:31 -070075void DebugCommand::usage() const {
76
77 static const std::string debug =
78 "debug:\n"
Steven Moreland5f328892018-01-18 14:38:07 -080079 " lshal debug [-E] <interface> [options [options [...]]] \n"
Yifan Honga8bedc62017-09-08 18:00:31 -070080 " Print debug information of a specified interface.\n"
Steven Moreland5f328892018-01-18 14:38:07 -080081 " -E: excludes debug output if HAL is actually a subclass.\n"
Yifan Honga8bedc62017-09-08 18:00:31 -070082 " <inteface>: Format is `android.hardware.foo@1.0::IFoo/default`.\n"
83 " If instance name is missing `default` is used.\n"
84 " options: space separated options to IBase::debug.\n";
85
86 mLshal.err() << debug;
87}
88
Yifan Hong48dc9f82017-05-09 19:33:08 -070089} // namespace lshal
90} // namespace android
91