1
1
mirror of https://github.com/tstack/lnav.git synced 2024-09-11 13:05:51 +03:00

[debug] more debugging stuff

Defect Number:
    Reviewed By:
   Testing Done:
This commit is contained in:
Timothy Stack 2014-03-06 06:58:49 -08:00
parent 86e32f4b45
commit b6baae7730
41 changed files with 202 additions and 164 deletions

View File

@ -32,7 +32,6 @@
#ifndef __auto_fd_hh
#define __auto_fd_hh
#include <assert.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/select.h>
@ -40,6 +39,8 @@
#include <new>
#include <exception>
#include "lnav_log.hh"
/**
* Resource management class for file descriptors.
*
@ -60,7 +61,7 @@ public:
{
int retval, fd[2];
assert(fd != NULL);
require(fd != NULL);
if ((retval = ::pipe(fd)) == 0) {
af[0] = fd[0];
@ -78,8 +79,8 @@ public:
auto_fd(int fd = -1)
: af_fd(fd)
{
assert(fd >= -1);
assert(fd < (int)FD_SETSIZE);
require(fd >= -1);
require(fd < (int)FD_SETSIZE);
};
/**
@ -126,8 +127,8 @@ public:
*/
auto_fd &operator =(int fd)
{
assert(fd >= -1);
assert(fd < (int)FD_SETSIZE);
require(fd >= -1);
require(fd < (int)FD_SETSIZE);
this->reset(fd);
return *this;
@ -186,8 +187,8 @@ public:
*/
void reset(int fd = -1)
{
assert(fd >= -1);
assert(fd < (int)FD_SETSIZE);
require(fd >= -1);
require(fd < (int)FD_SETSIZE);
if (this->af_fd != fd) {
if (this->af_fd != -1) {

View File

@ -33,7 +33,6 @@
#define __auto_mem_hh
#include <string.h>
#include <assert.h>
#include <unistd.h>
#include <stdlib.h>

View File

@ -40,14 +40,14 @@ LineType bookmark_vector<LineType>::next(LineType start)
LineType retval(-1);
assert(start >= -1);
require(start >= -1);
ub = upper_bound(this->begin(), this->end(), start);
if (ub != this->end()) {
retval = *ub;
}
assert(retval == -1 || start < retval);
ensure(retval == -1 || start < retval);
return retval;
}
@ -59,7 +59,7 @@ LineType bookmark_vector<LineType>::prev(LineType start)
LineType retval(-1);
assert(start >= 0);
require(start >= 0);
lb = lower_bound(this->begin(), this->end(), start);
if (lb != this->begin()) {
@ -67,7 +67,7 @@ LineType bookmark_vector<LineType>::prev(LineType start)
retval = *lb;
}
assert(retval < start);
ensure(retval < start);
return retval;
}

View File

@ -32,13 +32,12 @@
#ifndef __bookmarks_hh
#define __bookmarks_hh
#include <assert.h>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include "lnav_log.hh"
#include "listview_curses.hh"
struct bookmark_metadata {
@ -72,7 +71,7 @@ public:
{
typename bookmark_vector::iterator lb, retval;
assert(vl >= 0);
require(vl >= 0);
lb = std::lower_bound(this->begin(), this->end(), vl);
if (lb == this->end() || *lb != vl) {

View File

@ -31,11 +31,12 @@
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <sys/types.h>
#include <string>
#include "lnav_log.hh"
template<size_t COUNT, typename T = unsigned char>
struct byte_array {
static const size_t BYTE_COUNT = COUNT * sizeof(T);
@ -64,7 +65,7 @@ struct byte_array {
void to_string(char *buffer) const
{
assert(buffer != NULL);
require(buffer != NULL);
for (size_t lpc = 0; lpc < BYTE_COUNT; lpc++) {
snprintf(&buffer[lpc * 2], 3, "%02x", this->ba_data[lpc]);

View File

@ -39,6 +39,7 @@
#include <iterator>
#include <algorithm>
#include "lnav_log.hh"
#include "yajlpp.hh"
#include "pcrepp.hh"
#include "byte_array.hh"
@ -260,7 +261,7 @@ public:
element(const element &other)
{
/* assert(other.e_sub_elements == NULL); */
/* require(other.e_sub_elements == NULL); */
this->e_capture = other.e_capture;
this->e_token = other.e_token;
@ -311,7 +312,7 @@ public:
const element & get_pair_value(void) const
{
assert(this->e_token == DNT_PAIR);
require(this->e_token == DNT_PAIR);
return this->e_sub_elements->back();
};
@ -757,12 +758,12 @@ private:
pcre_context::iterator pc_iter;
pc_iter = std::find_if(pc.begin(), pc.end(), capture_if_not(-1));
assert(pc_iter != pc.end());
require(pc_iter != pc.end());
elem.e_capture = *pc_iter;
assert(elem.e_capture.c_begin != -1);
assert(elem.e_capture.c_end != -1);
require(elem.e_capture.c_begin != -1);
require(elem.e_capture.c_end != -1);
prefix_state = dfs_prefix_next(prefix_state, elem.e_token);
semi_state = dfs_semi_next(semi_state, elem.e_token);

View File

@ -320,7 +320,7 @@ bool data_scanner::tokenize(pcre_context &pc, data_token_t &token_out)
}
}
assert((0 <= token_out && token_out < DT_TERMINAL_MAX));
ensure((0 <= token_out && token_out < DT_TERMINAL_MAX));
return true;
}

View File

@ -33,7 +33,6 @@
#include <stdio.h>
#include <errno.h>
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
@ -64,7 +63,7 @@ grep_proc::grep_proc(pcre *code,
gp_sink(NULL),
gp_control(NULL)
{
assert(this->invariant());
require(this->invariant());
}
grep_proc::~grep_proc()
@ -101,7 +100,7 @@ void grep_proc::handle_match(int line,
void grep_proc::start(void)
{
assert(this->invariant());
require(this->invariant());
if (this->gp_child_started || this->gp_queue.empty()) {
return;
@ -135,7 +134,7 @@ void grep_proc::start(void)
fcntl(err_pipe.read_end(), F_SETFL, O_NONBLOCK);
fcntl(err_pipe.read_end(), F_SETFD, 1);
assert(this->gp_err_pipe.get() == -1);
require(this->gp_err_pipe.get() == -1);
this->gp_err_pipe = err_pipe.read_end();
this->gp_child_started = true;
@ -245,7 +244,7 @@ void grep_proc::cleanup(void)
while (waitpid(this->gp_child, &status, 0) < 0 && (errno == EINTR)) {
;
}
assert(!WIFSIGNALED(status) || WTERMSIG(status) != SIGABRT);
require(!WIFSIGNALED(status) || WTERMSIG(status) != SIGABRT);
this->gp_child = -1;
this->gp_child_started = false;
@ -266,7 +265,7 @@ void grep_proc::cleanup(void)
this->gp_pipe_offset = 0;
this->gp_line_buffer.reset();
assert(this->invariant());
ensure(this->invariant());
if (!this->gp_queue.empty()) {
this->start();
@ -277,7 +276,7 @@ void grep_proc::dispatch_line(char *line)
{
int start, end, capture_start;
assert(line != NULL);
require(line != NULL);
if (sscanf(line, "%d", this->gp_last_line.out()) == 1) {
/* Starting a new line with matches. */
@ -285,11 +284,11 @@ void grep_proc::dispatch_line(char *line)
if (this->gp_last_line > this->gp_highest_line) {
this->gp_highest_line = this->gp_last_line;
}
assert(this->gp_last_line >= 0);
ensure(this->gp_last_line >= 0);
}
else if (sscanf(line, "[%d:%d]", &start, &end) == 2) {
assert(start >= 0);
assert(end >= 0);
require(start >= 0);
require(end >= 0);
/* Pass the match offsets to the sink delegate. */
if (this->gp_sink != NULL) {
@ -297,8 +296,8 @@ void grep_proc::dispatch_line(char *line)
}
}
else if (sscanf(line, "(%d:%d)%n", &start, &end, &capture_start) == 2) {
assert(start == -1 || start >= 0);
assert(end >= 0);
require(start == -1 || start >= 0);
require(end >= 0);
/* Pass the captured strings to the sink delegate. */
if (this->gp_sink != NULL) {
@ -322,7 +321,7 @@ void grep_proc::dispatch_line(char *line)
void grep_proc::check_fd_set(fd_set &ready_fds)
{
assert(this->invariant());
require(this->invariant());
if (this->gp_err_pipe != -1 && FD_ISSET(this->gp_err_pipe, &ready_fds)) {
char buffer[1024 + 1];
@ -381,5 +380,5 @@ void grep_proc::check_fd_set(fd_set &ready_fds)
}
}
assert(this->invariant());
ensure(this->invariant());
}

View File

@ -35,7 +35,6 @@
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <assert.h>
#ifdef HAVE_PCRE_H
#include <pcre.h>
@ -51,6 +50,7 @@
#include "pcrepp.hh"
#include "auto_fd.hh"
#include "auto_mem.hh"
#include "lnav_log.hh"
#include "strong_int.hh"
#include "line_buffer.hh"
@ -212,8 +212,8 @@ public:
void queue_request(grep_line_t start = grep_line_t(0),
grep_line_t stop = grep_line_t(-1))
{
assert(start != -1 || stop == -1);
assert(stop == -1 || start < stop);
require(start != -1 || stop == -1);
require(stop == -1 || start < stop);
this->gp_queue.push_back(std::make_pair(start, stop));
};
@ -233,16 +233,16 @@ public:
/** Check the invariants for this object. */
bool invariant(void)
{
assert(this->gp_code != NULL);
require(this->gp_code != NULL);
if (this->gp_child_started) {
assert(this->gp_child > 0);
assert(this->gp_line_buffer.get_fd() != -1);
assert(FD_ISSET(this->gp_line_buffer.get_fd(), &this->gp_readfds));
require(this->gp_child > 0);
require(this->gp_line_buffer.get_fd() != -1);
require(FD_ISSET(this->gp_line_buffer.get_fd(), &this->gp_readfds));
}
else {
assert(this->gp_pipe_offset == 0);
/* assert(this->gp_child == -1); XXX doesnt work with static destr */
assert(this->gp_line_buffer.get_fd() == -1);
require(this->gp_pipe_offset == 0);
/* require(this->gp_child == -1); XXX doesnt work with static destr */
require(this->gp_line_buffer.get_fd() == -1);
}
return true;

View File

@ -39,6 +39,7 @@
#include <string>
#include <vector>
#include "lnav_log.hh"
#include "strong_int.hh"
#include "textview_curses.hh"
@ -93,7 +94,7 @@ public:
void set_bucket_size(unsigned int bs)
{
assert(bs > 0);
require(bs > 0);
this->hs_bucket_size = bs;
};
@ -101,7 +102,7 @@ public:
void set_group_size(unsigned int gs)
{
assert(gs > 0);
require(gs > 0);
this->hs_group_size = gs;
};
unsigned int get_group_size(void) const { return this->hs_group_size; };

View File

@ -126,7 +126,7 @@ line_buffer::line_buffer()
throw bad_alloc();
}
assert(this->invariant());
ensure(this->invariant());
}
line_buffer::~line_buffer()
@ -204,7 +204,7 @@ throw (error)
this->lb_buffer_size = 0;
this->lb_fd = fd;
assert(this->invariant());
ensure(this->invariant());
}
void line_buffer::resize_buffer(size_t new_max)
@ -268,11 +268,11 @@ throw (error)
*/
prefill = start - this->lb_file_offset;
}
assert(this->lb_file_offset <= start);
assert(prefill <= this->lb_buffer_size);
require(this->lb_file_offset <= start);
require(prefill <= this->lb_buffer_size);
available = this->lb_buffer_max - this->lb_buffer_size;
assert(available <= this->lb_buffer_max);
require(available <= this->lb_buffer_max);
if (max_length > available) {
/*
@ -300,7 +300,7 @@ throw (error)
{
bool retval = false;
assert(start >= 0);
require(start >= 0);
if (this->in_range(start) && this->in_range(start + max_length)) {
/* Cache already has the data, nothing to do. */
@ -434,7 +434,7 @@ throw (error)
break;
}
assert(this->lb_buffer_size <= this->lb_buffer_max);
ensure(this->lb_buffer_size <= this->lb_buffer_max);
}
return retval;
@ -446,7 +446,7 @@ throw (error)
size_t request_size = DEFAULT_INCREMENT;
char * retval = NULL;
assert(this->lb_fd != -1);
require(this->lb_fd != -1);
if (this->lb_last_line_offset != -1 && offset >
this->lb_last_line_offset) {
@ -514,11 +514,11 @@ throw (error)
}
}
assert((retval == NULL) ||
ensure((retval == NULL) ||
(retval >= this->lb_buffer &&
retval < (this->lb_buffer + this->lb_buffer_size)));
assert(len_out <= this->lb_buffer_size);
assert(this->invariant());
ensure(len_out <= this->lb_buffer_size);
ensure(this->invariant());
return retval;
}

View File

@ -33,13 +33,13 @@
#define __line_buffer_hh
#include <errno.h>
#include <assert.h>
#include <sys/types.h>
#include <unistd.h>
#include <zlib.h>
#include <exception>
#include "lnav_log.hh"
#include "auto_fd.hh"
#include "auto_mem.hh"
#include "shared_buffer.hh"
@ -144,8 +144,8 @@ public:
/** Check the invariants for this object. */
bool invariant(void)
{
assert(this->lb_buffer != NULL);
assert(this->lb_buffer_size <= this->lb_buffer_max);
require(this->lb_buffer != NULL);
require(this->lb_buffer_size <= this->lb_buffer_max);
return true;
};
@ -203,7 +203,7 @@ private:
off_t buffer_offset = start - this->lb_file_offset;
char *retval;
assert(buffer_offset >= 0);
require(buffer_offset >= 0);
retval = &this->lb_buffer[buffer_offset];
avail_out = this->lb_buffer_size - buffer_offset;

View File

@ -332,7 +332,7 @@ bool listview_curses::handle_mouse(mouse_event &me)
switch (this->lv_mouse_mode) {
case LV_MODE_NONE:
assert(0);
require(0);
break;
case LV_MODE_UP:

View File

@ -611,7 +611,7 @@ public:
return;
}
/* XXX assert(off <= total); */
/* XXX require(off <= total); */
if (off > (off_t)total) {
off = total;
}
@ -2441,7 +2441,7 @@ static void rl_search_internal(void *dummy, readline_curses *rc, bool complete =
break;
case LNM_CAPTURE:
assert(0);
require(0);
name = "$capture";
break;
@ -2480,7 +2480,7 @@ static void rl_search_internal(void *dummy, readline_curses *rc, bool complete =
return;
default:
assert(0);
require(0);
break;
}
@ -2534,7 +2534,7 @@ static void rl_callback(void *dummy, readline_curses *rc)
switch (lnav_data.ld_mode) {
case LNM_PAGING:
assert(0);
require(0);
break;
case LNM_COMMAND:
@ -3131,7 +3131,7 @@ static void handle_key(int ch)
break;
default:
assert(0);
require(0);
break;
}
}
@ -4143,7 +4143,7 @@ int main(int argc, char *argv[])
else {
try {
rescan_files(true);
log_info("startup: %s", PACKAGE_STRING);
log_host_info();
log_info("lnav_data:");

View File

@ -32,7 +32,6 @@
#include "config.h"
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <glob.h>
@ -69,7 +68,7 @@ bool check_experimental(const char *feature_name)
{
const char *env_value = getenv("LNAV_EXP");
assert(feature_name != NULL);
require(feature_name != NULL);
if (env_value && strcasestr(env_value, feature_name)) {
return true;

View File

@ -32,6 +32,7 @@
#include "config.h"
#include <time.h>
#include <ctype.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdlib.h>
@ -212,6 +213,51 @@ static void sigabrt(int sig)
tcsetattr(STDOUT_FILENO, TCSAFLUSH, lnav_log_orig_termios);
}
fprintf(stderr, CRASH_MSG, crash_path);
if (isatty(STDIN_FILENO)) {
char response;
fprintf(stderr, "\nWould you like to attach a debugger? (y/N) ");
fflush(stderr);
scanf("%c", &response);
if (tolower(response) == 'y') {
pid_t lnav_pid = getpid();
pid_t child_pid;
switch ((child_pid = fork())) {
case 0: {
char pid_str[32];
snprintf(pid_str, sizeof(pid_str), "--pid=%d", lnav_pid);
execlp("gdb", "gdb", pid_str, NULL);
snprintf(pid_str, sizeof(pid_str),
"--attach-pid=%d", lnav_pid);
execlp("lldb", "lldb", pid_str, NULL);
fprintf(stderr, "Could not attach gdb or lldb, exiting.\n");
_exit(1);
break;
}
case -1: {
break;
}
default: {
int status;
while (wait(&status) < 0) {
}
break;
}
}
}
}
_exit(1);
}
@ -223,3 +269,9 @@ void log_install_handlers(void)
signal(SIGILL, sigabrt);
signal(SIGFPE, sigabrt);
}
void log_abort(void)
{
sigabrt(SIGABRT);
_exit(1);
}

View File

@ -34,6 +34,12 @@
#include <stdio.h>
#include <termios.h>
#include <stdlib.h>
#include <sys/cdefs.h>
#ifndef __dead2
#define __dead2 __attribute__((noreturn))
#endif
enum lnav_log_level_t {
LOG_LEVEL_DEBUG,
@ -43,14 +49,15 @@ enum lnav_log_level_t {
};
void log_host_info(void);
void log_msg(lnav_log_level_t level, const char *src_file, int line_number,
void log_msg(enum lnav_log_level_t level, const char *src_file, int line_number,
const char *fmt, ...);
void log_install_handlers(void);
void log_abort(void) __dead2;
extern FILE *lnav_log_file;
extern const char *lnav_log_crash_dir;
extern const struct termios *lnav_log_orig_termios;
extern lnav_log_level_t lnav_log_level;
extern enum lnav_log_level_t lnav_log_level;
#define log_msg_wrapper(level, fmt...) \
do { \
@ -72,5 +79,14 @@ extern lnav_log_level_t lnav_log_level;
#define log_debug(fmt...) \
log_msg_wrapper(LOG_LEVEL_DEBUG, fmt);
#define require(e) \
((void) ((e) ? 0 : __require (#e, __FILE__, __LINE__)))
#define __require(e, file, line) \
(log_msg(LOG_LEVEL_ERROR, file, line, "failed precondition `%s'", e), log_abort(), 1)
#define ensure(e) \
((void) ((e) ? 0 : __ensure (#e, __FILE__, __LINE__)))
#define __ensure(e, file, line) \
(log_msg(LOG_LEVEL_ERROR, file, line, "failed postcondition `%s'", e), log_abort(), 1)
#endif

View File

@ -83,7 +83,7 @@ logline::level_t logline::string2level(const char *levelstr, size_t len, bool ex
int (*cmpfunc)(const char *, const char *, size_t);
assert(len == (size_t)-1 || (len != (size_t)-1 && exact));
require(len == (size_t)-1 || (len != (size_t)-1 && exact));
if (len == (size_t)-1)
len = strlen(levelstr);
@ -1065,7 +1065,7 @@ public:
break;
case logline_value::VALUE_UNKNOWN:
case logline_value::VALUE__MAX:
assert(0);
ensure(0);
break;
}
cols[vd.vd_column].vc_name = vd.vd_name.c_str();

View File

@ -32,7 +32,6 @@
#ifndef __log_format_hh
#define __log_format_hh
#include <assert.h>
#include <time.h>
#include <sys/time.h>
#include <stdint.h>
@ -48,6 +47,7 @@
#include "pcrepp.hh"
#include "yajlpp.hh"
#include "lnav_log.hh"
#include "lnav_util.hh"
#include "byte_array.hh"
#include "view_curses.hh"
@ -410,7 +410,7 @@ public:
case VALUE_UNKNOWN:
case VALUE__MAX:
assert(0);
ensure(0);
break;
}
};
@ -444,7 +444,7 @@ public:
break;
case VALUE_UNKNOWN:
case VALUE__MAX:
assert(0);
ensure(0);
break;
}

View File

@ -29,6 +29,7 @@
#include "config.h"
#include "lnav_log.hh"
#include "sql_util.hh"
#include "log_vtab_impl.hh"
@ -53,7 +54,7 @@ static const char *type_to_string(int type)
return "text";
}
assert("Invalid sqlite type");
ensure("Invalid sqlite type");
return NULL;
}
@ -76,7 +77,7 @@ std::string log_vtab_impl::get_table_statement(void)
for (iter = cols.begin(); iter != cols.end(); iter++) {
auto_mem<char, sqlite3_free> coldecl;
assert(iter->vc_name != NULL);
require(iter->vc_name != NULL);
coldecl = sqlite3_mprintf(" %Q %s %s collate %Q,\n",
iter->vc_name,
@ -239,7 +240,7 @@ static int vt_column(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int col)
logfile * lf = vt->lss->find(cl);
logfile::iterator ll = lf->begin() + cl;
assert(col >= 0);
require(col >= 0);
/* Just return the ordinal of the column requested. */
switch (col) {
@ -313,7 +314,7 @@ static int vt_column(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int col)
prev_time += prev_ll->get_millis();
curr_line_time = ll->get_time() * 1000ULL;
curr_line_time += ll->get_millis();
// assert(curr_line_time >= prev_time);
// require(curr_line_time >= prev_time);
sqlite3_result_int64(ctx, curr_line_time - prev_time);
}
break;
@ -401,7 +402,7 @@ static int vt_column(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int col)
case logline_value::VALUE_UNKNOWN:
case logline_value::VALUE__MAX:
assert(0);
require(0);
break;
}
}
@ -552,7 +553,7 @@ string log_vtab_manager::unregister_vtab(std::string name)
NULL,
NULL,
NULL);
assert(rc == SQLITE_OK);
require(rc == SQLITE_OK);
sqlite3_free(sql);

View File

@ -36,7 +36,6 @@
#include <stdarg.h>
#include <errno.h>
#include <fcntl.h>
#include <assert.h>
#include <unistd.h>
#include <ctype.h>
#include <sys/types.h>
@ -61,7 +60,7 @@ throw (error)
{
int reserve_size = 100;
assert(filename.size() > 0);
require(filename.size() > 0);
this->lf_time_offset.tv_sec = 0;
this->lf_time_offset.tv_usec = 0;
@ -104,7 +103,7 @@ throw (error)
this->lf_line_buffer.set_fd(fd);
this->lf_index.reserve(reserve_size);
assert(this->invariant());
ensure(this->invariant());
}
logfile::~logfile()
@ -156,7 +155,7 @@ void logfile::process_prefix(off_t offset, char *prefix, int len)
}
if ((*iter)->scan(this->lf_index, offset, prefix, len)) {
#if 0
assert(this->lf_index.size() == 1 ||
require(this->lf_index.size() == 1 ||
(this->lf_index[this->lf_index.size() - 2] <
this->lf_index[this->lf_index.size() - 1]));
#endif
@ -341,7 +340,7 @@ logfile_filter::type_t logfile::check_filter(iterator ll,
break;
default:
assert(0);
require(0);
break;
}
}
@ -430,7 +429,7 @@ void logfile::read_full_message(logfile::iterator ll,
shared_buffer_ref &msg_out,
int max_lines)
{
assert(ll->get_sub_offset() == 0);
require(ll->get_sub_offset() == 0);
size_t line_len = this->line_length(ll);

View File

@ -41,6 +41,7 @@
#include <vector>
#include <algorithm>
#include "lnav_log.hh"
#include "byte_array.hh"
#include "line_buffer.hh"
#include "log_format.hh"
@ -313,7 +314,7 @@ public:
/** Check the invariants for this object. */
bool invariant(void)
{
assert(this->lf_filename.size() > 0);
require(this->lf_filename.size() > 0);
return true;
};

View File

@ -172,8 +172,8 @@ void logfile_sub_source::text_value_for_line(textview_curses &tc,
{
content_line_t line(0);
assert(row >= 0);
assert((size_t)row < this->lss_index.size());
require(row >= 0);
require((size_t)row < this->lss_index.size());
line = this->lss_index[row];
this->lss_token_file = this->find(line);

View File

@ -40,6 +40,7 @@
#include <vector>
#include <algorithm>
#include "lnav_log.hh"
#include "strong_int.hh"
#include "logfile.hh"
#include "bookmarks.hh"
@ -168,7 +169,7 @@ public:
}
}
else if (lb != this->lss_user_marks[bm].end() && *lb == cl) {
assert(lb != this->lss_user_marks[bm].end());
require(lb != this->lss_user_marks[bm].end());
this->lss_user_marks[bm].erase(lb);
}
@ -192,7 +193,7 @@ public:
{
std::vector<logfile_data>::iterator existing;
assert(lf->size() < MAX_LINES_PER_FILE);
require(lf->size() < MAX_LINES_PER_FILE);
existing = std::find_if(this->lss_files.begin(),
this->lss_files.end(),

View File

@ -74,7 +74,7 @@ public:
capture(int begin, int end) : c_begin(begin), c_end(end)
{
assert(begin <= end);
require(begin <= end);
};
int c_begin;

View File

@ -31,7 +31,6 @@
#include "config.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
@ -45,6 +44,7 @@
#include <unistd.h>
#include <stdlib.h>
#include "lnav_log.hh"
#include "piper_proc.hh"
#include "line_buffer.hh"
@ -69,7 +69,7 @@ static int write_timestamp(int fd, off_t woff)
piper_proc::piper_proc(int pipefd, bool timestamp, const char *filename)
: pp_fd(-1), pp_child(-1)
{
assert(pipefd >= 0);
require(pipefd >= 0);
if (filename) {
if ((this->pp_fd =

View File

@ -185,7 +185,7 @@ char **readline_context::attempted_completion(const char *text,
rl_completion_append_character = 0;
space = strchr(rl_line_buffer, ' ');
assert(space != NULL);
require(space != NULL);
cmd = string(rl_line_buffer, 0, space - rl_line_buffer);
vector<string> &proto = loaded_context->rc_prototypes[cmd];
@ -300,7 +300,7 @@ void readline_curses::start(void)
fd_set rfds;
int maxfd;
assert(!this->rc_contexts.empty());
require(!this->rc_contexts.empty());
rl_completer_word_break_characters = (char *)" \t\n"; /* XXX */
@ -387,7 +387,7 @@ void readline_curses::start(void)
&context,
type,
&prompt_start) == 2) {
assert(this->rc_contexts[context] != NULL);
require(this->rc_contexts[context] != NULL);
this->rc_contexts[context]->
add_possibility(string(type),
@ -398,7 +398,7 @@ void readline_curses::start(void)
&context,
type,
&prompt_start) == 2) {
assert(this->rc_contexts[context] != NULL);
require(this->rc_contexts[context] != NULL);
this->rc_contexts[context]->
rem_possibility(string(type),
@ -722,43 +722,4 @@ void readline_curses::do_update(void)
wmove(this->vc_window, this->get_actual_y(), this->vc_x);
}
}
#if 0
{
static pcrepp captures("(?<!\\\\)\\((?:\\\\\\)|[^)])+$");
pcre_context_static<30> pc;
pcre_input pi(line, 0, rc);
while (captures.match(pc, pi)) {
pcre_context::capture_t *cap = pc.all();
mvwchgat(this->vc_window, this->get_actual_y(), cap->c_begin, 1, 0,
view_colors::ansi_color_pair_index(COLOR_RED, COLOR_BLACK),
NULL);
}
if (line[this->vc_x] == ')' && line[this->vc_x - 1] != '\\') {
for (int lpc = this->vc_x; lpc > 0; lpc--) {
if (line[lpc] == '(' && line[lpc - 1] != '\\') {
mvwchgat(this->vc_window, this->get_actual_y(), lpc, 1, A_BOLD | A_REVERSE,
view_colors::ansi_color_pair_index(COLOR_CYAN, COLOR_BLACK),
NULL);
break;
}
}
}
if (line[this->vc_x] == '(' && line[this->vc_x - 1] != '\\') {
for (int lpc = this->vc_x; lpc < rc; lpc++) {
if (line[lpc] == ')' && line[lpc - 1] != '\\') {
mvwchgat(this->vc_window, this->get_actual_y(), lpc, 1, A_BOLD | A_REVERSE,
view_colors::ansi_color_pair_index(COLOR_CYAN, COLOR_BLACK),
NULL);
break;
}
}
}
}
#endif
}

View File

@ -69,7 +69,8 @@ public:
command_map_t *commands = NULL,
bool case_sensitive = true)
: rc_name(name),
rc_case_sensitive(case_sensitive)
rc_case_sensitive(case_sensitive),
rc_highlighter(NULL)
{
char *home;

View File

@ -32,7 +32,6 @@
#ifndef __shared_buffer_hh
#define __shared_buffer_hh
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>

View File

@ -39,6 +39,7 @@
#include "sqlite3.h"
#include "lnav.hh"
#include "lnav_log.hh"
#include "sql_util.hh"
#include "sqlite-extension-func.h"
@ -54,7 +55,7 @@ static void sql_log_top_datetime(sqlite3_context *context,
{
char buffer[64];
assert(argc == 0);
require(argc == 0);
sql_strftime(buffer, sizeof(buffer),
lnav_data.ld_top_time,

View File

@ -30,9 +30,9 @@
* negative chars in their default char type.
*/
#include <assert.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include "strnatcmp.h"

View File

@ -90,7 +90,7 @@ void view_curses::mvwattrline(WINDOW *window,
size_t exp_index = 0;
string full_line;
assert(lr.lr_end >= 0);
require(lr.lr_end >= 0);
line_width = lr.length();
tab_count = count(line.begin(), line.end(), '\t');
@ -145,8 +145,8 @@ void view_curses::mvwattrline(WINDOW *window,
struct line_range attr_range = iter->sa_range;
std::map<size_t, size_t>::iterator tab_iter;
assert(attr_range.lr_start >= 0);
assert(attr_range.lr_end >= -1);
require(attr_range.lr_start >= 0);
require(attr_range.lr_end >= -1);
tab_iter = tab_list.lower_bound(attr_range.lr_start);
if (tab_iter != tab_list.end()) {

View File

@ -35,7 +35,6 @@
#include "config.h"
#include <zlib.h>
#include <assert.h>
#include <stdint.h>
#include <limits.h>
#include <signal.h>
@ -482,16 +481,16 @@ public:
*/
int attrs_for_role(role_t role) const
{
assert(role >= 0);
assert(role < VCR__MAX);
require(role >= 0);
require(role < VCR__MAX);
return this->vc_role_colors[role];
};
int reverse_attrs_for_role(role_t role) const
{
assert(role >= 0);
assert(role < VCR__MAX);
require(role >= 0);
require(role < VCR__MAX);
return this->vc_role_reverse_colors[role];
};

View File

@ -31,12 +31,12 @@
#include "config.h"
#include <assert.h>
#include <unistd.h>
#include <string.h>
#include <map>
#include "lnav_log.hh"
#include "vt52_curses.hh"
#if defined HAVE_NCURSESW_CURSES_H
@ -96,7 +96,7 @@ public:
map<string, const char *>::const_iterator iter;
const char *retval = NULL;
assert(seq != NULL);
require(seq != NULL);
if ((iter = this->vem_input_map.find(seq)) !=
this->vem_input_map.end()) {
@ -175,8 +175,8 @@ const char *vt52_curses::map_input(int ch, int &len_out)
len_out = 1;
}
assert(retval != NULL);
assert(len_out > 0);
ensure(retval != NULL);
ensure(len_out > 0);
return retval;
}
@ -185,7 +185,7 @@ void vt52_curses::map_output(const char *output, int len)
{
int y, lpc;
assert(this->vc_window != NULL);
require(this->vc_window != NULL);
y = this->get_actual_y();
wmove(this->vc_window, y, this->vc_x);
@ -214,7 +214,7 @@ void vt52_curses::map_output(const char *output, int len)
this->vc_escape_len = 0;
}
else {
assert(0);
ensure(0);
}
}
}

View File

@ -48,6 +48,7 @@ test_ansi_scrubber_SOURCES = test_ansi_scrubber.cc
test_ansi_scrubber_LDADD = ../src/libdiag.a $(CURSES_LIB)
test_auto_fd_SOURCES = test_auto_fd.cc
test_auto_fd_LDADD = ../src/libdiag.a
test_auto_mem_SOURCES = test_auto_mem.cc

View File

@ -170,8 +170,7 @@ test_ansi_scrubber_DEPENDENCIES = ../src/libdiag.a \
$(am__DEPENDENCIES_1)
am_test_auto_fd_OBJECTS = test_auto_fd.$(OBJEXT)
test_auto_fd_OBJECTS = $(am_test_auto_fd_OBJECTS)
test_auto_fd_LDADD = $(LDADD)
test_auto_fd_DEPENDENCIES =
test_auto_fd_DEPENDENCIES = ../src/libdiag.a
am_test_auto_mem_OBJECTS = test_auto_mem.$(OBJEXT)
test_auto_mem_OBJECTS = $(am_test_auto_mem_OBJECTS)
test_auto_mem_LDADD = $(LDADD)
@ -619,6 +618,7 @@ LDADD = -lz
test_ansi_scrubber_SOURCES = test_ansi_scrubber.cc
test_ansi_scrubber_LDADD = ../src/libdiag.a $(CURSES_LIB)
test_auto_fd_SOURCES = test_auto_fd.cc
test_auto_fd_LDADD = ../src/libdiag.a
test_auto_mem_SOURCES = test_auto_mem.cc
test_bookmarks_SOURCES = test_bookmarks.cc
test_bookmarks_LDADD = ../src/libdiag.a

View File

@ -29,6 +29,7 @@
#include "config.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

View File

@ -29,6 +29,7 @@
#include "config.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

View File

@ -29,6 +29,7 @@
#include "config.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

View File

@ -36,6 +36,8 @@
#include "config.h"
#include <assert.h>
#include "ansi_scrubber.hh"
using namespace std;

View File

@ -29,6 +29,7 @@
#include "config.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>