/* General Compile and inject code
- Copyright (C) 2014-2020 Free Software Foundation, Inc.
+ Copyright (C) 2014-2021 Free Software Foundation, Inc.
This file is part of GDB.
get_args (const compile_instance *compiler, struct gdbarch *gdbarch)
{
const char *cs_producer_options;
+ gdb_argv result;
- gdb_argv result (gdbarch_gcc_target_options (gdbarch).c_str ());
+ std::string gcc_options = gdbarch_gcc_target_options (gdbarch);
+
+ /* Make sure we have a non-empty set of options, otherwise GCC will
+ error out trying to look for a filename that is an empty string. */
+ if (!gcc_options.empty ())
+ result = gdb_argv (gcc_options.c_str ());
cs_producer_options = get_selected_pc_producer_options ();
if (cs_producer_options != NULL)
expr_pc = get_frame_address_in_block (get_selected_frame (NULL));
/* Set up instance and context for the compiler. */
- std::unique_ptr <compile_instance> compiler
- (current_language->get_compile_instance ());
+ std::unique_ptr<compile_instance> compiler
+ = current_language->get_compile_instance ();
if (compiler == nullptr)
error (_("No compiler support for language %s."),
current_language->name ());
const char *arch_rx = gdbarch_gnu_triplet_regexp (gdbarch);
/* Allow triplets with or without vendor set. */
- triplet_rx = std::string (arch_rx) + "(-[^-]*)?-" + os_rx;
+ triplet_rx = std::string (arch_rx) + "(-[^-]*)?-";
+ if (os_rx != nullptr)
+ triplet_rx += os_rx;
compiler->set_triplet_regexp (triplet_rx.c_str ());
}
int argc = argv_holder.count ();
char **argv = argv_holder.get ();
- gdb::unique_xmalloc_ptr<char> error_message;
- error_message.reset (compiler->set_arguments (argc, argv,
- triplet_rx.c_str ()));
+ gdb::unique_xmalloc_ptr<char> error_message
+ = compiler->set_arguments (argc, argv, triplet_rx.c_str ());
if (error_message != NULL)
error ("%s", error_message.get ());
/* See compile-internal.h. */
-char *
+gdb::unique_xmalloc_ptr<char>
compile_instance::set_arguments (int argc, char **argv, const char *regexp)
{
if (version () >= GCC_FE_VERSION_1)
- return FORWARD (set_arguments, argc, argv);
+ return gdb::unique_xmalloc_ptr<char> (FORWARD (set_arguments, argc, argv));
else
- return FORWARD (set_arguments_v0, regexp, argc, argv);
+ return gdb::unique_xmalloc_ptr<char> (FORWARD (set_arguments_v0, regexp,
+ argc, argv));
}
/* See compile-internal.h. */