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