1 //===-- RenderScriptScriptGroup.cpp -----------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Breakpoint/StoppointCallbackContext.h"
10 #include "lldb/Core/Debugger.h"
11 #include "lldb/Core/PluginManager.h"
12 #include "lldb/Interpreter/CommandInterpreter.h"
13 #include "lldb/Interpreter/CommandObjectMultiword.h"
14 #include "lldb/Interpreter/CommandReturnObject.h"
15 #include "lldb/Interpreter/Options.h"
16 #include "lldb/Symbol/Symbol.h"
17 #include "lldb/Symbol/Type.h"
18 #include "lldb/Symbol/VariableList.h"
19 #include "lldb/Target/Process.h"
20 #include "lldb/Target/Target.h"
21 #include "lldb/Utility/Args.h"
22 #include "lldb/Utility/ConstString.h"
23 #include "lldb/Utility/Log.h"
24 #include "lldb/Utility/Status.h"
26 #include "RenderScriptRuntime.h"
27 #include "RenderScriptScriptGroup.h"
30 using namespace lldb_private;
31 using namespace lldb_renderscript;
33 class CommandObjectRenderScriptScriptGroupBreakpointSet
34 : public CommandObjectParsed {
36 CommandObjectRenderScriptScriptGroupBreakpointSet(
37 CommandInterpreter &interpreter)
38 : CommandObjectParsed(
39 interpreter, "renderscript scriptgroup breakpoint set",
40 "Place a breakpoint on all kernels forming a script group.",
41 "renderscript scriptgroup breakpoint set <group_name>",
42 eCommandRequiresProcess | eCommandProcessMustBeLaunched) {}
44 ~CommandObjectRenderScriptScriptGroupBreakpointSet() override = default;
46 bool DoExecute(Args &command, CommandReturnObject &result) override {
47 Stream &stream = result.GetOutputStream();
48 RenderScriptRuntime *runtime = static_cast<RenderScriptRuntime *>(
49 m_exe_ctx.GetProcessPtr()->GetLanguageRuntime(
50 eLanguageTypeExtRenderScript));
52 auto &target = m_exe_ctx.GetTargetSP();
53 bool stop_on_all = false;
54 const llvm::StringRef long_stop_all("--stop-on-all"), short_stop_all("-a");
55 std::vector<ConstString> sites;
56 sites.reserve(command.GetArgumentCount());
57 for (size_t i = 0; i < command.GetArgumentCount(); ++i) {
58 const auto arg = command.GetArgumentAtIndex(i);
59 if (long_stop_all == arg || short_stop_all == arg)
62 sites.push_back(ConstString(arg));
64 for (const auto &name : sites) {
65 runtime->PlaceBreakpointOnScriptGroup(target, stream, name, stop_on_all);
67 result.SetStatus(eReturnStatusSuccessFinishResult);
72 class CommandObjectRenderScriptScriptGroupBreakpoint
73 : public CommandObjectMultiword {
75 CommandObjectRenderScriptScriptGroupBreakpoint(
76 CommandInterpreter &interpreter)
77 : CommandObjectMultiword(
78 interpreter, "renderscript scriptgroup breakpoint",
79 "Renderscript scriptgroup breakpoint interaction.",
80 "renderscript scriptgroup breakpoint set [--stop-on-all/-a]"
81 "<scriptgroup name> ...",
82 eCommandRequiresProcess | eCommandProcessMustBeLaunched) {
85 CommandObjectSP(new CommandObjectRenderScriptScriptGroupBreakpointSet(
89 ~CommandObjectRenderScriptScriptGroupBreakpoint() override = default;
92 class CommandObjectRenderScriptScriptGroupList : public CommandObjectParsed {
94 CommandObjectRenderScriptScriptGroupList(CommandInterpreter &interpreter)
95 : CommandObjectParsed(interpreter, "renderscript scriptgroup list",
96 "List all currently discovered script groups.",
97 "renderscript scriptgroup list",
98 eCommandRequiresProcess |
99 eCommandProcessMustBeLaunched) {}
101 ~CommandObjectRenderScriptScriptGroupList() override = default;
103 bool DoExecute(Args &command, CommandReturnObject &result) override {
104 Stream &stream = result.GetOutputStream();
105 RenderScriptRuntime *runtime = static_cast<RenderScriptRuntime *>(
106 m_exe_ctx.GetProcessPtr()->GetLanguageRuntime(
107 eLanguageTypeExtRenderScript));
109 const RSScriptGroupList &groups = runtime->GetScriptGroups();
110 // print script group count
111 stream.Printf("%" PRIu64 " script %s", uint64_t(groups.size()),
112 (groups.size() == 1) ? "group" : "groups");
114 // print script group details
116 for (const RSScriptGroupDescriptorSP &g : groups) {
120 stream.Printf("%s", g->m_name.AsCString());
122 // print out the kernels
124 for (const auto &k : g->m_kernels) {
126 stream.Printf(". %s", k.m_name.AsCString());
133 result.SetStatus(eReturnStatusSuccessFinishResult);
138 class CommandObjectRenderScriptScriptGroup : public CommandObjectMultiword {
140 CommandObjectRenderScriptScriptGroup(CommandInterpreter &interpreter)
141 : CommandObjectMultiword(interpreter, "renderscript scriptgroup",
142 "Command set for interacting with scriptgroups.",
143 nullptr, eCommandRequiresProcess |
144 eCommandProcessMustBeLaunched) {
148 new CommandObjectRenderScriptScriptGroupBreakpoint(interpreter)));
150 "list", CommandObjectSP(
151 new CommandObjectRenderScriptScriptGroupList(interpreter)));
154 ~CommandObjectRenderScriptScriptGroup() override = default;
157 lldb::CommandObjectSP NewCommandObjectRenderScriptScriptGroup(
158 lldb_private::CommandInterpreter &interpreter) {
159 return CommandObjectSP(new CommandObjectRenderScriptScriptGroup(interpreter));