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