From 61012eef8463764ccd9117dc1c9bc43cc452b7cc Mon Sep 17 00:00:00 2001 From: Gary Benson Date: Fri, 6 Mar 2015 09:42:06 +0000 Subject: 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. --- gdb/breakpoint.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'gdb/breakpoint.c') 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; -- cgit v1.1