fixed bsearch in debug API as its a lower bound one

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%4066
This commit is contained in:
Borja Ferrer 2006-08-19 20:52:42 +00:00
parent 063baa9e71
commit b8d6dddea5
2 changed files with 38 additions and 32 deletions

View File

@ -7,10 +7,10 @@
#define CELLBOUNDMAX (INT_MAX/sizeof(cell_t))
#define STACKMARGIN ((cell_t)(16*sizeof(cell_t)))
int main()
/*int main()
{
/** temporary testing area */
sp_context_t ctx;
/*sp_context_t ctx;
cell_t l, *p;
cell_t arr1[] = {1,3,3,7};
cell_t arr2[] = {123,1234,12345,123456};
@ -38,7 +38,7 @@ int main()
assert(SP_HeapRelease(&ctx, l) == SP_ERR_NONE);
return 0;
}
}*/
int SP_HeapAlloc(sp_context_t *ctx, unsigned int cells, cell_t *local_addr, cell_t **phys_addr)
{
@ -516,7 +516,7 @@ int SP_CreateBaseContext(sp_plugin_t *plugin, sp_context_t **ctx)
const char *strbase;
sp_fdbg_symbol_t *sym;
sp_fdbg_arraydim_t *arr;
sp_context_t *context = *ctx;
sp_context_t *context;
context = (sp_context_t *)malloc(sizeof(sp_context_t));
memset(context, 0, sizeof(sp_context_t));

View File

@ -1,30 +1,34 @@
#include "sp_vm.h"
#include "sp_vm_debug.h"
#define USHR(x) ((unsigned int)(x)>>1)
int SP_DbgLookupFile(sp_context_t *ctx, ucell_t addr, const char **filename)
{
int diff, high, low;
uint32_t mid;
int high, low, mid;
high = ctx->plugin->debug.files_num - 1;
low = 0;
high = ctx->plugin->debug.files_num;
low = -1;
while (low <= high)
while (high - low > 1)
{
mid = (low + high) / 2;
diff = ctx->files[mid].addr - addr;
if (diff == 0)
mid = USHR(low + high);
if (ctx->files[mid].addr <= addr)
{
*filename = ctx->files[mid].name;
return SP_ERR_NONE;
} else if (diff < 0) {
low = mid + 1;
low = mid;
} else {
high = mid - 1;
high = mid;
}
}
return SP_ERR_NOT_FOUND;
if (low == -1)
{
return SP_ERR_NOT_FOUND;
}
*filename = ctx->files[low].name;
return SP_ERR_NONE;
}
int SP_DbgLookupFunction(sp_context_t *ctx, ucell_t addr, const char **name)
@ -53,28 +57,30 @@ int SP_DbgLookupFunction(sp_context_t *ctx, ucell_t addr, const char **name)
int SP_DbgLookupLine(sp_context_t *ctx, ucell_t addr, uint32_t *line)
{
int diff, high, low;
uint32_t mid;
int high, low, mid;
high = ctx->plugin->debug.lines_num - 1;
low = 0;
high = ctx->plugin->debug.lines_num;
low = -1;
while (low <= high)
while (high - low > 1)
{
mid = (low + high) / 2;
diff = ctx->lines[mid].addr - addr;
if (diff == 0)
mid = USHR(low + high);
if (ctx->lines[mid].addr <= addr)
{
*line = ctx->lines[mid].line;
return SP_ERR_NONE;
} else if (diff < 0) {
low = mid + 1;
low = mid;
} else {
high = mid - 1;
high = mid;
}
}
return SP_ERR_NOT_FOUND;
if (low == -1)
{
return SP_ERR_NOT_FOUND;
}
*line = ctx->lines[low].line;
return SP_ERR_NONE;
}
int SP_DbgInstallBreak(sp_context_t *ctx, SPVM_DEBUGBREAK newpfn, SPVM_DEBUGBREAK *oldpfn)