4 * reads information from 'core' file
5 * Partly derived from 'adb' by D. Dugger.
15 #include <sys/ptrace.h>
17 #include <machine/archtypes.h>
18 #include <kernel/const.h>
19 #include <kernel/type.h>
20 #include <kernel/proc.h>
22 /* defined in kernel.c */
23 extern struct proc
*prc
;
34 unsigned long tmap
[3];
35 unsigned long dmap
[3];
36 unsigned long smap
[3];
37 char buf
[BSIZE
+ BSIZE
];
38 } Core_File
, *core_file
;
50 PRIVATE
long cnt
[3]; /* Sizes of segments */
51 PRIVATE
int h_size
; /* Size of core header */
52 PRIVATE
char def_name
[] = "core"; /* Default core name */
54 #define SIZE_MP_SEG (sizeof(struct mem_map) * NR_LOCAL_SEGS)
55 #define SIZE_KINFO sizeof(struct proc)
56 #define SIZE_HEADER SIZE_MP_SEG
58 FORWARD
_PROTOTYPE( int kernel_info
, (int fd
));
59 FORWARD
_PROTOTYPE( void setmap
, (struct file
*fp
));
60 FORWARD
_PROTOTYPE( void read_info
, (struct file
*fp
));
61 FORWARD
_PROTOTYPE( void ill_addr
, (long d
, int segment
));
62 FORWARD
_PROTOTYPE( long map_addr
, (long d
, int segment
));
63 FORWARD
_PROTOTYPE( unsigned long c_status
, (void));
64 FORWARD
_PROTOTYPE( long getn
, (long d
, int s
) );
67 * set and display mapping for core file
69 PRIVATE
void setmap(fp
)
72 long h
= (long) h_size
;
75 fp
->e1
= st_addr
+ cnt
[T
];
79 fp
->e2
= sd_addr
+ cnt
[D
];
83 fp
->e3
= sk_addr
+ cnt
[S
];
84 fp
->f3
= cnt
[T
] + cnt
[D
] + h
;
88 if ( end_addr
< et_addr
) end_addr
= et_addr
;
92 fp
->e2
= st_addr
+ cnt
[T
] + cnt
[D
];
101 Printf("From core file:\n");
102 Printf("T\t%8lx %8lx %8lx\n", core_file
->b1
, core_file
->e1
, core_file
->f1
);
103 Printf("D\t%8lx %8lx %8lx\n", core_file
->b2
, core_file
->e2
, core_file
->f2
);
104 Printf("S\t%8lx %8lx %8lx\n", core_file
->b3
, core_file
->e3
, core_file
->f3
);
112 Printf("%s I & D space\t", (is_separate
) ? "Separate " : "Combined ");
114 Printf("File: %s\n\n", core_file
->name
);
119 Printf("Pid: %d\n\n", curpid
);
125 /* Illegal address */
126 PRIVATE
void ill_addr(d
, segment
)
130 Printf("Bad addr=%lx seg=%d",d
,segment
);
134 /* Map virtual address -> core file addresses
135 * depends on current segment if Separate I & D
137 PRIVATE
long map_addr(d
, segment
)
145 if (d
>= core_file
->b1
&& d
< core_file
->e1
)
146 d
+= core_file
->f1
- core_file
->b1
;
152 if (d
>= core_file
->b2
&& d
< core_file
->e2
)
153 d
+= core_file
->f2
- core_file
->b2
;
154 else if (d
>= core_file
->b3
&& d
< core_file
->e3
)
155 d
+= core_file
->f3
- core_file
->b3
;
162 if (d
>= core_file
->b1
&& d
< core_file
->e1
)
163 d
+= core_file
->f1
- core_file
->b1
;
164 else if (d
>= core_file
->b2
&& d
< core_file
->e2
)
165 d
+= core_file
->f2
- core_file
->b2
;
166 else if (d
>= core_file
->b3
&& d
< core_file
->e3
)
167 d
+= core_file
->f3
- core_file
->b3
;
177 /* Get value with address d and segment s */
178 PRIVATE
long getn(d
, s
)
195 if (core_file
->cblock
!= b
) {
196 core_file
->cblock
= b
;
197 lseek(core_file
->fid
, b
<< LOGBS
, 0);
198 read(core_file
->fid
, core_file
->buf
, sizeof(core_file
->buf
));
202 data
.c
[i
] = core_file
->buf
[o
+i
];
206 Printf("getn at %8lx val %8lx\n", d
, data
.l
);
211 /* Read kernel info from core file into lbuf[] */
212 PRIVATE
int kernel_info(fd
)
218 /* Round SIZE_KINFO to multiple of sizeof(long) */
219 /* See mm/signal.c to see how a 'core' file is written */
220 ks
= ( SIZE_KINFO
/ sizeof(long) ) * sizeof(long);
221 r
= read(fd
, (char *)lbuf
, ks
);
222 return(r
== ks
) ? ks
: -1;
226 * Print status info from core - returns PC
228 PRIVATE
unsigned long c_status()
230 fprintf(stderr
, "WARNING: don't know pid from core; using proc nr for pid.\n");
232 Printf("Proc = %6d\n", prc
->p_nr
);
234 /* Set current pid to that of core */
235 curpid
= corepid
= prc
->p_nr
;
237 Printf("\nPC = 0x%0*lx\t", 2 * ADDRSIZE
, PC_MEMBER(prc
) & MASK(ADDRSIZE
));
238 symbolic((long) PC_MEMBER(prc
), '\n');
239 dasm((long) PC_MEMBER(prc
), 1, 1);
240 return PC_MEMBER(prc
);
243 /* Read memory maps and kernel info from core file */
244 PRIVATE
void read_info(fp
)
247 struct mem_map seg
[NR_LOCAL_SEGS
];
251 lseek(fp
->fid
, 0L, 0L);
253 /* First read memory map of all segments. */
254 if (read(fp
->fid
, (char *) seg
, (int) SIZE_MP_SEG
) < 0) {
256 Printf("mdb: cannot read core header\n");
260 h_size
= SIZE_HEADER
;
262 /* Read kernel dependent info */
263 r
= kernel_info(fp
->fid
);
266 Printf("mdb: cannot read kernel info from 'core' file\n");
273 for (i
= T
; i
<= S
; i
++)
274 cnt
[i
] = (long) seg
[i
].mem_len
<< CLICK_SHIFT
;
276 /* This needs to be set for map_addr() below */
277 if(coreonly
&& cnt
[T
] != 0) is_separate
= TRUE
;
279 st_addr
= (long) seg
[T
].mem_vir
<< CLICK_SHIFT
;
280 et_addr
= st_addr
+ ((long) seg
[T
].mem_len
<< CLICK_SHIFT
);
282 sd_addr
= (long) seg
[D
].mem_vir
<< CLICK_SHIFT
;
284 sd_addr
+ ((long) seg
[D
].mem_len
<< CLICK_SHIFT
);
286 sk_addr
= (long) seg
[S
].mem_vir
<< CLICK_SHIFT
;
287 sk_size
= (long) seg
[S
].mem_len
<< CLICK_SHIFT
;
292 /* initialization for core files
293 * returns PC address from core file
295 PUBLIC
unsigned long core_init(filename
)
298 core_file
= &Core_File
;
299 core_file
->name
= (filename
!= NULL
) ? filename
: def_name
;
301 core_file
->fid
= open(core_file
->name
, 0);
302 if (filename
!= NULL
&& core_file
->fid
< 0) {
303 Printf("mdb - warning cannot open: %s\n", core_file
->name
);
307 core_file
->b1
= core_file
->b2
= core_file
->b3
= 0;
308 core_file
->e1
= core_file
->e2
= core_file
->e3
= 0;
309 core_file
->f1
= core_file
->f2
= core_file
->f3
= 0;
310 core_file
->cblock
= -1;
312 if (core_file
->fid
> 0) {
313 read_info(core_file
);
320 /* initialization for a file ( -f option )
322 * Similar to core files.
324 PUBLIC
unsigned long file_init(filename
)
327 core_file
= &Core_File
;
328 core_file
->name
= (filename
!= NULL
) ? filename
: def_name
;
330 core_file
->fid
= open(core_file
->name
, 0);
331 if (filename
!= NULL
&& core_file
->fid
< 0) {
332 Printf("mdb - warning cannot open: %s\n", core_file
->name
);
336 core_file
->b1
= core_file
->b2
= core_file
->b3
= 0;
337 core_file
->e1
= core_file
->e2
= core_file
->e3
= 0;
338 core_file
->f1
= core_file
->f2
= core_file
->f3
= 0;
339 core_file
->cblock
= -1;
342 core_file
->e1
= file_size(core_file
->fid
);
343 curpid
= corepid
= 1;
349 * Read from core file
350 * Called by mdbtrace()
352 PUBLIC
long read_core(req
, addr
, data
)
363 /* Check segment and address - call getn to read core file */
364 segment
= (req
== T_GETINS
) ? T
: D
;
365 addr
&= MASK(ADDRSIZE
);
366 val
= getn(addr
, segment
);
368 if (debug
) Printf("val=>%lx\n", val
);
373 /* Convert addr to index to long array */
374 i
= (int) (addr
>> 2);
376 if (debug
) Printf("lbuf[%d] %lx\n", i
, lbuf
[i
]);
385 mdb_error("Not supported with 'core' files\n");