aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary Benson <gbenson@redhat.com>2015-03-06 09:42:06 +0000
committerGary Benson <gbenson@redhat.com>2015-03-06 09:42:06 +0000
commit61012eef8463764ccd9117dc1c9bc43cc452b7cc (patch)
treef576a77bcb77e71cc60e6592b56d2aa915b50c36
parente80417caef36c7d5e3d1da6a3b396a872d9d7201 (diff)
downloadgdb-61012eef8463764ccd9117dc1c9bc43cc452b7cc.zip
gdb-61012eef8463764ccd9117dc1c9bc43cc452b7cc.tar.gz
gdb-61012eef8463764ccd9117dc1c9bc43cc452b7cc.tar.bz2
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.
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/ada-lang.c55
-rw-r--r--gdb/amd64-tdep.c3
-rw-r--r--gdb/amd64-windows-tdep.c4
-rw-r--r--gdb/amd64obsd-tdep.c4
-rw-r--r--gdb/arch-utils.c2
-rw-r--r--gdb/arm-tdep.c28
-rw-r--r--gdb/arm-wince-tdep.c2
-rw-r--r--gdb/breakpoint.c8
-rw-r--r--gdb/bsd-uthread.c2
-rw-r--r--gdb/c-typeprint.c10
-rw-r--r--gdb/cli/cli-dump.c2
-rw-r--r--gdb/cli/cli-script.c28
-rw-r--r--gdb/coffread.c30
-rw-r--r--gdb/common/common-utils.h9
-rw-r--r--gdb/compile/compile.c4
-rw-r--r--gdb/corelow.c2
-rw-r--r--gdb/cp-namespace.c3
-rw-r--r--gdb/dbxread.c14
-rw-r--r--gdb/dictionary.c2
-rw-r--r--gdb/dwarf2-frame.c4
-rw-r--r--gdb/dwarf2read.c17
-rw-r--r--gdb/elfread.c2
-rw-r--r--gdb/gcore.c6
-rw-r--r--gdb/gdbserver/hostio.c12
-rw-r--r--gdb/gdbserver/linux-low.c4
-rw-r--r--gdb/gdbserver/linux-x86-low.c2
-rw-r--r--gdb/gdbserver/notif.c2
-rw-r--r--gdb/gdbserver/remote-utils.c6
-rw-r--r--gdb/gdbserver/server.c59
-rw-r--r--gdb/gdbserver/tracepoint.c63
-rw-r--r--gdb/gdbserver/win32-low.c2
-rw-r--r--gdb/gdbtypes.c4
-rw-r--r--gdb/gnu-v2-abi.c6
-rw-r--r--gdb/gnu-v3-abi.c6
-rw-r--r--gdb/go-lang.c4
-rw-r--r--gdb/guile/scm-type.c6
-rw-r--r--gdb/i386-cygwin-tdep.c2
-rw-r--r--gdb/i386-tdep.c7
-rw-r--r--gdb/i386obsd-tdep.c6
-rw-r--r--gdb/infcmd.c4
-rw-r--r--gdb/jv-typeprint.c4
-rw-r--r--gdb/linespec.c11
-rw-r--r--gdb/linux-nat.c8
-rw-r--r--gdb/m2-typeprint.c2
-rw-r--r--gdb/m32r-rom.c2
-rw-r--r--gdb/machoread.c2
-rw-r--r--gdb/macrocmd.c4
-rw-r--r--gdb/microblaze-rom.c4
-rw-r--r--gdb/minsyms.c2
-rw-r--r--gdb/mips-sde-tdep.c2
-rw-r--r--gdb/mips-tdep.c23
-rw-r--r--gdb/msp430-tdep.c3
-rw-r--r--gdb/nat/linux-procfs.c2
-rw-r--r--gdb/nbsd-tdep.c2
-rw-r--r--gdb/p-typeprint.c10
-rw-r--r--gdb/ppc-linux-tdep.c2
-rw-r--r--gdb/python/py-type.c6
-rw-r--r--gdb/regcache.c2
-rw-r--r--gdb/remote-m32r-sdi.c4
-rw-r--r--gdb/remote-notif.c2
-rw-r--r--gdb/remote.c25
-rw-r--r--gdb/reverse.c6
-rw-r--r--gdb/rs6000-tdep.c2
-rw-r--r--gdb/ser-tcp.c4
-rw-r--r--gdb/serial.c4
-rw-r--r--gdb/somread.c4
-rw-r--r--gdb/sparc64nbsd-tdep.c2
-rw-r--r--gdb/sparcnbsd-tdep.c2
-rw-r--r--gdb/symtab.c6
-rw-r--r--gdb/tracefile-tfile.c10
-rw-r--r--gdb/tracepoint.c6
-rw-r--r--gdb/tui/tui-data.c2
-rw-r--r--gdb/utils.c5
-rw-r--r--gdb/valops.c12
-rw-r--r--gdb/windows-nat.c8
-rw-r--r--gdb/xcoffread.c2
77 files changed, 309 insertions, 329 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index bfb584c..c7735f1 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2015-03-06 Gary Benson <gbenson@redhat.com>
+
+ * common/common-utils.h (startswith): New inline function.
+ All places where this logic was used updated to use the above.
+
2015-03-05 Pedro Alves <palves@redhat.com>
PR gdb/18002
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index b016723..1e70d12 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -596,7 +596,7 @@ field_name_match (const char *field_name, const char *target)
return
(strncmp (field_name, target, len) == 0
&& (field_name[len] == '\0'
- || (strncmp (field_name + len, "___", 3) == 0
+ || (startswith (field_name + len, "___")
&& strcmp (field_name + strlen (field_name) - 6,
"___XVN") != 0)));
}
@@ -1003,8 +1003,7 @@ ada_encode (const char *decoded)
for (mapping = ada_opname_table;
mapping->encoded != NULL
- && strncmp (mapping->decoded, p,
- strlen (mapping->decoded)) != 0; mapping += 1)
+ && !startswith (p, mapping->decoded); mapping += 1)
;
if (mapping->encoded == NULL)
error (_("invalid Ada operator name: %s"), p);
@@ -1085,9 +1084,9 @@ ada_remove_trailing_digits (const char *encoded, int *len)
*len = i;
else if (i >= 0 && encoded[i] == '$')
*len = i;
- else if (i >= 2 && strncmp (encoded + i - 2, "___", 3) == 0)
+ else if (i >= 2 && startswith (encoded + i - 2, "___"))
*len = i - 2;
- else if (i >= 1 && strncmp (encoded + i - 1, "__", 2) == 0)
+ else if (i >= 1 && startswith (encoded + i - 1, "__"))
*len = i - 1;
}
}
@@ -1156,7 +1155,7 @@ ada_decode (const char *encoded)
/* The name of the Ada main procedure starts with "_ada_".
This prefix is not part of the decoded name, so skip this part
if we see this prefix. */
- if (strncmp (encoded, "_ada_", 5) == 0)
+ if (startswith (encoded, "_ada_"))
encoded += 5;
/* If the name starts with '_', then it is not a properly encoded
@@ -1187,20 +1186,20 @@ ada_decode (const char *encoded)
is for the body of a task, but that information does not actually
appear in the decoded name. */
- if (len0 > 3 && strncmp (encoded + len0 - 3, "TKB", 3) == 0)
+ if (len0 > 3 && startswith (encoded + len0 - 3, "TKB"))
len0 -= 3;
/* Remove any trailing TB suffix. The TB suffix is slightly different
from the TKB suffix because it is used for non-anonymous task
bodies. */
- if (len0 > 2 && strncmp (encoded + len0 - 2, "TB", 2) == 0)
+ if (len0 > 2 && startswith (encoded + len0 - 2, "TB"))
len0 -= 2;
/* Remove trailing "B" suffixes. */
/* FIXME: brobecker/2006-04-19: Not sure what this are used for... */
- if (len0 > 1 && strncmp (encoded + len0 - 1, "B", 1) == 0)
+ if (len0 > 1 && startswith (encoded + len0 - 1, "B"))
len0 -= 1;
/* Make decoded big enough for possible expansion by operator name. */
@@ -1258,7 +1257,7 @@ ada_decode (const char *encoded)
/* Replace "TK__" with "__", which will eventually be translated
into "." (just below). */
- if (i < len0 - 4 && strncmp (encoded + i, "TK__", 4) == 0)
+ if (i < len0 - 4 && startswith (encoded + i, "TK__"))
i += 2;
/* Replace "__B_{DIGITS}+__" sequences by "__", which will eventually
@@ -1467,7 +1466,7 @@ match_name (const char *sym_name, const char *name, int wild)
return (strncmp (sym_name, name, len_name) == 0
&& is_name_suffix (sym_name + len_name))
- || (strncmp (sym_name, "_ada_", 5) == 0
+ || (startswith (sym_name, "_ada_")
&& strncmp (sym_name + 5, name, len_name) == 0
&& is_name_suffix (sym_name + len_name + 5));
}
@@ -4604,7 +4603,7 @@ lesseq_defined_than (struct symbol *sym0, struct symbol *sym1)
TYPE_CODE (type0) == TYPE_CODE (type1)
&& (equiv_types (type0, type1)
|| (len0 < strlen (name1) && strncmp (name0, name1, len0) == 0
- && strncmp (name1 + len0, "___XV", 5) == 0));
+ && startswith (name1 + len0, "___XV")));
}
case LOC_CONST:
return SYMBOL_VALUE (sym0) == SYMBOL_VALUE (sym1)
@@ -4700,7 +4699,7 @@ ada_lookup_simple_minsym (const char *name)
using, for instance, Standard.Constraint_Error when Constraint_Error
is ambiguous (due to the user defining its own Constraint_Error
entity inside its program). */
- if (strncmp (name, "standard__", sizeof ("standard__") - 1) == 0)
+ if (startswith (name, "standard__"))
name += sizeof ("standard__") - 1;
ALL_MSYMBOLS (objfile, msymbol)
@@ -5028,11 +5027,11 @@ old_renaming_is_invisible (const struct symbol *sym, const char *function_name)
a library-level function. Strip this prefix before doing the
comparison, as the encoding for the renaming does not contain
this prefix. */
- if (strncmp (function_name, "_ada_", 5) == 0)
+ if (startswith (function_name, "_ada_"))
function_name += 5;
{
- int is_invisible = strncmp (function_name, scope, strlen (scope)) != 0;
+ int is_invisible = !startswith (function_name, scope);
do_cleanups (old_chain);
return is_invisible;
@@ -5430,7 +5429,7 @@ ada_lookup_symbol_list_worker (const char *name0, const struct block *block0,
using, for instance, Standard.Constraint_Error when Constraint_Error
is ambiguous (due to the user defining its own Constraint_Error
entity inside its program). */
- if (strncmp (name0, "standard__", sizeof ("standard__") - 1) == 0)
+ if (startswith (name0, "standard__"))
{
block = NULL;
name = name0 + sizeof ("standard__") - 1;
@@ -5830,7 +5829,7 @@ advance_wild_match (const char **namep, const char *name0, int target0)
if ((t1 >= 'a' && t1 <= 'z') || (t1 >= '0' && t1 <= '9'))
{
name += 1;
- if (name == name0 + 5 && strncmp (name0, "_ada", 4) == 0)
+ if (name == name0 + 5 && startswith (name0, "_ada"))
break;
else
name += 1;
@@ -5984,7 +5983,7 @@ ada_add_block_symbols (struct obstack *obstackp,
cmp = (int) '_' - (int) SYMBOL_LINKAGE_NAME (sym)[0];
if (cmp == 0)
{
- cmp = strncmp ("_ada_", SYMBOL_LINKAGE_NAME (sym), 5);
+ cmp = !startswith (SYMBOL_LINKAGE_NAME (sym), "_ada_");
if (cmp == 0)
cmp = strncmp (name, SYMBOL_LINKAGE_NAME (sym) + 5,
name_len);
@@ -6371,7 +6370,7 @@ ada_is_ignored_field (struct type *type, int field_num)
for tagged types, and it contains the components inherited from
the parent type. This field should not be printed as is, but
should not be ignored either. */
- if (name[0] == '_' && strncmp (name, "_parent", 7) != 0)
+ if (name[0] == '_' && !startswith (name, "_parent"))
return 1;
}
@@ -6698,8 +6697,8 @@ ada_is_parent_field (struct type *type, int field_num)
const char *name = TYPE_FIELD_NAME (ada_check_typedef (type), field_num);
return (name != NULL
- && (strncmp (name, "PARENT", 6) == 0
- || strncmp (name, "_parent", 7) == 0));
+ && (startswith (name, "PARENT")
+ || startswith (name, "_parent")));
}
/* True iff field number FIELD_NUM of structure type TYPE is a
@@ -6714,9 +6713,9 @@ ada_is_wrapper_field (struct type *type, int field_num)
const char *name = TYPE_FIELD_NAME (type, field_num);
return (name != NULL
- && (strncmp (name, "PARENT", 6) == 0
+ && (startswith (name, "PARENT")
|| strcmp (name, "REP") == 0
- || strncmp (name, "_parent", 7) == 0
+ || startswith (name, "_parent")
|| name[0] == 'S' || name[0] == 'R' || name[0] == 'O'));
}
@@ -6787,7 +6786,7 @@ ada_variant_discrim_name (struct type *type0)
for (discrim_end = name + strlen (name) - 6; discrim_end != name;
discrim_end -= 1)
{
- if (strncmp (discrim_end, "___XVN", 6) == 0)
+ if (startswith (discrim_end, "___XVN"))
break;
}
if (discrim_end == name)
@@ -6799,7 +6798,7 @@ ada_variant_discrim_name (struct type *type0)
if (discrim_start == name + 1)
return "";
if ((discrim_start > name + 3
- && strncmp (discrim_start - 3, "___", 3) == 0)
+ && startswith (discrim_start - 3, "___"))
|| discrim_start[-1] == '.')
break;
}
@@ -7551,7 +7550,7 @@ field_alignment (struct type *type, int f)
else
align_offset = len - 1;
- if (align_offset < 7 || strncmp ("___XV", name + align_offset - 6, 5) != 0)
+ if (align_offset < 7 || !startswith (name + align_offset - 6, "___XV"))
return TARGET_CHAR_BIT;
return atoi (name + align_offset) * TARGET_CHAR_BIT;
@@ -12475,7 +12474,7 @@ catch_ada_exception_command_split (char *args,
/* Check to see if we have a condition. */
args = skip_spaces (args);
- if (strncmp (args, "if", 2) == 0
+ if (startswith (args, "if")
&& (isspace (args[2]) || args[2] == '\0'))
{
args += 2;
@@ -12736,7 +12735,7 @@ catch_ada_assert_command_split (char *args, char **cond_string)
args = skip_spaces (args);
/* Check whether a condition was provided. */
- if (strncmp (args, "if", 2) == 0
+ if (startswith (args, "if")
&& (isspace (args[2]) || args[2] == '\0'))
{
args += 2;
diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index e9de0f6..c768103 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -2378,8 +2378,7 @@ amd64_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
if (post_prologue_pc
&& (cust != NULL
&& COMPUNIT_PRODUCER (cust) != NULL
- && strncmp (COMPUNIT_PRODUCER (cust), "clang ",
- sizeof ("clang ") - 1) == 0))
+ && startswith (COMPUNIT_PRODUCER (cust), "clang ")))
return max (start_pc, post_prologue_pc);
}
diff --git a/gdb/amd64-windows-tdep.c b/gdb/amd64-windows-tdep.c
index 2aa10a1..de5d8c7 100644
--- a/gdb/amd64-windows-tdep.c
+++ b/gdb/amd64-windows-tdep.c
@@ -1157,8 +1157,8 @@ amd64_windows_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
if (symname)
{
- if (strncmp (symname, "__imp_", 6) == 0
- || strncmp (symname, "_imp_", 5) == 0)
+ if (startswith (symname, "__imp_")
+ || startswith (symname, "_imp_"))
destination
= read_memory_unsigned_integer (indirect_addr, 8, byte_order);
}
diff --git a/gdb/amd64obsd-tdep.c b/gdb/amd64obsd-tdep.c
index 04cd31f..d6c7e90 100644
--- a/gdb/amd64obsd-tdep.c
+++ b/gdb/amd64obsd-tdep.c
@@ -372,7 +372,7 @@ amd64obsd_trapframe_cache (struct frame_info *this_frame, void **this_cache)
sp = get_frame_register_unsigned (this_frame, AMD64_RSP_REGNUM);
find_pc_partial_function (func, &name, NULL, NULL);
- if (name && strncmp (name, "Xintr", 5) == 0)
+ if (name && startswith (name, "Xintr"))
addr = sp + 8; /* It's an interrupt frame. */
else
addr = sp;
@@ -436,7 +436,7 @@ amd64obsd_trapframe_sniffer (const struct frame_unwind *self,
return (name && ((strcmp (name, "calltrap") == 0)
|| (strcmp (name, "osyscall1") == 0)
|| (strcmp (name, "Xsyscall") == 0)
- || (strncmp (name, "Xintr", 5) == 0)));
+ || (startswith (name, "Xintr"))));
}
static const struct frame_unwind amd64obsd_trapframe_unwind = {
diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index 32d48a7..e1c8ab0 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -661,7 +661,7 @@ initialize_current_architecture (void)
chp = strchr (target_name, '-');
if (chp != NULL
&& chp - 2 >= target_name
- && strncmp (chp - 2, "el", 2) == 0)
+ && startswith (chp - 2, "el"))
default_byte_order = BFD_ENDIAN_LITTLE;
}
if (default_byte_order == BFD_ENDIAN_UNKNOWN)
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index d7cd6e5..630a207 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -484,15 +484,15 @@ skip_prologue_function (struct gdbarch *gdbarch, CORE_ADDR pc, int is_thumb)
/* On soft-float targets, __truncdfsf2 is called to convert promoted
arguments to their argument types in non-prototyped
functions. */
- if (strncmp (name, "__truncdfsf2", strlen ("__truncdfsf2")) == 0)
+ if (startswith (name, "__truncdfsf2"))
return 1;
- if (strncmp (name, "__aeabi_d2f", strlen ("__aeabi_d2f")) == 0)
+ if (startswith (name, "__aeabi_d2f"))
return 1;
/* Internal functions related to thread-local storage. */
- if (strncmp (name, "__tls_get_addr", strlen ("__tls_get_addr")) == 0)
+ if (startswith (name, "__tls_get_addr"))
return 1;
- if (strncmp (name, "__aeabi_read_tp", strlen ("__aeabi_read_tp")) == 0)
+ if (startswith (name, "__aeabi_read_tp"))
return 1;
}
else
@@ -1314,9 +1314,7 @@ arm_skip_stack_protector(CORE_ADDR pc, struct gdbarch *gdbarch)
/* ADDR must correspond to a symbol whose name is __stack_chk_guard.
Otherwise, this sequence cannot be for stack protector. */
if (stack_chk_guard.minsym == NULL
- || strncmp (MSYMBOL_LINKAGE_NAME (stack_chk_guard.minsym),
- "__stack_chk_guard",
- strlen ("__stack_chk_guard")) != 0)
+ || !startswith (MSYMBOL_LINKAGE_NAME (stack_chk_guard.minsym), "__stack_chk_guard"))
return pc;
if (is_thumb)
@@ -1413,10 +1411,8 @@ arm_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
if (post_prologue_pc
&& (cust == NULL
|| COMPUNIT_PRODUCER (cust) == NULL
- || strncmp (COMPUNIT_PRODUCER (cust), "GNU ",
- sizeof ("GNU ") - 1) == 0
- || strncmp (COMPUNIT_PRODUCER (cust), "clang ",
- sizeof ("clang ") - 1) == 0))
+ || startswith (COMPUNIT_PRODUCER (cust), "GNU ")
+ || startswith (COMPUNIT_PRODUCER (cust), "clang ")))
return post_prologue_pc;
if (post_prologue_pc != 0)
@@ -9315,8 +9311,8 @@ arm_skip_stub (struct frame_info *frame, CORE_ADDR pc)
_call_via_xx, where x is the register name. The possible names
are r0-r9, sl, fp, ip, sp, and lr. ARM RealView has similar
functions, named __ARM_call_via_r[0-7]. */
- if (strncmp (name, "_call_via_", 10) == 0
- || strncmp (name, "__ARM_call_via_", strlen ("__ARM_call_via_")) == 0)
+ if (startswith (name, "_call_via_")
+ || startswith (name, "__ARM_call_via_"))
{
/* Use the name suffix to determine which register contains the
target PC. */
@@ -9338,11 +9334,9 @@ arm_skip_stub (struct frame_info *frame, CORE_ADDR pc)
namelen = strlen (name);
if (name[0] == '_' && name[1] == '_'
&& ((namelen > 2 + strlen ("_from_thumb")
- && strncmp (name + namelen - strlen ("_from_thumb"), "_from_thumb",
- strlen ("_from_thumb")) == 0)
+ && startswith (name + namelen - strlen ("_from_thumb"), "_from_thumb"))
|| (namelen > 2 + strlen ("_from_arm")
- && strncmp (name + namelen - strlen ("_from_arm"), "_from_arm",
- strlen ("_from_arm")) == 0)))
+ && startswith (name + namelen - strlen ("_from_arm"), "_from_arm"))))
{
char *target_name;
int target_len = namelen - 2;
diff --git a/gdb/arm-wince-tdep.c b/gdb/arm-wince-tdep.c
index 206ff4f..72295ba 100644
--- a/gdb/arm-wince-tdep.c
+++ b/gdb/arm-wince-tdep.c
@@ -66,7 +66,7 @@ arm_pe_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
return 0;
symname = MSYMBOL_LINKAGE_NAME (indsym.minsym);
- if (symname == NULL || strncmp (symname, "__imp_", 6) != 0)
+ if (symname == NULL || !startswith (symname, "__imp_"))
return 0;
next_pc = read_memory_unsigned_integer (indirect, 4, byte_order);
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index c5d3240..d85f271 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -9729,7 +9729,7 @@ parse_breakpoint_sals (char **address,
/* If no arg given, or if first arg is 'if ', use the default
breakpoint. */
if ((*address) == NULL
- || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
+ || (startswith ((*address), "if") && isspace ((*address)[2])))
{
/* The last displayed codepoint, if it's valid, is our default breakpoint
address. */
@@ -11401,7 +11401,7 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
tok++;
toklen = end_tok - tok + 1;
- if (toklen == 6 && !strncmp (tok, "thread", 6))
+ if (toklen == 6 && startswith (tok, "thread"))
{
/* At this point we've found a "thread" token, which means
the user is trying to set a watchpoint that triggers
@@ -11423,7 +11423,7 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
if (!valid_thread_id (thread))
invalid_thread_id_error (thread);
}
- else if (toklen == 4 && !strncmp (tok, "mask", 4))
+ else if (toklen == 4 && startswith (tok, "mask"))
{
/* We've found a "mask" token, which means the user wants to
create a hardware watchpoint that is going to have the mask
@@ -15493,7 +15493,7 @@ strace_command (char *arg, int from_tty)
/* Decide if we are dealing with a static tracepoint marker (`-m'),
or with a normal static tracepoint. */
- if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2]))
+ if (arg && startswith (arg, "-m") && isspace (arg[2]))
ops = &strace_marker_breakpoint_ops;
else
ops = &tracepoint_breakpoint_ops;
diff --git a/gdb/bsd-uthread.c b/gdb/bsd-uthread.c
index 0a838ef..a5abb63 100644
--- a/gdb/bsd-uthread.c
+++ b/gdb/bsd-uthread.c
@@ -247,7 +247,7 @@ bsd_uthread_solib_loaded (struct so_list *so)
for (names = bsd_uthread_solib_names; *names; names++)
{
- if (strncmp (so->so_original_name, *names, strlen (*names)) == 0)
+ if (startswith (so->so_original_name, *names))
{
solib_read_symbols (so, 0);
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index 64279c8..421b720 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -544,7 +544,7 @@ is_type_conversion_operator (struct type *type, int i, int j)
some other way, feel free to rewrite this function. */
const char *name = TYPE_FN_FIELDLIST_NAME (type, i);
- if (strncmp (name, "operator", 8) != 0)
+ if (!startswith (name, "operator"))
return 0;
name += 8;
@@ -560,9 +560,9 @@ is_type_conversion_operator (struct type *type, int i, int j)
/* If this doesn't look like the start of an identifier, then it
isn't a type conversion operator. */
return 0;
- else if (strncmp (name, "new", 3) == 0)
+ else if (startswith (name, "new"))
name += 3;
- else if (strncmp (name, "delete", 6) == 0)
+ else if (startswith (name, "delete"))
name += 6;
else
/* If it doesn't look like new or delete, it's a type conversion
@@ -933,7 +933,7 @@ c_type_print_base (struct type *type, struct ui_file *stream,
enum}" tag for unnamed struct/union/enum's, which we don't
want to print. */
if (TYPE_TAG_NAME (type) != NULL
- && strncmp (TYPE_TAG_NAME (type), "{unnamed", 8))
+ && !startswith (TYPE_TAG_NAME (type), "{unnamed"))
{
/* When printing the tag name, we are still effectively
printing in the outer context, hence the use of FLAGS
@@ -1345,7 +1345,7 @@ c_type_print_base (struct type *type, struct ui_file *stream,
tag for unnamed struct/union/enum's, which we don't
want to print. */
if (TYPE_TAG_NAME (type) != NULL
- && strncmp (TYPE_TAG_NAME (type), "{unnamed", 8))
+ && !startswith (TYPE_TAG_NAME (type), "{unnamed"))
{
print_name_maybe_canonical (TYPE_TAG_NAME (type), flags, stream);
if (show > 0)
diff --git a/gdb/cli/cli-dump.c b/gdb/cli/cli-dump.c
index 481c3a2..0f9485f 100644
--- a/gdb/cli/cli-dump.c
+++ b/gdb/cli/cli-dump.c
@@ -575,7 +575,7 @@ restore_command (char *args_in, int from_tty)
char *binary_string = "binary";
/* Look for optional "binary" flag. */
- if (strncmp (args, binary_string, strlen (binary_string)) == 0)
+ if (startswith (args, binary_string))
{
binary_flag = 1;
args += strlen (binary_string);
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 65232da..010d661 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -800,7 +800,7 @@ locate_arg (char *p)
{
while ((p = strchr (p, '$')))
{
- if (strncmp (p, "$arg", 4) == 0
+ if (startswith (p, "$arg")
&& (isdigit (p[4]) || p[4] == 'c'))
return p;
p++;
@@ -988,7 +988,7 @@ process_next_line (char *p, struct command_line **command, int parse_commands,
/* 'end' is always recognized, regardless of parse_commands value.
We also permit whitespace before end and after. */
- if (p_end - p_start == 3 && !strncmp (p_start, "end", 3))
+ if (p_end - p_start == 3 && startswith (p_start, "end"))
return end_command;
if (parse_commands)
@@ -1005,14 +1005,14 @@ process_next_line (char *p, struct command_line **command, int parse_commands,
return nop_command;
/* Is the else clause of an if control structure? */
- if (p_end - p == 4 && !strncmp (p, "else", 4))
+ if (p_end - p == 4 && startswith (p, "else"))
return else_command;
/* Check for while, if, break, continue, etc and build a new
command line structure for them. */
- if ((p_end - p >= 14 && !strncmp (p, "while-stepping", 14))
- || (p_end - p >= 8 && !strncmp (p, "stepping", 8))
- || (p_end - p >= 2 && !strncmp (p, "ws", 2)))
+ if ((p_end - p >= 14 && startswith (p, "while-stepping"))
+ || (p_end - p >= 8 && startswith (p, "stepping"))
+ || (p_end - p >= 2 && startswith (p, "ws")))
{
/* Because validate_actionline and encode_action lookup
command's line as command, we need the line to
@@ -1027,7 +1027,7 @@ process_next_line (char *p, struct command_line **command, int parse_commands,
not. */
*command = build_command_line (while_stepping_control, p);
}
- else if (p_end - p > 5 && !strncmp (p, "while", 5))
+ else if (p_end - p > 5 && startswith (p, "while"))
{
char *first_arg;
@@ -1036,7 +1036,7 @@ process_next_line (char *p, struct command_line **command, int parse_commands,
first_arg++;
*command = build_command_line (while_control, first_arg);
}
- else if (p_end - p > 2 && !strncmp (p, "if", 2))
+ else if (p_end - p > 2 && startswith (p, "if"))
{
char *first_arg;
@@ -1045,7 +1045,7 @@ process_next_line (char *p, struct command_line **command, int parse_commands,
first_arg++;
*command = build_command_line (if_control, first_arg);
}
- else if (p_end - p >= 8 && !strncmp (p, "commands", 8))
+ else if (p_end - p >= 8 && startswith (p, "commands"))
{
char *first_arg;
@@ -1054,13 +1054,13 @@ process_next_line (char *p, struct command_line **command, int parse_commands,
first_arg++;
*command = build_command_line (commands_control, first_arg);
}
- else if (p_end - p == 6 && !strncmp (p, "python", 6))
+ else if (p_end - p == 6 && startswith (p, "python"))
{
/* Note that we ignore the inline "python command" form
here. */
*command = build_command_line (python_control, "");
}
- else if (p_end - p == 6 && !strncmp (p, "compile", 7))
+ else if (p_end - p == 6 && startswith (p, "compile"))
{
/* Note that we ignore the inline "compile command" form
here. */
@@ -1068,12 +1068,12 @@ process_next_line (char *p, struct command_line **command, int parse_commands,
(*command)->control_u.compile.scope = COMPILE_I_INVALID_SCOPE;
}
- else if (p_end - p == 5 && !strncmp (p, "guile", 5))
+ else if (p_end - p == 5 && startswith (p, "guile"))
{
/* Note that we ignore the inline "guile command" form here. */
*command = build_command_line (guile_control, "");
}
- else if (p_end - p == 10 && !strncmp (p, "loop_break", 10))
+ else if (p_end - p == 10 && startswith (p, "loop_break"))
{
*command = (struct command_line *)
xmalloc (sizeof (struct command_line));
@@ -1083,7 +1083,7 @@ process_next_line (char *p, struct command_line **command, int parse_commands,
(*command)->body_count = 0;
(*command)->body_list = NULL;
}
- else if (p_end - p == 13 && !strncmp (p, "loop_continue", 13))
+ else if (p_end - p == 13 && startswith (p, "loop_continue"))
{
*command = (struct command_line *)
xmalloc (sizeof (struct command_line));
diff --git a/gdb/coffread.c b/gdb/coffread.c
index 366d828..28f7b18 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -231,7 +231,7 @@ coff_locate_sections (bfd *abfd, asection *sectp, void *csip)
csi->textaddr = bfd_section_vma (abfd, sectp);
csi->textsize += bfd_section_size (abfd, sectp);
}
- else if (strncmp (name, ".text", sizeof ".text" - 1) == 0)
+ else if (startswith (name, ".text"))
{
csi->textsize += bfd_section_size (abfd, sectp);
}
@@ -239,7 +239,7 @@ coff_locate_sections (bfd *abfd, asection *sectp, void *csip)
{
csi->stabstrsect = sectp;
}
- else if (strncmp (name, ".stab", sizeof ".stab" - 1) == 0)
+ else if (startswith (name, ".stab"))
{
const char *s;
@@ -448,7 +448,7 @@ is_import_fixup_symbol (struct coff_symbol *cs,
return 0;
/* The name must start with "__fu<digits>__". */
- if (strncmp (cs->c_name, "__fu", 4) != 0)
+ if (!startswith (cs->c_name, "__fu"))
return 0;
if (! isdigit (cs->c_name[4]))
return 0;
@@ -605,8 +605,8 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags)
FIXME: We should use BFD to read the symbol table, and thus avoid
this problem. */
pe_file =
- strncmp (bfd_get_target (objfile->obfd), "pe", 2) == 0
- || strncmp (bfd_get_target (objfile->obfd), "epoc-pe", 7) == 0;
+ startswith (bfd_get_target (objfile->obfd), "pe")
+ || startswith (bfd_get_target (objfile->obfd), "epoc-pe");
/* End of warning. */
@@ -672,8 +672,8 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags)
symbol in OBJFILE. Note that 'maintenance print msymbols'
shows that type of these "_imp_XXXX" symbols is mst_data. */
if (MSYMBOL_TYPE (msym) == mst_data
- && (strncmp (name, "__imp_", 6) == 0
- || strncmp (name, "_imp_", 5) == 0))
+ && (startswith (name, "__imp_")
+ || startswith (name, "_imp_")))
{
const char *name1 = (name[1] == '_' ? &name[7] : &name[6]);
struct bound_minimal_symbol found;
@@ -946,14 +946,14 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms,
}
else if (!SDB_TYPE (cs->c_type)
&& cs->c_name[0] == 'L'
- && (strncmp (cs->c_name, "LI%", 3) == 0
- || strncmp (cs->c_name, "LF%", 3) == 0
- || strncmp (cs->c_name, "LC%", 3) == 0
- || strncmp (cs->c_name, "LP%", 3) == 0
- || strncmp (cs->c_name, "LPB%", 4) == 0
- || strncmp (cs->c_name, "LBB%", 4) == 0
- || strncmp (cs->c_name, "LBE%", 4) == 0
- || strncmp (cs->c_name, "LPBX%", 5) == 0))
+ && (startswith (cs->c_name, "LI%")
+ || startswith (cs->c_name, "LF%")
+ || startswith (cs->c_name, "LC%")
+ || startswith (cs->c_name, "LP%")
+ || startswith (cs->c_name, "LPB%")
+ || startswith (cs->c_name, "LBB%")
+ || startswith (cs->c_name, "LBE%")
+ || startswith (cs->c_name, "LPBX%")))
/* At least on a 3b1, gcc generates swbeg and string labels
that look like this. Ignore them. */
break;
diff --git a/gdb/common/common-utils.h b/gdb/common/common-utils.h
index 60aa030..cd2665a 100644
--- a/gdb/common/common-utils.h
+++ b/gdb/common/common-utils.h
@@ -68,4 +68,13 @@ char *savestring (const char *ptr, size_t len);
extern char *safe_strerror (int);
+/* Return non-zero if the start of STRING matches PATTERN, zero
+ otherwise. */
+
+static inline int
+startswith (const char *string, const char *pattern)
+{
+ return strncmp (string, pattern, strlen (pattern)) == 0;
+}
+
#endif
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index c204a13..1d342a0 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -172,7 +172,7 @@ do_rmdir (void *arg)
char *zap;
int wstat;
- gdb_assert (strncmp (dir, TMP_PREFIX, strlen (TMP_PREFIX)) == 0);
+ gdb_assert (startswith (dir, TMP_PREFIX));
zap = concat ("rm -rf ", dir, (char *) NULL);
wstat = system (zap);
if (wstat == -1 || !WIFEXITED (wstat) || WEXITSTATUS (wstat) != 0)
@@ -313,7 +313,7 @@ get_selected_pc_producer_options (void)
const char *cs;
if (symtab == NULL || symtab->producer == NULL
- || strncmp (symtab->producer, "GNU ", strlen ("GNU ")) != 0)
+ || !startswith (symtab->producer, "GNU "))
return NULL;
cs = symtab->producer;
diff --git a/gdb/corelow.c b/gdb/corelow.c
index c7d4318..65e1326 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -234,7 +234,7 @@ add_to_thread_list (bfd *abfd, asection *asect, void *reg_sect_arg)
int fake_pid_p = 0;
struct inferior *inf;
- if (strncmp (bfd_section_name (abfd, asect), ".reg/", 5) != 0)
+ if (!startswith (bfd_section_name (abfd, asect), ".reg/"))
return;
core_tid = atoi (bfd_section_name (abfd, asect) + 5);
diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c
index 4f68432..4a00cb6 100644
--- a/gdb/cp-namespace.c
+++ b/gdb/cp-namespace.c
@@ -497,8 +497,7 @@ cp_lookup_symbol_via_imports (const char *scope,
len = strlen (current->import_dest);
directive_match = (search_parents
- ? (strncmp (scope, current->import_dest,
- strlen (current->import_dest)) == 0
+ ? (startswith (scope, current->import_dest)
&& (len == 0
|| scope[len] == ':'
|| scope[len] == '\0'))
diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index 4f60e10..c8f974f 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -539,12 +539,12 @@ dbx_symfile_read (struct objfile *objfile, int symfile_flags)
differently from Solaris), and false for SunOS4 and other a.out
file formats. */
block_address_function_relative =
- ((0 == strncmp (bfd_get_target (sym_bfd), "elf", 3))
- || (0 == strncmp (bfd_get_target (sym_bfd), "som", 3))
- || (0 == strncmp (bfd_get_target (sym_bfd), "coff", 4))
- || (0 == strncmp (bfd_get_target (sym_bfd), "pe", 2))
- || (0 == strncmp (bfd_get_target (sym_bfd), "epoc-pe", 7))
- || (0 == strncmp (bfd_get_target (sym_bfd), "nlm", 3)));
+ ((startswith (bfd_get_target (sym_bfd), "elf"))
+ || (startswith (bfd_get_target (sym_bfd), "som"))
+ || (startswith (bfd_get_target (sym_bfd), "coff"))
+ || (startswith (bfd_get_target (sym_bfd), "pe"))
+ || (startswith (bfd_get_target (sym_bfd), "epoc-pe"))
+ || (startswith (bfd_get_target (sym_bfd), "nlm")));
val = bfd_seek (sym_bfd, DBX_SYMTAB_OFFSET (objfile), SEEK_SET);
if (val < 0)
@@ -2547,7 +2547,7 @@ read_ofile_symtab (struct objfile *objfile, struct partial_symtab *pst)
processing_gcc_compilation = 2;
if (tempstring[0] == bfd_get_symbol_leading_char (symfile_bfd))
++tempstring;
- if (strncmp (tempstring, "__gnu_compiled", 14) == 0)
+ if (startswith (tempstring, "__gnu_compiled"))
processing_gcc_compilation = 2;
}
}
diff --git a/gdb/dictionary.c b/gdb/dictionary.c
index 2c81182..a16955a 100644
--- a/gdb/dictionary.c
+++ b/gdb/dictionary.c
@@ -806,7 +806,7 @@ dict_hash (const char *string0)
string = string0;
if (*string == '_')
{
- if (strncmp (string, "_ada_", 5) == 0)
+ if (startswith (string, "_ada_"))
string += 5;
else
return msymbol_hash_iw (string0);
diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2-frame.c
index 71e3f6b..b648aa3 100644
--- a/gdb/dwarf2-frame.c
+++ b/gdb/dwarf2-frame.c
@@ -878,7 +878,7 @@ dwarf2_frame_find_quirks (struct dwarf2_frame_state *fs,
this problem is fixed (no quirk needed). If the armcc
augmentation is missing, the quirk is needed. */
if (fde->cie->version == 3
- && (strncmp (fde->cie->augmentation, "armcc", 5) != 0
+ && (!startswith (fde->cie->augmentation, "armcc")
|| strchr (fde->cie->augmentation + 5, '+') == NULL))
fs->armcc_cfa_offsets_reversed = 1;
@@ -1935,7 +1935,7 @@ decode_frame_entry_1 (struct comp_unit *unit, const gdb_byte *start,
/* Ignore armcc augmentations. We only use them for quirks,
and that doesn't happen until later. */
- if (strncmp (augmentation, "armcc", 5) == 0)
+ if (startswith (augmentation, "armcc"))
augmentation += strlen (augmentation);
/* The GCC 2.x "eh" augmentation has a pointer immediately
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 071f97b..a283cba 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -12306,7 +12306,7 @@ check_producer (struct dwarf2_cu *cu)
cu->producer_is_gxx_lt_4_6 = major < 4 || (major == 4 && minor < 6);
cu->producer_is_gcc_lt_4_3 = major < 4 || (major == 4 && minor < 3);
}
- else if (strncmp (cu->producer, "Intel(R) C", strlen ("Intel(R) C")) == 0)
+ else if (startswith (cu->producer, "Intel(R) C"))
cu->producer_is_icc = 1;
else
{
@@ -12987,8 +12987,8 @@ is_vtable_name (const char *name, struct dwarf2_cu *cu)
/* Look for the C++ and Java forms of the vtable. */
if ((cu->language == language_java
- && strncmp (name, vtable, sizeof (vtable) - 1) == 0)
- || (strncmp (name, vptr, sizeof (vptr) - 1) == 0
+ && startswith (name, vtable))
+ || (startswith (name, vptr)
&& is_cplus_marker (name[sizeof (vptr) - 1])))
return 1;
@@ -13296,8 +13296,7 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
}
}
else if (cu->producer
- && strncmp (cu->producer,
- "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
+ && startswith (cu->producer, "IBM(R) XL C/C++ Advanced Edition"))
{
/* The IBM XLC compiler does not provide direct indication
of the containing type, but the vtable pointer is
@@ -14695,7 +14694,7 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
type_flags |= TYPE_FLAG_UNSIGNED;
if (cu->language == language_fortran
&& name
- && strncmp (name, "character(", sizeof ("character(") - 1) == 0)
+ && startswith (name, "character("))
code = TYPE_CODE_CHAR;
break;
case DW_ATE_signed_char:
@@ -18262,7 +18261,7 @@ new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
if (cu->language == language_fortran && die->parent
&& die->parent->tag == DW_TAG_module
&& cu->producer
- && strncmp (cu->producer, "GNU Fortran ", 12) == 0)
+ && startswith (cu->producer, "GNU Fortran "))
SYMBOL_ACLASS_INDEX (sym) = LOC_UNRESOLVED;
/* A variable with DW_AT_external is never static,
@@ -19339,8 +19338,8 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
and GCC 4.4. We work around this problem by ignoring these. */
if (attr && DW_STRING (attr)
- && (strncmp (DW_STRING (attr), "._", 2) == 0
- || strncmp (DW_STRING (attr), "<anonymous", 10) == 0))
+ && (startswith (DW_STRING (attr), "._")
+ || startswith (DW_STRING (attr), "<anonymous")))
return NULL;
/* GCC might emit a nameless typedef that has a linkage name. See
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 4a6576f..4b97b04 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -322,7 +322,7 @@ elf_symtab_read (struct objfile *objfile, int type,
for that section is ".plt". So, if there is a ".plt"
section, and yet the section name of our symbol does not
start with ".plt", we ignore that symbol. */
- if (strncmp (sect->name, ".plt", 4) != 0
+ if (!startswith (sect->name, ".plt")
&& bfd_get_section_by_name (abfd, ".plt") != NULL)
continue;
diff --git a/gdb/gcore.c b/gdb/gcore.c
index 1ebff2a..3e05c61 100644
--- a/gdb/gcore.c
+++ b/gdb/gcore.c
@@ -387,9 +387,9 @@ make_output_phdrs (bfd *obfd, asection *osec, void *ignored)
int p_type = 0;
/* FIXME: these constants may only be applicable for ELF. */
- if (strncmp (bfd_section_name (obfd, osec), "load", 4) == 0)
+ if (startswith (bfd_section_name (obfd, osec), "load"))
p_type = PT_LOAD;
- else if (strncmp (bfd_section_name (obfd, osec), "note", 4) == 0)
+ else if (startswith (bfd_section_name (obfd, osec), "note"))
p_type = PT_NOTE;
else
p_type = PT_NULL;
@@ -562,7 +562,7 @@ gcore_copy_callback (bfd *obfd, asection *osec, void *ignored)
return;
/* Only interested in "load" sections. */
- if (strncmp ("load", bfd_section_name (obfd, osec), 4) != 0)
+ if (!startswith (bfd_section_name (obfd, osec), "load"))
return;
size = min (total_size, MAX_COPY_BYTES);
diff --git a/gdb/gdbserver/hostio.c b/gdb/gdbserver/hostio.c
index e6b7754..ec29eb9 100644
--- a/gdb/gdbserver/hostio.c
+++ b/gdb/gdbserver/hostio.c
@@ -511,17 +511,17 @@ handle_readlink (char *own_buf, int *new_packet_len)
int
handle_vFile (char *own_buf, int packet_len, int *new_packet_len)
{
- if (strncmp (own_buf, "vFile:open:", 11) == 0)
+ if (startswith (own_buf, "vFile:open:"))
handle_open (own_buf);
- else if (strncmp (own_buf, "vFile:pread:", 12) == 0)
+ else if (startswith (own_buf, "vFile:pread:"))
handle_pread (own_buf, new_packet_len);
- else if (strncmp (own_buf, "vFile:pwrite:", 13) == 0)
+ else if (startswith (own_buf, "vFile:pwrite:"))
handle_pwrite (own_buf, packet_len);
- else if (strncmp (own_buf, "vFile:close:", 12) == 0)
+ else if (startswith (own_buf, "vFile:close:"))
handle_close (own_buf);
- else if (strncmp (own_buf, "vFile:unlink:", 13) == 0)
+ else if (startswith (own_buf, "vFile:unlink:"))
handle_unlink (own_buf);
- else if (strncmp (own_buf, "vFile:readlink:", 15) == 0)
+ else if (startswith (own_buf, "vFile:readlink:"))
handle_readlink (own_buf, new_packet_len);
else
return 0;
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 4da11c6..48d905b 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -5903,9 +5903,9 @@ linux_qxfer_libraries_svr4 (const char *annex, unsigned char *readbuf,
break;
len = sep - annex;
- if (len == 5 && strncmp (annex, "start", 5) == 0)
+ if (len == 5 && startswith (annex, "start"))
addrp = &lm_addr;
- else if (len == 4 && strncmp (annex, "prev", 4) == 0)
+ else if (len == 4 && startswith (annex, "prev"))
addrp = &lm_prev;
else
{
diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c
index 3a10e61..72478d8 100644
--- a/gdb/gdbserver/linux-x86-low.c
+++ b/gdb/gdbserver/linux-x86-low.c
@@ -1523,7 +1523,7 @@ x86_linux_process_qsupported (const char *query)
with "i386" in qSupported query, it supports x86 XML target
descriptions. */
use_xml = 0;
- if (query != NULL && strncmp (query, "xmlRegisters=", 13) == 0)
+ if (query != NULL && startswith (query, "xmlRegisters="))
{
char *copy = xstrdup (query + 13);
char *p;
diff --git a/gdb/gdbserver/notif.c b/gdb/gdbserver/notif.c
index ba2af77..436c1b8 100644
--- a/gdb/gdbserver/notif.c
+++ b/gdb/gdbserver/notif.c
@@ -86,7 +86,7 @@ handle_notif_ack (char *own_buf, int packet_len)
{
const char *ack_name = notifs[i]->ack_name;
- if (strncmp (own_buf, ack_name, strlen (ack_name)) == 0
+ if (startswith (own_buf, ack_name)
&& packet_len == strlen (ack_name))
break;
}
diff --git a/gdb/gdbserver/remote-utils.c b/gdb/gdbserver/remote-utils.c
index 02c40f5..1de86be 100644
--- a/gdb/gdbserver/remote-utils.c
+++ b/gdb/gdbserver/remote-utils.c
@@ -531,7 +531,7 @@ hex_or_minus_one (char *buf, char **obuf)
{
ULONGEST ret;
- if (strncmp (buf, "-1", 2) == 0)
+ if (startswith (buf, "-1"))
{
ret = (ULONGEST) -1;
buf += 2;
@@ -1447,7 +1447,7 @@ look_up_one_symbol (const char *name, CORE_ADDR *addrp, int may_ask_gdb)
return -1;
}
- if (strncmp (own_buf, "qSymbol:", strlen ("qSymbol:")) != 0)
+ if (!startswith (own_buf, "qSymbol:"))
{
warning ("Malformed response to qSymbol, ignoring: %s\n", own_buf);
return -1;
@@ -1556,7 +1556,7 @@ relocate_instruction (CORE_ADDR *to, CORE_ADDR oldloc)
return -1;
}
- if (strncmp (own_buf, "qRelocInsn:", strlen ("qRelocInsn:")) != 0)
+ if (!startswith (own_buf, "qRelocInsn:"))
{
warning ("Malformed response to qRelocInsn, ignoring: %s\n",
own_buf);
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index 83529ff..4189877 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -429,7 +429,7 @@ handle_btrace_general_set (char *own_buf)
const char *err;
char *op;
- if (strncmp ("Qbtrace:", own_buf, strlen ("Qbtrace:")) != 0)
+ if (!startswith (own_buf, "Qbtrace:"))
return 0;
op = own_buf + strlen ("Qbtrace:");
@@ -473,7 +473,7 @@ handle_btrace_conf_general_set (char *own_buf)
struct thread_info *thread;
char *op;
- if (strncmp ("Qbtrace-conf:", own_buf, strlen ("Qbtrace-conf:")) != 0)
+ if (!startswith (own_buf, "Qbtrace-conf:"))
return 0;
op = own_buf + strlen ("Qbtrace-conf:");
@@ -492,7 +492,7 @@ handle_btrace_conf_general_set (char *own_buf)
return -1;
}
- if (strncmp (op, "bts:size=", strlen ("bts:size=")) == 0)
+ if (startswith (op, "bts:size="))
{
unsigned long size;
char *endp = NULL;
@@ -522,7 +522,7 @@ handle_btrace_conf_general_set (char *own_buf)
static void
handle_general_set (char *own_buf)
{
- if (strncmp ("QPassSignals:", own_buf, strlen ("QPassSignals:")) == 0)
+ if (startswith (own_buf, "QPassSignals:"))
{
int numsigs = (int) GDB_SIGNAL_LAST, i;
const char *p = own_buf + strlen ("QPassSignals:");
@@ -547,7 +547,7 @@ handle_general_set (char *own_buf)
return;
}
- if (strncmp ("QProgramSignals:", own_buf, strlen ("QProgramSignals:")) == 0)
+ if (startswith (own_buf, "QProgramSignals:"))
{
int numsigs = (int) GDB_SIGNAL_LAST, i;
const char *p = own_buf + strlen ("QProgramSignals:");
@@ -587,7 +587,7 @@ handle_general_set (char *own_buf)
return;
}
- if (strncmp (own_buf, "QNonStop:", 9) == 0)
+ if (startswith (own_buf, "QNonStop:"))
{
char *mode = own_buf + 9;
int req = -1;
@@ -624,8 +624,7 @@ handle_general_set (char *own_buf)
return;
}
- if (strncmp ("QDisableRandomization:", own_buf,
- strlen ("QDisableRandomization:")) == 0)
+ if (startswith (own_buf, "QDisableRandomization:"))
{
char *packet = own_buf + strlen ("QDisableRandomization:");
ULONGEST setting;
@@ -649,7 +648,7 @@ handle_general_set (char *own_buf)
&& handle_tracepoint_general_set (own_buf))
return;
- if (strncmp ("QAgent:", own_buf, strlen ("QAgent:")) == 0)
+ if (startswith (own_buf, "QAgent:"))
{
char *mode = own_buf + strlen ("QAgent:");
int req = 0;
@@ -1072,8 +1071,7 @@ handle_monitor_command (char *mon, char *own_buf)
remote_debug = 0;
monitor_output ("Protocol debug output disabled.\n");
}
- else if (strncmp (mon, "set debug-format ",
- sizeof ("set debug-format ") - 1) == 0)
+ else if (startswith (mon, "set debug-format "))
{
char *error_msg
= parse_debug_format_options (mon + sizeof ("set debug-format ") - 1,
@@ -1661,7 +1659,7 @@ handle_qxfer (char *own_buf, int packet_len, int *new_packet_len_p)
char *annex;
char *offset;
- if (strncmp (own_buf, "qXfer:", 6) != 0)
+ if (!startswith (own_buf, "qXfer:"))
return 0;
/* Grab the object, r/w and annex. */
@@ -1935,7 +1933,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
}
/* Protocol features query. */
- if (strncmp ("qSupported", own_buf, 10) == 0
+ if (startswith (own_buf, "qSupported")
&& (own_buf[10] == ':' || own_buf[10] == '\0'))
{
char *p = &own_buf[10];
@@ -2089,7 +2087,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
/* Thread-local storage support. */
if (the_target->get_tls_address != NULL
- && strncmp ("qGetTLSAddr:", own_buf, 12) == 0)
+ && startswith (own_buf, "qGetTLSAddr:"))
{
char *p = own_buf + 12;
CORE_ADDR parts[2], address = 0;
@@ -2154,7 +2152,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
/* Windows OS Thread Information Block address support. */
if (the_target->get_tib_address != NULL
- && strncmp ("qGetTIBAddr:", own_buf, 12) == 0)
+ && startswith (own_buf, "qGetTIBAddr:"))
{
char *annex;
int n;
@@ -2176,7 +2174,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
}
/* Handle "monitor" commands. */
- if (strncmp ("qRcmd,", own_buf, 6) == 0)
+ if (startswith (own_buf, "qRcmd,"))
{
char *mon = malloc (PBUFSIZ);
int len = strlen (own_buf + 6);
@@ -2207,8 +2205,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
return;
}
- if (strncmp ("qSearch:memory:", own_buf,
- sizeof ("qSearch:memory:") - 1) == 0)
+ if (startswith (own_buf, "qSearch:memory:"))
{
require_running (own_buf);
handle_search_memory (own_buf, packet_len);
@@ -2216,7 +2213,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
}
if (strcmp (own_buf, "qAttached") == 0
- || strncmp (own_buf, "qAttached:", sizeof ("qAttached:") - 1) == 0)
+ || startswith (own_buf, "qAttached:"))
{
struct process_info *process;
@@ -2242,7 +2239,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
return;
}
- if (strncmp ("qCRC:", own_buf, 5) == 0)
+ if (startswith (own_buf, "qCRC:"))
{
/* CRC check (compare-section). */
char *comma;
@@ -2672,14 +2669,14 @@ handle_v_requests (char *own_buf, int packet_len, int *new_packet_len)
{
if (!disable_packet_vCont)
{
- if (strncmp (own_buf, "vCont;", 6) == 0)
+ if (startswith (own_buf, "vCont;"))
{
require_running (own_buf);
handle_v_cont (own_buf);
return;
}
- if (strncmp (own_buf, "vCont?", 6) == 0)
+ if (startswith (own_buf, "vCont?"))
{
strcpy (own_buf, "vCont;c;C;s;S;t");
if (target_supports_range_stepping ())
@@ -2691,11 +2688,11 @@ handle_v_requests (char *own_buf, int packet_len, int *new_packet_len)
}
}
- if (strncmp (own_buf, "vFile:", 6) == 0
+ if (startswith (own_buf, "vFile:")
&& handle_vFile (own_buf, packet_len, new_packet_len))
return;
- if (strncmp (own_buf, "vAttach;", 8) == 0)
+ if (startswith (own_buf, "vAttach;"))
{
if ((!extended_protocol || !multi_process) && target_running ())
{
@@ -2707,7 +2704,7 @@ handle_v_requests (char *own_buf, int packet_len, int *new_packet_len)
return;
}
- if (strncmp (own_buf, "vRun;", 5) == 0)
+ if (startswith (own_buf, "vRun;"))
{
if ((!extended_protocol || !multi_process) && target_running ())
{
@@ -2719,7 +2716,7 @@ handle_v_requests (char *own_buf, int packet_len, int *new_packet_len)
return;
}
- if (strncmp (own_buf, "vKill;", 6) == 0)
+ if (startswith (own_buf, "vKill;"))
{
if (!target_running ())
{
@@ -3211,9 +3208,7 @@ captured_main (int argc, char *argv[])
}
else if (strcmp (*next_arg, "--debug") == 0)
debug_threads = 1;
- else if (strncmp (*next_arg,
- "--debug-format=",
- sizeof ("--debug-format=") - 1) == 0)
+ else if (startswith (*next_arg, "--debug-format="))
{
char *error_msg
= parse_debug_format_options ((*next_arg)
@@ -3232,9 +3227,7 @@ captured_main (int argc, char *argv[])
gdbserver_show_disableable (stdout);
exit (0);
}
- else if (strncmp (*next_arg,
- "--disable-packet=",
- sizeof ("--disable-packet=") - 1) == 0)
+ else if (startswith (*next_arg, "--disable-packet="))
{
char *packets, *tok;
@@ -3533,7 +3526,7 @@ process_point_options (struct breakpoint *bp, char **packet)
if (!add_breakpoint_condition (bp, &dataptr))
skip_to_semicolon (&dataptr);
}
- else if (strncmp (dataptr, "cmds:", strlen ("cmds:")) == 0)
+ else if (startswith (dataptr, "cmds:"))
{
dataptr += strlen ("cmds:");
if (debug_threads)
diff --git a/gdb/gdbserver/tracepoint.c b/gdb/gdbserver/tracepoint.c
index 6fcd0b0..27fcf03 100644
--- a/gdb/gdbserver/tracepoint.c
+++ b/gdb/gdbserver/tracepoint.c
@@ -3551,14 +3551,14 @@ cmd_qtframe (char *own_buf)
packet += strlen ("QTFrame:");
- if (strncmp (packet, "pc:", strlen ("pc:")) == 0)
+ if (startswith (packet, "pc:"))
{
packet += strlen ("pc:");
unpack_varlen_hex (packet, &pc);
trace_debug ("Want to find next traceframe at pc=0x%s", paddress (pc));
tframe = find_next_traceframe_in_range (pc, pc, 1, &tfnum);
}
- else if (strncmp (packet, "range:", strlen ("range:")) == 0)
+ else if (startswith (packet, "range:"))
{
packet += strlen ("range:");
packet = unpack_varlen_hex (packet, &lo);
@@ -3568,7 +3568,7 @@ cmd_qtframe (char *own_buf)
paddress (lo), paddress (hi));
tframe = find_next_traceframe_in_range (lo, hi, 1, &tfnum);
}
- else if (strncmp (packet, "outside:", strlen ("outside:")) == 0)
+ else if (startswith (packet, "outside:"))
{
packet += strlen ("outside:");
packet = unpack_varlen_hex (packet, &lo);
@@ -3579,7 +3579,7 @@ cmd_qtframe (char *own_buf)
paddress (lo), paddress (hi));
tframe = find_next_traceframe_in_range (lo, hi, 0, &tfnum);
}
- else if (strncmp (packet, "tdp:", strlen ("tdp:")) == 0)
+ else if (startswith (packet, "tdp:"))
{
packet += strlen ("tdp:");
unpack_varlen_hex (packet, &num);
@@ -3653,7 +3653,7 @@ cmd_qtstatus (char *packet)
/* The user visible error string in terror needs to be hex encoded.
We leave it as plain string in `tracing_stop_reason' to ease
debugging. */
- if (strncmp (stop_reason_rsp, "terror:", strlen ("terror:")) == 0)
+ if (startswith (stop_reason_rsp, "terror:"))
{
const char *result_name;
int hexstr_len;
@@ -4106,7 +4106,7 @@ cmd_qtnotes (char *own_buf)
while (*packet)
{
- if (strncmp ("user:", packet, strlen ("user:")) == 0)
+ if (startswith (packet, "user:"))
{
packet += strlen ("user:");
saved = packet;
@@ -4120,7 +4120,7 @@ cmd_qtnotes (char *own_buf)
xfree (tracing_user_name);
tracing_user_name = user;
}
- else if (strncmp ("notes:", packet, strlen ("notes:")) == 0)
+ else if (startswith (packet, "notes:"))
{
packet += strlen ("notes:");
saved = packet;
@@ -4134,7 +4134,7 @@ cmd_qtnotes (char *own_buf)
xfree (tracing_notes);
tracing_notes = notes;
}
- else if (strncmp ("tstop:", packet, strlen ("tstop:")) == 0)
+ else if (startswith (packet, "tstop:"))
{
packet += strlen ("tstop:");
saved = packet;
@@ -4163,32 +4163,32 @@ handle_tracepoint_general_set (char *packet)
cmd_qtinit (packet);
return 1;
}
- else if (strncmp ("QTDP:", packet, strlen ("QTDP:")) == 0)
+ else if (startswith (packet, "QTDP:"))
{
cmd_qtdp (packet);
return 1;
}
- else if (strncmp ("QTDPsrc:", packet, strlen ("QTDPsrc:")) == 0)
+ else if (startswith (packet, "QTDPsrc:"))
{
cmd_qtdpsrc (packet);
return 1;
}
- else if (strncmp ("QTEnable:", packet, strlen ("QTEnable:")) == 0)
+ else if (startswith (packet, "QTEnable:"))
{
cmd_qtenable_disable (packet, 1);
return 1;
}
- else if (strncmp ("QTDisable:", packet, strlen ("QTDisable:")) == 0)
+ else if (startswith (packet, "QTDisable:"))
{
cmd_qtenable_disable (packet, 0);
return 1;
}
- else if (strncmp ("QTDV:", packet, strlen ("QTDV:")) == 0)
+ else if (startswith (packet, "QTDV:"))
{
cmd_qtdv (packet);
return 1;
}
- else if (strncmp ("QTro:", packet, strlen ("QTro:")) == 0)
+ else if (startswith (packet, "QTro:"))
{
cmd_qtro (packet);
return 1;
@@ -4203,28 +4203,27 @@ handle_tracepoint_general_set (char *packet)
cmd_qtstop (packet);
return 1;
}
- else if (strncmp ("QTDisconnected:", packet,
- strlen ("QTDisconnected:")) == 0)
+ else if (startswith (packet, "QTDisconnected:"))
{
cmd_qtdisconnected (packet);
return 1;
}
- else if (strncmp ("QTFrame:", packet, strlen ("QTFrame:")) == 0)
+ else if (startswith (packet, "QTFrame:"))
{
cmd_qtframe (packet);
return 1;
}
- else if (strncmp ("QTBuffer:circular:", packet, strlen ("QTBuffer:circular:")) == 0)
+ else if (startswith (packet, "QTBuffer:circular:"))
{
cmd_bigqtbuffer_circular (packet);
return 1;
}
- else if (strncmp ("QTBuffer:size:", packet, strlen ("QTBuffer:size:")) == 0)
+ else if (startswith (packet, "QTBuffer:size:"))
{
cmd_bigqtbuffer_size (packet);
return 1;
}
- else if (strncmp ("QTNotes:", packet, strlen ("QTNotes:")) == 0)
+ else if (startswith (packet, "QTNotes:"))
{
cmd_qtnotes (packet);
return 1;
@@ -4241,7 +4240,7 @@ handle_tracepoint_query (char *packet)
cmd_qtstatus (packet);
return 1;
}
- else if (strncmp ("qTP:", packet, strlen ("qTP:")) == 0)
+ else if (startswith (packet, "qTP:"))
{
cmd_qtp (packet);
return 1;
@@ -4266,12 +4265,12 @@ handle_tracepoint_query (char *packet)
cmd_qtsv (packet);
return 1;
}
- else if (strncmp ("qTV:", packet, strlen ("qTV:")) == 0)
+ else if (startswith (packet, "qTV:"))
{
cmd_qtv (packet);
return 1;
}
- else if (strncmp ("qTBuffer:", packet, strlen ("qTBuffer:")) == 0)
+ else if (startswith (packet, "qTBuffer:"))
{
cmd_qtbuffer (packet);
return 1;
@@ -4286,7 +4285,7 @@ handle_tracepoint_query (char *packet)
cmd_qtsstm (packet);
return 1;
}
- else if (strncmp ("qTSTMat:", packet, strlen ("qTSTMat:")) == 0)
+ else if (startswith (packet, "qTSTMat:"))
{
cmd_qtstmat (packet);
return 1;
@@ -6123,7 +6122,7 @@ tracepoint_send_agent (struct tracepoint *tpoint)
if (ret)
return ret;
- if (strncmp (buf, "OK", 2) != 0)
+ if (!startswith (buf, "OK"))
return 1;
/* The value of tracepoint's target address is stored in BUF. */
@@ -7202,7 +7201,7 @@ gdb_agent_helper_thread (void *arg)
if (cmd_buf[0])
{
- if (strncmp ("close", cmd_buf, 5) == 0)
+ if (startswith (cmd_buf, "close"))
{
stop_loop = 1;
}
@@ -7215,21 +7214,15 @@ gdb_agent_helper_thread (void *arg)
{
cmd_qtsstm (cmd_buf);
}
- else if (strncmp ("unprobe_marker_at:",
- cmd_buf,
- sizeof ("unprobe_marker_at:") - 1) == 0)
+ else if (startswith (cmd_buf, "unprobe_marker_at:"))
{
unprobe_marker_at (cmd_buf);
}
- else if (strncmp ("probe_marker_at:",
- cmd_buf,
- sizeof ("probe_marker_at:") - 1) == 0)
+ else if (startswith (cmd_buf, "probe_marker_at:"))
{
probe_marker_at (cmd_buf);
}
- else if (strncmp ("qTSTMat:",
- cmd_buf,
- sizeof ("qTSTMat:") - 1) == 0)
+ else if (startswith (cmd_buf, "qTSTMat:"))
{
cmd_qtstmat (cmd_buf);
}
diff --git a/gdb/gdbserver/win32-low.c b/gdb/gdbserver/win32-low.c
index 2b24c87..6c86765 100644
--- a/gdb/gdbserver/win32-low.c
+++ b/gdb/gdbserver/win32-low.c
@@ -778,7 +778,7 @@ handle_output_debug_string (struct target_waitstatus *ourstatus)
return;
}
- if (strncmp (s, "cYg", 3) != 0)
+ if (!startswith (s, "cYg"))
{
if (!server_waiting)
{
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 24f64be..d087a12 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -2376,7 +2376,7 @@ check_stub_method (struct type *type, int method_id, int signature_id)
}
/* If we read one argument and it was ``void'', don't count it. */
- if (strncmp (argtypetext, "(void)", 6) == 0)
+ if (startswith (argtypetext, "(void)"))
argcount -= 1;
/* We need one extra slot, for the THIS pointer. */
@@ -2471,7 +2471,7 @@ check_stub_method_group (struct type *type, int method_id)
Therefore the only thing we need to handle here are v2 operator
names. */
- if (found_stub && strncmp (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z", 2) != 0)
+ if (found_stub && !startswith (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z"))
{
int ret;
char dem_opname[256];
diff --git a/gdb/gnu-v2-abi.c b/gdb/gnu-v2-abi.c
index 5389374..68b734c 100644
--- a/gdb/gnu-v2-abi.c
+++ b/gdb/gnu-v2-abi.c
@@ -37,7 +37,7 @@ static enum dtor_kinds
gnuv2_is_destructor_name (const char *name)
{
if ((name[0] == '_' && is_cplus_marker (name[1]) && name[2] == '_')
- || strncmp (name, "__dt__", 6) == 0)
+ || startswith (name, "__dt__"))
return complete_object_dtor;
else
return 0;
@@ -48,7 +48,7 @@ gnuv2_is_constructor_name (const char *name)
{
if ((name[0] == '_' && name[1] == '_'
&& (isdigit (name[2]) || strchr ("Qt", name[2])))
- || strncmp (name, "__ct__", 6) == 0)
+ || startswith (name, "__ct__"))
return complete_object_ctor;
else
return 0;
@@ -68,7 +68,7 @@ gnuv2_is_vtable_name (const char *name)
static int
gnuv2_is_operator_name (const char *name)
{
- return strncmp (name, "operator", 8) == 0;
+ return startswith (name, "operator");
}
diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
index 6a96d21..d1ed8fc 100644
--- a/gdb/gnu-v3-abi.c
+++ b/gdb/gnu-v3-abi.c
@@ -39,13 +39,13 @@ static struct gdbarch_data *std_type_info_gdbarch_data;
static int
gnuv3_is_vtable_name (const char *name)
{
- return strncmp (name, "_ZTV", 4) == 0;
+ return startswith (name, "_ZTV");
}
static int
gnuv3_is_operator_name (const char *name)
{
- return strncmp (name, "operator", 8) == 0;
+ return startswith (name, "operator");
}
@@ -330,7 +330,7 @@ gnuv3_rtti_type (struct value *value,
should work just as well, and doesn't read target memory. */
vtable_symbol_name = MSYMBOL_DEMANGLED_NAME (vtable_symbol);
if (vtable_symbol_name == NULL
- || strncmp (vtable_symbol_name, "vtable for ", 11))
+ || !startswith (vtable_symbol_name, "vtable for "))
{
warning (_("can't find linker symbol for virtual table for `%s' value"),
TYPE_SAFE_NAME (values_type));
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 9bdc99a..b48467d 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -233,8 +233,8 @@ unpack_mangled_go_symbol (const char *mangled_name,
libgo_.*: used by gccgo's runtime
Thus we don't support -fgo-prefix (except as used by the runtime). */
- if (strncmp (mangled_name, "go.", 3) != 0
- && strncmp (mangled_name, "libgo_", 6) != 0)
+ if (!startswith (mangled_name, "go.")
+ && !startswith (mangled_name, "libgo_"))
return NULL;
/* Quick check for whether a search may be fruitful. */
diff --git a/gdb/guile/scm-type.c b/gdb/guile/scm-type.c
index 196b4a1..d21a7ae 100644
--- a/gdb/guile/scm-type.c
+++ b/gdb/guile/scm-type.c
@@ -1216,11 +1216,11 @@ tyscm_lookup_typename (const char *type_name, const struct block *block)
TRY_CATCH (except, RETURN_MASK_ALL)
{
- if (!strncmp (type_name, "struct ", 7))
+ if (startswith (type_name, "struct "))
type = lookup_struct (type_name + 7, NULL);
- else if (!strncmp (type_name, "union ", 6))
+ else if (startswith (type_name, "union "))
type = lookup_union (type_name + 6, NULL);
- else if (!strncmp (type_name, "enum ", 5))
+ else if (startswith (type_name, "enum "))
type = lookup_enum (type_name + 5, NULL);
else
type = lookup_typename (current_language, get_current_arch (),
diff --git a/gdb/i386-cygwin-tdep.c b/gdb/i386-cygwin-tdep.c
index a4f64e5..79ff478 100644
--- a/gdb/i386-cygwin-tdep.c
+++ b/gdb/i386-cygwin-tdep.c
@@ -107,7 +107,7 @@ core_process_module_section (bfd *abfd, asection *sect, void *obj)
gdb_byte *buf = NULL;
- if (strncmp (sect->name, ".module", 7) != 0)
+ if (!startswith (sect->name, ".module"))
return;
buf = xmalloc (bfd_get_section_size (sect) + 1);
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 8c08f8b..a78bedf 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -1824,8 +1824,7 @@ i386_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
if (post_prologue_pc
&& (cust != NULL
&& COMPUNIT_PRODUCER (cust) != NULL
- && strncmp (COMPUNIT_PRODUCER (cust), "clang ",
- sizeof ("clang ") - 1) == 0))
+ && startswith (COMPUNIT_PRODUCER (cust), "clang ")))
return max (start_pc, post_prologue_pc);
}
@@ -3854,8 +3853,8 @@ i386_pe_skip_trampoline_code (struct frame_info *frame,
if (symname)
{
- if (strncmp (symname, "__imp_", 6) == 0
- || strncmp (symname, "_imp_", 5) == 0)
+ if (startswith (symname, "__imp_")
+ || startswith (symname, "_imp_"))
return name ? 1 :
read_memory_unsigned_integer (indirect, 4, byte_order);
}
diff --git a/gdb/i386obsd-tdep.c b/gdb/i386obsd-tdep.c
index 5e1d7f8..eae445c 100644
--- a/gdb/i386obsd-tdep.c
+++ b/gdb/i386obsd-tdep.c
@@ -357,7 +357,7 @@ i386obsd_trapframe_cache (struct frame_info *this_frame, void **this_cache)
sp = get_frame_register_unsigned (this_frame, I386_ESP_REGNUM);
find_pc_partial_function (func, &name, NULL, NULL);
- if (name && strncmp (name, "Xintr", 5) == 0)
+ if (name && startswith (name, "Xintr"))
addr = sp + 8; /* It's an interrupt frame. */
else
addr = sp;
@@ -420,8 +420,8 @@ i386obsd_trapframe_sniffer (const struct frame_unwind *self,
find_pc_partial_function (get_frame_pc (this_frame), &name, NULL, NULL);
return (name && (strcmp (name, "calltrap") == 0
|| strcmp (name, "syscall1") == 0
- || strncmp (name, "Xintr", 5) == 0
- || strncmp (name, "Xsoft", 5) == 0));
+ || startswith (name, "Xintr")
+ || startswith (name, "Xsoft")));
}
static const struct frame_unwind i386obsd_trapframe_unwind = {
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 3737b8f..99104e9 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -791,7 +791,7 @@ continue_command (char *args, int from_tty)
if (args != NULL)
{
- if (strncmp (args, "-a", sizeof ("-a") - 1) == 0)
+ if (startswith (args, "-a"))
{
all_threads = 1;
args += sizeof ("-a") - 1;
@@ -2870,7 +2870,7 @@ interrupt_command (char *args, int from_tty)
dont_repeat (); /* Not for the faint of heart. */
if (args != NULL
- && strncmp (args, "-a", sizeof ("-a") - 1) == 0)
+ && startswith (args, "-a"))
all_threads = 1;
if (!non_stop && all_threads)
diff --git a/gdb/jv-typeprint.c b/gdb/jv-typeprint.c
index 5338c95..0bf6d10 100644
--- a/gdb/jv-typeprint.c
+++ b/gdb/jv-typeprint.c
@@ -168,12 +168,12 @@ java_type_print_base (struct type *type, struct ui_file *stream, int show,
{
QUIT;
/* Don't print out virtual function table. */
- if (strncmp (TYPE_FIELD_NAME (type, i), "_vptr", 5) == 0
+ if (startswith (TYPE_FIELD_NAME (type, i), "_vptr")
&& is_cplus_marker ((TYPE_FIELD_NAME (type, i))[5]))
continue;
/* Don't print the dummy field "class". */
- if (strncmp (TYPE_FIELD_NAME (type, i), "class", 5) == 0)
+ if (startswith (TYPE_FIELD_NAME (type, i), "class"))
continue;
print_spaces_filtered (level + 4, stream);
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 0d012b4..7d7c58d 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -454,8 +454,7 @@ is_ada_operator (const char *string)
for (mapping = ada_opname_table;
mapping->encoded != NULL
- && strncmp (mapping->decoded, string,
- strlen (mapping->decoded)) != 0; ++mapping)
+ && !startswith (string, mapping->decoded); ++mapping)
;
return mapping->decoded == NULL ? 0 : strlen (mapping->decoded);
@@ -1122,9 +1121,9 @@ find_methods (struct type *t, const char *name,
const char *method_name = TYPE_FN_FIELDLIST_NAME (t, method_counter);
char dem_opname[64];
- if (strncmp (method_name, "__", 2) == 0 ||
- strncmp (method_name, "op", 2) == 0 ||
- strncmp (method_name, "type", 4) == 0)
+ if (startswith (method_name, "__") ||
+ startswith (method_name, "op") ||
+ startswith (method_name, "type"))
{
if (cplus_demangle_opname (method_name, dem_opname, DMGL_ANSI))
method_name = dem_opname;
@@ -1210,7 +1209,7 @@ find_toplevel_string (const char *haystack, const char *needle)
if (s != NULL)
{
/* Found first char in HAYSTACK; check rest of string. */
- if (strncmp (s, needle, strlen (needle)) == 0)
+ if (startswith (s, needle))
return s;
/* Didn't find it; loop over HAYSTACK, looking for the next
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 4a5a066..627280e 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -4215,13 +4215,13 @@ linux_proc_pending_signals (int pid, sigset_t *pending,
Unfortunately some Red Hat kernels include the shared pending
queue but not the ShdPnd status field. */
- if (strncmp (buffer, "SigPnd:\t", 8) == 0)
+ if (startswith (buffer, "SigPnd:\t"))
add_line_to_sigset (buffer + 8, pending);
- else if (strncmp (buffer, "ShdPnd:\t", 8) == 0)
+ else if (startswith (buffer, "ShdPnd:\t"))
add_line_to_sigset (buffer + 8, pending);
- else if (strncmp (buffer, "SigBlk:\t", 8) == 0)
+ else if (startswith (buffer, "SigBlk:\t"))
add_line_to_sigset (buffer + 8, blocked);
- else if (strncmp (buffer, "SigIgn:\t", 8) == 0)
+ else if (startswith (buffer, "SigIgn:\t"))
add_line_to_sigset (buffer + 8, ignored);
}
diff --git a/gdb/m2-typeprint.c b/gdb/m2-typeprint.c
index 21bca39..be19872 100644
--- a/gdb/m2-typeprint.c
+++ b/gdb/m2-typeprint.c
@@ -538,7 +538,7 @@ m2_record_fields (struct type *type, struct ui_file *stream, int show,
/* Print the tag if it exists. */
if (TYPE_TAG_NAME (type) != NULL)
{
- if (strncmp (TYPE_TAG_NAME (type), "$$", 2) != 0)
+ if (!startswith (TYPE_TAG_NAME (type), "$$"))
{
fputs_filtered (TYPE_TAG_NAME (type), stream);
if (show > 0)
diff --git a/gdb/m32r-rom.c b/gdb/m32r-rom.c
index 9d6b8b3..a2ac537 100644
--- a/gdb/m32r-rom.c
+++ b/gdb/m32r-rom.c
@@ -447,7 +447,7 @@ m32r_upload_command (char *args, int from_tty)
myIPaddress = skip_spaces (myIPaddress);
- if (!strncmp (myIPaddress, "0.0.", 4)) /* empty */
+ if (startswith (myIPaddress, "0.0.")) /* empty */
error (_("Please use 'set board-address' to "
"set the M32R-EVA board's IP address."));
if (strchr (myIPaddress, '('))
diff --git a/gdb/machoread.c b/gdb/machoread.c
index 790f665..831bbcb 100644
--- a/gdb/machoread.c
+++ b/gdb/machoread.c
@@ -1004,7 +1004,7 @@ macho_symfile_offsets (struct objfile *objfile,
const char *bfd_sect_name = osect->the_bfd_section->name;
int sect_index = osect - objfile->sections;;
- if (strncmp (bfd_sect_name, "LC_SEGMENT.", 11) == 0)
+ if (startswith (bfd_sect_name, "LC_SEGMENT."))
bfd_sect_name += 11;
if (strcmp (bfd_sect_name, "__TEXT") == 0
|| strcmp (bfd_sect_name, "__TEXT.__text") == 0)
diff --git a/gdb/macrocmd.c b/gdb/macrocmd.c
index a40049a..3db1239 100644
--- a/gdb/macrocmd.c
+++ b/gdb/macrocmd.c
@@ -325,7 +325,7 @@ extract_identifier (char **expp, int is_parameter)
char *p = *expp;
unsigned int len;
- if (is_parameter && !strncmp (p, "...", 3))
+ if (is_parameter && startswith (p, "..."))
{
/* Ok. */
}
@@ -339,7 +339,7 @@ extract_identifier (char **expp, int is_parameter)
;
}
- if (is_parameter && !strncmp (p, "...", 3))
+ if (is_parameter && startswith (p, "..."))
p += 3;
len = p - *expp;
diff --git a/gdb/microblaze-rom.c b/gdb/microblaze-rom.c
index 66251db..beffadf 100644
--- a/gdb/microblaze-rom.c
+++ b/gdb/microblaze-rom.c
@@ -83,7 +83,7 @@ picobug_dumpregs (struct regcache *regcache)
if (strchr (p, '-'))
{
/* Got a range. Either r0-r7, r8-r15 or ss0-ss4. */
- if (strncmp (p, "r0", 2) == 0 || strncmp (p, "r8", 2) == 0)
+ if (startswith (p, "r0") || startswith (p, "r8"))
{
int rn = (p[1] == '0' ? 0 : 8);
int i = 0;
@@ -97,7 +97,7 @@ picobug_dumpregs (struct regcache *regcache)
i++;
}
}
- else if (strncmp (p, "ss", 2) == 0)
+ else if (startswith (p, "ss"))
{
/* Get the next five values, ignoring the first. */
int rn;
diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index f8985e8..d7097a9 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -996,7 +996,7 @@ prim_record_minimal_symbol_full (const char *name, int name_len, int copy_name,
--name_len;
}
- if (ms_type == mst_file_text && strncmp (name, "__gnu_compiled", 14) == 0)
+ if (ms_type == mst_file_text && startswith (name, "__gnu_compiled"))
return (NULL);
if (msym_bunch_index == BUNCH_SIZE)
diff --git a/gdb/mips-sde-tdep.c b/gdb/mips-sde-tdep.c
index eb171bf..0246b27 100644
--- a/gdb/mips-sde-tdep.c
+++ b/gdb/mips-sde-tdep.c
@@ -212,7 +212,7 @@ mips_sde_elf_osabi_sniff_abi_tag_sections (bfd *abfd, asection *sect,
/* The presence of a section with a ".sde" prefix is indicative
of an SDE binary. */
- if (strncmp (name, ".sde", 4) == 0)
+ if (startswith (name, ".sde"))
*os_ident_ptr = GDB_OSABI_SDE;
}
diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index bd8faef..6e8ccd6 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -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"));
}
diff --git a/gdb/msp430-tdep.c b/gdb/msp430-tdep.c
index f4ee41a..622ce55 100644
--- a/gdb/msp430-tdep.c
+++ b/gdb/msp430-tdep.c
@@ -834,8 +834,7 @@ msp430_in_return_stub (struct gdbarch *gdbarch, CORE_ADDR pc,
const char *name)
{
return (name != NULL
- && strncmp (msp430_epilog_name_prefix, name,
- strlen (msp430_epilog_name_prefix)) == 0);
+ && startswith (name, msp430_epilog_name_prefix));
}
/* Implement the "skip_trampoline_code" gdbarch method. */
diff --git a/gdb/nat/linux-procfs.c b/gdb/nat/linux-procfs.c
index 1e922b9..f149383 100644
--- a/gdb/nat/linux-procfs.c
+++ b/gdb/nat/linux-procfs.c
@@ -93,7 +93,7 @@ linux_proc_pid_get_state (pid_t pid, char *buffer, size_t buffer_size,
have_state = 0;
while (fgets (buffer, buffer_size, procfile) != NULL)
- if (strncmp (buffer, "State:", 6) == 0)
+ if (startswith (buffer, "State:"))
{
have_state = 1;
break;
diff --git a/gdb/nbsd-tdep.c b/gdb/nbsd-tdep.c
index 59d97d4..762d80f 100644
--- a/gdb/nbsd-tdep.c
+++ b/gdb/nbsd-tdep.c
@@ -45,5 +45,5 @@ nbsd_pc_in_sigtramp (CORE_ADDR pc, const char *func_name)
have function names which begin with "__sigtramp". */
return (func_name != NULL
- && strncmp (func_name, "__sigtramp", 10) == 0);
+ && startswith (func_name, "__sigtramp"));
}
diff --git a/gdb/p-typeprint.c b/gdb/p-typeprint.c
index 5a7a887..b5bf4d4 100644
--- a/gdb/p-typeprint.c
+++ b/gdb/p-typeprint.c
@@ -154,8 +154,8 @@ void
pascal_type_print_method_args (const char *physname, const char *methodname,
struct ui_file *stream)
{
- int is_constructor = (strncmp (physname, "__ct__", 6) == 0);
- int is_destructor = (strncmp (physname, "__dt__", 6) == 0);
+ int is_constructor = (startswith (physname, "__ct__"));
+ int is_destructor = (startswith (physname, "__dt__"));
if (is_constructor || is_destructor)
{
@@ -567,7 +567,7 @@ pascal_type_print_base (struct type *type, struct ui_file *stream, int show,
{
QUIT;
/* Don't print out virtual function table. */
- if ((strncmp (TYPE_FIELD_NAME (type, i), "_vptr", 5) == 0)
+ if ((startswith (TYPE_FIELD_NAME (type, i), "_vptr"))
&& is_cplus_marker ((TYPE_FIELD_NAME (type, i))[5]))
continue;
@@ -643,8 +643,8 @@ pascal_type_print_base (struct type *type, struct ui_file *stream, int show,
{
const char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
- int is_constructor = (strncmp (physname, "__ct__", 6) == 0);
- int is_destructor = (strncmp (physname, "__dt__", 6) == 0);
+ int is_constructor = (startswith (physname, "__ct__"));
+ int is_destructor = (startswith (physname, "__dt__"));
QUIT;
if (TYPE_FN_FIELD_PROTECTED (f, j))
diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c
index a7b1163..6c6eacf 100644
--- a/gdb/ppc-linux-tdep.c
+++ b/gdb/ppc-linux-tdep.c
@@ -985,7 +985,7 @@ ppc_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
static int
ppc_linux_spu_section (bfd *abfd, asection *asect, void *user_data)
{
- return strncmp (bfd_section_name (abfd, asect), "SPU/", 4) == 0;
+ return startswith (bfd_section_name (abfd, asect), "SPU/");
}
static const struct target_desc *
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index a3da678..72d4dcf 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -747,11 +747,11 @@ typy_lookup_typename (const char *type_name, const struct block *block)
TRY_CATCH (except, RETURN_MASK_ALL)
{
- if (!strncmp (type_name, "struct ", 7))
+ if (startswith (type_name, "struct "))
type = lookup_struct (type_name + 7, NULL);
- else if (!strncmp (type_name, "union ", 6))
+ else if (startswith (type_name, "union "))
type = lookup_union (type_name + 6, NULL);
- else if (!strncmp (type_name, "enum ", 5))
+ else if (startswith (type_name, "enum "))
type = lookup_enum (type_name + 5, NULL);
else
type = lookup_typename (python_language, python_gdbarch,
diff --git a/gdb/regcache.c b/gdb/regcache.c
index 9373ceb..366eba0 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -1342,7 +1342,7 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
t = n;
}
/* Chop a leading builtin_type. */
- if (strncmp (t, blt, strlen (blt)) == 0)
+ if (startswith (t, blt))
t += strlen (blt);
}
fprintf_unfiltered (file, " %-15s", t);
diff --git a/gdb/remote-m32r-sdi.c b/gdb/remote-m32r-sdi.c
index c55b75c..f7ea0b8 100644
--- a/gdb/remote-m32r-sdi.c
+++ b/gdb/remote-m32r-sdi.c
@@ -1265,9 +1265,9 @@ m32r_load (struct target_ops *self, const char *args, int from_tty)
if (*arg != '-')
filename = arg;
- else if (strncmp (arg, "-quiet", strlen (arg)) == 0)
+ else if (startswith ("-quiet", arg))
quiet = 1;
- else if (strncmp (arg, "-nostart", strlen (arg)) == 0)
+ else if (startswith ("-nostart", arg))
nostart = 1;
else
error (_("Unknown option `%s'"), arg);
diff --git a/gdb/remote-notif.c b/gdb/remote-notif.c
index 3e07fc7..2d24a9a 100644
--- a/gdb/remote-notif.c
+++ b/gdb/remote-notif.c
@@ -133,7 +133,7 @@ handle_notification (struct remote_notif_state *state, char *buf)
{
const char *name = notifs[i]->name;
- if (strncmp (buf, name, strlen (name)) == 0
+ if (startswith (buf, name)
&& buf[strlen (name)] == ':')
break;
}
diff --git a/gdb/remote.c b/gdb/remote.c
index 8f783a4..495dfdc 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -491,7 +491,7 @@ remote_get_noisy_reply (char **buf_p,
buf = *buf_p;
if (buf[0] == 'E')
trace_error (buf);
- else if (strncmp (buf, "qRelocInsn:", strlen ("qRelocInsn:")) == 0)
+ else if (startswith (buf, "qRelocInsn:"))
{
ULONGEST ul;
CORE_ADDR from, to, org_to;
@@ -3157,14 +3157,14 @@ get_offsets (void)
ptr = buf;
lose = 0;
- if (strncmp (ptr, "Text=", 5) == 0)
+ if (startswith (ptr, "Text="))
{
ptr += 5;
/* Don't use strtol, could lose on big values. */
while (*ptr && *ptr != ';')
text_addr = (text_addr << 4) + fromhex (*ptr++);
- if (strncmp (ptr, ";Data=", 6) == 0)
+ if (startswith (ptr, ";Data="))
{
ptr += 6;
while (*ptr && *ptr != ';')
@@ -3173,7 +3173,7 @@ get_offsets (void)
else
lose = 1;
- if (!lose && strncmp (ptr, ";Bss=", 5) == 0)
+ if (!lose && startswith (ptr, ";Bss="))
{
ptr += 5;
while (*ptr && *ptr != ';')
@@ -3185,7 +3185,7 @@ get_offsets (void)
else
lose = 1;
}
- else if (strncmp (ptr, "TextSeg=", 8) == 0)
+ else if (startswith (ptr, "TextSeg="))
{
ptr += 8;
/* Don't use strtol, could lose on big values. */
@@ -3193,7 +3193,7 @@ get_offsets (void)
text_addr = (text_addr << 4) + fromhex (*ptr++);
num_segments = 1;
- if (strncmp (ptr, ";DataSeg=", 9) == 0)
+ if (startswith (ptr, ";DataSeg="))
{
ptr += 9;
while (*ptr && *ptr != ';')
@@ -3800,7 +3800,7 @@ remote_check_symbols (void)
packet_ok (rs->buf, &remote_protocol_packets[PACKET_qSymbol]);
reply = rs->buf;
- while (strncmp (reply, "qSymbol:", 8) == 0)
+ while (startswith (reply, "qSymbol:"))
{
struct bound_minimal_symbol sym;
@@ -3840,7 +3840,7 @@ remote_serial_open (const char *name)
of in ser-tcp.c, because it is the remote protocol assuming that the
serial connection is reliable and not the serial connection promising
to be. */
- if (!udp_warning && strncmp (name, "udp:", 4) == 0)
+ if (!udp_warning && startswith (name, "udp:"))
{
warning (_("The remote protocol may be unreliable over UDP.\n"
"Some events may be lost, rendering further debugging "
@@ -4631,7 +4631,7 @@ remote_vcont_probe (struct remote_state *rs)
buf = rs->buf;
/* Make sure that the features we assume are supported. */
- if (strncmp (buf, "vCont", 5) == 0)
+ if (startswith (buf, "vCont"))
{
char *p = &buf[5];
int support_s, support_S, support_c, support_C;
@@ -5729,8 +5729,7 @@ Packet: '%s'\n"),
if (*p == '\0')
;
- else if (strncmp (p,
- "process:", sizeof ("process:") - 1) == 0)
+ else if (startswith (p, "process:"))
{
ULONGEST upid;
@@ -10212,9 +10211,7 @@ remote_bfd_iovec_stat (struct bfd *abfd, void *stream, struct stat *sb)
int
remote_filename_p (const char *filename)
{
- return strncmp (filename,
- REMOTE_SYSROOT_PREFIX,
- sizeof (REMOTE_SYSROOT_PREFIX) - 1) == 0;
+ return startswith (filename, REMOTE_SYSROOT_PREFIX);
}
bfd *
diff --git a/gdb/reverse.c b/gdb/reverse.c
index e0946c8..ed55a3a 100644
--- a/gdb/reverse.c
+++ b/gdb/reverse.c
@@ -255,9 +255,9 @@ goto_bookmark_command (char *args, int from_tty)
if (args == NULL || args[0] == '\0')
error (_("Command requires an argument."));
- if (strncmp (args, "start", strlen ("start")) == 0
- || strncmp (args, "begin", strlen ("begin")) == 0
- || strncmp (args, "end", strlen ("end")) == 0)
+ if (startswith (args, "start")
+ || startswith (args, "begin")
+ || startswith (args, "end"))
{
/* Special case. Give target opportunity to handle. */
target_goto_bookmark ((gdb_byte *) args, from_tty);
diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
index 46f6e41..0a86929 100644
--- a/gdb/rs6000-tdep.c
+++ b/gdb/rs6000-tdep.c
@@ -2220,7 +2220,7 @@ static int
rs6000_in_solib_return_trampoline (struct gdbarch *gdbarch,
CORE_ADDR pc, const char *name)
{
- return name && !strncmp (name, "@FIX", 4);
+ return name && startswith (name, "@FIX");
}
/* Skip code that the user doesn't want to see when stepping:
diff --git a/gdb/ser-tcp.c b/gdb/ser-tcp.c
index 3467b1f..9c3dcf4 100644
--- a/gdb/ser-tcp.c
+++ b/gdb/ser-tcp.c
@@ -168,12 +168,12 @@ net_open (struct serial *scb, const char *name)
unsigned int polls = 0;
use_udp = 0;
- if (strncmp (name, "udp:", 4) == 0)
+ if (startswith (name, "udp:"))
{
use_udp = 1;
name = name + 4;
}
- else if (strncmp (name, "tcp:", 4) == 0)
+ else if (startswith (name, "tcp:"))
name = name + 4;
port_str = strchr (name, ':');
diff --git a/gdb/serial.c b/gdb/serial.c
index 59bf7af..b7e620d 100644
--- a/gdb/serial.c
+++ b/gdb/serial.c
@@ -190,9 +190,9 @@ serial_open (const char *name)
if (strcmp (name, "pc") == 0)
ops = serial_interface_lookup ("pc");
- else if (strncmp (name, "lpt", 3) == 0)
+ else if (startswith (name, "lpt"))
ops = serial_interface_lookup ("parallel");
- else if (strncmp (name, "|", 1) == 0)
+ else if (startswith (name, "|"))
{
ops = serial_interface_lookup ("pipe");
/* Discard ``|'' and any space before the command itself. */
diff --git a/gdb/somread.c b/gdb/somread.c
index 2bee2b1..49cfe76 100644
--- a/gdb/somread.c
+++ b/gdb/somread.c
@@ -212,8 +212,8 @@ som_symtab_read (bfd *abfd, struct objfile *objfile,
if ((symname[0] == 'L' && symname[1] == '$')
|| (symname[0] == '$' && symname[strlen (symname) - 1] == '$')
|| (symname[0] == 'D' && symname[1] == '$')
- || (strncmp (symname, "L0\001", 3) == 0)
- || (strncmp (symname, "$PIC", 4) == 0))
+ || (startswith (symname, "L0\001"))
+ || (startswith (symname, "$PIC")))
continue;
break;
diff --git a/gdb/sparc64nbsd-tdep.c b/gdb/sparc64nbsd-tdep.c
index 78e3b58..32da6ac 100644
--- a/gdb/sparc64nbsd-tdep.c
+++ b/gdb/sparc64nbsd-tdep.c
@@ -216,7 +216,7 @@ sparc64nbsd_sigtramp_frame_sniffer (const struct frame_unwind *self,
find_pc_partial_function (pc, &name, NULL, NULL);
if (sparc64nbsd_pc_in_sigtramp (pc, name))
{
- if (name == NULL || strncmp (name, "__sigtramp_sigcontext", 21))
+ if (name == NULL || !startswith (name, "__sigtramp_sigcontext"))
return 1;
}
diff --git a/gdb/sparcnbsd-tdep.c b/gdb/sparcnbsd-tdep.c
index b5fab8b..c145919 100644
--- a/gdb/sparcnbsd-tdep.c
+++ b/gdb/sparcnbsd-tdep.c
@@ -241,7 +241,7 @@ sparc32nbsd_sigcontext_frame_sniffer (const struct frame_unwind *self,
find_pc_partial_function (pc, &name, NULL, NULL);
if (sparc32nbsd_pc_in_sigtramp (pc, name))
{
- if (name == NULL || strncmp (name, "__sigtramp_sigcontext", 21))
+ if (name == NULL || !startswith (name, "__sigtramp_sigcontext"))
return 1;
}
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 12168cb..aebe2d9 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -535,7 +535,7 @@ gdb_mangle_name (struct type *type, int method_id, int signature_id)
|| (newname && strcmp (field_name, newname) == 0);
if (!is_destructor)
- is_destructor = (strncmp (physname, "__dt", 4) == 0);
+ is_destructor = (startswith (physname, "__dt"));
if (is_destructor || is_full_physname_constructor)
{
@@ -3950,7 +3950,7 @@ static const char *
operator_chars (const char *p, const char **end)
{
*end = "";
- if (strncmp (p, "operator", 8))
+ if (!startswith (p, "operator"))
return *end;
p += 8;
@@ -6003,7 +6003,7 @@ producer_is_realview (const char *producer)
return 0;
for (i = 0; i < ARRAY_SIZE (arm_idents); i++)
- if (strncmp (producer, arm_idents[i], strlen (arm_idents[i])) == 0)
+ if (startswith (producer, arm_idents[i]))
return 1;
return 0;
diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c
index 44c6189..3ee7243 100644
--- a/gdb/tracefile-tfile.c
+++ b/gdb/tracefile-tfile.c
@@ -426,7 +426,7 @@ tfile_open (const char *arg, int from_tty)
bytes += TRACE_HEADER_SIZE;
if (!(header[0] == 0x7f
- && (strncmp (header + 1, "TRACE0\n", 7) == 0)))
+ && (startswith (header + 1, "TRACE0\n"))))
error (_("File is not a valid trace file."));
push_target (&tfile_ops);
@@ -510,22 +510,22 @@ tfile_interp_line (char *line, struct uploaded_tp **utpp,
{
char *p = line;
- if (strncmp (p, "R ", strlen ("R ")) == 0)
+ if (startswith (p, "R "))
{
p += strlen ("R ");
trace_regblock_size = strtol (p, &p, 16);
}
- else if (strncmp (p, "status ", strlen ("status ")) == 0)
+ else if (startswith (p, "status "))
{
p += strlen ("status ");
parse_trace_status (p, current_trace_status ());
}
- else if (strncmp (p, "tp ", strlen ("tp ")) == 0)
+ else if (startswith (p, "tp "))
{
p += strlen ("tp ");
parse_tracepoint_definition (p, utpp);
}
- else if (strncmp (p, "tsv ", strlen ("tsv ")) == 0)
+ else if (startswith (p, "tsv "))
{
p += strlen ("tsv ");
parse_tsv_definition (p, utsvp);
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 0774f5e..7c04ecb 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -3830,11 +3830,11 @@ parse_tracepoint_definition (char *line, struct uploaded_tp **utpp)
end = hex2bin (p, (gdb_byte *) buf, strlen (p) / 2);
buf[end] = '\0';
- if (strncmp (srctype, "at:", strlen ("at:")) == 0)
+ if (startswith (srctype, "at:"))
utp->at_string = xstrdup (buf);
- else if (strncmp (srctype, "cond:", strlen ("cond:")) == 0)
+ else if (startswith (srctype, "cond:"))
utp->cond_string = xstrdup (buf);
- else if (strncmp (srctype, "cmd:", strlen ("cmd:")) == 0)
+ else if (startswith (srctype, "cmd:"))
VEC_safe_push (char_ptr, utp->cmd_strings, xstrdup (buf));
}
else if (piece == 'V')
diff --git a/gdb/tui/tui-data.c b/gdb/tui/tui-data.c
index 3eff9fd..43bcec2 100644
--- a/gdb/tui/tui-data.c
+++ b/gdb/tui/tui-data.c
@@ -391,7 +391,7 @@ tui_partial_win_by_name (char *name)
char *cur_name = tui_win_name (&tui_win_list[i]->generic);
if (strlen (name) <= strlen (cur_name)
- && strncmp (name, cur_name, strlen (name)) == 0)
+ && startswith (cur_name, name))
win_info = tui_win_list[i];
}
i++;
diff --git a/gdb/utils.c b/gdb/utils.c
index 4f9f4f0..7172bba 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -2663,8 +2663,7 @@ subset_compare (char *string_to_compare, char *template_string)
if (template_string != (char *) NULL && string_to_compare != (char *) NULL
&& strlen (string_to_compare) <= strlen (template_string))
match =
- (strncmp
- (template_string, string_to_compare, strlen (string_to_compare)) == 0);
+ (startswith (template_string, string_to_compare));
else
match = 0;
return match;
@@ -3278,7 +3277,7 @@ producer_is_gcc (const char *producer, int *major, int *minor)
{
const char *cs;
- if (producer != NULL && strncmp (producer, "GNU ", strlen ("GNU ")) == 0)
+ if (producer != NULL && startswith (producer, "GNU "))
{
int maj, min;
diff --git a/gdb/valops.c b/gdb/valops.c
index 23a4b37..b096a51 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -1992,9 +1992,9 @@ search_struct_method (const char *name, struct value **arg1p,
const char *t_field_name = TYPE_FN_FIELDLIST_NAME (type, i);
/* FIXME! May need to check for ARM demangling here. */
- if (strncmp (t_field_name, "__", 2) == 0 ||
- strncmp (t_field_name, "op", 2) == 0 ||
- strncmp (t_field_name, "type", 4) == 0)
+ if (startswith (t_field_name, "__") ||
+ startswith (t_field_name, "op") ||
+ startswith (t_field_name, "type"))
{
if (cplus_demangle_opname (t_field_name, dem_opname, DMGL_ANSI))
t_field_name = dem_opname;
@@ -3386,9 +3386,9 @@ value_struct_elt_for_reference (struct type *domain, int offset,
const char *t_field_name = TYPE_FN_FIELDLIST_NAME (t, i);
char dem_opname[64];
- if (strncmp (t_field_name, "__", 2) == 0
- || strncmp (t_field_name, "op", 2) == 0
- || strncmp (t_field_name, "type", 4) == 0)
+ if (startswith (t_field_name, "__")
+ || startswith (t_field_name, "op")
+ || startswith (t_field_name, "type"))
{
if (cplus_demangle_opname (t_field_name,
dem_opname, DMGL_ANSI))
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 107bdf2..42a6046 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -813,11 +813,10 @@ handle_output_debug_string (struct target_waitstatus *ourstatus)
&s, 1024, 0)
|| !s || !*s)
/* nothing to do */;
- else if (strncmp (s, _CYGWIN_SIGNAL_STRING,
- sizeof (_CYGWIN_SIGNAL_STRING) - 1) != 0)
+ else if (!startswith (s, _CYGWIN_SIGNAL_STRING))
{
#ifdef __CYGWIN__
- if (strncmp (s, "cYg", 3) != 0)
+ if (!startswith (s, "cYg"))
#endif
warning (("%s"), s);
}
@@ -1014,8 +1013,7 @@ handle_exception (struct target_waitstatus *ourstatus)
if ((!cygwin_exceptions && (addr >= cygwin_load_start
&& addr < cygwin_load_end))
|| (find_pc_partial_function (addr, &fn, NULL, NULL)
- && strncmp (fn, "KERNEL32!IsBad",
- strlen ("KERNEL32!IsBad")) == 0))
+ && startswith (fn, "KERNEL32!IsBad")))
return 0;
}
#endif
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index e83bd13..3cb6eda 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -2839,7 +2839,7 @@ scan_xcoff_symtab (struct objfile *objfile)
loader-generated definitions. Keeping the global
symbols leads to "in psymbols but not in symbols"
errors. */
- if (strncmp (namestring, "@FIX", 4) == 0)
+ if (startswith (namestring, "@FIX"))
continue;
symbol.n_value += ANOFFSET (objfile->section_offsets,