vm: fix potential null deref
[minix.git] / commands / mdb / trace.c
blob4a64bbcb29d8ed60cbe32dcb7c8db3f16bfcd7b2
1 /*
2 * trace.c for mdb
3 */
5 #include "mdb.h"
6 #include <stdio.h>
7 #include <sys/ptrace.h>
8 #include "proto.h"
10 /* mdbtrace()
11 * Call ptrace and check for error if debugging running process
12 * Otherwise read 'core' file
13 */
14 long mdbtrace(req, pid, addr, data)
15 int req, pid;
16 long addr, data;
18 long val;
19 int i;
20 int segment;
22 #ifdef DEBUG
23 if (debug) Printf("ptrace: req=%d pid=%d addr=%lx data=%lx\n",
24 req, pid, addr, data);
25 #endif
27 if (corepid < 0)
29 errno = 0;
30 /* Call normal ptrace and check for error */
31 val = ptrace(req, pid, addr, data);
32 if (errno != 0) {
33 do_error("mdb ptrace error ");
34 mdb_error("\n");
36 #ifdef DEBUG
37 if (debug) Printf("ptrace: val=>%lx\n", val);
38 #endif
39 return val;
41 else
42 return read_core(req, addr, data);
45 /* Used by disassembler */
46 u32_t peek_dword(addr)
47 off_t addr;
49 return mdbtrace(T_GETINS, curpid, addr, 0L);