Example #1
0
void breakpoint_preset(){
    BP* temp=head;
	if(head==NULL)
		return;
	if(head->type==true){
		while(temp!=NULL){
			swaddr_write(temp->address,1,0xcc);
			temp=temp->next;
		}
	}
	else{
		while(temp!=NULL){
			if(swaddr_read(temp->address,4)!=temp->instr)
				swaddr_write(temp->address,1,0xcc);
			temp=temp->next;
		}
	}
}
Example #2
0
void enable_all_bp() {
    BP* current = head;
    while (current != NULL) {
        if (current->expr[0] == '\0') {
            Log("addr = %x, value = %x", current->addr, current->value);
            current->value = swaddr_read(current->addr, 1);
            swaddr_write(current->addr, 1, INT3_CODE);
        }
        current = current->next;
    }
}
Example #3
0
/*设置断点*/
void set_b(unsigned x)
{
	BP* newb = new_bp();//从free中找到一个新的可使用的断点
	if(newb == NULL) { assert(0);}//free为空
	newb -> b_or_w = true;
	newb -> addr = x;//储存内存地址
	newb -> sav_istr = swaddr_read(x,1);//储存原指令
	swaddr_write(x,1,INT3_CODE);
	newb -> enb = true;//enable
	newb -> isUsed = true;
	printf("Breakpoint %d at 0x%x\n",(newb -> NO)+1,x);
}
Example #4
0
//first judge this is bp.If it is bp, end it.
void end_wp(uint32_t addr){
	WP *temp;
	bool iswp=0;
	for (temp=head;temp!=free_;temp=temp->next) {
		if (addr==temp->addr) {
			iswp=1;
			break;
		}
	}
	if (iswp==0)
		return;
	swaddr_write(addr,1,temp->data);
}
Example #5
0
void free_all() {
    while(head != NULL) { 
        BP* temp = head;
        head = head->next;
        temp->next = free;
        free = temp;

        /* breakpoint need to restore the memory value */
        if (temp->expr[0] == '\0')
            swaddr_write(temp->addr, 1, temp->value);

        /* init */
        temp->addr = 0;
        temp->value = 0;
        temp->expr[0] = '\0';
    }
    bp_state = NORMAL;
}
Example #6
0
void reset_b()
{
	BP *p=head;
	while(p!=NULL)
	{
		if(p->type == 'b')
		{
			if(swaddr_read(p->address,1) != 0)
				if(swaddr_read(p->address,1) !=0xcc)
				{
					p->content = swaddr_read(p->address,1);
					swaddr_write(p->address,1,0xcc);
				}
		}
		p = p->next;
	}

}
Example #7
0
/* add new breakpoint in the rear position */
void add_bp(swaddr_t addr) {
    BP* temp = new_bp();

    /* add to the rear */
    if (head == NULL) {
        head = temp;
    } else {
        /* travel to the rear */
        BP* rear = head;
        while (rear->next != NULL)
            rear = rear->next;
        rear->next = temp;
    }
    
    /* init */
    temp->next = NULL;
    temp->addr = addr;
    temp->value = swaddr_read(addr, 1);
    swaddr_write(addr, 1, INT3_CODE);
    assert(temp->expr[0] == '\0');
}
Example #8
0
bool check_wp(swaddr_t addr){
	if (head==NULL)
		return false;
	bool ret=false;
	bool success=true;
	uint32_t value;
	WP *temp;
	for (temp=head;temp!=free_;temp=temp->next) {
		value=expr(temp->expr,&success);
		if (success==true){
			if (value!=temp->value) {
				temp->addr=swaddr_read(addr,1);
				swaddr_write(addr, 1, 0xcc);
				temp->stop=true;
				ret=true;
				printf("Hit watchpoint: %s\n",temp->expr);
			}
		}
	}
	return ret;
}
Example #9
0
/*把某个内存地址的断点释放*/
void free_bp(unsigned n)
{
	BP* current = head,*last;
	while(current -> addr != n && current != NULL) 
	{
		last = current;
		current = current -> next;
	}
	if(current -> addr == n)
	{
		if(current == head)
			head = current -> next;
		else
			last -> next = current -> next;
		current -> next = free_;
		free_ = current;
		swaddr_write(n,1,current -> sav_istr);
		current -> isUsed = false;
	}
	else
		printf("There does't exist the breakpoint!\n");
}
Example #10
0
/* restore the value of the address
 * after the breakpoint being triggered
 */
void restore_bp(swaddr_t addr) {
    BP* dest = search_bp(addr);
    if (dest != NULL) {
        swaddr_write(addr, 1, dest->value);
    }
}
Example #11
0
BP* new_bp(int num,uint32_t baddress,char c,char *s)
{
	if(free_->next==NULL)
	{
		assert(0);
	}
	else if(head==NULL)
	{
		assert(head==NULL);
		head=&bp_pool[0];
		free_=head->next;
		head->next=NULL;
		head->NO=num;
		head->type=c;
		if(head->type=='b')
		{
			head->address=baddress;
			if(swaddr_read(baddress,1) != 0)
			{
				head->content=swaddr_read(baddress,1);
				swaddr_write(baddress,1,0xcc);
			}
		}
		else if(head->type=='w')
		{
			strcpy(head->s,s);
			head->val=expr(head->s);
		}
		return head;
	}
	else
	{
		BP* p=head;
		BP* p1=head;
		while(p!=NULL)
		{
			if(p->address==baddress&&p->type==c&&c=='b')
				assert(0);
			if(p->NO==num)
			{
				p->type=c;
				if(p->type=='b')
				{
					p->address=baddress;
					if(swaddr_read(baddress,1) != 0)
					{
						p->content=swaddr_read(baddress,1);
						swaddr_write(baddress,1,0xcc);
					}
				}
				else if(p->type=='w')
				{
					strcpy(p->s,s);
					p->val=expr(p->s);
				}
				return p;
			}
			p1=p;
			p=p->next;
		}
		p1->next=free_;
		p1=free_;
		free_=free_->next;
		p1->next=NULL;
		p1->NO=num;
		p1->type=c;
		if(p1->type=='b')
		{
			p1->address=baddress;
			if(swaddr_read(baddress,1) != 0)
			{
				p1->content=swaddr_read(baddress,1);
				swaddr_write(baddress,1,0xcc);
			}
		}
		else if(p1->type=='w')
		{
			strcpy(p1->s,s);
			p1->val=expr(p1->s);
		}
		return p1;
	}
}
Example #12
0
void breakpoint_reset(swaddr_t n){
	BP* temp=head;
	while(temp->next!=NULL&&temp->address!=n)
		temp=temp->next;
	swaddr_write(n,1,temp->instr);
}