diff --git a/exec.c b/exec.c index 14553e92a..f10d630b7 100644 --- a/exec.c +++ b/exec.c @@ -815,13 +815,18 @@ void exec( job_t *j ) break; } + /* + These two lines must be called before the new block is pushed + */ int lineno = parser_get_lineno(); + wchar_t *file = parser_current_filename()?wcsdup(parser_current_filename()):0; parser_push_block( FUNCTION_CALL ); 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; if( builtin_count_args(p->argv)>1 ) { diff --git a/parser.c b/parser.c index 2bd4de55f..bce57a104 100644 --- a/parser.c +++ b/parser.c @@ -401,6 +401,7 @@ void parser_pop_block() case FUNCTION_CALL: { free( current_block->param1.function_name ); + free( current_block->param4.function_filename ); al_foreach( ¤t_block->param2.function_vars, (void (*)(const void *))&free ); al_destroy( ¤t_block->param2.function_vars ); @@ -1023,7 +1024,8 @@ static void parser_stack_trace( block_t *b, string_buffer_t *buff) sb_printf( buff, _(L"in function '%ls',\n"), b->param1.function_name ); - const wchar_t *file = function_get_definition_file( b->param1.function_name ); + const wchar_t *file = b->param4.function_filename; + if( file ) sb_printf( buff, _(L"\tcalled on line %d of file '%ls',\n"), @@ -1094,7 +1096,7 @@ int parser_get_lineno() return lineno; } -static const wchar_t *parser_current_filename() +const wchar_t *parser_current_filename() { block_t *b = current_block; @@ -1188,7 +1190,7 @@ wchar_t *parser_current_line() /** If we are not going to print a stack trace, at least print the line number and filename */ - if( !is_interactive ) + if( !is_interactive || is_function() ) { int prev_width = my_wcswidth( (wchar_t *)lineinfo->buff ); if( file ) diff --git a/parser.h b/parser.h index 5087cc6cf..1728953e5 100644 --- a/parser.h +++ b/parser.h @@ -92,6 +92,7 @@ typedef struct block union { array_list_t *function_events; + wchar_t *function_filename; } param4; /** @@ -338,4 +339,12 @@ void parser_destroy(); */ int parser_is_help( wchar_t *s, int min_match ); +/** + Returns the file currently evaluated by the parser. This can be + different than reader_current_filename, e.g. if we are evaulating a + function defined in a different file than the one curently read. +*/ +const wchar_t *parser_current_filename(); + + #endif