Skip to content

Commit

Permalink
debugger: move commands into their separate implementation file
Browse files Browse the repository at this point in the history
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
  • Loading branch information
bazsi committed Dec 10, 2024
1 parent 186334d commit fb10503
Show file tree
Hide file tree
Showing 13 changed files with 503 additions and 204 deletions.
13 changes: 12 additions & 1 deletion lib/debugger/Makefile.am
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down
32 changes: 32 additions & 0 deletions lib/debugger/cmd-continue.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2015 Balabit
* Copyright (c) 2015 Balázs Scheidler
* Copyright (c) 2024 Balázs Scheidler <balazs.scheidler@axoflow.com>
* 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;
}
42 changes: 42 additions & 0 deletions lib/debugger/cmd-display.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2015 Balabit
* Copyright (c) 2015 Balázs Scheidler
* Copyright (c) 2024 Balázs Scheidler <balazs.scheidler@axoflow.com>
* 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;
}
32 changes: 32 additions & 0 deletions lib/debugger/cmd-drop.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2015 Balabit
* Copyright (c) 2015 Balázs Scheidler
* Copyright (c) 2024 Balázs Scheidler <balazs.scheidler@axoflow.com>
* 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;
}
32 changes: 32 additions & 0 deletions lib/debugger/cmd-follow.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2015 Balabit
* Copyright (c) 2015 Balázs Scheidler
* Copyright (c) 2024 Balázs Scheidler <balazs.scheidler@axoflow.com>
* 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;
}
60 changes: 60 additions & 0 deletions lib/debugger/cmd-help.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2015 Balabit
* Copyright (c) 2015 Balázs Scheidler
* Copyright (c) 2024 Balázs Scheidler <balazs.scheidler@axoflow.com>
* 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[])
{
if (self->breakpoint_site)
{
printf("syslog-ng interactive console\n"
"Stopped on a breakpoint.\n"
"The following commands are available:\n\n"
" help, h, ? Display this help\n"
" info, i Display information about the current execution state\n"
" list, l Display source code at the current location\n"
" continue, c Continue until the next breakpoint\n"
" step, s Single step\n"
" follow, f Follow this message, ignoring any other breakpoints\n"
" display Set the displayed message template\n"
" trace, t Trace this message along the configuration\n"
" print, p Print the current log message\n"
" drop, d Drop the current message\n"
" quit, q Tell syslog-ng to exit\n"
);
}
else
{
printf("syslog-ng interactive console\n"
"Stopped on an interrupt.\n"
"The following commands are available:\n\n"
" help, h, ? Display this help\n"
" list, l Display source code at the current location\n"
" continue, c Continue until the next breakpoint\n"
" quit, q Tell syslog-ng to exit\n"
);
}
return TRUE;
}
50 changes: 50 additions & 0 deletions lib/debugger/cmd-info.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2015 Balabit
* Copyright (c) 2015 Balázs Scheidler
* Copyright (c) 2024 Balázs Scheidler <balazs.scheidler@axoflow.com>
* 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;
}
57 changes: 57 additions & 0 deletions lib/debugger/cmd-list.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2015 Balabit
* Copyright (c) 2015 Balázs Scheidler
* Copyright (c) 2024 Balázs Scheidler <balazs.scheidler@axoflow.com>
* 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;
}
Loading

0 comments on commit fb10503

Please sign in to comment.