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:
parent
063baa9e71
commit
b8d6dddea5
@ -7,10 +7,10 @@
|
|||||||
#define CELLBOUNDMAX (INT_MAX/sizeof(cell_t))
|
#define CELLBOUNDMAX (INT_MAX/sizeof(cell_t))
|
||||||
#define STACKMARGIN ((cell_t)(16*sizeof(cell_t)))
|
#define STACKMARGIN ((cell_t)(16*sizeof(cell_t)))
|
||||||
|
|
||||||
int main()
|
/*int main()
|
||||||
{
|
{
|
||||||
/** temporary testing area */
|
/** temporary testing area */
|
||||||
sp_context_t ctx;
|
/*sp_context_t ctx;
|
||||||
cell_t l, *p;
|
cell_t l, *p;
|
||||||
cell_t arr1[] = {1,3,3,7};
|
cell_t arr1[] = {1,3,3,7};
|
||||||
cell_t arr2[] = {123,1234,12345,123456};
|
cell_t arr2[] = {123,1234,12345,123456};
|
||||||
@ -38,7 +38,7 @@ int main()
|
|||||||
assert(SP_HeapRelease(&ctx, l) == SP_ERR_NONE);
|
assert(SP_HeapRelease(&ctx, l) == SP_ERR_NONE);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
int SP_HeapAlloc(sp_context_t *ctx, unsigned int cells, cell_t *local_addr, cell_t **phys_addr)
|
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;
|
const char *strbase;
|
||||||
sp_fdbg_symbol_t *sym;
|
sp_fdbg_symbol_t *sym;
|
||||||
sp_fdbg_arraydim_t *arr;
|
sp_fdbg_arraydim_t *arr;
|
||||||
sp_context_t *context = *ctx;
|
sp_context_t *context;
|
||||||
|
|
||||||
context = (sp_context_t *)malloc(sizeof(sp_context_t));
|
context = (sp_context_t *)malloc(sizeof(sp_context_t));
|
||||||
memset(context, 0, sizeof(sp_context_t));
|
memset(context, 0, sizeof(sp_context_t));
|
||||||
|
@ -1,30 +1,34 @@
|
|||||||
#include "sp_vm.h"
|
#include "sp_vm.h"
|
||||||
#include "sp_vm_debug.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 SP_DbgLookupFile(sp_context_t *ctx, ucell_t addr, const char **filename)
|
||||||
{
|
{
|
||||||
int diff, high, low;
|
int high, low, mid;
|
||||||
uint32_t mid;
|
|
||||||
|
|
||||||
high = ctx->plugin->debug.files_num - 1;
|
high = ctx->plugin->debug.files_num;
|
||||||
low = 0;
|
low = -1;
|
||||||
|
|
||||||
while (low <= high)
|
while (high - low > 1)
|
||||||
{
|
{
|
||||||
mid = (low + high) / 2;
|
mid = USHR(low + high);
|
||||||
diff = ctx->files[mid].addr - addr;
|
if (ctx->files[mid].addr <= addr)
|
||||||
if (diff == 0)
|
|
||||||
{
|
{
|
||||||
*filename = ctx->files[mid].name;
|
low = mid;
|
||||||
return SP_ERR_NONE;
|
|
||||||
} else if (diff < 0) {
|
|
||||||
low = mid + 1;
|
|
||||||
} else {
|
} 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)
|
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 SP_DbgLookupLine(sp_context_t *ctx, ucell_t addr, uint32_t *line)
|
||||||
{
|
{
|
||||||
int diff, high, low;
|
int high, low, mid;
|
||||||
uint32_t mid;
|
|
||||||
|
|
||||||
high = ctx->plugin->debug.lines_num - 1;
|
high = ctx->plugin->debug.lines_num;
|
||||||
low = 0;
|
low = -1;
|
||||||
|
|
||||||
while (low <= high)
|
while (high - low > 1)
|
||||||
{
|
{
|
||||||
mid = (low + high) / 2;
|
mid = USHR(low + high);
|
||||||
diff = ctx->lines[mid].addr - addr;
|
if (ctx->lines[mid].addr <= addr)
|
||||||
if (diff == 0)
|
|
||||||
{
|
{
|
||||||
*line = ctx->lines[mid].line;
|
low = mid;
|
||||||
return SP_ERR_NONE;
|
|
||||||
} else if (diff < 0) {
|
|
||||||
low = mid + 1;
|
|
||||||
} else {
|
} 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)
|
int SP_DbgInstallBreak(sp_context_t *ctx, SPVM_DEBUGBREAK newpfn, SPVM_DEBUGBREAK *oldpfn)
|
||||||
|
Loading…
Reference in New Issue
Block a user