Debugging smf(5)-managed processes

Recently, I've seen a couple questions (internally and externally) about the best way to debug something controlled by smf(5); since the process isn't started up directly, the usual ways of running things under a debugger aren't effective. If you don't need to debug the initialization process, it's also easy; just attach the debugger after the daemon is running.

If you need to debug the initialization, however, you need some way to stop the process before it does so. The easiest way is to use dtrace(1M). The following script:

# cat > stop_daemon.d <<\\EOF
#!/usr/sbin/dtrace -s

#pragma D option quiet
#pragma D option destructive

BEGIN
{
        printf("READY\\n");
}

proc:::start
/execname == $$1/
{
        stop();
        printf("stopped %d\\n", pid);
        exit(0);
}
EOF
# chmod +x stop_daemon.d
Will let you grab the \*daemon\* process (i.e. at the time of the second fork()). If you need to grab the parent process, change proc:::start to proc:::exec-success. It takes the "execname" of the daemon (i.e. the first 16 characters of the executable name, which you can get using "pgrep -l daemon") as its argument. For example, if you wanted to debug the fault manager, you can do:
# ./stop_daemon fmd &
# READY
svcadm restart fmd
# stopped 5678
mdb -p 5678
Loading modules: [ fmd ld.so.1 ... ]
> 
Any debugger which can attach to processes will work; mdb(1), dbx(1), gdb(1), etc.

Technorati Tag:
Technorati Tag:

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

jwadams

Search

Top Tags
Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today