From: Simon Marchi Date: Sun, 3 Sep 2017 08:23:31 +0000 (+0200) Subject: Make target_waitstatus_to_string return an std::string X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=23fdd69e42180578b3e15ba8f053fadde965bfe8;p=binutils-gdb.git Make target_waitstatus_to_string return an std::string A quite straightforward change. It does "fix" leaks in record-btrace.c, although since this is only used in debug printing code, it has no real world impact. gdb/ChangeLog: * target/waitstatus.h (target_waitstatus_to_string): Change return type to std::string. * target/waitstatus.c (target_waitstatus_to_string): Return std::string. * target.h (target_waitstatus_to_string): Remove declaration. * infrun.c (resume, clear_proceed_status_thread, print_target_wait_results, do_target_wait, save_waitstatus, stop_all_threads): Adjust. * record-btrace.c (record_btrace_wait): Adjust. * target-debug.h (target_debug_print_struct_target_waitstatus_p): Adjust. gdb/gdbserver/ChangeLog: * linux-low.c (linux_wait_1): Adjust. * server.c (queue_stop_reply_callback): Adjust. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 44dfe5b7945..71566bdc65f 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,17 @@ +2017-09-03 Simon Marchi + + * target/waitstatus.h (target_waitstatus_to_string): Change + return type to std::string. + * target/waitstatus.c (target_waitstatus_to_string): Return + std::string. + * target.h (target_waitstatus_to_string): Remove declaration. + * infrun.c (resume, clear_proceed_status_thread, + print_target_wait_results, do_target_wait, save_waitstatus, + stop_all_threads): Adjust. + * record-btrace.c (record_btrace_wait): Adjust. + * target-debug.h + (target_debug_print_struct_target_waitstatus_p): Adjust. + 2017-09-01 Jan Kratochvil PR gdb/22046 diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index 492f0ab9ed5..e5635d8c51a 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,3 +1,8 @@ +2017-09-03 Simon Marchi + + * linux-low.c (linux_wait_1): Adjust. + * server.c (queue_stop_reply_callback): Adjust. + 2017-08-31 Sergio Durigan Junior * server.c (handle_general_set): Handle QEnvironmentHexEncoded, diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index fd46d85ed5a..6f4b26afb94 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -3733,12 +3733,11 @@ linux_wait_1 (ptid_t ptid, { if (event_child->waitstatus.kind != TARGET_WAITKIND_IGNORE) { - char *str; + std::string str + = target_waitstatus_to_string (&event_child->waitstatus); - str = target_waitstatus_to_string (&event_child->waitstatus); debug_printf ("LWP %ld: extended event with waitstatus %s\n", - lwpid_of (get_lwp_thread (event_child)), str); - xfree (str); + lwpid_of (get_lwp_thread (event_child)), str.c_str ()); } if (current_thread->last_resume_kind == resume_step) { diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c index 88a5ddc393f..7210d1ff9d3 100644 --- a/gdb/gdbserver/server.c +++ b/gdb/gdbserver/server.c @@ -3181,14 +3181,12 @@ queue_stop_reply_callback (struct inferior_list_entry *entry, void *arg) { if (debug_threads) { - char *status_string + std::string status_string = target_waitstatus_to_string (&thread->last_status); debug_printf ("Reporting thread %s as already stopped with %s\n", target_pid_to_str (entry->id), - status_string); - - xfree (status_string); + status_string.c_str ()); } gdb_assert (thread->last_status.kind != TARGET_WAITKIND_IGNORE); diff --git a/gdb/infrun.c b/gdb/infrun.c index d0e41055d91..06b45b44ed6 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -2409,15 +2409,14 @@ resume (enum gdb_signal sig) { if (debug_infrun) { - char *statstr; + std::string statstr + = target_waitstatus_to_string (&tp->suspend.waitstatus); - statstr = target_waitstatus_to_string (&tp->suspend.waitstatus); fprintf_unfiltered (gdb_stdlog, - "infrun: resume: thread %s has pending wait status %s " - "(currently_stepping=%d).\n", - target_pid_to_str (tp->ptid), statstr, + "infrun: resume: thread %s has pending wait " + "status %s (currently_stepping=%d).\n", + target_pid_to_str (tp->ptid), statstr.c_str (), currently_stepping (tp)); - xfree (statstr); } tp->resumed = 1; @@ -2820,16 +2819,15 @@ clear_proceed_status_thread (struct thread_info *tp) } else if (debug_infrun) { - char *statstr; + std::string statstr + = target_waitstatus_to_string (&tp->suspend.waitstatus); - statstr = target_waitstatus_to_string (&tp->suspend.waitstatus); fprintf_unfiltered (gdb_stdlog, "infrun: clear_proceed_status_thread: thread %s " "has pending wait status %s " "(currently_stepping=%d).\n", - target_pid_to_str (tp->ptid), statstr, + target_pid_to_str (tp->ptid), statstr.c_str (), currently_stepping (tp)); - xfree (statstr); } } @@ -3418,7 +3416,7 @@ void print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid, const struct target_waitstatus *ws) { - char *status_string = target_waitstatus_to_string (ws); + std::string status_string = target_waitstatus_to_string (ws); string_file stb; /* The text is split over several lines because it was getting too long. @@ -3438,13 +3436,11 @@ print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid, ptid_get_lwp (result_ptid), ptid_get_tid (result_ptid), target_pid_to_str (result_ptid)); - stb.printf ("infrun: %s\n", status_string); + stb.printf ("infrun: %s\n", status_string.c_str ()); /* This uses %s in part to handle %'s in the text, but also to avoid a gcc error: the format attribute requires a string literal. */ fprintf_unfiltered (gdb_stdlog, "%s", stb.c_str ()); - - xfree (status_string); } /* Select a thread at random, out of those which are resumed and have @@ -3566,14 +3562,13 @@ do_target_wait (ptid_t ptid, struct target_waitstatus *status, int options) { if (debug_infrun) { - char *statstr; + std::string statstr + = target_waitstatus_to_string (&tp->suspend.waitstatus); - statstr = target_waitstatus_to_string (&tp->suspend.waitstatus); fprintf_unfiltered (gdb_stdlog, "infrun: Using pending wait status %s for %s.\n", - statstr, + statstr.c_str (), target_pid_to_str (tp->ptid)); - xfree (statstr); } /* Now that we've selected our final event LWP, un-adjust its PC @@ -4395,16 +4390,14 @@ save_waitstatus (struct thread_info *tp, struct target_waitstatus *ws) if (debug_infrun) { - char *statstr; + std::string statstr = target_waitstatus_to_string (ws); - statstr = target_waitstatus_to_string (ws); fprintf_unfiltered (gdb_stdlog, "infrun: saving status %s for %d.%ld.%ld\n", - statstr, + statstr.c_str (), ptid_get_pid (tp->ptid), ptid_get_lwp (tp->ptid), ptid_get_tid (tp->ptid)); - xfree (statstr); } /* Record for later. */ @@ -4634,17 +4627,15 @@ stop_all_threads (void) if (debug_infrun) { - char *statstr; + std::string statstr = target_waitstatus_to_string (&ws); - statstr = target_waitstatus_to_string (&ws); fprintf_unfiltered (gdb_stdlog, "infrun: target_wait %s, saving " "status for %d.%ld.%ld\n", - statstr, + statstr.c_str (), ptid_get_pid (t->ptid), ptid_get_lwp (t->ptid), ptid_get_tid (t->ptid)); - xfree (statstr); } /* Record for later. */ diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c index b216f1f9cad..6ac85734f89 100644 --- a/gdb/record-btrace.c +++ b/gdb/record-btrace.c @@ -2478,7 +2478,7 @@ record_btrace_wait (struct target_ops *ops, ptid_t ptid, *status = btrace_step_no_resumed (); DEBUG ("wait ended by %s: %s", target_pid_to_str (null_ptid), - target_waitstatus_to_string (status)); + target_waitstatus_to_string (status).c_str ()); do_cleanups (cleanups); return null_ptid; @@ -2570,7 +2570,7 @@ record_btrace_wait (struct target_ops *ops, ptid_t ptid, DEBUG ("wait ended by thread %s (%s): %s", print_thread_id (eventing), target_pid_to_str (eventing->ptid), - target_waitstatus_to_string (status)); + target_waitstatus_to_string (status).c_str ()); do_cleanups (cleanups); return eventing->ptid; diff --git a/gdb/target-debug.h b/gdb/target-debug.h index 6923608afdf..532e98d45de 100644 --- a/gdb/target-debug.h +++ b/gdb/target-debug.h @@ -166,10 +166,9 @@ static void target_debug_print_struct_target_waitstatus_p (struct target_waitstatus *status) { - char *str = target_waitstatus_to_string (status); + std::string str = target_waitstatus_to_string (status); - fputs_unfiltered (str, gdb_stdlog); - xfree (str); + fputs_unfiltered (str.c_str (), gdb_stdlog); } diff --git a/gdb/target.h b/gdb/target.h index c0155c17a19..5971151ded9 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -108,10 +108,6 @@ struct syscall const char *name; }; -/* Return a pretty printed form of target_waitstatus. - Space for the result is malloc'd, caller must free. */ -extern char *target_waitstatus_to_string (const struct target_waitstatus *); - /* Return a pretty printed form of TARGET_OPTIONS. Space for the result is malloc'd, caller must free. */ extern char *target_options_to_string (int target_options); diff --git a/gdb/target/waitstatus.c b/gdb/target/waitstatus.c index c59d1b64784..eede2d631cd 100644 --- a/gdb/target/waitstatus.c +++ b/gdb/target/waitstatus.c @@ -23,7 +23,7 @@ /* Return a pretty printed form of target_waitstatus. Space for the result is malloc'd, caller must free. */ -char * +std::string target_waitstatus_to_string (const struct target_waitstatus *ws) { const char *kind_str = "status->kind = "; @@ -31,44 +31,44 @@ target_waitstatus_to_string (const struct target_waitstatus *ws) switch (ws->kind) { case TARGET_WAITKIND_EXITED: - return xstrprintf ("%sexited, status = %d", - kind_str, ws->value.integer); + return string_printf ("%sexited, status = %d", + kind_str, ws->value.integer); case TARGET_WAITKIND_STOPPED: - return xstrprintf ("%sstopped, signal = %s", - kind_str, - gdb_signal_to_symbol_string (ws->value.sig)); + return string_printf ("%sstopped, signal = %s", + kind_str, + gdb_signal_to_symbol_string (ws->value.sig)); case TARGET_WAITKIND_SIGNALLED: - return xstrprintf ("%ssignalled, signal = %s", - kind_str, - gdb_signal_to_symbol_string (ws->value.sig)); + return string_printf ("%ssignalled, signal = %s", + kind_str, + gdb_signal_to_symbol_string (ws->value.sig)); case TARGET_WAITKIND_LOADED: - return xstrprintf ("%sloaded", kind_str); + return string_printf ("%sloaded", kind_str); case TARGET_WAITKIND_FORKED: - return xstrprintf ("%sforked", kind_str); + return string_printf ("%sforked", kind_str); case TARGET_WAITKIND_VFORKED: - return xstrprintf ("%svforked", kind_str); + return string_printf ("%svforked", kind_str); case TARGET_WAITKIND_EXECD: - return xstrprintf ("%sexecd", kind_str); + return string_printf ("%sexecd", kind_str); case TARGET_WAITKIND_VFORK_DONE: - return xstrprintf ("%svfork-done", kind_str); + return string_printf ("%svfork-done", kind_str); case TARGET_WAITKIND_SYSCALL_ENTRY: - return xstrprintf ("%sentered syscall", kind_str); + return string_printf ("%sentered syscall", kind_str); case TARGET_WAITKIND_SYSCALL_RETURN: - return xstrprintf ("%sexited syscall", kind_str); + return string_printf ("%sexited syscall", kind_str); case TARGET_WAITKIND_SPURIOUS: - return xstrprintf ("%sspurious", kind_str); + return string_printf ("%sspurious", kind_str); case TARGET_WAITKIND_IGNORE: - return xstrprintf ("%signore", kind_str); + return string_printf ("%signore", kind_str); case TARGET_WAITKIND_NO_HISTORY: - return xstrprintf ("%sno-history", kind_str); + return string_printf ("%sno-history", kind_str); case TARGET_WAITKIND_NO_RESUMED: - return xstrprintf ("%sno-resumed", kind_str); + return string_printf ("%sno-resumed", kind_str); case TARGET_WAITKIND_THREAD_CREATED: - return xstrprintf ("%sthread created", kind_str); + return string_printf ("%sthread created", kind_str); case TARGET_WAITKIND_THREAD_EXITED: - return xstrprintf ("%sthread exited, status = %d", - kind_str, ws->value.integer); + return string_printf ("%sthread exited, status = %d", + kind_str, ws->value.integer); default: - return xstrprintf ("%sunknown???", kind_str); + return string_printf ("%sunknown???", kind_str); } } diff --git a/gdb/target/waitstatus.h b/gdb/target/waitstatus.h index 52be3907e35..8eee198f987 100644 --- a/gdb/target/waitstatus.h +++ b/gdb/target/waitstatus.h @@ -145,8 +145,7 @@ enum target_stop_reason /* Prototypes */ -/* Return a pretty printed form of target_waitstatus. - Space for the result is malloc'd, caller must free. */ -extern char *target_waitstatus_to_string (const struct target_waitstatus *); +/* Return a pretty printed form of target_waitstatus. */ +std::string target_waitstatus_to_string (const struct target_waitstatus *); #endif /* WAITSTATUS_H */