/** * Parse string literal (ECMA-262 v5, 7.8.4) */ static token parse_string (void) { ecma_char_t c = (ecma_char_t) LA (0); JERRY_ASSERT (c == '\'' || c == '"'); consume_char (); new_token (); const bool is_double_quoted = (c == '"'); const char end_char = (is_double_quoted ? '"' : '\''); do { c = (ecma_char_t) LA (0); consume_char (); if (c == '\0') { PARSE_ERROR ("Unclosed string", token_start - buffer_start); } else if (ecma_char_is_line_terminator (c)) { PARSE_ERROR ("String literal shall not contain newline character", token_start - buffer_start); } else if (c == '\\') { ecma_char_t nc = (ecma_char_t) LA (0); if (convert_single_escape_character (nc, NULL)) { consume_char (); } else if (ecma_char_is_line_terminator (nc)) { consume_char (); if (ecma_char_is_carriage_return (nc)) { nc = (ecma_char_t) LA (0); if (ecma_char_is_new_line (nc)) { consume_char (); } } } } } while (c != end_char); token ret = convert_string_to_token_transform_escape_seq (TOK_STRING, token_start, (size_t) (buffer - token_start) - 1u); token_start = NULL; return ret; } /* parse_string */
static void kernel_syscall_entry_process(struct ltt_module *mod, struct parse_result *res, int pass) { unsigned int ip, id; kernel_common(res, pass); if (sscanf(res->values, " ip = 0x%x, syscall_id = %u", &ip, &id) != 2) { PARSE_ERROR(mod, res->values); return; } if (pass == 1) { atag_store(ip); } if (pass == 2) { struct ltt_trace *current_process; current_process = find_task_trace(res->pid); emit_trace(current_process, (union ltt_value)PROCESS_KERNEL); current_process->value = (union ltt_value)PROCESS_KERNEL; if (id < sizeof(syscall_name)/sizeof(syscall_name[0])) emit_trace(¤t_process[1], (union ltt_value)syscall_name[id]); else emit_trace(¤t_process[1], (union ltt_value)"syscall %d", id); emit_trace(&syscall_id, (union ltt_value)id); emit_trace(&syscall_pc, (union ltt_value)ip); } }
static void fs_exec_process(struct ltt_module *mod, struct parse_result *res, int pass) { char *s; if (sscanf(res->values, " filename = \"%m[^\"]\"", &s) != 1) { PARSE_ERROR(mod, res->values); return; } free(s); /* if (pass == 1) { find_or_add_task_trace(s, res->pid, pass); } if ((pass == 2) && (current_process)) { if (current_process) { emit_trace(current_process,(union ltt_value)LT_IDLE); } current_process = find_or_add_task_trace(s, res->pid, pass); emit_trace(current_process, (union ltt_value)LT_S0); } */ }
Parser::ObjType Parser::ParseObjType(char *msg) { switch( *msg ) { case 'g': case 'G': return ParseGoal(msg); case 'f': case 'F': return ParseMarker(msg); case 'l': return ParseLine(msg); case 'p': case 'P': return ParsePlayer(msg); case 'b': case 'B': return ParseBall(msg); default: PARSE_ERROR("unknown object"); break; } ObjType result; result.type = OBJ_None; return result; }
/** * Initialize lexer to start parsing of a new source */ void lexer_init (const jerry_api_char_t *source, /**< script source */ size_t source_size, /**< script source size in bytes */ bool is_print_source_code) /**< flag indicating whether to dump * processed source code */ { empty_token.type = TOK_EMPTY; empty_token.uid = 0; empty_token.loc = LIT_ITERATOR_POS_ZERO; saved_token = prev_token = sent_token = prev_non_lf_token = empty_token; if (!lit_is_utf8_string_valid (source, (lit_utf8_size_t) source_size)) { PARSE_ERROR (JSP_EARLY_ERROR_SYNTAX, "Invalid source encoding", LIT_ITERATOR_POS_ZERO); } src_iter = lit_utf8_iterator_create (source, (lit_utf8_size_t) source_size); buffer_size = source_size; buffer_start = source; is_token_parse_in_progress = false; lexer_set_strict_mode (false); #ifndef JERRY_NDEBUG allow_dump_lines = is_print_source_code; #else /* JERRY_NDEBUG */ (void) is_print_source_code; allow_dump_lines = false; #endif /* JERRY_NDEBUG */ } /* lexer_init */
static void kernel_softirq_entry_process(struct ltt_module *mod, struct parse_result *res, int pass) { int id; char *s; kernel_common(res, pass); if (sscanf(res->values, " softirq_id = %d [%m[^]]", &id, &s) != 2) { PARSE_ERROR(mod, res->values); return; } if (pass == 2) { emit_trace(&sirq[0], (union ltt_value)SOFTIRQ_RUNNING); emit_cpu_idle_state(res, (union ltt_value)IDLE_CPU_PREEMPT); if (id < sizeof(sofirq_tag)/sizeof(char *) && sofirq_tag[id]) emit_trace(&sirq[1], (union ltt_value)sofirq_tag[id]); else emit_trace(&sirq[1], (union ltt_value)"softirq %d", id); emit_trace(&sirq[2], (union ltt_value)s); softirqstate = SOFTIRQS_RUN; /* stat stuff */ strncpy(softirqtask, s, sizeof(softirqtask)); softirqtask[sizeof(softirqtask)-1] = 0; softirqtime = res->clock; /* end stat stuff */ } free(s); }
void jsp_early_error_check_delete (bool is_strict, locus loc __attr_unused___) { if (is_strict) { PARSE_ERROR (JSP_EARLY_ERROR_SYNTAX, "'delete' operator shall not apply on identifier in strict mode.", loc); } }
void syntax_check_delete (bool is_strict, locus loc __attr_unused___) { if (is_strict) { PARSE_ERROR ("'delete' operator shall not apply on identifier in strict mode.", loc); } }
Parser::ObjType Parser::ParseLine(char *msg) { ObjType result; result.type = OBJ_Line; msg += 2; // 'l' if ( *msg == 'r' ) { result.line = SL_Right; } else if ( *msg == 'l' ) { result.line = SL_Left; } else if ( *msg == 't' ) { result.line = SL_Top; } else if ( *msg == 'b' ) { result.line = SL_Bottom; } else { PARSE_ERROR("line ?"); } return result; }
/** * Parse a comment * * @return true if newline was met during parsing * false - otherwise */ static bool lexer_parse_comment (void) { ecma_char_t c = LA (0); bool multiline; bool was_newlines = false; JERRY_ASSERT (LA (0) == LIT_CHAR_SLASH); JERRY_ASSERT (LA (1) == LIT_CHAR_SLASH || LA (1) == LIT_CHAR_ASTERISK); multiline = (LA (1) == LIT_CHAR_ASTERISK); consume_char (); consume_char (); while (!lit_utf8_iterator_is_eos (&src_iter)) { c = LA (0); if (!multiline) { if (lit_char_is_line_terminator (c)) { return true; } } else { if (c == LIT_CHAR_ASTERISK && LA (1) == LIT_CHAR_SLASH) { consume_char (); consume_char (); return was_newlines; } else if (lit_char_is_line_terminator (c)) { was_newlines = true; } } consume_char (); } if (multiline) { PARSE_ERROR (JSP_EARLY_ERROR_SYNTAX, "Unclosed multiline comment", lit_utf8_iterator_get_pos (&src_iter)); } return false; } /* lexer_parse_comment */
static void kernel_process_fork_process(struct ltt_module *mod, struct parse_result *res, int pass) { int ppid, pid, tgid; kernel_common(res, pass); if (sscanf(res->values, " parent_pid = %d, child_pid = %d, child_tgid = %d", &ppid, &pid, &tgid) != 3) { PARSE_ERROR(mod, res->values); return; } if (pass == 1) { find_or_add_task_trace(res->pname, pid, tgid); } }
void FilterParser::CaptureParameterValueTokens( token_list::const_iterator& i, token_list::const_iterator& j ) { if ( i->token == '{' ) { for ( token_list::const_iterator k = ++i; k < j; ++k ) { if ( k->token == '}' ) { j = k; return; } if ( k->token == '{' ) PARSE_ERROR( "Unexpected left bracket", k ); } PARSE_ERROR( "Missing right bracket", i ); } if ( i->token == '}' ) PARSE_ERROR( "Unexpected right bracket", i ); j = i; ++j; }
void jsp_early_error_emit_error_on_eval_and_arguments (literal_t lit, /**< literal to check */ locus loc) /**< location of the literal in source code */ { if (lit_literal_equal_type_utf8 (lit, lit_get_magic_string_utf8 (LIT_MAGIC_STRING_ARGUMENTS), lit_get_magic_string_size (LIT_MAGIC_STRING_ARGUMENTS)) || lit_literal_equal_type_utf8 (lit, lit_get_magic_string_utf8 (LIT_MAGIC_STRING_EVAL), lit_get_magic_string_size (LIT_MAGIC_STRING_EVAL))) { PARSE_ERROR (JSP_EARLY_ERROR_SYNTAX, "'eval' and 'arguments' are not allowed here in strict mode", loc); } }
static void kernel_sched_wakeup_new_task_process(struct ltt_module *mod, struct parse_result *res, int pass) { unsigned int pid, cpu_id, state; kernel_common(res, pass); if (sscanf(res->values, " pid = %u, state = %u, cpu_id = %u", &pid, &state, &cpu_id) != 3) { PARSE_ERROR(mod, res->values); return; } if (pass == 2) { emit_trace(&sched_event, (union ltt_value)"new task %d", pid); } }
static void emit_error_on_eval_and_arguments (jsp_operand_t op, locus loc __attr_unused___) { if (op.is_literal_operand ()) { if (lit_literal_equal_type_utf8 (lit_get_literal_by_cp (op.get_literal ()), lit_get_magic_string_utf8 (LIT_MAGIC_STRING_ARGUMENTS), lit_get_magic_string_size (LIT_MAGIC_STRING_ARGUMENTS)) || lit_literal_equal_type_utf8 (lit_get_literal_by_cp (op.get_literal ()), lit_get_magic_string_utf8 (LIT_MAGIC_STRING_EVAL), lit_get_magic_string_size (LIT_MAGIC_STRING_EVAL))) { PARSE_ERROR (JSP_EARLY_ERROR_SYNTAX, "'eval' and 'arguments' are not allowed here in strict mode", loc); } } }
Parser::ObjType Parser::ParseGoal(char *msg) { ObjType result; if ( *msg == 'g' ) { // goal result.type = OBJ_Marker; msg += 2; // 'g ' if ( *msg == 'r' ) { result.marker = Goal_R; } else if ( *msg == 'l' ) { result.marker = Goal_L; } else { PARSE_ERROR("goal ?"); } } else if ( *msg =='G' ){ // goal behind result.type = OBJ_Marker_Behind; //result.marker = _pMem->ClosestGoal(); TODO: how to process? } return result; }
static void kernel_thread_setname_process(struct ltt_module *mod, struct parse_result *res, int pass) { int id; char *s; kernel_common(res, pass); if (sscanf(res->values, " pid = %d , name = \"%m[^\"]\"", &id, &s) != 2) { PARSE_ERROR(mod, res->values); return; } if (pass == 1) { find_or_add_task_trace(s, id, 0); } free(s); }
static void emit_error_on_eval_and_arguments (operand op, locus loc __attr_unused___) { if (op.type == OPERAND_LITERAL) { if (lit_literal_equal_type_utf8 (lit_get_literal_by_cp (op.data.lit_id), lit_get_magic_string_utf8 (LIT_MAGIC_STRING_ARGUMENTS), lit_get_magic_string_size (LIT_MAGIC_STRING_ARGUMENTS)) || lit_literal_equal_type_utf8 (lit_get_literal_by_cp (op.data.lit_id), lit_get_magic_string_utf8 (LIT_MAGIC_STRING_EVAL), lit_get_magic_string_size (LIT_MAGIC_STRING_EVAL))) { PARSE_ERROR ("'eval' and 'arguments' are not allowed here in strict mode", loc); } } }
static void kernel_send_signal_process(struct ltt_module *mod, struct parse_result *res, int pass) { unsigned int pid, signal; kernel_common(res, pass); if (sscanf(res->values, " pid = %u, signal = %u", &pid, &signal) != 2) { PARSE_ERROR(mod, res->values); return; } if (pass == 2) { emit_trace(&sched_event, (union ltt_value)"%d send signal %d to pid %d", res->pid, signal, pid); } }
static bool replace_comment_by_newline (void) { ecma_char_t c = LA (0); bool multiline; bool was_newlines = false; JERRY_ASSERT (LA (0) == '/'); JERRY_ASSERT (LA (1) == '/' || LA (1) == '*'); multiline = (LA (1) == '*'); consume_char (); consume_char (); while (true) { c = LA (0); if (!multiline && (c == '\n' || c == '\0')) { return false; } if (multiline && c == '*' && LA (1) == '/') { consume_char (); consume_char (); if (was_newlines) { return true; } else { return false; } } if (multiline && c == '\n') { was_newlines = true; } if (multiline && c == '\0') { PARSE_ERROR ("Unclosed multiline comment", buffer - buffer_start); } consume_char (); } }
/** * Construct next token from current source code position and increment the position * * @return the constructed token */ token lexer_next_token (bool maybe_regexp, /**< read '/' as regexp? */ bool is_strict) /**< strict mode is on (true) / off (false) */ { lit_utf8_iterator_pos_t src_pos = lit_utf8_iterator_get_pos (&src_iter); if (src_pos.offset == 0 && !src_pos.is_non_bmp_middle) { dump_current_line (); } if (!is_empty (saved_token)) { sent_token = saved_token; saved_token = empty_token; } else { /** * FIXME: * The way to raise syntax errors for unexpected EOF * should be reworked so that EOF would be checked by * caller of the routine, and the following condition * would be checked as assertion in the routine. */ if (lexer_get_token_type (prev_token) == TOK_EOF && lexer_get_token_type (sent_token) == TOK_EOF) { PARSE_ERROR (JSP_EARLY_ERROR_SYNTAX, "Unexpected EOF", lit_utf8_iterator_get_pos (&src_iter)); } prev_token = sent_token; jsp_token_flag_t flags = JSP_TOKEN_FLAG__NO_FLAGS; bool is_preceded_by_new_lines; sent_token = lexer_parse_token (maybe_regexp, &is_preceded_by_new_lines, is_strict); if (is_preceded_by_new_lines) { flags = (jsp_token_flag_t) (flags | JSP_TOKEN_FLAG_PRECEDED_BY_NEWLINES); } sent_token.flags = flags; } return sent_token; } /* lexer_next_token */
static void kernel_process_free_process(struct ltt_module *mod, struct parse_result *res, int pass) { int pid; kernel_common(res, pass); if (sscanf(res->values, " pid = %d", &pid) != 1) { PARSE_ERROR(mod, res->values); return; } if (pass == 2) { struct ltt_trace *current_process; current_process = find_task_trace(pid); emit_trace(current_process, (union ltt_value)PROCESS_DEAD); } }
token lexer_next_token (void) { lit_utf8_iterator_pos_t src_pos = lit_utf8_iterator_get_pos (&src_iter); if (src_pos.offset == 0 && !src_pos.is_non_bmp_middle) { dump_current_line (); } if (!is_empty (saved_token)) { sent_token = saved_token; saved_token = empty_token; goto end; } /** * FIXME: * The way to raise syntax errors for unexpected EOF * should be reworked so that EOF would be checked by * caller of the routine, and the following condition * would be checked as assertion in the routine. */ if (prev_token.type == TOK_EOF && sent_token.type == TOK_EOF) { PARSE_ERROR (JSP_EARLY_ERROR_SYNTAX, "Unexpected EOF", lit_utf8_iterator_get_pos (&src_iter)); } prev_token = sent_token; sent_token = lexer_parse_token (); if (sent_token.type == TOK_NEWLINE) { dump_current_line (); } else { prev_non_lf_token = sent_token; } end: return sent_token; }
static void kernel_timer_update_time_process(struct ltt_module *mod, struct parse_result *res, int pass) { unsigned int c_jiffies; unsigned long long c_jiffies64; kernel_common(res, pass); if (sscanf(res->values, " jiffies = %llu", &c_jiffies64) != 1) { PARSE_ERROR(mod, res->values); return; } c_jiffies = c_jiffies64 & 0xffffffff; if (pass == 2) { static unsigned int old_jiffies; static double jiffies_clock; static double jiffies_diff; if (old_jiffies && old_jiffies+1 != c_jiffies) TDIAG(res, "missing jiffies jump from %x to %x (broken trace ?)\n", old_jiffies, c_jiffies); if (jiffies_clock > 0) { double diff = res->clock - jiffies_clock; if (jiffies_diff > 0) { /* we allow a jitter of 0,1 ms */ if (diff > jiffies_diff + 0.0001 || diff < jiffies_diff - 0.0001) { TDIAG(res, "unstable jiffies for %x took %fs (instead of %fs)\n", old_jiffies, diff, jiffies_diff); } } else { jiffies_diff = diff; TDIAG(res, "set jiffies times to %fs\n", jiffies_diff); } } jiffies_clock = res->clock; old_jiffies = c_jiffies; emit_trace(&jiffies, (union ltt_value)c_jiffies); } }
static void kernel_sched_try_wakeup_process(struct ltt_module *mod, struct parse_result *res, int pass) { unsigned int pid, cpu_id, state; kernel_common(res, pass); if (sscanf(res->values, " pid = %u, cpu_id = %u, state = %u", &pid, &cpu_id, &state) != 3) { PARSE_ERROR(mod, res->values); return; } if (pass == 2) { emit_trace(&sched_event, (union ltt_value)"%d try wakeup %d", res->pid, pid); if (res->pid != pid) { struct ltt_trace *next_process; next_process = find_task_trace(pid); emit_trace(next_process, (union ltt_value)PROCESS_WAKEUP); } } }
static void kernel_page_fault_exit_process(struct ltt_module *mod, struct parse_result *res, int pass) { int fault; if (pass == 1) { init_traces(); } if (sscanf(res->values, " res = %d", &fault) != 1) { PARSE_ERROR(mod, res->values); return; } if (pass == 2) { emit_trace(&trace_fault[0], (union ltt_value)LT_IDLE); emit_trace(&trace_fault[1], (union ltt_value)"-> %d", fault); } }
static void kernel_printk_process(struct ltt_module *mod, struct parse_result *res, int pass) { unsigned int ip; kernel_common(res, pass); if (sscanf(res->values, " ip = 0x%x", &ip) != 1) { PARSE_ERROR(mod, res->values); return; } if (pass == 1) { atag_store(ip); } if (pass == 2) { emit_trace(&printk_pc, (union ltt_value)ip); } }
static void kernel_page_fault_get_user_entry_process(struct ltt_module *mod, struct parse_result *res, int pass) { int wr; unsigned long long address; if (pass == 1) { init_traces(); } if (sscanf(res->values, " address = %llx, write_access = %d", &address, &wr) != 2) { PARSE_ERROR(mod, res->values); return; } if (pass == 2) { emit_trace(&trace_fault[2], (union ltt_value)(wr?LT_S2:LT_S0)); emit_trace(&trace_fault[3], (union ltt_value)"%c@0x%08x", (wr)? 'W' : 'R', (uint32_t)address); } }
static void kernel_softirq_raise_process(struct ltt_module *mod, struct parse_result *res, int pass) { int id; kernel_common(res, pass); if (sscanf(res->values, " softirq_id = %d", &id) != 1) { PARSE_ERROR(mod, res->values); return; } if (pass == 2) { if (softirqstate == SOFTIRQS_IDLE) emit_trace(&sirq[0], (union ltt_value)SOFTIRQ_RAISING); if (id < sizeof(sofirq_tag)/sizeof(char *) && sofirq_tag[id]) emit_trace(&sirq[1], (union ltt_value)"! %s", sofirq_tag[id]); else emit_trace(&sirq[1], (union ltt_value)"raise %d", id); softirqstate = SOFTIRQS_RAISE; } }
static void kernel_page_fault_entry_process(struct ltt_module *mod, struct parse_result *res, int pass) { int wr; unsigned long ip; unsigned long address; if (pass == 1) { init_traces(); } if (sscanf(res->values, " ip = %lx, address = %lx, trap_id = 14, write_access = %d", &ip, &address, &wr) != 3) { PARSE_ERROR(mod, res->values); return; } if (pass == 2) { emit_trace(&trace_fault[0], (union ltt_value)(wr?LT_S2:LT_S0)); emit_trace(&trace_fault[1], (union ltt_value)"0x%08x@%c0x%08x", ip, (wr)? 'W' : 'R', (uint32_t)address); } }