Skip to content

Commit cab6e39

Browse files
authored
Merge pull request #585 from ddiss/lkl_hijack_dbg
lkl: hijack: move dbg_handler out of liblkl
2 parents fd33ab3 + db1bf05 commit cab6e39

File tree

6 files changed

+51
-55
lines changed

6 files changed

+51
-55
lines changed

tools/lkl/include/lkl.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -835,18 +835,6 @@ lkl_netdev_wintap_create(const char *ifparams)
835835
}
836836
#endif
837837

838-
839-
/*
840-
* lkl_register_dbg_handler- register a signal handler that loads a debug lib.
841-
*
842-
* The signal handler is triggered by Ctrl-Z. It creates a new pthread which
843-
* call dbg_entrance().
844-
*
845-
* If you run the program from shell script, make sure you ignore SIGTSTP by
846-
* "trap '' TSTP" in the shell script.
847-
*/
848-
void lkl_register_dbg_handler(void);
849-
850838
/**
851839
* lkl_add_neighbor - add a permanent arp entry
852840
* @ifindex - the ifindex of the interface

tools/lkl/lib/Build

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ liblkl-$(LKL_HOST_CONFIG_NT) += nt-host.o
1111
liblkl-y += utils.o
1212
liblkl-y += virtio_blk.o
1313
liblkl-y += virtio.o
14-
liblkl-y += dbg.o
15-
liblkl-y += dbg_handler.o
1614
liblkl-$(LKL_HOST_CONFIG_VIRTIO_NET) += virtio_net.o
1715
liblkl-$(LKL_HOST_CONFIG_VIRTIO_NET_FD) += virtio_net_fd.o
1816
liblkl-$(LKL_HOST_CONFIG_VIRTIO_NET_FD) += virtio_net_tap.o

tools/lkl/lib/dbg_handler.c

Lines changed: 0 additions & 39 deletions
This file was deleted.

tools/lkl/lib/hijack/Build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ liblkl-hijack-y += preload.o
22
liblkl-hijack-y += hijack.o
33
liblkl-hijack-y += init.o
44
liblkl-hijack-y += xlate.o
5+
liblkl-hijack-y += dbg_handler.o
56

67
liblkl-zpoline-y += zpoline.o
78
liblkl-zpoline-y += hijack.o
89
liblkl-zpoline-y += init.o
910
liblkl-zpoline-y += xlate.o
11+
liblkl-zpoline-y += dbg_handler.o
Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
#include <lkl.h>
33
#include <limits.h>
44
#include <string.h>
5-
#include <stdio.h>
65
#include <stdlib.h>
6+
#include <stdio.h>
7+
#include <lkl_host.h>
78

9+
static int dbg_running = 0;
810
static const char* PROMOTE = "$";
911
#define str(x) #x
1012
#define xstr(s) str(s)
@@ -248,7 +250,7 @@ static void run_cmd() {
248250
}
249251
}
250252

251-
void dbg_entrance() {
253+
static void dbg_entrance() {
252254
char input[MAX_BUF + 1];
253255
int ret;
254256
int c;
@@ -272,3 +274,37 @@ void dbg_entrance() {
272274
run_cmd();
273275
} while(1);
274276
}
277+
278+
static void dbg_thread(void* arg) {
279+
lkl_host_ops.thread_detach();
280+
printf("======Enter Debug======\n");
281+
dbg_entrance();
282+
printf("======Exit Debug======\n");
283+
dbg_running = 0;
284+
}
285+
286+
void dbg_handler(int signum) {
287+
/* We don't care about the possible race on dbg_running. */
288+
if (dbg_running) {
289+
fprintf(stderr, "A debug lib is running\n");
290+
return;
291+
}
292+
dbg_running = 1;
293+
lkl_host_ops.thread_create(&dbg_thread, NULL);
294+
}
295+
296+
#ifndef __MINGW32__
297+
#include <signal.h>
298+
void lkl_register_dbg_handler() {
299+
struct sigaction sa;
300+
sigemptyset(&sa.sa_mask);
301+
sa.sa_handler = dbg_handler;
302+
if (sigaction(SIGTSTP, &sa, NULL) == -1) {
303+
perror("sigaction");
304+
}
305+
}
306+
#else
307+
void lkl_register_dbg_handler() {
308+
fprintf(stderr, "lkl_register_dbg_handler is not implemented.\n");
309+
}
310+
#endif

tools/lkl/lib/hijack/init.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,15 @@ extern int dual_fds[];
77
void __hijack_init(void);
88
void __hijack_fini(void);
99

10+
/*
11+
* lkl_register_dbg_handler- register a signal handler that loads a debug lib.
12+
*
13+
* The signal handler is triggered by Ctrl-Z. It creates a new pthread which
14+
* call dbg_entrance().
15+
*
16+
* If you run the program from shell script, make sure you ignore SIGTSTP by
17+
* "trap '' TSTP" in the shell script.
18+
*/
19+
void lkl_register_dbg_handler(void);
20+
1021
#endif /*_LKL_HIJACK_INIT_H */

0 commit comments

Comments
 (0)