1 058b0118 2005-01-03 devnull .TH MACH-CMD 3
3 058b0118 2005-01-03 devnull attachargs, attachcore, attachdynamic, attachproc, proctextfile \- debugging processes and core files
4 058b0118 2005-01-03 devnull .SH SYNOPSIS
5 058b0118 2005-01-03 devnull .B #include <u.h>
7 058b0118 2005-01-03 devnull .B #include <libc.h>
9 058b0118 2005-01-03 devnull .B #include <mach.h>
11 058b0118 2005-01-03 devnull .ta +\w'\fLextern 'u +\w'\fLchar *'u
13 058b0118 2005-01-03 devnull int attachcore(Fhdr *hdr)
16 058b0118 2005-01-03 devnull int attachproc(int pid)
19 058b0118 2005-01-03 devnull int attachdynamic(void)
22 058b0118 2005-01-03 devnull char* proctextfile(int pid)
25 058b0118 2005-01-03 devnull int attachargs(int argc, char **argv, int omode)
29 058b0118 2005-01-03 devnull extern Fhdr* symhdr;
30 058b0118 2005-01-03 devnull extern char* symfil;
31 058b0118 2005-01-03 devnull extern Map* symmap;
32 058b0118 2005-01-03 devnull extern Fhdr* fhdrlist;
33 058b0118 2005-01-03 devnull .ift .sp .5
35 058b0118 2005-01-03 devnull extern Fhdr* corhdr;
36 058b0118 2005-01-03 devnull extern char* corfil;
37 058b0118 2005-01-03 devnull extern Map* cormap;
38 058b0118 2005-01-03 devnull .ift .sp .5
40 058b0118 2005-01-03 devnull extern int corpid;
41 058b0118 2005-01-03 devnull extern Regs* correg;
42 058b0118 2005-01-03 devnull .SH DESCRIPTION
43 058b0118 2005-01-03 devnull These routines provide access to the objects
44 058b0118 2005-01-03 devnull a typical debugger manipulates: an executable binary,
45 058b0118 2005-01-03 devnull some number of shared libraries, a memory image
46 058b0118 2005-01-03 devnull in the form of a core dump or active process,
47 058b0118 2005-01-03 devnull and a register set.
49 058b0118 2005-01-03 devnull The maintained state is:
51 058b0118 2005-01-03 devnull .I symhdr
52 058b0118 2005-01-03 devnull The file header for the main binary.
54 058b0118 2005-01-03 devnull .I symfil
55 058b0118 2005-01-03 devnull The file name of the main binary.
57 058b0118 2005-01-03 devnull .I symmap
58 058b0118 2005-01-03 devnull The memory map of the main binary.
60 058b0118 2005-01-03 devnull .I fhdrlist
61 058b0118 2005-01-03 devnull A linked list (via the
62 058b0118 2005-01-03 devnull .B Fhdr.next
63 058b0118 2005-01-03 devnull fields) of all currently open headers
65 058b0118 2005-01-03 devnull .I symopen
67 058b0118 2005-01-03 devnull .IR mach-symbol (3)).
68 058b0118 2005-01-03 devnull When dynamically linked objects have been attached,
69 058b0118 2005-01-03 devnull they are present in this linked list,
70 058b0118 2005-01-03 devnull and therefore included in searches by
71 058b0118 2005-01-03 devnull .IR indexsym ,
72 058b0118 2005-01-03 devnull .IR lookupsym ,
74 058b0118 2005-01-03 devnull .I findsym
76 058b0118 2005-01-03 devnull .IR mach-symbol (3)).
78 058b0118 2005-01-03 devnull .I corhdr
79 058b0118 2005-01-03 devnull The file header for the core dump, if any.
81 058b0118 2005-01-03 devnull .I corfil
82 058b0118 2005-01-03 devnull The file name of the core dump, if any.
84 058b0118 2005-01-03 devnull .I cormap
85 058b0118 2005-01-03 devnull The memory map of the core dump or attached process.
87 058b0118 2005-01-03 devnull .I corpid
88 058b0118 2005-01-03 devnull The process id of the attached process, if any.
90 058b0118 2005-01-03 devnull .I correg
91 058b0118 2005-01-03 devnull The register set of the core dump or attached process.
93 058b0118 2005-01-03 devnull If these fields are not valid, they are zeroed.
95 058b0118 2005-01-03 devnull .I Attachcore
97 058b0118 2005-01-03 devnull .I attachproc
98 058b0118 2005-01-03 devnull attach to an opened core file or an executing process.
100 058b0118 2005-01-03 devnull .IR corhdr ,
101 058b0118 2005-01-03 devnull .IR corfil ,
102 058b0118 2005-01-03 devnull .IR cormap ,
103 058b0118 2005-01-03 devnull .IR corpid ,
105 058b0118 2005-01-03 devnull .IR correg .
107 058b0118 2005-01-03 devnull .I Proctextfile
108 058b0118 2005-01-03 devnull returns the name of the main binary for the process with id
109 058b0118 2005-01-03 devnull .IR pid .
111 058b0118 2005-01-03 devnull .I Attachdynamic
112 058b0118 2005-01-03 devnull requires that the memory image already be attached.
113 058b0118 2005-01-03 devnull It reads the dynamic linker's internal run-time data structures
114 058b0118 2005-01-03 devnull and then opens all the dynamic objects that are currently
117 058b0118 2005-01-03 devnull .I Attachargs
118 058b0118 2005-01-03 devnull uses all of these functions while
119 058b0118 2005-01-03 devnull parsing an argument vector as would be passed to
120 058b0118 2005-01-03 devnull a debugger like
121 058b0118 2005-01-03 devnull .IR db (1)
123 058b0118 2005-01-03 devnull .IR acid (1).
124 058b0118 2005-01-03 devnull It expects a list of executable files, core dump files, or process ids,
125 058b0118 2005-01-03 devnull given in any order.
126 058b0118 2005-01-03 devnull If extra arguments are given (for example, more than one executable, or both
127 058b0118 2005-01-03 devnull a core dump and a process id), they are ignored and diagnostics are printed to
128 058b0118 2005-01-03 devnull standard error.
129 058b0118 2005-01-03 devnull If arguments are missing (for example, the process id is given without an
130 058b0118 2005-01-03 devnull executable file),
131 058b0118 2005-01-03 devnull .I attachargs
132 058b0118 2005-01-03 devnull fills them in as best it can.
133 058b0118 2005-01-03 devnull .SH SOURCE
134 058b0118 2005-01-03 devnull .B /usr/local/plan9/src/libmach
135 058b0118 2005-01-03 devnull .SH "SEE ALSO
136 058b0118 2005-01-03 devnull .IR mach (3),
137 058b0118 2005-01-03 devnull .IR mach-file (3),
138 058b0118 2005-01-03 devnull .IR mach-map (3)
139 058b0118 2005-01-03 devnull .SH BUGS
140 058b0118 2005-01-03 devnull The interface needs to be changed to support
141 058b0118 2005-01-03 devnull multiple threads, each with its own register set.