* [Qemu-devel] How to follow a child process created in the guest OS? @ 2012-02-09 10:33 陳韋任 2012-02-10 8:14 ` Stefan Hajnoczi 2012-02-10 9:24 ` Max Filippov 0 siblings, 2 replies; 10+ messages in thread From: 陳韋任 @ 2012-02-09 10:33 UTC (permalink / raw) To: qemu-devel Hi all, The question is not so related to QEMU itself, but I want to give it a try. I am running a tiny OS on QEMU and debugging it with gdbstub. The tiny OS will fork process 1, 2, ... and so on. I want to follow the child process, but the GDB command `set follow-fork-mode child` doesn't work. This seems to be a bug or missing feature in GDB remote protocol. [1] Is there a way to do what I'm trying to do? Thanks! Regards, chenwj [1] http://sourceware.org/bugzilla/show_bug.cgi?id=13584 -- Wei-Ren Chen (陳韋任) Computer Systems Lab, Institute of Information Science, Academia Sinica, Taiwan (R.O.C.) Tel:886-2-2788-3799 #1667 Homepage: http://people.cs.nctu.edu.tw/~chenwj ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] How to follow a child process created in the guest OS? 2012-02-09 10:33 [Qemu-devel] How to follow a child process created in the guest OS? 陳韋任 @ 2012-02-10 8:14 ` Stefan Hajnoczi 2012-02-10 10:26 ` 陳韋任 2012-02-10 9:24 ` Max Filippov 1 sibling, 1 reply; 10+ messages in thread From: Stefan Hajnoczi @ 2012-02-10 8:14 UTC (permalink / raw) To: 陳韋任; +Cc: qemu-devel On Thu, Feb 09, 2012 at 06:33:16PM +0800, 陳韋任 wrote: > The question is not so related to QEMU itself, but I want to give it a try. > I am running a tiny OS on QEMU and debugging it with gdbstub. The tiny OS will > fork process 1, 2, ... and so on. I want to follow the child process, but the > GDB command `set follow-fork-mode child` doesn't work. This seems to be a bug > or missing feature in GDB remote protocol. [1] > > Is there a way to do what I'm trying to do? Thanks! I'm confused. If you are running a system emulator with a guest OS inside then GDB's process-level features are not available. The QEMU gdbstub gives you access at the system-level. If you want to debug guest processes, run gdb inside the guest. Stefan ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] How to follow a child process created in the guest OS? 2012-02-10 8:14 ` Stefan Hajnoczi @ 2012-02-10 10:26 ` 陳韋任 2012-02-10 23:48 ` Paul Brook 2012-02-11 0:42 ` Andreas Färber 0 siblings, 2 replies; 10+ messages in thread From: 陳韋任 @ 2012-02-10 10:26 UTC (permalink / raw) To: Stefan Hajnoczi; +Cc: qemu-devel, 陳韋任 On Fri, Feb 10, 2012 at 08:14:41AM +0000, Stefan Hajnoczi wrote: > On Thu, Feb 09, 2012 at 06:33:16PM +0800, 陳韋任 wrote: > > The question is not so related to QEMU itself, but I want to give it a try. > > I am running a tiny OS on QEMU and debugging it with gdbstub. The tiny OS will > > fork process 1, 2, ... and so on. I want to follow the child process, but the > > GDB command `set follow-fork-mode child` doesn't work. This seems to be a bug > > or missing feature in GDB remote protocol. [1] > > > > Is there a way to do what I'm trying to do? Thanks! > > I'm confused. If you are running a system emulator with a guest OS > inside then GDB's process-level features are not available. The QEMU > gdbstub gives you access at the system-level. If you want to debug > guest processes, run gdb inside the guest. Hope the code snip below can clarify what I am trying to do. ----------------- Tiny OS code ----------------------------- void main(void) /* This really IS void, no error here. */ { /* initialize enviroment */ sti(); move_to_user_mode(); if (!fork()) { /* we count on this going ok */ init(); // task 1 } for(;;) pause(); // task 0 } ------------------------------------------------------------ I am running this tiny OS on QEMU then using GDB to connect it. I want to follow task 1 after the forking, but it seems that GDB stick with task 0 and cannot follow task 1 even I do `set follow-fork-mode child`. Thanks! Regards, chenwj -- Wei-Ren Chen (陳韋任) Computer Systems Lab, Institute of Information Science, Academia Sinica, Taiwan (R.O.C.) Tel:886-2-2788-3799 #1667 Homepage: http://people.cs.nctu.edu.tw/~chenwj ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] How to follow a child process created in the guest OS? 2012-02-10 10:26 ` 陳韋任 @ 2012-02-10 23:48 ` Paul Brook 2012-02-10 23:54 ` 陳韋任 2012-02-11 0:42 ` Andreas Färber 1 sibling, 1 reply; 10+ messages in thread From: Paul Brook @ 2012-02-10 23:48 UTC (permalink / raw) To: qemu-devel; +Cc: Stefan Hajnoczi, 陳韋任 > I am running this tiny OS on QEMU then using GDB to connect it. > > I want to follow task 1 after the forking, but it seems that GDB > stick with task 0 and cannot follow task 1 even I do `set follow-fork-mode > child`. You have exactly one CPU. That's what the qemu GDB stub exposes. Multiple processes are an illusion created by your operating system. It is not something qemu knows or cares about. In most cases if you want to do debugging within that OS created illusion (aka a userspace process) then you probably don't want to be using a hardware debug probe (i.e. the qemu gdb stub) at all. Instead you want to be using the debug facilities provided by your operating system. On linux this would be ptrace, probably via gdbserver. Paul ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] How to follow a child process created in the guest OS? 2012-02-10 23:48 ` Paul Brook @ 2012-02-10 23:54 ` 陳韋任 0 siblings, 0 replies; 10+ messages in thread From: 陳韋任 @ 2012-02-10 23:54 UTC (permalink / raw) To: Paul Brook; +Cc: qemu-devel On Fri, Feb 10, 2012 at 11:48:05PM +0000, Paul Brook wrote: > > I am running this tiny OS on QEMU then using GDB to connect it. > > > > I want to follow task 1 after the forking, but it seems that GDB > > stick with task 0 and cannot follow task 1 even I do `set follow-fork-mode > > child`. > > You have exactly one CPU. That's what the qemu GDB stub exposes. Multiple > processes are an illusion created by your operating system. It is not > something qemu knows or cares about. > > In most cases if you want to do debugging within that OS created illusion (aka > a userspace process) then you probably don't want to be using a hardware debug > probe (i.e. the qemu gdb stub) at all. Instead you want to be using the debug > facilities provided by your operating system. On linux this would be ptrace, > probably via gdbserver. I see. Thanks. Regards, chenwj -- Wei-Ren Chen (陳韋任) Computer Systems Lab, Institute of Information Science, Academia Sinica, Taiwan (R.O.C.) Tel:886-2-2788-3799 #1667 Homepage: http://people.cs.nctu.edu.tw/~chenwj ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] How to follow a child process created in the guest OS? 2012-02-10 10:26 ` 陳韋任 2012-02-10 23:48 ` Paul Brook @ 2012-02-11 0:42 ` Andreas Färber 2012-02-11 0:50 ` malc 1 sibling, 1 reply; 10+ messages in thread From: Andreas Färber @ 2012-02-11 0:42 UTC (permalink / raw) To: 陳韋任; +Cc: Stefan Hajnoczi, qemu-devel Am 10.02.2012 11:26, schrieb 陳韋任: > On Fri, Feb 10, 2012 at 08:14:41AM +0000, Stefan Hajnoczi wrote: >> On Thu, Feb 09, 2012 at 06:33:16PM +0800, 陳韋任 wrote: >>> I am running a tiny OS on QEMU and debugging it with gdbstub. The tiny OS will >>> fork process 1, 2, ... and so on. I want to follow the child process, [...] >>> >>> Is there a way to do what I'm trying to do? Thanks! > ----------------- Tiny OS code ----------------------------- > void main(void) /* This really IS void, no error here. */ > { > /* initialize enviroment */ > > sti(); > move_to_user_mode(); > if (!fork()) { /* we count on this going ok */ > init(); // task 1 > } > > for(;;) pause(); // task 0 > } > ------------------------------------------------------------ > > I am running this tiny OS on QEMU then using GDB to connect it. > I want to follow task 1 after the forking, [...] Since this seems to be your code, if this were PowerPC I'd simply try to place via inline assembler a trap instruction first thing inside the init() function. That can easily be caught in gdbstub. Depending on what you really want to do, you could always try some printf-style output to serial. ;) Andreas -- SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] How to follow a child process created in the guest OS? 2012-02-11 0:42 ` Andreas Färber @ 2012-02-11 0:50 ` malc 2012-02-12 3:00 ` Wei Yang 0 siblings, 1 reply; 10+ messages in thread From: malc @ 2012-02-11 0:50 UTC (permalink / raw) To: Andreas Färber; +Cc: Stefan Hajnoczi, qemu-devel, 陳韋任 On Sat, 11 Feb 2012, Andreas F?rber wrote: > Am 10.02.2012 11:26, schrieb ???: > > On Fri, Feb 10, 2012 at 08:14:41AM +0000, Stefan Hajnoczi wrote: > >> On Thu, Feb 09, 2012 at 06:33:16PM +0800, ??? wrote: > >>> I am running a tiny OS on QEMU and debugging it with gdbstub. The tiny OS will > >>> fork process 1, 2, ... and so on. I want to follow the child process, [...] > >>> > >>> Is there a way to do what I'm trying to do? Thanks! > > > ----------------- Tiny OS code ----------------------------- > > void main(void) /* This really IS void, no error here. */ > > { > > /* initialize enviroment */ > > > > sti(); > > move_to_user_mode(); > > if (!fork()) { /* we count on this going ok */ > > init(); // task 1 > > } > > > > for(;;) pause(); // task 0 > > } > > ------------------------------------------------------------ > > > > I am running this tiny OS on QEMU then using GDB to connect it. > > I want to follow task 1 after the forking, [...] > > Since this seems to be your code, if this were PowerPC I'd simply try to > place via inline assembler a trap instruction first thing inside the Being hardcore are we? __builtin_trap () is there for a reason. > init() function. That can easily be caught in gdbstub. > > Depending on what you really want to do, you could always try some > printf-style output to serial. ;) > > Andreas > > -- mailto:av1474@comtv.ru ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] How to follow a child process created in the guest OS? 2012-02-11 0:50 ` malc @ 2012-02-12 3:00 ` Wei Yang 2012-02-13 10:49 ` Stefan Hajnoczi 0 siblings, 1 reply; 10+ messages in thread From: Wei Yang @ 2012-02-12 3:00 UTC (permalink / raw) To: malc Cc: Stefan Hajnoczi, Andreas Färber, ���f任, qemu-devel 2012/2/11 malc <av1474@comtv.ru>: > On Sat, 11 Feb 2012, Andreas F?rber wrote: > >> Am 10.02.2012 11:26, schrieb ???: >> > On Fri, Feb 10, 2012 at 08:14:41AM +0000, Stefan Hajnoczi wrote: >> >> On Thu, Feb 09, 2012 at 06:33:16PM +0800, ??? wrote: >> >>> I am running a tiny OS on QEMU and debugging it with gdbstub. The tiny OS will >> >>> fork process 1, 2, ... and so on. I want to follow the child process, [...] >> >>> >> >>> Is there a way to do what I'm trying to do? Thanks! >> >> > ----------------- Tiny OS code ----------------------------- >> > void main(void) /* This really IS void, no error here. */ >> > { >> > /* initialize enviroment */ >> > >> > sti(); >> > move_to_user_mode(); >> > if (!fork()) { /* we count on this going ok */ >> > init(); // task 1 >> > } >> > >> > for(;;) pause(); // task 0 >> > } >> > ------------------------------------------------------------ >> > >> > I am running this tiny OS on QEMU then using GDB to connect it. >> > I want to follow task 1 after the forking, [...] >> Could the Qemu gdbstub debug a user space process? -- Richard Yang Help You, Help Me ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] How to follow a child process created in the guest OS? 2012-02-12 3:00 ` Wei Yang @ 2012-02-13 10:49 ` Stefan Hajnoczi 0 siblings, 0 replies; 10+ messages in thread From: Stefan Hajnoczi @ 2012-02-13 10:49 UTC (permalink / raw) To: Wei Yang; +Cc: Andreas Färber, 陳韋任, qemu-devel On Sun, Feb 12, 2012 at 3:00 AM, Wei Yang <weiyang.kernel@gmail.com> wrote: > 2012/2/11 malc <av1474@comtv.ru>: >> On Sat, 11 Feb 2012, Andreas F?rber wrote: >> >>> Am 10.02.2012 11:26, schrieb ???: >>> > On Fri, Feb 10, 2012 at 08:14:41AM +0000, Stefan Hajnoczi wrote: >>> >> On Thu, Feb 09, 2012 at 06:33:16PM +0800, ??? wrote: >>> >>> I am running a tiny OS on QEMU and debugging it with gdbstub. The tiny OS will >>> >>> fork process 1, 2, ... and so on. I want to follow the child process, [...] >>> >>> >>> >>> Is there a way to do what I'm trying to do? Thanks! >>> >>> > ----------------- Tiny OS code ----------------------------- >>> > void main(void) /* This really IS void, no error here. */ >>> > { >>> > /* initialize enviroment */ >>> > >>> > sti(); >>> > move_to_user_mode(); >>> > if (!fork()) { /* we count on this going ok */ >>> > init(); // task 1 >>> > } >>> > >>> > for(;;) pause(); // task 0 >>> > } >>> > ------------------------------------------------------------ >>> > >>> > I am running this tiny OS on QEMU then using GDB to connect it. >>> > I want to follow task 1 after the forking, [...] >>> > > Could the Qemu gdbstub debug a user space process? What people have been trying to explain is that, yes, gdbstub can debug user space processes but not in an easy way. It's like using a bicycle to travel from Paris to Beijing - it takes a lot of time and effort, you may want to catch a plane instead. The QEMU gdbstub is a hardware-level debugger. It shows you what the CPU is doing. It does not know about processes. Of course, if *you* understand how processes are implemented in this operating systems, *you* could do all the process-level debugging yourself without the help of the debugger. Stefan ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] How to follow a child process created in the guest OS? 2012-02-09 10:33 [Qemu-devel] How to follow a child process created in the guest OS? 陳韋任 2012-02-10 8:14 ` Stefan Hajnoczi @ 2012-02-10 9:24 ` Max Filippov 1 sibling, 0 replies; 10+ messages in thread From: Max Filippov @ 2012-02-10 9:24 UTC (permalink / raw) To: 陳韋任; +Cc: qemu-devel > The question is not so related to QEMU itself, but I want to give it a try. > I am running a tiny OS on QEMU and debugging it with gdbstub. The tiny OS will > fork process 1, 2, ... and so on. I want to follow the child process, but the > GDB command `set follow-fork-mode child` doesn't work. This seems to be a bug > or missing feature in GDB remote protocol. [1] QEMU gdbstub has no idea of the guest OS, its fork, its processes or threads. All that it has is a number of VCPUs that it treats like threads, and they execute continuous stream of instructions. There's no special instruction for fork and the guest OS doesn't notify gdbstub of it either. The natural way to debug processes would be to use OS's native debugger/gdbstub. It is still possible to use QEMU gdbstub, but you'll need to analyze guest OS state to determine if you e.g. hit the breakpoint in the desired process context. -- Thanks. -- Max ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2012-02-13 10:49 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2012-02-09 10:33 [Qemu-devel] How to follow a child process created in the guest OS? 陳韋任 2012-02-10 8:14 ` Stefan Hajnoczi 2012-02-10 10:26 ` 陳韋任 2012-02-10 23:48 ` Paul Brook 2012-02-10 23:54 ` 陳韋任 2012-02-11 0:42 ` Andreas Färber 2012-02-11 0:50 ` malc 2012-02-12 3:00 ` Wei Yang 2012-02-13 10:49 ` Stefan Hajnoczi 2012-02-10 9:24 ` Max Filippov
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).