Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] thread specific breakpoints and single stepping
@ 2008-07-08  2:49 Ems SUZUKI
  2008-07-08 20:05 ` Pedro Alves
  0 siblings, 1 reply; 6+ messages in thread
From: Ems SUZUKI @ 2008-07-08  2:49 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: Text/Plain, Size: 2298 bytes --]

Hello, 

I've seen the following session log while GDB is stepping over a
thread specific breakpoint:

--------
GNU gdb (GDB) 6.8.50.20080707-cvs
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
(gdb) b 9
Breakpoint 1 at 0x80484a1: file main.c, line 9.
(gdb) run
Starting program: /home/suzuki/test/thread
[Thread debugging using libthread_db enabled]
[New Thread 0xb7f9db90 (LWP 5271)]
[Switching to Thread 0xb7f9db90 (LWP 5271)]

Breakpoint 1, thread_entry (args=0x0) at main.c:9
9         i+=1;
(gdb) l
4       void *
5       thread_entry (void* args)
6       {
7         int i = 0;
8
9         i+=1;
10        i+=2;
11        i+=3;
12
13        return NULL;
(gdb) info threads
* 2 Thread 0xb7f9db90 (LWP 5271)  thread_entry (args=0x0) at main.c:9
  1 Thread 0xb7f9e940 (LWP 5268)  0x0012b402 in __kernel_vsyscall ()
(gdb) b 10 thread 1
Breakpoint 2 at 0x80484a5: file main.c, line 10.
(gdb) step
11        i+=3;
(gdb) 
--------

After the program reached to line 9, I set a breakpoint for only
thread 1 at line 10.  And I invoked step for thread 2.  I expected
thread 2 would stop at line 10, but it hopped over there and stopped
at line 11.  (I've attached the program I used to this mail.)

The cause is in the below:

infrun.c:2117

      if (regular_breakpoint_inserted_here_p (stop_pc))
        {
          ecs->random_signal = 0;
          if (!breakpoint_thread_match (stop_pc, ecs->ptid))
            thread_hop_needed = 1;
        }

thread_hop_needed would be set as 1, in the case that the stopped
thread does not match the condition of the breakpoint.  The thread
which is currently single-stepping would also go into here.  But the
stepping thread should not hop over the breakpoints unconditionally,
but check if it has reached the location where stepping would end.  

I think I've add a check for it with the attached diff.  Does it make
sense?

-- 
Emi SUZUKI / emi-suzuki at tjsys.co.jp

[-- Attachment #2: main.c --]
[-- Type: Text/Plain, Size: 387 bytes --]

#include <stdio.h>
#include <pthread.h>

void *
thread_entry (void* args)
{
  int i = 0;

  i += 1;
  i += 2;
  i += 3;

  return NULL;
}

int
main (int argc, char *argv[])
{
  pthread_t pid;
  void* status;

  pthread_create (&pid, NULL, (void *) thread_entry, NULL);

  if (pthread_join (pid, &status))
    {
      perror ("Failed pthread_join");
      return -1;
    }

  return 0;
}

[-- Attachment #3: thread_specific_break_and_step.diff --]
[-- Type: Text/X-Diff, Size: 722 bytes --]

Index: gdb/infrun.c
===================================================================
RCS file: /cvs/src/src/gdb/infrun.c,v
retrieving revision 1.284
diff -u -r1.284 infrun.c
--- gdb/infrun.c	28 Jun 2008 09:42:15 -0000	1.284
+++ gdb/infrun.c	8 Jul 2008 02:34:39 -0000
@@ -2118,7 +2118,11 @@
 	{
 	  ecs->random_signal = 0;
 	  if (!breakpoint_thread_match (stop_pc, ecs->ptid))
-	    thread_hop_needed = 1;
+	    /* If the thread is currently single-stepping, whether it will
+	       step over the breakpoint or not should be determined later. */
+	    if (!ptid_equal (ecs->ptid, inferior_ptid)
+		|| !currently_stepping (ecs))
+	      thread_hop_needed = 1;
 	}
       else if (singlestep_breakpoints_inserted_p)
 	{

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-08-19  6:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-08  2:49 [RFA] thread specific breakpoints and single stepping Ems SUZUKI
2008-07-08 20:05 ` Pedro Alves
2008-07-09 12:15   ` Emi SUZUKI
2008-07-26  3:02     ` Daniel Jacobowitz
2008-08-01 12:00       ` Emi SUZUKI
2008-08-19  6:10         ` SUZUKI Emi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox