void message_data_race(struct messaging_state *state, unsigned int eip, unsigned int most_recent_syscall, bool confirmed) { struct output_message m; m.tag = DATA_RACE; m.content.dr.eip = eip; m.content.dr.most_recent_syscall = most_recent_syscall; m.content.dr.confirmed = confirmed; /* pretty print the data race addr to propagate to master program */ char *func; char *file; int line; bool res = symtable_lookup(eip, &func, &file, &line); if (!res || func == NULL) { scnprintf(m.content.dr.pretty_printed, MESSAGE_BUF_SIZE, "0x%.8x <unknown>", eip); } else if (file == NULL) { scnprintf(m.content.dr.pretty_printed, MESSAGE_BUF_SIZE, "0x%.8x in %s <source unknown>", eip, func); } else { scnprintf(m.content.dr.pretty_printed, MESSAGE_BUF_SIZE, "0x%.8x in %s (%s:%d)", eip, func, file, line); } if (res) { if (func != NULL) MM_FREE(func); if (file != NULL) MM_FREE(file); } send(state, &m); }
static int symtable_visit_stmt(struct symtable *st, stmt_ty s) { switch (s->kind) { case FunctionDef_kind: if (!symtable_add_def(st, s->v.FunctionDef.name, DEF_LOCAL)) return 0; if (s->v.FunctionDef.args->defaults) VISIT_SEQ(st, expr, s->v.FunctionDef.args->defaults); if (s->v.FunctionDef.decorator_list) VISIT_SEQ(st, expr, s->v.FunctionDef.decorator_list); if (!symtable_enter_block(st, s->v.FunctionDef.name, FunctionBlock, (void *)s, s->lineno)) return 0; VISIT_IN_BLOCK(st, arguments, s->v.FunctionDef.args, s); VISIT_SEQ_IN_BLOCK(st, stmt, s->v.FunctionDef.body, s); if (!symtable_exit_block(st, s)) return 0; break; case ClassDef_kind: { PyObject *tmp; if (!symtable_add_def(st, s->v.ClassDef.name, DEF_LOCAL)) return 0; VISIT_SEQ(st, expr, s->v.ClassDef.bases); if (s->v.ClassDef.decorator_list) VISIT_SEQ(st, expr, s->v.ClassDef.decorator_list); if (!symtable_enter_block(st, s->v.ClassDef.name, ClassBlock, (void *)s, s->lineno)) return 0; tmp = st->st_private; st->st_private = s->v.ClassDef.name; VISIT_SEQ_IN_BLOCK(st, stmt, s->v.ClassDef.body, s); st->st_private = tmp; if (!symtable_exit_block(st, s)) return 0; break; } case Return_kind: if (s->v.Return.value) { VISIT(st, expr, s->v.Return.value); st->st_cur->ste_returns_value = 1; if (st->st_cur->ste_generator) { PyErr_SetString(PyExc_SyntaxError, RETURN_VAL_IN_GENERATOR); PyErr_SyntaxLocation(st->st_filename, s->lineno); return 0; } } break; case Delete_kind: VISIT_SEQ(st, expr, s->v.Delete.targets); break; case Assign_kind: VISIT_SEQ(st, expr, s->v.Assign.targets); VISIT(st, expr, s->v.Assign.value); break; case AugAssign_kind: VISIT(st, expr, s->v.AugAssign.target); VISIT(st, expr, s->v.AugAssign.value); break; case Print_kind: if (s->v.Print.dest) VISIT(st, expr, s->v.Print.dest); VISIT_SEQ(st, expr, s->v.Print.values); break; case For_kind: VISIT(st, expr, s->v.For.target); VISIT(st, expr, s->v.For.iter); VISIT_SEQ(st, stmt, s->v.For.body); if (s->v.For.orelse) VISIT_SEQ(st, stmt, s->v.For.orelse); break; case While_kind: VISIT(st, expr, s->v.While.test); VISIT_SEQ(st, stmt, s->v.While.body); if (s->v.While.orelse) VISIT_SEQ(st, stmt, s->v.While.orelse); break; case If_kind: /* XXX if 0: and lookup_yield() hacks */ VISIT(st, expr, s->v.If.test); VISIT_SEQ(st, stmt, s->v.If.body); if (s->v.If.orelse) VISIT_SEQ(st, stmt, s->v.If.orelse); break; case Raise_kind: if (s->v.Raise.type) { VISIT(st, expr, s->v.Raise.type); if (s->v.Raise.inst) { VISIT(st, expr, s->v.Raise.inst); if (s->v.Raise.tback) VISIT(st, expr, s->v.Raise.tback); } } break; case TryExcept_kind: VISIT_SEQ(st, stmt, s->v.TryExcept.body); VISIT_SEQ(st, stmt, s->v.TryExcept.orelse); VISIT_SEQ(st, excepthandler, s->v.TryExcept.handlers); break; case TryFinally_kind: VISIT_SEQ(st, stmt, s->v.TryFinally.body); VISIT_SEQ(st, stmt, s->v.TryFinally.finalbody); break; case Assert_kind: VISIT(st, expr, s->v.Assert.test); if (s->v.Assert.msg) VISIT(st, expr, s->v.Assert.msg); break; case Import_kind: VISIT_SEQ(st, alias, s->v.Import.names); /* XXX Don't have the lineno available inside visit_alias */ if (st->st_cur->ste_unoptimized && !st->st_cur->ste_opt_lineno) st->st_cur->ste_opt_lineno = s->lineno; break; case ImportFrom_kind: VISIT_SEQ(st, alias, s->v.ImportFrom.names); /* XXX Don't have the lineno available inside visit_alias */ if (st->st_cur->ste_unoptimized && !st->st_cur->ste_opt_lineno) st->st_cur->ste_opt_lineno = s->lineno; break; case Exec_kind: VISIT(st, expr, s->v.Exec.body); if (!st->st_cur->ste_opt_lineno) st->st_cur->ste_opt_lineno = s->lineno; if (s->v.Exec.globals) { st->st_cur->ste_unoptimized |= OPT_EXEC; VISIT(st, expr, s->v.Exec.globals); if (s->v.Exec.locals) VISIT(st, expr, s->v.Exec.locals); } else { st->st_cur->ste_unoptimized |= OPT_BARE_EXEC; } break; case Global_kind: { int i; asdl_seq *seq = s->v.Global.names; for (i = 0; i < asdl_seq_LEN(seq); i++) { identifier name = (identifier)asdl_seq_GET(seq, i); char *c_name = PyString_AS_STRING(name); long cur = symtable_lookup(st, name); if (cur < 0) return 0; if (cur & (DEF_LOCAL | USE)) { char buf[256]; if (cur & DEF_LOCAL) PyOS_snprintf(buf, sizeof(buf), GLOBAL_AFTER_ASSIGN, c_name); else PyOS_snprintf(buf, sizeof(buf), GLOBAL_AFTER_USE, c_name); if (!symtable_warn(st, buf, s->lineno)) return 0; } if (!symtable_add_def(st, name, DEF_GLOBAL)) return 0; } break; } case Expr_kind: VISIT(st, expr, s->v.Expr.value); break; case Pass_kind: case Break_kind: case Continue_kind: /* nothing to do here */ break; case With_kind: VISIT(st, expr, s->v.With.context_expr); if (s->v.With.optional_vars) { VISIT(st, expr, s->v.With.optional_vars); } VISIT_SEQ(st, stmt, s->v.With.body); break; } return 1; }
int lexan(void) { char *s, *s_end; char ch, ch1; int i; while (1) { ch = line_next_char(); s = curr_lex.str; s_end = s + LEXEME_MAX_LEN; if (isspace(ch)) { /* skip spaces */ continue; } if (!ch) { /* line was read */ *s = '\0'; curr_lex.token = DONE; return 0; } if (isdigit(ch)) { /* start of number. Number can be: 0|[1-9][0-9]* - DEC_NUM 0[0-7]+ - OCT_NUM 0x[0-9a-fA-F]+ - HEX_NUM 0b[01]+ - BIN_NUM */ if (ch != '0') { /* DEC_NUM */ while (s < s_end && isdigit(ch)) { *s++ = ch; ch = line_next_char(); } if (s == s_end) { printf("too long decimal number. Max length is %d\n", LEXEME_MAX_LEN); return 1; } *s = '\0'; curr_lex.token = DEC_NUM; line_prev_char(); return 0; } ch1 = line_next_char(); switch (ch1) { case 'x' : /* HEX_NUM */ ch = line_next_char(); while (s < s_end && isxdigit(ch)) { *s++ = ch; ch = line_next_char(); } if (s == s_end) { printf("too long hexadecimal number. Max length is %d\n", LEXEME_MAX_LEN); return 1; } if (s == curr_lex.str) { /* end of line */ printf("wrong end of hexadecimal number\n"); return 1; } *s = '\0'; curr_lex.token = HEX_NUM; line_prev_char(); return 0; case 'b' : /* BIN_NUM */ ch = line_next_char(); while (s < s_end && (ch == '0' || ch == '1')) { *s++ = ch; ch = line_next_char(); } if (s == s_end) { printf("too long binary number. Max length is %d\n", LEXEME_MAX_LEN); return 1; } if (s == curr_lex.str) { /* end of line */ printf("wrong end of binary number\n"); return 1; } *s = '\0'; curr_lex.token = BIN_NUM; line_prev_char(); return 0; default : /* OCT_NUM */ *s++ = ch; ch = ch1; while (s < s_end && ch - '0' >= 0 && ch - '0' < 8) { *s++ = ch; ch = line_next_char(); } if (s == s_end) { printf("too long octal number. Max length is %d\n", LEXEME_MAX_LEN); return 1; } *s = '\0'; curr_lex.token = OCT_NUM; line_prev_char(); return 0; } } /* if isxdigit(ch) */ if (isalpha(ch) || ch == '_') { /* ID */ while (s < s_end && (isalnum(ch) || ch == '_')) { *s++ = (char) tolower(ch); ch = line_next_char(); } if (s == s_end) { printf("too long id. Max length is %d\n", LEXEME_MAX_LEN); return 1; } *s = '\0'; i = symtable_lookup(curr_lex.str); curr_lex.token = (i < 0) ? ID : symtable[i].token; line_prev_char(); return 0; } if (ch == '>') { if (line_next_char() == '>') { *s++ = ch; *s++ = ch; *s = '\0'; curr_lex.token = SHR; return 0; } line_prev_char(); } if (ch == '<') { if (line_next_char() == '<') { *s++ = ch; *s++ = ch; *s = '\0'; curr_lex.token = SHL; return 0; } line_prev_char(); } /* token is [ch] */ *s++ = ch; *s = '\0'; curr_lex.token = (token_id) ch; return 0; } return 0; }