*/
static int GetLogLines(int from_pos, char* dest_buf, int max_size);
+ /**
+ * The minimum allowed size for a log lines buffer. If the size of
+ * the buffer given will not be enough to hold a line of the maximum
+ * length, an attempt to find a log line end in GetLogLines will
+ * fail, and an empty result will be returned.
+ */
+ static const int kMinimumSizeForLogLinesBuffer = 2048;
+
/**
* Retrieve the V8 thread id of the calling thread.
*
int V8::GetLogLines(int from_pos, char* dest_buf, int max_size) {
#ifdef ENABLE_LOGGING_AND_PROFILING
+ ASSERT(max_size >= kMinimumSizeForLogLinesBuffer);
return i::Logger::GetLogLines(from_pos, dest_buf, max_size);
#endif
return 0;
char* end_pos = dest_buf + actual_size - 1;
while (end_pos >= dest_buf && *end_pos != '\n') --end_pos;
actual_size = static_cast<int>(end_pos - dest_buf + 1);
+ // If the assertion below is hit, it means that there was no line end
+ // found --- something wrong has happened.
+ ASSERT(actual_size > 0);
ASSERT(actual_size <= max_size);
return actual_size;
}
CHECK_EQ(0, Logger::GetLogLines(0, NULL, 0));
char log_lines[100];
memset(log_lines, 0, sizeof(log_lines));
- // Requesting data size which is smaller than first log message length.
- CHECK_EQ(0, Logger::GetLogLines(0, log_lines, 3));
// See Logger::StringEvent.
const char* line_1 = "aaa,\"bbb\"\n";
const int line_1_len = StrLength(line_1);
- // Still smaller than log message length.
- CHECK_EQ(0, Logger::GetLogLines(0, log_lines, line_1_len - 1));
// The exact size.
CHECK_EQ(line_1_len, Logger::GetLogLines(0, log_lines, line_1_len));
CHECK_EQ(line_1, log_lines);
const int line_2_len = StrLength(line_2);
// Now start with line_2 beginning.
CHECK_EQ(0, Logger::GetLogLines(line_1_len, log_lines, 0));
- CHECK_EQ(0, Logger::GetLogLines(line_1_len, log_lines, 3));
- CHECK_EQ(0, Logger::GetLogLines(line_1_len, log_lines, line_2_len - 1));
CHECK_EQ(line_2_len, Logger::GetLogLines(line_1_len, log_lines, line_2_len));
CHECK_EQ(line_2, log_lines);
memset(log_lines, 0, sizeof(log_lines));