2
debugger.h - necessary definition for skyeye debugger
3
Copyright (C) 2003 Skyeye Develop Group
4
for help please send mail to <skyeye-developer@lists.sf.linuxforum.net>
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
#include "skyeye2gdb.h"
26
extern void fetch_inferior_registers (int regno, unsigned char *memory);
27
extern register_defs_t *current_reg_type;
29
int add_tracepoint (unsigned int tp_number,unsigned int tp_address)
31
if (skyeye_ice.num_tps<MAX_TRACEPOINTS)
33
skyeye_ice.tps[skyeye_ice.num_tps].tp_address=tp_address;
34
skyeye_ice.tps[skyeye_ice.num_tps].number=tp_number;
35
set_tracepoint_status(skyeye_ice.num_tps, TRACEPOINT_DISABLED);
36
skyeye_ice.tps[skyeye_ice.num_tps].pass_count=0;
37
skyeye_ice.tps[skyeye_ice.num_tps].remaining_pass=0;
38
skyeye_ice.tps[skyeye_ice.num_tps].remaining_step=0;
40
return(skyeye_ice.num_tps-1);
48
int find_tp_id (unsigned int tp_number,unsigned int tp_address)
51
for (i=0;i<skyeye_ice.num_tps;i++)
53
if ((skyeye_ice.tps[i].number==tp_number)&&(skyeye_ice.tps[i].tp_address==tp_address))
60
void set_tracepoint_status(int tp_id, tracepoint_status status)
62
skyeye_ice.tps[tp_id].status=status;
65
tracepoint_status get_tracepoint_status(int tp_id)
67
return (skyeye_ice.tps[tp_id].status);
70
void set_tracepoint_address(int tp_id, unsigned int address )
72
skyeye_ice.tps[tp_id].tp_address=address;
75
unsigned int get_tracepoint_address(int tp_id)
77
return (skyeye_ice.tps[tp_id].tp_address);
80
void set_tracepoint_number(int tp_id, unsigned int number )
82
skyeye_ice.tps[tp_id].number=number;
85
unsigned int get_tracepoint_number(int tp_id)
87
return (skyeye_ice.tps[tp_id].number);
90
void set_tracepoint_pass_count(int tp_id, unsigned int pass_count )
92
skyeye_ice.tps[tp_id].pass_count=pass_count;
95
unsigned int get_tracepoint_pass_count(int tp_id)
97
return (skyeye_ice.tps[tp_id].pass_count);
100
void set_tracepoint_remaining_pass(int tp_id, unsigned int remaining_pass )
102
skyeye_ice.tps[tp_id].remaining_pass=remaining_pass;
105
unsigned int get_tracepoint_remaining_pass(int tp_id)
107
return (skyeye_ice.tps[tp_id].remaining_pass);
110
void set_tracepoint_remaining_step(int tp_id, unsigned int remaining_step )
112
skyeye_ice.tps[tp_id].remaining_step=remaining_step;
115
unsigned int get_tracepoint_remaining_step(int tp_id)
117
return (skyeye_ice.tps[tp_id].remaining_step);
120
void populate_default_action(action * current_action)
122
current_action->type=ACTION_UNASSIGNED;
123
current_action->sibling=NULL;
124
current_action->child=NULL;
129
action* prepare_action(int tp_id, action *parent_action)
132
if (parent_action==NULL) //we are not in a while-stepping case
134
if(skyeye_ice.tps[tp_id].actions ==NULL)
136
skyeye_ice.tps[tp_id].actions=(action *)malloc(sizeof(action));
137
populate_default_action(skyeye_ice.tps[tp_id].actions);
138
return(skyeye_ice.tps[tp_id].actions);
142
current =skyeye_ice.tps[tp_id].actions;
147
if(parent_action->child ==NULL)
149
parent_action->child=(action *)malloc(sizeof(action));
150
populate_default_action(parent_action->child);
151
return(parent_action->child);
155
current =parent_action->child;
158
while (current->sibling!=NULL)
160
current=current->sibling;
162
current->sibling=(action *)malloc(sizeof(action));
163
populate_default_action(current->sibling);
164
return(current->sibling);
170
void set_action_type (action *action_p, action_type type)
175
action_type get_action_type (action *action_p)
177
return (action_p->type);
180
void set_action_data_type(action *action_p, collect_action_type type )
182
action_p->action_data.ca.type=type;
185
collect_action_type get_action_data_type(action *action_p)
187
return (action_p->action_data.ca.type);
190
void set_wa_step_count (action *action_p, unsigned int step_count)
192
action_p->action_data.wa.step_count=step_count;
195
unsigned int get_wa_step_count (action *action_p)
197
return (action_p->action_data.wa.step_count);
200
void set_wa_remaining_steps (action *action_p, unsigned int remaining_steps)
202
action_p->action_data.wa.remaining_steps=remaining_steps;
205
void set_rc_action_mask( action *action_p, unsigned int mask)
207
action_p->action_data.ca.description.rc.mask=mask;
210
void set_mc_action_base_reg(action *action_p, unsigned int base_reg)
212
action_p->action_data.ca.description.mc.base_reg=base_reg;
215
void set_mc_action_offset(action *action_p, unsigned int offset)
217
action_p->action_data.ca.description.mc.offset=offset;
220
void set_mc_action_length(action *action_p, unsigned int length)
222
action_p->action_data.ca.description.mc.length=length;
225
void delete_action (action * current_action)
227
//post fix iteration in a binary tree
228
if (current_action->sibling!=NULL)
230
delete_action(current_action->sibling);
231
current_action->sibling=NULL;
233
if (current_action->child!=NULL)
235
delete_action(current_action->child);
236
current_action->child=NULL;
238
if ((current_action->sibling==NULL)&&(current_action->child==NULL))
240
free(current_action);
246
void clear_ro_regions(void)
248
ro_region * previous_ro_region ,*next_ro_region;
250
if (skyeye_ice.ro_region_head!=NULL)
252
next_ro_region = skyeye_ice.ro_region_head;
253
while(next_ro_region!=NULL)
255
previous_ro_region=next_ro_region;
256
next_ro_region=next_ro_region->next;
257
free(previous_ro_region);
259
skyeye_ice.ro_region_head=NULL;
264
int is_in_ro_region(unsigned int addr, int length)
266
ro_region *current_ro_region;
267
if (skyeye_ice.ro_region_head==NULL)
271
current_ro_region=skyeye_ice.ro_region_head;
272
while(current_ro_region!=NULL)
274
if ((current_ro_region->start <=addr)&&(current_ro_region->end >=addr+length))
278
current_ro_region=current_ro_region->next;
285
void add_ro_region(unsigned int start, unsigned int end)
287
ro_region *current_ro_region;
288
if (skyeye_ice.ro_region_head!=NULL)
290
current_ro_region=skyeye_ice.ro_region_head;
291
while(current_ro_region->next !=NULL)
293
current_ro_region=current_ro_region->next;
295
current_ro_region->next=(ro_region *)malloc (sizeof(ro_region));
296
current_ro_region=current_ro_region->next;
300
skyeye_ice.ro_region_head=(ro_region *)malloc (sizeof(ro_region));
301
current_ro_region=skyeye_ice.ro_region_head;
303
current_ro_region->start=start;
304
current_ro_region->end=end;
305
current_ro_region->next=NULL;
308
void clear_collect_records(collect_record *head_record)
310
collect_record * previous_collect_record ,*next_collect_record;
312
if (head_record!=NULL)
314
next_collect_record = head_record;
315
while(next_collect_record!=NULL)
317
previous_collect_record=next_collect_record;
318
next_collect_record=next_collect_record->next;
319
free(previous_collect_record);
325
void clear_frame_buffers(void)
327
frame_buffer * previous_frame_buffer ,*next_frame_buffer;
329
if (skyeye_ice.fb!=NULL)
331
next_frame_buffer = skyeye_ice.fb;
332
while(next_frame_buffer!=NULL)
334
previous_frame_buffer=next_frame_buffer;
335
next_frame_buffer=next_frame_buffer->next;
336
clear_collect_records(previous_frame_buffer->head_record);
337
free(previous_frame_buffer);
340
skyeye_ice.num_fb =0;
346
frame_buffer * add_frame_buffer ( void )
348
frame_buffer * current_frame_buffer;
350
current_frame_buffer = skyeye_ice.fb;
351
if (skyeye_ice.fb ==NULL)
353
skyeye_ice.fb= (frame_buffer *)malloc (sizeof(frame_buffer));
354
current_frame_buffer=skyeye_ice.fb;
358
while (current_frame_buffer ->next !=NULL)
360
current_frame_buffer = current_frame_buffer ->next;
362
current_frame_buffer ->next =(frame_buffer *)malloc (sizeof(frame_buffer));
363
current_frame_buffer=current_frame_buffer ->next;
365
// set every thing to default
366
current_frame_buffer->tp_number=0;
367
current_frame_buffer->frame_number=skyeye_ice.num_fb;
368
current_frame_buffer->head_record=NULL;
369
current_frame_buffer->next=NULL;
371
return (current_frame_buffer);
375
void trace_fetch_registers(int regno, unsigned char *memory)
377
collect_record *current_record;
378
if(skyeye_ice.selected_fb!=NULL)
380
current_record=skyeye_ice.selected_fb->head_record;
381
while (current_record!=NULL)
383
if (current_record->ca->type ==COLLECT_REGISTERS)
385
memcpy (memory,current_record->collect_data,current_record->collect_data_length);
390
current_record=current_record->next;
396
int trace_read (unsigned int addr, unsigned char *buffer, int size)
398
collect_record *current_record;
399
if(skyeye_ice.selected_fb!=NULL)
401
current_record=skyeye_ice.selected_fb->head_record;
402
while (current_record!=NULL)
404
if (current_record->ca->type ==COLLECT_MEMORY)
406
if ((addr >=current_record->ca->description.mc.offset)&&(addr+size<=current_record->ca->description.mc.offset+current_record->ca->description.mc.length))
408
memcpy (buffer,(current_record->collect_data)+(addr-current_record->ca->description.mc.offset),size);
413
current_record=current_record->next;
418
current_record=current_record->next;
426
int select_frame_buffer_by_fn (int *tracepoint_number,int frame_number)
428
frame_buffer * current_fb;
429
if ( frame_number >skyeye_ice.num_fb)
431
//the frame couldn't be found
436
skyeye_ice.selected_fb=skyeye_ice.fb;
437
current_fb=skyeye_ice.selected_fb;
438
while (current_fb !=NULL)
440
if (current_fb->frame_number==frame_number)
442
skyeye_ice.selected_fb=current_fb;
443
*tracepoint_number=skyeye_ice.selected_fb->tp_number;
448
current_fb=current_fb->next;
455
int select_frame_buffer_by_tpn (int tracepoint_number, int *frame_number)
457
frame_buffer * current_fb;
458
if (skyeye_ice.selected_fb==NULL)
460
skyeye_ice.selected_fb=skyeye_ice.fb;
462
if (skyeye_ice.selected_fb ==NULL) return (0);
464
current_fb=skyeye_ice.selected_fb->next;
465
while (current_fb !=NULL)
467
if (current_fb->tp_number==tracepoint_number)
469
skyeye_ice.selected_fb=current_fb;
470
*frame_number=skyeye_ice.selected_fb->frame_number;
475
current_fb=current_fb->next;
483
void do_action (unsigned int tp_id, action * current_action, frame_buffer * record_fb)
486
unsigned char * buffer ;
487
collect_record * current_collect_record;
488
unsigned int base_reg_val;
489
unsigned char *registers;
491
//point to the lase record in the frame buffer
492
if (record_fb==NULL) return;
493
if (record_fb->head_record !=NULL)
495
current_collect_record =record_fb->head_record;
496
while (current_collect_record->next !=NULL)
498
current_collect_record = current_collect_record->next;
500
current_collect_record->next = (collect_record *) malloc (sizeof (collect_record));
501
current_collect_record=current_collect_record->next;
505
record_fb->head_record = (collect_record *) malloc (sizeof (collect_record));
506
current_collect_record=record_fb->head_record;
509
if (current_action!=NULL)
511
switch (current_action->type)
513
case ACTION_COLLECT :
515
switch (current_action->action_data.ca.type)
517
case COLLECT_REGISTERS:
519
current_collect_record->collect_data= (char *)malloc (current_reg_type->register_bytes);
520
fetch_inferior_registers (-1, current_collect_record ->collect_data);
521
current_collect_record->collect_data_length=current_reg_type->register_bytes;
522
current_collect_record->ca=&(current_action->action_data.ca);
523
current_collect_record->next=NULL;
528
current_collect_record->collect_data= (char *)malloc(current_action->action_data.ca.description.mc.length);
529
//should be the content of basereg
530
if (current_action->action_data.ca.description.mc.base_reg == -1)
536
registers = (unsigned char *)malloc(current_reg_type->register_bytes);
538
fetch_inferior_registers (current_action->action_data.ca.description.mc.base_reg, registers);
539
base_reg_val=registers[current_reg_type->register_byte (current_action->action_data.ca.description.mc.base_reg)];
543
current_collect_record->collect_data_length=sim_read (base_reg_val+current_action->action_data.ca.description.mc.offset, current_collect_record->collect_data, current_action->action_data.ca.description.mc.length);
544
current_collect_record->ca=&(current_action->action_data.ca);
545
current_collect_record->next=NULL;
548
case COLLECT_EXPRESSION : ;
563
void do_action_list (unsigned int tp_id, action* actions, frame_buffer * fb)
565
frame_buffer *current_frame_buffer;
566
action * current_action;
568
current_frame_buffer =fb;
569
current_action =actions;
570
while (current_action !=NULL)
572
switch (current_action->type)
576
do_action(tp_id,current_action,current_frame_buffer);
577
fprintf (stderr," tracepoint : %x, remaining pass : %x, action collect \n",skyeye_ice.tps[tp_id].number,skyeye_ice.tps[tp_id].remaining_pass);
578
current_action=current_action->sibling;
583
if (current_action->action_data.wa.remaining_steps !=0)
585
set_tracepoint_status(tp_id, TRACEPOINT_STEPPING);
586
current_action->action_data.wa.remaining_steps--;
587
do_action_list(tp_id,current_action->child,current_frame_buffer);
589
fprintf (stderr," tracepoint : %x, remaining pass : %x, action stepping \n",skyeye_ice.tps[tp_id].number,skyeye_ice.tps[tp_id].remaining_pass);
592
if (current_action->action_data.wa.remaining_steps ==0)
594
set_tracepoint_status(tp_id, TRACEPOINT_ENABLED);
595
current_action->action_data.wa.remaining_steps=current_action->action_data.wa.step_count;
596
fprintf (stderr," tracepoint : %x, action stepping end \n",skyeye_ice.tps[tp_id].number);
598
current_action=current_action->sibling;
605
void handle_tracepoint(int tp_id)
607
action * current_action;
608
frame_buffer *current_frame_buffer;
610
if (get_tracepoint_status(tp_id)==TRACEPOINT_STEPPING)
612
//find the while stepping action
613
current_action=skyeye_ice.tps[tp_id].actions;
614
while (current_action->type!=ACTION_WHILE)
616
if (current_action->sibling !=NULL)
618
current_action=current_action->sibling;
624
current_frame_buffer= add_frame_buffer();
625
current_frame_buffer->tp_number=skyeye_ice.tps[tp_id].number;
626
//current action is a while action
627
do_action_list (tp_id,current_action,current_frame_buffer);
630
if (get_tracepoint_status(tp_id)==TRACEPOINT_ENABLED)
632
if (skyeye_ice.tps[tp_id].pass_count!=0)
634
if (skyeye_ice.tps[tp_id].remaining_pass!=0)
636
//decrease the remaining_pass
637
skyeye_ice.tps[tp_id].remaining_pass--;
641
//remaining_pass ==0, don't collect tracess
645
current_frame_buffer= add_frame_buffer();
646
current_frame_buffer->tp_number=skyeye_ice.tps[tp_id].number;
647
do_action_list (tp_id,skyeye_ice.tps[tp_id].actions,current_frame_buffer);
651
void clear_tracepoints(void)
655
skyeye_ice.num_tps=0;
657
for (i=0;i<MAX_TRACEPOINTS;i++)
659
if (skyeye_ice.tps[i].actions!=NULL)
660
delete_action(skyeye_ice.tps[i].actions);
661
skyeye_ice.tps[i].actions=NULL;
667
void init_tracepoints ()
670
skyeye_ice.tps_status=TRACE_STOPPED;
672
clear_frame_buffers();
674
skyeye_ice.selected_fb=NULL;
681
void start_trace_recording ()
683
skyeye_ice.tps_status=TRACE_STARTED;
686
void stop_trace_recording ()
688
skyeye_ice.tps_status=TRACE_STOPPED;
691
void start_trace_focusing ()
693
skyeye_ice.tps_status=TRACE_FOCUSING;
696
void stop_trace_focusing ()
698
skyeye_ice.tps_status=TRACE_STARTED;
699
skyeye_ice.selected_fb=NULL;
702
trace_status get_trace_status()
704
return(skyeye_ice.tps_status);