aboutsummaryrefslogtreecommitdiff
path: root/gdb/location.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2023-12-10 07:45:24 -0700
committerTom Tromey <tom@tromey.com>2023-12-13 14:12:52 -0700
commitfde841947e445a98f22a04465daa75a9fb6af051 (patch)
treef95774d5b6c4e560ee50c593ffd3241f8e0519bc /gdb/location.c
parente7cdec6605837a5b79442fc06bd66d6372025040 (diff)
downloadbinutils-fde841947e445a98f22a04465daa75a9fb6af051.zip
binutils-fde841947e445a98f22a04465daa75a9fb6af051.tar.gz
binutils-fde841947e445a98f22a04465daa75a9fb6af051.tar.bz2
Use unique_xmalloc_ptr in explicit_location_spec
This changes explicit_location_spec to use unique_xmalloc_ptr, removing some manual memory management. Reviewed-By: John Baldwin <jhb@FreeBSD.org>
Diffstat (limited to 'gdb/location.c')
-rw-r--r--gdb/location.c30
1 files changed, 12 insertions, 18 deletions
diff --git a/gdb/location.c b/gdb/location.c
index df9a7d5..876f138 100644
--- a/gdb/location.c
+++ b/gdb/location.c
@@ -156,25 +156,19 @@ address_location_spec::compute_string () const
return std::string ("*") + addr_string;
}
-explicit_location_spec::explicit_location_spec ()
- : location_spec (EXPLICIT_LOCATION_SPEC)
+explicit_location_spec::explicit_location_spec (const char *function_name)
+ : location_spec (EXPLICIT_LOCATION_SPEC),
+ function_name (maybe_xstrdup (function_name))
{
}
-explicit_location_spec::~explicit_location_spec ()
-{
- xfree (source_filename);
- xfree (function_name);
- xfree (label_name);
-}
-
explicit_location_spec::explicit_location_spec
(const explicit_location_spec &other)
: location_spec (other),
- source_filename (maybe_xstrdup (other.source_filename)),
- function_name (maybe_xstrdup (other.function_name)),
+ source_filename (maybe_xstrdup (other.source_filename.get ())),
+ function_name (maybe_xstrdup (other.function_name.get ())),
func_name_match_type (other.func_name_match_type),
- label_name (maybe_xstrdup (other.label_name)),
+ label_name (maybe_xstrdup (other.label_name.get ())),
line_offset (other.line_offset)
{
}
@@ -291,7 +285,7 @@ explicit_to_string_internal (bool as_linespec,
{
if (!as_linespec)
buf.puts ("-source ");
- buf.puts (explicit_loc->source_filename);
+ buf.puts (explicit_loc->source_filename.get ());
need_space = true;
}
@@ -303,7 +297,7 @@ explicit_to_string_internal (bool as_linespec,
buf.puts ("-qualified ");
if (!as_linespec)
buf.puts ("-function ");
- buf.puts (explicit_loc->function_name);
+ buf.puts (explicit_loc->function_name.get ());
need_space = true;
}
@@ -313,7 +307,7 @@ explicit_to_string_internal (bool as_linespec,
buf.putc (space);
if (!as_linespec)
buf.puts ("-label ");
- buf.puts (explicit_loc->label_name);
+ buf.puts (explicit_loc->label_name.get ());
need_space = true;
}
@@ -705,13 +699,13 @@ string_to_explicit_location_spec (const char **argp,
{
set_oarg (explicit_location_spec_lex_one (argp, language,
completion_info));
- locspec->source_filename = oarg.release ();
+ locspec->source_filename = std::move (oarg);
}
else if (strncmp (opt.get (), "-function", len) == 0)
{
set_oarg (explicit_location_spec_lex_one_function (argp, language,
completion_info));
- locspec->function_name = oarg.release ();
+ locspec->function_name = std::move (oarg);
}
else if (strncmp (opt.get (), "-qualified", len) == 0)
{
@@ -731,7 +725,7 @@ string_to_explicit_location_spec (const char **argp,
{
set_oarg (explicit_location_spec_lex_one (argp, language,
completion_info));
- locspec->label_name = oarg.release ();
+ locspec->label_name = std::move (oarg);
}
/* Only emit an "invalid argument" error for options
that look like option strings. */