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
Signature · 5 lines
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
Quoted 5 lines
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 childdoesn'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.
Signature · 2 lines
Thanks. -- Max
Quoted 7 lines · 陳韋任
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 commandset follow-fork-mode childdoesn'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
Quoted 7 lines · Stefan Hajnoczi
Quoted 6 lines · 陳韋任
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 commandset follow-fork-mode childdoesn't work. This seems to be a bug or missing feature in GDB remote protocol. [1]
Quoted 6 lines
Quoted 1 line
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
Signature · 5 lines
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
Quoted 5 lines
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
Quoted 10 lines · Paul Brook
Quoted 5 lines
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.
Quoted 5 lines
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
Signature · 5 lines
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
Am 10.02.2012 11:26, schrieb 陳韋任:
Quoted 18 lines · Stefan Hajnoczi
Quoted 5 lines · 陳韋任
Quoted 4 lines
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 }
Quoted 6 lines
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
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Quoted 23 lines · Andreas F?rber
Am 10.02.2012 11:26, schrieb ???:
Quoted 22 lines · Stefan Hajnoczi
Quoted 5 lines · ???
Quoted 4 lines
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
}
------------------------------------------------------------
Quoted 5 lines
Quoted 2 lines
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.
Quoted 8 lines
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
Signature · 1 line
mailto:[email protected]
2012/2/11 malc <[email protected]>:
Quoted 21 lines · Andreas F?rber
Quoted 20 lines
Am 10.02.2012 11:26, schrieb ???:
Quoted 18 lines · Stefan Hajnoczi
Quoted 5 lines · ???
Quoted 4 lines
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
}
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
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?
Signature · 2 lines
Richard Yang Help You, Help Me
Quoted 26 lines · Wei Yang
2012/2/11 malc <[email protected]>:
Quoted 25 lines · Andreas F?rber
Quoted 24 lines
Am 10.02.2012 11:26, schrieb ???:
Quoted 22 lines · Stefan Hajnoczi
Quoted 5 lines · ???
Quoted 4 lines
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
}
------------------------------------------------------------
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
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