当前位置: 技术问答>linux和unix
dbx如何进入fork之后的子线程里呢?
来源: 互联网 发布时间:2016-12-07
本文导语: 代码如下: main() { switch(*pid = fork()) { case -1: /* Error forking */ ..... case 0: /* In child process */ .... /*我想debug这段代码*/ default: /...
代码如下:
main()
{
switch(*pid = fork()) {
case -1: /* Error forking */
.....
case 0: /* In child process */
.... /*我想debug这段代码*/
default: /* parent */
break;
}
return 1;
}
我用dbx debug这段代码里,一会就退出了,怎么debug到其产生的子进程中啊?
我本来在子进程代码行加了下断点: stop at "main.c":102,但根本停不下来
main()
{
switch(*pid = fork()) {
case -1: /* Error forking */
.....
case 0: /* In child process */
.... /*我想debug这段代码*/
default: /* parent */
break;
}
return 1;
}
我用dbx debug这段代码里,一会就退出了,怎么debug到其产生的子进程中啊?
我本来在子进程代码行加了下断点: stop at "main.c":102,但根本停不下来
|
5.12 Debugging Multiple Asynchronous Processes
The dbx debugger can debug multiple simultaneous asynchronous processes. While debugging asynchronous processes, dbx can display status and accept commands asynchronously. When running asynchronously, the debugger might exhibit confusing behavior because a running process can display output on the screen while you are entering commands to examine a different process that is stopped.
The debugger automatically enters asynchronous mode in either of the following circumstances:
* You command it to attach to a new process while a previous process is still attached.
* The process to which dbx is attached forks off a child process, and the debugger automatically attaches to the child process without detaching from the parent.
The debugger uses several predefined variables to define the behavior of asynchronous debugging. (See also Table 5-8.) The variable $asynch_interface can be viewed as a counter that is incremented by 1 when a new process is attached and decremented by 1 when a process terminates or is detached. The default value is 0.
When $asynch_interface has a positive nonzero value, asynchronous debugging is enabled; when the variable is 0 (zero) or negative, asynchronous debugging is disabled. To prevent dbx from entering asynchronous mode, set the $asynch_interface variable to a negative value. (Note that disabling asynchronous mode might make debugging more difficult if a parent is waiting on a child that is stopped.)
When a process executes a fork( ) or vfork( ) call, dbx attaches to the child process and automatically enters asynchronous mode (if permitted by $asynch_interface). The default behavior is to stop the child process right after the fork. You can change this default by setting the variable $stop_on_fork to 0; in this case, dbx will attach to the child process but not stop it.
The dbx debugger attempts to apply a degree of intelligence to the handling of forks by filtering out many of the fork calls made by various system and library calls. If you want to stop the process on these forks also, you can set the predefined variable $stop_all_forks to 1. This variable's default value is 0. Stopping on all forks can be particularly useful when you are debugging a library routine.
You can use the debugger's plist and switch commands to monitor and switch between processes.
The dbx debugger can debug multiple simultaneous asynchronous processes. While debugging asynchronous processes, dbx can display status and accept commands asynchronously. When running asynchronously, the debugger might exhibit confusing behavior because a running process can display output on the screen while you are entering commands to examine a different process that is stopped.
The debugger automatically enters asynchronous mode in either of the following circumstances:
* You command it to attach to a new process while a previous process is still attached.
* The process to which dbx is attached forks off a child process, and the debugger automatically attaches to the child process without detaching from the parent.
The debugger uses several predefined variables to define the behavior of asynchronous debugging. (See also Table 5-8.) The variable $asynch_interface can be viewed as a counter that is incremented by 1 when a new process is attached and decremented by 1 when a process terminates or is detached. The default value is 0.
When $asynch_interface has a positive nonzero value, asynchronous debugging is enabled; when the variable is 0 (zero) or negative, asynchronous debugging is disabled. To prevent dbx from entering asynchronous mode, set the $asynch_interface variable to a negative value. (Note that disabling asynchronous mode might make debugging more difficult if a parent is waiting on a child that is stopped.)
When a process executes a fork( ) or vfork( ) call, dbx attaches to the child process and automatically enters asynchronous mode (if permitted by $asynch_interface). The default behavior is to stop the child process right after the fork. You can change this default by setting the variable $stop_on_fork to 0; in this case, dbx will attach to the child process but not stop it.
The dbx debugger attempts to apply a degree of intelligence to the handling of forks by filtering out many of the fork calls made by various system and library calls. If you want to stop the process on these forks also, you can set the predefined variable $stop_all_forks to 1. This variable's default value is 0. Stopping on all forks can be particularly useful when you are debugging a library routine.
You can use the debugger's plist and switch commands to monitor and switch between processes.