blob: f371320bd06c4424e76286ec1df71cdbae74a663 [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 }
38 mInterfaceName = arg.argv[optind];
39 ++optind;
40 for (; optind < arg.argc; ++optind) {
41 mOptions.push_back(arg.argv[optind]);
42 }
43 return OK;
44}
45
Yifan Honga8bedc62017-09-08 18:00:31 -070046Status DebugCommand::main(const Arg &arg) {
47 Status status = parseArgs(arg);
Yifan Hong48dc9f82017-05-09 19:33:08 -070048 if (status != OK) {
49 return status;
50 }
Steven Moreland3481c9a2018-01-04 17:14:17 -080051
Yifan Hong48dc9f82017-05-09 19:33:08 -070052 auto pair = splitFirst(mInterfaceName, '/');
Steven Moreland3481c9a2018-01-04 17:14:17 -080053
54 FQName fqName(pair.first);
55 if (!fqName.isValid() || fqName.isIdentifier() || !fqName.isFullyQualified()) {
56 mLshal.err() << "Invalid fully-qualified name '" << pair.first << "'\n\n";
57 return USAGE;
58 }
59
Yifan Hong48dc9f82017-05-09 19:33:08 -070060 return mLshal.emitDebugInfo(
61 pair.first, pair.second.empty() ? "default" : pair.second, mOptions,
62 mLshal.out().buf(),
63 mLshal.err());
64}
65
Yifan Honga8bedc62017-09-08 18:00:31 -070066void DebugCommand::usage() const {
67
68 static const std::string debug =
69 "debug:\n"
70 " lshal debug <interface> [options [options [...]]] \n"
71 " Print debug information of a specified interface.\n"
72 " <inteface>: Format is `android.hardware.foo@1.0::IFoo/default`.\n"
73 " If instance name is missing `default` is used.\n"
74 " options: space separated options to IBase::debug.\n";
75
76 mLshal.err() << debug;
77}
78
Yifan Hong48dc9f82017-05-09 19:33:08 -070079} // namespace lshal
80} // namespace android
81