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 <xiaojing.liu@intel.com>
Reviewed-by: Zhang Yanmin <yanmin.zhang@intel.com>
Reviewed-by: Liu Chuansheng <chuansheng.liu@intel.com>
Reviewed-by: Zhao Yakui <yakui.zhao@intel.com>
Reviewed-by: Geoffroy Van Cutsem <geoffroy.vancutsem@intel.com>
Acked-by: Eddie Dong <Eddie.dong@intel.com>
This commit is contained in:
xiaojin2 2018-05-14 14:10:38 +08:00 committed by lijinxia
parent 6627fdf772
commit 14cf505a01
2 changed files with 70 additions and 1 deletions

View File

@ -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 $<

View File

@ -0,0 +1,61 @@
/*
* Copyright (C) <2018> Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#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 <pid> (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;
}