New common function "startswith"

This commit introduces a new inline common function "startswith"
which takes two string arguments and returns nonzero if the first
string starts with the second.  It also updates the 295 places
where this logic was written out longhand to use the new function.

gdb/ChangeLog:

	* common/common-utils.h (startswith): New inline function.
	All places where this logic was used updated to use the above.
This commit is contained in:
Gary Benson 2015-03-06 09:42:06 +00:00
parent e80417caef
commit 61012eef84
77 changed files with 309 additions and 329 deletions

View file

@ -1345,14 +1345,13 @@ mips_in_frame_stub (CORE_ADDR pc)
return 0;
/* If the PC is in __mips16_call_stub_*, this is a call/return stub. */
if (strncmp (name, mips_str_mips16_call_stub,
strlen (mips_str_mips16_call_stub)) == 0)
if (startswith (name, mips_str_mips16_call_stub))
return 1;
/* If the PC is in __call_stub_*, this is a call/return or a call stub. */
if (strncmp (name, mips_str_call_stub, strlen (mips_str_call_stub)) == 0)
if (startswith (name, mips_str_call_stub))
return 1;
/* If the PC is in __fn_stub_*, this is a call stub. */
if (strncmp (name, mips_str_fn_stub, strlen (mips_str_fn_stub)) == 0)
if (startswith (name, mips_str_fn_stub))
return 1;
return 0; /* Not a stub. */
@ -3813,7 +3812,7 @@ mips_stub_frame_sniffer (const struct frame_unwind *self,
msym = lookup_minimal_symbol_by_pc (pc);
if (msym.minsym != NULL
&& MSYMBOL_LINKAGE_NAME (msym.minsym) != NULL
&& strncmp (MSYMBOL_LINKAGE_NAME (msym.minsym), ".pic.", 5) == 0)
&& startswith (MSYMBOL_LINKAGE_NAME (msym.minsym), ".pic."))
return 1;
return 0;
@ -7846,8 +7845,8 @@ mips_skip_mips16_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
/* If the PC is in __call_stub_* or __fn_stub*, this is one of the
compiler-generated call or call/return stubs. */
if (strncmp (name, mips_str_fn_stub, strlen (mips_str_fn_stub)) == 0
|| strncmp (name, mips_str_call_stub, strlen (mips_str_call_stub)) == 0)
if (startswith (name, mips_str_fn_stub)
|| startswith (name, mips_str_call_stub))
{
if (pc == start_addr)
/* This is the 'call' part of a call stub. Call this helper
@ -7934,7 +7933,7 @@ mips_skip_pic_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
if (msym.minsym == NULL
|| BMSYMBOL_VALUE_ADDRESS (msym) != pc
|| MSYMBOL_LINKAGE_NAME (msym.minsym) == NULL
|| strncmp (MSYMBOL_LINKAGE_NAME (msym.minsym), ".pic.", 5) != 0)
|| !startswith (MSYMBOL_LINKAGE_NAME (msym.minsym), ".pic."))
return 0;
/* A two-instruction header. */
@ -8099,7 +8098,7 @@ mips_find_abi_section (bfd *abfd, asection *sect, void *obj)
if (*abip != MIPS_ABI_UNKNOWN)
return;
if (strncmp (name, ".mdebug.", 8) != 0)
if (!startswith (name, ".mdebug."))
return;
if (strcmp (name, ".mdebug.abi32") == 0)
@ -8124,11 +8123,11 @@ mips_find_long_section (bfd *abfd, asection *sect, void *obj)
int *lbp = (int *) obj;
const char *name = bfd_get_section_name (abfd, sect);
if (strncmp (name, ".gcc_compiled_long32", 20) == 0)
if (startswith (name, ".gcc_compiled_long32"))
*lbp = 32;
else if (strncmp (name, ".gcc_compiled_long64", 20) == 0)
else if (startswith (name, ".gcc_compiled_long64"))
*lbp = 64;
else if (strncmp (name, ".gcc_compiled_long", 18) == 0)
else if (startswith (name, ".gcc_compiled_long"))
warning (_("unrecognized .gcc_compiled_longXX"));
}