15ec532a9SColin Riley //===-- RenderScriptRuntime.h -----------------------------------*- C++ -*-===// 25ec532a9SColin Riley // 35ec532a9SColin Riley // The LLVM Compiler Infrastructure 45ec532a9SColin Riley // 55ec532a9SColin Riley // This file is distributed under the University of Illinois Open Source 65ec532a9SColin Riley // License. See LICENSE.TXT for details. 75ec532a9SColin Riley // 85ec532a9SColin Riley //===----------------------------------------------------------------------===// 95ec532a9SColin Riley 105ec532a9SColin Riley #ifndef liblldb_RenderScriptRuntime_h_ 115ec532a9SColin Riley #define liblldb_RenderScriptRuntime_h_ 125ec532a9SColin Riley 135ec532a9SColin Riley // C Includes 145ec532a9SColin Riley // C++ Includes 15222b937cSEugene Zelenko #include <array> 16222b937cSEugene Zelenko #include <map> 17222b937cSEugene Zelenko #include <memory> 18222b937cSEugene Zelenko #include <string> 19222b937cSEugene Zelenko #include <vector> 20222b937cSEugene Zelenko 215ec532a9SColin Riley // Other libraries and framework includes 227f193d69SLuke Drummond #include "llvm/ADT/SmallVector.h" 237f193d69SLuke Drummond #include "llvm/ADT/StringRef.h" 245ec532a9SColin Riley // Project includes 255ec532a9SColin Riley #include "lldb/Core/Module.h" 2619459580SLuke Drummond #include "lldb/Expression/LLVMUserExpression.h" 27b3f7f69dSAidan Dodds #include "lldb/Target/CPPLanguageRuntime.h" 28b3f7f69dSAidan Dodds #include "lldb/Target/LanguageRuntime.h" 29b3f7f69dSAidan Dodds #include "lldb/lldb-private.h" 305ec532a9SColin Riley 31b9c1b51eSKate Stone namespace lldb_private { 32b9c1b51eSKate Stone namespace lldb_renderscript { 3398156583SEwan Crawford 345ec532a9SColin Riley typedef uint32_t RSSlot; 355ec532a9SColin Riley class RSModuleDescriptor; 364640cde1SColin Riley struct RSGlobalDescriptor; 374640cde1SColin Riley struct RSKernelDescriptor; 387f193d69SLuke Drummond struct RSReductionDescriptor; 39*21fed052SAidan Dodds struct RSScriptGroupDescriptor; 404640cde1SColin Riley 414640cde1SColin Riley typedef std::shared_ptr<RSModuleDescriptor> RSModuleDescriptorSP; 424640cde1SColin Riley typedef std::shared_ptr<RSGlobalDescriptor> RSGlobalDescriptorSP; 434640cde1SColin Riley typedef std::shared_ptr<RSKernelDescriptor> RSKernelDescriptorSP; 44*21fed052SAidan Dodds typedef std::shared_ptr<RSScriptGroupDescriptor> RSScriptGroupDescriptorSP; 45*21fed052SAidan Dodds 4600f56eebSLuke Drummond struct RSCoordinate { 4700f56eebSLuke Drummond uint32_t x, y, z; 4800f56eebSLuke Drummond 4900f56eebSLuke Drummond RSCoordinate() : x(), y(), z(){}; 5000f56eebSLuke Drummond 5100f56eebSLuke Drummond bool operator==(const lldb_renderscript::RSCoordinate &rhs) { 5200f56eebSLuke Drummond return x == rhs.x && y == rhs.y && z == rhs.z; 5300f56eebSLuke Drummond } 5400f56eebSLuke Drummond }; 554640cde1SColin Riley 5680af0b9eSLuke Drummond // Breakpoint Resolvers decide where a breakpoint is placed, so having our own 5780af0b9eSLuke Drummond // allows us to limit the search scope to RS kernel modules. As well as check 5880af0b9eSLuke Drummond // for .expand kernels as a fallback. 59b9c1b51eSKate Stone class RSBreakpointResolver : public BreakpointResolver { 6098156583SEwan Crawford public: 6180af0b9eSLuke Drummond RSBreakpointResolver(Breakpoint *bp, ConstString name) 6280af0b9eSLuke Drummond : BreakpointResolver(bp, BreakpointResolver::NameResolver), 63b9c1b51eSKate Stone m_kernel_name(name) {} 6498156583SEwan Crawford 65b9c1b51eSKate Stone void GetDescription(Stream *strm) override { 6698156583SEwan Crawford if (strm) 67b9c1b51eSKate Stone strm->Printf("RenderScript kernel breakpoint for '%s'", 68b9c1b51eSKate Stone m_kernel_name.AsCString()); 6998156583SEwan Crawford } 7098156583SEwan Crawford 71b9c1b51eSKate Stone void Dump(Stream *s) const override {} 7298156583SEwan Crawford 73b9c1b51eSKate Stone Searcher::CallbackReturn SearchCallback(SearchFilter &filter, 74b9c1b51eSKate Stone SymbolContext &context, Address *addr, 75b9c1b51eSKate Stone bool containing) override; 7698156583SEwan Crawford 77b9c1b51eSKate Stone Searcher::Depth GetDepth() override { return Searcher::eDepthModule; } 7898156583SEwan Crawford 7998156583SEwan Crawford lldb::BreakpointResolverSP 80b9c1b51eSKate Stone CopyForBreakpoint(Breakpoint &breakpoint) override { 81b9c1b51eSKate Stone lldb::BreakpointResolverSP ret_sp( 82b9c1b51eSKate Stone new RSBreakpointResolver(&breakpoint, m_kernel_name)); 8398156583SEwan Crawford return ret_sp; 8498156583SEwan Crawford } 8598156583SEwan Crawford 8698156583SEwan Crawford protected: 8798156583SEwan Crawford ConstString m_kernel_name; 8898156583SEwan Crawford }; 895ec532a9SColin Riley 90b3bbcb12SLuke Drummond class RSReduceBreakpointResolver : public BreakpointResolver { 91b3bbcb12SLuke Drummond public: 92b3bbcb12SLuke Drummond enum ReduceKernelTypeFlags { 93b3bbcb12SLuke Drummond eKernelTypeAll = ~(0), 94b3bbcb12SLuke Drummond eKernelTypeNone = 0, 95b3bbcb12SLuke Drummond eKernelTypeAccum = (1 << 0), 96b3bbcb12SLuke Drummond eKernelTypeInit = (1 << 1), 97b3bbcb12SLuke Drummond eKernelTypeComb = (1 << 2), 98b3bbcb12SLuke Drummond eKernelTypeOutC = (1 << 3), 99b3bbcb12SLuke Drummond eKernelTypeHalter = (1 << 4) 100b3bbcb12SLuke Drummond }; 101b3bbcb12SLuke Drummond 102b3bbcb12SLuke Drummond RSReduceBreakpointResolver( 103b3bbcb12SLuke Drummond Breakpoint *breakpoint, ConstString reduce_name, 104b3bbcb12SLuke Drummond std::vector<lldb_renderscript::RSModuleDescriptorSP> *rs_modules, 105b3bbcb12SLuke Drummond int kernel_types = eKernelTypeAll) 106b3bbcb12SLuke Drummond : BreakpointResolver(breakpoint, BreakpointResolver::NameResolver), 107b3bbcb12SLuke Drummond m_reduce_name(reduce_name), m_rsmodules(rs_modules), 108b3bbcb12SLuke Drummond m_kernel_types(kernel_types) { 109b3bbcb12SLuke Drummond // The reduce breakpoint resolver handles adding breakpoints for named 110b3bbcb12SLuke Drummond // reductions. 111b3bbcb12SLuke Drummond // Breakpoints will be resolved for all constituent kernels in the named 112b3bbcb12SLuke Drummond // reduction 113b3bbcb12SLuke Drummond } 114b3bbcb12SLuke Drummond 115b3bbcb12SLuke Drummond void GetDescription(Stream *strm) override { 116b3bbcb12SLuke Drummond if (strm) 117b3bbcb12SLuke Drummond strm->Printf("RenderScript reduce breakpoint for '%s'", 118b3bbcb12SLuke Drummond m_reduce_name.AsCString()); 119b3bbcb12SLuke Drummond } 120b3bbcb12SLuke Drummond 121b3bbcb12SLuke Drummond void Dump(Stream *s) const override {} 122b3bbcb12SLuke Drummond 123b3bbcb12SLuke Drummond Searcher::CallbackReturn SearchCallback(SearchFilter &filter, 124b3bbcb12SLuke Drummond SymbolContext &context, Address *addr, 125b3bbcb12SLuke Drummond bool containing) override; 126b3bbcb12SLuke Drummond 127b3bbcb12SLuke Drummond Searcher::Depth GetDepth() override { return Searcher::eDepthModule; } 128b3bbcb12SLuke Drummond 129b3bbcb12SLuke Drummond lldb::BreakpointResolverSP 130b3bbcb12SLuke Drummond CopyForBreakpoint(Breakpoint &breakpoint) override { 131b3bbcb12SLuke Drummond lldb::BreakpointResolverSP ret_sp(new RSReduceBreakpointResolver( 132b3bbcb12SLuke Drummond &breakpoint, m_reduce_name, m_rsmodules, m_kernel_types)); 133b3bbcb12SLuke Drummond return ret_sp; 134b3bbcb12SLuke Drummond } 135b3bbcb12SLuke Drummond 136b3bbcb12SLuke Drummond private: 137b3bbcb12SLuke Drummond ConstString m_reduce_name; // The name of the reduction 138b3bbcb12SLuke Drummond std::vector<lldb_renderscript::RSModuleDescriptorSP> *m_rsmodules; 139b3bbcb12SLuke Drummond int m_kernel_types; 140b3bbcb12SLuke Drummond }; 141b3bbcb12SLuke Drummond 142b9c1b51eSKate Stone struct RSKernelDescriptor { 1435ec532a9SColin Riley public: 1447f193d69SLuke Drummond RSKernelDescriptor(const RSModuleDescriptor *module, llvm::StringRef name, 145b9c1b51eSKate Stone uint32_t slot) 146b9c1b51eSKate Stone : m_module(module), m_name(name), m_slot(slot) {} 1475ec532a9SColin Riley 148b9c1b51eSKate Stone void Dump(Stream &strm) const; 1495ec532a9SColin Riley 1504640cde1SColin Riley const RSModuleDescriptor *m_module; 1515ec532a9SColin Riley ConstString m_name; 1525ec532a9SColin Riley RSSlot m_slot; 1535ec532a9SColin Riley }; 1545ec532a9SColin Riley 155b9c1b51eSKate Stone struct RSGlobalDescriptor { 1565ec532a9SColin Riley public: 1577f193d69SLuke Drummond RSGlobalDescriptor(const RSModuleDescriptor *module, llvm::StringRef name) 158b9c1b51eSKate Stone : m_module(module), m_name(name) {} 1595ec532a9SColin Riley 160b9c1b51eSKate Stone void Dump(Stream &strm) const; 1615ec532a9SColin Riley 1624640cde1SColin Riley const RSModuleDescriptor *m_module; 1635ec532a9SColin Riley ConstString m_name; 1645ec532a9SColin Riley }; 1655ec532a9SColin Riley 1667f193d69SLuke Drummond struct RSReductionDescriptor { 1677f193d69SLuke Drummond RSReductionDescriptor(const RSModuleDescriptor *module, uint32_t sig, 1687f193d69SLuke Drummond uint32_t accum_data_size, llvm::StringRef name, 1697f193d69SLuke Drummond llvm::StringRef init_name, llvm::StringRef accum_name, 1707f193d69SLuke Drummond llvm::StringRef comb_name, llvm::StringRef outc_name, 1717f193d69SLuke Drummond llvm::StringRef halter_name = ".") 1727f193d69SLuke Drummond : m_module(module), m_reduce_name(name), m_init_name(init_name), 1737f193d69SLuke Drummond m_accum_name(accum_name), m_comb_name(comb_name), 1747f193d69SLuke Drummond m_outc_name(outc_name), m_halter_name(halter_name) { 1757f193d69SLuke Drummond // TODO Check whether the combiner is an autogenerated name, and track 1767f193d69SLuke Drummond // this 1777f193d69SLuke Drummond } 1787f193d69SLuke Drummond 1797f193d69SLuke Drummond void Dump(Stream &strm) const; 1807f193d69SLuke Drummond 1817f193d69SLuke Drummond const RSModuleDescriptor *m_module; 1827f193d69SLuke Drummond ConstString m_reduce_name; // This is the name given to the general reduction 1837f193d69SLuke Drummond // as a group as passed to pragma 1847f193d69SLuke Drummond // reduce(m_reduce_name). There is no kernel function with this name 1857f193d69SLuke Drummond ConstString m_init_name; // The name of the initializer name. "." if no 1867f193d69SLuke Drummond // initializer given 1877f193d69SLuke Drummond ConstString m_accum_name; // The accumulator function name. "." if not given 1887f193d69SLuke Drummond ConstString m_comb_name; // The name of the combiner function. If this was not 1897f193d69SLuke Drummond // given, a name is generated by the 1907f193d69SLuke Drummond // compiler. TODO 1917f193d69SLuke Drummond ConstString m_outc_name; // The name of the outconverter 1927f193d69SLuke Drummond 1937f193d69SLuke Drummond ConstString m_halter_name; // The name of the halter function. XXX This is not 1947f193d69SLuke Drummond // yet specified by the RenderScript 1957f193d69SLuke Drummond // compiler or runtime, and its semantics and existence is still under 1967f193d69SLuke Drummond // discussion by the 1977f193d69SLuke Drummond // RenderScript Contributors 1987f193d69SLuke Drummond RSSlot m_accum_sig; // metatdata signature for this reduction (bitwise mask of 1997f193d69SLuke Drummond // type information (see 2007f193d69SLuke Drummond // libbcc/include/bcinfo/MetadataExtractor.h 2017f193d69SLuke Drummond uint32_t m_accum_data_size; // Data size of the accumulator function input 2027f193d69SLuke Drummond bool m_comb_name_generated; // Was the combiner name generated by the compiler 2037f193d69SLuke Drummond }; 2047f193d69SLuke Drummond 205b9c1b51eSKate Stone class RSModuleDescriptor { 2067f193d69SLuke Drummond bool ParseExportForeachCount(llvm::StringRef *, size_t n_lines); 2077f193d69SLuke Drummond 2087f193d69SLuke Drummond bool ParseExportVarCount(llvm::StringRef *, size_t n_lines); 2097f193d69SLuke Drummond 2107f193d69SLuke Drummond bool ParseExportReduceCount(llvm::StringRef *, size_t n_lines); 2117f193d69SLuke Drummond 2127f193d69SLuke Drummond bool ParseBuildChecksum(llvm::StringRef *, size_t n_lines); 2137f193d69SLuke Drummond 2147f193d69SLuke Drummond bool ParsePragmaCount(llvm::StringRef *, size_t n_lines); 2157f193d69SLuke Drummond 2165ec532a9SColin Riley public: 217b3f7f69dSAidan Dodds RSModuleDescriptor(const lldb::ModuleSP &module) : m_module(module) {} 2185ec532a9SColin Riley 219222b937cSEugene Zelenko ~RSModuleDescriptor() = default; 2205ec532a9SColin Riley 221b9c1b51eSKate Stone bool ParseRSInfo(); 2225ec532a9SColin Riley 223b9c1b51eSKate Stone void Dump(Stream &strm) const; 2245ec532a9SColin Riley 2255ec532a9SColin Riley const lldb::ModuleSP m_module; 2265ec532a9SColin Riley std::vector<RSKernelDescriptor> m_kernels; 2275ec532a9SColin Riley std::vector<RSGlobalDescriptor> m_globals; 2287f193d69SLuke Drummond std::vector<RSReductionDescriptor> m_reductions; 2294640cde1SColin Riley std::map<std::string, std::string> m_pragmas; 2304640cde1SColin Riley std::string m_resname; 2315ec532a9SColin Riley }; 2325ec532a9SColin Riley 233*21fed052SAidan Dodds struct RSScriptGroupDescriptor { 234*21fed052SAidan Dodds struct Kernel { 235*21fed052SAidan Dodds ConstString m_name; 236*21fed052SAidan Dodds lldb::addr_t m_addr; 237*21fed052SAidan Dodds }; 238*21fed052SAidan Dodds ConstString m_name; 239*21fed052SAidan Dodds std::vector<Kernel> m_kernels; 240*21fed052SAidan Dodds }; 241*21fed052SAidan Dodds 242*21fed052SAidan Dodds typedef std::vector<RSScriptGroupDescriptorSP> RSScriptGroupList; 243*21fed052SAidan Dodds 244*21fed052SAidan Dodds class RSScriptGroupBreakpointResolver : public BreakpointResolver { 245*21fed052SAidan Dodds public: 246*21fed052SAidan Dodds RSScriptGroupBreakpointResolver(Breakpoint *bp, const ConstString &name, 247*21fed052SAidan Dodds const RSScriptGroupList &groups, 248*21fed052SAidan Dodds bool stop_on_all) 249*21fed052SAidan Dodds : BreakpointResolver(bp, BreakpointResolver::NameResolver), 250*21fed052SAidan Dodds m_group_name(name), m_script_groups(groups), 251*21fed052SAidan Dodds m_stop_on_all(stop_on_all) {} 252*21fed052SAidan Dodds 253*21fed052SAidan Dodds void GetDescription(Stream *strm) override { 254*21fed052SAidan Dodds if (strm) 255*21fed052SAidan Dodds strm->Printf("RenderScript ScriptGroup breakpoint for '%s'", 256*21fed052SAidan Dodds m_group_name.AsCString()); 257*21fed052SAidan Dodds } 258*21fed052SAidan Dodds 259*21fed052SAidan Dodds void Dump(Stream *s) const override {} 260*21fed052SAidan Dodds 261*21fed052SAidan Dodds Searcher::CallbackReturn SearchCallback(SearchFilter &filter, 262*21fed052SAidan Dodds SymbolContext &context, Address *addr, 263*21fed052SAidan Dodds bool containing) override; 264*21fed052SAidan Dodds 265*21fed052SAidan Dodds Searcher::Depth GetDepth() override { return Searcher::eDepthModule; } 266*21fed052SAidan Dodds 267*21fed052SAidan Dodds lldb::BreakpointResolverSP 268*21fed052SAidan Dodds CopyForBreakpoint(Breakpoint &breakpoint) override { 269*21fed052SAidan Dodds lldb::BreakpointResolverSP ret_sp(new RSScriptGroupBreakpointResolver( 270*21fed052SAidan Dodds &breakpoint, m_group_name, m_script_groups, m_stop_on_all)); 271*21fed052SAidan Dodds return ret_sp; 272*21fed052SAidan Dodds } 273*21fed052SAidan Dodds 274*21fed052SAidan Dodds protected: 275*21fed052SAidan Dodds const RSScriptGroupDescriptorSP 276*21fed052SAidan Dodds FindScriptGroup(const ConstString &name) const { 277*21fed052SAidan Dodds for (auto sg : m_script_groups) { 278*21fed052SAidan Dodds if (ConstString::Compare(sg->m_name, name) == 0) 279*21fed052SAidan Dodds return sg; 280*21fed052SAidan Dodds } 281*21fed052SAidan Dodds return RSScriptGroupDescriptorSP(); 282*21fed052SAidan Dodds } 283*21fed052SAidan Dodds 284*21fed052SAidan Dodds ConstString m_group_name; 285*21fed052SAidan Dodds const RSScriptGroupList &m_script_groups; 286*21fed052SAidan Dodds bool m_stop_on_all; 287*21fed052SAidan Dodds }; 288222b937cSEugene Zelenko } // namespace lldb_renderscript 28998156583SEwan Crawford 290b9c1b51eSKate Stone class RenderScriptRuntime : public lldb_private::CPPLanguageRuntime { 2915ec532a9SColin Riley public: 292b9c1b51eSKate Stone enum ModuleKind { 293ef20b08fSColin Riley eModuleKindIgnored, 294ef20b08fSColin Riley eModuleKindLibRS, 295ef20b08fSColin Riley eModuleKindDriver, 296ef20b08fSColin Riley eModuleKindImpl, 297ef20b08fSColin Riley eModuleKindKernelObj 298ef20b08fSColin Riley }; 299ef20b08fSColin Riley 300222b937cSEugene Zelenko ~RenderScriptRuntime() override; 3015ec532a9SColin Riley 3025ec532a9SColin Riley //------------------------------------------------------------------ 3035ec532a9SColin Riley // Static Functions 3045ec532a9SColin Riley //------------------------------------------------------------------ 305b9c1b51eSKate Stone static void Initialize(); 3065ec532a9SColin Riley 307b9c1b51eSKate Stone static void Terminate(); 3085ec532a9SColin Riley 309b3f7f69dSAidan Dodds static lldb_private::LanguageRuntime * 310b3f7f69dSAidan Dodds CreateInstance(Process *process, lldb::LanguageType language); 3115ec532a9SColin Riley 312b3f7f69dSAidan Dodds static lldb::CommandObjectSP 313b3f7f69dSAidan Dodds GetCommandObject(CommandInterpreter &interpreter); 3144640cde1SColin Riley 315b9c1b51eSKate Stone static lldb_private::ConstString GetPluginNameStatic(); 3165ec532a9SColin Riley 317b9c1b51eSKate Stone static bool IsRenderScriptModule(const lldb::ModuleSP &module_sp); 318ef20b08fSColin Riley 319b9c1b51eSKate Stone static ModuleKind GetModuleKind(const lldb::ModuleSP &module_sp); 320ef20b08fSColin Riley 321b9c1b51eSKate Stone static void ModulesDidLoad(const lldb::ProcessSP &process_sp, 322b9c1b51eSKate Stone const ModuleList &module_list); 323ef20b08fSColin Riley 324b9c1b51eSKate Stone bool IsVTableName(const char *name) override; 3255ec532a9SColin Riley 326b9c1b51eSKate Stone bool GetDynamicTypeAndAddress(ValueObject &in_value, 327b9c1b51eSKate Stone lldb::DynamicValueType use_dynamic, 328b9c1b51eSKate Stone TypeAndOrName &class_type_or_name, 329b9c1b51eSKate Stone Address &address, 3305f57b6eeSEnrico Granata Value::ValueType &value_type) override; 331c74275bcSEnrico Granata 332b9c1b51eSKate Stone TypeAndOrName FixUpDynamicType(const TypeAndOrName &type_and_or_name, 333b9c1b51eSKate Stone ValueObject &static_value) override; 3345ec532a9SColin Riley 335b9c1b51eSKate Stone bool CouldHaveDynamicValue(ValueObject &in_value) override; 3365ec532a9SColin Riley 33780af0b9eSLuke Drummond lldb::BreakpointResolverSP CreateExceptionResolver(Breakpoint *bp, 338b9c1b51eSKate Stone bool catch_bp, 339b9c1b51eSKate Stone bool throw_bp) override; 3405ec532a9SColin Riley 341b9c1b51eSKate Stone bool LoadModule(const lldb::ModuleSP &module_sp); 3425ec532a9SColin Riley 343b9c1b51eSKate Stone void DumpModules(Stream &strm) const; 3445ec532a9SColin Riley 345b9c1b51eSKate Stone void DumpContexts(Stream &strm) const; 3464640cde1SColin Riley 347b9c1b51eSKate Stone void DumpKernels(Stream &strm) const; 3484640cde1SColin Riley 349b9c1b51eSKate Stone bool DumpAllocation(Stream &strm, StackFrame *frame_ptr, const uint32_t id); 350a0f08674SEwan Crawford 351b9c1b51eSKate Stone void ListAllocations(Stream &strm, StackFrame *frame_ptr, 352b9c1b51eSKate Stone const uint32_t index); 35315f2bd95SEwan Crawford 354b9c1b51eSKate Stone bool RecomputeAllAllocations(Stream &strm, StackFrame *frame_ptr); 3550d2bfcfbSEwan Crawford 35600f56eebSLuke Drummond bool PlaceBreakpointOnKernel( 35700f56eebSLuke Drummond lldb::TargetSP target, Stream &messages, const char *name, 35800f56eebSLuke Drummond const lldb_renderscript::RSCoordinate *coords = nullptr); 3594640cde1SColin Riley 360b3bbcb12SLuke Drummond bool PlaceBreakpointOnReduction( 361b3bbcb12SLuke Drummond lldb::TargetSP target, Stream &messages, const char *reduce_name, 362b3bbcb12SLuke Drummond const lldb_renderscript::RSCoordinate *coords = nullptr, 363b3bbcb12SLuke Drummond int kernel_types = ~(0)); 364b3bbcb12SLuke Drummond 365*21fed052SAidan Dodds bool PlaceBreakpointOnScriptGroup(lldb::TargetSP target, Stream &strm, 366*21fed052SAidan Dodds const ConstString &name, bool stop_on_all); 367*21fed052SAidan Dodds 368b9c1b51eSKate Stone void SetBreakAllKernels(bool do_break, lldb::TargetSP target); 3697dc7771cSEwan Crawford 370b9c1b51eSKate Stone void Status(Stream &strm) const; 3714640cde1SColin Riley 372b9c1b51eSKate Stone void ModulesDidLoad(const ModuleList &module_list) override; 373ef20b08fSColin Riley 374b9c1b51eSKate Stone bool LoadAllocation(Stream &strm, const uint32_t alloc_id, 375b9c1b51eSKate Stone const char *filename, StackFrame *frame_ptr); 37655232f09SEwan Crawford 377b9c1b51eSKate Stone bool SaveAllocation(Stream &strm, const uint32_t alloc_id, 378b9c1b51eSKate Stone const char *filename, StackFrame *frame_ptr); 37955232f09SEwan Crawford 380b9c1b51eSKate Stone void Update(); 381ef20b08fSColin Riley 382b9c1b51eSKate Stone void Initiate(); 383ef20b08fSColin Riley 384*21fed052SAidan Dodds const lldb_renderscript::RSScriptGroupList &GetScriptGroups() const { 385*21fed052SAidan Dodds return m_scriptGroups; 386*21fed052SAidan Dodds }; 387*21fed052SAidan Dodds 388*21fed052SAidan Dodds bool IsKnownKernel(const ConstString &name) { 389*21fed052SAidan Dodds for (const auto &module : m_rsmodules) 390*21fed052SAidan Dodds for (const auto &kernel : module->m_kernels) 391*21fed052SAidan Dodds if (kernel.m_name == name) 392*21fed052SAidan Dodds return true; 393*21fed052SAidan Dodds return false; 394*21fed052SAidan Dodds } 395*21fed052SAidan Dodds 396222b937cSEugene Zelenko //------------------------------------------------------------------ 397222b937cSEugene Zelenko // PluginInterface protocol 398222b937cSEugene Zelenko //------------------------------------------------------------------ 399b9c1b51eSKate Stone lldb_private::ConstString GetPluginName() override; 4004640cde1SColin Riley 401b9c1b51eSKate Stone uint32_t GetPluginVersion() override; 402222b937cSEugene Zelenko 403b9c1b51eSKate Stone static bool GetKernelCoordinate(lldb_renderscript::RSCoordinate &coord, 404b9c1b51eSKate Stone Thread *thread_ptr); 4054f8817c2SEwan Crawford 406*21fed052SAidan Dodds bool ResolveKernelName(lldb::addr_t kernel_address, ConstString &name); 407*21fed052SAidan Dodds 408222b937cSEugene Zelenko protected: 40915f2bd95SEwan Crawford struct ScriptDetails; 41015f2bd95SEwan Crawford struct AllocationDetails; 4118b244e21SEwan Crawford struct Element; 41215f2bd95SEwan Crawford 413*21fed052SAidan Dodds lldb_renderscript::RSScriptGroupList m_scriptGroups; 414*21fed052SAidan Dodds 415b9c1b51eSKate Stone void InitSearchFilter(lldb::TargetSP target) { 4167dc7771cSEwan Crawford if (!m_filtersp) 4177dc7771cSEwan Crawford m_filtersp.reset(new SearchFilterForUnconstrainedSearches(target)); 4187dc7771cSEwan Crawford } 4197dc7771cSEwan Crawford 420b9c1b51eSKate Stone void FixupScriptDetails(lldb_renderscript::RSModuleDescriptorSP rsmodule_sp); 4214640cde1SColin Riley 422b9c1b51eSKate Stone void LoadRuntimeHooks(lldb::ModuleSP module, ModuleKind kind); 4234640cde1SColin Riley 42480af0b9eSLuke Drummond bool RefreshAllocation(AllocationDetails *alloc, StackFrame *frame_ptr); 42515f2bd95SEwan Crawford 426b9c1b51eSKate Stone bool EvalRSExpression(const char *expression, StackFrame *frame_ptr, 427b9c1b51eSKate Stone uint64_t *result); 42815f2bd95SEwan Crawford 429*21fed052SAidan Dodds lldb::BreakpointSP CreateScriptGroupBreakpoint(const ConstString &name, 430*21fed052SAidan Dodds bool multi); 431*21fed052SAidan Dodds 432b9c1b51eSKate Stone lldb::BreakpointSP CreateKernelBreakpoint(const ConstString &name); 4337dc7771cSEwan Crawford 434b3bbcb12SLuke Drummond lldb::BreakpointSP CreateReductionBreakpoint(const ConstString &name, 435b3bbcb12SLuke Drummond int kernel_types); 436b3bbcb12SLuke Drummond 437b9c1b51eSKate Stone void BreakOnModuleKernels( 438b9c1b51eSKate Stone const lldb_renderscript::RSModuleDescriptorSP rsmodule_sp); 4397dc7771cSEwan Crawford 4404640cde1SColin Riley struct RuntimeHook; 441b9c1b51eSKate Stone typedef void (RenderScriptRuntime::*CaptureStateFn)( 442b9c1b51eSKate Stone RuntimeHook *hook_info, 443b3f7f69dSAidan Dodds ExecutionContext &context); // Please do this! 4444640cde1SColin Riley 445b9c1b51eSKate Stone struct HookDefn { 4464640cde1SColin Riley const char *name; 44782780287SAidan Dodds const char *symbol_name_m32; // mangled name for the 32 bit architectures 44882780287SAidan Dodds const char *symbol_name_m64; // mangled name for the 64 bit archs 4494640cde1SColin Riley uint32_t version; 4504640cde1SColin Riley ModuleKind kind; 4514640cde1SColin Riley CaptureStateFn grabber; 4524640cde1SColin Riley }; 4534640cde1SColin Riley 454b9c1b51eSKate Stone struct RuntimeHook { 4554640cde1SColin Riley lldb::addr_t address; 4564640cde1SColin Riley const HookDefn *defn; 4574640cde1SColin Riley lldb::BreakpointSP bp_sp; 4584640cde1SColin Riley }; 4594640cde1SColin Riley 4604640cde1SColin Riley typedef std::shared_ptr<RuntimeHook> RuntimeHookSP; 4614640cde1SColin Riley 4624640cde1SColin Riley lldb::ModuleSP m_libRS; 4634640cde1SColin Riley lldb::ModuleSP m_libRSDriver; 4644640cde1SColin Riley lldb::ModuleSP m_libRSCpuRef; 46598156583SEwan Crawford std::vector<lldb_renderscript::RSModuleDescriptorSP> m_rsmodules; 46678f339d1SEwan Crawford 46778f339d1SEwan Crawford std::vector<std::unique_ptr<ScriptDetails>> m_scripts; 46878f339d1SEwan Crawford std::vector<std::unique_ptr<AllocationDetails>> m_allocations; 4694640cde1SColin Riley 470b9c1b51eSKate Stone std::map<lldb::addr_t, lldb_renderscript::RSModuleDescriptorSP> 471b9c1b51eSKate Stone m_scriptMappings; 4724640cde1SColin Riley std::map<lldb::addr_t, RuntimeHookSP> m_runtimeHooks; 47300f56eebSLuke Drummond std::map<lldb::user_id_t, std::unique_ptr<lldb_renderscript::RSCoordinate>> 47400f56eebSLuke Drummond m_conditional_breaks; 4754640cde1SColin Riley 476b9c1b51eSKate Stone lldb::SearchFilterSP 477b9c1b51eSKate Stone m_filtersp; // Needed to create breakpoints through Target API 4787dc7771cSEwan Crawford 479ef20b08fSColin Riley bool m_initiated; 4804640cde1SColin Riley bool m_debuggerPresentFlagged; 4817dc7771cSEwan Crawford bool m_breakAllKernels; 4824640cde1SColin Riley static const HookDefn s_runtimeHookDefns[]; 4834640cde1SColin Riley static const size_t s_runtimeHookCount; 48419459580SLuke Drummond LLVMUserExpression::IRPasses *m_ir_passes; 4854640cde1SColin Riley 4865ec532a9SColin Riley private: 4875ec532a9SColin Riley RenderScriptRuntime(Process *process); // Call CreateInstance instead. 4884640cde1SColin Riley 489b9c1b51eSKate Stone static bool HookCallback(void *baton, StoppointCallbackContext *ctx, 490b9c1b51eSKate Stone lldb::user_id_t break_id, 4914640cde1SColin Riley lldb::user_id_t break_loc_id); 4924640cde1SColin Riley 493b9c1b51eSKate Stone static bool KernelBreakpointHit(void *baton, StoppointCallbackContext *ctx, 494b9c1b51eSKate Stone lldb::user_id_t break_id, 495b9c1b51eSKate Stone lldb::user_id_t break_loc_id); 496018f5a7eSEwan Crawford 497b9c1b51eSKate Stone void HookCallback(RuntimeHook *hook_info, ExecutionContext &context); 4984640cde1SColin Riley 499*21fed052SAidan Dodds // Callback function when 'debugHintScriptGroup2' executes on the target. 500*21fed052SAidan Dodds void CaptureDebugHintScriptGroup2(RuntimeHook *hook_info, 501*21fed052SAidan Dodds ExecutionContext &context); 502*21fed052SAidan Dodds 503b9c1b51eSKate Stone void CaptureScriptInit(RuntimeHook *hook_info, ExecutionContext &context); 5044640cde1SColin Riley 505b9c1b51eSKate Stone void CaptureAllocationInit(RuntimeHook *hook_info, ExecutionContext &context); 506a0f08674SEwan Crawford 507b9c1b51eSKate Stone void CaptureAllocationDestroy(RuntimeHook *hook_info, 508b9c1b51eSKate Stone ExecutionContext &context); 509b3f7f69dSAidan Dodds 510b9c1b51eSKate Stone void CaptureSetGlobalVar(RuntimeHook *hook_info, ExecutionContext &context); 511b3f7f69dSAidan Dodds 512b9c1b51eSKate Stone void CaptureScriptInvokeForEachMulti(RuntimeHook *hook_info, 513b9c1b51eSKate Stone ExecutionContext &context); 514b3f7f69dSAidan Dodds 515b9c1b51eSKate Stone AllocationDetails *FindAllocByID(Stream &strm, const uint32_t alloc_id); 516b3f7f69dSAidan Dodds 51780af0b9eSLuke Drummond std::shared_ptr<uint8_t> GetAllocationData(AllocationDetails *alloc, 518b9c1b51eSKate Stone StackFrame *frame_ptr); 519b3f7f69dSAidan Dodds 520b9c1b51eSKate Stone void SetElementSize(Element &elem); 521b3f7f69dSAidan Dodds 522b9c1b51eSKate Stone static bool GetFrameVarAsUnsigned(const lldb::StackFrameSP, 523b9c1b51eSKate Stone const char *var_name, uint64_t &val); 524b3f7f69dSAidan Dodds 525b9c1b51eSKate Stone void FindStructTypeName(Element &elem, StackFrame *frame_ptr); 526b3f7f69dSAidan Dodds 527b9c1b51eSKate Stone size_t PopulateElementHeaders(const std::shared_ptr<uint8_t> header_buffer, 528b9c1b51eSKate Stone size_t offset, const Element &elem); 529b9c1b51eSKate Stone 530b9c1b51eSKate Stone size_t CalculateElementHeaderSize(const Element &elem); 53126e52a70SEwan Crawford 53200f56eebSLuke Drummond void SetConditional(lldb::BreakpointSP bp, lldb_private::Stream &messages, 53300f56eebSLuke Drummond const lldb_renderscript::RSCoordinate &coord); 53415f2bd95SEwan Crawford // 53515f2bd95SEwan Crawford // Helper functions for jitting the runtime 53615f2bd95SEwan Crawford // 53715f2bd95SEwan Crawford 53880af0b9eSLuke Drummond bool JITDataPointer(AllocationDetails *alloc, StackFrame *frame_ptr, 539b3f7f69dSAidan Dodds uint32_t x = 0, uint32_t y = 0, uint32_t z = 0); 54015f2bd95SEwan Crawford 54180af0b9eSLuke Drummond bool JITTypePointer(AllocationDetails *alloc, StackFrame *frame_ptr); 54215f2bd95SEwan Crawford 54380af0b9eSLuke Drummond bool JITTypePacked(AllocationDetails *alloc, StackFrame *frame_ptr); 54415f2bd95SEwan Crawford 545b9c1b51eSKate Stone bool JITElementPacked(Element &elem, const lldb::addr_t context, 546b9c1b51eSKate Stone StackFrame *frame_ptr); 5478b244e21SEwan Crawford 54880af0b9eSLuke Drummond bool JITAllocationSize(AllocationDetails *alloc, StackFrame *frame_ptr); 549a0f08674SEwan Crawford 550b9c1b51eSKate Stone bool JITSubelements(Element &elem, const lldb::addr_t context, 551b9c1b51eSKate Stone StackFrame *frame_ptr); 552b3f7f69dSAidan Dodds 55380af0b9eSLuke Drummond bool JITAllocationStride(AllocationDetails *alloc, StackFrame *frame_ptr); 554a0f08674SEwan Crawford 55578f339d1SEwan Crawford // Search for a script detail object using a target address. 55678f339d1SEwan Crawford // If a script does not currently exist this function will return nullptr. 55778f339d1SEwan Crawford // If 'create' is true and there is no previous script with this address, 558b9c1b51eSKate Stone // then a new Script detail object will be created for this address and 559b9c1b51eSKate Stone // returned. 560b9c1b51eSKate Stone ScriptDetails *LookUpScript(lldb::addr_t address, bool create); 56178f339d1SEwan Crawford 562b9c1b51eSKate Stone // Search for a previously saved allocation detail object using a target 563b9c1b51eSKate Stone // address. 564b9c1b51eSKate Stone // If an allocation does not exist for this address then nullptr will be 565b9c1b51eSKate Stone // returned. 566b9c1b51eSKate Stone AllocationDetails *LookUpAllocation(lldb::addr_t address); 5675d057637SLuke Drummond 568b9c1b51eSKate Stone // Creates a new allocation with the specified address assigning a new ID and 569b9c1b51eSKate Stone // removes 5705d057637SLuke Drummond // any previous stored allocation which has the same address. 571b9c1b51eSKate Stone AllocationDetails *CreateAllocation(lldb::addr_t address); 57219459580SLuke Drummond 573b9c1b51eSKate Stone bool GetOverrideExprOptions(clang::TargetOptions &prototype) override; 57419459580SLuke Drummond 575b9c1b51eSKate Stone bool GetIRPasses(LLVMUserExpression::IRPasses &passes) override; 5765ec532a9SColin Riley }; 5775ec532a9SColin Riley 5785ec532a9SColin Riley } // namespace lldb_private 5795ec532a9SColin Riley 5805ec532a9SColin Riley #endif // liblldb_RenderScriptRuntime_h_ 581