mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-03 13:23:00 +08:00
Make linux_ptrace_attach_fail_reason return an std::string
This patch makes linux_ptrace_attach_fail_reason and linux_ptrace_attach_fail_reason_string return std::string. It also replaces usages of struct buffer with std::string. This allows getting rid of a cleanup in in linux_ptrace_attach_fail_reason_string and simplifies the code in general. Something that looks odd to me is that in linux_ptrace_attach_fail_reason, if the two messages are appended, there is no separating space or \n, so the result won't be very nice. I left it as-is for now though. gdb/ChangeLog: * nat/linux-ptrace.h (linux_ptrace_attach_fail_reason): Return std::string. (linux_ptrace_attach_fail_reason_string): Likewise. * nat/linux-ptrace.c (linux_ptrace_attach_fail_reason): Likewise. (linux_ptrace_attach_fail_reason_string): Likewise. * linux-nat.c (attach_proc_task_lwp_callback): Adjust. gdb/gdbserver/ChangeLog: * linux-low.c (attach_proc_task_lwp_callback): Adjust to linux_ptrace_attach_fail_reason_string now returning an std::string. (linux_attach): Likewise. * thread-db.c (attach_thread): Likewise.
This commit is contained in:
@ -1167,10 +1167,11 @@ attach_proc_task_lwp_callback (ptid_t ptid)
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string reason
|
||||
= linux_ptrace_attach_fail_reason_string (ptid, err);
|
||||
|
||||
warning (_("Cannot attach to lwp %d: %s"),
|
||||
lwpid,
|
||||
linux_ptrace_attach_fail_reason_string (ptid,
|
||||
err));
|
||||
lwpid, reason.c_str ());
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -1223,18 +1224,10 @@ linux_nat_attach (struct target_ops *ops, const char *args, int from_tty)
|
||||
CATCH (ex, RETURN_MASK_ERROR)
|
||||
{
|
||||
pid_t pid = parse_pid_to_attach (args);
|
||||
struct buffer buffer;
|
||||
char *buffer_s;
|
||||
std::string reason = linux_ptrace_attach_fail_reason (pid);
|
||||
|
||||
buffer_init (&buffer);
|
||||
linux_ptrace_attach_fail_reason (pid, &buffer);
|
||||
|
||||
buffer_grow_str0 (&buffer, "");
|
||||
buffer_s = buffer_finish (&buffer);
|
||||
make_cleanup (xfree, buffer_s);
|
||||
|
||||
if (*buffer_s != '\0')
|
||||
throw_error (ex.error, "warning: %s\n%s", buffer_s, ex.message);
|
||||
if (!reason.empty ())
|
||||
throw_error (ex.error, "warning: %s\n%s", reason.c_str (), ex.message);
|
||||
else
|
||||
throw_error (ex.error, "%s", ex.message);
|
||||
}
|
||||
|
Reference in New Issue
Block a user