Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 1 | //===-- RenderScriptRuntime.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 | |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 10 | // C Includes |
| 11 | // C++ Includes |
| 12 | // Other libraries and framework includes |
| 13 | // Project includes |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 14 | #include "RenderScriptRuntime.h" |
| 15 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 16 | #include "lldb/Breakpoint/StoppointCallbackContext.h" |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 17 | #include "lldb/Core/ConstString.h" |
| 18 | #include "lldb/Core/Debugger.h" |
| 19 | #include "lldb/Core/Error.h" |
| 20 | #include "lldb/Core/Log.h" |
| 21 | #include "lldb/Core/PluginManager.h" |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 22 | #include "lldb/Core/RegularExpression.h" |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 23 | #include "lldb/Core/ValueObjectVariable.h" |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 24 | #include "lldb/DataFormatters/DumpValueObjectOptions.h" |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 25 | #include "lldb/Expression/UserExpression.h" |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 26 | #include "lldb/Host/StringConvert.h" |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 27 | #include "lldb/Interpreter/Args.h" |
| 28 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 29 | #include "lldb/Interpreter/CommandObjectMultiword.h" |
| 30 | #include "lldb/Interpreter/CommandReturnObject.h" |
| 31 | #include "lldb/Interpreter/Options.h" |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 32 | #include "lldb/Symbol/Symbol.h" |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 33 | #include "lldb/Symbol/Type.h" |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 34 | #include "lldb/Symbol/VariableList.h" |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 35 | #include "lldb/Target/Process.h" |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 36 | #include "lldb/Target/RegisterContext.h" |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 37 | #include "lldb/Target/Target.h" |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 38 | #include "lldb/Target/Thread.h" |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 39 | |
| 40 | using namespace lldb; |
| 41 | using namespace lldb_private; |
Ewan Crawford | 9815658 | 2015-09-04 08:56:52 +0000 | [diff] [blame] | 42 | using namespace lldb_renderscript; |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 43 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 44 | namespace |
| 45 | { |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 46 | |
| 47 | // The empirical_type adds a basic level of validation to arbitrary data |
| 48 | // allowing us to track if data has been discovered and stored or not. |
| 49 | // An empirical_type will be marked as valid only if it has been explicitly assigned to. |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 50 | template <typename type_t> class empirical_type |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 51 | { |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 52 | public: |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 53 | // Ctor. Contents is invalid when constructed. |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 54 | empirical_type() : valid(false) {} |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 55 | |
| 56 | // Return true and copy contents to out if valid, else return false. |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 57 | bool |
| 58 | get(type_t &out) const |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 59 | { |
| 60 | if (valid) |
| 61 | out = data; |
| 62 | return valid; |
| 63 | } |
| 64 | |
| 65 | // Return a pointer to the contents or nullptr if it was not valid. |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 66 | const type_t * |
| 67 | get() const |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 68 | { |
| 69 | return valid ? &data : nullptr; |
| 70 | } |
| 71 | |
| 72 | // Assign data explicitly. |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 73 | void |
| 74 | set(const type_t in) |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 75 | { |
| 76 | data = in; |
| 77 | valid = true; |
| 78 | } |
| 79 | |
| 80 | // Mark contents as invalid. |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 81 | void |
| 82 | invalidate() |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 83 | { |
| 84 | valid = false; |
| 85 | } |
| 86 | |
| 87 | // Returns true if this type contains valid data. |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 88 | bool |
| 89 | isValid() const |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 90 | { |
| 91 | return valid; |
| 92 | } |
| 93 | |
| 94 | // Assignment operator. |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 95 | empirical_type<type_t> & |
| 96 | operator=(const type_t in) |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 97 | { |
| 98 | set(in); |
| 99 | return *this; |
| 100 | } |
| 101 | |
| 102 | // Dereference operator returns contents. |
| 103 | // Warning: Will assert if not valid so use only when you know data is valid. |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 104 | const type_t &operator*() const |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 105 | { |
| 106 | assert(valid); |
| 107 | return data; |
| 108 | } |
| 109 | |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 110 | protected: |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 111 | bool valid; |
| 112 | type_t data; |
| 113 | }; |
| 114 | |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 115 | // ArgItem is used by the GetArgs() function when reading function arguments from the target. |
| 116 | struct ArgItem |
| 117 | { |
| 118 | enum |
| 119 | { |
| 120 | ePointer, |
| 121 | eInt32, |
| 122 | eInt64, |
| 123 | eLong, |
| 124 | eBool |
| 125 | } type; |
| 126 | |
| 127 | uint64_t value; |
| 128 | |
| 129 | explicit operator uint64_t() const { return value; } |
| 130 | }; |
| 131 | |
| 132 | // Context structure to be passed into GetArgsXXX(), argument reading functions below. |
| 133 | struct GetArgsCtx |
| 134 | { |
| 135 | RegisterContext *reg_ctx; |
| 136 | Process *process; |
| 137 | }; |
| 138 | |
| 139 | bool |
| 140 | GetArgsX86(const GetArgsCtx &ctx, ArgItem *arg_list, size_t num_args) |
| 141 | { |
| 142 | Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE); |
| 143 | |
Aidan Dodds | 67dc3e1 | 2016-03-10 17:50:01 +0000 | [diff] [blame] | 144 | Error error; |
| 145 | |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 146 | // get the current stack pointer |
| 147 | uint64_t sp = ctx.reg_ctx->GetSP(); |
| 148 | |
| 149 | for (size_t i = 0; i < num_args; ++i) |
| 150 | { |
| 151 | ArgItem &arg = arg_list[i]; |
| 152 | // advance up the stack by one argument |
| 153 | sp += sizeof(uint32_t); |
| 154 | // get the argument type size |
| 155 | size_t arg_size = sizeof(uint32_t); |
| 156 | // read the argument from memory |
| 157 | arg.value = 0; |
| 158 | Error error; |
| 159 | size_t read = ctx.process->ReadMemory(sp, &arg.value, sizeof(uint32_t), error); |
| 160 | if (read != arg_size || !error.Success()) |
| 161 | { |
| 162 | if (log) |
| 163 | log->Printf("%s - error reading argument: %" PRIu64 " '%s'", __FUNCTION__, uint64_t(i), |
| 164 | error.AsCString()); |
| 165 | return false; |
| 166 | } |
| 167 | } |
| 168 | return true; |
| 169 | } |
| 170 | |
| 171 | bool |
| 172 | GetArgsX86_64(GetArgsCtx &ctx, ArgItem *arg_list, size_t num_args) |
| 173 | { |
| 174 | Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE); |
| 175 | |
| 176 | // number of arguments passed in registers |
| 177 | static const uint32_t c_args_in_reg = 6; |
| 178 | // register passing order |
Saleem Abdulrasool | 1ee0725 | 2016-02-15 21:50:28 +0000 | [diff] [blame] | 179 | static const std::array<const char *, c_args_in_reg> c_reg_names{{"rdi", "rsi", "rdx", "rcx", "r8", "r9"}}; |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 180 | // argument type to size mapping |
Saleem Abdulrasool | 1ee0725 | 2016-02-15 21:50:28 +0000 | [diff] [blame] | 181 | static const std::array<size_t, 5> arg_size{{ |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 182 | 8, // ePointer, |
| 183 | 4, // eInt32, |
| 184 | 8, // eInt64, |
| 185 | 8, // eLong, |
| 186 | 4, // eBool, |
Saleem Abdulrasool | 1ee0725 | 2016-02-15 21:50:28 +0000 | [diff] [blame] | 187 | }}; |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 188 | |
Aidan Dodds | 17e07c0 | 2016-03-10 17:27:41 +0000 | [diff] [blame] | 189 | Error error; |
| 190 | |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 191 | // get the current stack pointer |
| 192 | uint64_t sp = ctx.reg_ctx->GetSP(); |
| 193 | // step over the return address |
| 194 | sp += sizeof(uint64_t); |
| 195 | |
| 196 | // check the stack alignment was correct (16 byte aligned) |
| 197 | if ((sp & 0xf) != 0x0) |
| 198 | { |
| 199 | if (log) |
| 200 | log->Printf("%s - stack misaligned", __FUNCTION__); |
| 201 | return false; |
| 202 | } |
| 203 | |
| 204 | // find the start of arguments on the stack |
| 205 | uint64_t sp_offset = 0; |
| 206 | for (uint32_t i = c_args_in_reg; i < num_args; ++i) |
| 207 | { |
| 208 | sp_offset += arg_size[arg_list[i].type]; |
| 209 | } |
| 210 | // round up to multiple of 16 |
| 211 | sp_offset = (sp_offset + 0xf) & 0xf; |
| 212 | sp += sp_offset; |
| 213 | |
| 214 | for (size_t i = 0; i < num_args; ++i) |
| 215 | { |
| 216 | bool success = false; |
| 217 | ArgItem &arg = arg_list[i]; |
| 218 | // arguments passed in registers |
| 219 | if (i < c_args_in_reg) |
| 220 | { |
| 221 | const RegisterInfo *rArg = ctx.reg_ctx->GetRegisterInfoByName(c_reg_names[i]); |
| 222 | RegisterValue rVal; |
| 223 | if (ctx.reg_ctx->ReadRegister(rArg, rVal)) |
| 224 | arg.value = rVal.GetAsUInt64(0, &success); |
| 225 | } |
| 226 | // arguments passed on the stack |
| 227 | else |
| 228 | { |
| 229 | // get the argument type size |
| 230 | const size_t size = arg_size[arg_list[i].type]; |
| 231 | // read the argument from memory |
| 232 | arg.value = 0; |
| 233 | // note: due to little endian layout reading 4 or 8 bytes will give the correct value. |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 234 | size_t read = ctx.process->ReadMemory(sp, &arg.value, size, error); |
| 235 | success = (error.Success() && read==size); |
| 236 | // advance past this argument |
| 237 | sp -= size; |
| 238 | } |
| 239 | // fail if we couldn't read this argument |
| 240 | if (!success) |
| 241 | { |
| 242 | if (log) |
Aidan Dodds | 17e07c0 | 2016-03-10 17:27:41 +0000 | [diff] [blame] | 243 | log->Printf("%s - error reading argument: %" PRIu64", reason: %s", |
| 244 | __FUNCTION__, uint64_t(i), error.AsCString("n/a")); |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 245 | return false; |
| 246 | } |
| 247 | } |
| 248 | return true; |
| 249 | } |
| 250 | |
| 251 | bool |
| 252 | GetArgsArm(GetArgsCtx &ctx, ArgItem *arg_list, size_t num_args) |
| 253 | { |
| 254 | // number of arguments passed in registers |
| 255 | static const uint32_t c_args_in_reg = 4; |
| 256 | |
| 257 | Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE); |
| 258 | |
Aidan Dodds | 17e07c0 | 2016-03-10 17:27:41 +0000 | [diff] [blame] | 259 | Error error; |
| 260 | |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 261 | // get the current stack pointer |
| 262 | uint64_t sp = ctx.reg_ctx->GetSP(); |
| 263 | |
| 264 | for (size_t i = 0; i < num_args; ++i) |
| 265 | { |
| 266 | bool success = false; |
| 267 | ArgItem &arg = arg_list[i]; |
| 268 | // arguments passed in registers |
| 269 | if (i < c_args_in_reg) |
| 270 | { |
| 271 | const RegisterInfo *rArg = ctx.reg_ctx->GetRegisterInfoAtIndex(i); |
| 272 | RegisterValue rVal; |
| 273 | if (ctx.reg_ctx->ReadRegister(rArg, rVal)) |
| 274 | arg.value = rVal.GetAsUInt32(0, &success); |
| 275 | } |
| 276 | // arguments passed on the stack |
| 277 | else |
| 278 | { |
| 279 | // get the argument type size |
| 280 | const size_t arg_size = sizeof(uint32_t); |
| 281 | // clear all 64bits |
| 282 | arg.value = 0; |
| 283 | // read this argument from memory |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 284 | size_t bytes_read = ctx.process->ReadMemory(sp, &arg.value, arg_size, error); |
| 285 | success = (error.Success() && bytes_read == arg_size); |
| 286 | // advance the stack pointer |
| 287 | sp += sizeof(uint32_t); |
| 288 | } |
| 289 | // fail if we couldn't read this argument |
| 290 | if (!success) |
| 291 | { |
| 292 | if (log) |
Aidan Dodds | 17e07c0 | 2016-03-10 17:27:41 +0000 | [diff] [blame] | 293 | log->Printf("%s - error reading argument: %" PRIu64", reason: %s", |
| 294 | __FUNCTION__, uint64_t(i), error.AsCString("n/a")); |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 295 | return false; |
| 296 | } |
| 297 | } |
| 298 | return true; |
| 299 | } |
| 300 | |
| 301 | bool |
| 302 | GetArgsAarch64(GetArgsCtx &ctx, ArgItem *arg_list, size_t num_args) |
| 303 | { |
| 304 | // number of arguments passed in registers |
| 305 | static const uint32_t c_args_in_reg = 8; |
| 306 | |
| 307 | Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE); |
| 308 | |
| 309 | for (size_t i = 0; i < num_args; ++i) |
| 310 | { |
| 311 | bool success = false; |
| 312 | ArgItem &arg = arg_list[i]; |
| 313 | // arguments passed in registers |
| 314 | if (i < c_args_in_reg) |
| 315 | { |
| 316 | const RegisterInfo *rArg = ctx.reg_ctx->GetRegisterInfoAtIndex(i); |
| 317 | RegisterValue rVal; |
| 318 | if (ctx.reg_ctx->ReadRegister(rArg, rVal)) |
| 319 | arg.value = rVal.GetAsUInt64(0, &success); |
| 320 | } |
| 321 | // arguments passed on the stack |
| 322 | else |
| 323 | { |
| 324 | if (log) |
| 325 | log->Printf("%s - reading arguments spilled to stack not implemented", __FUNCTION__); |
| 326 | } |
| 327 | // fail if we couldn't read this argument |
| 328 | if (!success) |
| 329 | { |
| 330 | if (log) |
| 331 | log->Printf("%s - error reading argument: %" PRIu64, __FUNCTION__, |
| 332 | uint64_t(i)); |
| 333 | return false; |
| 334 | } |
| 335 | } |
| 336 | return true; |
| 337 | } |
| 338 | |
| 339 | bool |
| 340 | GetArgsMipsel(GetArgsCtx &ctx, ArgItem *arg_list, size_t num_args) |
| 341 | { |
| 342 | // number of arguments passed in registers |
| 343 | static const uint32_t c_args_in_reg = 4; |
| 344 | // register file offset to first argument |
| 345 | static const uint32_t c_reg_offset = 4; |
| 346 | |
| 347 | Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE); |
| 348 | |
Aidan Dodds | 17e07c0 | 2016-03-10 17:27:41 +0000 | [diff] [blame] | 349 | Error error; |
| 350 | |
| 351 | // find offset to arguments on the stack (+16 to skip over a0-a3 shadow space) |
| 352 | uint64_t sp = ctx.reg_ctx->GetSP() + 16; |
| 353 | |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 354 | for (size_t i = 0; i < num_args; ++i) |
| 355 | { |
| 356 | bool success = false; |
| 357 | ArgItem &arg = arg_list[i]; |
| 358 | // arguments passed in registers |
| 359 | if (i < c_args_in_reg) |
| 360 | { |
| 361 | const RegisterInfo *rArg = ctx.reg_ctx->GetRegisterInfoAtIndex(i + c_reg_offset); |
| 362 | RegisterValue rVal; |
| 363 | if (ctx.reg_ctx->ReadRegister(rArg, rVal)) |
| 364 | arg.value = rVal.GetAsUInt64(0, &success); |
| 365 | } |
| 366 | // arguments passed on the stack |
| 367 | else |
| 368 | { |
Aidan Dodds | 6dd4b57 | 2016-03-10 17:37:02 +0000 | [diff] [blame] | 369 | const size_t arg_size = sizeof(uint32_t); |
Aidan Dodds | 6dd4b57 | 2016-03-10 17:37:02 +0000 | [diff] [blame] | 370 | arg.value = 0; |
Aidan Dodds | 67dc3e1 | 2016-03-10 17:50:01 +0000 | [diff] [blame] | 371 | size_t bytes_read = ctx.process->ReadMemory(sp, &arg.value, arg_size, error); |
Aidan Dodds | 6dd4b57 | 2016-03-10 17:37:02 +0000 | [diff] [blame] | 372 | success = (error.Success() && bytes_read == arg_size); |
Aidan Dodds | 67dc3e1 | 2016-03-10 17:50:01 +0000 | [diff] [blame] | 373 | // advance the stack pointer |
| 374 | sp += arg_size; |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 375 | } |
| 376 | // fail if we couldn't read this argument |
| 377 | if (!success) |
| 378 | { |
| 379 | if (log) |
Aidan Dodds | 67dc3e1 | 2016-03-10 17:50:01 +0000 | [diff] [blame] | 380 | log->Printf("%s - error reading argument: %" PRIu64", reason: %s", |
| 381 | __FUNCTION__, uint64_t(i), error.AsCString("n/a")); |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 382 | return false; |
| 383 | } |
| 384 | } |
| 385 | return true; |
| 386 | } |
| 387 | |
| 388 | bool |
| 389 | GetArgsMips64el(GetArgsCtx &ctx, ArgItem *arg_list, size_t num_args) |
| 390 | { |
| 391 | // number of arguments passed in registers |
| 392 | static const uint32_t c_args_in_reg = 8; |
| 393 | // register file offset to first argument |
| 394 | static const uint32_t c_reg_offset = 4; |
| 395 | |
| 396 | Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE); |
| 397 | |
Aidan Dodds | 17e07c0 | 2016-03-10 17:27:41 +0000 | [diff] [blame] | 398 | Error error; |
| 399 | |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 400 | // get the current stack pointer |
| 401 | uint64_t sp = ctx.reg_ctx->GetSP(); |
| 402 | |
| 403 | for (size_t i = 0; i < num_args; ++i) |
| 404 | { |
| 405 | bool success = false; |
| 406 | ArgItem &arg = arg_list[i]; |
| 407 | // arguments passed in registers |
| 408 | if (i < c_args_in_reg) |
| 409 | { |
| 410 | const RegisterInfo *rArg = ctx.reg_ctx->GetRegisterInfoAtIndex(i + c_reg_offset); |
| 411 | RegisterValue rVal; |
| 412 | if (ctx.reg_ctx->ReadRegister(rArg, rVal)) |
Aidan Dodds | 72f7752 | 2016-02-11 17:17:12 +0000 | [diff] [blame] | 413 | arg.value = rVal.GetAsUInt64(0, &success); |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 414 | } |
| 415 | // arguments passed on the stack |
| 416 | else |
| 417 | { |
| 418 | // get the argument type size |
| 419 | const size_t arg_size = sizeof(uint64_t); |
| 420 | // clear all 64bits |
| 421 | arg.value = 0; |
| 422 | // read this argument from memory |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 423 | size_t bytes_read = ctx.process->ReadMemory(sp, &arg.value, arg_size, error); |
| 424 | success = (error.Success() && bytes_read == arg_size); |
| 425 | // advance the stack pointer |
| 426 | sp += arg_size; |
| 427 | } |
| 428 | // fail if we couldn't read this argument |
| 429 | if (!success) |
| 430 | { |
| 431 | if (log) |
Aidan Dodds | 17e07c0 | 2016-03-10 17:27:41 +0000 | [diff] [blame] | 432 | log->Printf("%s - error reading argument: %" PRIu64", reason: %s", |
| 433 | __FUNCTION__, uint64_t(i), error.AsCString("n/a")); |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 434 | return false; |
| 435 | } |
| 436 | } |
| 437 | return true; |
| 438 | } |
| 439 | |
| 440 | bool |
| 441 | GetArgs(ExecutionContext &context, ArgItem *arg_list, size_t num_args) |
| 442 | { |
| 443 | Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE); |
| 444 | |
| 445 | // verify that we have a target |
| 446 | if (!context.GetTargetPtr()) |
| 447 | { |
| 448 | if (log) |
| 449 | log->Printf("%s - invalid target", __FUNCTION__); |
| 450 | return false; |
| 451 | } |
| 452 | |
| 453 | GetArgsCtx ctx = {context.GetRegisterContext(), context.GetProcessPtr()}; |
| 454 | assert(ctx.reg_ctx && ctx.process); |
| 455 | |
| 456 | // dispatch based on architecture |
| 457 | switch (context.GetTargetPtr()->GetArchitecture().GetMachine()) |
| 458 | { |
| 459 | case llvm::Triple::ArchType::x86: |
| 460 | return GetArgsX86(ctx, arg_list, num_args); |
| 461 | |
| 462 | case llvm::Triple::ArchType::x86_64: |
| 463 | return GetArgsX86_64(ctx, arg_list, num_args); |
| 464 | |
| 465 | case llvm::Triple::ArchType::arm: |
| 466 | return GetArgsArm(ctx, arg_list, num_args); |
| 467 | |
| 468 | case llvm::Triple::ArchType::aarch64: |
| 469 | return GetArgsAarch64(ctx, arg_list, num_args); |
| 470 | |
| 471 | case llvm::Triple::ArchType::mipsel: |
| 472 | return GetArgsMipsel(ctx, arg_list, num_args); |
| 473 | |
| 474 | case llvm::Triple::ArchType::mips64el: |
| 475 | return GetArgsMips64el(ctx, arg_list, num_args); |
| 476 | |
| 477 | default: |
| 478 | // unsupported architecture |
| 479 | if (log) |
| 480 | { |
| 481 | log->Printf("%s - architecture not supported: '%s'", __FUNCTION__, |
| 482 | context.GetTargetRef().GetArchitecture().GetArchitectureName()); |
| 483 | } |
| 484 | return false; |
| 485 | } |
| 486 | } |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 487 | } // anonymous namespace |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 488 | |
| 489 | // The ScriptDetails class collects data associated with a single script instance. |
| 490 | struct RenderScriptRuntime::ScriptDetails |
| 491 | { |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 492 | ~ScriptDetails() = default; |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 493 | |
| 494 | enum ScriptType |
| 495 | { |
| 496 | eScript, |
| 497 | eScriptC |
| 498 | }; |
| 499 | |
| 500 | // The derived type of the script. |
| 501 | empirical_type<ScriptType> type; |
| 502 | // The name of the original source file. |
| 503 | empirical_type<std::string> resName; |
| 504 | // Path to script .so file on the device. |
| 505 | empirical_type<std::string> scriptDyLib; |
| 506 | // Directory where kernel objects are cached on device. |
| 507 | empirical_type<std::string> cacheDir; |
| 508 | // Pointer to the context which owns this script. |
| 509 | empirical_type<lldb::addr_t> context; |
| 510 | // Pointer to the script object itself. |
| 511 | empirical_type<lldb::addr_t> script; |
| 512 | }; |
| 513 | |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 514 | // This Element class represents the Element object in RS, |
| 515 | // defining the type associated with an Allocation. |
| 516 | struct RenderScriptRuntime::Element |
| 517 | { |
| 518 | // Taken from rsDefines.h |
| 519 | enum DataKind |
| 520 | { |
| 521 | RS_KIND_USER, |
| 522 | RS_KIND_PIXEL_L = 7, |
| 523 | RS_KIND_PIXEL_A, |
| 524 | RS_KIND_PIXEL_LA, |
| 525 | RS_KIND_PIXEL_RGB, |
| 526 | RS_KIND_PIXEL_RGBA, |
| 527 | RS_KIND_PIXEL_DEPTH, |
| 528 | RS_KIND_PIXEL_YUV, |
| 529 | RS_KIND_INVALID = 100 |
| 530 | }; |
| 531 | |
| 532 | // Taken from rsDefines.h |
| 533 | enum DataType |
| 534 | { |
| 535 | RS_TYPE_NONE = 0, |
| 536 | RS_TYPE_FLOAT_16, |
| 537 | RS_TYPE_FLOAT_32, |
| 538 | RS_TYPE_FLOAT_64, |
| 539 | RS_TYPE_SIGNED_8, |
| 540 | RS_TYPE_SIGNED_16, |
| 541 | RS_TYPE_SIGNED_32, |
| 542 | RS_TYPE_SIGNED_64, |
| 543 | RS_TYPE_UNSIGNED_8, |
| 544 | RS_TYPE_UNSIGNED_16, |
| 545 | RS_TYPE_UNSIGNED_32, |
| 546 | RS_TYPE_UNSIGNED_64, |
Ewan Crawford | 2e92071 | 2015-12-17 16:40:05 +0000 | [diff] [blame] | 547 | RS_TYPE_BOOLEAN, |
| 548 | |
| 549 | RS_TYPE_UNSIGNED_5_6_5, |
| 550 | RS_TYPE_UNSIGNED_5_5_5_1, |
| 551 | RS_TYPE_UNSIGNED_4_4_4_4, |
| 552 | |
| 553 | RS_TYPE_MATRIX_4X4, |
| 554 | RS_TYPE_MATRIX_3X3, |
| 555 | RS_TYPE_MATRIX_2X2, |
| 556 | |
| 557 | RS_TYPE_ELEMENT = 1000, |
| 558 | RS_TYPE_TYPE, |
| 559 | RS_TYPE_ALLOCATION, |
| 560 | RS_TYPE_SAMPLER, |
| 561 | RS_TYPE_SCRIPT, |
| 562 | RS_TYPE_MESH, |
| 563 | RS_TYPE_PROGRAM_FRAGMENT, |
| 564 | RS_TYPE_PROGRAM_VERTEX, |
| 565 | RS_TYPE_PROGRAM_RASTER, |
| 566 | RS_TYPE_PROGRAM_STORE, |
| 567 | RS_TYPE_FONT, |
| 568 | |
| 569 | RS_TYPE_INVALID = 10000 |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 570 | }; |
| 571 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 572 | std::vector<Element> children; // Child Element fields for structs |
| 573 | empirical_type<lldb::addr_t> element_ptr; // Pointer to the RS Element of the Type |
| 574 | empirical_type<DataType> type; // Type of each data pointer stored by the allocation |
| 575 | empirical_type<DataKind> type_kind; // Defines pixel type if Allocation is created from an image |
| 576 | empirical_type<uint32_t> type_vec_size; // Vector size of each data point, e.g '4' for uchar4 |
| 577 | empirical_type<uint32_t> field_count; // Number of Subelements |
| 578 | empirical_type<uint32_t> datum_size; // Size of a single Element with padding |
| 579 | empirical_type<uint32_t> padding; // Number of padding bytes |
| 580 | empirical_type<uint32_t> array_size; // Number of items in array, only needed for strucrs |
| 581 | ConstString type_name; // Name of type, only needed for structs |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 582 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 583 | static const ConstString & |
| 584 | GetFallbackStructName(); // Print this as the type name of a struct Element |
| 585 | // If we can't resolve the actual struct name |
Ewan Crawford | 8b59062 | 2015-12-10 10:20:39 +0000 | [diff] [blame] | 586 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 587 | bool |
| 588 | shouldRefresh() const |
Ewan Crawford | 8b59062 | 2015-12-10 10:20:39 +0000 | [diff] [blame] | 589 | { |
| 590 | const bool valid_ptr = element_ptr.isValid() && *element_ptr.get() != 0x0; |
| 591 | const bool valid_type = type.isValid() && type_vec_size.isValid() && type_kind.isValid(); |
| 592 | return !valid_ptr || !valid_type || !datum_size.isValid(); |
| 593 | } |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 594 | }; |
| 595 | |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 596 | // This AllocationDetails class collects data associated with a single |
| 597 | // allocation instance. |
| 598 | struct RenderScriptRuntime::AllocationDetails |
| 599 | { |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 600 | struct Dimension |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 601 | { |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 602 | uint32_t dim_1; |
| 603 | uint32_t dim_2; |
| 604 | uint32_t dim_3; |
| 605 | uint32_t cubeMap; |
| 606 | |
| 607 | Dimension() |
| 608 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 609 | dim_1 = 0; |
| 610 | dim_2 = 0; |
| 611 | dim_3 = 0; |
| 612 | cubeMap = 0; |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 613 | } |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 614 | }; |
| 615 | |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 616 | // The FileHeader struct specifies the header we use for writing allocations to a binary file. |
| 617 | // Our format begins with the ASCII characters "RSAD", identifying the file as an allocation dump. |
| 618 | // Member variables dims and hdr_size are then written consecutively, immediately followed by an instance of |
| 619 | // the ElementHeader struct. Because Elements can contain subelements, there may be more than one instance |
| 620 | // of the ElementHeader struct. With this first instance being the root element, and the other instances being |
| 621 | // the root's descendants. To identify which instances are an ElementHeader's children, each struct |
| 622 | // is immediately followed by a sequence of consecutive offsets to the start of its child structs. |
| 623 | // These offsets are 4 bytes in size, and the 0 offset signifies no more children. |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 624 | struct FileHeader |
| 625 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 626 | uint8_t ident[4]; // ASCII 'RSAD' identifying the file |
| 627 | uint32_t dims[3]; // Dimensions |
| 628 | uint16_t hdr_size; // Header size in bytes, including all element headers |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 629 | }; |
| 630 | |
| 631 | struct ElementHeader |
| 632 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 633 | uint16_t type; // DataType enum |
| 634 | uint32_t kind; // DataKind enum |
| 635 | uint32_t element_size; // Size of a single element, including padding |
| 636 | uint16_t vector_size; // Vector width |
| 637 | uint32_t array_size; // Number of elements in array |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 638 | }; |
| 639 | |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 640 | // Monotonically increasing from 1 |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 641 | static uint32_t ID; |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 642 | |
| 643 | // Maps Allocation DataType enum and vector size to printable strings |
| 644 | // using mapping from RenderScript numerical types summary documentation |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 645 | static const char *RsDataTypeToString[][4]; |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 646 | |
| 647 | // Maps Allocation DataKind enum to printable strings |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 648 | static const char *RsDataKindToString[]; |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 649 | |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 650 | // Maps allocation types to format sizes for printing. |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 651 | static const uint32_t RSTypeToFormat[][3]; |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 652 | |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 653 | // Give each allocation an ID as a way |
| 654 | // for commands to reference it. |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 655 | const uint32_t id; |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 656 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 657 | RenderScriptRuntime::Element element; // Allocation Element type |
| 658 | empirical_type<Dimension> dimension; // Dimensions of the Allocation |
| 659 | empirical_type<lldb::addr_t> address; // Pointer to address of the RS Allocation |
| 660 | empirical_type<lldb::addr_t> data_ptr; // Pointer to the data held by the Allocation |
| 661 | empirical_type<lldb::addr_t> type_ptr; // Pointer to the RS Type of the Allocation |
| 662 | empirical_type<lldb::addr_t> context; // Pointer to the RS Context of the Allocation |
| 663 | empirical_type<uint32_t> size; // Size of the allocation |
| 664 | empirical_type<uint32_t> stride; // Stride between rows of the allocation |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 665 | |
| 666 | // Give each allocation an id, so we can reference it in user commands. |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 667 | AllocationDetails() : id(ID++) {} |
Ewan Crawford | 8b59062 | 2015-12-10 10:20:39 +0000 | [diff] [blame] | 668 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 669 | bool |
| 670 | shouldRefresh() const |
Ewan Crawford | 8b59062 | 2015-12-10 10:20:39 +0000 | [diff] [blame] | 671 | { |
| 672 | bool valid_ptrs = data_ptr.isValid() && *data_ptr.get() != 0x0; |
| 673 | valid_ptrs = valid_ptrs && type_ptr.isValid() && *type_ptr.get() != 0x0; |
| 674 | return !valid_ptrs || !dimension.isValid() || !size.isValid() || element.shouldRefresh(); |
| 675 | } |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 676 | }; |
| 677 | |
Adrian McCarthy | fe06b5a | 2015-11-30 22:18:43 +0000 | [diff] [blame] | 678 | const ConstString & |
| 679 | RenderScriptRuntime::Element::GetFallbackStructName() |
| 680 | { |
| 681 | static const ConstString FallbackStructName("struct"); |
| 682 | return FallbackStructName; |
| 683 | } |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 684 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 685 | uint32_t RenderScriptRuntime::AllocationDetails::ID = 1; |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 686 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 687 | const char *RenderScriptRuntime::AllocationDetails::RsDataKindToString[] = { |
| 688 | "User", |
| 689 | "Undefined", "Undefined", "Undefined", "Undefined", "Undefined", "Undefined", // Enum jumps from 0 to 7 |
| 690 | "L Pixel", "A Pixel", "LA Pixel", "RGB Pixel", |
| 691 | "RGBA Pixel", "Pixel Depth", "YUV Pixel"}; |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 692 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 693 | const char *RenderScriptRuntime::AllocationDetails::RsDataTypeToString[][4] = { |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 694 | {"None", "None", "None", "None"}, |
| 695 | {"half", "half2", "half3", "half4"}, |
| 696 | {"float", "float2", "float3", "float4"}, |
| 697 | {"double", "double2", "double3", "double4"}, |
| 698 | {"char", "char2", "char3", "char4"}, |
| 699 | {"short", "short2", "short3", "short4"}, |
| 700 | {"int", "int2", "int3", "int4"}, |
| 701 | {"long", "long2", "long3", "long4"}, |
| 702 | {"uchar", "uchar2", "uchar3", "uchar4"}, |
| 703 | {"ushort", "ushort2", "ushort3", "ushort4"}, |
| 704 | {"uint", "uint2", "uint3", "uint4"}, |
| 705 | {"ulong", "ulong2", "ulong3", "ulong4"}, |
Ewan Crawford | 2e92071 | 2015-12-17 16:40:05 +0000 | [diff] [blame] | 706 | {"bool", "bool2", "bool3", "bool4"}, |
| 707 | {"packed_565", "packed_565", "packed_565", "packed_565"}, |
| 708 | {"packed_5551", "packed_5551", "packed_5551", "packed_5551"}, |
| 709 | {"packed_4444", "packed_4444", "packed_4444", "packed_4444"}, |
| 710 | {"rs_matrix4x4", "rs_matrix4x4", "rs_matrix4x4", "rs_matrix4x4"}, |
| 711 | {"rs_matrix3x3", "rs_matrix3x3", "rs_matrix3x3", "rs_matrix3x3"}, |
| 712 | {"rs_matrix2x2", "rs_matrix2x2", "rs_matrix2x2", "rs_matrix2x2"}, |
| 713 | |
| 714 | // Handlers |
| 715 | {"RS Element", "RS Element", "RS Element", "RS Element"}, |
| 716 | {"RS Type", "RS Type", "RS Type", "RS Type"}, |
| 717 | {"RS Allocation", "RS Allocation", "RS Allocation", "RS Allocation"}, |
| 718 | {"RS Sampler", "RS Sampler", "RS Sampler", "RS Sampler"}, |
| 719 | {"RS Script", "RS Script", "RS Script", "RS Script"}, |
| 720 | |
| 721 | // Deprecated |
| 722 | {"RS Mesh", "RS Mesh", "RS Mesh", "RS Mesh"}, |
| 723 | {"RS Program Fragment", "RS Program Fragment", "RS Program Fragment", "RS Program Fragment"}, |
| 724 | {"RS Program Vertex", "RS Program Vertex", "RS Program Vertex", "RS Program Vertex"}, |
| 725 | {"RS Program Raster", "RS Program Raster", "RS Program Raster", "RS Program Raster"}, |
| 726 | {"RS Program Store", "RS Program Store", "RS Program Store", "RS Program Store"}, |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 727 | {"RS Font", "RS Font", "RS Font", "RS Font"}}; |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 728 | |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 729 | // Used as an index into the RSTypeToFormat array elements |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 730 | enum TypeToFormatIndex |
| 731 | { |
| 732 | eFormatSingle = 0, |
| 733 | eFormatVector, |
| 734 | eElementSize |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 735 | }; |
| 736 | |
| 737 | // { format enum of single element, format enum of element vector, size of element} |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 738 | const uint32_t RenderScriptRuntime::AllocationDetails::RSTypeToFormat[][3] = { |
| 739 | {eFormatHex, eFormatHex, 1}, // RS_TYPE_NONE |
| 740 | {eFormatFloat, eFormatVectorOfFloat16, 2}, // RS_TYPE_FLOAT_16 |
| 741 | {eFormatFloat, eFormatVectorOfFloat32, sizeof(float)}, // RS_TYPE_FLOAT_32 |
| 742 | {eFormatFloat, eFormatVectorOfFloat64, sizeof(double)}, // RS_TYPE_FLOAT_64 |
| 743 | {eFormatDecimal, eFormatVectorOfSInt8, sizeof(int8_t)}, // RS_TYPE_SIGNED_8 |
| 744 | {eFormatDecimal, eFormatVectorOfSInt16, sizeof(int16_t)}, // RS_TYPE_SIGNED_16 |
| 745 | {eFormatDecimal, eFormatVectorOfSInt32, sizeof(int32_t)}, // RS_TYPE_SIGNED_32 |
| 746 | {eFormatDecimal, eFormatVectorOfSInt64, sizeof(int64_t)}, // RS_TYPE_SIGNED_64 |
| 747 | {eFormatDecimal, eFormatVectorOfUInt8, sizeof(uint8_t)}, // RS_TYPE_UNSIGNED_8 |
| 748 | {eFormatDecimal, eFormatVectorOfUInt16, sizeof(uint16_t)}, // RS_TYPE_UNSIGNED_16 |
| 749 | {eFormatDecimal, eFormatVectorOfUInt32, sizeof(uint32_t)}, // RS_TYPE_UNSIGNED_32 |
| 750 | {eFormatDecimal, eFormatVectorOfUInt64, sizeof(uint64_t)}, // RS_TYPE_UNSIGNED_64 |
| 751 | {eFormatBoolean, eFormatBoolean, 1}, // RS_TYPE_BOOL |
| 752 | {eFormatHex, eFormatHex, sizeof(uint16_t)}, // RS_TYPE_UNSIGNED_5_6_5 |
| 753 | {eFormatHex, eFormatHex, sizeof(uint16_t)}, // RS_TYPE_UNSIGNED_5_5_5_1 |
| 754 | {eFormatHex, eFormatHex, sizeof(uint16_t)}, // RS_TYPE_UNSIGNED_4_4_4_4 |
Ewan Crawford | 2e92071 | 2015-12-17 16:40:05 +0000 | [diff] [blame] | 755 | {eFormatVectorOfFloat32, eFormatVectorOfFloat32, sizeof(float) * 16}, // RS_TYPE_MATRIX_4X4 |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 756 | {eFormatVectorOfFloat32, eFormatVectorOfFloat32, sizeof(float) * 9}, // RS_TYPE_MATRIX_3X3 |
| 757 | {eFormatVectorOfFloat32, eFormatVectorOfFloat32, sizeof(float) * 4} // RS_TYPE_MATRIX_2X2 |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 758 | }; |
| 759 | |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 760 | //------------------------------------------------------------------ |
| 761 | // Static Functions |
| 762 | //------------------------------------------------------------------ |
| 763 | LanguageRuntime * |
| 764 | RenderScriptRuntime::CreateInstance(Process *process, lldb::LanguageType language) |
| 765 | { |
| 766 | |
| 767 | if (language == eLanguageTypeExtRenderScript) |
| 768 | return new RenderScriptRuntime(process); |
| 769 | else |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 770 | return nullptr; |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 771 | } |
| 772 | |
Ewan Crawford | 9815658 | 2015-09-04 08:56:52 +0000 | [diff] [blame] | 773 | // Callback with a module to search for matching symbols. |
| 774 | // We first check that the module contains RS kernels. |
| 775 | // Then look for a symbol which matches our kernel name. |
| 776 | // The breakpoint address is finally set using the address of this symbol. |
| 777 | Searcher::CallbackReturn |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 778 | RSBreakpointResolver::SearchCallback(SearchFilter &filter, SymbolContext &context, Address *, bool) |
Ewan Crawford | 9815658 | 2015-09-04 08:56:52 +0000 | [diff] [blame] | 779 | { |
| 780 | ModuleSP module = context.module_sp; |
| 781 | |
| 782 | if (!module) |
| 783 | return Searcher::eCallbackReturnContinue; |
| 784 | |
| 785 | // Is this a module containing renderscript kernels? |
| 786 | if (nullptr == module->FindFirstSymbolWithNameAndType(ConstString(".rs.info"), eSymbolTypeData)) |
| 787 | return Searcher::eCallbackReturnContinue; |
| 788 | |
| 789 | // Attempt to set a breakpoint on the kernel name symbol within the module library. |
| 790 | // If it's not found, it's likely debug info is unavailable - try to set a |
| 791 | // breakpoint on <name>.expand. |
| 792 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 793 | const Symbol *kernel_sym = module->FindFirstSymbolWithNameAndType(m_kernel_name, eSymbolTypeCode); |
Ewan Crawford | 9815658 | 2015-09-04 08:56:52 +0000 | [diff] [blame] | 794 | if (!kernel_sym) |
| 795 | { |
| 796 | std::string kernel_name_expanded(m_kernel_name.AsCString()); |
| 797 | kernel_name_expanded.append(".expand"); |
| 798 | kernel_sym = module->FindFirstSymbolWithNameAndType(ConstString(kernel_name_expanded.c_str()), eSymbolTypeCode); |
| 799 | } |
| 800 | |
| 801 | if (kernel_sym) |
| 802 | { |
| 803 | Address bp_addr = kernel_sym->GetAddress(); |
| 804 | if (filter.AddressPasses(bp_addr)) |
| 805 | m_breakpoint->AddLocation(bp_addr); |
| 806 | } |
| 807 | |
| 808 | return Searcher::eCallbackReturnContinue; |
| 809 | } |
| 810 | |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 811 | void |
| 812 | RenderScriptRuntime::Initialize() |
| 813 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 814 | PluginManager::RegisterPlugin(GetPluginNameStatic(), "RenderScript language support", CreateInstance, |
| 815 | GetCommandObject); |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | void |
| 819 | RenderScriptRuntime::Terminate() |
| 820 | { |
| 821 | PluginManager::UnregisterPlugin(CreateInstance); |
| 822 | } |
| 823 | |
| 824 | lldb_private::ConstString |
| 825 | RenderScriptRuntime::GetPluginNameStatic() |
| 826 | { |
| 827 | static ConstString g_name("renderscript"); |
| 828 | return g_name; |
| 829 | } |
| 830 | |
Aidan Dodds | 35e7b1a | 2016-01-06 15:43:52 +0000 | [diff] [blame] | 831 | RenderScriptRuntime::ModuleKind |
Colin Riley | ef20b08 | 2015-04-14 07:39:24 +0000 | [diff] [blame] | 832 | RenderScriptRuntime::GetModuleKind(const lldb::ModuleSP &module_sp) |
| 833 | { |
| 834 | if (module_sp) |
| 835 | { |
| 836 | // Is this a module containing renderscript kernels? |
| 837 | const Symbol *info_sym = module_sp->FindFirstSymbolWithNameAndType(ConstString(".rs.info"), eSymbolTypeData); |
| 838 | if (info_sym) |
| 839 | { |
| 840 | return eModuleKindKernelObj; |
| 841 | } |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 842 | |
| 843 | // Is this the main RS runtime library |
| 844 | const ConstString rs_lib("libRS.so"); |
| 845 | if (module_sp->GetFileSpec().GetFilename() == rs_lib) |
| 846 | { |
| 847 | return eModuleKindLibRS; |
| 848 | } |
| 849 | |
| 850 | const ConstString rs_driverlib("libRSDriver.so"); |
| 851 | if (module_sp->GetFileSpec().GetFilename() == rs_driverlib) |
| 852 | { |
| 853 | return eModuleKindDriver; |
| 854 | } |
| 855 | |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 856 | const ConstString rs_cpureflib("libRSCpuRef.so"); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 857 | if (module_sp->GetFileSpec().GetFilename() == rs_cpureflib) |
| 858 | { |
| 859 | return eModuleKindImpl; |
| 860 | } |
Colin Riley | ef20b08 | 2015-04-14 07:39:24 +0000 | [diff] [blame] | 861 | } |
| 862 | return eModuleKindIgnored; |
| 863 | } |
| 864 | |
| 865 | bool |
| 866 | RenderScriptRuntime::IsRenderScriptModule(const lldb::ModuleSP &module_sp) |
| 867 | { |
| 868 | return GetModuleKind(module_sp) != eModuleKindIgnored; |
| 869 | } |
| 870 | |
Aidan Dodds | 35e7b1a | 2016-01-06 15:43:52 +0000 | [diff] [blame] | 871 | void |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 872 | RenderScriptRuntime::ModulesDidLoad(const ModuleList &module_list) |
Colin Riley | ef20b08 | 2015-04-14 07:39:24 +0000 | [diff] [blame] | 873 | { |
Saleem Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 874 | std::lock_guard<std::recursive_mutex> guard(module_list.GetMutex()); |
Colin Riley | ef20b08 | 2015-04-14 07:39:24 +0000 | [diff] [blame] | 875 | |
| 876 | size_t num_modules = module_list.GetSize(); |
| 877 | for (size_t i = 0; i < num_modules; i++) |
| 878 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 879 | auto mod = module_list.GetModuleAtIndex(i); |
| 880 | if (IsRenderScriptModule(mod)) |
Colin Riley | ef20b08 | 2015-04-14 07:39:24 +0000 | [diff] [blame] | 881 | { |
| 882 | LoadModule(mod); |
| 883 | } |
| 884 | } |
| 885 | } |
| 886 | |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 887 | //------------------------------------------------------------------ |
| 888 | // PluginInterface protocol |
| 889 | //------------------------------------------------------------------ |
| 890 | lldb_private::ConstString |
| 891 | RenderScriptRuntime::GetPluginName() |
| 892 | { |
| 893 | return GetPluginNameStatic(); |
| 894 | } |
| 895 | |
| 896 | uint32_t |
| 897 | RenderScriptRuntime::GetPluginVersion() |
| 898 | { |
| 899 | return 1; |
| 900 | } |
| 901 | |
| 902 | bool |
| 903 | RenderScriptRuntime::IsVTableName(const char *name) |
| 904 | { |
| 905 | return false; |
| 906 | } |
| 907 | |
| 908 | bool |
Enrico Granata | 5f57b6e | 2016-05-05 21:10:28 +0000 | [diff] [blame] | 909 | RenderScriptRuntime::GetDynamicTypeAndAddress(ValueObject &in_value, lldb::DynamicValueType use_dynamic, |
| 910 | TypeAndOrName &class_type_or_name, Address &address, |
| 911 | Value::ValueType &value_type) |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 912 | { |
| 913 | return false; |
| 914 | } |
| 915 | |
Enrico Granata | c74275b | 2015-09-22 19:45:52 +0000 | [diff] [blame] | 916 | TypeAndOrName |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 917 | RenderScriptRuntime::FixUpDynamicType(const TypeAndOrName &type_and_or_name, ValueObject &static_value) |
Enrico Granata | c74275b | 2015-09-22 19:45:52 +0000 | [diff] [blame] | 918 | { |
| 919 | return type_and_or_name; |
| 920 | } |
| 921 | |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 922 | bool |
| 923 | RenderScriptRuntime::CouldHaveDynamicValue(ValueObject &in_value) |
| 924 | { |
| 925 | return false; |
| 926 | } |
| 927 | |
| 928 | lldb::BreakpointResolverSP |
| 929 | RenderScriptRuntime::CreateExceptionResolver(Breakpoint *bkpt, bool catch_bp, bool throw_bp) |
| 930 | { |
| 931 | BreakpointResolverSP resolver_sp; |
| 932 | return resolver_sp; |
| 933 | } |
| 934 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 935 | const RenderScriptRuntime::HookDefn RenderScriptRuntime::s_runtimeHookDefns[] = { |
| 936 | // rsdScript |
Aidan Dodds | 8278028 | 2015-09-18 16:49:39 +0000 | [diff] [blame] | 937 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 938 | "rsdScriptInit", |
| 939 | "_Z13rsdScriptInitPKN7android12renderscript7ContextEPNS0_7ScriptCEPKcS7_PKhjj", |
| 940 | "_Z13rsdScriptInitPKN7android12renderscript7ContextEPNS0_7ScriptCEPKcS7_PKhmj", |
| 941 | 0, |
| 942 | RenderScriptRuntime::eModuleKindDriver, |
| 943 | &lldb_private::RenderScriptRuntime::CaptureScriptInit |
Aidan Dodds | 8278028 | 2015-09-18 16:49:39 +0000 | [diff] [blame] | 944 | }, |
| 945 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 946 | "rsdScriptInvokeForEachMulti", |
| 947 | "_Z27rsdScriptInvokeForEachMultiPKN7android12renderscript7ContextEPNS0_6ScriptEjPPKNS0_10AllocationEjPS6_PKvjPK12RsScriptCall", |
| 948 | "_Z27rsdScriptInvokeForEachMultiPKN7android12renderscript7ContextEPNS0_6ScriptEjPPKNS0_10AllocationEmPS6_PKvmPK12RsScriptCall", |
| 949 | 0, |
| 950 | RenderScriptRuntime::eModuleKindDriver, |
| 951 | &lldb_private::RenderScriptRuntime::CaptureScriptInvokeForEachMulti |
Aidan Dodds | 8278028 | 2015-09-18 16:49:39 +0000 | [diff] [blame] | 952 | }, |
| 953 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 954 | "rsdScriptSetGlobalVar", |
| 955 | "_Z21rsdScriptSetGlobalVarPKN7android12renderscript7ContextEPKNS0_6ScriptEjPvj", |
| 956 | "_Z21rsdScriptSetGlobalVarPKN7android12renderscript7ContextEPKNS0_6ScriptEjPvm", |
| 957 | 0, |
| 958 | RenderScriptRuntime::eModuleKindDriver, |
| 959 | &lldb_private::RenderScriptRuntime::CaptureSetGlobalVar |
Aidan Dodds | 8278028 | 2015-09-18 16:49:39 +0000 | [diff] [blame] | 960 | }, |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 961 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 962 | // rsdAllocation |
Aidan Dodds | 8278028 | 2015-09-18 16:49:39 +0000 | [diff] [blame] | 963 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 964 | "rsdAllocationInit", |
| 965 | "_Z17rsdAllocationInitPKN7android12renderscript7ContextEPNS0_10AllocationEb", |
| 966 | "_Z17rsdAllocationInitPKN7android12renderscript7ContextEPNS0_10AllocationEb", |
| 967 | 0, |
| 968 | RenderScriptRuntime::eModuleKindDriver, |
| 969 | &lldb_private::RenderScriptRuntime::CaptureAllocationInit |
Aidan Dodds | 8278028 | 2015-09-18 16:49:39 +0000 | [diff] [blame] | 970 | }, |
| 971 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 972 | "rsdAllocationRead2D", |
| 973 | "_Z19rsdAllocationRead2DPKN7android12renderscript7ContextEPKNS0_10AllocationEjjj23RsAllocationCubemapFacejjPvjj", |
| 974 | "_Z19rsdAllocationRead2DPKN7android12renderscript7ContextEPKNS0_10AllocationEjjj23RsAllocationCubemapFacejjPvmm", |
| 975 | 0, |
| 976 | RenderScriptRuntime::eModuleKindDriver, |
| 977 | nullptr |
Aidan Dodds | 8278028 | 2015-09-18 16:49:39 +0000 | [diff] [blame] | 978 | }, |
Ewan Crawford | e69df38 | 2015-12-09 16:01:58 +0000 | [diff] [blame] | 979 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 980 | "rsdAllocationDestroy", |
| 981 | "_Z20rsdAllocationDestroyPKN7android12renderscript7ContextEPNS0_10AllocationE", |
| 982 | "_Z20rsdAllocationDestroyPKN7android12renderscript7ContextEPNS0_10AllocationE", |
| 983 | 0, |
| 984 | RenderScriptRuntime::eModuleKindDriver, |
| 985 | &lldb_private::RenderScriptRuntime::CaptureAllocationDestroy |
Ewan Crawford | e69df38 | 2015-12-09 16:01:58 +0000 | [diff] [blame] | 986 | }, |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 987 | }; |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 988 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 989 | const size_t RenderScriptRuntime::s_runtimeHookCount = sizeof(s_runtimeHookDefns) / sizeof(s_runtimeHookDefns[0]); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 990 | |
| 991 | bool |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 992 | RenderScriptRuntime::HookCallback(void *baton, StoppointCallbackContext *ctx, lldb::user_id_t break_id, |
| 993 | lldb::user_id_t break_loc_id) |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 994 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 995 | RuntimeHook *hook_info = (RuntimeHook *)baton; |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 996 | ExecutionContext context(ctx->exe_ctx_ref); |
| 997 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 998 | RenderScriptRuntime *lang_rt = |
| 999 | (RenderScriptRuntime *)context.GetProcessPtr()->GetLanguageRuntime(eLanguageTypeExtRenderScript); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1000 | |
| 1001 | lang_rt->HookCallback(hook_info, context); |
Aidan Dodds | 35e7b1a | 2016-01-06 15:43:52 +0000 | [diff] [blame] | 1002 | |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1003 | return false; |
| 1004 | } |
| 1005 | |
Aidan Dodds | 35e7b1a | 2016-01-06 15:43:52 +0000 | [diff] [blame] | 1006 | void |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1007 | RenderScriptRuntime::HookCallback(RuntimeHook *hook_info, ExecutionContext &context) |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1008 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1009 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE)); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1010 | |
Aidan Dodds | 8278028 | 2015-09-18 16:49:39 +0000 | [diff] [blame] | 1011 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1012 | log->Printf("%s - '%s'", __FUNCTION__, hook_info->defn->name); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1013 | |
Aidan Dodds | 35e7b1a | 2016-01-06 15:43:52 +0000 | [diff] [blame] | 1014 | if (hook_info->defn->grabber) |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1015 | { |
| 1016 | (this->*(hook_info->defn->grabber))(hook_info, context); |
| 1017 | } |
| 1018 | } |
| 1019 | |
Aidan Dodds | 35e7b1a | 2016-01-06 15:43:52 +0000 | [diff] [blame] | 1020 | void |
Aidan Dodds | e09c44b | 2016-01-14 15:39:28 +0000 | [diff] [blame] | 1021 | RenderScriptRuntime::CaptureScriptInvokeForEachMulti(RuntimeHook* hook_info, |
| 1022 | ExecutionContext& context) |
| 1023 | { |
| 1024 | Log* log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE)); |
| 1025 | |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1026 | enum |
Aidan Dodds | e09c44b | 2016-01-14 15:39:28 +0000 | [diff] [blame] | 1027 | { |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1028 | eRsContext = 0, |
| 1029 | eRsScript, |
| 1030 | eRsSlot, |
| 1031 | eRsAIns, |
| 1032 | eRsInLen, |
| 1033 | eRsAOut, |
| 1034 | eRsUsr, |
| 1035 | eRsUsrLen, |
| 1036 | eRsSc, |
| 1037 | }; |
Aidan Dodds | e09c44b | 2016-01-14 15:39:28 +0000 | [diff] [blame] | 1038 | |
Saleem Abdulrasool | 1ee0725 | 2016-02-15 21:50:28 +0000 | [diff] [blame] | 1039 | std::array<ArgItem, 9> args{{ |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1040 | ArgItem{ArgItem::ePointer, 0}, // const Context *rsc |
| 1041 | ArgItem{ArgItem::ePointer, 0}, // Script *s |
| 1042 | ArgItem{ArgItem::eInt32, 0}, // uint32_t slot |
| 1043 | ArgItem{ArgItem::ePointer, 0}, // const Allocation **aIns |
| 1044 | ArgItem{ArgItem::eInt32, 0}, // size_t inLen |
| 1045 | ArgItem{ArgItem::ePointer, 0}, // Allocation *aout |
| 1046 | ArgItem{ArgItem::ePointer, 0}, // const void *usr |
| 1047 | ArgItem{ArgItem::eInt32, 0}, // size_t usrLen |
| 1048 | ArgItem{ArgItem::ePointer, 0}, // const RsScriptCall *sc |
Saleem Abdulrasool | 1ee0725 | 2016-02-15 21:50:28 +0000 | [diff] [blame] | 1049 | }}; |
Aidan Dodds | e09c44b | 2016-01-14 15:39:28 +0000 | [diff] [blame] | 1050 | |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1051 | bool success = GetArgs(context, &args[0], args.size()); |
Aidan Dodds | e09c44b | 2016-01-14 15:39:28 +0000 | [diff] [blame] | 1052 | if (!success) |
| 1053 | { |
| 1054 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1055 | log->Printf("%s - Error while reading the function parameters", __FUNCTION__); |
Aidan Dodds | e09c44b | 2016-01-14 15:39:28 +0000 | [diff] [blame] | 1056 | return; |
| 1057 | } |
| 1058 | |
| 1059 | const uint32_t target_ptr_size = m_process->GetAddressByteSize(); |
| 1060 | Error error; |
| 1061 | std::vector<uint64_t> allocs; |
| 1062 | |
| 1063 | // traverse allocation list |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1064 | for (uint64_t i = 0; i < uint64_t(args[eRsInLen]); ++i) |
Aidan Dodds | e09c44b | 2016-01-14 15:39:28 +0000 | [diff] [blame] | 1065 | { |
| 1066 | // calculate offest to allocation pointer |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1067 | const addr_t addr = addr_t(args[eRsAIns]) + i * target_ptr_size; |
Aidan Dodds | e09c44b | 2016-01-14 15:39:28 +0000 | [diff] [blame] | 1068 | |
| 1069 | // Note: due to little endian layout, reading 32bits or 64bits into res64 will |
| 1070 | // give the correct results. |
| 1071 | |
| 1072 | uint64_t res64 = 0; |
| 1073 | size_t read = m_process->ReadMemory(addr, &res64, target_ptr_size, error); |
| 1074 | if (read != target_ptr_size || !error.Success()) |
| 1075 | { |
| 1076 | if (log) |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1077 | log->Printf("%s - Error while reading allocation list argument %" PRIu64, __FUNCTION__, i); |
Aidan Dodds | e09c44b | 2016-01-14 15:39:28 +0000 | [diff] [blame] | 1078 | } |
| 1079 | else |
| 1080 | { |
| 1081 | allocs.push_back(res64); |
| 1082 | } |
| 1083 | } |
| 1084 | |
| 1085 | // if there is an output allocation track it |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1086 | if (uint64_t aOut = uint64_t(args[eRsAOut])) |
Aidan Dodds | e09c44b | 2016-01-14 15:39:28 +0000 | [diff] [blame] | 1087 | { |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1088 | allocs.push_back(aOut); |
Aidan Dodds | e09c44b | 2016-01-14 15:39:28 +0000 | [diff] [blame] | 1089 | } |
| 1090 | |
| 1091 | // for all allocations we have found |
| 1092 | for (const uint64_t alloc_addr : allocs) |
| 1093 | { |
Luke Drummond | 5d05763 | 2016-08-03 17:31:58 +0000 | [diff] [blame] | 1094 | AllocationDetails *alloc = LookUpAllocation(alloc_addr); |
| 1095 | if (!alloc) |
| 1096 | alloc = CreateAllocation(alloc_addr); |
| 1097 | |
Aidan Dodds | e09c44b | 2016-01-14 15:39:28 +0000 | [diff] [blame] | 1098 | if (alloc) |
| 1099 | { |
| 1100 | // save the allocation address |
| 1101 | if (alloc->address.isValid()) |
| 1102 | { |
| 1103 | // check the allocation address we already have matches |
| 1104 | assert(*alloc->address.get() == alloc_addr); |
| 1105 | } |
| 1106 | else |
| 1107 | { |
| 1108 | alloc->address = alloc_addr; |
| 1109 | } |
| 1110 | |
| 1111 | // save the context |
| 1112 | if (log) |
| 1113 | { |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1114 | if (alloc->context.isValid() && *alloc->context.get() != addr_t(args[eRsContext])) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1115 | log->Printf("%s - Allocation used by multiple contexts", __FUNCTION__); |
Aidan Dodds | e09c44b | 2016-01-14 15:39:28 +0000 | [diff] [blame] | 1116 | } |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1117 | alloc->context = addr_t(args[eRsContext]); |
Aidan Dodds | e09c44b | 2016-01-14 15:39:28 +0000 | [diff] [blame] | 1118 | } |
| 1119 | } |
| 1120 | |
| 1121 | // make sure we track this script object |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1122 | if (lldb_private::RenderScriptRuntime::ScriptDetails *script = LookUpScript(addr_t(args[eRsScript]), true)) |
Aidan Dodds | e09c44b | 2016-01-14 15:39:28 +0000 | [diff] [blame] | 1123 | { |
| 1124 | if (log) |
| 1125 | { |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1126 | if (script->context.isValid() && *script->context.get() != addr_t(args[eRsContext])) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1127 | log->Printf("%s - Script used by multiple contexts", __FUNCTION__); |
Aidan Dodds | e09c44b | 2016-01-14 15:39:28 +0000 | [diff] [blame] | 1128 | } |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1129 | script->context = addr_t(args[eRsContext]); |
Aidan Dodds | e09c44b | 2016-01-14 15:39:28 +0000 | [diff] [blame] | 1130 | } |
| 1131 | } |
| 1132 | |
| 1133 | void |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1134 | RenderScriptRuntime::CaptureSetGlobalVar(RuntimeHook *hook_info, ExecutionContext &context) |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1135 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1136 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE)); |
Aidan Dodds | 35e7b1a | 2016-01-06 15:43:52 +0000 | [diff] [blame] | 1137 | |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1138 | enum |
| 1139 | { |
| 1140 | eRsContext, |
| 1141 | eRsScript, |
| 1142 | eRsId, |
| 1143 | eRsData, |
| 1144 | eRsLength, |
| 1145 | }; |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1146 | |
Saleem Abdulrasool | 1ee0725 | 2016-02-15 21:50:28 +0000 | [diff] [blame] | 1147 | std::array<ArgItem, 5> args{{ |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1148 | ArgItem{ArgItem::ePointer, 0}, // eRsContext |
| 1149 | ArgItem{ArgItem::ePointer, 0}, // eRsScript |
| 1150 | ArgItem{ArgItem::eInt32, 0}, // eRsId |
| 1151 | ArgItem{ArgItem::ePointer, 0}, // eRsData |
| 1152 | ArgItem{ArgItem::eInt32, 0}, // eRsLength |
Saleem Abdulrasool | 1ee0725 | 2016-02-15 21:50:28 +0000 | [diff] [blame] | 1153 | }}; |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1154 | |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1155 | bool success = GetArgs(context, &args[0], args.size()); |
Aidan Dodds | 8278028 | 2015-09-18 16:49:39 +0000 | [diff] [blame] | 1156 | if (!success) |
| 1157 | { |
| 1158 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1159 | log->Printf("%s - error reading the function parameters.", __FUNCTION__); |
Aidan Dodds | 8278028 | 2015-09-18 16:49:39 +0000 | [diff] [blame] | 1160 | return; |
| 1161 | } |
Aidan Dodds | 35e7b1a | 2016-01-06 15:43:52 +0000 | [diff] [blame] | 1162 | |
Aidan Dodds | 8278028 | 2015-09-18 16:49:39 +0000 | [diff] [blame] | 1163 | if (log) |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1164 | { |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1165 | log->Printf("%s - 0x%" PRIx64 ",0x%" PRIx64 " slot %" PRIu64 " = 0x%" PRIx64 ":%" PRIu64 "bytes.", __FUNCTION__, |
| 1166 | uint64_t(args[eRsContext]), uint64_t(args[eRsScript]), uint64_t(args[eRsId]), |
| 1167 | uint64_t(args[eRsData]), uint64_t(args[eRsLength])); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1168 | |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1169 | addr_t script_addr = addr_t(args[eRsScript]); |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1170 | if (m_scriptMappings.find(script_addr) != m_scriptMappings.end()) |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1171 | { |
| 1172 | auto rsm = m_scriptMappings[script_addr]; |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1173 | if (uint64_t(args[eRsId]) < rsm->m_globals.size()) |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1174 | { |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1175 | auto rsg = rsm->m_globals[uint64_t(args[eRsId])]; |
| 1176 | log->Printf("%s - Setting of '%s' within '%s' inferred", __FUNCTION__, rsg.m_name.AsCString(), |
| 1177 | rsm->m_module->GetFileSpec().GetFilename().AsCString()); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1178 | } |
| 1179 | } |
| 1180 | } |
| 1181 | } |
| 1182 | |
Aidan Dodds | 35e7b1a | 2016-01-06 15:43:52 +0000 | [diff] [blame] | 1183 | void |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1184 | RenderScriptRuntime::CaptureAllocationInit(RuntimeHook *hook_info, ExecutionContext &context) |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1185 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1186 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE)); |
Aidan Dodds | 35e7b1a | 2016-01-06 15:43:52 +0000 | [diff] [blame] | 1187 | |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1188 | enum |
| 1189 | { |
| 1190 | eRsContext, |
| 1191 | eRsAlloc, |
| 1192 | eRsForceZero |
| 1193 | }; |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1194 | |
Saleem Abdulrasool | 1ee0725 | 2016-02-15 21:50:28 +0000 | [diff] [blame] | 1195 | std::array<ArgItem, 3> args{{ |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1196 | ArgItem{ArgItem::ePointer, 0}, // eRsContext |
| 1197 | ArgItem{ArgItem::ePointer, 0}, // eRsAlloc |
| 1198 | ArgItem{ArgItem::eBool, 0}, // eRsForceZero |
Saleem Abdulrasool | 1ee0725 | 2016-02-15 21:50:28 +0000 | [diff] [blame] | 1199 | }}; |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1200 | |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1201 | bool success = GetArgs(context, &args[0], args.size()); |
Aidan Dodds | 8278028 | 2015-09-18 16:49:39 +0000 | [diff] [blame] | 1202 | if (!success) // error case |
| 1203 | { |
| 1204 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1205 | log->Printf("%s - error while reading the function parameters", __FUNCTION__); |
Aidan Dodds | 8278028 | 2015-09-18 16:49:39 +0000 | [diff] [blame] | 1206 | return; // abort |
| 1207 | } |
| 1208 | |
| 1209 | if (log) |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1210 | log->Printf("%s - 0x%" PRIx64 ",0x%" PRIx64 ",0x%" PRIx64 " .", __FUNCTION__, uint64_t(args[eRsContext]), |
| 1211 | uint64_t(args[eRsAlloc]), uint64_t(args[eRsForceZero])); |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 1212 | |
Luke Drummond | 5d05763 | 2016-08-03 17:31:58 +0000 | [diff] [blame] | 1213 | AllocationDetails *alloc = CreateAllocation(uint64_t(args[eRsAlloc])); |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 1214 | if (alloc) |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1215 | alloc->context = uint64_t(args[eRsContext]); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1216 | } |
| 1217 | |
Ewan Crawford | e69df38 | 2015-12-09 16:01:58 +0000 | [diff] [blame] | 1218 | void |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1219 | RenderScriptRuntime::CaptureAllocationDestroy(RuntimeHook *hook_info, ExecutionContext &context) |
Ewan Crawford | e69df38 | 2015-12-09 16:01:58 +0000 | [diff] [blame] | 1220 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1221 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE)); |
Ewan Crawford | e69df38 | 2015-12-09 16:01:58 +0000 | [diff] [blame] | 1222 | |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1223 | enum |
| 1224 | { |
| 1225 | eRsContext, |
| 1226 | eRsAlloc, |
| 1227 | }; |
Ewan Crawford | e69df38 | 2015-12-09 16:01:58 +0000 | [diff] [blame] | 1228 | |
Saleem Abdulrasool | 1ee0725 | 2016-02-15 21:50:28 +0000 | [diff] [blame] | 1229 | std::array<ArgItem, 2> args{{ |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1230 | ArgItem{ArgItem::ePointer, 0}, // eRsContext |
| 1231 | ArgItem{ArgItem::ePointer, 0}, // eRsAlloc |
Saleem Abdulrasool | 1ee0725 | 2016-02-15 21:50:28 +0000 | [diff] [blame] | 1232 | }}; |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1233 | |
| 1234 | bool success = GetArgs(context, &args[0], args.size()); |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1235 | if (!success) |
Ewan Crawford | e69df38 | 2015-12-09 16:01:58 +0000 | [diff] [blame] | 1236 | { |
| 1237 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1238 | log->Printf("%s - error while reading the function parameters.", __FUNCTION__); |
| 1239 | return; |
Ewan Crawford | e69df38 | 2015-12-09 16:01:58 +0000 | [diff] [blame] | 1240 | } |
| 1241 | |
| 1242 | if (log) |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1243 | log->Printf("%s - 0x%" PRIx64 ", 0x%" PRIx64 ".", __FUNCTION__, uint64_t(args[eRsContext]), |
| 1244 | uint64_t(args[eRsAlloc])); |
Ewan Crawford | e69df38 | 2015-12-09 16:01:58 +0000 | [diff] [blame] | 1245 | |
| 1246 | for (auto iter = m_allocations.begin(); iter != m_allocations.end(); ++iter) |
| 1247 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1248 | auto &allocation_ap = *iter; // get the unique pointer |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1249 | if (allocation_ap->address.isValid() && *allocation_ap->address.get() == addr_t(args[eRsAlloc])) |
Ewan Crawford | e69df38 | 2015-12-09 16:01:58 +0000 | [diff] [blame] | 1250 | { |
| 1251 | m_allocations.erase(iter); |
| 1252 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1253 | log->Printf("%s - deleted allocation entry.", __FUNCTION__); |
Ewan Crawford | e69df38 | 2015-12-09 16:01:58 +0000 | [diff] [blame] | 1254 | return; |
| 1255 | } |
| 1256 | } |
| 1257 | |
| 1258 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1259 | log->Printf("%s - couldn't find destroyed allocation.", __FUNCTION__); |
Ewan Crawford | e69df38 | 2015-12-09 16:01:58 +0000 | [diff] [blame] | 1260 | } |
| 1261 | |
Aidan Dodds | 35e7b1a | 2016-01-06 15:43:52 +0000 | [diff] [blame] | 1262 | void |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1263 | RenderScriptRuntime::CaptureScriptInit(RuntimeHook *hook_info, ExecutionContext &context) |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1264 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1265 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE)); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1266 | |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1267 | Error error; |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1268 | Process *process = context.GetProcessPtr(); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1269 | |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1270 | enum |
| 1271 | { |
| 1272 | eRsContext, |
| 1273 | eRsScript, |
| 1274 | eRsResNamePtr, |
| 1275 | eRsCachedDirPtr |
| 1276 | }; |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1277 | |
Saleem Abdulrasool | 1ee0725 | 2016-02-15 21:50:28 +0000 | [diff] [blame] | 1278 | std::array<ArgItem, 4> args{{ArgItem{ArgItem::ePointer, 0}, ArgItem{ArgItem::ePointer, 0}, |
| 1279 | ArgItem{ArgItem::ePointer, 0}, ArgItem{ArgItem::ePointer, 0}}}; |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1280 | bool success = GetArgs(context, &args[0], args.size()); |
Aidan Dodds | 8278028 | 2015-09-18 16:49:39 +0000 | [diff] [blame] | 1281 | if (!success) |
| 1282 | { |
| 1283 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1284 | log->Printf("%s - error while reading the function parameters.", __FUNCTION__); |
Aidan Dodds | 8278028 | 2015-09-18 16:49:39 +0000 | [diff] [blame] | 1285 | return; |
| 1286 | } |
| 1287 | |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1288 | std::string resname; |
| 1289 | process->ReadCStringFromMemory(addr_t(args[eRsResNamePtr]), resname, error); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1290 | if (error.Fail()) |
| 1291 | { |
Aidan Dodds | 8278028 | 2015-09-18 16:49:39 +0000 | [diff] [blame] | 1292 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1293 | log->Printf("%s - error reading resname: %s.", __FUNCTION__, error.AsCString()); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1294 | } |
| 1295 | |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1296 | std::string cachedir; |
| 1297 | process->ReadCStringFromMemory(addr_t(args[eRsCachedDirPtr]), cachedir, error); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1298 | if (error.Fail()) |
| 1299 | { |
Aidan Dodds | 8278028 | 2015-09-18 16:49:39 +0000 | [diff] [blame] | 1300 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1301 | log->Printf("%s - error reading cachedir: %s.", __FUNCTION__, error.AsCString()); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1302 | } |
Aidan Dodds | 35e7b1a | 2016-01-06 15:43:52 +0000 | [diff] [blame] | 1303 | |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1304 | if (log) |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1305 | log->Printf("%s - 0x%" PRIx64 ",0x%" PRIx64 " => '%s' at '%s' .", __FUNCTION__, uint64_t(args[eRsContext]), |
| 1306 | uint64_t(args[eRsScript]), resname.c_str(), cachedir.c_str()); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1307 | |
| 1308 | if (resname.size() > 0) |
| 1309 | { |
| 1310 | StreamString strm; |
| 1311 | strm.Printf("librs.%s.so", resname.c_str()); |
| 1312 | |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1313 | ScriptDetails *script = LookUpScript(addr_t(args[eRsScript]), true); |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 1314 | if (script) |
| 1315 | { |
| 1316 | script->type = ScriptDetails::eScriptC; |
| 1317 | script->cacheDir = cachedir; |
| 1318 | script->resName = resname; |
| 1319 | script->scriptDyLib = strm.GetData(); |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1320 | script->context = addr_t(args[eRsContext]); |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 1321 | } |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1322 | |
| 1323 | if (log) |
Aidan Dodds | f478678 | 2016-02-11 15:16:37 +0000 | [diff] [blame] | 1324 | log->Printf("%s - '%s' tagged with context 0x%" PRIx64 " and script 0x%" PRIx64 ".", __FUNCTION__, |
| 1325 | strm.GetData(), uint64_t(args[eRsContext]), uint64_t(args[eRsScript])); |
Aidan Dodds | 35e7b1a | 2016-01-06 15:43:52 +0000 | [diff] [blame] | 1326 | } |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1327 | else if (log) |
| 1328 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1329 | log->Printf("%s - resource name invalid, Script not tagged.", __FUNCTION__); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1330 | } |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1331 | } |
| 1332 | |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1333 | void |
| 1334 | RenderScriptRuntime::LoadRuntimeHooks(lldb::ModuleSP module, ModuleKind kind) |
| 1335 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1336 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE)); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1337 | |
| 1338 | if (!module) |
| 1339 | { |
| 1340 | return; |
| 1341 | } |
| 1342 | |
Aidan Dodds | 8278028 | 2015-09-18 16:49:39 +0000 | [diff] [blame] | 1343 | Target &target = GetProcess()->GetTarget(); |
| 1344 | llvm::Triple::ArchType targetArchType = target.GetArchitecture().GetMachine(); |
| 1345 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1346 | if (targetArchType != llvm::Triple::ArchType::x86 && |
| 1347 | targetArchType != llvm::Triple::ArchType::arm && |
| 1348 | targetArchType != llvm::Triple::ArchType::aarch64 && |
| 1349 | targetArchType != llvm::Triple::ArchType::mipsel && |
| 1350 | targetArchType != llvm::Triple::ArchType::mips64el && |
| 1351 | targetArchType != llvm::Triple::ArchType::x86_64) |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1352 | { |
| 1353 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1354 | log->Printf("%s - unable to hook runtime functions.", __FUNCTION__); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1355 | return; |
| 1356 | } |
| 1357 | |
Aidan Dodds | 8278028 | 2015-09-18 16:49:39 +0000 | [diff] [blame] | 1358 | uint32_t archByteSize = target.GetArchitecture().GetAddressByteSize(); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1359 | |
| 1360 | for (size_t idx = 0; idx < s_runtimeHookCount; idx++) |
| 1361 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1362 | const HookDefn *hook_defn = &s_runtimeHookDefns[idx]; |
| 1363 | if (hook_defn->kind != kind) |
| 1364 | { |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1365 | continue; |
| 1366 | } |
| 1367 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1368 | const char *symbol_name = (archByteSize == 4) ? hook_defn->symbol_name_m32 : hook_defn->symbol_name_m64; |
Aidan Dodds | 8278028 | 2015-09-18 16:49:39 +0000 | [diff] [blame] | 1369 | |
| 1370 | const Symbol *sym = module->FindFirstSymbolWithNameAndType(ConstString(symbol_name), eSymbolTypeCode); |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1371 | if (!sym) |
| 1372 | { |
| 1373 | if (log) |
| 1374 | { |
| 1375 | log->Printf("%s - symbol '%s' related to the function %s not found", |
| 1376 | __FUNCTION__, symbol_name, hook_defn->name); |
Aidan Dodds | 8278028 | 2015-09-18 16:49:39 +0000 | [diff] [blame] | 1377 | } |
| 1378 | continue; |
| 1379 | } |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1380 | |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 1381 | addr_t addr = sym->GetLoadAddress(&target); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1382 | if (addr == LLDB_INVALID_ADDRESS) |
| 1383 | { |
Aidan Dodds | 8278028 | 2015-09-18 16:49:39 +0000 | [diff] [blame] | 1384 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1385 | log->Printf("%s - unable to resolve the address of hook function '%s' with symbol '%s'.", |
| 1386 | __FUNCTION__, hook_defn->name, symbol_name); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1387 | continue; |
| 1388 | } |
Aidan Dodds | 8278028 | 2015-09-18 16:49:39 +0000 | [diff] [blame] | 1389 | else |
| 1390 | { |
| 1391 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1392 | log->Printf("%s - function %s, address resolved at 0x%" PRIx64, |
| 1393 | __FUNCTION__, hook_defn->name, addr); |
Aidan Dodds | 8278028 | 2015-09-18 16:49:39 +0000 | [diff] [blame] | 1394 | } |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1395 | |
| 1396 | RuntimeHookSP hook(new RuntimeHook()); |
| 1397 | hook->address = addr; |
| 1398 | hook->defn = hook_defn; |
| 1399 | hook->bp_sp = target.CreateBreakpoint(addr, true, false); |
| 1400 | hook->bp_sp->SetCallback(HookCallback, hook.get(), true); |
| 1401 | m_runtimeHooks[addr] = hook; |
| 1402 | if (log) |
| 1403 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1404 | log->Printf("%s - successfully hooked '%s' in '%s' version %" PRIu64 " at 0x%" PRIx64 ".", |
| 1405 | __FUNCTION__, hook_defn->name, module->GetFileSpec().GetFilename().AsCString(), |
| 1406 | (uint64_t)hook_defn->version, (uint64_t)addr); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1407 | } |
| 1408 | } |
| 1409 | } |
| 1410 | |
| 1411 | void |
| 1412 | RenderScriptRuntime::FixupScriptDetails(RSModuleDescriptorSP rsmodule_sp) |
| 1413 | { |
| 1414 | if (!rsmodule_sp) |
| 1415 | return; |
| 1416 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1417 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE)); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1418 | |
| 1419 | const ModuleSP module = rsmodule_sp->m_module; |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1420 | const FileSpec &file = module->GetPlatformFileSpec(); |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 1421 | |
| 1422 | // Iterate over all of the scripts that we currently know of. |
| 1423 | // Note: We cant push or pop to m_scripts here or it may invalidate rs_script. |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1424 | for (const auto &rs_script : m_scripts) |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1425 | { |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 1426 | // Extract the expected .so file path for this script. |
| 1427 | std::string dylib; |
| 1428 | if (!rs_script->scriptDyLib.get(dylib)) |
| 1429 | continue; |
| 1430 | |
| 1431 | // Only proceed if the module that has loaded corresponds to this script. |
| 1432 | if (file.GetFilename() != ConstString(dylib.c_str())) |
| 1433 | continue; |
| 1434 | |
| 1435 | // Obtain the script address which we use as a key. |
| 1436 | lldb::addr_t script; |
| 1437 | if (!rs_script->script.get(script)) |
| 1438 | continue; |
| 1439 | |
| 1440 | // If we have a script mapping for the current script. |
| 1441 | if (m_scriptMappings.find(script) != m_scriptMappings.end()) |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1442 | { |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 1443 | // if the module we have stored is different to the one we just received. |
| 1444 | if (m_scriptMappings[script] != rsmodule_sp) |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1445 | { |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1446 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1447 | log->Printf("%s - script %" PRIx64 " wants reassigned to new rsmodule '%s'.", __FUNCTION__, |
| 1448 | (uint64_t)script, rsmodule_sp->m_module->GetFileSpec().GetFilename().AsCString()); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1449 | } |
| 1450 | } |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 1451 | // We don't have a script mapping for the current script. |
| 1452 | else |
| 1453 | { |
| 1454 | // Obtain the script resource name. |
| 1455 | std::string resName; |
| 1456 | if (rs_script->resName.get(resName)) |
| 1457 | // Set the modules resource name. |
| 1458 | rsmodule_sp->m_resname = resName; |
| 1459 | // Add Script/Module pair to map. |
| 1460 | m_scriptMappings[script] = rsmodule_sp; |
| 1461 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1462 | log->Printf("%s - script %" PRIx64 " associated with rsmodule '%s'.", __FUNCTION__, |
| 1463 | (uint64_t)script, rsmodule_sp->m_module->GetFileSpec().GetFilename().AsCString()); |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 1464 | } |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1465 | } |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 1466 | } |
| 1467 | |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1468 | // Uses the Target API to evaluate the expression passed as a parameter to the function |
Ed Maste | 75500e7 | 2016-07-19 15:28:02 +0000 | [diff] [blame] | 1469 | // The result of that expression is returned an unsigned 64 bit int, via the result* parameter. |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1470 | // Function returns true on success, and false on failure |
| 1471 | bool |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1472 | RenderScriptRuntime::EvalRSExpression(const char *expression, StackFrame *frame_ptr, uint64_t *result) |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1473 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1474 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE)); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1475 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1476 | log->Printf("%s(%s)", __FUNCTION__, expression); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1477 | |
| 1478 | ValueObjectSP expr_result; |
Aidan Dodds | 8433fdb | 2016-03-10 17:23:33 +0000 | [diff] [blame] | 1479 | EvaluateExpressionOptions options; |
| 1480 | options.SetLanguage(lldb::eLanguageTypeC_plus_plus); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1481 | // Perform the actual expression evaluation |
Aidan Dodds | 8433fdb | 2016-03-10 17:23:33 +0000 | [diff] [blame] | 1482 | GetProcess()->GetTarget().EvaluateExpression(expression, frame_ptr, expr_result, options); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1483 | |
| 1484 | if (!expr_result) |
| 1485 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1486 | if (log) |
| 1487 | log->Printf("%s: couldn't evaluate expression.", __FUNCTION__); |
| 1488 | return false; |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | // The result of the expression is invalid |
| 1492 | if (!expr_result->GetError().Success()) |
| 1493 | { |
| 1494 | Error err = expr_result->GetError(); |
| 1495 | if (err.GetError() == UserExpression::kNoResult) // Expression returned void, so this is actually a success |
| 1496 | { |
| 1497 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1498 | log->Printf("%s - expression returned void.", __FUNCTION__); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1499 | |
| 1500 | result = nullptr; |
| 1501 | return true; |
| 1502 | } |
| 1503 | |
| 1504 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1505 | log->Printf("%s - error evaluating expression result: %s", __FUNCTION__, |
| 1506 | err.AsCString()); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1507 | return false; |
| 1508 | } |
| 1509 | |
| 1510 | bool success = false; |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1511 | *result = expr_result->GetValueAsUnsigned(0, &success); // We only read the result as an uint32_t. |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1512 | |
| 1513 | if (!success) |
| 1514 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1515 | if (log) |
| 1516 | log->Printf("%s - couldn't convert expression result to uint32_t", __FUNCTION__); |
| 1517 | return false; |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | return true; |
| 1521 | } |
| 1522 | |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 1523 | namespace |
| 1524 | { |
Ewan Crawford | 836d965 | 2016-01-18 09:16:02 +0000 | [diff] [blame] | 1525 | // Used to index expression format strings |
| 1526 | enum ExpressionStrings |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1527 | { |
Ewan Crawford | 836d965 | 2016-01-18 09:16:02 +0000 | [diff] [blame] | 1528 | eExprGetOffsetPtr = 0, |
| 1529 | eExprAllocGetType, |
| 1530 | eExprTypeDimX, |
| 1531 | eExprTypeDimY, |
| 1532 | eExprTypeDimZ, |
| 1533 | eExprTypeElemPtr, |
| 1534 | eExprElementType, |
| 1535 | eExprElementKind, |
| 1536 | eExprElementVec, |
| 1537 | eExprElementFieldCount, |
| 1538 | eExprSubelementsId, |
| 1539 | eExprSubelementsName, |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 1540 | eExprSubelementsArrSize, |
| 1541 | |
| 1542 | _eExprLast // keep at the end, implicit size of the array runtimeExpressions |
Ewan Crawford | 836d965 | 2016-01-18 09:16:02 +0000 | [diff] [blame] | 1543 | }; |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1544 | |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 1545 | // max length of an expanded expression |
| 1546 | const int jit_max_expr_size = 512; |
| 1547 | |
| 1548 | // Retrieve the string to JIT for the given expression |
| 1549 | const char* |
| 1550 | JITTemplate(ExpressionStrings e) |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1551 | { |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 1552 | // Format strings containing the expressions we may need to evaluate. |
| 1553 | static std::array<const char*, _eExprLast> runtimeExpressions = {{ |
| 1554 | // Mangled GetOffsetPointer(Allocation*, xoff, yoff, zoff, lod, cubemap) |
Aidan Dodds | 577570b | 2016-02-24 14:17:33 +0000 | [diff] [blame] | 1555 | "(int*)_Z12GetOffsetPtrPKN7android12renderscript10AllocationEjjjj23RsAllocationCubemapFace" |
| 1556 | "(0x%" PRIx64 ", %" PRIu32 ", %" PRIu32 ", %" PRIu32 ", 0, 0)", |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1557 | |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 1558 | // Type* rsaAllocationGetType(Context*, Allocation*) |
Aidan Dodds | 577570b | 2016-02-24 14:17:33 +0000 | [diff] [blame] | 1559 | "(void*)rsaAllocationGetType(0x%" PRIx64 ", 0x%" PRIx64 ")", |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1560 | |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 1561 | // rsaTypeGetNativeData(Context*, Type*, void* typeData, size) |
| 1562 | // Pack the data in the following way mHal.state.dimX; mHal.state.dimY; mHal.state.dimZ; |
| 1563 | // mHal.state.lodCount; mHal.state.faces; mElement; into typeData |
| 1564 | // Need to specify 32 or 64 bit for uint_t since this differs between devices |
Aidan Dodds | 577570b | 2016-02-24 14:17:33 +0000 | [diff] [blame] | 1565 | "uint%" PRIu32 "_t data[6]; (void*)rsaTypeGetNativeData(0x%" PRIx64 ", 0x%" PRIx64 ", data, 6); data[0]", // X dim |
| 1566 | "uint%" PRIu32 "_t data[6]; (void*)rsaTypeGetNativeData(0x%" PRIx64 ", 0x%" PRIx64 ", data, 6); data[1]", // Y dim |
| 1567 | "uint%" PRIu32 "_t data[6]; (void*)rsaTypeGetNativeData(0x%" PRIx64 ", 0x%" PRIx64 ", data, 6); data[2]", // Z dim |
| 1568 | "uint%" PRIu32 "_t data[6]; (void*)rsaTypeGetNativeData(0x%" PRIx64 ", 0x%" PRIx64 ", data, 6); data[5]", // Element ptr |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1569 | |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 1570 | // rsaElementGetNativeData(Context*, Element*, uint32_t* elemData,size) |
| 1571 | // Pack mType; mKind; mNormalized; mVectorSize; NumSubElements into elemData |
Aidan Dodds | 577570b | 2016-02-24 14:17:33 +0000 | [diff] [blame] | 1572 | "uint32_t data[5]; (void*)rsaElementGetNativeData(0x%" PRIx64 ", 0x%" PRIx64 ", data, 5); data[0]", // Type |
| 1573 | "uint32_t data[5]; (void*)rsaElementGetNativeData(0x%" PRIx64 ", 0x%" PRIx64 ", data, 5); data[1]", // Kind |
| 1574 | "uint32_t data[5]; (void*)rsaElementGetNativeData(0x%" PRIx64 ", 0x%" PRIx64 ", data, 5); data[3]", // Vector Size |
| 1575 | "uint32_t data[5]; (void*)rsaElementGetNativeData(0x%" PRIx64 ", 0x%" PRIx64 ", data, 5); data[4]", // Field Count |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 1576 | |
Aidan Dodds | 577570b | 2016-02-24 14:17:33 +0000 | [diff] [blame] | 1577 | // rsaElementGetSubElements(RsContext con, RsElement elem, uintptr_t *ids, const char **names, |
| 1578 | // size_t *arraySizes, uint32_t dataSize) |
| 1579 | // Needed for Allocations of structs to gather details about fields/Subelements |
| 1580 | // Element* of field |
| 1581 | "void* ids[%" PRIu32 "]; const char* names[%" PRIu32 "]; size_t arr_size[%" PRIu32 "];" |
| 1582 | "(void*)rsaElementGetSubElements(0x%" PRIx64 ", 0x%" PRIx64 ", ids, names, arr_size, %" PRIu32 "); ids[%" PRIu32 "]", |
Ewan Crawford | 836d965 | 2016-01-18 09:16:02 +0000 | [diff] [blame] | 1583 | |
Aidan Dodds | 577570b | 2016-02-24 14:17:33 +0000 | [diff] [blame] | 1584 | // Name of field |
| 1585 | "void* ids[%" PRIu32 "]; const char* names[%" PRIu32 "]; size_t arr_size[%" PRIu32 "];" |
| 1586 | "(void*)rsaElementGetSubElements(0x%" PRIx64 ", 0x%" PRIx64 ", ids, names, arr_size, %" PRIu32 "); names[%" PRIu32 "]", |
Ewan Crawford | 836d965 | 2016-01-18 09:16:02 +0000 | [diff] [blame] | 1587 | |
Aidan Dodds | 577570b | 2016-02-24 14:17:33 +0000 | [diff] [blame] | 1588 | // Array size of field |
| 1589 | "void* ids[%" PRIu32 "]; const char* names[%" PRIu32 "]; size_t arr_size[%" PRIu32 "];" |
| 1590 | "(void*)rsaElementGetSubElements(0x%" PRIx64 ", 0x%" PRIx64 ", ids, names, arr_size, %" PRIu32 "); arr_size[%" PRIu32 "]" |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 1591 | }}; |
| 1592 | |
| 1593 | return runtimeExpressions[e]; |
| 1594 | } |
| 1595 | } // end of the anonymous namespace |
| 1596 | |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1597 | |
| 1598 | // JITs the RS runtime for the internal data pointer of an allocation. |
| 1599 | // Is passed x,y,z coordinates for the pointer to a specific element. |
| 1600 | // Then sets the data_ptr member in Allocation with the result. |
| 1601 | // Returns true on success, false otherwise |
| 1602 | bool |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1603 | RenderScriptRuntime::JITDataPointer(AllocationDetails *allocation, StackFrame *frame_ptr, uint32_t x, |
| 1604 | uint32_t y, uint32_t z) |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1605 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1606 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE)); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1607 | |
| 1608 | if (!allocation->address.isValid()) |
| 1609 | { |
| 1610 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1611 | log->Printf("%s - failed to find allocation details.", __FUNCTION__); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1612 | return false; |
| 1613 | } |
| 1614 | |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 1615 | const char *expr_cstr = JITTemplate(eExprGetOffsetPtr); |
| 1616 | char buffer[jit_max_expr_size]; |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1617 | |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 1618 | int chars_written = snprintf(buffer, jit_max_expr_size, expr_cstr, *allocation->address.get(), x, y, z); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1619 | if (chars_written < 0) |
| 1620 | { |
| 1621 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1622 | log->Printf("%s - encoding error in snprintf().", __FUNCTION__); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1623 | return false; |
| 1624 | } |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 1625 | else if (chars_written >= jit_max_expr_size) |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1626 | { |
| 1627 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1628 | log->Printf("%s - expression too long.", __FUNCTION__); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1629 | return false; |
| 1630 | } |
| 1631 | |
| 1632 | uint64_t result = 0; |
| 1633 | if (!EvalRSExpression(buffer, frame_ptr, &result)) |
| 1634 | return false; |
| 1635 | |
| 1636 | addr_t mem_ptr = static_cast<lldb::addr_t>(result); |
| 1637 | allocation->data_ptr = mem_ptr; |
| 1638 | |
| 1639 | return true; |
| 1640 | } |
| 1641 | |
| 1642 | // JITs the RS runtime for the internal pointer to the RS Type of an allocation |
| 1643 | // Then sets the type_ptr member in Allocation with the result. |
| 1644 | // Returns true on success, false otherwise |
| 1645 | bool |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1646 | RenderScriptRuntime::JITTypePointer(AllocationDetails *allocation, StackFrame *frame_ptr) |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1647 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1648 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE)); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1649 | |
| 1650 | if (!allocation->address.isValid() || !allocation->context.isValid()) |
| 1651 | { |
| 1652 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1653 | log->Printf("%s - failed to find allocation details.", __FUNCTION__); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1654 | return false; |
| 1655 | } |
| 1656 | |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 1657 | const char *expr_cstr = JITTemplate(eExprAllocGetType); |
| 1658 | char buffer[jit_max_expr_size]; |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1659 | |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 1660 | int chars_written = |
| 1661 | snprintf(buffer, jit_max_expr_size, expr_cstr, *allocation->context.get(), *allocation->address.get()); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1662 | if (chars_written < 0) |
| 1663 | { |
| 1664 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1665 | log->Printf("%s - encoding error in snprintf().", __FUNCTION__); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1666 | return false; |
| 1667 | } |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 1668 | else if (chars_written >= jit_max_expr_size) |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1669 | { |
| 1670 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1671 | log->Printf("%s - expression too long.", __FUNCTION__); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1672 | return false; |
| 1673 | } |
| 1674 | |
| 1675 | uint64_t result = 0; |
| 1676 | if (!EvalRSExpression(buffer, frame_ptr, &result)) |
| 1677 | return false; |
| 1678 | |
| 1679 | addr_t type_ptr = static_cast<lldb::addr_t>(result); |
| 1680 | allocation->type_ptr = type_ptr; |
| 1681 | |
| 1682 | return true; |
| 1683 | } |
| 1684 | |
| 1685 | // JITs the RS runtime for information about the dimensions and type of an allocation |
| 1686 | // Then sets dimension and element_ptr members in Allocation with the result. |
| 1687 | // Returns true on success, false otherwise |
| 1688 | bool |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1689 | RenderScriptRuntime::JITTypePacked(AllocationDetails *allocation, StackFrame *frame_ptr) |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1690 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1691 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE)); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1692 | |
| 1693 | if (!allocation->type_ptr.isValid() || !allocation->context.isValid()) |
| 1694 | { |
| 1695 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1696 | log->Printf("%s - Failed to find allocation details.", __FUNCTION__); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1697 | return false; |
| 1698 | } |
| 1699 | |
| 1700 | // Expression is different depending on if device is 32 or 64 bit |
| 1701 | uint32_t archByteSize = GetProcess()->GetTarget().GetArchitecture().GetAddressByteSize(); |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1702 | const uint32_t bits = archByteSize == 4 ? 32 : 64; |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1703 | |
| 1704 | // We want 4 elements from packed data |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1705 | const uint32_t num_exprs = 4; |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1706 | assert(num_exprs == (eExprTypeElemPtr - eExprTypeDimX + 1) && "Invalid number of expressions"); |
| 1707 | |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 1708 | char buffer[num_exprs][jit_max_expr_size]; |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1709 | uint64_t results[num_exprs]; |
| 1710 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1711 | for (uint32_t i = 0; i < num_exprs; ++i) |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1712 | { |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 1713 | const char *expr_cstr = JITTemplate(ExpressionStrings(eExprTypeDimX + i)); |
| 1714 | int chars_written = snprintf(buffer[i], jit_max_expr_size, expr_cstr, bits, *allocation->context.get(), |
| 1715 | *allocation->type_ptr.get()); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1716 | if (chars_written < 0) |
| 1717 | { |
| 1718 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1719 | log->Printf("%s - encoding error in snprintf().", __FUNCTION__); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1720 | return false; |
| 1721 | } |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 1722 | else if (chars_written >= jit_max_expr_size) |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1723 | { |
| 1724 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1725 | log->Printf("%s - expression too long.", __FUNCTION__); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1726 | return false; |
| 1727 | } |
| 1728 | |
| 1729 | // Perform expression evaluation |
| 1730 | if (!EvalRSExpression(buffer[i], frame_ptr, &results[i])) |
| 1731 | return false; |
| 1732 | } |
| 1733 | |
| 1734 | // Assign results to allocation members |
| 1735 | AllocationDetails::Dimension dims; |
| 1736 | dims.dim_1 = static_cast<uint32_t>(results[0]); |
| 1737 | dims.dim_2 = static_cast<uint32_t>(results[1]); |
| 1738 | dims.dim_3 = static_cast<uint32_t>(results[2]); |
| 1739 | allocation->dimension = dims; |
| 1740 | |
| 1741 | addr_t elem_ptr = static_cast<lldb::addr_t>(results[3]); |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 1742 | allocation->element.element_ptr = elem_ptr; |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1743 | |
| 1744 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1745 | log->Printf("%s - dims (%" PRIu32 ", %" PRIu32 ", %" PRIu32 ") Element*: 0x%" PRIx64 ".", __FUNCTION__, |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1746 | dims.dim_1, dims.dim_2, dims.dim_3, elem_ptr); |
| 1747 | |
| 1748 | return true; |
| 1749 | } |
| 1750 | |
| 1751 | // JITs the RS runtime for information about the Element of an allocation |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 1752 | // Then sets type, type_vec_size, field_count and type_kind members in Element with the result. |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1753 | // Returns true on success, false otherwise |
| 1754 | bool |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1755 | RenderScriptRuntime::JITElementPacked(Element &elem, const lldb::addr_t context, StackFrame *frame_ptr) |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1756 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1757 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE)); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1758 | |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 1759 | if (!elem.element_ptr.isValid()) |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1760 | { |
| 1761 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1762 | log->Printf("%s - failed to find allocation details.", __FUNCTION__); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1763 | return false; |
| 1764 | } |
| 1765 | |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 1766 | // We want 4 elements from packed data |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1767 | const uint32_t num_exprs = 4; |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 1768 | assert(num_exprs == (eExprElementFieldCount - eExprElementType + 1) && "Invalid number of expressions"); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1769 | |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 1770 | char buffer[num_exprs][jit_max_expr_size]; |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1771 | uint64_t results[num_exprs]; |
| 1772 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1773 | for (uint32_t i = 0; i < num_exprs; i++) |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1774 | { |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 1775 | const char *expr_cstr = JITTemplate(ExpressionStrings(eExprElementType + i)); |
| 1776 | int chars_written = snprintf(buffer[i], jit_max_expr_size, expr_cstr, context, *elem.element_ptr.get()); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1777 | if (chars_written < 0) |
| 1778 | { |
| 1779 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1780 | log->Printf("%s - encoding error in snprintf().", __FUNCTION__); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1781 | return false; |
| 1782 | } |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 1783 | else if (chars_written >= jit_max_expr_size) |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1784 | { |
| 1785 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1786 | log->Printf("%s - expression too long.", __FUNCTION__); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1787 | return false; |
| 1788 | } |
| 1789 | |
| 1790 | // Perform expression evaluation |
| 1791 | if (!EvalRSExpression(buffer[i], frame_ptr, &results[i])) |
| 1792 | return false; |
| 1793 | } |
| 1794 | |
| 1795 | // Assign results to allocation members |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 1796 | elem.type = static_cast<RenderScriptRuntime::Element::DataType>(results[0]); |
| 1797 | elem.type_kind = static_cast<RenderScriptRuntime::Element::DataKind>(results[1]); |
| 1798 | elem.type_vec_size = static_cast<uint32_t>(results[2]); |
| 1799 | elem.field_count = static_cast<uint32_t>(results[3]); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1800 | |
| 1801 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1802 | log->Printf("%s - data type %" PRIu32 ", pixel type %" PRIu32 ", vector size %" PRIu32 ", field count %" PRIu32, |
| 1803 | __FUNCTION__, *elem.type.get(), *elem.type_kind.get(), *elem.type_vec_size.get(), *elem.field_count.get()); |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 1804 | |
| 1805 | // If this Element has subelements then JIT rsaElementGetSubElements() for details about its fields |
| 1806 | if (*elem.field_count.get() > 0 && !JITSubelements(elem, context, frame_ptr)) |
| 1807 | return false; |
| 1808 | |
| 1809 | return true; |
| 1810 | } |
| 1811 | |
| 1812 | // JITs the RS runtime for information about the subelements/fields of a struct allocation |
| 1813 | // This is necessary for infering the struct type so we can pretty print the allocation's contents. |
| 1814 | // Returns true on success, false otherwise |
| 1815 | bool |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1816 | RenderScriptRuntime::JITSubelements(Element &elem, const lldb::addr_t context, StackFrame *frame_ptr) |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 1817 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1818 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE)); |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 1819 | |
| 1820 | if (!elem.element_ptr.isValid() || !elem.field_count.isValid()) |
| 1821 | { |
| 1822 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1823 | log->Printf("%s - failed to find allocation details.", __FUNCTION__); |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 1824 | return false; |
| 1825 | } |
| 1826 | |
| 1827 | const short num_exprs = 3; |
| 1828 | assert(num_exprs == (eExprSubelementsArrSize - eExprSubelementsId + 1) && "Invalid number of expressions"); |
| 1829 | |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 1830 | char expr_buffer[jit_max_expr_size]; |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 1831 | uint64_t results; |
| 1832 | |
| 1833 | // Iterate over struct fields. |
| 1834 | const uint32_t field_count = *elem.field_count.get(); |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1835 | for (uint32_t field_index = 0; field_index < field_count; ++field_index) |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 1836 | { |
| 1837 | Element child; |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1838 | for (uint32_t expr_index = 0; expr_index < num_exprs; ++expr_index) |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 1839 | { |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 1840 | const char *expr_cstr = JITTemplate(ExpressionStrings(eExprSubelementsId + expr_index)); |
| 1841 | int chars_written = snprintf(expr_buffer, jit_max_expr_size, expr_cstr, |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 1842 | field_count, field_count, field_count, |
| 1843 | context, *elem.element_ptr.get(), field_count, field_index); |
| 1844 | if (chars_written < 0) |
| 1845 | { |
| 1846 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1847 | log->Printf("%s - encoding error in snprintf().", __FUNCTION__); |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 1848 | return false; |
| 1849 | } |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 1850 | else if (chars_written >= jit_max_expr_size) |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 1851 | { |
| 1852 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1853 | log->Printf("%s - expression too long.", __FUNCTION__); |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 1854 | return false; |
| 1855 | } |
| 1856 | |
| 1857 | // Perform expression evaluation |
| 1858 | if (!EvalRSExpression(expr_buffer, frame_ptr, &results)) |
| 1859 | return false; |
| 1860 | |
| 1861 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1862 | log->Printf("%s - expr result 0x%" PRIx64 ".", __FUNCTION__, results); |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 1863 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1864 | switch (expr_index) |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 1865 | { |
| 1866 | case 0: // Element* of child |
| 1867 | child.element_ptr = static_cast<addr_t>(results); |
| 1868 | break; |
| 1869 | case 1: // Name of child |
| 1870 | { |
| 1871 | lldb::addr_t address = static_cast<addr_t>(results); |
| 1872 | Error err; |
| 1873 | std::string name; |
| 1874 | GetProcess()->ReadCStringFromMemory(address, name, err); |
| 1875 | if (!err.Fail()) |
| 1876 | child.type_name = ConstString(name); |
| 1877 | else |
| 1878 | { |
| 1879 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1880 | log->Printf("%s - warning: Couldn't read field name.", __FUNCTION__); |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 1881 | } |
| 1882 | break; |
| 1883 | } |
| 1884 | case 2: // Array size of child |
| 1885 | child.array_size = static_cast<uint32_t>(results); |
| 1886 | break; |
| 1887 | } |
| 1888 | } |
| 1889 | |
| 1890 | // We need to recursively JIT each Element field of the struct since |
| 1891 | // structs can be nested inside structs. |
| 1892 | if (!JITElementPacked(child, context, frame_ptr)) |
| 1893 | return false; |
| 1894 | elem.children.push_back(child); |
| 1895 | } |
| 1896 | |
| 1897 | // Try to infer the name of the struct type so we can pretty print the allocation contents. |
| 1898 | FindStructTypeName(elem, frame_ptr); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 1899 | |
| 1900 | return true; |
| 1901 | } |
| 1902 | |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 1903 | // JITs the RS runtime for the address of the last element in the allocation. |
Ed Maste | 75500e7 | 2016-07-19 15:28:02 +0000 | [diff] [blame] | 1904 | // The `elem_size` parameter represents the size of a single element, including padding. |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 1905 | // Which is needed as an offset from the last element pointer. |
| 1906 | // Using this offset minus the starting address we can calculate the size of the allocation. |
| 1907 | // Returns true on success, false otherwise |
| 1908 | bool |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1909 | RenderScriptRuntime::JITAllocationSize(AllocationDetails *allocation, StackFrame *frame_ptr) |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 1910 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1911 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE)); |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 1912 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1913 | if (!allocation->address.isValid() || !allocation->dimension.isValid() || !allocation->data_ptr.isValid() || |
| 1914 | !allocation->element.datum_size.isValid()) |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 1915 | { |
| 1916 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1917 | log->Printf("%s - failed to find allocation details.", __FUNCTION__); |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 1918 | return false; |
| 1919 | } |
| 1920 | |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 1921 | // Find dimensions |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1922 | uint32_t dim_x = allocation->dimension.get()->dim_1; |
| 1923 | uint32_t dim_y = allocation->dimension.get()->dim_2; |
| 1924 | uint32_t dim_z = allocation->dimension.get()->dim_3; |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 1925 | |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 1926 | // Our plan of jitting the last element address doesn't seem to work for struct Allocations |
| 1927 | // Instead try to infer the size ourselves without any inter element padding. |
| 1928 | if (allocation->element.children.size() > 0) |
| 1929 | { |
| 1930 | if (dim_x == 0) dim_x = 1; |
| 1931 | if (dim_y == 0) dim_y = 1; |
| 1932 | if (dim_z == 0) dim_z = 1; |
| 1933 | |
| 1934 | allocation->size = dim_x * dim_y * dim_z * *allocation->element.datum_size.get(); |
| 1935 | |
| 1936 | if (log) |
Ed Maste | 75500e7 | 2016-07-19 15:28:02 +0000 | [diff] [blame] | 1937 | log->Printf("%s - inferred size of struct allocation %" PRIu32 ".", __FUNCTION__, |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1938 | *allocation->size.get()); |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 1939 | return true; |
| 1940 | } |
| 1941 | |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 1942 | const char *expr_cstr = JITTemplate(eExprGetOffsetPtr); |
| 1943 | char buffer[jit_max_expr_size]; |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 1944 | |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 1945 | // Calculate last element |
| 1946 | dim_x = dim_x == 0 ? 0 : dim_x - 1; |
| 1947 | dim_y = dim_y == 0 ? 0 : dim_y - 1; |
| 1948 | dim_z = dim_z == 0 ? 0 : dim_z - 1; |
| 1949 | |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 1950 | int chars_written = snprintf(buffer, jit_max_expr_size, expr_cstr, *allocation->address.get(), dim_x, dim_y, dim_z); |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 1951 | if (chars_written < 0) |
| 1952 | { |
| 1953 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1954 | log->Printf("%s - encoding error in snprintf().", __FUNCTION__); |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 1955 | return false; |
| 1956 | } |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 1957 | else if (chars_written >= jit_max_expr_size) |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 1958 | { |
| 1959 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1960 | log->Printf("%s - expression too long.", __FUNCTION__); |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 1961 | return false; |
| 1962 | } |
| 1963 | |
| 1964 | uint64_t result = 0; |
| 1965 | if (!EvalRSExpression(buffer, frame_ptr, &result)) |
| 1966 | return false; |
| 1967 | |
| 1968 | addr_t mem_ptr = static_cast<lldb::addr_t>(result); |
| 1969 | // Find pointer to last element and add on size of an element |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1970 | allocation->size = |
| 1971 | static_cast<uint32_t>(mem_ptr - *allocation->data_ptr.get()) + *allocation->element.datum_size.get(); |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 1972 | |
| 1973 | return true; |
| 1974 | } |
| 1975 | |
| 1976 | // JITs the RS runtime for information about the stride between rows in the allocation. |
| 1977 | // This is done to detect padding, since allocated memory is 16-byte aligned. |
| 1978 | // Returns true on success, false otherwise |
| 1979 | bool |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1980 | RenderScriptRuntime::JITAllocationStride(AllocationDetails *allocation, StackFrame *frame_ptr) |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 1981 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1982 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE)); |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 1983 | |
| 1984 | if (!allocation->address.isValid() || !allocation->data_ptr.isValid()) |
| 1985 | { |
| 1986 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1987 | log->Printf("%s - failed to find allocation details.", __FUNCTION__); |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 1988 | return false; |
| 1989 | } |
| 1990 | |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 1991 | const char *expr_cstr = JITTemplate(eExprGetOffsetPtr); |
| 1992 | char buffer[jit_max_expr_size]; |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 1993 | |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 1994 | int chars_written = snprintf(buffer, jit_max_expr_size, expr_cstr, *allocation->address.get(), 0, 1, 0); |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 1995 | if (chars_written < 0) |
| 1996 | { |
| 1997 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 1998 | log->Printf("%s - encoding error in snprintf().", __FUNCTION__); |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 1999 | return false; |
| 2000 | } |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 2001 | else if (chars_written >= jit_max_expr_size) |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2002 | { |
| 2003 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2004 | log->Printf("%s - expression too long.", __FUNCTION__); |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2005 | return false; |
| 2006 | } |
| 2007 | |
| 2008 | uint64_t result = 0; |
| 2009 | if (!EvalRSExpression(buffer, frame_ptr, &result)) |
| 2010 | return false; |
| 2011 | |
| 2012 | addr_t mem_ptr = static_cast<lldb::addr_t>(result); |
| 2013 | allocation->stride = static_cast<uint32_t>(mem_ptr - *allocation->data_ptr.get()); |
| 2014 | |
| 2015 | return true; |
| 2016 | } |
| 2017 | |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 2018 | // JIT all the current runtime info regarding an allocation |
| 2019 | bool |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2020 | RenderScriptRuntime::RefreshAllocation(AllocationDetails *allocation, StackFrame *frame_ptr) |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 2021 | { |
| 2022 | // GetOffsetPointer() |
| 2023 | if (!JITDataPointer(allocation, frame_ptr)) |
| 2024 | return false; |
| 2025 | |
| 2026 | // rsaAllocationGetType() |
| 2027 | if (!JITTypePointer(allocation, frame_ptr)) |
| 2028 | return false; |
| 2029 | |
| 2030 | // rsaTypeGetNativeData() |
| 2031 | if (!JITTypePacked(allocation, frame_ptr)) |
| 2032 | return false; |
| 2033 | |
| 2034 | // rsaElementGetNativeData() |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 2035 | if (!JITElementPacked(allocation->element, *allocation->context.get(), frame_ptr)) |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 2036 | return false; |
| 2037 | |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 2038 | // Sets the datum_size member in Element |
| 2039 | SetElementSize(allocation->element); |
| 2040 | |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2041 | // Use GetOffsetPointer() to infer size of the allocation |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 2042 | if (!JITAllocationSize(allocation, frame_ptr)) |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2043 | return false; |
| 2044 | |
| 2045 | return true; |
| 2046 | } |
| 2047 | |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 2048 | // Function attempts to set the type_name member of the paramaterised Element object. |
| 2049 | // This string should be the name of the struct type the Element represents. |
| 2050 | // We need this string for pretty printing the Element to users. |
| 2051 | void |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2052 | RenderScriptRuntime::FindStructTypeName(Element &elem, StackFrame *frame_ptr) |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2053 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2054 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE)); |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 2055 | |
| 2056 | if (!elem.type_name.IsEmpty()) // Name already set |
| 2057 | return; |
| 2058 | else |
Adrian McCarthy | fe06b5a | 2015-11-30 22:18:43 +0000 | [diff] [blame] | 2059 | elem.type_name = Element::GetFallbackStructName(); // Default type name if we don't succeed |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 2060 | |
| 2061 | // Find all the global variables from the script rs modules |
| 2062 | VariableList variable_list; |
| 2063 | for (auto module_sp : m_rsmodules) |
| 2064 | module_sp->m_module->FindGlobalVariables(RegularExpression("."), true, UINT32_MAX, variable_list); |
| 2065 | |
| 2066 | // Iterate over all the global variables looking for one with a matching type to the Element. |
| 2067 | // We make the assumption a match exists since there needs to be a global variable to reflect the |
| 2068 | // struct type back into java host code. |
| 2069 | for (uint32_t var_index = 0; var_index < variable_list.GetSize(); ++var_index) |
| 2070 | { |
| 2071 | const VariableSP var_sp(variable_list.GetVariableAtIndex(var_index)); |
| 2072 | if (!var_sp) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2073 | continue; |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 2074 | |
| 2075 | ValueObjectSP valobj_sp = ValueObjectVariable::Create(frame_ptr, var_sp); |
| 2076 | if (!valobj_sp) |
| 2077 | continue; |
| 2078 | |
| 2079 | // Find the number of variable fields. |
| 2080 | // If it has no fields, or more fields than our Element, then it can't be the struct we're looking for. |
| 2081 | // Don't check for equality since RS can add extra struct members for padding. |
| 2082 | size_t num_children = valobj_sp->GetNumChildren(); |
| 2083 | if (num_children > elem.children.size() || num_children == 0) |
| 2084 | continue; |
| 2085 | |
| 2086 | // Iterate over children looking for members with matching field names. |
| 2087 | // If all the field names match, this is likely the struct we want. |
| 2088 | // |
| 2089 | // TODO: This could be made more robust by also checking children data sizes, or array size |
| 2090 | bool found = true; |
| 2091 | for (size_t child_index = 0; child_index < num_children; ++child_index) |
| 2092 | { |
| 2093 | ValueObjectSP child = valobj_sp->GetChildAtIndex(child_index, true); |
| 2094 | if (!child || (child->GetName() != elem.children[child_index].type_name)) |
| 2095 | { |
| 2096 | found = false; |
| 2097 | break; |
| 2098 | } |
| 2099 | } |
| 2100 | |
| 2101 | // RS can add extra struct members for padding in the format '#rs_padding_[0-9]+' |
| 2102 | if (found && num_children < elem.children.size()) |
| 2103 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2104 | const uint32_t size_diff = elem.children.size() - num_children; |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 2105 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2106 | log->Printf("%s - %" PRIu32 " padding struct entries", __FUNCTION__, size_diff); |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 2107 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2108 | for (uint32_t padding_index = 0; padding_index < size_diff; ++padding_index) |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 2109 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2110 | const ConstString &name = elem.children[num_children + padding_index].type_name; |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 2111 | if (strcmp(name.AsCString(), "#rs_padding") < 0) |
| 2112 | found = false; |
| 2113 | } |
| 2114 | } |
| 2115 | |
| 2116 | // We've found a global var with matching type |
| 2117 | if (found) |
| 2118 | { |
| 2119 | // Dereference since our Element type isn't a pointer. |
| 2120 | if (valobj_sp->IsPointerType()) |
| 2121 | { |
| 2122 | Error err; |
| 2123 | ValueObjectSP deref_valobj = valobj_sp->Dereference(err); |
| 2124 | if (!err.Fail()) |
| 2125 | valobj_sp = deref_valobj; |
| 2126 | } |
| 2127 | |
| 2128 | // Save name of variable in Element. |
| 2129 | elem.type_name = valobj_sp->GetTypeName(); |
| 2130 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2131 | log->Printf("%s - element name set to %s", __FUNCTION__, elem.type_name.AsCString()); |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 2132 | |
| 2133 | return; |
| 2134 | } |
| 2135 | } |
| 2136 | } |
| 2137 | |
| 2138 | // Function sets the datum_size member of Element. Representing the size of a single instance including padding. |
| 2139 | // Assumes the relevant allocation information has already been jitted. |
| 2140 | void |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2141 | RenderScriptRuntime::SetElementSize(Element &elem) |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 2142 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2143 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE)); |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 2144 | const Element::DataType type = *elem.type.get(); |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2145 | assert(type >= Element::RS_TYPE_NONE && type <= Element::RS_TYPE_FONT && "Invalid allocation type"); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2146 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2147 | const uint32_t vec_size = *elem.type_vec_size.get(); |
| 2148 | uint32_t data_size = 0; |
| 2149 | uint32_t padding = 0; |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2150 | |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 2151 | // Element is of a struct type, calculate size recursively. |
| 2152 | if ((type == Element::RS_TYPE_NONE) && (elem.children.size() > 0)) |
| 2153 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2154 | for (Element &child : elem.children) |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 2155 | { |
| 2156 | SetElementSize(child); |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2157 | const uint32_t array_size = child.array_size.isValid() ? *child.array_size.get() : 1; |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 2158 | data_size += *child.datum_size.get() * array_size; |
| 2159 | } |
| 2160 | } |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2161 | // These have been packed already |
| 2162 | else if (type == Element::RS_TYPE_UNSIGNED_5_6_5 || |
| 2163 | type == Element::RS_TYPE_UNSIGNED_5_5_5_1 || |
| 2164 | type == Element::RS_TYPE_UNSIGNED_4_4_4_4) |
Ewan Crawford | 2e92071 | 2015-12-17 16:40:05 +0000 | [diff] [blame] | 2165 | { |
| 2166 | data_size = AllocationDetails::RSTypeToFormat[type][eElementSize]; |
| 2167 | } |
| 2168 | else if (type < Element::RS_TYPE_ELEMENT) |
| 2169 | { |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 2170 | data_size = vec_size * AllocationDetails::RSTypeToFormat[type][eElementSize]; |
Ewan Crawford | 2e92071 | 2015-12-17 16:40:05 +0000 | [diff] [blame] | 2171 | if (vec_size == 3) |
| 2172 | padding = AllocationDetails::RSTypeToFormat[type][eElementSize]; |
| 2173 | } |
| 2174 | else |
| 2175 | data_size = GetProcess()->GetTarget().GetArchitecture().GetAddressByteSize(); |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 2176 | |
| 2177 | elem.padding = padding; |
| 2178 | elem.datum_size = data_size + padding; |
| 2179 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2180 | log->Printf("%s - element size set to %" PRIu32, __FUNCTION__, data_size + padding); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2181 | } |
| 2182 | |
| 2183 | // Given an allocation, this function copies the allocation contents from device into a buffer on the heap. |
| 2184 | // Returning a shared pointer to the buffer containing the data. |
| 2185 | std::shared_ptr<uint8_t> |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2186 | RenderScriptRuntime::GetAllocationData(AllocationDetails *allocation, StackFrame *frame_ptr) |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2187 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2188 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE)); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2189 | |
| 2190 | // JIT all the allocation details |
Ewan Crawford | 8b59062 | 2015-12-10 10:20:39 +0000 | [diff] [blame] | 2191 | if (allocation->shouldRefresh()) |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2192 | { |
| 2193 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2194 | log->Printf("%s - allocation details not calculated yet, jitting info", __FUNCTION__); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2195 | |
| 2196 | if (!RefreshAllocation(allocation, frame_ptr)) |
| 2197 | { |
| 2198 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2199 | log->Printf("%s - couldn't JIT allocation details", __FUNCTION__); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2200 | return nullptr; |
| 2201 | } |
| 2202 | } |
| 2203 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2204 | assert(allocation->data_ptr.isValid() && allocation->element.type.isValid() && |
| 2205 | allocation->element.type_vec_size.isValid() && allocation->size.isValid() && |
| 2206 | "Allocation information not available"); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2207 | |
| 2208 | // Allocate a buffer to copy data into |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2209 | const uint32_t size = *allocation->size.get(); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2210 | std::shared_ptr<uint8_t> buffer(new uint8_t[size]); |
| 2211 | if (!buffer) |
| 2212 | { |
| 2213 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2214 | log->Printf("%s - couldn't allocate a %" PRIu32 " byte buffer", __FUNCTION__, size); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2215 | return nullptr; |
| 2216 | } |
| 2217 | |
| 2218 | // Read the inferior memory |
| 2219 | Error error; |
| 2220 | lldb::addr_t data_ptr = *allocation->data_ptr.get(); |
| 2221 | GetProcess()->ReadMemory(data_ptr, buffer.get(), size, error); |
| 2222 | if (error.Fail()) |
| 2223 | { |
| 2224 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2225 | log->Printf("%s - '%s' Couldn't read %" PRIu32 " bytes of allocation data from 0x%" PRIx64, |
| 2226 | __FUNCTION__, error.AsCString(), size, data_ptr); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2227 | return nullptr; |
| 2228 | } |
| 2229 | |
| 2230 | return buffer; |
| 2231 | } |
| 2232 | |
| 2233 | // Function copies data from a binary file into an allocation. |
| 2234 | // There is a header at the start of the file, FileHeader, before the data content itself. |
Ed Maste | 75500e7 | 2016-07-19 15:28:02 +0000 | [diff] [blame] | 2235 | // Information from this header is used to display warnings to the user about incompatibilities |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2236 | bool |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2237 | RenderScriptRuntime::LoadAllocation(Stream &strm, const uint32_t alloc_id, const char *filename, StackFrame *frame_ptr) |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2238 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2239 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE)); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2240 | |
| 2241 | // Find allocation with the given id |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2242 | AllocationDetails *alloc = FindAllocByID(strm, alloc_id); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2243 | if (!alloc) |
| 2244 | return false; |
| 2245 | |
| 2246 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2247 | log->Printf("%s - found allocation 0x%" PRIx64, __FUNCTION__, *alloc->address.get()); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2248 | |
| 2249 | // JIT all the allocation details |
Ewan Crawford | 8b59062 | 2015-12-10 10:20:39 +0000 | [diff] [blame] | 2250 | if (alloc->shouldRefresh()) |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2251 | { |
| 2252 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2253 | log->Printf("%s - allocation details not calculated yet, jitting info.", __FUNCTION__); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2254 | |
| 2255 | if (!RefreshAllocation(alloc, frame_ptr)) |
| 2256 | { |
| 2257 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2258 | log->Printf("%s - couldn't JIT allocation details", __FUNCTION__); |
Sylvestre Ledru | 4cfc919 | 2015-10-26 08:49:04 +0000 | [diff] [blame] | 2259 | return false; |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2260 | } |
| 2261 | } |
| 2262 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2263 | assert(alloc->data_ptr.isValid() && alloc->element.type.isValid() && alloc->element.type_vec_size.isValid() && |
| 2264 | alloc->size.isValid() && alloc->element.datum_size.isValid() && "Allocation information not available"); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2265 | |
| 2266 | // Check we can read from file |
| 2267 | FileSpec file(filename, true); |
| 2268 | if (!file.Exists()) |
| 2269 | { |
| 2270 | strm.Printf("Error: File %s does not exist", filename); |
| 2271 | strm.EOL(); |
| 2272 | return false; |
| 2273 | } |
| 2274 | |
| 2275 | if (!file.Readable()) |
| 2276 | { |
| 2277 | strm.Printf("Error: File %s does not have readable permissions", filename); |
| 2278 | strm.EOL(); |
| 2279 | return false; |
| 2280 | } |
| 2281 | |
| 2282 | // Read file into data buffer |
| 2283 | DataBufferSP data_sp(file.ReadFileContents()); |
| 2284 | |
| 2285 | // Cast start of buffer to FileHeader and use pointer to read metadata |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2286 | void *file_buffer = data_sp->GetBytes(); |
| 2287 | if (file_buffer == nullptr || |
| 2288 | data_sp->GetByteSize() < (sizeof(AllocationDetails::FileHeader) + sizeof(AllocationDetails::ElementHeader))) |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 2289 | { |
| 2290 | strm.Printf("Error: File %s does not contain enough data for header", filename); |
| 2291 | strm.EOL(); |
| 2292 | return false; |
| 2293 | } |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2294 | const AllocationDetails::FileHeader *file_header = static_cast<AllocationDetails::FileHeader *>(file_buffer); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2295 | |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 2296 | // Check file starts with ascii characters "RSAD" |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2297 | if (memcmp(file_header->ident, "RSAD", 4)) |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 2298 | { |
| 2299 | strm.Printf("Error: File doesn't contain identifier for an RS allocation dump. Are you sure this is the correct file?"); |
| 2300 | strm.EOL(); |
| 2301 | return false; |
| 2302 | } |
| 2303 | |
| 2304 | // Look at the type of the root element in the header |
| 2305 | AllocationDetails::ElementHeader root_element_header; |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2306 | memcpy(&root_element_header, static_cast<uint8_t *>(file_buffer) + sizeof(AllocationDetails::FileHeader), |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 2307 | sizeof(AllocationDetails::ElementHeader)); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2308 | |
| 2309 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2310 | log->Printf("%s - header type %" PRIu32 ", element size %" PRIu32, __FUNCTION__, |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 2311 | root_element_header.type, root_element_header.element_size); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2312 | |
| 2313 | // Check if the target allocation and file both have the same number of bytes for an Element |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 2314 | if (*alloc->element.datum_size.get() != root_element_header.element_size) |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2315 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2316 | strm.Printf("Warning: Mismatched Element sizes - file %" PRIu32 " bytes, allocation %" PRIu32 " bytes", |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 2317 | root_element_header.element_size, *alloc->element.datum_size.get()); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2318 | strm.EOL(); |
| 2319 | } |
| 2320 | |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 2321 | // Check if the target allocation and file both have the same type |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2322 | const uint32_t alloc_type = static_cast<uint32_t>(*alloc->element.type.get()); |
| 2323 | const uint32_t file_type = root_element_header.type; |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 2324 | |
| 2325 | if (file_type > Element::RS_TYPE_FONT) |
| 2326 | { |
| 2327 | strm.Printf("Warning: File has unknown allocation type"); |
| 2328 | strm.EOL(); |
| 2329 | } |
| 2330 | else if (alloc_type != file_type) |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2331 | { |
Ewan Crawford | 2e92071 | 2015-12-17 16:40:05 +0000 | [diff] [blame] | 2332 | // Enum value isn't monotonous, so doesn't always index RsDataTypeToString array |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2333 | uint32_t printable_target_type_index = alloc_type; |
| 2334 | uint32_t printable_head_type_index = file_type; |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 2335 | if (alloc_type >= Element::RS_TYPE_ELEMENT && alloc_type <= Element::RS_TYPE_FONT) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2336 | printable_target_type_index = static_cast<Element::DataType>((alloc_type - Element::RS_TYPE_ELEMENT) + |
| 2337 | Element::RS_TYPE_MATRIX_2X2 + 1); |
Ewan Crawford | 2e92071 | 2015-12-17 16:40:05 +0000 | [diff] [blame] | 2338 | |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 2339 | if (file_type >= Element::RS_TYPE_ELEMENT && file_type <= Element::RS_TYPE_FONT) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2340 | printable_head_type_index = static_cast<Element::DataType>((file_type - Element::RS_TYPE_ELEMENT) + |
| 2341 | Element::RS_TYPE_MATRIX_2X2 + 1); |
Ewan Crawford | 2e92071 | 2015-12-17 16:40:05 +0000 | [diff] [blame] | 2342 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2343 | const char *file_type_cstr = AllocationDetails::RsDataTypeToString[printable_head_type_index][0]; |
| 2344 | const char *target_type_cstr = AllocationDetails::RsDataTypeToString[printable_target_type_index][0]; |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2345 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2346 | strm.Printf("Warning: Mismatched Types - file '%s' type, allocation '%s' type", file_type_cstr, |
| 2347 | target_type_cstr); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2348 | strm.EOL(); |
| 2349 | } |
| 2350 | |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 2351 | // Advance buffer past header |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2352 | file_buffer = static_cast<uint8_t *>(file_buffer) + file_header->hdr_size; |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 2353 | |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2354 | // Calculate size of allocation data in file |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 2355 | size_t length = data_sp->GetByteSize() - file_header->hdr_size; |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2356 | |
| 2357 | // Check if the target allocation and file both have the same total data size. |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2358 | const uint32_t alloc_size = *alloc->size.get(); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2359 | if (alloc_size != length) |
| 2360 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2361 | strm.Printf("Warning: Mismatched allocation sizes - file 0x%" PRIx64 " bytes, allocation 0x%" PRIx32 " bytes", |
| 2362 | (uint64_t)length, alloc_size); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2363 | strm.EOL(); |
| 2364 | length = alloc_size < length ? alloc_size : length; // Set length to copy to minimum |
| 2365 | } |
| 2366 | |
| 2367 | // Copy file data from our buffer into the target allocation. |
| 2368 | lldb::addr_t alloc_data = *alloc->data_ptr.get(); |
| 2369 | Error error; |
| 2370 | size_t bytes_written = GetProcess()->WriteMemory(alloc_data, file_buffer, length, error); |
| 2371 | if (!error.Success() || bytes_written != length) |
| 2372 | { |
| 2373 | strm.Printf("Error: Couldn't write data to allocation %s", error.AsCString()); |
| 2374 | strm.EOL(); |
| 2375 | return false; |
| 2376 | } |
| 2377 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2378 | strm.Printf("Contents of file '%s' read into allocation %" PRIu32, filename, alloc->id); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2379 | strm.EOL(); |
| 2380 | |
| 2381 | return true; |
| 2382 | } |
| 2383 | |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 2384 | // Function takes as parameters a byte buffer, which will eventually be written to file as the element header, |
| 2385 | // an offset into that buffer, and an Element that will be saved into the buffer at the parametrised offset. |
| 2386 | // Return value is the new offset after writing the element into the buffer. |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2387 | // Elements are saved to the file as the ElementHeader struct followed by offsets to the structs of all the element's |
| 2388 | // children. |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 2389 | size_t |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2390 | RenderScriptRuntime::PopulateElementHeaders(const std::shared_ptr<uint8_t> header_buffer, size_t offset, |
| 2391 | const Element &elem) |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 2392 | { |
| 2393 | // File struct for an element header with all the relevant details copied from elem. |
| 2394 | // We assume members are valid already. |
| 2395 | AllocationDetails::ElementHeader elem_header; |
| 2396 | elem_header.type = *elem.type.get(); |
| 2397 | elem_header.kind = *elem.type_kind.get(); |
| 2398 | elem_header.element_size = *elem.datum_size.get(); |
| 2399 | elem_header.vector_size = *elem.type_vec_size.get(); |
| 2400 | elem_header.array_size = elem.array_size.isValid() ? *elem.array_size.get() : 0; |
| 2401 | const size_t elem_header_size = sizeof(AllocationDetails::ElementHeader); |
| 2402 | |
| 2403 | // Copy struct into buffer and advance offset |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2404 | // We assume that header_buffer has been checked for nullptr before this method is called |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 2405 | memcpy(header_buffer.get() + offset, &elem_header, elem_header_size); |
| 2406 | offset += elem_header_size; |
| 2407 | |
| 2408 | // Starting offset of child ElementHeader struct |
| 2409 | size_t child_offset = offset + ((elem.children.size() + 1) * sizeof(uint32_t)); |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2410 | for (const RenderScriptRuntime::Element &child : elem.children) |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 2411 | { |
| 2412 | // Recursively populate the buffer with the element header structs of children. |
| 2413 | // Then save the offsets where they were set after the parent element header. |
| 2414 | memcpy(header_buffer.get() + offset, &child_offset, sizeof(uint32_t)); |
| 2415 | offset += sizeof(uint32_t); |
| 2416 | |
| 2417 | child_offset = PopulateElementHeaders(header_buffer, child_offset, child); |
| 2418 | } |
| 2419 | |
| 2420 | // Zero indicates no more children |
| 2421 | memset(header_buffer.get() + offset, 0, sizeof(uint32_t)); |
| 2422 | |
| 2423 | return child_offset; |
| 2424 | } |
| 2425 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2426 | // Given an Element object this function returns the total size needed in the file header to store the element's |
| 2427 | // details. |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 2428 | // Taking into account the size of the element header struct, plus the offsets to all the element's children. |
| 2429 | // Function is recursive so that the size of all ancestors is taken into account. |
| 2430 | size_t |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2431 | RenderScriptRuntime::CalculateElementHeaderSize(const Element &elem) |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 2432 | { |
| 2433 | size_t size = (elem.children.size() + 1) * sizeof(uint32_t); // Offsets to children plus zero terminator |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2434 | size += sizeof(AllocationDetails::ElementHeader); // Size of header struct with type details |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 2435 | |
| 2436 | // Calculate recursively for all descendants |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2437 | for (const Element &child : elem.children) |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 2438 | size += CalculateElementHeaderSize(child); |
| 2439 | |
| 2440 | return size; |
| 2441 | } |
| 2442 | |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2443 | // Function copies allocation contents into a binary file. |
| 2444 | // This file can then be loaded later into a different allocation. |
| 2445 | // There is a header, FileHeader, before the allocation data containing meta-data. |
| 2446 | bool |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2447 | RenderScriptRuntime::SaveAllocation(Stream &strm, const uint32_t alloc_id, const char *filename, StackFrame *frame_ptr) |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2448 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2449 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE)); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2450 | |
| 2451 | // Find allocation with the given id |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2452 | AllocationDetails *alloc = FindAllocByID(strm, alloc_id); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2453 | if (!alloc) |
| 2454 | return false; |
| 2455 | |
| 2456 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2457 | log->Printf("%s - found allocation 0x%" PRIx64 ".", __FUNCTION__, *alloc->address.get()); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2458 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2459 | // JIT all the allocation details |
Ewan Crawford | 8b59062 | 2015-12-10 10:20:39 +0000 | [diff] [blame] | 2460 | if (alloc->shouldRefresh()) |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2461 | { |
| 2462 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2463 | log->Printf("%s - allocation details not calculated yet, jitting info.", __FUNCTION__); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2464 | |
| 2465 | if (!RefreshAllocation(alloc, frame_ptr)) |
| 2466 | { |
| 2467 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2468 | log->Printf("%s - couldn't JIT allocation details.", __FUNCTION__); |
Sylvestre Ledru | 4cfc919 | 2015-10-26 08:49:04 +0000 | [diff] [blame] | 2469 | return false; |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2470 | } |
| 2471 | } |
| 2472 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2473 | assert(alloc->data_ptr.isValid() && alloc->element.type.isValid() && alloc->element.type_vec_size.isValid() && |
| 2474 | alloc->element.datum_size.get() && alloc->element.type_kind.isValid() && alloc->dimension.isValid() && |
| 2475 | "Allocation information not available"); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2476 | |
| 2477 | // Check we can create writable file |
| 2478 | FileSpec file_spec(filename, true); |
| 2479 | File file(file_spec, File::eOpenOptionWrite | File::eOpenOptionCanCreate | File::eOpenOptionTruncate); |
| 2480 | if (!file) |
| 2481 | { |
| 2482 | strm.Printf("Error: Failed to open '%s' for writing", filename); |
| 2483 | strm.EOL(); |
| 2484 | return false; |
| 2485 | } |
| 2486 | |
| 2487 | // Read allocation into buffer of heap memory |
| 2488 | const std::shared_ptr<uint8_t> buffer = GetAllocationData(alloc, frame_ptr); |
| 2489 | if (!buffer) |
| 2490 | { |
| 2491 | strm.Printf("Error: Couldn't read allocation data into buffer"); |
| 2492 | strm.EOL(); |
| 2493 | return false; |
| 2494 | } |
| 2495 | |
| 2496 | // Create the file header |
| 2497 | AllocationDetails::FileHeader head; |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2498 | memcpy(head.ident, "RSAD", 4); |
Ewan Crawford | 2d62328 | 2015-10-21 10:27:10 +0000 | [diff] [blame] | 2499 | head.dims[0] = static_cast<uint32_t>(alloc->dimension.get()->dim_1); |
| 2500 | head.dims[1] = static_cast<uint32_t>(alloc->dimension.get()->dim_2); |
| 2501 | head.dims[2] = static_cast<uint32_t>(alloc->dimension.get()->dim_3); |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 2502 | |
| 2503 | const size_t element_header_size = CalculateElementHeaderSize(alloc->element); |
| 2504 | assert((sizeof(AllocationDetails::FileHeader) + element_header_size) < UINT16_MAX && "Element header too large"); |
| 2505 | head.hdr_size = static_cast<uint16_t>(sizeof(AllocationDetails::FileHeader) + element_header_size); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2506 | |
| 2507 | // Write the file header |
| 2508 | size_t num_bytes = sizeof(AllocationDetails::FileHeader); |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 2509 | if (log) |
Greg Clayton | cec91ef | 2016-02-26 01:20:20 +0000 | [diff] [blame] | 2510 | log->Printf("%s - writing File Header, 0x%" PRIx64 " bytes", __FUNCTION__, (uint64_t)num_bytes); |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 2511 | |
| 2512 | Error err = file.Write(&head, num_bytes); |
| 2513 | if (!err.Success()) |
| 2514 | { |
| 2515 | strm.Printf("Error: '%s' when writing to file '%s'", err.AsCString(), filename); |
| 2516 | strm.EOL(); |
| 2517 | return false; |
| 2518 | } |
| 2519 | |
| 2520 | // Create the headers describing the element type of the allocation. |
| 2521 | std::shared_ptr<uint8_t> element_header_buffer(new uint8_t[element_header_size]); |
| 2522 | if (element_header_buffer == nullptr) |
| 2523 | { |
Greg Clayton | cec91ef | 2016-02-26 01:20:20 +0000 | [diff] [blame] | 2524 | strm.Printf("Internal Error: Couldn't allocate %" PRIu64 " bytes on the heap", (uint64_t)element_header_size); |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 2525 | strm.EOL(); |
| 2526 | return false; |
| 2527 | } |
| 2528 | |
| 2529 | PopulateElementHeaders(element_header_buffer, 0, alloc->element); |
| 2530 | |
| 2531 | // Write headers for allocation element type to file |
| 2532 | num_bytes = element_header_size; |
| 2533 | if (log) |
Greg Clayton | cec91ef | 2016-02-26 01:20:20 +0000 | [diff] [blame] | 2534 | log->Printf("%s - writing element headers, 0x%" PRIx64 " bytes.", __FUNCTION__, (uint64_t)num_bytes); |
Ewan Crawford | 26e52a7 | 2016-01-07 10:19:09 +0000 | [diff] [blame] | 2535 | |
| 2536 | err = file.Write(element_header_buffer.get(), num_bytes); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2537 | if (!err.Success()) |
| 2538 | { |
| 2539 | strm.Printf("Error: '%s' when writing to file '%s'", err.AsCString(), filename); |
| 2540 | strm.EOL(); |
| 2541 | return false; |
| 2542 | } |
| 2543 | |
| 2544 | // Write allocation data to file |
| 2545 | num_bytes = static_cast<size_t>(*alloc->size.get()); |
| 2546 | if (log) |
Greg Clayton | cec91ef | 2016-02-26 01:20:20 +0000 | [diff] [blame] | 2547 | log->Printf("%s - writing 0x%" PRIx64 " bytes", __FUNCTION__, (uint64_t)num_bytes); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2548 | |
| 2549 | err = file.Write(buffer.get(), num_bytes); |
| 2550 | if (!err.Success()) |
| 2551 | { |
| 2552 | strm.Printf("Error: '%s' when writing to file '%s'", err.AsCString(), filename); |
| 2553 | strm.EOL(); |
| 2554 | return false; |
| 2555 | } |
| 2556 | |
| 2557 | strm.Printf("Allocation written to file '%s'", filename); |
| 2558 | strm.EOL(); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 2559 | return true; |
| 2560 | } |
| 2561 | |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 2562 | bool |
| 2563 | RenderScriptRuntime::LoadModule(const lldb::ModuleSP &module_sp) |
| 2564 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2565 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE)); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 2566 | |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 2567 | if (module_sp) |
| 2568 | { |
| 2569 | for (const auto &rs_module : m_rsmodules) |
| 2570 | { |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 2571 | if (rs_module->m_module == module_sp) |
Ewan Crawford | 7dc7771 | 2015-09-10 10:08:48 +0000 | [diff] [blame] | 2572 | { |
| 2573 | // Check if the user has enabled automatically breaking on |
| 2574 | // all RS kernels. |
| 2575 | if (m_breakAllKernels) |
| 2576 | BreakOnModuleKernels(rs_module); |
| 2577 | |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 2578 | return false; |
Ewan Crawford | 7dc7771 | 2015-09-10 10:08:48 +0000 | [diff] [blame] | 2579 | } |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 2580 | } |
Colin Riley | ef20b08 | 2015-04-14 07:39:24 +0000 | [diff] [blame] | 2581 | bool module_loaded = false; |
| 2582 | switch (GetModuleKind(module_sp)) |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 2583 | { |
Colin Riley | ef20b08 | 2015-04-14 07:39:24 +0000 | [diff] [blame] | 2584 | case eModuleKindKernelObj: |
| 2585 | { |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 2586 | RSModuleDescriptorSP module_desc; |
| 2587 | module_desc.reset(new RSModuleDescriptor(module_sp)); |
| 2588 | if (module_desc->ParseRSInfo()) |
Colin Riley | ef20b08 | 2015-04-14 07:39:24 +0000 | [diff] [blame] | 2589 | { |
| 2590 | m_rsmodules.push_back(module_desc); |
| 2591 | module_loaded = true; |
| 2592 | } |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 2593 | if (module_loaded) |
| 2594 | { |
| 2595 | FixupScriptDetails(module_desc); |
| 2596 | } |
Colin Riley | ef20b08 | 2015-04-14 07:39:24 +0000 | [diff] [blame] | 2597 | break; |
| 2598 | } |
| 2599 | case eModuleKindDriver: |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 2600 | { |
| 2601 | if (!m_libRSDriver) |
| 2602 | { |
| 2603 | m_libRSDriver = module_sp; |
| 2604 | LoadRuntimeHooks(m_libRSDriver, RenderScriptRuntime::eModuleKindDriver); |
| 2605 | } |
| 2606 | break; |
| 2607 | } |
Colin Riley | ef20b08 | 2015-04-14 07:39:24 +0000 | [diff] [blame] | 2608 | case eModuleKindImpl: |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 2609 | { |
| 2610 | m_libRSCpuRef = module_sp; |
| 2611 | break; |
| 2612 | } |
Colin Riley | ef20b08 | 2015-04-14 07:39:24 +0000 | [diff] [blame] | 2613 | case eModuleKindLibRS: |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 2614 | { |
Aidan Dodds | 35e7b1a | 2016-01-06 15:43:52 +0000 | [diff] [blame] | 2615 | if (!m_libRS) |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 2616 | { |
| 2617 | m_libRS = module_sp; |
| 2618 | static ConstString gDbgPresentStr("gDebuggerPresent"); |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2619 | const Symbol *debug_present = |
| 2620 | m_libRS->FindFirstSymbolWithNameAndType(gDbgPresentStr, eSymbolTypeData); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 2621 | if (debug_present) |
| 2622 | { |
| 2623 | Error error; |
| 2624 | uint32_t flag = 0x00000001U; |
| 2625 | Target &target = GetProcess()->GetTarget(); |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2626 | addr_t addr = debug_present->GetLoadAddress(&target); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 2627 | GetProcess()->WriteMemory(addr, &flag, sizeof(flag), error); |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2628 | if (error.Success()) |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 2629 | { |
| 2630 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2631 | log->Printf("%s - debugger present flag set on debugee.", __FUNCTION__); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 2632 | |
| 2633 | m_debuggerPresentFlagged = true; |
| 2634 | } |
| 2635 | else if (log) |
| 2636 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2637 | log->Printf("%s - error writing debugger present flags '%s' ", __FUNCTION__, |
| 2638 | error.AsCString()); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 2639 | } |
| 2640 | } |
| 2641 | else if (log) |
| 2642 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2643 | log->Printf("%s - error writing debugger present flags - symbol not found", __FUNCTION__); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 2644 | } |
| 2645 | } |
| 2646 | break; |
| 2647 | } |
Colin Riley | ef20b08 | 2015-04-14 07:39:24 +0000 | [diff] [blame] | 2648 | default: |
| 2649 | break; |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 2650 | } |
Colin Riley | ef20b08 | 2015-04-14 07:39:24 +0000 | [diff] [blame] | 2651 | if (module_loaded) |
Aidan Dodds | 35e7b1a | 2016-01-06 15:43:52 +0000 | [diff] [blame] | 2652 | Update(); |
Colin Riley | ef20b08 | 2015-04-14 07:39:24 +0000 | [diff] [blame] | 2653 | return module_loaded; |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 2654 | } |
| 2655 | return false; |
| 2656 | } |
| 2657 | |
Colin Riley | ef20b08 | 2015-04-14 07:39:24 +0000 | [diff] [blame] | 2658 | void |
| 2659 | RenderScriptRuntime::Update() |
| 2660 | { |
| 2661 | if (m_rsmodules.size() > 0) |
| 2662 | { |
| 2663 | if (!m_initiated) |
| 2664 | { |
| 2665 | Initiate(); |
| 2666 | } |
| 2667 | } |
| 2668 | } |
| 2669 | |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 2670 | // The maximum line length of an .rs.info packet |
| 2671 | #define MAXLINE 500 |
Aidan Dodds | b0be30f | 2016-02-18 10:59:46 +0000 | [diff] [blame] | 2672 | #define STRINGIFY(x) #x |
| 2673 | #define MAXLINESTR_(x) "%" STRINGIFY(x) "s" |
| 2674 | #define MAXLINESTR MAXLINESTR_(MAXLINE) |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 2675 | |
| 2676 | // The .rs.info symbol in renderscript modules contains a string which needs to be parsed. |
| 2677 | // The string is basic and is parsed on a line by line basis. |
| 2678 | bool |
| 2679 | RSModuleDescriptor::ParseRSInfo() |
| 2680 | { |
Aidan Dodds | b0be30f | 2016-02-18 10:59:46 +0000 | [diff] [blame] | 2681 | assert(m_module); |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 2682 | const Symbol *info_sym = m_module->FindFirstSymbolWithNameAndType(ConstString(".rs.info"), eSymbolTypeData); |
Aidan Dodds | b0be30f | 2016-02-18 10:59:46 +0000 | [diff] [blame] | 2683 | if (!info_sym) |
| 2684 | return false; |
| 2685 | |
| 2686 | const addr_t addr = info_sym->GetAddressRef().GetFileAddress(); |
| 2687 | if (addr == LLDB_INVALID_ADDRESS) |
| 2688 | return false; |
| 2689 | |
| 2690 | const addr_t size = info_sym->GetByteSize(); |
| 2691 | const FileSpec fs = m_module->GetFileSpec(); |
| 2692 | |
| 2693 | const DataBufferSP buffer = fs.ReadFileContents(addr, size); |
| 2694 | if (!buffer) |
| 2695 | return false; |
| 2696 | |
| 2697 | // split rs.info. contents into lines |
| 2698 | std::vector<std::string> info_lines; |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 2699 | { |
Aidan Dodds | b0be30f | 2016-02-18 10:59:46 +0000 | [diff] [blame] | 2700 | const std::string info((const char *)buffer->GetBytes()); |
| 2701 | for (size_t tail = 0; tail < info.size();) |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 2702 | { |
Aidan Dodds | b0be30f | 2016-02-18 10:59:46 +0000 | [diff] [blame] | 2703 | // find next new line or end of string |
| 2704 | size_t head = info.find('\n', tail); |
| 2705 | head = (head == std::string::npos) ? info.size() : head; |
| 2706 | std::string line = info.substr(tail, head - tail); |
| 2707 | // add to line list |
| 2708 | info_lines.push_back(line); |
| 2709 | tail = head + 1; |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 2710 | } |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 2711 | } |
Aidan Dodds | b0be30f | 2016-02-18 10:59:46 +0000 | [diff] [blame] | 2712 | |
Saleem Abdulrasool | 7ccf137 | 2016-02-23 04:56:31 +0000 | [diff] [blame] | 2713 | std::array<char, MAXLINE> name{{'\0'}}; |
| 2714 | std::array<char, MAXLINE> value{{'\0'}}; |
Aidan Dodds | b0be30f | 2016-02-18 10:59:46 +0000 | [diff] [blame] | 2715 | |
| 2716 | // parse all text lines of .rs.info |
| 2717 | for (auto line = info_lines.begin(); line != info_lines.end(); ++line) |
| 2718 | { |
| 2719 | uint32_t numDefns = 0; |
| 2720 | if (sscanf(line->c_str(), "exportVarCount: %" PRIu32 "", &numDefns) == 1) |
| 2721 | { |
| 2722 | while (numDefns--) |
| 2723 | m_globals.push_back(RSGlobalDescriptor(this, (++line)->c_str())); |
| 2724 | } |
| 2725 | else if (sscanf(line->c_str(), "exportForEachCount: %" PRIu32 "", &numDefns) == 1) |
| 2726 | { |
| 2727 | while (numDefns--) |
| 2728 | { |
| 2729 | uint32_t slot = 0; |
| 2730 | name[0] = '\0'; |
| 2731 | static const char *fmt_s = "%" PRIu32 " - " MAXLINESTR; |
| 2732 | if (sscanf((++line)->c_str(), fmt_s, &slot, name.data()) == 2) |
| 2733 | { |
| 2734 | if (name[0] != '\0') |
| 2735 | m_kernels.push_back(RSKernelDescriptor(this, name.data(), slot)); |
| 2736 | } |
| 2737 | } |
| 2738 | } |
| 2739 | else if (sscanf(line->c_str(), "pragmaCount: %" PRIu32 "", &numDefns) == 1) |
| 2740 | { |
| 2741 | while (numDefns--) |
| 2742 | { |
| 2743 | name[0] = value[0] = '\0'; |
| 2744 | static const char *fmt_s = MAXLINESTR " - " MAXLINESTR; |
| 2745 | if (sscanf((++line)->c_str(), fmt_s, name.data(), value.data()) != 0) |
| 2746 | { |
| 2747 | if (name[0] != '\0') |
| 2748 | m_pragmas[std::string(name.data())] = value.data(); |
| 2749 | } |
| 2750 | } |
| 2751 | } |
| 2752 | else |
| 2753 | { |
| 2754 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE)); |
| 2755 | if (log) |
| 2756 | { |
| 2757 | log->Printf("%s - skipping .rs.info field '%s'", __FUNCTION__, line->c_str()); |
| 2758 | } |
| 2759 | } |
| 2760 | } |
| 2761 | |
| 2762 | // 'root' kernel should always be present |
| 2763 | return m_kernels.size() > 0; |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 2764 | } |
| 2765 | |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 2766 | void |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 2767 | RenderScriptRuntime::Status(Stream &strm) const |
| 2768 | { |
| 2769 | if (m_libRS) |
| 2770 | { |
| 2771 | strm.Printf("Runtime Library discovered."); |
| 2772 | strm.EOL(); |
| 2773 | } |
| 2774 | if (m_libRSDriver) |
| 2775 | { |
| 2776 | strm.Printf("Runtime Driver discovered."); |
| 2777 | strm.EOL(); |
| 2778 | } |
| 2779 | if (m_libRSCpuRef) |
| 2780 | { |
| 2781 | strm.Printf("CPU Reference Implementation discovered."); |
| 2782 | strm.EOL(); |
| 2783 | } |
Aidan Dodds | 35e7b1a | 2016-01-06 15:43:52 +0000 | [diff] [blame] | 2784 | |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 2785 | if (m_runtimeHooks.size()) |
| 2786 | { |
| 2787 | strm.Printf("Runtime functions hooked:"); |
| 2788 | strm.EOL(); |
| 2789 | for (auto b : m_runtimeHooks) |
| 2790 | { |
| 2791 | strm.Indent(b.second->defn->name); |
| 2792 | strm.EOL(); |
| 2793 | } |
Aidan Dodds | 35e7b1a | 2016-01-06 15:43:52 +0000 | [diff] [blame] | 2794 | } |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 2795 | else |
| 2796 | { |
| 2797 | strm.Printf("Runtime is not hooked."); |
| 2798 | strm.EOL(); |
| 2799 | } |
| 2800 | } |
| 2801 | |
Aidan Dodds | 35e7b1a | 2016-01-06 15:43:52 +0000 | [diff] [blame] | 2802 | void |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 2803 | RenderScriptRuntime::DumpContexts(Stream &strm) const |
| 2804 | { |
| 2805 | strm.Printf("Inferred RenderScript Contexts:"); |
| 2806 | strm.EOL(); |
| 2807 | strm.IndentMore(); |
| 2808 | |
| 2809 | std::map<addr_t, uint64_t> contextReferences; |
| 2810 | |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 2811 | // Iterate over all of the currently discovered scripts. |
| 2812 | // Note: We cant push or pop from m_scripts inside this loop or it may invalidate script. |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2813 | for (const auto &script : m_scripts) |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 2814 | { |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 2815 | if (!script->context.isValid()) |
| 2816 | continue; |
| 2817 | lldb::addr_t context = *script->context; |
| 2818 | |
| 2819 | if (contextReferences.find(context) != contextReferences.end()) |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 2820 | { |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 2821 | contextReferences[context]++; |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 2822 | } |
| 2823 | else |
| 2824 | { |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 2825 | contextReferences[context] = 1; |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 2826 | } |
| 2827 | } |
| 2828 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2829 | for (const auto &cRef : contextReferences) |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 2830 | { |
| 2831 | strm.Printf("Context 0x%" PRIx64 ": %" PRIu64 " script instances", cRef.first, cRef.second); |
| 2832 | strm.EOL(); |
| 2833 | } |
| 2834 | strm.IndentLess(); |
| 2835 | } |
| 2836 | |
Aidan Dodds | 35e7b1a | 2016-01-06 15:43:52 +0000 | [diff] [blame] | 2837 | void |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 2838 | RenderScriptRuntime::DumpKernels(Stream &strm) const |
| 2839 | { |
| 2840 | strm.Printf("RenderScript Kernels:"); |
| 2841 | strm.EOL(); |
| 2842 | strm.IndentMore(); |
| 2843 | for (const auto &module : m_rsmodules) |
| 2844 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2845 | strm.Printf("Resource '%s':", module->m_resname.c_str()); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 2846 | strm.EOL(); |
| 2847 | for (const auto &kernel : module->m_kernels) |
| 2848 | { |
| 2849 | strm.Indent(kernel.m_name.AsCString()); |
| 2850 | strm.EOL(); |
| 2851 | } |
| 2852 | } |
| 2853 | strm.IndentLess(); |
| 2854 | } |
| 2855 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2856 | RenderScriptRuntime::AllocationDetails * |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2857 | RenderScriptRuntime::FindAllocByID(Stream &strm, const uint32_t alloc_id) |
| 2858 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2859 | AllocationDetails *alloc = nullptr; |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2860 | |
| 2861 | // See if we can find allocation using id as an index; |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2862 | if (alloc_id <= m_allocations.size() && alloc_id != 0 && m_allocations[alloc_id - 1]->id == alloc_id) |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2863 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2864 | alloc = m_allocations[alloc_id - 1].get(); |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2865 | return alloc; |
| 2866 | } |
| 2867 | |
| 2868 | // Fallback to searching |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2869 | for (const auto &a : m_allocations) |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2870 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2871 | if (a->id == alloc_id) |
| 2872 | { |
| 2873 | alloc = a.get(); |
| 2874 | break; |
| 2875 | } |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2876 | } |
| 2877 | |
| 2878 | if (alloc == nullptr) |
| 2879 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2880 | strm.Printf("Error: Couldn't find allocation with id matching %" PRIu32, alloc_id); |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2881 | strm.EOL(); |
| 2882 | } |
| 2883 | |
| 2884 | return alloc; |
| 2885 | } |
| 2886 | |
| 2887 | // Prints the contents of an allocation to the output stream, which may be a file |
| 2888 | bool |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2889 | RenderScriptRuntime::DumpAllocation(Stream &strm, StackFrame *frame_ptr, const uint32_t id) |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2890 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2891 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE)); |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2892 | |
| 2893 | // Check we can find the desired allocation |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2894 | AllocationDetails *alloc = FindAllocByID(strm, id); |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2895 | if (!alloc) |
| 2896 | return false; // FindAllocByID() will print error message for us here |
| 2897 | |
| 2898 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2899 | log->Printf("%s - found allocation 0x%" PRIx64, __FUNCTION__, *alloc->address.get()); |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2900 | |
| 2901 | // Check we have information about the allocation, if not calculate it |
Ewan Crawford | 8b59062 | 2015-12-10 10:20:39 +0000 | [diff] [blame] | 2902 | if (alloc->shouldRefresh()) |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2903 | { |
| 2904 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2905 | log->Printf("%s - allocation details not calculated yet, jitting info.", __FUNCTION__); |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2906 | |
| 2907 | // JIT all the allocation information |
| 2908 | if (!RefreshAllocation(alloc, frame_ptr)) |
| 2909 | { |
| 2910 | strm.Printf("Error: Couldn't JIT allocation details"); |
| 2911 | strm.EOL(); |
| 2912 | return false; |
| 2913 | } |
| 2914 | } |
| 2915 | |
| 2916 | // Establish format and size of each data element |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2917 | const uint32_t vec_size = *alloc->element.type_vec_size.get(); |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 2918 | const Element::DataType type = *alloc->element.type.get(); |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2919 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2920 | assert(type >= Element::RS_TYPE_NONE && type <= Element::RS_TYPE_FONT && "Invalid allocation type"); |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2921 | |
Ewan Crawford | 2e92071 | 2015-12-17 16:40:05 +0000 | [diff] [blame] | 2922 | lldb::Format format; |
| 2923 | if (type >= Element::RS_TYPE_ELEMENT) |
| 2924 | format = eFormatHex; |
| 2925 | else |
| 2926 | format = vec_size == 1 ? static_cast<lldb::Format>(AllocationDetails::RSTypeToFormat[type][eFormatSingle]) |
| 2927 | : static_cast<lldb::Format>(AllocationDetails::RSTypeToFormat[type][eFormatVector]); |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2928 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2929 | const uint32_t data_size = *alloc->element.datum_size.get(); |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2930 | |
| 2931 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2932 | log->Printf("%s - element size %" PRIu32 " bytes, including padding", __FUNCTION__, data_size); |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2933 | |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2934 | // Allocate a buffer to copy data into |
| 2935 | std::shared_ptr<uint8_t> buffer = GetAllocationData(alloc, frame_ptr); |
| 2936 | if (!buffer) |
| 2937 | { |
Ewan Crawford | 2e92071 | 2015-12-17 16:40:05 +0000 | [diff] [blame] | 2938 | strm.Printf("Error: Couldn't read allocation data"); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2939 | strm.EOL(); |
| 2940 | return false; |
| 2941 | } |
| 2942 | |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2943 | // Calculate stride between rows as there may be padding at end of rows since |
| 2944 | // allocated memory is 16-byte aligned |
| 2945 | if (!alloc->stride.isValid()) |
| 2946 | { |
| 2947 | if (alloc->dimension.get()->dim_2 == 0) // We only have one dimension |
| 2948 | alloc->stride = 0; |
| 2949 | else if (!JITAllocationStride(alloc, frame_ptr)) |
| 2950 | { |
| 2951 | strm.Printf("Error: Couldn't calculate allocation row stride"); |
| 2952 | strm.EOL(); |
| 2953 | return false; |
| 2954 | } |
| 2955 | } |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2956 | const uint32_t stride = *alloc->stride.get(); |
| 2957 | const uint32_t size = *alloc->size.get(); // Size of whole allocation |
| 2958 | const uint32_t padding = alloc->element.padding.isValid() ? *alloc->element.padding.get() : 0; |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2959 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2960 | log->Printf("%s - stride %" PRIu32 " bytes, size %" PRIu32 " bytes, padding %" PRIu32, |
| 2961 | __FUNCTION__, stride, size, padding); |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2962 | |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2963 | // Find dimensions used to index loops, so need to be non-zero |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2964 | uint32_t dim_x = alloc->dimension.get()->dim_1; |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2965 | dim_x = dim_x == 0 ? 1 : dim_x; |
| 2966 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2967 | uint32_t dim_y = alloc->dimension.get()->dim_2; |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2968 | dim_y = dim_y == 0 ? 1 : dim_y; |
| 2969 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2970 | uint32_t dim_z = alloc->dimension.get()->dim_3; |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2971 | dim_z = dim_z == 0 ? 1 : dim_z; |
| 2972 | |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 2973 | // Use data extractor to format output |
| 2974 | const uint32_t archByteSize = GetProcess()->GetTarget().GetArchitecture().GetAddressByteSize(); |
| 2975 | DataExtractor alloc_data(buffer.get(), size, GetProcess()->GetByteOrder(), archByteSize); |
| 2976 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2977 | uint32_t offset = 0; // Offset in buffer to next element to be printed |
| 2978 | uint32_t prev_row = 0; // Offset to the start of the previous row |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2979 | |
| 2980 | // Iterate over allocation dimensions, printing results to user |
| 2981 | strm.Printf("Data (X, Y, Z):"); |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2982 | for (uint32_t z = 0; z < dim_z; ++z) |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2983 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2984 | for (uint32_t y = 0; y < dim_y; ++y) |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2985 | { |
| 2986 | // Use stride to index start of next row. |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2987 | if (!(y == 0 && z == 0)) |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2988 | offset = prev_row + stride; |
| 2989 | prev_row = offset; |
| 2990 | |
| 2991 | // Print each element in the row individually |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2992 | for (uint32_t x = 0; x < dim_x; ++x) |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 2993 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 2994 | strm.Printf("\n(%" PRIu32 ", %" PRIu32 ", %" PRIu32 ") = ", x, y, z); |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 2995 | if ((type == Element::RS_TYPE_NONE) && (alloc->element.children.size() > 0) && |
Adrian McCarthy | fe06b5a | 2015-11-30 22:18:43 +0000 | [diff] [blame] | 2996 | (alloc->element.type_name != Element::GetFallbackStructName())) |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 2997 | { |
| 2998 | // Here we are dumping an Element of struct type. |
| 2999 | // This is done using expression evaluation with the name of the struct type and pointer to element. |
| 3000 | |
| 3001 | // Don't print the name of the resulting expression, since this will be '$[0-9]+' |
| 3002 | DumpValueObjectOptions expr_options; |
| 3003 | expr_options.SetHideName(true); |
| 3004 | |
| 3005 | // Setup expression as derefrencing a pointer cast to element address. |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 3006 | char expr_char_buffer[jit_max_expr_size]; |
| 3007 | int chars_written = snprintf(expr_char_buffer, jit_max_expr_size, "*(%s*) 0x%" PRIx64, |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3008 | alloc->element.type_name.AsCString(), *alloc->data_ptr.get() + offset); |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 3009 | |
Ewan Crawford | ea0636b | 2016-02-10 11:23:27 +0000 | [diff] [blame] | 3010 | if (chars_written < 0 || chars_written >= jit_max_expr_size) |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 3011 | { |
| 3012 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3013 | log->Printf("%s - error in snprintf().", __FUNCTION__); |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 3014 | continue; |
| 3015 | } |
| 3016 | |
| 3017 | // Evaluate expression |
| 3018 | ValueObjectSP expr_result; |
| 3019 | GetProcess()->GetTarget().EvaluateExpression(expr_char_buffer, frame_ptr, expr_result); |
| 3020 | |
| 3021 | // Print the results to our stream. |
| 3022 | expr_result->Dump(strm, expr_options); |
| 3023 | } |
| 3024 | else |
| 3025 | { |
| 3026 | alloc_data.Dump(&strm, offset, format, data_size - padding, 1, 1, LLDB_INVALID_ADDRESS, 0, 0); |
| 3027 | } |
| 3028 | offset += data_size; |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 3029 | } |
| 3030 | } |
| 3031 | } |
| 3032 | strm.EOL(); |
| 3033 | |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 3034 | return true; |
| 3035 | } |
| 3036 | |
Ewan Crawford | 0d2bfcf | 2016-02-04 09:44:23 +0000 | [diff] [blame] | 3037 | // Function recalculates all our cached information about allocations by jitting the |
| 3038 | // RS runtime regarding each allocation we know about. |
| 3039 | // Returns true if all allocations could be recomputed, false otherwise. |
| 3040 | bool |
| 3041 | RenderScriptRuntime::RecomputeAllAllocations(Stream &strm, StackFrame *frame_ptr) |
| 3042 | { |
| 3043 | bool success = true; |
| 3044 | for (auto &alloc : m_allocations) |
| 3045 | { |
| 3046 | // JIT current allocation information |
| 3047 | if (!RefreshAllocation(alloc.get(), frame_ptr)) |
| 3048 | { |
| 3049 | strm.Printf("Error: Couldn't evaluate details for allocation %" PRIu32 "\n", alloc->id); |
| 3050 | success = false; |
| 3051 | } |
| 3052 | } |
| 3053 | |
| 3054 | if (success) |
| 3055 | strm.Printf("All allocations successfully recomputed"); |
| 3056 | strm.EOL(); |
| 3057 | |
| 3058 | return success; |
| 3059 | } |
| 3060 | |
Ewan Crawford | b649b00 | 2016-01-26 10:41:08 +0000 | [diff] [blame] | 3061 | // Prints information regarding currently loaded allocations. |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 3062 | // These details are gathered by jitting the runtime, which has as latency. |
Ewan Crawford | b649b00 | 2016-01-26 10:41:08 +0000 | [diff] [blame] | 3063 | // Index parameter specifies a single allocation ID to print, or a zero value to print them all |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 3064 | void |
Ewan Crawford | b649b00 | 2016-01-26 10:41:08 +0000 | [diff] [blame] | 3065 | RenderScriptRuntime::ListAllocations(Stream &strm, StackFrame *frame_ptr, const uint32_t index) |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 3066 | { |
| 3067 | strm.Printf("RenderScript Allocations:"); |
| 3068 | strm.EOL(); |
| 3069 | strm.IndentMore(); |
| 3070 | |
| 3071 | for (auto &alloc : m_allocations) |
| 3072 | { |
Ewan Crawford | b649b00 | 2016-01-26 10:41:08 +0000 | [diff] [blame] | 3073 | // index will only be zero if we want to print all allocations |
| 3074 | if (index != 0 && index != alloc->id) |
| 3075 | continue; |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 3076 | |
| 3077 | // JIT current allocation information |
Ewan Crawford | b649b00 | 2016-01-26 10:41:08 +0000 | [diff] [blame] | 3078 | if (alloc->shouldRefresh() && !RefreshAllocation(alloc.get(), frame_ptr)) |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 3079 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3080 | strm.Printf("Error: Couldn't evaluate details for allocation %" PRIu32, alloc->id); |
| 3081 | strm.EOL(); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 3082 | continue; |
| 3083 | } |
| 3084 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3085 | strm.Printf("%" PRIu32 ":", alloc->id); |
| 3086 | strm.EOL(); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 3087 | strm.IndentMore(); |
| 3088 | |
| 3089 | strm.Indent("Context: "); |
| 3090 | if (!alloc->context.isValid()) |
| 3091 | strm.Printf("unknown\n"); |
| 3092 | else |
| 3093 | strm.Printf("0x%" PRIx64 "\n", *alloc->context.get()); |
| 3094 | |
| 3095 | strm.Indent("Address: "); |
| 3096 | if (!alloc->address.isValid()) |
| 3097 | strm.Printf("unknown\n"); |
| 3098 | else |
| 3099 | strm.Printf("0x%" PRIx64 "\n", *alloc->address.get()); |
| 3100 | |
| 3101 | strm.Indent("Data pointer: "); |
| 3102 | if (!alloc->data_ptr.isValid()) |
| 3103 | strm.Printf("unknown\n"); |
| 3104 | else |
| 3105 | strm.Printf("0x%" PRIx64 "\n", *alloc->data_ptr.get()); |
| 3106 | |
| 3107 | strm.Indent("Dimensions: "); |
| 3108 | if (!alloc->dimension.isValid()) |
| 3109 | strm.Printf("unknown\n"); |
| 3110 | else |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3111 | strm.Printf("(%" PRId32 ", %" PRId32 ", %" PRId32 ")\n", |
| 3112 | alloc->dimension.get()->dim_1, alloc->dimension.get()->dim_2, alloc->dimension.get()->dim_3); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 3113 | |
| 3114 | strm.Indent("Data Type: "); |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 3115 | if (!alloc->element.type.isValid() || !alloc->element.type_vec_size.isValid()) |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 3116 | strm.Printf("unknown\n"); |
| 3117 | else |
| 3118 | { |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 3119 | const int vector_size = *alloc->element.type_vec_size.get(); |
Ewan Crawford | 2e92071 | 2015-12-17 16:40:05 +0000 | [diff] [blame] | 3120 | Element::DataType type = *alloc->element.type.get(); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 3121 | |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 3122 | if (!alloc->element.type_name.IsEmpty()) |
| 3123 | strm.Printf("%s\n", alloc->element.type_name.AsCString()); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 3124 | else |
Ewan Crawford | 2e92071 | 2015-12-17 16:40:05 +0000 | [diff] [blame] | 3125 | { |
| 3126 | // Enum value isn't monotonous, so doesn't always index RsDataTypeToString array |
| 3127 | if (type >= Element::RS_TYPE_ELEMENT && type <= Element::RS_TYPE_FONT) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3128 | type = static_cast<Element::DataType>((type - Element::RS_TYPE_ELEMENT) + |
| 3129 | Element::RS_TYPE_MATRIX_2X2 + 1); |
Ewan Crawford | 2e92071 | 2015-12-17 16:40:05 +0000 | [diff] [blame] | 3130 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3131 | if (type >= (sizeof(AllocationDetails::RsDataTypeToString) / |
| 3132 | sizeof(AllocationDetails::RsDataTypeToString[0])) || |
| 3133 | vector_size > 4 || vector_size < 1) |
Ewan Crawford | 2e92071 | 2015-12-17 16:40:05 +0000 | [diff] [blame] | 3134 | strm.Printf("invalid type\n"); |
| 3135 | else |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3136 | strm.Printf("%s\n", AllocationDetails::RsDataTypeToString[static_cast<uint32_t>(type)] |
| 3137 | [vector_size - 1]); |
Ewan Crawford | 2e92071 | 2015-12-17 16:40:05 +0000 | [diff] [blame] | 3138 | } |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 3139 | } |
| 3140 | |
| 3141 | strm.Indent("Data Kind: "); |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 3142 | if (!alloc->element.type_kind.isValid()) |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 3143 | strm.Printf("unknown\n"); |
| 3144 | else |
| 3145 | { |
Ewan Crawford | 8b244e2 | 2015-11-30 10:29:49 +0000 | [diff] [blame] | 3146 | const Element::DataKind kind = *alloc->element.type_kind.get(); |
| 3147 | if (kind < Element::RS_KIND_USER || kind > Element::RS_KIND_PIXEL_YUV) |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 3148 | strm.Printf("invalid kind\n"); |
| 3149 | else |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3150 | strm.Printf("%s\n", AllocationDetails::RsDataKindToString[static_cast<uint32_t>(kind)]); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 3151 | } |
| 3152 | |
| 3153 | strm.EOL(); |
| 3154 | strm.IndentLess(); |
| 3155 | } |
| 3156 | strm.IndentLess(); |
| 3157 | } |
| 3158 | |
Ewan Crawford | 7dc7771 | 2015-09-10 10:08:48 +0000 | [diff] [blame] | 3159 | // Set breakpoints on every kernel found in RS module |
| 3160 | void |
| 3161 | RenderScriptRuntime::BreakOnModuleKernels(const RSModuleDescriptorSP rsmodule_sp) |
| 3162 | { |
| 3163 | for (const auto &kernel : rsmodule_sp->m_kernels) |
| 3164 | { |
| 3165 | // Don't set breakpoint on 'root' kernel |
| 3166 | if (strcmp(kernel.m_name.AsCString(), "root") == 0) |
| 3167 | continue; |
| 3168 | |
| 3169 | CreateKernelBreakpoint(kernel.m_name); |
| 3170 | } |
| 3171 | } |
| 3172 | |
| 3173 | // Method is internally called by the 'kernel breakpoint all' command to |
| 3174 | // enable or disable breaking on all kernels. |
| 3175 | // |
| 3176 | // When do_break is true we want to enable this functionality. |
| 3177 | // When do_break is false we want to disable it. |
| 3178 | void |
| 3179 | RenderScriptRuntime::SetBreakAllKernels(bool do_break, TargetSP target) |
| 3180 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3181 | Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_LANGUAGE | LIBLLDB_LOG_BREAKPOINTS)); |
Ewan Crawford | 7dc7771 | 2015-09-10 10:08:48 +0000 | [diff] [blame] | 3182 | |
| 3183 | InitSearchFilter(target); |
| 3184 | |
| 3185 | // Set breakpoints on all the kernels |
| 3186 | if (do_break && !m_breakAllKernels) |
| 3187 | { |
| 3188 | m_breakAllKernels = true; |
| 3189 | |
| 3190 | for (const auto &module : m_rsmodules) |
| 3191 | BreakOnModuleKernels(module); |
| 3192 | |
| 3193 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3194 | log->Printf("%s(True) - breakpoints set on all currently loaded kernels.", __FUNCTION__); |
Ewan Crawford | 7dc7771 | 2015-09-10 10:08:48 +0000 | [diff] [blame] | 3195 | } |
| 3196 | else if (!do_break && m_breakAllKernels) // Breakpoints won't be set on any new kernels. |
| 3197 | { |
| 3198 | m_breakAllKernels = false; |
| 3199 | |
| 3200 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3201 | log->Printf("%s(False) - breakpoints no longer automatically set.", __FUNCTION__); |
Ewan Crawford | 7dc7771 | 2015-09-10 10:08:48 +0000 | [diff] [blame] | 3202 | } |
| 3203 | } |
| 3204 | |
| 3205 | // Given the name of a kernel this function creates a breakpoint using our |
| 3206 | // own breakpoint resolver, and returns the Breakpoint shared pointer. |
| 3207 | BreakpointSP |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3208 | RenderScriptRuntime::CreateKernelBreakpoint(const ConstString &name) |
Ewan Crawford | 7dc7771 | 2015-09-10 10:08:48 +0000 | [diff] [blame] | 3209 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3210 | Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_LANGUAGE | LIBLLDB_LOG_BREAKPOINTS)); |
Ewan Crawford | 7dc7771 | 2015-09-10 10:08:48 +0000 | [diff] [blame] | 3211 | |
| 3212 | if (!m_filtersp) |
| 3213 | { |
| 3214 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3215 | log->Printf("%s - error, no breakpoint search filter set.", __FUNCTION__); |
Ewan Crawford | 7dc7771 | 2015-09-10 10:08:48 +0000 | [diff] [blame] | 3216 | return nullptr; |
| 3217 | } |
| 3218 | |
| 3219 | BreakpointResolverSP resolver_sp(new RSBreakpointResolver(nullptr, name)); |
| 3220 | BreakpointSP bp = GetProcess()->GetTarget().CreateBreakpoint(m_filtersp, resolver_sp, false, false, false); |
| 3221 | |
Ewan Crawford | 54782db | 2015-09-16 10:02:57 +0000 | [diff] [blame] | 3222 | // Give RS breakpoints a specific name, so the user can manipulate them as a group. |
| 3223 | Error err; |
| 3224 | if (!bp->AddName("RenderScriptKernel", err) && log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3225 | log->Printf("%s - error setting break name, '%s'.", __FUNCTION__, err.AsCString()); |
Ewan Crawford | 54782db | 2015-09-16 10:02:57 +0000 | [diff] [blame] | 3226 | |
Ewan Crawford | 7dc7771 | 2015-09-10 10:08:48 +0000 | [diff] [blame] | 3227 | return bp; |
| 3228 | } |
| 3229 | |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3230 | // Given an expression for a variable this function tries to calculate the variable's value. |
| 3231 | // If this is possible it returns true and sets the uint64_t parameter to the variables unsigned value. |
| 3232 | // Otherwise function returns false. |
| 3233 | bool |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3234 | RenderScriptRuntime::GetFrameVarAsUnsigned(const StackFrameSP frame_sp, const char *var_name, uint64_t &val) |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3235 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3236 | Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_LANGUAGE)); |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3237 | Error error; |
| 3238 | VariableSP var_sp; |
| 3239 | |
| 3240 | // Find variable in stack frame |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3241 | ValueObjectSP value_sp(frame_sp->GetValueForVariableExpressionPath( |
| 3242 | var_name, eNoDynamicValues, |
| 3243 | StackFrame::eExpressionPathOptionCheckPtrVsMember | StackFrame::eExpressionPathOptionsAllowDirectIVarAccess, |
| 3244 | var_sp, error)); |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3245 | if (!error.Success()) |
| 3246 | { |
| 3247 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3248 | log->Printf("%s - error, couldn't find '%s' in frame", __FUNCTION__, var_name); |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3249 | return false; |
| 3250 | } |
| 3251 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3252 | // Find the uint32_t value for the variable |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3253 | bool success = false; |
| 3254 | val = value_sp->GetValueAsUnsigned(0, &success); |
| 3255 | if (!success) |
| 3256 | { |
| 3257 | if (log) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3258 | log->Printf("%s - error, couldn't parse '%s' as an uint32_t.", __FUNCTION__, var_name); |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3259 | return false; |
| 3260 | } |
| 3261 | |
| 3262 | return true; |
| 3263 | } |
| 3264 | |
Ewan Crawford | 4f8817c | 2016-01-20 12:03:29 +0000 | [diff] [blame] | 3265 | // Function attempts to find the current coordinate of a kernel invocation by investigating the |
| 3266 | // values of frame variables in the .expand function. These coordinates are returned via the coord |
| 3267 | // array reference parameter. Returns true if the coordinates could be found, and false otherwise. |
| 3268 | bool |
| 3269 | RenderScriptRuntime::GetKernelCoordinate(RSCoordinate &coord, Thread *thread_ptr) |
| 3270 | { |
Greg Clayton | 1e05c3b | 2016-03-24 21:48:10 +0000 | [diff] [blame] | 3271 | static const std::string s_runtimeExpandSuffix(".expand"); |
| 3272 | static const std::array<const char *, 3> s_runtimeCoordVars{{"rsIndex", "p->current.y", "p->current.z"}}; |
| 3273 | |
Ewan Crawford | 4f8817c | 2016-01-20 12:03:29 +0000 | [diff] [blame] | 3274 | Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_LANGUAGE)); |
| 3275 | |
| 3276 | if (!thread_ptr) |
| 3277 | { |
| 3278 | if (log) |
| 3279 | log->Printf("%s - Error, No thread pointer", __FUNCTION__); |
| 3280 | |
| 3281 | return false; |
| 3282 | } |
| 3283 | |
| 3284 | // Walk the call stack looking for a function whose name has the suffix '.expand' |
| 3285 | // and contains the variables we're looking for. |
| 3286 | for (uint32_t i = 0; i < thread_ptr->GetStackFrameCount(); ++i) |
| 3287 | { |
| 3288 | if (!thread_ptr->SetSelectedFrameByIndex(i)) |
| 3289 | continue; |
| 3290 | |
| 3291 | StackFrameSP frame_sp = thread_ptr->GetSelectedFrame(); |
| 3292 | if (!frame_sp) |
| 3293 | continue; |
| 3294 | |
| 3295 | // Find the function name |
| 3296 | const SymbolContext sym_ctx = frame_sp->GetSymbolContext(false); |
| 3297 | const char *func_name_cstr = sym_ctx.GetFunctionName().AsCString(); |
| 3298 | if (!func_name_cstr) |
| 3299 | continue; |
| 3300 | |
| 3301 | if (log) |
| 3302 | log->Printf("%s - Inspecting function '%s'", __FUNCTION__, func_name_cstr); |
| 3303 | |
| 3304 | // Check if function name has .expand suffix |
| 3305 | std::string func_name(func_name_cstr); |
Greg Clayton | 1e05c3b | 2016-03-24 21:48:10 +0000 | [diff] [blame] | 3306 | const int length_difference = func_name.length() - s_runtimeExpandSuffix.length(); |
Ewan Crawford | 4f8817c | 2016-01-20 12:03:29 +0000 | [diff] [blame] | 3307 | if (length_difference <= 0) |
| 3308 | continue; |
| 3309 | |
| 3310 | const int32_t has_expand_suffix = func_name.compare(length_difference, |
Greg Clayton | 1e05c3b | 2016-03-24 21:48:10 +0000 | [diff] [blame] | 3311 | s_runtimeExpandSuffix.length(), |
| 3312 | s_runtimeExpandSuffix); |
Ewan Crawford | 4f8817c | 2016-01-20 12:03:29 +0000 | [diff] [blame] | 3313 | |
| 3314 | if (has_expand_suffix != 0) |
| 3315 | continue; |
| 3316 | |
| 3317 | if (log) |
| 3318 | log->Printf("%s - Found .expand function '%s'", __FUNCTION__, func_name_cstr); |
| 3319 | |
| 3320 | // Get values for variables in .expand frame that tell us the current kernel invocation |
| 3321 | bool found_coord_variables = true; |
Greg Clayton | 1e05c3b | 2016-03-24 21:48:10 +0000 | [diff] [blame] | 3322 | assert(s_runtimeCoordVars.size() == coord.size()); |
Ewan Crawford | 4f8817c | 2016-01-20 12:03:29 +0000 | [diff] [blame] | 3323 | |
| 3324 | for (uint32_t i = 0; i < coord.size(); ++i) |
| 3325 | { |
| 3326 | uint64_t value = 0; |
Greg Clayton | 1e05c3b | 2016-03-24 21:48:10 +0000 | [diff] [blame] | 3327 | if (!GetFrameVarAsUnsigned(frame_sp, s_runtimeCoordVars[i], value)) |
Ewan Crawford | 4f8817c | 2016-01-20 12:03:29 +0000 | [diff] [blame] | 3328 | { |
| 3329 | found_coord_variables = false; |
| 3330 | break; |
| 3331 | } |
| 3332 | coord[i] = value; |
| 3333 | } |
| 3334 | |
| 3335 | if (found_coord_variables) |
| 3336 | return true; |
| 3337 | } |
| 3338 | return false; |
| 3339 | } |
| 3340 | |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3341 | // Callback when a kernel breakpoint hits and we're looking for a specific coordinate. |
| 3342 | // Baton parameter contains a pointer to the target coordinate we want to break on. |
| 3343 | // Function then checks the .expand frame for the current coordinate and breaks to user if it matches. |
| 3344 | // Parameter 'break_id' is the id of the Breakpoint which made the callback. |
| 3345 | // Parameter 'break_loc_id' is the id for the BreakpointLocation which was hit, |
| 3346 | // a single logical breakpoint can have multiple addresses. |
| 3347 | bool |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3348 | RenderScriptRuntime::KernelBreakpointHit(void *baton, StoppointCallbackContext *ctx, user_id_t break_id, |
| 3349 | user_id_t break_loc_id) |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3350 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3351 | Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_LANGUAGE | LIBLLDB_LOG_BREAKPOINTS)); |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3352 | |
| 3353 | assert(baton && "Error: null baton in conditional kernel breakpoint callback"); |
| 3354 | |
| 3355 | // Coordinate we want to stop on |
Ewan Crawford | 4f8817c | 2016-01-20 12:03:29 +0000 | [diff] [blame] | 3356 | const uint32_t *target_coord = static_cast<const uint32_t *>(baton); |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3357 | |
| 3358 | if (log) |
Ewan Crawford | 4f8817c | 2016-01-20 12:03:29 +0000 | [diff] [blame] | 3359 | log->Printf("%s - Break ID %" PRIu64 ", (%" PRIu32 ", %" PRIu32 ", %" PRIu32 ")", __FUNCTION__, break_id, |
| 3360 | target_coord[0], target_coord[1], target_coord[2]); |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3361 | |
Ewan Crawford | 4f8817c | 2016-01-20 12:03:29 +0000 | [diff] [blame] | 3362 | // Select current thread |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3363 | ExecutionContext context(ctx->exe_ctx_ref); |
Ewan Crawford | 4f8817c | 2016-01-20 12:03:29 +0000 | [diff] [blame] | 3364 | Thread *thread_ptr = context.GetThreadPtr(); |
| 3365 | assert(thread_ptr && "Null thread pointer"); |
| 3366 | |
| 3367 | // Find current kernel invocation from .expand frame variables |
| 3368 | RSCoordinate current_coord{}; // Zero initialise array |
| 3369 | if (!GetKernelCoordinate(current_coord, thread_ptr)) |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3370 | { |
| 3371 | if (log) |
Ewan Crawford | 4f8817c | 2016-01-20 12:03:29 +0000 | [diff] [blame] | 3372 | log->Printf("%s - Error, couldn't select .expand stack frame", __FUNCTION__); |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3373 | return false; |
| 3374 | } |
| 3375 | |
Ewan Crawford | 4f8817c | 2016-01-20 12:03:29 +0000 | [diff] [blame] | 3376 | if (log) |
| 3377 | log->Printf("%s - (%" PRIu32 ",%" PRIu32 ",%" PRIu32 ")", __FUNCTION__, current_coord[0], current_coord[1], |
| 3378 | current_coord[2]); |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3379 | |
| 3380 | // Check if the current kernel invocation coordinate matches our target coordinate |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3381 | if (current_coord[0] == target_coord[0] && |
| 3382 | current_coord[1] == target_coord[1] && |
Ewan Crawford | 4f8817c | 2016-01-20 12:03:29 +0000 | [diff] [blame] | 3383 | current_coord[2] == target_coord[2]) |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3384 | { |
| 3385 | if (log) |
Ewan Crawford | 4f8817c | 2016-01-20 12:03:29 +0000 | [diff] [blame] | 3386 | log->Printf("%s, BREAKING (%" PRIu32 ",%" PRIu32 ",%" PRIu32 ")", __FUNCTION__, current_coord[0], |
| 3387 | current_coord[1], current_coord[2]); |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3388 | |
| 3389 | BreakpointSP breakpoint_sp = context.GetTargetPtr()->GetBreakpointByID(break_id); |
| 3390 | assert(breakpoint_sp != nullptr && "Error: Couldn't find breakpoint matching break id for callback"); |
| 3391 | breakpoint_sp->SetEnabled(false); // Optimise since conditional breakpoint should only be hit once. |
| 3392 | return true; |
| 3393 | } |
| 3394 | |
| 3395 | // No match on coordinate |
| 3396 | return false; |
| 3397 | } |
| 3398 | |
| 3399 | // Tries to set a breakpoint on the start of a kernel, resolved using the kernel name. |
| 3400 | // Argument 'coords', represents a three dimensional coordinate which can be used to specify |
| 3401 | // a single kernel instance to break on. If this is set then we add a callback to the breakpoint. |
Ewan Crawford | 9815658 | 2015-09-04 08:56:52 +0000 | [diff] [blame] | 3402 | void |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3403 | RenderScriptRuntime::PlaceBreakpointOnKernel(Stream &strm, const char *name, const std::array<int, 3> coords, |
| 3404 | Error &error, TargetSP target) |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3405 | { |
Ewan Crawford | 9815658 | 2015-09-04 08:56:52 +0000 | [diff] [blame] | 3406 | if (!name) |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3407 | { |
| 3408 | error.SetErrorString("invalid kernel name"); |
| 3409 | return; |
| 3410 | } |
| 3411 | |
Ewan Crawford | 7dc7771 | 2015-09-10 10:08:48 +0000 | [diff] [blame] | 3412 | InitSearchFilter(target); |
Ewan Crawford | 9815658 | 2015-09-04 08:56:52 +0000 | [diff] [blame] | 3413 | |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3414 | ConstString kernel_name(name); |
Ewan Crawford | 7dc7771 | 2015-09-10 10:08:48 +0000 | [diff] [blame] | 3415 | BreakpointSP bp = CreateKernelBreakpoint(kernel_name); |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3416 | |
| 3417 | // We have a conditional breakpoint on a specific coordinate |
| 3418 | if (coords[0] != -1) |
| 3419 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3420 | strm.Printf("Conditional kernel breakpoint on coordinate %" PRId32 ", %" PRId32 ", %" PRId32, |
| 3421 | coords[0], coords[1], coords[2]); |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3422 | strm.EOL(); |
| 3423 | |
| 3424 | // Allocate memory for the baton, and copy over coordinate |
Ewan Crawford | 4f8817c | 2016-01-20 12:03:29 +0000 | [diff] [blame] | 3425 | uint32_t *baton = new uint32_t[coords.size()]; |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3426 | baton[0] = coords[0]; baton[1] = coords[1]; baton[2] = coords[2]; |
| 3427 | |
Ed Maste | 75500e7 | 2016-07-19 15:28:02 +0000 | [diff] [blame] | 3428 | // Create a callback that will be invoked every time the breakpoint is hit. |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3429 | // The baton object passed to the handler is the target coordinate we want to break on. |
| 3430 | bp->SetCallback(KernelBreakpointHit, baton, true); |
| 3431 | |
| 3432 | // Store a shared pointer to the baton, so the memory will eventually be cleaned up after destruction |
Ewan Crawford | 4f8817c | 2016-01-20 12:03:29 +0000 | [diff] [blame] | 3433 | m_conditional_breaks[bp->GetID()] = std::shared_ptr<uint32_t>(baton); |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3434 | } |
| 3435 | |
Ewan Crawford | 9815658 | 2015-09-04 08:56:52 +0000 | [diff] [blame] | 3436 | if (bp) |
| 3437 | bp->GetDescription(&strm, lldb::eDescriptionLevelInitial, false); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3438 | } |
| 3439 | |
| 3440 | void |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 3441 | RenderScriptRuntime::DumpModules(Stream &strm) const |
| 3442 | { |
| 3443 | strm.Printf("RenderScript Modules:"); |
| 3444 | strm.EOL(); |
| 3445 | strm.IndentMore(); |
| 3446 | for (const auto &module : m_rsmodules) |
| 3447 | { |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3448 | module->Dump(strm); |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 3449 | } |
| 3450 | strm.IndentLess(); |
| 3451 | } |
| 3452 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3453 | RenderScriptRuntime::ScriptDetails * |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 3454 | RenderScriptRuntime::LookUpScript(addr_t address, bool create) |
| 3455 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3456 | for (const auto &s : m_scripts) |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 3457 | { |
| 3458 | if (s->script.isValid()) |
| 3459 | if (*s->script == address) |
| 3460 | return s.get(); |
| 3461 | } |
| 3462 | if (create) |
| 3463 | { |
| 3464 | std::unique_ptr<ScriptDetails> s(new ScriptDetails); |
| 3465 | s->script = address; |
| 3466 | m_scripts.push_back(std::move(s)); |
Ewan Crawford | d10ca9d | 2015-09-22 13:36:35 +0000 | [diff] [blame] | 3467 | return m_scripts.back().get(); |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 3468 | } |
| 3469 | return nullptr; |
| 3470 | } |
| 3471 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3472 | RenderScriptRuntime::AllocationDetails * |
Luke Drummond | 5d05763 | 2016-08-03 17:31:58 +0000 | [diff] [blame] | 3473 | RenderScriptRuntime::LookUpAllocation(addr_t address) |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 3474 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3475 | for (const auto &a : m_allocations) |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 3476 | { |
| 3477 | if (a->address.isValid()) |
| 3478 | if (*a->address == address) |
| 3479 | return a.get(); |
| 3480 | } |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 3481 | return nullptr; |
| 3482 | } |
| 3483 | |
Luke Drummond | 5d05763 | 2016-08-03 17:31:58 +0000 | [diff] [blame] | 3484 | RenderScriptRuntime::AllocationDetails * |
| 3485 | RenderScriptRuntime::CreateAllocation(addr_t address) |
| 3486 | { |
| 3487 | Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE); |
| 3488 | |
| 3489 | // Remove any previous allocation which contains the same address |
| 3490 | auto it = m_allocations.begin(); |
| 3491 | while (it != m_allocations.end()) |
| 3492 | { |
| 3493 | if (*((*it)->address) == address) |
| 3494 | { |
| 3495 | if (log) |
| 3496 | log->Printf("%s - Removing allocation id: %d, address: 0x%" PRIx64, __FUNCTION__, (*it)->id, address); |
| 3497 | |
| 3498 | it = m_allocations.erase(it); |
| 3499 | } |
| 3500 | else |
| 3501 | { |
| 3502 | it++; |
| 3503 | } |
| 3504 | } |
| 3505 | |
| 3506 | std::unique_ptr<AllocationDetails> a(new AllocationDetails); |
| 3507 | a->address = address; |
| 3508 | m_allocations.push_back(std::move(a)); |
| 3509 | return m_allocations.back().get(); |
| 3510 | } |
| 3511 | |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 3512 | void |
| 3513 | RSModuleDescriptor::Dump(Stream &strm) const |
| 3514 | { |
| 3515 | strm.Indent(); |
| 3516 | m_module->GetFileSpec().Dump(&strm); |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3517 | if (m_module->GetNumCompileUnits()) |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3518 | { |
| 3519 | strm.Indent("Debug info loaded."); |
| 3520 | } |
| 3521 | else |
| 3522 | { |
| 3523 | strm.Indent("Debug info does not exist."); |
| 3524 | } |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 3525 | strm.EOL(); |
| 3526 | strm.IndentMore(); |
| 3527 | strm.Indent(); |
Colin Riley | 189598e | 2015-04-12 22:05:58 +0000 | [diff] [blame] | 3528 | strm.Printf("Globals: %" PRIu64, static_cast<uint64_t>(m_globals.size())); |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 3529 | strm.EOL(); |
| 3530 | strm.IndentMore(); |
| 3531 | for (const auto &global : m_globals) |
| 3532 | { |
| 3533 | global.Dump(strm); |
| 3534 | } |
| 3535 | strm.IndentLess(); |
| 3536 | strm.Indent(); |
Colin Riley | 189598e | 2015-04-12 22:05:58 +0000 | [diff] [blame] | 3537 | strm.Printf("Kernels: %" PRIu64, static_cast<uint64_t>(m_kernels.size())); |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 3538 | strm.EOL(); |
| 3539 | strm.IndentMore(); |
| 3540 | for (const auto &kernel : m_kernels) |
| 3541 | { |
| 3542 | kernel.Dump(strm); |
| 3543 | } |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3544 | strm.Printf("Pragmas: %" PRIu64, static_cast<uint64_t>(m_pragmas.size())); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3545 | strm.EOL(); |
| 3546 | strm.IndentMore(); |
| 3547 | for (const auto &key_val : m_pragmas) |
| 3548 | { |
| 3549 | strm.Printf("%s: %s", key_val.first.c_str(), key_val.second.c_str()); |
| 3550 | strm.EOL(); |
| 3551 | } |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 3552 | strm.IndentLess(4); |
| 3553 | } |
| 3554 | |
| 3555 | void |
| 3556 | RSGlobalDescriptor::Dump(Stream &strm) const |
| 3557 | { |
| 3558 | strm.Indent(m_name.AsCString()); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3559 | VariableList var_list; |
| 3560 | m_module->m_module->FindGlobalVariables(m_name, nullptr, true, 1U, var_list); |
| 3561 | if (var_list.GetSize() == 1) |
| 3562 | { |
| 3563 | auto var = var_list.GetVariableAtIndex(0); |
| 3564 | auto type = var->GetType(); |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3565 | if (type) |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3566 | { |
| 3567 | strm.Printf(" - "); |
| 3568 | type->DumpTypeName(&strm); |
| 3569 | } |
| 3570 | else |
| 3571 | { |
| 3572 | strm.Printf(" - Unknown Type"); |
| 3573 | } |
| 3574 | } |
| 3575 | else |
| 3576 | { |
| 3577 | strm.Printf(" - variable identified, but not found in binary"); |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3578 | const Symbol *s = m_module->m_module->FindFirstSymbolWithNameAndType(m_name, eSymbolTypeData); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3579 | if (s) |
| 3580 | { |
| 3581 | strm.Printf(" (symbol exists) "); |
| 3582 | } |
| 3583 | } |
| 3584 | |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 3585 | strm.EOL(); |
| 3586 | } |
| 3587 | |
| 3588 | void |
| 3589 | RSKernelDescriptor::Dump(Stream &strm) const |
| 3590 | { |
| 3591 | strm.Indent(m_name.AsCString()); |
| 3592 | strm.EOL(); |
| 3593 | } |
| 3594 | |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 3595 | class CommandObjectRenderScriptRuntimeModuleDump : public CommandObjectParsed |
| 3596 | { |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3597 | public: |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 3598 | CommandObjectRenderScriptRuntimeModuleDump(CommandInterpreter &interpreter) |
| 3599 | : CommandObjectParsed(interpreter, "renderscript module dump", |
| 3600 | "Dumps renderscript specific information for all modules.", "renderscript module dump", |
Enrico Granata | e87764f | 2015-05-27 05:04:35 +0000 | [diff] [blame] | 3601 | eCommandRequiresProcess | eCommandProcessMustBeLaunched) |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 3602 | { |
| 3603 | } |
| 3604 | |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3605 | ~CommandObjectRenderScriptRuntimeModuleDump() override = default; |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 3606 | |
| 3607 | bool |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3608 | DoExecute(Args &command, CommandReturnObject &result) override |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 3609 | { |
| 3610 | RenderScriptRuntime *runtime = |
| 3611 | (RenderScriptRuntime *)m_exe_ctx.GetProcessPtr()->GetLanguageRuntime(eLanguageTypeExtRenderScript); |
| 3612 | runtime->DumpModules(result.GetOutputStream()); |
| 3613 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 3614 | return true; |
| 3615 | } |
| 3616 | }; |
| 3617 | |
| 3618 | class CommandObjectRenderScriptRuntimeModule : public CommandObjectMultiword |
| 3619 | { |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3620 | public: |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 3621 | CommandObjectRenderScriptRuntimeModule(CommandInterpreter &interpreter) |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 3622 | : CommandObjectMultiword(interpreter, "renderscript module", "Commands that deal with RenderScript modules.", |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3623 | nullptr) |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 3624 | { |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 3625 | LoadSubCommand("dump", CommandObjectSP(new CommandObjectRenderScriptRuntimeModuleDump(interpreter))); |
| 3626 | } |
| 3627 | |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3628 | ~CommandObjectRenderScriptRuntimeModule() override = default; |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 3629 | }; |
| 3630 | |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3631 | class CommandObjectRenderScriptRuntimeKernelList : public CommandObjectParsed |
| 3632 | { |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3633 | public: |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3634 | CommandObjectRenderScriptRuntimeKernelList(CommandInterpreter &interpreter) |
| 3635 | : CommandObjectParsed(interpreter, "renderscript kernel list", |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3636 | "Lists renderscript kernel names and associated script resources.", |
| 3637 | "renderscript kernel list", eCommandRequiresProcess | eCommandProcessMustBeLaunched) |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3638 | { |
| 3639 | } |
| 3640 | |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3641 | ~CommandObjectRenderScriptRuntimeKernelList() override = default; |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3642 | |
| 3643 | bool |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3644 | DoExecute(Args &command, CommandReturnObject &result) override |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3645 | { |
| 3646 | RenderScriptRuntime *runtime = |
| 3647 | (RenderScriptRuntime *)m_exe_ctx.GetProcessPtr()->GetLanguageRuntime(eLanguageTypeExtRenderScript); |
| 3648 | runtime->DumpKernels(result.GetOutputStream()); |
| 3649 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 3650 | return true; |
| 3651 | } |
| 3652 | }; |
| 3653 | |
Ewan Crawford | 7dc7771 | 2015-09-10 10:08:48 +0000 | [diff] [blame] | 3654 | class CommandObjectRenderScriptRuntimeKernelBreakpointSet : public CommandObjectParsed |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3655 | { |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3656 | public: |
Ewan Crawford | 7dc7771 | 2015-09-10 10:08:48 +0000 | [diff] [blame] | 3657 | CommandObjectRenderScriptRuntimeKernelBreakpointSet(CommandInterpreter &interpreter) |
| 3658 | : CommandObjectParsed(interpreter, "renderscript kernel breakpoint set", |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3659 | "Sets a breakpoint on a renderscript kernel.", |
| 3660 | "renderscript kernel breakpoint set <kernel_name> [-c x,y,z]", |
| 3661 | eCommandRequiresProcess | eCommandProcessMustBeLaunched | eCommandProcessMustBePaused), |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame^] | 3662 | m_options() |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3663 | { |
| 3664 | } |
| 3665 | |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3666 | ~CommandObjectRenderScriptRuntimeKernelBreakpointSet() override = default; |
| 3667 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3668 | Options * |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3669 | GetOptions() override |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3670 | { |
| 3671 | return &m_options; |
| 3672 | } |
| 3673 | |
| 3674 | class CommandOptions : public Options |
| 3675 | { |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3676 | public: |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame^] | 3677 | CommandOptions() : Options() {} |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3678 | |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3679 | ~CommandOptions() override = default; |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3680 | |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3681 | Error |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame^] | 3682 | SetOptionValue(uint32_t option_idx, const char *option_arg, |
| 3683 | ExecutionContext *execution_context) override |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3684 | { |
| 3685 | Error error; |
| 3686 | const int short_option = m_getopt_table[option_idx].val; |
| 3687 | |
| 3688 | switch (short_option) |
| 3689 | { |
| 3690 | case 'c': |
| 3691 | if (!ParseCoordinate(option_arg)) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3692 | error.SetErrorStringWithFormat("Couldn't parse coordinate '%s', should be in format 'x,y,z'.", |
| 3693 | option_arg); |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3694 | break; |
| 3695 | default: |
| 3696 | error.SetErrorStringWithFormat("unrecognized option '%c'", short_option); |
| 3697 | break; |
| 3698 | } |
| 3699 | return error; |
| 3700 | } |
| 3701 | |
| 3702 | // -c takes an argument of the form 'num[,num][,num]'. |
| 3703 | // Where 'id_cstr' is this argument with the whitespace trimmed. |
| 3704 | // Missing coordinates are defaulted to zero. |
| 3705 | bool |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3706 | ParseCoordinate(const char *id_cstr) |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3707 | { |
| 3708 | RegularExpression regex; |
| 3709 | RegularExpression::Match regex_match(3); |
| 3710 | |
| 3711 | bool matched = false; |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3712 | if (regex.Compile("^([0-9]+),([0-9]+),([0-9]+)$") && regex.Execute(id_cstr, ®ex_match)) |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3713 | matched = true; |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3714 | else if (regex.Compile("^([0-9]+),([0-9]+)$") && regex.Execute(id_cstr, ®ex_match)) |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3715 | matched = true; |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3716 | else if (regex.Compile("^([0-9]+)$") && regex.Execute(id_cstr, ®ex_match)) |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3717 | matched = true; |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3718 | for (uint32_t i = 0; i < 3; i++) |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3719 | { |
| 3720 | std::string group; |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3721 | if (regex_match.GetMatchAtIndex(id_cstr, i + 1, group)) |
| 3722 | m_coord[i] = (uint32_t)strtoul(group.c_str(), nullptr, 0); |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3723 | else |
| 3724 | m_coord[i] = 0; |
| 3725 | } |
| 3726 | return matched; |
| 3727 | } |
| 3728 | |
| 3729 | void |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame^] | 3730 | OptionParsingStarting(ExecutionContext *execution_context) override |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3731 | { |
| 3732 | // -1 means the -c option hasn't been set |
| 3733 | m_coord[0] = -1; |
| 3734 | m_coord[1] = -1; |
| 3735 | m_coord[2] = -1; |
| 3736 | } |
| 3737 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3738 | const OptionDefinition * |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3739 | GetDefinitions() override |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3740 | { |
| 3741 | return g_option_table; |
| 3742 | } |
| 3743 | |
| 3744 | static OptionDefinition g_option_table[]; |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3745 | std::array<int, 3> m_coord; |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3746 | }; |
| 3747 | |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3748 | bool |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3749 | DoExecute(Args &command, CommandReturnObject &result) override |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3750 | { |
| 3751 | const size_t argc = command.GetArgumentCount(); |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3752 | if (argc < 1) |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3753 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3754 | result.AppendErrorWithFormat("'%s' takes 1 argument of kernel name, and an optional coordinate.", |
| 3755 | m_cmd_name.c_str()); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3756 | result.SetStatus(eReturnStatusFailed); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3757 | return false; |
| 3758 | } |
| 3759 | |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3760 | RenderScriptRuntime *runtime = |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3761 | (RenderScriptRuntime *)m_exe_ctx.GetProcessPtr()->GetLanguageRuntime(eLanguageTypeExtRenderScript); |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3762 | |
| 3763 | Error error; |
| 3764 | runtime->PlaceBreakpointOnKernel(result.GetOutputStream(), command.GetArgumentAtIndex(0), m_options.m_coord, |
| 3765 | error, m_exe_ctx.GetTargetSP()); |
| 3766 | |
| 3767 | if (error.Success()) |
| 3768 | { |
| 3769 | result.AppendMessage("Breakpoint(s) created"); |
| 3770 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 3771 | return true; |
| 3772 | } |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3773 | result.SetStatus(eReturnStatusFailed); |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3774 | result.AppendErrorWithFormat("Error: %s", error.AsCString()); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3775 | return false; |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3776 | } |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3777 | |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3778 | private: |
| 3779 | CommandOptions m_options; |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3780 | }; |
| 3781 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3782 | OptionDefinition CommandObjectRenderScriptRuntimeKernelBreakpointSet::CommandOptions::g_option_table[] = { |
| 3783 | {LLDB_OPT_SET_1, false, "coordinate", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeValue, |
| 3784 | "Set a breakpoint on a single invocation of the kernel with specified coordinate.\n" |
| 3785 | "Coordinate takes the form 'x[,y][,z] where x,y,z are positive integers representing kernel dimensions. " |
| 3786 | "Any unset dimensions will be defaulted to zero."}, |
| 3787 | {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}}; |
Ewan Crawford | 018f5a7e | 2015-10-26 14:04:37 +0000 | [diff] [blame] | 3788 | |
Ewan Crawford | 7dc7771 | 2015-09-10 10:08:48 +0000 | [diff] [blame] | 3789 | class CommandObjectRenderScriptRuntimeKernelBreakpointAll : public CommandObjectParsed |
| 3790 | { |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3791 | public: |
Ewan Crawford | 7dc7771 | 2015-09-10 10:08:48 +0000 | [diff] [blame] | 3792 | CommandObjectRenderScriptRuntimeKernelBreakpointAll(CommandInterpreter &interpreter) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3793 | : CommandObjectParsed( |
| 3794 | interpreter, "renderscript kernel breakpoint all", |
| 3795 | "Automatically sets a breakpoint on all renderscript kernels that are or will be loaded.\n" |
| 3796 | "Disabling option means breakpoints will no longer be set on any kernels loaded in the future, " |
| 3797 | "but does not remove currently set breakpoints.", |
| 3798 | "renderscript kernel breakpoint all <enable/disable>", |
| 3799 | eCommandRequiresProcess | eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) |
Ewan Crawford | 7dc7771 | 2015-09-10 10:08:48 +0000 | [diff] [blame] | 3800 | { |
| 3801 | } |
| 3802 | |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3803 | ~CommandObjectRenderScriptRuntimeKernelBreakpointAll() override = default; |
Ewan Crawford | 7dc7771 | 2015-09-10 10:08:48 +0000 | [diff] [blame] | 3804 | |
| 3805 | bool |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3806 | DoExecute(Args &command, CommandReturnObject &result) override |
Ewan Crawford | 7dc7771 | 2015-09-10 10:08:48 +0000 | [diff] [blame] | 3807 | { |
| 3808 | const size_t argc = command.GetArgumentCount(); |
| 3809 | if (argc != 1) |
| 3810 | { |
| 3811 | result.AppendErrorWithFormat("'%s' takes 1 argument of 'enable' or 'disable'", m_cmd_name.c_str()); |
| 3812 | result.SetStatus(eReturnStatusFailed); |
| 3813 | return false; |
| 3814 | } |
| 3815 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3816 | RenderScriptRuntime *runtime = static_cast<RenderScriptRuntime *>( |
| 3817 | m_exe_ctx.GetProcessPtr()->GetLanguageRuntime(eLanguageTypeExtRenderScript)); |
Ewan Crawford | 7dc7771 | 2015-09-10 10:08:48 +0000 | [diff] [blame] | 3818 | |
| 3819 | bool do_break = false; |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3820 | const char *argument = command.GetArgumentAtIndex(0); |
Ewan Crawford | 7dc7771 | 2015-09-10 10:08:48 +0000 | [diff] [blame] | 3821 | if (strcmp(argument, "enable") == 0) |
| 3822 | { |
| 3823 | do_break = true; |
| 3824 | result.AppendMessage("Breakpoints will be set on all kernels."); |
| 3825 | } |
| 3826 | else if (strcmp(argument, "disable") == 0) |
| 3827 | { |
| 3828 | do_break = false; |
| 3829 | result.AppendMessage("Breakpoints will not be set on any new kernels."); |
| 3830 | } |
| 3831 | else |
| 3832 | { |
| 3833 | result.AppendErrorWithFormat("Argument must be either 'enable' or 'disable'"); |
| 3834 | result.SetStatus(eReturnStatusFailed); |
| 3835 | return false; |
| 3836 | } |
| 3837 | |
| 3838 | runtime->SetBreakAllKernels(do_break, m_exe_ctx.GetTargetSP()); |
| 3839 | |
| 3840 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 3841 | return true; |
| 3842 | } |
| 3843 | }; |
| 3844 | |
Ewan Crawford | 4f8817c | 2016-01-20 12:03:29 +0000 | [diff] [blame] | 3845 | class CommandObjectRenderScriptRuntimeKernelCoordinate : public CommandObjectParsed |
| 3846 | { |
| 3847 | public: |
| 3848 | CommandObjectRenderScriptRuntimeKernelCoordinate(CommandInterpreter &interpreter) |
| 3849 | : CommandObjectParsed(interpreter, "renderscript kernel coordinate", |
| 3850 | "Shows the (x,y,z) coordinate of the current kernel invocation.", |
| 3851 | "renderscript kernel coordinate", |
| 3852 | eCommandRequiresProcess | eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) |
| 3853 | { |
| 3854 | } |
| 3855 | |
| 3856 | ~CommandObjectRenderScriptRuntimeKernelCoordinate() override = default; |
| 3857 | |
| 3858 | bool |
| 3859 | DoExecute(Args &command, CommandReturnObject &result) override |
| 3860 | { |
| 3861 | RSCoordinate coord{}; // Zero initialize array |
| 3862 | bool success = RenderScriptRuntime::GetKernelCoordinate(coord, m_exe_ctx.GetThreadPtr()); |
| 3863 | Stream &stream = result.GetOutputStream(); |
| 3864 | |
| 3865 | if (success) |
| 3866 | { |
| 3867 | stream.Printf("Coordinate: (%" PRIu32 ", %" PRIu32 ", %" PRIu32 ")", coord[0], coord[1], coord[2]); |
| 3868 | stream.EOL(); |
| 3869 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 3870 | } |
| 3871 | else |
| 3872 | { |
| 3873 | stream.Printf("Error: Coordinate could not be found."); |
| 3874 | stream.EOL(); |
| 3875 | result.SetStatus(eReturnStatusFailed); |
| 3876 | } |
| 3877 | return true; |
| 3878 | } |
| 3879 | }; |
| 3880 | |
Ewan Crawford | 7dc7771 | 2015-09-10 10:08:48 +0000 | [diff] [blame] | 3881 | class CommandObjectRenderScriptRuntimeKernelBreakpoint : public CommandObjectMultiword |
| 3882 | { |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3883 | public: |
Ewan Crawford | 7dc7771 | 2015-09-10 10:08:48 +0000 | [diff] [blame] | 3884 | CommandObjectRenderScriptRuntimeKernelBreakpoint(CommandInterpreter &interpreter) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3885 | : CommandObjectMultiword(interpreter, "renderscript kernel", |
| 3886 | "Commands that generate breakpoints on renderscript kernels.", nullptr) |
Ewan Crawford | 7dc7771 | 2015-09-10 10:08:48 +0000 | [diff] [blame] | 3887 | { |
| 3888 | LoadSubCommand("set", CommandObjectSP(new CommandObjectRenderScriptRuntimeKernelBreakpointSet(interpreter))); |
| 3889 | LoadSubCommand("all", CommandObjectSP(new CommandObjectRenderScriptRuntimeKernelBreakpointAll(interpreter))); |
| 3890 | } |
| 3891 | |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3892 | ~CommandObjectRenderScriptRuntimeKernelBreakpoint() override = default; |
Ewan Crawford | 7dc7771 | 2015-09-10 10:08:48 +0000 | [diff] [blame] | 3893 | }; |
| 3894 | |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3895 | class CommandObjectRenderScriptRuntimeKernel : public CommandObjectMultiword |
| 3896 | { |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3897 | public: |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3898 | CommandObjectRenderScriptRuntimeKernel(CommandInterpreter &interpreter) |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 3899 | : CommandObjectMultiword(interpreter, "renderscript kernel", "Commands that deal with RenderScript kernels.", |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3900 | nullptr) |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3901 | { |
| 3902 | LoadSubCommand("list", CommandObjectSP(new CommandObjectRenderScriptRuntimeKernelList(interpreter))); |
Ewan Crawford | 36175cc | 2016-01-29 10:11:03 +0000 | [diff] [blame] | 3903 | LoadSubCommand("coordinate", |
| 3904 | CommandObjectSP(new CommandObjectRenderScriptRuntimeKernelCoordinate(interpreter))); |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3905 | LoadSubCommand("breakpoint", |
| 3906 | CommandObjectSP(new CommandObjectRenderScriptRuntimeKernelBreakpoint(interpreter))); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3907 | } |
| 3908 | |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3909 | ~CommandObjectRenderScriptRuntimeKernel() override = default; |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3910 | }; |
| 3911 | |
| 3912 | class CommandObjectRenderScriptRuntimeContextDump : public CommandObjectParsed |
| 3913 | { |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3914 | public: |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3915 | CommandObjectRenderScriptRuntimeContextDump(CommandInterpreter &interpreter) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3916 | : CommandObjectParsed(interpreter, "renderscript context dump", "Dumps renderscript context information.", |
| 3917 | "renderscript context dump", eCommandRequiresProcess | eCommandProcessMustBeLaunched) |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3918 | { |
| 3919 | } |
| 3920 | |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3921 | ~CommandObjectRenderScriptRuntimeContextDump() override = default; |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3922 | |
| 3923 | bool |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3924 | DoExecute(Args &command, CommandReturnObject &result) override |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3925 | { |
| 3926 | RenderScriptRuntime *runtime = |
| 3927 | (RenderScriptRuntime *)m_exe_ctx.GetProcessPtr()->GetLanguageRuntime(eLanguageTypeExtRenderScript); |
| 3928 | runtime->DumpContexts(result.GetOutputStream()); |
| 3929 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 3930 | return true; |
| 3931 | } |
| 3932 | }; |
| 3933 | |
| 3934 | class CommandObjectRenderScriptRuntimeContext : public CommandObjectMultiword |
| 3935 | { |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3936 | public: |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3937 | CommandObjectRenderScriptRuntimeContext(CommandInterpreter &interpreter) |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 3938 | : CommandObjectMultiword(interpreter, "renderscript context", "Commands that deal with RenderScript contexts.", |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3939 | nullptr) |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3940 | { |
| 3941 | LoadSubCommand("dump", CommandObjectSP(new CommandObjectRenderScriptRuntimeContextDump(interpreter))); |
| 3942 | } |
| 3943 | |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3944 | ~CommandObjectRenderScriptRuntimeContext() override = default; |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 3945 | }; |
| 3946 | |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 3947 | class CommandObjectRenderScriptRuntimeAllocationDump : public CommandObjectParsed |
| 3948 | { |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3949 | public: |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 3950 | CommandObjectRenderScriptRuntimeAllocationDump(CommandInterpreter &interpreter) |
| 3951 | : CommandObjectParsed(interpreter, "renderscript allocation dump", |
| 3952 | "Displays the contents of a particular allocation", "renderscript allocation dump <ID>", |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3953 | eCommandRequiresProcess | eCommandProcessMustBeLaunched), |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame^] | 3954 | m_options() |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 3955 | { |
| 3956 | } |
| 3957 | |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3958 | ~CommandObjectRenderScriptRuntimeAllocationDump() override = default; |
| 3959 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 3960 | Options * |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3961 | GetOptions() override |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 3962 | { |
| 3963 | return &m_options; |
| 3964 | } |
| 3965 | |
| 3966 | class CommandOptions : public Options |
| 3967 | { |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3968 | public: |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame^] | 3969 | CommandOptions() : Options() {} |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 3970 | |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3971 | ~CommandOptions() override = default; |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 3972 | |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 3973 | Error |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame^] | 3974 | SetOptionValue(uint32_t option_idx, const char *option_arg, |
| 3975 | ExecutionContext *execution_context) override |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 3976 | { |
| 3977 | Error error; |
| 3978 | const int short_option = m_getopt_table[option_idx].val; |
| 3979 | |
| 3980 | switch (short_option) |
| 3981 | { |
| 3982 | case 'f': |
| 3983 | m_outfile.SetFile(option_arg, true); |
| 3984 | if (m_outfile.Exists()) |
| 3985 | { |
| 3986 | m_outfile.Clear(); |
| 3987 | error.SetErrorStringWithFormat("file already exists: '%s'", option_arg); |
| 3988 | } |
| 3989 | break; |
| 3990 | default: |
| 3991 | error.SetErrorStringWithFormat("unrecognized option '%c'", short_option); |
| 3992 | break; |
| 3993 | } |
| 3994 | return error; |
| 3995 | } |
| 3996 | |
| 3997 | void |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame^] | 3998 | OptionParsingStarting(ExecutionContext *execution_context) override |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 3999 | { |
| 4000 | m_outfile.Clear(); |
| 4001 | } |
| 4002 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 4003 | const OptionDefinition * |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 4004 | GetDefinitions() override |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 4005 | { |
| 4006 | return g_option_table; |
| 4007 | } |
| 4008 | |
| 4009 | static OptionDefinition g_option_table[]; |
| 4010 | FileSpec m_outfile; |
| 4011 | }; |
| 4012 | |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 4013 | bool |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 4014 | DoExecute(Args &command, CommandReturnObject &result) override |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 4015 | { |
| 4016 | const size_t argc = command.GetArgumentCount(); |
| 4017 | if (argc < 1) |
| 4018 | { |
| 4019 | result.AppendErrorWithFormat("'%s' takes 1 argument, an allocation ID. As well as an optional -f argument", |
| 4020 | m_cmd_name.c_str()); |
| 4021 | result.SetStatus(eReturnStatusFailed); |
| 4022 | return false; |
| 4023 | } |
| 4024 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 4025 | RenderScriptRuntime *runtime = static_cast<RenderScriptRuntime *>( |
| 4026 | m_exe_ctx.GetProcessPtr()->GetLanguageRuntime(eLanguageTypeExtRenderScript)); |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 4027 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 4028 | const char *id_cstr = command.GetArgumentAtIndex(0); |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 4029 | bool convert_complete = false; |
| 4030 | const uint32_t id = StringConvert::ToUInt32(id_cstr, UINT32_MAX, 0, &convert_complete); |
| 4031 | if (!convert_complete) |
| 4032 | { |
| 4033 | result.AppendErrorWithFormat("invalid allocation id argument '%s'", id_cstr); |
| 4034 | result.SetStatus(eReturnStatusFailed); |
| 4035 | return false; |
| 4036 | } |
| 4037 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 4038 | Stream *output_strm = nullptr; |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 4039 | StreamFile outfile_stream; |
| 4040 | const FileSpec &outfile_spec = m_options.m_outfile; // Dump allocation to file instead |
| 4041 | if (outfile_spec) |
| 4042 | { |
| 4043 | // Open output file |
| 4044 | char path[256]; |
| 4045 | outfile_spec.GetPath(path, sizeof(path)); |
| 4046 | if (outfile_stream.GetFile().Open(path, File::eOpenOptionWrite | File::eOpenOptionCanCreate).Success()) |
| 4047 | { |
| 4048 | output_strm = &outfile_stream; |
| 4049 | result.GetOutputStream().Printf("Results written to '%s'", path); |
| 4050 | result.GetOutputStream().EOL(); |
| 4051 | } |
| 4052 | else |
| 4053 | { |
| 4054 | result.AppendErrorWithFormat("Couldn't open file '%s'", path); |
| 4055 | result.SetStatus(eReturnStatusFailed); |
| 4056 | return false; |
| 4057 | } |
| 4058 | } |
| 4059 | else |
| 4060 | output_strm = &result.GetOutputStream(); |
| 4061 | |
| 4062 | assert(output_strm != nullptr); |
| 4063 | bool success = runtime->DumpAllocation(*output_strm, m_exe_ctx.GetFramePtr(), id); |
| 4064 | |
| 4065 | if (success) |
| 4066 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 4067 | else |
| 4068 | result.SetStatus(eReturnStatusFailed); |
| 4069 | |
| 4070 | return true; |
| 4071 | } |
| 4072 | |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 4073 | private: |
| 4074 | CommandOptions m_options; |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 4075 | }; |
| 4076 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 4077 | OptionDefinition CommandObjectRenderScriptRuntimeAllocationDump::CommandOptions::g_option_table[] = { |
| 4078 | {LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFilename, |
| 4079 | "Print results to specified file instead of command line."}, |
| 4080 | {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}}; |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 4081 | |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 4082 | class CommandObjectRenderScriptRuntimeAllocationList : public CommandObjectParsed |
| 4083 | { |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 4084 | public: |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 4085 | CommandObjectRenderScriptRuntimeAllocationList(CommandInterpreter &interpreter) |
| 4086 | : CommandObjectParsed(interpreter, "renderscript allocation list", |
| 4087 | "List renderscript allocations and their information.", "renderscript allocation list", |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 4088 | eCommandRequiresProcess | eCommandProcessMustBeLaunched), |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame^] | 4089 | m_options() |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 4090 | { |
| 4091 | } |
| 4092 | |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 4093 | ~CommandObjectRenderScriptRuntimeAllocationList() override = default; |
| 4094 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 4095 | Options * |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 4096 | GetOptions() override |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 4097 | { |
| 4098 | return &m_options; |
| 4099 | } |
| 4100 | |
| 4101 | class CommandOptions : public Options |
| 4102 | { |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 4103 | public: |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame^] | 4104 | CommandOptions() : Options(), m_id(0) {} |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 4105 | |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 4106 | ~CommandOptions() override = default; |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 4107 | |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 4108 | Error |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame^] | 4109 | SetOptionValue(uint32_t option_idx, const char *option_arg, |
| 4110 | ExecutionContext *execution_context) override |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 4111 | { |
| 4112 | Error error; |
| 4113 | const int short_option = m_getopt_table[option_idx].val; |
| 4114 | |
| 4115 | switch (short_option) |
| 4116 | { |
Ewan Crawford | b649b00 | 2016-01-26 10:41:08 +0000 | [diff] [blame] | 4117 | case 'i': |
| 4118 | bool success; |
| 4119 | m_id = StringConvert::ToUInt32(option_arg, 0, 0, &success); |
| 4120 | if (!success) |
| 4121 | error.SetErrorStringWithFormat("invalid integer value for option '%c'", short_option); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 4122 | break; |
| 4123 | default: |
| 4124 | error.SetErrorStringWithFormat("unrecognized option '%c'", short_option); |
| 4125 | break; |
| 4126 | } |
| 4127 | return error; |
| 4128 | } |
| 4129 | |
| 4130 | void |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame^] | 4131 | OptionParsingStarting(ExecutionContext *execution_context) override |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 4132 | { |
Ewan Crawford | b649b00 | 2016-01-26 10:41:08 +0000 | [diff] [blame] | 4133 | m_id = 0; |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 4134 | } |
| 4135 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 4136 | const OptionDefinition * |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 4137 | GetDefinitions() override |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 4138 | { |
| 4139 | return g_option_table; |
| 4140 | } |
| 4141 | |
| 4142 | static OptionDefinition g_option_table[]; |
Ewan Crawford | b649b00 | 2016-01-26 10:41:08 +0000 | [diff] [blame] | 4143 | uint32_t m_id; |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 4144 | }; |
| 4145 | |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 4146 | bool |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 4147 | DoExecute(Args &command, CommandReturnObject &result) override |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 4148 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 4149 | RenderScriptRuntime *runtime = static_cast<RenderScriptRuntime *>( |
| 4150 | m_exe_ctx.GetProcessPtr()->GetLanguageRuntime(eLanguageTypeExtRenderScript)); |
Ewan Crawford | b649b00 | 2016-01-26 10:41:08 +0000 | [diff] [blame] | 4151 | runtime->ListAllocations(result.GetOutputStream(), m_exe_ctx.GetFramePtr(), m_options.m_id); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 4152 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 4153 | return true; |
| 4154 | } |
| 4155 | |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 4156 | private: |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 4157 | CommandOptions m_options; |
| 4158 | }; |
| 4159 | |
Ewan Crawford | b649b00 | 2016-01-26 10:41:08 +0000 | [diff] [blame] | 4160 | OptionDefinition CommandObjectRenderScriptRuntimeAllocationList::CommandOptions::g_option_table[] = { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 4161 | {LLDB_OPT_SET_1, false, "id", 'i', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeIndex, |
Ewan Crawford | b649b00 | 2016-01-26 10:41:08 +0000 | [diff] [blame] | 4162 | "Only show details of a single allocation with specified id."}, |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 4163 | {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}}; |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 4164 | |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 4165 | class CommandObjectRenderScriptRuntimeAllocationLoad : public CommandObjectParsed |
| 4166 | { |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 4167 | public: |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 4168 | CommandObjectRenderScriptRuntimeAllocationLoad(CommandInterpreter &interpreter) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 4169 | : CommandObjectParsed( |
| 4170 | interpreter, "renderscript allocation load", "Loads renderscript allocation contents from a file.", |
| 4171 | "renderscript allocation load <ID> <filename>", eCommandRequiresProcess | eCommandProcessMustBeLaunched) |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 4172 | { |
| 4173 | } |
| 4174 | |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 4175 | ~CommandObjectRenderScriptRuntimeAllocationLoad() override = default; |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 4176 | |
| 4177 | bool |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 4178 | DoExecute(Args &command, CommandReturnObject &result) override |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 4179 | { |
| 4180 | const size_t argc = command.GetArgumentCount(); |
| 4181 | if (argc != 2) |
| 4182 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 4183 | result.AppendErrorWithFormat("'%s' takes 2 arguments, an allocation ID and filename to read from.", |
| 4184 | m_cmd_name.c_str()); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 4185 | result.SetStatus(eReturnStatusFailed); |
| 4186 | return false; |
| 4187 | } |
| 4188 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 4189 | RenderScriptRuntime *runtime = static_cast<RenderScriptRuntime *>( |
| 4190 | m_exe_ctx.GetProcessPtr()->GetLanguageRuntime(eLanguageTypeExtRenderScript)); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 4191 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 4192 | const char *id_cstr = command.GetArgumentAtIndex(0); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 4193 | bool convert_complete = false; |
| 4194 | const uint32_t id = StringConvert::ToUInt32(id_cstr, UINT32_MAX, 0, &convert_complete); |
| 4195 | if (!convert_complete) |
| 4196 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 4197 | result.AppendErrorWithFormat("invalid allocation id argument '%s'", id_cstr); |
| 4198 | result.SetStatus(eReturnStatusFailed); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 4199 | return false; |
| 4200 | } |
| 4201 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 4202 | const char *filename = command.GetArgumentAtIndex(1); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 4203 | bool success = runtime->LoadAllocation(result.GetOutputStream(), id, filename, m_exe_ctx.GetFramePtr()); |
| 4204 | |
| 4205 | if (success) |
| 4206 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 4207 | else |
| 4208 | result.SetStatus(eReturnStatusFailed); |
| 4209 | |
| 4210 | return true; |
| 4211 | } |
| 4212 | }; |
| 4213 | |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 4214 | class CommandObjectRenderScriptRuntimeAllocationSave : public CommandObjectParsed |
| 4215 | { |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 4216 | public: |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 4217 | CommandObjectRenderScriptRuntimeAllocationSave(CommandInterpreter &interpreter) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 4218 | : CommandObjectParsed( |
| 4219 | interpreter, "renderscript allocation save", "Write renderscript allocation contents to a file.", |
| 4220 | "renderscript allocation save <ID> <filename>", eCommandRequiresProcess | eCommandProcessMustBeLaunched) |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 4221 | { |
| 4222 | } |
| 4223 | |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 4224 | ~CommandObjectRenderScriptRuntimeAllocationSave() override = default; |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 4225 | |
| 4226 | bool |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 4227 | DoExecute(Args &command, CommandReturnObject &result) override |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 4228 | { |
| 4229 | const size_t argc = command.GetArgumentCount(); |
| 4230 | if (argc != 2) |
| 4231 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 4232 | result.AppendErrorWithFormat("'%s' takes 2 arguments, an allocation ID and filename to read from.", |
| 4233 | m_cmd_name.c_str()); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 4234 | result.SetStatus(eReturnStatusFailed); |
| 4235 | return false; |
| 4236 | } |
| 4237 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 4238 | RenderScriptRuntime *runtime = static_cast<RenderScriptRuntime *>( |
| 4239 | m_exe_ctx.GetProcessPtr()->GetLanguageRuntime(eLanguageTypeExtRenderScript)); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 4240 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 4241 | const char *id_cstr = command.GetArgumentAtIndex(0); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 4242 | bool convert_complete = false; |
| 4243 | const uint32_t id = StringConvert::ToUInt32(id_cstr, UINT32_MAX, 0, &convert_complete); |
| 4244 | if (!convert_complete) |
| 4245 | { |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 4246 | result.AppendErrorWithFormat("invalid allocation id argument '%s'", id_cstr); |
| 4247 | result.SetStatus(eReturnStatusFailed); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 4248 | return false; |
| 4249 | } |
| 4250 | |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 4251 | const char *filename = command.GetArgumentAtIndex(1); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 4252 | bool success = runtime->SaveAllocation(result.GetOutputStream(), id, filename, m_exe_ctx.GetFramePtr()); |
| 4253 | |
| 4254 | if (success) |
| 4255 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 4256 | else |
| 4257 | result.SetStatus(eReturnStatusFailed); |
| 4258 | |
| 4259 | return true; |
| 4260 | } |
| 4261 | }; |
| 4262 | |
Ewan Crawford | 0d2bfcf | 2016-02-04 09:44:23 +0000 | [diff] [blame] | 4263 | class CommandObjectRenderScriptRuntimeAllocationRefresh : public CommandObjectParsed |
| 4264 | { |
| 4265 | public: |
| 4266 | CommandObjectRenderScriptRuntimeAllocationRefresh(CommandInterpreter &interpreter) |
| 4267 | : CommandObjectParsed(interpreter, "renderscript allocation refresh", |
| 4268 | "Recomputes the details of all allocations.", "renderscript allocation refresh", |
| 4269 | eCommandRequiresProcess | eCommandProcessMustBeLaunched) |
| 4270 | { |
| 4271 | } |
| 4272 | |
| 4273 | ~CommandObjectRenderScriptRuntimeAllocationRefresh() override = default; |
| 4274 | |
| 4275 | bool |
| 4276 | DoExecute(Args &command, CommandReturnObject &result) override |
| 4277 | { |
| 4278 | RenderScriptRuntime *runtime = static_cast<RenderScriptRuntime *>( |
| 4279 | m_exe_ctx.GetProcessPtr()->GetLanguageRuntime(eLanguageTypeExtRenderScript)); |
| 4280 | |
| 4281 | bool success = runtime->RecomputeAllAllocations(result.GetOutputStream(), m_exe_ctx.GetFramePtr()); |
| 4282 | |
| 4283 | if (success) |
| 4284 | { |
| 4285 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 4286 | return true; |
| 4287 | } |
| 4288 | else |
| 4289 | { |
| 4290 | result.SetStatus(eReturnStatusFailed); |
| 4291 | return false; |
| 4292 | } |
| 4293 | } |
| 4294 | }; |
| 4295 | |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 4296 | class CommandObjectRenderScriptRuntimeAllocation : public CommandObjectMultiword |
| 4297 | { |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 4298 | public: |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 4299 | CommandObjectRenderScriptRuntimeAllocation(CommandInterpreter &interpreter) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 4300 | : CommandObjectMultiword(interpreter, "renderscript allocation", |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 4301 | "Commands that deal with RenderScript allocations.", nullptr) |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 4302 | { |
| 4303 | LoadSubCommand("list", CommandObjectSP(new CommandObjectRenderScriptRuntimeAllocationList(interpreter))); |
Ewan Crawford | a0f0867 | 2015-10-16 08:28:47 +0000 | [diff] [blame] | 4304 | LoadSubCommand("dump", CommandObjectSP(new CommandObjectRenderScriptRuntimeAllocationDump(interpreter))); |
Ewan Crawford | 55232f0 | 2015-10-21 08:50:42 +0000 | [diff] [blame] | 4305 | LoadSubCommand("save", CommandObjectSP(new CommandObjectRenderScriptRuntimeAllocationSave(interpreter))); |
| 4306 | LoadSubCommand("load", CommandObjectSP(new CommandObjectRenderScriptRuntimeAllocationLoad(interpreter))); |
Ewan Crawford | 0d2bfcf | 2016-02-04 09:44:23 +0000 | [diff] [blame] | 4307 | LoadSubCommand("refresh", CommandObjectSP(new CommandObjectRenderScriptRuntimeAllocationRefresh(interpreter))); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 4308 | } |
| 4309 | |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 4310 | ~CommandObjectRenderScriptRuntimeAllocation() override = default; |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 4311 | }; |
| 4312 | |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 4313 | class CommandObjectRenderScriptRuntimeStatus : public CommandObjectParsed |
| 4314 | { |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 4315 | public: |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 4316 | CommandObjectRenderScriptRuntimeStatus(CommandInterpreter &interpreter) |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 4317 | : CommandObjectParsed(interpreter, "renderscript status", "Displays current RenderScript runtime status.", |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 4318 | "renderscript status", eCommandRequiresProcess | eCommandProcessMustBeLaunched) |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 4319 | { |
| 4320 | } |
| 4321 | |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 4322 | ~CommandObjectRenderScriptRuntimeStatus() override = default; |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 4323 | |
| 4324 | bool |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 4325 | DoExecute(Args &command, CommandReturnObject &result) override |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 4326 | { |
| 4327 | RenderScriptRuntime *runtime = |
| 4328 | (RenderScriptRuntime *)m_exe_ctx.GetProcessPtr()->GetLanguageRuntime(eLanguageTypeExtRenderScript); |
| 4329 | runtime->Status(result.GetOutputStream()); |
| 4330 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 4331 | return true; |
| 4332 | } |
| 4333 | }; |
| 4334 | |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 4335 | class CommandObjectRenderScriptRuntime : public CommandObjectMultiword |
| 4336 | { |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 4337 | public: |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 4338 | CommandObjectRenderScriptRuntime(CommandInterpreter &interpreter) |
Kate Stone | 7428a18 | 2016-07-14 22:03:10 +0000 | [diff] [blame] | 4339 | : CommandObjectMultiword(interpreter, "renderscript", "Commands for operating on the RenderScript runtime.", |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 4340 | "renderscript <subcommand> [<subcommand-options>]") |
| 4341 | { |
| 4342 | LoadSubCommand("module", CommandObjectSP(new CommandObjectRenderScriptRuntimeModule(interpreter))); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 4343 | LoadSubCommand("status", CommandObjectSP(new CommandObjectRenderScriptRuntimeStatus(interpreter))); |
| 4344 | LoadSubCommand("kernel", CommandObjectSP(new CommandObjectRenderScriptRuntimeKernel(interpreter))); |
| 4345 | LoadSubCommand("context", CommandObjectSP(new CommandObjectRenderScriptRuntimeContext(interpreter))); |
Ewan Crawford | 15f2bd9 | 2015-10-06 08:42:32 +0000 | [diff] [blame] | 4346 | LoadSubCommand("allocation", CommandObjectSP(new CommandObjectRenderScriptRuntimeAllocation(interpreter))); |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 4347 | } |
| 4348 | |
Eugene Zelenko | 222b937 | 2015-10-27 00:45:06 +0000 | [diff] [blame] | 4349 | ~CommandObjectRenderScriptRuntime() override = default; |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 4350 | }; |
Colin Riley | ef20b08 | 2015-04-14 07:39:24 +0000 | [diff] [blame] | 4351 | |
| 4352 | void |
| 4353 | RenderScriptRuntime::Initiate() |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 4354 | { |
Colin Riley | ef20b08 | 2015-04-14 07:39:24 +0000 | [diff] [blame] | 4355 | assert(!m_initiated); |
Colin Riley | 5ec532a | 2015-04-09 16:49:25 +0000 | [diff] [blame] | 4356 | } |
Colin Riley | ef20b08 | 2015-04-14 07:39:24 +0000 | [diff] [blame] | 4357 | |
| 4358 | RenderScriptRuntime::RenderScriptRuntime(Process *process) |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 4359 | : lldb_private::CPPLanguageRuntime(process), |
| 4360 | m_initiated(false), |
| 4361 | m_debuggerPresentFlagged(false), |
Luke Drummond | 1945958 | 2016-07-28 14:21:07 +0000 | [diff] [blame] | 4362 | m_breakAllKernels(false), |
| 4363 | m_ir_passes(nullptr) |
Colin Riley | ef20b08 | 2015-04-14 07:39:24 +0000 | [diff] [blame] | 4364 | { |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 4365 | ModulesDidLoad(process->GetTarget().GetImages()); |
Colin Riley | ef20b08 | 2015-04-14 07:39:24 +0000 | [diff] [blame] | 4366 | } |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 4367 | |
| 4368 | lldb::CommandObjectSP |
Aidan Dodds | b3f7f69 | 2016-01-28 16:39:44 +0000 | [diff] [blame] | 4369 | RenderScriptRuntime::GetCommandObject(lldb_private::CommandInterpreter &interpreter) |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 4370 | { |
Enrico Granata | 0a66e2f | 2016-02-06 00:43:07 +0000 | [diff] [blame] | 4371 | return CommandObjectSP(new CommandObjectRenderScriptRuntime(interpreter)); |
Colin Riley | 4640cde | 2015-06-01 18:23:41 +0000 | [diff] [blame] | 4372 | } |
| 4373 | |
Ewan Crawford | 78f339d | 2015-09-21 10:53:18 +0000 | [diff] [blame] | 4374 | RenderScriptRuntime::~RenderScriptRuntime() = default; |