00001
00034 #include "breakpoints.H"
00035
00041 Breakpoints::Breakpoints(int quant) {
00042 quantMax = quant;
00043 if ( ( bp = (unsigned int *) calloc( quantMax,
00044 sizeof( unsigned int ) ) ) == NULL )
00045 {
00046 perror( "Couldn't allocate breakpoint array." );
00047 quantMax = 0;
00048 }
00049 memset( bp, 255, sizeof(unsigned int)* quantMax );
00050 this->quant = 0;
00051 }
00052
00053
00057 Breakpoints::~Breakpoints() {
00058 if ( bp ) free( bp );
00059 bp = NULL;
00060 }
00061
00062
00070 int Breakpoints::add(unsigned int address) {
00071 int i, tmp;
00072
00073 if ( ( ! bp ) || ( quant >= quantMax ) )
00074 return -1;
00075
00076 for ( i = 0; i < quant; i++ )
00077
00078 if ( address < bp[i] )
00079 {
00080 tmp = address;
00081 address = bp[i];
00082 bp[i] = tmp;
00083 }
00084
00085 bp[ quant ++ ] = address;
00086 return 0;
00087 }
00088
00089
00097 int Breakpoints::remove(unsigned int address) {
00098 int i;
00099
00100 if ( ( ! bp ) || ( quant >= quantMax ) )
00101 return -1;
00102
00103 for ( i = 0; i < quant; i ++ )
00104 if ( bp[ i ] == address )
00105 {
00106
00107 for ( ; i < ( quant - 1 ); i ++ )
00108 bp[ i ] = bp[ i + 1 ];
00109
00110 quant --;
00111 return 0;
00112 }
00113
00114 return -1;
00115 }
00116
00124 int Breakpoints::exists(unsigned int address) {
00125 int i;
00126
00127 if ( ( ! bp ) || ( quant >= quantMax ) )
00128 return 0;
00129
00130 for ( i = 0; i < quant; i ++ )
00131 if ( address == bp[ i ] )
00132 return 1;
00133 else
00134
00135
00136
00137 if ( bp[ i ] > address )
00138 return 0;
00139
00140 return 0;
00141 }