1 /*
2 * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
3 * Description: add debug utils.
4 * Create: 2020/11/20
5 */
6
7 #include <stdio.h>
8
9 #include "debug-utils.h"
10 #include "ecma-conversion.h"
11 #include "ecma-globals.h"
12 #include "ecma-helpers.h"
13 #include "vm.h"
14
PrintObjectValueProperties(ecma_value_t value)15 void PrintObjectValueProperties(ecma_value_t value)
16 {
17 if (!ecma_is_value_object(value)) {
18 return;
19 }
20 ecma_object_t* object = ecma_get_object_from_value(value);
21 PrintObjectProperties(object);
22 }
23
PrintObjectProperties(ecma_object_t * object)24 void PrintObjectProperties(ecma_object_t* object)
25 {
26 jmem_cpointer_t prop_iter_cp = object->u1.property_list_cp;
27
28 while (prop_iter_cp != JMEM_CP_NULL) {
29 ecma_property_header_t *prop_iter_p = ECMA_GET_NON_NULL_POINTER (ecma_property_header_t, prop_iter_cp);
30 JERRY_ASSERT (ECMA_PROPERTY_IS_PROPERTY_PAIR (prop_iter_p));
31
32 ecma_property_pair_t *prop_pair_p = (ecma_property_pair_t *) prop_iter_p;
33
34 for (int i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++) {
35 if (ECMA_PROPERTY_IS_NAMED_PROPERTY (prop_iter_p->types[i])) {
36 if (ECMA_PROPERTY_GET_NAME_TYPE (prop_iter_p->types[i]) == ECMA_DIRECT_STRING_MAGIC
37 && prop_pair_p->names_cp[i] >= LIT_NON_INTERNAL_MAGIC_STRING__COUNT) {
38 printf("Skipped direct string with big lit property\n");
39 continue;
40 }
41
42 ecma_string_t *prop_name = ecma_string_from_property_name (prop_iter_p->types[i],
43 prop_pair_p->names_cp[i]);
44 ecma_property_value_t prop_value_p = prop_pair_p->values[i];
45
46 ecma_string_t *string_value;
47 if (ecma_is_value_object(prop_value_p.value)) {
48 // Expand it more?
49 string_value = ecma_op_to_string (prop_value_p.value);
50 } else {
51 string_value = ecma_op_to_string (prop_value_p.value);
52 }
53 // handle value_value is error value?
54 JERRY_ASSERT (string_value != NULL);
55
56 ecma_string_t* separator_str = ecma_new_ecma_string_from_utf8((const lit_utf8_byte_t *)" :> ", 4);
57 prop_name = ecma_concat_ecma_strings(prop_name, separator_str);
58 prop_name = ecma_concat_ecma_strings(prop_name, string_value);
59
60 ECMA_STRING_TO_UTF8_STRING(prop_name, buf, buf_size);
61 printf("PROPERTY PAIR : ");
62 for (int ii = 0; ii < (int)buf_size; ++ii) {
63 printf("%c", buf[ii]);
64 }
65 printf("\n");
66
67 ecma_deref_ecma_string(prop_name);
68 ecma_deref_ecma_string(string_value);
69 ecma_deref_ecma_string(separator_str);
70 }
71 }
72 prop_iter_cp = prop_iter_p->next_property_cp;
73 }
74 }
75
PrintString(ecma_string_t * str)76 void PrintString(ecma_string_t* str)
77 {
78 ECMA_STRING_TO_UTF8_STRING(str, buf, buf_size);
79 printf("String: ");
80 for (int i = 0; i < (int)buf_size; ++i) {
81 printf("%c", buf[i]);
82 }
83 printf("\n");
84 }
85