From 14cf505a01b5a96398b473d2f6d455f90e305de8 Mon Sep 17 00:00:00 2001 From: xiaojin2 Date: Mon, 14 May 2018 14:10:38 +0800 Subject: [PATCH] tools: acrn-crashlog: implementation for debugger This patch is the implementation patch for debugger. Debugger is the extra feature of usercrash tool. It could be run without server in command line "debugger pid" to debug the running process. It will dump the process info on the screen, and also the info could be reloacted to a file. Signed-off-by: xiaojin2 Reviewed-by: Zhang Yanmin Reviewed-by: Liu Chuansheng Reviewed-by: Zhao Yakui Reviewed-by: Geoffroy Van Cutsem Acked-by: Eddie Dong --- tools/acrn-crashlog/usercrash/Makefile | 10 +++- tools/acrn-crashlog/usercrash/debugger.c | 61 ++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 tools/acrn-crashlog/usercrash/debugger.c 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; +}