* [RFA] Include thread ID in target_wait debugging output.
@ 2009-02-26 19:22 Doug Evans
2009-02-27 19:56 ` Pedro Alves
0 siblings, 1 reply; 5+ messages in thread
From: Doug Evans @ 2009-02-26 19:22 UTC (permalink / raw)
To: gdb-patches
Hi.
Printing the result of target_wait when "set debug infrun 1" is great,
but I've found I've needed the thread ID.
The output line was getting a bit long, so I split it up.
There are other ways to split it up, but this works for me.
Ok to check in?
2009-02-26 Doug Evans <dje@google.com>
Include thread ID in target_wait debugging output.
* infrun.c (print_target_wait_results): New function.
(wait_for_inferior,fetch_inferior_event): Call it.
Index: infrun.c
===================================================================
RCS file: /cvs/src/src/gdb/infrun.c,v
retrieving revision 1.360
diff -u -p -r1.360 infrun.c
--- infrun.c 25 Feb 2009 02:14:22 -0000 1.360
+++ infrun.c 26 Feb 2009 18:34:57 -0000
@@ -1737,6 +1737,30 @@ delete_step_thread_step_resume_breakpoin
delete_step_thread_step_resume_breakpoint ();
}
+/* Pretty print the results of target_wait, for debugging purposes. */
+
+static 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);
+
+ fprintf_unfiltered (gdb_stdlog,
+ "infrun: target_wait (%d", PIDGET (waiton_ptid));
+ if (PIDGET (waiton_ptid) != -1)
+ fprintf_unfiltered (gdb_stdlog,
+ " [%s]", target_pid_to_str (waiton_ptid));
+ fprintf_unfiltered (gdb_stdlog, ", status) =\n");
+ fprintf_unfiltered (gdb_stdlog,
+ "infrun: %d [%s],\n",
+ PIDGET (result_ptid), target_pid_to_str (result_ptid));
+ fprintf_unfiltered (gdb_stdlog,
+ "infrun: %s\n",
+ status_string);
+
+ xfree (status_string);
+}
+
/* Wait for control to return from inferior to debugger.
If TREAT_EXEC_AS_SIGTRAP is non-zero, then handle EXEC signals
@@ -1790,14 +1814,7 @@ wait_for_inferior (int treat_exec_as_sig
ecs->ptid = target_wait (waiton_ptid, &ecs->ws);
if (debug_infrun)
- {
- char *status_string = target_waitstatus_to_string (&ecs->ws);
- fprintf_unfiltered (gdb_stdlog,
- "infrun: target_wait (%d, status) = %d, %s\n",
- PIDGET (waiton_ptid), PIDGET (ecs->ptid),
- status_string);
- xfree (status_string);
- }
+ print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
if (treat_exec_as_sigtrap && ecs->ws.kind == TARGET_WAITKIND_EXECD)
{
@@ -1875,14 +1892,7 @@ fetch_inferior_event (void *client_data)
ecs->ptid = target_wait (waiton_ptid, &ecs->ws);
if (debug_infrun)
- {
- char *status_string = target_waitstatus_to_string (&ecs->ws);
- fprintf_unfiltered (gdb_stdlog,
- "infrun: target_wait (%d, status) = %d, %s\n",
- PIDGET (waiton_ptid), PIDGET (ecs->ptid),
- status_string);
- xfree (status_string);
- }
+ print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
if (non_stop
&& ecs->ws.kind != TARGET_WAITKIND_IGNORE
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [RFA] Include thread ID in target_wait debugging output. 2009-02-26 19:22 [RFA] Include thread ID in target_wait debugging output Doug Evans @ 2009-02-27 19:56 ` Pedro Alves 2009-02-27 21:13 ` Doug Evans 0 siblings, 1 reply; 5+ messages in thread From: Pedro Alves @ 2009-02-27 19:56 UTC (permalink / raw) To: gdb-patches; +Cc: Doug Evans Hi Doug, On Thursday 26 February 2009 18:41:07, Doug Evans wrote: > Hi. > > Printing the result of target_wait when "set debug infrun 1" is great, > but I've found I've needed the thread ID. > > The output line was getting a bit long, so I split it up. > There are other ways to split it up, but this works for me. > The downside of that, is that "set debug timespamp" will print a timestamp for each piece of the log, and any signal debug output in async mode will mingle up. Maybe do the printing to a mem_fileopen buffer, and then print that to stderr in one go? An issue I though would be desirable to avoid here, is calling target_pid_to_str, which isn't garanteed to not have side effects. Introducing side effects when you enable debug output is undesirable. Maybe print the ptid in raw form, say, like: (pid, lwp, tid)? OTOH, infrun debugging output has been doing that for years, so it's probably fine... > Ok to check in? > > 2009-02-26 Doug Evans <dje@google.com> > > Include thread ID in target_wait debugging output. > * infrun.c (print_target_wait_results): New function. > (wait_for_inferior,fetch_inferior_event): Call it. > > Index: infrun.c > =================================================================== > RCS file: /cvs/src/src/gdb/infrun.c,v > retrieving revision 1.360 > diff -u -p -r1.360 infrun.c > --- infrun.c 25 Feb 2009 02:14:22 -0000 1.360 > +++ infrun.c 26 Feb 2009 18:34:57 -0000 > @@ -1737,6 +1737,30 @@ delete_step_thread_step_resume_breakpoin > delete_step_thread_step_resume_breakpoint (); > } > > +/* Pretty print the results of target_wait, for debugging purposes. */ > + > +static 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); > + > + fprintf_unfiltered (gdb_stdlog, > + "infrun: target_wait (%d", PIDGET (waiton_ptid)); > + if (PIDGET (waiton_ptid) != -1) > + fprintf_unfiltered (gdb_stdlog, > + " [%s]", target_pid_to_str (waiton_ptid)); > + fprintf_unfiltered (gdb_stdlog, ", status) =\n"); > + fprintf_unfiltered (gdb_stdlog, > + "infrun: %d [%s],\n", > + PIDGET (result_ptid), target_pid_to_str (result_ptid)); > + fprintf_unfiltered (gdb_stdlog, > + "infrun: %s\n", > + status_string); > + > + xfree (status_string); > +} > + > /* Wait for control to return from inferior to debugger. > > If TREAT_EXEC_AS_SIGTRAP is non-zero, then handle EXEC signals > @@ -1790,14 +1814,7 @@ wait_for_inferior (int treat_exec_as_sig > ecs->ptid = target_wait (waiton_ptid, &ecs->ws); > > if (debug_infrun) > - { > - char *status_string = target_waitstatus_to_string (&ecs->ws); > - fprintf_unfiltered (gdb_stdlog, > - "infrun: target_wait (%d, status) = %d, %s\n", > - PIDGET (waiton_ptid), PIDGET (ecs->ptid), > - status_string); > - xfree (status_string); > - } > + print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws); > > if (treat_exec_as_sigtrap && ecs->ws.kind == TARGET_WAITKIND_EXECD) > { > @@ -1875,14 +1892,7 @@ fetch_inferior_event (void *client_data) > ecs->ptid = target_wait (waiton_ptid, &ecs->ws); > > if (debug_infrun) > - { > - char *status_string = target_waitstatus_to_string (&ecs->ws); > - fprintf_unfiltered (gdb_stdlog, > - "infrun: target_wait (%d, status) = %d, %s\n", > - PIDGET (waiton_ptid), PIDGET (ecs->ptid), > - status_string); > - xfree (status_string); > - } > + print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws); > > if (non_stop > && ecs->ws.kind != TARGET_WAITKIND_IGNORE > -- Pedro Alves ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFA] Include thread ID in target_wait debugging output. 2009-02-27 19:56 ` Pedro Alves @ 2009-02-27 21:13 ` Doug Evans 2009-02-27 22:11 ` Doug Evans 0 siblings, 1 reply; 5+ messages in thread From: Doug Evans @ 2009-02-27 21:13 UTC (permalink / raw) To: Pedro Alves; +Cc: gdb-patches On Fri, Feb 27, 2009 at 11:41 AM, Pedro Alves <pedro@codesourcery.com> wrote: > Hi Doug, > > On Thursday 26 February 2009 18:41:07, Doug Evans wrote: >> Hi. >> >> Printing the result of target_wait when "set debug infrun 1" is great, >> but I've found I've needed the thread ID. >> >> The output line was getting a bit long, so I split it up. >> There are other ways to split it up, but this works for me. >> > > The downside of that, is that "set debug timespamp" will print > a timestamp for each piece of the log, and any signal debug > output in async mode will mingle up. Maybe do the printing to > a mem_fileopen buffer, and then print that to stderr in one go? Ok, I'll print to mem_fileopen first, and then print in one go. > An issue I though would be desirable to avoid here, is calling > target_pid_to_str, which isn't garanteed to not have side > effects. That's unfortunate. Is that documented somewhere? > Introducing side effects when you enable debug > output is undesirable. Yep. > Maybe print the ptid in raw form, say, > like: (pid, lwp, tid)? OTOH, infrun debugging output has been > doing that for years, so it's probably fine... Ya, there's LOTS of calls to target_pid_to_str for debugging output. > >> Ok to check in? >> >> 2009-02-26 Doug Evans <dje@google.com> >> >> Include thread ID in target_wait debugging output. >> * infrun.c (print_target_wait_results): New function. >> (wait_for_inferior,fetch_inferior_event): Call it. >> >> Index: infrun.c >> =================================================================== >> RCS file: /cvs/src/src/gdb/infrun.c,v >> retrieving revision 1.360 >> diff -u -p -r1.360 infrun.c >> --- infrun.c 25 Feb 2009 02:14:22 -0000 1.360 >> +++ infrun.c 26 Feb 2009 18:34:57 -0000 >> @@ -1737,6 +1737,30 @@ delete_step_thread_step_resume_breakpoin >> delete_step_thread_step_resume_breakpoint (); >> } >> >> +/* Pretty print the results of target_wait, for debugging purposes. */ >> + >> +static 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); >> + >> + fprintf_unfiltered (gdb_stdlog, >> + "infrun: target_wait (%d", PIDGET (waiton_ptid)); >> + if (PIDGET (waiton_ptid) != -1) >> + fprintf_unfiltered (gdb_stdlog, >> + " [%s]", target_pid_to_str (waiton_ptid)); >> + fprintf_unfiltered (gdb_stdlog, ", status) =\n"); >> + fprintf_unfiltered (gdb_stdlog, >> + "infrun: %d [%s],\n", >> + PIDGET (result_ptid), target_pid_to_str (result_ptid)); >> + fprintf_unfiltered (gdb_stdlog, >> + "infrun: %s\n", >> + status_string); >> + >> + xfree (status_string); >> +} >> + >> /* Wait for control to return from inferior to debugger. >> >> If TREAT_EXEC_AS_SIGTRAP is non-zero, then handle EXEC signals >> @@ -1790,14 +1814,7 @@ wait_for_inferior (int treat_exec_as_sig >> ecs->ptid = target_wait (waiton_ptid, &ecs->ws); >> >> if (debug_infrun) >> - { >> - char *status_string = target_waitstatus_to_string (&ecs->ws); >> - fprintf_unfiltered (gdb_stdlog, >> - "infrun: target_wait (%d, status) = %d, %s\n", >> - PIDGET (waiton_ptid), PIDGET (ecs->ptid), >> - status_string); >> - xfree (status_string); >> - } >> + print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws); >> >> if (treat_exec_as_sigtrap && ecs->ws.kind == TARGET_WAITKIND_EXECD) >> { >> @@ -1875,14 +1892,7 @@ fetch_inferior_event (void *client_data) >> ecs->ptid = target_wait (waiton_ptid, &ecs->ws); >> >> if (debug_infrun) >> - { >> - char *status_string = target_waitstatus_to_string (&ecs->ws); >> - fprintf_unfiltered (gdb_stdlog, >> - "infrun: target_wait (%d, status) = %d, %s\n", >> - PIDGET (waiton_ptid), PIDGET (ecs->ptid), >> - status_string); >> - xfree (status_string); >> - } >> + print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws); >> >> if (non_stop >> && ecs->ws.kind != TARGET_WAITKIND_IGNORE >> > > > > -- > Pedro Alves > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFA] Include thread ID in target_wait debugging output. 2009-02-27 21:13 ` Doug Evans @ 2009-02-27 22:11 ` Doug Evans 2009-02-27 22:14 ` Pedro Alves 0 siblings, 1 reply; 5+ messages in thread From: Doug Evans @ 2009-02-27 22:11 UTC (permalink / raw) To: Pedro Alves; +Cc: gdb-patches [-- Attachment #1: Type: text/plain, Size: 4765 bytes --] On Fri, Feb 27, 2009 at 11:56 AM, Doug Evans <dje@google.com> wrote: > On Fri, Feb 27, 2009 at 11:41 AM, Pedro Alves <pedro@codesourcery.com> wrote: >> Hi Doug, >> >> On Thursday 26 February 2009 18:41:07, Doug Evans wrote: >>> Hi. >>> >>> Printing the result of target_wait when "set debug infrun 1" is great, >>> but I've found I've needed the thread ID. >>> >>> The output line was getting a bit long, so I split it up. >>> There are other ways to split it up, but this works for me. >>> >> >> The downside of that, is that "set debug timespamp" will print >> a timestamp for each piece of the log, and any signal debug >> output in async mode will mingle up. Maybe do the printing to >> a mem_fileopen buffer, and then print that to stderr in one go? > > Ok, I'll print to mem_fileopen first, and then print in one go. > >> An issue I though would be desirable to avoid here, is calling >> target_pid_to_str, which isn't garanteed to not have side >> effects. > > That's unfortunate. Is that documented somewhere? > >> Introducing side effects when you enable debug >> output is undesirable. > > Yep. > >> Maybe print the ptid in raw form, say, >> like: (pid, lwp, tid)? OTOH, infrun debugging output has been >> doing that for years, so it's probably fine... > > Ya, there's LOTS of calls to target_pid_to_str for debugging output. > >> >>> Ok to check in? >>> >>> 2009-02-26 Doug Evans <dje@google.com> >>> >>> Include thread ID in target_wait debugging output. >>> * infrun.c (print_target_wait_results): New function. >>> (wait_for_inferior,fetch_inferior_event): Call it. >>> >>> Index: infrun.c >>> =================================================================== >>> RCS file: /cvs/src/src/gdb/infrun.c,v >>> retrieving revision 1.360 >>> diff -u -p -r1.360 infrun.c >>> --- infrun.c 25 Feb 2009 02:14:22 -0000 1.360 >>> +++ infrun.c 26 Feb 2009 18:34:57 -0000 >>> @@ -1737,6 +1737,30 @@ delete_step_thread_step_resume_breakpoin >>> delete_step_thread_step_resume_breakpoint (); >>> } >>> >>> +/* Pretty print the results of target_wait, for debugging purposes. */ >>> + >>> +static 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); >>> + >>> + fprintf_unfiltered (gdb_stdlog, >>> + "infrun: target_wait (%d", PIDGET (waiton_ptid)); >>> + if (PIDGET (waiton_ptid) != -1) >>> + fprintf_unfiltered (gdb_stdlog, >>> + " [%s]", target_pid_to_str (waiton_ptid)); >>> + fprintf_unfiltered (gdb_stdlog, ", status) =\n"); >>> + fprintf_unfiltered (gdb_stdlog, >>> + "infrun: %d [%s],\n", >>> + PIDGET (result_ptid), target_pid_to_str (result_ptid)); >>> + fprintf_unfiltered (gdb_stdlog, >>> + "infrun: %s\n", >>> + status_string); >>> + >>> + xfree (status_string); >>> +} >>> + >>> /* Wait for control to return from inferior to debugger. >>> >>> If TREAT_EXEC_AS_SIGTRAP is non-zero, then handle EXEC signals >>> @@ -1790,14 +1814,7 @@ wait_for_inferior (int treat_exec_as_sig >>> ecs->ptid = target_wait (waiton_ptid, &ecs->ws); >>> >>> if (debug_infrun) >>> - { >>> - char *status_string = target_waitstatus_to_string (&ecs->ws); >>> - fprintf_unfiltered (gdb_stdlog, >>> - "infrun: target_wait (%d, status) = %d, %s\n", >>> - PIDGET (waiton_ptid), PIDGET (ecs->ptid), >>> - status_string); >>> - xfree (status_string); >>> - } >>> + print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws); >>> >>> if (treat_exec_as_sigtrap && ecs->ws.kind == TARGET_WAITKIND_EXECD) >>> { >>> @@ -1875,14 +1892,7 @@ fetch_inferior_event (void *client_data) >>> ecs->ptid = target_wait (waiton_ptid, &ecs->ws); >>> >>> if (debug_infrun) >>> - { >>> - char *status_string = target_waitstatus_to_string (&ecs->ws); >>> - fprintf_unfiltered (gdb_stdlog, >>> - "infrun: target_wait (%d, status) = %d, %s\n", >>> - PIDGET (waiton_ptid), PIDGET (ecs->ptid), >>> - status_string); >>> - xfree (status_string); >>> - } >>> + print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws); >>> >>> if (non_stop >>> && ecs->ws.kind != TARGET_WAITKIND_IGNORE >>> >> >> How about this? 2009-02-27 Doug Evans <dje@google.com> Include thread ID in target_wait debugging output. * infrun.c (print_target_wait_results): New function. (wait_for_inferior,fetch_inferior_event): Call it. [-- Attachment #2: gdb-090227-debug-target-wait-2.patch.txt --] [-- Type: text/plain, Size: 3228 bytes --] 2009-02-27 Doug Evans <dje@google.com> Include thread ID in target_wait debugging output. * infrun.c (print_target_wait_results): New function. (wait_for_inferior,fetch_inferior_event): Call it. Index: infrun.c =================================================================== RCS file: /cvs/src/src/gdb/infrun.c,v retrieving revision 1.360 diff -u -p -u -p -r1.360 infrun.c --- infrun.c 25 Feb 2009 02:14:22 -0000 1.360 +++ infrun.c 27 Feb 2009 21:42:48 -0000 @@ -1737,6 +1737,46 @@ delete_step_thread_step_resume_breakpoin delete_step_thread_step_resume_breakpoint (); } +/* Pretty print the results of target_wait, for debugging purposes. */ + +static 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); + struct ui_file *tmp_stream = mem_fileopen (); + char *text; + long len; + + /* The text is split over several lines because it was getting too long. + Call fprintf_unfiltered (gdb_stdlog) once so that the text is still + output as a unit; we want only one timestamp printed if debug_timestamp + is set. */ + + fprintf_unfiltered (tmp_stream, + "infrun: target_wait (%d", PIDGET (waiton_ptid)); + if (PIDGET (waiton_ptid) != -1) + fprintf_unfiltered (tmp_stream, + " [%s]", target_pid_to_str (waiton_ptid)); + fprintf_unfiltered (tmp_stream, ", status) =\n"); + fprintf_unfiltered (tmp_stream, + "infrun: %d [%s],\n", + PIDGET (result_ptid), target_pid_to_str (result_ptid)); + fprintf_unfiltered (tmp_stream, + "infrun: %s\n", + status_string); + + text = ui_file_xstrdup (tmp_stream, &len); + + /* 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", text); + + xfree (status_string); + xfree (text); + ui_file_delete (tmp_stream); +} + /* Wait for control to return from inferior to debugger. If TREAT_EXEC_AS_SIGTRAP is non-zero, then handle EXEC signals @@ -1790,14 +1830,7 @@ wait_for_inferior (int treat_exec_as_sig ecs->ptid = target_wait (waiton_ptid, &ecs->ws); if (debug_infrun) - { - char *status_string = target_waitstatus_to_string (&ecs->ws); - fprintf_unfiltered (gdb_stdlog, - "infrun: target_wait (%d, status) = %d, %s\n", - PIDGET (waiton_ptid), PIDGET (ecs->ptid), - status_string); - xfree (status_string); - } + print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws); if (treat_exec_as_sigtrap && ecs->ws.kind == TARGET_WAITKIND_EXECD) { @@ -1875,14 +1908,7 @@ fetch_inferior_event (void *client_data) ecs->ptid = target_wait (waiton_ptid, &ecs->ws); if (debug_infrun) - { - char *status_string = target_waitstatus_to_string (&ecs->ws); - fprintf_unfiltered (gdb_stdlog, - "infrun: target_wait (%d, status) = %d, %s\n", - PIDGET (waiton_ptid), PIDGET (ecs->ptid), - status_string); - xfree (status_string); - } + print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws); if (non_stop && ecs->ws.kind != TARGET_WAITKIND_IGNORE ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFA] Include thread ID in target_wait debugging output. 2009-02-27 22:11 ` Doug Evans @ 2009-02-27 22:14 ` Pedro Alves 0 siblings, 0 replies; 5+ messages in thread From: Pedro Alves @ 2009-02-27 22:14 UTC (permalink / raw) To: Doug Evans; +Cc: gdb-patches On Friday 27 February 2009 21:48:48, Doug Evans wrote: > >>> Ok to check in? Yes. Thanks. -- Pedro Alves ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-02-27 22:11 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2009-02-26 19:22 [RFA] Include thread ID in target_wait debugging output Doug Evans 2009-02-27 19:56 ` Pedro Alves 2009-02-27 21:13 ` Doug Evans 2009-02-27 22:11 ` Doug Evans 2009-02-27 22:14 ` Pedro Alves
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox