mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-25 04:49:54 +08:00
dwarf2.c: simplify best_fit_len tests
* dwarf2.c (lookup_address_in_function_table): Simplify best_fit_len test. (info_hash_lookup_funcinfo): Likewise. (lookup_symbol_in_function_table): Likewise, also reorder tests and check "file" is set. (lookup_symbol_in_variable_table): Reorder tests.
This commit is contained in:
54
bfd/dwarf2.c
54
bfd/dwarf2.c
@ -3288,7 +3288,7 @@ lookup_address_in_function_table (struct comp_unit *unit,
|
|||||||
struct lookup_funcinfo* lookup_funcinfo = NULL;
|
struct lookup_funcinfo* lookup_funcinfo = NULL;
|
||||||
struct funcinfo* funcinfo = NULL;
|
struct funcinfo* funcinfo = NULL;
|
||||||
struct funcinfo* best_fit = NULL;
|
struct funcinfo* best_fit = NULL;
|
||||||
bfd_vma best_fit_len = 0;
|
bfd_vma best_fit_len = (bfd_vma) -1;
|
||||||
bfd_size_type low, high, mid, first;
|
bfd_size_type low, high, mid, first;
|
||||||
struct arange *arange;
|
struct arange *arange;
|
||||||
|
|
||||||
@ -3334,8 +3334,7 @@ lookup_address_in_function_table (struct comp_unit *unit,
|
|||||||
if (addr < arange->low || addr >= arange->high)
|
if (addr < arange->low || addr >= arange->high)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!best_fit
|
if (arange->high - arange->low < best_fit_len
|
||||||
|| arange->high - arange->low < best_fit_len
|
|
||||||
/* The following comparison is designed to return the same
|
/* The following comparison is designed to return the same
|
||||||
match as the previous algorithm for routines which have the
|
match as the previous algorithm for routines which have the
|
||||||
same best fit length. */
|
same best fit length. */
|
||||||
@ -3367,32 +3366,24 @@ lookup_symbol_in_function_table (struct comp_unit *unit,
|
|||||||
const char **filename_ptr,
|
const char **filename_ptr,
|
||||||
unsigned int *linenumber_ptr)
|
unsigned int *linenumber_ptr)
|
||||||
{
|
{
|
||||||
struct funcinfo* each_func;
|
struct funcinfo* each;
|
||||||
struct funcinfo* best_fit = NULL;
|
struct funcinfo* best_fit = NULL;
|
||||||
bfd_vma best_fit_len = 0;
|
bfd_vma best_fit_len = (bfd_vma) -1;
|
||||||
struct arange *arange;
|
struct arange *arange;
|
||||||
const char *name = bfd_asymbol_name (sym);
|
const char *name = bfd_asymbol_name (sym);
|
||||||
|
|
||||||
for (each_func = unit->function_table;
|
for (each = unit->function_table; each; each = each->prev_func)
|
||||||
each_func;
|
for (arange = &each->arange; arange; arange = arange->next)
|
||||||
each_func = each_func->prev_func)
|
if (addr >= arange->low
|
||||||
{
|
&& addr < arange->high
|
||||||
for (arange = &each_func->arange;
|
&& arange->high - arange->low < best_fit_len
|
||||||
arange;
|
&& each->file
|
||||||
arange = arange->next)
|
&& each->name
|
||||||
|
&& strcmp (name, each->name) == 0)
|
||||||
{
|
{
|
||||||
if (addr >= arange->low
|
best_fit = each;
|
||||||
&& addr < arange->high
|
best_fit_len = arange->high - arange->low;
|
||||||
&& each_func->name
|
|
||||||
&& strcmp (name, each_func->name) == 0
|
|
||||||
&& (!best_fit
|
|
||||||
|| arange->high - arange->low < best_fit_len))
|
|
||||||
{
|
|
||||||
best_fit = each_func;
|
|
||||||
best_fit_len = arange->high - arange->low;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (best_fit)
|
if (best_fit)
|
||||||
{
|
{
|
||||||
@ -3400,8 +3391,8 @@ lookup_symbol_in_function_table (struct comp_unit *unit,
|
|||||||
*linenumber_ptr = best_fit->line;
|
*linenumber_ptr = best_fit->line;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Variable table functions. */
|
/* Variable table functions. */
|
||||||
@ -3416,14 +3407,14 @@ lookup_symbol_in_variable_table (struct comp_unit *unit,
|
|||||||
const char **filename_ptr,
|
const char **filename_ptr,
|
||||||
unsigned int *linenumber_ptr)
|
unsigned int *linenumber_ptr)
|
||||||
{
|
{
|
||||||
const char *name = bfd_asymbol_name (sym);
|
|
||||||
struct varinfo* each;
|
struct varinfo* each;
|
||||||
|
const char *name = bfd_asymbol_name (sym);
|
||||||
|
|
||||||
for (each = unit->variable_table; each; each = each->prev_var)
|
for (each = unit->variable_table; each; each = each->prev_var)
|
||||||
if (! each->stack
|
if (each->addr == addr
|
||||||
|
&& !each->stack
|
||||||
&& each->file != NULL
|
&& each->file != NULL
|
||||||
&& each->name != NULL
|
&& each->name != NULL
|
||||||
&& each->addr == addr
|
|
||||||
&& strcmp (name, each->name) == 0)
|
&& strcmp (name, each->name) == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -5087,7 +5078,7 @@ info_hash_lookup_funcinfo (struct info_hash_table *hash_table,
|
|||||||
{
|
{
|
||||||
struct funcinfo* each_func;
|
struct funcinfo* each_func;
|
||||||
struct funcinfo* best_fit = NULL;
|
struct funcinfo* best_fit = NULL;
|
||||||
bfd_vma best_fit_len = 0;
|
bfd_vma best_fit_len = (bfd_vma) -1;
|
||||||
struct info_list_node *node;
|
struct info_list_node *node;
|
||||||
struct arange *arange;
|
struct arange *arange;
|
||||||
const char *name = bfd_asymbol_name (sym);
|
const char *name = bfd_asymbol_name (sym);
|
||||||
@ -5103,8 +5094,7 @@ info_hash_lookup_funcinfo (struct info_hash_table *hash_table,
|
|||||||
{
|
{
|
||||||
if (addr >= arange->low
|
if (addr >= arange->low
|
||||||
&& addr < arange->high
|
&& addr < arange->high
|
||||||
&& (!best_fit
|
&& arange->high - arange->low < best_fit_len)
|
||||||
|| arange->high - arange->low < best_fit_len))
|
|
||||||
{
|
{
|
||||||
best_fit = each_func;
|
best_fit = each_func;
|
||||||
best_fit_len = arange->high - arange->low;
|
best_fit_len = arange->high - arange->low;
|
||||||
@ -5135,9 +5125,9 @@ info_hash_lookup_varinfo (struct info_hash_table *hash_table,
|
|||||||
const char **filename_ptr,
|
const char **filename_ptr,
|
||||||
unsigned int *linenumber_ptr)
|
unsigned int *linenumber_ptr)
|
||||||
{
|
{
|
||||||
const char *name = bfd_asymbol_name (sym);
|
|
||||||
struct varinfo* each;
|
struct varinfo* each;
|
||||||
struct info_list_node *node;
|
struct info_list_node *node;
|
||||||
|
const char *name = bfd_asymbol_name (sym);
|
||||||
|
|
||||||
for (node = lookup_info_hash_table (hash_table, name);
|
for (node = lookup_info_hash_table (hash_table, name);
|
||||||
node;
|
node;
|
||||||
|
Reference in New Issue
Block a user