Browse code

Downgrade some messages to debug.

Török Edvin authored on 2010/03/25 00:55:04
Showing 4 changed files
... ...
@@ -821,8 +821,8 @@ static void readConstant(struct cli_bc *bc, unsigned i, unsigned comp,
821 821
 	bc->globals[i][j++] = readNumber(buffer, offset, len, ok);
822 822
     }
823 823
     if (*ok && j != comp) {
824
-	cli_errmsg("bytecode: constant has too few subcomponents: %u < %u\n", j, comp);
825
-//	*ok = 0;
824
+	cli_dbgmsg("bytecode: constant has too few subcomponents: %u < %u\n", j, comp);
825
+/*	*ok = 0; */
826 826
     }
827 827
     (*offset)++;
828 828
 }
... ...
@@ -59,13 +59,15 @@ int32_t cli_bcapi_read(struct cli_bc_ctx* ctx, uint8_t *data, int32_t size)
59 59
     if (!ctx->fmap)
60 60
 	return -1;
61 61
     if (size < 0 || size > CLI_MAX_ALLOCATION) {
62
-	cli_errmsg("bytecode: negative read size: %d\n", size);
62
+	cli_warnmsg("bytecode: negative read size: %d\n", size);
63 63
 	return -1;
64 64
     }
65 65
 /*    cli_dbgmsg("read data at %d\n", ctx->off);*/
66 66
     n = fmap_readn(ctx->fmap, data, ctx->off, size);
67
-    if (n <= 0)
67
+    if (n <= 0) {
68
+	cli_dbgmsg("bcapi_read: fmap_readn failed\n");
68 69
 	return n;
70
+    }
69 71
     ctx->off += n;
70 72
     return n;
71 73
 }
... ...
@@ -73,8 +75,10 @@ int32_t cli_bcapi_read(struct cli_bc_ctx* ctx, uint8_t *data, int32_t size)
73 73
 int32_t cli_bcapi_seek(struct cli_bc_ctx* ctx, int32_t pos, uint32_t whence)
74 74
 {
75 75
     off_t off;
76
-    if (!ctx->fmap)
76
+    if (!ctx->fmap) {
77
+	cli_dbgmsg("bcapi_seek: no fmap\n");
77 78
 	return -1;
79
+    }
78 80
     switch (whence) {
79 81
 	case 0:
80 82
 	    off = pos;
... ...
@@ -86,8 +90,11 @@ int32_t cli_bcapi_seek(struct cli_bc_ctx* ctx, int32_t pos, uint32_t whence)
86 86
 	    off = ctx->file_size + pos;
87 87
 	    break;
88 88
     }
89
-    if (off < 0 || off > ctx->file_size)
89
+    if (off < 0 || off > ctx->file_size) {
90
+	cli_dbgmsg("bcapi_seek: out of file: %ld (max %d)\n",
91
+		   off, ctx->file_size);
90 92
 	return -1;
93
+    }
91 94
     ctx->off = off;
92 95
     return off;
93 96
 }
... ...
@@ -125,8 +132,10 @@ uint32_t cli_bcapi_disasm_x86(struct cli_bc_ctx *ctx, struct DISASM_RESULT *res,
125 125
     n = MIN(32, ctx->fmap->len - ctx->off);
126 126
     buf = fmap_need_off_once(ctx->fmap, ctx->off, n);
127 127
     next = cli_disasm_one(buf, n, res, 0);
128
-    if (!next)
128
+    if (!next) {
129
+	cli_dbgmsg("bcapi_disasm: failed\n");
129 130
 	return -1;
131
+    }
130 132
     return ctx->off + next - buf;
131 133
 }
132 134
 
... ...
@@ -162,7 +171,7 @@ int32_t cli_bcapi_write(struct cli_bc_ctx *ctx, uint8_t*data, int32_t len)
162 162
     res = cli_writen(ctx->outfd, data, len);
163 163
     if (res > 0) ctx->written += res;
164 164
     if (res == -1)
165
-	    cli_dbgmsg("Bytecode API: write failed: %d\n", errno);
165
+	cli_dbgmsg("Bytecode API: write failed: %d\n", errno);
166 166
     return res;
167 167
 }
168 168
 
... ...
@@ -274,8 +283,10 @@ uint32_t cli_bcapi_pe_rawaddr(struct cli_bc_ctx *ctx, uint32_t rva)
274 274
   const struct cli_pe_hook_data *pe = ctx->hooks.pedata;
275 275
   ret = cli_rawaddr(rva, ctx->sections, pe->nsections, &err,
276 276
 		    ctx->file_size, pe->hdr_size);
277
-  if (err)
277
+  if (err) {
278
+    cli_dbgmsg("bcapi_pe_rawaddr invalid rva: %u\n", rva);
278 279
     return PE_INVALID_RVA;
280
+  }
279 281
   return ret;
280 282
 }
281 283
 
