6 #include <sys/utsname.h>
16 unsigned long next_addr;
19 unsigned char databyte;
22 static struct wine_bp wbp[N_BP] = {{0,},};
24 static int current_bp = -1;
25 static int cont_mode=0; /* 0 - continuous execution
26 1 - advancing after breakpoint
27 2 - single step - not implemented
33 fprintf(stderr,"Breakpoint status\n");
36 fprintf(stderr,"%d: %c %8lx\n", j, (wbp[j].enabled ? 'y' : 'n'),
40 void disable_break(int bpnum)
42 if(bpnum >= N_BP || bpnum < 0)
43 fprintf(stderr,"Breakpoint number out of range\n");
45 wbp[bpnum].enabled = 0;
48 void enable_break(int bpnum)
50 if(bpnum >= N_BP || bpnum < 0)
51 fprintf(stderr,"Breakpoint number out of range\n");
53 wbp[bpnum].enabled = 1;
56 void add_break(unsigned long addr)
68 fprintf(stderr,"No more breakpoints\n");
76 perror("Sorry, can't set break point");
80 if(strcmp(buf.sysname,"Linux")==0)
81 { if(strcmp(buf.release,"1.1.62")<0)
82 fprintf(stderr,"Your current Linux release is %s. "
83 "You should upgrade to 1.1.62 or higher\n"
84 "Alternatively, in /usr/src/linux/fs/exec.c,"
85 " change MAP_SHARED to MAP_PRIVATE.\n", buf.release);
87 fprintf(stderr,"Why did you compile for Linux, while your system is"
88 " actually %s?\n",buf.sysname);
93 void insert_break(int flag)
101 /* There are a couple of problems with this. On Linux prior to
102 1.1.62, this call fails (ENOACCESS) due to a bug in fs/exec.c.
103 This code is currently not tested at all on BSD.
104 How do I determine the page size in a more symbolic manner?
105 And why does mprotect need that start address of the page
107 Not that portability matters, this code is i386 only anyways...
108 How do I get the old protection in order to restore it later on?
110 if(mprotect((caddr_t)(wbp[j].addr & (~4095)), 4096,
111 PROT_READ|PROT_WRITE|PROT_EXEC) == -1){
115 pnt = (unsigned char *) wbp[j].addr;
117 wbp[j].databyte = *pnt;
118 *pnt = 0xcc; /* Change to an int 3 instruction */
120 *pnt = wbp[j].databyte;
122 mprotect((caddr_t)(wbp[j].addr & ~4095), 4096, PROT_READ|PROT_EXEC);
126 /* Get the breakpoint number that we broke upon */
127 int get_bpnum(unsigned int addr)
131 for(j=0; j<N_BP; j++)
133 if(wbp[j].addr == addr) return j;
138 void toggle_next(int num)
142 if(wbp[num].next_addr == 0)
143 wbp[num].next_addr=addr+print_insn(addr,addr,stderr,dbg_mode);
144 wbp[num].addr=wbp[num].next_addr;
145 wbp[num].next_addr=addr;
148 int should_continue(int bpnum)
152 if(bpnum==current_bp){