Skip to content

Commit

Permalink
Only build and expose the gdb interface when requested
Browse files Browse the repository at this point in the history
The gdb interface should be used for debugging libpulp, so applications
may not want this exposed.

To enable it, build with
```
configure --enable-gdb-interface
```

Signed-off-by: Giuliano Belinassi <[email protected]>
  • Loading branch information
giulianobelinassi committed Nov 4, 2024
1 parent a14c8dd commit 0486ff5
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 2 deletions.
10 changes: 10 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ AC_SUBST([LIBUNWIND_LIBS], ["-lunwind-generic -lunwind-ptrace -lunwind"])
AC_DEFINE(ENABLE_STACK_CHECK, 1, [Enable stack checking routines]),
AC_DEFINE(ENABLE_STACK_CHECK, 0, [Disable stack checking routines]))

# Enable a gdb interface so that livepatches can be triggered within gdb.
AC_ARG_ENABLE(gdb-interface,
AS_HELP_STRING([--enable-gdb-interface],
[build and exposes an interface for livepatching withing gdb. [default=no]]),
[enable_gdb_interface=yes],
[enable_gdb_interface=no; break])

AS_IF([test "$enable_gdb_interface" = "yes"],
AC_DEFINE(ENABLE_GDB_INTERFACE, 1, [Enable gdb interface for livepatching]))

# Check if libseccomp is present. This is required for testing.
CFLAGS="$CFLAGS -I/usr/include/libseccomp/"
AC_CHECK_HEADER([seccomp.h],,
Expand Down
5 changes: 5 additions & 0 deletions include/insn_queue_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ ulp_error_t insnq_insert_write(void *addr, int n, const void *bytes);

int insnq_ensure_emptiness(void);

/* Not necessary if compiling without gdb interface. */
#ifdef ENABLE_GDB_INTERFACE

/** Interpret the global instruction queue from process side. */
int insnq_interpret_from_lib(void);

#endif //ENABLE_GDB_INTERFACE

#endif
5 changes: 5 additions & 0 deletions include/minielf.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
* in this library.
*/

/* This file is not needed if we are compiling without gdb interface. */
#ifdef ENABLE_GDB_INTERFACE

#include <elf.h>

/** Maximum size of the Section String Table. */
Expand Down Expand Up @@ -67,3 +70,5 @@ long Get_ULP_Section(unsigned dest_size, unsigned char *dest, const char *file);

/** Get the .ulp.rev section from the given ELF file. */
long Get_ULP_REV_Section(unsigned dest_size, unsigned char *dest, const char *file);

#endif //ENABLE_GDB_INTERFACE
1 change: 1 addition & 0 deletions include/ulp_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#ifndef _ULP_LIB_COMMON_
#define _ULP_LIB_COMMON_

#include "config.h"
#include <elf.h>
#include <stdbool.h>
#include <stddef.h>
Expand Down
11 changes: 9 additions & 2 deletions lib/gdb_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
*/

/* Small interface that allows livepatches to be applied or reverted
* within gdb. */
* within gdb. There is no need to compile this file if
* ENABLE_GDB_INTERFACE is not defined.
*/

#include "config.h"

#ifdef ENABLE_GDB_INTERFACE

#ifndef _GNU_SOURCE
#define _GNU_SOURCE
Expand All @@ -30,7 +36,6 @@
#include <sys/types.h>
#include <link.h>

#include "config.h"
#include "ulp_common.h"
#include "ulp.h"
#include "minielf.h"
Expand Down Expand Up @@ -151,3 +156,5 @@ gdb_ulp_revert(const char *path)

return 0;
}

#endif //ENABLE_GDB_INTERFACE
7 changes: 7 additions & 0 deletions lib/minielf.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
* in this library.
*/

#include "config.h"

/* So far there is no need to compile this file if GDB interface is not set. */
#ifdef ENABLE_GDB_INTERFACE

#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
Expand Down Expand Up @@ -246,3 +251,5 @@ Get_ULP_REV_Section(unsigned dest_size, unsigned char *dest, const char *file)
{
return Get_Elf_Section(dest_size, dest, ".ulp.rev", file);
}

#endif //ENABLE_GDB_INTERFACE

0 comments on commit 0486ff5

Please sign in to comment.