@@ -2677,19 +2677,20 @@ read_v2_paths (struct backtrace_state *state, struct unit *u,
2677
2677
++ hdr -> dirs_count ;
2678
2678
}
2679
2679
2680
- hdr -> dirs = NULL ;
2681
- if ( hdr -> dirs_count != 0 )
2682
- {
2683
- hdr -> dirs = (( const char * * )
2684
- backtrace_alloc ( state ,
2685
- hdr -> dirs_count * sizeof ( const char * ) ,
2686
- hdr_buf -> error_callback ,
2687
- hdr_buf -> data ));
2688
- if ( hdr -> dirs == NULL )
2689
- return 0 ;
2690
- }
2680
+ /* The index of the first entry in the list of directories is 1. Index 0 is
2681
+ used for the current directory of the compilation. To simplify index
2682
+ handling, we set entry 0 to the compilation unit directory. */
2683
+ ++ hdr -> dirs_count ;
2684
+ hdr -> dirs = (( const char * * )
2685
+ backtrace_alloc ( state ,
2686
+ hdr -> dirs_count * sizeof ( const char * ) ,
2687
+ hdr_buf -> error_callback ,
2688
+ hdr_buf -> data ));
2689
+ if ( hdr -> dirs == NULL )
2690
+ return 0 ;
2691
2691
2692
- i = 0 ;
2692
+ hdr -> dirs [0 ] = u -> comp_dir ;
2693
+ i = 1 ;
2693
2694
while (* hdr_buf -> buf != '\0' )
2694
2695
{
2695
2696
if (hdr_buf -> reported_underflow )
@@ -2716,14 +2717,19 @@ read_v2_paths (struct backtrace_state *state, struct unit *u,
2716
2717
++ hdr -> filenames_count ;
2717
2718
}
2718
2719
2720
+ /* The index of the first entry in the list of file names is 1. Index 0 is
2721
+ used for the DW_AT_name of the compilation unit. To simplify index
2722
+ handling, we set entry 0 to the compilation unit file name. */
2723
+ ++ hdr -> filenames_count ;
2719
2724
hdr -> filenames = ((const char * * )
2720
2725
backtrace_alloc (state ,
2721
2726
hdr -> filenames_count * sizeof (char * ),
2722
2727
hdr_buf -> error_callback ,
2723
2728
hdr_buf -> data ));
2724
2729
if (hdr -> filenames == NULL )
2725
2730
return 0 ;
2726
- i = 0 ;
2731
+ hdr -> filenames [0 ] = u -> filename ;
2732
+ i = 1 ;
2727
2733
while (* hdr_buf -> buf != '\0' )
2728
2734
{
2729
2735
const char * filename ;
@@ -2737,7 +2743,7 @@ read_v2_paths (struct backtrace_state *state, struct unit *u,
2737
2743
return 0 ;
2738
2744
dir_index = read_uleb128 (hdr_buf );
2739
2745
if (IS_ABSOLUTE_PATH (filename )
2740
- || (dir_index == 0 && u -> comp_dir == NULL ))
2746
+ || (dir_index < hdr -> dirs_count && hdr -> dirs [ dir_index ] == NULL ))
2741
2747
hdr -> filenames [i ] = filename ;
2742
2748
else
2743
2749
{
@@ -2746,10 +2752,8 @@ read_v2_paths (struct backtrace_state *state, struct unit *u,
2746
2752
size_t filename_len ;
2747
2753
char * s ;
2748
2754
2749
- if (dir_index == 0 )
2750
- dir = u -> comp_dir ;
2751
- else if (dir_index - 1 < hdr -> dirs_count )
2752
- dir = hdr -> dirs [dir_index - 1 ];
2755
+ if (dir_index < hdr -> dirs_count )
2756
+ dir = hdr -> dirs [dir_index ];
2753
2757
else
2754
2758
{
2755
2759
dwarf_buf_error (hdr_buf ,
@@ -3037,8 +3041,8 @@ read_line_header (struct backtrace_state *state, struct dwarf_data *ddata,
3037
3041
3038
3042
static int
3039
3043
read_line_program (struct backtrace_state * state , struct dwarf_data * ddata ,
3040
- struct unit * u , const struct line_header * hdr ,
3041
- struct dwarf_buf * line_buf , struct line_vector * vec )
3044
+ const struct line_header * hdr , struct dwarf_buf * line_buf ,
3045
+ struct line_vector * vec )
3042
3046
{
3043
3047
uint64_t address ;
3044
3048
unsigned int op_index ;
@@ -3048,8 +3052,8 @@ read_line_program (struct backtrace_state *state, struct dwarf_data *ddata,
3048
3052
3049
3053
address = 0 ;
3050
3054
op_index = 0 ;
3051
- if (hdr -> filenames_count > 0 )
3052
- reset_filename = hdr -> filenames [0 ];
3055
+ if (hdr -> filenames_count > 1 )
3056
+ reset_filename = hdr -> filenames [1 ];
3053
3057
else
3054
3058
reset_filename = "" ;
3055
3059
filename = reset_filename ;
@@ -3114,10 +3118,8 @@ read_line_program (struct backtrace_state *state, struct dwarf_data *ddata,
3114
3118
size_t f_len ;
3115
3119
char * p ;
3116
3120
3117
- if (dir_index == 0 && hdr -> version < 5 )
3118
- dir = u -> comp_dir ;
3119
- else if (dir_index - 1 < hdr -> dirs_count )
3120
- dir = hdr -> dirs [dir_index - 1 ];
3121
+ if (dir_index < hdr -> dirs_count )
3122
+ dir = hdr -> dirs [dir_index ];
3121
3123
else
3122
3124
{
3123
3125
dwarf_buf_error (line_buf ,
@@ -3184,14 +3186,14 @@ read_line_program (struct backtrace_state *state, struct dwarf_data *ddata,
3184
3186
filename = "" ;
3185
3187
else
3186
3188
{
3187
- if (fileno - 1 >= hdr -> filenames_count )
3189
+ if (fileno >= hdr -> filenames_count )
3188
3190
{
3189
3191
dwarf_buf_error (line_buf ,
3190
3192
("invalid file number in "
3191
3193
"line number program" ));
3192
3194
return 0 ;
3193
3195
}
3194
- filename = hdr -> filenames [fileno - 1 ];
3196
+ filename = hdr -> filenames [fileno ];
3195
3197
}
3196
3198
}
3197
3199
break ;
@@ -3281,7 +3283,7 @@ read_line_info (struct backtrace_state *state, struct dwarf_data *ddata,
3281
3283
if (!read_line_header (state , ddata , u , is_dwarf64 , & line_buf , hdr ))
3282
3284
goto fail ;
3283
3285
3284
- if (!read_line_program (state , ddata , u , hdr , & line_buf , & vec ))
3286
+ if (!read_line_program (state , ddata , hdr , & line_buf , & vec ))
3285
3287
goto fail ;
3286
3288
3287
3289
if (line_buf .reported_underflow )
@@ -3622,15 +3624,15 @@ read_function_entry (struct backtrace_state *state, struct dwarf_data *ddata,
3622
3624
function -> caller_filename = "" ;
3623
3625
else
3624
3626
{
3625
- if (val .u .uint - 1 >= lhdr -> filenames_count )
3627
+ if (val .u .uint >= lhdr -> filenames_count )
3626
3628
{
3627
3629
dwarf_buf_error (unit_buf ,
3628
3630
("invalid file number in "
3629
3631
"DW_AT_call_file attribute" ));
3630
3632
return 0 ;
3631
3633
}
3632
3634
function -> caller_filename =
3633
- lhdr -> filenames [val .u .uint - 1 ];
3635
+ lhdr -> filenames [val .u .uint ];
3634
3636
}
3635
3637
}
3636
3638
break ;
0 commit comments