From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 4EA883857C46; Tue, 18 Jan 2022 17:13:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4EA883857C46 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Remove EL_* macros from location.c X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 7910e2dee3d8b5ea7f59973277baf95525c63be1 X-Git-Newrev: 49a9cf56ffd49539234e6cb33a5d1d19ba4e2388 Message-Id: <20220118171354.4EA883857C46@sourceware.org> Date: Tue, 18 Jan 2022 17:13:54 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Jan 2022 17:13:54 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D49a9cf56ffd4= 9539234e6cb33a5d1d19ba4e2388 commit 49a9cf56ffd49539234e6cb33a5d1d19ba4e2388 Author: Tom Tromey Date: Fri Jan 14 07:33:33 2022 -0700 Remove EL_* macros from location.c =20 This patch removes the old-style EL_* macros from location.c. This cleans up the code by itself, IMO, but also enables further cleanups in subsequent patches. Diff: --- gdb/location.c | 183 ++++++++++++++++++++++++++++-------------------------= ---- 1 file changed, 90 insertions(+), 93 deletions(-) diff --git a/gdb/location.c b/gdb/location.c index 35ca2ac71b8..9c33ea4746e 100644 --- a/gdb/location.c +++ b/gdb/location.c @@ -37,31 +37,25 @@ struct event_location { /* The type of this breakpoint specification. */ enum event_location_type type; -#define EL_TYPE(P) (P)->type =20 union { /* A probe. */ char *addr_string; -#define EL_PROBE(P) ((P)->u.addr_string) =20 /* A "normal" linespec. */ struct linespec_location linespec_location; -#define EL_LINESPEC(P) (&(P)->u.linespec_location) =20 /* An address in the inferior. */ CORE_ADDR address; -#define EL_ADDRESS(P) (P)->u.address =20 /* An explicit location. */ struct explicit_location explicit_loc; -#define EL_EXPLICIT(P) (&((P)->u.explicit_loc)) } u; =20 /* Cached string representation of this location. This is used, e.g., to save stop event locations to file. Malloc'd. */ char *as_string; -#define EL_STRING(P) ((P)->as_string) }; =20 /* See description in location.h. */ @@ -69,7 +63,7 @@ struct event_location enum event_location_type event_location_type (const struct event_location *location) { - return EL_TYPE (location); + return location->type; } =20 /* See description in location.h. */ @@ -91,8 +85,8 @@ new_linespec_location (const char **linespec, struct event_location *location; =20 location =3D XCNEW (struct event_location); - EL_TYPE (location) =3D LINESPEC_LOCATION; - EL_LINESPEC (location)->match_type =3D match_type; + location->type =3D LINESPEC_LOCATION; + location->u.linespec_location.match_type =3D match_type; if (*linespec !=3D NULL) { const char *p; @@ -101,7 +95,8 @@ new_linespec_location (const char **linespec, linespec_lex_to_end (linespec); p =3D remove_trailing_whitespace (orig, *linespec); if ((p - orig) > 0) - EL_LINESPEC (location)->spec_string =3D savestring (orig, p - orig); + location->u.linespec_location.spec_string + =3D savestring (orig, p - orig); } return event_location_up (location); } @@ -111,8 +106,8 @@ new_linespec_location (const char **linespec, const linespec_location * get_linespec_location (const struct event_location *location) { - gdb_assert (EL_TYPE (location) =3D=3D LINESPEC_LOCATION); - return EL_LINESPEC (location); + gdb_assert (location->type =3D=3D LINESPEC_LOCATION); + return &location->u.linespec_location; } =20 /* See description in location.h. */ @@ -124,10 +119,10 @@ new_address_location (CORE_ADDR addr, const char *add= r_string, struct event_location *location; =20 location =3D XCNEW (struct event_location); - EL_TYPE (location) =3D ADDRESS_LOCATION; - EL_ADDRESS (location) =3D addr; + location->type =3D ADDRESS_LOCATION; + location->u.address =3D addr; if (addr_string !=3D NULL) - EL_STRING (location) =3D xstrndup (addr_string, addr_string_len); + location->as_string =3D xstrndup (addr_string, addr_string_len); return event_location_up (location); } =20 @@ -136,8 +131,8 @@ new_address_location (CORE_ADDR addr, const char *addr_= string, CORE_ADDR get_address_location (const struct event_location *location) { - gdb_assert (EL_TYPE (location) =3D=3D ADDRESS_LOCATION); - return EL_ADDRESS (location); + gdb_assert (location->type =3D=3D ADDRESS_LOCATION); + return location->u.address; } =20 /* See description in location.h. */ @@ -145,8 +140,8 @@ get_address_location (const struct event_location *loca= tion) const char * get_address_string_location (const struct event_location *location) { - gdb_assert (EL_TYPE (location) =3D=3D ADDRESS_LOCATION); - return EL_STRING (location); + gdb_assert (location->type =3D=3D ADDRESS_LOCATION); + return location->as_string; } =20 /* See description in location.h. */ @@ -157,9 +152,9 @@ new_probe_location (const char *probe) struct event_location *location; =20 location =3D XCNEW (struct event_location); - EL_TYPE (location) =3D PROBE_LOCATION; + location->type =3D PROBE_LOCATION; if (probe !=3D NULL) - EL_PROBE (location) =3D xstrdup (probe); + location->u.addr_string =3D xstrdup (probe); return event_location_up (location); } =20 @@ -168,8 +163,8 @@ new_probe_location (const char *probe) const char * get_probe_location (const struct event_location *location) { - gdb_assert (EL_TYPE (location) =3D=3D PROBE_LOCATION); - return EL_PROBE (location); + gdb_assert (location->type =3D=3D PROBE_LOCATION); + return location->u.addr_string; } =20 /* See description in location.h. */ @@ -180,28 +175,28 @@ new_explicit_location (const struct explicit_location= *explicit_loc) struct event_location tmp; =20 memset (&tmp, 0, sizeof (struct event_location)); - EL_TYPE (&tmp) =3D EXPLICIT_LOCATION; - initialize_explicit_location (EL_EXPLICIT (&tmp)); + tmp.type =3D EXPLICIT_LOCATION; + initialize_explicit_location (&tmp.u.explicit_loc); if (explicit_loc !=3D NULL) { - EL_EXPLICIT (&tmp)->func_name_match_type + tmp.u.explicit_loc.func_name_match_type =3D explicit_loc->func_name_match_type; =20 if (explicit_loc->source_filename !=3D NULL) { - EL_EXPLICIT (&tmp)->source_filename + tmp.u.explicit_loc.source_filename =3D explicit_loc->source_filename; } =20 if (explicit_loc->function_name !=3D NULL) - EL_EXPLICIT (&tmp)->function_name + tmp.u.explicit_loc.function_name =3D explicit_loc->function_name; =20 if (explicit_loc->label_name !=3D NULL) - EL_EXPLICIT (&tmp)->label_name =3D explicit_loc->label_name; + tmp.u.explicit_loc.label_name =3D explicit_loc->label_name; =20 if (explicit_loc->line_offset.sign !=3D LINE_OFFSET_UNKNOWN) - EL_EXPLICIT (&tmp)->line_offset =3D explicit_loc->line_offset; + tmp.u.explicit_loc.line_offset =3D explicit_loc->line_offset; } =20 return copy_event_location (&tmp); @@ -212,8 +207,8 @@ new_explicit_location (const struct explicit_location *= explicit_loc) struct explicit_location * get_explicit_location (struct event_location *location) { - gdb_assert (EL_TYPE (location) =3D=3D EXPLICIT_LOCATION); - return EL_EXPLICIT (location); + gdb_assert (location->type =3D=3D EXPLICIT_LOCATION); + return &location->u.explicit_loc; } =20 /* See description in location.h. */ @@ -221,8 +216,8 @@ get_explicit_location (struct event_location *location) const struct explicit_location * get_explicit_location_const (const struct event_location *location) { - gdb_assert (EL_TYPE (location) =3D=3D EXPLICIT_LOCATION); - return EL_EXPLICIT (location); + gdb_assert (location->type =3D=3D EXPLICIT_LOCATION); + return &location->u.explicit_loc; } =20 /* This convenience function returns a malloc'd string which @@ -309,44 +304,46 @@ copy_event_location (const struct event_location *src) struct event_location *dst; =20 dst =3D XCNEW (struct event_location); - EL_TYPE (dst) =3D EL_TYPE (src); - if (EL_STRING (src) !=3D NULL) - EL_STRING (dst) =3D xstrdup (EL_STRING (src)); + dst->type =3D src->type; + if (src->as_string !=3D NULL) + dst->as_string =3D xstrdup (src->as_string); =20 - switch (EL_TYPE (src)) + switch (src->type) { case LINESPEC_LOCATION: - EL_LINESPEC (dst)->match_type =3D EL_LINESPEC (src)->match_type; - if (EL_LINESPEC (src)->spec_string !=3D NULL) - EL_LINESPEC (dst)->spec_string - =3D xstrdup (EL_LINESPEC (src)->spec_string); + dst->u.linespec_location.match_type + =3D src->u.linespec_location.match_type; + if (src->u.linespec_location.spec_string !=3D NULL) + dst->u.linespec_location.spec_string + =3D xstrdup (src->u.linespec_location.spec_string); break; =20 case ADDRESS_LOCATION: - EL_ADDRESS (dst) =3D EL_ADDRESS (src); + dst->u.address =3D src->u.address; break; =20 case EXPLICIT_LOCATION: - EL_EXPLICIT (dst)->func_name_match_type - =3D EL_EXPLICIT (src)->func_name_match_type; - if (EL_EXPLICIT (src)->source_filename !=3D NULL) - EL_EXPLICIT (dst)->source_filename - =3D xstrdup (EL_EXPLICIT (src)->source_filename); + dst->u.explicit_loc.func_name_match_type + =3D src->u.explicit_loc.func_name_match_type; + if (src->u.explicit_loc.source_filename !=3D NULL) + dst->u.explicit_loc.source_filename + =3D xstrdup (src->u.explicit_loc.source_filename); =20 - if (EL_EXPLICIT (src)->function_name !=3D NULL) - EL_EXPLICIT (dst)->function_name - =3D xstrdup (EL_EXPLICIT (src)->function_name); + if (src->u.explicit_loc.function_name !=3D NULL) + dst->u.explicit_loc.function_name + =3D xstrdup (src->u.explicit_loc.function_name); =20 - if (EL_EXPLICIT (src)->label_name !=3D NULL) - EL_EXPLICIT (dst)->label_name =3D xstrdup (EL_EXPLICIT (src)->label_name); + if (src->u.explicit_loc.label_name !=3D NULL) + dst->u.explicit_loc.label_name + =3D xstrdup (src->u.explicit_loc.label_name); =20 - EL_EXPLICIT (dst)->line_offset =3D EL_EXPLICIT (src)->line_offset; + dst->u.explicit_loc.line_offset =3D src->u.explicit_loc.line_offset; break; =20 =20 case PROBE_LOCATION: - if (EL_PROBE (src) !=3D NULL) - EL_PROBE (dst) =3D xstrdup (EL_PROBE (src)); + if (src->u.addr_string !=3D NULL) + dst->u.addr_string =3D xstrdup (src->u.addr_string); break; =20 default: @@ -361,12 +358,12 @@ event_location_deleter::operator() (event_location *l= ocation) const { if (location !=3D NULL) { - xfree (EL_STRING (location)); + xfree (location->as_string); =20 - switch (EL_TYPE (location)) + switch (location->type) { case LINESPEC_LOCATION: - xfree (EL_LINESPEC (location)->spec_string); + xfree (location->u.linespec_location.spec_string); break; =20 case ADDRESS_LOCATION: @@ -374,13 +371,13 @@ event_location_deleter::operator() (event_location *l= ocation) const break; =20 case EXPLICIT_LOCATION: - xfree (EL_EXPLICIT (location)->source_filename); - xfree (EL_EXPLICIT (location)->function_name); - xfree (EL_EXPLICIT (location)->label_name); + xfree (location->u.explicit_loc.source_filename); + xfree (location->u.explicit_loc.function_name); + xfree (location->u.explicit_loc.label_name); break; =20 case PROBE_LOCATION: - xfree (EL_PROBE (location)); + xfree (location->u.addr_string); break; =20 default: @@ -396,40 +393,40 @@ event_location_deleter::operator() (event_location *l= ocation) const const char * event_location_to_string (struct event_location *location) { - if (EL_STRING (location) =3D=3D NULL) + if (location->as_string =3D=3D NULL) { - switch (EL_TYPE (location)) + switch (location->type) { case LINESPEC_LOCATION: - if (EL_LINESPEC (location)->spec_string !=3D NULL) + if (location->u.linespec_location.spec_string !=3D NULL) { - linespec_location *ls =3D EL_LINESPEC (location); + linespec_location *ls =3D &location->u.linespec_location; if (ls->match_type =3D=3D symbol_name_match_type::FULL) { - EL_STRING (location) + location->as_string =3D concat ("-qualified ", ls->spec_string, (char *) NULL); } else - EL_STRING (location) =3D xstrdup (ls->spec_string); + location->as_string =3D xstrdup (ls->spec_string); } break; =20 case ADDRESS_LOCATION: { const char *addr_string - =3D core_addr_to_string (EL_ADDRESS (location)); - EL_STRING (location) + =3D core_addr_to_string (location->u.address); + location->as_string =3D xstrprintf ("*%s", addr_string).release (); } break; =20 case EXPLICIT_LOCATION: - EL_STRING (location) - =3D explicit_location_to_string (EL_EXPLICIT (location)).release (); + location->as_string + =3D explicit_location_to_string (&location->u.explicit_loc).release (= ); break; =20 case PROBE_LOCATION: - EL_STRING (location) =3D xstrdup (EL_PROBE (location)); + location->as_string =3D xstrdup (location->u.addr_string); break; =20 default: @@ -437,7 +434,7 @@ event_location_to_string (struct event_location *locati= on) } } =20 - return EL_STRING (location); + return location->as_string; } =20 /* Find an instance of the quote character C in the string S that is @@ -804,17 +801,17 @@ string_to_explicit_location (const char **argp, { set_oarg (explicit_location_lex_one (argp, language, completion_info)); - EL_EXPLICIT (location)->source_filename =3D oarg.release (); + location->u.explicit_loc.source_filename =3D oarg.release (); } else if (strncmp (opt.get (), "-function", len) =3D=3D 0) { set_oarg (explicit_location_lex_one_function (argp, language, completion_info)); - EL_EXPLICIT (location)->function_name =3D oarg.release (); + location->u.explicit_loc.function_name =3D oarg.release (); } else if (strncmp (opt.get (), "-qualified", len) =3D=3D 0) { - EL_EXPLICIT (location)->func_name_match_type + location->u.explicit_loc.func_name_match_type =3D symbol_name_match_type::FULL; } else if (strncmp (opt.get (), "-line", len) =3D=3D 0) @@ -823,7 +820,7 @@ string_to_explicit_location (const char **argp, *argp =3D skip_spaces (*argp); if (have_oarg) { - EL_EXPLICIT (location)->line_offset + location->u.explicit_loc.line_offset =3D linespec_parse_line_offset (oarg.get ()); continue; } @@ -831,7 +828,7 @@ string_to_explicit_location (const char **argp, else if (strncmp (opt.get (), "-label", len) =3D=3D 0) { set_oarg (explicit_location_lex_one (argp, language, completion_info)); - EL_EXPLICIT (location)->label_name =3D oarg.release (); + location->u.explicit_loc.label_name =3D oarg.release (); } /* Only emit an "invalid argument" error for options that look like option strings. */ @@ -861,10 +858,10 @@ string_to_explicit_location (const char **argp, =20 /* One special error check: If a source filename was given without offset, function, or label, issue an error. */ - if (EL_EXPLICIT (location)->source_filename !=3D NULL - && EL_EXPLICIT (location)->function_name =3D=3D NULL - && EL_EXPLICIT (location)->label_name =3D=3D NULL - && (EL_EXPLICIT (location)->line_offset.sign =3D=3D LINE_OFFSET_UNKN= OWN) + if (location->u.explicit_loc.source_filename !=3D NULL + && location->u.explicit_loc.function_name =3D=3D NULL + && location->u.explicit_loc.label_name =3D=3D NULL + && (location->u.explicit_loc.line_offset.sign =3D=3D LINE_OFFSET_UNK= NOWN) && completion_info =3D=3D NULL) { error (_("Source filename requires function, label, or " @@ -940,7 +937,7 @@ string_to_event_location (const char **stringp, "-qualified", otherwise string_to_explicit_location would have thrown an error. Save the flags for "basic" linespec parsing below and discard the explicit location. */ - match_type =3D EL_EXPLICIT (location)->func_name_match_type; + match_type =3D location->u.explicit_loc.func_name_match_type; } =20 /* Everything else is a "basic" linespec, address, or probe @@ -953,7 +950,7 @@ string_to_event_location (const char **stringp, int event_location_empty_p (const struct event_location *location) { - switch (EL_TYPE (location)) + switch (location->type) { case LINESPEC_LOCATION: /* Linespecs are never "empty." (NULL is a valid linespec) */ @@ -963,14 +960,14 @@ event_location_empty_p (const struct event_location *= location) return 0; =20 case EXPLICIT_LOCATION: - return (EL_EXPLICIT (location)->source_filename =3D=3D NULL - && EL_EXPLICIT (location)->function_name =3D=3D NULL - && EL_EXPLICIT (location)->label_name =3D=3D NULL - && (EL_EXPLICIT (location)->line_offset.sign + return (location->u.explicit_loc.source_filename =3D=3D NULL + && location->u.explicit_loc.function_name =3D=3D NULL + && location->u.explicit_loc.label_name =3D=3D NULL + && (location->u.explicit_loc.line_offset.sign =3D=3D LINE_OFFSET_UNKNOWN)); =20 case PROBE_LOCATION: - return EL_PROBE (location) =3D=3D NULL; + return location->u.addr_string =3D=3D NULL; =20 default: gdb_assert_not_reached ("unknown event location type"); @@ -983,6 +980,6 @@ void set_event_location_string (struct event_location *location, gdb::unique_xmalloc_ptr string) { - xfree (EL_STRING (location)); - EL_STRING (location) =3D string.release (); + xfree (location->as_string); + location->as_string =3D string.release (); }