Re: [Qemu-devel] How to follow a child process created in the guest OS?
On Sun, Feb 12, 2012 at 3:00 AM, Wei Yang wrote: > 2012/2/11 malc : >> 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 +, 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
Re: [Qemu-devel] How to follow a child process created in the guest OS?
2012/2/11 malc : > 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 +, 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
Re: [Qemu-devel] How to follow a child process created in the guest OS?
On Fri, Feb 10, 2012 at 11:48:05PM +, 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
Re: [Qemu-devel] How to follow a child process created in the guest OS?
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 +, 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:av1...@comtv.ru
Re: [Qemu-devel] How to follow a child process created in the guest OS?
Am 10.02.2012 11:26, schrieb 陳韋任: > On Fri, Feb 10, 2012 at 08:14:41AM +, 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
Re: [Qemu-devel] How to follow a child process created in the guest OS?
> 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
Re: [Qemu-devel] How to follow a child process created in the guest OS?
On Fri, Feb 10, 2012 at 08:14:41AM +, 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
Re: [Qemu-devel] How to follow a child process created in the guest OS?
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
Re: [Qemu-devel] How to follow a child process created in the guest OS?
> 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
[Qemu-devel] How to follow a child process created in the guest OS?
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