@@ -3891,6 +3891,11 @@ report_inlined_functions (uintptr_t pc, struct function *function,
3891
3891
if (function -> function_addrs_count == 0 )
3892
3892
return 0 ;
3893
3893
3894
+ /* Our search isn't safe if pc == -1, as that is the sentinel
3895
+ value. */
3896
+ if (pc + 1 == 0 )
3897
+ return 0 ;
3898
+
3894
3899
p = ((struct function_addrs * )
3895
3900
bsearch (& pc , function -> function_addrs ,
3896
3901
function -> function_addrs_count ,
@@ -3900,9 +3905,12 @@ report_inlined_functions (uintptr_t pc, struct function *function,
3900
3905
return 0 ;
3901
3906
3902
3907
/* Here pc >= p->low && pc < (p + 1)->low. The function_addrs are
3903
- sorted by low, so we are at the end of a range of function_addrs
3904
- with the same low alue. Walk backward and use the first range
3905
- that includes pc. */
3908
+ sorted by low, so if pc > p->low we are at the end of a range of
3909
+ function_addrs with the same low value. If pc == p->low walk
3910
+ forward to the end of the range with that low value. Then walk
3911
+ backward and use the first range that includes pc. */
3912
+ while (pc == (p + 1 )-> low )
3913
+ ++ p ;
3906
3914
match = NULL ;
3907
3915
while (1 )
3908
3916
{
@@ -3969,8 +3977,10 @@ dwarf_lookup_pc (struct backtrace_state *state, struct dwarf_data *ddata,
3969
3977
3970
3978
* found = 1 ;
3971
3979
3972
- /* Find an address range that includes PC. */
3973
- entry = (ddata -> addrs_count == 0
3980
+ /* Find an address range that includes PC. Our search isn't safe if
3981
+ PC == -1, as we use that as a sentinel value, so skip the search
3982
+ in that case. */
3983
+ entry = (ddata -> addrs_count == 0 || pc + 1 == 0
3974
3984
? NULL
3975
3985
: bsearch (& pc , ddata -> addrs , ddata -> addrs_count ,
3976
3986
sizeof (struct unit_addrs ), unit_addrs_search ));
@@ -3982,9 +3992,12 @@ dwarf_lookup_pc (struct backtrace_state *state, struct dwarf_data *ddata,
3982
3992
}
3983
3993
3984
3994
/* Here pc >= entry->low && pc < (entry + 1)->low. The unit_addrs
3985
- are sorted by low, so we are at the end of a range of unit_addrs
3986
- with the same low value. Walk backward and use the first range
3987
- that includes pc. */
3995
+ are sorted by low, so if pc > p->low we are at the end of a range
3996
+ of unit_addrs with the same low value. If pc == p->low walk
3997
+ forward to the end of the range with that low value. Then walk
3998
+ backward and use the first range that includes pc. */
3999
+ while (pc == (entry + 1 )-> low )
4000
+ ++ entry ;
3988
4001
found_entry = 0 ;
3989
4002
while (1 )
3990
4003
{
@@ -4165,9 +4178,12 @@ dwarf_lookup_pc (struct backtrace_state *state, struct dwarf_data *ddata,
4165
4178
return callback (data , pc , ln -> filename , ln -> lineno , NULL );
4166
4179
4167
4180
/* Here pc >= p->low && pc < (p + 1)->low. The function_addrs are
4168
- sorted by low, so we are at the end of a range of function_addrs
4169
- with the same low alue. Walk backward and use the first range
4170
- that includes pc. */
4181
+ sorted by low, so if pc > p->low we are at the end of a range of
4182
+ function_addrs with the same low value. If pc == p->low walk
4183
+ forward to the end of the range with that low value. Then walk
4184
+ backward and use the first range that includes pc. */
4185
+ while (pc == (p + 1 )-> low )
4186
+ ++ p ;
4171
4187
fmatch = NULL ;
4172
4188
while (1 )
4173
4189
{
0 commit comments