From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31395 invoked by alias); 9 Aug 2011 15:25:53 -0000 Received: (qmail 31369 invoked by uid 22791); 9 Aug 2011 15:25:50 -0000 X-SWARE-Spam-Status: Yes, hits=5.4 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,WEBMAIL_BODY X-Spam-Check-By: sourceware.org Received: from nm3-vm1.bt.bullet.mail.ird.yahoo.com (HELO nm3-vm1.bt.bullet.mail.ird.yahoo.com) (212.82.108.95) by sourceware.org (qpsmtpd/0.43rc1) with SMTP; Tue, 09 Aug 2011 15:25:35 +0000 Received: from [212.82.108.229] by nm3.bt.bullet.mail.ird.yahoo.com with NNFMP; 09 Aug 2011 15:25:34 -0000 Received: from [212.82.108.227] by tm2.bt.bullet.mail.ird.yahoo.com with NNFMP; 09 Aug 2011 15:25:34 -0000 Received: from [127.0.0.1] by omp1004.bt.mail.ird.yahoo.com with NNFMP; 09 Aug 2011 15:25:34 -0000 Received: (qmail 58814 invoked by uid 60001); 9 Aug 2011 15:25:33 -0000 Received: from [2.100.65.244] by web86701.mail.ird.yahoo.com via HTTP; Tue, 09 Aug 2011 16:25:33 BST References: <1311947955.89527.YahooMailRC@web86708.mail.ird.yahoo.com> <1312026270.62521.YahooMailRC@web86705.mail.ird.yahoo.com> <1312803282.12167.YahooMailRC@web86707.mail.ird.yahoo.com> <201108081606.58401.pedro@codesourcery.com> <1312816830.93830.YahooMailRC@web86703.mail.ird.yahoo.com> Message-ID: <1312903533.54894.YahooMailRC@web86701.mail.ird.yahoo.com> Date: Tue, 09 Aug 2011 15:25:00 -0000 From: pfee@talk21.com Subject: Re: Enhancement - show old and new thread info when switching during debugging To: Pedro Alves , gdb-patches@sourceware.org Cc: Joel Brobecker , Tom Tromey In-Reply-To: <1312816830.93830.YahooMailRC@web86703.mail.ird.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-08/txt/msg00195.txt.bz2 >> Sorry, but current_inferior_ptid for this will be even more confusing. >> There's several current_FOO globals that represent the currently selected >> state. And one of them is "current_inferior". Having current_inferior() >> return one thing, and current_inferior_ptid mean another thing will be a= =20 >> recipe for long term confusion. >=20 > No problem, I'll pick another name. I've reverted current_inferior_ptid back to previous_inferior_ptid, which=20 makes the patch smaller. The new variable is now previous_selected_ptid. >> Any chance you can convince your mailer to attach patches >> with "Content-Type: text/x-patch" or some other text mime >> type? >=20 > I'm using Yahoo webmail, it's handling of attachments could be better.=20 > I'll try using a traditional email client. I tried kmail which allows setting the content-type and content-disposition= , but=20 the email didn't reach the gdb-patches list. I'm reverting to using webmai= l and=20 I'll put the patch as plain text below. >> Please no leading * on every comment line. See other >> comments, and follow the same style. >=20 > Ok Done >=20 >>=20 >> In order for this to be accepted, it will need some >> documentation in the manual. Let's consider documentation once the patch is acceptable. >>=20 >> I'm not sure the variable is sufficiently well defined yet. >> What does gdb print in this case? >>=20 >> (gdb) thread 2 >> (gdb) thread 3 >> (gdb) p $_prev_thread >>=20 >> It feels like it should print thread 2, that is, we'd >> define it to the thread the user last had selected, >> and so: >>=20 >> (gdb) thread $_prev_thread >> (gdb) thread $_prev_thread >>=20 >> would cycle between thread 2 and 3. I now also set previous_selected_ptid in do_captured_thread_select(), which= =20 results in the behaviour you've asked for. >>=20 >> This definition works for non-stop mode as well. >> Otherwise, as is, we get to define it as "the thread that >> the user had selected the last time an execution command >> was ran" (and the $_prev_thread is undefined/meaningless in >> non-stop mode). >=20 > I appreciate the feedback, your summary of the current operation is > correct. I'll take a look at making $_prev_thread be influenced by the > user entering > "thread" commands. Since that should then give us consistent operation in > both all-stop and non-stop modes, the additional change will be > worthwhile. I tested the patch in non-stop mode. $_prev_thread only gets modified when= =20 the user switches using the "thread" command. I think that's what you're=20 asking for also. Thanks, Paul 2011-08-09 Paul Fee * inferior.h: Add $_prev_thread convenience variable. * infrun.c: Add $_prev_thread convenience variable, set it when current= =20 thread changes. * thread.c: Add $_prev_thread convenience variable, set it when user=20 switches threads. Index: inferior.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/inferior.h,v retrieving revision 1.161 diff -c -p -r1.161 inferior.h *** inferior.h 21 Jul 2011 23:46:08 -0000 1.161 --- inferior.h 9 Aug 2011 14:44:23 -0000 *************** extern const char *get_inferior_io_termi *** 94,99 **** --- 94,105 ---- =20=20 extern ptid_t inferior_ptid; =20=20 + /* Values move from interior_ptid to previous_inferior_ptid to + * previous_selected_ptid. The previous value is exposed to the + * user through the $_prev_thread convenience variable. + */ + extern ptid_t previous_selected_ptid; +=20 /* Are we simulating synchronous execution? This is used in async gdb to implement the 'run', 'continue' etc commands, which will not redisplay the prompt until the execution is actually over. */ *************** extern int stop_on_solib_events; *** 204,209 **** --- 210,218 ---- =20=20 extern void start_remote (int from_tty); =20=20 + extern struct value *prev_thread_id_make_value (struct gdbarch *, + struct internalvar *); +=20 extern void normal_stop (void); =20=20 extern int signal_stop_state (int); Index: infrun.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/infrun.c,v retrieving revision 1.498 diff -c -p -r1.498 infrun.c *** infrun.c 4 Aug 2011 19:10:12 -0000 1.498 --- infrun.c 9 Aug 2011 14:44:29 -0000 *************** int sync_execution =3D 0; *** 127,132 **** --- 127,138 ---- =20=20 static ptid_t previous_inferior_ptid; =20=20 + /* Values move from interior_ptid to previous_inferior_ptid to + previous_selected_ptid. The previous selected value is exposed + to the user through the $_prev_thread convenience variable. */ +=20 + ptid_t previous_selected_ptid; +=20 /* Default behavior is to detach newly forked processes (legacy). */ int detach_fork =3D 1; =20=20 *************** print_no_history_reason (void) *** 5730,5735 **** --- 5736,5753 ---- ui_out_text (current_uiout, "\nNo more reverse-execution history.\n"); } =20=20 + /* Return the previous thread's id. Return a value of 0 if + no previous thread was selected, or it doesn't exist. */ +=20 + struct value * + prev_thread_id_make_value (struct gdbarch *gdbarch, struct internalvar *v= ar) + { + struct thread_info *tp =3D find_thread_ptid (previous_selected_ptid); +=20 + return value_from_longest (builtin_type (gdbarch)->builtin_int, + (tp ? tp->num : 0)); + } +=20 /* Here to return control to GDB when the inferior stops for real. Print appropriate messages, remove breakpoints, give terminal our mode= s. =20=20 *************** normal_stop (void) *** 5777,5784 **** { target_terminal_ours_for_output (); printf_filtered (_("[Switching to %s]\n"), ! target_pid_to_str (inferior_ptid)); annotate_thread_changed (); previous_inferior_ptid =3D inferior_ptid; } =20=20 --- 5795,5803 ---- { target_terminal_ours_for_output (); printf_filtered (_("[Switching to %s]\n"), ! target_pid_to_str (inferior_ptid)); annotate_thread_changed (); + previous_selected_ptid =3D previous_inferior_ptid; previous_inferior_ptid =3D inferior_ptid; } =20=20 Index: thread.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/thread.c,v retrieving revision 1.142 diff -c -p -r1.142 thread.c *** thread.c 4 Aug 2011 19:10:13 -0000 1.142 --- thread.c 9 Aug 2011 14:44:30 -0000 *************** do_captured_thread_select (struct ui_out *** 1394,1399 **** --- 1394,1400 ---- if (!thread_alive (tp)) error (_("Thread ID %d has terminated."), num); =20=20 + previous_selected_ptid =3D inferior_ptid; switch_to_thread (tp->ptid); =20=20 annotate_thread_changed (); *************** Show printing of thread events (such as=20 *** 1498,1501 **** --- 1499,1503 ---- &setprintlist, &showprintlist); =20=20 create_internalvar_type_lazy ("_thread", thread_id_make_value); + create_internalvar_type_lazy ("_prev_thread", prev_thread_id_make_value= ); }