From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31126 invoked by alias); 10 May 2011 16:27:41 -0000 Received: (qmail 31077 invoked by uid 22791); 10 May 2011 16:27:37 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-qw0-f41.google.com (HELO mail-qw0-f41.google.com) (209.85.216.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 10 May 2011 16:27:21 +0000 Received: by qwa26 with SMTP id 26so5133678qwa.0 for ; Tue, 10 May 2011 09:27:20 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.26.213 with SMTP id f21mr6130904qcc.217.1305044840570; Tue, 10 May 2011 09:27:20 -0700 (PDT) Received: by 10.229.135.145 with HTTP; Tue, 10 May 2011 09:27:20 -0700 (PDT) Date: Tue, 10 May 2011 16:27:00 -0000 Message-ID: Subject: Stepping of multithreaded application From: Tomas Martinec To: gdb@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2011-05/txt/msg00034.txt.bz2 Hello, I am developing an Eclipse plugin that allows debugging of a MIPS virtual machine. The GDB is used as a debugger backend. I have difficulties with debugging multiprocessor machines (processors are represented as threads in the GDB). Stepping of different threads does not seem to work well. When I change the current thread in the eclipse and apply the step command, the debugger is stopped in the previous thread. I expect that the debugger should be stopped at the next line of the newly set thread. Is my expectation right? I minimalized the scenario to the GDB/virtual machine only and I got an example gdb session. The structure of the session is basically this: tomas@tomas-laptop:~/workspaceGDB/gdb-7.2/gdb$ ./gdb --interpreter mi2 // use the MI // connect to the machine target remote :10001 // bsp_start is the first C function of the bootstrap processor break bsp_start // go to the C code continue // get information about the other processors/threads info threads // do a step with the third processor -exec-next --thread 3 1 *stopped,reason=3D"signal-received",signal-name=3D"SIGTRAP",signal-meaning= =3D"Trace/breakpoint trap",frame=3D{addr=3D"0x80004354",func=3D"print",args=3D[{name=3D"text",va= lue=3D"0x0"}],file=3D"drivers/printer.c",fullname=3D"/home/tomas/runtime-Ec= lipseApplication/kalisto/kernel/drivers/printer.c",line=3D"27"},thread-id= =3D"1",stopped-threads=3D"all" // the first processor was stepped instead the third one Here is the complete session log (without the remote debugging messages): tomas@tomas-laptop:~/workspaceGDB/gdb-7.2/gdb$ ./gdb --interpreter mi2 =3Dthread-group-added,id=3D"i1" ~"GNU gdb (GDB) 7.2\n" ~"Copyright (C) 2010 Free Software Foundation, Inc.\n" ~"License GPLv3+: GNU GPL version 3 or later \nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law. Type \"show copying\"\nand \"show warranty\" for details.\n" ~"This GDB was configured as \"--host=3Di686-pc-linux-gnu --target=3Dmips\".\nFor bug reporting instructions, please see:\n" ~".\n" ~"The target is assumed to be little endian\n" (gdb) set debug remote 1 ^done (gdb) target remote :10001 ~"Remote debugging using :10001\n" =3Dthread-group-started,id=3D"i1",pid=3D"42000" =3Dthread-created,id=3D"1",group-id=3D"i1" ~"0xbfc00000 in ?? ()\n" *stopped,frame=3D{addr=3D"0xbfc00000",func=3D"??",args=3D[]},thread-id=3D"1= ",stopped-threads=3D"all" ^done (gdb) break bsp_start ~"Breakpoint 1 at 0x80002540: file main.c, line 69.\n" ^done (gdb) continue ~"Continuing.\n" ^running *running,thread-id=3D"all" (gdb) ~"\nBreakpoint " ~"1, bsp_start () at main.c:69\n" ~"69\t\tprint (\"Initializing Kalisto\\n\");\n" *stopped,frame=3D{addr=3D"0x80002540",func=3D"bsp_start",args=3D[],file=3D"= main.c",fullname=3D"/home/tomas/runtime-EclipseApplication/kalisto/kernel/m= ain.c",line=3D"69"},thread-id=3D"1",stopped-threads=3D"all" (gdb) info threads =3Dthread-created,id=3D"2",group-id=3D"i1" ~"[New Thread 2]\n" =3Dthread-created,id=3D"3",group-id=3D"i1" ~"[New Thread 3]\n" ~" 3 Thread 3 (CPU 3) 0x80002654 in ap_start () at main.c:129\n" ~" 2 Thread 2 (CPU 2) 0x80002654 in ap_start () at main.c:129\n" ~"* 1 Thread 1 (CPU 1) bsp_start () at main.c:69\n" ^done (gdb) -exec-next --thread 3 1 ^running *running,thread-id=3D"1" (gdb) *running,thread-id=3D"all" ~"[Switching to Thread 1]\n" *stopped,reason=3D"signal-received",signal-name=3D"SIGTRAP",signal-meaning= =3D"Trace/breakpoint trap",frame=3D{addr=3D"0x80004354",func=3D"print",args=3D[{name=3D"text",va= lue=3D"0x0"}],file=3D"drivers/printer.c",fullname=3D"/home/tomas/runtime-Ec= lipseApplication/kalisto/kernel/drivers/printer.c",line=3D"27"},thread-id= =3D"1",stopped-threads=3D"all" =3Dthread-selected,id=3D"1" (gdb) I have also the same log but with the remote debugging messages. It is quite long, so I paste only the relevant part: -exec-next --thread 3 1 &"Sending packet: $Hg3#e2..." &"Ack\n" &"Packet received: OK\n" &"Sending packet: $g#67..." &"Ack\n" &"Packet received: 000000000000000000000000000000000000000000000000000000000000000000000000000= 000000000000000000000000000000000000000000000000000000000000000000000000000= 000000000000000000000000000000000000000000000000000000000000010000020000000= 0000080d8060080000000004c03008004004000000000000000000000000000000000005426= 0080\n" &"Sending packet: $Hg1#e0..." &"Ack\n" &"Packet received: OK\n" &"Sending packet: $g#67..." &"Ack\n" &"Packet received: 000000000000000000000000000000000000000000000000000000000000000000000000000= 000000000000000000000000000000000000000000000000000000000000000000000000000= 000000000000000000000000000000000000000000000000000000000000010000000000000= 0000080d8040080d80400803803008004004000000000000000000000000000000000004025= 0080\n" &"Sending packet: $g#67..." &"Ack\n" &"Packet received: 000000000000000000000000000000000000000000000000000000000000000000000000000= 000000000000000000000000000000000000000000000000000000000000000000000000000= 000000000000000000000000000000000000000000000000000000000000010000000000000= 0000080d8040080d80400803803008004004000000000000000000000000000000000004025= 0080\n" &"Sending packet: $Hc1#dc..." &"Ack\n" &"Packet received: OK\n" &"Sending packet: $s#73..." &"Ack\n" ^running *running,thread-id=3D"1" (gdb) &"Packet received: T05thread:00000001;25:44250080;\n" &"Sending packet: $Hg3#e2..." &"Ack\n" &"Packet received: OK\n" &"Sending packet: $g#67..." &"Ack\n" &"Packet received: 000000000000000000000000000000000000000000000000000000000000000000000000000= 000000000000000000000000000000000000000000000000000000000000000000000000000= 000000000000000000000000000000000000000000000000000000000000010000020000000= 0000080d8060080000000004c03008004004000000000000000000000000000000000005826= 0080\n" &"Sending packet: $Hc0#db..." &"Ack\n" &"Packet received: \n" &"Sending packet: $s#73..." &"Ack\n" *running,thread-id=3D"all" &"Packet received: T05thread:00000001;25:48250080;\n" &"Sending packet: $g#67..." &"Ack\n" &"Packet received: 000000000000000000000080000000000000000000000000000000000000000000000000000= 000000000000000000000000000000000000000000000000000000000000000000000000000= 000000000000000000000000000000000000000000000000000000000000010000000000000= 0000080d8040080d80400804c25008004004000000000000000000000000000000000004825= 0080\n" &"Sending packet: $T3#87..." &"Ack\n" &"Packet received: OK\n" &"Sending packet: $Hg3#e2..." &"Ack\n" &"Packet received: OK\n" &"Sending packet: $g#67..." &"Ack\n" &"Packet received: 000000000000000000000000000000000000000000000000000000000000000000000000000= 000000000000000000000000000000000000000000000000000000000000000000000000000= 000000000000000000000000000000000000000000000000000000000000010000020000000= 0000080d8060080d80600804c03008004004000000000000000000000000000000000005c26= 0080\n" &"Sending packet: $Hg1#e0..." &"Ack\n" &"Packet received: OK\n" &"Sending packet: $g#67..." &"Ack\n" &"Packet received: 000000000000000000000080000000000000000000000000000000000000000000000000000= 000000000000000000000000000000000000000000000000000000000000000000000000000= 000000000000000000000000000000000000000000000000000000000000010000000000000= 0000080d8040080d80400804c25008004004000000000000000000000000000000000004825= 0080\n" &"Sending packet: $Z0,80002540,4#a9..." &"Ack\n" &"Packet received: OK\n" &"Sending packet: $Hg3#e2..." &"Ack\n" &"Packet received: OK\n" &"Sending packet: $g#67..." &"Ack\n" &"Packet received: 000000000000000000000000000000000000000000000000000000000000000000000000000= 000000000000000000000000000000000000000000000000000000000000000000000000000= 000000000000000000000000000000000000000000000000000000000000010000020000000= 0000080d8060080d80600804c03008004004000000000000000000000000000000000005c26= 0080\n" &"Sending packet: $s#73..." &"Ack\n" &"Packet received: T05thread:00000001;25:54430080;\n" &"Sending packet: $g#67..." &"Ack\n" &"Packet received: 00000000000000000000008000000000ec43008000000000000000000000000000000000000= 000000000000000000000000000000000000000000000000000000000000000000000000000= 000000000000000000000000000000000000000000000000000000000000010000000000000= 0000080d8040080d80400804c25008004004000000000000000000000000000000000005443= 0080\n" ~"[Switching to Thread 1]\n" &"Sending packet: $z0,80002540,4#c9..." &"Ack\n" &"Packet received: OK\n" &"Sending packet: $m800004c0,40#bc..." &"Ack\n" &"Packet received: 000000000000000000000000000000000000000000000000000000000000000000000000000= 00000000000000000000000000000000000000000000038030080\n" *stopped,reason=3D"signal-received",signal-name=3D"SIGTRAP",signal-meaning= =3D"Trace/breakpoint trap",frame=3D{addr=3D"0x80004354",func=3D"print",args=3D[{name=3D"text",va= lue=3D"0x0"}],file=3D"drivers/printer.c",fullname=3D"/home/tomas/runtime-Ec= lipseApplication/kalisto/kernel/drivers/printer.c",line=3D"27"},thread-id= =3D"1",stopped-threads=3D"all" =3Dthread-selected,id=3D"1" =46rom the debugging messages I can see, that the GDB steps twice. The first step is for the first thread - maybe because the first thread has just raised the breakpoint. Before the second step the GDB tries to change the current thread in the virtual machine to 0 (means ANY according to the doc). That is not supported in the virtual machine and the machine responds so. I believe not supporting the Hc0 command is not wrong for the virtual machine. Anyway the second step is aimed for ANY thread and it is applied for the first thread, which both leads to the unexpected behaviour. I think that the GDB should send Hc3 command to the simulator before the second step. I have also tried to find out why the Hc3 command is not send from the GDB sources. The thread id that will be step is determined in resume function of target.c. In my case the RESUME_ALL ptid is used. That ptid leads to the Hc0 command. So far I have not understood why the resume_ptid is kept in the default RESUME_ALL. Sorry for quite a story. I have been solving it for some time and advice would be appreciated. Any idea why the GDB does not send the Hc3 command? Maybe I just cannot see something simple. Regards, Tomas