diff --git a/gdb/top.c b/gdb/top.c index 0b819091d11..92de30a1472 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -471,6 +471,8 @@ execute_command (const char *p, int from_tty) return; } + std::string cmd_copy = p; + target_log_command (p); while (*p == ' ' || *p == '\t') @@ -577,7 +579,7 @@ execute_command (const char *p, int from_tty) We need to lookup the command again since during its execution, a command may redefine itself. In this case, C pointer becomes invalid so we need to look it up again. */ - const char *cmd2 = cmd_start; + const char *cmd2 = cmd_copy.c_str (); c = lookup_cmd (&cmd2, cmdlist, "", nullptr, 1, 1); if (c != nullptr) execute_cmd_post_hook (c);