diff options
author | Tom Tromey <tom@tromey.com> | 2024-10-08 19:31:51 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2024-10-20 10:13:05 -0600 |
commit | 40ae603e6e0fe21fd0c1677dcf4e137cf99c2ebe (patch) | |
tree | 37b815b09eb8c8da38cd0846cdc7cd9136149167 | |
parent | 32dc367249e85ecb2449d4be8cafc8e3fc2f359f (diff) | |
download | gdb-40ae603e6e0fe21fd0c1677dcf4e137cf99c2ebe.zip gdb-40ae603e6e0fe21fd0c1677dcf4e137cf99c2ebe.tar.gz gdb-40ae603e6e0fe21fd0c1677dcf4e137cf99c2ebe.tar.bz2 |
Use std::make_unique in more places
I searched for spots using ".reset (new ...)" and replaced most of
these with std::make_unique. I think this is a bit cleaner and more
idiomatic.
Regression tested on x86-64 Fedora 40.
Reviewed-By: Klaus Gerlicher<klaus.gerlicher@intel.com>
-rw-r--r-- | gdb/breakpoint.c | 4 | ||||
-rw-r--r-- | gdb/cli/cli-interp.c | 2 | ||||
-rw-r--r-- | gdb/dwarf2/cu.c | 9 | ||||
-rw-r--r-- | gdb/dwarf2/read.c | 16 | ||||
-rw-r--r-- | gdb/jit.c | 7 | ||||
-rw-r--r-- | gdb/osdata.c | 2 | ||||
-rw-r--r-- | gdb/parse.c | 2 | ||||
-rw-r--r-- | gdb/regcache-dump.c | 14 | ||||
-rw-r--r-- | gdb/remote.c | 4 | ||||
-rw-r--r-- | gdb/typeprint.c | 4 | ||||
-rw-r--r-- | gdb/ui-out.c | 2 |
11 files changed, 35 insertions, 31 deletions
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 4cf6857..b7e4f5d 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -10494,9 +10494,9 @@ watch_command_1 (const char *arg, int accessflag, int from_tty, std::unique_ptr<watchpoint> w; if (use_mask) - w.reset (new masked_watchpoint (nullptr, bp_type)); + w = std::make_unique<masked_watchpoint> (nullptr, bp_type); else - w.reset (new watchpoint (nullptr, bp_type)); + w = std::make_unique<watchpoint> (nullptr, bp_type); /* At most one of thread or task can be set on a watchpoint. */ gdb_assert (thread == -1 || task == -1); diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c index 1817573..dbe2ed1 100644 --- a/gdb/cli/cli-interp.c +++ b/gdb/cli/cli-interp.c @@ -269,7 +269,7 @@ cli_interp_base::set_logging (ui_file_up logfile, bool logging_redirect, if (logfile != nullptr) { gdb_assert (m_saved_output == nullptr); - m_saved_output.reset (new saved_output_files); + m_saved_output = std::make_unique<saved_output_files> (); m_saved_output->out = gdb_stdout; m_saved_output->err = gdb_stderr; m_saved_output->log = gdb_stdlog; diff --git a/gdb/dwarf2/cu.c b/gdb/dwarf2/cu.c index 5cb2291..76cdd6f 100644 --- a/gdb/dwarf2/cu.c +++ b/gdb/dwarf2/cu.c @@ -77,9 +77,12 @@ dwarf2_cu::start_compunit_symtab (const char *name, const char *comp_dir, name_for_id = name_for_id_holder.c_str (); } - m_builder.reset (new struct buildsym_compunit - (this->per_objfile->objfile, - name, comp_dir, name_for_id, lang (), low_pc)); + m_builder = std::make_unique<buildsym_compunit> (this->per_objfile->objfile, + name, + comp_dir, + name_for_id, + lang (), + low_pc); list_in_scope = get_builder ()->get_file_symbols (); diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index bd2de02..cc49c47 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -3970,7 +3970,7 @@ cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data *this_cu, /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu in per_objfile yet. */ gdb_assert (per_objfile->get_cu (this_cu) == nullptr); - m_new_cu.reset (new dwarf2_cu (this_cu, per_objfile)); + m_new_cu = std::make_unique<dwarf2_cu> (this_cu, per_objfile); cu = m_new_cu.get (); } @@ -4067,7 +4067,7 @@ cutu_reader::cutu_reader (dwarf2_per_cu_data *this_cu, thread-safe. */ gdb_assert (cache != nullptr || per_objfile->get_cu (this_cu) == nullptr); - m_new_cu.reset (new dwarf2_cu (this_cu, per_objfile)); + m_new_cu = std::make_unique<dwarf2_cu> (this_cu, per_objfile); cu = m_new_cu.get (); } @@ -4257,7 +4257,7 @@ cutu_reader::cutu_reader (dwarf2_per_cu_data *this_cu, /* This is cheap if the section is already read in. */ section->read (objfile); - m_new_cu.reset (new dwarf2_cu (this_cu, per_objfile)); + m_new_cu = std::make_unique<dwarf2_cu> (this_cu, per_objfile); begin_info_ptr = info_ptr = section->buffer + to_underlying (this_cu->sect_off); info_ptr = read_and_check_comp_unit_head (per_objfile, &m_new_cu->header, @@ -7366,7 +7366,7 @@ find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu) res.set_name (make_unique_xstrdup (lbasename (res.get_name ()))); } - cu->per_cu->fnd.reset (new file_and_directory (std::move (res))); + cu->per_cu->fnd = std::make_unique<file_and_directory> (std::move (res)); return *cu->per_cu->fnd; } @@ -7612,11 +7612,11 @@ dwarf2_cu::setup_type_unit_groups (struct die_info *die) gdb_assert (tug_unshare->symtabs == NULL); gdb_assert (m_builder == nullptr); struct compunit_symtab *cust = tug_unshare->compunit_symtab; - m_builder.reset (new struct buildsym_compunit + m_builder = std::make_unique<buildsym_compunit> (cust->objfile (), "", cust->dirname (), cust->language (), - 0, cust)); + 0, cust); list_in_scope = get_builder ()->get_file_symbols (); } return; @@ -7666,11 +7666,11 @@ dwarf2_cu::setup_type_unit_groups (struct die_info *die) { gdb_assert (m_builder == nullptr); struct compunit_symtab *cust = tug_unshare->compunit_symtab; - m_builder.reset (new struct buildsym_compunit + m_builder = std::make_unique<buildsym_compunit> (cust->objfile (), "", cust->dirname (), cust->language (), - 0, cust)); + 0, cust); list_in_scope = get_builder ()->get_file_symbols (); auto &file_names = line_header->file_names (); @@ -222,7 +222,7 @@ static jiter_objfile_data * get_jiter_objfile_data (objfile *objf) { if (objf->jiter_data == nullptr) - objf->jiter_data.reset (new jiter_objfile_data ()); + objf->jiter_data = std::make_unique<jiter_objfile_data> (); return objf->jiter_data.get (); } @@ -236,8 +236,9 @@ add_objfile_entry (struct objfile *objfile, CORE_ADDR entry, { gdb_assert (objfile->jited_data == nullptr); - objfile->jited_data.reset (new jited_objfile_data (entry, symfile_addr, - symfile_size)); + objfile->jited_data = std::make_unique<jited_objfile_data> (entry, + symfile_addr, + symfile_size); } /* Helper function for reading the global JIT descriptor from remote diff --git a/gdb/osdata.c b/gdb/osdata.c index e4d9b0b..e22c249 100644 --- a/gdb/osdata.c +++ b/gdb/osdata.c @@ -63,7 +63,7 @@ osdata_start_osdata (struct gdb_xml_parser *parser, gdb_xml_error (parser, _("Seen more than on osdata element")); char *type = (char *) xml_find_attribute (attributes, "type")->value.get (); - data->osdata.reset (new struct osdata (std::string (type))); + data->osdata = std::make_unique<osdata> (std::string (type)); } /* Handle the start of a <item> element. */ diff --git a/gdb/parse.c b/gdb/parse.c index e0837de..ffefe6f 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -100,7 +100,7 @@ void parser_state::mark_struct_expression (expr::structop_base_operation *op) { gdb_assert (parse_completion && m_completion_state == nullptr); - m_completion_state.reset (new expr_complete_structop (op)); + m_completion_state = std::make_unique<expr_complete_structop> (op); } /* Indicate that the current parser invocation is completing a tag. diff --git a/gdb/regcache-dump.c b/gdb/regcache-dump.c index 6b711bf..3e68805 100644 --- a/gdb/regcache-dump.c +++ b/gdb/regcache-dump.c @@ -244,13 +244,13 @@ regcache_print (const char *args, enum regcache_dump_what what_to_dump) switch (what_to_dump) { case regcache_dump_none: - dump.reset (new register_dump_none (gdbarch)); + dump = std::make_unique<register_dump_none> (gdbarch); break; case regcache_dump_remote: - dump.reset (new register_dump_remote (gdbarch)); + dump = std::make_unique<register_dump_remote> (gdbarch); break; case regcache_dump_groups: - dump.reset (new register_dump_groups (gdbarch)); + dump = std::make_unique<register_dump_groups> (gdbarch); break; case regcache_dump_raw: case regcache_dump_cooked: @@ -258,15 +258,15 @@ regcache_print (const char *args, enum regcache_dump_what what_to_dump) auto dump_pseudo = (what_to_dump == regcache_dump_cooked); if (target_has_registers ()) - dump.reset (new register_dump_regcache (get_thread_regcache - (inferior_thread ()), - dump_pseudo)); + dump = (std::make_unique<register_dump_regcache> + (get_thread_regcache (inferior_thread ()), dump_pseudo)); else { /* For the benefit of "maint print registers" & co when debugging an executable, allow dumping a regcache even when there is no thread selected / no registers. */ - dump.reset (new register_dump_reg_buffer (gdbarch, dump_pseudo)); + dump = std::make_unique<register_dump_reg_buffer> (gdbarch, + dump_pseudo); } } break; diff --git a/gdb/remote.c b/gdb/remote.c index 5323491..fdd83ec 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -3049,7 +3049,7 @@ get_remote_thread_info (thread_info *thread) gdb_assert (thread != NULL); if (thread->priv == NULL) - thread->priv.reset (new remote_thread_info); + thread->priv = std::make_unique<remote_thread_info> (); return gdb::checked_static_cast<remote_thread_info *> (thread->priv.get ()); } @@ -7099,7 +7099,7 @@ static remote_inferior * get_remote_inferior (inferior *inf) { if (inf->priv == NULL) - inf->priv.reset (new remote_inferior); + inf->priv = std::make_unique<remote_inferior> (); return gdb::checked_static_cast<remote_inferior *> (inf->priv.get ()); } diff --git a/gdb/typeprint.c b/gdb/typeprint.c index 274f602..456d8dc 100644 --- a/gdb/typeprint.c +++ b/gdb/typeprint.c @@ -562,10 +562,10 @@ whatis_exp (const char *exp, int show) std::unique_ptr<ext_lang_type_printers> printer_holder; if (!flags.raw) { - table_holder.reset (new typedef_hash_table); + table_holder = std::make_unique<typedef_hash_table> (); flags.global_typedefs = table_holder.get (); - printer_holder.reset (new ext_lang_type_printers); + printer_holder = std::make_unique<ext_lang_type_printers> (); flags.global_printers = printer_holder.get (); } diff --git a/gdb/ui-out.c b/gdb/ui-out.c index 3330cc8..41ce6ef 100644 --- a/gdb/ui-out.c +++ b/gdb/ui-out.c @@ -353,7 +353,7 @@ ui_out::table_begin (int nr_cols, int nr_rows, const std::string &tblid) internal_error (_("tables cannot be nested; table_begin found before \ previous table_end.")); - m_table_up.reset (new ui_out_table (level () + 1, nr_cols, tblid)); + m_table_up = std::make_unique<ui_out_table> (level () + 1, nr_cols, tblid); do_table_begin (nr_cols, nr_rows, tblid.c_str ()); } |