From cdfdfae3222022c68d09f94b25f37096b0bc8464 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Wed, 22 Oct 2014 09:58:17 -0300 Subject: input: Fix ctrl+c handling in convert_input --- src/nvim/os/input.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index b7eba47d5e..2c8026d099 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -264,15 +264,15 @@ static void convert_input(void) for (int i = (int)count - 1; i >= 0; i--) { if (inbuf[i] == 3) { + got_int = true; consume_count = (size_t)i; break; } } - if (consume_count) { + if (got_int) { // Remove everything typed before the CTRL-C rbuffer_consumed(input_buffer, consume_count); - got_int = true; } } -- cgit From 97f0c1eda19f5a2f8c13ba2cb1c8a1e60ed52c2d Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Wed, 22 Oct 2014 10:12:08 -0300 Subject: travis: Force verification of DLOG macros We use INFO as the default log level, which leaves code inside DLOG macros unverified(currently it has compilation errors). Decrease the log level on travis builds for automatic verification in PRs. --- .ci/common.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.ci/common.sh b/.ci/common.sh index d84a306885..76faf595c8 100644 --- a/.ci/common.sh +++ b/.ci/common.sh @@ -67,3 +67,5 @@ install_prebuilt_deps sudo apt-mark hold oracle-java7-installer oracle-java8-installer sudo apt-get update + +export CFLAGS='-DMIN_LOG_LEVEL=0' # force verification of DLOG macros -- cgit From 42334463447e884b9a1198be599d734fbe2d1eb7 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Wed, 22 Oct 2014 10:16:52 -0300 Subject: debug: Fix broken DLOG macro calls --- scripts/msgpack-gen.lua | 1 + src/nvim/os/rstream.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/msgpack-gen.lua b/scripts/msgpack-gen.lua index ba962d69d1..aa3aaf40fa 100644 --- a/scripts/msgpack-gen.lua +++ b/scripts/msgpack-gen.lua @@ -86,6 +86,7 @@ end output = io.open(outputf, 'wb') output:write([[ +#include #include #include #include diff --git a/src/nvim/os/rstream.c b/src/nvim/os/rstream.c index 8cfd9d1b75..d96b3d931c 100644 --- a/src/nvim/os/rstream.c +++ b/src/nvim/os/rstream.c @@ -73,13 +73,14 @@ void rbuffer_consumed(RBuffer *rbuffer, size_t count) void rbuffer_produced(RBuffer *rbuffer, size_t count) { rbuffer->wpos += count; - DLOG("Received %u bytes from RStream(%p)", (size_t)cnt, rbuffer->rstream); + DLOG("Received %u bytes from RStream(%p)", (size_t)count, rbuffer->rstream); rbuffer_relocate(rbuffer); if (rbuffer->rstream && rbuffer->wpos == rbuffer->capacity) { // The last read filled the buffer, stop reading for now + // rstream_stop(rbuffer->rstream); - DLOG("Buffer for RStream(%p) is full, stopping it", rstream); + DLOG("Buffer for RStream(%p) is full, stopping it", rbuffer->rstream); } } -- cgit From b31a74ad11c8943b795d132c7d3e3c961d048118 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Wed, 22 Oct 2014 10:45:54 -0300 Subject: debug: Improve debugging of msgpack-rpc requests - Add the api_stringify function to display API objects - Use api_stringify to display request arguments and return values in DLOG statements. --- scripts/msgpack-gen.lua | 14 +++++- src/nvim/api/private/helpers.c | 98 ++++++++++++++++++++++++++++++++++++++++++ src/nvim/msgpack_rpc/channel.c | 5 --- 3 files changed, 111 insertions(+), 6 deletions(-) diff --git a/scripts/msgpack-gen.lua b/scripts/msgpack-gen.lua index aa3aaf40fa..284956a43c 100644 --- a/scripts/msgpack-gen.lua +++ b/scripts/msgpack-gen.lua @@ -164,7 +164,13 @@ for i = 1, #functions do output:write('static Object handle_'..fn.name..'(uint64_t channel_id, uint64_t request_id, Array args, Error *error)') output:write('\n{') - output:write('\n DLOG("Handling msgpack-rpc call to '..fn.name..'(request id: %" PRIu64 ")", request_id);') + output:write('\n') + output:write('\n#if MIN_LOG_LEVEL <= DEBUG_LOG_LEVEL\n {') + output:write('\n char *args_repr = api_stringify(ARRAY_OBJ(args));') + output:write('\n DLOG("msgpack-rpc request received(id: %" PRIu64 ", method: '..fn.name..' , arguments: %s)", request_id, args_repr);') + output:write('\n free(args_repr);') + output:write('\n }\n#endif') + output:write('\n') output:write('\n Object ret = NIL;') -- Declare/initialize variables that will hold converted arguments for j = 1, #fn.parameters do @@ -229,6 +235,7 @@ for i = 1, #functions do end -- and check for the error output:write('\n if (error->set) {') + output:write('\n DLOG("msgpack-rpc request failed(id: %" PRIu64 ", method: '..fn.name..' , error: %s)", request_id, error->msg);') output:write('\n goto cleanup;') output:write('\n }\n') else @@ -238,6 +245,11 @@ for i = 1, #functions do if fn.return_type ~= 'void' then output:write('\n ret = '..string.upper(real_type(fn.return_type))..'_OBJ(rv);') end + output:write('\n#if MIN_LOG_LEVEL <= DEBUG_LOG_LEVEL\n {') + output:write('\n char *rv_repr = api_stringify(ret);') + output:write('\n DLOG("msgpack-rpc request succeeded(id: %" PRIu64 ", method: '..fn.name..' , return value: %s)", request_id, rv_repr);') + output:write('\n free(rv_repr);') + output:write('\n }\n#endif') -- Now generate the cleanup label for freeing memory allocated for the -- arguments output:write('\n\ncleanup:'); diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 093cb0e55f..784915cd16 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -553,6 +554,103 @@ Dictionary api_metadata(void) return copy_object(DICTIONARY_OBJ(metadata)).data.dictionary; } +char *api_stringify(Object obj) +{ + Array array = ARRAY_DICT_INIT; + print_to_array(obj, &array); + size_t size = 0; + for (size_t i = 0; i < array.size; i++) { + size += array.items[i].data.string.size; + } + + char *rv = xmalloc(size + 1); + size_t pos = 0; + for (size_t i = 0; i < array.size; i++) { + String str = array.items[i].data.string; + memcpy(rv + pos, str.data, str.size); + pos += str.size; + free(str.data); + } + rv[pos] = NUL; + free(array.items); + return rv; +} + +static void print_to_array(Object obj, Array *array) +{ + char buf[32]; + + switch (obj.type) { + case kObjectTypeNil: + ADD(*array, STRING_OBJ(cstr_to_string("nil"))); + break; + + case kObjectTypeBoolean: + ADD(*array, + STRING_OBJ(cstr_to_string(obj.data.boolean ? "true" : "false"))); + break; + + case kObjectTypeInteger: + snprintf(buf, sizeof(buf), "%" PRId64, obj.data.integer); + ADD(*array, STRING_OBJ(cstr_to_string(buf))); + break; + + case kObjectTypeFloat: + snprintf(buf, sizeof(buf), "%f", obj.data.floating); + ADD(*array, STRING_OBJ(cstr_to_string(buf))); + break; + + case kObjectTypeBuffer: + snprintf(buf, sizeof(buf), "Buffer(%" PRIu64 ")", obj.data.buffer); + ADD(*array, STRING_OBJ(cstr_to_string(buf))); + break; + + case kObjectTypeWindow: + snprintf(buf, sizeof(buf), "Window(%" PRIu64 ")", obj.data.window); + ADD(*array, STRING_OBJ(cstr_to_string(buf))); + break; + + case kObjectTypeTabpage: + snprintf(buf, sizeof(buf), "Tabpage(%" PRIu64 ")", obj.data.tabpage); + ADD(*array, STRING_OBJ(cstr_to_string(buf))); + break; + + case kObjectTypeString: + ADD(*array, STRING_OBJ(cstr_to_string("\""))); + ADD(*array, STRING_OBJ(cstr_to_string(obj.data.string.data))); + ADD(*array, STRING_OBJ(cstr_to_string("\""))); + break; + + case kObjectTypeArray: + ADD(*array, STRING_OBJ(cstr_to_string("["))); + for (size_t i = 0; i < obj.data.array.size; i++) { + print_to_array(obj.data.array.items[i], array); + if (i < obj.data.array.size - 1) { + ADD(*array, STRING_OBJ(cstr_to_string(", "))); + } + } + ADD(*array, STRING_OBJ(cstr_to_string("]"))); + break; + + case kObjectTypeDictionary: + ADD(*array, STRING_OBJ(cstr_to_string("{"))); + for (size_t i = 0; i < obj.data.dictionary.size; i++) { + ADD(*array, + STRING_OBJ(cstr_to_string(obj.data.dictionary.items[i].key.data))); + ADD(*array, STRING_OBJ(cstr_to_string(": "))); + print_to_array(obj.data.dictionary.items[i].value, array); + if (i < obj.data.array.size - 1) { + ADD(*array, STRING_OBJ(cstr_to_string(", "))); + } + } + ADD(*array, STRING_OBJ(cstr_to_string("}"))); + break; + + default: + ADD(*array, STRING_OBJ(cstr_to_string("INVALID"))); + } +} + static void init_error_type_metadata(Dictionary *metadata) { Dictionary types = ARRAY_DICT_INIT; diff --git a/src/nvim/msgpack_rpc/channel.c b/src/nvim/msgpack_rpc/channel.c index a1ab12f7c3..94605c37e9 100644 --- a/src/nvim/msgpack_rpc/channel.c +++ b/src/nvim/msgpack_rpc/channel.c @@ -461,15 +461,10 @@ static void call_request_handler(Channel *channel, msgpack_packer_init(&response, &out_buffer, msgpack_sbuffer_write); if (error.set) { - ELOG("Error dispatching msgpack-rpc call: %s(request: id %" PRIu64 ")", - error.msg, - request_id); channel_write(channel, serialize_response(request_id, &error, NIL, &out_buffer)); } - DLOG("Successfully completed mspgack-rpc call(request id: %" PRIu64 ")", - request_id); channel_write(channel, serialize_response(request_id, &error, result, &out_buffer)); } -- cgit