blob: ac6b3bbdf6891e36c82b619b6c88d88f78e70d36 [file] [log] [blame]
attachargs, attachcore, attachdynamic, attachproc, proctextfile \- debugging processes and core files
.B #include <u.h>
.B #include <libc.h>
.B #include <mach.h>
.ta +\w'\fLextern 'u +\w'\fLchar *'u
int attachcore(Fhdr *hdr)
int attachproc(int pid)
int attachdynamic(void)
char* proctextfile(int pid)
int attachargs(int argc, char **argv, int omode)
extern Fhdr* symhdr;
extern char* symfil;
extern Map* symmap;
extern Fhdr* fhdrlist;
.ift .sp .5
.ifn .sp
extern Fhdr* corhdr;
extern char* corfil;
extern Map* cormap;
.ift .sp .5
.ifn .sp
extern int corpid;
extern Regs* correg;
These routines provide access to the objects
a typical debugger manipulates: an executable binary,
some number of shared libraries, a memory image
in the form of a core dump or active process,
and a register set.
The maintained state is:
.I symhdr
The file header for the main binary.
.I symfil
The file name of the main binary.
.I symmap
The memory map of the main binary.
.I fhdrlist
A linked list (via the
fields) of all currently open headers
.I symopen
.IR mach-symbol (3)).
When dynamically linked objects have been attached,
they are present in this linked list,
and therefore included in searches by
.IR indexsym ,
.IR lookupsym ,
.I findsym
.IR mach-symbol (3)).
.I corhdr
The file header for the core dump, if any.
.I corfil
The file name of the core dump, if any.
.I cormap
The memory map of the core dump or attached process.
.I corpid
The process id of the attached process, if any.
.I correg
The register set of the core dump or attached process.
If these fields are not valid, they are zeroed.
.I Attachcore
.I attachproc
attach to an opened core file or an executing process.
They set
.IR corhdr ,
.IR corfil ,
.IR cormap ,
.IR corpid ,
.IR correg .
.I Proctextfile
returns the name of the main binary for the process with id
.IR pid .
.I Attachdynamic
requires that the memory image already be attached.
It reads the dynamic linker's internal run-time data structures
and then opens all the dynamic objects that are currently
.I Attachargs
uses all of these functions while
parsing an argument vector as would be passed to
a debugger like
.IR db (1)
.IR acid (1).
It expects a list of executable files, core dump files, or process ids,
given in any order.
If extra arguments are given (for example, more than one executable, or both
a core dump and a process id), they are ignored and diagnostics are printed to
standard error.
If arguments are missing (for example, the process id is given without an
executable file),
.I attachargs
fills them in as best it can.
.B \*9/src/libmach
.IR mach (3),
.IR mach-file (3),
.IR mach-map (3)
The interface needs to be changed to support
multiple threads, each with its own register set.