Add line info support. (#2286)

Add line info data to byte, which allows getting a backtrace info directly
from the engine. Snapshots are not supported.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2018-04-19 02:12:54 +02:00
committed by yichoi
parent 095b730f9d
commit 5e097dc354
24 changed files with 773 additions and 52 deletions
+4
View File
@@ -539,6 +539,10 @@
/* Basic opcodes. */ \
CBC_OPCODE (CBC_EXT_DEBUGGER, CBC_NO_FLAG, 0, \
VM_OC_NONE) \
CBC_OPCODE (CBC_EXT_RESOURCE_NAME, CBC_NO_FLAG, 0, \
VM_OC_RESOURCE_NAME) \
CBC_OPCODE (CBC_EXT_LINE, CBC_NO_FLAG, 0, \
VM_OC_LINE) \
\
/* Binary compound assignment opcodes with pushing the result. */ \
CBC_EXT_BINARY_LVALUE_OPERATION (CBC_EXT_ASSIGN_ADD, \
+11 -1
View File
@@ -308,8 +308,12 @@ typedef struct
/** extra data for each breakpoint */
parser_breakpoint_info_t breakpoint_info[JERRY_DEBUGGER_MAX_BUFFER_SIZE / sizeof (parser_breakpoint_info_t)];
uint16_t breakpoint_info_count; /**< current breakpoint index */
parser_line_counter_t last_breakpoint_line; /**< last line where breakpoint was inserted */
parser_line_counter_t last_breakpoint_line; /**< last line where breakpoint has been inserted */
#endif /* JERRY_DEBUGGER */
#ifdef JERRY_ENABLE_LINE_INFO
parser_line_counter_t last_line_info_line; /**< last line where line info has been inserted */
#endif /* JERRY_ENABLE_LINE_INFO */
} parser_context_t;
/**
@@ -485,6 +489,12 @@ void parser_send_breakpoints (parser_context_t *context_p, jerry_debugger_header
#endif /* JERRY_DEBUGGER */
#ifdef JERRY_ENABLE_LINE_INFO
void parser_emit_line_info (parser_context_t *context_p, uint32_t line, bool flush_cbc);
#endif /* JERRY_ENABLE_LINE_INFO */
/**
* @}
* @}
+52 -4
View File
@@ -17,9 +17,9 @@
#ifndef JERRY_DISABLE_JS_PARSER
#ifdef JERRY_DEBUGGER
#if defined (JERRY_DEBUGGER) || defined (JERRY_ENABLE_LINE_INFO)
#include "jcontext.h"
#endif /*JERRY_DEBUGGER */
#endif /* JERRY_DEBUGGER || JERRY_ENABLE_LINE_INFO */
/** \addtogroup parser Parser
* @{
@@ -314,9 +314,9 @@ parser_parse_var_statement (parser_context_t *context_p) /**< context */
JERRY_ASSERT (context_p->token.type == LEXER_LITERAL
&& context_p->token.lit_location.type == LEXER_IDENT_LITERAL);
#ifdef JERRY_DEBUGGER
#if defined (JERRY_DEBUGGER) || defined (JERRY_ENABLE_LINE_INFO)
parser_line_counter_t ident_line_counter = context_p->token.line;
#endif /* JERRY_DEBUGGER */
#endif /* JERRY_DEBUGGER || JERRY_ENABLE_LINE_INFO */
context_p->lit_object.literal_p->status_flags |= LEXER_FLAG_VAR;
@@ -347,6 +347,13 @@ parser_parse_var_statement (parser_context_t *context_p) /**< context */
}
#endif /* JERRY_DEBUGGER */
#ifdef JERRY_ENABLE_LINE_INFO
if (ident_line_counter != context_p->last_line_info_line)
{
parser_emit_line_info (context_p, ident_line_counter, false);
}
#endif /* JERRY_ENABLE_LINE_INFO */
parser_parse_expression (context_p,
PARSE_EXPR_STATEMENT | PARSE_EXPR_NO_COMMA | PARSE_EXPR_HAS_LITERAL);
}
@@ -1080,6 +1087,10 @@ parser_parse_switch_statement_start (parser_context_t *context_p) /**< context *
switch_case_was_found = false;
default_case_was_found = false;
#ifdef JERRY_ENABLE_LINE_INFO
uint32_t last_line_info_line = context_p->last_line_info_line;
#endif /* JERRY_ENABLE_LINE_INFO */
while (true)
{
parser_scan_until (context_p, &unused_range, LEXER_KEYW_CASE);
@@ -1134,6 +1145,13 @@ parser_parse_switch_statement_start (parser_context_t *context_p) /**< context *
lexer_next_token (context_p);
#ifdef JERRY_ENABLE_LINE_INFO
if (context_p->token.line != context_p->last_line_info_line)
{
parser_emit_line_info (context_p, context_p->token.line, true);
}
#endif /* JERRY_ENABLE_LINE_INFO */
parser_parse_expression (context_p, PARSE_EXPR);
if (context_p->token.type != LEXER_COLON)
@@ -1148,6 +1166,10 @@ parser_parse_switch_statement_start (parser_context_t *context_p) /**< context *
JERRY_ASSERT (switch_case_was_found || default_case_was_found);
#ifdef JERRY_ENABLE_LINE_INFO
context_p->last_line_info_line = last_line_info_line;
#endif /* JERRY_ENABLE_LINE_INFO */
if (!switch_case_was_found)
{
/* There was no case statement, so the expression result
@@ -1634,6 +1656,15 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
}
#endif /* JERRY_DEBUGGER */
#ifdef JERRY_ENABLE_LINE_INFO
if (JERRY_CONTEXT (resource_name) != ECMA_VALUE_UNDEFINED)
{
parser_emit_cbc_ext (context_p, CBC_EXT_RESOURCE_NAME);
parser_flush_cbc (context_p);
}
context_p->last_line_info_line = 0;
#endif /* JERRY_ENABLE_LINE_INFO */
while (context_p->token.type == LEXER_LITERAL
&& context_p->token.lit_location.type == LEXER_STRING_LITERAL)
{
@@ -1685,6 +1716,9 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
context_p->last_breakpoint_line = context_p->token.line;
}
#endif /* JERRY_DEBUGGER */
#ifdef JERRY_ENABLE_LINE_INFO
parser_emit_line_info (context_p, context_p->token.line, false);
#endif /* JERRY_ENABLE_LINE_INFO */
lexer_construct_literal_object (context_p, &lit_location, LEXER_STRING_LITERAL);
parser_emit_cbc_literal_from_token (context_p, CBC_PUSH_LITERAL);
@@ -1755,6 +1789,20 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
}
#endif /* JERRY_DEBUGGER */
#ifdef JERRY_ENABLE_LINE_INFO
if (context_p->token.line != context_p->last_line_info_line
&& context_p->token.type != LEXER_SEMICOLON
&& context_p->token.type != LEXER_LEFT_BRACE
&& context_p->token.type != LEXER_RIGHT_BRACE
&& context_p->token.type != LEXER_KEYW_VAR
&& context_p->token.type != LEXER_KEYW_FUNCTION
&& context_p->token.type != LEXER_KEYW_CASE
&& context_p->token.type != LEXER_KEYW_DEFAULT)
{
parser_emit_line_info (context_p, context_p->token.line, true);
}
#endif /* JERRY_ENABLE_LINE_INFO */
switch (context_p->token.type)
{
case LEXER_SEMICOLON:
+55
View File
@@ -17,6 +17,10 @@
#ifndef JERRY_DISABLE_JS_PARSER
#ifdef JERRY_ENABLE_LINE_INFO
#include "jcontext.h"
#endif /* JERRY_ENABLE_LINE_INFO */
/** \addtogroup parser Parser
* @{
*
@@ -352,6 +356,57 @@ parser_emit_cbc_push_number (parser_context_t *context_p, /**< context */
}
} /* parser_emit_cbc_push_number */
#ifdef JERRY_ENABLE_LINE_INFO
/**
* Append a line info data
*/
void
parser_emit_line_info (parser_context_t *context_p, /**< context */
uint32_t line, /**< current line */
bool flush_cbc) /**< flush last byte code */
{
if (JERRY_CONTEXT (resource_name) == ECMA_VALUE_UNDEFINED)
{
return;
}
if (flush_cbc && context_p->last_cbc_opcode != PARSER_CBC_UNAVAILABLE)
{
parser_flush_cbc (context_p);
}
#ifdef PARSER_DUMP_BYTE_CODE
if (context_p->is_show_opcodes)
{
JERRY_DEBUG_MSG (" [%3d] CBC_EXT_LINE %d\n", (int) context_p->stack_depth, line);
}
#endif /* PARSER_DUMP_BYTE_CODE */
parser_emit_two_bytes (context_p, CBC_EXT_OPCODE, CBC_EXT_LINE);
context_p->byte_code_size += 2;
context_p->last_line_info_line = line;
do
{
uint8_t byte = (uint8_t) (line & CBC_LOWER_SEVEN_BIT_MASK);
line >>= 7;
if (line > 0)
{
byte = (uint8_t) (byte | CBC_HIGHEST_BIT_MASK);
}
PARSER_APPEND_TO_BYTE_CODE (context_p, byte);
context_p->byte_code_size++;
}
while (line > 0);
} /* parser_emit_line_info */
#endif /* JERRY_ENABLE_LINE_INFO */
/**
* Append a byte code with a branch argument
*/
+76
View File
@@ -1292,6 +1292,24 @@ parse_print_final_cbc (ecma_compiled_code_t *compiled_code_p, /**< compiled code
flags = cbc_ext_flags[ext_opcode];
JERRY_DEBUG_MSG (" %3d : %s", (int) cbc_offset, cbc_ext_names[ext_opcode]);
byte_code_p += 2;
#ifdef JERRY_ENABLE_LINE_INFO
if (ext_opcode == CBC_EXT_LINE)
{
uint32_t value = 0;
uint8_t byte;
do
{
byte = *byte_code_p++;
value = (value << 7) | (byte & CBC_LOWER_SEVEN_BIT_MASK);
}
while (byte & CBC_HIGHEST_BIT_MASK);
JERRY_DEBUG_MSG (" %d\n", (int) value);
continue;
}
#endif /* JERRY_ENABLE_LINE_INFO */
}
if (flags & (CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2))
@@ -1488,6 +1506,23 @@ parser_post_processing (parser_context_t *context_p) /**< context */
flags = cbc_ext_flags[ext_opcode];
PARSER_NEXT_BYTE (page_p, offset);
length++;
#ifdef JERRY_ENABLE_LINE_INFO
if (ext_opcode == CBC_EXT_LINE)
{
uint8_t last_byte = 0;
do
{
last_byte = page_p->bytes[offset];
PARSER_NEXT_BYTE (page_p, offset);
length++;
}
while (last_byte & CBC_HIGHEST_BIT_MASK);
continue;
}
#endif /* JERRY_ENABLE_LINE_INFO */
}
while (flags & (CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2))
@@ -1639,6 +1674,13 @@ parser_post_processing (parser_context_t *context_p) /**< context */
total_size += context_p->argument_count * sizeof (ecma_value_t);
}
#ifdef JERRY_ENABLE_LINE_INFO
if (JERRY_CONTEXT (resource_name) != ECMA_VALUE_UNDEFINED)
{
total_size += sizeof (ecma_value_t);
}
#endif /* JERRY_ENABLE_LINE_INFO */
#ifdef JERRY_ENABLE_SNAPSHOT_SAVE
total_size_used = total_size;
#endif
@@ -1802,6 +1844,25 @@ parser_post_processing (parser_context_t *context_p) /**< context */
opcode_p++;
real_offset++;
PARSER_NEXT_BYTE_UPDATE (page_p, offset, real_offset);
#ifdef JERRY_ENABLE_LINE_INFO
if (ext_opcode == CBC_EXT_LINE)
{
uint8_t last_byte = 0;
do
{
last_byte = page_p->bytes[offset];
*dst_p++ = last_byte;
real_offset++;
PARSER_NEXT_BYTE_UPDATE (page_p, offset, real_offset);
}
while (last_byte & CBC_HIGHEST_BIT_MASK);
continue;
}
#endif /* JERRY_ENABLE_LINE_INFO */
}
if (flags & CBC_HAS_BRANCH_ARG)
@@ -1994,6 +2055,21 @@ parser_post_processing (parser_context_t *context_p) /**< context */
}
}
#ifdef JERRY_ENABLE_LINE_INFO
if (JERRY_CONTEXT (resource_name) != ECMA_VALUE_UNDEFINED)
{
ecma_value_t *resource_name_p = (ecma_value_t *) (((uint8_t *) compiled_code_p) + total_size);
if ((context_p->status_flags & PARSER_ARGUMENTS_NEEDED)
&& !(context_p->status_flags & PARSER_IS_STRICT))
{
resource_name_p -= context_p->argument_count;
}
resource_name_p[-1] = JERRY_CONTEXT (resource_name);
}
#endif /* JERRY_ENABLE_LINE_INFO */
if (context_p->status_flags & PARSER_NAMED_FUNCTION_EXP)
{
ECMA_SET_INTERNAL_VALUE_POINTER (literal_pool_p[const_literal_end],