-
Notifications
You must be signed in to change notification settings - Fork 688
List scope chain levels and their variables to the selected stack frame. #2557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
List scope chain levels and their variables to the selected stack frame. #2557
Conversation
a342847 to
ba01461
Compare
ba01461 to
aa64635
Compare
jerry-core/debugger/debugger.c
Outdated
| } | ||
| } | ||
|
|
||
| memcpy (message_type_p->string + buffer_pos++, &level_type, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need memcpy to copy 1 byte. To prepare classes ignore non-declarative and non-object-bound lex envs.
| const size_t max_byte_count = JERRY_DEBUGGER_SEND_MAX (uint8_t); | ||
| const size_t max_message_size = JERRY_DEBUGGER_SEND_SIZE (max_byte_count, uint8_t); | ||
|
|
||
| ECMA_STRING_TO_UTF8_STRING (value_str, str_buff, str_buff_size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a cesu8 string or some costly conversion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the name or value of the property. So, it is always returns with the cesu8 character array of a string.
jerry-core/debugger/debugger.c
Outdated
| { | ||
| if (!jerry_debugger_send (max_message_size)) | ||
| { | ||
| ECMA_FINALIZE_UTF8_STRING (str_buff, str_buff_size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have never seen such a macro used for early return. They should behave block like.
jerry-core/debugger/debugger.c
Outdated
| jerry_debugger_send_type (JERRY_DEBUGGER_SCOPE_VARIABLES_END); | ||
| return; | ||
| } | ||
| chain_index--; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore non this object or declarative lex envs as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not understand exactly what you mean. It will steps through the outer references of the current lexical environment until the chain_index argument reach zero. It is always touch a declarative or this object bound lexical environment. If not, it will returns with an empty message with JERRY_DEBUGGER_SCOPE_VARIABLES_END type (e.g.: the chain_index argument is invalid / bigger than the scope chain).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future classes will introduces a new scope type. This type should not be shared by the debugger client side, and when encountered it should be skipped. Therefore only the two currently supported types should be handled by this loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see, thanks. I've updated it.
tests/debugger/do_variables.expected
Outdated
| d | Number | 12 | ||
| addThree | Function | function(){/* ecmascript */} | ||
| f | Function | function(){/* ecmascript */} | ||
| addX | Function | function(){/* ecmascript */} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should send no values for functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, it makes sense. I've updated it accordingly.
tests/debugger/do_variables.expected
Outdated
| f | Function | function(){/* ecmascript */} | ||
| addX | Function | function(){/* ecmascript */} | ||
| z | undefined | undefined | ||
| c | undefined | undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about objects?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This really missed. I've added.
567553b to
e1ae997
Compare
jerry-core/debugger/debugger.c
Outdated
| else | ||
| { | ||
| level_type = JERRY_DEBUGGER_SCOPE_WITH; | ||
| next_func_is_local = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this value is set to true here? I might misunderstood its purpose.
jerry-core/debugger/debugger.c
Outdated
|
|
||
| if (ecma_get_lex_env_outer_reference (lex_env_p) == NULL) | ||
| { | ||
| level_type = JERRY_DEBUGGER_SCOPE_GLOBAL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A break could be added here, and change the loop to while(true)
jerry-core/debugger/debugger.c
Outdated
|
|
||
| if (ecma_is_value_undefined (value)) | ||
| { | ||
| ret_value = JERRY_DEBUGGER_VARIABLE_UNDEFINED; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be nitpicking, but I think VALUE is better than VARIABLE, since the value of a variable is undefined, rather than the variable, which would mean it does not exist.
jerry-core/debugger/debugger.c
Outdated
| *buffer_pos = 0; | ||
| } | ||
|
|
||
| if (copied_values == 3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds like a state for a switch. Furthermore the last case is handled specially, I would take it out from this loop and done separately, since it already has a copy loop.
jerry-core/debugger/debugger.c
Outdated
| { | ||
| lex_env_p = ecma_get_lex_env_outer_reference (lex_env_p); | ||
|
|
||
| if (lex_env_p == NULL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JERRY_UNLIKELY
|
|
||
| for (int i = 0; i < ECMA_PROPERTY_PAIR_ITEM_COUNT; i++) | ||
| { | ||
| if (ECMA_PROPERTY_IS_NAMED_PROPERTY (prop_iter_p->types[i])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure all names are printable. I think Promises has some internal properties with special magic string names. They should be ignored.
jerry-core/ecma/base/ecma-globals.h
Outdated
| /** | ||
| * Catch clause. | ||
| */ | ||
| #define ECMA_OBJECT_FLAG_CATCH_CLAUSE 0x20 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would call it local scope, since we might add let/const at some day and they would be marked this flag as well.
434fb3b to
3004684
Compare
|
@zherczeg : Thanks for the review, I've updated the patch based on your suggestions. |
jerry-core/vm/vm.c
Outdated
| } | ||
|
|
||
| ecma_object_t *catch_env_p = ecma_create_decl_lex_env (frame_ctx_p->lex_env_p); | ||
| catch_env_p->type_flags_refs = (uint16_t) (catch_env_p->type_flags_refs | ECMA_OBJECT_FLAG_NON_CLOSURE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two questions:
- Is this code debugger-specific? If so, it should be wrapped into
#ifdef JERRY_DEBUGGER/#endif /* JERRY_DEBUGGER */. - Isn't this equivalent to
catch_env_p->type_flags_refs |= (uint16_t) ECMA_OBJECT_FLAG_NON_CLOSURE;?
jerry-core/debugger/debugger.c
Outdated
| JERRY_ASSERT (ret_value != JERRY_DEBUGGER_VALUE_NONE); | ||
|
|
||
| return ret_value; | ||
| } /* ecma_get_typeof_scope_variable */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The names of the new static functions are somewhat inconsistent. Most are prefixed with jerry_debugger_ but this one here is ecma_get_typeof_scope_variable while the next one is simply copy_scope_variables_to_string_message without any obvious prefix. Is this intentional?
zherczeg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty good now.
jerry-core/debugger/debugger.c
Outdated
| { | ||
| if ((lex_env_p->type_flags_refs & ECMA_OBJECT_FLAG_NON_CLOSURE) != 0) | ||
| { | ||
| message_type_p->string[buffer_pos++] = JERRY_DEBUGGER_SCOPE_CATCH; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don\t call this catch.
3004684 to
409fb8f
Compare
jerry-core/debugger/debugger.c
Outdated
| * false - otherwise | ||
| */ | ||
| static bool | ||
| jerry_debugger_copy_variables_to_string_message (jerry_debugger_scope_variable_type_t variable_type, /**< type */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check-vera.sh is reporting a style issue here (extra space at the start of the line)
It supports to list the scope chain of the current execution context and see which variables are available. JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
409fb8f to
87a55a4
Compare
zherczeg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
akosthekiss
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
It supports to list the scope chain of the current execution context and see which variables are available.
Please note that this is not a complete list, virtual properties are not included. I plan to expand them in a follow-up patch.
An example run should look like this:
test.js