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