jkummerow@chromium.org | 1145ef8 | 2012-02-02 16:21:15 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include "v8.h" |
| 29 | |
| 30 | #include "disassembler.h" |
| 31 | #include "disasm.h" |
| 32 | #include "jsregexp.h" |
| 33 | #include "objects-visiting.h" |
| 34 | |
| 35 | namespace v8 { |
| 36 | namespace internal { |
| 37 | |
| 38 | #ifdef OBJECT_PRINT |
| 39 | |
| 40 | static const char* TypeToString(InstanceType type); |
| 41 | |
| 42 | |
| 43 | void MaybeObject::Print(FILE* out) { |
| 44 | Object* this_as_object; |
| 45 | if (ToObject(&this_as_object)) { |
| 46 | if (this_as_object->IsSmi()) { |
| 47 | Smi::cast(this_as_object)->SmiPrint(out); |
| 48 | } else { |
| 49 | HeapObject::cast(this_as_object)->HeapObjectPrint(out); |
| 50 | } |
| 51 | } else { |
| 52 | Failure::cast(this)->FailurePrint(out); |
| 53 | } |
| 54 | Flush(out); |
| 55 | } |
| 56 | |
| 57 | |
| 58 | void MaybeObject::PrintLn(FILE* out) { |
| 59 | Print(out); |
| 60 | PrintF(out, "\n"); |
| 61 | } |
| 62 | |
| 63 | |
| 64 | void HeapObject::PrintHeader(FILE* out, const char* id) { |
| 65 | PrintF(out, "%p: [%s]\n", reinterpret_cast<void*>(this), id); |
| 66 | } |
| 67 | |
| 68 | |
| 69 | void HeapObject::HeapObjectPrint(FILE* out) { |
| 70 | InstanceType instance_type = map()->instance_type(); |
| 71 | |
| 72 | HandleScope scope; |
| 73 | if (instance_type < FIRST_NONSTRING_TYPE) { |
| 74 | String::cast(this)->StringPrint(out); |
| 75 | return; |
| 76 | } |
| 77 | |
| 78 | switch (instance_type) { |
| 79 | case MAP_TYPE: |
| 80 | Map::cast(this)->MapPrint(out); |
| 81 | break; |
| 82 | case HEAP_NUMBER_TYPE: |
| 83 | HeapNumber::cast(this)->HeapNumberPrint(out); |
| 84 | break; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 85 | case FIXED_DOUBLE_ARRAY_TYPE: |
| 86 | FixedDoubleArray::cast(this)->FixedDoubleArrayPrint(out); |
| 87 | break; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 88 | case FIXED_ARRAY_TYPE: |
| 89 | FixedArray::cast(this)->FixedArrayPrint(out); |
| 90 | break; |
| 91 | case BYTE_ARRAY_TYPE: |
| 92 | ByteArray::cast(this)->ByteArrayPrint(out); |
| 93 | break; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 94 | case FREE_SPACE_TYPE: |
| 95 | FreeSpace::cast(this)->FreeSpacePrint(out); |
| 96 | break; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 97 | case EXTERNAL_PIXEL_ARRAY_TYPE: |
| 98 | ExternalPixelArray::cast(this)->ExternalPixelArrayPrint(out); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 99 | break; |
| 100 | case EXTERNAL_BYTE_ARRAY_TYPE: |
| 101 | ExternalByteArray::cast(this)->ExternalByteArrayPrint(out); |
| 102 | break; |
| 103 | case EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE: |
| 104 | ExternalUnsignedByteArray::cast(this) |
| 105 | ->ExternalUnsignedByteArrayPrint(out); |
| 106 | break; |
| 107 | case EXTERNAL_SHORT_ARRAY_TYPE: |
| 108 | ExternalShortArray::cast(this)->ExternalShortArrayPrint(out); |
| 109 | break; |
| 110 | case EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE: |
| 111 | ExternalUnsignedShortArray::cast(this) |
| 112 | ->ExternalUnsignedShortArrayPrint(out); |
| 113 | break; |
| 114 | case EXTERNAL_INT_ARRAY_TYPE: |
| 115 | ExternalIntArray::cast(this)->ExternalIntArrayPrint(out); |
| 116 | break; |
| 117 | case EXTERNAL_UNSIGNED_INT_ARRAY_TYPE: |
| 118 | ExternalUnsignedIntArray::cast(this)->ExternalUnsignedIntArrayPrint(out); |
| 119 | break; |
| 120 | case EXTERNAL_FLOAT_ARRAY_TYPE: |
| 121 | ExternalFloatArray::cast(this)->ExternalFloatArrayPrint(out); |
| 122 | break; |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 123 | case EXTERNAL_DOUBLE_ARRAY_TYPE: |
| 124 | ExternalDoubleArray::cast(this)->ExternalDoubleArrayPrint(out); |
| 125 | break; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 126 | case FILLER_TYPE: |
| 127 | PrintF(out, "filler"); |
| 128 | break; |
| 129 | case JS_OBJECT_TYPE: // fall through |
| 130 | case JS_CONTEXT_EXTENSION_OBJECT_TYPE: |
| 131 | case JS_ARRAY_TYPE: |
| 132 | case JS_REGEXP_TYPE: |
| 133 | JSObject::cast(this)->JSObjectPrint(out); |
| 134 | break; |
| 135 | case ODDBALL_TYPE: |
| 136 | Oddball::cast(this)->to_string()->Print(out); |
| 137 | break; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 138 | case JS_MODULE_TYPE: |
| 139 | JSModule::cast(this)->JSModulePrint(out); |
| 140 | break; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 141 | case JS_FUNCTION_TYPE: |
| 142 | JSFunction::cast(this)->JSFunctionPrint(out); |
| 143 | break; |
| 144 | case JS_GLOBAL_PROXY_TYPE: |
| 145 | JSGlobalProxy::cast(this)->JSGlobalProxyPrint(out); |
| 146 | break; |
| 147 | case JS_GLOBAL_OBJECT_TYPE: |
| 148 | JSGlobalObject::cast(this)->JSGlobalObjectPrint(out); |
| 149 | break; |
| 150 | case JS_BUILTINS_OBJECT_TYPE: |
| 151 | JSBuiltinsObject::cast(this)->JSBuiltinsObjectPrint(out); |
| 152 | break; |
| 153 | case JS_VALUE_TYPE: |
| 154 | PrintF(out, "Value wrapper around:"); |
| 155 | JSValue::cast(this)->value()->Print(out); |
| 156 | break; |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 157 | case JS_DATE_TYPE: |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 158 | JSDate::cast(this)->JSDatePrint(out); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 159 | break; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 160 | case CODE_TYPE: |
| 161 | Code::cast(this)->CodePrint(out); |
| 162 | break; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 163 | case JS_PROXY_TYPE: |
| 164 | JSProxy::cast(this)->JSProxyPrint(out); |
| 165 | break; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 166 | case JS_FUNCTION_PROXY_TYPE: |
| 167 | JSFunctionProxy::cast(this)->JSFunctionProxyPrint(out); |
| 168 | break; |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 169 | case JS_WEAK_MAP_TYPE: |
| 170 | JSWeakMap::cast(this)->JSWeakMapPrint(out); |
| 171 | break; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 172 | case FOREIGN_TYPE: |
| 173 | Foreign::cast(this)->ForeignPrint(out); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 174 | break; |
| 175 | case SHARED_FUNCTION_INFO_TYPE: |
| 176 | SharedFunctionInfo::cast(this)->SharedFunctionInfoPrint(out); |
| 177 | break; |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 178 | case JS_MESSAGE_OBJECT_TYPE: |
| 179 | JSMessageObject::cast(this)->JSMessageObjectPrint(out); |
| 180 | break; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 181 | case JS_GLOBAL_PROPERTY_CELL_TYPE: |
| 182 | JSGlobalPropertyCell::cast(this)->JSGlobalPropertyCellPrint(out); |
| 183 | break; |
| 184 | #define MAKE_STRUCT_CASE(NAME, Name, name) \ |
| 185 | case NAME##_TYPE: \ |
| 186 | Name::cast(this)->Name##Print(out); \ |
| 187 | break; |
| 188 | STRUCT_LIST(MAKE_STRUCT_CASE) |
| 189 | #undef MAKE_STRUCT_CASE |
| 190 | |
| 191 | default: |
| 192 | PrintF(out, "UNKNOWN TYPE %d", map()->instance_type()); |
| 193 | UNREACHABLE(); |
| 194 | break; |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | |
| 199 | void ByteArray::ByteArrayPrint(FILE* out) { |
| 200 | PrintF(out, "byte array, data starts at %p", GetDataStartAddress()); |
| 201 | } |
| 202 | |
| 203 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 204 | void FreeSpace::FreeSpacePrint(FILE* out) { |
| 205 | PrintF(out, "free space, size %d", Size()); |
| 206 | } |
| 207 | |
| 208 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 209 | void ExternalPixelArray::ExternalPixelArrayPrint(FILE* out) { |
| 210 | PrintF(out, "external pixel array"); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | |
| 214 | void ExternalByteArray::ExternalByteArrayPrint(FILE* out) { |
| 215 | PrintF(out, "external byte array"); |
| 216 | } |
| 217 | |
| 218 | |
| 219 | void ExternalUnsignedByteArray::ExternalUnsignedByteArrayPrint(FILE* out) { |
| 220 | PrintF(out, "external unsigned byte array"); |
| 221 | } |
| 222 | |
| 223 | |
| 224 | void ExternalShortArray::ExternalShortArrayPrint(FILE* out) { |
| 225 | PrintF(out, "external short array"); |
| 226 | } |
| 227 | |
| 228 | |
| 229 | void ExternalUnsignedShortArray::ExternalUnsignedShortArrayPrint(FILE* out) { |
| 230 | PrintF(out, "external unsigned short array"); |
| 231 | } |
| 232 | |
| 233 | |
| 234 | void ExternalIntArray::ExternalIntArrayPrint(FILE* out) { |
| 235 | PrintF(out, "external int array"); |
| 236 | } |
| 237 | |
| 238 | |
| 239 | void ExternalUnsignedIntArray::ExternalUnsignedIntArrayPrint(FILE* out) { |
| 240 | PrintF(out, "external unsigned int array"); |
| 241 | } |
| 242 | |
| 243 | |
| 244 | void ExternalFloatArray::ExternalFloatArrayPrint(FILE* out) { |
| 245 | PrintF(out, "external float array"); |
| 246 | } |
| 247 | |
| 248 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 249 | void ExternalDoubleArray::ExternalDoubleArrayPrint(FILE* out) { |
| 250 | PrintF(out, "external double array"); |
| 251 | } |
| 252 | |
| 253 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 254 | void JSObject::PrintProperties(FILE* out) { |
| 255 | if (HasFastProperties()) { |
| 256 | DescriptorArray* descs = map()->instance_descriptors(); |
| 257 | for (int i = 0; i < descs->number_of_descriptors(); i++) { |
| 258 | PrintF(out, " "); |
| 259 | descs->GetKey(i)->StringPrint(out); |
| 260 | PrintF(out, ": "); |
| 261 | switch (descs->GetType(i)) { |
| 262 | case FIELD: { |
| 263 | int index = descs->GetFieldIndex(i); |
| 264 | FastPropertyAt(index)->ShortPrint(out); |
| 265 | PrintF(out, " (field at offset %d)\n", index); |
| 266 | break; |
| 267 | } |
| 268 | case CONSTANT_FUNCTION: |
| 269 | descs->GetConstantFunction(i)->ShortPrint(out); |
| 270 | PrintF(out, " (constant function)\n"); |
| 271 | break; |
| 272 | case CALLBACKS: |
| 273 | descs->GetCallbacksObject(i)->ShortPrint(out); |
| 274 | PrintF(out, " (callback)\n"); |
| 275 | break; |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 276 | case NORMAL: // only in slow mode |
| 277 | case HANDLER: // only in lookup results, not in descriptors |
| 278 | case INTERCEPTOR: // only in lookup results, not in descriptors |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 279 | // There are no transitions in the descriptor array. |
| 280 | case TRANSITION: |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 281 | case NONEXISTENT: |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 282 | UNREACHABLE(); |
| 283 | break; |
| 284 | } |
| 285 | } |
| 286 | } else { |
| 287 | property_dictionary()->Print(out); |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | |
| 292 | void JSObject::PrintElements(FILE* out) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 293 | // Don't call GetElementsKind, its validation code can cause the printer to |
| 294 | // fail when debugging. |
| 295 | switch (map()->elements_kind()) { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 296 | case FAST_HOLEY_SMI_ELEMENTS: |
| 297 | case FAST_SMI_ELEMENTS: |
| 298 | case FAST_HOLEY_ELEMENTS: |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 299 | case FAST_ELEMENTS: { |
| 300 | // Print in array notation for non-sparse arrays. |
| 301 | FixedArray* p = FixedArray::cast(elements()); |
| 302 | for (int i = 0; i < p->length(); i++) { |
| 303 | PrintF(out, " %d: ", i); |
| 304 | p->get(i)->ShortPrint(out); |
| 305 | PrintF(out, "\n"); |
| 306 | } |
| 307 | break; |
| 308 | } |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 309 | case FAST_HOLEY_DOUBLE_ELEMENTS: |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 310 | case FAST_DOUBLE_ELEMENTS: { |
| 311 | // Print in array notation for non-sparse arrays. |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 312 | if (elements()->length() > 0) { |
| 313 | FixedDoubleArray* p = FixedDoubleArray::cast(elements()); |
| 314 | for (int i = 0; i < p->length(); i++) { |
| 315 | if (p->is_the_hole(i)) { |
| 316 | PrintF(out, " %d: <the hole>", i); |
| 317 | } else { |
| 318 | PrintF(out, " %d: %g", i, p->get_scalar(i)); |
| 319 | } |
| 320 | PrintF(out, "\n"); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 321 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 322 | } |
| 323 | break; |
| 324 | } |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 325 | case EXTERNAL_PIXEL_ELEMENTS: { |
| 326 | ExternalPixelArray* p = ExternalPixelArray::cast(elements()); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 327 | for (int i = 0; i < p->length(); i++) { |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 328 | PrintF(out, " %d: %d\n", i, p->get_scalar(i)); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 329 | } |
| 330 | break; |
| 331 | } |
| 332 | case EXTERNAL_BYTE_ELEMENTS: { |
| 333 | ExternalByteArray* p = ExternalByteArray::cast(elements()); |
| 334 | for (int i = 0; i < p->length(); i++) { |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 335 | PrintF(out, " %d: %d\n", i, static_cast<int>(p->get_scalar(i))); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 336 | } |
| 337 | break; |
| 338 | } |
| 339 | case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: { |
| 340 | ExternalUnsignedByteArray* p = |
| 341 | ExternalUnsignedByteArray::cast(elements()); |
| 342 | for (int i = 0; i < p->length(); i++) { |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 343 | PrintF(out, " %d: %d\n", i, static_cast<int>(p->get_scalar(i))); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 344 | } |
| 345 | break; |
| 346 | } |
| 347 | case EXTERNAL_SHORT_ELEMENTS: { |
| 348 | ExternalShortArray* p = ExternalShortArray::cast(elements()); |
| 349 | for (int i = 0; i < p->length(); i++) { |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 350 | PrintF(out, " %d: %d\n", i, static_cast<int>(p->get_scalar(i))); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 351 | } |
| 352 | break; |
| 353 | } |
| 354 | case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: { |
| 355 | ExternalUnsignedShortArray* p = |
| 356 | ExternalUnsignedShortArray::cast(elements()); |
| 357 | for (int i = 0; i < p->length(); i++) { |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 358 | PrintF(out, " %d: %d\n", i, static_cast<int>(p->get_scalar(i))); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 359 | } |
| 360 | break; |
| 361 | } |
| 362 | case EXTERNAL_INT_ELEMENTS: { |
| 363 | ExternalIntArray* p = ExternalIntArray::cast(elements()); |
| 364 | for (int i = 0; i < p->length(); i++) { |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 365 | PrintF(out, " %d: %d\n", i, static_cast<int>(p->get_scalar(i))); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 366 | } |
| 367 | break; |
| 368 | } |
| 369 | case EXTERNAL_UNSIGNED_INT_ELEMENTS: { |
| 370 | ExternalUnsignedIntArray* p = |
| 371 | ExternalUnsignedIntArray::cast(elements()); |
| 372 | for (int i = 0; i < p->length(); i++) { |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 373 | PrintF(out, " %d: %d\n", i, static_cast<int>(p->get_scalar(i))); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 374 | } |
| 375 | break; |
| 376 | } |
| 377 | case EXTERNAL_FLOAT_ELEMENTS: { |
| 378 | ExternalFloatArray* p = ExternalFloatArray::cast(elements()); |
| 379 | for (int i = 0; i < p->length(); i++) { |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 380 | PrintF(out, " %d: %f\n", i, p->get_scalar(i)); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 381 | } |
| 382 | break; |
| 383 | } |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 384 | case EXTERNAL_DOUBLE_ELEMENTS: { |
| 385 | ExternalDoubleArray* p = ExternalDoubleArray::cast(elements()); |
| 386 | for (int i = 0; i < p->length(); i++) { |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 387 | PrintF(out, " %d: %f\n", i, p->get_scalar(i)); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 388 | } |
| 389 | break; |
| 390 | } |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 391 | case DICTIONARY_ELEMENTS: |
| 392 | elements()->Print(out); |
| 393 | break; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 394 | case NON_STRICT_ARGUMENTS_ELEMENTS: { |
| 395 | FixedArray* p = FixedArray::cast(elements()); |
| 396 | for (int i = 2; i < p->length(); i++) { |
| 397 | PrintF(out, " %d: ", i); |
| 398 | p->get(i)->ShortPrint(out); |
| 399 | PrintF(out, "\n"); |
| 400 | } |
| 401 | break; |
| 402 | } |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 403 | } |
| 404 | } |
| 405 | |
| 406 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 407 | void JSObject::PrintTransitions(FILE* out) { |
| 408 | if (!map()->HasTransitionArray()) return; |
| 409 | TransitionArray* transitions = map()->transitions(); |
| 410 | for (int i = 0; i < transitions->number_of_transitions(); i++) { |
| 411 | PrintF(out, " "); |
| 412 | transitions->GetKey(i)->StringPrint(out); |
| 413 | PrintF(out, ": "); |
| 414 | switch (transitions->GetTargetDetails(i).type()) { |
| 415 | case FIELD: { |
| 416 | PrintF(out, " (transition to field)\n"); |
| 417 | break; |
| 418 | } |
| 419 | case CONSTANT_FUNCTION: |
| 420 | PrintF(out, " (transition to constant function)\n"); |
| 421 | break; |
| 422 | case CALLBACKS: |
| 423 | PrintF(out, " (transition to callback)\n"); |
| 424 | break; |
| 425 | // Values below are never in the target descriptor array. |
| 426 | case NORMAL: |
| 427 | case HANDLER: |
| 428 | case INTERCEPTOR: |
| 429 | case TRANSITION: |
| 430 | case NONEXISTENT: |
| 431 | UNREACHABLE(); |
| 432 | break; |
| 433 | } |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 438 | void JSObject::JSObjectPrint(FILE* out) { |
| 439 | PrintF(out, "%p: [JSObject]\n", reinterpret_cast<void*>(this)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 440 | PrintF(out, " - map = %p [", reinterpret_cast<void*>(map())); |
| 441 | // Don't call GetElementsKind, its validation code can cause the printer to |
| 442 | // fail when debugging. |
| 443 | PrintElementsKind(out, this->map()->elements_kind()); |
| 444 | PrintF(out, |
| 445 | "]\n - prototype = %p\n", |
| 446 | reinterpret_cast<void*>(GetPrototype())); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 447 | PrintF(out, " {\n"); |
| 448 | PrintProperties(out); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 449 | PrintTransitions(out); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 450 | PrintElements(out); |
| 451 | PrintF(out, " }\n"); |
| 452 | } |
| 453 | |
| 454 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 455 | void JSModule::JSModulePrint(FILE* out) { |
| 456 | HeapObject::PrintHeader(out, "JSModule"); |
| 457 | PrintF(out, " - map = 0x%p\n", reinterpret_cast<void*>(map())); |
| 458 | PrintF(out, " - context = "); |
| 459 | context()->Print(out); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 460 | PrintF(out, " - scope_info = "); |
| 461 | scope_info()->ShortPrint(out); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 462 | PrintElementsKind(out, this->map()->elements_kind()); |
| 463 | PrintF(out, " {\n"); |
| 464 | PrintProperties(out); |
| 465 | PrintElements(out); |
| 466 | PrintF(out, " }\n"); |
| 467 | } |
| 468 | |
| 469 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 470 | static const char* TypeToString(InstanceType type) { |
| 471 | switch (type) { |
| 472 | case INVALID_TYPE: return "INVALID"; |
| 473 | case MAP_TYPE: return "MAP"; |
| 474 | case HEAP_NUMBER_TYPE: return "HEAP_NUMBER"; |
| 475 | case SYMBOL_TYPE: return "SYMBOL"; |
| 476 | case ASCII_SYMBOL_TYPE: return "ASCII_SYMBOL"; |
| 477 | case CONS_SYMBOL_TYPE: return "CONS_SYMBOL"; |
| 478 | case CONS_ASCII_SYMBOL_TYPE: return "CONS_ASCII_SYMBOL"; |
| 479 | case EXTERNAL_ASCII_SYMBOL_TYPE: |
| 480 | case EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE: |
| 481 | case EXTERNAL_SYMBOL_TYPE: return "EXTERNAL_SYMBOL"; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 482 | case SHORT_EXTERNAL_ASCII_SYMBOL_TYPE: |
| 483 | case SHORT_EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE: |
| 484 | case SHORT_EXTERNAL_SYMBOL_TYPE: return "SHORT_EXTERNAL_SYMBOL"; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 485 | case ASCII_STRING_TYPE: return "ASCII_STRING"; |
| 486 | case STRING_TYPE: return "TWO_BYTE_STRING"; |
| 487 | case CONS_STRING_TYPE: |
| 488 | case CONS_ASCII_STRING_TYPE: return "CONS_STRING"; |
| 489 | case EXTERNAL_ASCII_STRING_TYPE: |
| 490 | case EXTERNAL_STRING_WITH_ASCII_DATA_TYPE: |
| 491 | case EXTERNAL_STRING_TYPE: return "EXTERNAL_STRING"; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 492 | case SHORT_EXTERNAL_ASCII_STRING_TYPE: |
| 493 | case SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE: |
| 494 | case SHORT_EXTERNAL_STRING_TYPE: return "SHORT_EXTERNAL_STRING"; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 495 | case FIXED_ARRAY_TYPE: return "FIXED_ARRAY"; |
| 496 | case BYTE_ARRAY_TYPE: return "BYTE_ARRAY"; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 497 | case FREE_SPACE_TYPE: return "FREE_SPACE"; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 498 | case EXTERNAL_PIXEL_ARRAY_TYPE: return "EXTERNAL_PIXEL_ARRAY"; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 499 | case EXTERNAL_BYTE_ARRAY_TYPE: return "EXTERNAL_BYTE_ARRAY"; |
| 500 | case EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE: |
| 501 | return "EXTERNAL_UNSIGNED_BYTE_ARRAY"; |
| 502 | case EXTERNAL_SHORT_ARRAY_TYPE: return "EXTERNAL_SHORT_ARRAY"; |
| 503 | case EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE: |
| 504 | return "EXTERNAL_UNSIGNED_SHORT_ARRAY"; |
| 505 | case EXTERNAL_INT_ARRAY_TYPE: return "EXTERNAL_INT_ARRAY"; |
| 506 | case EXTERNAL_UNSIGNED_INT_ARRAY_TYPE: |
| 507 | return "EXTERNAL_UNSIGNED_INT_ARRAY"; |
| 508 | case EXTERNAL_FLOAT_ARRAY_TYPE: return "EXTERNAL_FLOAT_ARRAY"; |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 509 | case EXTERNAL_DOUBLE_ARRAY_TYPE: return "EXTERNAL_DOUBLE_ARRAY"; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 510 | case FILLER_TYPE: return "FILLER"; |
| 511 | case JS_OBJECT_TYPE: return "JS_OBJECT"; |
| 512 | case JS_CONTEXT_EXTENSION_OBJECT_TYPE: return "JS_CONTEXT_EXTENSION_OBJECT"; |
| 513 | case ODDBALL_TYPE: return "ODDBALL"; |
| 514 | case JS_GLOBAL_PROPERTY_CELL_TYPE: return "JS_GLOBAL_PROPERTY_CELL"; |
| 515 | case SHARED_FUNCTION_INFO_TYPE: return "SHARED_FUNCTION_INFO"; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 516 | case JS_MODULE_TYPE: return "JS_MODULE"; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 517 | case JS_FUNCTION_TYPE: return "JS_FUNCTION"; |
| 518 | case CODE_TYPE: return "CODE"; |
| 519 | case JS_ARRAY_TYPE: return "JS_ARRAY"; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 520 | case JS_PROXY_TYPE: return "JS_PROXY"; |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 521 | case JS_WEAK_MAP_TYPE: return "JS_WEAK_MAP"; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 522 | case JS_REGEXP_TYPE: return "JS_REGEXP"; |
| 523 | case JS_VALUE_TYPE: return "JS_VALUE"; |
| 524 | case JS_GLOBAL_OBJECT_TYPE: return "JS_GLOBAL_OBJECT"; |
| 525 | case JS_BUILTINS_OBJECT_TYPE: return "JS_BUILTINS_OBJECT"; |
| 526 | case JS_GLOBAL_PROXY_TYPE: return "JS_GLOBAL_PROXY"; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 527 | case FOREIGN_TYPE: return "FOREIGN"; |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 528 | case JS_MESSAGE_OBJECT_TYPE: return "JS_MESSAGE_OBJECT_TYPE"; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 529 | #define MAKE_STRUCT_CASE(NAME, Name, name) case NAME##_TYPE: return #NAME; |
| 530 | STRUCT_LIST(MAKE_STRUCT_CASE) |
| 531 | #undef MAKE_STRUCT_CASE |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 532 | default: return "UNKNOWN"; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 533 | } |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | |
| 537 | void Map::MapPrint(FILE* out) { |
| 538 | HeapObject::PrintHeader(out, "Map"); |
| 539 | PrintF(out, " - type: %s\n", TypeToString(instance_type())); |
| 540 | PrintF(out, " - instance size: %d\n", instance_size()); |
| 541 | PrintF(out, " - inobject properties: %d\n", inobject_properties()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 542 | PrintF(out, " - elements kind: "); |
| 543 | PrintElementsKind(out, elements_kind()); |
| 544 | PrintF(out, "\n - pre-allocated property fields: %d\n", |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 545 | pre_allocated_property_fields()); |
| 546 | PrintF(out, " - unused property fields: %d\n", unused_property_fields()); |
| 547 | if (is_hidden_prototype()) { |
| 548 | PrintF(out, " - hidden_prototype\n"); |
| 549 | } |
| 550 | if (has_named_interceptor()) { |
| 551 | PrintF(out, " - named_interceptor\n"); |
| 552 | } |
| 553 | if (has_indexed_interceptor()) { |
| 554 | PrintF(out, " - indexed_interceptor\n"); |
| 555 | } |
| 556 | if (is_undetectable()) { |
| 557 | PrintF(out, " - undetectable\n"); |
| 558 | } |
| 559 | if (has_instance_call_handler()) { |
| 560 | PrintF(out, " - instance_call_handler\n"); |
| 561 | } |
| 562 | if (is_access_check_needed()) { |
| 563 | PrintF(out, " - access_check_needed\n"); |
| 564 | } |
| 565 | PrintF(out, " - instance descriptors: "); |
| 566 | instance_descriptors()->ShortPrint(out); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 567 | if (HasTransitionArray()) { |
| 568 | PrintF(out, "\n - transitions: "); |
| 569 | transitions()->ShortPrint(out); |
| 570 | } |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 571 | PrintF(out, "\n - prototype: "); |
| 572 | prototype()->ShortPrint(out); |
| 573 | PrintF(out, "\n - constructor: "); |
| 574 | constructor()->ShortPrint(out); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 575 | PrintF(out, "\n - code cache: "); |
| 576 | code_cache()->ShortPrint(out); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 577 | PrintF(out, "\n"); |
| 578 | } |
| 579 | |
| 580 | |
| 581 | void CodeCache::CodeCachePrint(FILE* out) { |
| 582 | HeapObject::PrintHeader(out, "CodeCache"); |
| 583 | PrintF(out, "\n - default_cache: "); |
| 584 | default_cache()->ShortPrint(out); |
| 585 | PrintF(out, "\n - normal_type_cache: "); |
| 586 | normal_type_cache()->ShortPrint(out); |
| 587 | } |
| 588 | |
| 589 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 590 | void PolymorphicCodeCache::PolymorphicCodeCachePrint(FILE* out) { |
| 591 | HeapObject::PrintHeader(out, "PolymorphicCodeCache"); |
| 592 | PrintF(out, "\n - cache: "); |
| 593 | cache()->ShortPrint(out); |
| 594 | } |
| 595 | |
| 596 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 597 | void TypeFeedbackInfo::TypeFeedbackInfoPrint(FILE* out) { |
| 598 | HeapObject::PrintHeader(out, "TypeFeedbackInfo"); |
ulan@chromium.org | ea52b5f | 2012-07-30 13:05:33 +0000 | [diff] [blame] | 599 | PrintF(out, " - ic_total_count: %d, ic_with_type_info_count: %d\n", |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 600 | ic_total_count(), ic_with_type_info_count()); |
ulan@chromium.org | ea52b5f | 2012-07-30 13:05:33 +0000 | [diff] [blame] | 601 | PrintF(out, " - type_feedback_cells: "); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 602 | type_feedback_cells()->FixedArrayPrint(out); |
| 603 | } |
| 604 | |
| 605 | |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 606 | void AliasedArgumentsEntry::AliasedArgumentsEntryPrint(FILE* out) { |
| 607 | HeapObject::PrintHeader(out, "AliasedArgumentsEntry"); |
| 608 | PrintF(out, "\n - aliased_context_slot: %d", aliased_context_slot()); |
| 609 | } |
| 610 | |
| 611 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 612 | void FixedArray::FixedArrayPrint(FILE* out) { |
| 613 | HeapObject::PrintHeader(out, "FixedArray"); |
| 614 | PrintF(out, " - length: %d", length()); |
| 615 | for (int i = 0; i < length(); i++) { |
| 616 | PrintF(out, "\n [%d]: ", i); |
| 617 | get(i)->ShortPrint(out); |
| 618 | } |
| 619 | PrintF(out, "\n"); |
| 620 | } |
| 621 | |
| 622 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 623 | void FixedDoubleArray::FixedDoubleArrayPrint(FILE* out) { |
| 624 | HeapObject::PrintHeader(out, "FixedDoubleArray"); |
| 625 | PrintF(out, " - length: %d", length()); |
| 626 | for (int i = 0; i < length(); i++) { |
jkummerow@chromium.org | 1145ef8 | 2012-02-02 16:21:15 +0000 | [diff] [blame] | 627 | if (is_the_hole(i)) { |
| 628 | PrintF(out, "\n [%d]: <the hole>", i); |
| 629 | } else { |
| 630 | PrintF(out, "\n [%d]: %g", i, get_scalar(i)); |
| 631 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 632 | } |
| 633 | PrintF(out, "\n"); |
| 634 | } |
| 635 | |
| 636 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 637 | void JSValue::JSValuePrint(FILE* out) { |
| 638 | HeapObject::PrintHeader(out, "ValueObject"); |
| 639 | value()->Print(out); |
| 640 | } |
| 641 | |
| 642 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 643 | void JSMessageObject::JSMessageObjectPrint(FILE* out) { |
| 644 | HeapObject::PrintHeader(out, "JSMessageObject"); |
| 645 | PrintF(out, " - type: "); |
| 646 | type()->ShortPrint(out); |
| 647 | PrintF(out, "\n - arguments: "); |
| 648 | arguments()->ShortPrint(out); |
| 649 | PrintF(out, "\n - start_position: %d", start_position()); |
| 650 | PrintF(out, "\n - end_position: %d", end_position()); |
| 651 | PrintF(out, "\n - script: "); |
| 652 | script()->ShortPrint(out); |
| 653 | PrintF(out, "\n - stack_trace: "); |
| 654 | stack_trace()->ShortPrint(out); |
| 655 | PrintF(out, "\n - stack_frames: "); |
| 656 | stack_frames()->ShortPrint(out); |
| 657 | PrintF(out, "\n"); |
| 658 | } |
| 659 | |
| 660 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 661 | void String::StringPrint(FILE* out) { |
| 662 | if (StringShape(this).IsSymbol()) { |
| 663 | PrintF(out, "#"); |
| 664 | } else if (StringShape(this).IsCons()) { |
| 665 | PrintF(out, "c\""); |
| 666 | } else { |
| 667 | PrintF(out, "\""); |
| 668 | } |
| 669 | |
| 670 | const char truncated_epilogue[] = "...<truncated>"; |
| 671 | int len = length(); |
| 672 | if (!FLAG_use_verbose_printer) { |
| 673 | if (len > 100) { |
| 674 | len = 100 - sizeof(truncated_epilogue); |
| 675 | } |
| 676 | } |
| 677 | for (int i = 0; i < len; i++) { |
| 678 | PrintF(out, "%c", Get(i)); |
| 679 | } |
| 680 | if (len != length()) { |
| 681 | PrintF(out, "%s", truncated_epilogue); |
| 682 | } |
| 683 | |
| 684 | if (!StringShape(this).IsSymbol()) PrintF(out, "\""); |
| 685 | } |
| 686 | |
| 687 | |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 688 | // This method is only meant to be called from gdb for debugging purposes. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 689 | // Since the string can also be in two-byte encoding, non-ASCII characters |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 690 | // will be ignored in the output. |
| 691 | char* String::ToAsciiArray() { |
| 692 | // Static so that subsequent calls frees previously allocated space. |
| 693 | // This also means that previous results will be overwritten. |
| 694 | static char* buffer = NULL; |
| 695 | if (buffer != NULL) free(buffer); |
| 696 | buffer = new char[length()+1]; |
| 697 | WriteToFlat(this, buffer, 0, length()); |
| 698 | buffer[length()] = 0; |
| 699 | return buffer; |
| 700 | } |
| 701 | |
| 702 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 703 | static const char* const weekdays[] = { |
| 704 | "???", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" |
| 705 | }; |
| 706 | |
| 707 | void JSDate::JSDatePrint(FILE* out) { |
| 708 | HeapObject::PrintHeader(out, "JSDate"); |
| 709 | PrintF(out, " - map = 0x%p\n", reinterpret_cast<void*>(map())); |
| 710 | PrintF(out, " - value = "); |
| 711 | value()->Print(out); |
| 712 | if (!year()->IsSmi()) { |
| 713 | PrintF(out, " - time = NaN\n"); |
| 714 | } else { |
| 715 | PrintF(out, " - time = %s %04d/%02d/%02d %02d:%02d:%02d\n", |
| 716 | weekdays[weekday()->IsSmi() ? Smi::cast(weekday())->value() + 1 : 0], |
| 717 | year()->IsSmi() ? Smi::cast(year())->value() : -1, |
| 718 | month()->IsSmi() ? Smi::cast(month())->value() : -1, |
| 719 | day()->IsSmi() ? Smi::cast(day())->value() : -1, |
| 720 | hour()->IsSmi() ? Smi::cast(hour())->value() : -1, |
| 721 | min()->IsSmi() ? Smi::cast(min())->value() : -1, |
| 722 | sec()->IsSmi() ? Smi::cast(sec())->value() : -1); |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 727 | void JSProxy::JSProxyPrint(FILE* out) { |
| 728 | HeapObject::PrintHeader(out, "JSProxy"); |
| 729 | PrintF(out, " - map = 0x%p\n", reinterpret_cast<void*>(map())); |
| 730 | PrintF(out, " - handler = "); |
| 731 | handler()->Print(out); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 732 | PrintF(out, " - hash = "); |
| 733 | hash()->Print(out); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 734 | PrintF(out, "\n"); |
| 735 | } |
| 736 | |
| 737 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 738 | void JSFunctionProxy::JSFunctionProxyPrint(FILE* out) { |
| 739 | HeapObject::PrintHeader(out, "JSFunctionProxy"); |
| 740 | PrintF(out, " - map = 0x%p\n", reinterpret_cast<void*>(map())); |
| 741 | PrintF(out, " - handler = "); |
| 742 | handler()->Print(out); |
| 743 | PrintF(out, " - call_trap = "); |
| 744 | call_trap()->Print(out); |
| 745 | PrintF(out, " - construct_trap = "); |
| 746 | construct_trap()->Print(out); |
| 747 | PrintF(out, "\n"); |
| 748 | } |
| 749 | |
| 750 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 751 | void JSWeakMap::JSWeakMapPrint(FILE* out) { |
| 752 | HeapObject::PrintHeader(out, "JSWeakMap"); |
| 753 | PrintF(out, " - map = 0x%p\n", reinterpret_cast<void*>(map())); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 754 | PrintF(out, " - table = "); |
| 755 | table()->ShortPrint(out); |
| 756 | PrintF(out, "\n"); |
| 757 | } |
| 758 | |
| 759 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 760 | void JSFunction::JSFunctionPrint(FILE* out) { |
| 761 | HeapObject::PrintHeader(out, "Function"); |
| 762 | PrintF(out, " - map = 0x%p\n", reinterpret_cast<void*>(map())); |
| 763 | PrintF(out, " - initial_map = "); |
| 764 | if (has_initial_map()) { |
| 765 | initial_map()->ShortPrint(out); |
| 766 | } |
| 767 | PrintF(out, "\n - shared_info = "); |
| 768 | shared()->ShortPrint(out); |
| 769 | PrintF(out, "\n - name = "); |
| 770 | shared()->name()->Print(out); |
| 771 | PrintF(out, "\n - context = "); |
| 772 | unchecked_context()->ShortPrint(out); |
yangguo@chromium.org | 9c741c8 | 2012-06-28 15:04:22 +0000 | [diff] [blame] | 773 | PrintF(out, "\n - literals = "); |
| 774 | literals()->ShortPrint(out); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 775 | PrintF(out, "\n - code = "); |
| 776 | code()->ShortPrint(out); |
| 777 | PrintF(out, "\n"); |
| 778 | |
| 779 | PrintProperties(out); |
| 780 | PrintElements(out); |
| 781 | |
| 782 | PrintF(out, "\n"); |
| 783 | } |
| 784 | |
| 785 | |
| 786 | void SharedFunctionInfo::SharedFunctionInfoPrint(FILE* out) { |
| 787 | HeapObject::PrintHeader(out, "SharedFunctionInfo"); |
| 788 | PrintF(out, " - name: "); |
| 789 | name()->ShortPrint(out); |
| 790 | PrintF(out, "\n - expected_nof_properties: %d", expected_nof_properties()); |
| 791 | PrintF(out, "\n - instance class name = "); |
| 792 | instance_class_name()->Print(out); |
| 793 | PrintF(out, "\n - code = "); |
| 794 | code()->ShortPrint(out); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 795 | if (HasSourceCode()) { |
| 796 | PrintF(out, "\n - source code = "); |
ulan@chromium.org | ea52b5f | 2012-07-30 13:05:33 +0000 | [diff] [blame] | 797 | String* source = String::cast(Script::cast(script())->source()); |
| 798 | int start = start_position(); |
| 799 | int length = end_position() - start; |
| 800 | SmartArrayPointer<char> source_string = |
| 801 | source->ToCString(DISALLOW_NULLS, |
| 802 | FAST_STRING_TRAVERSAL, |
| 803 | start, length, NULL); |
| 804 | PrintF(out, "%s", *source_string); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 805 | } |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 806 | // Script files are often large, hard to read. |
| 807 | // PrintF(out, "\n - script ="); |
| 808 | // script()->Print(out); |
| 809 | PrintF(out, "\n - function token position = %d", function_token_position()); |
| 810 | PrintF(out, "\n - start position = %d", start_position()); |
| 811 | PrintF(out, "\n - end position = %d", end_position()); |
| 812 | PrintF(out, "\n - is expression = %d", is_expression()); |
| 813 | PrintF(out, "\n - debug info = "); |
| 814 | debug_info()->ShortPrint(out); |
| 815 | PrintF(out, "\n - length = %d", length()); |
| 816 | PrintF(out, "\n - has_only_simple_this_property_assignments = %d", |
| 817 | has_only_simple_this_property_assignments()); |
| 818 | PrintF(out, "\n - this_property_assignments = "); |
| 819 | this_property_assignments()->ShortPrint(out); |
| 820 | PrintF(out, "\n"); |
| 821 | } |
| 822 | |
| 823 | |
| 824 | void JSGlobalProxy::JSGlobalProxyPrint(FILE* out) { |
ulan@chromium.org | ea52b5f | 2012-07-30 13:05:33 +0000 | [diff] [blame] | 825 | PrintF(out, "global_proxy "); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 826 | JSObjectPrint(out); |
danno@chromium.org | eb83146 | 2012-08-24 11:57:08 +0000 | [diff] [blame^] | 827 | PrintF(out, "context : "); |
| 828 | context()->ShortPrint(out); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 829 | PrintF(out, "\n"); |
| 830 | } |
| 831 | |
| 832 | |
| 833 | void JSGlobalObject::JSGlobalObjectPrint(FILE* out) { |
| 834 | PrintF(out, "global "); |
| 835 | JSObjectPrint(out); |
danno@chromium.org | eb83146 | 2012-08-24 11:57:08 +0000 | [diff] [blame^] | 836 | PrintF(out, "global context : "); |
| 837 | global_context()->ShortPrint(out); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 838 | PrintF(out, "\n"); |
| 839 | } |
| 840 | |
| 841 | |
| 842 | void JSBuiltinsObject::JSBuiltinsObjectPrint(FILE* out) { |
| 843 | PrintF(out, "builtins "); |
| 844 | JSObjectPrint(out); |
| 845 | } |
| 846 | |
| 847 | |
| 848 | void JSGlobalPropertyCell::JSGlobalPropertyCellPrint(FILE* out) { |
| 849 | HeapObject::PrintHeader(out, "JSGlobalPropertyCell"); |
| 850 | } |
| 851 | |
| 852 | |
| 853 | void Code::CodePrint(FILE* out) { |
| 854 | HeapObject::PrintHeader(out, "Code"); |
| 855 | #ifdef ENABLE_DISASSEMBLER |
| 856 | if (FLAG_use_verbose_printer) { |
| 857 | Disassemble(NULL, out); |
| 858 | } |
| 859 | #endif |
| 860 | } |
| 861 | |
| 862 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 863 | void Foreign::ForeignPrint(FILE* out) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 864 | PrintF(out, "foreign address : %p", foreign_address()); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | |
| 868 | void AccessorInfo::AccessorInfoPrint(FILE* out) { |
| 869 | HeapObject::PrintHeader(out, "AccessorInfo"); |
| 870 | PrintF(out, "\n - getter: "); |
| 871 | getter()->ShortPrint(out); |
| 872 | PrintF(out, "\n - setter: "); |
| 873 | setter()->ShortPrint(out); |
| 874 | PrintF(out, "\n - name: "); |
| 875 | name()->ShortPrint(out); |
| 876 | PrintF(out, "\n - data: "); |
| 877 | data()->ShortPrint(out); |
| 878 | PrintF(out, "\n - flag: "); |
| 879 | flag()->ShortPrint(out); |
| 880 | } |
| 881 | |
| 882 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 883 | void AccessorPair::AccessorPairPrint(FILE* out) { |
| 884 | HeapObject::PrintHeader(out, "AccessorPair"); |
| 885 | PrintF(out, "\n - getter: "); |
| 886 | getter()->ShortPrint(out); |
| 887 | PrintF(out, "\n - setter: "); |
| 888 | setter()->ShortPrint(out); |
| 889 | } |
| 890 | |
| 891 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 892 | void AccessCheckInfo::AccessCheckInfoPrint(FILE* out) { |
| 893 | HeapObject::PrintHeader(out, "AccessCheckInfo"); |
| 894 | PrintF(out, "\n - named_callback: "); |
| 895 | named_callback()->ShortPrint(out); |
| 896 | PrintF(out, "\n - indexed_callback: "); |
| 897 | indexed_callback()->ShortPrint(out); |
| 898 | PrintF(out, "\n - data: "); |
| 899 | data()->ShortPrint(out); |
| 900 | } |
| 901 | |
| 902 | |
| 903 | void InterceptorInfo::InterceptorInfoPrint(FILE* out) { |
| 904 | HeapObject::PrintHeader(out, "InterceptorInfo"); |
| 905 | PrintF(out, "\n - getter: "); |
| 906 | getter()->ShortPrint(out); |
| 907 | PrintF(out, "\n - setter: "); |
| 908 | setter()->ShortPrint(out); |
| 909 | PrintF(out, "\n - query: "); |
| 910 | query()->ShortPrint(out); |
| 911 | PrintF(out, "\n - deleter: "); |
| 912 | deleter()->ShortPrint(out); |
| 913 | PrintF(out, "\n - enumerator: "); |
| 914 | enumerator()->ShortPrint(out); |
| 915 | PrintF(out, "\n - data: "); |
| 916 | data()->ShortPrint(out); |
| 917 | } |
| 918 | |
| 919 | |
| 920 | void CallHandlerInfo::CallHandlerInfoPrint(FILE* out) { |
| 921 | HeapObject::PrintHeader(out, "CallHandlerInfo"); |
| 922 | PrintF(out, "\n - callback: "); |
| 923 | callback()->ShortPrint(out); |
| 924 | PrintF(out, "\n - data: "); |
| 925 | data()->ShortPrint(out); |
| 926 | PrintF(out, "\n - call_stub_cache: "); |
| 927 | } |
| 928 | |
| 929 | |
| 930 | void FunctionTemplateInfo::FunctionTemplateInfoPrint(FILE* out) { |
| 931 | HeapObject::PrintHeader(out, "FunctionTemplateInfo"); |
| 932 | PrintF(out, "\n - class name: "); |
| 933 | class_name()->ShortPrint(out); |
| 934 | PrintF(out, "\n - tag: "); |
| 935 | tag()->ShortPrint(out); |
| 936 | PrintF(out, "\n - property_list: "); |
| 937 | property_list()->ShortPrint(out); |
| 938 | PrintF(out, "\n - serial_number: "); |
| 939 | serial_number()->ShortPrint(out); |
| 940 | PrintF(out, "\n - call_code: "); |
| 941 | call_code()->ShortPrint(out); |
| 942 | PrintF(out, "\n - property_accessors: "); |
| 943 | property_accessors()->ShortPrint(out); |
| 944 | PrintF(out, "\n - prototype_template: "); |
| 945 | prototype_template()->ShortPrint(out); |
| 946 | PrintF(out, "\n - parent_template: "); |
| 947 | parent_template()->ShortPrint(out); |
| 948 | PrintF(out, "\n - named_property_handler: "); |
| 949 | named_property_handler()->ShortPrint(out); |
| 950 | PrintF(out, "\n - indexed_property_handler: "); |
| 951 | indexed_property_handler()->ShortPrint(out); |
| 952 | PrintF(out, "\n - instance_template: "); |
| 953 | instance_template()->ShortPrint(out); |
| 954 | PrintF(out, "\n - signature: "); |
| 955 | signature()->ShortPrint(out); |
| 956 | PrintF(out, "\n - access_check_info: "); |
| 957 | access_check_info()->ShortPrint(out); |
| 958 | PrintF(out, "\n - hidden_prototype: %s", |
| 959 | hidden_prototype() ? "true" : "false"); |
| 960 | PrintF(out, "\n - undetectable: %s", undetectable() ? "true" : "false"); |
| 961 | PrintF(out, "\n - need_access_check: %s", |
| 962 | needs_access_check() ? "true" : "false"); |
| 963 | } |
| 964 | |
| 965 | |
| 966 | void ObjectTemplateInfo::ObjectTemplateInfoPrint(FILE* out) { |
| 967 | HeapObject::PrintHeader(out, "ObjectTemplateInfo"); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 968 | PrintF(out, " - tag: "); |
| 969 | tag()->ShortPrint(out); |
| 970 | PrintF(out, "\n - property_list: "); |
| 971 | property_list()->ShortPrint(out); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 972 | PrintF(out, "\n - constructor: "); |
| 973 | constructor()->ShortPrint(out); |
| 974 | PrintF(out, "\n - internal_field_count: "); |
| 975 | internal_field_count()->ShortPrint(out); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 976 | PrintF(out, "\n"); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | |
| 980 | void SignatureInfo::SignatureInfoPrint(FILE* out) { |
| 981 | HeapObject::PrintHeader(out, "SignatureInfo"); |
| 982 | PrintF(out, "\n - receiver: "); |
| 983 | receiver()->ShortPrint(out); |
| 984 | PrintF(out, "\n - args: "); |
| 985 | args()->ShortPrint(out); |
| 986 | } |
| 987 | |
| 988 | |
| 989 | void TypeSwitchInfo::TypeSwitchInfoPrint(FILE* out) { |
| 990 | HeapObject::PrintHeader(out, "TypeSwitchInfo"); |
| 991 | PrintF(out, "\n - types: "); |
| 992 | types()->ShortPrint(out); |
| 993 | } |
| 994 | |
| 995 | |
| 996 | void Script::ScriptPrint(FILE* out) { |
| 997 | HeapObject::PrintHeader(out, "Script"); |
| 998 | PrintF(out, "\n - source: "); |
| 999 | source()->ShortPrint(out); |
| 1000 | PrintF(out, "\n - name: "); |
| 1001 | name()->ShortPrint(out); |
| 1002 | PrintF(out, "\n - line_offset: "); |
| 1003 | line_offset()->ShortPrint(out); |
| 1004 | PrintF(out, "\n - column_offset: "); |
| 1005 | column_offset()->ShortPrint(out); |
| 1006 | PrintF(out, "\n - type: "); |
| 1007 | type()->ShortPrint(out); |
| 1008 | PrintF(out, "\n - id: "); |
| 1009 | id()->ShortPrint(out); |
| 1010 | PrintF(out, "\n - data: "); |
| 1011 | data()->ShortPrint(out); |
| 1012 | PrintF(out, "\n - context data: "); |
| 1013 | context_data()->ShortPrint(out); |
| 1014 | PrintF(out, "\n - wrapper: "); |
| 1015 | wrapper()->ShortPrint(out); |
| 1016 | PrintF(out, "\n - compilation type: "); |
| 1017 | compilation_type()->ShortPrint(out); |
| 1018 | PrintF(out, "\n - line ends: "); |
| 1019 | line_ends()->ShortPrint(out); |
| 1020 | PrintF(out, "\n - eval from shared: "); |
| 1021 | eval_from_shared()->ShortPrint(out); |
| 1022 | PrintF(out, "\n - eval from instructions offset: "); |
| 1023 | eval_from_instructions_offset()->ShortPrint(out); |
| 1024 | PrintF(out, "\n"); |
| 1025 | } |
| 1026 | |
| 1027 | |
| 1028 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1029 | void DebugInfo::DebugInfoPrint(FILE* out) { |
| 1030 | HeapObject::PrintHeader(out, "DebugInfo"); |
| 1031 | PrintF(out, "\n - shared: "); |
| 1032 | shared()->ShortPrint(out); |
| 1033 | PrintF(out, "\n - original_code: "); |
| 1034 | original_code()->ShortPrint(out); |
| 1035 | PrintF(out, "\n - code: "); |
| 1036 | code()->ShortPrint(out); |
| 1037 | PrintF(out, "\n - break_points: "); |
| 1038 | break_points()->Print(out); |
| 1039 | } |
| 1040 | |
| 1041 | |
| 1042 | void BreakPointInfo::BreakPointInfoPrint(FILE* out) { |
| 1043 | HeapObject::PrintHeader(out, "BreakPointInfo"); |
| 1044 | PrintF(out, "\n - code_position: %d", code_position()->value()); |
| 1045 | PrintF(out, "\n - source_position: %d", source_position()->value()); |
| 1046 | PrintF(out, "\n - statement_position: %d", statement_position()->value()); |
| 1047 | PrintF(out, "\n - break_point_objects: "); |
| 1048 | break_point_objects()->ShortPrint(out); |
| 1049 | } |
| 1050 | #endif // ENABLE_DEBUGGER_SUPPORT |
| 1051 | |
| 1052 | |
| 1053 | void DescriptorArray::PrintDescriptors(FILE* out) { |
| 1054 | PrintF(out, "Descriptor array %d\n", number_of_descriptors()); |
| 1055 | for (int i = 0; i < number_of_descriptors(); i++) { |
| 1056 | PrintF(out, " %d: ", i); |
| 1057 | Descriptor desc; |
| 1058 | Get(i, &desc); |
| 1059 | desc.Print(out); |
| 1060 | } |
| 1061 | PrintF(out, "\n"); |
| 1062 | } |
| 1063 | |
| 1064 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 1065 | void TransitionArray::PrintTransitions(FILE* out) { |
| 1066 | PrintF(out, "Transition array %d\n", number_of_transitions()); |
| 1067 | for (int i = 0; i < number_of_transitions(); i++) { |
| 1068 | PrintF(out, " %d: ", i); |
| 1069 | GetKey(i)->StringPrint(out); |
| 1070 | PrintF(out, ": "); |
| 1071 | switch (GetTargetDetails(i).type()) { |
| 1072 | case FIELD: { |
| 1073 | PrintF(out, " (transition to field)\n"); |
| 1074 | break; |
| 1075 | } |
| 1076 | case CONSTANT_FUNCTION: |
| 1077 | PrintF(out, " (transition to constant function)\n"); |
| 1078 | break; |
| 1079 | case CALLBACKS: |
| 1080 | PrintF(out, " (transition to callback)\n"); |
| 1081 | break; |
| 1082 | // Values below are never in the target descriptor array. |
| 1083 | case NORMAL: |
| 1084 | case HANDLER: |
| 1085 | case INTERCEPTOR: |
| 1086 | case TRANSITION: |
| 1087 | case NONEXISTENT: |
| 1088 | UNREACHABLE(); |
| 1089 | break; |
| 1090 | } |
| 1091 | } |
| 1092 | PrintF(out, "\n"); |
| 1093 | } |
| 1094 | |
| 1095 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 1096 | #endif // OBJECT_PRINT |
| 1097 | |
| 1098 | |
| 1099 | } } // namespace v8::internal |