improve error reporting

This commit is contained in:
krakjoe 2014-02-16 23:12:24 +00:00
parent ff95046b76
commit 4af3e39147
4 changed files with 40 additions and 31 deletions

View file

@ -11,14 +11,17 @@
#include "phpdbg.h" #include "phpdbg.h"
#include "phpdbg_cmd.h" #include "phpdbg_cmd.h"
#include "phpdbg_utils.h"
#define YYSTYPE phpdbg_param_t #define YYSTYPE phpdbg_param_t
#include "phpdbg_parser.h" #include "phpdbg_parser.h"
#include "phpdbg_lexer.h" #include "phpdbg_lexer.h"
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
int yyerror(phpdbg_param_t *stack, yyscan_t scanner, const char *msg) { int yyerror(phpdbg_param_t *stack, yyscan_t scanner, const char *msg) {
fprintf(stderr, "Parse Error: %s\n", msg); phpdbg_error("Parse Error: %s", msg);
} }
void phpdbg_debug_param(const phpdbg_param_t *param, const char *msg) { void phpdbg_debug_param(const phpdbg_param_t *param, const char *msg) {
@ -139,6 +142,7 @@ int phpdbg_stack_execute(phpdbg_param_t *stack, char **why) {
%} %}
%code requires { %code requires {
#include "phpdbg.h"
#ifndef YY_TYPEDEF_YY_SCANNER_T #ifndef YY_TYPEDEF_YY_SCANNER_T
#define YY_TYPEDEF_YY_SCANNER_T #define YY_TYPEDEF_YY_SCANNER_T
typedef void* yyscan_t; typedef void* yyscan_t;

View file

@ -556,7 +556,7 @@ readline:
phpdbg_init_param(&stack, STACK_PARAM); phpdbg_init_param(&stack, STACK_PARAM);
if (yylex_init(&scanner)) { if (yylex_init(&scanner)) {
fprintf(stderr, "could not initialize scanner\n"); phpdbg_error("could not initialize scanner");
return buffer; return buffer;
} }
@ -566,8 +566,8 @@ readline:
char *why = NULL; char *why = NULL;
if (phpdbg_stack_execute(&stack, &why) != SUCCESS) { if (phpdbg_stack_execute(&stack, &why) != SUCCESS) {
fprintf(stderr, phpdbg_error(
"Execution Error: %s\n", "Execution Error: %s",
why ? why : "for no particular reason"); why ? why : "for no particular reason");
} }

View file

@ -79,14 +79,17 @@
#include "phpdbg.h" #include "phpdbg.h"
#include "phpdbg_cmd.h" #include "phpdbg_cmd.h"
#include "phpdbg_utils.h"
#define YYSTYPE phpdbg_param_t #define YYSTYPE phpdbg_param_t
#include "phpdbg_parser.h" #include "phpdbg_parser.h"
#include "phpdbg_lexer.h" #include "phpdbg_lexer.h"
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
int yyerror(phpdbg_param_t *stack, yyscan_t scanner, const char *msg) { int yyerror(phpdbg_param_t *stack, yyscan_t scanner, const char *msg) {
fprintf(stderr, "Parse Error: %s\n", msg); phpdbg_error("Parse Error: %s", msg);
} }
void phpdbg_debug_param(const phpdbg_param_t *param, const char *msg) { void phpdbg_debug_param(const phpdbg_param_t *param, const char *msg) {
@ -207,7 +210,7 @@ int phpdbg_stack_execute(phpdbg_param_t *stack, char **why) {
/* Line 268 of yacc.c */ /* Line 268 of yacc.c */
#line 211 "sapi/phpdbg/phpdbg_parser.c" #line 214 "sapi/phpdbg/phpdbg_parser.c"
/* Enabling traces. */ /* Enabling traces. */
#ifndef YYDEBUG #ifndef YYDEBUG
@ -230,8 +233,9 @@ int phpdbg_stack_execute(phpdbg_param_t *stack, char **why) {
/* "%code requires" blocks. */ /* "%code requires" blocks. */
/* Line 288 of yacc.c */ /* Line 288 of yacc.c */
#line 141 "sapi/phpdbg/dev/phpdbg_parser.y" #line 144 "sapi/phpdbg/dev/phpdbg_parser.y"
#include "phpdbg.h"
#ifndef YY_TYPEDEF_YY_SCANNER_T #ifndef YY_TYPEDEF_YY_SCANNER_T
#define YY_TYPEDEF_YY_SCANNER_T #define YY_TYPEDEF_YY_SCANNER_T
typedef void* yyscan_t; typedef void* yyscan_t;
@ -240,7 +244,7 @@ typedef void* yyscan_t;
/* Line 288 of yacc.c */ /* Line 288 of yacc.c */
#line 244 "sapi/phpdbg/phpdbg_parser.c" #line 248 "sapi/phpdbg/phpdbg_parser.c"
/* Tokens. */ /* Tokens. */
#ifndef YYTOKENTYPE #ifndef YYTOKENTYPE
@ -278,7 +282,7 @@ typedef int YYSTYPE;
/* Line 343 of yacc.c */ /* Line 343 of yacc.c */
#line 282 "sapi/phpdbg/phpdbg_parser.c" #line 286 "sapi/phpdbg/phpdbg_parser.c"
#ifdef short #ifdef short
# undef short # undef short
@ -571,9 +575,9 @@ static const yytype_int8 yyrhs[] =
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint8 yyrline[] = static const yytype_uint8 yyrline[] =
{ {
0, 173, 173, 177, 178, 181, 183, 187, 188, 192, 0, 177, 177, 181, 182, 185, 187, 191, 192, 196,
193, 197, 198, 202, 203, 204, 205, 206, 207, 208, 197, 201, 202, 206, 207, 208, 209, 210, 211, 212,
209, 213 213, 217
}; };
#endif #endif
@ -1529,105 +1533,105 @@ yyreduce:
case 3: case 3:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 177 "sapi/phpdbg/dev/phpdbg_parser.y" #line 181 "sapi/phpdbg/dev/phpdbg_parser.y"
{ phpdbg_stack_push(stack, &(yyvsp[(1) - (1)])); } { phpdbg_stack_push(stack, &(yyvsp[(1) - (1)])); }
break; break;
case 4: case 4:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 178 "sapi/phpdbg/dev/phpdbg_parser.y" #line 182 "sapi/phpdbg/dev/phpdbg_parser.y"
{ phpdbg_stack_push(stack, &(yyvsp[(2) - (2)])); } { phpdbg_stack_push(stack, &(yyvsp[(2) - (2)])); }
break; break;
case 7: case 7:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 187 "sapi/phpdbg/dev/phpdbg_parser.y" #line 191 "sapi/phpdbg/dev/phpdbg_parser.y"
{ phpdbg_stack_push(stack, &(yyvsp[(1) - (1)])); } { phpdbg_stack_push(stack, &(yyvsp[(1) - (1)])); }
break; break;
case 8: case 8:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 188 "sapi/phpdbg/dev/phpdbg_parser.y" #line 192 "sapi/phpdbg/dev/phpdbg_parser.y"
{ phpdbg_stack_push(stack, &(yyvsp[(2) - (2)])); } { phpdbg_stack_push(stack, &(yyvsp[(2) - (2)])); }
break; break;
case 9: case 9:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 192 "sapi/phpdbg/dev/phpdbg_parser.y" #line 196 "sapi/phpdbg/dev/phpdbg_parser.y"
{ phpdbg_stack_push(stack, &(yyvsp[(1) - (2)])); phpdbg_stack_push(stack, &(yyvsp[(2) - (2)])); } { phpdbg_stack_push(stack, &(yyvsp[(1) - (2)])); phpdbg_stack_push(stack, &(yyvsp[(2) - (2)])); }
break; break;
case 10: case 10:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 193 "sapi/phpdbg/dev/phpdbg_parser.y" #line 197 "sapi/phpdbg/dev/phpdbg_parser.y"
{ phpdbg_stack_push(stack, &(yyvsp[(1) - (2)])); phpdbg_stack_push(stack, &(yyvsp[(2) - (2)])); } { phpdbg_stack_push(stack, &(yyvsp[(1) - (2)])); phpdbg_stack_push(stack, &(yyvsp[(2) - (2)])); }
break; break;
case 13: case 13:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 202 "sapi/phpdbg/dev/phpdbg_parser.y" #line 206 "sapi/phpdbg/dev/phpdbg_parser.y"
{ (yyval) = (yyvsp[(1) - (1)]); } { (yyval) = (yyvsp[(1) - (1)]); }
break; break;
case 14: case 14:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 203 "sapi/phpdbg/dev/phpdbg_parser.y" #line 207 "sapi/phpdbg/dev/phpdbg_parser.y"
{ (yyval) = (yyvsp[(1) - (1)]); } { (yyval) = (yyvsp[(1) - (1)]); }
break; break;
case 15: case 15:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 204 "sapi/phpdbg/dev/phpdbg_parser.y" #line 208 "sapi/phpdbg/dev/phpdbg_parser.y"
{ (yyval) = (yyvsp[(1) - (1)]); } { (yyval) = (yyvsp[(1) - (1)]); }
break; break;
case 16: case 16:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 205 "sapi/phpdbg/dev/phpdbg_parser.y" #line 209 "sapi/phpdbg/dev/phpdbg_parser.y"
{ (yyval) = (yyvsp[(1) - (1)]); } { (yyval) = (yyvsp[(1) - (1)]); }
break; break;
case 17: case 17:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 206 "sapi/phpdbg/dev/phpdbg_parser.y" #line 210 "sapi/phpdbg/dev/phpdbg_parser.y"
{ (yyval) = (yyvsp[(1) - (1)]); } { (yyval) = (yyvsp[(1) - (1)]); }
break; break;
case 18: case 18:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 207 "sapi/phpdbg/dev/phpdbg_parser.y" #line 211 "sapi/phpdbg/dev/phpdbg_parser.y"
{ (yyval) = (yyvsp[(1) - (1)]); } { (yyval) = (yyvsp[(1) - (1)]); }
break; break;
case 19: case 19:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 208 "sapi/phpdbg/dev/phpdbg_parser.y" #line 212 "sapi/phpdbg/dev/phpdbg_parser.y"
{ (yyval) = (yyvsp[(1) - (1)]); } { (yyval) = (yyvsp[(1) - (1)]); }
break; break;
case 20: case 20:
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 209 "sapi/phpdbg/dev/phpdbg_parser.y" #line 213 "sapi/phpdbg/dev/phpdbg_parser.y"
{ (yyval) = (yyvsp[(1) - (1)]); } { (yyval) = (yyvsp[(1) - (1)]); }
break; break;
/* Line 1806 of yacc.c */ /* Line 1806 of yacc.c */
#line 1631 "sapi/phpdbg/phpdbg_parser.c" #line 1635 "sapi/phpdbg/phpdbg_parser.c"
default: break; default: break;
} }
/* User semantic actions sometimes alter yychar, and that requires /* User semantic actions sometimes alter yychar, and that requires
@ -1858,6 +1862,6 @@ yyreturn:
/* Line 2067 of yacc.c */ /* Line 2067 of yacc.c */
#line 215 "sapi/phpdbg/dev/phpdbg_parser.y" #line 219 "sapi/phpdbg/dev/phpdbg_parser.y"

View file

@ -33,8 +33,9 @@
/* "%code requires" blocks. */ /* "%code requires" blocks. */
/* Line 2068 of yacc.c */ /* Line 2068 of yacc.c */
#line 141 "sapi/phpdbg/dev/phpdbg_parser.y" #line 144 "sapi/phpdbg/dev/phpdbg_parser.y"
#include "phpdbg.h"
#ifndef YY_TYPEDEF_YY_SCANNER_T #ifndef YY_TYPEDEF_YY_SCANNER_T
#define YY_TYPEDEF_YY_SCANNER_T #define YY_TYPEDEF_YY_SCANNER_T
typedef void* yyscan_t; typedef void* yyscan_t;
@ -43,7 +44,7 @@ typedef void* yyscan_t;
/* Line 2068 of yacc.c */ /* Line 2068 of yacc.c */
#line 47 "sapi/phpdbg/phpdbg_parser.h" #line 48 "sapi/phpdbg/phpdbg_parser.h"
/* Tokens. */ /* Tokens. */
#ifndef YYTOKENTYPE #ifndef YYTOKENTYPE