[or-cvs] Add even more debugging code; temporarily disable inlines i...
Nick Mathewson
nickm at seul.org
Wed Apr 27 00:53:47 UTC 2005
Update of /home/or/cvsroot/tor/src/or
In directory moria.mit.edu:/tmp/cvs-serv20880/src/or
Modified Files:
buffers.c
Log Message:
Add even more debugging code; temporarily disable inlines in buffers.c
Index: buffers.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/buffers.c,v
retrieving revision 1.138
retrieving revision 1.139
diff -u -d -r1.138 -r1.139
--- buffers.c 26 Apr 2005 21:29:20 -0000 1.138
+++ buffers.c 27 Apr 2005 00:53:44 -0000 1.139
@@ -12,8 +12,9 @@
#include "or.h"
-#undef SENTINELS
-#undef CHECK_AFTER_RESIZE
+#define SENTINELS
+#define CHECK_AFTER_RESIZE
+#define PARANOIA
#ifdef SENTINELS
/* If SENTINELS is defined, check for attempts to write beyond the
@@ -33,6 +34,15 @@
#define SET_GUARDS(m,ln) do {} while (0)
#endif
+#ifdef PARANOIA
+#define check() do { assert_buf_ok(buf); } while (0)
+#else
+#define check() do { } while (0)
+#endif
+
+#undef INLINE
+#define INLINE
+
#define BUFFER_MAGIC 0xB0FFF312u
struct buf_t {
uint32_t magic; /**< Magic cookie for debugging: Must be set to BUFFER_MAGIC */
@@ -53,6 +63,7 @@
static void buf_normalize(buf_t *buf)
{
+ check();
if (buf->start + buf->datalen <= buf->mem+buf->len) {
return;
} else {
@@ -65,6 +76,7 @@
memcpy(newmem+sz, buf->mem, buf->datalen-sz);
free(RAW_MEM(buf->mem));
buf->mem = buf->start = newmem;
+ check();
}
}
@@ -91,6 +103,7 @@
size_t *more_len)
{
char *eos = at + *len;
+ check();
if (eos >= (buf->mem + buf->len)) {
*more_len = eos - (buf->mem + buf->len);
*len -= *more_len;
@@ -226,6 +239,7 @@
buf->datalen -= n;
buf->start = _wrap_ptr(buf, buf->start+n);
buf_shrink_if_underfull(buf);
+ check();
}
/** Make sure that the memory in buf ends with a zero byte. */
@@ -349,7 +363,7 @@
_split_range(buf, next, &at_most, &at_start);
r = read_to_buf_impl(s, at_most, buf, next, reached_eof);
-
+ check();
if (r < 0 || (size_t)r < at_most) {
return r; /* Either error, eof, block, or no more to read. */
}
@@ -358,6 +372,7 @@
int r2;
tor_assert(_buf_end(buf) == buf->mem);
r2 = read_to_buf_impl(s, at_start, buf, buf->start, reached_eof);
+ check();
if (r2 < 0) {
return r2;
} else {
@@ -411,6 +426,7 @@
_split_range(buf, next, &at_most, &at_start);
r = read_to_buf_tls_impl(tls, at_most, buf, next);
+ check();
if (r < 0 || (size_t)r < at_most)
return r; /* Either error, eof, block, or no more to read. */
@@ -418,6 +434,7 @@
int r2;
tor_assert(_buf_end(buf) == buf->mem);
r2 = read_to_buf_tls_impl(tls, at_start, buf, buf->mem);
+ check();
if (r2 < 0)
return r2;
else
@@ -472,6 +489,7 @@
_split_range(buf, buf->start, &flushlen0, &flushlen1);
r = flush_buf_impl(s, buf, flushlen0, buf_flushlen);
+ check();
log_fn(LOG_DEBUG,"%d: flushed %d bytes, %d ready to flush, %d remain.",
s,r,(int)*buf_flushlen,(int)buf->datalen);
@@ -482,6 +500,7 @@
if (flushlen1) {
tor_assert(buf->start == buf->mem);
r = flush_buf_impl(s, buf, flushlen1, buf_flushlen);
+ check();
log_fn(LOG_DEBUG,"%d: flushed %d bytes, %d ready to flush, %d remain.",
s,r,(int)*buf_flushlen,(int)buf->datalen);
if (r<0)
@@ -526,6 +545,7 @@
_split_range(buf, buf->start, &flushlen0, &flushlen1);
r = flush_buf_tls_impl(tls, buf, flushlen0, buf_flushlen);
+ check();
if (r < 0 || (size_t)r < flushlen0)
return r; /* Error, or can't flush any more now. */
flushed = r;
@@ -533,6 +553,7 @@
if (flushlen1) {
tor_assert(buf->start == buf->mem);
r = flush_buf_tls_impl(tls, buf, flushlen1, buf_flushlen);
+ check();
if (r<0)
return r;
flushed += r;
@@ -575,6 +596,7 @@
buf->datalen += len2;
}
log_fn(LOG_DEBUG,"added %d bytes to buf (now %d total).",(int)string_len, (int)buf->datalen);
+ check();
return buf->datalen;
}
@@ -610,8 +632,10 @@
*
* Return the number of bytes still on the buffer. */
+ check();
peek_from_buf(string, string_len, buf);
buf_remove_from_front(buf, string_len);
+ check();
return buf->datalen;
}
@@ -1040,7 +1064,11 @@
tor_assert(buf->mem);
tor_assert(buf->datalen <= buf->len);
#ifdef SENTINELS
- tor_assert(get_uint32(buf->mem - 4) == START_MAGIC);
- tor_assert(get_uint32(buf->mem + buf->len) == END_MAGIC);
+ {
+ uint32_t u32 = get_uint32(buf->mem - 4);
+ tor_assert(u32 == START_MAGIC);
+ u32 = get_uint32(buf->mem + buf->len);
+ tor_assert(u32 == END_MAGIC);
+ }
#endif
}
More information about the tor-commits
mailing list