diff --git a/gdb/corelow.c b/gdb/corelow.c index 9b9bee05bac..ee57a9c4865 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -1169,27 +1169,22 @@ core_target_open (const char *arg, int from_tty) if (ctx.valid ()) { - std::string args; - for (const auto &a : ctx.args ()) - { - args += ' '; - args += a.get (); - } - - gdb_printf (_("Core was generated by `%ps%s'.\n"), - styled_string (file_name_style.style (), - ctx.execfn ()), - args.c_str ()); - /* Copy the arguments into the inferior. */ std::vector argv; - for (const auto &a : ctx.args ()) + for (const gdb::unique_xmalloc_ptr &a : ctx.args ()) argv.push_back (a.get ()); gdb::array_view view (argv.data (), argv.size ()); current_inferior ()->set_args (view); /* And now copy the environment. */ current_inferior ()->environment = ctx.environment (); + + /* Inform the user of executable and arguments. */ + const std::string &args = current_inferior ()->args (); + gdb_printf (_("Core was generated by `%ps%s%s'.\n"), + styled_string (file_name_style.style (), + ctx.execfn ()), + (args.length () > 0 ? " " : ""), args.c_str ()); } else { diff --git a/gdb/testsuite/gdb.base/corefile-exec-context.exp b/gdb/testsuite/gdb.base/corefile-exec-context.exp index 73e13e60d75..d6d4c0de4be 100644 --- a/gdb/testsuite/gdb.base/corefile-exec-context.exp +++ b/gdb/testsuite/gdb.base/corefile-exec-context.exp @@ -69,7 +69,7 @@ gdb_test_multiple "core-file $corefile_1" "load core file no args" { } # Generate a core file, this time pass some arguments to the inferior. -set args "aaaaa bbbbb ccccc ddddd eeeee" +set args "aaaaa bbbbb ccccc ddddd e\\\\ e\\\\ e\\\\ e\\\\ e" set corefile [core_find $binfile {} $args] if {$corefile == ""} { untested "unable to create corefile" @@ -101,6 +101,27 @@ gdb_test_multiple "core-file $corefile_2" "load core file with args" { gdb_test "show args" \ "Argument list to give program being debugged when it is started is \"$args\"\\." +# Move up to 'main'. Do it this way because we cannot know how many +# frames up 'main' actually is. +gdb_test_multiple "up" "move up to main" { + -re -wrap "#$decimal\\s+\[^\r\n\]+ in main .*" { + pass $gdb_test_name + } + + -re -wrap "#$decimal\\s+\[^\r\n\]+ in .*" { + send_gdb "up\n" + exp_continue + } +} + +# Check that the inferior was started with the expected arguments. +gdb_test "print argc" " = 6" +gdb_test "print argv\[1\]" " = $hex \"aaaaa\"" +gdb_test "print argv\[2\]" " = $hex \"bbbbb\"" +gdb_test "print argv\[3\]" " = $hex \"ccccc\"" +gdb_test "print argv\[4\]" " = $hex \"ddddd\"" +gdb_test "print argv\[5\]" " = $hex \"e e e e e\"" + # Find the name of an environment variable that is not set. set env_var_base "GDB_TEST_ENV_VAR_" set env_var_name ""