当前位置: 首页 > 工具软件 > bash-parser > 使用案例 >

bash源代码分析----bison--debug或-t选项的作用

瞿文柏
2023-12-01

bison--debug或-t选项的作用
bison -y parse.y

/* Debug traces.  */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif
#if YYDEBUG
extern int yydebug;
#endif

bison -y --debug parse.y
/* Debug traces.  */
#ifndef YYDEBUG
# define YYDEBUG 1
#endif
#if YYDEBUG
extern int yydebug;
#endif


eval.c文件里面在调用yyparse()之前加上如下代码:

extern int yydebug;
yydebug = 1;

[root@localhost bash-4.2.53]# ./bash --version
GNU bash, version 4.2.53(9)-release (x86_64-unknown-linux-gnu)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

eval.c文件修改如下:

/* Call the YACC-generated parser and return the status of the parse.
   Input is read from the current input stream (bash_input).  yyparse
   leaves the parsed command in the global variable GLOBAL_COMMAND.
   This is where PROMPT_COMMAND is executed. */
int
parse_command ()
{
  int r;
  char *command_to_execute;
        extern int yydebug;
        yydebug = 1;

  need_here_doc = 0;
  run_pending_traps ();

 


parse.y里面加上最后一行

#ifdef DEBUG
#  define YYDEBUG 1
#else
#  define YYDEBUG 0
#endif


#  define YYDEBUG 1

 类似资料: