From 1c5f08a4117505624a718e46b75f6c54e97ed924 Mon Sep 17 00:00:00 2001 From: Balazs Scheidler Date: Sat, 26 Oct 2024 15:05:00 +0200 Subject: [PATCH] debugger: move commands into their separate implementation file Signed-off-by: Balazs Scheidler --- lib/debugger/Makefile.am | 13 ++- lib/debugger/cmd-continue.c | 32 ++++++ lib/debugger/cmd-display.c | 42 ++++++++ lib/debugger/cmd-drop.c | 32 ++++++ lib/debugger/cmd-follow.c | 32 ++++++ lib/debugger/cmd-help.c | 43 ++++++++ lib/debugger/cmd-info.c | 50 +++++++++ lib/debugger/cmd-list.c | 57 +++++++++++ lib/debugger/cmd-print.c | 73 +++++++++++++ lib/debugger/cmd-quit.c | 35 +++++++ lib/debugger/cmd-step.c | 32 ++++++ lib/debugger/cmd-trace.c | 33 ++++++ lib/debugger/debugger.c | 199 +++--------------------------------- 13 files changed, 486 insertions(+), 187 deletions(-) create mode 100644 lib/debugger/cmd-continue.c create mode 100644 lib/debugger/cmd-display.c create mode 100644 lib/debugger/cmd-drop.c create mode 100644 lib/debugger/cmd-follow.c create mode 100644 lib/debugger/cmd-help.c create mode 100644 lib/debugger/cmd-info.c create mode 100644 lib/debugger/cmd-list.c create mode 100644 lib/debugger/cmd-print.c create mode 100644 lib/debugger/cmd-quit.c create mode 100644 lib/debugger/cmd-step.c create mode 100644 lib/debugger/cmd-trace.c diff --git a/lib/debugger/Makefile.am b/lib/debugger/Makefile.am index 74e0854138..f1ef5a7290 100644 --- a/lib/debugger/Makefile.am +++ b/lib/debugger/Makefile.am @@ -1,6 +1,17 @@ debuggerincludedir = ${pkgincludedir}/debugger -EXTRA_DIST += lib/debugger/CMakeLists.txt +EXTRA_DIST += lib/debugger/CMakeLists.txt \ + cmd-continue.c \ + cmd-display.c \ + cmd-drop.c \ + cmd-follow.c \ + cmd-help.c \ + cmd-info.c \ + cmd-list.c \ + cmd-print.c \ + cmd-quit.c \ + cmd-step.c \ + cmd-trace.c debuggerinclude_HEADERS = \ lib/debugger/debugger.h \ diff --git a/lib/debugger/cmd-continue.c b/lib/debugger/cmd-continue.c new file mode 100644 index 0000000000..b056f41ee4 --- /dev/null +++ b/lib/debugger/cmd-continue.c @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2015 Balabit + * Copyright (c) 2015 Balázs Scheidler + * Copyright (c) 2024 Balázs Scheidler + * Copyright (c) 2024 Axoflow + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * As an additional exemption you are allowed to compile & link against the + * OpenSSL libraries as published by the OpenSSL project. See the file + * COPYING for details. + * + */ + +static gboolean +_cmd_continue(Debugger *self, gint argc, gchar *argv[]) +{ + _set_mode(self, DBG_WAITING_FOR_BREAKPOINT, FALSE); + return FALSE; +} diff --git a/lib/debugger/cmd-display.c b/lib/debugger/cmd-display.c new file mode 100644 index 0000000000..e52d53a25b --- /dev/null +++ b/lib/debugger/cmd-display.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2015 Balabit + * Copyright (c) 2015 Balázs Scheidler + * Copyright (c) 2024 Balázs Scheidler + * Copyright (c) 2024 Axoflow + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * As an additional exemption you are allowed to compile & link against the + * OpenSSL libraries as published by the OpenSSL project. See the file + * COPYING for details. + * + */ + +static gboolean +_cmd_display(Debugger *self, gint argc, gchar *argv[]) +{ + if (argc == 2) + { + GError *error = NULL; + if (!log_template_compile(self->display_template, argv[1], &error)) + { + printf("display: Error compiling template: %s\n", error->message); + g_clear_error(&error); + return TRUE; + } + } + printf("display: The template is set to: \"%s\"\n", self->display_template->template_str); + return TRUE; +} diff --git a/lib/debugger/cmd-drop.c b/lib/debugger/cmd-drop.c new file mode 100644 index 0000000000..10864af2b5 --- /dev/null +++ b/lib/debugger/cmd-drop.c @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2015 Balabit + * Copyright (c) 2015 Balázs Scheidler + * Copyright (c) 2024 Balázs Scheidler + * Copyright (c) 2024 Axoflow + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * As an additional exemption you are allowed to compile & link against the + * OpenSSL libraries as published by the OpenSSL project. See the file + * COPYING for details. + * + */ + +static gboolean +_cmd_drop(Debugger *self, gint argc, gchar *argv[]) +{ + self->breakpoint_site->drop = TRUE; + return FALSE; +} diff --git a/lib/debugger/cmd-follow.c b/lib/debugger/cmd-follow.c new file mode 100644 index 0000000000..7e8b408197 --- /dev/null +++ b/lib/debugger/cmd-follow.c @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2015 Balabit + * Copyright (c) 2015 Balázs Scheidler + * Copyright (c) 2024 Balázs Scheidler + * Copyright (c) 2024 Axoflow + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * As an additional exemption you are allowed to compile & link against the + * OpenSSL libraries as published by the OpenSSL project. See the file + * COPYING for details. + * + */ + +static gboolean +_cmd_follow(Debugger *self, gint argc, gchar *argv[]) +{ + _set_mode(self, DBG_FOLLOW_AND_BREAK, TRUE); + return FALSE; +} diff --git a/lib/debugger/cmd-help.c b/lib/debugger/cmd-help.c new file mode 100644 index 0000000000..f08252c384 --- /dev/null +++ b/lib/debugger/cmd-help.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2015 Balabit + * Copyright (c) 2015 Balázs Scheidler + * Copyright (c) 2024 Balázs Scheidler + * Copyright (c) 2024 Axoflow + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * As an additional exemption you are allowed to compile & link against the + * OpenSSL libraries as published by the OpenSSL project. See the file + * COPYING for details. + * + */ + +static gboolean +_cmd_help(Debugger *self, gint argc, gchar *argv[]) +{ + printf("syslog-ng interactive console, the following commands are available\n\n" + " help, h, or ? Display this help\n" + " continue or c Continue until the next breakpoint\n" + " step or s Single step\n" + " follow or f Follow this message, ignoring any other breakpoints\n" + " trace or t Trace this message along the configuration\n" + " info Display information about the current execution state\n" + " list or l Display source code at the current location\n" + " print, p Print the current log message\n" + " drop, d Drop the current message\n" + " quit, q Tell syslog-ng to exit\n" + ); + return TRUE; +} diff --git a/lib/debugger/cmd-info.c b/lib/debugger/cmd-info.c new file mode 100644 index 0000000000..ba3dd92082 --- /dev/null +++ b/lib/debugger/cmd-info.c @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2015 Balabit + * Copyright (c) 2015 Balázs Scheidler + * Copyright (c) 2024 Balázs Scheidler + * Copyright (c) 2024 Axoflow + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * As an additional exemption you are allowed to compile & link against the + * OpenSSL libraries as published by the OpenSSL project. See the file + * COPYING for details. + * + */ + +static gboolean +_cmd_info_pipe(Debugger *self, LogPipe *pipe) +{ + gchar buf[1024]; + + printf("LogPipe %p at %s\n", pipe, log_expr_node_format_location(pipe->expr_node, buf, sizeof(buf))); + _display_source_line(self); + + return TRUE; +} + +static gboolean +_cmd_info(Debugger *self, gint argc, gchar *argv[]) +{ + if (argc >= 2) + { + if (strcmp(argv[1], "pipe") == 0) + return _cmd_info_pipe(self, self->breakpoint_site->pipe); + } + + printf("info: List of info subcommands\n" + "info pipe -- display information about the current pipe\n"); + return TRUE; +} diff --git a/lib/debugger/cmd-list.c b/lib/debugger/cmd-list.c new file mode 100644 index 0000000000..955328f700 --- /dev/null +++ b/lib/debugger/cmd-list.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2015 Balabit + * Copyright (c) 2015 Balázs Scheidler + * Copyright (c) 2024 Balázs Scheidler + * Copyright (c) 2024 Axoflow + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * As an additional exemption you are allowed to compile & link against the + * OpenSSL libraries as published by the OpenSSL project. See the file + * COPYING for details. + * + */ + +static gboolean +_cmd_list(Debugger *self, gint argc, gchar *argv[]) +{ + gint shift = 11; + if (argc >= 2) + { + if (strcmp(argv[1], "+") == 0) + shift = 11; + else if (strcmp(argv[1], "-") == 0) + shift = -11; + else if (strcmp(argv[1], ".") == 0) + { + shift = 0; + if (self->breakpoint_site) + _set_current_location(self, self->breakpoint_site->pipe->expr_node); + } + else if (isdigit(argv[1][0])) + { + gint target_lineno = atoi(argv[1]); + if (target_lineno <= 0) + target_lineno = 1; + self->current_location.list_start = target_lineno; + } + /* drop any arguments for repeated execution */ + _set_command(self, "l"); + } + _display_source_line(self); + if (shift) + self->current_location.list_start += shift; + return TRUE; +} diff --git a/lib/debugger/cmd-print.c b/lib/debugger/cmd-print.c new file mode 100644 index 0000000000..5f47d867ca --- /dev/null +++ b/lib/debugger/cmd-print.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2015 Balabit + * Copyright (c) 2015 Balázs Scheidler + * Copyright (c) 2024 Balázs Scheidler + * Copyright (c) 2024 Axoflow + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * As an additional exemption you are allowed to compile & link against the + * OpenSSL libraries as published by the OpenSSL project. See the file + * COPYING for details. + * + */ + + +static void +_display_msg_details(Debugger *self, LogMessage *msg) +{ + GString *output = g_string_sized_new(128); + + log_msg_values_foreach(msg, _format_nvpair, NULL); + g_string_truncate(output, 0); + log_msg_format_tags(msg, output, TRUE); + printf("TAGS=%s\n", output->str); + printf("\n"); + g_string_free(output, TRUE); +} + +static gboolean +_display_msg_with_template_string(Debugger *self, LogMessage *msg, const gchar *template_string, GError **error) +{ + LogTemplate *template; + + template = log_template_new(self->cfg, NULL); + if (!log_template_compile(template, template_string, error)) + { + return FALSE; + } + _display_msg_with_template(self, msg, template); + log_template_unref(template); + return TRUE; +} + +static gboolean +_cmd_print(Debugger *self, gint argc, gchar *argv[]) +{ + if (argc == 1) + _display_msg_details(self, self->breakpoint_site->msg); + else if (argc == 2) + { + GError *error = NULL; + if (!_display_msg_with_template_string(self, self->breakpoint_site->msg, argv[1], &error)) + { + printf("print: %s\n", error->message); + g_clear_error(&error); + } + } + else + printf("print: expected no arguments or exactly one\n"); + return TRUE; +} diff --git a/lib/debugger/cmd-quit.c b/lib/debugger/cmd-quit.c new file mode 100644 index 0000000000..0190d1ead7 --- /dev/null +++ b/lib/debugger/cmd-quit.c @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2015 Balabit + * Copyright (c) 2015 Balázs Scheidler + * Copyright (c) 2024 Balázs Scheidler + * Copyright (c) 2024 Axoflow + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * As an additional exemption you are allowed to compile & link against the + * OpenSSL libraries as published by the OpenSSL project. See the file + * COPYING for details. + * + */ + +static gboolean +_cmd_quit(Debugger *self, gint argc, gchar *argv[]) +{ + _set_mode(self, DBG_QUIT, FALSE); + if (self->breakpoint_site) + self->breakpoint_site->drop = TRUE; + main_loop_exit(self->main_loop); + return FALSE; +} diff --git a/lib/debugger/cmd-step.c b/lib/debugger/cmd-step.c new file mode 100644 index 0000000000..71db537cf7 --- /dev/null +++ b/lib/debugger/cmd-step.c @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2015 Balabit + * Copyright (c) 2015 Balázs Scheidler + * Copyright (c) 2024 Balázs Scheidler + * Copyright (c) 2024 Axoflow + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * As an additional exemption you are allowed to compile & link against the + * OpenSSL libraries as published by the OpenSSL project. See the file + * COPYING for details. + * + */ + +static gboolean +_cmd_step(Debugger *self, gint argc, gchar *argv[]) +{ + _set_mode(self, DBG_WAITING_FOR_STEP, FALSE); + return FALSE; +} diff --git a/lib/debugger/cmd-trace.c b/lib/debugger/cmd-trace.c new file mode 100644 index 0000000000..ffff71107d --- /dev/null +++ b/lib/debugger/cmd-trace.c @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2015 Balabit + * Copyright (c) 2015 Balázs Scheidler + * Copyright (c) 2024 Balázs Scheidler + * Copyright (c) 2024 Axoflow + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * As an additional exemption you are allowed to compile & link against the + * OpenSSL libraries as published by the OpenSSL project. See the file + * COPYING for details. + * + */ + +static gboolean +_cmd_trace(Debugger *self, gint argc, gchar *argv[]) +{ + clock_gettime(CLOCK_MONOTONIC, &self->last_trace_event); + _set_mode(self, DBG_FOLLOW_AND_TRACE, TRUE); + return FALSE; +} diff --git a/lib/debugger/debugger.c b/lib/debugger/debugger.c index e87f6d5ddb..91e842381d 100644 --- a/lib/debugger/debugger.c +++ b/lib/debugger/debugger.c @@ -1,6 +1,8 @@ /* * Copyright (c) 2015 Balabit * Copyright (c) 2015 Balázs Scheidler + * Copyright (c) 2024 Balázs Scheidler + * Copyright (c) 2024 Axoflow * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -91,19 +93,6 @@ _format_nvpair(NVHandle handle, return FALSE; } -static void -_display_msg_details(Debugger *self, LogMessage *msg) -{ - GString *output = g_string_sized_new(128); - - log_msg_values_foreach(msg, _format_nvpair, NULL); - g_string_truncate(output, 0); - log_msg_format_tags(msg, output, TRUE); - printf("TAGS=%s\n", output->str); - printf("\n"); - g_string_free(output, TRUE); -} - static void _display_msg_with_template(Debugger *self, LogMessage *msg, LogTemplate *template) { @@ -114,21 +103,6 @@ _display_msg_with_template(Debugger *self, LogMessage *msg, LogTemplate *templat g_string_free(output, TRUE); } -static gboolean -_display_msg_with_template_string(Debugger *self, LogMessage *msg, const gchar *template_string, GError **error) -{ - LogTemplate *template; - - template = log_template_new(self->cfg, NULL); - if (!log_template_compile(template, template_string, error)) - { - return FALSE; - } - _display_msg_with_template(self, msg, template); - log_template_unref(template); - return TRUE; -} - static void _set_current_location(Debugger *self, LogExprNode *expr_node) { @@ -156,126 +130,6 @@ _display_source_line(Debugger *self) puts("Unable to list source, no current location set"); } -static gboolean -_cmd_help(Debugger *self, gint argc, gchar *argv[]) -{ - printf("syslog-ng interactive console, the following commands are available\n\n" - " help, h, or ? Display this help\n" - " continue or c Continue until the next breakpoint\n" - " step or s Single step\n" - " follow or f Follow this message, ignoring any other breakpoints\n" - " trace or t Trace this message along the configuration\n" - " info Display information about the current execution state\n" - " list or l Display source code at the current location\n" - " print, p Print the current log message\n" - " drop, d Drop the current message\n" - " quit, q Tell syslog-ng to exit\n" - ); - return TRUE; -} - - -static gboolean -_cmd_print(Debugger *self, gint argc, gchar *argv[]) -{ - if (argc == 1) - _display_msg_details(self, self->breakpoint_site->msg); - else if (argc == 2) - { - GError *error = NULL; - if (!_display_msg_with_template_string(self, self->breakpoint_site->msg, argv[1], &error)) - { - printf("print: %s\n", error->message); - g_clear_error(&error); - } - } - else - printf("print: expected no arguments or exactly one\n"); - return TRUE; -} - -static gboolean -_cmd_display(Debugger *self, gint argc, gchar *argv[]) -{ - if (argc == 2) - { - GError *error = NULL; - if (!log_template_compile(self->display_template, argv[1], &error)) - { - printf("display: Error compiling template: %s\n", error->message); - g_clear_error(&error); - return TRUE; - } - } - printf("display: The template is set to: \"%s\"\n", self->display_template->template_str); - return TRUE; -} - -static gboolean -_cmd_drop(Debugger *self, gint argc, gchar *argv[]) -{ - self->breakpoint_site->drop = TRUE; - return FALSE; -} - - -static gboolean -_cmd_info_pipe(Debugger *self, LogPipe *pipe) -{ - gchar buf[1024]; - - printf("LogPipe %p at %s\n", pipe, log_expr_node_format_location(pipe->expr_node, buf, sizeof(buf))); - _display_source_line(self); - - return TRUE; -} - -static gboolean -_cmd_info(Debugger *self, gint argc, gchar *argv[]) -{ - if (argc >= 2) - { - if (strcmp(argv[1], "pipe") == 0) - return _cmd_info_pipe(self, self->breakpoint_site->pipe); - } - - printf("info: List of info subcommands\n" - "info pipe -- display information about the current pipe\n"); - return TRUE; -} - -static gboolean -_cmd_list(Debugger *self, gint argc, gchar *argv[]) -{ - gint shift = 11; - if (argc >= 2) - { - if (strcmp(argv[1], "+") == 0) - shift = 11; - else if (strcmp(argv[1], "-") == 0) - shift = -11; - else if (strcmp(argv[1], ".") == 0) - { - shift = 0; - if (self->breakpoint_site) - _set_current_location(self, self->breakpoint_site->pipe->expr_node); - } - else if (isdigit(argv[1][0])) - { - gint target_lineno = atoi(argv[1]); - if (target_lineno <= 0) - target_lineno = 1; - self->current_location.list_start = target_lineno; - } - /* drop any arguments for repeated execution */ - _set_command(self, "l"); - } - _display_source_line(self); - if (shift) - self->current_location.list_start += shift; - return TRUE; -} - static inline void _set_mode(Debugger *self, DebuggerMode new_mode, gboolean trace_message) { @@ -289,44 +143,17 @@ _set_mode(Debugger *self, DebuggerMode new_mode, gboolean trace_message) } } -static gboolean -_cmd_continue(Debugger *self, gint argc, gchar *argv[]) -{ - _set_mode(self, DBG_WAITING_FOR_BREAKPOINT, FALSE); - return FALSE; -} - -static gboolean -_cmd_step(Debugger *self, gint argc, gchar *argv[]) -{ - _set_mode(self, DBG_WAITING_FOR_STEP, FALSE); - return FALSE; -} - -static gboolean -_cmd_trace(Debugger *self, gint argc, gchar *argv[]) -{ - clock_gettime(CLOCK_MONOTONIC, &self->last_trace_event); - _set_mode(self, DBG_FOLLOW_AND_TRACE, TRUE); - return FALSE; -} - -static gboolean -_cmd_follow(Debugger *self, gint argc, gchar *argv[]) -{ - _set_mode(self, DBG_FOLLOW_AND_BREAK, TRUE); - return FALSE; -} - -static gboolean -_cmd_quit(Debugger *self, gint argc, gchar *argv[]) -{ - _set_mode(self, DBG_QUIT, FALSE); - if (self->breakpoint_site) - self->breakpoint_site->drop = TRUE; - main_loop_exit(self->main_loop); - return FALSE; -} +#include "cmd-help.c" +#include "cmd-print.c" +#include "cmd-display.c" +#include "cmd-drop.c" +#include "cmd-info.c" +#include "cmd-list.c" +#include "cmd-continue.c" +#include "cmd-step.c" +#include "cmd-trace.c" +#include "cmd-follow.c" +#include "cmd-quit.c" typedef gboolean (*DebuggerCommandFunc)(Debugger *self, gint argc, gchar *argv[]);