blob: 622f86661790376fb5e28fbef3f2ed4e55238944 [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
21namespace android {
22namespace lshal {
23
Yifan Hong795b6ec2017-09-13 11:25:28 -070024std::string DebugCommand::getName() const {
25 return "debug";
26}
27
28std::string DebugCommand::getSimpleDescription() const {
29 return "Debug a specified HAL.";
30}
31
Yifan Honga8bedc62017-09-08 18:00:31 -070032Status DebugCommand::parseArgs(const Arg &arg) {
Yifan Hong48dc9f82017-05-09 19:33:08 -070033 if (optind >= arg.argc) {
Yifan Hong48dc9f82017-05-09 19:33:08 -070034 return USAGE;
35 }
36 mInterfaceName = arg.argv[optind];
37 ++optind;
38 for (; optind < arg.argc; ++optind) {
39 mOptions.push_back(arg.argv[optind]);
40 }
41 return OK;
42}
43
Yifan Honga8bedc62017-09-08 18:00:31 -070044Status DebugCommand::main(const Arg &arg) {
45 Status status = parseArgs(arg);
Yifan Hong48dc9f82017-05-09 19:33:08 -070046 if (status != OK) {
47 return status;
48 }
49 auto pair = splitFirst(mInterfaceName, '/');
50 return mLshal.emitDebugInfo(
51 pair.first, pair.second.empty() ? "default" : pair.second, mOptions,
52 mLshal.out().buf(),
53 mLshal.err());
54}
55
Yifan Honga8bedc62017-09-08 18:00:31 -070056void DebugCommand::usage() const {
57
58 static const std::string debug =
59 "debug:\n"
60 " lshal debug <interface> [options [options [...]]] \n"
61 " Print debug information of a specified interface.\n"
62 " <inteface>: Format is `android.hardware.foo@1.0::IFoo/default`.\n"
63 " If instance name is missing `default` is used.\n"
64 " options: space separated options to IBase::debug.\n";
65
66 mLshal.err() << debug;
67}
68
Yifan Hong48dc9f82017-05-09 19:33:08 -070069} // namespace lshal
70} // namespace android
71