aboutsummaryrefslogtreecommitdiff
path: root/gdb/probe.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2017-09-10 14:48:30 -0600
committerTom Tromey <tom@tromey.com>2017-09-11 15:46:14 -0600
commitcb791d59489576280e416262eb61ab59765a0baf (patch)
tree16a968a28a8926f82e69990be93b5f86dec81ae3 /gdb/probe.c
parent2039bd9f0ce667f3f0ee99c18e25de1ea18a2288 (diff)
downloadgdb-cb791d59489576280e416262eb61ab59765a0baf.zip
gdb-cb791d59489576280e416262eb61ab59765a0baf.tar.gz
gdb-cb791d59489576280e416262eb61ab59765a0baf.tar.bz2
Make extract_arg return a std::string
Change extract_arg to return a std::string and fix up all the users. I think string is mildly better than unique_xmalloc_ptr<char>, when possible, because it provides a more robust API. I changed the error messages emitted from find_location_by_number to avoid either writing to a string or an extra allocation; this can be changed but I thought that the new message was not any less clear. You can see an example in the testsuite patch. ChangeLog 2017-09-11 Tom Tromey <tom@tromey.com> * demangle.c (demangle_command): Update. * breakpoint.c (disable_command): Update. (enable_command): Update. (find_location_by_number): Make "number" const. Use get_number_trailer. * cli/cli-utils.c (extract_arg): Return std::string. * probe.c (parse_probe_linespec): Update. Change types. (collect_probes): Take string arguments. (parse_probe_linespec): Likewise. (info_probes_for_ops): Update. (enable_probes_command): Update. (disable_probes_command): Update. * break-catch-sig.c (catch_signal_split_args): Update. * mi/mi-parse.c (mi_parse): Update. testsuite/ChangeLog 2017-09-11 Tom Tromey <tom@tromey.com> * gdb.base/ena-dis-br.exp (test_ena_dis_br): Update test.
Diffstat (limited to 'gdb/probe.c')
-rw-r--r--gdb/probe.c50
1 files changed, 22 insertions, 28 deletions
diff --git a/gdb/probe.c b/gdb/probe.c
index 7b3b888..970d5bd 100644
--- a/gdb/probe.c
+++ b/gdb/probe.c
@@ -275,8 +275,8 @@ find_probe_by_pc (CORE_ADDR pc)
Each argument is a regexp, or NULL, which matches anything. */
static VEC (bound_probe_s) *
-collect_probes (char *objname, char *provider, char *probe_name,
- const struct probe_ops *pops)
+collect_probes (const std::string &objname, const std::string &provider,
+ const std::string &probe_name, const struct probe_ops *pops)
{
struct objfile *objfile;
VEC (bound_probe_s) *result = NULL;
@@ -285,12 +285,15 @@ collect_probes (char *objname, char *provider, char *probe_name,
cleanup = make_cleanup (VEC_cleanup (bound_probe_s), &result);
- if (provider != NULL)
- prov_pat.emplace (provider, REG_NOSUB, _("Invalid provider regexp"));
- if (probe_name != NULL)
- probe_pat.emplace (probe_name, REG_NOSUB, _("Invalid probe regexp"));
- if (objname != NULL)
- obj_pat.emplace (objname, REG_NOSUB, _("Invalid object file regexp"));
+ if (!provider.empty ())
+ prov_pat.emplace (provider.c_str (), REG_NOSUB,
+ _("Invalid provider regexp"));
+ if (!probe_name.empty ())
+ probe_pat.emplace (probe_name.c_str (), REG_NOSUB,
+ _("Invalid probe regexp"));
+ if (!objname.empty ())
+ obj_pat.emplace (objname.c_str (), REG_NOSUB,
+ _("Invalid object file regexp"));
ALL_OBJFILES (objfile)
{
@@ -301,7 +304,7 @@ collect_probes (char *objname, char *provider, char *probe_name,
if (! objfile->sf || ! objfile->sf->sym_probe_fns)
continue;
- if (objname)
+ if (obj_pat)
{
if (obj_pat->exec (objfile_name (objfile), 0, NULL, 0) != 0)
continue;
@@ -316,11 +319,11 @@ collect_probes (char *objname, char *provider, char *probe_name,
if (pops != NULL && probe->pops != pops)
continue;
- if (provider
+ if (prov_pat
&& prov_pat->exec (probe->provider, 0, NULL, 0) != 0)
continue;
- if (probe_name
+ if (probe_pat
&& probe_pat->exec (probe->name, 0, NULL, 0) != 0)
continue;
@@ -553,16 +556,16 @@ exists_probe_with_pops (VEC (bound_probe_s) *probes,
[PROBE [OBJNAME]]] from the provided string STR. */
static void
-parse_probe_linespec (const char *str, char **provider,
- char **probe_name, char **objname)
+parse_probe_linespec (const char *str, std::string *provider,
+ std::string *probe_name, std::string *objname)
{
- *probe_name = *objname = NULL;
+ *probe_name = *objname = "";
*provider = extract_arg (&str);
- if (*provider != NULL)
+ if (!provider->empty ())
{
*probe_name = extract_arg (&str);
- if (*probe_name != NULL)
+ if (!probe_name->empty ())
*objname = extract_arg (&str);
}
}
@@ -573,7 +576,7 @@ void
info_probes_for_ops (const char *arg, int from_tty,
const struct probe_ops *pops)
{
- char *provider, *probe_name = NULL, *objname = NULL;
+ std::string provider, probe_name, objname;
struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
VEC (bound_probe_s) *probes;
int i, any_found;
@@ -587,9 +590,6 @@ info_probes_for_ops (const char *arg, int from_tty,
struct gdbarch *gdbarch = get_current_arch ();
parse_probe_linespec (arg, &provider, &probe_name, &objname);
- make_cleanup (xfree, provider);
- make_cleanup (xfree, probe_name);
- make_cleanup (xfree, objname);
probes = collect_probes (objname, provider, probe_name, pops);
make_cleanup (VEC_cleanup (probe_p), &probes);
@@ -721,16 +721,13 @@ info_probes_command (char *arg, int from_tty)
static void
enable_probes_command (char *arg, int from_tty)
{
- char *provider, *probe_name = NULL, *objname = NULL;
+ std::string provider, probe_name, objname;
struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
VEC (bound_probe_s) *probes;
struct bound_probe *probe;
int i;
parse_probe_linespec ((const char *) arg, &provider, &probe_name, &objname);
- make_cleanup (xfree, provider);
- make_cleanup (xfree, probe_name);
- make_cleanup (xfree, objname);
probes = collect_probes (objname, provider, probe_name, NULL);
if (VEC_empty (bound_probe_s, probes))
@@ -765,16 +762,13 @@ enable_probes_command (char *arg, int from_tty)
static void
disable_probes_command (char *arg, int from_tty)
{
- char *provider, *probe_name = NULL, *objname = NULL;
+ std::string provider, probe_name, objname;
struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
VEC (bound_probe_s) *probes;
struct bound_probe *probe;
int i;
parse_probe_linespec ((const char *) arg, &provider, &probe_name, &objname);
- make_cleanup (xfree, provider);
- make_cleanup (xfree, probe_name);
- make_cleanup (xfree, objname);
probes = collect_probes (objname, provider, probe_name, NULL /* pops */);
if (VEC_empty (bound_probe_s, probes))