1*0b57cec5SDimitry Andric //===-- RenderScriptScriptGroup.cpp ---------------------------------------===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric
9*0b57cec5SDimitry Andric #include "lldb/Breakpoint/StoppointCallbackContext.h"
10*0b57cec5SDimitry Andric #include "lldb/Core/Debugger.h"
11*0b57cec5SDimitry Andric #include "lldb/Core/PluginManager.h"
12*0b57cec5SDimitry Andric #include "lldb/Interpreter/CommandInterpreter.h"
13*0b57cec5SDimitry Andric #include "lldb/Interpreter/CommandObjectMultiword.h"
14*0b57cec5SDimitry Andric #include "lldb/Interpreter/CommandReturnObject.h"
15*0b57cec5SDimitry Andric #include "lldb/Interpreter/Options.h"
16*0b57cec5SDimitry Andric #include "lldb/Symbol/Symbol.h"
17*0b57cec5SDimitry Andric #include "lldb/Symbol/Type.h"
18*0b57cec5SDimitry Andric #include "lldb/Symbol/VariableList.h"
19*0b57cec5SDimitry Andric #include "lldb/Target/Process.h"
20*0b57cec5SDimitry Andric #include "lldb/Target/Target.h"
21*0b57cec5SDimitry Andric #include "lldb/Utility/Args.h"
22*0b57cec5SDimitry Andric #include "lldb/Utility/ConstString.h"
23*0b57cec5SDimitry Andric #include "lldb/Utility/Log.h"
24*0b57cec5SDimitry Andric #include "lldb/Utility/Status.h"
25*0b57cec5SDimitry Andric
26*0b57cec5SDimitry Andric #include "RenderScriptRuntime.h"
27*0b57cec5SDimitry Andric #include "RenderScriptScriptGroup.h"
28*0b57cec5SDimitry Andric
29*0b57cec5SDimitry Andric using namespace lldb;
30*0b57cec5SDimitry Andric using namespace lldb_private;
31*0b57cec5SDimitry Andric using namespace lldb_renderscript;
32*0b57cec5SDimitry Andric
33*0b57cec5SDimitry Andric class CommandObjectRenderScriptScriptGroupBreakpointSet
34*0b57cec5SDimitry Andric : public CommandObjectParsed {
35*0b57cec5SDimitry Andric public:
CommandObjectRenderScriptScriptGroupBreakpointSet(CommandInterpreter & interpreter)36*0b57cec5SDimitry Andric CommandObjectRenderScriptScriptGroupBreakpointSet(
37*0b57cec5SDimitry Andric CommandInterpreter &interpreter)
38*0b57cec5SDimitry Andric : CommandObjectParsed(
39*0b57cec5SDimitry Andric interpreter, "renderscript scriptgroup breakpoint set",
40*0b57cec5SDimitry Andric "Place a breakpoint on all kernels forming a script group.",
41*0b57cec5SDimitry Andric "renderscript scriptgroup breakpoint set <group_name>",
42*0b57cec5SDimitry Andric eCommandRequiresProcess | eCommandProcessMustBeLaunched) {}
43*0b57cec5SDimitry Andric
44*0b57cec5SDimitry Andric ~CommandObjectRenderScriptScriptGroupBreakpointSet() override = default;
45*0b57cec5SDimitry Andric
DoExecute(Args & command,CommandReturnObject & result)46*0b57cec5SDimitry Andric bool DoExecute(Args &command, CommandReturnObject &result) override {
47*0b57cec5SDimitry Andric Stream &stream = result.GetOutputStream();
48*0b57cec5SDimitry Andric RenderScriptRuntime *runtime = static_cast<RenderScriptRuntime *>(
49*0b57cec5SDimitry Andric m_exe_ctx.GetProcessPtr()->GetLanguageRuntime(
50*0b57cec5SDimitry Andric eLanguageTypeExtRenderScript));
51*0b57cec5SDimitry Andric assert(runtime);
52*0b57cec5SDimitry Andric auto &target = m_exe_ctx.GetTargetSP();
53*0b57cec5SDimitry Andric bool stop_on_all = false;
54*0b57cec5SDimitry Andric const llvm::StringRef long_stop_all("--stop-on-all"), short_stop_all("-a");
55*0b57cec5SDimitry Andric std::vector<ConstString> sites;
56*0b57cec5SDimitry Andric sites.reserve(command.GetArgumentCount());
57*0b57cec5SDimitry Andric for (size_t i = 0; i < command.GetArgumentCount(); ++i) {
58*0b57cec5SDimitry Andric const auto arg = command.GetArgumentAtIndex(i);
59*0b57cec5SDimitry Andric if (long_stop_all == arg || short_stop_all == arg)
60*0b57cec5SDimitry Andric stop_on_all = true;
61*0b57cec5SDimitry Andric else
62*0b57cec5SDimitry Andric sites.push_back(ConstString(arg));
63*0b57cec5SDimitry Andric }
64*0b57cec5SDimitry Andric for (const auto &name : sites) {
65*0b57cec5SDimitry Andric runtime->PlaceBreakpointOnScriptGroup(target, stream, name, stop_on_all);
66*0b57cec5SDimitry Andric }
67*0b57cec5SDimitry Andric result.SetStatus(eReturnStatusSuccessFinishResult);
68*0b57cec5SDimitry Andric return true;
69*0b57cec5SDimitry Andric }
70*0b57cec5SDimitry Andric };
71*0b57cec5SDimitry Andric
72*0b57cec5SDimitry Andric class CommandObjectRenderScriptScriptGroupBreakpoint
73*0b57cec5SDimitry Andric : public CommandObjectMultiword {
74*0b57cec5SDimitry Andric public:
CommandObjectRenderScriptScriptGroupBreakpoint(CommandInterpreter & interpreter)75*0b57cec5SDimitry Andric CommandObjectRenderScriptScriptGroupBreakpoint(
76*0b57cec5SDimitry Andric CommandInterpreter &interpreter)
77*0b57cec5SDimitry Andric : CommandObjectMultiword(
78*0b57cec5SDimitry Andric interpreter, "renderscript scriptgroup breakpoint",
79*0b57cec5SDimitry Andric "Renderscript scriptgroup breakpoint interaction.",
80*0b57cec5SDimitry Andric "renderscript scriptgroup breakpoint set [--stop-on-all/-a]"
81*0b57cec5SDimitry Andric "<scriptgroup name> ...",
82*0b57cec5SDimitry Andric eCommandRequiresProcess | eCommandProcessMustBeLaunched) {
83*0b57cec5SDimitry Andric LoadSubCommand(
84*0b57cec5SDimitry Andric "set",
85*0b57cec5SDimitry Andric CommandObjectSP(new CommandObjectRenderScriptScriptGroupBreakpointSet(
86*0b57cec5SDimitry Andric interpreter)));
87*0b57cec5SDimitry Andric }
88*0b57cec5SDimitry Andric
89*0b57cec5SDimitry Andric ~CommandObjectRenderScriptScriptGroupBreakpoint() override = default;
90*0b57cec5SDimitry Andric };
91*0b57cec5SDimitry Andric
92*0b57cec5SDimitry Andric class CommandObjectRenderScriptScriptGroupList : public CommandObjectParsed {
93*0b57cec5SDimitry Andric public:
CommandObjectRenderScriptScriptGroupList(CommandInterpreter & interpreter)94*0b57cec5SDimitry Andric CommandObjectRenderScriptScriptGroupList(CommandInterpreter &interpreter)
95*0b57cec5SDimitry Andric : CommandObjectParsed(interpreter, "renderscript scriptgroup list",
96*0b57cec5SDimitry Andric "List all currently discovered script groups.",
97*0b57cec5SDimitry Andric "renderscript scriptgroup list",
98*0b57cec5SDimitry Andric eCommandRequiresProcess |
99*0b57cec5SDimitry Andric eCommandProcessMustBeLaunched) {}
100*0b57cec5SDimitry Andric
101*0b57cec5SDimitry Andric ~CommandObjectRenderScriptScriptGroupList() override = default;
102*0b57cec5SDimitry Andric
DoExecute(Args & command,CommandReturnObject & result)103*0b57cec5SDimitry Andric bool DoExecute(Args &command, CommandReturnObject &result) override {
104*0b57cec5SDimitry Andric Stream &stream = result.GetOutputStream();
105*0b57cec5SDimitry Andric RenderScriptRuntime *runtime = static_cast<RenderScriptRuntime *>(
106*0b57cec5SDimitry Andric m_exe_ctx.GetProcessPtr()->GetLanguageRuntime(
107*0b57cec5SDimitry Andric eLanguageTypeExtRenderScript));
108*0b57cec5SDimitry Andric assert(runtime);
109*0b57cec5SDimitry Andric const RSScriptGroupList &groups = runtime->GetScriptGroups();
110*0b57cec5SDimitry Andric // print script group count
111*0b57cec5SDimitry Andric stream.Printf("%" PRIu64 " script %s", uint64_t(groups.size()),
112*0b57cec5SDimitry Andric (groups.size() == 1) ? "group" : "groups");
113*0b57cec5SDimitry Andric stream.EOL();
114*0b57cec5SDimitry Andric // print script group details
115*0b57cec5SDimitry Andric stream.IndentMore();
116*0b57cec5SDimitry Andric for (const RSScriptGroupDescriptorSP &g : groups) {
117*0b57cec5SDimitry Andric if (g) {
118*0b57cec5SDimitry Andric stream.Indent();
119*0b57cec5SDimitry Andric // script group name
120*0b57cec5SDimitry Andric stream.Printf("%s", g->m_name.AsCString());
121*0b57cec5SDimitry Andric stream.EOL();
122*0b57cec5SDimitry Andric // print out the kernels
123*0b57cec5SDimitry Andric stream.IndentMore();
124*0b57cec5SDimitry Andric for (const auto &k : g->m_kernels) {
125*0b57cec5SDimitry Andric stream.Indent();
126*0b57cec5SDimitry Andric stream.Printf(". %s", k.m_name.AsCString());
127*0b57cec5SDimitry Andric stream.EOL();
128*0b57cec5SDimitry Andric }
129*0b57cec5SDimitry Andric stream.IndentLess();
130*0b57cec5SDimitry Andric }
131*0b57cec5SDimitry Andric }
132*0b57cec5SDimitry Andric stream.IndentLess();
133*0b57cec5SDimitry Andric result.SetStatus(eReturnStatusSuccessFinishResult);
134*0b57cec5SDimitry Andric return true;
135*0b57cec5SDimitry Andric }
136*0b57cec5SDimitry Andric };
137*0b57cec5SDimitry Andric
138*0b57cec5SDimitry Andric class CommandObjectRenderScriptScriptGroup : public CommandObjectMultiword {
139*0b57cec5SDimitry Andric public:
CommandObjectRenderScriptScriptGroup(CommandInterpreter & interpreter)140*0b57cec5SDimitry Andric CommandObjectRenderScriptScriptGroup(CommandInterpreter &interpreter)
141*0b57cec5SDimitry Andric : CommandObjectMultiword(interpreter, "renderscript scriptgroup",
142*0b57cec5SDimitry Andric "Command set for interacting with scriptgroups.",
143*0b57cec5SDimitry Andric nullptr, eCommandRequiresProcess |
144*0b57cec5SDimitry Andric eCommandProcessMustBeLaunched) {
145*0b57cec5SDimitry Andric LoadSubCommand(
146*0b57cec5SDimitry Andric "breakpoint",
147*0b57cec5SDimitry Andric CommandObjectSP(
148*0b57cec5SDimitry Andric new CommandObjectRenderScriptScriptGroupBreakpoint(interpreter)));
149*0b57cec5SDimitry Andric LoadSubCommand(
150*0b57cec5SDimitry Andric "list", CommandObjectSP(
151*0b57cec5SDimitry Andric new CommandObjectRenderScriptScriptGroupList(interpreter)));
152*0b57cec5SDimitry Andric }
153*0b57cec5SDimitry Andric
154*0b57cec5SDimitry Andric ~CommandObjectRenderScriptScriptGroup() override = default;
155*0b57cec5SDimitry Andric };
156*0b57cec5SDimitry Andric
NewCommandObjectRenderScriptScriptGroup(lldb_private::CommandInterpreter & interpreter)157*0b57cec5SDimitry Andric lldb::CommandObjectSP NewCommandObjectRenderScriptScriptGroup(
158*0b57cec5SDimitry Andric lldb_private::CommandInterpreter &interpreter) {
159*0b57cec5SDimitry Andric return CommandObjectSP(new CommandObjectRenderScriptScriptGroup(interpreter));
160*0b57cec5SDimitry Andric }
161