mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 05:28:49 +00:00
Display use of . (source) builtin in stack traces
darcs-hash:20060128113440-ac50b-6556097eb766cc7561a3d30ef994bc913181fe65.gz
This commit is contained in:
parent
00dea8a082
commit
003c4d776f
5 changed files with 41 additions and 38 deletions
35
builtin.c
35
builtin.c
|
@ -969,19 +969,6 @@ static int wcsbindingname( wchar_t *str )
|
|||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
Debug function to print the current block stack
|
||||
*/
|
||||
static void print_block_stack( block_t *b )
|
||||
{
|
||||
if( !b )
|
||||
return;
|
||||
|
||||
wprintf( L"%ls (%d)\n", parser_get_block_desc( b->type ), b->job?b->job->job_id:-1 );
|
||||
print_block_stack( b->outer );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
The function builtin, used for providing subroutines.
|
||||
|
@ -1133,8 +1120,6 @@ static int builtin_function( wchar_t **argv )
|
|||
{
|
||||
block_t *b = current_block;
|
||||
|
||||
// print_block_stack( b );
|
||||
|
||||
while( b && (b->type != SUBST) )
|
||||
b = b->outer;
|
||||
|
||||
|
@ -1144,15 +1129,8 @@ static int builtin_function( wchar_t **argv )
|
|||
}
|
||||
if( b->job )
|
||||
{
|
||||
// debug( 1, L"Found block, type is %ls", parser_get_block_desc( b->type ) );
|
||||
|
||||
job_id = b->job->job_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
// debug( 1, L"Calling block is null" );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if( job_id == -1 )
|
||||
|
@ -1990,16 +1968,23 @@ static int builtin_source( wchar_t ** argv )
|
|||
}
|
||||
else
|
||||
{
|
||||
reader_push_current_filename( argv[1] );
|
||||
|
||||
/*
|
||||
Push a new non-shadowwing variable scope to the stack. That
|
||||
way one can use explicitly local variables in sourced files
|
||||
that will die on return to the calling file.
|
||||
*/
|
||||
env_push(0);
|
||||
int lineno = parser_get_lineno();
|
||||
wchar_t *file = parser_current_filename()?wcsdup(parser_current_filename()):0;
|
||||
reader_push_current_filename( argv[1] );
|
||||
parser_push_block( SOURCE );
|
||||
|
||||
current_block->param1.source_dest = wcsdup( argv[1] );
|
||||
current_block->param3.call_lineno = lineno;
|
||||
current_block->param4.call_filename = file;
|
||||
|
||||
res = reader_read( fd );
|
||||
env_pop();
|
||||
parser_pop_block();
|
||||
if( res )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
|
|
|
@ -509,9 +509,6 @@ int builtin_set( wchar_t **argv )
|
|||
!erase &&
|
||||
!list )
|
||||
{
|
||||
/*
|
||||
Only update the variable scope
|
||||
*/
|
||||
env_set( name, 0, scope );
|
||||
finished = 1;
|
||||
}
|
||||
|
|
4
exec.c
4
exec.c
|
@ -825,8 +825,8 @@ void exec( job_t *j )
|
|||
|
||||
al_init( ¤t_block->param2.function_vars );
|
||||
current_block->param1.function_name = wcsdup( p->argv[0] );
|
||||
current_block->param3.function_lineno = lineno;
|
||||
current_block->param4.function_filename = file;
|
||||
current_block->param3.call_lineno = lineno;
|
||||
current_block->param4.call_filename = file;
|
||||
|
||||
if( builtin_count_args(p->argv)>1 )
|
||||
{
|
||||
|
|
31
parser.c
31
parser.c
|
@ -228,6 +228,12 @@ The fish parser. Contains functions for parsing code.
|
|||
#define BEGIN_BLOCK _( L"'begin' unconditional block" )
|
||||
|
||||
|
||||
/**
|
||||
Source block description
|
||||
*/
|
||||
#define SOURCE_BLOCK _( L"Block created by the . builtin" )
|
||||
|
||||
|
||||
/**
|
||||
Unknown block description
|
||||
*/
|
||||
|
@ -401,13 +407,20 @@ void parser_pop_block()
|
|||
case FUNCTION_CALL:
|
||||
{
|
||||
free( current_block->param1.function_name );
|
||||
free( current_block->param4.function_filename );
|
||||
free( current_block->param4.call_filename );
|
||||
al_foreach( ¤t_block->param2.function_vars,
|
||||
(void (*)(const void *))&free );
|
||||
al_destroy( ¤t_block->param2.function_vars );
|
||||
break;
|
||||
}
|
||||
|
||||
case SOURCE:
|
||||
{
|
||||
free( current_block->param4.call_filename );
|
||||
free( current_block->param1.source_dest );
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for( eb=current_block->first_event_block; eb; eb=eb_next )
|
||||
|
@ -455,6 +468,9 @@ const wchar_t *parser_get_block_desc( int block )
|
|||
case BEGIN:
|
||||
return BEGIN_BLOCK;
|
||||
|
||||
case SOURCE:
|
||||
return SOURCE_BLOCK;
|
||||
|
||||
default:
|
||||
return UNKNOWN_BLOCK;
|
||||
}
|
||||
|
@ -1018,18 +1034,21 @@ static void parser_stack_trace( block_t *b, string_buffer_t *buff)
|
|||
if( !b )
|
||||
return;
|
||||
|
||||
if( b->type == FUNCTION_CALL )
|
||||
if( b->type == FUNCTION_CALL || b->type==SOURCE)
|
||||
{
|
||||
int i;
|
||||
|
||||
sb_printf( buff, _(L"in function '%ls',\n"), b->param1.function_name );
|
||||
|
||||
const wchar_t *file = b->param4.function_filename;
|
||||
if( b->type==SOURCE)
|
||||
sb_printf( buff, _(L"in . (source) call of file '%ls',\n"), b->param1.source_dest );
|
||||
else
|
||||
sb_printf( buff, _(L"in function '%ls',\n"), b->param1.function_name );
|
||||
|
||||
const wchar_t *file = b->param4.call_filename;
|
||||
|
||||
if( file )
|
||||
sb_printf( buff,
|
||||
_(L"\tcalled on line %d of file '%ls',\n"),
|
||||
b->param3.function_lineno,
|
||||
b->param3.call_lineno,
|
||||
file );
|
||||
else
|
||||
sb_printf( buff,
|
||||
|
|
6
parser.h
6
parser.h
|
@ -64,6 +64,7 @@ typedef struct block
|
|||
int if_state; /**< The state of the if block */
|
||||
wchar_t *switch_value; /**< The value to test in a switch block */
|
||||
wchar_t *function_name; /**< The name of the function to define or the function called*/
|
||||
wchar_t *source_dest; /**< The name of the file to source*/
|
||||
} param1;
|
||||
|
||||
/**
|
||||
|
@ -83,7 +84,7 @@ typedef struct block
|
|||
union
|
||||
{
|
||||
int function_is_binding; /**< Whether a function is a keybinding */
|
||||
int function_lineno; /**< Function invocation line number */
|
||||
int call_lineno; /**< Function invocation line number */
|
||||
} param3;
|
||||
|
||||
/**
|
||||
|
@ -92,7 +93,7 @@ typedef struct block
|
|||
union
|
||||
{
|
||||
array_list_t *function_events;
|
||||
wchar_t *function_filename;
|
||||
wchar_t *call_filename;
|
||||
} param4;
|
||||
|
||||
/**
|
||||
|
@ -121,6 +122,7 @@ enum block_type
|
|||
SUBST, /**< Command substitution scope */
|
||||
TOP, /**< Outermost block */
|
||||
BEGIN, /**< Unconditional block */
|
||||
SOURCE, /**< Block created by the . (source) builtin */
|
||||
}
|
||||
;
|
||||
|
||||
|
|
Loading…
Reference in a new issue