Move write_debug to buffer utils as write_to_debug_buffer
This commit is contained in:
parent
be03db9a24
commit
e6f0e8ef75
|
@ -1,8 +1,8 @@
|
||||||
#include "assert.hh"
|
#include "assert.hh"
|
||||||
|
|
||||||
#include "exception.hh"
|
|
||||||
#include "debug.hh"
|
|
||||||
#include "backtrace.hh"
|
#include "backtrace.hh"
|
||||||
|
#include "buffer_utils.hh"
|
||||||
|
#include "exception.hh"
|
||||||
|
|
||||||
#if defined(__CYGWIN__)
|
#if defined(__CYGWIN__)
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
@ -48,7 +48,7 @@ bool notify_fatal_error(const String& msg)
|
||||||
void on_assert_failed(const char* message)
|
void on_assert_failed(const char* message)
|
||||||
{
|
{
|
||||||
String debug_info = format("pid: {}\ncallstack:\n{}", getpid(), Backtrace{}.desc());
|
String debug_info = format("pid: {}\ncallstack:\n{}", getpid(), Backtrace{}.desc());
|
||||||
write_debug(format("assert failed: '{}'\n{}", message, debug_info));
|
write_to_debug_buffer(format("assert failed: '{}'\n{}", message, debug_info));
|
||||||
|
|
||||||
const auto msg = format("{}\n[Debug Infos]\n{}", message, debug_info);
|
const auto msg = format("{}\n[Debug Infos]\n{}", message, debug_info);
|
||||||
if (not notify_fatal_error(msg))
|
if (not notify_fatal_error(msg))
|
||||||
|
|
|
@ -166,4 +166,23 @@ Buffer* create_fifo_buffer(String name, int fd, bool scroll)
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void write_to_debug_buffer(StringView str)
|
||||||
|
{
|
||||||
|
if (not BufferManager::has_instance())
|
||||||
|
{
|
||||||
|
write(2, str.data(), (int)str.length());
|
||||||
|
write(2, "\n", 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const StringView debug_buffer_name = "*debug*";
|
||||||
|
if (Buffer* buffer = BufferManager::instance().get_buffer_ifp(debug_buffer_name))
|
||||||
|
buffer->insert(buffer->end(), str);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
String line = str + ((str.empty() or str.back() != '\n') ? "\n" : "");
|
||||||
|
create_buffer_from_data(line, debug_buffer_name, Buffer::Flags::NoUndo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,8 @@ Buffer* create_buffer_from_data(StringView data, StringView name,
|
||||||
Buffer::Flags flags,
|
Buffer::Flags flags,
|
||||||
time_t fs_timestamp = InvalidTime);
|
time_t fs_timestamp = InvalidTime);
|
||||||
|
|
||||||
|
void write_to_debug_buffer(StringView str);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // buffer_utils_hh_INCLUDED
|
#endif // buffer_utils_hh_INCLUDED
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
#include "completion.hh"
|
#include "completion.hh"
|
||||||
#include "containers.hh"
|
#include "containers.hh"
|
||||||
#include "context.hh"
|
#include "context.hh"
|
||||||
#include "debug.hh"
|
|
||||||
#include "event_manager.hh"
|
#include "event_manager.hh"
|
||||||
#include "face_registry.hh"
|
#include "face_registry.hh"
|
||||||
#include "file.hh"
|
#include "file.hh"
|
||||||
|
@ -870,7 +869,7 @@ const CommandDesc echo_cmd = {
|
||||||
{
|
{
|
||||||
String message = join(parser, ' ', false);
|
String message = join(parser, ' ', false);
|
||||||
if (parser.get_switch("debug"))
|
if (parser.get_switch("debug"))
|
||||||
write_debug(message);
|
write_to_debug_buffer(message);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto face = get_face(parser.get_switch("color").value_or("StatusLine").str());
|
auto face = get_face(parser.get_switch("color").value_or("StatusLine").str());
|
||||||
|
@ -898,34 +897,34 @@ const CommandDesc debug_cmd = {
|
||||||
{
|
{
|
||||||
if (parser[0] == "info")
|
if (parser[0] == "info")
|
||||||
{
|
{
|
||||||
write_debug(format("pid: {}", getpid()));
|
write_to_debug_buffer(format("pid: {}", getpid()));
|
||||||
write_debug(format("session: {}", Server::instance().session()));
|
write_to_debug_buffer(format("session: {}", Server::instance().session()));
|
||||||
}
|
}
|
||||||
else if (parser[0] == "buffers")
|
else if (parser[0] == "buffers")
|
||||||
{
|
{
|
||||||
write_debug("Buffers:");
|
write_to_debug_buffer("Buffers:");
|
||||||
for (auto& buffer : BufferManager::instance())
|
for (auto& buffer : BufferManager::instance())
|
||||||
write_debug(buffer->debug_description());
|
write_to_debug_buffer(buffer->debug_description());
|
||||||
}
|
}
|
||||||
else if (parser[0] == "options")
|
else if (parser[0] == "options")
|
||||||
{
|
{
|
||||||
write_debug("Options:");
|
write_to_debug_buffer("Options:");
|
||||||
for (auto& option : context.options().flatten_options())
|
for (auto& option : context.options().flatten_options())
|
||||||
write_debug(format(" * {}: {}", option->name(), option->get_as_string()));
|
write_to_debug_buffer(format(" * {}: {}", option->name(), option->get_as_string()));
|
||||||
}
|
}
|
||||||
else if (parser[0] == "memory")
|
else if (parser[0] == "memory")
|
||||||
{
|
{
|
||||||
auto total = 0;
|
auto total = 0;
|
||||||
write_debug("Memory usage:");
|
write_to_debug_buffer("Memory usage:");
|
||||||
for (int domain = 0; domain < (int)MemoryDomain::Count; ++domain)
|
for (int domain = 0; domain < (int)MemoryDomain::Count; ++domain)
|
||||||
{
|
{
|
||||||
size_t count = domain_allocated_bytes[domain];
|
size_t count = domain_allocated_bytes[domain];
|
||||||
total += count;
|
total += count;
|
||||||
write_debug(format(" {}: {}", domain_name((MemoryDomain)domain), count));
|
write_to_debug_buffer(format(" {}: {}", domain_name((MemoryDomain)domain), count));
|
||||||
}
|
}
|
||||||
write_debug(format(" Total: {}", total));
|
write_to_debug_buffer(format(" Total: {}", total));
|
||||||
#if defined(__GLIBC__) || defined(__CYGWIN__)
|
#if defined(__GLIBC__) || defined(__CYGWIN__)
|
||||||
write_debug(format(" Malloced: {}", mallinfo().uordblks));
|
write_to_debug_buffer(format(" Malloced: {}", mallinfo().uordblks));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if (parser[0] == "shared-strings")
|
else if (parser[0] == "shared-strings")
|
||||||
|
@ -954,7 +953,7 @@ const CommandDesc source_cmd = {
|
||||||
}
|
}
|
||||||
catch (Kakoune::runtime_error& err)
|
catch (Kakoune::runtime_error& err)
|
||||||
{
|
{
|
||||||
write_debug(format("{}:{}", parser[0], err.what()));
|
write_to_debug_buffer(format("{}:{}", parser[0], err.what()));
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
31
src/debug.cc
31
src/debug.cc
|
@ -1,31 +0,0 @@
|
||||||
#include "debug.hh"
|
|
||||||
|
|
||||||
#include "assert.hh"
|
|
||||||
#include "buffer.hh"
|
|
||||||
#include "buffer_manager.hh"
|
|
||||||
#include "buffer_utils.hh"
|
|
||||||
#include "string.hh"
|
|
||||||
|
|
||||||
namespace Kakoune
|
|
||||||
{
|
|
||||||
|
|
||||||
void write_debug(StringView str)
|
|
||||||
{
|
|
||||||
if (not BufferManager::has_instance())
|
|
||||||
{
|
|
||||||
write(2, str.data(), (int)str.length());
|
|
||||||
write(2, "\n", 1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const StringView debug_buffer_name = "*debug*";
|
|
||||||
if (Buffer* buffer = BufferManager::instance().get_buffer_ifp(debug_buffer_name))
|
|
||||||
buffer->insert(buffer->end(), str);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
String line = str + ((str.empty() or str.back() != '\n') ? "\n" : "");
|
|
||||||
create_buffer_from_data(line, debug_buffer_name, Buffer::Flags::NoUndo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
13
src/debug.hh
13
src/debug.hh
|
@ -1,13 +0,0 @@
|
||||||
#ifndef debug_hh_INCLUDED
|
|
||||||
#define debug_hh_INCLUDED
|
|
||||||
|
|
||||||
namespace Kakoune
|
|
||||||
{
|
|
||||||
|
|
||||||
class StringView;
|
|
||||||
|
|
||||||
void write_debug(StringView str);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // debug_hh_INCLUDED
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include "buffer.hh"
|
#include "buffer.hh"
|
||||||
#include "buffer_manager.hh"
|
#include "buffer_manager.hh"
|
||||||
#include "buffer_utils.hh"
|
#include "buffer_utils.hh"
|
||||||
#include "debug.hh"
|
|
||||||
#include "unicode.hh"
|
#include "unicode.hh"
|
||||||
#include "regex.hh"
|
#include "regex.hh"
|
||||||
#include "string.hh"
|
#include "string.hh"
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include "containers.hh"
|
#include "containers.hh"
|
||||||
#include "context.hh"
|
#include "context.hh"
|
||||||
#include "debug.hh"
|
#include "buffer_utils.hh"
|
||||||
#include "regex.hh"
|
#include "regex.hh"
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
|
@ -60,7 +60,7 @@ void HookManager::run_hook(StringView hook_name,
|
||||||
}
|
}
|
||||||
catch (runtime_error& err)
|
catch (runtime_error& err)
|
||||||
{
|
{
|
||||||
write_debug(format("error running hook {}/{}: {}",
|
write_to_debug_buffer(format("error running hook {}/{}: {}",
|
||||||
hook_name, hook.first, err.what()));
|
hook_name, hook.first, err.what()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
#include "buffer_manager.hh"
|
#include "buffer_manager.hh"
|
||||||
#include "buffer_utils.hh"
|
#include "buffer_utils.hh"
|
||||||
#include "context.hh"
|
#include "context.hh"
|
||||||
#include "debug.hh"
|
|
||||||
#include "display_buffer.hh"
|
#include "display_buffer.hh"
|
||||||
#include "face_registry.hh"
|
#include "face_registry.hh"
|
||||||
#include "file.hh"
|
#include "file.hh"
|
||||||
|
@ -430,7 +429,7 @@ bool InsertCompleter::try_complete(CompleteFunc complete_func)
|
||||||
}
|
}
|
||||||
catch (runtime_error& e)
|
catch (runtime_error& e)
|
||||||
{
|
{
|
||||||
write_debug(format("error while trying to run completer: {}", e.what()));
|
write_to_debug_buffer(format("error while trying to run completer: {}", e.what()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (not m_completions.is_valid())
|
if (not m_completions.is_valid())
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
#include "commands.hh"
|
#include "commands.hh"
|
||||||
#include "containers.hh"
|
#include "containers.hh"
|
||||||
#include "context.hh"
|
#include "context.hh"
|
||||||
#include "debug.hh"
|
|
||||||
#include "event_manager.hh"
|
#include "event_manager.hh"
|
||||||
#include "face_registry.hh"
|
#include "face_registry.hh"
|
||||||
#include "file.hh"
|
#include "file.hh"
|
||||||
|
@ -383,7 +382,7 @@ int run_server(StringView session, StringView init_command,
|
||||||
register_commands();
|
register_commands();
|
||||||
register_highlighters();
|
register_highlighters();
|
||||||
|
|
||||||
write_debug("*** This is the debug buffer, where debug info will be written ***");
|
write_to_debug_buffer("*** This is the debug buffer, where debug info will be written ***");
|
||||||
|
|
||||||
Server server(session.empty() ? to_string(getpid()) : session.str());
|
Server server(session.empty() ? to_string(getpid()) : session.str());
|
||||||
|
|
||||||
|
@ -395,11 +394,11 @@ int run_server(StringView session, StringView init_command,
|
||||||
}
|
}
|
||||||
catch (Kakoune::runtime_error& error)
|
catch (Kakoune::runtime_error& error)
|
||||||
{
|
{
|
||||||
write_debug(format("error while parsing kakrc:\n {}", error.what()));
|
write_to_debug_buffer(format("error while parsing kakrc:\n {}", error.what()));
|
||||||
}
|
}
|
||||||
catch (Kakoune::client_removed&)
|
catch (Kakoune::client_removed&)
|
||||||
{
|
{
|
||||||
write_debug("error while parsing kakrc: asked to quit");
|
write_to_debug_buffer("error while parsing kakrc: asked to quit");
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -419,7 +418,7 @@ int run_server(StringView session, StringView init_command,
|
||||||
}
|
}
|
||||||
catch (Kakoune::runtime_error& error)
|
catch (Kakoune::runtime_error& error)
|
||||||
{
|
{
|
||||||
write_debug(format("error while opening command line files: {}", error.what()));
|
write_to_debug_buffer(format("error while opening command line files: {}", error.what()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
new Buffer("*scratch*", Buffer::Flags::None);
|
new Buffer("*scratch*", Buffer::Flags::None);
|
||||||
|
|
|
@ -2,15 +2,15 @@
|
||||||
|
|
||||||
#include "buffer.hh"
|
#include "buffer.hh"
|
||||||
#include "buffer_manager.hh"
|
#include "buffer_manager.hh"
|
||||||
|
#include "buffer_utils.hh"
|
||||||
#include "client_manager.hh"
|
#include "client_manager.hh"
|
||||||
#include "command_manager.hh"
|
#include "command_manager.hh"
|
||||||
#include "commands.hh"
|
#include "commands.hh"
|
||||||
#include "containers.hh"
|
#include "containers.hh"
|
||||||
#include "context.hh"
|
#include "context.hh"
|
||||||
#include "debug.hh"
|
|
||||||
#include "face_registry.hh"
|
#include "face_registry.hh"
|
||||||
#include "flags.hh"
|
|
||||||
#include "file.hh"
|
#include "file.hh"
|
||||||
|
#include "flags.hh"
|
||||||
#include "option_manager.hh"
|
#include "option_manager.hh"
|
||||||
#include "register_manager.hh"
|
#include "register_manager.hh"
|
||||||
#include "selectors.hh"
|
#include "selectors.hh"
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#include "remote.hh"
|
#include "remote.hh"
|
||||||
|
|
||||||
#include "buffer_manager.hh"
|
#include "buffer_manager.hh"
|
||||||
|
#include "buffer_utils.hh"
|
||||||
#include "client_manager.hh"
|
#include "client_manager.hh"
|
||||||
#include "command_manager.hh"
|
#include "command_manager.hh"
|
||||||
#include "debug.hh"
|
|
||||||
#include "display_buffer.hh"
|
#include "display_buffer.hh"
|
||||||
#include "event_manager.hh"
|
#include "event_manager.hh"
|
||||||
|
|
||||||
|
@ -289,12 +289,12 @@ RemoteUI::RemoteUI(int socket)
|
||||||
m_input_callback(mode);
|
m_input_callback(mode);
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
write_debug(format("remote client connected: {}", m_socket_watcher.fd()));
|
write_to_debug_buffer(format("remote client connected: {}", m_socket_watcher.fd()));
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteUI::~RemoteUI()
|
RemoteUI::~RemoteUI()
|
||||||
{
|
{
|
||||||
write_debug(format("remote client disconnected: {}", m_socket_watcher.fd()));
|
write_to_debug_buffer(format("remote client disconnected: {}", m_socket_watcher.fd()));
|
||||||
m_socket_watcher.close_fd();
|
m_socket_watcher.close_fd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -402,7 +402,7 @@ Key RemoteUI::get_key()
|
||||||
}
|
}
|
||||||
catch (socket_error&)
|
catch (socket_error&)
|
||||||
{
|
{
|
||||||
write_debug("ungraceful deconnection detected");
|
write_to_debug_buffer("ungraceful deconnection detected");
|
||||||
throw client_removed{};
|
throw client_removed{};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -585,7 +585,7 @@ private:
|
||||||
}
|
}
|
||||||
catch (runtime_error& e)
|
catch (runtime_error& e)
|
||||||
{
|
{
|
||||||
write_debug(format("error running command '{}': {}",
|
write_to_debug_buffer(format("error running command '{}': {}",
|
||||||
m_buffer, e.what()));
|
m_buffer, e.what()));
|
||||||
}
|
}
|
||||||
catch (client_removed&) {}
|
catch (client_removed&) {}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include "shared_string.hh"
|
#include "shared_string.hh"
|
||||||
#include "debug.hh"
|
#include "buffer_utils.hh"
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
@ -28,7 +28,7 @@ void StringRegistry::purge_unused()
|
||||||
|
|
||||||
void StringRegistry::debug_stats() const
|
void StringRegistry::debug_stats() const
|
||||||
{
|
{
|
||||||
write_debug("Shared Strings stats:");
|
write_to_debug_buffer("Shared Strings stats:");
|
||||||
size_t total_refcount = 0;
|
size_t total_refcount = 0;
|
||||||
size_t total_size = 0;
|
size_t total_size = 0;
|
||||||
size_t count = m_strings.size();
|
size_t count = m_strings.size();
|
||||||
|
@ -37,8 +37,8 @@ void StringRegistry::debug_stats() const
|
||||||
total_refcount += st.m_storage->refcount - 1;
|
total_refcount += st.m_storage->refcount - 1;
|
||||||
total_size += (int)st.m_storage->length;
|
total_size += (int)st.m_storage->length;
|
||||||
}
|
}
|
||||||
write_debug(format(" data size: {}, mean: {}", total_size, (float)total_size/count));
|
write_to_debug_buffer(format(" data size: {}, mean: {}", total_size, (float)total_size/count));
|
||||||
write_debug(format(" refcounts: {}, mean: {}", total_refcount, (float)total_refcount/count));
|
write_to_debug_buffer(format(" refcounts: {}, mean: {}", total_refcount, (float)total_refcount/count));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "shell_manager.hh"
|
#include "shell_manager.hh"
|
||||||
|
|
||||||
#include "context.hh"
|
#include "context.hh"
|
||||||
#include "debug.hh"
|
#include "buffer_utils.hh"
|
||||||
#include "event_manager.hh"
|
#include "event_manager.hh"
|
||||||
#include "file.hh"
|
#include "file.hh"
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ std::pair<String, int> ShellManager::eval(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (not child_stderr.empty())
|
if (not child_stderr.empty())
|
||||||
write_debug("shell stderr: <<<\n" + child_stderr + ">>>");
|
write_to_debug_buffer(format("shell stderr: <<<\n{}>>>", child_stderr));
|
||||||
|
|
||||||
int status = 0;
|
int status = 0;
|
||||||
waitpid(pid, &status, 0);
|
waitpid(pid, &status, 0);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user