... ...
@@ -311,8 +322,10 @@ int32_t cli_bcapi_file_find(struct cli_bc_ctx *ctx, const uint8_t* data, uint32_
311 311
     uint32_t off = ctx->off, newoff;
312 312
     int n;
313 313
 
314
-    if (!map || len > sizeof(buf)/4 || len <= 0)
314
+    if (!map || len > sizeof(buf)/4 || len <= 0) {
315
+	cli_dbgmsg("bcapi_file_find preconditions not met\n");
315 316
 	return -1;
317
+    }
316 318
     for (;;) {
317 319
 	const char *p;
318 320
 	n = fmap_readn(map, buf, off, sizeof(buf));
... ...
@@ -329,10 +342,14 @@ int32_t cli_bcapi_file_find(struct cli_bc_ctx *ctx, const uint8_t* data, uint32_
329 329
 int32_t cli_bcapi_file_byteat(struct cli_bc_ctx *ctx, uint32_t off)
330 330
 {
331 331
     unsigned char c;
332
-    if (!ctx->fmap)
332
+    if (!ctx->fmap) {
333
+	cli_dbgmsg("bcapi_file_byteat: no fmap\n");
333 334
 	return -1;
334
-    if (fmap_readn(ctx->fmap, &c, off, 1) != 1)
335
+    }
336
+    if (fmap_readn(ctx->fmap, &c, off, 1) != 1) {
337
+	cli_dbgmsg("bcapi_file_byteat: fmap_readn failed at %u\n", off);
335 338
 	return -1;
339
+    }
336 340
     return c;
337 341
 }
338 342
 
... ...
@@ -390,8 +407,10 @@ int32_t cli_bcapi_fill_buffer(struct cli_bc_ctx *ctx, uint8_t* buf,
390 390
 	return -1;
391 391
     }
392 392
     res = cli_bcapi_read(ctx, buf+remaining, tofill);
393
-    if (res <= 0)
393
+    if (res <= 0) {
394
+	cli_dbgmsg("fill_buffer5\n");
394 395
 	return res;
396
+    }
395 397
     return remaining + res;
396 398
 }
397 399
 
... ...
@@ -39,7 +39,7 @@ int cli_bytecode_prepare_jit(struct cli_all_bc *bcs)
39 39
 	    return CL_EBYTECODE;
40 40
 	}
41 41
     }
42
-    cli_warnmsg("JIT not compiled in\n");
42
+    cli_dbgmsg("JIT not compiled in\n");
43 43
     return CL_EBYTECODE;
44 44
 }
45 45
 
... ...
@@ -42,7 +42,7 @@
42 42
 static int never_inline bcfail(const char *msg, long a, long b,
43 43
 		  const char *file, unsigned line)
44 44
 {
45
-    cli_errmsg("bytecode: check failed %s (%lx and %lx) at %s:%u\n", msg, a, b, file, line);
45
+    cli_warnmsg("bytecode: check failed %s (%lx and %lx) at %s:%u\n", msg, a, b, file, line);
46 46
     return CL_EARG;
47 47
 }
48 48
 
... ...
@@ -131,7 +131,7 @@ static always_inline void* cli_stack_alloc(struct stack *stack, unsigned bytes)
131 131
     }
132 132
 
133 133
     if(bytes >= STACK_CHUNKSIZE) {
134
-	cli_errmsg("cli_stack_alloc: Attempt to allocate more than STACK_CHUNKSIZE bytes!\n");
134
+	cli_warnmsg("cli_stack_alloc: Attempt to allocate more than STACK_CHUNKSIZE bytes!\n");
135 135
 	return NULL;
136 136
     }
137 137
     /* not enough room here, allocate new chunk */
... ...
@@ -153,17 +153,17 @@ static always_inline void cli_stack_free(struct stack *stack, void *data)
153 153
     uint16_t last_size;
154 154
     struct stack_chunk *chunk = stack->chunk;
155 155
     if (!chunk) {
156
-	cli_errmsg("cli_stack_free: stack empty!\n");
156
+	cli_warnmsg("cli_stack_free: stack empty!\n");
157 157
 	return;
158 158
     }
159 159
     if ((chunk->u.data + chunk->used) != ((char*)data + stack->last_size*sizeof(align_t))) {
160
-	cli_errmsg("cli_stack_free: wrong free order: %p, expected %p\n",
160
+	cli_warnmsg("cli_stack_free: wrong free order: %p, expected %p\n",
161 161
 		   data, chunk->u.data + chunk->used - stack->last_size*sizeof(align_t));
162 162
 	return;
163 163
     }
164 164
     last_size = *(uint16_t*)&chunk->u.data[chunk->used-2];
165 165
     if (chunk->used < stack->last_size*sizeof(align_t)) {
166
-	cli_errmsg("cli_stack_free: last_size is corrupt!\n");
166
+	cli_warnmsg("cli_stack_free: last_size is corrupt!\n");
167 167
 	return;
168 168
     }
169 169
     chunk->used -= stack->last_size*sizeof(align_t);
... ...
@@ -622,7 +622,7 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct
622 622
 	    if (tv1.tv_sec > timeout.tv_sec ||
623 623
 		(tv1.tv_sec == timeout.tv_sec &&
624 624
 		 tv1.tv_usec > timeout.tv_usec)) {
625
-		cli_errmsg("Bytecode run timed out in interpreter\n");
625
+		cli_warnmsg("Bytecode run timed out in interpreter\n");
626 626
 		stop = CL_ETIMEOUT;
627 627
 		break;
628 628
 	    }
... ...
@@ -816,7 +816,7 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct
816 816
 			break;
817 817
 		    }
818 818
 		    default:
819
-			cli_errmsg("bytecode: type %u apicalls not yet implemented!\n", api->kind);
819
+			cli_warnmsg("bytecode: type %u apicalls not yet implemented!\n", api->kind);
820 820
 			stop = CL_EBYTECODE;
821 821
 		}
822 822
 		WRITE32(inst->dest, res);
... ...
@@ -838,7 +838,7 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct
838 838
 		/* TODO: unregister on ret */
839 839
 		TRACE_EXEC(inst->u.ops.funcid, inst->dest, inst->type, stack_depth);
840 840
 		if (stack_depth > 10000) {
841
-		    cli_errmsg("bytecode: stack depth exceeded\n");
841
+		    cli_warnmsg("bytecode: stack depth exceeded\n");
842 842
 		    stop = CL_EBYTECODE;
843 843
 		    break;
844 844
 		}