15ec532a9SColin Riley //===-- RenderScriptRuntime.h -----------------------------------*- C++ -*-===// 25ec532a9SColin Riley // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 65ec532a9SColin Riley // 75ec532a9SColin Riley //===----------------------------------------------------------------------===// 85ec532a9SColin Riley 9cdc514e4SJonas Devlieghere #ifndef LLDB_SOURCE_PLUGINS_LANGUAGERUNTIME_RENDERSCRIPT_RENDERSCRIPTRUNTIME_RENDERSCRIPTRUNTIME_H 10cdc514e4SJonas Devlieghere #define LLDB_SOURCE_PLUGINS_LANGUAGERUNTIME_RENDERSCRIPT_RENDERSCRIPTRUNTIME_RENDERSCRIPTRUNTIME_H 115ec532a9SColin Riley 12222b937cSEugene Zelenko #include <array> 13222b937cSEugene Zelenko #include <map> 14222b937cSEugene Zelenko #include <memory> 15222b937cSEugene Zelenko #include <string> 16222b937cSEugene Zelenko #include <vector> 17222b937cSEugene Zelenko 187f193d69SLuke Drummond #include "llvm/ADT/SmallVector.h" 197f193d69SLuke Drummond #include "llvm/ADT/StringRef.h" 205ec532a9SColin Riley #include "lldb/Core/Module.h" 2119459580SLuke Drummond #include "lldb/Expression/LLVMUserExpression.h" 22b3f7f69dSAidan Dodds #include "lldb/Target/LanguageRuntime.h" 23b3f7f69dSAidan Dodds #include "lldb/lldb-private.h" 245ec532a9SColin Riley 25e0678ca5SAlex Langford #include "Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h" 26e0678ca5SAlex Langford 272637769bSAlex Langford namespace clang { 282637769bSAlex Langford class TargetOptions; 29534aeb0bSMartin Storsjö } 302637769bSAlex Langford 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; 3921fed052SAidan 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; 4421fed052SAidan Dodds typedef std::shared_ptr<RSScriptGroupDescriptor> RSScriptGroupDescriptorSP; 4521fed052SAidan Dodds 4600f56eebSLuke Drummond struct RSCoordinate { 479494c510SJonas Devlieghere uint32_t x = 0, y = 0, z = 0; 4800f56eebSLuke Drummond 49fd2433e1SJonas Devlieghere RSCoordinate() = default; 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: RSBreakpointResolver(const lldb::BreakpointSP & bp,ConstString name)616c17cc53STatyana Krasnukha RSBreakpointResolver(const lldb::BreakpointSP &bp, ConstString name) 6280af0b9eSLuke Drummond : BreakpointResolver(bp, BreakpointResolver::NameResolver), 63b9c1b51eSKate Stone m_kernel_name(name) {} 6498156583SEwan Crawford GetDescription(Stream * strm)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 Dump(Stream * s)71b9c1b51eSKate Stone void Dump(Stream *s) const override {} 7298156583SEwan Crawford 73b9c1b51eSKate Stone Searcher::CallbackReturn SearchCallback(SearchFilter &filter, 7495e264fcSRaphael Isemann SymbolContext &context, 7595e264fcSRaphael Isemann Address *addr) override; 7698156583SEwan Crawford GetDepth()774911d36aSJim Ingham lldb::SearchDepth GetDepth() override { return lldb::eSearchDepthModule; } 7898156583SEwan Crawford 7998156583SEwan Crawford lldb::BreakpointResolverSP CopyForBreakpoint(lldb::BreakpointSP & breakpoint)806c17cc53STatyana Krasnukha CopyForBreakpoint(lldb::BreakpointSP &breakpoint) override { 81b9c1b51eSKate Stone lldb::BreakpointResolverSP ret_sp( 826c17cc53STatyana Krasnukha 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( 1036c17cc53STatyana Krasnukha const lldb::BreakpointSP &breakpoint, ConstString reduce_name, 104b3bbcb12SLuke Drummond std::vector<lldb_renderscript::RSModuleDescriptorSP> *rs_modules, 105b3bbcb12SLuke Drummond int kernel_types = eKernelTypeAll) BreakpointResolver(breakpoint,BreakpointResolver::NameResolver)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 GetDescription(Stream * strm)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 Dump(Stream * s)121b3bbcb12SLuke Drummond void Dump(Stream *s) const override {} 122b3bbcb12SLuke Drummond 123b3bbcb12SLuke Drummond Searcher::CallbackReturn SearchCallback(SearchFilter &filter, 12495e264fcSRaphael Isemann SymbolContext &context, 12595e264fcSRaphael Isemann Address *addr) override; 126b3bbcb12SLuke Drummond GetDepth()1274911d36aSJim Ingham lldb::SearchDepth GetDepth() override { return lldb::eSearchDepthModule; } 128b3bbcb12SLuke Drummond 129b3bbcb12SLuke Drummond lldb::BreakpointResolverSP CopyForBreakpoint(lldb::BreakpointSP & breakpoint)1306c17cc53STatyana Krasnukha CopyForBreakpoint(lldb::BreakpointSP &breakpoint) override { 131b3bbcb12SLuke Drummond lldb::BreakpointResolverSP ret_sp(new RSReduceBreakpointResolver( 1326c17cc53STatyana Krasnukha 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: RSKernelDescriptorRSKernelDescriptor1447f193d69SLuke 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: RSGlobalDescriptorRSGlobalDescriptor1577f193d69SLuke 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 = ".") m_moduleRSReductionDescriptor1727f193d69SLuke 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), 174*459cfa5eSSlava Gurevich m_outc_name(outc_name), m_halter_name(halter_name), m_accum_sig(0), 175*459cfa5eSSlava Gurevich m_accum_data_size(0), m_comb_name_generated(false) { 1767f193d69SLuke Drummond // TODO Check whether the combiner is an autogenerated name, and track 1777f193d69SLuke Drummond // this 1787f193d69SLuke Drummond } 1797f193d69SLuke Drummond 1807f193d69SLuke Drummond void Dump(Stream &strm) const; 1817f193d69SLuke Drummond 1827f193d69SLuke Drummond const RSModuleDescriptor *m_module; 1837f193d69SLuke Drummond ConstString m_reduce_name; // This is the name given to the general reduction 1847f193d69SLuke Drummond // as a group as passed to pragma 1857f193d69SLuke Drummond // reduce(m_reduce_name). There is no kernel function with this name 1867f193d69SLuke Drummond ConstString m_init_name; // The name of the initializer name. "." if no 1877f193d69SLuke Drummond // initializer given 1887f193d69SLuke Drummond ConstString m_accum_name; // The accumulator function name. "." if not given 1897f193d69SLuke Drummond ConstString m_comb_name; // The name of the combiner function. If this was not 1907f193d69SLuke Drummond // given, a name is generated by the 1917f193d69SLuke Drummond // compiler. TODO 1927f193d69SLuke Drummond ConstString m_outc_name; // The name of the outconverter 1937f193d69SLuke Drummond 1947f193d69SLuke Drummond ConstString m_halter_name; // The name of the halter function. XXX This is not 1957f193d69SLuke Drummond // yet specified by the RenderScript 1967f193d69SLuke Drummond // compiler or runtime, and its semantics and existence is still under 1977f193d69SLuke Drummond // discussion by the 1987f193d69SLuke Drummond // RenderScript Contributors 1997f193d69SLuke Drummond RSSlot m_accum_sig; // metatdata signature for this reduction (bitwise mask of 2007f193d69SLuke Drummond // type information (see 2017f193d69SLuke Drummond // libbcc/include/bcinfo/MetadataExtractor.h 2027f193d69SLuke Drummond uint32_t m_accum_data_size; // Data size of the accumulator function input 2037f193d69SLuke Drummond bool m_comb_name_generated; // Was the combiner name generated by the compiler 2047f193d69SLuke Drummond }; 2057f193d69SLuke Drummond 206b9c1b51eSKate Stone class RSModuleDescriptor { 20747d64161SLuke Drummond std::string m_slang_version; 20847d64161SLuke Drummond std::string m_bcc_version; 20947d64161SLuke Drummond 21047d64161SLuke Drummond bool ParseVersionInfo(llvm::StringRef *, size_t n_lines); 21147d64161SLuke Drummond 2127f193d69SLuke Drummond bool ParseExportForeachCount(llvm::StringRef *, size_t n_lines); 2137f193d69SLuke Drummond 2147f193d69SLuke Drummond bool ParseExportVarCount(llvm::StringRef *, size_t n_lines); 2157f193d69SLuke Drummond 2167f193d69SLuke Drummond bool ParseExportReduceCount(llvm::StringRef *, size_t n_lines); 2177f193d69SLuke Drummond 2187f193d69SLuke Drummond bool ParseBuildChecksum(llvm::StringRef *, size_t n_lines); 2197f193d69SLuke Drummond 2207f193d69SLuke Drummond bool ParsePragmaCount(llvm::StringRef *, size_t n_lines); 2217f193d69SLuke Drummond 2225ec532a9SColin Riley public: RSModuleDescriptor(const lldb::ModuleSP & module)223b3f7f69dSAidan Dodds RSModuleDescriptor(const lldb::ModuleSP &module) : m_module(module) {} 2245ec532a9SColin Riley 225222b937cSEugene Zelenko ~RSModuleDescriptor() = default; 2265ec532a9SColin Riley 227b9c1b51eSKate Stone bool ParseRSInfo(); 2285ec532a9SColin Riley 229b9c1b51eSKate Stone void Dump(Stream &strm) const; 2305ec532a9SColin Riley 23147d64161SLuke Drummond void WarnIfVersionMismatch(Stream *s) const; 23247d64161SLuke Drummond 2335ec532a9SColin Riley const lldb::ModuleSP m_module; 2345ec532a9SColin Riley std::vector<RSKernelDescriptor> m_kernels; 2355ec532a9SColin Riley std::vector<RSGlobalDescriptor> m_globals; 2367f193d69SLuke Drummond std::vector<RSReductionDescriptor> m_reductions; 2374640cde1SColin Riley std::map<std::string, std::string> m_pragmas; 2384640cde1SColin Riley std::string m_resname; 2395ec532a9SColin Riley }; 2405ec532a9SColin Riley 24121fed052SAidan Dodds struct RSScriptGroupDescriptor { 24221fed052SAidan Dodds struct Kernel { 24321fed052SAidan Dodds ConstString m_name; 24421fed052SAidan Dodds lldb::addr_t m_addr; 24521fed052SAidan Dodds }; 24621fed052SAidan Dodds ConstString m_name; 24721fed052SAidan Dodds std::vector<Kernel> m_kernels; 24821fed052SAidan Dodds }; 24921fed052SAidan Dodds 25021fed052SAidan Dodds typedef std::vector<RSScriptGroupDescriptorSP> RSScriptGroupList; 25121fed052SAidan Dodds 25221fed052SAidan Dodds class RSScriptGroupBreakpointResolver : public BreakpointResolver { 25321fed052SAidan Dodds public: RSScriptGroupBreakpointResolver(const lldb::BreakpointSP & bp,ConstString name,const RSScriptGroupList & groups,bool stop_on_all)2546c17cc53STatyana Krasnukha RSScriptGroupBreakpointResolver(const lldb::BreakpointSP &bp, 2556c17cc53STatyana Krasnukha ConstString name, 25621fed052SAidan Dodds const RSScriptGroupList &groups, 25721fed052SAidan Dodds bool stop_on_all) 25821fed052SAidan Dodds : BreakpointResolver(bp, BreakpointResolver::NameResolver), 25921fed052SAidan Dodds m_group_name(name), m_script_groups(groups), 26021fed052SAidan Dodds m_stop_on_all(stop_on_all) {} 26121fed052SAidan Dodds GetDescription(Stream * strm)26221fed052SAidan Dodds void GetDescription(Stream *strm) override { 26321fed052SAidan Dodds if (strm) 26421fed052SAidan Dodds strm->Printf("RenderScript ScriptGroup breakpoint for '%s'", 26521fed052SAidan Dodds m_group_name.AsCString()); 26621fed052SAidan Dodds } 26721fed052SAidan Dodds Dump(Stream * s)26821fed052SAidan Dodds void Dump(Stream *s) const override {} 26921fed052SAidan Dodds 27021fed052SAidan Dodds Searcher::CallbackReturn SearchCallback(SearchFilter &filter, 27195e264fcSRaphael Isemann SymbolContext &context, 27295e264fcSRaphael Isemann Address *addr) override; 27321fed052SAidan Dodds GetDepth()2744911d36aSJim Ingham lldb::SearchDepth GetDepth() override { return lldb::eSearchDepthModule; } 27521fed052SAidan Dodds 27621fed052SAidan Dodds lldb::BreakpointResolverSP CopyForBreakpoint(lldb::BreakpointSP & breakpoint)2776c17cc53STatyana Krasnukha CopyForBreakpoint(lldb::BreakpointSP &breakpoint) override { 27821fed052SAidan Dodds lldb::BreakpointResolverSP ret_sp(new RSScriptGroupBreakpointResolver( 2796c17cc53STatyana Krasnukha breakpoint, m_group_name, m_script_groups, m_stop_on_all)); 28021fed052SAidan Dodds return ret_sp; 28121fed052SAidan Dodds } 28221fed052SAidan Dodds 28321fed052SAidan Dodds protected: 28421fed052SAidan Dodds const RSScriptGroupDescriptorSP FindScriptGroup(ConstString name)2850e4c4821SAdrian Prantl FindScriptGroup(ConstString name) const { 28621fed052SAidan Dodds for (auto sg : m_script_groups) { 28721fed052SAidan Dodds if (ConstString::Compare(sg->m_name, name) == 0) 28821fed052SAidan Dodds return sg; 28921fed052SAidan Dodds } 29021fed052SAidan Dodds return RSScriptGroupDescriptorSP(); 29121fed052SAidan Dodds } 29221fed052SAidan Dodds 29321fed052SAidan Dodds ConstString m_group_name; 29421fed052SAidan Dodds const RSScriptGroupList &m_script_groups; 29521fed052SAidan Dodds bool m_stop_on_all; 29621fed052SAidan Dodds }; 297222b937cSEugene Zelenko } // namespace lldb_renderscript 29898156583SEwan Crawford 299b9c1b51eSKate Stone class RenderScriptRuntime : public lldb_private::CPPLanguageRuntime { 3005ec532a9SColin Riley public: 301b9c1b51eSKate Stone enum ModuleKind { 302ef20b08fSColin Riley eModuleKindIgnored, 303ef20b08fSColin Riley eModuleKindLibRS, 304ef20b08fSColin Riley eModuleKindDriver, 305ef20b08fSColin Riley eModuleKindImpl, 306ef20b08fSColin Riley eModuleKindKernelObj 307ef20b08fSColin Riley }; 308ef20b08fSColin Riley 309222b937cSEugene Zelenko ~RenderScriptRuntime() override; 3105ec532a9SColin Riley 3115ec532a9SColin Riley // Static Functions 312b9c1b51eSKate Stone static void Initialize(); 3135ec532a9SColin Riley 314b9c1b51eSKate Stone static void Terminate(); 3155ec532a9SColin Riley 316b3f7f69dSAidan Dodds static lldb_private::LanguageRuntime * 317b3f7f69dSAidan Dodds CreateInstance(Process *process, lldb::LanguageType language); 3185ec532a9SColin Riley 319b3f7f69dSAidan Dodds static lldb::CommandObjectSP 320b3f7f69dSAidan Dodds GetCommandObject(CommandInterpreter &interpreter); 3214640cde1SColin Riley GetPluginNameStatic()32249481b53SPavel Labath static llvm::StringRef GetPluginNameStatic() { return "renderscript"; } 3235ec532a9SColin Riley 324056f6f18SAlex Langford static char ID; 325056f6f18SAlex Langford isA(const void * ClassID)326056f6f18SAlex Langford bool isA(const void *ClassID) const override { 327056f6f18SAlex Langford return ClassID == &ID || CPPLanguageRuntime::isA(ClassID); 328056f6f18SAlex Langford } 329056f6f18SAlex Langford classof(const LanguageRuntime * runtime)330056f6f18SAlex Langford static bool classof(const LanguageRuntime *runtime) { 331056f6f18SAlex Langford return runtime->isA(&ID); 332056f6f18SAlex Langford } 333056f6f18SAlex Langford 334b9c1b51eSKate Stone static bool IsRenderScriptModule(const lldb::ModuleSP &module_sp); 335ef20b08fSColin Riley 336b9c1b51eSKate Stone static ModuleKind GetModuleKind(const lldb::ModuleSP &module_sp); 337ef20b08fSColin Riley 338b9c1b51eSKate Stone static void ModulesDidLoad(const lldb::ProcessSP &process_sp, 339b9c1b51eSKate Stone const ModuleList &module_list); 340ef20b08fSColin Riley 341b9c1b51eSKate Stone bool GetDynamicTypeAndAddress(ValueObject &in_value, 342b9c1b51eSKate Stone lldb::DynamicValueType use_dynamic, 343b9c1b51eSKate Stone TypeAndOrName &class_type_or_name, 344b9c1b51eSKate Stone Address &address, 3455f57b6eeSEnrico Granata Value::ValueType &value_type) override; 346c74275bcSEnrico Granata 347b9c1b51eSKate Stone TypeAndOrName FixUpDynamicType(const TypeAndOrName &type_and_or_name, 348b9c1b51eSKate Stone ValueObject &static_value) override; 3495ec532a9SColin Riley 350b9c1b51eSKate Stone bool CouldHaveDynamicValue(ValueObject &in_value) override; 3515ec532a9SColin Riley 3526c17cc53STatyana Krasnukha lldb::BreakpointResolverSP 3536c17cc53STatyana Krasnukha CreateExceptionResolver(const lldb::BreakpointSP &bp, 3546c17cc53STatyana Krasnukha bool catch_bp, bool throw_bp) override; 3555ec532a9SColin Riley 356b9c1b51eSKate Stone bool LoadModule(const lldb::ModuleSP &module_sp); 3575ec532a9SColin Riley 358b9c1b51eSKate Stone void DumpModules(Stream &strm) const; 3595ec532a9SColin Riley 360b9c1b51eSKate Stone void DumpContexts(Stream &strm) const; 3614640cde1SColin Riley 362b9c1b51eSKate Stone void DumpKernels(Stream &strm) const; 3634640cde1SColin Riley 364b9c1b51eSKate Stone bool DumpAllocation(Stream &strm, StackFrame *frame_ptr, const uint32_t id); 365a0f08674SEwan Crawford 366b9c1b51eSKate Stone void ListAllocations(Stream &strm, StackFrame *frame_ptr, 367b9c1b51eSKate Stone const uint32_t index); 36815f2bd95SEwan Crawford 369b9c1b51eSKate Stone bool RecomputeAllAllocations(Stream &strm, StackFrame *frame_ptr); 3700d2bfcfbSEwan Crawford 37100f56eebSLuke Drummond bool PlaceBreakpointOnKernel( 37200f56eebSLuke Drummond lldb::TargetSP target, Stream &messages, const char *name, 37300f56eebSLuke Drummond const lldb_renderscript::RSCoordinate *coords = nullptr); 3744640cde1SColin Riley 375b3bbcb12SLuke Drummond bool PlaceBreakpointOnReduction( 376b3bbcb12SLuke Drummond lldb::TargetSP target, Stream &messages, const char *reduce_name, 377b3bbcb12SLuke Drummond const lldb_renderscript::RSCoordinate *coords = nullptr, 378b3bbcb12SLuke Drummond int kernel_types = ~(0)); 379b3bbcb12SLuke Drummond 38021fed052SAidan Dodds bool PlaceBreakpointOnScriptGroup(lldb::TargetSP target, Stream &strm, 3810e4c4821SAdrian Prantl ConstString name, bool stop_on_all); 38221fed052SAidan Dodds 383b9c1b51eSKate Stone void SetBreakAllKernels(bool do_break, lldb::TargetSP target); 3847dc7771cSEwan Crawford 38597206d57SZachary Turner void DumpStatus(Stream &strm) const; 3864640cde1SColin Riley 387b9c1b51eSKate Stone void ModulesDidLoad(const ModuleList &module_list) override; 388ef20b08fSColin Riley 389b9c1b51eSKate Stone bool LoadAllocation(Stream &strm, const uint32_t alloc_id, 390b9c1b51eSKate Stone const char *filename, StackFrame *frame_ptr); 39155232f09SEwan Crawford 392b9c1b51eSKate Stone bool SaveAllocation(Stream &strm, const uint32_t alloc_id, 393b9c1b51eSKate Stone const char *filename, StackFrame *frame_ptr); 39455232f09SEwan Crawford 395b9c1b51eSKate Stone void Update(); 396ef20b08fSColin Riley 397b9c1b51eSKate Stone void Initiate(); 398ef20b08fSColin Riley GetScriptGroups()39921fed052SAidan Dodds const lldb_renderscript::RSScriptGroupList &GetScriptGroups() const { 40021fed052SAidan Dodds return m_scriptGroups; 40121fed052SAidan Dodds }; 40221fed052SAidan Dodds IsKnownKernel(ConstString name)4030e4c4821SAdrian Prantl bool IsKnownKernel(ConstString name) { 40421fed052SAidan Dodds for (const auto &module : m_rsmodules) 40521fed052SAidan Dodds for (const auto &kernel : module->m_kernels) 40621fed052SAidan Dodds if (kernel.m_name == name) 40721fed052SAidan Dodds return true; 40821fed052SAidan Dodds return false; 40921fed052SAidan Dodds } 41021fed052SAidan Dodds 4112637769bSAlex Langford bool GetOverrideExprOptions(clang::TargetOptions &prototype); 4122637769bSAlex Langford 413222b937cSEugene Zelenko // PluginInterface protocol GetPluginName()41449481b53SPavel Labath llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); } 4154640cde1SColin Riley 416b9c1b51eSKate Stone static bool GetKernelCoordinate(lldb_renderscript::RSCoordinate &coord, 417b9c1b51eSKate Stone Thread *thread_ptr); 4184f8817c2SEwan Crawford 41921fed052SAidan Dodds bool ResolveKernelName(lldb::addr_t kernel_address, ConstString &name); 42021fed052SAidan Dodds 421222b937cSEugene Zelenko protected: 42215f2bd95SEwan Crawford struct ScriptDetails; 42315f2bd95SEwan Crawford struct AllocationDetails; 4248b244e21SEwan Crawford struct Element; 42515f2bd95SEwan Crawford 42621fed052SAidan Dodds lldb_renderscript::RSScriptGroupList m_scriptGroups; 42721fed052SAidan Dodds InitSearchFilter(lldb::TargetSP target)428b9c1b51eSKate Stone void InitSearchFilter(lldb::TargetSP target) { 4297dc7771cSEwan Crawford if (!m_filtersp) 430827c0122SJonas Devlieghere m_filtersp = 431827c0122SJonas Devlieghere std::make_shared<SearchFilterForUnconstrainedSearches>(target); 4327dc7771cSEwan Crawford } 4337dc7771cSEwan Crawford 434b9c1b51eSKate Stone void FixupScriptDetails(lldb_renderscript::RSModuleDescriptorSP rsmodule_sp); 4354640cde1SColin Riley 436b9c1b51eSKate Stone void LoadRuntimeHooks(lldb::ModuleSP module, ModuleKind kind); 4374640cde1SColin Riley 43880af0b9eSLuke Drummond bool RefreshAllocation(AllocationDetails *alloc, StackFrame *frame_ptr); 43915f2bd95SEwan Crawford 440b9c1b51eSKate Stone bool EvalRSExpression(const char *expression, StackFrame *frame_ptr, 441b9c1b51eSKate Stone uint64_t *result); 44215f2bd95SEwan Crawford 4430e4c4821SAdrian Prantl lldb::BreakpointSP CreateScriptGroupBreakpoint(ConstString name, 44421fed052SAidan Dodds bool multi); 44521fed052SAidan Dodds 4460e4c4821SAdrian Prantl lldb::BreakpointSP CreateKernelBreakpoint(ConstString name); 4477dc7771cSEwan Crawford 4480e4c4821SAdrian Prantl lldb::BreakpointSP CreateReductionBreakpoint(ConstString name, 449b3bbcb12SLuke Drummond int kernel_types); 450b3bbcb12SLuke Drummond 451b9c1b51eSKate Stone void BreakOnModuleKernels( 452b9c1b51eSKate Stone const lldb_renderscript::RSModuleDescriptorSP rsmodule_sp); 4537dc7771cSEwan Crawford 4544640cde1SColin Riley struct RuntimeHook; 455b9c1b51eSKate Stone typedef void (RenderScriptRuntime::*CaptureStateFn)( 456b9c1b51eSKate Stone RuntimeHook *hook_info, 457b3f7f69dSAidan Dodds ExecutionContext &context); // Please do this! 4584640cde1SColin Riley 459b9c1b51eSKate Stone struct HookDefn { 4604640cde1SColin Riley const char *name; 46182780287SAidan Dodds const char *symbol_name_m32; // mangled name for the 32 bit architectures 46282780287SAidan Dodds const char *symbol_name_m64; // mangled name for the 64 bit archs 4634640cde1SColin Riley uint32_t version; 4644640cde1SColin Riley ModuleKind kind; 4654640cde1SColin Riley CaptureStateFn grabber; 4664640cde1SColin Riley }; 4674640cde1SColin Riley 468b9c1b51eSKate Stone struct RuntimeHook { 4694640cde1SColin Riley lldb::addr_t address; 4704640cde1SColin Riley const HookDefn *defn; 4714640cde1SColin Riley lldb::BreakpointSP bp_sp; 4724640cde1SColin Riley }; 4734640cde1SColin Riley 4744640cde1SColin Riley typedef std::shared_ptr<RuntimeHook> RuntimeHookSP; 4754640cde1SColin Riley 4764640cde1SColin Riley lldb::ModuleSP m_libRS; 4774640cde1SColin Riley lldb::ModuleSP m_libRSDriver; 4784640cde1SColin Riley lldb::ModuleSP m_libRSCpuRef; 47998156583SEwan Crawford std::vector<lldb_renderscript::RSModuleDescriptorSP> m_rsmodules; 48078f339d1SEwan Crawford 48178f339d1SEwan Crawford std::vector<std::unique_ptr<ScriptDetails>> m_scripts; 48278f339d1SEwan Crawford std::vector<std::unique_ptr<AllocationDetails>> m_allocations; 4834640cde1SColin Riley 484b9c1b51eSKate Stone std::map<lldb::addr_t, lldb_renderscript::RSModuleDescriptorSP> 485b9c1b51eSKate Stone m_scriptMappings; 4864640cde1SColin Riley std::map<lldb::addr_t, RuntimeHookSP> m_runtimeHooks; 48700f56eebSLuke Drummond std::map<lldb::user_id_t, std::unique_ptr<lldb_renderscript::RSCoordinate>> 48800f56eebSLuke Drummond m_conditional_breaks; 4894640cde1SColin Riley 490b9c1b51eSKate Stone lldb::SearchFilterSP 491b9c1b51eSKate Stone m_filtersp; // Needed to create breakpoints through Target API 4927dc7771cSEwan Crawford 493ef20b08fSColin Riley bool m_initiated; 4944640cde1SColin Riley bool m_debuggerPresentFlagged; 4957dc7771cSEwan Crawford bool m_breakAllKernels; 4964640cde1SColin Riley static const HookDefn s_runtimeHookDefns[]; 4974640cde1SColin Riley static const size_t s_runtimeHookCount; 49819459580SLuke Drummond LLVMUserExpression::IRPasses *m_ir_passes; 4994640cde1SColin Riley 5005ec532a9SColin Riley private: 5015ec532a9SColin Riley RenderScriptRuntime(Process *process); // Call CreateInstance instead. 5024640cde1SColin Riley 503b9c1b51eSKate Stone static bool HookCallback(void *baton, StoppointCallbackContext *ctx, 504b9c1b51eSKate Stone lldb::user_id_t break_id, 5054640cde1SColin Riley lldb::user_id_t break_loc_id); 5064640cde1SColin Riley 507b9c1b51eSKate Stone static bool KernelBreakpointHit(void *baton, StoppointCallbackContext *ctx, 508b9c1b51eSKate Stone lldb::user_id_t break_id, 509b9c1b51eSKate Stone lldb::user_id_t break_loc_id); 510018f5a7eSEwan Crawford 511b9c1b51eSKate Stone void HookCallback(RuntimeHook *hook_info, ExecutionContext &context); 5124640cde1SColin Riley 51321fed052SAidan Dodds // Callback function when 'debugHintScriptGroup2' executes on the target. 51421fed052SAidan Dodds void CaptureDebugHintScriptGroup2(RuntimeHook *hook_info, 51521fed052SAidan Dodds ExecutionContext &context); 51621fed052SAidan Dodds 517b9c1b51eSKate Stone void CaptureScriptInit(RuntimeHook *hook_info, ExecutionContext &context); 5184640cde1SColin Riley 519b9c1b51eSKate Stone void CaptureAllocationInit(RuntimeHook *hook_info, ExecutionContext &context); 520a0f08674SEwan Crawford 521b9c1b51eSKate Stone void CaptureAllocationDestroy(RuntimeHook *hook_info, 522b9c1b51eSKate Stone ExecutionContext &context); 523b3f7f69dSAidan Dodds 524b9c1b51eSKate Stone void CaptureSetGlobalVar(RuntimeHook *hook_info, ExecutionContext &context); 525b3f7f69dSAidan Dodds 526b9c1b51eSKate Stone void CaptureScriptInvokeForEachMulti(RuntimeHook *hook_info, 527b9c1b51eSKate Stone ExecutionContext &context); 528b3f7f69dSAidan Dodds 529b9c1b51eSKate Stone AllocationDetails *FindAllocByID(Stream &strm, const uint32_t alloc_id); 530b3f7f69dSAidan Dodds 53180af0b9eSLuke Drummond std::shared_ptr<uint8_t> GetAllocationData(AllocationDetails *alloc, 532b9c1b51eSKate Stone StackFrame *frame_ptr); 533b3f7f69dSAidan Dodds 534b9c1b51eSKate Stone void SetElementSize(Element &elem); 535b3f7f69dSAidan Dodds 536b9c1b51eSKate Stone static bool GetFrameVarAsUnsigned(const lldb::StackFrameSP, 537b9c1b51eSKate Stone const char *var_name, uint64_t &val); 538b3f7f69dSAidan Dodds 539b9c1b51eSKate Stone void FindStructTypeName(Element &elem, StackFrame *frame_ptr); 540b3f7f69dSAidan Dodds 541b9c1b51eSKate Stone size_t PopulateElementHeaders(const std::shared_ptr<uint8_t> header_buffer, 542b9c1b51eSKate Stone size_t offset, const Element &elem); 543b9c1b51eSKate Stone 544b9c1b51eSKate Stone size_t CalculateElementHeaderSize(const Element &elem); 54526e52a70SEwan Crawford 54600f56eebSLuke Drummond void SetConditional(lldb::BreakpointSP bp, lldb_private::Stream &messages, 54700f56eebSLuke Drummond const lldb_renderscript::RSCoordinate &coord); 54815f2bd95SEwan Crawford // 54915f2bd95SEwan Crawford // Helper functions for jitting the runtime 55015f2bd95SEwan Crawford // 55115f2bd95SEwan Crawford 55280af0b9eSLuke Drummond bool JITDataPointer(AllocationDetails *alloc, StackFrame *frame_ptr, 553b3f7f69dSAidan Dodds uint32_t x = 0, uint32_t y = 0, uint32_t z = 0); 55415f2bd95SEwan Crawford 55580af0b9eSLuke Drummond bool JITTypePointer(AllocationDetails *alloc, StackFrame *frame_ptr); 55615f2bd95SEwan Crawford 55780af0b9eSLuke Drummond bool JITTypePacked(AllocationDetails *alloc, StackFrame *frame_ptr); 55815f2bd95SEwan Crawford 559b9c1b51eSKate Stone bool JITElementPacked(Element &elem, const lldb::addr_t context, 560b9c1b51eSKate Stone StackFrame *frame_ptr); 5618b244e21SEwan Crawford 56280af0b9eSLuke Drummond bool JITAllocationSize(AllocationDetails *alloc, StackFrame *frame_ptr); 563a0f08674SEwan Crawford 564b9c1b51eSKate Stone bool JITSubelements(Element &elem, const lldb::addr_t context, 565b9c1b51eSKate Stone StackFrame *frame_ptr); 566b3f7f69dSAidan Dodds 56780af0b9eSLuke Drummond bool JITAllocationStride(AllocationDetails *alloc, StackFrame *frame_ptr); 568a0f08674SEwan Crawford 56978f339d1SEwan Crawford // Search for a script detail object using a target address. 57078f339d1SEwan Crawford // If a script does not currently exist this function will return nullptr. 57178f339d1SEwan Crawford // If 'create' is true and there is no previous script with this address, 572b9c1b51eSKate Stone // then a new Script detail object will be created for this address and 573b9c1b51eSKate Stone // returned. 574b9c1b51eSKate Stone ScriptDetails *LookUpScript(lldb::addr_t address, bool create); 57578f339d1SEwan Crawford 576b9c1b51eSKate Stone // Search for a previously saved allocation detail object using a target 577b9c1b51eSKate Stone // address. 578b9c1b51eSKate Stone // If an allocation does not exist for this address then nullptr will be 579b9c1b51eSKate Stone // returned. 580b9c1b51eSKate Stone AllocationDetails *LookUpAllocation(lldb::addr_t address); 5815d057637SLuke Drummond 582b9c1b51eSKate Stone // Creates a new allocation with the specified address assigning a new ID and 583b9c1b51eSKate Stone // removes 5845d057637SLuke Drummond // any previous stored allocation which has the same address. 585b9c1b51eSKate Stone AllocationDetails *CreateAllocation(lldb::addr_t address); 58619459580SLuke Drummond 587b9c1b51eSKate Stone bool GetIRPasses(LLVMUserExpression::IRPasses &passes) override; 5885ec532a9SColin Riley }; 5895ec532a9SColin Riley 5905ec532a9SColin Riley } // namespace lldb_private 5915ec532a9SColin Riley 592cdc514e4SJonas Devlieghere #endif // LLDB_SOURCE_PLUGINS_LANGUAGERUNTIME_RENDERSCRIPT_RENDERSCRIPTRUNTIME_RENDERSCRIPTRUNTIME_H 593