diff --git a/tools/acrn-crashlog/usercrash/Makefile b/tools/acrn-crashlog/usercrash/Makefile index 2df1dc005..b4c75c443 100644 --- a/tools/acrn-crashlog/usercrash/Makefile +++ b/tools/acrn-crashlog/usercrash/Makefile @@ -1,4 +1,4 @@ -all: check_obj usercrash_s usercrash_c +all: check_obj usercrash_s usercrash_c debugger CURRDIR := $(shell pwd) INCLUDE += -I $(CURRDIR)/include/ @@ -19,6 +19,14 @@ usercrash_c: $(BUILDDIR)/usercrash/obj/protocol.o \ $(BUILDDIR)/common/obj/strutils.o $(CC) -g $(CFLAGS) $(INCLUDE) $^ -o $(BUILDDIR)/usercrash/bin/$@ -lsystemd +debugger: $(BUILDDIR)/usercrash/obj/debugger.o \ + $(BUILDDIR)/usercrash/obj/crash_dump.o \ + $(BUILDDIR)/common/obj/log_sys.o \ + $(BUILDDIR)/common/obj/cmdutils.o \ + $(BUILDDIR)/common/obj/fsutils.o \ + $(BUILDDIR)/common/obj/strutils.o + $(CC) -g $(CFLAGS) $(INCLUDE) $^ -o $(BUILDDIR)/usercrash/bin/$@ -lsystemd + $(BUILDDIR)/usercrash/obj/%.o:%.c $(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $< diff --git a/tools/acrn-crashlog/usercrash/debugger.c b/tools/acrn-crashlog/usercrash/debugger.c new file mode 100644 index 000000000..d454dfe5f --- /dev/null +++ b/tools/acrn-crashlog/usercrash/debugger.c @@ -0,0 +1,61 @@ +/* + * Copyright (C) <2018> Intel Corporation + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include +#include +#include +#include +#include "crash_dump.h" +#include "log_sys.h" + +/** + * Debugger can work without server when uses "debugger pid" commands to + * debug the running process. This function will dump the process info on the + * screen, also you can relocate the info to a file. + */ +static void print_usage(void) +{ + printf("debugger - tool to dump process info of a running process. "); + printf("[Usage]\n"); + printf("\t--shell cmd, debugger (root role to run)\n"); + printf("(root role to run)\n"); + printf("[Option]\n"); + printf("\t-h: print this usage message\n"); + printf("\t-v: print debugger version\n"); +} + +int main(int argc, char *argv[]) +{ + int pid; + + if (argc > 1) { + if (strcmp(argv[1], "-v") == 0) { + printf("debugger version is 1.0\n"); + return 0; + } + if (strcmp(argv[1], "-h") == 0) { + print_usage(); + return 0; + } + } else + print_usage(); + + if (getuid() != 0) { + LOGE("failed to execute debugger, root is required\n"); + exit(EXIT_FAILURE); + } + + if (argc == 2) { + /* it's from shell cmd */ + pid = atoi(argv[1]); + crash_dump(pid, 0, STDOUT_FILENO); + } else { + print_usage(); + return 0; + } + + return 0; +}