3 #if defined(__cplusplus)
10 * Architecture-dependent application data.
12 * The code assumes that ulong is big enough to hold
13 * an address on any system of interest as well as any
14 * register. Debugging 64-bit code on 32-bit machines
15 * will be interesting.
17 * Supported architectures:
26 * AT&T 3210 DSP (limited)
30 typedef struct Fhdr Fhdr;
31 typedef struct Loc Loc;
32 typedef struct Mach Mach;
33 typedef struct Map Map;
34 typedef struct Regdesc Regdesc;
35 typedef struct Regs Regs;
36 typedef struct Seg Seg;
37 typedef struct Symbol Symbol;
38 typedef struct Symtype Symtype;
40 typedef int (*Tracer)(Map*, Regs*, ulong, ulong, Symbol*, int);
46 * Byte-order data layout manipulation.
49 u16int beswap2(u16int u);
50 u32int beswap4(u32int u);
51 u64int beswap8(u64int u);
52 int beieeeftoa32(char*, uint, void*);
53 int beieeeftoa64(char*, uint, void*);
54 int beieeeftoa80(char*, uint, void*);
56 u16int leswap2(u16int u);
57 u32int leswap4(u32int u);
58 u64int leswap8(u64int u);
59 int leieeeftoa32(char *a, uint n, void *v);
60 int leieeeftoa64(char *a, uint n, void *v);
61 int leieeeftoa80(char *a, uint n, void *v);
63 u16int beload2(uchar*);
64 u32int beload4(uchar*);
65 u64int beload8(uchar*);
67 u16int leload2(uchar*);
68 u32int leload4(uchar*);
69 u64int leload8(uchar*);
71 int ieeeftoa32(char *a, uint n, u32int u);
72 int ieeeftoa64(char *a, uint n, u32int h, u32int u);
75 * Machine-independent access to an executable image.
88 int (*rw)(Map*, Seg*, ulong, void*, uint, int);
99 int (*rw)(Regs*, char*, ulong*, int);
102 typedef struct UregRegs UregRegs;
108 int _uregrw(Regs*, char*, ulong*, int);
110 typedef struct PidRegs PidRegs;
118 int addseg(Map *map, Seg seg);
119 int findseg(Map *map, char *name, char *file);
120 int addrtoseg(Map *map, ulong addr, Seg *seg);
121 int addrtosegafter(Map *map, ulong addr, Seg *seg);
122 void removeseg(Map *map, int i);
125 int get1(Map *map, ulong addr, uchar *a, uint n);
126 int get2(Map *map, ulong addr, u16int *u);
127 int get4(Map *map, ulong addr, u32int *u);
128 int get8(Map *map, ulong addr, u64int *u);
130 int put1(Map *map, ulong addr, uchar *a, uint n);
131 int put2(Map *map, ulong addr, u16int u);
132 int put4(Map *map, ulong addr, u32int u);
133 int put8(Map *map, ulong addr, u64int u);
135 int rget(Regs*, char*, ulong*);
136 int rput(Regs*, char*, ulong);
139 * A location is either a memory address or a register.
140 * It is useful to be able to specify constant values that
141 * originate from outside the register set and memory,
142 * hence LCONST. If the register values are known, then
143 * we can dispense with LOFFSET, but it's useful to be able
144 * to look up local symbols (via findlsym) with locations
155 LADDR, /* absolute address */
156 LCONST, /* constant (an anonymous readonly location) */
157 LOFFSET, /* dereference offset + register ptr */
162 uint type; /* LNONE, ... */
163 char *reg; /* LREG */
164 ulong addr; /* LADDR, CONST */
165 long offset; /* LOFFSET */
168 int lget1(Map *map, Regs *regs, Loc loc, uchar *a, uint n);
169 int lget2(Map *map, Regs *regs, Loc loc, u16int *v);
170 int lget4(Map *map, Regs *regs, Loc loc, u32int *v);
171 int lget8(Map *map, Regs *regs, Loc loc, u64int *v);
173 int lput1(Map *map, Regs *regs, Loc loc, uchar *a, uint n);
174 int lput2(Map *map, Regs *regs, Loc loc, u16int v);
175 int lput4(Map *map, Regs *regs, Loc loc, u32int v);
176 int lput8(Map *map, Regs *regs, Loc loc, u64int v);
179 Loc locaddr(ulong addr);
180 Loc locconst(ulong con);
182 Loc locindir(char*, long);
185 * Executable file parsing.
187 * An Fhdr represents an open file image.
188 * The contents are a grab bag of constants used for the
189 * various file types. Not all elements are used by all
192 * crackadotplan9.c crackadotunix.c
193 * crackelf.c crackdwarf.c
199 FEXEC, /* executable image */
201 FOBJ, /* object file */
202 FRELOC, /* relocatable executable */
203 FSHLIB, /* shared library */
204 FSHOBJ, /* shared object */
205 FCORE, /* core dump */
206 FBOOT, /* bootable image */
207 FKERNEL, /* kernel image */
219 /* I wish this could be kept in stabs.h */
226 u16int (*e2)(uchar*);
227 u32int (*e4)(uchar*);
232 int fd; /* file descriptor */
233 char *filename; /* file name */
234 Mach *mach; /* machine */
235 char *mname; /* 386, power, ... */
236 uint mtype; /* machine type M386, ... */
237 char *fname; /* core, executable, boot image, ... */
238 uint ftype; /* file type FCORE, ... */
239 char *aname; /* abi name */
240 uint atype; /* abi type ALINUX, ... */
242 ulong magic; /* magic number */
243 ulong txtaddr; /* text address */
244 ulong entry; /* entry point */
245 ulong txtsz; /* text size */
246 ulong txtoff; /* text offset in file */
247 ulong dataddr; /* data address */
248 ulong datsz; /* data size */
249 ulong datoff; /* data offset in file */
250 ulong bsssz; /* bss size */
251 ulong symsz; /* symbol table size */
252 ulong symoff; /* symbol table offset in file */
253 ulong sppcsz; /* size of sp-pc table */
254 ulong sppcoff; /* offset of sp-pc table in file */
255 ulong lnpcsz; /* size of line number-pc table */
256 ulong lnpcoff; /* size of line number-pc table */
257 void *elf; /* handle to elf image */
258 void *dwarf; /* handle to dwarf image */
259 void *macho; /* handle to mach-o image */
261 uint pid; /* for core files */
262 char *prog; /* program name, for core files */
263 char *cmdline; /* command-line that produced core */
264 struct { /* thread state for core files */
271 Symbol *sym; /* cached list of symbols */
275 Symbol *esym; /* elf symbols */
277 ulong base; /* base address for relocatables */
278 Fhdr *next; /* link to next fhdr (internal) */
281 int (*map)(Fhdr*, ulong, Map*, Regs**);
283 /* debugging symbol access; see below */
284 int (*syminit)(Fhdr*);
285 void (*symclose)(Fhdr*);
287 int (*pc2file)(Fhdr*, ulong, char*, uint, ulong*);
288 int (*file2pc)(Fhdr*, char*, ulong, ulong*);
289 int (*line2pc)(Fhdr*, ulong, ulong, ulong*);
291 int (*lookuplsym)(Fhdr*, Symbol*, char*, Symbol*);
292 int (*indexlsym)(Fhdr*, Symbol*, uint, Symbol*);
293 int (*findlsym)(Fhdr*, Symbol*, Loc, Symbol*);
295 int (*unwind)(Fhdr*, Map*, Regs*, ulong*, Symbol*);
298 Fhdr* crackhdr(char *file, int mode);
299 void uncrackhdr(Fhdr *hdr);
300 int crackelf(int fd, Fhdr *hdr);
301 int crackmacho(int fd, Fhdr *hdr);
302 Regs* coreregs(Fhdr*, uint);
309 void symclose(Fhdr*);
311 int mapfile(Fhdr *fp, ulong base, Map *map, Regs **regs);
312 void unmapfile(Fhdr *fp, Map *map);
315 * Process manipulation.
317 int mapproc(int pid, Map *map, Regs **regs);
318 void unmapproc(Map *map);
319 int detachproc(int pid);
320 int ctlproc(int pid, char *msg);
321 int procnotes(int pid, char ***notes);
322 char* proctextfile(int pid);
325 * Command-line debugger help
336 int attachproc(int pid);
337 int attachcore(Fhdr *hdr);
338 int attachargs(int argc, char **argv, int omode, int);
339 int attachdynamic(int);
341 * Machine descriptions.
345 * machsparc.c dissparc.c
350 * Register sets. The Regs are opaque, accessed by using
351 * the reglist (and really the accessor functions).
355 /* must be big enough for all machine register sets */
365 char *name; /* register name */
366 uint offset; /* offset in b */
367 uint flags; /* RINT/RFLT/RRDONLY */
368 uint format; /* print format: 'x', 'X', 'f', 'z', 'Z' */
375 MMIPS, /* MIPS R3000 */
376 MSPARC, /* SUN SPARC */
377 M68000, /* Motorola 68000 */
378 M386, /* Intel 32-bit x86*/
379 M960, /* Intel 960 */
380 M3210, /* AT&T 3210 DSP */
381 MMIPS2, /* MIPS R4000 */
382 M29000, /* AMD 29000 */
384 MPOWER, /* PowerPC */
385 MALPHA, /* DEC/Compaq Alpha */
391 char *name; /* "386", ... */
392 uint type; /* M386, ... */
393 Regdesc *reglist; /* register set */
394 uint regsize; /* size of register set in bytes */
395 uint fpregsize; /* size of fp register set in bytes */
396 char *pc; /* name of program counter */
397 char *sp; /* name of stack pointer */
398 char *fp; /* name of frame pointer */
399 char *link; /* name of link register */
400 char *sbreg; /* name of static base */
401 ulong sb; /* value of static base */
402 uint pgsize; /* page size */
403 ulong kbase; /* kernel base address for Plan 9 */
404 ulong ktmask; /* ktzero = kbase & ~ktmask */
405 uint pcquant; /* pc quantum */
406 uint szaddr; /* size of pointer in bytes */
407 uint szreg; /* size of integer register */
408 uint szfloat; /* size of float */
409 uint szdouble; /* size of double */
410 char** windreg; /* unwinding registers */
413 uchar bpinst[4]; /* break point instruction */
414 uint bpsize; /* size of bp instruction */
416 int (*foll)(Map*, Regs*, ulong, ulong*); /* follow set */
417 char* (*exc)(Map*, Regs*); /* last exception */
418 int (*unwind)(Map*, Regs*, ulong*, Symbol*);
420 /* cvt to local byte order */
421 u16int (*swap2)(u16int);
422 u32int (*swap4)(u32int);
423 u64int (*swap8)(u64int);
424 int (*ftoa32)(char*, uint, void*);
425 int (*ftoa64)(char*, uint, void*);
426 int (*ftoa80)(char*, uint, void*);
429 int (*das)(Map*, ulong, char, char*, int); /* symbolic */
430 int (*kendas)(Map*, ulong, char, char*, int); /* symbolic */
431 int (*codas)(Map*, ulong, char, char*, int);
432 int (*hexinst)(Map*, ulong, char*, int); /* hex */
433 int (*instsize)(Map*, ulong); /* instruction size */
436 Mach *machbyname(char*);
437 Mach *machbytype(uint);
440 extern Mach machsparc;
441 extern Mach machmips;
442 extern Mach machpower;
445 * Debugging symbols and type information.
446 * (Not all objects include type information.)
453 /* symbol table classes */
455 CAUTO, /* stack variable */
456 CPARAM, /* function parameter */
457 CTEXT, /* text segment */
458 CDATA, /* data segment */
464 char *name; /* name of symbol */
465 char *xname; /* demangled name */
467 /* Symtype *typedesc; /* type info, if any */
468 Loc loc; /* location of symbol */
469 Loc hiloc; /* location of end of symbol */
470 char class; /* CAUTO, ... */
471 char type; /* type letter from a.out.h */
472 Fhdr *fhdr; /* where did this come from? */
473 uint index; /* in by-address list */
475 /* private use by various symbol implementations */
491 void *aux; /* for use by client */
494 /* look through all currently cracked Fhdrs calling their fns */
495 int pc2file(ulong pc, char *file, uint nfile, ulong *line);
496 int file2pc(char *file, ulong line, ulong *addr);
497 int line2pc(ulong basepc, ulong line, ulong *pc);
498 int fnbound(ulong pc, ulong *bounds);
499 int fileline(ulong pc, char *a, uint n);
500 int pc2line(ulong pc, ulong *line);
502 int lookupsym(char *fn, char *var, Symbol *s);
503 int indexsym(uint ndx, Symbol *s);
504 int findsym(Loc loc, uint class, Symbol *s);
505 int findexsym(Fhdr*, uint, Symbol*);
507 int lookuplsym(Symbol *s1, char *name, Symbol *s2);
508 int indexlsym(Symbol *s1, uint ndx, Symbol *s2);
509 int findlsym(Symbol *s1, Loc loc, Symbol *s);
510 int symoff(char *a, uint n, ulong addr, uint class);
511 int unwindframe(Map *map, Regs *regs, ulong *next, Symbol*);
515 extern Fhdr* fhdrlist;
516 Fhdr* findhdr(char*);
518 Symbol* flookupsym(Fhdr*, char*);
519 Symbol* ffindsym(Fhdr*, Loc, uint);
520 Symbol* _addsym(Fhdr*, Symbol*);
522 char* demangle(char*, char*, int);
523 char* demanglegcc3(char*, char*);
524 char* demanglegcc2(char*, char*);
526 * Stack frame walking.
530 int stacktrace(Map*, Regs*, Tracer);
531 int windindex(char*);
532 Loc* windreglocs(void);
537 int localaddr(Map *map, Regs *regs, char *fn, char *var, ulong *val);
538 int fpformat(Map *map, Regdesc *reg, char *a, uint n, uint code);
539 char* _hexify(char*, ulong, int);
541 int loccmp(Loc*, Loc*);
542 int locsimplify(Map *map, Regs *regs, Loc loc, Loc *newloc);
543 Regdesc* regdesc(char*);
545 extern int machdebug;
546 #if defined(__cplusplus)